@typescript-eslint/eslint-plugin 8.60.1-alpha.5 → 8.60.1-alpha.7

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.
@@ -457,6 +457,7 @@ exports.default = (0, util_1.createRule)({
457
457
  return [
458
458
  selector,
459
459
  (node) => {
460
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
460
461
  handler(node, validator);
461
462
  },
462
463
  ];
@@ -322,29 +322,59 @@ exports.default = (0, util_1.createRule)({
322
322
  return false;
323
323
  }
324
324
  /**
325
- * Checks if a variable is inside the initializer of scopeVar.
325
+ * Finds the uppermost expression node that can evaluate to the given one,
326
+ * unwrapping through LogicalExpression and non-test ConditionalExpression branches.
327
+ * @param node The node to unwrap.
328
+ * @returns The topmost unwrapped node.
329
+ */
330
+ function unwrapExpression(node) {
331
+ const { parent } = node;
332
+ if (parent?.type === utils_1.AST_NODE_TYPES.LogicalExpression ||
333
+ (parent?.type === utils_1.AST_NODE_TYPES.ConditionalExpression &&
334
+ parent.test !== node)) {
335
+ return unwrapExpression(parent);
336
+ }
337
+ return node;
338
+ }
339
+ /**
340
+ * Checks if a variable is the name of a function or class expression that is
341
+ * directly assigned (or transparently through `||`/`?:`) as the initializer
342
+ * of scopeVar.
326
343
  *
327
- * To avoid reporting at declarations such as `var a = function a() {};`.
328
- * But it should report `var a = function(a) {};` or `var a = function() { function a() {} };`.
344
+ * Allows `var a = function a() {}` but reports `var a = wrap(function a() {})`.
329
345
  * @param variable The variable to check.
330
346
  * @param scopeVar The scope variable to look for.
331
- * @returns Whether or not the variable is inside initializer of scopeVar.
347
+ * @returns Whether or not the variable is the direct initializer name of scopeVar.
332
348
  */
333
349
  function isOnInitializer(variable, scopeVar) {
334
- const outerScope = scopeVar.scope;
335
350
  const outerDef = scopeVar.defs.at(0);
336
- const outer = outerDef?.parent?.range;
337
- const innerScope = variable.scope;
338
351
  const innerDef = variable.defs.at(0);
339
- const inner = innerDef?.name.range;
340
- return !!(outer &&
341
- inner &&
342
- outer[0] < inner[0] &&
343
- inner[1] < outer[1] &&
344
- ((innerDef.type === scope_manager_1.DefinitionType.FunctionName &&
345
- innerDef.node.type === utils_1.AST_NODE_TYPES.FunctionExpression) ||
346
- innerDef.node.type === utils_1.AST_NODE_TYPES.ClassExpression) &&
347
- outerScope === innerScope.upper);
352
+ if (!outerDef || !innerDef) {
353
+ return false;
354
+ }
355
+ if (!((innerDef.type === scope_manager_1.DefinitionType.FunctionName &&
356
+ innerDef.node.type === utils_1.AST_NODE_TYPES.FunctionExpression) ||
357
+ (innerDef.type === scope_manager_1.DefinitionType.ClassName &&
358
+ innerDef.node.type === utils_1.AST_NODE_TYPES.ClassExpression))) {
359
+ return false;
360
+ }
361
+ const outerIdentifier = outerDef.name;
362
+ let initializerNode;
363
+ if (outerIdentifier.parent.type === utils_1.AST_NODE_TYPES.VariableDeclarator) {
364
+ initializerNode = outerIdentifier.parent.init;
365
+ }
366
+ else if (outerIdentifier.parent.type === utils_1.AST_NODE_TYPES.AssignmentPattern) {
367
+ initializerNode = outerIdentifier.parent.right;
368
+ }
369
+ if (!initializerNode) {
370
+ return false;
371
+ }
372
+ const nodeToCheck = innerDef.node;
373
+ if (!(initializerNode.range[0] <= nodeToCheck.range[0] &&
374
+ nodeToCheck.range[1] <= initializerNode.range[1])) {
375
+ return false;
376
+ }
377
+ return initializerNode === unwrapExpression(nodeToCheck);
348
378
  }
349
379
  /**
350
380
  * Get a range of a variable's identifier node.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@typescript-eslint/eslint-plugin",
3
- "version": "8.60.1-alpha.5",
3
+ "version": "8.60.1-alpha.7",
4
4
  "description": "TypeScript plugin for ESLint",
5
5
  "files": [
6
6
  "dist",
@@ -52,16 +52,17 @@
52
52
  "ignore": "^7.0.5",
53
53
  "natural-compare": "^1.4.0",
54
54
  "ts-api-utils": "^2.5.0",
55
- "@typescript-eslint/scope-manager": "8.60.1-alpha.5",
56
- "@typescript-eslint/type-utils": "8.60.1-alpha.5",
57
- "@typescript-eslint/visitor-keys": "8.60.1-alpha.5",
58
- "@typescript-eslint/utils": "8.60.1-alpha.5"
55
+ "@typescript-eslint/scope-manager": "8.60.1-alpha.7",
56
+ "@typescript-eslint/type-utils": "8.60.1-alpha.7",
57
+ "@typescript-eslint/utils": "8.60.1-alpha.7",
58
+ "@typescript-eslint/visitor-keys": "8.60.1-alpha.7"
59
59
  },
60
60
  "devDependencies": {
61
61
  "@types/json-schema": "^7.0.15",
62
62
  "@types/mdast": "^4.0.4",
63
63
  "@types/natural-compare": "^1.4.3",
64
64
  "@types/react": "^18.3.21",
65
+ "@typescript/native-preview": "7.0.0-dev.20260518.1",
65
66
  "@vitest/coverage-v8": "^4.0.18",
66
67
  "ajv": "^6.12.6",
67
68
  "eslint": "^10.0.0",
@@ -78,13 +79,13 @@
78
79
  "typescript": ">=4.8.4 <6.1.0",
79
80
  "unist-util-visit": "^5.0.0",
80
81
  "vitest": "^4.0.18",
81
- "@typescript-eslint/rule-schema-to-typescript-types": "8.60.1-alpha.5",
82
- "@typescript-eslint/rule-tester": "8.60.1-alpha.5"
82
+ "@typescript-eslint/rule-schema-to-typescript-types": "8.60.1-alpha.7",
83
+ "@typescript-eslint/rule-tester": "8.60.1-alpha.7"
83
84
  },
84
85
  "peerDependencies": {
85
86
  "eslint": "^8.57.0 || ^9.0.0 || ^10.0.0",
86
87
  "typescript": ">=4.8.4 <6.1.0",
87
- "@typescript-eslint/parser": "^8.60.1-alpha.5"
88
+ "@typescript-eslint/parser": "^8.60.1-alpha.7"
88
89
  },
89
90
  "funding": {
90
91
  "type": "opencollective",
@@ -107,7 +108,8 @@
107
108
  },
108
109
  "lint": {
109
110
  "command": "eslint"
110
- }
111
+ },
112
+ "typecheck:tsgo": {}
111
113
  }
112
114
  },
113
115
  "scripts": {
@@ -118,6 +120,7 @@
118
120
  "generate-configs": "pnpm -w run generate-configs",
119
121
  "lint": "pnpm -w exec nx lint",
120
122
  "test": "pnpm -w exec nx test",
121
- "typecheck": "pnpm -w exec nx typecheck"
123
+ "typecheck": "pnpm -w exec nx typecheck",
124
+ "typecheck:tsgo": "pnpm -w exec nx typecheck:tsgo"
122
125
  }
123
126
  }