Socket
Socket
Sign inDemoInstall

eslint-plugin-jsdoc

Package Overview
Dependencies
100
Maintainers
1
Versions
613
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    eslint-plugin-jsdoc

JSDoc linting rules for ESLint.


Version published
Weekly downloads
2M
decreased by-1.48%
Maintainers
1
Install size
3.65 MB
Created
Weekly downloads
 

Package description

What is eslint-plugin-jsdoc?

The eslint-plugin-jsdoc package is a plugin for ESLint that provides linting rules for JSDoc comments. JSDoc is a markup language used to annotate JavaScript source code files. Using eslint-plugin-jsdoc, developers can ensure that their JSDoc comments are consistent and follow best practices.

What are eslint-plugin-jsdoc's main functionalities?

Check alignment

Ensures that JSDoc blocks are aligned properly.

/* eslint jsdoc/check-alignment: "error" */
/**
 * Function description.
 *
 * @param {string} name - The name of the person.
 * @return {string} - The greeting message.
 */
function greet(name) {
  return `Hello, ${name}!`;
}

Check indentation

Ensures that JSDoc blocks have consistent indentation.

/* eslint jsdoc/check-indentation: "error" */
/**
 * Function description.
 *
 * @param {string} name - The name of the person.
 * @return {string} - The greeting message.
 */
function greet(name) {
  return `Hello, ${name}!`;
}

Check types

Validates JSDoc comments for type correctness.

/* eslint jsdoc/check-types: "error" */
/**
 * Function description.
 *
 * @param {String} name - The name of the person.
 * @return {String} - The greeting message.
 */
function greet(name) {
  return `Hello, ${name}!`;
}

Require JSDoc

Requires JSDoc comments for certain nodes in the code.

/* eslint jsdoc/require-jsdoc: "error" */
/**
 * Function description.
 */
function greet(name) {
  return `Hello, ${name}!`;
}

Other packages similar to eslint-plugin-jsdoc

Readme

Source

eslint-plugin-jsdoc

NPM version Travis build status js-canonical-style Discord Chat

JSDoc linting rules for ESLint.

Installation

Install ESLint either locally or globally.

npm install --save-dev eslint

If you have installed ESLint globally, you have to install JSDoc plugin globally too. Otherwise, install it locally.

npm install --save-dev eslint-plugin-jsdoc

Configuration

Flat config

import jsdoc from 'eslint-plugin-jsdoc';

const config = [
  // configuration included in plugin
  jsdoc.configs['flat/recommended'],
  // other configuration objects...
  {
    files: ['**/*.js'],
    plugins: {
      jsdoc,
    },
    rules: {
      'jsdoc/require-description': 'warn'
    }
  }
];

export default config;

eslintrc

Add plugins section to .eslintrc.* and specify eslint-plugin-jsdoc as a plugin.

{
    "plugins": [
        "jsdoc"
    ]
}

Finally, enable all of the rules that you would like to use.

{
    "rules": {
        "jsdoc/check-access": 1, // Recommended
        "jsdoc/check-alignment": 1, // Recommended
        "jsdoc/check-examples": 1,
        "jsdoc/check-indentation": 1,
        "jsdoc/check-line-alignment": 1,
        "jsdoc/check-param-names": 1, // Recommended
        "jsdoc/check-property-names": 1, // Recommended
        "jsdoc/check-syntax": 1,
        "jsdoc/check-tag-names": 1, // Recommended
        "jsdoc/check-types": 1, // Recommended
        "jsdoc/check-values": 1, // Recommended
        "jsdoc/empty-tags": 1, // Recommended
        "jsdoc/implements-on-classes": 1, // Recommended
        "jsdoc/informative-docs": 1,
        "jsdoc/match-description": 1,
        "jsdoc/multiline-blocks": 1, // Recommended
        "jsdoc/no-bad-blocks": 1,
        "jsdoc/no-blank-block-descriptions": 1,
        "jsdoc/no-defaults": 1,
        "jsdoc/no-missing-syntax": 1,
        "jsdoc/no-multi-asterisks": 1, // Recommended
        "jsdoc/no-restricted-syntax": 1,
        "jsdoc/no-types": 1,
        "jsdoc/no-undefined-types": 1, // Recommended
        "jsdoc/require-asterisk-prefix": 1,
        "jsdoc/require-description": 1,
        "jsdoc/require-description-complete-sentence": 1,
        "jsdoc/require-example": 1,
        "jsdoc/require-file-overview": 1,
        "jsdoc/require-hyphen-before-param-description": 1,
        "jsdoc/require-jsdoc": 1, // Recommended
        "jsdoc/require-param": 1, // Recommended
        "jsdoc/require-param-description": 1, // Recommended
        "jsdoc/require-param-name": 1, // Recommended
        "jsdoc/require-param-type": 1, // Recommended
        "jsdoc/require-property": 1, // Recommended
        "jsdoc/require-property-description": 1, // Recommended
        "jsdoc/require-property-name": 1, // Recommended
        "jsdoc/require-property-type": 1, // Recommended
        "jsdoc/require-returns": 1, // Recommended
        "jsdoc/require-returns-check": 1, // Recommended
        "jsdoc/require-returns-description": 1, // Recommended
        "jsdoc/require-returns-type": 1, // Recommended
        "jsdoc/require-throws": 1,
        "jsdoc/require-yields": 1, // Recommended
        "jsdoc/require-yields-check": 1, // Recommended
        "jsdoc/sort-tags": 1,
        "jsdoc/tag-lines": 1, // Recommended
        "jsdoc/valid-types": 1 // Recommended
    }
}

