Heading Indentation

ESLint rule to prevent indentation of Markdown headings in JSDoc descriptions.

Usage

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

rule

ESLint rule to prevent indentation of Markdown headings in JSDoc descriptions.

Bad:

/**
* Boop beep.
*
*    ## Boop
*
* Beep.
*
* @returns {string} a value
*
* @example
* var str = beep();
* // returns 'boop'
*/
function beep() {
    return 'boop';
}

Good:

/**
* Boop beep.
*
* ## Boop
*
* Beep.
*
* @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-heading-indent' );

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

// Generate our source code:
code = [
    '/**',
    '* Beep boop.',
    '*',
    '*    ## Beep',
    '*',
    '* boop',
    '*',
    '*  ## Boop',
    '*',
    '* beep',
    '*',
    '*',
    '* @param {string} str - input value',
    '* @returns {string} output value',
    '*',
    '* @example',
    '* var out = beep( "boop" );',
    '* // returns "beepboop"',
    '*/',
    'function beep( str ) {',
    '\treturn "beep" + str;',
    '}'
].join( '\n' );

// Register the ESLint rule:
linter.defineRule( 'jsdoc-no-heading-indent', rule );

// Lint the code:
result = linter.verify( code, {
    'rules': {
        'jsdoc-no-heading-indent': 'error'
    }
});
console.log( result );
/* =>
    [
        {
            'ruleId': 'jsdoc-no-heading-indent',
            'severity': 2,
            'message': 'Remove 3 spaces before this heading',
            'line': 4,
            'column': 6,
            'nodeType': null,
            'source': '*    ## Beep',
            'endLine': 18,
            'endColumn': 3
        },
        {
            'ruleId': 'jsdoc-no-heading-indent',
            'severity': 2,
            'message': 'Remove 1 space before this heading',
            'line': 8,
            'column': 4,
            'nodeType': null,
            'source': '*  ## Boop',
            'endLine': 18,
            'endColumn': 3
        }
    ]
*/