JSDoc linting rules for ESLint.
-
eslint-plugin-jsdoc
- Installation
- Configuration
- Options
-
Settings
- Allow tags (
@private
or@internal
) to disable rules for that comment block maxLines
andminLines
- Mode
- Alias Preference
@override
/@augments
/@extends
/@implements
/@ignore
Without Accompanying@param
/@description
/@example
/@returns
/@throws
/@yields
- Settings to Configure
check-types
andno-undefined-types
structuredTags
- Allow tags (
- Advanced
-
Rules
check-access
check-alignment
check-examples
check-indentation
check-line-alignment
check-param-names
check-property-names
check-syntax
check-tag-names
check-types
check-values
empty-tags
implements-on-classes
match-description
match-name
multiline-blocks
newline-after-description
no-bad-blocks
no-defaults
no-missing-syntax
no-multi-asterisks
no-restricted-syntax
no-types
no-undefined-types
require-asterisk-prefix
require-description-complete-sentence
require-description
require-example
require-file-overview
require-hyphen-before-param-description
require-jsdoc
require-param-description
require-param-name
require-param-type
require-param
require-property
require-property-description
require-property-name
require-property-type
require-returns-check
require-returns-description
require-returns-type
require-returns
require-throws
require-yields
require-yields-check
tag-lines
valid-types
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
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/match-description": 1,
"jsdoc/multiline-blocks": 1, // Recommended
"jsdoc/newline-after-description": 1, // Recommended
"jsdoc/no-bad-blocks": 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/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.
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:
{
avoidExampleOnConstructors: true,
exemptedBy: ['type']
}
]
}
}
-
settings.jsdoc.ignorePrivate
- Disables all rules for the comment block on which a@private
tag (or@access private
) occurs. Defaults tofalse
. Note: This has no effect with the rulecheck-access
(whose purpose is to check access modifiers) orempty-tags
(which checks@private
itself). -
settings.jsdoc.ignoreInternal
- Disables all rules for the comment block on which a@internal
tag occurs. Defaults tofalse
. Note: This has no effect with the ruleempty-tags
(which checks@internal
itself).
One can use minLines
and maxLines
to indicate how many line breaks
(if any) will be checked to find a jsdoc comment block before the given
code block. These settings default to 0
and 1
respectively.
In conjunction with the require-jsdoc
rule, these settings can
be enforced so as to report problems if a jsdoc block is not found within
the specified boundaries. The settings are also used in the fixer to determine
how many line breaks to add when a block is missing.
-
settings.jsdoc.mode
- Set totypescript
,closure
, orjsdoc
(the default unless the@typescript-eslint
parser is in use in which casetypescript
will be the default). Note that if you do not wish to use separate.eslintrc.*
files for a project containing both JavaScript and TypeScript, you can also useoverrides
. You may also set to"permissive"
to try to be as accommodating to any of the styles, but this is not recommended. Currently is used for the following:-
check-tag-names
: Determine valid tags and aliases -
no-undefined-types
: Only check@template
for types in "closure" and "typescript" modes -
check-syntax
: determines aspects that may be enforced -
valid-types
: in non-Closure mode,@extends
,@package
and access tags (e.g.,@private
) with a bracketed type are reported as are missing names with@typedef
- For type/namepath-checking rules, determine which tags will be checked for types/namepaths (Closure allows types on some tags which the others do not, so these tags will additionally be checked in "closure" mode)
- For type-checking rules, impacts parsing of types (through jsdoc-type-pratt-parser dependency)
- Check preferred tag names
- Disallows namepath on
@interface
for "closure" mode invalid-types
(and avoids checking in other rules)
-
Use settings.jsdoc.tagNamePreference
to configure a preferred alias name for
a JSDoc tag. The format of the configuration is:
<primary tag name>: <preferred alias name>
, e.g.
{
"rules": {},
"settings": {
"jsdoc": {
"tagNamePreference": {
"param": "arg",
"returns": "return"
}
}
}
}
Note: ESLint does not allow settings to have keys which conflict with
Object.prototype
e.g. 'constructor'
. To work around this, you can use the
key 'tag constructor'
.
One may also use an object with a message
and replacement
.
The following will report the message
@extends is to be used over @augments as it is more evocative of classes than @augments
upon encountering @augments
.
{
"rules": {},
"settings": {
"jsdoc": {
"tagNamePreference": {
"augments": {
"message": "@extends is to be used over @augments as it is more evocative of classes than @augments",
"replacement": "extends"
}
}
}
}
}
If one wishes to reject a normally valid tag, e.g., @todo
, one may set the
tag to false
:
{
"rules": {},
"settings": {
"jsdoc": {
"tagNamePreference": {
"todo": false
}
}
}
}
A project wishing to ensure no blocks are left excluded from entering the
documentation, might wish to prevent the @ignore
tag in the above manner.
Or one may set the targeted tag to an object with a custom message
, but
without a replacement
property:
{
"rules": {},
"settings": {
"jsdoc": {
"tagNamePreference": {
"todo": {
"message": "We expect immediate perfection, so don't leave to-dos in your code."
}
}
}
}
}
Note that the preferred tags indicated in the
settings.jsdoc.tagNamePreference
map will be assumed to be defined by
check-tag-names
.
See check-tag-names
for how that fact can be used to set an alias to itself
to allow both the alias and the default (since aliases are otherwise not
permitted unless used in tagNamePreference
).
The defaults in eslint-plugin-jsdoc
(for tags which offer
aliases) are as follows:
-
@abstract
(over@virtual
) -
@augments
(over@extends
) -
@class
(over@constructor
) -
@constant
(over@const
) -
@default
(over@defaultvalue
) -
@description
(over@desc
) -
@external
(over@host
) -
@file
(over@fileoverview
,@overview
) -
@fires
(over@emits
) -
@function
(over@func
,@method
) -
@member
(over@var
) -
@param
(over@arg
,@argument
) -
@property
(over@prop
) -
@returns
(over@return
) -
@throws
(over@exception
) -
@yields
(over@yield
)
This setting is utilized by the the rule for tag name checking
(check-tag-names
) as well as in the @param
and @require
rules:
check-param-names
check-tag-names
require-hyphen-before-param-description
require-description
require-param
require-param-description
require-param-name
require-param-type
require-returns
require-returns-check
require-returns-description
require-returns-type
@override
/@augments
/@extends
/@implements
/@ignore
Without Accompanying @param
/@description
/@example
/@returns
/@throws
/@yields
The following settings allows the element(s) they reference to be omitted
on the JSDoc comment block of the function or that of its parent class
for any of the "require" rules (i.e., require-param
, require-description
,
require-example
, require-returns
, require-throws
, require-yields
).
-
settings.jsdoc.ignoreReplacesDocs
(@ignore
) - Defaults totrue
-
settings.jsdoc.overrideReplacesDocs
(@override
) - Defaults totrue
-
settings.jsdoc.augmentsExtendsReplacesDocs
(@augments
or its alias@extends
) - Defaults tofalse
. -
settings.jsdoc.implementsReplacesDocs
(@implements
) - Defaults tofalse
The format of the configuration is as follows:
{
"rules": {},
"settings": {
"jsdoc": {
"ignoreReplacesDocs": true,
"overrideReplacesDocs": true,
"augmentsExtendsReplacesDocs": true,
"implementsReplacesDocs": true
}
}
}
-
settings.jsdoc.preferredTypes
An option map to indicate preferred or forbidden types (if default types are indicated here, these will have precedence over the default recommendations forcheck-types
). The keys of this map are the types to be replaced (or forbidden). These keys may include:- The "ANY" type,
*
- The pseudo-type
[]
which we use to denote the parent (array) types used in the syntaxstring[]
,number[]
, etc. - The pseudo-type
.<>
(or.
) to represent the formatArray.<value>
orObject.<key, value>
- The pseudo-type
<>
to represent the formatArray<value>
orObject<key, value>
- A plain string type, e.g.,
MyType
- A plain string type followed by one of the above pseudo-types (except
for
[]
which is always assumed to be anArray
), e.g.,Array.
, orSpecialObject<>
.
If a bare pseudo-type is used, it will match all parent types of that form. If a pseudo-type prefixed with a type name is used, it will only match parent types of that form and type name.
The values can be:
-
false
to forbid the type - a string to indicate the type that should be preferred in its place
(and which
fix
mode can replace); this can be one of the formats of the keys described above.- Note that the format will not be changed unless you use a pseudo-type
in the replacement. (For example,
'Array.<>': 'MyArray'
will changeArray.<string>
toMyArray.<string>
, preserving the dot. To get rid of the dot, you must use the pseudo-type with<>
, i.e.,'Array.<>': 'MyArray<>'
, which will changeArray.<string>
toMyArray<string>
). - If you use a bare pseudo-type in the replacement (e.g.,
'MyArray.<>': '<>'
), the type will be converted to the format of the pseudo-type without changing the type name. For example,MyArray.<string>
will becomeMyArray<string>
butArray.<string>
will not be modified.
- Note that the format will not be changed unless you use a pseudo-type
in the replacement. (For example,
- an object with:
- the key
message
to provide a specific error message when encountering the discouraged type.- The message string will have the substrings with special meaning,
{{tagName}}
and{{tagValue}}
, replaced with their corresponding value.
- The message string will have the substrings with special meaning,
- an optional key
replacement
with either of the following values:- a string type to be preferred in its place (and which
fix
mode can replace) -
false
(for forbidding the type)
- a string type to be preferred in its place (and which
- the key
- The "ANY" type,
Note that the preferred types indicated as targets in
settings.jsdoc.preferredTypes
map will be assumed to be defined by
no-undefined-types
.
See the option of check-types
, unifyParentAndChildTypeChecks
, for
how the keys of preferredTypes
may have <>
or .<>
(or just .
)
appended and its bearing on whether types are checked as parents/children
only (e.g., to match Array
if the type is Array
vs. Array.<string>
).
Note that if a value is present both as a key and as a value, neither the
key nor the value will be reported. Thus in check-types
, this fact can
be used to allow both object
and Object
if one has a preferredTypes
key object: 'Object'
and Object: 'object'
.
An object indicating tags whose types and names/namepaths (whether defining or
referencing namepaths) will be checked, subject to configuration. If the tags
have predefined behavior or allowEmptyNamepaths
behavior, this option will
override that behavior for any specified tags, though this option can also be
used for tags without predefined behavior. Its keys are tag names and its
values are objects with the following optional properties:
-
name
- String set to one of the following:-
"text"
- When a name is present, plain text will be allowed in the name position (non-whitespace immediately after the tag and whitespace), e.g., in@throws This is an error
, "This" would normally be the name, but "text" allows non-name text here also. This is the default. -
"namepath-defining"
- As withnamepath-referencing
, but also indicates the tag adds a namepath to definitions, e.g., to preventno-undefined-types
from reporting references to that namepath. -
"namepath-referencing"
- This will cause any name position to be checked to ensure it is a valid namepath. You might use this to ensure that tags which normally allow free text, e.g.,@see
will instead require a namepath. -
false
- This will disallow any text in the name position.
-
-
type
:-
true
- Allows valid types within brackets. This is the default. -
false
- Explicitly disallows any brackets or bracketed type. You might use this with@throws
to suggest that only free form text is being input or with@augments
(for jsdoc mode) to disallow Closure-style bracketed usage along with a required namepath. - (An array of strings) - A list of permissible types.
-
-
required
- Array of one of the following (defaults to an empty array, meaning none are required):- One or both of the following strings (if both are included, then both
are required):
-
"name"
- Indicates that a name position is required (not just that if present, it is a valid namepath). You might use this withsee
to insist that a value (or namepath, depending on thename
value) is always present. -
"type"
- Indicates that the type position (within curly brackets) is required (not just that if present, it is a valid type). You might use this with@throws
or@typedef
which might otherwise normally have their types optional. See the type groups 3-5 above.
-
-
"typeOrName"
- Must have either type (e.g.,@throws {aType}
) or name (@throws Some text
); does not require that both exist but disallows just an empty tag.
- One or both of the following strings (if both are included, then both
are required):
For various rules, one can add to the environments to which the rule applies
by using the contexts
option.
This option works with ESLint's selectors which are esquery expressions one may use to target a specific node type or types, including subsets of the type(s) such as nodes with certain children or attributes.
These expressions are used within ESLint plugins to find those parts of
your files' code which are of interest to check. However, in
eslint-plugin-jsdoc
, we also allow you to use these selectors to define
additional contexts where you wish our own rules to be applied.
While at their simplest, these can be an array of string selectors, one can
also supply an object with context
(in place of the string) and one of two
properties:
- For
require-jsdoc
, there is also ainlineCommentBlock
property. See that rule for details. - For
no-missing-syntax
andno-restricted-syntax
, there is also amessage
property which allows customization of the message to be shown when the rule is triggered. - For
no-missing-syntax
, there is also aminimum
property. See that rule. - For other rules, there is a
comment
property which adds to thecontext
in requiring that thecomment
AST condition is also met, e.g., to require that certain tags are present and/or or types and type operators are in use. Note that this AST (either forJsdoc*
orJsdocType*
AST) has not been standardized and should be considered experimental. Note that this property might also become obsolete if parsers begin to include JSDoc-structured AST. A parser is available which aims to support comment AST as a first class citizen where comment/comment types can be used anywhere within a normal AST selector but this should only be considered experimental. When using such a parser, you need not usecomment
and can just use a plain string context. The determination of the node on which the comment is attached is also subject to change. It may be currently possible for different structures to map to the same comment block. This is because normally when querying to find either the declaration of the function expression forconst quux = function () {}
, the associated comment would, in both cases, generally be expected to be on the line above both, rather than to be immediately preceding the function (in the case of the function). See @es-joy/jsdoccomment for the precise structure of the comment (and comment type) nodes.
To know all of the AST definitions one may target, it will depend on the
parser
you are using with ESLint (e.g., espree
is the default parser for ESLint,
and this follows EStree AST but
to support the the latest experimental features of JavaScript, one may use
@babel/eslint-parser
or to be able to have one's rules (including JSDoc rules)
apply to TypeScript, one may use @typescript-eslint/parser
, etc.
So you can look up a particular parser to see its rules, e.g., browse through the ESTree docs as used by Espree or see ESLint's overview of the structure of AST.
However, it can sometimes be even more helpful to get an idea of AST by just providing some of your JavaScript to the wonderful AST Explorer tool and see what AST is built out of your code. You can set the tool to the specific parser which you are using.
And if you wish to introspect on the AST of code within your projects, you can use eslint-plugin-query. Though it also works as a plugin, you can use it with its own CLI, e.g., to search your files for matching esquery selectors, optionally showing it as AST JSON.
Tip: If you want to more deeply understand not just the resulting AST tree
structures for any given code but also the syntax for esquery selectors so
that you can, for example, find only those nodes with a child of a certain
type, you can set the "Transform" feature to ESLint and test out
esquery selectors in place of the selector expression (e.g., replace
'VariableDeclaration > VariableDeclarator > Identifier[name="someVar"]'
as
we have
here)
to the selector you wish so as to get messages reported in the bottom right
pane which match your esquery
selector).
Checks that @access
tags use one of the following values:
- "package", "private", "protected", "public"
Also reports:
- Mixing of
@access
with@public
,@private
,@protected
, or@package
on the same doc block. - Use of multiple instances of
@access
(or the@public
, etc. style tags) on the same doc block.
Context | everywhere |
Tags | @access |
Recommended | false |
Settings | |
Options |
The following patterns are considered problems:
/**
* @access foo
*/
function quux (foo) {
}
// Message: Missing valid JSDoc @access level.
/**
* @access foo
*/
function quux (foo) {
}
// Settings: {"jsdoc":{"ignorePrivate":true}}
// Message: Missing valid JSDoc @access level.
/**
* @accessLevel foo
*/
function quux (foo) {
}
// Settings: {"jsdoc":{"tagNamePreference":{"access":"accessLevel"}}}
// Message: Missing valid JSDoc @accessLevel level.
/**
* @access
*/
function quux (foo) {
}
// Settings: {"jsdoc":{"tagNamePreference":{"access":false}}}
// Message: Unexpected tag `@access`
class MyClass {
/**
* @access
*/
myClassField = 1
}
// Message: Missing valid JSDoc @access level.
/**
* @access public
* @public
*/
function quux (foo) {
}
// Message: The @access tag may not be used with specific access-control tags (@package, @private, @protected, or @public).
/**
* @access public
* @access private
*/
function quux (foo) {
}
// Message: At most one access-control tag may be present on a jsdoc block.
/**
* @access public
* @access private
*/
function quux (foo) {
}
// Settings: {"jsdoc":{"ignorePrivate":true}}
// Message: At most one access-control tag may be present on a jsdoc block.
/**
* @public
* @private
*/
function quux (foo) {
}
// Message: At most one access-control tag may be present on a jsdoc block.
/**
* @public
* @private
*/
function quux (foo) {
}
// Settings: {"jsdoc":{"ignorePrivate":true}}
// Message: At most one access-control tag may be present on a jsdoc block.
/**
* @public
* @public
*/
function quux (foo) {
}
// Message: At most one access-control tag may be present on a jsdoc block.
The following patterns are not considered problems:
/**
*
*/
function quux (foo) {
}
/**
* @access public
*/
function quux (foo) {
}
/**
* @accessLevel package
*/
function quux (foo) {
}
// Settings: {"jsdoc":{"tagNamePreference":{"access":"accessLevel"}}}
class MyClass {
/**
* @access private
*/
myClassField = 1
}
/**
* @public
*/
function quux (foo) {
}
/**
* @private
*/
function quux (foo) {
}
// Settings: {"jsdoc":{"ignorePrivate":true}}
Reports invalid alignment of JSDoc block asterisks.
Context | everywhere |
Tags | N/A |
Recommended | true |
The following patterns are considered problems:
/**
* @param {Number} foo
*/
function quux (foo) {
// with spaces
}
// Message: Expected JSDoc block to be aligned.
/**
* @param {Number} foo
*/
function quux (foo) {
// with tabs
}
// Message: Expected JSDoc block to be aligned.
/**
* @param {Number} foo
*/
function quux (foo) {
// with spaces
}
// Message: Expected JSDoc block to be aligned.
/**
* @param {Number} foo
*/
function quux (foo) {
// with spaces
}
// Message: Expected JSDoc block to be aligned.
/**
* @param {Number} foo
*/
function quux (foo) {
}
// Message: Expected JSDoc block to be aligned.
/**
* @param {Number} foo
*/
function quux (foo) {
}
// Message: Expected JSDoc block to be aligned.
/**
* @param {Number} foo
*/
function quux (foo) {
}
// Message: Expected JSDoc block to be aligned.
/**
* @param {Number} foo
*/
function quux (foo) {
}
// Message: Expected JSDoc block to be aligned.
/**
* A jsdoc not attached to any node.
*/
// Message: Expected JSDoc block to be aligned.
class Foo {
/**
* Some method
* @param a
*/
quux(a) {}
}
// Message: Expected JSDoc block to be aligned.
The following patterns are not considered problems:
/**
* Desc
*
* @param {Number} foo
*/
function quux (foo) {
}
/**
* Desc
*
* @param {{
foo: Bar,
bar: Baz
* }} foo
*
*/
function quux (foo) {
}
/* <- JSDoc must start with 2 stars.
* So this is unchecked.
*/
function quux (foo) {}
/**
* @param {Number} foo
* @private
*/
function quux (foo) {
// with spaces
}
// Settings: {"jsdoc":{"ignorePrivate":true}}
/**
* @param {Number} foo
* @access private
*/
function quux (foo) {
// with spaces
}
// Settings: {"jsdoc":{"ignorePrivate":true}}
NOTE: This rule currently does not work in ESLint 8 (we are waiting for issue 14745).
Ensures that (JavaScript) examples within JSDoc adhere to ESLint rules. Also
has options to lint the default values of optional @param
/@arg
/@argument
and @property
/@prop
tags or the values of @default
/@defaultvalue
tags.
The options below all default to no-op/false
except as noted.
JSDoc specs use of an optional <caption>
element at the beginning of
@example
.
The option captionRequired
insists on a <caption>
being present at
the beginning of any @example
.
Used only for @example
.
JSDoc does not specify a formal means for delimiting code blocks within
@example
(it uses generic syntax highlighting techniques for its own
syntax highlighting). The following options determine whether a given
@example
tag will have the check-examples
checks applied to it:
-
exampleCodeRegex
- Regex which whitelists lintable examples. If a parenthetical group is used, the first one will be used, so you may wish to use(?:...)
groups where you do not wish the first such group treated as one to include. If no parenthetical group exists or matches, the whole matching expression will be used. An example might be"^```(?:js|javascript)([\\s\\S]*)```\s*$"
to only match explicitly fenced JavaScript blocks. Defaults to only using theu
flag, so to add your own flags, encapsulate your expression as a string, but like a literal, e.g.,/```js.*```/gi
. Note that specifying a global regular expression (i.e., withg
) will allow independent linting of matched blocks within a single@example
. -
rejectExampleCodeRegex
- Regex blacklist which rejects non-lintable examples (has priority overexampleCodeRegex
). An example might be"^`"
to avoid linting fenced blocks which may indicate a non-JavaScript language. SeeexampleCodeRegex
on how to add flags if the defaultu
is not sufficient.
If neither is in use, all examples will be matched. Note also that even if
captionRequired
is not set, any initial <caption>
will be stripped out
before doing the regex matching.
This integer property allows one to add a fixed amount of whitespace at the
beginning of the second or later lines of the example to be stripped so as
to avoid linting issues with the decorative whitespace. For example, if set
to a value of 4
, the initial whitespace below will not trigger indent
rule errors as the extra 4 spaces on each subsequent line will be stripped
out before evaluation.
/**
* @example
* anArray.filter((a) => {
* return a.b;
* });
*/
Only applied to @example
linting.
If not set to false
, reportUnusedDisableDirectives
will report disabled
directives which are not used (and thus not needed). Defaults to true
.
Corresponds to ESLint's --report-unused-disable-directives
.
Inline ESLint config within @example
JavaScript is allowed (or within
@default
, etc.), though the disabling of ESLint directives which are not
needed by the resolved rules will be reported as with the ESLint
--report-unused-disable-directives
command.
Options for Determining ESLint Rule Applicability (allowInlineConfig
, noDefaultExampleRules
, matchingFileName
, configFile
, checkEslintrc
, and baseConfig
)
The following options determine which individual ESLint rules will be
applied to the JavaScript found within the @example
tags (as determined
to be applicable by the above regex options) or for the other tags checked by
checkDefaults
, checkParams
, or checkProperties
options. They are ordered
by decreasing precedence:
-
allowInlineConfig
- If not set tofalse
, will allow inline config within the@example
to override other config. Defaults totrue
. -
noDefaultExampleRules
- Setting totrue
will disable the default rules which are expected to be troublesome for most documentation use. See the section below for the specific default rules. -
configFile
- A config file. Corresponds to ESLint's-c
. -
matchingFileName
- Option for a file name (even non-existent) to trigger specific rules defined in one's config; usable with ESLint.eslintrc.*
overrides
->files
globs, to apply a desired subset of rules with@example
(besides allowing for rules specific to examples, this option can be useful for enabling reuse of the same rules within@example
as with JavaScript Markdown lintable by other plugins, e.g., if one setsmatchingFileName
todummy.md/*.js
so that@example
rules will follow rules for fenced JavaScript blocks within one's Markdown rules). (In ESLint 6's processor API andeslint-plugin-markdown
< 2, one would instead usedummy.md
.) For@example
only. -
matchingFileNameDefaults
- As withmatchingFileName
but for use withcheckDefaults
and defaulting to.jsdoc-defaults
as extension. -
matchingFileNameParams
- As withmatchingFileName
but for use withcheckParams
and defaulting to.jsdoc-params
as extension. -
matchingFileNameProperties
As withmatchingFileName
but for use withcheckProperties
and defaulting to.jsdoc-properties
as extension. -
checkEslintrc
- Defaults totrue
in adding rules based on an.eslintrc.*
file. Setting tofalse
corresponds to ESLint's--no-eslintrc
. IfmatchingFileName
is set, this will automatically betrue
and will use the config corresponding to that file. IfmatchingFileName
is not set and this value is set tofalse
, the.eslintrc.*
configs will not be checked. IfmatchingFileName
is not set, and this is unset or set totrue
, the.eslintrc.*
configs will be checked as though the file name were the same as the file containing the example, with any file extension changed to".md/*.js"
(and if there is no file extension,"dummy.md/*.js"
will be the result). This allows convenient sharing of similar rules with often also context-free Markdown as well as use ofoverrides
as described undermatchingFileName
. Note that this option (whether set bymatchingFileName
or set manually totrue
) may come at somewhat of a performance penalty as the file's existence is checked by eslint. -
baseConfig
- Set to an object of rules with the same schema as.eslintrc.*
for defaults.
-
eol-last
- Insisting that a newline "always" be at the end is less likely to be desired in sample code as with the code file convention. -
no-console
- This rule is unlikely to have inadvertent temporary debugging within examples. -
no-multiple-empty-lines
- This rule may be problematic for projects which use an initial newline just to start an example. Also, projects may wish to use extra lines within examples just for easier illustration purposes. -
no-undef
- Many variables in examples will beundefined
. -
no-unused-vars
- It is common to define variables for clarity without always using them within examples. -
padded-blocks
- It can generally look nicer to pad a little even if one's code follows more stringency as far as block padding. -
jsdoc/require-file-overview
- Shouldn't check example for jsdoc blocks. -
jsdoc/require-jsdoc
- Wouldn't expect jsdoc blocks within jsdoc blocks. -
import/no-unresolved
- One wouldn't generally expect example paths to resolve relative to the current JavaScript file as one would with real code. -
import/unambiguous
- Snippets in examples are likely too short to always include full import/export info. -
node/no-missing-import
- Seeimport/no-unresolved
. -
node/no-missing-require
- Seeimport/no-unresolved
.
For checkDefaults
, checkParams
, and checkProperties
, the following
expression-oriented rules will be used by default as well:
-
quotes
- Will insist on "double". -
semi
- Will insist on "never". -
strict
- Disabled. -
no-empty-function
- Disabled. -
no-new
- Disabled. -
no-unused-expressions
- Disabled. -
chai-friendly/no-unused-expressions
- Disabled.
-
checkDefaults
- Whether to check the values of@default
/@defaultvalue
tags -
checkParams
- Whether to check@param
/@arg
/@argument
default values -
checkProperties
- Whether to check@property
/@prop
default values
Context | everywhere |
Tags | example |
Recommended | false |
Options | See above |
The following patterns are considered problems:
/**
* @example alert('hello')
*/
function quux () {
}
// "jsdoc/check-examples": ["error"|"warn", {"baseConfig":{"rules":{"no-alert":2,"semi":["error","always"]}},"checkEslintrc":false}]
// Message: @example error (no-alert): Unexpected alert.
/**
* @example alert('hello')
*/
class quux {
}
// "jsdoc/check-examples": ["error"|"warn", {"baseConfig":{"rules":{"no-alert":2,"semi":["error","always"]}},"checkEslintrc":false}]
// Message: @example error (no-alert): Unexpected alert.
/**
* @example ```js
alert('hello');
```
*/
function quux () {
}
// "jsdoc/check-examples": ["error"|"warn", {"baseConfig":{"rules":{"semi":["error","never"]}},"checkEslintrc":false,"exampleCodeRegex":"```js([\\s\\S]*)```"}]
// Message: @example error (semi): Extra semicolon.
/**
* @example
*
* ```js alert('hello'); ```
*/
function quux () {
}
// "jsdoc/check-examples": ["error"|"warn", {"baseConfig":{"rules":{"semi":["error","never"]}},"checkEslintrc":false,"exampleCodeRegex":"```js ([\\s\\S]*)```"}]
// Message: @example error (semi): Extra semicolon.
/**
* @example
* ```js alert('hello'); ```
*/
var quux = {
};
// "jsdoc/check-examples": ["error"|"warn", {"baseConfig":{"rules":{"semi":["error","never"]}},"checkEslintrc":false,"exampleCodeRegex":"```js ([\\s\\S]*)```"}]
// Message: @example error (semi): Extra semicolon.
/**
* @example ```
* js alert('hello'); ```
*/
function quux () {
}
// "jsdoc/check-examples": ["error"|"warn", {"baseConfig":{"rules":{"semi":["error","never"]}},"checkEslintrc":false,"exampleCodeRegex":"```\njs ([\\s\\S]*)```"}]
// Message: @example error (semi): Extra semicolon.
/**
* @example <b>Not JavaScript</b>
*/
function quux () {
}
/**
* @example quux2();
*/
function quux2 () {
}
// "jsdoc/check-examples": ["error"|"warn", {"baseConfig":{"rules":{"semi":["error","never"]}},"checkEslintrc":false,"rejectExampleCodeRegex":"^\\s*<.*>\\s*$"}]
// Message: @example error (semi): Extra semicolon.
/**
* @example
* quux(); // does something useful
*/
function quux () {
}
// "jsdoc/check-examples": ["error"|"warn", {"baseConfig":{"rules":{"no-undef":["error"]}},"checkEslintrc":false,"noDefaultExampleRules":true}]
// Message: @example error (no-undef): 'quux' is not defined.
/**
* @example <caption>Valid usage</caption>
* quux(); // does something useful
*
* @example
* quux('random unwanted arg'); // results in an error
*/
function quux () {
}
// "jsdoc/check-examples": ["error"|"warn", {"captionRequired":true,"checkEslintrc":false}]
// Message: Caption is expected for examples.
/**
* @example quux();
*/
function quux () {
}
// "jsdoc/check-examples": ["error"|"warn", {"baseConfig":{"rules":{"indent":["error"]}},"checkEslintrc":false,"noDefaultExampleRules":false}]
// Message: @example error (indent): Expected indentation of 0 spaces but found 1.
/**
* @example test() // eslint-disable-line semi
*/
function quux () {}
// "jsdoc/check-examples": ["error"|"warn", {"checkEslintrc":false,"noDefaultExampleRules":true,"reportUnusedDisableDirectives":true}]
// Message: @example error: Unused eslint-disable directive (no problems were reported from 'semi').
/**
* @example
test() // eslint-disable-line semi
*/
function quux () {}
// "jsdoc/check-examples": ["error"|"warn", {"allowInlineConfig":false,"baseConfig":{"rules":{"semi":["error","always"]}},"checkEslintrc":false,"noDefaultExampleRules":true}]
// Message: @example error (semi): Missing semicolon.
/**
* @example const i = 5;
* quux2()
*/
function quux2 () {
}
// "jsdoc/check-examples": ["error"|"warn", {"matchingFileName":"../../jsdocUtils.js"}]
// Message: @example warning (id-length): Identifier name 'i' is too short (< 2).
/**
* @example const i = 5;
* quux2()
*/
function quux2 () {
}
// "jsdoc/check-examples": ["error"|"warn", {"configFile":".eslintrc.json","matchingFileName":"../../jsdocUtils.js"}]
// Message: @example warning (id-length): Identifier name 'i' is too short (< 2).
/**
* @example const i = 5;
* quux2()
*/
function quux2 () {
}
// Message: @example warning (id-length): Identifier name 'i' is too short (< 2).
/**
* @example const i = 5;
* quux2()
*/
function quux2 () {
}
// "jsdoc/check-examples": ["error"|"warn", {"paddedIndent":2}]
// Message: @example warning (id-length): Identifier name 'i' is too short (< 2).
/**
* @example
* const i = 5;
* quux2()
*/
function quux2 () {
}
// Message: @example warning (id-length): Identifier name 'i' is too short (< 2).
/**
* @example const idx = 5;
* quux2()
*/
function quux2 () {
}
// "jsdoc/check-examples": ["error"|"warn", {"matchingFileName":"dummy.js"}]
// Message: @example error (semi): Missing semicolon.
/**
* @example const idx = 5;
*
* quux2()
*/
function quux2 () {
}
// "jsdoc/check-examples": ["error"|"warn", {"matchingFileName":"dummy.js"}]
// Message: @example error (semi): Missing semicolon.
/**
* @example const idx = 5;
*
* quux2()
*/
function quux2 () {
}
// "jsdoc/check-examples": ["error"|"warn", {"checkEslintrc":false,"matchingFileName":"dummy.js"}]
// Message: @example error: Parsing error: The keyword 'const' is reserved
/**
* @example // begin
alert('hello')
// end
*/
function quux () {
}
// "jsdoc/check-examples": ["error"|"warn", {"baseConfig":{"rules":{"semi":["warn","always"]}},"checkEslintrc":false,"exampleCodeRegex":"// begin[\\s\\S]*// end","noDefaultExampleRules":true}]
// Message: @example warning (semi): Missing semicolon.
/**
* @typedef {string} Foo
* @example <caption></caption>
* 'foo'
*/
// "jsdoc/check-examples": ["error"|"warn", {"captionRequired":true,"checkEslintrc":false}]
// Message: Caption is expected for examples.
/**
* @example
* const list: number[] = [1, 2, 3]
* quux(list);
*/
function quux () {
}
// "jsdoc/check-examples": ["error"|"warn", {"baseConfig":{"parser":"@typescript-eslint/parser","parserOptions":{"ecmaVersion":6},"rules":{"semi":["error","always"]}},"checkEslintrc":false}]
// Message: @example error (semi): Missing semicolon.
/**
* @example
* const test = something.find((_) => {
* return _
* });
*/
function quux () {
}
// "jsdoc/check-examples": ["error"|"warn", {"baseConfig":{"parserOptions":{"ecmaVersion":6},"rules":{"semi":["error","always"]}}}]
// Message: @example error (semi): Missing semicolon.
/**
* @example <caption>Say `Hello!` to the user.</caption>
* First, import the function:
*
* ```js
* import popup from './popup'
* const aConstInSameScope = 5;
* ```
*
* Then use it like this:
*
* ```js
* const aConstInSameScope = 7;
* popup('Hello!')
* ```
*
* Here is the result on macOS:
*
* 
*/
// "jsdoc/check-examples": ["error"|"warn", {"baseConfig":{"parserOptions":{"ecmaVersion":2015,"sourceType":"module"},"rules":{"semi":["error","always"]}},"checkEslintrc":false,"exampleCodeRegex":"/^```(?:js|javascript)\\n([\\s\\S]*?)```$/gm"}]
// Message: @example error (semi): Missing semicolon.
/**
* @example // begin
alert('hello')
// end
* And here is another example:
// begin
alert('there')
// end
*/
function quux () {
}
// "jsdoc/check-examples": ["error"|"warn", {"baseConfig":{"rules":{"semi":["warn","always"]}},"checkEslintrc":false,"exampleCodeRegex":"/\\/\\/ begin[\\s\\S]*?// end/g","noDefaultExampleRules":true}]
// Message: @example warning (semi): Missing semicolon.
/**
* @example
* quux();
*/
function quux () {
}
// "jsdoc/check-examples": ["error"|"warn", {"baseConfig":{"rules":{"indent":["error"]}},"checkEslintrc":false,"noDefaultExampleRules":false}]
// Message: @example error (indent): Expected indentation of 0 spaces but found 2.
/**
* @default 'abc'
*/
const str = 'abc';
// "jsdoc/check-examples": ["error"|"warn", {"checkDefaults":true}]
// Message: @default error (quotes): Strings must use doublequote.
/**
* @param {myType} [name='abc']
*/
function quux () {
}
// "jsdoc/check-examples": ["error"|"warn", {"checkParams":true}]
// Message: @param error (quotes): Strings must use doublequote.
/**
* @property {myType} [name='abc']
*/
const obj = {};
// "jsdoc/check-examples": ["error"|"warn", {"checkProperties":true}]
// Message: @property error (quotes): Strings must use doublequote.
/**
* Test function.
*
* @example <caption>functionName (paramOne: string, paramTwo?: any,
* paramThree?: any): boolean</caption> test()
*
* @param {string} paramOne Parameter description.
* @param {any} [paramTwo] Parameter description.
* @param {any} [paramThree] Parameter description.
* @returns {boolean} Return description.
*/
const functionName = function (paramOne, paramTwo,
paramThree) {
return false;
};
// "jsdoc/check-examples": ["error"|"warn", {"baseConfig":{"parserOptions":{"ecmaVersion":2015,"sourceType":"module"},"rules":{"semi":["error","always"]}},"captionRequired":true,"checkEslintrc":false}]
// Message: @example error (semi): Missing semicolon.
The following patterns are not considered problems:
/**
* @example ```js
alert('hello');
```
*/
function quux () {
}
// "jsdoc/check-examples": ["error"|"warn", {"baseConfig":{"rules":{"semi":["error","always"]}},"checkEslintrc":false,"exampleCodeRegex":"```js([\\s\\S]*)```"}]
/**
* @example ```js
alert('hello');
```
*/
function quux () {
}
// "jsdoc/check-examples": ["error"|"warn", {"baseConfig":{"rules":{"semi":["error","always"]}},"checkEslintrc":false,"exampleCodeRegex":"/```js([\\s\\S]*)```/"}]
/**
* @example
* // arbitrary example content
*/
function quux () {
}
// "jsdoc/check-examples": ["error"|"warn", {"checkEslintrc":false}]
/**
* @example
* quux(); // does something useful
*/
function quux () {
}
// "jsdoc/check-examples": ["error"|"warn", {"baseConfig":{"rules":{"no-undef":["error"]}},"checkEslintrc":false,"noDefaultExampleRules":false}]
/**
* @example quux();
*/
function quux () {
}
// "jsdoc/check-examples": ["error"|"warn", {"baseConfig":{"rules":{"indent":["error"]}},"checkEslintrc":false,"noDefaultExampleRules":false}]
/**
* @example <caption>Valid usage</caption>
* quux(); // does something useful
*
* @example <caption>Invalid usage</caption>
* quux('random unwanted arg'); // results in an error
*/
function quux () {
}
// "jsdoc/check-examples": ["error"|"warn", {"captionRequired":true,"checkEslintrc":false}]
/**
* @example test() // eslint-disable-line semi
*/
function quux () {}
// "jsdoc/check-examples": ["error"|"warn", {"checkEslintrc":false,"noDefaultExampleRules":true,"reportUnusedDisableDirectives":false}]
/**
* @example
test() // eslint-disable-line semi
*/
function quux () {}
// "jsdoc/check-examples": ["error"|"warn", {"allowInlineConfig":true,"baseConfig":{"rules":{"semi":["error","always"]}},"checkEslintrc":false,"noDefaultExampleRules":true}]
/**
* @example ```js
alert('hello')
```
*/
var quux = {
};
// "jsdoc/check-examples": ["error"|"warn", {"baseConfig":{"rules":{"semi":["error","never"]}},"checkEslintrc":false,"exampleCodeRegex":"```js([\\s\\S]*)```"}]
/**
* @example
* foo(function (err) {
* throw err;
* });
*/
function quux () {}
// "jsdoc/check-examples": ["error"|"warn", {"baseConfig":{"rules":{"indent":["error"]}},"checkEslintrc":false,"noDefaultExampleRules":false}]
/**
* @example
* const list: number[] = [1, 2, 3];
* quux(list);
*/
function quux () {
}
// "jsdoc/check-examples": ["error"|"warn", {"baseConfig":{"parser":"@typescript-eslint/parser","parserOptions":{"ecmaVersion":6},"rules":{"semi":["error","always"]}},"checkEslintrc":false}]
/**
* @example const ident = 5;
* quux2();
* bar();
*/
function quux2 () {
}
// "jsdoc/check-examples": ["error"|"warn", {"paddedIndent":2}]
/**
* @example
* function quux() {
* bar();
* }
*/
function quux () {
}
// "jsdoc/check-examples": ["error"|"warn", {"baseConfig":{"rules":{"indent":["error"]}},"checkEslintrc":false,"noDefaultExampleRules":false}]
// Comment
a();
export default {};
/**
*
*/
function f () {
}
/**
* Does quux
* @example
* // Do it!
* quux();
*/
function quux () {
}
// "jsdoc/check-examples": ["error"|"warn", {"baseConfig":{"plugins":["jsdoc"],"rules":{"jsdoc/require-file-overview":["error"]}},"checkEslintrc":false,"noDefaultExampleRules":false}]
/**
* @default "abc"
*/
const str = 'abc';
// "jsdoc/check-examples": ["error"|"warn", {"checkDefaults":true}]
/**
* @default
*/
const str = 'abc';
// "jsdoc/check-examples": ["error"|"warn", {"checkDefaults":true}]
/**
* @param {myType} [name="abc"]
*/
function quux () {
}
// "jsdoc/check-examples": ["error"|"warn", {"checkParams":true}]
/**
* @param {myType} name
*/
function quux () {
}
// "jsdoc/check-examples": ["error"|"warn", {"checkParams":true}]
/**
* @property {myType} [name="abc"]
*/
const obj = {};
// "jsdoc/check-examples": ["error"|"warn", {"checkProperties":true}]
/**
* @property {myType} [name]
*/
const obj = {};
// "jsdoc/check-examples": ["error"|"warn", {"checkProperties":true}]
/**
* @default 'abc'
*/
const str = 'abc';
// "jsdoc/check-examples": ["error"|"warn", {"checkDefaults":false,"matchingFileNameDefaults":"dummy.js"}]
/**
* @param {myType} [name='abc']
*/
function quux () {
}
// "jsdoc/check-examples": ["error"|"warn", {"checkParams":false,"matchingFileNameParams":"dummy.js"}]
/**
* @property {myType} [name='abc']
*/
const obj = {};
// "jsdoc/check-examples": ["error"|"warn", {"checkProperties":false,"matchingFileNameProperties":"dummy.js"}]
/**
* Test function.
*
* @example <caption>functionName (paramOne: string, paramTwo?: any,
* paramThree?: any): boolean</caption> test();
*
* @param {string} paramOne Parameter description.
* @param {any} [paramTwo] Parameter description.
* @param {any} [paramThree] Parameter description.
* @returns {boolean} Return description.
*/
const functionName = function (paramOne, paramTwo,
paramThree) {
return false;
};
// "jsdoc/check-examples": ["error"|"warn", {"baseConfig":{"parserOptions":{"ecmaVersion":2015,"sourceType":"module"},"rules":{"semi":["error","always"]}},"captionRequired":true,"checkEslintrc":false}]
Reports invalid padding inside JSDoc blocks.
Ignores parts enclosed in Markdown "code block"'s. For example, the following description is not reported:
/**
* Some description:
* ```html
* <section>
* <title>test</title>
* </section>
* ```
*/
This rule has an object option.
Array of tags (e.g., ['example', 'description']
) whose content will be
"hidden" from the check-indentation
rule. Defaults to ['example']
.
By default, the whole JSDoc block will be checked for invalid padding.
That would include @example
blocks too, which can get in the way
of adding full, readable examples of code without ending up with multiple
linting issues.
When disabled (by passing excludeTags: []
option), the following code will
report a padding issue:
/**
* @example
* anArray.filter((a) => {
* return a.b;
* });
*/
Context | everywhere |
Tags | N/A |
Recommended | false |
Options | excludeTags |
The following patterns are considered problems:
/** foo */
function quux () {
}
// Message: There must be no indentation.
/**
* foo
*
* @param bar
* baz
*/
function quux () {
}
// Message: There must be no indentation.
/**
* Foo
* bar
*/
class Moo {}
// Message: There must be no indentation.
/**
* foo
*
* @example
* anArray.filter((a) => {
* return a.b;
* });
*/
function quux () {
}
// "jsdoc/check-indentation": ["error"|"warn", {"excludeTags":[]}]
// Message: There must be no indentation.
/**
* foo
*
* @example
* aaaa
* @returns
* eeee
*/
function quux () {
}
// Message: There must be no indentation.
/**
* foo
* ```html
* <section>
* <title>test</title>
* </section>
* ```
* @returns
* eeee
*/
function quux () {
}
// Message: There must be no indentation.
/**
* foo
* ``` aaaa```
* @returns
* eeee
*/
function quux () {
}
// Message: There must be no indentation.
/**
* @example <caption>
* Here is a long
* indented summary of this
* example
* </caption>
* ```js
* function hi () {
* alert('Hello');
* }
* ```
*/
// "jsdoc/check-indentation": ["error"|"warn", {"excludeTags":[]}]
// Message: There must be no indentation.
/**
* @example <caption>
* Here is a long
* summary of this
* example
* </caption>
* // Code is not wrapped into fenced code block
* function hi () {
* alert('Hello');
* }
*/
// "jsdoc/check-indentation": ["error"|"warn", {"excludeTags":[]}]
// Message: There must be no indentation.
The following patterns are not considered problems:
/**
* foo
*
* @param bar
* baz
*/
function quux () {
}
/*** foo */
function quux () {
}
/**
* foo
*
* @example
* anArray.filter((a) => {
* return a.b;
* });
*/
function quux () {
}
/**
* foo
*
* @example
* anArray.filter((a) => {
* return a.b;
* });
* @returns
* eeee
*/
function quux () {
}
// "jsdoc/check-indentation": ["error"|"warn", {"excludeTags":["example","returns"]}]
/**
* foo
* ```html
* <section>
* <title>test</title>
* </section>
* ```
* @returns eeee
*/
function quux () {
}
/**
* foo
* ``` aaaa```
* @returns eeee
*/
function quux () {
}
/**
* @example <caption>
* Here is a long
* summary of this
* example
* </caption>
* ```js
* function hi () {
* alert('Hello');
* }
* ```
*/
// "jsdoc/check-indentation": ["error"|"warn", {"excludeTags":[]}]
/**
* @example
* ```
* @MyDecorator({
* myOptions: 42
* })
* export class MyClass {}
* ```
*/
function MyDecorator(options: { myOptions: number }) {
return (Base: Function) => {};
}
// "jsdoc/check-indentation": ["error"|"warn", {"excludeTags":["example","MyDecorator"]}]
/**
* @example ```
* @MyDecorator({
* myOptions: 42
* })
* export class MyClass {}
* ```
*/
function MyDecorator(options: { myOptions: number }) {
return (Base: Function) => {};
}
Reports invalid alignment of JSDoc block lines. This is a standard recommended to WordPress code, for example.
This rule allows one optional string argument. If it is "always"
then a
problem is raised when the lines are not aligned. If it is "never"
then
a problem should be raised when there is more than one space between each
line's parts. Defaults to "never"
.
Note that in addition to alignment, both options will ensure at least one space is present after the asterisk delimiter.
After the string, an options object is allowed with the following properties.
Use this to change the tags which are sought for alignment changes. Currently
only works with the "never" option. Defaults to an array of
['param', 'arg', 'argument', 'property', 'prop', 'returns', 'return']
.
An object with any of the following keys set to an integer. Affects spacing:
-
postDelimiter
- after the asterisk (e.g.,* @param
) -
postTag
- after the tag (e.g.,* @param
) -
postType
- after the type (e.g.,* @param {someType}
) -
postName
- after the name (e.g.,* @param {someType} name
)
If a spacing is not defined, it defaults to one.
Context | everywhere |
Options | (a string matching "always" or "never" and optional object with tags and customSpacings ) |
Tags |
param , property , returns and others added by tags
|
Aliases |
arg , argument , prop , return
|
Recommended | false |
The following patterns are considered problems:
/**
* Function description.
*
* @param {string} lorem Description.
* @param {int} sit Description multi words.
*/
const fn = ( lorem, sit ) => {}
// "jsdoc/check-line-alignment": ["error"|"warn", "always"]
// Message: Expected JSDoc block lines to be aligned.
/**
* With tabs.
*
* @param {string} lorem Description.
* @param {int} sit Description multi words.
*/
const fn = ( lorem, sit ) => {}
// "jsdoc/check-line-alignment": ["error"|"warn", "always"]
// Message: Expected JSDoc block lines to be aligned.
/**
* Function description.
*
* @param {string} lorem - Description.
* @param {int} sit - Description multi words.
*/
const fn = ( lorem, sit ) => {}
// "jsdoc/check-line-alignment": ["error"|"warn", "always"]
// Message: Expected JSDoc block lines to be aligned.
/**
* Function description.
*
* @param {string} lorem Description.
* @param {int} sit Description multi words.
*/
const fn = ( lorem, sit ) => {}
// "jsdoc/check-line-alignment": ["error"|"warn", "always"]
// Message: Expected JSDoc block lines to be aligned.
/**
* Function description.
*
* @param {string} lorem Description.
* @param {int} sit Description multi words.
*/
const fn = ( lorem, sit ) => {}
// "jsdoc/check-line-alignment": ["error"|"warn", "always"]
// Message: Expected JSDoc block lines to be aligned.
/**
* Function description.
*
* @param {string} lorem Description.
* @param {int} sit Description multi words.
*/
const fn = ( lorem, sit ) => {}
// "jsdoc/check-line-alignment": ["error"|"warn", "always"]
// Message: Expected JSDoc block lines to be aligned.
/**
* Function description.
*
* @param {string} lorem Description.
* @param {int} sit Description multi words.
*/
const fn = ( lorem, sit ) => {}
// "jsdoc/check-line-alignment": ["error"|"warn", "always"]
// Message: Expected JSDoc block lines to be aligned.
/**
* Function description.
*
* @param {string} lorem Description.
* @param {int} sit Description multi words.
*/
function fn( lorem, sit ) {}
// "jsdoc/check-line-alignment": ["error"|"warn", "always"]
// Message: Expected JSDoc block lines to be aligned.
const object = {
/**
* Function description.
*
* @param {string} lorem Description.
* @param {int} sit Description multi words.
*/
fn( lorem, sit ) {}
}
// "jsdoc/check-line-alignment": ["error"|"warn", "always"]
// Message: Expected JSDoc block lines to be aligned.
class ClassName {
/**
* Function description.
*
* @param {string} lorem Description.
* @param {int} sit Description multi words.
*/
fn( lorem, sit ) {}
}
// "jsdoc/check-line-alignment": ["error"|"warn", "always"]
// Message: Expected JSDoc block lines to be aligned.
/**
* Function description.
*
* @arg {string} lorem Description.
* @arg {int} sit Description multi words.
*/
const fn = ( lorem, sit ) => {}
// "jsdoc/check-line-alignment": ["error"|"warn", "always"]
// Message: Expected JSDoc block lines to be aligned.
/**
* @namespace
* @property {object} defaults Description.
* @property {int} defaults.lorem Description multi words.
*/
const config = {
defaults: {
lorem: 1
}
}
// "jsdoc/check-line-alignment": ["error"|"warn", "always"]
// Message: Expected JSDoc block lines to be aligned.
/**
* My object.
*
* @typedef {Object} MyObject
*
* @property {string} lorem Description.
* @property {int} sit Description multi words.
*/
// "jsdoc/check-line-alignment": ["error"|"warn", "always"]
// Message: Expected JSDoc block lines to be aligned.
/**
* My object.
*
* @typedef {Object} MyObject
*
* @property {{a: number, b: string, c}} lorem Description.
* @property {Object.<string, Class>} sit Description multi words.
* @property {Object.<string, Class>} amet Description} weird {multi} {{words}}.
* @property {Object.<string, Class>} dolor
*/
// "jsdoc/check-line-alignment": ["error"|"warn", "always"]
// Message: Expected JSDoc block lines to be aligned.
/**
* My object.
*
* @typedef {Object} MyObject
*
* @property {{a: number, b: string, c}} lorem Description.
* @property {Object.<string, Class>} sit Description multi words.
* @property {Object.<string, Class>} amet Description} weird {multi} {{words}}.
* @property {Object.<string, Class>} dolor
*/
// "jsdoc/check-line-alignment": ["error"|"warn", "always",{"tags":["typedef","property"]}]
// Message: Expected JSDoc block lines to be aligned.
/**
* My function.
*
* @param {string} lorem Description.
* @param {int} sit Description multi words.
*/
const fn = ( lorem, sit ) => {}
// "jsdoc/check-line-alignment": ["error"|"warn", "never"]
// Message: Expected JSDoc block lines to not be aligned.
/**
* My function.
*
* @param {string} lorem Description.
* @param {int} sit Description multi words.
*/
const fn = ( lorem, sit ) => {}
// "jsdoc/check-line-alignment": ["error"|"warn", "never"]
// Message: Expected JSDoc block lines to not be aligned.
/**
* My function.
*
* @param {string} lorem Description.
* @param {int} sit
*/
const fn = ( lorem, sit ) => {}
// "jsdoc/check-line-alignment": ["error"|"warn", "never"]
// Message: Expected JSDoc block lines to not be aligned.
/**
* My function.
*
* @param {string} lorem Description.
* @param {int} sit
*/
const fn = ( lorem, sit ) => {}
// Message: Expected JSDoc block lines to not be aligned.
/**
* Function description.
*
* @param {string} lorem Description.
* @param {int} sit Description multi
line without *.
*/
const fn = ( lorem, sit ) => {}
// "jsdoc/check-line-alignment": ["error"|"warn", "always"]
// Message: Expected JSDoc block lines to be aligned.
/**
* My function.
*
* @param {string} lorem Description.
* @param {int} sit
*
* @return {string} Return description
* with multi line, but don't touch.
*/
const fn = ( lorem, sit ) => {}
// "jsdoc/check-line-alignment": ["error"|"warn", "always",{"tags":["param"]}]
// Message: Expected JSDoc block lines to be aligned.
/**
* Only return doc.
*
* @return {boolean} Return description.
*/
const fn = ( lorem, sit ) => {}
// "jsdoc/check-line-alignment": ["error"|"warn", "always"]
// Message: Expected JSDoc block lines to be aligned.
/**
* Creates OS based shortcuts for files, folders, and applications.
*
* @param {object} options Options object for each OS.
* @return {boolean} True = success, false = failed to create the icon
*/
function quux () {}
// "jsdoc/check-line-alignment": ["error"|"warn", "never"]
// Message: Expected JSDoc block lines to not be aligned.
/**
* Creates OS based shortcuts for files, folders, and applications.
*
* @param {object} options Options object for each OS.
* @return {boolean} True = success, false = failed to create the icon
*/
function quux () {}
// "jsdoc/check-line-alignment": ["error"|"warn", "never"]
// Message: Expected JSDoc block lines to not be aligned.
/**
* Creates OS based shortcuts for files, folders, and applications.
*
* @param {object} options Options object for each OS.
* @return True = success, false = failed to create the icon
*/
function quux () {}
// "jsdoc/check-line-alignment": ["error"|"warn", "never"]
// Message: Expected JSDoc block lines to not be aligned.
/**
* Creates OS based shortcuts for files, folders, and applications.
*
* @param options Options object for each OS.
* @return True = success, false = failed to create the icon
*/
function quux () {}
// "jsdoc/check-line-alignment": ["error"|"warn", "never"]
// Message: Expected JSDoc block lines to not be aligned.
/**
* Creates OS based shortcuts for files, folders, and applications.
*
* @param {object} options Options object for each OS.
* @param {object} other Other.
* @return True = success, false = failed to create the icon
*/
function quux () {}
// "jsdoc/check-line-alignment": ["error"|"warn", "never",{"tags":["param","return"]}]
// Message: Expected JSDoc block lines to not be aligned.
/**
* Returns the value stored in the process.env for a given
* environment variable.
*
* @param {string} withPercents '%USERNAME%'
* @param {string} withoutPercents 'USERNAME'
* @return {string} 'bob' || '%USERNAME%'
*/
function quux () {}
// "jsdoc/check-line-alignment": ["error"|"warn", "never"]
// Message: Expected JSDoc block lines to not be aligned.
/**
* Function description
* description with post delimiter.
*
* @param {string} lorem Description.
* @param {int} sit Description multi words.
*/
const fn = ( lorem, sit ) => {}
// "jsdoc/check-line-alignment": ["error"|"warn", "always"]
// Message: Expected JSDoc block lines to be aligned.
/**
* Function description.
*
* @param {string} lorem Description.
* @param {int} sit Description multi words.
*
* @return {string} Return description.
*/
const fn = ( lorem, sit ) => {}
// "jsdoc/check-line-alignment": ["error"|"warn", "always",{"customSpacings":{"postDelimiter":2,"postTag":3,"postType":2}}]
// Message: Expected JSDoc block lines to be aligned.
/**
* Function description.
*
* @param {string} lorem Description.
* @param {int} sit Description multi words.
*
* @return {string} Return description.
*/
const fn = ( lorem, sit ) => {}
// "jsdoc/check-line-alignment": ["error"|"warn", "always",{"customSpacings":{"postName":3}}]
// Message: Expected JSDoc block lines to be aligned.
/**
* Function description.
*
* @param {string} lorem Description.
* @param {int} sit Description multi words.
*/
const fn = ( lorem, sit ) => {}
// "jsdoc/check-line-alignment": ["error"|"warn", "never",{"customSpacings":{"postDelimiter":2,"postTag":3,"postType":2}}]
// Message: Expected JSDoc block lines to not be aligned.
/**
* Function description.
*
* @param {string} lorem Description.
* @param {int} sit Description multi words.
*/
const fn = ( lorem, sit ) => {}
// "jsdoc/check-line-alignment": ["error"|"warn", "never",{"customSpacings":{"postName":3}}]
// Message: Expected JSDoc block lines to not be aligned.
/**
* Function description.
*
* @param {string} lorem Description.
* @param {int} sit Description multi words.
* @param {string} sth Multi
* line description.
*/
const fn = ( lorem, sit ) => {}
// "jsdoc/check-line-alignment": ["error"|"warn", "always"]
// Message: Expected JSDoc block lines to be aligned.
The following patterns are not considered problems:
/**
* Function description.
*
* @param {string} lorem Description.
* @param {int} sit Description multi words.
*/
const fn = ( lorem, sit ) => {}
// "jsdoc/check-line-alignment": ["error"|"warn", "always"]
/**
* With tabs.
*
* @param {string} lorem Description.
* @param {int} sit Description multi words.
*/
const fn = ( lorem, sit ) => {}
// "jsdoc/check-line-alignment": ["error"|"warn", "always"]
/**
* Function description.
*
* @param {string} lorem - Description.
* @param {int} sit - Description multi words.
*/
const fn = ( lorem, sit ) => {}
// "jsdoc/check-line-alignment": ["error"|"warn", "always"]
/**
* @param {string} lorem Description.
* @param {int} sit
*/
const fn = ( lorem, sit ) => {}
// "jsdoc/check-line-alignment": ["error"|"warn", "always"]
/**
* @param {int} sit
* @param {string} lorem Description.
*/
const fn = ( lorem, sit ) => {}
// "jsdoc/check-line-alignment": ["error"|"warn", "always"]
/**
* No params.
*/
const fn = () => {}
// "jsdoc/check-line-alignment": ["error"|"warn", "always"]
const fn = ( lorem, sit ) => {}
// "jsdoc/check-line-alignment": ["error"|"warn", "always"]
/**
* Function description.
*
* @param {string} lorem Description.
* @param {int} sit Description multi words.
*/
function fn( lorem, sit ) {}
// "jsdoc/check-line-alignment": ["error"|"warn", "always"]
const object = {
/**
* Function description.
*
* @param {string} lorem Description.
* @param {int} sit Description multi words.
*/
fn( lorem, sit ) {},
}
// "jsdoc/check-line-alignment": ["error"|"warn", "always"]
class ClassName {
/**
* Function description.
*
* @param {string} lorem Description.
* @param {int} sit Description multi words.
*/
fn( lorem, sit ) {}
}
// "jsdoc/check-line-alignment": ["error"|"warn", "always"]
/**
* Function description.
*
* @arg {string} lorem Description.
* @arg {int} sit Description multi words.
*/
const fn = ( lorem, sit ) => {}
// "jsdoc/check-line-alignment": ["error"|"warn", "always"]
/**
* @namespace
* @property {object} defaults Description.
* @property {int} defaults.lorem Description multi words.
*/
const config = {
defaults: {
lorem: 1
}
}
// "jsdoc/check-line-alignment": ["error"|"warn", "always"]
/**
* My object.
*
* @typedef {Object} MyObject
*
* @property {string} lorem Description.
* @property {int} sit Description multi words.
*/
// "jsdoc/check-line-alignment": ["error"|"warn", "always"]
/**
* My object.
*
* @typedef {Object} MyObject
*
* @property {{a: number, b: string, c}} lorem Description.
* @property {Object.<string, Class>} sit Description multi words.
* @property {Object.<string, Class>} amet Description} weird {multi} {{words}}.
* @property {Object.<string, Class>} dolor
*/
// "jsdoc/check-line-alignment": ["error"|"warn", "always"]
/**
* My object.
*
* @typedef {Object} MyObject
*
* @property {{a: number, b: string, c}} lorem Description.
* @property {Object.<string, Class>} sit Description multi words.
* @property {Object.<string, Class>} amet Description} weird {multi} {{words}}.
* @property {Object.<string, Class>} dolor
*/
// "jsdoc/check-line-alignment": ["error"|"warn", "always",{"tags":["typedef","property"]}]
/**
* My object.
*
* @template T
* @template W,X,Y,Z
* @template {string} K - K must be a string or string literal
* @template {{ serious(): string }} Seriousalizable - must have a serious method
*
* @param {{a: number, b: string, c}} lorem Description.
*/
// "jsdoc/check-line-alignment": ["error"|"warn", "always",{"tags":["template","param"]}]
/** @param {number} lorem */
const fn = ( lorem ) => {}
// "jsdoc/check-line-alignment": ["error"|"warn", "always"]
/**
* Creates OS based shortcuts for files, folders, and applications.
*
* @param {object} options Options object for each OS.
* @return {boolean} True = success, false = failed to create the icon
*/
function quux () {}
// "jsdoc/check-line-alignment": ["error"|"warn", "always"]
/**
* Creates OS based shortcuts for files, folders, and applications.
*
* @param {object} options Options object for each OS.
* @return {boolean}
*/
function quux () {}
// "jsdoc/check-line-alignment": ["error"|"warn", "always"]
/**
* Only return doc.
*
* @return {boolean} Return description.
*/
function quux () {}
// "jsdoc/check-line-alignment": ["error"|"warn", "always"]
/**
* Not validating without option.
*
* @param {string} lorem Description.
* @param {int} sit Description multi words.
*/
const fn = ( lorem, sit ) => {}
/**
* Creates OS based shortcuts for files, folders, and applications.
*
* @param {object} options Options object for each OS.
* @return {boolean} True = success, false = failed to create the icon
*/
function quux (options) {}
/**
* Creates OS based shortcuts for files, folders, and applications.
*
* @param {object} options Options object for each OS.
* @param {object} other Other.
* @return True = success, false = failed to create the icon
*/
function quux () {}
// "jsdoc/check-line-alignment": ["error"|"warn", "never",{"tags":["param"]}]
/**
* @param parameter Description.
*/
function func(parameter){
}
/**
* Function description
* description with post delimiter.
*
* @param {string} lorem Description.
* @param {int} sit Description multi words.
*/
const fn = ( lorem, sit ) => {}
// "jsdoc/check-line-alignment": ["error"|"warn", "always",{"preserveMainDescriptionPostDelimiter":true}]
/**
* Function description.
*
* @param {string} lorem Description.
* @param {int} sit Description multi words.
*
* @return {string} Return description.
*/
const fn = ( lorem, sit ) => {}
// "jsdoc/check-line-alignment": ["error"|"warn", "always",{"customSpacings":{"postDelimiter":2,"postTag":3,"postType":2}}]
/**
* Function description.
*
* @param {string} lorem Description.
* @param {int} sit Description multi words.
*
* @return {string} Return description.
*/
const fn = ( lorem, sit ) => {}
// "jsdoc/check-line-alignment": ["error"|"warn", "never",{"customSpacings":{"postDelimiter":2,"postTag":3,"postType":2}}]
/**
* @param {{
* ids: number[]
* }} params
*/
const fn = ({ids}) => {}
// "jsdoc/check-line-alignment": ["error"|"warn", "always"]
/**
* Function description.
*
* @param {string} lorem Description.
* @param {int} sit Description multi words.
* @param {string} sth Multi
* line description.
*/
const fn = ( lorem, sit ) => {}
// "jsdoc/check-line-alignment": ["error"|"warn", "always"]
Ensures that parameter names in JSDoc match those in the function declaration.
Note that by default the rule will not report parameters present on the docs but non-existing on the function signature when an object rest property is part of that function signature since the seemingly non-existing properties might actually be a part of the object rest property.
/**
* @param options
* @param options.foo
*/
function quux ({foo, ...extra}) {}
To require that extra
be documented--and that any extraneous properties
get reported--e.g., if there had been a @param options.bar
above--you
can use the checkRestProperty
option which insists that the rest
property be documented (and that there be no other implicit properties).
Note, however, that jsdoc does not appear
to currently support syntax or output to distinguish rest properties from
other properties, so in looking at the docs alone without looking at the
function signature, the disadvantage of enabling this option is that it
may appear that there is an actual property named extra
.
See the "Destructuring" section. Defaults to false
.
See require-param
under the option of the same name.
Set to true
to auto-remove @param
duplicates (based on identical
names).
Note that this option will remove duplicates of the same name even if the definitions do not match in other ways (e.g., the second param will be removed even if it has a different type or description).
If set to true
, this option will allow extra @param
definitions (e.g.,
representing future expected or virtual params) to be present without needing
their presence within the function signature. Other inconsistencies between
@param
's and present function parameters will still be reported.
Whether to check destructured properties. Defaults to true
.
Set to true
if you wish to avoid reporting of child property documentation
where instead of destructuring, a whole plain object is supplied as default
value but you wish its keys to be considered as signalling that the properties
are present and can therefore be documented. Defaults to false
.
Whether to check for extra destructured properties. Defaults to false
. Change
to true
if you want to be able to document properties which are not actually
destructured. Keep as false
if you expect properties to be documented in
their own types. Note that extra properties will always be reported if another
item at the same level is destructured as destructuring will prevent other
access and this option is only intended to permit documenting extra properties
that are available and actually used in the function.
Context |
ArrowFunctionExpression , FunctionDeclaration , FunctionExpression
|
Options |
allowExtraTrailingParamDocs , checkDestructured , checkRestProperty , checkTypesPattern , useDefaultObjectProperties , disableExtraPropertyReporting
|
Tags | param |
Aliases |
arg , argument
|
Recommended | true |
The following patterns are considered problems: |
/**
* @param Foo
*/
function quux (foo = 'FOO') {
}
// Message: Expected @param names to be "foo". Got "Foo".
/**
* @arg Foo
*/
function quux (foo = 'FOO') {
}
// Settings: {"jsdoc":{"tagNamePreference":{"param":"arg"}}}
// Message: Expected @arg names to be "foo". Got "Foo".
/**
* @param Foo
*/
function quux (foo) {
}
// Message: Expected @param names to be "foo". Got "Foo".
/**
* @param Foo.Bar
*/
function quux (foo) {
}
// Message: @param path declaration ("Foo.Bar") appears before any real parameter.
/**
* @param foo
* @param Foo.Bar
*/
function quux (foo) {
}
// Message: @param path declaration ("Foo.Bar") root node name ("Foo") does not match previous real parameter name ("foo").
/**
* Assign the project to a list of employees.
* @param {string} employees[].name - The name of an employee.
* @param {string} employees[].department - The employee's department.
*/
function assign (employees) {
};
// Message: @param path declaration ("employees[].name") appears before any real parameter.
/**
* Assign the project to a list of employees.
* @param {string} employees[].name - The name of an employee.
* @param {string} employees[].name - The employee's department.
*/
function assign (employees) {
};
// "jsdoc/check-param-names": ["error"|"warn", {"enableFixer":true}]
// Message: Duplicate @param "employees[].name"
/**
* @param foo
* @param foo.bar
* @param bar
*/
function quux (bar, foo) {
}
// Message: Expected @param names to be "bar, foo". Got "foo, bar".
/**
* @param foo
* @param bar
*/
function quux (foo) {
}
// Message: @param "bar" does not match an existing function parameter.
/**
* @param foo
* @param foo
*/
function quux (foo) {
}
// "jsdoc/check-param-names": ["error"|"warn", {"enableFixer":true}]
// Message: Duplicate @param "foo"
class bar {
/**
* @param foo
* @param foo
*/
quux (foo) {
}
}
// "jsdoc/check-param-names": ["error"|"warn", {"enableFixer":true}]
// Message: Duplicate @param "foo"
/**
* @param foo
* @param foo
*/
function quux (foo, bar) {
}
// "jsdoc/check-param-names": ["error"|"warn", {"enableFixer":true}]
// Message: Duplicate @param "foo"
/**
* @param foo
* @param foo
*/
function quux (foo, foo) {
}
// "jsdoc/check-param-names": ["error"|"warn", {"enableFixer":true}]
// Message: Duplicate @param "foo"
/**
* @param cfg
* @param cfg.foo
* @param cfg.foo
*/
function quux ({foo}) {
}
// "jsdoc/check-param-names": ["error"|"warn", {"enableFixer":true}]
// Message: Duplicate @param "cfg.foo"
/**
* @param cfg
* @param cfg.foo
* @param cfg.foo
*/
function quux ({foo}) {
}
// Message: Duplicate @param "cfg.foo"
/**
* @param cfg
* @param cfg.foo
*/
function quux ({foo, bar}) {
}
// Message: Missing @param "cfg.bar"
/**
* @param cfg
* @param cfg.foo
* @param [cfg.foo]
* @param baz
*/
function quux ({foo}, baz) {
}
// "jsdoc/check-param-names": ["error"|"warn", {"enableFixer":true}]
// Message: Duplicate @param "cfg.foo"
/**
* @param cfg
* @param cfg.foo
* @param [cfg.foo="with a default"]
* @param baz
*/
function quux ({foo, bar}, baz) {
}
// Message: Missing @param "cfg.bar"
/**
* @param cfg
* @param cfg.foo
* @param [cfg.foo="with a default"]
* @param baz
*/
function quux ({foo}, baz) {
}
// "jsdoc/check-param-names": ["error"|"warn", {"enableFixer":true}]
// Message: Duplicate @param "cfg.foo"
/**
* @param cfg
* @param [cfg.foo="with a default"]
* @param baz
*/
function quux ({foo, bar}, baz) {
}
// Message: Missing @param "cfg.bar"
/**
* @param args
*/
function quux ({a, b}) {
}
// Message: Missing @param "args.a"
/**
* @param args
*/
function quux ({a, b} = {}) {
}
// Message: Missing @param "args.a"
export class SomeClass {
/**
* @param prop
*/
constructor(private property: string) {}
}
// Message: Expected @param names to be "property". Got "prop".
export class SomeClass {
/**
* @param prop
* @param prop.foo
*/
constructor(prop: { foo: string, bar: string }) {}
}
// Message: Missing @param "prop.bar"
export class SomeClass {
/**
* @param prop
* @param prop.foo
* @param prop.bar
*/
constructor(options: { foo: string, bar: string }) {}
}
// Message: @param "prop" does not match parameter name "options"
export class SomeClass {
/**
* @param options
* @param options.foo
* @param options.bar
*/
constructor(options: { foo: string }) {}
}
// Message: @param "options.bar" does not exist on options
/**
* @param foo
*/
function quux (foo) {
}
// Settings: {"jsdoc":{"tagNamePreference":{"param":false}}}
// Message: Unexpected tag `@param`
/**
* @param {Error} error Exit code
* @param {number} [code = 1] Exit code
*/
function quux (error, cde = 1) {
};
// Message: Expected @param names to be "error, cde". Got "error, code".
/**
* @param foo
*/
function quux ([a, b] = []) {
}
// Message: Missing @param "foo."0""
/**
* @param options
* @param options.foo
*/
function quux ({foo, ...extra}) {
}
// "jsdoc/check-param-names": ["error"|"warn", {"checkRestProperty":true}]
// Message: Missing @param "options.extra"
/**
* @param cfg
* @param cfg.foo
* @param cfg.bar
* @param cfg.extra
*/
function quux ({foo, ...extra}) {
}
// "jsdoc/check-param-names": ["error"|"warn", {"checkRestProperty":true}]
// Message: @param "cfg.bar" does not exist on cfg
/**
* Converts an SVGRect into an object.
* @param {SVGRect} bbox - a SVGRect
*/
const bboxToObj = function ({x, y, width, height}) {
return {x, y, width, height};
};
// "jsdoc/check-param-names": ["error"|"warn", {"checkTypesPattern":"SVGRect"}]
// Message: Missing @param "bbox.x"
/**
* Converts an SVGRect into an object.
* @param {object} bbox - a SVGRect
*/
const bboxToObj = function ({x, y, width, height}) {
return {x, y, width, height};
};
// Message: Missing @param "bbox.x"
module.exports = class GraphQL {
/**
* @param fetchOptions
* @param cacheKey
*/
fetch = ({ url, ...options }, cacheKey) => {
}
};
// "jsdoc/check-param-names": ["error"|"warn", {"checkRestProperty":true}]
// Message: Missing @param "fetchOptions.url"
/**
* Testing
*
* @param options
* @param options.one One
* @param options.two Two
* @param options.four Four
*/
function testingEslint(options: {
one: string;
two: string;
three: string;
}): string {
return one + two + three;
}
// Message: Missing @param "options.three"
/**
*
*/
function quux() {
}
// Settings: {"jsdoc":{"structuredTags":{"see":{"name":false,"required":["name"]}}}}
// Message: Cannot add "name" to `require` with the tag's `name` set to `false`
/**
* @param root
* @param foo
*/
function quux ({foo, bar}, baz) {
}
// "jsdoc/check-param-names": ["error"|"warn", {"checkDestructured":false}]
// Message: Expected @param names to be "root, baz". Got "root, foo".
/**
* Description.
* @param {Object} options
* @param {FooBar} foo
*/
function quux ({ foo: { bar } }) {}
// Message: Missing @param "options.foo"
/**
* Description.
* @param {Object} options
* @param options.foo
*/
function quux ({ foo: { bar } }) {}
// Message: Missing @param "options.foo.bar"
/**
* Description.
* @param {object} options Options.
* @param {object} options.foo A description.
* @param {object} options.foo.bar
*/
function foo({ foo: { bar: { baz } }}) {}
// Message: Missing @param "options.foo.bar.baz"
/**
* Returns a number.
* @param {Object} props Props.
* @param {Object} props.prop Prop.
* @param {string} props.prop.a String.
* @param {string} props.prop.b String.
* @return {number} A number.
*/
export function testFn1 ({ prop = { a: 1, b: 2 } }) {
}
// "jsdoc/check-param-names": ["error"|"warn", {"useDefaultObjectProperties":false}]
// Message: @param "props.prop.a" does not exist on props
/**
* @param {object} cfg
* @param {string} cfg.foo
* @param {string} cfg.bar
* @param {object} cfg.extra
*/
function quux ({foo}) {
}
// Message: @param "cfg.bar" does not exist on cfg
/**
* @param {object} cfg
* @param {string} cfg.foo
* @param {string} cfg.bar
* @param {object} cfg.extra
*/
function quux ({foo}) {
}
// "jsdoc/check-param-names": ["error"|"warn", {"disableExtraPropertyReporting":true}]
// Message: @param "cfg.bar" does not exist on cfg
/**
* @param {object} root
* @param {object} root.cfg
* @param {object} root.cfg.a
* @param {string} root.cfg.a.foo
* @param {string} root.cfg.a.bar
* @param {object} root.cfg.a.extra
*/
function quux ({cfg: {a: {foo}}}) {
}
// Message: @param "root.cfg.a.bar" does not exist on root
/**
* @param {object} root
* @param {object} root.cfg
* @param {object} root.cfg.a
* @param {string} root.cfg.a.foo
* @param {string} root.cfg.a.bar
* @param {object} root.cfg.a.extra
*/
function quux ({cfg: {a: {foo}}}) {
}
// "jsdoc/check-param-names": ["error"|"warn", {"disableExtraPropertyReporting":true}]
// Message: @param "root.cfg.a.bar" does not exist on root
/**
* @param {object} root
* @param {object} root.cfg
* @param {string} root.cfg.foo
* @param {string} root.cfg.bar
* @param {object} root.cfg.extra
*/
function quux ({cfg}) {
}
// Message: @param "root.cfg.foo" does not exist on root
/**
* @param foo
* @param foo
* on another line
*/
function quux (foo) {
}
// "jsdoc/check-param-names": ["error"|"warn", {"enableFixer":true}]
// Message: Duplicate @param "foo"
The following patterns are not considered problems:
/**
*
*/
function quux (foo) {
}
/**
* @param foo
*/
function quux (foo) {
}
/**
* @param foo
* @param bar
*/
function quux (foo, bar) {
}
/**
* @param foo
* @param bar
*/
function quux (foo, bar, baz) {
}
/**
* @param foo
* @param foo.foo
* @param bar
*/
function quux (foo, bar) {
}
/**
* @param args
*/
function quux (...args) {
}
/**
* @param foo
* @param foo.a
* @param foo.b
*/
function quux ({a, b}) {
}
/**
* @param foo
* @param foo.a
* @param foo.b
*/
function quux ({"a": A, b}) {
}
/**
* @param foo
* @param foo."a"
* @param foo.b
*/
function quux ({a: A, b}) {
}
/**
* @param foo
* @param foo."a-b"
* @param foo.b
*/
function quux ({"a-b": A, b}) {
}
/**
* @param foo
* @param foo.bar
* @param foo.baz
* @param bar
*/
function quux (foo, bar) {
}
/**
* Assign the project to a list of employees.
* @param {object[]} employees - The employees who are responsible for the project.
* @param {string} employees[].name - The name of an employee.
* @param {string} employees[].department - The employee's department.
*/
function assign (employees) {
};
export class SomeClass {
/**
* @param property
*/
constructor(private property: string) {}
}
export class SomeClass {
/**
* @param options
* @param options.foo
* @param options.bar
*/
constructor(options: { foo: string, bar: string }) {}
}
export class SomeClass {
/**
* @param options
* @param options.foo
* @param options.bar
*/
constructor({ foo, bar }: { foo: string, bar: string }) {}
}
export class SomeClass {
/**
* @param options
* @param options.foo
* @param options.bar
*/
constructor({ foo, bar }: { foo: string, bar: string }) {}
}
/**
* @param {Error} error Exit code
* @param {number} [code = 1] Exit code
*/
function quux (error, code = 1) {
};
/**
* @param foo
* @param bar
*/
function quux (foo) {
}
// "jsdoc/check-param-names": ["error"|"warn", {"allowExtraTrailingParamDocs":true}]
/**
* @param cfg
* @param cfg.foo
* @param baz
*/
function quux ({foo}, baz) {
}
/**
* @param cfg
* @param cfg.foo
* @param cfg2
*/
function quux ({foo}, cfg2) {
}
/**
* @param cfg
* @param cfg.foo
* @param baz
* @param baz.cfg
*/
function quux ({foo}, {cfg}) {
}
/**
* @param options
* @param options.foo
*/
function quux ({foo, ...extra}) {
}
/**
* @param foo
* @param bar
*/
function quux (foo, bar, ...extra) {
}
/**
* Converts an SVGRect into an object.
* @param {SVGRect} bbox - a SVGRect
*/
const bboxToObj = function ({x, y, width, height}) {
return {x, y, width, height};
};
/**
* Converts an SVGRect into an object.
* @param {SVGRect} bbox - a SVGRect
*/
const bboxToObj = function ({x, y, width, height}) {
return {x, y, width, height};
};
/**
* Converts an SVGRect into an object.
* @param {object} bbox - a SVGRect
*/
const bboxToObj = function ({x, y, width, height}) {
return {x, y, width, height};
};
// "jsdoc/check-param-names": ["error"|"warn", {"checkTypesPattern":"SVGRect"}]
class CSS {
/**
* Set one or more CSS properties for the set of matched elements.
*
* @param {Object} propertyObject - An object of property-value pairs to set.
*/
setCssObject(propertyObject: {[key: string]: string | number}): void {
}
}
/**
* Logs a string.
*
* @param input - String to output.
*/
export default function (input: {
[foo: string]: { a: string; b: string };
}): void {
input;
}
export class Thing {
foo: any;
/**
* @param {} C
*/
constructor(C: { new (): any }) {
this.foo = new C();
}
}
/**
* @param foo
* @param root
*/
function quux (foo, {bar}) {
}
// "jsdoc/check-param-names": ["error"|"warn", {"checkDestructured":false}]
class A {
/**
* Show a prompt.
* @param hideButton true if button should be hidden, false otherwise
* @param onHidden delegate to call when the prompt is hidden
*/
public async showPrompt(hideButton: boolean, onHidden: {(): void}): Promise<void>
{
}
}
/**
* Description.
* @param {Object} options Options.
* @param {FooBar} options.foo foo description.
*/
function quux ({ foo: { bar }}) {}
/**
* Description.
* @param {FooBar} options
* @param {Object} options.foo
*/
function quux ({ foo: { bar } }) {}
// "jsdoc/check-param-names": ["error"|"warn", {"checkTypesPattern":"FooBar"}]
/**
* Description.
* @param {Object} options
* @param {FooBar} options.foo
* @param {FooBar} options.baz
*/
function quux ({ foo: { bar }, baz: { cfg } }) {}
/**
* Item
*
* @param {object} props
* @param {object} props.data - case data
* @param {string} props.data.className - additional css class
* @param props.val
*/
export default function Item({
data: {
className,
} = {},
val = 4
}) {
}
/**
* @param obj
* @param obj.data
* @param obj.data."0"
* @param obj.data."1"
* @param obj.data."2"
* @param obj.defaulting
* @param obj.defaulting."0"
* @param obj.defaulting."1"
*/
function Item({
data: [foo, bar, ...baz],
defaulting: [quux, xyz] = []
}) {
}
/**
* Returns a number.
* @param {Object} props Props.
* @param {Object} props.prop Prop.
* @param {string} props.prop.a String.
* @param {string} props.prop.b String.
* @return {number} A number.
*/
export function testFn1 ({ prop = { a: 1, b: 2 } }) {
}
// "jsdoc/check-param-names": ["error"|"warn", {"useDefaultObjectProperties":true}]
/**
* @param {object} root
* @param {object} root.cfg
* @param {string} root.cfg.foo
* @param {string} root.cfg.bar
* @param {object} root.cfg.extra
*/
function quux ({cfg}) {
}
// "jsdoc/check-param-names": ["error"|"warn", {"disableExtraPropertyReporting":true}]
class A {
/**
* @param cfg
* @param cfg.abc
*/
constructor({
[new.target.prop]: cX,
abc
}) {
}
}
/**
* @param root
* @param root."0" Ignored
* @param root."1" Our "b"
*/
const foo = ([, b]) => b;
Ensures that property names in JSDoc are not duplicated on the same block and that nested properties have defined roots.
Set to true
to auto-remove @property
duplicates (based on
identical names).
Note that this option will remove duplicates of the same name even if the definitions do not match in other ways (e.g., the second property will be removed even if it has a different type or description).
Context | Everywhere |
Options | enableFixer |
Tags | property |
Aliases | prop |
Recommended | true |
The following patterns are considered problems:
/**
* @typedef (SomeType) SomeTypedef
* @property Foo.Bar
*/
// Message: @property path declaration ("Foo.Bar") appears before any real property.
/**
* @typedef (SomeType) SomeTypedef
* @property foo
* @property Foo.Bar
*/
// Message: @property path declaration ("Foo.Bar") root node name ("Foo") does not match previous real property name ("foo").
/**
* Assign the project to a list of employees.
* @typedef (SomeType) SomeTypedef
* @property {string} employees[].name - The name of an employee.
* @property {string} employees[].department - The employee's department.
*/
// Message: @property path declaration ("employees[].name") appears before any real property.
/**
* Assign the project to a list of employees.
* @typedef (SomeType) SomeTypedef
* @property {string} employees[].name - The name of an employee.
* @property {string} employees[].name - The employee's department.
*/
// "jsdoc/check-property-names": ["error"|"warn", {"enableFixer":true}]
// Message: Duplicate @property "employees[].name"
/**
* @typedef (SomeType) SomeTypedef
* @property foo
* @property foo
*/
// "jsdoc/check-property-names": ["error"|"warn", {"enableFixer":true}]
// Message: Duplicate @property "foo"
/**
* @typedef (SomeType) SomeTypedef
* @property foo
* @property foo
*/
// Message: Duplicate @property "foo"
/**
* @typedef (SomeType) SomeTypedef
* @property cfg
* @property cfg.foo
* @property cfg.foo
*/
function quux ({foo, bar}) {
}
// "jsdoc/check-property-names": ["error"|"warn", {"enableFixer":true}]
// Message: Duplicate @property "cfg.foo"
class Test {
/**
* @typedef (SomeType) SomeTypedef
* @property cfg
* @property cfg.foo
* @property cfg.foo
*/
quux ({foo, bar}) {
}
}
// "jsdoc/check-property-names": ["error"|"warn", {"enableFixer":true}]
// Message: Duplicate @property "cfg.foo"
/**
* @typedef (SomeType) SomeTypedef
* @property cfg
* @property cfg.foo
* @property [cfg.foo]
* @property baz
*/
function quux ({foo, bar}, baz) {
}
// "jsdoc/check-property-names": ["error"|"warn", {"enableFixer":true}]
// Message: Duplicate @property "cfg.foo"
/**
* @typedef (SomeType) SomeTypedef
* @property cfg
* @property cfg.foo
* @property [cfg.foo="with a default"]
* @property baz
*/
function quux ({foo, bar}, baz) {
}
// "jsdoc/check-property-names": ["error"|"warn", {"enableFixer":true}]
// Message: Duplicate @property "cfg.foo"
/**
* @typedef (SomeType) SomeTypedef
* @prop foo
* @prop foo
*/
// Settings: {"jsdoc":{"tagNamePreference":{"property":"prop"}}}
// "jsdoc/check-property-names": ["error"|"warn", {"enableFixer":true}]
// Message: Duplicate @prop "foo"
/**
* @typedef (SomeType) SomeTypedef
* @property foo
*/
// Settings: {"jsdoc":{"tagNamePreference":{"property":false}}}
// Message: Unexpected tag `@property`
The following patterns are not considered problems:
/**
*
*/
/**
* @typedef (SomeType) SomeTypedef
* @property foo
*/
/**
* @typedef (SomeType) SomeTypedef
* @prop foo
*/
/**
* @typedef (SomeType) SomeTypedef
* @property foo
* @property bar
*/
/**
* @typedef (SomeType) SomeTypedef
* @property foo
* @property foo.foo
* @property bar
*/
/**
* Assign the project to a list of employees.
* @typedef (SomeType) SomeTypedef
* @property {object[]} employees - The employees who are responsible for the project.
* @property {string} employees[].name - The name of an employee.
* @property {string} employees[].department - The employee's department.
*/
/**
* @typedef (SomeType) SomeTypedef
* @property {Error} error Exit code
* @property {number} [code = 1] Exit code
*/
/**
* @namespace (SomeType) SomeNamespace
* @property {Error} error Exit code
* @property {number} [code = 1] Exit code
*/
/**
* @class
* @property {Error} error Exit code
* @property {number} [code = 1] Exit code
*/
function quux (code = 1) {
this.error = new Error('oops');
this.code = code;
}
/**
* @typedef (SomeType) SomeTypedef
* @property foo
* @property foo.bar
* @property foo.baz
* @property bar
*/
Reports against syntax not encouraged for the mode (e.g., Google Closure
Compiler in "jsdoc" or "typescript" mode). Note that this rule will not check
for types that are wholly invalid for a given mode, as that is covered by
valid-types
.
Currently checks against:
- Use of
=
in "jsdoc" or "typescript" mode
Note that "jsdoc" actually allows Closure syntax, but with another option available for optional parameters (enclosing the name in brackets), the rule is enforced (except under "permissive" and "closure" modes).
Context | everywhere |
Tags | N/A |
Recommended | false |
The following patterns are considered problems:
/**
* @param {string=} foo
*/
function quux (foo) {
}
// Message: Syntax should not be Google Closure Compiler style.
The following patterns are not considered problems:
/**
* @param {string=} foo
*/
function quux (foo) {
}
// Settings: {"jsdoc":{"mode":"closure"}}
/**
* @param {string} [foo]
*/
function quux (foo) {
}
/**
*
*/
function quux (foo) {
}
Reports invalid block tag names.
Valid JSDoc 3 Block Tags are:
abstract
access
alias
async
augments
author
borrows
callback
class
classdesc
constant
constructs
copyright
default
deprecated
description
enum
event
example
exports
external
file
fires
function
generator
global
hideconstructor
ignore
implements
inheritdoc
inner
instance
interface
kind
lends
license
listens
member
memberof
memberof!
mixes
mixin
module
name
namespace
override
package
param
private
property
protected
public
readonly
requires
returns
see
since
static
summary
this
throws
todo
tutorial
type
typedef
variation
version
yields
modifies
is also supported (see source)
but is undocumented.
The following synonyms are also recognized if you set them in
tagNamePreference
as a key (or replacement):
arg
argument
const
constructor
defaultvalue
desc
emits
exception
extends
fileoverview
func
host
method
overview
prop
return
var
virtual
yield
If you wish to allow in certain cases both a primary tag name and its
alias(es), you can set a normally non-preferred tag name to itself to indicate
that you want to allow both the default tag (in this case @returns
) and a
non-default (in this case return
):
"tagNamePreference": {
"return": "return",
}
Because the tags indicated as replacements in
settings.jsdoc.tagNamePreference
will automatically be considered as valid,
the above works.
Likewise are the tag keys of settings.jsdoc.structuredTags
automatically
considered as valid (as their defining an expected structure for tags implies
the tags may be used).
For TypeScript
(or Closure), when settings.jsdoc.mode
is set to typescript
or closure
,
one may also use the following:
template
And for Closure,
when settings.jsdoc.mode
is set to closure
, one may use the following (in
addition to the jsdoc and TypeScript tags–though replacing returns
with
return
):
define (synonym of `const` per jsdoc source)
dict
export
externs
final
implicitCast (casing distinct from that recognized by jsdoc internally)
inheritDoc (casing distinct from that recognized by jsdoc internally)
noalias
nocollapse
nocompile
noinline
nosideeffects
polymer
polymerBehavior
preserve
record (synonym of `interface` per jsdoc source)
struct
suppress
unrestricted
...and these undocumented tags which are only in source:
closurePrimitive
customElement
expose
hidden
idGenerator
meaning
mixinClass
mixinFunction
ngInject
owner
typeSummary
wizaction
Use an array of definedTags
strings to configure additional, allowed tags.
The format is as follows:
{
"definedTags": ["note", "record"]
}
If this is set to true
, all of the following tags used to control JSX output are allowed:
jsx
jsxFrag
jsxImportSource
jsxRuntime
For more information, see the babel documentation.
Context | everywhere |
Tags | N/A |
Recommended | true |
Options | definedTags |
Settings |
tagNamePreference , mode
|
The following patterns are considered problems:
/** @typoo {string} */
let a;
// Message: Invalid JSDoc tag name "typoo".
/** @typoo {string} */
let a;
// Settings: {"jsdoc":{"structuredTags":{"parameter":{"name":"namepath-referencing","required":["type","name"],"type":true}}}}
// Message: Invalid JSDoc tag name "typoo".
/**
* @Param
*/
function quux () {
}
// Message: Invalid JSDoc tag name "Param".
/**
* @foo
*/
function quux () {
}
// Message: Invalid JSDoc tag name "foo".
/**
* @arg foo
*/
function quux (foo) {
}
// Message: Invalid JSDoc tag (preference). Replace "arg" JSDoc tag with "param".
/**
* @param foo
*/
function quux (foo) {
}
// Settings: {"jsdoc":{"tagNamePreference":{"param":"arg"}}}
// Message: Invalid JSDoc tag (preference). Replace "param" JSDoc tag with "arg".
/**
* @constructor foo
*/
function quux (foo) {
}
// Settings: {"jsdoc":{"tagNamePreference":{"tag constructor":"cons"}}}
// Message: Invalid JSDoc tag (preference). Replace "constructor" JSDoc tag with "cons".
/**
* @arg foo
*/
function quux (foo) {
}
// Settings: {"jsdoc":{"tagNamePreference":{"arg":"somethingDifferent"}}}
// Message: Invalid JSDoc tag (preference). Replace "arg" JSDoc tag with "somethingDifferent".
/**
* @param foo
*/
function quux (foo) {
}
// Settings: {"jsdoc":{"tagNamePreference":{"param":"parameter"}}}
// Message: Invalid JSDoc tag (preference). Replace "param" JSDoc tag with "parameter".
/**
* @bar foo
*/
function quux (foo) {
}
// Message: Invalid JSDoc tag name "bar".
/**
* @baz @bar foo
*/
function quux (foo) {
}
// "jsdoc/check-tag-names": ["error"|"warn", {"definedTags":["bar"]}]
// Message: Invalid JSDoc tag name "baz".
/**
* @bar
* @baz
*/
function quux (foo) {
}
// "jsdoc/check-tag-names": ["error"|"warn", {"definedTags":["bar"]}]
// Message: Invalid JSDoc tag name "baz".
/**
* @todo
*/
function quux () {
}
// Settings: {"jsdoc":{"tagNamePreference":{"todo":false}}}
// Message: Blacklisted tag found (`@todo`)
/**
* @todo
*/
function quux () {
}
// Settings: {"jsdoc":{"tagNamePreference":{"todo":{"message":"Please resolve to-dos or add to the tracker"}}}}
// Message: Please resolve to-dos or add to the tracker
/**
* @todo
*/
function quux () {
}
// Settings: {"jsdoc":{"tagNamePreference":{"todo":{"message":"Please use x-todo instead of todo","replacement":"x-todo"}}}}
// Message: Please use x-todo instead of todo
/**
* @todo
*/
function quux () {
}
// Settings: {"jsdoc":{"tagNamePreference":{"todo":{"message":"Please use x-todo instead of todo","replacement":"x-todo"}}}}
// Message: Please use x-todo instead of todo
/**
* @todo
*/
function quux () {
}
// Settings: {"jsdoc":{"tagNamePreference":{"todo":55}}}
// Message: Invalid `settings.jsdoc.tagNamePreference`. Values must be falsy, a string, or an object.
/**
* @property {object} a
* @prop {boolean} b
*/
function quux () {
}
// Message: Invalid JSDoc tag (preference). Replace "prop" JSDoc tag with "property".
/**
* @abc foo
* @abcd bar
*/
function quux () {
}
// Settings: {"jsdoc":{"tagNamePreference":{"abc":"abcd"}}}
// "jsdoc/check-tag-names": ["error"|"warn", {"definedTags":["abcd"]}]
// Message: Invalid JSDoc tag (preference). Replace "abc" JSDoc tag with "abcd".
/**
* @abc
* @abcd
*/
function quux () {
}
// Settings: {"jsdoc":{"tagNamePreference":{"abc":"abcd"}}}
// Message: Invalid JSDoc tag (preference). Replace "abc" JSDoc tag with "abcd".
/**
* @returns
*/
function quux (foo) {}
// Settings: {"jsdoc":{"mode":"closure"}}
// Message: Invalid JSDoc tag (preference). Replace "returns" JSDoc tag with "return".
/**
* @modifies
* @abstract
* @access
* @alias
* @async
* @augments
* @author
* @borrows
* @callback
* @class
* @classdesc
* @constant
* @constructs
* @copyright
* @default
* @deprecated
* @description
* @enum
* @event
* @example
* @exports
* @external
* @file
* @fires
* @function
* @generator
* @global
* @hideconstructor
* @ignore
* @implements
* @inheritdoc
* @inheritDoc
* @inner
* @instance
* @interface
* @kind
* @lends
* @license
* @listens
* @member
* @memberof
* @memberof!
* @mixes
* @mixin
* @module
* @name
* @namespace
* @override
* @package
* @param
* @private
* @property
* @protected
* @public
* @readonly
* @requires
* @returns
* @see
* @since
* @static
* @summary
* @this
* @throws
* @todo
* @tutorial
* @type
* @typedef
* @variation
* @version
* @yields
*/
function quux (foo) {}
// Settings: {"jsdoc":{"mode":"badMode"}}
// Message: Unrecognized value `badMode` for `settings.jsdoc.mode`.
/**
* @modifies
* @abstract
* @access
* @alias
* @async
* @augments
* @author
* @borrows
* @callback
* @class
* @classdesc
* @constant
* @constructs
* @copyright
* @default
* @deprecated
* @description
* @enum
* @event
* @example
* @exports
* @external
* @file
* @fires
* @function
* @generator
* @global
* @hideconstructor
* @ignore
* @implements
* @inheritdoc
* @inheritDoc
* @inner
* @instance
* @interface
* @kind
* @lends
* @license
* @listens
* @member
* @memberof
* @memberof!
* @mixes
* @mixin
* @module
* @name
* @namespace
* @override
* @package
* @param
* @private
* @property
* @protected
* @public
* @readonly
* @requires
* @returns
* @see
* @since
* @static
* @summary
* @this
* @throws
* @todo
* @tutorial
* @type
* @typedef
* @variation
* @version
* @yields
* @template
*/
function quux (foo) {}
// Message: Invalid JSDoc tag name "template".
/**
* @externs
*/
function quux (foo) {}
// Message: Invalid JSDoc tag name "externs".
/** @jsx h */
/** @jsxFrag Fragment */
/** @jsxImportSource preact */
/** @jsxRuntime automatic */
// Message: Invalid JSDoc tag name "jsx".
The following patterns are not considered problems:
/**
* @param foo
*/
function quux (foo) {
}
/**
* @memberof! foo
*/
function quux (foo) {
}
/**
* @arg foo
*/
function quux (foo) {
}
// Settings: {"jsdoc":{"tagNamePreference":{"param":"arg"}}}
/**
* @parameter foo
*/
function quux (foo) {
}
// Settings: {"jsdoc":{"structuredTags":{"parameter":{"name":"namepath-referencing","required":["type","name"],"type":true}}}}
/**
* @bar foo
*/
function quux (foo) {
}
// "jsdoc/check-tag-names": ["error"|"warn", {"definedTags":["bar"]}]
/**
* @baz @bar foo
*/
function quux (foo) {
}
// "jsdoc/check-tag-names": ["error"|"warn", {"definedTags":["baz","bar"]}]
/**
* @baz @bar foo
*/
function quux (foo) {
}
// Settings: {"jsdoc":{"tagNamePreference":{"param":"baz","returns":{"message":"Prefer `bar`","replacement":"bar"},"todo":false}}}
/**
* @returns
*/
function quux (foo) {}
/**
* @return
*/
function quux (foo) {}
// Settings: {"jsdoc":{"mode":"closure"}}
/**
* @modifies
* @abstract
* @access
* @alias
* @async
* @augments
* @author
* @borrows
* @callback
* @class
* @classdesc
* @constant
* @constructs
* @copyright
* @default
* @deprecated
* @description
* @enum
* @event
* @example
* @exports
* @external
* @file
* @fires
* @function
* @generator
* @global
* @hideconstructor
* @ignore
* @implements
* @inheritdoc
* @inheritDoc
* @inner
* @instance
* @interface
* @kind
* @lends
* @license
* @listens
* @member
* @memberof
* @memberof!
* @mixes
* @mixin
* @module
* @name
* @namespace
* @override
* @package
* @param
* @private
* @property
* @protected
* @public
* @readonly
* @requires
* @returns
* @see
* @since
* @static
* @summary
* @this
* @throws
* @todo
* @tutorial
* @type
* @typedef
* @variation
* @version
* @yields
*/
function quux (foo) {}
/**
* @modifies
* @abstract
* @access
* @alias
* @async
* @augments
* @author
* @borrows
* @callback
* @class
* @classdesc
* @constant
* @constructs
* @copyright
* @default
* @deprecated
* @description
* @enum
* @event
* @example
* @exports
* @external
* @file
* @fires
* @function
* @generator
* @global
* @hideconstructor
* @ignore
* @implements
* @inheritdoc
* @inheritDoc
* @inner
* @instance
* @interface
* @kind
* @lends
* @license
* @listens
* @member
* @memberof
* @memberof!
* @mixes
* @mixin
* @module
* @name
* @namespace
* @override
* @package
* @param
* @private
* @property
* @protected
* @public
* @readonly
* @requires
* @returns
* @see
* @since
* @static
* @summary
* @this
* @throws
* @todo
* @tutorial
* @type
* @typedef
* @variation
* @version
* @yields
* @template
*/
function quux (foo) {}
// Settings: {"jsdoc":{"mode":"typescript"}}
/**
* @externs
*/
function quux (foo) {}
// Settings: {"jsdoc":{"mode":"closure"}}
/**
*
*/
function quux (foo) {
}
/**
* @todo
*/
function quux () {
}
/**
* @extends Foo
*/
function quux () {
}
// Settings: {"jsdoc":{"tagNamePreference":{"augments":{"message":"@extends is to be used over @augments.","replacement":"extends"}}}}
/**
* (Set tag name preference to itself to get aliases to
* work along with main tag name.)
* @augments Bar
* @extends Foo
*/
function quux () {
}
// Settings: {"jsdoc":{"tagNamePreference":{"extends":"extends"}}}
/**
* Registers the `target` class as a transient dependency; each time the dependency is resolved a new instance will be created.
*
* @param target - The class / constructor function to register as transient.
*
* @example ```ts
@transient()
class Foo { }
```
* @param Time for a new tag
*/
export function transient<T>(target?: T): T {
// ...
}
/** @jsx h */
/** @jsxFrag Fragment */
/** @jsxImportSource preact */
/** @jsxRuntime automatic */
// "jsdoc/check-tag-names": ["error"|"warn", {"jsxTags":true}]
Reports invalid types.
By default, ensures that the casing of native types is the same as in this list:
undefined
null
boolean
number
bigint
string
symbol
object
Array
Function
Date
RegExp
check-types
allows one option:
- An option object:
- with the key
noDefaults
to insist that only the supplied option type map is to be used, and that the default preferences (such as "string" over "String") will not be enforced. The option's default isfalse
. - with the key
exemptTagContexts
which will avoid reporting when a bad type is found on a specified tag. Set to an array of objects with a keytag
set to the tag to exempt, and atypes
key which can either betrue
to indicate that any types on that tag will be allowed, or to an array of strings which will only allow specific bad types. If an array of strings is given, these must match the type exactly, e.g., if you only allow"object"
, it will not allow"object<string, string>"
. Note that this is different from the behavior ofsettings.jsdoc.preferredTypes
. This option is useful for normally restricting generic types likeobject
withpreferredTypes
, but allowingtypedef
to indicate that its base type isobject
. - with the key
unifyParentAndChildTypeChecks
which will treatsettings.jsdoc.preferredTypes
keys such asSomeType
as matching not only child types such as an unadornedSomeType
but alsoSomeType<aChildType>
,SomeType.<aChildType>
, or ifSomeType
isArray
(or[]
), it will matchaChildType[]
. If this isfalse
or unset, the former format will only apply to types which are not parent types/unions whereas the latter formats will only apply for parent types/unions. The special types[]
,.<>
(or.
), and<>
act only as parent types (and will not match a bare child type such asArray
even when unified, though, as mentioned,Array
will match saystring[]
orArray.<string>
when unified). The special type*
is only a child type. Note that there is no detection of parent and child type together, e.g., you cannot specify preferences forstring[]
specifically as distinct from saynumber[]
, but you can target both with[]
or the child typesnumber
orstring
.
- with the key
If a value is present both as a key and as a value, neither the key nor the
value will be reported. Thus one can use this fact to allow both object
and Object
, for example. Note that in "typescript" mode, this is the default
behavior.
See also the documentation on settings.jsdoc.preferredTypes
which impacts
the behavior of check-types
.
Note that if there is an error parsing
types for a tag, the function will silently ignore that tag, leaving it to
the valid-types
rule to report parsing errors.
Why are boolean
, number
and string
exempt from starting with a capital
letter? Let's take string
as an example. In Javascript, everything is an
object. The string Object has prototypes for string functions such as
.toUpperCase()
.
Fortunately we don't have to write new String()
everywhere in our code.
Javascript will automatically wrap string primitives into string Objects when
we're applying a string function to a string primitive. This way the memory
footprint is a tiny little bit smaller, and the
GC has
less work to do.
So in a sense, there are two types of strings in Javascript:
-
{string}
literals, also called primitives -
{String}
Objects.
We use the primitives because it's easier to write and uses less memory.
{String}
and {string}
are technically both valid, but they are not the same.
new String('lard') // String {0: "l", 1: "a", 2: "r", 3: "d", length: 4}
'lard' // "lard"
new String('lard') === 'lard' // false
To make things more confusing, there are also object literals and object Objects. But object literals are still static Objects and object Objects are instantiated Objects. So an object primitive is still an object Object.
However, Object.create(null)
objects are not instanceof Object
, however, so
in the case of this Object we lower-case to indicate possible support for
these objects.
Basically, for primitives, we want to define the type as a primitive, because
that's what we use in 99.9% of cases. For everything else, we use the type
rather than the primitive. Otherwise it would all just be {object}
.
In short: It's not about consistency, rather about the 99.9% use case. (And some functions might not even support the objects if they are checking for identity.)
type name | typeof |
check-types | testcase |
---|---|---|---|
Array | object | Array |
([]) instanceof Array -> true
|
Function | function | Function |
(function f () {}) instanceof Function -> true
|
Date | object | Date |
(new Date()) instanceof Date -> true
|
RegExp | object | RegExp |
(new RegExp(/.+/)) instanceof RegExp -> true
|
Object | object | object |
({}) instanceof Object -> true but Object.create(null) instanceof Object -> false
|
Boolean | boolean | boolean |
(true) instanceof Boolean -> false
|
Number | number | number |
(41) instanceof Number -> false
|
String | string | string |
("test") instanceof String -> false
|
If you define your own tags and don't wish their bracketed portions checked
for types, you can use settings.jsdoc.structuredTags
with a tag type
of
false
. If you set their type
to an array, only those values will be
permitted.
Context | everywhere |
Tags |
augments , class , constant , enum , implements , member , module , namespace , param , property , returns , throws , type , typedef , yields
|
Aliases |
constructor , const , extends , var , arg , argument , prop , return , exception , yield
|
Closure-only |
package , private , protected , public , static
|
Recommended | true |
Options |
noDefaults , exemptTagContexts , unifyParentAndChildTypeChecks
|
Settings |
preferredTypes , mode , structuredTags
|
The following patterns are considered problems:
/**
* @param {abc} foo
*/
function quux (foo) {
}
// Settings: {"jsdoc":{"preferredTypes":{"abc":100}}}
// Message: Invalid `settings.jsdoc.preferredTypes`. Values must be falsy, a string, or an object.
/**
* @param {Number} foo
*/
function quux (foo) {
}
// Message: Invalid JSDoc @param "foo" type "Number"; prefer: "number".
/**
* @arg {Number} foo
*/
function quux (foo) {
}
// Message: Invalid JSDoc @arg "foo" type "Number"; prefer: "number".
/**
* @returns {Number} foo
* @throws {Number} foo
*/
function quux () {
}
// Message: Invalid JSDoc @returns type "Number"; prefer: "number".
/**
* @param {(Number | string | Boolean)=} foo
*/
function quux (foo, bar, baz) {
}
// Message: Invalid JSDoc @param "foo" type "Number"; prefer: "number".
/**
* @param {Array.<Number | String>} foo
*/
function quux (foo, bar, baz) {
}
// Message: Invalid JSDoc @param "foo" type "Number"; prefer: "number".
/**
* @param {(Number | String)[]} foo
*/
function quux (foo, bar, baz) {
}
// Message: Invalid JSDoc @param "foo" type "Number"; prefer: "number".
/**
* @param {abc} foo
*/
function qux(foo) {
}
// Settings: {"jsdoc":{"preferredTypes":{"abc":"Abc","string":"Str"}}}
// Message: Invalid JSDoc @param "foo" type "abc"; prefer: "Abc".
/**
* @param {abc} foo
*/
function qux(foo) {
}
// Settings: {"jsdoc":{"preferredTypes":{"abc":{"replacement":"Abc"},"string":"Str"}}}
// Message: Invalid JSDoc @param "foo" type "abc"; prefer: "Abc".
/**
* @param {abc} foo
*/
function qux(foo) {
}
// Settings: {"jsdoc":{"preferredTypes":{"abc":{"message":"Messed up JSDoc @{{tagName}}{{tagValue}} type \"abc\"; prefer: \"Abc\".","replacement":"Abc"},"string":"Str"}}}
// Message: Messed up JSDoc @param "foo" type "abc"; prefer: "Abc".
/**
* @param {abc} foo
* @param {cde} bar
* @param {object} baz
*/
function qux(foo, bar, baz) {
}
// Settings: {"jsdoc":{"preferredTypes":{"abc":{"message":"Messed up JSDoc @{{tagName}}{{tagValue}} type \"abc\"; prefer: \"Abc\".","replacement":"Abc"},"cde":{"message":"More messed up JSDoc @{{tagName}}{{tagValue}} type \"cde\"; prefer: \"Cde\".","replacement":"Cde"},"object":"Object"}}}
// Message: Messed up JSDoc @param "foo" type "abc"; prefer: "Abc".
/**
* @param {abc} foo
*/
function qux(foo) {
}
// Settings: {"jsdoc":{"preferredTypes":{"abc":{"message":"Messed up JSDoc @{{tagName}}{{tagValue}} type \"abc\".","replacement":false},"string":"Str"}}}
// Message: Messed up JSDoc @param "foo" type "abc".
/**
* @param {abc} foo
*/
function qux(foo) {
}
// Settings: {"jsdoc":{"preferredTypes":{"abc":{"message":"Messed up JSDoc @{{tagName}}{{tagValue}} type \"abc\"."},"string":"Str"}}}
// Message: Messed up JSDoc @param "foo" type "abc".
/**
* @param {abc} foo
* @param {Number} bar
*/
function qux(foo, bar) {
}
// Settings: {"jsdoc":{"preferredTypes":{"abc":"Abc","string":"Str"}}}
// "jsdoc/check-types": ["error"|"warn", {"noDefaults":true}]
// Message: Invalid JSDoc @param "foo" type "abc"; prefer: "Abc".
/**
* @param {abc} foo
* @param {Number} bar
*/
function qux(foo, bar) {
}
// Settings: {"jsdoc":{"preferredTypes":{"abc":"Abc","string":"Str"}}}
// Message: Invalid JSDoc @param "foo" type "abc"; prefer: "Abc".
/**
* @param {abc} foo
*/
function qux(foo) {
}
// Settings: {"jsdoc":{"preferredTypes":{"abc":false,"string":"Str"}}}
// Message: Invalid JSDoc @param "foo" type "abc".
/**
* @param {abc} foo
*/
function qux(foo) {
}
// Settings: {"jsdoc":{"preferredTypes":{"abc":false}}}
// Message: Invalid JSDoc @param "foo" type "abc".
/**
* @param {*} baz
*/
function qux(baz) {
}
// Settings: {"jsdoc":{"preferredTypes":{"*":false,"abc":"Abc","string":"Str"}}}
// Message: Invalid JSDoc @param "baz" type "*".
/**
* @param {*} baz
*/
function qux(baz) {
}
// Settings: {"jsdoc":{"preferredTypes":{"*":"aaa","abc":"Abc","string":"Str"}}}
// Message: Invalid JSDoc @param "baz" type "*"; prefer: "aaa".
/**
* @param {abc} foo
* @param {Number} bar
*/
function qux(foo, bar) {
}
// Settings: {"jsdoc":{"preferredTypes":{"abc":"Abc","string":"Str"}}}
// Message: Invalid JSDoc @param "foo" type "abc"; prefer: "Abc".
/**
* @param {Array} foo
*/
function quux (foo) {
}
// Settings: {"jsdoc":{"preferredTypes":{"Array":"GenericArray"}}}
// Message: Invalid JSDoc @param "foo" type "Array"; prefer: "GenericArray".
/**
* @param {Array} foo
*/
function quux (foo) {
}
// Settings: {"jsdoc":{"preferredTypes":{"Array":"GenericArray","Array.<>":"GenericArray"}}}
// Message: Invalid JSDoc @param "foo" type "Array"; prefer: "GenericArray".
/**
* @param {Array.<string>} foo
*/
function quux (foo) {
}
// Settings: {"jsdoc":{"preferredTypes":{"Array.<>":"GenericArray"}}}
// Message: Invalid JSDoc @param "foo" type "Array"; prefer: "GenericArray".
/**
* @param {Array<string>} foo
*/
function quux (foo) {
}
// Settings: {"jsdoc":{"preferredTypes":{"Array<>":"GenericArray"}}}
// Message: Invalid JSDoc @param "foo" type "Array"; prefer: "GenericArray".
/**
* @param {string[]} foo
*/
function quux (foo) {
}
// Settings: {"jsdoc":{"preferredTypes":{"[]":"SpecialTypeArray"}}}
// Message: Invalid JSDoc @param "foo" type "[]"; prefer: "SpecialTypeArray".
/**
* @param {string[]} foo
*/
function quux (foo) {
}
// Settings: {"jsdoc":{"preferredTypes":{"[]":"SpecialTypeArray"}}}
// "jsdoc/check-types": ["error"|"warn", {"unifyParentAndChildTypeChecks":true}]
// Message: Invalid JSDoc @param "foo" type "[]"; prefer: "SpecialTypeArray".
/**
* @param {string[]} foo
*/
function quux (foo) {
}
// Settings: {"jsdoc":{"preferredTypes":{"Array":"SpecialTypeArray"}}}
// "jsdoc/check-types": ["error"|"warn", {"unifyParentAndChildTypeChecks":true}]
// Message: Invalid JSDoc @param "foo" type "Array"; prefer: "SpecialTypeArray".
/**
* @param {object} foo
*/
function quux (foo) {
}
// Settings: {"jsdoc":{"preferredTypes":{"object":"GenericObject"}}}
// Message: Invalid JSDoc @param "foo" type "object"; prefer: "GenericObject".
/**
* @param {object} foo
*/
function quux (foo) {
}
// Settings: {"jsdoc":{"preferredTypes":{"object":"GenericObject","object.<>":"GenericObject"}}}
// Message: Invalid JSDoc @param "foo" type "object"; prefer: "GenericObject".
/**
* @param {object} foo
*/
function quux (foo) {
}
// Settings: {"jsdoc":{"preferredTypes":{"object":"GenericObject","object<>":"GenericObject"}}}
// Message: Invalid JSDoc @param "foo" type "object"; prefer: "GenericObject".
/**
* @param {object.<string>} foo
*/
function quux (foo) {
}
// Settings: {"jsdoc":{"preferredTypes":{"object.<>":"GenericObject"}}}
// Message: Invalid JSDoc @param "foo" type "object"; prefer: "GenericObject".
/**
* @param {object<string>} foo
*/
function quux (foo) {
}
// Settings: {"jsdoc":{"preferredTypes":{"object<>":"GenericObject"}}}
// Message: Invalid JSDoc @param "foo" type "object"; prefer: "GenericObject".
/**
* @param {object.<string, number>} foo
*/
function quux (foo) {
}
// Settings: {"jsdoc":{"preferredTypes":{"object.<>":"GenericObject"}}}
// Message: Invalid JSDoc @param "foo" type "object"; prefer: "GenericObject".
/**
* @param {object<string, number>} foo
*/
function quux (foo) {
}
// Settings: {"jsdoc":{"preferredTypes":{"object<>":"GenericObject"}}}
// Message: Invalid JSDoc @param "foo" type "object"; prefer: "GenericObject".
/**
* @param {object.<string>} foo
*/
function quux (foo) {
}
// Settings: {"jsdoc":{"preferredTypes":{"object":"GenericObject"}}}
// "jsdoc/check-types": ["error"|"warn", {"unifyParentAndChildTypeChecks":true}]
// Message: Invalid JSDoc @param "foo" type "object"; prefer: "GenericObject".
/**
* @param {object<string>} foo
*/
function quux (foo) {
}
// Settings: {"jsdoc":{"preferredTypes":{"object":"GenericObject"}}}
// "jsdoc/check-types": ["error"|"warn", {"unifyParentAndChildTypeChecks":true}]
// Message: Invalid JSDoc @param "foo" type "object"; prefer: "GenericObject".
/**
* @param {object} foo
*/
function quux (foo) {
}
// Settings: {"jsdoc":{"preferredTypes":{"object":"GenericObject"}}}
// "jsdoc/check-types": ["error"|"warn", {"unifyParentAndChildTypeChecks":true}]
// Message: Invalid JSDoc @param "foo" type "object"; prefer: "GenericObject".
/**
* @param {object} foo
*/
function quux (foo) {
}
// Settings: {"jsdoc":{"preferredTypes":{"object":false}}}
// "jsdoc/check-types": ["error"|"warn", {"unifyParentAndChildTypeChecks":true}]
// Message: Invalid JSDoc @param "foo" type "object".
/**
* @param {object} foo
*/
function quux (foo) {
}
// Settings: {"jsdoc":{"preferredTypes":{"object":false}}}
// Message: Invalid JSDoc @param "foo" type "object".
/**
* @param {object.<string, number>} foo
*/
function quux (foo) {
}
// Settings: {"jsdoc":{"preferredTypes":{"object":"GenericObject"}}}
// "jsdoc/check-types": ["error"|"warn", {"unifyParentAndChildTypeChecks":true}]
// Message: Invalid JSDoc @param "foo" type "object"; prefer: "GenericObject".
/**
* @param {object<string, number>} foo
*/
function quux (foo) {
}
// Settings: {"jsdoc":{"preferredTypes":{"object":"GenericObject"}}}
// "jsdoc/check-types": ["error"|"warn", {"unifyParentAndChildTypeChecks":true}]
// Message: Invalid JSDoc @param "foo" type "object"; prefer: "GenericObject".
/**
*
* @param {string[][]} foo
*/
function quux (foo) {
}
// Settings: {"jsdoc":{"preferredTypes":{"[]":"Array."}}}
// Message: Invalid JSDoc @param "foo" type "[]"; prefer: "Array.".
/**
*
* @param {string[][]} foo
*/
function quux (foo) {
}
// Settings: {"jsdoc":{"preferredTypes":{"[]":"Array.<>"}}}
// Message: Invalid JSDoc @param "foo" type "[]"; prefer: "Array.<>".
/**
*
* @param {string[][]} foo
*/
function quux (foo) {
}
// Settings: {"jsdoc":{"preferredTypes":{"[]":"Array<>"}}}
// Message: Invalid JSDoc @param "foo" type "[]"; prefer: "Array<>".
/**
*
* @param {object.<string, object.<string, string>>} foo
*/
function quux (foo) {
}
// Settings: {"jsdoc":{"preferredTypes":{"object.":"Object"}}}
// Message: Invalid JSDoc @param "foo" type "object"; prefer: "Object".
/**
*
* @param {object.<string, object.<string, string>>} foo
*/
function quux (foo) {
}
// Settings: {"jsdoc":{"preferredTypes":{"object.":"Object<>"}}}
// Message: Invalid JSDoc @param "foo" type "object"; prefer: "Object<>".
/**
*
* @param {object<string, object<string, string>>} foo
*/
function quux (foo) {
}
// Settings: {"jsdoc":{"preferredTypes":{"object<>":"Object."}}}
// Message: Invalid JSDoc @param "foo" type "object"; prefer: "Object.".
/**
*
* @param {Array.<Array.<string>>} foo
*/
function quux (foo) {
}
// Settings: {"jsdoc":{"preferredTypes":{"Array.":"[]"}}}
// Message: Invalid JSDoc @param "foo" type "Array"; prefer: "[]".
/**
*
* @param {Array.<Array.<string>>} foo
*/
function quux (foo) {
}
// Settings: {"jsdoc":{"preferredTypes":{"Array.":"Array<>"}}}
// Message: Invalid JSDoc @param "foo" type "Array"; prefer: "Array<>".
/**
*
* @param {Array.<Array.<string>>} foo
*/
function quux (foo) {
}
// Settings: {"jsdoc":{"preferredTypes":{"Array.":"<>"}}}
// Message: Invalid JSDoc @param "foo" type "Array"; prefer: "<>".
/**
*
* @param {Array.<MyArray.<string>>} foo
*/
function quux (foo) {
}
// Settings: {"jsdoc":{"preferredTypes":{"Array.":"<>"}}}
// Message: Invalid JSDoc @param "foo" type "Array"; prefer: "<>".
/**
*
* @param {Array.<MyArray.<string>>} foo
*/
function quux (foo) {
}
// Settings: {"jsdoc":{"preferredTypes":{"MyArray.":"<>"}}}
// Message: Invalid JSDoc @param "foo" type "MyArray"; prefer: "<>".
/**
*
* @param {Array<Array<string>>} foo
*/
function quux (foo) {
}
// Settings: {"jsdoc":{"preferredTypes":{"<>":"Array."}}}
// Message: Invalid JSDoc @param "foo" type "Array"; prefer: "Array.".
/**
*
* @param {Array<Array<string>>} foo
*/
function quux (foo) {
}
// Settings: {"jsdoc":{"preferredTypes":{"Array":"Array."}}}
// "jsdoc/check-types": ["error"|"warn", {"unifyParentAndChildTypeChecks":true}]
// Message: Invalid JSDoc @param "foo" type "Array"; prefer: "Array.".
/**
*
* @param {Array<Array<string>>} foo
*/
function quux (foo) {
}
// Settings: {"jsdoc":{"preferredTypes":{"<>":"[]"}}}
// Message: Invalid JSDoc @param "foo" type "Array"; prefer: "[]".
/** @typedef {String} foo */
// Message: Invalid JSDoc @typedef "foo" type "String"; prefer: "string".
/**
* @this {array}
*/
function quux () {}
// Settings: {"jsdoc":{"mode":"closure"}}
// Message: Invalid JSDoc @this type "array"; prefer: "Array".
/**
* @export {array}
*/
function quux () {}
// Settings: {"jsdoc":{"mode":"closure"}}
// Message: Invalid JSDoc @export type "array"; prefer: "Array".
/**
* @typedef {object} foo
* @property {object} bar
*/
// Settings: {"jsdoc":{"preferredTypes":{"object":"Object"}}}
// "jsdoc/check-types": ["error"|"warn", {"exemptTagContexts":[{"tag":"typedef","types":true}]}]
// Message: Invalid JSDoc @property "bar" type "object"; prefer: "Object".
/** @typedef {object} foo */
// Settings: {"jsdoc":{"preferredTypes":{"object":"Object"}}}
// "jsdoc/check-types": ["error"|"warn", {"exemptTagContexts":[{"tag":"typedef","types":["array"]}]}]
// Message: Invalid JSDoc @typedef "foo" type "object"; prefer: "Object".
/**
* @typedef {object} foo
* @property {object} bar
*/
// Settings: {"jsdoc":{"preferredTypes":{"object":"Object"}}}
// "jsdoc/check-types": ["error"|"warn", {"exemptTagContexts":[{"tag":"typedef","types":["object"]}]}]
// Message: Invalid JSDoc @property "bar" type "object"; prefer: "Object".
/** @typedef {object<string, string>} foo */
// Settings: {"jsdoc":{"preferredTypes":{"object<>":"Object<>"}}}
// "jsdoc/check-types": ["error"|"warn", {"exemptTagContexts":[{"tag":"typedef","types":["object"]}]}]
// Message: Invalid JSDoc @typedef "foo" type "object"; prefer: "Object<>".
/**
* @param {Array<number | undefined>} foo
*/
function quux (foo) {
}
// Settings: {"jsdoc":{"preferredTypes":{"Array.<>":"[]","Array<>":"[]"}}}
// Message: Invalid JSDoc @param "foo" type "Array"; prefer: "[]".
/**
* @typedef {object} foo
*/
function a () {}
/**
* @typedef {Object} foo
*/
function b () {}
// Settings: {"jsdoc":{"mode":"typescript","preferredTypes":{"object":"Object"}}}
// Message: Invalid JSDoc @typedef "foo" type "object"; prefer: "Object".
/**
* @aCustomTag {Number} foo
*/
// Settings: {"jsdoc":{"structuredTags":{"aCustomTag":{"type":true}}}}
// Message: Invalid JSDoc @aCustomTag "foo" type "Number"; prefer: "number".
/**
* @aCustomTag {Number} foo
*/
// Settings: {"jsdoc":{"structuredTags":{"aCustomTag":{"type":["otherType","anotherType"]}}}}
// Message: Invalid JSDoc @aCustomTag "foo" type "Number"; prefer: ["otherType","anotherType"].
The following patterns are not considered problems:
/**
* @param {number} foo
* @param {Bar} bar
* @param {*} baz
*/
function quux (foo, bar, baz) {
}
/**
* @arg {number} foo
* @arg {Bar} bar
* @arg {*} baz
*/
function quux (foo, bar, baz) {
}
/**
* @param {(number | string | boolean)=} foo
*/
function quux (foo, bar, baz) {
}
/**
* @param {typeof bar} foo
*/
function qux(foo) {
}
/**
* @param {import('./foo').bar.baz} foo
*/
function qux(foo) {
}
/**
* @param {(x: number, y: string) => string} foo
*/
function qux(foo) {
}
/**
* @param {() => string} foo
*/
function qux(foo) {
}
/**
* @returns {Number} foo
* @throws {Number} foo
*/
function quux () {
}
// "jsdoc/check-types": ["error"|"warn", {"noDefaults":true}]
/**
* @param {Object} foo
*/
function quux (foo) {
}
// Settings: {"jsdoc":{"preferredTypes":{"object":"Object"}}}
/**
* @param {Array} foo
*/
function quux (foo) {
}
/**
* @param {Array.<string>} foo
*/
function quux (foo) {
}
// Settings: {"jsdoc":{"preferredTypes":{"Array":"GenericArray"}}}
/**
* @param {Array<string>} foo
*/
function quux (foo) {
}
// Settings: {"jsdoc":{"preferredTypes":{"Array":"GenericArray"}}}
/**
* @param {string[]} foo
*/
function quux (foo) {
}
// Settings: {"jsdoc":{"preferredTypes":{"Array":"SpecialTypeArray","Array.<>":"SpecialTypeArray","Array<>":"SpecialTypeArray"}}}
/**
* @param {string[]} foo
*/
function quux (foo) {
}
// Settings: {"jsdoc":{"preferredTypes":{"Array.<>":"SpecialTypeArray","Array<>":"SpecialTypeArray"}}}
// "jsdoc/check-types": ["error"|"warn", {"unifyParentAndChildTypeChecks":true}]
/**
* @param {Array} foo
*/
function quux (foo) {
}
// Settings: {"jsdoc":{"preferredTypes":{"[]":"SpecialTypeArray"}}}
/**
* @param {Array} foo
*/
function quux (foo) {
}
// Settings: {"jsdoc":{"preferredTypes":{"[]":"SpecialTypeArray"}}}
// "jsdoc/check-types": ["error"|"warn", {"unifyParentAndChildTypeChecks":true}]
/**
* @param {Array} foo
*/
function quux (foo) {
}
// Settings: {"jsdoc":{"preferredTypes":{"Array.<>":"GenericArray"}}}
/**
* @param {Array} foo
*/
function quux (foo) {
}
// Settings: {"jsdoc":{"preferredTypes":{"Array<>":"GenericArray"}}}
/**
* @param {object} foo
*/
function quux (foo) {
}
/**
* @param {object.<string>} foo
*/
function quux (foo) {
}
// Settings: {"jsdoc":{"preferredTypes":{"object":"GenericObject"}}}
/**
* @param {object<string>} foo
*/
function quux (foo) {
}
// Settings: {"jsdoc":{"preferredTypes":{"object":"GenericObject"}}}
/**
* @param {object.<string, number>} foo
*/
function quux (foo) {
}
// Settings: {"jsdoc":{"preferredTypes":{"object":"GenericObject"}}}
/**
* @param {object<string, number>} foo
*/
function quux (foo) {
}
// Settings: {"jsdoc":{"preferredTypes":{"object":"GenericObject"}}}
/**
* @param {object} foo
*/
function quux (foo) {
}
// Settings: {"jsdoc":{"preferredTypes":{"object.<>":"GenericObject"}}}
/**
* @param {object} foo
*/
function quux (foo) {
}
// Settings: {"jsdoc":{"preferredTypes":{"object<>":"GenericObject"}}}
/**
* @param {Number<} Ignore the error as not a validating rule
*/
function quux (foo) {
}
/** @param {function(...)} callback The function to invoke. */
var subscribe = function(callback) {};
/**
* @this {Array}
*/
function quux () {}
// Settings: {"jsdoc":{"mode":"closure"}}
/**
* @export {Array}
*/
function quux () {}
// Settings: {"jsdoc":{"mode":"closure"}}
/** @type {new() => EntityBase} */
/** @typedef {object} foo */
// Settings: {"jsdoc":{"preferredTypes":{"object":"Object"}}}
// "jsdoc/check-types": ["error"|"warn", {"exemptTagContexts":[{"tag":"typedef","types":true}]}]
/** @typedef {object<string, string>} foo */
// Settings: {"jsdoc":{"preferredTypes":{"object":"Object"}}}
/** @typedef {object<string, string>} foo */
// Settings: {"jsdoc":{"preferredTypes":{"object<>":"Object<>"}}}
// "jsdoc/check-types": ["error"|"warn", {"exemptTagContexts":[{"tag":"typedef","types":["object<string, string>"]}]}]
/**
* @typedef {object} foo
*/
/**
* @typedef {Object} foo
*/
// Settings: {"jsdoc":{"preferredTypes":{"object":"Object","Object":"object"}}}
/**
* @typedef {object} foo
*/
function a () {}
/**
* @typedef {Object} foo
*/
function b () {}
// Settings: {"jsdoc":{"preferredTypes":{"object":"Object","Object":"object"}}}
/**
* @typedef {object} foo
*/
function a () {}
/**
* @typedef {Object} foo
*/
function b () {}
// Settings: {"jsdoc":{"mode":"typescript"}}
/**
* @aCustomTag {Number} foo
*/
// Settings: {"jsdoc":{"structuredTags":{"aCustomTag":{"type":false}}}}
/**
* @aCustomTag {otherType} foo
*/
// Settings: {"jsdoc":{"structuredTags":{"aCustomTag":{"type":["otherType","anotherType"]}}}}
/**
* @aCustomTag {anotherType|otherType} foo
*/
// Settings: {"jsdoc":{"structuredTags":{"aCustomTag":{"type":["otherType","anotherType"]}}}}
/**
* Bad types handled by `valid-types` instead.
* @param {str(} foo
*/
function quux (foo) {
}
This rule checks the values for a handful of tags:
-
@version
- Checks that there is a present and valid semver version value. -
@since
- As with@version
-
@license
- Checks that there is a present and valid SPDX identifier or is present within anallowedLicenses
option. -
@author
- Checks that there is a value present, and if the optionallowedAuthors
is present, ensure that the author value is one of these array items. -
@variation
- IfnumericOnlyVariation
is set, will checks that there is a value present, and that it is an integer (otherwise, jsdoc allows any value).
An array of allowable author values. If absent, only non-whitespace will be checked for.
An array of allowable license values or true
to allow any license text.
If present as an array, will be used in place of SPDX identifiers.
A string to be converted into a RegExp
(with u
flag) and whose first
parenthetical grouping, if present, will match the portion of the license
description to check (if no grouping is present, then the whole portion
matched will be used). Defaults to /([^\n\r]*)/gu
, i.e., the SPDX expression
is expected before any line breaks.
Note that the /
delimiters are optional, but necessary to add flags.
Defaults to using the u
flag, so to add your own flags, encapsulate
your expression as a string, but like a literal, e.g., /^mit$/ui
.
Whether to enable validation that @variation
must be a number. Defaults to
false
.
Context | everywhere |
Tags |
@version , @since , @license , @author , @variation
|
Recommended | true |
Options |
allowedAuthors , allowedLicenses , licensePattern
|
Settings | tagNamePreference |
The following patterns are considered problems:
/**
* @version
*/
function quux (foo) {
}
// Message: Missing JSDoc @version value.
/**
* @version 3.1
*/
function quux (foo) {
}
// Message: Invalid JSDoc @version: "3.1".
/**
* @variation -3
*/
function quux (foo) {
}
// "jsdoc/check-values": ["error"|"warn", {"numericOnlyVariation":true}]
// Message: Invalid JSDoc @variation: "-3".
/**
* @since
*/
function quux (foo) {
}
// Message: Missing JSDoc @since value.
/**
* @since 3.1
*/
function quux (foo) {
}
// Message: Invalid JSDoc @since: "3.1".
/**
* @license
*/
function quux (foo) {
}
// Message: Missing JSDoc @license value.
/**
* @license FOO
*/
function quux (foo) {
}
// Message: Invalid JSDoc @license: "FOO"; expected SPDX expression: https://spdx.org/licenses/.
/**
* @license FOO
*/
function quux (foo) {
}
// "jsdoc/check-values": ["error"|"warn", {"allowedLicenses":["BAR","BAX"]}]
// Message: Invalid JSDoc @license: "FOO"; expected one of BAR, BAX.
/**
* @license MIT-7
* Some extra text...
*/
function quux (foo) {
}
// Message: Invalid JSDoc @license: "MIT-7"; expected SPDX expression: https://spdx.org/licenses/.
/**
* @license (MIT OR GPL-2.5)
*/
function quux (foo) {
}
// Message: Invalid JSDoc @license: "(MIT OR GPL-2.5)"; expected SPDX expression: https://spdx.org/licenses/.
/**
* @license MIT
* Some extra text
*/
function quux (foo) {
}
// "jsdoc/check-values": ["error"|"warn", {"licensePattern":"[\\s\\S]*"}]
// Message: Invalid JSDoc @license: "MIT
Some extra text"; expected SPDX expression: https://spdx.org/licenses/.
/**
* @author
*/
function quux (foo) {
}
// Message: Missing JSDoc @author value.
/**
* @author Brett Zamir
*/
function quux (foo) {
}
// "jsdoc/check-values": ["error"|"warn", {"allowedAuthors":["Gajus Kuizinas","golopot"]}]
// Message: Invalid JSDoc @author: "Brett Zamir"; expected one of Gajus Kuizinas, golopot.
/**
* @variation
*/
function quux (foo) {
}
// "jsdoc/check-values": ["error"|"warn", {"numericOnlyVariation":true}]
// Message: Missing JSDoc @variation value.
/**
* @variation 5.2
*/
function quux (foo) {
}
// "jsdoc/check-values": ["error"|"warn", {"numericOnlyVariation":true}]
// Message: Invalid JSDoc @variation: "5.2".
The following patterns are not considered problems:
/**
* @version 3.4.1
*/
function quux (foo) {
}
/**
* @version 3.4.1
*/
function quux (foo) {
}
/**
* @since 3.4.1
*/
function quux (foo) {
}
/**
* @since 3.4.1
*/
function quux (foo) {
}
/**
* @license MIT
*/
function quux (foo) {
}
/**
* @license MIT
* Some extra text...
*/
function quux (foo) {
}
/**
* @license (MIT OR GPL-2.0)
*/
function quux (foo) {
}
/**
* @license FOO
*/
function quux (foo) {
}
// "jsdoc/check-values": ["error"|"warn", {"allowedLicenses":["FOO","BAR","BAX"]}]
/**
* @license FOO
*/
function quux (foo) {
}
// "jsdoc/check-values": ["error"|"warn", {"allowedLicenses":true}]
/**
* @license MIT
* Some extra text
*/
function quux (foo) {
}
// "jsdoc/check-values": ["error"|"warn", {"licensePattern":"[^\n]*"}]
/**
* @author Gajus Kuizinas
*/
function quux (foo) {
}
/**
* @author Brett Zamir
*/
function quux (foo) {
}
// "jsdoc/check-values": ["error"|"warn", {"allowedAuthors":["Gajus Kuizinas","golopot","Brett Zamir"]}]
/**
* @variation 3
*/
function quux (foo) {
}
// "jsdoc/check-values": ["error"|"warn", {"numericOnlyVariation":true}]
/**
* @variation abc
*/
function quux (foo) {
}
/**
* @module test
* @license MIT
*/
'use strict';
Expects the following tags to be empty of any content:
@abstract
@async
@generator
@global
@hideconstructor
@ignore
@inheritdoc
@inner
@instance
-
@internal
(used by TypeScript) @override
@readonly
The following will also be expected to be empty unless settings.jsdoc.mode
is set to "closure" (which allows types).
@package
@private
@protected
@public
@static
Note that @private
will still be checked for content by this rule even with
settings.jsdoc.ignorePrivate
set to true
(a setting which normally
causes rules not to take effect).
Similarly, @internal
will still be checked for content by this rule even with
settings.jsdoc.ignoreInternal
set to true
.
If you want additional tags to be checked for their descriptions, you may add them within this option.
{
'jsdoc/empty-tags': ['error', {tags: ['event']}]
}
Context | everywhere |
Tags |
abstract , async , generator , global , hideconstructor , ignore , inheritdoc , inner , instance , internal , override , readonly , package , private , protected , public , static and others added by tags
|
Recommended | true |
Options | tags |
The following patterns are considered problems: |
/**
* @abstract extra text
*/
function quux () {
}
// Message: @abstract should be empty.
class Test {
/**
* @abstract extra text
*/
quux () {
}
}
// Message: @abstract should be empty.
/**
* @abstract extra text
* @inheritdoc
* @async out of place
*/
function quux () {
}
// Message: @abstract should be empty.
/**
* @event anEvent
*/
function quux () {
}
// "jsdoc/empty-tags": ["error"|"warn", {"tags":["event"]}]
// Message: @event should be empty.
/**
* @private {someType}
*/
function quux () {
}
// Message: @private should be empty.
/**
* @internal {someType}
*/
function quux () {
}
// Message: @internal should be empty.
/**
* @private {someType}
*/
function quux () {
}
// Settings: {"jsdoc":{"ignorePrivate":true}}
// Message: @private should be empty.
The following patterns are not considered problems:
/**
* @abstract
*/
function quux () {
}
/**
*
*/
function quux () {
}
/**
* @param aName
*/
function quux () {
}
/**
* @abstract
* @inheritdoc
* @async
*/
function quux () {
}
/**
* @private {someType}
*/
function quux () {
}
// Settings: {"jsdoc":{"mode":"closure"}}
/**
* @private
*/
function quux () {
}
/**
* @internal
*/
function quux () {
}
/**
* Create an array.
*
* @private
*
* @param {string[]} [elem] - Elements to make an array of.
* @param {boolean} [clone] - Optionally clone nodes.
* @returns {string[]} The array of nodes.
*/
function quux () {}
Reports an issue with any non-constructor function using @implements
.
Constructor functions, whether marked with @class
, @constructs
, or being
an ES6 class constructor, will not be flagged.
To indicate that a function follows another function's signature, one might
instead use @type
to indicate the @function
or @callback
to which the
function is adhering.
Set this to an array of strings representing the AST context (or an object with
context
and comment
properties) where you wish the rule to be applied.
Overrides the default contexts (see below). Set to "any"
if you want
the rule to apply to any jsdoc block throughout your files (as is necessary
for finding function blocks not attached to a function declaration or
expression, i.e., @callback
or @function
(or its aliases @func
or
@method
) (including those associated with an @interface
).
See the "AST and Selectors" section of our README for more on the expected format.
Context |
ArrowFunctionExpression , FunctionDeclaration , FunctionExpression ; others when contexts option enabled |
Tags |
implements (prevented) |
Recommended | true |
Options | contexts |
The following patterns are considered problems:
/**
* @implements {SomeClass}
*/
function quux () {
}
// Message: @implements used on a non-constructor function
/**
* @implements {SomeClass}
*/
function quux () {
}
// "jsdoc/implements-on-classes": ["error"|"warn", {"contexts":["any"]}]
// Message: @implements used on a non-constructor function
/**
* @function
* @implements {SomeClass}
*/
function quux () {
}
// "jsdoc/implements-on-classes": ["error"|"warn", {"contexts":["any"]}]
// Message: @implements used on a non-constructor function
/**
* @callback
* @implements {SomeClass}
*/
// "jsdoc/implements-on-classes": ["error"|"warn", {"contexts":["any"]}]
// Message: @implements used on a non-constructor function
/**
* @implements {SomeClass}
*/
function quux () {
}
// Settings: {"jsdoc":{"tagNamePreference":{"implements":false}}}
// Message: Unexpected tag `@implements`
class Foo {
/**
* @implements {SomeClass}
*/
constructor() {}
/**
* @implements {SomeClass}
*/
bar() {}
}
// "jsdoc/implements-on-classes": ["error"|"warn", {"contexts":["MethodDefinition"]}]
// Message: @implements used on a non-constructor function
class Foo {
/**
* @implements {SomeClass}
*/
constructor() {}
/**
* @implements {SomeClass}
*/
bar() {}
}
// "jsdoc/implements-on-classes": ["error"|"warn", {"contexts":["any"]}]
// Message: @implements used on a non-constructor function
The following patterns are not considered problems:
/**
* @implements {SomeClass}
* @class
*/
function quux () {
}
/**
* @implements {SomeClass}
* @class
*/
function quux () {
}
// "jsdoc/implements-on-classes": ["error"|"warn", {"contexts":["any"]}]
/**
* @implements {SomeClass}
*/
// "jsdoc/implements-on-classes": ["error"|"warn", {"contexts":["any"]}]
/**
* @implements {SomeClass}
* @constructor
*/
function quux () {
}
/**
*
*/
class quux {
/**
* @implements {SomeClass}
*/
constructor () {
}
}
/**
*
*/
const quux = class {
/**
* @implements {SomeClass}
*/
constructor () {
}
}
/**
*
*/
function quux () {
}
/**
*
*/
function quux () {
}
// Settings: {"jsdoc":{"tagNamePreference":{"implements":false}}}
/**
* @function
* @implements {SomeClass}
*/
/**
* @callback
* @implements {SomeClass}
*/
Enforces a regular expression pattern on descriptions.
The default is this basic expression to match English sentences (Support for Unicode upper case may be added in a future version when it can be handled by our supported Node versions):
^([A-Z]|[`\\d_])[\\s\\S]*[.?!`]$
Applies to the jsdoc block description and @description
(or @desc
)
by default but the tags
option (see below) may be used to match other tags.
The default (and all regex options) defaults to using (only) the u
flag, so
to add your own flags, encapsulate your expression as a string, but like a
literal, e.g., /[A-Z].*\\./ui
.
Note that /
delimiters are optional, but necessary to add flags (besides
u
).
Also note that the default or optional regular expressions is not
case-insensitive unless one opts in to add the i
flag.
You can add the s
flag if you want .
to match newlines. Note, however,
that the trailing newlines of a description will not be matched.
You can supply your own expression to override the default, passing a
matchDescription
string on the options object.
{
'jsdoc/match-description': ['error', {matchDescription: '[A-Z].*\\.'}]
}
You may provide a custom default message by using the following format:
{
'jsdoc/match-description': ['error', {
message: 'The default dscription should begin with a capital letter.'
}]
}
This can be overridden per tag or for the main block description by setting
message
within tags
or mainDescription
, respectively.
If you want different regular expressions to apply to tags, you may use
the tags
option object:
{
'jsdoc/match-description': ['error', {tags: {
param: '\\- [A-Z].*\\.',
returns: '[A-Z].*\\.'
}}]
}
In place of a string, you can also add true
to indicate that a particular
tag should be linted with the matchDescription
value (or the default).
{
'jsdoc/match-description': ['error', {tags: {
param: true,
returns: true
}}]
}
Alternatively, you may supply an object with a message
property to indicate
the error message for that tag.
{
'jsdoc/match-description': ['error', {tags: {
param: {message: 'Begin with a hyphen', match: '\\- [A-Z].*\\.'},
returns: {message: 'Capitalize for returns (the default)', match: true}
}}]
}
The tags @param
/@arg
/@argument
and @property
/@prop
will be properly
parsed to ensure that the matched "description" text includes only the text
after the name.
All other tags will treat the text following the tag name, a space, and
an optional curly-bracketed type expression (and another space) as part of
its "description" (e.g., for @returns {someType} some description
, the
description is some description
while for @some-tag xyz
, the description
is xyz
).
If you wish to override the main block description without changing the
default match-description
(which can cascade to the tags
with true
),
you may use mainDescription
:
{
'jsdoc/match-description': ['error', {
mainDescription: '[A-Z].*\\.',
tags: {
param: true,
returns: true
}
}]
}
There is no need to add mainDescription: true
, as by default, the main
block description (and only the main block description) is linted, though you
may disable checking it by setting it to false
.
You may also provide an object with message
:
{
'jsdoc/match-description': ['error', {
mainDescription: {
message: 'Capitalize first word of JSDoc block descriptions',
match: '[A-Z].*\\.'
},
tags: {
param: true,
returns: true
}
}]
}
Set this to an array of strings representing the AST context (or an object with
context
and comment
properties) where you wish the rule to be applied.
(e.g., ClassDeclaration
for ES6
classes). Overrides the default contexts (see below). Set to "any"
if you
want the rule to apply to any jsdoc block throughout your files.
See the "AST and Selectors" section of our README for more on the expected format.
Context |
ArrowFunctionExpression , FunctionDeclaration , FunctionExpression ; others when contexts option enabled |
Tags | docblock and @description by default but more with tags
|
Aliases | @desc |
Recommended | false |
Settings | |
Options |
contexts , tags (accepts tags with names and optional type such as 'param', 'arg', 'argument', 'property', and 'prop', and accepts arbitrary list of other tags with an optional type (but without names), e.g., 'returns', 'return'), mainDescription , matchDescription
|
The following patterns are considered problems:
/**
* foo.
*/
const q = class {
}
// "jsdoc/match-description": ["error"|"warn", {"contexts":["ClassExpression"]}]
// Message: JSDoc description does not satisfy the regex pattern.
/**
* foo.
*/
const q = class {
}
// "jsdoc/match-description": ["error"|"warn", {"contexts":["ClassExpression"],"message":"Needs to begin with a capital letter and end with an end mark."}]
// Message: Needs to begin with a capital letter and end with an end mark.
/**
* foo.
*/
// "jsdoc/match-description": ["error"|"warn", {"contexts":["any"]}]
// Message: JSDoc description does not satisfy the regex pattern.
/**
* foo.
*/
// "jsdoc/match-description": ["error"|"warn", {"contexts":["any"]}]
// Message: JSDoc description does not satisfy the regex pattern.
/**
* foo.
*/
const q = {
};
// "jsdoc/match-description": ["error"|"warn", {"contexts":["ObjectExpression"]}]
// Message: JSDoc description does not satisfy the regex pattern.
/**
* foo.
*/
function quux () {
}
// Message: JSDoc description does not satisfy the regex pattern.
/**
* Foo)
*/
function quux () {
}
// Message: JSDoc description does not satisfy the regex pattern.
/**
* тест.
*/
function quux () {
}
// "jsdoc/match-description": ["error"|"warn", {"matchDescription":"[А-Я][А-я]+\\."}]
// Message: JSDoc description does not satisfy the regex pattern.
/**
* тест.
*/
function quux () {
}
// "jsdoc/match-description": ["error"|"warn", {"matchDescription":"[А-Я][А-я]+\\.","message":"Needs to begin with a capital letter and end with an end mark."}]
// Message: Needs to begin with a capital letter and end with an end mark.
/**
* Abc.
*/
function quux () {
}
// "jsdoc/match-description": ["error"|"warn", {"mainDescription":"[А-Я][А-я]+\\.","tags":{"param":true}}]
// Message: JSDoc description does not satisfy the regex pattern.
/**
* Abc.
*/
function quux () {
}
// "jsdoc/match-description": ["error"|"warn", {"mainDescription":{"match":"[А-Я][А-я]+\\.","message":"Needs to begin with a Cyrillic capital letter and end with a period."},"tags":{"param":true}}]
// Message: Needs to begin with a Cyrillic capital letter and end with a period.
/**
* Foo
*/
function quux () {
}
// Message: JSDoc description does not satisfy the regex pattern.
/**
* Foo.
*
* @param foo foo.
*/
function quux (foo) {
}
// "jsdoc/match-description": ["error"|"warn", {"tags":{"param":true}}]
// Message: JSDoc description does not satisfy the regex pattern.
/**
* Foo.
*
* @template Abc, Def foo.
*/
function quux (foo) {
}
// "jsdoc/match-description": ["error"|"warn", {"tags":{"template":true}}]
// Message: JSDoc description does not satisfy the regex pattern.
/**
* Foo.
*
* @prop foo foo.
*/
function quux (foo) {
}
// "jsdoc/match-description": ["error"|"warn", {"tags":{"prop":true}}]
// Message: JSDoc description does not satisfy the regex pattern.
/**
* Foo.
*
* @summary foo.
*/
function quux () {
}
// "jsdoc/match-description": ["error"|"warn", {"tags":{"summary":true}}]
// Message: JSDoc description does not satisfy the regex pattern.
/**
* Foo.
*
* @author
*/
function quux () {
}
// "jsdoc/match-description": ["error"|"warn", {"tags":{"author":".+"}}]
// Message: JSDoc description does not satisfy the regex pattern.
/**
* Foo.
*
* @x-tag
*/
function quux () {
}
// "jsdoc/match-description": ["error"|"warn", {"tags":{"x-tag":".+"}}]
// Message: JSDoc description does not satisfy the regex pattern.
/**
* Foo.
*
* @description foo foo.
*/
function quux (foo) {
}
// "jsdoc/match-description": ["error"|"warn", {"tags":{"description":true}}]
// Message: JSDoc description does not satisfy the regex pattern.
/**
* Foo
*
* @param foo foo.
*/
function quux (foo) {
}
// "jsdoc/match-description": ["error"|"warn", {"mainDescription":"^[a-zA-Z]*$","tags":{"param":true}}]
// Message: JSDoc description does not satisfy the regex pattern.
/**
* Foo
*
* @param foo foo.
*/
function quux (foo) {
}
// "jsdoc/match-description": ["error"|"warn", {"mainDescription":{"match":"^[a-zA-Z]*$","message":"Letters only"},"tags":{"param":{"match":true,"message":"Needs to begin with a capital letter and end with a period."}}}]
// Message: Needs to begin with a capital letter and end with a period.
/**
* Foo
*
* @param foo foo.
*/
function quux (foo) {
}
// "jsdoc/match-description": ["error"|"warn", {"mainDescription":false,"tags":{"param":true}}]
// Message: JSDoc description does not satisfy the regex pattern.
/**
* Foo.
*
* @param foo bar
*/
function quux (foo) {
}
// "jsdoc/match-description": ["error"|"warn", {"tags":{"param":true}}]
// Message: JSDoc description does not satisfy the regex pattern.
/**
* {@see Foo.bar} buz
*/
function quux (foo) {
}
// Message: JSDoc description does not satisfy the regex pattern.
/**
* Foo.
*
* @returns {number} foo
*/
function quux (foo) {
}
// "jsdoc/match-description": ["error"|"warn", {"tags":{"returns":true}}]
// Message: JSDoc description does not satisfy the regex pattern.
/**
* Foo.
*
* @returns foo.
*/
function quux (foo) {
}
// "jsdoc/match-description": ["error"|"warn", {"tags":{"returns":true}}]
// Message: JSDoc description does not satisfy the regex pattern.
/**
* lorem ipsum dolor sit amet, consectetur adipiscing elit. pellentesque elit diam,
* iaculis eu dignissim sed, ultrices sed nisi. nulla at ligula auctor, consectetur neque sed,
* tincidunt nibh. vivamus sit amet vulputate ligula. vivamus interdum elementum nisl,
* vitae rutrum tortor semper ut. morbi porta ante vitae dictum fermentum.
* proin ut nulla at quam convallis gravida in id elit. sed dolor mauris, blandit quis ante at,
* consequat auctor magna. duis pharetra purus in porttitor mollis.
*/
function longDescription (foo) {
}
// Message: JSDoc description does not satisfy the regex pattern.
/**
* @arg {number} foo - Foo
*/
function quux (foo) {
}
// "jsdoc/match-description": ["error"|"warn", {"tags":{"arg":true}}]
// Message: JSDoc description does not satisfy the regex pattern.
/**
* @argument {number} foo - Foo
*/
function quux (foo) {
}
// "jsdoc/match-description": ["error"|"warn", {"tags":{"argument":true}}]
// Message: JSDoc description does not satisfy the regex pattern.
/**
* @return {number} foo
*/
function quux (foo) {
}
// "jsdoc/match-description": ["error"|"warn", {"tags":{"return":true}}]
// Message: JSDoc description does not satisfy the regex pattern.
/**
* Returns bar.
*
* @return {number} bar
*/
function quux (foo) {
}
// "jsdoc/match-description": ["error"|"warn", {"tags":{"return":true}}]
// Message: JSDoc description does not satisfy the regex pattern.
/**
* @param notRet
* @returns Тест.
*/
function quux () {
}
// "jsdoc/match-description": ["error"|"warn", {"tags":{"param":"[А-Я][А-я]+\\."}}]
// Message: JSDoc description does not satisfy the regex pattern.
/**
* @description notRet
* @returns Тест.
*/
function quux () {
}
// "jsdoc/match-description": ["error"|"warn", {"tags":{"description":"[А-Я][А-я]+\\."}}]
// Message: JSDoc description does not satisfy the regex pattern.
/**
* foo.
*/
class quux {
}
// "jsdoc/match-description": ["error"|"warn", {"contexts":["ClassDeclaration"]}]
// Message: JSDoc description does not satisfy the regex pattern.
class MyClass {
/**
* Abc
*/
myClassField = 1
}
// "jsdoc/match-description": ["error"|"warn", {"contexts":["PropertyDefinition"]}]
// Message: JSDoc description does not satisfy the regex pattern.
/**
* foo.
*/
interface quux {
}
// "jsdoc/match-description": ["error"|"warn", {"contexts":["TSInterfaceDeclaration"]}]
// Message: JSDoc description does not satisfy the regex pattern.
const myObject = {
/**
* Bad description
*/
myProp: true
};
// "jsdoc/match-description": ["error"|"warn", {"contexts":["Property"]}]
// Message: JSDoc description does not satisfy the regex pattern.
/**
* @param foo Foo bar
*/
function quux (foo) {
}
// Settings: {"jsdoc":{"tagNamePreference":{"description":false}}}
// "jsdoc/match-description": ["error"|"warn", {"tags":{"param":true}}]
// Message: JSDoc description does not satisfy the regex pattern.
/**
* Foo bar
*/
function quux (foo) {
}
// Settings: {"jsdoc":{"tagNamePreference":{"description":false}}}
// Message: JSDoc description does not satisfy the regex pattern.
The following patterns are not considered problems:
/**
*
*/
/**
*
*/
function quux () {
}
/**
* @param foo - Foo.
*/
function quux () {
}
// "jsdoc/match-description": ["error"|"warn", {"tags":{"param":true}}]
/**
* Foo.
*/
function quux () {
}
/**
* Foo.
* Bar.
*/
function quux () {
}
/**
* Foo.
*
* Bar.
*/
function quux () {
}
/**
* Foo.
*
* Bar.
*/
function quux () {
}
// "jsdoc/match-description": ["error"|"warn", {"message":"This won't be shown"}]
/**
* Тест.
*/
function quux () {
}
// "jsdoc/match-description": ["error"|"warn", {"matchDescription":"[А-Я][А-я]+\\."}]
/**
* @param notRet
* @returns Тест.
*/
function quux () {
}
// "jsdoc/match-description": ["error"|"warn", {"tags":{"returns":"[А-Я][А-я]+\\."}}]
/**
* @param notRet
* @description Тест.
*/
function quux () {
}
// "jsdoc/match-description": ["error"|"warn", {"tags":{"description":"[А-Я][А-я]+\\."}}]
/**
* Foo
* bar.
*/
function quux () {
}
/**
* @returns Foo bar.
*/
function quux () {
}
// "jsdoc/match-description": ["error"|"warn", {"tags":{"returns":true}}]
/**
* @returns {type1} Foo bar.
*/
function quux () {
}
// "jsdoc/match-description": ["error"|"warn", {"tags":{"returns":true}}]
/**
* @description Foo bar.
*/
function quux () {
}
// "jsdoc/match-description": ["error"|"warn", {"tags":{"description":true}}]
/**
* @description Foo
* bar.
* @param
*/
function quux () {
}
// "jsdoc/match-description": ["error"|"warn", {"tags":{"description":true}}]
/** @description Foo bar. */
function quux () {
}
// "jsdoc/match-description": ["error"|"warn", {"tags":{"description":true}}]
/**
* @description Foo
* bar.
*/
function quux () {
}
// "jsdoc/match-description": ["error"|"warn", {"tags":{"description":true}}]
/**
* Foo. {@see Math.sin}.
*/
function quux () {
}
/**
* Foo {@see Math.sin} bar.
*/
function quux () {
}
/**
* Foo?
*
* Bar!
*
* Baz:
* 1. Foo.
* 2. Bar.
*/
function quux () {
}
/**
* Hello:
* World.
*/
function quux () {
}
/**
* Hello: world.
*/
function quux () {
}
/**
* Foo
* Bar.
*/
function quux () {
}
/**
* Foo.
*
* foo.
*/
function quux () {
}
/**
* foo.
*/
function quux () {
}
// "jsdoc/match-description": ["error"|"warn", {"mainDescription":false}]
/**
* foo.
*/
class quux {
}
/**
* foo.
*/
class quux {
}
// "jsdoc/match-description": ["error"|"warn", {"mainDescription":true}]
class MyClass {
/**
* Abc.
*/
myClassField = 1
}
// "jsdoc/match-description": ["error"|"warn", {"contexts":["PropertyDefinition"]}]
/**
* Foo.
*/
interface quux {
}
// "jsdoc/match-description": ["error"|"warn", {"contexts":["TSInterfaceDeclaration"]}]
const myObject = {
/**
* Bad description
*/
myProp: true
};
// "jsdoc/match-description": ["error"|"warn", {"contexts":[]}]
/**
* foo.
*/
const q = class {
}
// "jsdoc/match-description": ["error"|"warn", {"contexts":[]}]
/**
* foo.
*/
const q = {
};
// "jsdoc/match-description": ["error"|"warn", {"contexts":[]}]
/**
* @description foo.
*/
function quux () {
}
// "jsdoc/match-description": ["error"|"warn", {"tags":{"param":true}}]
/**
* Foo.
*
* @summary Foo.
*/
function quux () {
}
// "jsdoc/match-description": ["error"|"warn", {"tags":{"summary":true}}]
/**
* Foo.
*
* @author Somebody
*/
function quux () {
}
// "jsdoc/match-description": ["error"|"warn", {"tags":{"author":".+"}}]
/**
* Foo.
*
* @x-tag something
*/
function quux () {
}
// "jsdoc/match-description": ["error"|"warn", {"tags":{"x-tag":".+"}}]
/**
* Foo.
*
* @prop foo Foo.
*/
function quux (foo) {
}
// "jsdoc/match-description": ["error"|"warn", {"tags":{"prop":true}}]
/**
* @param foo Foo bar.
*/
function quux (foo) {
}
// Settings: {"jsdoc":{"tagNamePreference":{"description":false}}}
/**
*
*/
function quux () {
}
// Settings: {"jsdoc":{"tagNamePreference":{"description":false}}}
/**
* Foo.
*
* @template Abc, Def Foo.
*/
function quux (foo) {
}
// "jsdoc/match-description": ["error"|"warn", {"tags":{"template":true}}]
/**
* Enable or disable plugin.
*
* When enabling with this function, the script will be attached to the `document` if:.
* - the script runs in browser context.
* - the `document` doesn't have the script already attached.
* - the `loadScript` option is set to `true`.
* @param enabled `true` to enable, `false` to disable. Default: `true`.
*/
// "jsdoc/match-description": ["error"|"warn", {"contexts":["any"],"mainDescription":"/^[A-Z`-].*\\.$/us","matchDescription":"^([A-Z`-].*(\\.|:)|-\\s.*)$","tags":{"param":true,"returns":true}}]
Reports the name portion of a JSDoc tag if matching or not matching a given regular expression.
Note that some tags do not possess names and anything appearing to be a
name will actually be part of the description (e.g., for
@returns {type} notAName
). If you are defining your own tags, see the
structuredTags
setting (if name: false
, this rule will not apply to
that tag).
A single options object with the following properties:
match
is a required option containing an array of objects which determine
the conditions whereby a name is reported as being problematic.
These objects can have any combination of the following groups of optional properties, all of which act to confine one another:
-
tags
- This array should include tag names or*
to indicate the match will apply for all tags (except as confined by any context properties). If*
is not used, then these rules will only apply to the specified tags. Iftags
is omitted, then*
is assumed. -
allowName
- Indicates which names are allowed for the given tag (or*
). Accepts a string regular expression (optionally wrapped between two/
delimiters followed by optional flags) used to match the name. -
disallowName
- As withallowName
but indicates names that are not allowed. -
replacement
- IfdisallowName
is supplied and this value is present, it will replace the matcheddisallowName
text. -
context
- AST to confine the allowing or disallowing to jsdoc blocks associated with a particular context. See the "AST and Selectors" section of our README for more on the expected format. -
comment
- As withcontext
but AST for the JSDoc block comment and types -
message
- An optional custom message to use when there is a match.
Note that comment
, even if targeting a specific tag, is used to match the
whole block. So if a comment
finds its specific tag, it may still apply
fixes found by the likes of disallowName
even when a different tag has the
disallowed name. An alternative is to ensure that comment
finds the specific
tag of the desired tag and/or name and no disallowName
(or allowName
) is
supplied. In such a case, only one error will be reported, but no fixer will
be applied, however.
Context | everywhere |
Tags | (The tags specified by tags , including any tag if * is set) |
Recommended | false |
Settings | structuredTags |
Options | match |
The following patterns are considered problems:
/**
* @param opt_a
* @param opt_b
*/
// "jsdoc/match-name": ["error"|"warn", {"match":[{"disallowName":"/^opt_/i"}]}]
// Message: Only allowing names not matching `/^opt_/i` but found "opt_a".
/**
* @param opt_a
* @param opt_b
*/
// "jsdoc/match-name": ["error"|"warn", {"match":[{"disallowName":"/^opt_/i","replacement":""}]}]
// Message: Only allowing names not matching `/^opt_/i` but found "opt_a".
/**
* @param a
* @param opt_b
*/
// "jsdoc/match-name": ["error"|"warn", {"match":[{"allowName":"/^[a-z]+$/i"}]}]
// Message: Only allowing names matching `/^[a-z]+$/i` but found "opt_b".
/**
* @param arg
* @param opt_b
*/
// "jsdoc/match-name": ["error"|"warn", {"match":[{"allowName":"/^[a-z]+$/i","disallowName":"/^arg/i"}]}]
// Message: Only allowing names not matching `/^arg/i` but found "arg".
/**
* @param opt_a
* @param arg
*/
// "jsdoc/match-name": ["error"|"warn", {"match":[{"disallowName":"/^arg$/i"},{"disallowName":"/^opt_/i"}]}]
// Message: Only allowing names not matching `/^opt_/i` but found "opt_a".
/**
* @property opt_a
* @param opt_b
*/
// "jsdoc/match-name": ["error"|"warn", {"match":[{"disallowName":"/^opt_/i","tags":["param"]}]}]
// Message: Only allowing names not matching `/^opt_/i` but found "opt_b".
/**
* @someTag opt_a
* @param opt_b
*/
// Settings: {"jsdoc":{"structuredTags":{"someTag":{"name":"namepath-defining"}}}}
// "jsdoc/match-name": ["error"|"warn", {"match":[{"disallowName":"/^opt_/i","tags":["param"]}]}]
// Message: Only allowing names not matching `/^opt_/i` but found "opt_b".
/**
* @property opt_a
* @param opt_b
*/
// "jsdoc/match-name": ["error"|"warn", {"match":[{"disallowName":"/^opt_/i","tags":["*"]}]}]
// Message: Only allowing names not matching `/^opt_/i` but found "opt_a".
/**
* @param opt_a
* @param opt_b
*/
function quux () {
}
// "jsdoc/match-name": ["error"|"warn", {"match":[{"context":"FunctionDeclaration","disallowName":"/^opt_/i"}]}]
// Message: Only allowing names not matching `/^opt_/i` but found "opt_a".
/**
* @property opt_a
* @param {Bar|Foo} opt_b
*/
// "jsdoc/match-name": ["error"|"warn", {"match":[{"comment":"JSDocBlock:has(JSDocTag[tag=\"param\"][name=/opt_/] > JSDocTypeUnion:has(JsdocTypeName[value=\"Bar\"]:nth-child(1)))"}]}]
// Message: Prohibited context for "opt_a".
/**
* @property opt_a
* @param {Bar|Foo} opt_b
*/
// "jsdoc/match-name": ["error"|"warn", {"match":[{"comment":"JSDocBlock:has(JSDocTag[tag=\"param\"][name=/opt_/] > JSDocTypeUnion:has(JsdocTypeName[value=\"Bar\"]:nth-child(1)))","message":"Don't use `opt_` prefixes with Bar|..."}]}]
// Message: Don't use `opt_` prefixes with Bar|...
/**
* @param opt_a
* @param opt_b
*/
function quux () {}
// "jsdoc/match-name": ["error"|"warn", ]
// Message: Rule `no-restricted-syntax` is missing a `match` option.
The following patterns are not considered problems:
/**
* @param opt_a
* @param opt_b
*/
// "jsdoc/match-name": ["error"|"warn", {"match":[{"disallowName":"/^arg/i"}]}]
/**
* @param a
* @param opt_b
*/
// "jsdoc/match-name": ["error"|"warn", {"match":[{"allowName":"/^[a-z_]+$/i"}]}]
/**
* @param someArg
* @param anotherArg
*/
// "jsdoc/match-name": ["error"|"warn", {"match":[{"allowName":"/^[a-z]+$/i","disallowName":"/^arg/i"}]}]
/**
* @param elem1
* @param elem2
*/
// "jsdoc/match-name": ["error"|"warn", {"match":[{"disallowName":"/^arg$/i"},{"disallowName":"/^opt_/i"}]}]
/**
* @someTag opt_a
* @param opt_b
*/
// Settings: {"jsdoc":{"structuredTags":{"someTag":{"name":"namepath-defining"}}}}
// "jsdoc/match-name": ["error"|"warn", {"match":[{"disallowName":"/^opt_/i","tags":["property"]}]}]
/**
* @property opt_a
* @param opt_b
*/
// "jsdoc/match-name": ["error"|"warn", {"match":[{"disallowName":"/^arg/i","tags":["*"]}]}]
/**
* @param opt_a
* @param opt_b
*/
class A {
}
// "jsdoc/match-name": ["error"|"warn", {"match":[{"context":"FunctionDeclaration","disallowName":"/^opt_/i"}]}]
/**
* @property opt_a
* @param {Foo|Bar} opt_b
*/
// "jsdoc/match-name": ["error"|"warn", {"match":[{"comment":"JSDocBlock > JSDocTag[tag=\"param\"] > JSDocTypeUnion[left.name=\"Bar\"]","disallowName":"/^opt_/i"}]}]
Controls how and whether jsdoc blocks can be expressed as single or multiple line blocks.
Note that if you set noSingleLineBlocks
and noMultilineBlocks
to true
and configure them in a certain manner, you might effectively be prohibiting
all jsdoc blocks!
Also allows for preventing text at the very beginning or very end of blocks.
A single options object with the following properties.
For multiline blocks, any non-whitespace text immediately after the /**
and
space will be reported. (Text after a newline is not reported.)
noMultilineBlocks
will have priority over this rule if it applies.
For multiline blocks, any non-whitespace text preceding the */
on the final
line will be reported. (Text preceding a newline is not reported.)
noMultilineBlocks
will have priority over this rule if it applies.
If this is true
, any single line blocks will be reported, except those which
are whitelisted in singleLineTags
.
An array of tags which can nevertheless be allowed as single line blocks when
noSingleLineBlocks
is set. You may set this to a empty array to
cause all single line blocks to be reported. If '*'
is present, then
the presence of a tag will allow single line blocks (but not if a tag is
missing).
Requires that jsdoc blocks are restricted to single lines only unless impacted
by the options minimumLengthForMultiline
, multilineTags
, or
allowMultipleTags
.
If noMultilineBlocks
is set with this numeric option, multiline blocks will
be permitted if containing at least the given amount of text.
If not set, multiline blocks will not be permitted regardless of length unless
a relevant tag is present and multilineTags
is set.
If noMultilineBlocks
is set with this option, multiline blocks may be allowed
regardless of length as long as a tag or a tag of a certain type is present.
If *
is included in the array, the presence of a tags will allow for
multiline blocks (but not when without any tags unless the amount of text is
over an amount specified by minimumLengthForMultiline
).
If the array does not include *
but lists certain tags, the presence of
such a tag will cause multiline blocks to be allowed.
You may set this to an empty array to prevent any tag from permitting multiple lines.
If noMultilineBlocks
is set to true
with this option and multiple tags are
found in a block, an error will not be reported.
Since multiple-tagged lines cannot be collapsed into a single line, this option
prevents them from being reported. Set to false
if you really want to report
any blocks.
This option will also be applied when there is a block description and a single tag (since a description cannot precede a tag on a single line, and also cannot be reliably added after the tag either).
Context | everywhere |
Tags | Any (though singleLineTags and multilineTags control the application) |
Recommended | true |
Settings | |
Options |
noZeroLineText , noSingleLineBlocks , singleLineTags , noMultilineBlocks , minimumLengthForMultiline , multilineTags , allowMultipleTags , noFinalLineText
|
The following patterns are considered problems:
/** Reported up here
* because the rest is multiline
*/
// Message: Should have no text on the "0th" line (after the `/**`).
/** Reported up here
* because the rest is multiline
*/
// "jsdoc/multiline-blocks": ["error"|"warn", {"noZeroLineText":true}]
// Message: Should have no text on the "0th" line (after the `/**`).
/** @abc {aType} aName Reported up here
* because the rest is multiline
*/
// "jsdoc/multiline-blocks": ["error"|"warn", {"noZeroLineText":true}]
// Message: Should have no text on the "0th" line (after the `/**`).
/** @tag */
// "jsdoc/multiline-blocks": ["error"|"warn", {"noSingleLineBlocks":true}]
// Message: Single line blocks are not permitted by your configuration.
/** @tag {someType} */
// "jsdoc/multiline-blocks": ["error"|"warn", {"noSingleLineBlocks":true}]
// Message: Single line blocks are not permitted by your configuration.
/** @tag {someType} aName */
// "jsdoc/multiline-blocks": ["error"|"warn", {"noSingleLineBlocks":true}]
// Message: Single line blocks are not permitted by your configuration.
/** @tag */
// "jsdoc/multiline-blocks": ["error"|"warn", {"noSingleLineBlocks":true,"singleLineTags":["someOtherTag"]}]
// Message: Single line blocks are not permitted by your configuration.
/** desc */
// "jsdoc/multiline-blocks": ["error"|"warn", {"noSingleLineBlocks":true,"singleLineTags":["*"]}]
// Message: Single line blocks are not permitted by your configuration.
/**
* Desc.
*/
// "jsdoc/multiline-blocks": ["error"|"warn", {"noMultilineBlocks":true}]
// Message: Multiline jsdoc blocks are prohibited by your configuration.
/** desc
*
*/
// "jsdoc/multiline-blocks": ["error"|"warn", {"noMultilineBlocks":true}]
// Message: Multiline jsdoc blocks are prohibited by your configuration.
/** desc
*
*/
// "jsdoc/multiline-blocks": ["error"|"warn", {"noMultilineBlocks":true,"noSingleLineBlocks":true}]
// Message: Multiline jsdoc blocks are prohibited by your configuration but fixing would result in a single line block which you have prohibited with `noSingleLineBlocks`.
/**
*
*/
// "jsdoc/multiline-blocks": ["error"|"warn", {"noMultilineBlocks":true}]
// Message: Multiline jsdoc blocks are prohibited by your configuration.
/**
* This is not long enough to be permitted.
*/
// "jsdoc/multiline-blocks": ["error"|"warn", {"minimumLengthForMultiline":100,"noMultilineBlocks":true}]
// Message: Multiline jsdoc blocks are prohibited by your configuration.
/**
* This is not long enough to be permitted.
*/
// "jsdoc/multiline-blocks": ["error"|"warn", {"allowMultipleTags":true,"minimumLengthForMultiline":100,"noMultilineBlocks":true}]
// Message: Multiline jsdoc blocks are prohibited by your configuration.
/**
* This has the wrong tags so is not permitted.
* @notTheRightTag
*/
// "jsdoc/multiline-blocks": ["error"|"warn", {"allowMultipleTags":false,"multilineTags":["onlyThisIsExempted"],"noMultilineBlocks":true}]
// Message: Multiline jsdoc blocks are prohibited by your configuration but the block has a description with a tag.
/**
* This has too many tags so cannot be fixed ot a single line.
* @oneTag
* @anotherTag
*/
// "jsdoc/multiline-blocks": ["error"|"warn", {"allowMultipleTags":false,"multilineTags":[],"noMultilineBlocks":true}]
// Message: Multiline jsdoc blocks are prohibited by your configuration but the block has multiple tags.
/**
* This has a tag and description so cannot be fixed ot a single line.
* @oneTag
*/
// "jsdoc/multiline-blocks": ["error"|"warn", {"allowMultipleTags":false,"multilineTags":[],"noMultilineBlocks":true}]
// Message: Multiline jsdoc blocks are prohibited by your configuration but the block has a description with a tag.
/**
* This has no tags so is not permitted.
*/
// "jsdoc/multiline-blocks": ["error"|"warn", {"multilineTags":["*"],"noMultilineBlocks":true}]
// Message: Multiline jsdoc blocks are prohibited by your configuration.
/**
* This has the wrong tags so is not permitted.
* @notTheRightTag
*/
// "jsdoc/multiline-blocks": ["error"|"warn", {"allowMultipleTags":false,"minimumLengthForMultiline":500,"multilineTags":["onlyThisIsExempted"],"noMultilineBlocks":true}]
// Message: Multiline jsdoc blocks are prohibited by your configuration but the block has a description with a tag.
/**
* @lends This can be safely fixed to a single line.
*/
// "jsdoc/multiline-blocks": ["error"|"warn", {"multilineTags":[],"noMultilineBlocks":true,"noSingleLineBlocks":true}]
// Message: Multiline jsdoc blocks are prohibited by your configuration.
/**
* @type {aType} This can be safely fixed to a single line.
*/
// "jsdoc/multiline-blocks": ["error"|"warn", {"multilineTags":[],"noMultilineBlocks":true,"noSingleLineBlocks":true}]
// Message: Multiline jsdoc blocks are prohibited by your configuration.
/**
* @aTag
*/
// "jsdoc/multiline-blocks": ["error"|"warn", {"multilineTags":[],"noMultilineBlocks":true}]
// Message: Multiline jsdoc blocks are prohibited by your configuration.
/**
* This is a problem when single and multiline are blocked.
*/
// "jsdoc/multiline-blocks": ["error"|"warn", {"noMultilineBlocks":true,"noSingleLineBlocks":true}]
// Message: Multiline jsdoc blocks are prohibited by your configuration but fixing would result in a single line block which you have prohibited with `noSingleLineBlocks`.
/** This comment is bad
* It should not have text on line zero
*/
// "jsdoc/multiline-blocks": ["error"|"warn", {"minimumLengthForMultiline":50,"noMultilineBlocks":true,"noZeroLineText":true}]
// Message: Should have no text on the "0th" line (after the `/**`).
/**
* @lends This can be safely fixed
* to a single
* line. */
// "jsdoc/multiline-blocks": ["error"|"warn", {"multilineTags":[],"noMultilineBlocks":true}]
// Message: Multiline jsdoc blocks are prohibited by your configuration.
/**
* @someTag {aType} with Description */
// "jsdoc/multiline-blocks": ["error"|"warn", {"noFinalLineBlocks":true}]
// Message: Should have no text on the final line (before the `*/`).
/**
* Description */
// "jsdoc/multiline-blocks": ["error"|"warn", {"noFinalLineBlocks":true}]
// Message: Should have no text on the final line (before the `*/`).
The following patterns are not considered problems:
/** Not reported */
/**
* Not reported
*/
/** Reported up here
* because the rest is multiline
*/
// "jsdoc/multiline-blocks": ["error"|"warn", {"noZeroLineText":false}]
/** @tag */
/** @lends */
// "jsdoc/multiline-blocks": ["error"|"warn", {"noSingleLineBlocks":true}]
/** @tag */
// "jsdoc/multiline-blocks": ["error"|"warn", {"noSingleLineBlocks":true,"singleLineTags":["tag"]}]
/** @tag */
// "jsdoc/multiline-blocks": ["error"|"warn", {"noSingleLineBlocks":true,"singleLineTags":["*"]}]
/**
*
*/
/**
*
*/
// "jsdoc/multiline-blocks": ["error"|"warn", {"noMultilineBlocks":false}]
/** Test */
// "jsdoc/multiline-blocks": ["error"|"warn", {"noMultilineBlocks":true}]
/**
* This is long enough to be permitted by our config.
*/
// "jsdoc/multiline-blocks": ["error"|"warn", {"minimumLengthForMultiline":25,"noMultilineBlocks":true}]
/**
* This is long enough to be permitted by our config.
*/
// "jsdoc/multiline-blocks": ["error"|"warn", {"minimumLengthForMultiline":50,"noMultilineBlocks":true}]
/**
* This has the right tag so is permitted.
* @theRightTag
*/
// "jsdoc/multiline-blocks": ["error"|"warn", {"multilineTags":["theRightTag"],"noMultilineBlocks":true}]
/** This has no tags but is single line so is not permitted. */
// "jsdoc/multiline-blocks": ["error"|"warn", {"multilineTags":["*"],"noMultilineBlocks":true}]
/**
* This has the wrong tags so is not permitted.
* @notTheRightTag
*/
// "jsdoc/multiline-blocks": ["error"|"warn", {"minimumLengthForMultiline":10,"multilineTags":["onlyThisIsExempted"],"noMultilineBlocks":true}]
/**
* This has the wrong tags so is not permitted.
* @theRightTag
*/
// "jsdoc/multiline-blocks": ["error"|"warn", {"minimumLengthForMultiline":500,"multilineTags":["theRightTag"],"noMultilineBlocks":true}]
/** tag */
/**
* @lends This is ok per multiline
*/
// "jsdoc/multiline-blocks": ["error"|"warn", {"noMultilineBlocks":true,"noSingleLineBlocks":true}]
/**
* This has too many tags so cannot be fixed ot a single line.
* @oneTag
* @anotherTag
*/
// "jsdoc/multiline-blocks": ["error"|"warn", {"multilineTags":[],"noMultilineBlocks":true}]
/**
* This has too many tags so cannot be fixed ot a single line.
* @oneTag
* @anotherTag
*/
// "jsdoc/multiline-blocks": ["error"|"warn", {"allowMultipleTags":true,"multilineTags":[],"noMultilineBlocks":true}]
/**
* This has a tag and description so cannot be fixed ot a single line.
* @oneTag
*/
// "jsdoc/multiline-blocks": ["error"|"warn", {"allowMultipleTags":true,"multilineTags":[],"noMultilineBlocks":true}]
/**
* This has a tag and description so cannot be fixed ot a single line.
* @oneTag
*/
// "jsdoc/multiline-blocks": ["error"|"warn", {"allowMultipleTags":false,"multilineTags":["oneTag"],"noMultilineBlocks":true}]
/** @someTag with Description */
// "jsdoc/multiline-blocks": ["error"|"warn", {"noFinalLineBlocks":true}]
Enforces a consistent padding of the block description.
This rule allows one optional string argument. If it is "always"
then a
problem is raised when there is no newline after the description. If it is
"never"
then a problem is raised when there is a newline after the
description. The default value is "always"
.
Context | everywhere |
Tags | N/A (doc block) |
Options | (a string matching "always" or "never" ) |
Recommended | true |
The following patterns are considered problems:
/**
* Foo.
*
* Foo.
* @foo
*/
function quux () {
}
// "jsdoc/newline-after-description": ["error"|"warn", "always"]
// Message: There must be a newline after the description of the JSDoc block.
/**
* Foo.
* @foo
*
* Foo.
*/
function quux () {
}
// "jsdoc/newline-after-description": ["error"|"warn", "always"]
// Message: There must be a newline after the description of the JSDoc block.
/**
* Foo.
*
* Foo.
* @foo
*/
function quux () {
}
// Message: There must be a newline after the description of the JSDoc block.
/**
* Bar.
*
* Bar.
*
* @bar
*/
function quux () {
}
// "jsdoc/newline-after-description": ["error"|"warn", "never"]
// Message: There must be no newline after the description of the JSDoc block.
/**
* Bar.
*
* @bar
*
* Bar.
*/
function quux () {
}
// "jsdoc/newline-after-description": ["error"|"warn", "never"]
// Message: There must be no newline after the description of the JSDoc block.
/**
* Bar.
*
* Bar.
*
* @bar
*/
function quux () {
}
// "jsdoc/newline-after-description": ["error"|"warn", "never"]
// Message: There must be no newline after the description of the JSDoc block.
/**
* A.
*
* @typedef {object} A
* @prop {boolean} a A.
*/
// "jsdoc/newline-after-description": ["error"|"warn", "never"]
// Message: There must be no newline after the description of the JSDoc block.
/**
* A.
* @typedef {object} A
* @prop {boolean} a A.
*/
// "jsdoc/newline-after-description": ["error"|"warn", "always"]
// Message: There must be a newline after the description of the JSDoc block.
/**
* Service for fetching symbols.
* @param {object} $http - Injected http helper.
* @param {object} $q - Injected Promise api helper.
* @param {object} $location - Injected window location object.
* @param {object} REPORT_DIALOG_CONSTANTS - Injected handle.
*/
// Message: There must be a newline after the description of the JSDoc block.
/** An example function.
*
* @returns {number} An example number.
*/
function example() {
return 42;
}
// "jsdoc/newline-after-description": ["error"|"warn", "never"]
// Message: There must be no newline after the description of the JSDoc block.
/** An example function.
* @returns {number} An example number.
*/
function example() {
return 42;
}
// "jsdoc/newline-after-description": ["error"|"warn", "always"]
// Message: There must be a newline after the description of the JSDoc block.
The following patterns are not considered problems:
/**
* Foo.
*/
function quux () {
}
// "jsdoc/newline-after-description": ["error"|"warn", "always"]
/**
* Bar.
*/
function quux () {
}
// "jsdoc/newline-after-description": ["error"|"warn", "never"]
/**
* Foo.
*
* @foo
*/
function quux () {
}
// "jsdoc/newline-after-description": ["error"|"warn", "always"]
/**
* Bar.
* @bar
*/
function quux () {
}
// "jsdoc/newline-after-description": ["error"|"warn", "never"]
/**
* @foo
* Test
* abc
* @bar
*/
/**
*
* @foo
* Test
* abc
* @bar
*/
/***
*
*/
function quux () {
}
// "jsdoc/newline-after-description": ["error"|"warn", "always"]
/**
* Parses query string to object containing URL parameters
*
* @param queryString
* Input string
*
* @returns
* Object containing URL parameters
*/
export function parseQueryString(queryString: string): { [key: string]: string } { // <-- Line 10 that fails
}
/** An example function.
*
* @returns {number} An example number.
*/
function example() {
return 42;
}
/** An example function.
* @returns {number} An example number.
*/
function example() {
return 42;
}
// "jsdoc/newline-after-description": ["error"|"warn", "never"]
This rule checks for multi-line-style comments which fail to meet the
criteria of a jsdoc block, namely that it should begin with two and only two
asterisks, but which appear to be intended as jsdoc blocks due to the presence
of whitespace followed by whitespace or asterisks, and
an at-sign (@
) and some non-whitespace (as with a jsdoc block tag).
Takes an optional options object with the following.
An array of directives that will not be reported if present at the beginning of
a multi-comment block and at-sign /* @
.
Defaults to ['ts-check', 'ts-expect-error', 'ts-ignore', 'ts-nocheck']
(some directives used by TypeScript).
A boolean (defaulting to false
) which if true
will prevent all
multi-asterisked blocks even those without apparent tag content.
Context | Everywhere |
Tags | N/A |
Recommended | false |
Options |
ignore , preventAllMultiAsteriskBlocks
|
The following patterns are considered problems:
/*
* @param foo
*/
function quux (foo) {
}
// Message: Expected JSDoc-like comment to begin with two asterisks.
/*
* @property foo
*/
// Message: Expected JSDoc-like comment to begin with two asterisks.
function quux() {
}
// Settings: {"jsdoc":{"structuredTags":{"see":{"name":false,"required":["name"]}}}}
// Message: Cannot add "name" to `require` with the tag's `name` set to `false`
/* @ts-ignore */
// "jsdoc/no-bad-blocks": ["error"|"warn", {"ignore":[]}]
// Message: Expected JSDoc-like comment to begin with two asterisks.
/*
* Some description.
*
* @returns {string} Some string
*/
function echo() {
return 'Something';
}
// Message: Expected JSDoc-like comment to begin with two asterisks.
/***
* @param foo
*/
function quux (foo) {
}
// Message: Expected JSDoc-like comment to begin with two asterisks.
/***
*
*/
function quux (foo) {
}
// "jsdoc/no-bad-blocks": ["error"|"warn", {"preventAllMultiAsteriskBlocks":true}]
// Message: Expected JSDoc-like comment to begin with two asterisks.
The following patterns are not considered problems:
/**
* @property foo
*/
/**
* @param foo
*/
function quux () {
}
function quux () {
}
/* This could just be intended as a regular multiline comment,
so don't report this */
function quux () {
}
/* Just a regular multiline comment with an `@` but not appearing
like a tag in a jsdoc-block, so don't report */
function quux () {
}
/* @ts-check */
/* @ts-expect-error */
/* @ts-ignore */
/* @ts-nocheck */
/* */
/* @custom */
// "jsdoc/no-bad-blocks": ["error"|"warn", {"ignore":["custom"]}]
/***
* This is not JSDoc because of the 3 asterisks, but
* is allowed without `preventAllMultiAsteriskBlocks`, as
* some might wish normal multiline comments.
*/
function quux (foo) {
}
This rule reports defaults being used on the relevant portion of @param
or @default
. It also optionally reports the presence of the
square-bracketed optional arguments at all.
The rule is intended to prevent the indication of defaults on tags where
this would be redundant with ES6 default parameters (or for @default
,
where it would be redundant with the context to which the @default
tag is attached).
Unless your @default
is on a function, you will need to set contexts
to an appropriate context, including, if you wish, "any".
Set this to true
to report the presence of optional parameters. May be
used if the project is insisting on optionality being indicated by
the presence of ES6 default parameters (bearing in mind that such
"defaults" are only applied when the supplied value is missing or
undefined
but not for null
or other "falsey" values).
Set this to an array of strings representing the AST context (or an object with
context
and comment
properties) where you wish the rule to be applied.
Overrides the default contexts (see below). Set to "any"
if you want
the rule to apply to any jsdoc block throughout your files (as is necessary
for finding function blocks not attached to a function declaration or
expression, i.e., @callback
or @function
(or its aliases @func
or
@method
) (including those associated with an @interface
).
See the "AST and Selectors" section of our README for more on the expected format.
Context |
ArrowFunctionExpression , FunctionDeclaration , FunctionExpression ; others when contexts option enabled |
Tags |
param , default
|
Aliases |
arg , argument , defaultvalue
|
Recommended | false |
Options |
contexts , noOptionalParamNames
|
The following patterns are considered problems:
/**
* @param {number} [foo="7"]
*/
function quux (foo) {
}
// Message: Defaults are not permitted on @param.
class Test {
/**
* @param {number} [foo="7"]
*/
quux (foo) {
}
}
// Message: Defaults are not permitted on @param.
/**
* @param {number} [foo="7"]
*/
function quux (foo) {
}
// "jsdoc/no-defaults": ["error"|"warn", {"noOptionalParamNames":true}]
// Message: Optional param names are not permitted on @param.
/**
* @arg {number} [foo="7"]
*/
function quux (foo) {
}
// Settings: {"jsdoc":{"tagNamePreference":{"param":"arg"}}}
// Message: Defaults are not permitted on @arg.
/**
* @param {number} [foo="7"]
*/
function quux (foo) {
}
// "jsdoc/no-defaults": ["error"|"warn", {"contexts":["any"]}]
// Message: Defaults are not permitted on @param.
/**
* @function
* @param {number} [foo="7"]
*/
// "jsdoc/no-defaults": ["error"|"warn", {"contexts":["any"]}]
// Message: Defaults are not permitted on @param.
/**
* @callback
* @param {number} [foo="7"]
*/
// "jsdoc/no-defaults": ["error"|"warn", {"contexts":["any"]}]
// Message: Defaults are not permitted on @param.
/**
* @default {}
*/
const a = {};
// "jsdoc/no-defaults": ["error"|"warn", {"contexts":["any"]}]
// Message: Default values are not permitted on @default.
/**
* @defaultvalue {}
*/
const a = {};
// Settings: {"jsdoc":{"tagNamePreference":{"default":"defaultvalue"}}}
// "jsdoc/no-defaults": ["error"|"warn", {"contexts":["any"]}]
// Message: Default values are not permitted on @defaultvalue.
The following patterns are not considered problems:
/**
* @param foo
*/
function quux (foo) {
}
/**
* @param {number} foo
*/
function quux (foo) {
}
/**
* @param foo
*/
// "jsdoc/no-defaults": ["error"|"warn", {"contexts":["any"]}]
/**
* @function
* @param {number} foo
*/
/**
* @callback
* @param {number} foo
*/
/**
* @param {number} foo
*/
function quux (foo) {
}
// "jsdoc/no-defaults": ["error"|"warn", {"noOptionalParamNames":true}]
/**
* @default
*/
const a = {};
// "jsdoc/no-defaults": ["error"|"warn", {"contexts":["any"]}]
This rule lets you report if certain always expected comment structures are missing.
This (along with no-restricted-syntax
) is a bit similar to Schematron for
XML or jsontron for JSON--you can validate expectations of there being
arbitrary structures.
This differs from the rule of the same name in
eslint-plugin-query
in that this rule always looks for a comment above a structure (whether or not
you have a comment
condition).
This rule might be especially useful with overrides
where you need only require tags and/or types within specific directories
(e.g., to enforce that a plugins or locale directory always has a certain form
of export and comment therefor).
In addition to being generally useful for precision in requiring contexts,
it is hoped that the ability to specify required tags on structures can
be used for requiring @type
or other types for a minimalist yet adequate
specification of types which can be used to compile JavaScript+JSDoc (JJ)
to WebAssembly (e.g., by converting it to TypeSscript and then using
AssemblyScript to convert to WebAssembly). (It may be possible that one
will need to require types with certain structures beyond function
declarations and the like, as well as optionally requiring specification
of number types.)
Note that you can use selectors which make use of negators like :not()
including with asterisk, e.g., *:not(FunctionDeclaration)
to indicate types
which are not adequate to satisfy a condition, e.g.,
FunctionDeclaration:not(FunctionDeclaration[id.name="ignoreMe"])
would
not report if there were only a function declaration of the name "ignoreMe"
(though it would report by function declarations of other names).
Set this to an array of strings representing the AST context (or an object with
context
and comment
properties) where you wish the rule to be applied.
Use the minimum
property (defaults to 1) to indicate how many are required
for the rule to be reported.
Use the message
property to indicate the specific error to be shown when an
error is reported for that context being found missing. You may use
{{context}}
and {{comment}}
with such messages.
Set to "any"
if you want the rule to apply to any jsdoc block throughout
your files (as is necessary for finding function blocks not attached to a
function declaration or expression, i.e., @callback
or @function
(or its
aliases @func
or @method
) (including those associated with an @interface
).
See the "AST and Selectors" section of our README for more on the expected format.
Context | None except those indicated by contexts
|
Tags | Any if indicated by AST |
Recommended | false |
Options | contexts |
The following patterns are considered problems:
/**
* @implements {Bar|Foo}
*/
function quux () {
}
// "jsdoc/no-missing-syntax": ["error"|"warn", {"contexts":[{"comment":"JsdocBlock[postDelimiter=\"\"]:has(JsdocTypeUnion > JsdocTypeName[value=\"Foo\"]:nth-child(1))","context":"FunctionDeclaration"}]}]
// Message: Syntax is required: FunctionDeclaration with JsdocBlock[postDelimiter=""]:has(JsdocTypeUnion > JsdocTypeName[value="Foo"]:nth-child(1))
/**
* @implements {Bar|Foo}
*/
function quux () {
}
// "jsdoc/no-missing-syntax": ["error"|"warn", {"contexts":[{"comment":"JsdocBlock[postDelimiter=\"\"]:has(JsdocTypeUnion > JsdocTypeName[value=\"Foo\"]:nth-child(1))","context":"FunctionDeclaration","message":"Problematically missing function syntax: `{{context}}` with `{{comment}}`."}]}]
// Message: Problematically missing function syntax: `FunctionDeclaration` with `JsdocBlock[postDelimiter=""]:has(JsdocTypeUnion > JsdocTypeName[value="Foo"]:nth-child(1))`.
/**
* @implements {Bar|Foo}
*/
function quux () {
}
// "jsdoc/no-missing-syntax": ["error"|"warn", {"contexts":["FunctionDeclaration"]}]
// Message: Syntax is required: FunctionDeclaration
/**
* @implements {Bar|Foo}
*/
function quux () {
}
// Message: Rule `no-missing-syntax` is missing a `context` option.
/**
* @implements {Bar|Foo}
*/
function quux () {
}
// "jsdoc/no-missing-syntax": ["error"|"warn", {"contexts":[{"comment":"JsdocBlock[postDelimiter=\"\"]:has(JsdocTypeUnion > JsdocTypeName[value=\"Bar\"]:nth-child(1))","context":"FunctionDeclaration","minimum":2}]}]
// Message: Syntax is required: FunctionDeclaration with JsdocBlock[postDelimiter=""]:has(JsdocTypeUnion > JsdocTypeName[value="Bar"]:nth-child(1))
/**
* @param ab
* @param cd
*/
// "jsdoc/no-missing-syntax": ["error"|"warn", {"contexts":[{"comment":"JsdocBlock:has(JsdocTag[name=/opt_/])","context":"any","message":"Require names matching `/^opt_/i`."}]}]
// Message: Require names matching `/^opt_/i`.
/**
* @param ab
* @param cd
*/
// "jsdoc/no-missing-syntax": ["error"|"warn", {"contexts":[{"comment":"JsdocBlock:has(JsdocTag[name=/opt_/])","message":"Require names matching `/^opt_/i`."}]}]
// Message: Require names matching `/^opt_/i`.
/**
* @param ab
* @param cd
*/
function quux () {}
// "jsdoc/no-missing-syntax": ["error"|"warn", {"contexts":[{"comment":"JsdocBlock:has(JsdocTag[name=/opt_/])","context":"any","message":"Require names matching `/^opt_/i`."}]}]
// Message: Require names matching `/^opt_/i`.
The following patterns are not considered problems:
/**
* @implements {Bar|Foo}
*/
function quux () {
}
// "jsdoc/no-missing-syntax": ["error"|"warn", {"contexts":[{"comment":"JsdocBlock[postDelimiter=\"\"]:has(JsdocTypeUnion > JsdocTypeName[value=\"Bar\"]:nth-child(1))","context":"FunctionDeclaration"}]}]
/**
* @implements {Bar|Foo}
*/
function quux () {
}
/**
* @implements {Bar|Foo}
*/
function bar () {
}
/**
* @implements {Bar|Foo}
*/
function baz () {
}
// "jsdoc/no-missing-syntax": ["error"|"warn", {"contexts":[{"comment":"JsdocBlock[postDelimiter=\"\"]:has(JsdocTypeUnion > JsdocTypeName[value=\"Bar\"]:nth-child(1))","context":"FunctionDeclaration","minimum":2}]}]
/**
* @param opt_a
* @param opt_b
*/
// "jsdoc/no-missing-syntax": ["error"|"warn", {"contexts":[{"comment":"JsdocBlock:has(JsdocTag[name=/opt_/])","context":"any","message":"Require names matching `/^opt_/i`."}]}]
/**
* @param opt_a
* @param opt_b
*/
function quux () {}
// "jsdoc/no-missing-syntax": ["error"|"warn", {"contexts":[{"comment":"JsdocBlock:has(JsdocTag[name=/opt_/])","context":"any","message":"Require names matching `/^opt_/i`."}]}]
/**
* @param opt_a
* @param opt_b
*/
function quux () {}
// "jsdoc/no-missing-syntax": ["error"|"warn", {"contexts":[{"comment":"JsdocBlock:has(JsdocTag[name=/opt_/])","message":"Require names matching `/^opt_/i`."}]}]
Prevents use of multiple asterisks at the beginning of lines.
Note that if you wish to prevent multiple asterisks at the very beginning of
the jsdoc block, you should use no-bad-blocks
(as that is not proper jsdoc
and that rule is for catching blocks which only seem like jsdoc).
Prevent the likes of this:
/**
*
**
*/
Prevent the likes of this:
/**
*
*
**/
Context | everywhere |
Tags | (any) |
Recommended | true |
Settings | |
Options |
preventAtEnd , preventAtMiddleLines
|
The following patterns are considered problems:
/**
*
**
*/
// Message: Should be no multiple asterisks on middle lines.
/**
*
**
*/
// "jsdoc/no-multi-asterisks": ["error"|"warn", {"preventAtMiddleLines":true}]
// Message: Should be no multiple asterisks on middle lines.
/**
*
**
*/
// "jsdoc/no-multi-asterisks": ["error"|"warn", {"preventAtEnd":false}]
// Message: Should be no multiple asterisks on middle lines.
/**
* With a description
* @tag {SomeType} and a tag with details
**
*/
// Message: Should be no multiple asterisks on middle lines.
/**
**
*
*/
// Message: Should be no multiple asterisks on middle lines.
/**
* Desc.
*
**/
// Message: Should be no multiple asterisks on end lines.
/**
* Desc.
*
**/
// "jsdoc/no-multi-asterisks": ["error"|"warn", {"preventAtEnd":true}]
// Message: Should be no multiple asterisks on end lines.
/**
* Desc.
*
abc * **/
// "jsdoc/no-multi-asterisks": ["error"|"warn", {"preventAtEnd":true}]
// Message: Should be no multiple asterisks on end lines.
/**
* Desc.
*
**/
// "jsdoc/no-multi-asterisks": ["error"|"warn", {"preventAtMiddleLines":false}]
// Message: Should be no multiple asterisks on end lines.
/** Desc. **/
// Message: Should be no multiple asterisks on end lines.
/** @someTag name desc. **/
// Message: Should be no multiple asterisks on end lines.
/** abc * */
// Message: Should be no multiple asterisks on end lines.
/**
* Preserve user's whitespace when fixing (though one may also
* use an align rule)
*
* */
// "jsdoc/no-multi-asterisks": ["error"|"warn", {"preventAtEnd":true}]
// Message: Should be no multiple asterisks on end lines.
The following patterns are not considered problems:
/**
*
* Desc. ***
*/
/**
* Desc. ***
*
*/
/**
* Desc.
*
* sth */
/**
**
*
*/
// "jsdoc/no-multi-asterisks": ["error"|"warn", {"preventAtMiddleLines":false}]
/**
*
*
**/
// "jsdoc/no-multi-asterisks": ["error"|"warn", {"preventAtEnd":false}]
/**
* With a desc.
* and ***
*/
/**
* and ***
* With a desc.
*/
/**
* With a desc.
* With a desc.
* Desc. */
/**
* With a description
* @tag {SomeType} and a tag with details
*
*/
/** abc */
function foo() {
//
}
/** foo */
function foo(): void {
//
}
/** @aTag abc */
function foo() {
//
}
/**
* **Bold**
*/
/**
* Preserve user's bold statement when fixing.
*
* **Bold example:** Hi there.
*/
Reports when certain comment structures are present.
Note that this rule differs from ESLint's no-restricted-syntax
rule in expecting values within a single options object's
contexts
property, and with the property context
being used in place of
selector
(as well as allowing for comment
). The format also differs from
the format expected by eslint-plugin-query
.
Unlike those rules, this is specific to finding comments attached to
structures, (whether or not you add a specific comment
condition).
Note that if your parser supports comment AST (as jsdoc-eslint-parser/ is designed to do), you can just use ESLint's rule.
Set this to an array of strings representing the AST context (or an object with
context
and comment
properties) where you wish the rule to be applied.
Use the message
property to indicate the specific error to be shown when an
error is reported for that context being found.
Set to "any"
if you want the rule to apply to any jsdoc block throughout
your files (as is necessary for finding function blocks not attached to a
function declaration or expression, i.e., @callback
or @function
(or its
aliases @func
or @method
) (including those associated with an @interface
).
See the "AST and Selectors" section of our README for more on the expected format.
Context | None except those indicated by contexts
|
Tags | Any if indicated by AST |
Recommended | false |
Options | contexts |
The following patterns are considered problems:
/**
*
*/
function quux () {
}
// "jsdoc/no-restricted-syntax": ["error"|"warn", {"contexts":["FunctionDeclaration"]}]
// Message: Syntax is restricted: FunctionDeclaration.
/**
*
*/
function quux () {
}
// "jsdoc/no-restricted-syntax": ["error"|"warn", {"contexts":[{"context":"FunctionDeclaration","message":"Oops: `{{context}}`."}]}]
// Message: Oops: `FunctionDeclaration`.
/**
* @implements {Bar|Foo}
*/
function quux () {
}
// "jsdoc/no-restricted-syntax": ["error"|"warn", {"contexts":[{"comment":"JsdocBlock[postDelimiter=\"\"]:has(JsdocTypeUnion > JsdocTypeName[value=\"Bar\"]:nth-child(1))","context":"FunctionDeclaration"}]}]
// Message: Syntax is restricted: FunctionDeclaration.
/**
* @implements {Bar|Foo}
*/
function quux () {
}
// "jsdoc/no-restricted-syntax": ["error"|"warn", {"contexts":[{"comment":"JsdocBlock[postDelimiter=\"\"]:has(JsdocTypeUnion > JsdocTypeName[value=\"Foo\"]:nth-child(1))","context":"FunctionDeclaration","message":"The foo one: {{context}}."},{"comment":"JsdocBlock[postDelimiter=\"\"]:has(JsdocTypeUnion > JsdocTypeName[value=\"Bar\"]:nth-child(1))","context":"FunctionDeclaration","message":"The bar one: {{context}}."}]}]
// Message: The bar one: FunctionDeclaration.
/**
* @implements {Bar|Foo}
*/
function quux () {
}
// Message: Rule `no-restricted-syntax` is missing a `context` option.
/**
* @param opt_a
* @param opt_b
*/
function a () {}
// "jsdoc/no-restricted-syntax": ["error"|"warn", {"contexts":[{"comment":"JsdocBlock:has(JsdocTag[name=/opt_/])","context":"FunctionDeclaration","message":"Only allowing names not matching `/^opt_/i`."}]}]
// Message: Only allowing names not matching `/^opt_/i`.
/**
* @param opt_a
* @param opt_b
*/
function a () {}
// "jsdoc/no-restricted-syntax": ["error"|"warn", {"contexts":[{"comment":"JsdocBlock:has(JsdocTag[name=/opt_/])","context":"any","message":"Only allowing names not matching `/^opt_/i`."}]}]
// Message: Only allowing names not matching `/^opt_/i`.
/**
* @param opt_a
* @param opt_b
*/
function a () {}
// "jsdoc/no-restricted-syntax": ["error"|"warn", {"contexts":[{"comment":"JsdocBlock:has(JsdocTag[name=/opt_/])","message":"Only allowing names not matching `/^opt_/i`."}]}]
// Message: Only allowing names not matching `/^opt_/i`.
/**
* @param opt_a
* @param opt_b
*/
function a () {}
// "jsdoc/no-restricted-syntax": ["error"|"warn", {"contexts":[{"comment":"JsdocBlock:has(JsdocTag[name=/not-this/])","context":"any","message":"Only allowing names not matching `/^not-this/i`."},{"comment":"JsdocBlock:has(JsdocTag[name=/opt_/])","context":"any","message":"Only allowing names not matching `/^opt_/i`."}]}]
// Message: Only allowing names not matching `/^opt_/i`.
/**
* @param opt_a
* @param opt_b
*/
// "jsdoc/no-restricted-syntax": ["error"|"warn", {"contexts":[{"comment":"JsdocBlock:has(JsdocTag[name=/opt_/])","context":"any","message":"Only allowing names not matching `/^opt_/i`."}]}]
// Message: Only allowing names not matching `/^opt_/i`.
The following patterns are not considered problems:
/**
*
*/
function quux () {
}
// "jsdoc/no-restricted-syntax": ["error"|"warn", {"contexts":["FunctionExpression"]}]
/**
* @implements {Bar|Foo}
*/
function quux () {
}
// "jsdoc/no-restricted-syntax": ["error"|"warn", {"contexts":[{"comment":"JsdocBlock[postDelimiter=\"\"]:has(JsdocTypeUnion > JsdocTypeName[value=\"Foo\"]:nth-child(1))","context":"FunctionDeclaration"}]}]
/**
* @param ab
* @param cd
*/
function a () {}
// "jsdoc/no-restricted-syntax": ["error"|"warn", {"contexts":[{"comment":"JsdocBlock:has(JsdocTag[name=/opt_/])","context":"any","message":"Only allowing names not matching `/^opt_/i`."}]}]
/**
* @param ab
* @param cd
*/
// "jsdoc/no-restricted-syntax": ["error"|"warn", {"contexts":[{"comment":"JsdocBlock:has(JsdocTag[name=/opt_/])","context":"any","message":"Only allowing names not matching `/^opt_/i`."}]}]
/**
* @param ab
* @param cd
*/
// "jsdoc/no-restricted-syntax": ["error"|"warn", {"contexts":[{"comment":"JsdocBlock:has(JsdocTag[name=/opt_/])","message":"Only allowing names not matching `/^opt_/i`."}]}]
This rule reports types being used on @param
or @returns
.
The rule is intended to prevent the indication of types on tags where the type information would be redundant with TypeScript.
Set this to an array of strings representing the AST context (or an object with
context
and comment
properties) where you wish the rule to be applied.
Overrides the default contexts (see below). Set to "any"
if you want
the rule to apply to any jsdoc block throughout your files (as is necessary
for finding function blocks not attached to a function declaration or
expression, i.e., @callback
or @function
(or its aliases @func
or
@method
) (including those associated with an @interface
).
See the "AST and Selectors" section of our README for more on the expected format.
Context |
ArrowFunctionExpression , FunctionDeclaration , FunctionExpression ; others when contexts option enabled |
Tags |
param , returns
|
Aliases |
arg , argument , return
|
Recommended | false |
Options | contexts |
The following patterns are considered problems:
/**
* @param {number} foo
*/
function quux (foo) {
}
// Message: Types are not permitted on @param.
class quux {
/**
* @param {number} foo
*/
bar (foo) {
}
}
// Message: Types are not permitted on @param.
/**
* @param {number} foo
*/
function quux (foo) {
}
// "jsdoc/no-types": ["error"|"warn", {"contexts":["any"]}]
// Message: Types are not permitted on @param.
class quux {
/**
* @param {number} foo
*/
quux (foo) {
}
}
// "jsdoc/no-types": ["error"|"warn", {"contexts":["any"]}]
// Message: Types are not permitted on @param.
/**
* @function
* @param {number} foo
*/
// "jsdoc/no-types": ["error"|"warn", {"contexts":["any"]}]
// Message: Types are not permitted on @param.
/**
* @callback
* @param {number} foo
*/
// "jsdoc/no-types": ["error"|"warn", {"contexts":["any"]}]
// Message: Types are not permitted on @param.
/**
* @returns {number}
*/
function quux () {
}
// Message: Types are not permitted on @returns.
/**
* Beep
* Boop
*
* @returns {number}
*/
function quux () {
}
// Message: Types are not permitted on @returns.
The following patterns are not considered problems:
/**
* @param foo
*/
function quux (foo) {
}
/**
* @param foo
*/
// "jsdoc/no-types": ["error"|"warn", {"contexts":["any"]}]
/**
* @function
* @param {number} foo
*/
/**
* @callback
* @param {number} foo
*/
Checks that types in jsdoc comments are defined. This can be used to check unimported types.
When enabling this rule, types in jsdoc comments will resolve as used
variables, i.e. will not be marked as unused by no-unused-vars
.
In addition to considering globals found in code (or in ESLint-indicated
globals
) as defined, the following tags will also be checked for
name(path) definitions to also serve as a potential "type" for checking
the tag types in the table below:
@callback
, @class
(or @constructor
), @constant
(or @const
),
@event
, @external
(or @host
), @function
(or @func
or @method
),
@interface
, @member
(or @var
), @mixin
, @name
, @namespace
,
@template
(for "closure" or "typescript" settings.jsdoc.mode
only),
@typedef
.
The following tags will also be checked but only when the mode is closure
:
@package
, @private
, @protected
, @public
, @static
The following types are always considered defined.
-
null
,undefined
,void
,string
,boolean
,object
,function
,symbol
-
number
,bigint
,NaN
,Infinity
-
any
,*
-
this
,true
,false
-
Array
,Object
,RegExp
,Date
,Function
Note that preferred types indicated within settings.jsdoc.preferredTypes
will
also be assumed to be defined.
Also note that if there is an error parsing
types for a tag, the function will silently ignore that tag, leaving it to
the valid-types
rule to report parsing errors.
If you define your own tags, you can use settings.jsdoc.structuredTags
t