Or you can simply add the following to .eslintrc.*, which enables the rules commented above as "recommended":

{
  "extends": ["plugin:jsdoc/recommended"]
}

You can then selectively add to or override the recommended rules.

Alternatively, if you wish to have all linting issues reported as failing errors, you may use the "recommended-error" config:

{
  "extends": ["plugin:jsdoc/recommended-error"]
}

If you plan to use TypeScript syntax (and not just "typescript" mode to indicate the JSDoc flavor is TypeScript), you can use:

{
  "extends": ["plugin:jsdoc/recommended-typescript"]
}

...or to report with failing errors instead of mere warnings:

{
  "extends": ["plugin:jsdoc/recommended-typescript-error"]
}

If you are not using TypeScript syntax (your source files are still .js files) but you are using the TypeScript flavor within JSDoc (i.e., the default "typescript" mode in eslint-plugin-jsdoc) and you are perhaps using allowJs and checkJs options of TypeScript's tsconfig.json), you may use:

{
  "extends": ["plugin:jsdoc/recommended-typescript-flavor"]
}

...or to report with failing errors instead of mere warnings:

{
  "extends": ["plugin:jsdoc/recommended-typescript-flavor-error"]
}

Options

Rules may, as per the ESLint user guide, have their own individual options. In eslint-plugin-jsdoc, a few options, such as, exemptedBy and contexts, may be used across different rules.

