Code Block Style

ESLint rule to require that Markdown code blocks adhere to a specific style in JSDoc descriptions.

Usage

var rule = require( '@stdlib/_tools/eslint/rules/jsdoc-code-block-style' );

rule

ESLint rule to require that Markdown code blocks adhere to a specific style in JSDoc descriptions.

Bad:

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

Good:

/**
* Beep.
*
* ```javascript
* y = x;
* ```
*
* @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. By default, the rule requires that code blocks be demarcated using fences.

Examples

var Linter = require( 'eslint' ).Linter;
var rule = require( '@stdlib/_tools/eslint/rules/jsdoc-code-block-style' );

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

// Generate our source code:
code = [
    '/**',
    '* Beep boop.',
    '*',
    '*     var x = y;',
    '*',
    '*',
    '* @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-code-block-style', rule );

// Lint the code:
result = linter.verify( code, {
    'rules': {
        'jsdoc-code-block-style': [ 'error', 'fenced' ]
    }
});
console.log( result );
/* =>
    [
        {
            'ruleId': 'jsdoc-code-block-style',
            'severity': 2,
            'message': 'Code blocks should be fenced',
            'line': 4,
            'column': 3,
            'nodeType': null,
            'source': '*     var x = y;',
            'endLine': 13,
            'endColumn': 3
        }
    ]
*/