eslint 8.56.0 → 9.0.0-alpha.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.
Files changed (121) hide show
  1. package/README.md +7 -2
  2. package/conf/ecma-version.js +16 -0
  3. package/conf/rule-type-list.json +3 -1
  4. package/lib/api.js +1 -1
  5. package/lib/cli-engine/cli-engine.js +14 -3
  6. package/lib/cli-engine/formatters/formatters-meta.json +1 -29
  7. package/lib/cli-engine/lint-result-cache.js +2 -2
  8. package/lib/cli.js +46 -25
  9. package/lib/config/default-config.js +3 -0
  10. package/lib/config/flat-config-array.js +0 -20
  11. package/lib/config/flat-config-helpers.js +41 -20
  12. package/lib/config/flat-config-schema.js +35 -25
  13. package/lib/config/rule-validator.js +27 -4
  14. package/lib/eslint/eslint-helpers.js +32 -12
  15. package/lib/eslint/eslint.js +856 -373
  16. package/lib/eslint/index.js +2 -2
  17. package/lib/eslint/legacy-eslint.js +722 -0
  18. package/lib/linter/apply-disable-directives.js +35 -7
  19. package/lib/linter/code-path-analysis/code-path.js +5 -19
  20. package/lib/linter/code-path-analysis/fork-context.js +1 -1
  21. package/lib/linter/config-comment-parser.js +8 -11
  22. package/lib/linter/linter.js +196 -100
  23. package/lib/linter/report-translator.js +2 -2
  24. package/lib/linter/rules.js +6 -15
  25. package/lib/linter/source-code-fixer.js +1 -1
  26. package/lib/options.js +9 -1
  27. package/lib/rule-tester/rule-tester.js +234 -291
  28. package/lib/rules/array-bracket-newline.js +1 -1
  29. package/lib/rules/array-bracket-spacing.js +1 -1
  30. package/lib/rules/block-scoped-var.js +1 -1
  31. package/lib/rules/callback-return.js +2 -2
  32. package/lib/rules/comma-dangle.js +1 -1
  33. package/lib/rules/comma-style.js +2 -2
  34. package/lib/rules/complexity.js +1 -1
  35. package/lib/rules/constructor-super.js +1 -1
  36. package/lib/rules/default-case.js +1 -1
  37. package/lib/rules/eol-last.js +2 -2
  38. package/lib/rules/function-paren-newline.js +2 -2
  39. package/lib/rules/indent-legacy.js +5 -5
  40. package/lib/rules/indent.js +5 -5
  41. package/lib/rules/index.js +1 -2
  42. package/lib/rules/key-spacing.js +2 -2
  43. package/lib/rules/line-comment-position.js +1 -1
  44. package/lib/rules/lines-around-directive.js +2 -2
  45. package/lib/rules/max-depth.js +1 -1
  46. package/lib/rules/max-len.js +3 -3
  47. package/lib/rules/max-lines.js +3 -3
  48. package/lib/rules/max-nested-callbacks.js +1 -1
  49. package/lib/rules/max-params.js +1 -1
  50. package/lib/rules/max-statements.js +1 -1
  51. package/lib/rules/multiline-comment-style.js +7 -7
  52. package/lib/rules/new-cap.js +1 -1
  53. package/lib/rules/newline-after-var.js +1 -1
  54. package/lib/rules/newline-before-return.js +1 -1
  55. package/lib/rules/no-constant-binary-expression.js +6 -6
  56. package/lib/rules/no-constructor-return.js +2 -2
  57. package/lib/rules/no-dupe-class-members.js +2 -2
  58. package/lib/rules/no-else-return.js +1 -1
  59. package/lib/rules/no-empty-function.js +2 -2
  60. package/lib/rules/no-empty-static-block.js +1 -1
  61. package/lib/rules/no-extra-semi.js +1 -1
  62. package/lib/rules/no-fallthrough.js +1 -1
  63. package/lib/rules/no-implicit-coercion.js +17 -1
  64. package/lib/rules/no-inner-declarations.js +23 -2
  65. package/lib/rules/no-invalid-regexp.js +1 -1
  66. package/lib/rules/no-invalid-this.js +1 -1
  67. package/lib/rules/no-lone-blocks.js +2 -2
  68. package/lib/rules/no-loss-of-precision.js +1 -1
  69. package/lib/rules/no-misleading-character-class.js +174 -65
  70. package/lib/rules/no-mixed-spaces-and-tabs.js +1 -1
  71. package/lib/rules/no-multiple-empty-lines.js +1 -1
  72. package/lib/rules/no-new-native-nonconstructor.js +1 -1
  73. package/lib/rules/no-new-symbol.js +8 -1
  74. package/lib/rules/no-restricted-globals.js +1 -1
  75. package/lib/rules/no-restricted-imports.js +2 -2
  76. package/lib/rules/no-restricted-modules.js +2 -2
  77. package/lib/rules/no-return-await.js +1 -1
  78. package/lib/rules/no-sequences.js +1 -0
  79. package/lib/rules/no-trailing-spaces.js +2 -3
  80. package/lib/rules/no-unneeded-ternary.js +1 -1
  81. package/lib/rules/no-unsafe-optional-chaining.js +1 -1
  82. package/lib/rules/no-unused-private-class-members.js +1 -1
  83. package/lib/rules/no-unused-vars.js +6 -8
  84. package/lib/rules/no-useless-assignment.js +566 -0
  85. package/lib/rules/no-useless-backreference.js +1 -1
  86. package/lib/rules/object-curly-spacing.js +3 -3
  87. package/lib/rules/object-property-newline.js +1 -1
  88. package/lib/rules/one-var.js +5 -5
  89. package/lib/rules/padded-blocks.js +7 -7
  90. package/lib/rules/prefer-arrow-callback.js +3 -3
  91. package/lib/rules/prefer-reflect.js +1 -1
  92. package/lib/rules/prefer-regex-literals.js +1 -1
  93. package/lib/rules/prefer-template.js +1 -1
  94. package/lib/rules/radix.js +2 -2
  95. package/lib/rules/semi-style.js +1 -1
  96. package/lib/rules/sort-imports.js +1 -1
  97. package/lib/rules/sort-keys.js +1 -1
  98. package/lib/rules/sort-vars.js +1 -1
  99. package/lib/rules/space-unary-ops.js +1 -1
  100. package/lib/rules/strict.js +1 -1
  101. package/lib/rules/utils/ast-utils.js +7 -7
  102. package/lib/rules/yield-star-spacing.js +1 -1
  103. package/lib/shared/types.js +1 -1
  104. package/lib/source-code/source-code.js +5 -83
  105. package/lib/source-code/token-store/index.js +2 -2
  106. package/lib/unsupported-api.js +3 -5
  107. package/package.json +12 -14
  108. package/conf/config-schema.js +0 -93
  109. package/lib/cli-engine/formatters/checkstyle.js +0 -60
  110. package/lib/cli-engine/formatters/compact.js +0 -60
  111. package/lib/cli-engine/formatters/jslint-xml.js +0 -41
  112. package/lib/cli-engine/formatters/junit.js +0 -82
  113. package/lib/cli-engine/formatters/tap.js +0 -95
  114. package/lib/cli-engine/formatters/unix.js +0 -58
  115. package/lib/cli-engine/formatters/visualstudio.js +0 -63
  116. package/lib/eslint/flat-eslint.js +0 -1142
  117. package/lib/rule-tester/flat-rule-tester.js +0 -1122
  118. package/lib/rules/require-jsdoc.js +0 -122
  119. package/lib/rules/valid-jsdoc.js +0 -516
  120. package/lib/shared/config-validator.js +0 -347
  121. package/lib/shared/relative-module-resolver.js +0 -50
