@typescript-eslint/eslint-plugin 8.65.1-alpha.9 → 8.66.1-alpha.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.
@@ -113,22 +113,29 @@ exports.default = (0, util_1.createRule)({
113
113
  if (hasDuplicateKeySetter) {
114
114
  return;
115
115
  }
116
+ const getterBody = node.value.body;
116
117
  context.report({
117
118
  node: node.key,
118
119
  messageId: 'preferFieldStyle',
119
- suggest: [
120
- {
120
+ ...(0, util_1.getFixOrSuggest)({
121
+ fixOrSuggest: node.decorators.length === 0 ? 'suggest' : 'none',
122
+ suggestion: {
121
123
  messageId: 'preferFieldStyleSuggestion',
122
124
  fix(fixer) {
123
125
  const name = context.sourceCode.getText(node.key);
126
+ const closingParen = (0, util_1.nullThrows)(context.sourceCode.getTokenBefore(node.value.returnType ?? getterBody), 'Getter should have a closing parenthesis.');
127
+ const betweenParensAndBody = context.sourceCode
128
+ .getText()
129
+ .slice(closingParen.range[1], getterBody.range[0]);
124
130
  let text = '';
125
131
  text += printNodeModifiers(node, 'readonly');
126
132
  text += node.computed ? `[${name}]` : name;
127
- text += ` = ${context.sourceCode.getText(argument)};`;
133
+ text += betweenParensAndBody;
134
+ text += `= ${context.sourceCode.getText(argument)};`;
128
135
  return fixer.replaceText(node, text);
129
136
  },
130
137
  },
131
- ],
138
+ }),
132
139
  });
133
140
  },
134
141
  }),
@@ -233,7 +233,7 @@ exports.default = (0, util_1.createRule)({
233
233
  }
234
234
  const typeFlag = builtInTypeFlags[nodeCallee.name];
235
235
  const scope = context.sourceCode.getScope(node);
236
- const variable = scope.set.get(nodeCallee.name);
236
+ const variable = utils_1.ASTUtils.findVariable(scope, nodeCallee.name);
237
237
  if (!!variable?.defs.length ||
238
238
  !doesUnderlyingTypeMatchFlag((0, util_1.getConstrainedTypeAtLocation)(services, node.arguments[0]), typeFlag)) {
239
239
  return;
@@ -356,6 +356,11 @@ function collectTypeParameterUsageCounts(checker, node, foundIdentifierUsages, f
356
356
  // They have properties, so we need to avoid double-counting.
357
357
  visitType(type.templateType ?? type.constraintType, false);
358
358
  }
359
+ // TS doesn't count mapped types key remapping (`{[K in 'a' as T]: K}`)
360
+ // but handles this under `MappedType.nameType`, so we need to visit that too.
361
+ if (type.nameType) {
362
+ visitType(type.nameType, false);
363
+ }
359
364
  }
360
365
  visitType(type.getNumberIndexType(), true);
361
366
  visitType(type.getStringIndexType(), true);
@@ -138,21 +138,24 @@ exports.default = (0, util_1.createRule)({
138
138
  signatures[0].getDeclaration() === tsFunc) {
139
139
  return;
140
140
  }
141
- const params = signatures[0].getParameters();
142
- if (paramIndex < params.length) {
141
+ const defaultCanBeUsed = signatures.some(signature => {
142
+ const params = signature.getParameters();
143
+ if (paramIndex >= params.length) {
144
+ return true;
145
+ }
143
146
  const paramSymbol = params[paramIndex];
144
147
  if (paramSymbol.valueDeclaration &&
145
- ts.isParameter(paramSymbol.valueDeclaration) &&
146
- paramSymbol.valueDeclaration.dotDotDotToken != null) {
147
- return;
148
+ (0, util_1.isRestParameterDeclaration)(paramSymbol.valueDeclaration)) {
149
+ return true;
148
150
  }
149
- if (!tsutils.isSymbolFlagSet(paramSymbol, ts.SymbolFlags.Optional)) {
150
- const paramType = checker.getTypeOfSymbol(paramSymbol);
151
- if (!tsutils.isTypeParameter(paramType) &&
152
- !canBeUndefined(paramType)) {
153
- reportUselessDefaultAssignment(node, 'parameter');
154
- }
151
+ if (tsutils.isSymbolFlagSet(paramSymbol, ts.SymbolFlags.Optional)) {
152
+ return true;
155
153
  }
154
+ const paramType = checker.getTypeOfSymbol(paramSymbol);
155
+ return (tsutils.isTypeParameter(paramType) || canBeUndefined(paramType));
156
+ });
157
+ if (!defaultCanBeUsed) {
158
+ reportUselessDefaultAssignment(node, 'parameter');
156
159
  }
157
160
  }
158
161
  }
@@ -468,7 +468,7 @@ function isBuiltInBooleanCall(node, context) {
468
468
  node.callee.name === 'Boolean' &&
469
469
  node.arguments[0]) {
470
470
  const scope = context.sourceCode.getScope(node);
471
- const variable = scope.set.get(utils_1.AST_TOKEN_TYPES.Boolean);
471
+ const variable = utils_1.ASTUtils.findVariable(scope, node.callee);
472
472
  return variable == null || variable.defs.length === 0;
473
473
  }
474
474
  return false;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@typescript-eslint/eslint-plugin",
3
- "version": "8.65.1-alpha.9",
3
+ "version": "8.66.1-alpha.0",
4
4
  "description": "TypeScript plugin for ESLint",
5
5
  "files": [
6
6
  "dist",
@@ -49,10 +49,10 @@
49
49
  "ignore": "^7.0.5",
50
50
  "natural-compare": "^1.4.0",
51
51
  "ts-api-utils": "^2.5.0",
52
- "@typescript-eslint/scope-manager": "8.65.1-alpha.9",
53
- "@typescript-eslint/utils": "8.65.1-alpha.9",
54
- "@typescript-eslint/visitor-keys": "8.65.1-alpha.9",
55
- "@typescript-eslint/type-utils": "8.65.1-alpha.9"
52
+ "@typescript-eslint/scope-manager": "8.66.1-alpha.0",
53
+ "@typescript-eslint/type-utils": "8.66.1-alpha.0",
54
+ "@typescript-eslint/utils": "8.66.1-alpha.0",
55
+ "@typescript-eslint/visitor-keys": "8.66.1-alpha.0"
56
56
  },
57
57
  "devDependencies": {
58
58
  "@types/json-schema": "^7.0.15",
@@ -76,13 +76,13 @@
76
76
  "typescript": ">=4.8.4 <6.1.0",
77
77
  "unist-util-visit": "^5.0.0",
78
78
  "vitest": "^4.0.18",
79
- "@typescript-eslint/rule-schema-to-typescript-types": "8.65.1-alpha.9",
80
- "@typescript-eslint/rule-tester": "8.65.1-alpha.9"
79
+ "@typescript-eslint/rule-tester": "8.66.1-alpha.0",
80
+ "@typescript-eslint/rule-schema-to-typescript-types": "8.66.1-alpha.0"
81
81
  },
82
82
  "peerDependencies": {
83
83
  "eslint": "^8.57.0 || ^9.0.0 || ^10.0.0",
84
84
  "typescript": ">=4.8.4 <6.1.0",
85
- "@typescript-eslint/parser": "^8.65.1-alpha.9"
85
+ "@typescript-eslint/parser": "^8.66.1-alpha.0"
86
86
  },
87
87
  "funding": {
88
88
  "type": "opencollective",