eslint 9.18.0 → 9.19.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.
package/README.md CHANGED
@@ -1,11 +1,9 @@
1
1
  [![npm version](https://img.shields.io/npm/v/eslint.svg)](https://www.npmjs.com/package/eslint)
2
2
  [![Downloads](https://img.shields.io/npm/dm/eslint.svg)](https://www.npmjs.com/package/eslint)
3
3
  [![Build Status](https://github.com/eslint/eslint/workflows/CI/badge.svg)](https://github.com/eslint/eslint/actions)
4
- [![FOSSA Status](https://app.fossa.io/api/projects/git%2Bhttps%3A%2F%2Fgithub.com%2Feslint%2Feslint.svg?type=shield)](https://app.fossa.io/projects/git%2Bhttps%3A%2F%2Fgithub.com%2Feslint%2Feslint?ref=badge_shield)
5
- <br />
4
+ <br>
6
5
  [![Open Collective Backers](https://img.shields.io/opencollective/backers/eslint)](https://opencollective.com/eslint)
7
6
  [![Open Collective Sponsors](https://img.shields.io/opencollective/sponsors/eslint)](https://opencollective.com/eslint)
8
- [![Follow us on Twitter](https://img.shields.io/twitter/follow/geteslint?label=Follow&style=social)](https://twitter.com/intent/user?screen_name=geteslint)
9
7
 
10
8
  # ESLint
11
9
 
@@ -17,7 +15,8 @@
17
15
  [Code of Conduct](https://eslint.org/conduct) |
18
16
  [Twitter](https://twitter.com/geteslint) |
19
17
  [Discord](https://eslint.org/chat) |
20
- [Mastodon](https://fosstodon.org/@eslint)
18
+ [Mastodon](https://fosstodon.org/@eslint) |
19
+ [Bluesky](https://bsky.app/profile/eslint.org)
21
20
 
22
21
  ESLint is a tool for identifying and reporting on patterns found in ECMAScript/JavaScript code. In many ways, it is similar to JSLint and JSHint with a few exceptions:
23
22
 
@@ -203,7 +202,27 @@ This means:
203
202
 
204
203
  ## License
205
204
 
206
- [![FOSSA Status](https://app.fossa.io/api/projects/git%2Bhttps%3A%2F%2Fgithub.com%2Feslint%2Feslint.svg?type=large)](https://app.fossa.io/projects/git%2Bhttps%3A%2F%2Fgithub.com%2Feslint%2Feslint?ref=badge_large)
205
+ MIT License
206
+
207
+ Copyright OpenJS Foundation and other contributors, <www.openjsf.org>
208
+
209
+ Permission is hereby granted, free of charge, to any person obtaining a copy
210
+ of this software and associated documentation files (the "Software"), to deal
211
+ in the Software without restriction, including without limitation the rights
212
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
213
+ copies of the Software, and to permit persons to whom the Software is
214
+ furnished to do so, subject to the following conditions:
215
+
216
+ The above copyright notice and this permission notice shall be included in
217
+ all copies or substantial portions of the Software.
218
+
219
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
220
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
221
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
222
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
223
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
224
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
225
+ THE SOFTWARE.
207
226
 
208
227
  ## Team
209
228
 
@@ -298,9 +317,9 @@ to get your logo on our READMEs and [website](https://eslint.org/sponsors).
298
317
 
299
318
  <h3>Platinum Sponsors</h3>
300
319
  <p><a href="https://automattic.com"><img src="https://images.opencollective.com/automattic/d0ef3e1/logo.png" alt="Automattic" height="128"></a> <a href="https://www.airbnb.com/"><img src="https://images.opencollective.com/airbnb/d327d66/logo.png" alt="Airbnb" height="128"></a></p><h3>Gold Sponsors</h3>
301
- <p><a href="https://trunk.io/"><img src="https://images.opencollective.com/trunkio/fb92d60/avatar.png" alt="trunk.io" height="96"></a></p><h3>Silver Sponsors</h3>
320
+ <p><a href="https://qlty.sh/"><img src="https://images.opencollective.com/qltysh/33d157d/logo.png" alt="Qlty Software" height="96"></a> <a href="https://trunk.io/"><img src="https://images.opencollective.com/trunkio/fb92d60/avatar.png" alt="trunk.io" height="96"></a></p><h3>Silver Sponsors</h3>
302
321
  <p><a href="https://www.serptriumph.com/"><img src="https://images.opencollective.com/serp-triumph5/fea3074/logo.png" alt="SERP Triumph" height="64"></a> <a href="https://www.jetbrains.com/"><img src="https://images.opencollective.com/jetbrains/fe76f99/logo.png" alt="JetBrains" height="64"></a> <a href="https://liftoff.io/"><img src="https://images.opencollective.com/liftoff/5c4fa84/logo.png" alt="Liftoff" height="64"></a> <a href="https://americanexpress.io"><img src="https://avatars.githubusercontent.com/u/3853301" alt="American Express" height="64"></a></p><h3>Bronze Sponsors</h3>
303
- <p><a href="https://cybozu.co.jp/"><img src="https://images.opencollective.com/cybozu/933e46d/logo.png" alt="Cybozu" height="32"></a> <a href="https://www.crosswordsolver.org/anagram-solver/"><img src="https://images.opencollective.com/anagram-solver/2666271/logo.png" alt="Anagram Solver" height="32"></a> <a href="https://icons8.com/"><img src="https://images.opencollective.com/icons8/7fa1641/logo.png" alt="Icons8" height="32"></a> <a href="https://discord.com"><img src="https://images.opencollective.com/discordapp/f9645d9/logo.png" alt="Discord" height="32"></a> <a href="https://www.gitbook.com"><img src="https://avatars.githubusercontent.com/u/7111340" alt="GitBook" height="32"></a> <a href="https://nx.dev"><img src="https://avatars.githubusercontent.com/u/23692104" alt="Nx" height="32"></a> <a href="https://opensource.mercedes-benz.com/"><img src="https://avatars.githubusercontent.com/u/34240465" alt="Mercedes-Benz Group" height="32"></a> <a href="https://herocoders.com"><img src="https://avatars.githubusercontent.com/u/37549774" alt="HeroCoders" height="32"></a></p>
322
+ <p><a href="https://cybozu.co.jp/"><img src="https://images.opencollective.com/cybozu/933e46d/logo.png" alt="Cybozu" height="32"></a> <a href="https://www.crosswordsolver.org/anagram-solver/"><img src="https://images.opencollective.com/anagram-solver/2666271/logo.png" alt="Anagram Solver" height="32"></a> <a href="https://icons8.com/"><img src="https://images.opencollective.com/icons8/7fa1641/logo.png" alt="Icons8" height="32"></a> <a href="https://discord.com"><img src="https://images.opencollective.com/discordapp/f9645d9/logo.png" alt="Discord" height="32"></a> <a href="https://www.gitbook.com"><img src="https://avatars.githubusercontent.com/u/7111340" alt="GitBook" height="32"></a> <a href="https://nolebase.ayaka.io"><img src="https://avatars.githubusercontent.com/u/11081491" alt="Neko" height="32"></a> <a href="https://nx.dev"><img src="https://avatars.githubusercontent.com/u/23692104" alt="Nx" height="32"></a> <a href="https://opensource.mercedes-benz.com/"><img src="https://avatars.githubusercontent.com/u/34240465" alt="Mercedes-Benz Group" height="32"></a> <a href="https://herocoders.com"><img src="https://avatars.githubusercontent.com/u/37549774" alt="HeroCoders" height="32"></a></p>
304
323
  <h3>Technology Sponsors</h3>
305
324
  Technology sponsors allow us to use their products and services for free as part of a contribution to the open source ecosystem and our work.
306
325
  <p><a href="https://netlify.com"><img src="https://raw.githubusercontent.com/eslint/eslint.org/main/src/assets/images/techsponsors/netlify-icon.svg" alt="Netlify" height="32"></a> <a href="https://algolia.com"><img src="https://raw.githubusercontent.com/eslint/eslint.org/main/src/assets/images/techsponsors/algolia-icon.svg" alt="Algolia" height="32"></a> <a href="https://1password.com"><img src="https://raw.githubusercontent.com/eslint/eslint.org/main/src/assets/images/techsponsors/1password-icon.svg" alt="1Password" height="32"></a></p>
package/lib/cli.js CHANGED
@@ -128,6 +128,7 @@ async function translateOptions({
128
128
  quiet,
129
129
  reportUnusedDisableDirectives,
130
130
  reportUnusedDisableDirectivesSeverity,
131
+ reportUnusedInlineConfigs,
131
132
  resolvePluginsRelativeTo,
132
133
  rule,
133
134
  rulesdir,
@@ -180,6 +181,13 @@ async function translateOptions({
180
181
  };
181
182
  }
182
183
 
184
+ if (reportUnusedInlineConfigs !== void 0) {
185
+ overrideConfig[0].linterOptions = {
186
+ ...overrideConfig[0].linterOptions,
187
+ reportUnusedInlineConfigs: normalizeSeverityToString(reportUnusedInlineConfigs)
188
+ };
189
+ }
190
+
183
191
  if (plugin) {
184
192
  overrideConfig[0].plugins = await loadPlugins(importer, plugin);
185
193
  }
@@ -304,6 +304,20 @@ const disableDirectiveSeveritySchema = {
304
304
  }
305
305
  };
306
306
 
307
+ /** @type {ObjectPropertySchema} */
308
+ const unusedInlineConfigsSeveritySchema = {
309
+ merge(first, second) {
310
+ const value = second === void 0 ? first : second;
311
+
312
+ return normalizeSeverityToNumber(value);
313
+ },
314
+ validate(value) {
315
+ if (!ALLOWED_SEVERITIES.has(value)) {
316
+ throw new TypeError("Expected one of: \"error\", \"warn\", \"off\", 0, 1, or 2.");
317
+ }
318
+ }
319
+ };
320
+
307
321
  /** @type {ObjectPropertySchema} */
308
322
  const deepObjectAssignSchema = {
309
323
  merge(first = {}, second = {}) {
@@ -555,7 +569,8 @@ const flatConfigSchema = {
555
569
  linterOptions: {
556
570
  schema: {
557
571
  noInlineConfig: booleanSchema,
558
- reportUnusedDisableDirectives: disableDirectiveSeveritySchema
572
+ reportUnusedDisableDirectives: disableDirectiveSeveritySchema,
573
+ reportUnusedInlineConfigs: unusedInlineConfigsSeveritySchema
559
574
  }
560
575
  },
561
576
  language: languageSchema,
@@ -40,7 +40,7 @@ const { FlatConfigArray } = require("../config/flat-config-array");
40
40
  const { startTime, endTime } = require("../shared/stats");
41
41
  const { RuleValidator } = require("../config/rule-validator");
42
42
  const { assertIsRuleSeverity } = require("../config/flat-config-schema");
43
- const { normalizeSeverityToString } = require("../shared/severity");
43
+ const { normalizeSeverityToString, normalizeSeverityToNumber } = require("../shared/severity");
44
44
  const { deepMergeArrays } = require("../shared/deep-merge-arrays");
45
45
  const jslang = require("../languages/js");
46
46
  const { activeFlags, inactiveFlags } = require("../shared/flags");
@@ -56,6 +56,7 @@ const { VFile } = require("./vfile");
56
56
  const { ParserService } = require("../services/parser-service");
57
57
  const { FileContext } = require("./file-context");
58
58
  const { ProcessorService } = require("../services/processor-service");
59
+ const { containsDifferentProperty } = require("../shared/option-utils");
59
60
  const STEP_KIND_VISIT = 1;
60
61
  const STEP_KIND_CALL = 2;
61
62
 
@@ -76,6 +77,7 @@ const STEP_KIND_CALL = 2;
76
77
  /** @typedef {import("@eslint/core").Language} Language */
77
78
  /** @typedef {import("@eslint/core").RuleSeverity} RuleSeverity */
78
79
  /** @typedef {import("@eslint/core").RuleConfig} RuleConfig */
80
+ /** @typedef {import("../types").Linter.StringSeverity} StringSeverity */
79
81
 
80
82
 
81
83
  /* eslint-disable jsdoc/valid-types -- https://github.com/jsdoc-type-pratt-parser/jsdoc-type-pratt-parser/issues/4#issuecomment-778805577 */
@@ -141,7 +143,8 @@ const STEP_KIND_CALL = 2;
141
143
  /**
142
144
  * @typedef {Object} InternalOptions
143
145
  * @property {string | null} warnInlineConfig The config name what `noInlineConfig` setting came from. If `noInlineConfig` setting didn't exist, this is null. If this is a config name, then the linter warns directive comments.
144
- * @property {"off" | "warn" | "error"} reportUnusedDisableDirectives (boolean values were normalized)
146
+ * @property {StringSeverity} reportUnusedDisableDirectives Severity to report unused disable directives, if not "off" (boolean values were normalized).
147
+ * @property {StringSeverity} reportUnusedInlineConfigs Severity to report unused inline configs, if not "off".
145
148
  */
146
149
 
147
150
  //------------------------------------------------------------------------------
@@ -314,6 +317,62 @@ function createLintingProblem(options) {
314
317
  };
315
318
  }
316
319
 
320
+ /**
321
+ * Wraps the value in an Array if it isn't already one.
322
+ * @template T
323
+ * @param {T|T[]} value Value to be wrapped.
324
+ * @returns {Array} The value as an array.
325
+ */
326
+ function asArray(value) {
327
+ return Array.isArray(value) ? value : [value];
328
+ }
329
+
330
+ /**
331
+ * Pushes a problem to inlineConfigProblems if ruleOptions are redundant.
332
+ * @param {ConfigData} config Provided config.
333
+ * @param {Object} loc A line/column location
334
+ * @param {Array} problems Problems that may be added to.
335
+ * @param {string} ruleId The rule ID.
336
+ * @param {Array} ruleOptions The rule options, merged with the config's.
337
+ * @param {Array} ruleOptionsInline The rule options from the comment.
338
+ * @param {"error"|"warn"} severity The severity to report.
339
+ * @returns {void}
340
+ */
341
+ function addProblemIfSameSeverityAndOptions(config, loc, problems, ruleId, ruleOptions, ruleOptionsInline, severity) {
342
+ const existingConfigRaw = config.rules?.[ruleId];
343
+ const existingConfig = existingConfigRaw ? asArray(existingConfigRaw) : ["off"];
344
+ const existingSeverity = normalizeSeverityToString(existingConfig[0]);
345
+ const inlineSeverity = normalizeSeverityToString(ruleOptions[0]);
346
+ const sameSeverity = existingSeverity === inlineSeverity;
347
+
348
+ if (!sameSeverity) {
349
+ return;
350
+ }
351
+
352
+ const alreadyConfigured = existingConfigRaw
353
+ ? `is already configured to '${existingSeverity}'`
354
+ : "is not enabled so can't be turned off";
355
+ let message;
356
+
357
+ if ((existingConfig.length === 1 && ruleOptions.length === 1) || existingSeverity === "off") {
358
+ message = `Unused inline config ('${ruleId}' ${alreadyConfigured}).`;
359
+ } else if (!containsDifferentProperty(ruleOptions.slice(1), existingConfig.slice(1))) {
360
+ message = ruleOptionsInline.length === 1
361
+ ? `Unused inline config ('${ruleId}' ${alreadyConfigured}).`
362
+ : `Unused inline config ('${ruleId}' ${alreadyConfigured} with the same options).`;
363
+ }
364
+
365
+ if (message) {
366
+ problems.push(createLintingProblem({
367
+ ruleId: null,
368
+ message,
369
+ loc,
370
+ language: config.language,
371
+ severity: normalizeSeverityToNumber(severity)
372
+ }));
373
+ }
374
+ }
375
+
317
376
  /**
318
377
  * Creates a collection of disable directives from a comment
319
378
  * @param {Object} options to create disable directives
@@ -517,7 +576,7 @@ function getDirectiveComments(sourceCode, ruleMapper, warnInlineConfig, config)
517
576
  return;
518
577
  }
519
578
 
520
- let ruleOptions = Array.isArray(ruleValue) ? ruleValue : [ruleValue];
579
+ let ruleOptions = asArray(ruleValue);
521
580
 
522
581
  /*
523
582
  * If the rule was already configured, inline rule configuration that
@@ -555,7 +614,7 @@ function getDirectiveComments(sourceCode, ruleMapper, warnInlineConfig, config)
555
614
  */
556
615
  ruleOptions = [
557
616
  ruleOptions[0], // severity from the inline config
558
- ...Array.isArray(config.rules[name]) ? config.rules[name].slice(1) : [] // options from the provided config
617
+ ...asArray(config.rules[name]).slice(1) // options from the provided config
559
618
  ];
560
619
  }
561
620
 
@@ -774,6 +833,8 @@ function normalizeVerifyOptions(providedOptions, config) {
774
833
  }
775
834
  }
776
835
 
836
+ const reportUnusedInlineConfigs = linterOptions.reportUnusedInlineConfigs === void 0 ? "off" : normalizeSeverityToString(linterOptions.reportUnusedInlineConfigs);
837
+
777
838
  let ruleFilter = providedOptions.ruleFilter;
778
839
 
779
840
  if (typeof ruleFilter !== "function") {
@@ -787,6 +848,7 @@ function normalizeVerifyOptions(providedOptions, config) {
787
848
  ? `your config${configNameOfNoInlineConfig}`
788
849
  : null,
789
850
  reportUnusedDisableDirectives,
851
+ reportUnusedInlineConfigs,
790
852
  disableFixes: Boolean(providedOptions.disableFixes),
791
853
  stats: providedOptions.stats,
792
854
  ruleFilter
@@ -1787,7 +1849,8 @@ class Linter {
1787
1849
 
1788
1850
  try {
1789
1851
 
1790
- let ruleOptions = Array.isArray(ruleValue) ? ruleValue : [ruleValue];
1852
+ const ruleOptionsInline = asArray(ruleValue);
1853
+ let ruleOptions = ruleOptionsInline;
1791
1854
 
1792
1855
  assertIsRuleSeverity(ruleId, ruleOptions[0]);
1793
1856
 
@@ -1850,6 +1913,12 @@ class Linter {
1850
1913
  }
1851
1914
  }
1852
1915
 
1916
+ if (options.reportUnusedInlineConfigs !== "off") {
1917
+ addProblemIfSameSeverityAndOptions(
1918
+ config, loc, inlineConfigProblems, ruleId, ruleOptions, ruleOptionsInline, options.reportUnusedInlineConfigs
1919
+ );
1920
+ }
1921
+
1853
1922
  if (shouldValidateOptions) {
1854
1923
  ruleValidator.validate({
1855
1924
  plugins: config.plugins,
package/lib/options.js CHANGED
@@ -187,6 +187,18 @@ module.exports = function(usingFlatConfig) {
187
187
  };
188
188
  }
189
189
 
190
+ let reportUnusedInlineConfigsFlag;
191
+
192
+ if (usingFlatConfig) {
193
+ reportUnusedInlineConfigsFlag = {
194
+ option: "report-unused-inline-configs",
195
+ type: "String",
196
+ default: void 0,
197
+ description: "Adds reported errors for unused eslint inline config comments",
198
+ enum: ["off", "warn", "error", "0", "1", "2"]
199
+ };
200
+ }
201
+
190
202
  return optionator({
191
203
  prepend: "eslint [options] file.js [file.js] [dir]",
192
204
  defaults: {
@@ -350,6 +362,7 @@ module.exports = function(usingFlatConfig) {
350
362
  description: "Chooses severity level for reporting unused eslint-disable and eslint-enable directives",
351
363
  enum: ["off", "warn", "error", "0", "1", "2"]
352
364
  },
365
+ reportUnusedInlineConfigsFlag,
353
366
  {
354
367
  heading: "Caching"
355
368
  },
@@ -0,0 +1,56 @@
1
+ /**
2
+ * @fileoverview Utilities to operate on option objects.
3
+ * @author Josh Goldberg
4
+ */
5
+
6
+ "use strict";
7
+
8
+ /**
9
+ * Determines whether any of input's properties are different
10
+ * from values that already exist in original.
11
+ * @template T
12
+ * @param {Partial<T>} input New value.
13
+ * @param {T} original Original value.
14
+ * @returns {boolean} Whether input includes an explicit difference.
15
+ */
16
+ function containsDifferentProperty(input, original) {
17
+ if (input === original) {
18
+ return false;
19
+ }
20
+
21
+ if (
22
+ typeof input !== typeof original ||
23
+ Array.isArray(input) !== Array.isArray(original)
24
+ ) {
25
+ return true;
26
+ }
27
+
28
+ if (Array.isArray(input)) {
29
+ return (
30
+ input.length !== original.length ||
31
+ input.some((value, i) =>
32
+ containsDifferentProperty(value, original[i]))
33
+ );
34
+ }
35
+
36
+ if (typeof input === "object") {
37
+ if (input === null || original === null) {
38
+ return true;
39
+ }
40
+
41
+ const inputKeys = Object.keys(input);
42
+ const originalKeys = Object.keys(original);
43
+
44
+ return inputKeys.length !== originalKeys.length || inputKeys.some(
45
+ inputKey =>
46
+ !Object.hasOwn(original, inputKey) ||
47
+ containsDifferentProperty(input[inputKey], original[inputKey])
48
+ );
49
+ }
50
+
51
+ return true;
52
+ }
53
+
54
+ module.exports = {
55
+ containsDifferentProperty
56
+ };
@@ -1371,6 +1371,12 @@ export namespace Linter {
1371
1371
  * tracked and reported.
1372
1372
  */
1373
1373
  reportUnusedDisableDirectives?: Severity | StringSeverity | boolean;
1374
+
1375
+ /**
1376
+ * A severity value indicating if and how unused inline configs should be
1377
+ * tracked and reported.
1378
+ */
1379
+ reportUnusedInlineConfigs?: Severity | StringSeverity;
1374
1380
  }
1375
1381
 
1376
1382
  interface Stats {