eslint-plugin-jsdoc 56.0.0 → 56.0.2

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.
Files changed (79) hide show
  1. package/dist/cjs/getJsdocProcessorPlugin.d.cts +5 -1
  2. package/dist/cjs/iterateJsdoc.d.cts +6 -2
  3. package/dist/getJsdocProcessorPlugin.cts +3 -1
  4. package/dist/iterateJsdoc.cts +9 -4
  5. package/package.json +4 -4
  6. package/src/getJsdocProcessorPlugin.cts +3 -1
  7. package/src/iterateJsdoc.cts +9 -4
  8. package/dist/cjs/WarnSettings.js +0 -30
  9. package/dist/cjs/alignTransform.js +0 -285
  10. package/dist/cjs/defaultTagOrder.js +0 -152
  11. package/dist/cjs/exportParser.js +0 -754
  12. package/dist/cjs/getDefaultTagStructureForMode.js +0 -840
  13. package/dist/cjs/getJsdocProcessorPlugin.cjs +0 -4
  14. package/dist/cjs/getJsdocProcessorPlugin.js +0 -553
  15. package/dist/cjs/index-cjs.js +0 -492
  16. package/dist/cjs/index.cjs.cjs +0 -6
  17. package/dist/cjs/iterateJsdoc.cjs +0 -38
  18. package/dist/cjs/iterateJsdoc.js +0 -1981
  19. package/dist/cjs/jsdocUtils.js +0 -1470
  20. package/dist/cjs/rules/checkAccess.js +0 -35
  21. package/dist/cjs/rules/checkAlignment.js +0 -63
  22. package/dist/cjs/rules/checkExamples.js +0 -486
  23. package/dist/cjs/rules/checkIndentation.js +0 -66
  24. package/dist/cjs/rules/checkLineAlignment.js +0 -297
  25. package/dist/cjs/rules/checkParamNames.js +0 -320
  26. package/dist/cjs/rules/checkPropertyNames.js +0 -105
  27. package/dist/cjs/rules/checkSyntax.js +0 -27
  28. package/dist/cjs/rules/checkTagNames.js +0 -252
  29. package/dist/cjs/rules/checkTemplateNames.js +0 -189
  30. package/dist/cjs/rules/checkTypes.js +0 -421
  31. package/dist/cjs/rules/checkValues.js +0 -163
  32. package/dist/cjs/rules/convertToJsdocComments.js +0 -313
  33. package/dist/cjs/rules/emptyTags.js +0 -79
  34. package/dist/cjs/rules/implementsOnClasses.js +0 -63
  35. package/dist/cjs/rules/importsAsDependencies.js +0 -105
  36. package/dist/cjs/rules/informativeDocs.js +0 -153
  37. package/dist/cjs/rules/linesBeforeBlock.js +0 -106
  38. package/dist/cjs/rules/matchDescription.js +0 -240
  39. package/dist/cjs/rules/matchName.js +0 -122
  40. package/dist/cjs/rules/multilineBlocks.js +0 -339
  41. package/dist/cjs/rules/noBadBlocks.js +0 -88
  42. package/dist/cjs/rules/noBlankBlockDescriptions.js +0 -56
  43. package/dist/cjs/rules/noBlankBlocks.js +0 -41
  44. package/dist/cjs/rules/noDefaults.js +0 -84
  45. package/dist/cjs/rules/noMissingSyntax.js +0 -164
  46. package/dist/cjs/rules/noMultiAsterisks.js +0 -83
  47. package/dist/cjs/rules/noRestrictedSyntax.js +0 -75
  48. package/dist/cjs/rules/noTypes.js +0 -88
  49. package/dist/cjs/rules/noUndefinedTypes.js +0 -451
  50. package/dist/cjs/rules/requireAsteriskPrefix.js +0 -144
  51. package/dist/cjs/rules/requireDescription.js +0 -136
  52. package/dist/cjs/rules/requireDescriptionCompleteSentence.js +0 -258
  53. package/dist/cjs/rules/requireExample.js +0 -103
  54. package/dist/cjs/rules/requireFileOverview.js +0 -117
  55. package/dist/cjs/rules/requireHyphenBeforeParamDescription.js +0 -144
  56. package/dist/cjs/rules/requireJsdoc.js +0 -629
  57. package/dist/cjs/rules/requireParam.js +0 -480
  58. package/dist/cjs/rules/requireParamDescription.js +0 -77
  59. package/dist/cjs/rules/requireParamName.js +0 -52
  60. package/dist/cjs/rules/requireParamType.js +0 -77
  61. package/dist/cjs/rules/requireProperty.js +0 -44
  62. package/dist/cjs/rules/requirePropertyDescription.js +0 -22
  63. package/dist/cjs/rules/requirePropertyName.js +0 -22
  64. package/dist/cjs/rules/requirePropertyType.js +0 -22
  65. package/dist/cjs/rules/requireReturns.js +0 -197
  66. package/dist/cjs/rules/requireReturnsCheck.js +0 -108
  67. package/dist/cjs/rules/requireReturnsDescription.js +0 -58
  68. package/dist/cjs/rules/requireReturnsType.js +0 -52
  69. package/dist/cjs/rules/requireTemplate.js +0 -173
  70. package/dist/cjs/rules/requireThrows.js +0 -101
  71. package/dist/cjs/rules/requireYields.js +0 -172
  72. package/dist/cjs/rules/requireYieldsCheck.js +0 -164
  73. package/dist/cjs/rules/sortTags.js +0 -392
  74. package/dist/cjs/rules/tagLines.js +0 -259
  75. package/dist/cjs/rules/textEscaping.js +0 -125
  76. package/dist/cjs/rules/typeFormatting.js +0 -328
  77. package/dist/cjs/rules/validTypes.js +0 -333
  78. package/dist/cjs/tagNames.js +0 -209
  79. package/dist/cjs/utils/hasReturnValue.js +0 -469
