Fenced Code Marker

ESLint rule to enforce a specific Markdown fenced code marker in JSDoc descriptions.

Usage

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

rule

ESLint rule to enforce a specific Markdown fenced code marker in JSDoc descriptions.

Bad:

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

Good:

/**
* Beep boop.
*
* ```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 enforces that ` be used as the Markdown fenced code marker in JSDoc descriptions.

Examples

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

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

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

// Lint the code:
result = linter.verify( code, {
    'rules': {
        'jsdoc-fenced-code-marker': [ 'error', '`' ]
    }
});
console.log( result );
/* =>
    [
        {
            'ruleId': 'jsdoc-fenced-code-marker',
            'severity': 2,
            'message': 'Fenced code should use ` as a marker',
            'line': 4,
            'column': 3,
            'nodeType': null,
            'source': '* ~~~javascript',
            'endLine': 14,
            'endColumn': 3
        }
    ]
*/