eslint 8.55.0 → 9.0.0-alpha.0

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 (54) hide show
  1. package/README.md +15 -15
  2. package/conf/rule-type-list.json +3 -1
  3. package/lib/api.js +1 -1
  4. package/lib/cli-engine/cli-engine.js +15 -4
  5. package/lib/cli-engine/formatters/formatters-meta.json +1 -29
  6. package/lib/cli.js +52 -10
  7. package/lib/config/default-config.js +3 -0
  8. package/lib/config/flat-config-array.js +0 -20
  9. package/lib/config/flat-config-helpers.js +41 -20
  10. package/lib/config/flat-config-schema.js +57 -26
  11. package/lib/config/rule-validator.js +27 -4
  12. package/lib/eslint/eslint-helpers.js +35 -22
  13. package/lib/eslint/eslint.js +856 -373
  14. package/lib/eslint/index.js +2 -2
  15. package/lib/eslint/legacy-eslint.js +722 -0
  16. package/lib/linter/apply-disable-directives.js +33 -5
  17. package/lib/linter/config-comment-parser.js +36 -2
  18. package/lib/linter/linter.js +100 -120
  19. package/lib/linter/rules.js +6 -15
  20. package/lib/options.js +17 -1
  21. package/lib/rule-tester/rule-tester.js +240 -272
  22. package/lib/rules/index.js +0 -2
  23. package/lib/rules/no-constant-binary-expression.js +1 -1
  24. package/lib/rules/no-constructor-return.js +1 -1
  25. package/lib/rules/no-empty-static-block.js +1 -1
  26. package/lib/rules/no-extra-semi.js +1 -1
  27. package/lib/rules/no-implicit-coercion.js +17 -1
  28. package/lib/rules/no-inner-declarations.js +1 -1
  29. package/lib/rules/no-invalid-regexp.js +1 -1
  30. package/lib/rules/no-invalid-this.js +1 -1
  31. package/lib/rules/no-mixed-spaces-and-tabs.js +1 -1
  32. package/lib/rules/no-new-native-nonconstructor.js +1 -1
  33. package/lib/rules/no-new-symbol.js +8 -1
  34. package/lib/rules/no-promise-executor-return.js +9 -6
  35. package/lib/rules/no-restricted-properties.js +15 -28
  36. package/lib/rules/no-sequences.js +1 -0
  37. package/lib/rules/no-unused-private-class-members.js +1 -1
  38. package/lib/shared/config-validator.js +44 -11
  39. package/lib/shared/severity.js +49 -0
  40. package/lib/shared/types.js +1 -1
  41. package/lib/source-code/source-code.js +3 -102
  42. package/lib/unsupported-api.js +3 -5
  43. package/package.json +12 -14
  44. package/lib/cli-engine/formatters/checkstyle.js +0 -60
  45. package/lib/cli-engine/formatters/compact.js +0 -60
  46. package/lib/cli-engine/formatters/jslint-xml.js +0 -41
  47. package/lib/cli-engine/formatters/junit.js +0 -82
  48. package/lib/cli-engine/formatters/tap.js +0 -95
  49. package/lib/cli-engine/formatters/unix.js +0 -58
  50. package/lib/cli-engine/formatters/visualstudio.js +0 -63
  51. package/lib/eslint/flat-eslint.js +0 -1149
  52. package/lib/rule-tester/flat-rule-tester.js +0 -1122
  53. package/lib/rules/require-jsdoc.js +0 -122
  54. package/lib/rules/valid-jsdoc.js +0 -516
@@ -1,122 +0,0 @@
1
- /**
2
- * @fileoverview Rule to check for jsdoc presence.
3
- * @author Gyandeep Singh
4
- * @deprecated in ESLint v5.10.0
5
- */
6
- "use strict";
7
-
8
- /** @type {import('../shared/types').Rule} */
9
- module.exports = {
10
- meta: {
11
- type: "suggestion",
12
-
13
- docs: {
14
- description: "Require JSDoc comments",
15
- recommended: false,
16
- url: "https://eslint.org/docs/latest/rules/require-jsdoc"
17
- },
18
-
19
- schema: [
20
- {
21
- type: "object",
22
- properties: {
23
- require: {
24
- type: "object",
25
- properties: {
26
- ClassDeclaration: {
27
- type: "boolean",
28
- default: false
29
- },
30
- MethodDefinition: {
31
- type: "boolean",
32
- default: false
33
- },
34
- FunctionDeclaration: {
35
- type: "boolean",
36
- default: true
37
- },
38
- ArrowFunctionExpression: {
39
- type: "boolean",
40
- default: false
41
- },
42
- FunctionExpression: {
43
- type: "boolean",
44
- default: false
45
- }
46
- },
47
- additionalProperties: false,
48
- default: {}
49
- }
50
- },
51
- additionalProperties: false
52
- }
53
- ],
54
-
55
- deprecated: true,
56
- replacedBy: [],
57
-
58
- messages: {
59
- missingJSDocComment: "Missing JSDoc comment."
60
- }
61
- },
62
-
63
- create(context) {
64
- const source = context.sourceCode;
65
- const DEFAULT_OPTIONS = {
66
- FunctionDeclaration: true,
67
- MethodDefinition: false,
68
- ClassDeclaration: false,
69
- ArrowFunctionExpression: false,
70
- FunctionExpression: false
71
- };
72
- const options = Object.assign(DEFAULT_OPTIONS, context.options[0] && context.options[0].require);
73
-
74
- /**
75
- * Report the error message
76
- * @param {ASTNode} node node to report
77
- * @returns {void}
78
- */
79
- function report(node) {
80
- context.report({ node, messageId: "missingJSDocComment" });
81
- }
82
-
83
- /**
84
- * Check if the jsdoc comment is present or not.
85
- * @param {ASTNode} node node to examine
86
- * @returns {void}
87
- */
88
- function checkJsDoc(node) {
89
- const jsdocComment = source.getJSDocComment(node);
90
-
91
- if (!jsdocComment) {
92
- report(node);
93
- }
94
- }
95
-
96
- return {
97
- FunctionDeclaration(node) {
98
- if (options.FunctionDeclaration) {
99
- checkJsDoc(node);
100
- }
101
- },
102
- FunctionExpression(node) {
103
- if (
104
- (options.MethodDefinition && node.parent.type === "MethodDefinition") ||
105
- (options.FunctionExpression && (node.parent.type === "VariableDeclarator" || (node.parent.type === "Property" && node === node.parent.value)))
106
- ) {
107
- checkJsDoc(node);
108
- }
109
- },
110
- ClassDeclaration(node) {
111
- if (options.ClassDeclaration) {
112
- checkJsDoc(node);
113
- }
114
- },
115
- ArrowFunctionExpression(node) {
116
- if (options.ArrowFunctionExpression && node.parent.type === "VariableDeclarator") {
117
- checkJsDoc(node);
118
- }
119
- }
120
- };
121
- }
122
- };
@@ -1,516 +0,0 @@
1
- /**
2
- * @fileoverview Validates JSDoc comments are syntactically correct
3
- * @author Nicholas C. Zakas
4
- * @deprecated in ESLint v5.10.0
5
- */
6
- "use strict";
7
-
8
- //------------------------------------------------------------------------------
9
- // Requirements
10
- //------------------------------------------------------------------------------
11
-
12
- const doctrine = require("doctrine");
13
-
14
- //------------------------------------------------------------------------------
15
- // Rule Definition
16
- //------------------------------------------------------------------------------
17
-
18
- /** @type {import('../shared/types').Rule} */
19
- module.exports = {
20
- meta: {
21
- type: "suggestion",
22
-
23
- docs: {
24
- description: "Enforce valid JSDoc comments",
25
- recommended: false,
26
- url: "https://eslint.org/docs/latest/rules/valid-jsdoc"
27
- },
28
-
29
- schema: [
30
- {
31
- type: "object",
32
- properties: {
33
- prefer: {
34
- type: "object",
35
- additionalProperties: {
36
- type: "string"
37
- }
38
- },
39
- preferType: {
40
- type: "object",
41
- additionalProperties: {
42
- type: "string"
43
- }
44
- },
45
- requireReturn: {
46
- type: "boolean",
47
- default: true
48
- },
49
- requireParamDescription: {
50
- type: "boolean",
51
- default: true
52
- },
53
- requireReturnDescription: {
54
- type: "boolean",
55
- default: true
56
- },
57
- matchDescription: {
58
- type: "string"
59
- },
60
- requireReturnType: {
61
- type: "boolean",
62
- default: true
63
- },
64
- requireParamType: {
65
- type: "boolean",
66
- default: true
67
- }
68
- },
69
- additionalProperties: false
70
- }
71
- ],
72
-
73
- fixable: "code",
74
- messages: {
75
- unexpectedTag: "Unexpected @{{title}} tag; function has no return statement.",
76
- expected: "Expected JSDoc for '{{name}}' but found '{{jsdocName}}'.",
77
- use: "Use @{{name}} instead.",
78
- useType: "Use '{{expectedTypeName}}' instead of '{{currentTypeName}}'.",
79
- syntaxError: "JSDoc syntax error.",
80
- missingBrace: "JSDoc type missing brace.",
81
- missingParamDesc: "Missing JSDoc parameter description for '{{name}}'.",
82
- missingParamType: "Missing JSDoc parameter type for '{{name}}'.",
83
- missingReturnType: "Missing JSDoc return type.",
84
- missingReturnDesc: "Missing JSDoc return description.",
85
- missingReturn: "Missing JSDoc @{{returns}} for function.",
86
- missingParam: "Missing JSDoc for parameter '{{name}}'.",
87
- duplicateParam: "Duplicate JSDoc parameter '{{name}}'.",
88
- unsatisfiedDesc: "JSDoc description does not satisfy the regex pattern."
89
- },
90
-
91
- deprecated: true,
92
- replacedBy: []
93
- },
94
-
95
- create(context) {
96
-
97
- const options = context.options[0] || {},
98
- prefer = options.prefer || {},
99
- sourceCode = context.sourceCode,
100
-
101
- // these both default to true, so you have to explicitly make them false
102
- requireReturn = options.requireReturn !== false,
103
- requireParamDescription = options.requireParamDescription !== false,
104
- requireReturnDescription = options.requireReturnDescription !== false,
105
- requireReturnType = options.requireReturnType !== false,
106
- requireParamType = options.requireParamType !== false,
107
- preferType = options.preferType || {},
108
- checkPreferType = Object.keys(preferType).length !== 0;
109
-
110
- //--------------------------------------------------------------------------
111
- // Helpers
112
- //--------------------------------------------------------------------------
113
-
114
- // Using a stack to store if a function returns or not (handling nested functions)
115
- const fns = [];
116
-
117
- /**
118
- * Check if node type is a Class
119
- * @param {ASTNode} node node to check.
120
- * @returns {boolean} True is its a class
121
- * @private
122
- */
123
- function isTypeClass(node) {
124
- return node.type === "ClassExpression" || node.type === "ClassDeclaration";
125
- }
126
-
127
- /**
128
- * When parsing a new function, store it in our function stack.
129
- * @param {ASTNode} node A function node to check.
130
- * @returns {void}
131
- * @private
132
- */
133
- function startFunction(node) {
134
- fns.push({
135
- returnPresent: (node.type === "ArrowFunctionExpression" && node.body.type !== "BlockStatement") ||
136
- isTypeClass(node) || node.async
137
- });
138
- }
139
-
140
- /**
141
- * Indicate that return has been found in the current function.
142
- * @param {ASTNode} node The return node.
143
- * @returns {void}
144
- * @private
145
- */
146
- function addReturn(node) {
147
- const functionState = fns[fns.length - 1];
148
-
149
- if (functionState && node.argument !== null) {
150
- functionState.returnPresent = true;
151
- }
152
- }
153
-
154
- /**
155
- * Check if return tag type is void or undefined
156
- * @param {Object} tag JSDoc tag
157
- * @returns {boolean} True if its of type void or undefined
158
- * @private
159
- */
160
- function isValidReturnType(tag) {
161
- return tag.type === null || tag.type.name === "void" || tag.type.type === "UndefinedLiteral";
162
- }
163
-
164
- /**
165
- * Check if type should be validated based on some exceptions
166
- * @param {Object} type JSDoc tag
167
- * @returns {boolean} True if it can be validated
168
- * @private
169
- */
170
- function canTypeBeValidated(type) {
171
- return type !== "UndefinedLiteral" && // {undefined} as there is no name property available.
172
- type !== "NullLiteral" && // {null}
173
- type !== "NullableLiteral" && // {?}
174
- type !== "FunctionType" && // {function(a)}
175
- type !== "AllLiteral"; // {*}
176
- }
177
-
178
- /**
179
- * Extract the current and expected type based on the input type object
180
- * @param {Object} type JSDoc tag
181
- * @returns {{currentType: Doctrine.Type, expectedTypeName: string}} The current type annotation and
182
- * the expected name of the annotation
183
- * @private
184
- */
185
- function getCurrentExpectedTypes(type) {
186
- let currentType;
187
-
188
- if (type.name) {
189
- currentType = type;
190
- } else if (type.expression) {
191
- currentType = type.expression;
192
- }
193
-
194
- return {
195
- currentType,
196
- expectedTypeName: currentType && preferType[currentType.name]
197
- };
198
- }
199
-
200
- /**
201
- * Gets the location of a JSDoc node in a file
202
- * @param {Token} jsdocComment The comment that this node is parsed from
203
- * @param {{range: number[]}} parsedJsdocNode A tag or other node which was parsed from this comment
204
- * @returns {{start: SourceLocation, end: SourceLocation}} The 0-based source location for the tag
205
- */
206
- function getAbsoluteRange(jsdocComment, parsedJsdocNode) {
207
- return {
208
- start: sourceCode.getLocFromIndex(jsdocComment.range[0] + 2 + parsedJsdocNode.range[0]),
209
- end: sourceCode.getLocFromIndex(jsdocComment.range[0] + 2 + parsedJsdocNode.range[1])
210
- };
211
- }
212
-
213
- /**
214
- * Validate type for a given JSDoc node
215
- * @param {Object} jsdocNode JSDoc node
216
- * @param {Object} type JSDoc tag
217
- * @returns {void}
218
- * @private
219
- */
220
- function validateType(jsdocNode, type) {
221
- if (!type || !canTypeBeValidated(type.type)) {
222
- return;
223
- }
224
-
225
- const typesToCheck = [];
226
- let elements = [];
227
-
228
- switch (type.type) {
229
- case "TypeApplication": // {Array.<String>}
230
- elements = type.applications[0].type === "UnionType" ? type.applications[0].elements : type.applications;
231
- typesToCheck.push(getCurrentExpectedTypes(type));
232
- break;
233
- case "RecordType": // {{20:String}}
234
- elements = type.fields;
235
- break;
236
- case "UnionType": // {String|number|Test}
237
- case "ArrayType": // {[String, number, Test]}
238
- elements = type.elements;
239
- break;
240
- case "FieldType": // Array.<{count: number, votes: number}>
241
- if (type.value) {
242
- typesToCheck.push(getCurrentExpectedTypes(type.value));
243
- }
244
- break;
245
- default:
246
- typesToCheck.push(getCurrentExpectedTypes(type));
247
- }
248
-
249
- elements.forEach(validateType.bind(null, jsdocNode));
250
-
251
- typesToCheck.forEach(typeToCheck => {
252
- if (typeToCheck.expectedTypeName &&
253
- typeToCheck.expectedTypeName !== typeToCheck.currentType.name) {
254
- context.report({
255
- node: jsdocNode,
256
- messageId: "useType",
257
- loc: getAbsoluteRange(jsdocNode, typeToCheck.currentType),
258
- data: {
259
- currentTypeName: typeToCheck.currentType.name,
260
- expectedTypeName: typeToCheck.expectedTypeName
261
- },
262
- fix(fixer) {
263
- return fixer.replaceTextRange(
264
- typeToCheck.currentType.range.map(indexInComment => jsdocNode.range[0] + 2 + indexInComment),
265
- typeToCheck.expectedTypeName
266
- );
267
- }
268
- });
269
- }
270
- });
271
- }
272
-
273
- /**
274
- * Validate the JSDoc node and output warnings if anything is wrong.
275
- * @param {ASTNode} node The AST node to check.
276
- * @returns {void}
277
- * @private
278
- */
279
- function checkJSDoc(node) {
280
- const jsdocNode = sourceCode.getJSDocComment(node),
281
- functionData = fns.pop(),
282
- paramTagsByName = Object.create(null),
283
- paramTags = [];
284
- let hasReturns = false,
285
- returnsTag,
286
- hasConstructor = false,
287
- isInterface = false,
288
- isOverride = false,
289
- isAbstract = false;
290
-
291
- // make sure only to validate JSDoc comments
292
- if (jsdocNode) {
293
- let jsdoc;
294
-
295
- try {
296
- jsdoc = doctrine.parse(jsdocNode.value, {
297
- strict: true,
298
- unwrap: true,
299
- sloppy: true,
300
- range: true
301
- });
302
- } catch (ex) {
303
-
304
- if (/braces/iu.test(ex.message)) {
305
- context.report({ node: jsdocNode, messageId: "missingBrace" });
306
- } else {
307
- context.report({ node: jsdocNode, messageId: "syntaxError" });
308
- }
309
-
310
- return;
311
- }
312
-
313
- jsdoc.tags.forEach(tag => {
314
-
315
- switch (tag.title.toLowerCase()) {
316
-
317
- case "param":
318
- case "arg":
319
- case "argument":
320
- paramTags.push(tag);
321
- break;
322
-
323
- case "return":
324
- case "returns":
325
- hasReturns = true;
326
- returnsTag = tag;
327
- break;
328
-
329
- case "constructor":
330
- case "class":
331
- hasConstructor = true;
332
- break;
333
-
334
- case "override":
335
- case "inheritdoc":
336
- isOverride = true;
337
- break;
338
-
339
- case "abstract":
340
- case "virtual":
341
- isAbstract = true;
342
- break;
343
-
344
- case "interface":
345
- isInterface = true;
346
- break;
347
-
348
- // no default
349
- }
350
-
351
- // check tag preferences
352
- if (Object.prototype.hasOwnProperty.call(prefer, tag.title) && tag.title !== prefer[tag.title]) {
353
- const entireTagRange = getAbsoluteRange(jsdocNode, tag);
354
-
355
- context.report({
356
- node: jsdocNode,
357
- messageId: "use",
358
- loc: {
359
- start: entireTagRange.start,
360
- end: {
361
- line: entireTagRange.start.line,
362
- column: entireTagRange.start.column + `@${tag.title}`.length
363
- }
364
- },
365
- data: { name: prefer[tag.title] },
366
- fix(fixer) {
367
- return fixer.replaceTextRange(
368
- [
369
- jsdocNode.range[0] + tag.range[0] + 3,
370
- jsdocNode.range[0] + tag.range[0] + tag.title.length + 3
371
- ],
372
- prefer[tag.title]
373
- );
374
- }
375
- });
376
- }
377
-
378
- // validate the types
379
- if (checkPreferType && tag.type) {
380
- validateType(jsdocNode, tag.type);
381
- }
382
- });
383
-
384
- paramTags.forEach(param => {
385
- if (requireParamType && !param.type) {
386
- context.report({
387
- node: jsdocNode,
388
- messageId: "missingParamType",
389
- loc: getAbsoluteRange(jsdocNode, param),
390
- data: { name: param.name }
391
- });
392
- }
393
- if (!param.description && requireParamDescription) {
394
- context.report({
395
- node: jsdocNode,
396
- messageId: "missingParamDesc",
397
- loc: getAbsoluteRange(jsdocNode, param),
398
- data: { name: param.name }
399
- });
400
- }
401
- if (paramTagsByName[param.name]) {
402
- context.report({
403
- node: jsdocNode,
404
- messageId: "duplicateParam",
405
- loc: getAbsoluteRange(jsdocNode, param),
406
- data: { name: param.name }
407
- });
408
- } else if (!param.name.includes(".")) {
409
- paramTagsByName[param.name] = param;
410
- }
411
- });
412
-
413
- if (hasReturns) {
414
- if (!requireReturn && !functionData.returnPresent && (returnsTag.type === null || !isValidReturnType(returnsTag)) && !isAbstract) {
415
- context.report({
416
- node: jsdocNode,
417
- messageId: "unexpectedTag",
418
- loc: getAbsoluteRange(jsdocNode, returnsTag),
419
- data: {
420
- title: returnsTag.title
421
- }
422
- });
423
- } else {
424
- if (requireReturnType && !returnsTag.type) {
425
- context.report({ node: jsdocNode, messageId: "missingReturnType" });
426
- }
427
-
428
- if (!isValidReturnType(returnsTag) && !returnsTag.description && requireReturnDescription) {
429
- context.report({ node: jsdocNode, messageId: "missingReturnDesc" });
430
- }
431
- }
432
- }
433
-
434
- // check for functions missing @returns
435
- if (!isOverride && !hasReturns && !hasConstructor && !isInterface &&
436
- node.parent.kind !== "get" && node.parent.kind !== "constructor" &&
437
- node.parent.kind !== "set" && !isTypeClass(node)) {
438
- if (requireReturn || (functionData.returnPresent && !node.async)) {
439
- context.report({
440
- node: jsdocNode,
441
- messageId: "missingReturn",
442
- data: {
443
- returns: prefer.returns || "returns"
444
- }
445
- });
446
- }
447
- }
448
-
449
- // check the parameters
450
- const jsdocParamNames = Object.keys(paramTagsByName);
451
-
452
- if (node.params) {
453
- node.params.forEach((param, paramsIndex) => {
454
- const bindingParam = param.type === "AssignmentPattern"
455
- ? param.left
456
- : param;
457
-
458
- // TODO(nzakas): Figure out logical things to do with destructured, default, rest params
459
- if (bindingParam.type === "Identifier") {
460
- const name = bindingParam.name;
461
-
462
- if (jsdocParamNames[paramsIndex] && (name !== jsdocParamNames[paramsIndex])) {
463
- context.report({
464
- node: jsdocNode,
465
- messageId: "expected",
466
- loc: getAbsoluteRange(jsdocNode, paramTagsByName[jsdocParamNames[paramsIndex]]),
467
- data: {
468
- name,
469
- jsdocName: jsdocParamNames[paramsIndex]
470
- }
471
- });
472
- } else if (!paramTagsByName[name] && !isOverride) {
473
- context.report({
474
- node: jsdocNode,
475
- messageId: "missingParam",
476
- data: {
477
- name
478
- }
479
- });
480
- }
481
- }
482
- });
483
- }
484
-
485
- if (options.matchDescription) {
486
- const regex = new RegExp(options.matchDescription, "u");
487
-
488
- if (!regex.test(jsdoc.description)) {
489
- context.report({ node: jsdocNode, messageId: "unsatisfiedDesc" });
490
- }
491
- }
492
-
493
- }
494
-
495
- }
496
-
497
- //--------------------------------------------------------------------------
498
- // Public
499
- //--------------------------------------------------------------------------
500
-
501
- return {
502
- ArrowFunctionExpression: startFunction,
503
- FunctionExpression: startFunction,
504
- FunctionDeclaration: startFunction,
505
- ClassExpression: startFunction,
506
- ClassDeclaration: startFunction,
507
- "ArrowFunctionExpression:exit": checkJSDoc,
508
- "FunctionExpression:exit": checkJSDoc,
509
- "FunctionDeclaration:exit": checkJSDoc,
510
- "ClassExpression:exit": checkJSDoc,
511
- "ClassDeclaration:exit": checkJSDoc,
512
- ReturnStatement: addReturn
513
- };
514
-
515
- }
516
- };