eslint 9.25.1 → 9.26.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.
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @fileoverview Disallow shadowing of NaN, undefined, and Infinity (ES5 section 15.1.1)
2
+ * @fileoverview Disallow shadowing of globalThis, NaN, undefined, and Infinity (ES2020 section 18.1)
3
3
  * @author Michael Ficarra
4
4
  */
5
5
  "use strict";
@@ -32,13 +32,29 @@ module.exports = {
32
32
  meta: {
33
33
  type: "suggestion",
34
34
 
35
+ defaultOptions: [
36
+ {
37
+ reportGlobalThis: false,
38
+ },
39
+ ],
40
+
35
41
  docs: {
36
42
  description: "Disallow identifiers from shadowing restricted names",
37
43
  recommended: true,
38
44
  url: "https://eslint.org/docs/latest/rules/no-shadow-restricted-names",
39
45
  },
40
46
 
41
- schema: [],
47
+ schema: [
48
+ {
49
+ type: "object",
50
+ properties: {
51
+ reportGlobalThis: {
52
+ type: "boolean",
53
+ },
54
+ },
55
+ additionalProperties: false,
56
+ },
57
+ ],
42
58
 
43
59
  messages: {
44
60
  shadowingRestrictedName: "Shadowing of global property '{{name}}'.",
@@ -46,6 +62,8 @@ module.exports = {
46
62
  },
47
63
 
48
64
  create(context) {
65
+ const [{ reportGlobalThis }] = context.options;
66
+
49
67
  const RESTRICTED = new Set([
50
68
  "undefined",
51
69
  "NaN",
@@ -53,6 +71,11 @@ module.exports = {
53
71
  "arguments",
54
72
  "eval",
55
73
  ]);
74
+
75
+ if (reportGlobalThis) {
76
+ RESTRICTED.add("globalThis");
77
+ }
78
+
56
79
  const sourceCode = context.sourceCode;
57
80
 
58
81
  // Track reported nodes to avoid duplicate reports. For example, on class declarations.
@@ -55,6 +55,9 @@ module.exports = {
55
55
  enforceForJSX: {
56
56
  type: "boolean",
57
57
  },
58
+ ignoreDirectives: {
59
+ type: "boolean",
60
+ },
58
61
  },
59
62
  additionalProperties: false,
60
63
  },
@@ -66,6 +69,7 @@ module.exports = {
66
69
  allowTernary: false,
67
70
  allowTaggedTemplates: false,
68
71
  enforceForJSX: false,
72
+ ignoreDirectives: false,
69
73
  },
70
74
  ],
71
75
 
@@ -82,6 +86,7 @@ module.exports = {
82
86
  allowTernary,
83
87
  allowTaggedTemplates,
84
88
  enforceForJSX,
89
+ ignoreDirectives,
85
90
  },
86
91
  ] = context.options;
87
92
 
@@ -211,7 +216,8 @@ module.exports = {
211
216
  ExpressionStatement(node) {
212
217
  if (
213
218
  Checker.isDisallowed(node.expression) &&
214
- !isDirective(node)
219
+ !astUtils.isDirective(node) &&
220
+ !(ignoreDirectives && isDirective(node))
215
221
  ) {
216
222
  context.report({ node, messageId: "unusedExpression" });
217
223
  }
@@ -6,7 +6,7 @@
6
6
 
7
7
  const debug = require("debug")("eslint:rules");
8
8
 
9
- /** @typedef {import("../../shared/types").Rule} Rule */
9
+ /** @typedef {import("../../types").Rule.RuleModule} Rule */
10
10
 
11
11
  /**
12
12
  * The `Map` object that loads each rule when it's accessed.
@@ -19,7 +19,7 @@ const debug = require("debug")("eslint:rules");
19
19
  *
20
20
  * rules.get("semi"); // call `() => require("semi")` here.
21
21
  *
22
- * @extends {Map<string, () => Rule>}
22
+ * @extends {Map<string, Rule>}
23
23
  */
24
24
  class LazyLoadingRuleMap extends Map {
25
25
  /**
@@ -20,7 +20,6 @@ const { VFile } = require("../linter/vfile.js");
20
20
  /** @typedef {import("../shared/types.js").LintMessage} LintMessage */
21
21
  /** @typedef {import("../linter/vfile.js").VFile} VFile */
22
22
  /** @typedef {import("@eslint/core").Language} Language */
23
- /** @typedef {import("@eslint/core").LanguageOptions} LanguageOptions */
24
23
  /** @typedef {import("eslint").Linter.Processor} Processor */
25
24
 
26
25
  //-----------------------------------------------------------------------------
@@ -26,21 +26,44 @@ function isSerializablePrimitiveOrPlainObject(val) {
26
26
  * Check if a value is serializable.
27
27
  * Functions or objects like RegExp cannot be serialized by JSON.stringify().
28
28
  * Inspired by: https://stackoverflow.com/questions/30579940/reliable-way-to-check-if-objects-is-serializable-in-javascript
29
- * @param {any} val the value
30
- * @returns {boolean} true if the value is serializable
29
+ * @param {any} val The value
30
+ * @param {Set<Object>} seenObjects Objects already seen in this path from the root object.
31
+ * @returns {boolean} `true` if the value is serializable
31
32
  */
32
- function isSerializable(val) {
33
+ function isSerializable(val, seenObjects = new Set()) {
33
34
  if (!isSerializablePrimitiveOrPlainObject(val)) {
34
35
  return false;
35
36
  }
36
- if (typeof val === "object") {
37
+ if (typeof val === "object" && val !== null) {
38
+ if (seenObjects.has(val)) {
39
+ /*
40
+ * Since this is a depth-first traversal, encountering
41
+ * the same object again means there is a circular reference.
42
+ * Objects with circular references are not serializable.
43
+ */
44
+ return false;
45
+ }
37
46
  for (const property in val) {
38
47
  if (Object.hasOwn(val, property)) {
39
48
  if (!isSerializablePrimitiveOrPlainObject(val[property])) {
40
49
  return false;
41
50
  }
42
- if (typeof val[property] === "object") {
43
- if (!isSerializable(val[property])) {
51
+ if (
52
+ typeof val[property] === "object" &&
53
+ val[property] !== null
54
+ ) {
55
+ if (
56
+ /*
57
+ * We're creating a new Set of seen objects because we want to
58
+ * ensure that `val` doesn't appear again in this path, but it can appear
59
+ * in other paths. This allows for resuing objects in the graph, as long as
60
+ * there are no cycles.
61
+ */
62
+ !isSerializable(
63
+ val[property],
64
+ new Set([...seenObjects, val]),
65
+ )
66
+ ) {
44
67
  return false;
45
68
  }
46
69
  }
@@ -26,15 +26,6 @@ module.exports = {};
26
26
  * @property {boolean} [allowReserved] Allowing the use of reserved words as identifiers in ES3.
27
27
  */
28
28
 
29
- /**
30
- * @typedef {Object} LanguageOptions
31
- * @property {number|"latest"} [ecmaVersion] The ECMAScript version (or revision number).
32
- * @property {Record<string, GlobalConf>} [globals] The global variable settings.
33
- * @property {"script"|"module"|"commonjs"} [sourceType] The source code type.
34
- * @property {string|Object} [parser] The parser to use.
35
- * @property {Object} [parserOptions] The parser options to use.
36
- */
37
-
38
29
  /**
39
30
  * @typedef {Object} ConfigData
40
31
  * @property {Record<string, boolean>} [env] The environment settings.
@@ -166,14 +157,6 @@ module.exports = {};
166
157
  * @property {{ name?: string, url?: string }} [rule] Name and information of the replacement rule
167
158
  */
168
159
 
169
- /**
170
- * @typedef {Object} Plugin
171
- * @property {Record<string, ConfigData>} [configs] The definition of plugin configs.
172
- * @property {Record<string, Environment>} [environments] The definition of plugin environments.
173
- * @property {Record<string, Processor>} [processors] The definition of plugin processors.
174
- * @property {Record<string, Rule>} [rules] The definition of plugin rules.
175
- */
176
-
177
160
  /**
178
161
  * Information of deprecated rules.
179
162
  * @typedef {Object} DeprecatedRuleInfo
@@ -35,7 +35,6 @@ import type {
35
35
  LanguageOptions as GenericLanguageOptions,
36
36
  RuleDefinition,
37
37
  RuleContext as CoreRuleContext,
38
- RuleContextTypeOptions,
39
38
  DeprecatedInfo,
40
39
  } from "@eslint/core";
41
40
  import { JSONSchema4 } from "json-schema";
@@ -1934,6 +1933,9 @@ export namespace ESLint {
1934
1933
  }
1935
1934
 
1936
1935
  interface Plugin extends ObjectMetaProperties {
1936
+ meta?: ObjectMetaProperties["meta"] & {
1937
+ namespace?: string | undefined;
1938
+ };
1937
1939
  configs?:
1938
1940
  | Record<
1939
1941
  string,
@@ -2121,7 +2123,7 @@ export class RuleTester {
2121
2123
 
2122
2124
  run(
2123
2125
  name: string,
2124
- rule: Rule.RuleModule,
2126
+ rule: RuleDefinition,
2125
2127
  tests: {
2126
2128
  valid: Array<string | RuleTester.ValidTestCase>;
2127
2129
  invalid: RuleTester.InvalidTestCase[];
@@ -3578,7 +3578,16 @@ export interface ESLintRules extends Linter.RulesRecord {
3578
3578
  * @since 0.1.4
3579
3579
  * @see https://eslint.org/docs/latest/rules/no-shadow-restricted-names
3580
3580
  */
3581
- "no-shadow-restricted-names": Linter.RuleEntry<[]>;
3581
+ "no-shadow-restricted-names": Linter.RuleEntry<
3582
+ [
3583
+ Partial<{
3584
+ /**
3585
+ * @default false
3586
+ */
3587
+ reportGlobalThis: boolean;
3588
+ }>,
3589
+ ]
3590
+ >;
3582
3591
 
3583
3592
  /**
3584
3593
  * Rule to disallow spacing between function identifiers and their applications (deprecated).
@@ -3935,6 +3944,10 @@ export interface ESLintRules extends Linter.RulesRecord {
3935
3944
  * @default false
3936
3945
  */
3937
3946
  enforceForJSX: boolean;
3947
+ /**
3948
+ * @default false
3949
+ */
3950
+ ignoreDirectives: boolean;
3938
3951
  }>,
3939
3952
  ]
3940
3953
  >;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint",
3
- "version": "9.25.1",
3
+ "version": "9.26.0",
4
4
  "author": "Nicholas C. Zakas <nicholas+npm@nczconsulting.com>",
5
5
  "description": "An AST-based pattern checker for JavaScript.",
6
6
  "type": "commonjs",
@@ -110,11 +110,12 @@
110
110
  "@eslint/config-helpers": "^0.2.1",
111
111
  "@eslint/core": "^0.13.0",
112
112
  "@eslint/eslintrc": "^3.3.1",
113
- "@eslint/js": "9.25.1",
113
+ "@eslint/js": "9.26.0",
114
114
  "@eslint/plugin-kit": "^0.2.8",
115
115
  "@humanfs/node": "^0.16.6",
116
116
  "@humanwhocodes/module-importer": "^1.0.1",
117
117
  "@humanwhocodes/retry": "^0.4.2",
118
+ "@modelcontextprotocol/sdk": "^1.8.0",
118
119
  "@types/estree": "^1.0.6",
119
120
  "@types/json-schema": "^7.0.15",
120
121
  "ajv": "^6.12.4",
@@ -138,15 +139,17 @@
138
139
  "lodash.merge": "^4.6.2",
139
140
  "minimatch": "^3.1.2",
140
141
  "natural-compare": "^1.4.0",
141
- "optionator": "^0.9.3"
142
+ "optionator": "^0.9.3",
143
+ "zod": "^3.24.2"
142
144
  },
143
145
  "devDependencies": {
144
146
  "@arethetypeswrong/cli": "^0.17.0",
145
147
  "@babel/core": "^7.4.3",
146
148
  "@babel/preset-env": "^7.4.3",
147
149
  "@cypress/webpack-preprocessor": "^6.0.2",
148
- "@eslint/json": "^0.11.0",
150
+ "@eslint/json": "^0.12.0",
149
151
  "@trunkio/launcher": "^1.3.4",
152
+ "@types/esquery": "^1.5.4",
150
153
  "@types/node": "^22.13.14",
151
154
  "@typescript-eslint/parser": "^8.4.0",
152
155
  "babel-loader": "^8.0.5",