Duplicate Definitions

ESLint rule to prevent duplicate Markdown definitions in JSDoc descriptions.

Usage

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

rule

ESLint rule to prevent duplicate Markdown definitions in JSDoc descriptions.

Bad:

/**
* Boop [beep][beep].
*
* [beep]: https://beep.com
* [beep]: https://beep.com
*
* @returns {string} a value
*
* @example
* var str = beep();
* // returns 'boop'
*/
function beep() {
    return 'boop';
}

Good:

/**
* Boop [beep][beep].
*
* [beep]: https://beep.com
*
* @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-duplicate-definitions' );

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

// Generate our source code:
code = [
    '/**',
    '* [Beep][beep] [boop][beep].',
    '*',
    '* [beep]: https://beep.com',
    '* [beep]: https://boop.com',
    '*',
    '*',
    '* @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-duplicate-definitions', rule );

// Lint the code:
result = linter.verify( code, {
    'rules': {
        'jsdoc-no-duplicate-definitions': 'error'
    }
});
console.log( result );
/* =>
    [
        {
            'ruleId': 'jsdoc-no-duplicate-definitions',
            'severity': 2,
            'message': 'Do not use definitions with the same identifier (3:1)',
            'line': 5,
            'column': 3,
            'nodeType': null,
            'source': '* [beep]: https://boop.com',
            'endLine': 14,
            'endColumn': 3
        }
    ]
*/