@typescript-eslint/eslint-plugin 8.73.1-alpha.1 → 8.73.1-alpha.10

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,4 +1,10 @@
1
- declare const _default: import("@typescript-eslint/utils/ts-eslint").RuleModule<"adjacentSignature", [], import("../../rules").ESLintPluginDocs, import("@typescript-eslint/utils/ts-eslint").RuleListener> & {
1
+ export type Options = [
2
+ {
3
+ ignoreAccessors?: boolean;
4
+ }
5
+ ];
6
+ export type MessageIds = 'adjacentSignature';
7
+ declare const _default: import("@typescript-eslint/utils/ts-eslint").RuleModule<"adjacentSignature", Options, import("../../rules").ESLintPluginDocs, import("@typescript-eslint/utils/ts-eslint").RuleListener> & {
2
8
  name: string;
3
9
  };
4
10
  export default _default;
@@ -13,11 +13,22 @@ exports.default = (0, util_1.createRule)({
13
13
  messages: {
14
14
  adjacentSignature: 'All {{name}} signatures should be adjacent.',
15
15
  },
16
- schema: [],
16
+ schema: [
17
+ {
18
+ type: 'object',
19
+ additionalProperties: false,
20
+ properties: {
21
+ ignoreAccessors: {
22
+ type: 'boolean',
23
+ description: 'Whether to ignore getters and setters, which cannot be overloaded.',
24
+ },
25
+ },
26
+ },
27
+ ],
17
28
  },
18
29
  // eslint-disable-next-line @typescript-eslint/no-deprecated -- For compatibility with ESLint 8, see #12842
19
- defaultOptions: [],
20
- create(context) {
30
+ defaultOptions: [{ ignoreAccessors: false }],
31
+ create(context, [{ ignoreAccessors = false }]) {
21
32
  /**
22
33
  * Gets the name and attribute of the member being processed.
23
34
  * @param member the member being processed.
@@ -48,6 +59,10 @@ exports.default = (0, util_1.createRule)({
48
59
  }
49
60
  case utils_1.AST_NODE_TYPES.TSMethodSignature:
50
61
  case utils_1.AST_NODE_TYPES.MethodDefinition:
62
+ if (ignoreAccessors &&
63
+ (member.kind === 'get' || member.kind === 'set')) {
64
+ return null;
65
+ }
51
66
  return {
52
67
  ...(0, util_1.getNameFromMember)(member, context.sourceCode),
53
68
  callSignature: false,
@@ -83,12 +83,16 @@ exports.default = (0, util_1.createRule)({
83
83
  node.type !== utils_1.AST_NODE_TYPES.AccessorProperty) {
84
84
  return lhsName;
85
85
  }
86
- if (!node.computed) {
87
- return node.key;
88
- }
89
86
  // If the property's computed, we have to attach the
90
87
  // annotation after the square bracket, not the enclosed expression
91
- return (0, util_1.nullThrows)(context.sourceCode.getTokenAfter(node.key), util_1.NullThrowsReasons.MissingToken(']', 'key'));
88
+ const keyEnd = node.computed
89
+ ? (0, util_1.nullThrows)(context.sourceCode.getTokenAfter(node.key), util_1.NullThrowsReasons.MissingToken(']', 'key'))
90
+ : node.key;
91
+ if (!node.optional) {
92
+ return keyEnd;
93
+ }
94
+ // An optional property's annotation goes after the `?`
95
+ return (0, util_1.nullThrows)(context.sourceCode.getTokenAfter(keyEnd), util_1.NullThrowsReasons.MissingToken('?', 'key'));
92
96
  }
93
97
  return [
94
98
  fixer.remove(typeArguments),
@@ -112,7 +116,10 @@ exports.default = (0, util_1.createRule)({
112
116
  *fix(fixer) {
113
117
  yield fixer.remove(lhs.parent);
114
118
  for (const comment of extraComments) {
115
- yield fixer.insertTextAfter(rhs.callee, context.sourceCode.getText(comment));
119
+ // A line comment runs to the end of the line, so it needs a
120
+ // line break to keep the type arguments out of it
121
+ const suffix = comment.type === utils_1.AST_TOKEN_TYPES.Line ? '\n' : '';
122
+ yield fixer.insertTextAfter(rhs.callee, context.sourceCode.getText(comment) + suffix);
116
123
  }
117
124
  yield fixer.insertTextAfter(rhs.callee, context.sourceCode.getText(lhs.typeArguments));
118
125
  if (!hasParens) {
@@ -202,6 +202,15 @@ exports.default = (0, util_1.createRule)({
202
202
  const displayParts = tag.text;
203
203
  return displayParts ? ts.displayPartsToString(displayParts) : '';
204
204
  }
205
+ function getPropertyDeprecation(type, propertyName) {
206
+ for (const constituent of tsutils.unionConstituents(type)) {
207
+ const reason = getJsDocDeprecation(constituent.getProperty(propertyName));
208
+ if (reason != null) {
209
+ return { type: constituent, reason };
210
+ }
211
+ }
212
+ return undefined;
213
+ }
205
214
  function isNodeCalleeOfParent(node) {
206
215
  switch (node.parent?.type) {
207
216
  case utils_1.AST_NODE_TYPES.NewExpression:
@@ -275,8 +284,7 @@ exports.default = (0, util_1.createRule)({
275
284
  }
276
285
  function getJSXAttributeDeprecation(openingElement, propertyName) {
277
286
  const contextualType = (0, util_1.nullThrows)(services.getContextualType(openingElement.name), 'Expected JSX opening element name to have contextualType');
278
- const symbol = contextualType.getProperty(propertyName);
279
- return getJsDocDeprecation(symbol);
287
+ return getPropertyDeprecation(contextualType, propertyName)?.reason;
280
288
  }
281
289
  function getDeprecationReason(node) {
282
290
  const callLikeNode = getCallLikeNode(node);
@@ -360,11 +368,12 @@ exports.default = (0, util_1.createRule)({
360
368
  if (!contextualType) {
361
369
  return;
362
370
  }
363
- const reason = getJsDocDeprecation(contextualType.getProperty(propertyName));
364
- if (reason == null) {
371
+ const deprecation = getPropertyDeprecation(contextualType, propertyName);
372
+ if (!deprecation) {
365
373
  return;
366
374
  }
367
- if ((0, util_1.typeMatchesSomeSpecifier)(contextualType, allow, services.program)) {
375
+ const { type, reason } = deprecation;
376
+ if ((0, util_1.typeMatchesSomeSpecifier)(type, allow, services.program)) {
368
377
  return;
369
378
  }
370
379
  context.report({
@@ -391,12 +400,12 @@ exports.default = (0, util_1.createRule)({
391
400
  ? propertyType.value
392
401
  : // eslint-disable-next-line @typescript-eslint/no-base-to-string
393
402
  String(propertyType.value);
394
- const property = objectType.getProperty(propertyName);
395
- const reason = getJsDocDeprecation(property);
396
- if (reason == null) {
403
+ const deprecation = getPropertyDeprecation(objectType, propertyName);
404
+ if (!deprecation) {
397
405
  return;
398
406
  }
399
- if ((0, util_1.typeMatchesSomeSpecifier)(objectType, allow, services.program)) {
407
+ const { type, reason } = deprecation;
408
+ if ((0, util_1.typeMatchesSomeSpecifier)(type, allow, services.program)) {
400
409
  return;
401
410
  }
402
411
  context.report({
@@ -306,7 +306,7 @@ exports.default = (0, util_1.createRule)({
306
306
  const receiverTypes = checker
307
307
  .getSymbolAtLocation(services.esTreeNodeToTSNodeMap.get(node).expression)
308
308
  ?.declarations?.flatMap(declaration => getMappedKeyConstraintTypes(checker, declaration)) ?? [];
309
- if (receiverTypes.length === 0) {
309
+ if (!receiverTypes.some(receiverType => (0, shared_1.getEnumTypes)(checker, receiverType).length > 0)) {
310
310
  return;
311
311
  }
312
312
  // declare const foo: { [key in Fruit]: string };
@@ -2,9 +2,17 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.isReferenceToGlobalFunction = isReferenceToGlobalFunction;
4
4
  function isReferenceToGlobalFunction(calleeName, node, sourceCode) {
5
- const ref = sourceCode
6
- .getScope(node)
7
- .references.find(ref => ref.identifier.name === calleeName);
5
+ // The reference is not always in the scope of the node. For example, a
6
+ // `switch` discriminant belongs to the switch scope but is referenced from
7
+ // the scope that contains the `switch`.
8
+ let ref;
9
+ let scope = sourceCode.getScope(node);
10
+ while (scope && !ref) {
11
+ ref = scope.references.find(ref => ref.identifier.name === calleeName &&
12
+ ref.identifier.range[0] >= node.range[0] &&
13
+ ref.identifier.range[1] <= node.range[1]);
14
+ scope = scope.upper;
15
+ }
8
16
  // ensure it's the "global" version
9
17
  return !ref?.resolved?.defs.length;
10
18
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@typescript-eslint/eslint-plugin",
3
- "version": "8.73.1-alpha.1",
3
+ "version": "8.73.1-alpha.10",
4
4
  "description": "TypeScript plugin for ESLint",
5
5
  "files": [
6
6
  "dist",
@@ -47,10 +47,10 @@
47
47
  ],
48
48
  "dependencies": {
49
49
  "@eslint-community/regexpp": "^4.12.2",
50
- "@typescript-eslint/scope-manager": "8.73.1-alpha.1",
51
- "@typescript-eslint/type-utils": "8.73.1-alpha.1",
52
- "@typescript-eslint/utils": "8.73.1-alpha.1",
53
- "@typescript-eslint/visitor-keys": "8.73.1-alpha.1",
50
+ "@typescript-eslint/scope-manager": "8.73.1-alpha.10",
51
+ "@typescript-eslint/type-utils": "8.73.1-alpha.10",
52
+ "@typescript-eslint/utils": "8.73.1-alpha.10",
53
+ "@typescript-eslint/visitor-keys": "8.73.1-alpha.10",
54
54
  "ignore": "^7.0.5",
55
55
  "natural-compare": "^1.4.0",
56
56
  "ts-api-utils": "^2.5.0"
@@ -60,8 +60,8 @@
60
60
  "@types/mdast": "^4.0.4",
61
61
  "@types/natural-compare": "^1.4.3",
62
62
  "@types/react": "^18.3.21",
63
- "@typescript-eslint/rule-schema-to-typescript-types": "8.73.1-alpha.1",
64
- "@typescript-eslint/rule-tester": "8.73.1-alpha.1",
63
+ "@typescript-eslint/rule-schema-to-typescript-types": "8.73.1-alpha.10",
64
+ "@typescript-eslint/rule-tester": "8.73.1-alpha.10",
65
65
  "@typescript/native": "npm:typescript@7.1.0-dev.20261009.1",
66
66
  "@vitest/coverage-v8": "^5.0.3",
67
67
  "ajv": "^6.12.6",
@@ -81,7 +81,7 @@
81
81
  "vitest": "^5.0.3"
82
82
  },
83
83
  "peerDependencies": {
84
- "@typescript-eslint/parser": "^8.73.1-alpha.1",
84
+ "@typescript-eslint/parser": "^8.73.1-alpha.10",
85
85
  "eslint": "^8.57.0 || ^9.0.0 || ^10.0.0",
86
86
  "typescript": ">=4.8.4 <6.1.0"
87
87
  },