@typescript-eslint/eslint-plugin 8.48.1-alpha.7 → 8.48.1-alpha.9

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.
@@ -89,7 +89,8 @@ exports.default = (0, util_1.createRule)({
89
89
  ],
90
90
  create(context, [option]) {
91
91
  const services = (0, util_1.getParserServices)(context);
92
- const checker = services.program.getTypeChecker();
92
+ const { program } = services;
93
+ const checker = program.getTypeChecker();
93
94
  const ignoredTypeNames = option.ignoredTypeNames ?? [];
94
95
  function checkExpression(node, type) {
95
96
  if (node.type === utils_1.AST_NODE_TYPES.Literal) {
@@ -171,27 +172,6 @@ exports.default = (0, util_1.createRule)({
171
172
  }
172
173
  return Usefulness.Always;
173
174
  }
174
- function getBaseTypesForType(type) {
175
- if (!tsutils.isObjectType(type)) {
176
- return [];
177
- }
178
- const interfaceTarget = tsutils.isTypeReference(type)
179
- ? type.target
180
- : type;
181
- const interfaceType = tsutils.isObjectFlagSet(interfaceTarget, ts.ObjectFlags.Interface | ts.ObjectFlags.Class) && interfaceTarget;
182
- if (!interfaceType) {
183
- return [];
184
- }
185
- return checker.getBaseTypes(interfaceType);
186
- }
187
- function isIgnoredTypeOrBase(type, seen = new Set()) {
188
- if (seen.has(type)) {
189
- return false;
190
- }
191
- seen.add(type);
192
- return (ignoredTypeNames.includes((0, util_1.getTypeName)(checker, type)) ||
193
- getBaseTypesForType(type).some(base => isIgnoredTypeOrBase(base, seen)));
194
- }
195
175
  function collectToStringCertainty(type, visited) {
196
176
  if (visited.has(type)) {
197
177
  // don't report if this is a self referencing array or tuple type
@@ -218,7 +198,7 @@ exports.default = (0, util_1.createRule)({
218
198
  ignoredTypeNames.includes(symbol.name)) {
219
199
  return Usefulness.Always;
220
200
  }
221
- if (isIgnoredTypeOrBase(type)) {
201
+ if ((0, util_1.matchesTypeOrBaseType)(services, type => ignoredTypeNames.includes((0, util_1.getTypeName)(checker, type)), type)) {
222
202
  return Usefulness.Always;
223
203
  }
224
204
  if (type.isIntersection()) {
@@ -112,7 +112,7 @@ exports.default = (0, util_1.createRule)({
112
112
  return innerType.types.some(recursivelyCheckType);
113
113
  }
114
114
  return ((0, util_1.isTypeFlagSet)(innerType, typescript_1.TypeFlags.StringLike) ||
115
- (0, type_utils_1.typeMatchesSomeSpecifier)(innerType, allow, program) ||
115
+ (0, util_1.matchesTypeOrBaseType)(services, type => (0, type_utils_1.typeMatchesSomeSpecifier)(type, allow, program), innerType) ||
116
116
  enabledOptionTesters.some(({ tester }) => tester(innerType, checker, recursivelyCheckType)));
117
117
  }
118
118
  },
@@ -0,0 +1,13 @@
1
+ import type { ParserServicesWithTypeInformation } from '@typescript-eslint/utils';
2
+ import type { InterfaceType, Type } from 'typescript';
3
+ export declare function hasBaseTypes(type: Type): type is InterfaceType;
4
+ /**
5
+ * Recursively checks if a type or any of its base types matches the provided
6
+ * matcher function.
7
+ * @param services Parser services with type information
8
+ * @param matcher Function to test if a type matches the desired criteria
9
+ * @param type The type to check
10
+ * @param seen Set of already visited types to prevent infinite recursion
11
+ * @returns `true` if the type or any of its base types match the matcher
12
+ */
13
+ export declare function matchesTypeOrBaseType(services: ParserServicesWithTypeInformation, matcher: (type: Type) => boolean, type: Type, seen?: Set<Type>): boolean;
@@ -0,0 +1,75 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.hasBaseTypes = hasBaseTypes;
37
+ exports.matchesTypeOrBaseType = matchesTypeOrBaseType;
38
+ const ts_api_utils_1 = require("ts-api-utils");
39
+ const tsutils = __importStar(require("ts-api-utils"));
40
+ const ts = __importStar(require("typescript"));
41
+ function getBaseTypesForType(checker, type) {
42
+ if (!tsutils.isObjectType(type)) {
43
+ return [];
44
+ }
45
+ const interfaceTarget = tsutils.isTypeReference(type) ? type.target : type;
46
+ const interfaceType = tsutils.isObjectFlagSet(interfaceTarget, ts.ObjectFlags.Interface | ts.ObjectFlags.Class) && interfaceTarget;
47
+ if (!interfaceType) {
48
+ return [];
49
+ }
50
+ return checker.getBaseTypes(interfaceType);
51
+ }
52
+ function hasBaseTypes(type) {
53
+ return ((0, ts_api_utils_1.isObjectType)(type) &&
54
+ (0, ts_api_utils_1.isObjectFlagSet)(type, ts.ObjectFlags.Interface | ts.ObjectFlags.Class));
55
+ }
56
+ /**
57
+ * Recursively checks if a type or any of its base types matches the provided
58
+ * matcher function.
59
+ * @param services Parser services with type information
60
+ * @param matcher Function to test if a type matches the desired criteria
61
+ * @param type The type to check
62
+ * @param seen Set of already visited types to prevent infinite recursion
63
+ * @returns `true` if the type or any of its base types match the matcher
64
+ */
65
+ function matchesTypeOrBaseType(services, matcher, type, seen = new Set()) {
66
+ if (seen.has(type)) {
67
+ return false;
68
+ }
69
+ seen.add(type);
70
+ if (matcher(type)) {
71
+ return true;
72
+ }
73
+ const checker = services.program.getTypeChecker();
74
+ return getBaseTypesForType(checker, type).some(base => matchesTypeOrBaseType(services, matcher, base, seen));
75
+ }
@@ -1,5 +1,6 @@
1
1
  import { ESLintUtils } from '@typescript-eslint/utils';
2
2
  export * from './astUtils';
3
+ export * from './baseTypeUtils';
3
4
  export * from './collectUnusedVariables';
4
5
  export * from './createRule';
5
6
  export * from './getFixOrSuggest';
@@ -17,6 +17,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
17
17
  exports.NullThrowsReasons = exports.nullThrows = exports.isObjectNotArray = exports.getParserServices = exports.deepMerge = exports.applyDefault = void 0;
18
18
  const utils_1 = require("@typescript-eslint/utils");
19
19
  __exportStar(require("./astUtils"), exports);
20
+ __exportStar(require("./baseTypeUtils"), exports);
20
21
  __exportStar(require("./collectUnusedVariables"), exports);
21
22
  __exportStar(require("./createRule"), exports);
22
23
  __exportStar(require("./getFixOrSuggest"), exports);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@typescript-eslint/eslint-plugin",
3
- "version": "8.48.1-alpha.7",
3
+ "version": "8.48.1-alpha.9",
4
4
  "description": "TypeScript plugin for ESLint",
5
5
  "files": [
6
6
  "dist",
@@ -59,10 +59,10 @@
59
59
  },
60
60
  "dependencies": {
61
61
  "@eslint-community/regexpp": "^4.10.0",
62
- "@typescript-eslint/scope-manager": "8.48.1-alpha.7",
63
- "@typescript-eslint/type-utils": "8.48.1-alpha.7",
64
- "@typescript-eslint/utils": "8.48.1-alpha.7",
65
- "@typescript-eslint/visitor-keys": "8.48.1-alpha.7",
62
+ "@typescript-eslint/scope-manager": "8.48.1-alpha.9",
63
+ "@typescript-eslint/type-utils": "8.48.1-alpha.9",
64
+ "@typescript-eslint/utils": "8.48.1-alpha.9",
65
+ "@typescript-eslint/visitor-keys": "8.48.1-alpha.9",
66
66
  "graphemer": "^1.4.0",
67
67
  "ignore": "^7.0.0",
68
68
  "natural-compare": "^1.4.0",
@@ -71,8 +71,8 @@
71
71
  "devDependencies": {
72
72
  "@types/mdast": "^4.0.3",
73
73
  "@types/natural-compare": "*",
74
- "@typescript-eslint/rule-schema-to-typescript-types": "8.48.1-alpha.7",
75
- "@typescript-eslint/rule-tester": "8.48.1-alpha.7",
74
+ "@typescript-eslint/rule-schema-to-typescript-types": "8.48.1-alpha.9",
75
+ "@typescript-eslint/rule-tester": "8.48.1-alpha.9",
76
76
  "@vitest/coverage-v8": "^3.1.3",
77
77
  "ajv": "^6.12.6",
78
78
  "cross-fetch": "*",
@@ -92,7 +92,7 @@
92
92
  "vitest": "^3.1.3"
93
93
  },
94
94
  "peerDependencies": {
95
- "@typescript-eslint/parser": "^8.48.1-alpha.7",
95
+ "@typescript-eslint/parser": "^8.48.1-alpha.9",
96
96
  "eslint": "^8.57.0 || ^9.0.0",
97
97
  "typescript": ">=4.8.4 <6.0.0"
98
98
  },