eslint-plugin-jsdoc 48.0.0 → 48.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/WarnSettings.js +34 -0
- package/src/alignTransform.js +356 -0
- package/src/defaultTagOrder.js +168 -0
- package/src/exportParser.js +957 -0
- package/src/getDefaultTagStructureForMode.js +969 -0
- package/src/index.js +266 -0
- package/src/iterateJsdoc.js +2555 -0
- package/src/jsdocUtils.js +1693 -0
- package/src/rules/checkAccess.js +45 -0
- package/src/rules/checkAlignment.js +63 -0
- package/src/rules/checkExamples.js +594 -0
- package/src/rules/checkIndentation.js +75 -0
- package/src/rules/checkLineAlignment.js +364 -0
- package/src/rules/checkParamNames.js +404 -0
- package/src/rules/checkPropertyNames.js +152 -0
- package/src/rules/checkSyntax.js +30 -0
- package/src/rules/checkTagNames.js +314 -0
- package/src/rules/checkTypes.js +535 -0
- package/src/rules/checkValues.js +220 -0
- package/src/rules/emptyTags.js +88 -0
- package/src/rules/implementsOnClasses.js +64 -0
- package/src/rules/importsAsDependencies.js +131 -0
- package/src/rules/informativeDocs.js +182 -0
- package/src/rules/matchDescription.js +286 -0
- package/src/rules/matchName.js +147 -0
- package/src/rules/multilineBlocks.js +333 -0
- package/src/rules/noBadBlocks.js +109 -0
- package/src/rules/noBlankBlockDescriptions.js +69 -0
- package/src/rules/noBlankBlocks.js +53 -0
- package/src/rules/noDefaults.js +85 -0
- package/src/rules/noMissingSyntax.js +195 -0
- package/src/rules/noMultiAsterisks.js +134 -0
- package/src/rules/noRestrictedSyntax.js +91 -0
- package/src/rules/noTypes.js +73 -0
- package/src/rules/noUndefinedTypes.js +328 -0
- package/src/rules/requireAsteriskPrefix.js +189 -0
- package/src/rules/requireDescription.js +161 -0
- package/src/rules/requireDescriptionCompleteSentence.js +333 -0
- package/src/rules/requireExample.js +118 -0
- package/src/rules/requireFileOverview.js +154 -0
- package/src/rules/requireHyphenBeforeParamDescription.js +178 -0
- package/src/rules/requireJsdoc.js +629 -0
- package/src/rules/requireParam.js +592 -0
- package/src/rules/requireParamDescription.js +89 -0
- package/src/rules/requireParamName.js +55 -0
- package/src/rules/requireParamType.js +89 -0
- package/src/rules/requireProperty.js +48 -0
- package/src/rules/requirePropertyDescription.js +25 -0
- package/src/rules/requirePropertyName.js +25 -0
- package/src/rules/requirePropertyType.js +25 -0
- package/src/rules/requireReturns.js +238 -0
- package/src/rules/requireReturnsCheck.js +141 -0
- package/src/rules/requireReturnsDescription.js +59 -0
- package/src/rules/requireReturnsType.js +51 -0
- package/src/rules/requireThrows.js +111 -0
- package/src/rules/requireYields.js +216 -0
- package/src/rules/requireYieldsCheck.js +208 -0
- package/src/rules/sortTags.js +557 -0
- package/src/rules/tagLines.js +359 -0
- package/src/rules/textEscaping.js +146 -0
- package/src/rules/validTypes.js +368 -0
- package/src/tagNames.js +234 -0
- package/src/utils/hasReturnValue.js +549 -0
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
import iterateJsdoc from '../iterateJsdoc.js';
|
|
2
|
+
import semver from 'semver';
|
|
3
|
+
import spdxExpressionParse from 'spdx-expression-parse';
|
|
4
|
+
|
|
5
|
+
const allowedKinds = new Set([
|
|
6
|
+
'class',
|
|
7
|
+
'constant',
|
|
8
|
+
'event',
|
|
9
|
+
'external',
|
|
10
|
+
'file',
|
|
11
|
+
'function',
|
|
12
|
+
'member',
|
|
13
|
+
'mixin',
|
|
14
|
+
'module',
|
|
15
|
+
'namespace',
|
|
16
|
+
'typedef',
|
|
17
|
+
]);
|
|
18
|
+
|
|
19
|
+
export default iterateJsdoc(({
|
|
20
|
+
utils,
|
|
21
|
+
report,
|
|
22
|
+
context,
|
|
23
|
+
}) => {
|
|
24
|
+
const options = context.options[0] || {};
|
|
25
|
+
const {
|
|
26
|
+
allowedLicenses = null,
|
|
27
|
+
allowedAuthors = null,
|
|
28
|
+
numericOnlyVariation = false,
|
|
29
|
+
licensePattern = '/([^\n\r]*)/gu',
|
|
30
|
+
} = options;
|
|
31
|
+
|
|
32
|
+
utils.forEachPreferredTag('version', (jsdocParameter, targetTagName) => {
|
|
33
|
+
const version = /** @type {string} */ (
|
|
34
|
+
utils.getTagDescription(jsdocParameter)
|
|
35
|
+
).trim();
|
|
36
|
+
if (!version) {
|
|
37
|
+
report(
|
|
38
|
+
`Missing JSDoc @${targetTagName} value.`,
|
|
39
|
+
null,
|
|
40
|
+
jsdocParameter,
|
|
41
|
+
);
|
|
42
|
+
} else if (!semver.valid(version)) {
|
|
43
|
+
report(
|
|
44
|
+
`Invalid JSDoc @${targetTagName}: "${utils.getTagDescription(jsdocParameter)}".`,
|
|
45
|
+
null,
|
|
46
|
+
jsdocParameter,
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
utils.forEachPreferredTag('kind', (jsdocParameter, targetTagName) => {
|
|
52
|
+
const kind = /** @type {string} */ (
|
|
53
|
+
utils.getTagDescription(jsdocParameter)
|
|
54
|
+
).trim();
|
|
55
|
+
if (!kind) {
|
|
56
|
+
report(
|
|
57
|
+
`Missing JSDoc @${targetTagName} value.`,
|
|
58
|
+
null,
|
|
59
|
+
jsdocParameter,
|
|
60
|
+
);
|
|
61
|
+
} else if (!allowedKinds.has(kind)) {
|
|
62
|
+
report(
|
|
63
|
+
`Invalid JSDoc @${targetTagName}: "${utils.getTagDescription(jsdocParameter)}"; ` +
|
|
64
|
+
`must be one of: ${[
|
|
65
|
+
...allowedKinds,
|
|
66
|
+
].join(', ')}.`,
|
|
67
|
+
null,
|
|
68
|
+
jsdocParameter,
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
if (numericOnlyVariation) {
|
|
74
|
+
utils.forEachPreferredTag('variation', (jsdocParameter, targetTagName) => {
|
|
75
|
+
const variation = /** @type {string} */ (
|
|
76
|
+
utils.getTagDescription(jsdocParameter)
|
|
77
|
+
).trim();
|
|
78
|
+
if (!variation) {
|
|
79
|
+
report(
|
|
80
|
+
`Missing JSDoc @${targetTagName} value.`,
|
|
81
|
+
null,
|
|
82
|
+
jsdocParameter,
|
|
83
|
+
);
|
|
84
|
+
} else if (
|
|
85
|
+
!Number.isInteger(Number(variation)) ||
|
|
86
|
+
Number(variation) <= 0
|
|
87
|
+
) {
|
|
88
|
+
report(
|
|
89
|
+
`Invalid JSDoc @${targetTagName}: "${utils.getTagDescription(jsdocParameter)}".`,
|
|
90
|
+
null,
|
|
91
|
+
jsdocParameter,
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
utils.forEachPreferredTag('since', (jsdocParameter, targetTagName) => {
|
|
98
|
+
const version = /** @type {string} */ (
|
|
99
|
+
utils.getTagDescription(jsdocParameter)
|
|
100
|
+
).trim();
|
|
101
|
+
if (!version) {
|
|
102
|
+
report(
|
|
103
|
+
`Missing JSDoc @${targetTagName} value.`,
|
|
104
|
+
null,
|
|
105
|
+
jsdocParameter,
|
|
106
|
+
);
|
|
107
|
+
} else if (!semver.valid(version)) {
|
|
108
|
+
report(
|
|
109
|
+
`Invalid JSDoc @${targetTagName}: "${utils.getTagDescription(jsdocParameter)}".`,
|
|
110
|
+
null,
|
|
111
|
+
jsdocParameter,
|
|
112
|
+
);
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
utils.forEachPreferredTag('license', (jsdocParameter, targetTagName) => {
|
|
116
|
+
const licenseRegex = utils.getRegexFromString(licensePattern, 'g');
|
|
117
|
+
const matches = /** @type {string} */ (
|
|
118
|
+
utils.getTagDescription(jsdocParameter)
|
|
119
|
+
).matchAll(licenseRegex);
|
|
120
|
+
let positiveMatch = false;
|
|
121
|
+
for (const match of matches) {
|
|
122
|
+
const license = match[1] || match[0];
|
|
123
|
+
if (license) {
|
|
124
|
+
positiveMatch = true;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
if (!license.trim()) {
|
|
128
|
+
// Avoid reporting again as empty match
|
|
129
|
+
if (positiveMatch) {
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
report(
|
|
134
|
+
`Missing JSDoc @${targetTagName} value.`,
|
|
135
|
+
null,
|
|
136
|
+
jsdocParameter,
|
|
137
|
+
);
|
|
138
|
+
} else if (allowedLicenses) {
|
|
139
|
+
if (allowedLicenses !== true && !allowedLicenses.includes(license)) {
|
|
140
|
+
report(
|
|
141
|
+
`Invalid JSDoc @${targetTagName}: "${license}"; expected one of ${allowedLicenses.join(', ')}.`,
|
|
142
|
+
null,
|
|
143
|
+
jsdocParameter,
|
|
144
|
+
);
|
|
145
|
+
}
|
|
146
|
+
} else {
|
|
147
|
+
try {
|
|
148
|
+
spdxExpressionParse(license);
|
|
149
|
+
} catch {
|
|
150
|
+
report(
|
|
151
|
+
`Invalid JSDoc @${targetTagName}: "${license}"; expected SPDX expression: https://spdx.org/licenses/.`,
|
|
152
|
+
null,
|
|
153
|
+
jsdocParameter,
|
|
154
|
+
);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
utils.forEachPreferredTag('author', (jsdocParameter, targetTagName) => {
|
|
161
|
+
const author = /** @type {string} */ (
|
|
162
|
+
utils.getTagDescription(jsdocParameter)
|
|
163
|
+
).trim();
|
|
164
|
+
if (!author) {
|
|
165
|
+
report(
|
|
166
|
+
`Missing JSDoc @${targetTagName} value.`,
|
|
167
|
+
null,
|
|
168
|
+
jsdocParameter,
|
|
169
|
+
);
|
|
170
|
+
} else if (allowedAuthors && !allowedAuthors.includes(author)) {
|
|
171
|
+
report(
|
|
172
|
+
`Invalid JSDoc @${targetTagName}: "${utils.getTagDescription(jsdocParameter)}"; expected one of ${allowedAuthors.join(', ')}.`,
|
|
173
|
+
null,
|
|
174
|
+
jsdocParameter,
|
|
175
|
+
);
|
|
176
|
+
}
|
|
177
|
+
});
|
|
178
|
+
}, {
|
|
179
|
+
iterateAllJsdocs: true,
|
|
180
|
+
meta: {
|
|
181
|
+
docs: {
|
|
182
|
+
description: 'This rule checks the values for a handful of tags: `@version`, `@since`, `@license` and `@author`.',
|
|
183
|
+
url: 'https://github.com/gajus/eslint-plugin-jsdoc/blob/main/docs/rules/check-values.md#repos-sticky-header',
|
|
184
|
+
},
|
|
185
|
+
schema: [
|
|
186
|
+
{
|
|
187
|
+
additionalProperties: false,
|
|
188
|
+
properties: {
|
|
189
|
+
allowedAuthors: {
|
|
190
|
+
items: {
|
|
191
|
+
type: 'string',
|
|
192
|
+
},
|
|
193
|
+
type: 'array',
|
|
194
|
+
},
|
|
195
|
+
allowedLicenses: {
|
|
196
|
+
anyOf: [
|
|
197
|
+
{
|
|
198
|
+
items: {
|
|
199
|
+
type: 'string',
|
|
200
|
+
},
|
|
201
|
+
type: 'array',
|
|
202
|
+
},
|
|
203
|
+
{
|
|
204
|
+
type: 'boolean',
|
|
205
|
+
},
|
|
206
|
+
],
|
|
207
|
+
},
|
|
208
|
+
licensePattern: {
|
|
209
|
+
type: 'string',
|
|
210
|
+
},
|
|
211
|
+
numericOnlyVariation: {
|
|
212
|
+
type: 'boolean',
|
|
213
|
+
},
|
|
214
|
+
},
|
|
215
|
+
type: 'object',
|
|
216
|
+
},
|
|
217
|
+
],
|
|
218
|
+
type: 'suggestion',
|
|
219
|
+
},
|
|
220
|
+
});
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import iterateJsdoc from '../iterateJsdoc.js';
|
|
2
|
+
|
|
3
|
+
const defaultEmptyTags = new Set([
|
|
4
|
+
'abstract', 'async', 'generator', 'global', 'hideconstructor',
|
|
5
|
+
'ignore', 'inner', 'instance', 'override', 'readonly',
|
|
6
|
+
|
|
7
|
+
// jsdoc doesn't use this form in its docs, but allow for compatibility with
|
|
8
|
+
// TypeScript which allows and Closure which requires
|
|
9
|
+
'inheritDoc',
|
|
10
|
+
|
|
11
|
+
// jsdoc doesn't use but allow for TypeScript
|
|
12
|
+
'internal',
|
|
13
|
+
'overload',
|
|
14
|
+
]);
|
|
15
|
+
|
|
16
|
+
const emptyIfNotClosure = new Set([
|
|
17
|
+
'package', 'private', 'protected', 'public', 'static',
|
|
18
|
+
|
|
19
|
+
// Closure doesn't allow with this casing
|
|
20
|
+
'inheritdoc',
|
|
21
|
+
]);
|
|
22
|
+
|
|
23
|
+
const emptyIfClosure = new Set([
|
|
24
|
+
'interface',
|
|
25
|
+
]);
|
|
26
|
+
|
|
27
|
+
export default iterateJsdoc(({
|
|
28
|
+
settings,
|
|
29
|
+
jsdoc,
|
|
30
|
+
utils,
|
|
31
|
+
}) => {
|
|
32
|
+
const emptyTags = utils.filterTags(({
|
|
33
|
+
tag: tagName,
|
|
34
|
+
}) => {
|
|
35
|
+
return defaultEmptyTags.has(tagName) ||
|
|
36
|
+
utils.hasOptionTag(tagName) && jsdoc.tags.some(({
|
|
37
|
+
tag,
|
|
38
|
+
}) => {
|
|
39
|
+
return tag === tagName;
|
|
40
|
+
}) ||
|
|
41
|
+
settings.mode === 'closure' && emptyIfClosure.has(tagName) ||
|
|
42
|
+
settings.mode !== 'closure' && emptyIfNotClosure.has(tagName);
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
for (const tag of emptyTags) {
|
|
46
|
+
const content = tag.name || tag.description || tag.type;
|
|
47
|
+
if (content.trim()) {
|
|
48
|
+
const fix = () => {
|
|
49
|
+
// By time of call in fixer, `tag` will have `line` added
|
|
50
|
+
utils.setTag(
|
|
51
|
+
/**
|
|
52
|
+
* @type {import('comment-parser').Spec & {
|
|
53
|
+
* line: import('../iterateJsdoc.js').Integer
|
|
54
|
+
* }}
|
|
55
|
+
*/ (tag),
|
|
56
|
+
);
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
utils.reportJSDoc(`@${tag.tag} should be empty.`, tag, fix, true);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}, {
|
|
63
|
+
checkInternal: true,
|
|
64
|
+
checkPrivate: true,
|
|
65
|
+
iterateAllJsdocs: true,
|
|
66
|
+
meta: {
|
|
67
|
+
docs: {
|
|
68
|
+
description: 'Expects specific tags to be empty of any content.',
|
|
69
|
+
url: 'https://github.com/gajus/eslint-plugin-jsdoc/blob/main/docs/rules/empty-tags.md#repos-sticky-header',
|
|
70
|
+
},
|
|
71
|
+
fixable: 'code',
|
|
72
|
+
schema: [
|
|
73
|
+
{
|
|
74
|
+
additionalProperties: false,
|
|
75
|
+
properties: {
|
|
76
|
+
tags: {
|
|
77
|
+
items: {
|
|
78
|
+
type: 'string',
|
|
79
|
+
},
|
|
80
|
+
type: 'array',
|
|
81
|
+
},
|
|
82
|
+
},
|
|
83
|
+
type: 'object',
|
|
84
|
+
},
|
|
85
|
+
],
|
|
86
|
+
type: 'suggestion',
|
|
87
|
+
},
|
|
88
|
+
});
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import iterateJsdoc from '../iterateJsdoc.js';
|
|
2
|
+
|
|
3
|
+
export default iterateJsdoc(({
|
|
4
|
+
report,
|
|
5
|
+
utils,
|
|
6
|
+
}) => {
|
|
7
|
+
const iteratingFunction = utils.isIteratingFunction();
|
|
8
|
+
|
|
9
|
+
if (iteratingFunction) {
|
|
10
|
+
if (utils.hasATag([
|
|
11
|
+
'class',
|
|
12
|
+
'constructor',
|
|
13
|
+
]) ||
|
|
14
|
+
utils.isConstructor()
|
|
15
|
+
) {
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
} else if (!utils.isVirtualFunction()) {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
utils.forEachPreferredTag('implements', (tag) => {
|
|
23
|
+
report('@implements used on a non-constructor function', null, tag);
|
|
24
|
+
});
|
|
25
|
+
}, {
|
|
26
|
+
contextDefaults: true,
|
|
27
|
+
meta: {
|
|
28
|
+
docs: {
|
|
29
|
+
description: 'Reports an issue with any non-constructor function using `@implements`.',
|
|
30
|
+
url: 'https://github.com/gajus/eslint-plugin-jsdoc/blob/main/docs/rules/implements-on-classes.md#repos-sticky-header',
|
|
31
|
+
},
|
|
32
|
+
schema: [
|
|
33
|
+
{
|
|
34
|
+
additionalProperties: false,
|
|
35
|
+
properties: {
|
|
36
|
+
contexts: {
|
|
37
|
+
items: {
|
|
38
|
+
anyOf: [
|
|
39
|
+
{
|
|
40
|
+
type: 'string',
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
additionalProperties: false,
|
|
44
|
+
properties: {
|
|
45
|
+
comment: {
|
|
46
|
+
type: 'string',
|
|
47
|
+
},
|
|
48
|
+
context: {
|
|
49
|
+
type: 'string',
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
type: 'object',
|
|
53
|
+
},
|
|
54
|
+
],
|
|
55
|
+
},
|
|
56
|
+
type: 'array',
|
|
57
|
+
},
|
|
58
|
+
},
|
|
59
|
+
type: 'object',
|
|
60
|
+
},
|
|
61
|
+
],
|
|
62
|
+
type: 'suggestion',
|
|
63
|
+
},
|
|
64
|
+
});
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import iterateJsdoc from '../iterateJsdoc.js';
|
|
2
|
+
import {
|
|
3
|
+
parse,
|
|
4
|
+
traverse,
|
|
5
|
+
tryParse,
|
|
6
|
+
} from '@es-joy/jsdoccomment';
|
|
7
|
+
import {
|
|
8
|
+
readFileSync,
|
|
9
|
+
} from 'fs';
|
|
10
|
+
import isBuiltinModule from 'is-builtin-module';
|
|
11
|
+
import {
|
|
12
|
+
join,
|
|
13
|
+
} from 'path';
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* @type {Set<string>|null}
|
|
17
|
+
*/
|
|
18
|
+
let deps;
|
|
19
|
+
|
|
20
|
+
const setDeps = function () {
|
|
21
|
+
try {
|
|
22
|
+
const pkg = JSON.parse(
|
|
23
|
+
// @ts-expect-error It's ok
|
|
24
|
+
readFileSync(join(process.cwd(), './package.json')),
|
|
25
|
+
);
|
|
26
|
+
deps = new Set([
|
|
27
|
+
...(pkg.dependencies ?
|
|
28
|
+
/* c8 ignore next 2 */
|
|
29
|
+
Object.keys(pkg.dependencies) :
|
|
30
|
+
[]),
|
|
31
|
+
...(pkg.devDependencies ?
|
|
32
|
+
/* c8 ignore next 2 */
|
|
33
|
+
Object.keys(pkg.devDependencies) :
|
|
34
|
+
[]),
|
|
35
|
+
]);
|
|
36
|
+
/* c8 ignore next -- our package.json exists */
|
|
37
|
+
} catch (error) {
|
|
38
|
+
/* c8 ignore next -- our package.json exists */
|
|
39
|
+
deps = null;
|
|
40
|
+
/* c8 ignore next 4 -- our package.json exists */
|
|
41
|
+
/* eslint-disable no-console -- Inform user */
|
|
42
|
+
console.log(error);
|
|
43
|
+
/* eslint-enable no-console -- Inform user */
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
const moduleCheck = new Map();
|
|
48
|
+
|
|
49
|
+
export default iterateJsdoc(({
|
|
50
|
+
jsdoc,
|
|
51
|
+
settings,
|
|
52
|
+
utils,
|
|
53
|
+
}) => {
|
|
54
|
+
if (deps === undefined) {
|
|
55
|
+
setDeps();
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/* c8 ignore next 3 -- our package.json exists */
|
|
59
|
+
if (deps === null) {
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const {
|
|
64
|
+
mode,
|
|
65
|
+
} = settings;
|
|
66
|
+
|
|
67
|
+
for (const tag of jsdoc.tags) {
|
|
68
|
+
let typeAst;
|
|
69
|
+
try {
|
|
70
|
+
typeAst = mode === 'permissive' ? tryParse(tag.type) : parse(tag.type, mode);
|
|
71
|
+
} catch {
|
|
72
|
+
continue;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// eslint-disable-next-line no-loop-func -- Safe
|
|
76
|
+
traverse(typeAst, (nde) => {
|
|
77
|
+
/* c8 ignore next 3 -- TS guard */
|
|
78
|
+
if (deps === null) {
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
if (nde.type === 'JsdocTypeImport') {
|
|
83
|
+
let mod = nde.element.value.replace(
|
|
84
|
+
/^(@[^/]+\/[^/]+|[^/]+).*$/u, '$1',
|
|
85
|
+
);
|
|
86
|
+
|
|
87
|
+
if ((/^[./]/u).test(mod)) {
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
if (isBuiltinModule(mod)) {
|
|
92
|
+
// mod = '@types/node';
|
|
93
|
+
// moduleCheck.set(mod, !deps.has(mod));
|
|
94
|
+
return;
|
|
95
|
+
} else if (!moduleCheck.has(mod)) {
|
|
96
|
+
let pkg;
|
|
97
|
+
try {
|
|
98
|
+
pkg = JSON.parse(
|
|
99
|
+
// @ts-expect-error It's ok
|
|
100
|
+
readFileSync(join(process.cwd(), 'node_modules', mod, './package.json')),
|
|
101
|
+
);
|
|
102
|
+
} catch {
|
|
103
|
+
// Ignore
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
if (!pkg || (!pkg.types && !pkg.typings)) {
|
|
107
|
+
mod = `@types/${mod}`;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
moduleCheck.set(mod, !deps.has(mod));
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
if (moduleCheck.get(mod)) {
|
|
114
|
+
utils.reportJSDoc(
|
|
115
|
+
'import points to package which is not found in dependencies',
|
|
116
|
+
tag,
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
}, {
|
|
123
|
+
iterateAllJsdocs: true,
|
|
124
|
+
meta: {
|
|
125
|
+
docs: {
|
|
126
|
+
description: 'Reports if JSDoc `import()` statements point to a package which is not listed in `dependencies` or `devDependencies`',
|
|
127
|
+
url: 'https://github.com/gajus/eslint-plugin-jsdoc/blob/main/docs/rules/imports-as-dependencies.md#repos-sticky-header',
|
|
128
|
+
},
|
|
129
|
+
type: 'suggestion',
|
|
130
|
+
},
|
|
131
|
+
});
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
import iterateJsdoc from '../iterateJsdoc.js';
|
|
2
|
+
import {
|
|
3
|
+
areDocsInformative,
|
|
4
|
+
} from 'are-docs-informative';
|
|
5
|
+
|
|
6
|
+
const defaultAliases = {
|
|
7
|
+
a: [
|
|
8
|
+
'an', 'our',
|
|
9
|
+
],
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
const defaultUselessWords = [
|
|
13
|
+
'a', 'an', 'i', 'in', 'of', 's', 'the',
|
|
14
|
+
];
|
|
15
|
+
|
|
16
|
+
/* eslint-disable complexity -- Temporary */
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* @param {import('eslint').Rule.Node|import('@typescript-eslint/types').TSESTree.Node|null|undefined} node
|
|
20
|
+
* @returns {string[]}
|
|
21
|
+
*/
|
|
22
|
+
const getNamesFromNode = (node) => {
|
|
23
|
+
switch (node?.type) {
|
|
24
|
+
case 'AccessorProperty':
|
|
25
|
+
case 'MethodDefinition':
|
|
26
|
+
case 'PropertyDefinition':
|
|
27
|
+
case 'TSAbstractAccessorProperty':
|
|
28
|
+
case 'TSAbstractMethodDefinition':
|
|
29
|
+
case 'TSAbstractPropertyDefinition':
|
|
30
|
+
return [
|
|
31
|
+
...getNamesFromNode(
|
|
32
|
+
/** @type {import('@typescript-eslint/types').TSESTree.Node} */ (
|
|
33
|
+
node.parent
|
|
34
|
+
).parent,
|
|
35
|
+
),
|
|
36
|
+
...getNamesFromNode(
|
|
37
|
+
/** @type {import('@typescript-eslint/types').TSESTree.Node} */
|
|
38
|
+
(node.key),
|
|
39
|
+
),
|
|
40
|
+
];
|
|
41
|
+
case 'ClassDeclaration':
|
|
42
|
+
case 'ClassExpression':
|
|
43
|
+
case 'FunctionDeclaration':
|
|
44
|
+
case 'FunctionExpression':
|
|
45
|
+
case 'TSModuleDeclaration':
|
|
46
|
+
case 'TSMethodSignature':
|
|
47
|
+
case 'TSDeclareFunction':
|
|
48
|
+
case 'TSEnumDeclaration':
|
|
49
|
+
case 'TSEnumMember':
|
|
50
|
+
case 'TSInterfaceDeclaration':
|
|
51
|
+
case 'TSTypeAliasDeclaration':
|
|
52
|
+
return getNamesFromNode(
|
|
53
|
+
/** @type {import('@typescript-eslint/types').TSESTree.ClassDeclaration} */
|
|
54
|
+
(node).id,
|
|
55
|
+
);
|
|
56
|
+
case 'Identifier':
|
|
57
|
+
return [
|
|
58
|
+
node.name,
|
|
59
|
+
];
|
|
60
|
+
case 'Property':
|
|
61
|
+
return getNamesFromNode(
|
|
62
|
+
/** @type {import('@typescript-eslint/types').TSESTree.Node} */
|
|
63
|
+
(node.key),
|
|
64
|
+
);
|
|
65
|
+
case 'VariableDeclaration':
|
|
66
|
+
return getNamesFromNode(
|
|
67
|
+
/** @type {import('@typescript-eslint/types').TSESTree.Node} */
|
|
68
|
+
(node.declarations[0]),
|
|
69
|
+
);
|
|
70
|
+
case 'VariableDeclarator':
|
|
71
|
+
return [
|
|
72
|
+
...getNamesFromNode(
|
|
73
|
+
/** @type {import('@typescript-eslint/types').TSESTree.Node} */
|
|
74
|
+
(node.id),
|
|
75
|
+
),
|
|
76
|
+
...getNamesFromNode(
|
|
77
|
+
/** @type {import('@typescript-eslint/types').TSESTree.Node} */
|
|
78
|
+
(node.init),
|
|
79
|
+
),
|
|
80
|
+
].filter(Boolean);
|
|
81
|
+
default:
|
|
82
|
+
return [];
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
/* eslint-enable complexity -- Temporary */
|
|
86
|
+
|
|
87
|
+
export default iterateJsdoc(({
|
|
88
|
+
context,
|
|
89
|
+
jsdoc,
|
|
90
|
+
node,
|
|
91
|
+
report,
|
|
92
|
+
utils,
|
|
93
|
+
}) => {
|
|
94
|
+
const /** @type {{aliases: {[key: string]: string[]}, excludedTags: string[], uselessWords: string[]}} */ {
|
|
95
|
+
aliases = defaultAliases,
|
|
96
|
+
excludedTags = [],
|
|
97
|
+
uselessWords = defaultUselessWords,
|
|
98
|
+
} = context.options[0] || {};
|
|
99
|
+
const nodeNames = getNamesFromNode(node);
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* @param {string} text
|
|
103
|
+
* @param {string} extraName
|
|
104
|
+
* @returns {boolean}
|
|
105
|
+
*/
|
|
106
|
+
const descriptionIsRedundant = (text, extraName = '') => {
|
|
107
|
+
const textTrimmed = text.trim();
|
|
108
|
+
return Boolean(textTrimmed) && !areDocsInformative(textTrimmed, [
|
|
109
|
+
extraName, nodeNames,
|
|
110
|
+
].filter(Boolean).join(' '), {
|
|
111
|
+
aliases,
|
|
112
|
+
uselessWords,
|
|
113
|
+
});
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
const {
|
|
117
|
+
description,
|
|
118
|
+
lastDescriptionLine,
|
|
119
|
+
} = utils.getDescription();
|
|
120
|
+
let descriptionReported = false;
|
|
121
|
+
|
|
122
|
+
for (const tag of jsdoc.tags) {
|
|
123
|
+
if (excludedTags.includes(tag.tag)) {
|
|
124
|
+
continue;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
if (descriptionIsRedundant(tag.description, tag.name)) {
|
|
128
|
+
utils.reportJSDoc(
|
|
129
|
+
'This tag description only repeats the name it describes.',
|
|
130
|
+
tag,
|
|
131
|
+
);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
descriptionReported ||= tag.description === description &&
|
|
135
|
+
/** @type {import('comment-parser').Spec & {line: import('../iterateJsdoc.js').Integer}} */
|
|
136
|
+
(tag).line === lastDescriptionLine;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
if (!descriptionReported && descriptionIsRedundant(description)) {
|
|
140
|
+
report('This description only repeats the name it describes.');
|
|
141
|
+
}
|
|
142
|
+
}, {
|
|
143
|
+
iterateAllJsdocs: true,
|
|
144
|
+
meta: {
|
|
145
|
+
docs: {
|
|
146
|
+
description:
|
|
147
|
+
'This rule reports doc comments that only restate their attached name.',
|
|
148
|
+
url: 'https://github.com/gajus/eslint-plugin-jsdoc/blob/main/docs/rules/informative-docs.md#repos-sticky-header',
|
|
149
|
+
},
|
|
150
|
+
schema: [
|
|
151
|
+
{
|
|
152
|
+
additionalProperties: false,
|
|
153
|
+
properties: {
|
|
154
|
+
aliases: {
|
|
155
|
+
patternProperties: {
|
|
156
|
+
'.*': {
|
|
157
|
+
items: {
|
|
158
|
+
type: 'string',
|
|
159
|
+
},
|
|
160
|
+
type: 'array',
|
|
161
|
+
},
|
|
162
|
+
},
|
|
163
|
+
},
|
|
164
|
+
excludedTags: {
|
|
165
|
+
items: {
|
|
166
|
+
type: 'string',
|
|
167
|
+
},
|
|
168
|
+
type: 'array',
|
|
169
|
+
},
|
|
170
|
+
uselessWords: {
|
|
171
|
+
items: {
|
|
172
|
+
type: 'string',
|
|
173
|
+
},
|
|
174
|
+
type: 'array',
|
|
175
|
+
},
|
|
176
|
+
},
|
|
177
|
+
type: 'object',
|
|
178
|
+
},
|
|
179
|
+
],
|
|
180
|
+
type: 'suggestion',
|
|
181
|
+
},
|
|
182
|
+
});
|