@@ -1,347 +0,0 @@
1
- /*
2
- * STOP!!! DO NOT MODIFY.
3
- *
4
- * This file is part of the ongoing work to move the eslintrc-style config
5
- * system into the @eslint/eslintrc package. This file needs to remain
6
- * unchanged in order for this work to proceed.
7
- *
8
- * If you think you need to change this file, please contact @nzakas first.
9
- *
10
- * Thanks in advance for your cooperation.
11
- */
12
-
13
- /**
14
- * @fileoverview Validates configs.
15
- * @author Brandon Mills
16
- */
17
-
18
- "use strict";
19
-
20
- //------------------------------------------------------------------------------
21
- // Requirements
22
- //------------------------------------------------------------------------------
23
-
24
- const
25
- util = require("util"),
26
- configSchema = require("../../conf/config-schema"),
27
- BuiltInRules = require("../rules"),
28
- {
29
- Legacy: {
30
- ConfigOps,
31
- environments: BuiltInEnvironments
32
- }
33
- } = require("@eslint/eslintrc"),
34
- { emitDeprecationWarning } = require("./deprecation-warnings");
35
-
36
- const ajv = require("./ajv")();
37
- const ruleValidators = new WeakMap();
38
- const noop = Function.prototype;
39
-
40
- //------------------------------------------------------------------------------
41
- // Private
42
- //------------------------------------------------------------------------------
43
- let validateSchema;
44
- const severityMap = {
45
- error: 2,
46
- warn: 1,
47
- off: 0
48
- };
49
-
50
- /**
51
- * Gets a complete options schema for a rule.
52
- * @param {{create: Function, schema: (Array|null)}} rule A new-style rule object
53
- * @returns {Object} JSON Schema for the rule's options.
54
- */
55
- function getRuleOptionsSchema(rule) {
56
- if (!rule) {
57
- return null;
58
- }
59
-
60
- const schema = rule.schema || rule.meta && rule.meta.schema;
61
-
62
- // Given a tuple of schemas, insert warning level at the beginning
63
- if (Array.isArray(schema)) {
64
- if (schema.length) {
65
- return {
66
- type: "array",
67
- items: schema,
68
- minItems: 0,
69
- maxItems: schema.length
70
- };
71
- }
72
- return {
73
- type: "array",
74
- minItems: 0,
75
- maxItems: 0
76
- };
77
-
78
- }
79
-
80
- // Given a full schema, leave it alone
81
- return schema || null;
82
- }
83
-
84
- /**
85
- * Validates a rule's severity and returns the severity value. Throws an error if the severity is invalid.
86
- * @param {options} options The given options for the rule.
87
- * @throws {Error} Wrong severity value.
88
- * @returns {number|string} The rule's severity value
89
- */
90
- function validateRuleSeverity(options) {
91
- const severity = Array.isArray(options) ? options[0] : options;
92
- const normSeverity = typeof severity === "string" ? severityMap[severity.toLowerCase()] : severity;
93
-
94
- if (normSeverity === 0 || normSeverity === 1 || normSeverity === 2) {
95
- return normSeverity;
96
- }
97
-
98
- throw new Error(`\tSeverity should be one of the following: 0 = off, 1 = warn, 2 = error (you passed '${util.inspect(severity).replace(/'/gu, "\"").replace(/\n/gu, "")}').\n`);
99
-
100
- }
101
-
102
- /**
103
- * Validates the non-severity options passed to a rule, based on its schema.
104
- * @param {{create: Function}} rule The rule to validate
105
- * @param {Array} localOptions The options for the rule, excluding severity
106
- * @throws {Error} Any rule validation errors.
107
- * @returns {void}
108
- */
109
- function validateRuleSchema(rule, localOptions) {
110
- if (!ruleValidators.has(rule)) {
111
- const schema = getRuleOptionsSchema(rule);
112
-
113
- if (schema) {
114
- ruleValidators.set(rule, ajv.compile(schema));
115
- }
116
- }
117
-
118
- const validateRule = ruleValidators.get(rule);
119
-
120
- if (validateRule) {
121
- validateRule(localOptions);
122
- if (validateRule.errors) {
123
- throw new Error(validateRule.errors.map(
124
- error => `\tValue ${JSON.stringify(error.data)} ${error.message}.\n`
125
- ).join(""));
126
- }
127
- }
128
- }
129
-
130
- /**
131
- * Validates a rule's options against its schema.
132
- * @param {{create: Function}|null} rule The rule that the config is being validated for
133
- * @param {string} ruleId The rule's unique name.
134
- * @param {Array|number} options The given options for the rule.
135
- * @param {string|null} source The name of the configuration source to report in any errors. If null or undefined,
136
- * no source is prepended to the message.
137
- * @throws {Error} Upon any bad rule configuration.
138
- * @returns {void}
139
- */
140
- function validateRuleOptions(rule, ruleId, options, source = null) {
141
- try {
142
- const severity = validateRuleSeverity(options);
143
-
144
- if (severity !== 0) {
145
- validateRuleSchema(rule, Array.isArray(options) ? options.slice(1) : []);
146
- }
147
- } catch (err) {
148
- const enhancedMessage = `Configuration for rule "${ruleId}" is invalid:\n${err.message}`;
149
-
150
- if (typeof source === "string") {
151
- throw new Error(`${source}:\n\t${enhancedMessage}`);
152
- } else {
153
- throw new Error(enhancedMessage);
154
- }
155
- }
156
- }
157
-
158
- /**
159
- * Validates an environment object
160
- * @param {Object} environment The environment config object to validate.
161
- * @param {string} source The name of the configuration source to report in any errors.
162
- * @param {(envId:string) => Object} [getAdditionalEnv] A map from strings to loaded environments.
163
- * @returns {void}
164
- */
165
- function validateEnvironment(
166
- environment,
167
- source,
168
- getAdditionalEnv = noop
169
- ) {
170
-
171
- // not having an environment is ok
172
- if (!environment) {
173
- return;
174
- }
175
-
176
- Object.keys(environment).forEach(id => {
177
- const env = getAdditionalEnv(id) || BuiltInEnvironments.get(id) || null;
178
-
179
- if (!env) {
180
- const message = `${source}:\n\tEnvironment key "${id}" is unknown\n`;
181
-
182
- throw new Error(message);
183
- }
184
- });
185
- }
186
-
187
- /**
188
- * Validates a rules config object
189
- * @param {Object} rulesConfig The rules config object to validate.
190
- * @param {string} source The name of the configuration source to report in any errors.
191
- * @param {(ruleId:string) => Object} getAdditionalRule A map from strings to loaded rules
192
- * @returns {void}
193
- */
194
- function validateRules(
195
- rulesConfig,
196
- source,
197
- getAdditionalRule = noop
198
- ) {
199
- if (!rulesConfig) {
200
- return;
201
- }
202
-
203
- Object.keys(rulesConfig).forEach(id => {
204
- const rule = getAdditionalRule(id) || BuiltInRules.get(id) || null;
205
-
206
- validateRuleOptions(rule, id, rulesConfig[id], source);
207
- });
208
- }
209
-
210
- /**
211
- * Validates a `globals` section of a config file
212
- * @param {Object} globalsConfig The `globals` section
213
- * @param {string|null} source The name of the configuration source to report in the event of an error.
214
- * @returns {void}
215
- */
216
- function validateGlobals(globalsConfig, source = null) {
217
- if (!globalsConfig) {
218
- return;
219
- }
220
-
221
- Object.entries(globalsConfig)
222
- .forEach(([configuredGlobal, configuredValue]) => {
223
- try {
224
- ConfigOps.normalizeConfigGlobal(configuredValue);
225
- } catch (err) {
226
- throw new Error(`ESLint configuration of global '${configuredGlobal}' in ${source} is invalid:\n${err.message}`);
227
- }
228
- });
229
- }
230
-
231
- /**
232
- * Validate `processor` configuration.
233
- * @param {string|undefined} processorName The processor name.
234
- * @param {string} source The name of config file.
235
- * @param {(id:string) => Processor} getProcessor The getter of defined processors.
236
- * @throws {Error} For invalid processor configuration.
237
- * @returns {void}
238
- */
239
- function validateProcessor(processorName, source, getProcessor) {
240
- if (processorName && !getProcessor(processorName)) {
241
- throw new Error(`ESLint configuration of processor in '${source}' is invalid: '${processorName}' was not found.`);
242
- }
243
- }
244
-
245
- /**
246
- * Formats an array of schema validation errors.
247
- * @param {Array} errors An array of error messages to format.
248
- * @returns {string} Formatted error message
249
- */
250
- function formatErrors(errors) {
251
- return errors.map(error => {
252
- if (error.keyword === "additionalProperties") {
253
- const formattedPropertyPath = error.dataPath.length ? `${error.dataPath.slice(1)}.${error.params.additionalProperty}` : error.params.additionalProperty;
254
-
255
- return `Unexpected top-level property "${formattedPropertyPath}"`;
256
- }
257
- if (error.keyword === "type") {
258
- const formattedField = error.dataPath.slice(1);
259
- const formattedExpectedType = Array.isArray(error.schema) ? error.schema.join("/") : error.schema;
260
- const formattedValue = JSON.stringify(error.data);
261
-
262
- return `Property "${formattedField}" is the wrong type (expected ${formattedExpectedType} but got \`${formattedValue}\`)`;
263
- }
264
-
265
- const field = error.dataPath[0] === "." ? error.dataPath.slice(1) : error.dataPath;
266
-
267
- return `"${field}" ${error.message}. Value: ${JSON.stringify(error.data)}`;
268
- }).map(message => `\t- ${message}.\n`).join("");
269
- }
270
-
271
- /**
272
- * Validates the top level properties of the config object.
273
- * @param {Object} config The config object to validate.
274
- * @param {string} source The name of the configuration source to report in any errors.
275
- * @throws {Error} For any config invalid per the schema.
276
- * @returns {void}
277
- */
278
- function validateConfigSchema(config, source = null) {
279
- validateSchema = validateSchema || ajv.compile(configSchema);
280
-
281
- if (!validateSchema(config)) {
282
- throw new Error(`ESLint configuration in ${source} is invalid:\n${formatErrors(validateSchema.errors)}`);
283
- }
284
-
285
- if (Object.hasOwnProperty.call(config, "ecmaFeatures")) {
286
- emitDeprecationWarning(source, "ESLINT_LEGACY_ECMAFEATURES");
287
- }
288
- }
289
-
290
- /**
291
- * Validates an entire config object.
292
- * @param {Object} config The config object to validate.
293
- * @param {string} source The name of the configuration source to report in any errors.
294
- * @param {(ruleId:string) => Object} [getAdditionalRule] A map from strings to loaded rules.
295
- * @param {(envId:string) => Object} [getAdditionalEnv] A map from strings to loaded envs.
296
- * @returns {void}
297
- */
298
- function validate(config, source, getAdditionalRule, getAdditionalEnv) {
299
- validateConfigSchema(config, source);
300
- validateRules(config.rules, source, getAdditionalRule);
301
- validateEnvironment(config.env, source, getAdditionalEnv);
302
- validateGlobals(config.globals, source);
303
-
304
- for (const override of config.overrides || []) {
305
- validateRules(override.rules, source, getAdditionalRule);
306
- validateEnvironment(override.env, source, getAdditionalEnv);
307
- validateGlobals(config.globals, source);
308
- }
309
- }
310
-
311
- const validated = new WeakSet();
312
-
313
- /**
314
- * Validate config array object.
315
- * @param {ConfigArray} configArray The config array to validate.
316
- * @returns {void}
317
- */
318
- function validateConfigArray(configArray) {
319
- const getPluginEnv = Map.prototype.get.bind(configArray.pluginEnvironments);
320
- const getPluginProcessor = Map.prototype.get.bind(configArray.pluginProcessors);
321
- const getPluginRule = Map.prototype.get.bind(configArray.pluginRules);
322
-
323
- // Validate.
324
- for (const element of configArray) {
325
- if (validated.has(element)) {
326
- continue;
327
- }
328
- validated.add(element);
329
-
330
- validateEnvironment(element.env, element.name, getPluginEnv);
331
- validateGlobals(element.globals, element.name);
332
- validateProcessor(element.processor, element.name, getPluginProcessor);
333
- validateRules(element.rules, element.name, getPluginRule);
334
- }
335
- }
336
-
337
- //------------------------------------------------------------------------------
338
- // Public Interface
339
- //------------------------------------------------------------------------------
340
-
341
- module.exports = {
342
- getRuleOptionsSchema,
343
- validate,
344
- validateConfigArray,
345
- validateConfigSchema,
346
- validateRuleOptions
347
- };
@@ -1,50 +0,0 @@
1
- /*
2
- * STOP!!! DO NOT MODIFY.
3
- *
4
- * This file is part of the ongoing work to move the eslintrc-style config
5
- * system into the @eslint/eslintrc package. This file needs to remain
6
- * unchanged in order for this work to proceed.
7
- *
8
- * If you think you need to change this file, please contact @nzakas first.
9
- *
10
- * Thanks in advance for your cooperation.
11
- */
12
-
13
- /**
14
- * Utility for resolving a module relative to another module
15
- * @author Teddy Katz
16
- */
17
-
18
- "use strict";
19
-
20
- const { createRequire } = require("module");
21
-
22
- module.exports = {
23
-
24
- /**
25
- * Resolves a Node module relative to another module
26
- * @param {string} moduleName The name of a Node module, or a path to a Node module.
27
- * @param {string} relativeToPath An absolute path indicating the module that `moduleName` should be resolved relative to. This must be
28
- * a file rather than a directory, but the file need not actually exist.
29
- * @throws {Error} Any error from `module.createRequire` or its `resolve`.
30
- * @returns {string} The absolute path that would result from calling `require.resolve(moduleName)` in a file located at `relativeToPath`
31
- */
32
- resolve(moduleName, relativeToPath) {
33
- try {
34
- return createRequire(relativeToPath).resolve(moduleName);
35
- } catch (error) {
36
-
37
- // This `if` block is for older Node.js than 12.0.0. We can remove this block in the future.
38
- if (
39
- typeof error === "object" &&
40
- error !== null &&
41
- error.code === "MODULE_NOT_FOUND" &&
42
- !error.requireStack &&
43
- error.message.includes(moduleName)
44
- ) {
45
- error.message += `\nRequire stack:\n- ${relativeToPath}`;
46
- }
47
- throw error;
48
- }
49
- }
50
- };