jsdoc-tag-names

ESLint rule to enforce that only allowed JSDoc tags are used.

Usage

var rule = require( '@stdlib/_tools/eslint/rules/jsdoc-tag-names' );

rule

ESLint rule to enforce that only allowed JSDoc tags are used. By default, the following tags are whitelisted:

  • @constant
  • @constructor
  • @default
  • @example
  • @function
  • @memberof
  • @module
  • @name
  • @namespace
  • @param
  • @private
  • @readonly
  • @returns
  • @see
  • @throws
  • @type

To change the default list of allowed tags, set the tags option of the rule.

Bad:

/**
* Squares a number.
*
* @arg {number} x - input number
* @return {number} x squared
*
* @examples
* var y = square( 2.0 );
* // returns 4.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
*/
function square( x ) {
    return x*x;
}

Examples

var Linter = require( 'eslint' ).Linter;
var rule = require( '@stdlib/_tools/eslint/rules/jsdoc-tag-names' );

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

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

linter.defineRule( 'jsdoc-tag-names', rule );

result = linter.verify( code, {
    'rules': {
        'jsdoc-tag-names': 'error'
    }
});
console.log( result );
/* =>
    [
        {
            'ruleId': 'jsdoc-tag-names',
            'severity': 2,
            'message': '"params" is not one of the allowed tags (...)',
            'line': 1,
            'column': 1,
            'nodeType': null,
            'source': '/**',
            'endLine': 10,
            'endColumn': 3
        },
        {
            'ruleId': 'jsdoc-tag-names',
            'severity': 2,
            'message': '"examples" is not one of the allowed tags (...)',
            'line': 1,
            'column': 1,
            'nodeType': null,
            'source': '/**',
            'endLine': 10,
            'endColumn': 3
        }
    ]
*/