eslint-plugin-react-x 4.2.4-beta.0 → 5.0.0-beta.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.
- package/README.md +1 -1
- package/dist/index.js +190 -362
- package/package.json +7 -7
package/README.md
CHANGED
package/dist/index.js
CHANGED
|
@@ -4,12 +4,11 @@ import * as core from "@eslint-react/core";
|
|
|
4
4
|
import { isUseRefCall } from "@eslint-react/core";
|
|
5
5
|
import { AST_NODE_TYPES } from "@typescript-eslint/types";
|
|
6
6
|
import { ESLintUtils } from "@typescript-eslint/utils";
|
|
7
|
-
import { P, isMatching, match } from "ts-pattern";
|
|
8
|
-
import ts from "typescript";
|
|
9
7
|
import { JsxDetectionHint, findParentAttribute, getElementFullType, hasAttribute, isJsxLike } from "@eslint-react/jsx";
|
|
10
8
|
import { computeObjectType, findEnclosingAssignmentTarget, isAssignmentTargetEqual, resolve } from "@eslint-react/var";
|
|
11
9
|
import { DefinitionType } from "@typescript-eslint/scope-manager";
|
|
12
10
|
import { findVariable, getStaticValue, isIdentifier, isVariableDeclarator } from "@typescript-eslint/utils/ast-utils";
|
|
11
|
+
import { P, isMatching, match } from "ts-pattern";
|
|
13
12
|
import { compare } from "compare-versions";
|
|
14
13
|
import { getConstrainedTypeAtLocation } from "@typescript-eslint/type-utils";
|
|
15
14
|
import { unionConstituents } from "ts-api-utils";
|
|
@@ -68,7 +67,6 @@ const conflictingRules$1 = [
|
|
|
68
67
|
"react/no-find-dom-node",
|
|
69
68
|
"react/no-namespace",
|
|
70
69
|
"react/no-object-type-as-default-prop",
|
|
71
|
-
"react/no-redundant-should-component-update",
|
|
72
70
|
"react/no-render-return-value",
|
|
73
71
|
"react/no-string-refs",
|
|
74
72
|
"react/no-unknown-property",
|
|
@@ -145,7 +143,7 @@ const rules$7 = {
|
|
|
145
143
|
//#endregion
|
|
146
144
|
//#region package.json
|
|
147
145
|
var name$6 = "eslint-plugin-react-x";
|
|
148
|
-
var version = "
|
|
146
|
+
var version = "5.0.0-beta.0";
|
|
149
147
|
|
|
150
148
|
//#endregion
|
|
151
149
|
//#region src/utils/create-rule.ts
|
|
@@ -154,155 +152,9 @@ function getDocsUrl(ruleName) {
|
|
|
154
152
|
}
|
|
155
153
|
const createRule = ESLintUtils.RuleCreator(getDocsUrl);
|
|
156
154
|
|
|
157
|
-
//#endregion
|
|
158
|
-
//#region src/utils/type-is.ts
|
|
159
|
-
function isFlagSet(allFlags, flag) {
|
|
160
|
-
return (allFlags & flag) !== 0;
|
|
161
|
-
}
|
|
162
|
-
function isFlagSetOnObject(obj, flag) {
|
|
163
|
-
return isFlagSet(obj.flags, flag);
|
|
164
|
-
}
|
|
165
|
-
const isTypeFlagSet = isFlagSetOnObject;
|
|
166
|
-
function isBooleanLiteralType(type) {
|
|
167
|
-
return isTypeFlagSet(type, ts.TypeFlags.BooleanLiteral);
|
|
168
|
-
}
|
|
169
|
-
/** @internal */
|
|
170
|
-
const isFalseLiteralType = (type) => isBooleanLiteralType(type) && type.intrinsicName === "false";
|
|
171
|
-
/** @internal */
|
|
172
|
-
const isTrueLiteralType = (type) => isBooleanLiteralType(type) && type.intrinsicName === "true";
|
|
173
|
-
/** @internal */
|
|
174
|
-
const isAnyType = (type) => isTypeFlagSet(type, ts.TypeFlags.TypeParameter | ts.TypeFlags.Any);
|
|
175
|
-
/** @internal */
|
|
176
|
-
const isBigIntType = (type) => isTypeFlagSet(type, ts.TypeFlags.BigIntLike);
|
|
177
|
-
/** @internal */
|
|
178
|
-
const isBooleanType = (type) => isTypeFlagSet(type, ts.TypeFlags.BooleanLike);
|
|
179
|
-
/** @internal */
|
|
180
|
-
const isEnumType = (type) => isTypeFlagSet(type, ts.TypeFlags.EnumLike);
|
|
181
|
-
/** @internal */
|
|
182
|
-
const isFalsyBigIntType = (type) => type.isLiteral() && isMatching({ value: { base10Value: "0" } }, type);
|
|
183
|
-
/** @internal */
|
|
184
|
-
const isFalsyNumberType = (type) => type.isNumberLiteral() && type.value === 0;
|
|
185
|
-
/** @internal */
|
|
186
|
-
const isFalsyStringType = (type) => type.isStringLiteral() && type.value === "";
|
|
187
|
-
/** @internal */
|
|
188
|
-
const isNeverType = (type) => isTypeFlagSet(type, ts.TypeFlags.Never);
|
|
189
|
-
/** @internal */
|
|
190
|
-
const isNullishType = (type) => isTypeFlagSet(type, ts.TypeFlags.Null | ts.TypeFlags.Undefined | ts.TypeFlags.VoidLike);
|
|
191
|
-
/** @internal */
|
|
192
|
-
const isNumberType = (type) => isTypeFlagSet(type, ts.TypeFlags.NumberLike);
|
|
193
|
-
/** @internal */
|
|
194
|
-
const isObjectType = (type) => !isTypeFlagSet(type, ts.TypeFlags.Null | ts.TypeFlags.Undefined | ts.TypeFlags.VoidLike | ts.TypeFlags.BooleanLike | ts.TypeFlags.StringLike | ts.TypeFlags.NumberLike | ts.TypeFlags.BigIntLike | ts.TypeFlags.TypeParameter | ts.TypeFlags.Any | ts.TypeFlags.Unknown | ts.TypeFlags.Never);
|
|
195
|
-
/** @internal */
|
|
196
|
-
const isStringType = (type) => isTypeFlagSet(type, ts.TypeFlags.StringLike);
|
|
197
|
-
/** @internal */
|
|
198
|
-
const isTruthyBigIntType = (type) => type.isLiteral() && isMatching({ value: { base10Value: P.not("0") } }, type);
|
|
199
|
-
/** @internal */
|
|
200
|
-
const isTruthyNumberType = (type) => type.isNumberLiteral() && type.value !== 0;
|
|
201
|
-
/** @internal */
|
|
202
|
-
const isTruthyStringType = (type) => type.isStringLiteral() && type.value !== "";
|
|
203
|
-
/** @internal */
|
|
204
|
-
const isUnknownType = (type) => isTypeFlagSet(type, ts.TypeFlags.Unknown);
|
|
205
|
-
|
|
206
|
-
//#endregion
|
|
207
|
-
//#region src/utils/type-name.ts
|
|
208
|
-
/**
|
|
209
|
-
* An enhanced version of getFullyQualifiedName that handles cases that original function does not handle
|
|
210
|
-
* @param checker TypeScript type checker
|
|
211
|
-
* @param symbol Symbol to get fully qualified name for
|
|
212
|
-
* @returns Fully qualified name of the symbol
|
|
213
|
-
*/
|
|
214
|
-
function getFullyQualifiedNameEx(checker, symbol) {
|
|
215
|
-
let name = symbol.name;
|
|
216
|
-
let parent = symbol.declarations?.at(0)?.parent;
|
|
217
|
-
if (parent == null) return checker.getFullyQualifiedName(symbol);
|
|
218
|
-
while (parent.kind !== ts.SyntaxKind.SourceFile) {
|
|
219
|
-
switch (true) {
|
|
220
|
-
case ts.isInterfaceDeclaration(parent):
|
|
221
|
-
case ts.isTypeAliasDeclaration(parent):
|
|
222
|
-
case ts.isEnumDeclaration(parent):
|
|
223
|
-
case ts.isModuleDeclaration(parent):
|
|
224
|
-
case ts.isNamespaceImport(parent):
|
|
225
|
-
case ts.isNamespaceExport(parent):
|
|
226
|
-
case ts.isNamespaceExportDeclaration(parent):
|
|
227
|
-
name = `${parent.name.text}.${name}`;
|
|
228
|
-
break;
|
|
229
|
-
case ts.isPropertySignature(parent) && ts.isIdentifier(parent.name):
|
|
230
|
-
case ts.isPropertyDeclaration(parent) && ts.isIdentifier(parent.name):
|
|
231
|
-
case ts.isMethodDeclaration(parent) && ts.isIdentifier(parent.name):
|
|
232
|
-
case ts.isMethodSignature(parent) && ts.isIdentifier(parent.name):
|
|
233
|
-
case ts.isPropertyAssignment(parent) && ts.isIdentifier(parent.name):
|
|
234
|
-
name = `${parent.name.text}.${name}`;
|
|
235
|
-
break;
|
|
236
|
-
case ts.isFunctionDeclaration(parent) && parent.name != null:
|
|
237
|
-
case ts.isClassExpression(parent) && parent.name != null:
|
|
238
|
-
case ts.isClassDeclaration(parent) && parent.name != null:
|
|
239
|
-
name = `${parent.name.text}.${name}`;
|
|
240
|
-
break;
|
|
241
|
-
case ts.isEnumMember(parent):
|
|
242
|
-
name = `${parent.name.getText()}.${name}`;
|
|
243
|
-
break;
|
|
244
|
-
case ts.isTypeLiteralNode(parent):
|
|
245
|
-
case ts.isMappedTypeNode(parent):
|
|
246
|
-
case ts.isObjectLiteralExpression(parent):
|
|
247
|
-
case ts.isIntersectionTypeNode(parent):
|
|
248
|
-
case ts.isUnionTypeNode(parent): break;
|
|
249
|
-
default: break;
|
|
250
|
-
}
|
|
251
|
-
parent = parent.parent;
|
|
252
|
-
}
|
|
253
|
-
const namespace = parent.getSourceFile().statements.find((n) => ts.isNamespaceExportDeclaration(n))?.name.text;
|
|
254
|
-
if (namespace == null) return name;
|
|
255
|
-
if (name.startsWith(`${namespace}.`)) return name;
|
|
256
|
-
return `${namespace}.${name}`;
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
//#endregion
|
|
260
|
-
//#region src/utils/type-variant.ts
|
|
261
|
-
/**
|
|
262
|
-
* Ported from https://github.com/typescript-eslint/typescript-eslint/blob/eb736bbfc22554694400e6a4f97051d845d32e0b/packages/eslint-plugin/src/rules/strict-boolean-expressions.ts#L826 with some enhancements
|
|
263
|
-
* Get the variants of an array of types.
|
|
264
|
-
* @param types The types to get the variants of
|
|
265
|
-
* @returns The variants of the types
|
|
266
|
-
* @internal
|
|
267
|
-
*/
|
|
268
|
-
function getTypeVariants(types) {
|
|
269
|
-
const variants = /* @__PURE__ */ new Set();
|
|
270
|
-
if (types.some(isUnknownType)) {
|
|
271
|
-
variants.add("unknown");
|
|
272
|
-
return variants;
|
|
273
|
-
}
|
|
274
|
-
if (types.some(isNullishType)) variants.add("nullish");
|
|
275
|
-
const booleans = types.filter(isBooleanType);
|
|
276
|
-
const boolean0 = booleans[0];
|
|
277
|
-
if (booleans.length === 1 && boolean0 != null) {
|
|
278
|
-
if (isFalseLiteralType(boolean0)) variants.add("falsy boolean");
|
|
279
|
-
else if (isTrueLiteralType(boolean0)) variants.add("truthy boolean");
|
|
280
|
-
} else if (booleans.length === 2) variants.add("boolean");
|
|
281
|
-
const strings = types.filter(isStringType);
|
|
282
|
-
if (strings.length > 0) {
|
|
283
|
-
const evaluated = match(strings).when((types) => types.every(isTruthyStringType), () => "truthy string").when((types) => types.every(isFalsyStringType), () => "falsy string").otherwise(() => "string");
|
|
284
|
-
variants.add(evaluated);
|
|
285
|
-
}
|
|
286
|
-
const bigints = types.filter(isBigIntType);
|
|
287
|
-
if (bigints.length > 0) {
|
|
288
|
-
const evaluated = match(bigints).when((types) => types.every(isTruthyBigIntType), () => "truthy bigint").when((types) => types.every(isFalsyBigIntType), () => "falsy bigint").otherwise(() => "bigint");
|
|
289
|
-
variants.add(evaluated);
|
|
290
|
-
}
|
|
291
|
-
const numbers = types.filter(isNumberType);
|
|
292
|
-
if (numbers.length > 0) {
|
|
293
|
-
const evaluated = match(numbers).when((types) => types.every(isTruthyNumberType), () => "truthy number").when((types) => types.every(isFalsyNumberType), () => "falsy number").otherwise(() => "number");
|
|
294
|
-
variants.add(evaluated);
|
|
295
|
-
}
|
|
296
|
-
if (types.some(isEnumType)) variants.add("enum");
|
|
297
|
-
if (types.some(isObjectType)) variants.add("object");
|
|
298
|
-
if (types.some(isAnyType)) variants.add("any");
|
|
299
|
-
if (types.some(isNeverType)) variants.add("never");
|
|
300
|
-
return variants;
|
|
301
|
-
}
|
|
302
|
-
|
|
303
155
|
//#endregion
|
|
304
156
|
//#region src/rules/component-hook-factories/component-hook-factories.ts
|
|
305
|
-
const RULE_NAME$
|
|
157
|
+
const RULE_NAME$53 = "component-hook-factories";
|
|
306
158
|
var component_hook_factories_default = createRule({
|
|
307
159
|
meta: {
|
|
308
160
|
type: "problem",
|
|
@@ -313,8 +165,8 @@ var component_hook_factories_default = createRule({
|
|
|
313
165
|
},
|
|
314
166
|
schema: []
|
|
315
167
|
},
|
|
316
|
-
name: RULE_NAME$
|
|
317
|
-
create: create$
|
|
168
|
+
name: RULE_NAME$53,
|
|
169
|
+
create: create$53,
|
|
318
170
|
defaultOptions: []
|
|
319
171
|
});
|
|
320
172
|
/**
|
|
@@ -348,7 +200,7 @@ function isComponentTypeName(typeName) {
|
|
|
348
200
|
*/
|
|
349
201
|
function isHigherOrderComponent(fn) {
|
|
350
202
|
return fn.params.some((param) => {
|
|
351
|
-
if (param.type === AST_NODE_TYPES.Identifier && core.
|
|
203
|
+
if (param.type === AST_NODE_TYPES.Identifier && core.isFunctionComponentNameLoose(param.name)) return true;
|
|
352
204
|
if (hasComponentTypeAnnotation(param)) return true;
|
|
353
205
|
return false;
|
|
354
206
|
});
|
|
@@ -360,10 +212,10 @@ function isHigherOrderComponent(fn) {
|
|
|
360
212
|
function isInsideTestMockCallback(node) {
|
|
361
213
|
return ast.findParent(node, ast.isTestMockCallback) != null;
|
|
362
214
|
}
|
|
363
|
-
function create$
|
|
364
|
-
const hint = core.
|
|
365
|
-
const fCollector = core.
|
|
366
|
-
const cCollector = core.
|
|
215
|
+
function create$53(context) {
|
|
216
|
+
const hint = core.FunctionComponentDetectionHint.DoNotIncludeJsxWithNumberValue | core.FunctionComponentDetectionHint.DoNotIncludeJsxWithBooleanValue | core.FunctionComponentDetectionHint.DoNotIncludeJsxWithNullValue | core.FunctionComponentDetectionHint.DoNotIncludeJsxWithStringValue | core.FunctionComponentDetectionHint.DoNotIncludeJsxWithUndefinedValue | core.FunctionComponentDetectionHint.RequireBothSidesOfLogicalExpressionToBeJsx | core.FunctionComponentDetectionHint.RequireBothBranchesOfConditionalExpressionToBeJsx | core.FunctionComponentDetectionHint.DoNotIncludeFunctionDefinedAsArrayPatternElement | core.FunctionComponentDetectionHint.DoNotIncludeFunctionDefinedAsArrayExpressionElement | core.FunctionComponentDetectionHint.DoNotIncludeFunctionDefinedAsArrayMapCallback;
|
|
217
|
+
const fCollector = core.getFunctionComponentCollector(context, { hint });
|
|
218
|
+
const cCollector = core.getClassComponentCollector(context);
|
|
367
219
|
const hCollector = core.getHookCollector(context);
|
|
368
220
|
const reported = /* @__PURE__ */ new Set();
|
|
369
221
|
return defineRuleListener(fCollector.visitor, cCollector.visitor, hCollector.visitor, { "Program:exit"(program) {
|
|
@@ -411,7 +263,7 @@ function create$54(context) {
|
|
|
411
263
|
|
|
412
264
|
//#endregion
|
|
413
265
|
//#region src/rules/error-boundaries/error-boundaries.ts
|
|
414
|
-
const RULE_NAME$
|
|
266
|
+
const RULE_NAME$52 = "error-boundaries";
|
|
415
267
|
var error_boundaries_default = createRule({
|
|
416
268
|
meta: {
|
|
417
269
|
type: "problem",
|
|
@@ -422,29 +274,38 @@ var error_boundaries_default = createRule({
|
|
|
422
274
|
},
|
|
423
275
|
schema: []
|
|
424
276
|
},
|
|
425
|
-
name: RULE_NAME$
|
|
426
|
-
create: create$
|
|
277
|
+
name: RULE_NAME$52,
|
|
278
|
+
create: create$52,
|
|
427
279
|
defaultOptions: []
|
|
428
280
|
});
|
|
429
|
-
function create$
|
|
281
|
+
function create$52(context) {
|
|
430
282
|
if (!context.sourceCode.text.includes("try")) return {};
|
|
431
283
|
const hint = JsxDetectionHint.DoNotIncludeJsxWithNullValue | JsxDetectionHint.DoNotIncludeJsxWithNumberValue | JsxDetectionHint.DoNotIncludeJsxWithBigIntValue | JsxDetectionHint.DoNotIncludeJsxWithStringValue | JsxDetectionHint.DoNotIncludeJsxWithBooleanValue | JsxDetectionHint.DoNotIncludeJsxWithUndefinedValue | JsxDetectionHint.DoNotIncludeJsxWithEmptyArrayValue;
|
|
432
|
-
const
|
|
284
|
+
const fCollector = core.getFunctionComponentCollector(context);
|
|
285
|
+
const hCollector = core.getHookCollector(context);
|
|
433
286
|
const reported = /* @__PURE__ */ new Set();
|
|
434
|
-
|
|
287
|
+
const useCalls = /* @__PURE__ */ new Set();
|
|
288
|
+
return defineRuleListener(fCollector.visitor, hCollector.visitor, {
|
|
435
289
|
CallExpression(node) {
|
|
436
|
-
if (!core.isUseCall(node)) return;
|
|
437
|
-
|
|
438
|
-
if (stmt != null && !reported.has(stmt)) {
|
|
439
|
-
context.report({
|
|
440
|
-
messageId: "tryCatchWithUse",
|
|
441
|
-
node
|
|
442
|
-
});
|
|
443
|
-
reported.add(stmt);
|
|
444
|
-
}
|
|
290
|
+
if (!core.isUseCall(context, node)) return;
|
|
291
|
+
useCalls.add(node);
|
|
445
292
|
},
|
|
446
293
|
"Program:exit"(node) {
|
|
447
|
-
|
|
294
|
+
const comps = fCollector.api.getAllComponents(node);
|
|
295
|
+
const hooks = hCollector.api.getAllHooks(node);
|
|
296
|
+
const funcs = [...comps, ...hooks];
|
|
297
|
+
for (const call of useCalls) {
|
|
298
|
+
const stmt = ast.findParent(call, ast.is(AST_NODE_TYPES.TryStatement));
|
|
299
|
+
const func = ast.findParent(stmt, (n) => funcs.some((f) => f.node === n));
|
|
300
|
+
if (stmt != null && func != null && !reported.has(stmt)) {
|
|
301
|
+
context.report({
|
|
302
|
+
messageId: "tryCatchWithUse",
|
|
303
|
+
node: stmt
|
|
304
|
+
});
|
|
305
|
+
reported.add(stmt);
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
for (const { rets } of funcs) for (const ret of rets) {
|
|
448
309
|
if (ret == null) continue;
|
|
449
310
|
if (!isJsxLike(context, ret, hint)) continue;
|
|
450
311
|
const stmt = ast.findParent(ret, ast.is(AST_NODE_TYPES.TryStatement));
|
|
@@ -1368,7 +1229,7 @@ function getUnknownDependenciesMessage(reactiveHookName) {
|
|
|
1368
1229
|
|
|
1369
1230
|
//#endregion
|
|
1370
1231
|
//#region src/rules/immutability/immutability.ts
|
|
1371
|
-
const RULE_NAME$
|
|
1232
|
+
const RULE_NAME$51 = "immutability";
|
|
1372
1233
|
/**
|
|
1373
1234
|
* Array methods that mutate the array in place.
|
|
1374
1235
|
* @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array
|
|
@@ -1394,14 +1255,14 @@ var immutability_default = createRule({
|
|
|
1394
1255
|
},
|
|
1395
1256
|
schema: []
|
|
1396
1257
|
},
|
|
1397
|
-
name: RULE_NAME$
|
|
1398
|
-
create: create$
|
|
1258
|
+
name: RULE_NAME$51,
|
|
1259
|
+
create: create$51,
|
|
1399
1260
|
defaultOptions: []
|
|
1400
1261
|
});
|
|
1401
|
-
function create$
|
|
1262
|
+
function create$51(context) {
|
|
1402
1263
|
const { additionalStateHooks } = getSettingsFromContext(context);
|
|
1403
1264
|
const hCollector = core.getHookCollector(context);
|
|
1404
|
-
const cCollector = core.
|
|
1265
|
+
const cCollector = core.getFunctionComponentCollector(context);
|
|
1405
1266
|
/**
|
|
1406
1267
|
* Violations accumulated while traversing. Each entry records the node to
|
|
1407
1268
|
* report and the enclosing function so we can filter at Program:exit.
|
|
@@ -1714,7 +1575,7 @@ function getOrInsertComputed(map, key, callback) {
|
|
|
1714
1575
|
|
|
1715
1576
|
//#endregion
|
|
1716
1577
|
//#region src/rules/no-access-state-in-setstate/no-access-state-in-setstate.ts
|
|
1717
|
-
const RULE_NAME$
|
|
1578
|
+
const RULE_NAME$50 = "no-access-state-in-setstate";
|
|
1718
1579
|
function isKeyLiteral$2(node, key) {
|
|
1719
1580
|
return match(key).with({ type: AST_NODE_TYPES.Literal }, constTrue).with({
|
|
1720
1581
|
type: AST_NODE_TYPES.TemplateLiteral,
|
|
@@ -1728,11 +1589,11 @@ var no_access_state_in_setstate_default = createRule({
|
|
|
1728
1589
|
messages: { default: "Do not access 'this.state' within 'setState'. Use the update function instead." },
|
|
1729
1590
|
schema: []
|
|
1730
1591
|
},
|
|
1731
|
-
name: RULE_NAME$
|
|
1732
|
-
create: create$
|
|
1592
|
+
name: RULE_NAME$50,
|
|
1593
|
+
create: create$50,
|
|
1733
1594
|
defaultOptions: []
|
|
1734
1595
|
});
|
|
1735
|
-
function create$
|
|
1596
|
+
function create$50(context) {
|
|
1736
1597
|
if (!context.sourceCode.text.includes("setState")) return {};
|
|
1737
1598
|
const classStack = [];
|
|
1738
1599
|
const methodStack = [];
|
|
@@ -1803,7 +1664,7 @@ function create$51(context) {
|
|
|
1803
1664
|
|
|
1804
1665
|
//#endregion
|
|
1805
1666
|
//#region src/rules/no-array-index-key/no-array-index-key.ts
|
|
1806
|
-
const RULE_NAME$
|
|
1667
|
+
const RULE_NAME$49 = "no-array-index-key";
|
|
1807
1668
|
function getIndexParamPosition(methodName) {
|
|
1808
1669
|
switch (methodName) {
|
|
1809
1670
|
case "every":
|
|
@@ -1848,11 +1709,11 @@ var no_array_index_key_default = createRule({
|
|
|
1848
1709
|
messages: { default: "Do not use item index in the array as its key." },
|
|
1849
1710
|
schema: []
|
|
1850
1711
|
},
|
|
1851
|
-
name: RULE_NAME$
|
|
1852
|
-
create: create$
|
|
1712
|
+
name: RULE_NAME$49,
|
|
1713
|
+
create: create$49,
|
|
1853
1714
|
defaultOptions: []
|
|
1854
1715
|
});
|
|
1855
|
-
function create$
|
|
1716
|
+
function create$49(context) {
|
|
1856
1717
|
const indexParamNames = [];
|
|
1857
1718
|
function isArrayIndex(node) {
|
|
1858
1719
|
return node.type === AST_NODE_TYPES.Identifier && indexParamNames.some((name) => name != null && name === node.name);
|
|
@@ -1918,7 +1779,7 @@ function create$50(context) {
|
|
|
1918
1779
|
|
|
1919
1780
|
//#endregion
|
|
1920
1781
|
//#region src/rules/no-children-count/no-children-count.ts
|
|
1921
|
-
const RULE_NAME$
|
|
1782
|
+
const RULE_NAME$48 = "no-children-count";
|
|
1922
1783
|
var no_children_count_default = createRule({
|
|
1923
1784
|
meta: {
|
|
1924
1785
|
type: "suggestion",
|
|
@@ -1926,11 +1787,11 @@ var no_children_count_default = createRule({
|
|
|
1926
1787
|
messages: { default: "Using 'Children.count' is uncommon and can lead to fragile code. Use alternatives instead." },
|
|
1927
1788
|
schema: []
|
|
1928
1789
|
},
|
|
1929
|
-
name: RULE_NAME$
|
|
1930
|
-
create: create$
|
|
1790
|
+
name: RULE_NAME$48,
|
|
1791
|
+
create: create$48,
|
|
1931
1792
|
defaultOptions: []
|
|
1932
1793
|
});
|
|
1933
|
-
function create$
|
|
1794
|
+
function create$48(context) {
|
|
1934
1795
|
return defineRuleListener({ MemberExpression(node) {
|
|
1935
1796
|
if (core.isChildrenCount(context, node)) context.report({
|
|
1936
1797
|
messageId: "default",
|
|
@@ -1941,7 +1802,7 @@ function create$49(context) {
|
|
|
1941
1802
|
|
|
1942
1803
|
//#endregion
|
|
1943
1804
|
//#region src/rules/no-children-for-each/no-children-for-each.ts
|
|
1944
|
-
const RULE_NAME$
|
|
1805
|
+
const RULE_NAME$47 = "no-children-for-each";
|
|
1945
1806
|
var no_children_for_each_default = createRule({
|
|
1946
1807
|
meta: {
|
|
1947
1808
|
type: "suggestion",
|
|
@@ -1949,11 +1810,11 @@ var no_children_for_each_default = createRule({
|
|
|
1949
1810
|
messages: { default: "Using 'Children.forEach' is uncommon and can lead to fragile code. Use alternatives instead." },
|
|
1950
1811
|
schema: []
|
|
1951
1812
|
},
|
|
1952
|
-
name: RULE_NAME$
|
|
1953
|
-
create: create$
|
|
1813
|
+
name: RULE_NAME$47,
|
|
1814
|
+
create: create$47,
|
|
1954
1815
|
defaultOptions: []
|
|
1955
1816
|
});
|
|
1956
|
-
function create$
|
|
1817
|
+
function create$47(context) {
|
|
1957
1818
|
return defineRuleListener({ MemberExpression(node) {
|
|
1958
1819
|
if (core.isChildrenForEach(context, node)) context.report({
|
|
1959
1820
|
messageId: "default",
|
|
@@ -1964,7 +1825,7 @@ function create$48(context) {
|
|
|
1964
1825
|
|
|
1965
1826
|
//#endregion
|
|
1966
1827
|
//#region src/rules/no-children-map/no-children-map.ts
|
|
1967
|
-
const RULE_NAME$
|
|
1828
|
+
const RULE_NAME$46 = "no-children-map";
|
|
1968
1829
|
var no_children_map_default = createRule({
|
|
1969
1830
|
meta: {
|
|
1970
1831
|
type: "suggestion",
|
|
@@ -1972,11 +1833,11 @@ var no_children_map_default = createRule({
|
|
|
1972
1833
|
messages: { default: "Using 'Children.map' is uncommon and can lead to fragile code. Use alternatives instead." },
|
|
1973
1834
|
schema: []
|
|
1974
1835
|
},
|
|
1975
|
-
name: RULE_NAME$
|
|
1976
|
-
create: create$
|
|
1836
|
+
name: RULE_NAME$46,
|
|
1837
|
+
create: create$46,
|
|
1977
1838
|
defaultOptions: []
|
|
1978
1839
|
});
|
|
1979
|
-
function create$
|
|
1840
|
+
function create$46(context) {
|
|
1980
1841
|
return defineRuleListener({ MemberExpression(node) {
|
|
1981
1842
|
if (core.isChildrenMap(context, node)) context.report({
|
|
1982
1843
|
messageId: "default",
|
|
@@ -1987,7 +1848,7 @@ function create$47(context) {
|
|
|
1987
1848
|
|
|
1988
1849
|
//#endregion
|
|
1989
1850
|
//#region src/rules/no-children-only/no-children-only.ts
|
|
1990
|
-
const RULE_NAME$
|
|
1851
|
+
const RULE_NAME$45 = "no-children-only";
|
|
1991
1852
|
var no_children_only_default = createRule({
|
|
1992
1853
|
meta: {
|
|
1993
1854
|
type: "suggestion",
|
|
@@ -1995,11 +1856,11 @@ var no_children_only_default = createRule({
|
|
|
1995
1856
|
messages: { default: "Using 'Children.only' is uncommon and can lead to fragile code. Use alternatives instead." },
|
|
1996
1857
|
schema: []
|
|
1997
1858
|
},
|
|
1998
|
-
name: RULE_NAME$
|
|
1999
|
-
create: create$
|
|
1859
|
+
name: RULE_NAME$45,
|
|
1860
|
+
create: create$45,
|
|
2000
1861
|
defaultOptions: []
|
|
2001
1862
|
});
|
|
2002
|
-
function create$
|
|
1863
|
+
function create$45(context) {
|
|
2003
1864
|
return defineRuleListener({ MemberExpression(node) {
|
|
2004
1865
|
if (core.isChildrenOnly(context, node)) context.report({
|
|
2005
1866
|
messageId: "default",
|
|
@@ -2010,7 +1871,7 @@ function create$46(context) {
|
|
|
2010
1871
|
|
|
2011
1872
|
//#endregion
|
|
2012
1873
|
//#region src/rules/no-children-to-array/no-children-to-array.ts
|
|
2013
|
-
const RULE_NAME$
|
|
1874
|
+
const RULE_NAME$44 = "no-children-to-array";
|
|
2014
1875
|
var no_children_to_array_default = createRule({
|
|
2015
1876
|
meta: {
|
|
2016
1877
|
type: "suggestion",
|
|
@@ -2018,11 +1879,11 @@ var no_children_to_array_default = createRule({
|
|
|
2018
1879
|
messages: { default: "Using 'Children.toArray' is uncommon and can lead to fragile code. Use alternatives instead." },
|
|
2019
1880
|
schema: []
|
|
2020
1881
|
},
|
|
2021
|
-
name: RULE_NAME$
|
|
2022
|
-
create: create$
|
|
1882
|
+
name: RULE_NAME$44,
|
|
1883
|
+
create: create$44,
|
|
2023
1884
|
defaultOptions: []
|
|
2024
1885
|
});
|
|
2025
|
-
function create$
|
|
1886
|
+
function create$44(context) {
|
|
2026
1887
|
return defineRuleListener({ MemberExpression(node) {
|
|
2027
1888
|
if (core.isChildrenToArray(context, node)) context.report({
|
|
2028
1889
|
messageId: "default",
|
|
@@ -2033,7 +1894,7 @@ function create$45(context) {
|
|
|
2033
1894
|
|
|
2034
1895
|
//#endregion
|
|
2035
1896
|
//#region src/rules/no-class-component/no-class-component.ts
|
|
2036
|
-
const RULE_NAME$
|
|
1897
|
+
const RULE_NAME$43 = "no-class-component";
|
|
2037
1898
|
var no_class_component_default = createRule({
|
|
2038
1899
|
meta: {
|
|
2039
1900
|
type: "suggestion",
|
|
@@ -2041,13 +1902,13 @@ var no_class_component_default = createRule({
|
|
|
2041
1902
|
messages: { default: "Avoid using class components. Use function components instead." },
|
|
2042
1903
|
schema: []
|
|
2043
1904
|
},
|
|
2044
|
-
name: RULE_NAME$
|
|
2045
|
-
create: create$
|
|
1905
|
+
name: RULE_NAME$43,
|
|
1906
|
+
create: create$43,
|
|
2046
1907
|
defaultOptions: []
|
|
2047
1908
|
});
|
|
2048
|
-
function create$
|
|
1909
|
+
function create$43(context) {
|
|
2049
1910
|
if (!context.sourceCode.text.includes("Component")) return {};
|
|
2050
|
-
const { api, visitor } = core.
|
|
1911
|
+
const { api, visitor } = core.getClassComponentCollector(context);
|
|
2051
1912
|
return defineRuleListener(visitor, { "Program:exit"(program) {
|
|
2052
1913
|
for (const { name = "anonymous", node: component } of api.getAllComponents(program)) {
|
|
2053
1914
|
if (component.body.body.some((m) => core.isComponentDidCatch(m) || core.isGetDerivedStateFromError(m))) continue;
|
|
@@ -2062,7 +1923,7 @@ function create$44(context) {
|
|
|
2062
1923
|
|
|
2063
1924
|
//#endregion
|
|
2064
1925
|
//#region src/rules/no-clone-element/no-clone-element.ts
|
|
2065
|
-
const RULE_NAME$
|
|
1926
|
+
const RULE_NAME$42 = "no-clone-element";
|
|
2066
1927
|
var no_clone_element_default = createRule({
|
|
2067
1928
|
meta: {
|
|
2068
1929
|
type: "suggestion",
|
|
@@ -2070,11 +1931,11 @@ var no_clone_element_default = createRule({
|
|
|
2070
1931
|
messages: { default: "Using 'cloneElement' is uncommon and can lead to fragile code. Use alternatives instead." },
|
|
2071
1932
|
schema: []
|
|
2072
1933
|
},
|
|
2073
|
-
name: RULE_NAME$
|
|
2074
|
-
create: create$
|
|
1934
|
+
name: RULE_NAME$42,
|
|
1935
|
+
create: create$42,
|
|
2075
1936
|
defaultOptions: []
|
|
2076
1937
|
});
|
|
2077
|
-
function create$
|
|
1938
|
+
function create$42(context) {
|
|
2078
1939
|
return defineRuleListener({ CallExpression(node) {
|
|
2079
1940
|
if (core.isCloneElementCall(context, node)) context.report({
|
|
2080
1941
|
messageId: "default",
|
|
@@ -2085,7 +1946,7 @@ function create$43(context) {
|
|
|
2085
1946
|
|
|
2086
1947
|
//#endregion
|
|
2087
1948
|
//#region src/rules/no-component-will-mount/no-component-will-mount.ts
|
|
2088
|
-
const RULE_NAME$
|
|
1949
|
+
const RULE_NAME$41 = "no-component-will-mount";
|
|
2089
1950
|
var no_component_will_mount_default = createRule({
|
|
2090
1951
|
meta: {
|
|
2091
1952
|
type: "problem",
|
|
@@ -2094,13 +1955,13 @@ var no_component_will_mount_default = createRule({
|
|
|
2094
1955
|
messages: { default: "[Deprecated] Use 'UNSAFE_componentWillMount' instead." },
|
|
2095
1956
|
schema: []
|
|
2096
1957
|
},
|
|
2097
|
-
name: RULE_NAME$
|
|
2098
|
-
create: create$
|
|
1958
|
+
name: RULE_NAME$41,
|
|
1959
|
+
create: create$41,
|
|
2099
1960
|
defaultOptions: []
|
|
2100
1961
|
});
|
|
2101
|
-
function create$
|
|
1962
|
+
function create$41(context) {
|
|
2102
1963
|
if (!context.sourceCode.text.includes("componentWillMount")) return {};
|
|
2103
|
-
const { api, visitor } = core.
|
|
1964
|
+
const { api, visitor } = core.getClassComponentCollector(context);
|
|
2104
1965
|
return defineRuleListener(visitor, { "Program:exit"(program) {
|
|
2105
1966
|
for (const { node: component } of api.getAllComponents(program)) {
|
|
2106
1967
|
const { body } = component.body;
|
|
@@ -2118,7 +1979,7 @@ function create$42(context) {
|
|
|
2118
1979
|
|
|
2119
1980
|
//#endregion
|
|
2120
1981
|
//#region src/rules/no-component-will-receive-props/no-component-will-receive-props.ts
|
|
2121
|
-
const RULE_NAME$
|
|
1982
|
+
const RULE_NAME$40 = "no-component-will-receive-props";
|
|
2122
1983
|
var no_component_will_receive_props_default = createRule({
|
|
2123
1984
|
meta: {
|
|
2124
1985
|
type: "problem",
|
|
@@ -2127,13 +1988,13 @@ var no_component_will_receive_props_default = createRule({
|
|
|
2127
1988
|
messages: { default: "[Deprecated] Use 'UNSAFE_componentWillReceiveProps' instead." },
|
|
2128
1989
|
schema: []
|
|
2129
1990
|
},
|
|
2130
|
-
name: RULE_NAME$
|
|
2131
|
-
create: create$
|
|
1991
|
+
name: RULE_NAME$40,
|
|
1992
|
+
create: create$40,
|
|
2132
1993
|
defaultOptions: []
|
|
2133
1994
|
});
|
|
2134
|
-
function create$
|
|
1995
|
+
function create$40(context) {
|
|
2135
1996
|
if (!context.sourceCode.text.includes("componentWillReceiveProps")) return {};
|
|
2136
|
-
const { api, visitor } = core.
|
|
1997
|
+
const { api, visitor } = core.getClassComponentCollector(context);
|
|
2137
1998
|
return defineRuleListener(visitor, { "Program:exit"(program) {
|
|
2138
1999
|
for (const { node: component } of api.getAllComponents(program)) {
|
|
2139
2000
|
const { body } = component.body;
|
|
@@ -2151,7 +2012,7 @@ function create$41(context) {
|
|
|
2151
2012
|
|
|
2152
2013
|
//#endregion
|
|
2153
2014
|
//#region src/rules/no-component-will-update/no-component-will-update.ts
|
|
2154
|
-
const RULE_NAME$
|
|
2015
|
+
const RULE_NAME$39 = "no-component-will-update";
|
|
2155
2016
|
var no_component_will_update_default = createRule({
|
|
2156
2017
|
meta: {
|
|
2157
2018
|
type: "problem",
|
|
@@ -2160,13 +2021,13 @@ var no_component_will_update_default = createRule({
|
|
|
2160
2021
|
messages: { default: "[Deprecated] Use 'UNSAFE_componentWillUpdate' instead." },
|
|
2161
2022
|
schema: []
|
|
2162
2023
|
},
|
|
2163
|
-
name: RULE_NAME$
|
|
2164
|
-
create: create$
|
|
2024
|
+
name: RULE_NAME$39,
|
|
2025
|
+
create: create$39,
|
|
2165
2026
|
defaultOptions: []
|
|
2166
2027
|
});
|
|
2167
|
-
function create$
|
|
2028
|
+
function create$39(context) {
|
|
2168
2029
|
if (!context.sourceCode.text.includes("componentWillUpdate")) return {};
|
|
2169
|
-
const { api, visitor } = core.
|
|
2030
|
+
const { api, visitor } = core.getClassComponentCollector(context);
|
|
2170
2031
|
return defineRuleListener(visitor, { "Program:exit"(program) {
|
|
2171
2032
|
for (const { node: component } of api.getAllComponents(program)) {
|
|
2172
2033
|
const { body } = component.body;
|
|
@@ -2184,7 +2045,7 @@ function create$40(context) {
|
|
|
2184
2045
|
|
|
2185
2046
|
//#endregion
|
|
2186
2047
|
//#region src/rules/no-context-provider/no-context-provider.ts
|
|
2187
|
-
const RULE_NAME$
|
|
2048
|
+
const RULE_NAME$38 = "no-context-provider";
|
|
2188
2049
|
var no_context_provider_default = createRule({
|
|
2189
2050
|
meta: {
|
|
2190
2051
|
type: "suggestion",
|
|
@@ -2197,11 +2058,11 @@ var no_context_provider_default = createRule({
|
|
|
2197
2058
|
},
|
|
2198
2059
|
schema: []
|
|
2199
2060
|
},
|
|
2200
|
-
name: RULE_NAME$
|
|
2201
|
-
create: create$
|
|
2061
|
+
name: RULE_NAME$38,
|
|
2062
|
+
create: create$38,
|
|
2202
2063
|
defaultOptions: []
|
|
2203
2064
|
});
|
|
2204
|
-
function create$
|
|
2065
|
+
function create$38(context) {
|
|
2205
2066
|
if (!context.sourceCode.text.includes("Provider")) return {};
|
|
2206
2067
|
const { version } = getSettingsFromContext(context);
|
|
2207
2068
|
if (compare(version, "19.0.0", "<")) return {};
|
|
@@ -2217,7 +2078,7 @@ function create$39(context) {
|
|
|
2217
2078
|
node,
|
|
2218
2079
|
suggest: [{
|
|
2219
2080
|
fix(fixer) {
|
|
2220
|
-
if (!core.
|
|
2081
|
+
if (!core.isFunctionComponentNameLoose(contextSelfName)) return null;
|
|
2221
2082
|
const openingElement = node.openingElement;
|
|
2222
2083
|
const closingElement = node.closingElement;
|
|
2223
2084
|
if (closingElement == null) return fixer.replaceText(openingElement.name, contextFullName);
|
|
@@ -2231,7 +2092,7 @@ function create$39(context) {
|
|
|
2231
2092
|
|
|
2232
2093
|
//#endregion
|
|
2233
2094
|
//#region src/rules/no-create-ref/no-create-ref.ts
|
|
2234
|
-
const RULE_NAME$
|
|
2095
|
+
const RULE_NAME$37 = "no-create-ref";
|
|
2235
2096
|
var no_create_ref_default = createRule({
|
|
2236
2097
|
meta: {
|
|
2237
2098
|
type: "suggestion",
|
|
@@ -2239,11 +2100,11 @@ var no_create_ref_default = createRule({
|
|
|
2239
2100
|
messages: { default: "[Deprecated] Use 'useRef' instead." },
|
|
2240
2101
|
schema: []
|
|
2241
2102
|
},
|
|
2242
|
-
name: RULE_NAME$
|
|
2243
|
-
create: create$
|
|
2103
|
+
name: RULE_NAME$37,
|
|
2104
|
+
create: create$37,
|
|
2244
2105
|
defaultOptions: []
|
|
2245
2106
|
});
|
|
2246
|
-
function create$
|
|
2107
|
+
function create$37(context) {
|
|
2247
2108
|
return defineRuleListener({ CallExpression(node) {
|
|
2248
2109
|
if (core.isCreateRefCall(context, node) && ast.findParent(node, core.isClassComponent) == null) context.report({
|
|
2249
2110
|
messageId: "default",
|
|
@@ -2254,7 +2115,7 @@ function create$38(context) {
|
|
|
2254
2115
|
|
|
2255
2116
|
//#endregion
|
|
2256
2117
|
//#region src/rules/no-direct-mutation-state/no-direct-mutation-state.ts
|
|
2257
|
-
const RULE_NAME$
|
|
2118
|
+
const RULE_NAME$36 = "no-direct-mutation-state";
|
|
2258
2119
|
function isConstructorFunction(node) {
|
|
2259
2120
|
return ast.isOneOf([AST_NODE_TYPES.FunctionDeclaration, AST_NODE_TYPES.FunctionExpression])(node) && ast.isMethodOrProperty(node.parent) && node.parent.key.type === AST_NODE_TYPES.Identifier && node.parent.key.name === "constructor";
|
|
2260
2121
|
}
|
|
@@ -2265,11 +2126,11 @@ var no_direct_mutation_state_default = createRule({
|
|
|
2265
2126
|
messages: { default: "Do not mutate state directly. Use 'setState()' instead." },
|
|
2266
2127
|
schema: []
|
|
2267
2128
|
},
|
|
2268
|
-
name: RULE_NAME$
|
|
2269
|
-
create: create$
|
|
2129
|
+
name: RULE_NAME$36,
|
|
2130
|
+
create: create$36,
|
|
2270
2131
|
defaultOptions: []
|
|
2271
2132
|
});
|
|
2272
|
-
function create$
|
|
2133
|
+
function create$36(context) {
|
|
2273
2134
|
return defineRuleListener({ AssignmentExpression(node) {
|
|
2274
2135
|
if (!core.isAssignmentToThisState(node)) return;
|
|
2275
2136
|
const parentClass = ast.findParent(node, ast.isOneOf([AST_NODE_TYPES.ClassDeclaration, AST_NODE_TYPES.ClassExpression]));
|
|
@@ -2283,7 +2144,7 @@ function create$37(context) {
|
|
|
2283
2144
|
|
|
2284
2145
|
//#endregion
|
|
2285
2146
|
//#region src/rules/no-duplicate-key/no-duplicate-key.ts
|
|
2286
|
-
const RULE_NAME$
|
|
2147
|
+
const RULE_NAME$35 = "no-duplicate-key";
|
|
2287
2148
|
var no_duplicate_key_default = createRule({
|
|
2288
2149
|
meta: {
|
|
2289
2150
|
type: "problem",
|
|
@@ -2291,11 +2152,11 @@ var no_duplicate_key_default = createRule({
|
|
|
2291
2152
|
messages: { default: "The 'key' prop must be unique to its sibling elements." },
|
|
2292
2153
|
schema: []
|
|
2293
2154
|
},
|
|
2294
|
-
name: RULE_NAME$
|
|
2295
|
-
create: create$
|
|
2155
|
+
name: RULE_NAME$35,
|
|
2156
|
+
create: create$35,
|
|
2296
2157
|
defaultOptions: []
|
|
2297
2158
|
});
|
|
2298
|
-
function create$
|
|
2159
|
+
function create$35(context) {
|
|
2299
2160
|
if (!context.sourceCode.text.includes("key=")) return {};
|
|
2300
2161
|
const keyedEntries = /* @__PURE__ */ new Map();
|
|
2301
2162
|
function isKeyValueEqual(a, b) {
|
|
@@ -2350,7 +2211,7 @@ function create$36(context) {
|
|
|
2350
2211
|
|
|
2351
2212
|
//#endregion
|
|
2352
2213
|
//#region src/rules/no-forward-ref/no-forward-ref.ts
|
|
2353
|
-
const RULE_NAME$
|
|
2214
|
+
const RULE_NAME$34 = "no-forward-ref";
|
|
2354
2215
|
var no_forward_ref_default = createRule({
|
|
2355
2216
|
meta: {
|
|
2356
2217
|
type: "suggestion",
|
|
@@ -2363,11 +2224,11 @@ var no_forward_ref_default = createRule({
|
|
|
2363
2224
|
},
|
|
2364
2225
|
schema: []
|
|
2365
2226
|
},
|
|
2366
|
-
name: RULE_NAME$
|
|
2367
|
-
create: create$
|
|
2227
|
+
name: RULE_NAME$34,
|
|
2228
|
+
create: create$34,
|
|
2368
2229
|
defaultOptions: []
|
|
2369
2230
|
});
|
|
2370
|
-
function create$
|
|
2231
|
+
function create$34(context) {
|
|
2371
2232
|
if (!context.sourceCode.text.includes("forwardRef")) return {};
|
|
2372
2233
|
const { version } = getSettingsFromContext(context);
|
|
2373
2234
|
if (compare(version, "19.0.0", "<")) return {};
|
|
@@ -2397,8 +2258,8 @@ function canFix(context, node) {
|
|
|
2397
2258
|
const { importSource } = getSettingsFromContext(context);
|
|
2398
2259
|
const initialScope = context.sourceCode.getScope(node);
|
|
2399
2260
|
switch (node.callee.type) {
|
|
2400
|
-
case AST_NODE_TYPES.Identifier: return core.
|
|
2401
|
-
case AST_NODE_TYPES.MemberExpression: return node.callee.object.type === AST_NODE_TYPES.Identifier && core.
|
|
2261
|
+
case AST_NODE_TYPES.Identifier: return core.isAPIFromReact(node.callee.name, initialScope, importSource);
|
|
2262
|
+
case AST_NODE_TYPES.MemberExpression: return node.callee.object.type === AST_NODE_TYPES.Identifier && core.isAPIFromReact(node.callee.object.name, initialScope, importSource);
|
|
2402
2263
|
default: return false;
|
|
2403
2264
|
}
|
|
2404
2265
|
}
|
|
@@ -2472,7 +2333,7 @@ function getComponentPropsFixes(context, fixer, node, typeArguments) {
|
|
|
2472
2333
|
|
|
2473
2334
|
//#endregion
|
|
2474
2335
|
//#region src/rules/no-implicit-children/no-implicit-children.ts
|
|
2475
|
-
const RULE_NAME$
|
|
2336
|
+
const RULE_NAME$33 = "no-implicit-children";
|
|
2476
2337
|
const RE_REACT_CHILDREN_TYPE = /react\.(reactnode|reactelement|reactportal)$/i;
|
|
2477
2338
|
var no_implicit_children_default = createRule({
|
|
2478
2339
|
meta: {
|
|
@@ -2481,18 +2342,18 @@ var no_implicit_children_default = createRule({
|
|
|
2481
2342
|
messages: { default: "This spread attribute implicitly passes the 'children' prop to a component, this could lead to unexpected behavior. If you intend to pass the 'children' prop, use 'children={value}'." },
|
|
2482
2343
|
schema: []
|
|
2483
2344
|
},
|
|
2484
|
-
name: RULE_NAME$
|
|
2485
|
-
create: create$
|
|
2345
|
+
name: RULE_NAME$33,
|
|
2346
|
+
create: create$33,
|
|
2486
2347
|
defaultOptions: []
|
|
2487
2348
|
});
|
|
2488
|
-
function create$
|
|
2349
|
+
function create$33(context) {
|
|
2489
2350
|
const services = ESLintUtils.getParserServices(context, false);
|
|
2490
2351
|
const checker = services.program.getTypeChecker();
|
|
2491
2352
|
return defineRuleListener({ JSXSpreadAttribute(node) {
|
|
2492
2353
|
for (const type of unionConstituents(getConstrainedTypeAtLocation(services, node.argument))) {
|
|
2493
2354
|
const children = type.getProperty("children");
|
|
2494
2355
|
if (children == null) continue;
|
|
2495
|
-
const fqn = getFullyQualifiedNameEx(checker, children).toLowerCase();
|
|
2356
|
+
const fqn = core.getFullyQualifiedNameEx(checker, children).toLowerCase();
|
|
2496
2357
|
if (fqn.endsWith("attributes.children") || fqn.endsWith("propswithchildren.children")) continue;
|
|
2497
2358
|
const childrenType = checker.getTypeOfSymbol(children);
|
|
2498
2359
|
const typeSymbol = childrenType.aliasSymbol ?? childrenType.symbol;
|
|
@@ -2510,7 +2371,7 @@ function create$34(context) {
|
|
|
2510
2371
|
|
|
2511
2372
|
//#endregion
|
|
2512
2373
|
//#region src/rules/no-implicit-key/no-implicit-key.ts
|
|
2513
|
-
const RULE_NAME$
|
|
2374
|
+
const RULE_NAME$32 = "no-implicit-key";
|
|
2514
2375
|
var no_implicit_key_default = createRule({
|
|
2515
2376
|
meta: {
|
|
2516
2377
|
type: "problem",
|
|
@@ -2518,18 +2379,18 @@ var no_implicit_key_default = createRule({
|
|
|
2518
2379
|
messages: { default: "This spread attribute implicitly passes the 'key' prop to a component, this could lead to unexpected behavior. If you intend to pass the 'key' prop, use 'key={value}'." },
|
|
2519
2380
|
schema: []
|
|
2520
2381
|
},
|
|
2521
|
-
name: RULE_NAME$
|
|
2522
|
-
create: create$
|
|
2382
|
+
name: RULE_NAME$32,
|
|
2383
|
+
create: create$32,
|
|
2523
2384
|
defaultOptions: []
|
|
2524
2385
|
});
|
|
2525
|
-
function create$
|
|
2386
|
+
function create$32(context) {
|
|
2526
2387
|
const services = ESLintUtils.getParserServices(context, false);
|
|
2527
2388
|
const checker = services.program.getTypeChecker();
|
|
2528
2389
|
return defineRuleListener({ JSXSpreadAttribute(node) {
|
|
2529
2390
|
for (const type of unionConstituents(getConstrainedTypeAtLocation(services, node.argument))) {
|
|
2530
2391
|
const key = type.getProperty("key");
|
|
2531
2392
|
if (key == null) continue;
|
|
2532
|
-
if (getFullyQualifiedNameEx(checker, key).toLowerCase().endsWith("react.attributes.key")) continue;
|
|
2393
|
+
if (core.getFullyQualifiedNameEx(checker, key).toLowerCase().endsWith("react.attributes.key")) continue;
|
|
2533
2394
|
const keyType = checker.getTypeOfSymbol(key);
|
|
2534
2395
|
if (keyType.aliasSymbol != null) {
|
|
2535
2396
|
if (checker.getFullyQualifiedName(keyType.aliasSymbol).toLowerCase().endsWith("react.key")) continue;
|
|
@@ -2544,7 +2405,7 @@ function create$33(context) {
|
|
|
2544
2405
|
|
|
2545
2406
|
//#endregion
|
|
2546
2407
|
//#region src/rules/no-implicit-ref/no-implicit-ref.ts
|
|
2547
|
-
const RULE_NAME$
|
|
2408
|
+
const RULE_NAME$31 = "no-implicit-ref";
|
|
2548
2409
|
const RE_REACT_REF_TYPE = /react\.(ref|legacyref|refcallback|refobject)$/i;
|
|
2549
2410
|
var no_implicit_ref_default = createRule({
|
|
2550
2411
|
meta: {
|
|
@@ -2553,18 +2414,18 @@ var no_implicit_ref_default = createRule({
|
|
|
2553
2414
|
messages: { default: "This spread attribute implicitly passes the 'ref' prop to a component, this could lead to unexpected behavior. If you intend to pass the 'ref' prop, use 'ref={value}'." },
|
|
2554
2415
|
schema: []
|
|
2555
2416
|
},
|
|
2556
|
-
name: RULE_NAME$
|
|
2557
|
-
create: create$
|
|
2417
|
+
name: RULE_NAME$31,
|
|
2418
|
+
create: create$31,
|
|
2558
2419
|
defaultOptions: []
|
|
2559
2420
|
});
|
|
2560
|
-
function create$
|
|
2421
|
+
function create$31(context) {
|
|
2561
2422
|
const services = ESLintUtils.getParserServices(context, false);
|
|
2562
2423
|
const checker = services.program.getTypeChecker();
|
|
2563
2424
|
return defineRuleListener({ JSXSpreadAttribute(node) {
|
|
2564
2425
|
for (const type of unionConstituents(getConstrainedTypeAtLocation(services, node.argument))) {
|
|
2565
2426
|
const ref = type.getProperty("ref");
|
|
2566
2427
|
if (ref == null) continue;
|
|
2567
|
-
if (getFullyQualifiedNameEx(checker, ref).toLowerCase().endsWith("attributes.ref")) continue;
|
|
2428
|
+
if (core.getFullyQualifiedNameEx(checker, ref).toLowerCase().endsWith("attributes.ref")) continue;
|
|
2568
2429
|
const refType = checker.getTypeOfSymbol(ref);
|
|
2569
2430
|
const typeSymbol = refType.aliasSymbol ?? refType.symbol;
|
|
2570
2431
|
if (typeSymbol != null) {
|
|
@@ -2581,7 +2442,7 @@ function create$32(context) {
|
|
|
2581
2442
|
|
|
2582
2443
|
//#endregion
|
|
2583
2444
|
//#region src/rules/no-leaked-conditional-rendering/no-leaked-conditional-rendering.ts
|
|
2584
|
-
const RULE_NAME$
|
|
2445
|
+
const RULE_NAME$30 = "no-leaked-conditional-rendering";
|
|
2585
2446
|
var no_leaked_conditional_rendering_default = createRule({
|
|
2586
2447
|
meta: {
|
|
2587
2448
|
type: "problem",
|
|
@@ -2589,11 +2450,11 @@ var no_leaked_conditional_rendering_default = createRule({
|
|
|
2589
2450
|
messages: { default: "Potential leaked value {{value}} that might cause unintentionally rendered values or rendering crashes." },
|
|
2590
2451
|
schema: []
|
|
2591
2452
|
},
|
|
2592
|
-
name: RULE_NAME$
|
|
2593
|
-
create: create$
|
|
2453
|
+
name: RULE_NAME$30,
|
|
2454
|
+
create: create$30,
|
|
2594
2455
|
defaultOptions: []
|
|
2595
2456
|
});
|
|
2596
|
-
function create$
|
|
2457
|
+
function create$30(context) {
|
|
2597
2458
|
if (!context.sourceCode.text.includes("&&")) return {};
|
|
2598
2459
|
const { version } = getSettingsFromContext(context);
|
|
2599
2460
|
const allowedVariants = [
|
|
@@ -2631,7 +2492,8 @@ function create$31(context) {
|
|
|
2631
2492
|
messageId: "default",
|
|
2632
2493
|
node: left
|
|
2633
2494
|
};
|
|
2634
|
-
const
|
|
2495
|
+
const leftType = getConstrainedTypeAtLocation(services, left);
|
|
2496
|
+
const leftTypeVariants = core.getTypeVariants(unionConstituents(leftType));
|
|
2635
2497
|
if (Array.from(leftTypeVariants.values()).every((type) => allowedVariants.some((allowed) => allowed === type))) return getReportDescriptor(right);
|
|
2636
2498
|
return {
|
|
2637
2499
|
data: { value: context.sourceCode.getText(left) },
|
|
@@ -2650,7 +2512,7 @@ function create$31(context) {
|
|
|
2650
2512
|
|
|
2651
2513
|
//#endregion
|
|
2652
2514
|
//#region src/rules/no-missing-component-display-name/no-missing-component-display-name.ts
|
|
2653
|
-
const RULE_NAME$
|
|
2515
|
+
const RULE_NAME$29 = "no-missing-component-display-name";
|
|
2654
2516
|
var no_missing_component_display_name_default = createRule({
|
|
2655
2517
|
meta: {
|
|
2656
2518
|
type: "suggestion",
|
|
@@ -2658,20 +2520,20 @@ var no_missing_component_display_name_default = createRule({
|
|
|
2658
2520
|
messages: { default: "Add missing 'displayName' for component." },
|
|
2659
2521
|
schema: []
|
|
2660
2522
|
},
|
|
2661
|
-
name: RULE_NAME$
|
|
2662
|
-
create: create$
|
|
2523
|
+
name: RULE_NAME$29,
|
|
2524
|
+
create: create$29,
|
|
2663
2525
|
defaultOptions: []
|
|
2664
2526
|
});
|
|
2665
|
-
function create$
|
|
2527
|
+
function create$29(context) {
|
|
2666
2528
|
if (!context.sourceCode.text.includes("memo") && !context.sourceCode.text.includes("forwardRef")) return {};
|
|
2667
|
-
const { api, visitor } = core.
|
|
2529
|
+
const { api, visitor } = core.getFunctionComponentCollector(context, {
|
|
2668
2530
|
collectDisplayName: true,
|
|
2669
2531
|
hint: core.DEFAULT_COMPONENT_DETECTION_HINT
|
|
2670
2532
|
});
|
|
2671
2533
|
return defineRuleListener(visitor, { "Program:exit"(program) {
|
|
2672
2534
|
for (const { displayName, flag, node } of api.getAllComponents(program)) {
|
|
2673
2535
|
const id = ast.getFunctionId(node);
|
|
2674
|
-
const isMemoOrForwardRef = (flag & (core.
|
|
2536
|
+
const isMemoOrForwardRef = (flag & (core.FunctionComponentFlag.ForwardRef | core.FunctionComponentFlag.Memo)) > 0n;
|
|
2675
2537
|
if (id != null) continue;
|
|
2676
2538
|
if (!isMemoOrForwardRef) continue;
|
|
2677
2539
|
if (displayName == null) context.report({
|
|
@@ -2684,7 +2546,7 @@ function create$30(context) {
|
|
|
2684
2546
|
|
|
2685
2547
|
//#endregion
|
|
2686
2548
|
//#region src/rules/no-missing-context-display-name/no-missing-context-display-name.ts
|
|
2687
|
-
const RULE_NAME$
|
|
2549
|
+
const RULE_NAME$28 = "no-missing-context-display-name";
|
|
2688
2550
|
var no_missing_context_display_name_default = createRule({
|
|
2689
2551
|
meta: {
|
|
2690
2552
|
type: "suggestion",
|
|
@@ -2693,11 +2555,11 @@ var no_missing_context_display_name_default = createRule({
|
|
|
2693
2555
|
messages: { default: "Add missing 'displayName' for context." },
|
|
2694
2556
|
schema: []
|
|
2695
2557
|
},
|
|
2696
|
-
name: RULE_NAME$
|
|
2697
|
-
create: create$
|
|
2558
|
+
name: RULE_NAME$28,
|
|
2559
|
+
create: create$28,
|
|
2698
2560
|
defaultOptions: []
|
|
2699
2561
|
});
|
|
2700
|
-
function create$
|
|
2562
|
+
function create$28(context) {
|
|
2701
2563
|
if (!context.sourceCode.text.includes("createContext")) return {};
|
|
2702
2564
|
const createCalls = [];
|
|
2703
2565
|
const displayNameAssignments = [];
|
|
@@ -2749,7 +2611,7 @@ function create$29(context) {
|
|
|
2749
2611
|
|
|
2750
2612
|
//#endregion
|
|
2751
2613
|
//#region src/rules/no-missing-key/no-missing-key.ts
|
|
2752
|
-
const RULE_NAME$
|
|
2614
|
+
const RULE_NAME$27 = "no-missing-key";
|
|
2753
2615
|
var no_missing_key_default = createRule({
|
|
2754
2616
|
meta: {
|
|
2755
2617
|
type: "problem",
|
|
@@ -2760,11 +2622,11 @@ var no_missing_key_default = createRule({
|
|
|
2760
2622
|
},
|
|
2761
2623
|
schema: []
|
|
2762
2624
|
},
|
|
2763
|
-
name: RULE_NAME$
|
|
2764
|
-
create: create$
|
|
2625
|
+
name: RULE_NAME$27,
|
|
2626
|
+
create: create$27,
|
|
2765
2627
|
defaultOptions: []
|
|
2766
2628
|
});
|
|
2767
|
-
function create$
|
|
2629
|
+
function create$27(ctx) {
|
|
2768
2630
|
let inChildrenToArray = false;
|
|
2769
2631
|
function check(node) {
|
|
2770
2632
|
if (node.type === AST_NODE_TYPES.JSXElement) return !hasAttribute(ctx, node, "key") ? {
|
|
@@ -2834,7 +2696,7 @@ function create$28(ctx) {
|
|
|
2834
2696
|
|
|
2835
2697
|
//#endregion
|
|
2836
2698
|
//#region src/rules/no-misused-capture-owner-stack/no-misused-capture-owner-stack.ts
|
|
2837
|
-
const RULE_NAME$
|
|
2699
|
+
const RULE_NAME$26 = "no-misused-capture-owner-stack";
|
|
2838
2700
|
var no_misused_capture_owner_stack_default = createRule({
|
|
2839
2701
|
meta: {
|
|
2840
2702
|
type: "problem",
|
|
@@ -2845,11 +2707,11 @@ var no_misused_capture_owner_stack_default = createRule({
|
|
|
2845
2707
|
},
|
|
2846
2708
|
schema: []
|
|
2847
2709
|
},
|
|
2848
|
-
name: RULE_NAME$
|
|
2849
|
-
create: create$
|
|
2710
|
+
name: RULE_NAME$26,
|
|
2711
|
+
create: create$26,
|
|
2850
2712
|
defaultOptions: []
|
|
2851
2713
|
});
|
|
2852
|
-
function create$
|
|
2714
|
+
function create$26(context) {
|
|
2853
2715
|
if (!context.sourceCode.text.includes("captureOwnerStack")) return {};
|
|
2854
2716
|
const { importSource } = getSettingsFromContext(context);
|
|
2855
2717
|
return defineRuleListener({
|
|
@@ -2880,7 +2742,7 @@ function isDevelopmentOnlyCheck(node) {
|
|
|
2880
2742
|
|
|
2881
2743
|
//#endregion
|
|
2882
2744
|
//#region src/rules/no-nested-component-definitions/no-nested-component-definitions.ts
|
|
2883
|
-
const RULE_NAME$
|
|
2745
|
+
const RULE_NAME$25 = "no-nested-component-definitions";
|
|
2884
2746
|
var no_nested_component_definitions_default = createRule({
|
|
2885
2747
|
meta: {
|
|
2886
2748
|
type: "problem",
|
|
@@ -2888,14 +2750,14 @@ var no_nested_component_definitions_default = createRule({
|
|
|
2888
2750
|
messages: { default: "Do not nest component definitions inside other components or props. {{suggestion}}" },
|
|
2889
2751
|
schema: []
|
|
2890
2752
|
},
|
|
2891
|
-
name: RULE_NAME$
|
|
2892
|
-
create: create$
|
|
2753
|
+
name: RULE_NAME$25,
|
|
2754
|
+
create: create$25,
|
|
2893
2755
|
defaultOptions: []
|
|
2894
2756
|
});
|
|
2895
|
-
function create$
|
|
2896
|
-
const hint = core.
|
|
2897
|
-
const fCollector = core.
|
|
2898
|
-
const cCollector = core.
|
|
2757
|
+
function create$25(context) {
|
|
2758
|
+
const hint = core.FunctionComponentDetectionHint.DoNotIncludeJsxWithNumberValue | core.FunctionComponentDetectionHint.DoNotIncludeJsxWithBooleanValue | core.FunctionComponentDetectionHint.DoNotIncludeJsxWithNullValue | core.FunctionComponentDetectionHint.DoNotIncludeJsxWithStringValue | core.FunctionComponentDetectionHint.DoNotIncludeJsxWithUndefinedValue | core.FunctionComponentDetectionHint.RequireBothSidesOfLogicalExpressionToBeJsx | core.FunctionComponentDetectionHint.RequireBothBranchesOfConditionalExpressionToBeJsx | core.FunctionComponentDetectionHint.DoNotIncludeFunctionDefinedAsArrayPatternElement | core.FunctionComponentDetectionHint.DoNotIncludeFunctionDefinedAsArrayExpressionElement | core.FunctionComponentDetectionHint.DoNotIncludeFunctionDefinedAsArrayMapCallback;
|
|
2759
|
+
const fCollector = core.getFunctionComponentCollector(context, { hint });
|
|
2760
|
+
const cCollector = core.getClassComponentCollector(context);
|
|
2899
2761
|
return defineRuleListener(fCollector.visitor, cCollector.visitor, { "Program:exit"(program) {
|
|
2900
2762
|
const fComponents = [...fCollector.api.getAllComponents(program)];
|
|
2901
2763
|
const cComponents = [...cCollector.api.getAllComponents(program)];
|
|
@@ -2996,7 +2858,7 @@ function isInsideCreateElementProps(context, node) {
|
|
|
2996
2858
|
|
|
2997
2859
|
//#endregion
|
|
2998
2860
|
//#region src/rules/no-nested-lazy-component-declarations/no-nested-lazy-component-declarations.ts
|
|
2999
|
-
const RULE_NAME$
|
|
2861
|
+
const RULE_NAME$24 = "no-nested-lazy-component-declarations";
|
|
3000
2862
|
var no_nested_lazy_component_declarations_default = createRule({
|
|
3001
2863
|
meta: {
|
|
3002
2864
|
type: "problem",
|
|
@@ -3004,13 +2866,13 @@ var no_nested_lazy_component_declarations_default = createRule({
|
|
|
3004
2866
|
messages: { default: "Do not declare lazy components inside other components or hooks. Instead, always declare them at the top level of your module." },
|
|
3005
2867
|
schema: []
|
|
3006
2868
|
},
|
|
3007
|
-
name: RULE_NAME$
|
|
3008
|
-
create: create$
|
|
2869
|
+
name: RULE_NAME$24,
|
|
2870
|
+
create: create$24,
|
|
3009
2871
|
defaultOptions: []
|
|
3010
2872
|
});
|
|
3011
|
-
function create$
|
|
3012
|
-
const fCollector = core.
|
|
3013
|
-
const cCollector = core.
|
|
2873
|
+
function create$24(context) {
|
|
2874
|
+
const fCollector = core.getFunctionComponentCollector(context);
|
|
2875
|
+
const cCollector = core.getClassComponentCollector(context);
|
|
3014
2876
|
const hCollector = core.getHookCollector(context);
|
|
3015
2877
|
const lazyCalls = /* @__PURE__ */ new Set();
|
|
3016
2878
|
return defineRuleListener(fCollector.visitor, cCollector.visitor, hCollector.visitor, {
|
|
@@ -3032,39 +2894,6 @@ function create$25(context) {
|
|
|
3032
2894
|
});
|
|
3033
2895
|
}
|
|
3034
2896
|
|
|
3035
|
-
//#endregion
|
|
3036
|
-
//#region src/rules/no-redundant-should-component-update/no-redundant-should-component-update.ts
|
|
3037
|
-
const RULE_NAME$24 = "no-redundant-should-component-update";
|
|
3038
|
-
function isShouldComponentUpdate(node) {
|
|
3039
|
-
return ast.isMethodOrProperty(node) && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === "shouldComponentUpdate";
|
|
3040
|
-
}
|
|
3041
|
-
var no_redundant_should_component_update_default = createRule({
|
|
3042
|
-
meta: {
|
|
3043
|
-
type: "problem",
|
|
3044
|
-
docs: { description: "Disallows 'shouldComponentUpdate' when extending 'React.PureComponent'." },
|
|
3045
|
-
messages: { default: "'{{componentName}}' does not need 'shouldComponentUpdate' when extending 'React.PureComponent'." },
|
|
3046
|
-
schema: []
|
|
3047
|
-
},
|
|
3048
|
-
name: RULE_NAME$24,
|
|
3049
|
-
create: create$24,
|
|
3050
|
-
defaultOptions: []
|
|
3051
|
-
});
|
|
3052
|
-
function create$24(context) {
|
|
3053
|
-
if (!context.sourceCode.text.includes("shouldComponentUpdate")) return {};
|
|
3054
|
-
const { api, visitor } = core.getComponentCollectorLegacy(context);
|
|
3055
|
-
return defineRuleListener(visitor, { "Program:exit"(program) {
|
|
3056
|
-
for (const { name = "PureComponent", flag, node: component } of api.getAllComponents(program)) {
|
|
3057
|
-
if ((flag & core.ComponentFlag.PureComponent) === 0n) continue;
|
|
3058
|
-
const { body } = component.body;
|
|
3059
|
-
for (const member of body) if (isShouldComponentUpdate(member)) context.report({
|
|
3060
|
-
data: { componentName: name },
|
|
3061
|
-
messageId: "default",
|
|
3062
|
-
node: member
|
|
3063
|
-
});
|
|
3064
|
-
}
|
|
3065
|
-
} });
|
|
3066
|
-
}
|
|
3067
|
-
|
|
3068
2897
|
//#endregion
|
|
3069
2898
|
//#region src/rules/no-set-state-in-component-did-mount/no-set-state-in-component-did-mount.ts
|
|
3070
2899
|
const RULE_NAME$23 = "no-set-state-in-component-did-mount";
|
|
@@ -3176,7 +3005,7 @@ function create$20(context) {
|
|
|
3176
3005
|
if (!context.sourceCode.text.includes("useCallback")) return {};
|
|
3177
3006
|
return defineRuleListener({ VariableDeclarator(node) {
|
|
3178
3007
|
const { id, init } = node;
|
|
3179
|
-
if (id.type !== AST_NODE_TYPES.Identifier || init?.type !== AST_NODE_TYPES.CallExpression || !core.isUseCallbackCall(init)) return;
|
|
3008
|
+
if (id.type !== AST_NODE_TYPES.Identifier || init?.type !== AST_NODE_TYPES.CallExpression || !core.isUseCallbackCall(context, init)) return;
|
|
3180
3009
|
const [cbk, ...rest] = context.sourceCode.getDeclaredVariables(node);
|
|
3181
3010
|
if (cbk == null || rest.length > 0) return;
|
|
3182
3011
|
const checkForUsageInsideUseEffectReport = checkForUsageInsideUseEffect$1(context.sourceCode, init);
|
|
@@ -3256,7 +3085,7 @@ function create$19(context) {
|
|
|
3256
3085
|
if (!context.sourceCode.text.includes("useMemo")) return {};
|
|
3257
3086
|
return defineRuleListener({ VariableDeclarator(node) {
|
|
3258
3087
|
const { id, init } = node;
|
|
3259
|
-
if (id.type !== AST_NODE_TYPES.Identifier || init?.type !== AST_NODE_TYPES.CallExpression || !core.isUseMemoCall(init)) return;
|
|
3088
|
+
if (id.type !== AST_NODE_TYPES.Identifier || init?.type !== AST_NODE_TYPES.CallExpression || !core.isUseMemoCall(context, init)) return;
|
|
3260
3089
|
const [mem, ...rest] = context.sourceCode.getDeclaredVariables(node);
|
|
3261
3090
|
if (mem == null || rest.length > 0) return;
|
|
3262
3091
|
const checkForUsageInsideUseEffectReport = checkForUsageInsideUseEffect(context.sourceCode, init);
|
|
@@ -3340,6 +3169,7 @@ function create$18(context) {
|
|
|
3340
3169
|
const { api, visitor } = core.getHookCollector(context);
|
|
3341
3170
|
return defineRuleListener(visitor, { "Program:exit"(program) {
|
|
3342
3171
|
for (const { id, name, hookCalls, node } of api.getAllHooks(program)) {
|
|
3172
|
+
if (name == null) continue;
|
|
3343
3173
|
if (hookCalls.length > 0) continue;
|
|
3344
3174
|
if (ast.isFunctionEmpty(node)) continue;
|
|
3345
3175
|
if (WELL_KNOWN_HOOKS.includes(name)) continue;
|
|
@@ -3370,7 +3200,7 @@ var no_unsafe_component_will_mount_default = createRule({
|
|
|
3370
3200
|
});
|
|
3371
3201
|
function create$17(context) {
|
|
3372
3202
|
if (!context.sourceCode.text.includes("UNSAFE_componentWillMount")) return {};
|
|
3373
|
-
const { api, visitor } = core.
|
|
3203
|
+
const { api, visitor } = core.getClassComponentCollector(context);
|
|
3374
3204
|
return defineRuleListener(visitor, { "Program:exit"(program) {
|
|
3375
3205
|
for (const { node: component } of api.getAllComponents(program)) {
|
|
3376
3206
|
const { body } = component.body;
|
|
@@ -3398,7 +3228,7 @@ var no_unsafe_component_will_receive_props_default = createRule({
|
|
|
3398
3228
|
});
|
|
3399
3229
|
function create$16(context) {
|
|
3400
3230
|
if (!context.sourceCode.text.includes("UNSAFE_componentWillReceiveProps")) return {};
|
|
3401
|
-
const { api, visitor } = core.
|
|
3231
|
+
const { api, visitor } = core.getClassComponentCollector(context);
|
|
3402
3232
|
return defineRuleListener(visitor, { "Program:exit"(program) {
|
|
3403
3233
|
for (const { node: component } of api.getAllComponents(program)) {
|
|
3404
3234
|
const { body } = component.body;
|
|
@@ -3426,7 +3256,7 @@ var no_unsafe_component_will_update_default = createRule({
|
|
|
3426
3256
|
});
|
|
3427
3257
|
function create$15(context) {
|
|
3428
3258
|
if (!context.sourceCode.text.includes("UNSAFE_componentWillUpdate")) return {};
|
|
3429
|
-
const { api, visitor } = core.
|
|
3259
|
+
const { api, visitor } = core.getClassComponentCollector(context);
|
|
3430
3260
|
return defineRuleListener(visitor, { "Program:exit"(program) {
|
|
3431
3261
|
for (const { node: component } of api.getAllComponents(program)) {
|
|
3432
3262
|
const { body } = component.body;
|
|
@@ -3457,7 +3287,7 @@ function create$14(context) {
|
|
|
3457
3287
|
if (compilationMode === "infer" || compilationMode === "all") return {};
|
|
3458
3288
|
if (compilationMode === "annotation" && ast.isDirectiveInFile(context.sourceCode.ast, "use memo")) return {};
|
|
3459
3289
|
const isReact18OrBelow = compare(version, "19.0.0", "<");
|
|
3460
|
-
const { api, visitor } = core.
|
|
3290
|
+
const { api, visitor } = core.getFunctionComponentCollector(context);
|
|
3461
3291
|
const constructions = /* @__PURE__ */ new WeakMap();
|
|
3462
3292
|
return defineRuleListener(visitor, {
|
|
3463
3293
|
JSXOpeningElement(node) {
|
|
@@ -3537,7 +3367,7 @@ function create$13(context, [options]) {
|
|
|
3537
3367
|
const { compilationMode } = getSettingsFromContext(context);
|
|
3538
3368
|
if (compilationMode === "infer" || compilationMode === "all") return {};
|
|
3539
3369
|
if (compilationMode === "annotation" && ast.isDirectiveInFile(context.sourceCode.ast, "use memo")) return {};
|
|
3540
|
-
const { api, visitor } = core.
|
|
3370
|
+
const { api, visitor } = core.getFunctionComponentCollector(context);
|
|
3541
3371
|
const declarators = /* @__PURE__ */ new WeakMap();
|
|
3542
3372
|
const { safeDefaultProps = [] } = options;
|
|
3543
3373
|
const safePatterns = safeDefaultProps.map((s) => toRegExp(s));
|
|
@@ -3710,7 +3540,7 @@ var no_unused_props_default = createRule({
|
|
|
3710
3540
|
function create$11(context) {
|
|
3711
3541
|
const services = ESLintUtils.getParserServices(context, false);
|
|
3712
3542
|
const checker = services.program.getTypeChecker();
|
|
3713
|
-
const { api, visitor } = core.
|
|
3543
|
+
const { api, visitor } = core.getFunctionComponentCollector(context);
|
|
3714
3544
|
return defineRuleListener(visitor, { "Program:exit"(program) {
|
|
3715
3545
|
const totalDeclaredProps = /* @__PURE__ */ new Map();
|
|
3716
3546
|
const totalUsedDeclarations = /* @__PURE__ */ new Set();
|
|
@@ -3957,7 +3787,7 @@ function create$9(context) {
|
|
|
3957
3787
|
const { version } = getSettingsFromContext(context);
|
|
3958
3788
|
if (compare(version, "19.0.0", "<")) return {};
|
|
3959
3789
|
return defineRuleListener({ CallExpression(node) {
|
|
3960
|
-
if (!core.isUseContextCall(node)) return;
|
|
3790
|
+
if (!core.isUseContextCall(context, node)) return;
|
|
3961
3791
|
context.report({
|
|
3962
3792
|
messageId: "default",
|
|
3963
3793
|
node: node.callee,
|
|
@@ -3990,7 +3820,7 @@ var prefer_destructuring_assignment_default = createRule({
|
|
|
3990
3820
|
defaultOptions: []
|
|
3991
3821
|
});
|
|
3992
3822
|
function create$8(context) {
|
|
3993
|
-
const { api, visitor } = core.
|
|
3823
|
+
const { api, visitor } = core.getFunctionComponentCollector(context);
|
|
3994
3824
|
return defineRuleListener(visitor, { "Program:exit"(program) {
|
|
3995
3825
|
for (const component of api.getAllComponents(program)) {
|
|
3996
3826
|
if (component.name == null || component.isExportDefaultDeclaration) continue;
|
|
@@ -4064,7 +3894,7 @@ var purity_default = createRule({
|
|
|
4064
3894
|
});
|
|
4065
3895
|
function create$6(context) {
|
|
4066
3896
|
const hCollector = core.getHookCollector(context);
|
|
4067
|
-
const cCollector = core.
|
|
3897
|
+
const cCollector = core.getFunctionComponentCollector(context);
|
|
4068
3898
|
const cEntries = [];
|
|
4069
3899
|
const nEntries = [];
|
|
4070
3900
|
return defineRuleListener(hCollector.visitor, cCollector.visitor, {
|
|
@@ -4142,7 +3972,7 @@ var refs_default = createRule({
|
|
|
4142
3972
|
});
|
|
4143
3973
|
function create$5(context) {
|
|
4144
3974
|
const hCollector = core.getHookCollector(context);
|
|
4145
|
-
const cCollector = core.
|
|
3975
|
+
const cCollector = core.getFunctionComponentCollector(context);
|
|
4146
3976
|
const refAccesses = [];
|
|
4147
3977
|
const jsxRefIdentifiers = /* @__PURE__ */ new Set();
|
|
4148
3978
|
/**
|
|
@@ -4185,7 +4015,7 @@ function create$5(context) {
|
|
|
4185
4015
|
if (init == null) continue;
|
|
4186
4016
|
switch (true) {
|
|
4187
4017
|
case init.type === AST_NODE_TYPES.MemberExpression && init.object.type === AST_NODE_TYPES.Identifier && (init.object.name === "ref" || init.object.name.endsWith("Ref")): return true;
|
|
4188
|
-
case init.type === AST_NODE_TYPES.CallExpression && isUseRefCall(init): return true;
|
|
4018
|
+
case init.type === AST_NODE_TYPES.CallExpression && isUseRefCall(context, init): return true;
|
|
4189
4019
|
}
|
|
4190
4020
|
}
|
|
4191
4021
|
return false;
|
|
@@ -6527,7 +6357,7 @@ function create$4(context) {
|
|
|
6527
6357
|
if (init == null) continue;
|
|
6528
6358
|
switch (true) {
|
|
6529
6359
|
case init.type === AST_NODE_TYPES.MemberExpression && init.object.type === AST_NODE_TYPES.Identifier && (init.object.name === "ref" || init.object.name.endsWith("Ref")): return true;
|
|
6530
|
-
case init.type === AST_NODE_TYPES.CallExpression && isUseRefCall(init): return true;
|
|
6360
|
+
case init.type === AST_NODE_TYPES.CallExpression && isUseRefCall(context, init): return true;
|
|
6531
6361
|
}
|
|
6532
6362
|
}
|
|
6533
6363
|
return false;
|
|
@@ -6599,14 +6429,14 @@ function create$4(context) {
|
|
|
6599
6429
|
case AST_NODE_TYPES.ArrowFunctionExpression: {
|
|
6600
6430
|
const parent = node.parent.parent;
|
|
6601
6431
|
if (parent.type !== AST_NODE_TYPES.CallExpression) break;
|
|
6602
|
-
if (!core.isUseMemoCall(parent)) break;
|
|
6432
|
+
if (!core.isUseMemoCall(context, parent)) break;
|
|
6603
6433
|
const init = ast.findParent(parent, isHookDecl)?.init;
|
|
6604
6434
|
if (init != null) getOrInsertComputed(setStateInEffectArg, init, () => []).push(node);
|
|
6605
6435
|
break;
|
|
6606
6436
|
}
|
|
6607
6437
|
case AST_NODE_TYPES.CallExpression:
|
|
6608
6438
|
if (node !== node.parent.arguments.at(0)) break;
|
|
6609
|
-
if (core.isUseCallbackCall(node.parent)) {
|
|
6439
|
+
if (core.isUseCallbackCall(context, node.parent)) {
|
|
6610
6440
|
const init = ast.findParent(node.parent, isHookDecl)?.init;
|
|
6611
6441
|
if (init != null) getOrInsertComputed(setStateInEffectArg, init, () => []).push(node);
|
|
6612
6442
|
break;
|
|
@@ -6728,8 +6558,8 @@ function create$3(context) {
|
|
|
6728
6558
|
function isComponentOrHookLikeFunction(node) {
|
|
6729
6559
|
const id = ast.getFunctionId(node);
|
|
6730
6560
|
if (id == null) return false;
|
|
6731
|
-
if (id.type === AST_NODE_TYPES.Identifier) return core.
|
|
6732
|
-
if (id.type === AST_NODE_TYPES.MemberExpression && id.property.type === AST_NODE_TYPES.Identifier) return core.
|
|
6561
|
+
if (id.type === AST_NODE_TYPES.Identifier) return core.isFunctionComponentName(id.name) || core.isHookName(id.name);
|
|
6562
|
+
if (id.type === AST_NODE_TYPES.MemberExpression && id.property.type === AST_NODE_TYPES.Identifier) return core.isFunctionComponentName(id.property.name) || core.isHookName(id.property.name);
|
|
6733
6563
|
return false;
|
|
6734
6564
|
}
|
|
6735
6565
|
function getFunctionKind(node) {
|
|
@@ -6814,7 +6644,7 @@ function isIifeCall(node) {
|
|
|
6814
6644
|
}
|
|
6815
6645
|
function create$2(context) {
|
|
6816
6646
|
const hCollector = core.getHookCollector(context);
|
|
6817
|
-
const cCollector = core.
|
|
6647
|
+
const cCollector = core.getFunctionComponentCollector(context);
|
|
6818
6648
|
const evalCalls = [];
|
|
6819
6649
|
const withStmts = [];
|
|
6820
6650
|
return defineRuleListener(hCollector.visitor, cCollector.visitor, {
|
|
@@ -6889,7 +6719,7 @@ var use_memo_default = createRule({
|
|
|
6889
6719
|
function create$1(context) {
|
|
6890
6720
|
if (!context.sourceCode.text.includes("useMemo")) return {};
|
|
6891
6721
|
return defineRuleListener({ CallExpression(node) {
|
|
6892
|
-
if (!core.isUseMemoCall(node)) return;
|
|
6722
|
+
if (!core.isUseMemoCall(context, node)) return;
|
|
6893
6723
|
let parent = node.parent;
|
|
6894
6724
|
while (ast.isTypeExpression(parent)) parent = parent.parent;
|
|
6895
6725
|
if (!(parent.type === AST_NODE_TYPES.VariableDeclarator || parent.type === AST_NODE_TYPES.AssignmentExpression || parent.type === AST_NODE_TYPES.AssignmentPattern || parent.type === AST_NODE_TYPES.Property || parent.type === AST_NODE_TYPES.ReturnStatement || parent.type === AST_NODE_TYPES.JSXExpressionContainer || parent.type === AST_NODE_TYPES.CallExpression || parent.type === AST_NODE_TYPES.NewExpression || parent.type === AST_NODE_TYPES.ArrayExpression || parent.type === AST_NODE_TYPES.ConditionalExpression || parent.type === AST_NODE_TYPES.LogicalExpression || parent.type === AST_NODE_TYPES.SequenceExpression || parent.type === AST_NODE_TYPES.SpreadElement || parent.type === AST_NODE_TYPES.TemplateLiteral || parent.type === AST_NODE_TYPES.BinaryExpression || parent.type === AST_NODE_TYPES.UnaryExpression || parent.type === AST_NODE_TYPES.MemberExpression || parent.type === AST_NODE_TYPES.TaggedTemplateExpression || parent.type === AST_NODE_TYPES.ChainExpression || parent.type === AST_NODE_TYPES.ArrowFunctionExpression)) {
|
|
@@ -6976,7 +6806,7 @@ function create(context) {
|
|
|
6976
6806
|
for (const expr of ast.getNestedNewExpressions(useStateInput)) {
|
|
6977
6807
|
if (!("name" in expr.callee)) continue;
|
|
6978
6808
|
if (LAZY_INIT_ALLOW_LIST.includes(expr.callee.name)) continue;
|
|
6979
|
-
if (ast.findParent(expr, core.isUseCall) != null) continue;
|
|
6809
|
+
if (ast.findParent(expr, (n) => core.isUseCall(context, n)) != null) continue;
|
|
6980
6810
|
context.report({
|
|
6981
6811
|
messageId: "invalidInitialization",
|
|
6982
6812
|
node: expr
|
|
@@ -6986,7 +6816,7 @@ function create(context) {
|
|
|
6986
6816
|
if (!("name" in expr.callee)) continue;
|
|
6987
6817
|
if (core.isHookName(expr.callee.name)) continue;
|
|
6988
6818
|
if (LAZY_INIT_ALLOW_LIST.includes(expr.callee.name)) continue;
|
|
6989
|
-
if (ast.findParent(expr, core.isUseCall) != null) continue;
|
|
6819
|
+
if (ast.findParent(expr, (n) => core.isUseCall(context, n)) != null) continue;
|
|
6990
6820
|
context.report({
|
|
6991
6821
|
messageId: "invalidInitialization",
|
|
6992
6822
|
node: expr
|
|
@@ -7081,7 +6911,6 @@ const plugin = {
|
|
|
7081
6911
|
"no-misused-capture-owner-stack": no_misused_capture_owner_stack_default,
|
|
7082
6912
|
"no-nested-component-definitions": no_nested_component_definitions_default,
|
|
7083
6913
|
"no-nested-lazy-component-declarations": no_nested_lazy_component_declarations_default,
|
|
7084
|
-
"no-redundant-should-component-update": no_redundant_should_component_update_default,
|
|
7085
6914
|
"no-set-state-in-component-did-mount": no_set_state_in_component_did_mount_default,
|
|
7086
6915
|
"no-set-state-in-component-did-update": no_set_state_in_component_did_update_default,
|
|
7087
6916
|
"no-set-state-in-component-will-update": no_set_state_in_component_will_update_default,
|
|
@@ -7141,7 +6970,6 @@ const rules$6 = {
|
|
|
7141
6970
|
"react-x/no-missing-key": "error",
|
|
7142
6971
|
"react-x/no-nested-component-definitions": "error",
|
|
7143
6972
|
"react-x/no-nested-lazy-component-declarations": "error",
|
|
7144
|
-
"react-x/no-redundant-should-component-update": "error",
|
|
7145
6973
|
"react-x/no-set-state-in-component-did-mount": "warn",
|
|
7146
6974
|
"react-x/no-set-state-in-component-did-update": "warn",
|
|
7147
6975
|
"react-x/no-set-state-in-component-will-update": "warn",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-react-x",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "5.0.0-beta.0",
|
|
4
4
|
"description": "A set of composable ESLint rules for libraries and frameworks that use React as a UI runtime.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -45,16 +45,16 @@
|
|
|
45
45
|
"string-ts": "^2.3.1",
|
|
46
46
|
"ts-api-utils": "^2.5.0",
|
|
47
47
|
"ts-pattern": "^5.9.0",
|
|
48
|
-
"@eslint-react/ast": "
|
|
49
|
-
"@eslint-react/core": "
|
|
50
|
-
"@eslint-react/
|
|
51
|
-
"@eslint-react/
|
|
52
|
-
"@eslint-react/var": "
|
|
48
|
+
"@eslint-react/ast": "5.0.0-beta.0",
|
|
49
|
+
"@eslint-react/core": "5.0.0-beta.0",
|
|
50
|
+
"@eslint-react/jsx": "5.0.0-beta.0",
|
|
51
|
+
"@eslint-react/shared": "5.0.0-beta.0",
|
|
52
|
+
"@eslint-react/var": "5.0.0-beta.0"
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
55
|
"@types/react": "^19.2.14",
|
|
56
56
|
"@types/react-dom": "^19.2.3",
|
|
57
|
-
"eslint": "^10.
|
|
57
|
+
"eslint": "^10.2.0",
|
|
58
58
|
"tsdown": "^0.21.7",
|
|
59
59
|
"tsl-dx": "^0.10.2",
|
|
60
60
|
"@local/configs": "0.0.0",
|