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