eslint-plugin-jsdoc options, if present, are generally in the form of an object supplied as the second argument in an array after the error level (any exceptions to this format are explained within that rule's docs).

// `.eslintrc.js`
{
  rules: {
    'jsdoc/require-example': [
        // The Error level should be `error`, `warn`, or `off` (or 2, 1, or 0)
        'error',
        // The options vary by rule, but are generally added to an options
        //  object as follows:
        {
          checkConstructors: true,
          exemptedBy: ['type']
        }
    ]
  }
}

Settings

See Settings.

Advanced

See Advanced.

Rules

Problems reported by rules which have a wrench :wrench: below can be fixed automatically by running ESLint on the command line with --fix option.

Note that a number of fixable rules have an enableFixer option which can be set to false to disable the fixer (or in the case of check-param-names, check-property-names, and no-blank-blocks, set to true to enable a non-default-recommended fixer).

recommendedfixableruledescription
:heavy_check_mark:check-accessEnforces valid @access tags
:heavy_check_mark::wrench:check-alignmentEnforces alignment of JSDoc block asterisks
check-examplesLinting of JavaScript within @example
check-indentationChecks for invalid padding inside JSDoc blocks
:wrench:check-line-alignmentReports invalid alignment of JSDoc block lines.
:heavy_check_mark::wrench:check-param-namesChecks for dupe @param names, that nested param names have roots, and that parameter names in function declarations match jsdoc param names.
:heavy_check_mark::wrench:check-property-namesChecks for dupe @property names, that nested property names have roots
check-syntaxReports use against current mode (currently only prohibits Closure-specific syntax)
:heavy_check_mark::wrench:check-tag-namesReports invalid jsdoc (block) tag names
:heavy_check_mark::wrench:check-typesReports types deemed invalid (customizable and with defaults, for preventing and/or recommending replacements)
:heavy_check_mark:check-valuesChecks for expected content within some miscellaneous tags (@version, @since, @license, @author)
:heavy_check_mark::wrench:empty-tagsChecks tags that are expected to be empty (e.g., @abstract or @async), reporting if they have content
:heavy_check_mark:implements-on-classesProhibits use of @implements on non-constructor functions (to enforce the tag only being used on classes/constructors)
informative-docsReports on JSDoc texts that serve only to restate their attached name.
match-descriptionDefines customizable regular expression rules for your tag descriptions
:wrench:match-nameReports the name portion of a JSDoc tag if matching or not matching a given regular expression
:heavy_check_mark::wrench:multiline-blocksControls how and whether jsdoc blocks can be expressed as single or multiple line blocks
:wrench:no-bad-blocksThis rule checks for multi-line-style comments which fail to meet the criteria of a jsdoc block
:wrench:no-blank-block-descriptionsIf tags are present, this rule will prevent empty lines in the block description. If no tags are present, this rule will prevent extra empty lines in the block description.
:wrench:no-blank-blocksReports and optionally removes blocks with whitespace only
:heavy_check_mark::wrench:no-defaultsThis rule reports defaults being used on the relevant portion of @param or @default
no-missing-syntaxThis rule lets you report if certain always expected comment structures are missing.
:heavy_check_mark::wrench:no-multi-asterisksPrevents use of multiple asterisks at the beginning of lines
no-restricted-syntaxReports when certain comment structures are present
On in TS:wrench:no-typesProhibits types on @param or @returns (redundant with TypeScript)
:heavy_check_mark: (off in TS and TS flavor)no-undefined-typesBesides some expected built-in types, prohibits any types not specified as globals or within @typedef
:wrench:require-asterisk-prefixRequires that each JSDoc line starts with an *
require-descriptionRequires that all functions (and potentially other contexts) have a description.
:wrench:require-description-complete-sentenceRequires that block description, explicit @description, and @param/@returns tag descriptions are written in complete sentences
:wrench:require-exampleRequires that all functions (and potentially other contexts) have examples.
require-file-overviewBy default, requires a single @file tag at the beginning of each linted file
:wrench:require-hyphen-before-param-descriptionRequires a hyphen before @param descriptions (and optionally before @property descriptions)
:heavy_check_mark::wrench:require-jsdocChecks for presence of jsdoc comments, on functions and potentially other contexts (optionally limited to exports).
:heavy_check_mark::wrench:require-paramRequires that all function parameters are documented with a @param tag.
:heavy_check_mark:require-param-descriptionRequires that each @param tag has a description value.
:heavy_check_mark:require-param-nameRequires that all @param tags have names.
:heavy_check_mark: (off in TS)require-param-typeRequires that each @param tag has a type value (within curly brackets).
:heavy_check_mark::wrench:require-propertyRequires that all @typedef and @namespace tags have @property tags when their type is a plain object, Object, or PlainObject.
:heavy_check_mark:require-property-descriptionRequires that each @property tag has a description value.
:heavy_check_mark:require-property-nameRequires that all @property tags have names.
:heavy_check_mark: (off in TS)require-property-typeRequires that each @property tag has a type value (within curly brackets).
:heavy_check_mark:require-returnsRequires that return statements are documented.
:heavy_check_mark:require-returns-checkRequires a return statement be present in a function body if a @returns tag is specified in the jsdoc comment block (and reports if multiple @returns tags are present).
:heavy_check_mark:require-returns-descriptionRequires that the @returns tag has a description value (not including void/undefined type returns).
:heavy_check_mark: (off in TS)require-returns-typeRequires that @returns tag has a type value (in curly brackets).
require-throwsRequires that throw statements are documented
:heavy_check_mark:require-yieldsRequires that yields are documented
:heavy_check_mark:require-yields-checkEnsures that if a @yields is present that a yield (or yield with a value) is present in the function body (or that if a @next is present that there is a yield with a return value present)
sort-tagsSorts tags by a specified sequence according to tag name, optionally adding line breaks between tag groups
:heavy_check_mark::wrench:tag-linesEnforces lines (or no lines) between tags
:wrench:text-escapingThis rule can auto-escape certain characters that are input within block and tag descriptions
:heavy_check_mark:valid-typesRequires all types/namepaths to be valid JSDoc, Closure compiler, or TypeScript types (configurable in settings)

Keywords

FAQs

Last updated on 04 Apr 2024

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc