eslint 8.57.0 → 9.2.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 (156) hide show
  1. package/README.md +31 -28
  2. package/bin/eslint.js +4 -3
  3. package/conf/ecma-version.js +16 -0
  4. package/conf/globals.js +1 -0
  5. package/conf/rule-type-list.json +3 -1
  6. package/lib/api.js +7 -11
  7. package/lib/cli-engine/cli-engine.js +14 -3
  8. package/lib/cli-engine/formatters/formatters-meta.json +1 -29
  9. package/lib/cli-engine/lint-result-cache.js +2 -2
  10. package/lib/cli.js +115 -36
  11. package/lib/config/default-config.js +3 -0
  12. package/lib/config/flat-config-array.js +110 -24
  13. package/lib/config/flat-config-helpers.js +41 -20
  14. package/lib/config/flat-config-schema.js +1 -7
  15. package/lib/config/rule-validator.js +42 -6
  16. package/lib/eslint/eslint-helpers.js +116 -58
  17. package/lib/eslint/eslint.js +892 -377
  18. package/lib/eslint/index.js +2 -2
  19. package/lib/eslint/legacy-eslint.js +728 -0
  20. package/lib/linter/apply-disable-directives.js +59 -31
  21. package/lib/linter/code-path-analysis/code-path-analyzer.js +0 -1
  22. package/lib/linter/code-path-analysis/code-path.js +32 -30
  23. package/lib/linter/code-path-analysis/fork-context.js +1 -1
  24. package/lib/linter/config-comment-parser.js +8 -11
  25. package/lib/linter/index.js +1 -3
  26. package/lib/linter/interpolate.js +24 -2
  27. package/lib/linter/linter.js +428 -207
  28. package/lib/linter/report-translator.js +3 -3
  29. package/lib/linter/rules.js +6 -15
  30. package/lib/linter/source-code-fixer.js +1 -1
  31. package/lib/linter/timing.js +16 -8
  32. package/lib/options.js +35 -3
  33. package/lib/rule-tester/index.js +3 -1
  34. package/lib/rule-tester/rule-tester.js +424 -347
  35. package/lib/rules/array-bracket-newline.js +1 -1
  36. package/lib/rules/array-bracket-spacing.js +1 -1
  37. package/lib/rules/block-scoped-var.js +1 -1
  38. package/lib/rules/callback-return.js +2 -2
  39. package/lib/rules/camelcase.js +3 -5
  40. package/lib/rules/capitalized-comments.js +10 -7
  41. package/lib/rules/comma-dangle.js +1 -1
  42. package/lib/rules/comma-style.js +2 -2
  43. package/lib/rules/complexity.js +14 -1
  44. package/lib/rules/constructor-super.js +99 -100
  45. package/lib/rules/default-case.js +1 -1
  46. package/lib/rules/eol-last.js +2 -2
  47. package/lib/rules/function-paren-newline.js +2 -2
  48. package/lib/rules/indent-legacy.js +5 -5
  49. package/lib/rules/indent.js +5 -5
  50. package/lib/rules/index.js +1 -2
  51. package/lib/rules/key-spacing.js +2 -2
  52. package/lib/rules/line-comment-position.js +1 -1
  53. package/lib/rules/lines-around-directive.js +2 -2
  54. package/lib/rules/max-depth.js +1 -1
  55. package/lib/rules/max-len.js +3 -3
  56. package/lib/rules/max-lines.js +3 -3
  57. package/lib/rules/max-nested-callbacks.js +1 -1
  58. package/lib/rules/max-params.js +1 -1
  59. package/lib/rules/max-statements.js +1 -1
  60. package/lib/rules/multiline-comment-style.js +7 -7
  61. package/lib/rules/new-cap.js +1 -1
  62. package/lib/rules/newline-after-var.js +1 -1
  63. package/lib/rules/newline-before-return.js +1 -1
  64. package/lib/rules/no-case-declarations.js +13 -1
  65. package/lib/rules/no-constant-binary-expression.js +7 -8
  66. package/lib/rules/no-constant-condition.js +18 -7
  67. package/lib/rules/no-constructor-return.js +2 -2
  68. package/lib/rules/no-dupe-class-members.js +2 -2
  69. package/lib/rules/no-else-return.js +1 -1
  70. package/lib/rules/no-empty-function.js +2 -2
  71. package/lib/rules/no-empty-static-block.js +1 -1
  72. package/lib/rules/no-extend-native.js +1 -2
  73. package/lib/rules/no-extra-semi.js +1 -1
  74. package/lib/rules/no-fallthrough.js +41 -16
  75. package/lib/rules/no-implicit-coercion.js +66 -24
  76. package/lib/rules/no-inner-declarations.js +23 -2
  77. package/lib/rules/no-invalid-regexp.js +1 -1
  78. package/lib/rules/no-invalid-this.js +1 -1
  79. package/lib/rules/no-lone-blocks.js +3 -3
  80. package/lib/rules/no-loss-of-precision.js +1 -1
  81. package/lib/rules/no-misleading-character-class.js +225 -69
  82. package/lib/rules/no-mixed-spaces-and-tabs.js +1 -1
  83. package/lib/rules/no-multiple-empty-lines.js +1 -1
  84. package/lib/rules/no-new-native-nonconstructor.js +1 -1
  85. package/lib/rules/no-new-symbol.js +8 -1
  86. package/lib/rules/no-restricted-globals.js +1 -1
  87. package/lib/rules/no-restricted-imports.js +186 -40
  88. package/lib/rules/no-restricted-modules.js +2 -2
  89. package/lib/rules/no-return-await.js +1 -1
  90. package/lib/rules/no-sequences.js +1 -0
  91. package/lib/rules/no-this-before-super.js +45 -13
  92. package/lib/rules/no-trailing-spaces.js +2 -3
  93. package/lib/rules/no-unneeded-ternary.js +1 -1
  94. package/lib/rules/no-unsafe-optional-chaining.js +1 -1
  95. package/lib/rules/no-unused-private-class-members.js +1 -1
  96. package/lib/rules/no-unused-vars.js +197 -36
  97. package/lib/rules/no-useless-assignment.js +566 -0
  98. package/lib/rules/no-useless-backreference.js +1 -1
  99. package/lib/rules/no-useless-computed-key.js +2 -2
  100. package/lib/rules/no-useless-return.js +7 -2
  101. package/lib/rules/object-curly-spacing.js +3 -3
  102. package/lib/rules/object-property-newline.js +1 -1
  103. package/lib/rules/one-var.js +5 -5
  104. package/lib/rules/padded-blocks.js +7 -7
  105. package/lib/rules/prefer-arrow-callback.js +3 -3
  106. package/lib/rules/prefer-reflect.js +1 -1
  107. package/lib/rules/prefer-regex-literals.js +1 -1
  108. package/lib/rules/prefer-template.js +1 -1
  109. package/lib/rules/radix.js +2 -2
  110. package/lib/rules/semi-style.js +1 -1
  111. package/lib/rules/sort-imports.js +1 -1
  112. package/lib/rules/sort-keys.js +1 -1
  113. package/lib/rules/sort-vars.js +1 -1
  114. package/lib/rules/space-unary-ops.js +1 -1
  115. package/lib/rules/strict.js +1 -1
  116. package/lib/rules/use-isnan.js +101 -7
  117. package/lib/rules/utils/ast-utils.js +16 -7
  118. package/lib/rules/utils/char-source.js +240 -0
  119. package/lib/rules/utils/lazy-loading-rule-map.js +1 -1
  120. package/lib/rules/utils/unicode/index.js +9 -4
  121. package/lib/rules/yield-star-spacing.js +1 -1
  122. package/lib/shared/runtime-info.js +1 -0
  123. package/lib/shared/serialization.js +55 -0
  124. package/lib/shared/stats.js +30 -0
  125. package/lib/shared/string-utils.js +9 -11
  126. package/lib/shared/types.js +35 -1
  127. package/lib/source-code/index.js +3 -1
  128. package/lib/source-code/source-code.js +299 -85
  129. package/lib/source-code/token-store/backward-token-cursor.js +3 -3
  130. package/lib/source-code/token-store/cursors.js +4 -2
  131. package/lib/source-code/token-store/forward-token-comment-cursor.js +3 -3
  132. package/lib/source-code/token-store/forward-token-cursor.js +3 -3
  133. package/lib/source-code/token-store/index.js +2 -2
  134. package/lib/unsupported-api.js +3 -5
  135. package/messages/no-config-found.js +1 -1
  136. package/messages/plugin-conflict.js +1 -1
  137. package/messages/plugin-invalid.js +1 -1
  138. package/messages/plugin-missing.js +1 -1
  139. package/package.json +32 -29
  140. package/conf/config-schema.js +0 -93
  141. package/lib/cli-engine/formatters/checkstyle.js +0 -60
  142. package/lib/cli-engine/formatters/compact.js +0 -60
  143. package/lib/cli-engine/formatters/jslint-xml.js +0 -41
  144. package/lib/cli-engine/formatters/junit.js +0 -82
  145. package/lib/cli-engine/formatters/tap.js +0 -95
  146. package/lib/cli-engine/formatters/unix.js +0 -58
  147. package/lib/cli-engine/formatters/visualstudio.js +0 -63
  148. package/lib/cli-engine/xml-escape.js +0 -34
  149. package/lib/eslint/flat-eslint.js +0 -1155
  150. package/lib/rule-tester/flat-rule-tester.js +0 -1131
  151. package/lib/rules/require-jsdoc.js +0 -122
  152. package/lib/rules/utils/patterns/letters.js +0 -36
  153. package/lib/rules/valid-jsdoc.js +0 -516
  154. package/lib/shared/config-validator.js +0 -347
  155. package/lib/shared/deprecation-warnings.js +0 -58
  156. package/lib/shared/relative-module-resolver.js +0 -50
@@ -11,7 +11,7 @@
11
11
 
12
12
  const assert = require("assert");
13
13
  const ruleFixer = require("./rule-fixer");
14
- const interpolate = require("./interpolate");
14
+ const { interpolate } = require("./interpolate");
15
15
 
16
16
  //------------------------------------------------------------------------------
17
17
  // Typedefs
@@ -160,7 +160,7 @@ function mergeFixes(fixes, sourceCode) {
160
160
 
161
161
  const originalText = sourceCode.text;
162
162
  const start = fixes[0].range[0];
163
- const end = fixes[fixes.length - 1].range[1];
163
+ const end = fixes.at(-1).range[1];
164
164
  let text = "";
165
165
  let lastPos = Number.MIN_SAFE_INTEGER;
166
166
 
@@ -343,7 +343,7 @@ module.exports = function createReportTranslator(metadata) {
343
343
  if (descriptor.message) {
344
344
  throw new TypeError("context.report() called with a message and a messageId. Please only pass one.");
345
345
  }
346
- if (!messages || !Object.prototype.hasOwnProperty.call(messages, id)) {
346
+ if (!messages || !Object.hasOwn(messages, id)) {
347
347
  throw new TypeError(`context.report() called with a messageId of '${id}' which is not present in the 'messages' config: ${JSON.stringify(messages, null, 2)}`);
348
348
  }
349
349
  computedMessage = messages[id];
@@ -13,18 +13,10 @@
13
13
  const builtInRules = require("../rules");
14
14
 
15
15
  //------------------------------------------------------------------------------
16
- // Helpers
16
+ // Typedefs
17
17
  //------------------------------------------------------------------------------
18
18
 
19
- /**
20
- * Normalizes a rule module to the new-style API
21
- * @param {(Function|{create: Function})} rule A rule object, which can either be a function
22
- * ("old-style") or an object with a `create` method ("new-style")
23
- * @returns {{create: Function}} A new-style rule.
24
- */
25
- function normalizeRule(rule) {
26
- return typeof rule === "function" ? Object.assign({ create: rule }, rule) : rule;
27
- }
19
+ /** @typedef {import("../shared/types").Rule} Rule */
28
20
 
29
21
  //------------------------------------------------------------------------------
30
22
  // Public Interface
@@ -41,18 +33,17 @@ class Rules {
41
33
  /**
42
34
  * Registers a rule module for rule id in storage.
43
35
  * @param {string} ruleId Rule id (file name).
44
- * @param {Function} ruleModule Rule handler.
36
+ * @param {Rule} rule Rule object.
45
37
  * @returns {void}
46
38
  */
47
- define(ruleId, ruleModule) {
48
- this._rules[ruleId] = normalizeRule(ruleModule);
39
+ define(ruleId, rule) {
40
+ this._rules[ruleId] = rule;
49
41
  }
50
42
 
51
43
  /**
52
44
  * Access rule handler by id (file name).
53
45
  * @param {string} ruleId Rule id (file name).
54
- * @returns {{create: Function, schema: JsonSchema[]}}
55
- * A rule. This is normalized to always have the new-style shape with a `create` method.
46
+ * @returns {Rule} Rule object.
56
47
  */
57
48
  get(ruleId) {
58
49
  if (typeof this._rules[ruleId] === "string") {
@@ -107,7 +107,7 @@ SourceCodeFixer.applyFixes = function(sourceText, messages, shouldFix) {
107
107
  }
108
108
 
109
109
  messages.forEach(problem => {
110
- if (Object.prototype.hasOwnProperty.call(problem, "fix")) {
110
+ if (Object.hasOwn(problem, "fix")) {
111
111
  fixes.push(problem);
112
112
  } else {
113
113
  remainingMessages.push(problem);
@@ -5,6 +5,8 @@
5
5
 
6
6
  "use strict";
7
7
 
8
+ const { startTime, endTime } = require("../shared/stats");
9
+
8
10
  //------------------------------------------------------------------------------
9
11
  // Helpers
10
12
  //------------------------------------------------------------------------------
@@ -128,21 +130,27 @@ module.exports = (function() {
128
130
  * Time the run
129
131
  * @param {any} key key from the data object
130
132
  * @param {Function} fn function to be called
133
+ * @param {boolean} stats if 'stats' is true, return the result and the time difference
131
134
  * @returns {Function} function to be executed
132
135
  * @private
133
136
  */
134
- function time(key, fn) {
135
- if (typeof data[key] === "undefined") {
136
- data[key] = 0;
137
- }
137
+ function time(key, fn, stats) {
138
138
 
139
139
  return function(...args) {
140
- let t = process.hrtime();
140
+
141
+ const t = startTime();
141
142
  const result = fn(...args);
143
+ const tdiff = endTime(t);
144
+
145
+ if (enabled) {
146
+ if (typeof data[key] === "undefined") {
147
+ data[key] = 0;
148
+ }
149
+
150
+ data[key] += tdiff;
151
+ }
142
152
 
143
- t = process.hrtime(t);
144
- data[key] += t[0] * 1e3 + t[1] / 1e6;
145
- return result;
153
+ return stats ? { result, tdiff } : result;
146
154
  };
147
155
  }
148
156
 
package/lib/options.js CHANGED
@@ -38,7 +38,7 @@ const optionator = require("optionator");
38
38
  * @property {boolean} [help] Show help
39
39
  * @property {boolean} ignore Disable use of ignore files and patterns
40
40
  * @property {string} [ignorePath] Specify path of ignore file
41
- * @property {string[]} [ignorePattern] Pattern of files to ignore (in addition to those in .eslintignore)
41
+ * @property {string[]} [ignorePattern] Patterns of files to ignore. In eslintrc mode, these are in addition to `.eslintignore`
42
42
  * @property {boolean} init Run config initialization wizard
43
43
  * @property {boolean} inlineConfig Prevent comments from changing config or rules
44
44
  * @property {number} maxWarnings Number of warnings to trigger nonzero exit code
@@ -57,7 +57,10 @@ const optionator = require("optionator");
57
57
  * @property {boolean} quiet Report errors only
58
58
  * @property {boolean} [version] Output the version number
59
59
  * @property {boolean} warnIgnored Show warnings when the file list includes ignored files
60
+ * @property {boolean} [passOnNoPatterns=false] When set to true, missing patterns cause
61
+ * the linting operation to short circuit and not report any failures.
60
62
  * @property {string[]} _ Positional filenames or patterns
63
+ * @property {boolean} [stats] Report additional statistics
61
64
  */
62
65
 
63
66
  //------------------------------------------------------------------------------
@@ -101,6 +104,16 @@ module.exports = function(usingFlatConfig) {
101
104
  };
102
105
  }
103
106
 
107
+ let inspectConfigFlag;
108
+
109
+ if (usingFlatConfig) {
110
+ inspectConfigFlag = {
111
+ option: "inspect-config",
112
+ type: "Boolean",
113
+ description: "Open the config inspector with the current configuration"
114
+ };
115
+ }
116
+
104
117
  let extFlag;
105
118
 
106
119
  if (!usingFlatConfig) {
@@ -141,6 +154,17 @@ module.exports = function(usingFlatConfig) {
141
154
  };
142
155
  }
143
156
 
157
+ let statsFlag;
158
+
159
+ if (usingFlatConfig) {
160
+ statsFlag = {
161
+ option: "stats",
162
+ type: "Boolean",
163
+ default: "false",
164
+ description: "Add statistics to the lint report"
165
+ };
166
+ }
167
+
144
168
  let warnIgnoredFlag;
145
169
 
146
170
  if (usingFlatConfig) {
@@ -171,6 +195,7 @@ module.exports = function(usingFlatConfig) {
171
195
  ? "Use this configuration instead of eslint.config.js, eslint.config.mjs, or eslint.config.cjs"
172
196
  : "Use this configuration, overriding .eslintrc.* config options if present"
173
197
  },
198
+ inspectConfigFlag,
174
199
  envFlag,
175
200
  extFlag,
176
201
  {
@@ -236,7 +261,7 @@ module.exports = function(usingFlatConfig) {
236
261
  {
237
262
  option: "ignore-pattern",
238
263
  type: "[String]",
239
- description: "Pattern of files to ignore (in addition to those in .eslintignore)",
264
+ description: `Patterns of files to ignore${usingFlatConfig ? "" : " (in addition to those in .eslintignore)"}`,
240
265
  concatRepeatedArrays: [true, {
241
266
  oneValuePerFlag: true
242
267
  }]
@@ -370,6 +395,12 @@ module.exports = function(usingFlatConfig) {
370
395
  description: "Exit with exit code 2 in case of fatal error"
371
396
  },
372
397
  warnIgnoredFlag,
398
+ {
399
+ option: "pass-on-no-patterns",
400
+ type: "Boolean",
401
+ default: false,
402
+ description: "Exit with exit code 0 in case no file patterns are passed"
403
+ },
373
404
  {
374
405
  option: "debug",
375
406
  type: "Boolean",
@@ -392,7 +423,8 @@ module.exports = function(usingFlatConfig) {
392
423
  option: "print-config",
393
424
  type: "path::String",
394
425
  description: "Print the configuration for the given file"
395
- }
426
+ },
427
+ statsFlag
396
428
  ].filter(value => !!value)
397
429
  });
398
430
  };
@@ -1,5 +1,7 @@
1
1
  "use strict";
2
2
 
3
+ const RuleTester = require("./rule-tester");
4
+
3
5
  module.exports = {
4
- RuleTester: require("./rule-tester")
6
+ RuleTester
5
7
  };