jsdoc-no-duplicate-tags

ESLint rule to enforce that a JSDoc tag is only used once in a JSDoc comment.

Usage

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

rule

ESLint rule to enforce that a JSDoc tag is only used once in a JSDoc comment. By default, the following tags may appear multiple times in a JSDoc comment:

  • @arg
  • @argument
  • @augments
  • @author
  • @borrows
  • @example
  • @extends
  • @param
  • @property
  • @see
  • @throws
  • @todo
  • @tutorial

To change the default list of tags allowed to appear multiple times, set the exceptions option of the rule.

Bad:

/**
* Squares a number.
*
* @param {number} x - input number
* @returns {number} x squared
* @returns {number} x squared
*
* @example
* var y = square( 2.0 );
* // returns 4.0
*
* @example
* var y = square( 4.0 );
* // returns 16.0
*/
function square( x ) {
    return x*x;
}

Good:

/**
* Squares a number.
*
* @param {number} x - input number
* @returns {number} x squared
    *
* @example
* var y = square( 2.0 );
* // returns 4.0
*
* @example
* var y = square( 4.0 );
* // returns 16.0
*/
function square( x ) {
    return x*x;
}

Examples

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

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

code = [
    '/**',
    '* Squares a number.',
    '* ',
    '* @params {number} x - input number',
    '* @returns {number} x squared',
    '* @returns {number} x squared',
    '*',
    '* @examples',
    '* var y = square( 2.0 );',
    '* // returns 4.0',
    '*/',
    'function square( x ) {',
    '  return x*x;',
    '}'
].join( '\n' );

linter.defineRule( 'jsdoc-no-duplicate-tags', rule );

result = linter.verify( code, {
    'rules': {
        'jsdoc-no-duplicate-tags': 'error'
    }
});
console.log( result );
/* =>
    [
        {
            'ruleId': 'jsdoc-no-duplicate-tags',
            'severity': 2,
            'message': '"@returns" should only be used once',
            'line': 1,
            'column': 1,
            'nodeType': null,
            'source': '/**',
            'endLine': 11,
            'endColumn': 3
        }
    ]
*/