Table Pipes

ESLint rule to require pipes as fences for Markdown table rows in JSDoc descriptions.

Usage

var rule = require( '@stdlib/_tools/eslint/rules/jsdoc-table-pipes' );

rule

ESLint rule to require pipes as fences for Markdown table rows in JSDoc descriptions.

Bad:

/**
* Boop beep.
*
* x   | y
* any | boop
*
* @returns {string} a value
*
* @example
* var str = beep();
* // returns 'boop'
*/
function beep() {
    return 'boop';
}

Good:

/**
* Boop beep.
*
* | x   | y    |
* | any | boop |
*
* @returns {string} a value
*
* @example
* var str = beep();
* // returns 'boop'
*/
function beep() {
    return 'boop';
}

Examples

var Linter = require( 'eslint' ).Linter;
var rule = require( '@stdlib/_tools/eslint/rules/jsdoc-table-pipes' );

var linter = new Linter();
var result;
var code;

// Generate our source code:
code = [
    '/**',
    '* Squares a number.',
    '*',
    '* Input | Output',
    '* ----- | ------',
    '* 2     | 4',
    '*',
    '* @param {number} x - input value',
    '* @returns {number} output value',
    '*',
    '* @example',
    '* var out = square( 2 );',
    '* // returns 4',
    '*/',
    'function square( x ) {',
    '\treturn x*x;',
    '}'
].join( '\n' );

// Register the ESLint rule:
linter.defineRule( 'jsdoc-table-pipes', rule );

// Lint the code:
result = linter.verify( code, {
    'rules': {
        'jsdoc-table-pipes': 'error'
    }
});
console.log( result );
/* =>
    [
        {
            'ruleId': 'jsdoc-table-pipes',
            'severity': 2,
            'message': 'Missing initial pipe in table fence',
            'line': 4,
            'column': 3,
            'nodeType': null,
            'source': '* Input | Output',
            'endLine': 14,
            'endColumn': 3
        },
        {
            'ruleId': 'jsdoc-table-pipes',
            'severity': 2,
            'message': 'Missing final pipe in table fence',
            'line': 4,
            'column': 17,
            'nodeType': null,
            'source': '* Input | Output',
            'endLine': 14,
            'endColumn': 3
        },
        {
            'ruleId': 'jsdoc-table-pipes',
            'severity': 2,
            'message': 'Missing initial pipe in table fence',
            'line': 6,
            'column': 3,
            'nodeType': null,
            'source': '* 2     | 4',
            'endLine': 14,
            'endColumn': 3
        },
        {
            'ruleId': 'jsdoc-table-pipes',
            'severity': 2,
            'message': 'Missing final pipe in table fence',
            'line': 6,
            'column': 12,
            'nodeType': null,
            'source': '* 2     | 4',
            'endLine': 14,
            'endColumn': 3
        }
    ]
*/