Table Indentation

ESLint rule to prevent unnecessary indentation of Markdown tables in JSDoc descriptions.

Usage

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

rule

ESLint rule to prevent unnecessary indentation of Markdown tables 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-no-table-indentation' );

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-no-table-indentation', rule );

// Lint the code:
result = linter.verify( code, {
    'rules': {
        'jsdoc-no-table-indentation': 'error'
    }
});
console.log( result );
/* =>
    [
        {
            'ruleId': 'jsdoc-no-table-indentation',
            'severity': 2,
            'message': 'Do not indent table rows',
            'line': 4,
            'column': 3,
            'nodeType': null,
            'source': '*    | Input | Output |',
            'endLine': 14,
            'endColumn': 3
        },
        {
            'ruleId': 'jsdoc-no-table-indentation',
            'severity': 2,
            'message: 'Do not indent table rows',
            'line': 6,
            'column': 3,
            'nodeType': null,
            'source': '*    | 2     | 4      |',
            'endLine': 14,
            'endColumn': 3
        }
    ]
*/