@@ -1,153 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const iterateJsdoc_js_1 = __importDefault(require("../iterateJsdoc.js"));
7
- const are_docs_informative_1 = require("are-docs-informative");
8
- const defaultAliases = {
9
- a: [
10
- 'an', 'our',
11
- ],
12
- };
13
- const defaultUselessWords = [
14
- 'a', 'an', 'i', 'in', 'of', 's', 'the',
15
- ];
16
- /* eslint-disable complexity -- Temporary */
17
- /**
18
- * @param {import('eslint').Rule.Node|import('@typescript-eslint/types').TSESTree.Node|null|undefined} node
19
- * @returns {string[]}
20
- */
21
- const getNamesFromNode = (node) => {
22
- switch (node?.type) {
23
- case 'AccessorProperty':
24
- case 'MethodDefinition':
25
- case 'PropertyDefinition':
26
- case 'TSAbstractAccessorProperty':
27
- case 'TSAbstractMethodDefinition':
28
- case 'TSAbstractPropertyDefinition':
29
- return [
30
- ...getNamesFromNode(
31
- /** @type {import('@typescript-eslint/types').TSESTree.Node} */ (node.parent).parent),
32
- ...getNamesFromNode(
33
- /** @type {import('@typescript-eslint/types').TSESTree.Node} */
34
- (node.key)),
35
- ];
36
- case 'ClassDeclaration':
37
- case 'ClassExpression':
38
- case 'FunctionDeclaration':
39
- case 'FunctionExpression':
40
- case 'TSDeclareFunction':
41
- case 'TSEnumDeclaration':
42
- case 'TSEnumMember':
43
- case 'TSInterfaceDeclaration':
44
- case 'TSMethodSignature':
45
- case 'TSModuleDeclaration':
46
- case 'TSTypeAliasDeclaration':
47
- return getNamesFromNode(
48
- /** @type {import('@typescript-eslint/types').TSESTree.ClassDeclaration} */
49
- (node).id);
50
- case 'ExportDefaultDeclaration':
51
- case 'ExportNamedDeclaration':
52
- return getNamesFromNode(
53
- /** @type {import('@typescript-eslint/types').TSESTree.ExportNamedDeclaration} */
54
- (node).declaration);
55
- case 'Identifier':
56
- return [
57
- node.name,
58
- ];
59
- case 'Property':
60
- return getNamesFromNode(
61
- /** @type {import('@typescript-eslint/types').TSESTree.Node} */
62
- (node.key));
63
- case 'VariableDeclaration':
64
- return getNamesFromNode(
65
- /** @type {import('@typescript-eslint/types').TSESTree.Node} */
66
- (node.declarations[0]));
67
- case 'VariableDeclarator':
68
- return [
69
- ...getNamesFromNode(
70
- /** @type {import('@typescript-eslint/types').TSESTree.Node} */
71
- (node.id)),
72
- ...getNamesFromNode(
73
- /** @type {import('@typescript-eslint/types').TSESTree.Node} */
74
- (node.init)),
75
- ].filter(Boolean);
76
- default:
77
- return [];
78
- }
79
- };
80
- /* eslint-enable complexity -- Temporary */
81
- exports.default = (0, iterateJsdoc_js_1.default)(({ context, jsdoc, node, report, utils, }) => {
82
- const /** @type {{aliases: {[key: string]: string[]}, excludedTags: string[], uselessWords: string[]}} */ { aliases = defaultAliases, excludedTags = [], uselessWords = defaultUselessWords, } = context.options[0] || {};
83
- const nodeNames = getNamesFromNode(node);
84
- /**
85
- * @param {string} text
86
- * @param {string} extraName
87
- * @returns {boolean}
88
- */
89
- const descriptionIsRedundant = (text, extraName = '') => {
90
- const textTrimmed = text.trim();
91
- return Boolean(textTrimmed) && !(0, are_docs_informative_1.areDocsInformative)(textTrimmed, [
92
- extraName, nodeNames,
93
- ].filter(Boolean).join(' '), {
94
- aliases,
95
- uselessWords,
96
- });
97
- };
98
- const { description, lastDescriptionLine, } = utils.getDescription();
99
- let descriptionReported = false;
100
- for (const tag of jsdoc.tags) {
101
- if (excludedTags.includes(tag.tag)) {
102
- continue;
103
- }
104
- if (descriptionIsRedundant(tag.description, tag.name)) {
105
- utils.reportJSDoc('This tag description only repeats the name it describes.', tag);
106
- }
107
- descriptionReported ||= tag.description === description &&
108
- /** @type {import('comment-parser').Spec & {line: import('../iterateJsdoc.js').Integer}} */
109
- (tag).line === lastDescriptionLine;
110
- }
111
- if (!descriptionReported && descriptionIsRedundant(description)) {
112
- report('This description only repeats the name it describes.');
113
- }
114
- }, {
115
- iterateAllJsdocs: true,
116
- meta: {
117
- docs: {
118
- description: 'This rule reports doc comments that only restate their attached name.',
119
- url: 'https://github.com/gajus/eslint-plugin-jsdoc/blob/main/docs/rules/informative-docs.md#repos-sticky-header',
120
- },
121
- schema: [
122
- {
123
- additionalProperties: false,
124
- properties: {
125
- aliases: {
126
- patternProperties: {
127
- '.*': {
128
- items: {
129
- type: 'string',
130
- },
131
- type: 'array',
132
- },
133
- },
134
- },
135
- excludedTags: {
136
- items: {
137
- type: 'string',
138
- },
139
- type: 'array',
140
- },
141
- uselessWords: {
142
- items: {
143
- type: 'string',
144
- },
145
- type: 'array',
146
- },
147
- },
148
- type: 'object',
149
- },
150
- ],
151
- type: 'suggestion',
152
- },
153
- });
@@ -1,106 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const iterateJsdoc_js_1 = __importDefault(require("../iterateJsdoc.js"));
7
- /**
8
- * Punctuators that begin a logical group should not require a line before it skipped. Specifically
9
- * `[` starts an array, `{` starts an object or block, `(` starts a grouping, and `=` starts a
10
- * declaration (like a variable or a type alias).
11
- */
12
- const startPunctuators = new Set([
13
- '(', '=', '[', '{',
14
- ]);
15
- exports.default = (0, iterateJsdoc_js_1.default)(({ context, jsdocNode, report, sourceCode, utils, }) => {
16
- const { checkBlockStarts, excludedTags = [
17
- 'type',
18
- ], ignoreSameLine = true, ignoreSingleLines = true, lines = 1, } = context.options[0] || {};
19
- if (utils.hasATag(excludedTags)) {
20
- return;
21
- }
22
- const tokensBefore = sourceCode.getTokensBefore(jsdocNode, {
23
- includeComments: true,
24
- });
25
- const tokenBefore = tokensBefore.at(-1);
26
- if (!tokenBefore || (tokenBefore.type === 'Punctuator' &&
27
- !checkBlockStarts &&
28
- startPunctuators.has(tokenBefore.value))) {
29
- return;
30
- }
31
- if (tokenBefore.loc?.end?.line + lines >=
32
- /** @type {number} */
33
- (jsdocNode.loc?.start?.line)) {
34
- const startLine = jsdocNode.loc?.start?.line;
35
- const sameLine = tokenBefore.loc?.end?.line === startLine;
36
- if (sameLine && ignoreSameLine) {
37
- return;
38
- }
39
- if (ignoreSingleLines && jsdocNode.loc?.start.line === jsdocNode.loc?.end.line) {
40
- return;
41
- }
42
- /** @type {import('eslint').Rule.ReportFixer} */
43
- const fix = (fixer) => {
44
- let indent = '';
45
- if (sameLine) {
46
- const spaceDiff = /** @type {number} */ (jsdocNode.loc?.start?.column) -
47
- /** @type {number} */ (tokenBefore.loc?.end?.column);
48
- // @ts-expect-error Should be a comment
49
- indent = /** @type {import('estree').Comment} */ (jsdocNode).value.match(/^\*\n([\t ]*) \*/v)?.[1]?.slice(spaceDiff);
50
- if (!indent) {
51
- /** @type {import('eslint').AST.Token|import('estree').Comment|undefined} */
52
- let tokenPrior = tokenBefore;
53
- let startColumn;
54
- while (tokenPrior && tokenPrior?.loc?.start?.line === startLine) {
55
- startColumn = tokenPrior.loc?.start?.column;
56
- tokenPrior = tokensBefore.pop();
57
- }
58
- indent = ' '.repeat(
59
- /* c8 ignore next */
60
- /** @type {number} */ (startColumn ? startColumn - 1 : 0));
61
- }
62
- }
63
- return fixer.insertTextAfter(
64
- /** @type {import('eslint').AST.Token} */
65
- (tokenBefore), '\n'.repeat(lines) +
66
- (sameLine ? '\n' + indent : ''));
67
- };
68
- report(`Required ${lines} line(s) before JSDoc block`, fix);
69
- }
70
- }, {
71
- iterateAllJsdocs: true,
72
- meta: {
73
- docs: {
74
- description: 'Enforces minimum number of newlines before JSDoc comment blocks',
75
- url: 'https://github.com/gajus/eslint-plugin-jsdoc/blob/main/docs/rules/lines-before-block.md#repos-sticky-header',
76
- },
77
- fixable: 'code',
78
- schema: [
79
- {
80
- additionalProperties: false,
81
- properties: {
82
- checkBlockStarts: {
83
- type: 'boolean',
84
- },
85
- excludedTags: {
86
- items: {
87
- type: 'string',
88
- },
89
- type: 'array',
90
- },
91
- ignoreSameLine: {
92
- type: 'boolean',
93
- },
94
- ignoreSingleLines: {
95
- type: 'boolean',
96
- },
97
- lines: {
98
- type: 'integer',
99
- },
100
- },
101
- type: 'object',
102
- },
103
- ],
104
- type: 'suggestion',
105
- },
106
- });
@@ -1,240 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const iterateJsdoc_js_1 = __importDefault(require("../iterateJsdoc.js"));
7
- // If supporting Node >= 10, we could loosen the default to this for the
8
- // initial letter: \\p{Upper}
9
- const matchDescriptionDefault = '^\n?([A-Z`\\d_][\\s\\S]*[.?!`\\p{RGI_Emoji}]\\s*)?$';
10
- /**
11
- * @param {string} value
12
- * @param {string} userDefault
13
- * @returns {string}
14
- */
15
- const stringOrDefault = (value, userDefault) => {
16
- return typeof value === 'string' ?
17
- value :
18
- userDefault || matchDescriptionDefault;
19
- };
20
- exports.default = (0, iterateJsdoc_js_1.default)(({ context, jsdoc, report, utils, }) => {
21
- const { mainDescription, matchDescription, message, nonemptyTags = true, tags = {}, } = context.options[0] || {};
22
- /**
23
- * @param {string} desc
24
- * @param {import('comment-parser').Spec} [tag]
25
- * @returns {void}
26
- */
27
- const validateDescription = (desc, tag) => {
28
- let mainDescriptionMatch = mainDescription;
29
- let errorMessage = message;
30
- if (typeof mainDescription === 'object') {
31
- mainDescriptionMatch = mainDescription.match;
32
- errorMessage = mainDescription.message;
33
- }
34
- if (mainDescriptionMatch === false && (!tag || !Object.hasOwn(tags, tag.tag))) {
35
- return;
36
- }
37
- let tagValue = mainDescriptionMatch;
38
- if (tag) {
39
- const tagName = tag.tag;
40
- if (typeof tags[tagName] === 'object') {
41
- tagValue = tags[tagName].match;
42
- errorMessage = tags[tagName].message;
43
- }
44
- else {
45
- tagValue = tags[tagName];
46
- }
47
- }
48
- const regex = utils.getRegexFromString(stringOrDefault(tagValue, matchDescription));
49
- if (!regex.test(desc)) {
50
- report(errorMessage || 'JSDoc description does not satisfy the regex pattern.', null, tag || {
51
- // Add one as description would typically be into block
52
- line: jsdoc.source[0].number + 1,
53
- });
54
- }
55
- };
56
- const { description, } = utils.getDescription();
57
- if (description) {
58
- validateDescription(description);
59
- }
60
- /**
61
- * @param {string} tagName
62
- * @returns {boolean}
63
- */
64
- const hasNoTag = (tagName) => {
65
- return !tags[tagName];
66
- };
67
- for (const tag of [
68
- 'description',
69
- 'summary',
70
- 'file',
71
- 'classdesc',
72
- ]) {
73
- utils.forEachPreferredTag(tag, (matchingJsdocTag, targetTagName) => {
74
- const desc = (matchingJsdocTag.name + ' ' + utils.getTagDescription(matchingJsdocTag)).trim();
75
- if (hasNoTag(targetTagName)) {
76
- validateDescription(desc, matchingJsdocTag);
77
- }
78
- }, true);
79
- }
80
- if (nonemptyTags) {
81
- for (const tag of [
82
- 'copyright',
83
- 'example',
84
- 'see',
85
- 'todo',
86
- ]) {
87
- utils.forEachPreferredTag(tag, (matchingJsdocTag, targetTagName) => {
88
- const desc = (matchingJsdocTag.name + ' ' + utils.getTagDescription(matchingJsdocTag)).trim();
89
- if (hasNoTag(targetTagName) && !(/.+/v).test(desc)) {
90
- report('JSDoc description must not be empty.', null, matchingJsdocTag);
91
- }
92
- });
93
- }
94
- }
95
- if (!Object.keys(tags).length) {
96
- return;
97
- }
98
- /**
99
- * @param {string} tagName
100
- * @returns {boolean}
101
- */
102
- const hasOptionTag = (tagName) => {
103
- return Boolean(tags[tagName]);
104
- };
105
- const whitelistedTags = utils.filterTags(({ tag: tagName, }) => {
106
- return hasOptionTag(tagName);
107
- });
108
- const { tagsWithNames, tagsWithoutNames, } = utils.getTagsByType(whitelistedTags);
109
- tagsWithNames.some((tag) => {
110
- const desc = /** @type {string} */ (utils.getTagDescription(tag)).replace(/^[\- ]*/v, '')
111
- .trim();
112
- return validateDescription(desc, tag);
113
- });
114
- tagsWithoutNames.some((tag) => {
115
- const desc = (tag.name + ' ' + utils.getTagDescription(tag)).trim();
116
- return validateDescription(desc, tag);
117
- });
118
- }, {
119
- contextDefaults: true,
120
- meta: {
121
- docs: {
122
- description: 'Enforces a regular expression pattern on descriptions.',
123
- url: 'https://github.com/gajus/eslint-plugin-jsdoc/blob/main/docs/rules/match-description.md#repos-sticky-header',
124
- },
125
- schema: [
126
- {
127
- additionalProperties: false,
128
- properties: {
129
- contexts: {
130
- items: {
131
- anyOf: [
132
- {
133
- type: 'string',
134
- },
135
- {
136
- additionalProperties: false,
137
- properties: {
138
- comment: {
139
- type: 'string',
140
- },
141
- context: {
142
- type: 'string',
143
- },
144
- },
145
- type: 'object',
146
- },
147
- ],
148
- },
149
- type: 'array',
150
- },
151
- mainDescription: {
152
- oneOf: [
153
- {
154
- format: 'regex',
155
- type: 'string',
156
- },
157
- {
158
- type: 'boolean',
159
- },
160
- {
161
- additionalProperties: false,
162
- properties: {
163
- match: {
164
- oneOf: [
165
- {
166
- format: 'regex',
167
- type: 'string',
168
- },
169
- {
170
- type: 'boolean',
171
- },
172
- ],
173
- },
174
- message: {
175
- type: 'string',
176
- },
177
- },
178
- type: 'object',
179
- },
180
- ],
181
- },
182
- matchDescription: {
183
- format: 'regex',
184
- type: 'string',
185
- },
186
- message: {
187
- type: 'string',
188
- },
189
- nonemptyTags: {
190
- type: 'boolean',
191
- },
192
- tags: {
193
- patternProperties: {
194
- '.*': {
195
- oneOf: [
196
- {
197
- format: 'regex',
198
- type: 'string',
199
- },
200
- {
201
- enum: [
202
- true,
203
- ],
204
- type: 'boolean',
205
- },
206
- {
207
- additionalProperties: false,
208
- properties: {
209
- match: {
210
- oneOf: [
211
- {
212
- format: 'regex',
213
- type: 'string',
214
- },
215
- {
216
- enum: [
217
- true,
218
- ],
219
- type: 'boolean',
220
- },
221
- ],
222
- },
223
- message: {
224
- type: 'string',
225
- },
226
- },
227
- type: 'object',
228
- },
229
- ],
230
- },
231
- },
232
- type: 'object',
233
- },
234
- },
235
- type: 'object',
236
- },
237
- ],
238
- type: 'suggestion',
239
- },
240
- });
@@ -1,122 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const iterateJsdoc_js_1 = __importDefault(require("../iterateJsdoc.js"));
7
- // eslint-disable-next-line complexity
8
- exports.default = (0, iterateJsdoc_js_1.default)(({ context, info: { lastIndex, }, jsdoc, report, utils, }) => {
9
- const { match, } = context.options[0] || {};
10
- if (!match) {
11
- report('Rule `no-restricted-syntax` is missing a `match` option.');
12
- return;
13
- }
14
- const { allowName, disallowName, replacement, tags = [
15
- '*',
16
- ], } = match[ /** @type {import('../iterateJsdoc.js').Integer} */(lastIndex)];
17
- const allowNameRegex = allowName && utils.getRegexFromString(allowName);
18
- const disallowNameRegex = disallowName && utils.getRegexFromString(disallowName);
19
- let applicableTags = jsdoc.tags;
20
- if (!tags.includes('*')) {
21
- applicableTags = utils.getPresentTags(tags);
22
- }
23
- let reported = false;
24
- for (const tag of applicableTags) {
25
- const tagName = tag.name.replace(/^\[/v, '').replace(/(=.*)?\]$/v, '');
26
- const allowed = !allowNameRegex || allowNameRegex.test(tagName);
27
- const disallowed = disallowNameRegex && disallowNameRegex.test(tagName);
28
- const hasRegex = allowNameRegex || disallowNameRegex;
29
- if (hasRegex && allowed && !disallowed) {
30
- continue;
31
- }
32
- if (!hasRegex && reported) {
33
- continue;
34
- }
35
- const fixer = () => {
36
- for (const src of tag.source) {
37
- if (src.tokens.name) {
38
- src.tokens.name = src.tokens.name.replace(disallowNameRegex, replacement);
39
- break;
40
- }
41
- }
42
- };
43
- let { message, } = match[ /** @type {import('../iterateJsdoc.js').Integer} */(lastIndex)];
44
- if (!message) {
45
- if (hasRegex) {
46
- message = disallowed ?
47
- `Only allowing names not matching \`${disallowNameRegex}\` but found "${tagName}".` :
48
- `Only allowing names matching \`${allowNameRegex}\` but found "${tagName}".`;
49
- }
50
- else {
51
- message = `Prohibited context for "${tagName}".`;
52
- }
53
- }
54
- utils.reportJSDoc(message, hasRegex ? tag : null,
55
- // We could match up
56
- disallowNameRegex && replacement !== undefined ?
57
- fixer :
58
- null, false, {
59
- // Could also supply `context`, `comment`, `tags`
60
- allowName,
61
- disallowName,
62
- name: tagName,
63
- });
64
- if (!hasRegex) {
65
- reported = true;
66
- }
67
- }
68
- }, {
69
- matchContext: true,
70
- meta: {
71
- docs: {
72
- description: 'Reports the name portion of a JSDoc tag if matching or not matching a given regular expression.',
73
- url: 'https://github.com/gajus/eslint-plugin-jsdoc/blob/main/docs/rules/match-name.md#repos-sticky-header',
74
- },
75
- fixable: 'code',
76
- schema: [
77
- {
78
- additionalProperties: false,
79
- properties: {
80
- match: {
81
- items: {
82
- additionalProperties: false,
83
- properties: {
84
- allowName: {
85
- type: 'string',
86
- },
87
- comment: {
88
- type: 'string',
89
- },
90
- context: {
91
- type: 'string',
92
- },
93
- disallowName: {
94
- type: 'string',
95
- },
96
- message: {
97
- type: 'string',
98
- },
99
- replacement: {
100
- type: 'string',
101
- },
102
- tags: {
103
- items: {
104
- type: 'string',
105
- },
106
- type: 'array',
107
- },
108
- },
109
- type: 'object',
110
- },
111
- type: 'array',
112
- },
113
- },
114
- required: [
115
- 'match',
116
- ],
117
- type: 'object',
118
- },
119
- ],
120
- type: 'suggestion',
121
- },
122
- });