- 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
contexts
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 is nowtypescript
). 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 aliasesno-undefined-types
: Only check@template
for types in "closure" and "typescript" modescheck-syntax
: determines aspects that may be enforcedvalid-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)
Note that if you are using TypeScript syntax (and not just the TypeScript
flavor of JSDoc which mode
set to "typescript" implies), you may wish
to use the recommended-typescript
or recommended-typescript-error
config. This will add rules such as jsdoc/no-types
to expect you have
no types expressed in JSDoc (since these can be added in TypeScript).
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
- an optional key
skipRootChecking
(forcheck-types
) to allow for this type in the context of a root (i.e., a parent object of some child type)
- 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."namepath-or-url-referencing"
- For inline tags which may point to a namepath or URL.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.
"typeOrNameRequired"
- 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):
settings.jsdoc.contexts
can be used as the default for any rules
with a contexts
property option. Please note: This will replace any
default contexts, including for function rules, so if, for example, you exclude
FunctionDeclaration
here, rules like require-param
will not check
function declarations.
See the "AST and Selectors" section for more on this format.