Table Cell Padding

ESLint rule to require Markdown table cells in JSDoc descriptions to be correctly padded.

Usage

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

rule

ESLint rule to require Markdown table cells in JSDoc descriptions to be correctly padded.

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';
}

The rule may be configured using the same options as supported by remark.

  • padded: require table cells to be padded with spaces (default).
  • consistent: detects the first used cell padding style and requires subsequent cells to use same style.
  • compact: require table cells to be next to the pipes without any padding.

Examples

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

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-cell-padding', rule );

// Lint the code:
result = linter.verify( code, {
    'rules': {
        'jsdoc-table-cell-padding': 'error'
    }
});
console.log( result );
/* =>
    [
        {
            'ruleId': 'jsdoc-table-cell-padding',
            'severity': 2,
            'message': 'Cell should be padded',
            'line': 6,
            'column': 4,
            'nodeType': null,
            'source': '* |2      | 4      |',
            'endLine': 15,
            'endColumn': 3
        }
    ]
*/