eslint-plugin-react-x 3.0.0 → 4.0.0-beta.2
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 +2 -2
- package/dist/index.js +338 -712
- package/package.json +14 -13
package/dist/index.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { DEFAULT_ESLINT_REACT_SETTINGS, IMPURE_CTORS, IMPURE_FUNCS, WEBSITE_URL, defineRuleListener, getSettingsFromContext, report, toRegExp } from "@eslint-react/shared";
|
|
2
2
|
import * as ast from "@eslint-react/ast";
|
|
3
3
|
import * as core from "@eslint-react/core";
|
|
4
|
-
import {
|
|
4
|
+
import { isUseRefCall } from "@eslint-react/core";
|
|
5
5
|
import { ESLintUtils } from "@typescript-eslint/utils";
|
|
6
6
|
import { P, isMatching, match } from "ts-pattern";
|
|
7
7
|
import ts from "typescript";
|
|
8
|
+
import { JsxDetectionHint, findParentAttribute, getElementFullType, hasAttribute, isJsxLike } from "@eslint-react/jsx";
|
|
8
9
|
import { AST_NODE_TYPES } from "@typescript-eslint/types";
|
|
9
10
|
import { computeObjectType, findEnclosingAssignmentTarget, isAssignmentTargetEqual, resolve } from "@eslint-react/var";
|
|
10
11
|
import { DefinitionType } from "@typescript-eslint/scope-manager";
|
|
@@ -114,7 +115,6 @@ var disable_experimental_exports = /* @__PURE__ */ __exportAll({
|
|
|
114
115
|
const name$8 = "react-x/disable-experimental";
|
|
115
116
|
const rules$8 = {
|
|
116
117
|
"react-x/immutability": "off",
|
|
117
|
-
"react-x/jsx-key-before-spread": "off",
|
|
118
118
|
"react-x/no-duplicate-key": "off",
|
|
119
119
|
"react-x/no-implicit-children": "off",
|
|
120
120
|
"react-x/no-implicit-key": "off",
|
|
@@ -147,7 +147,7 @@ const rules$7 = {
|
|
|
147
147
|
//#endregion
|
|
148
148
|
//#region package.json
|
|
149
149
|
var name$6 = "eslint-plugin-react-x";
|
|
150
|
-
var version = "
|
|
150
|
+
var version = "4.0.0-beta.2";
|
|
151
151
|
|
|
152
152
|
//#endregion
|
|
153
153
|
//#region src/utils/create-rule.ts
|
|
@@ -304,7 +304,7 @@ function getTypeVariants(types) {
|
|
|
304
304
|
|
|
305
305
|
//#endregion
|
|
306
306
|
//#region src/rules/component-hook-factories/component-hook-factories.ts
|
|
307
|
-
const RULE_NAME$
|
|
307
|
+
const RULE_NAME$56 = "component-hook-factories";
|
|
308
308
|
var component_hook_factories_default = createRule({
|
|
309
309
|
meta: {
|
|
310
310
|
type: "problem",
|
|
@@ -315,23 +315,23 @@ var component_hook_factories_default = createRule({
|
|
|
315
315
|
},
|
|
316
316
|
schema: []
|
|
317
317
|
},
|
|
318
|
-
name: RULE_NAME$
|
|
319
|
-
create: create$
|
|
318
|
+
name: RULE_NAME$56,
|
|
319
|
+
create: create$56,
|
|
320
320
|
defaultOptions: []
|
|
321
321
|
});
|
|
322
|
-
function create$
|
|
323
|
-
const hint = core.ComponentDetectionHint.DoNotIncludeJsxWithNumberValue | core.ComponentDetectionHint.DoNotIncludeJsxWithBooleanValue | core.ComponentDetectionHint.DoNotIncludeJsxWithNullValue | core.ComponentDetectionHint.DoNotIncludeJsxWithStringValue | core.ComponentDetectionHint.DoNotIncludeJsxWithUndefinedValue | core.ComponentDetectionHint.RequireBothSidesOfLogicalExpressionToBeJsx | core.ComponentDetectionHint.RequireBothBranchesOfConditionalExpressionToBeJsx | core.ComponentDetectionHint.
|
|
324
|
-
const fCollector = core.
|
|
325
|
-
const cCollector = core.
|
|
326
|
-
const hCollector = core.
|
|
322
|
+
function create$56(context) {
|
|
323
|
+
const hint = core.ComponentDetectionHint.DoNotIncludeJsxWithNumberValue | core.ComponentDetectionHint.DoNotIncludeJsxWithBooleanValue | core.ComponentDetectionHint.DoNotIncludeJsxWithNullValue | core.ComponentDetectionHint.DoNotIncludeJsxWithStringValue | core.ComponentDetectionHint.DoNotIncludeJsxWithUndefinedValue | core.ComponentDetectionHint.RequireBothSidesOfLogicalExpressionToBeJsx | core.ComponentDetectionHint.RequireBothBranchesOfConditionalExpressionToBeJsx | core.ComponentDetectionHint.DoNotIncludeFunctionDefinedAsArrayPatternElement | core.ComponentDetectionHint.DoNotIncludeFunctionDefinedAsArrayExpressionElement | core.ComponentDetectionHint.DoNotIncludeFunctionDefinedAsArrayMapCallback;
|
|
324
|
+
const fCollector = core.getComponentCollector(context, { hint });
|
|
325
|
+
const cCollector = core.getComponentCollectorLegacy(context);
|
|
326
|
+
const hCollector = core.getHookCollector(context);
|
|
327
327
|
const reported = /* @__PURE__ */ new Set();
|
|
328
328
|
return defineRuleListener(fCollector.visitor, cCollector.visitor, hCollector.visitor, { "Program:exit"(program) {
|
|
329
|
-
const fComponents = [...fCollector.
|
|
330
|
-
const cComponents = [...cCollector.
|
|
331
|
-
const hooks = [...hCollector.
|
|
329
|
+
const fComponents = [...fCollector.api.getAllComponents(program)];
|
|
330
|
+
const cComponents = [...cCollector.api.getAllComponents(program)];
|
|
331
|
+
const hooks = [...hCollector.api.getAllHooks(program)];
|
|
332
332
|
for (const { name, node } of fComponents) {
|
|
333
333
|
if (name == null) continue;
|
|
334
|
-
if (ast.
|
|
334
|
+
if (ast.findParent(node, ast.isFunction) == null) continue;
|
|
335
335
|
if (reported.has(node)) continue;
|
|
336
336
|
context.report({
|
|
337
337
|
data: { name },
|
|
@@ -341,7 +341,7 @@ function create$63(context) {
|
|
|
341
341
|
reported.add(node);
|
|
342
342
|
}
|
|
343
343
|
for (const { name = "unknown", node } of cComponents) {
|
|
344
|
-
if (ast.
|
|
344
|
+
if (ast.findParent(node, ast.isFunction) == null) continue;
|
|
345
345
|
context.report({
|
|
346
346
|
data: { name },
|
|
347
347
|
messageId: "component",
|
|
@@ -349,7 +349,7 @@ function create$63(context) {
|
|
|
349
349
|
});
|
|
350
350
|
}
|
|
351
351
|
for (const { name, node } of hooks) {
|
|
352
|
-
if (ast.
|
|
352
|
+
if (ast.findParent(node, ast.isFunction) == null) continue;
|
|
353
353
|
if (reported.has(node)) continue;
|
|
354
354
|
context.report({
|
|
355
355
|
data: { name },
|
|
@@ -363,7 +363,7 @@ function create$63(context) {
|
|
|
363
363
|
|
|
364
364
|
//#endregion
|
|
365
365
|
//#region src/rules/error-boundaries/error-boundaries.ts
|
|
366
|
-
const RULE_NAME$
|
|
366
|
+
const RULE_NAME$55 = "error-boundaries";
|
|
367
367
|
var error_boundaries_default = createRule({
|
|
368
368
|
meta: {
|
|
369
369
|
type: "problem",
|
|
@@ -374,19 +374,19 @@ var error_boundaries_default = createRule({
|
|
|
374
374
|
},
|
|
375
375
|
schema: []
|
|
376
376
|
},
|
|
377
|
-
name: RULE_NAME$
|
|
378
|
-
create: create$
|
|
377
|
+
name: RULE_NAME$55,
|
|
378
|
+
create: create$55,
|
|
379
379
|
defaultOptions: []
|
|
380
380
|
});
|
|
381
|
-
function create$
|
|
381
|
+
function create$55(context) {
|
|
382
382
|
if (!context.sourceCode.text.includes("try")) return {};
|
|
383
|
-
const hint =
|
|
384
|
-
const {
|
|
383
|
+
const hint = JsxDetectionHint.DoNotIncludeJsxWithNullValue | JsxDetectionHint.DoNotIncludeJsxWithNumberValue | JsxDetectionHint.DoNotIncludeJsxWithBigIntValue | JsxDetectionHint.DoNotIncludeJsxWithStringValue | JsxDetectionHint.DoNotIncludeJsxWithBooleanValue | JsxDetectionHint.DoNotIncludeJsxWithUndefinedValue | JsxDetectionHint.DoNotIncludeJsxWithEmptyArrayValue;
|
|
384
|
+
const { api, visitor } = core.getComponentCollector(context);
|
|
385
385
|
const reported = /* @__PURE__ */ new Set();
|
|
386
386
|
return defineRuleListener(visitor, {
|
|
387
387
|
CallExpression(node) {
|
|
388
388
|
if (!core.isUseCall(node)) return;
|
|
389
|
-
const stmt = ast.
|
|
389
|
+
const stmt = ast.findParent(node, ast.is(AST_NODE_TYPES.TryStatement));
|
|
390
390
|
if (stmt != null && !reported.has(stmt)) {
|
|
391
391
|
context.report({
|
|
392
392
|
messageId: "tryCatchWithUse",
|
|
@@ -396,10 +396,10 @@ function create$62(context) {
|
|
|
396
396
|
}
|
|
397
397
|
},
|
|
398
398
|
"Program:exit"(node) {
|
|
399
|
-
for (const { rets } of
|
|
399
|
+
for (const { rets } of api.getAllComponents(node)) for (const ret of rets) {
|
|
400
400
|
if (ret == null) continue;
|
|
401
|
-
if (!
|
|
402
|
-
const stmt = ast.
|
|
401
|
+
if (!isJsxLike(context, ret, hint)) continue;
|
|
402
|
+
const stmt = ast.findParent(ret, ast.is(AST_NODE_TYPES.TryStatement));
|
|
403
403
|
if (stmt != null && !reported.has(stmt)) {
|
|
404
404
|
context.report({
|
|
405
405
|
messageId: "tryCatchWithJsx",
|
|
@@ -1320,7 +1320,7 @@ function getUnknownDependenciesMessage(reactiveHookName) {
|
|
|
1320
1320
|
|
|
1321
1321
|
//#endregion
|
|
1322
1322
|
//#region src/rules/immutability/immutability.ts
|
|
1323
|
-
const RULE_NAME$
|
|
1323
|
+
const RULE_NAME$54 = "immutability";
|
|
1324
1324
|
/**
|
|
1325
1325
|
* Array methods that mutate the array in place.
|
|
1326
1326
|
* @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array
|
|
@@ -1346,14 +1346,14 @@ var immutability_default = createRule({
|
|
|
1346
1346
|
},
|
|
1347
1347
|
schema: []
|
|
1348
1348
|
},
|
|
1349
|
-
name: RULE_NAME$
|
|
1350
|
-
create: create$
|
|
1349
|
+
name: RULE_NAME$54,
|
|
1350
|
+
create: create$54,
|
|
1351
1351
|
defaultOptions: []
|
|
1352
1352
|
});
|
|
1353
|
-
function create$
|
|
1353
|
+
function create$54(context) {
|
|
1354
1354
|
const { additionalStateHooks } = getSettingsFromContext(context);
|
|
1355
|
-
const hCollector = core.
|
|
1356
|
-
const cCollector = core.
|
|
1355
|
+
const hCollector = core.getHookCollector(context);
|
|
1356
|
+
const cCollector = core.getComponentCollector(context);
|
|
1357
1357
|
/**
|
|
1358
1358
|
* Violations accumulated while traversing. Each entry records the node to
|
|
1359
1359
|
* report and the enclosing function so we can filter at Program:exit.
|
|
@@ -1412,7 +1412,7 @@ function create$61(context) {
|
|
|
1412
1412
|
const rootId = ast.getRootIdentifier(object);
|
|
1413
1413
|
if (rootId == null) return;
|
|
1414
1414
|
if (rootId.name === "draft") return;
|
|
1415
|
-
const enclosingFn = ast.
|
|
1415
|
+
const enclosingFn = ast.findParent(node, ast.isFunction);
|
|
1416
1416
|
if (enclosingFn == null) return;
|
|
1417
1417
|
const isState = isStateValue(rootId);
|
|
1418
1418
|
const isProps = isPropsObject(rootId);
|
|
@@ -1432,7 +1432,7 @@ function create$61(context) {
|
|
|
1432
1432
|
const rootId = ast.getRootIdentifier(node.left);
|
|
1433
1433
|
if (rootId == null) return;
|
|
1434
1434
|
if (rootId.name === "draft") return;
|
|
1435
|
-
const enclosingFn = ast.
|
|
1435
|
+
const enclosingFn = ast.findParent(node, ast.isFunction);
|
|
1436
1436
|
if (enclosingFn == null) return;
|
|
1437
1437
|
const isState = isStateValue(rootId);
|
|
1438
1438
|
const isProps = isPropsObject(rootId);
|
|
@@ -1445,8 +1445,8 @@ function create$61(context) {
|
|
|
1445
1445
|
});
|
|
1446
1446
|
},
|
|
1447
1447
|
"Program:exit"(node) {
|
|
1448
|
-
const comps = cCollector.
|
|
1449
|
-
const hooks = hCollector.
|
|
1448
|
+
const comps = cCollector.api.getAllComponents(node);
|
|
1449
|
+
const hooks = hCollector.api.getAllHooks(node);
|
|
1450
1450
|
const funcs = [...comps, ...hooks];
|
|
1451
1451
|
for (const { data, func, messageId, node } of violations) {
|
|
1452
1452
|
let current = func;
|
|
@@ -1456,7 +1456,7 @@ function create$61(context) {
|
|
|
1456
1456
|
insideComponentOrHook = true;
|
|
1457
1457
|
break;
|
|
1458
1458
|
}
|
|
1459
|
-
current = ast.
|
|
1459
|
+
current = ast.findParent(current, ast.isFunction);
|
|
1460
1460
|
}
|
|
1461
1461
|
if (!insideComponentOrHook) continue;
|
|
1462
1462
|
context.report({
|
|
@@ -1469,227 +1469,6 @@ function create$61(context) {
|
|
|
1469
1469
|
});
|
|
1470
1470
|
}
|
|
1471
1471
|
|
|
1472
|
-
//#endregion
|
|
1473
|
-
//#region src/rules/jsx-dollar/jsx-dollar.ts
|
|
1474
|
-
const RULE_NAME$60 = "jsx-dollar";
|
|
1475
|
-
var jsx_dollar_default = createRule({
|
|
1476
|
-
meta: {
|
|
1477
|
-
type: "suggestion",
|
|
1478
|
-
docs: { description: "Prevents unintentional '$' sign before expression." },
|
|
1479
|
-
fixable: "code",
|
|
1480
|
-
hasSuggestions: true,
|
|
1481
|
-
messages: {
|
|
1482
|
-
default: "Prevents unintentional '$' sign before expression.",
|
|
1483
|
-
removeDollarSign: "Remove the dollar sign '$' before the expression."
|
|
1484
|
-
},
|
|
1485
|
-
schema: []
|
|
1486
|
-
},
|
|
1487
|
-
name: RULE_NAME$60,
|
|
1488
|
-
create: create$60,
|
|
1489
|
-
defaultOptions: []
|
|
1490
|
-
});
|
|
1491
|
-
function create$60(context) {
|
|
1492
|
-
/**
|
|
1493
|
-
* Visitor function for JSXElement and JSXFragment nodes
|
|
1494
|
-
* @param node The JSXElement or JSXFragment node to be checked
|
|
1495
|
-
*/
|
|
1496
|
-
const visitorFunction = (node) => {
|
|
1497
|
-
for (const [index, child] of node.children.entries()) {
|
|
1498
|
-
if (child.type !== AST_NODE_TYPES.JSXText || !child.value.endsWith("$")) continue;
|
|
1499
|
-
if (node.children[index + 1]?.type !== AST_NODE_TYPES.JSXExpressionContainer) continue;
|
|
1500
|
-
if (child.value === "$" && node.children.length === 2) continue;
|
|
1501
|
-
const pos = child.loc.end;
|
|
1502
|
-
context.report({
|
|
1503
|
-
loc: {
|
|
1504
|
-
end: {
|
|
1505
|
-
column: pos.column,
|
|
1506
|
-
line: pos.line
|
|
1507
|
-
},
|
|
1508
|
-
start: {
|
|
1509
|
-
column: pos.column - 1,
|
|
1510
|
-
line: pos.line
|
|
1511
|
-
}
|
|
1512
|
-
},
|
|
1513
|
-
messageId: "default",
|
|
1514
|
-
node: child,
|
|
1515
|
-
suggest: [{
|
|
1516
|
-
fix(fixer) {
|
|
1517
|
-
return fixer.removeRange([child.range[1] - 1, child.range[1]]);
|
|
1518
|
-
},
|
|
1519
|
-
messageId: "removeDollarSign"
|
|
1520
|
-
}]
|
|
1521
|
-
});
|
|
1522
|
-
}
|
|
1523
|
-
};
|
|
1524
|
-
return defineRuleListener({
|
|
1525
|
-
JSXElement: visitorFunction,
|
|
1526
|
-
JSXFragment: visitorFunction
|
|
1527
|
-
});
|
|
1528
|
-
}
|
|
1529
|
-
|
|
1530
|
-
//#endregion
|
|
1531
|
-
//#region src/rules/jsx-key-before-spread/jsx-key-before-spread.ts
|
|
1532
|
-
const RULE_NAME$59 = "jsx-key-before-spread";
|
|
1533
|
-
var jsx_key_before_spread_default = createRule({
|
|
1534
|
-
meta: {
|
|
1535
|
-
type: "problem",
|
|
1536
|
-
docs: { description: "Enforces 'key' prop placement before spread props." },
|
|
1537
|
-
messages: { default: "The 'key' prop must be placed before any spread props when using the new JSX transform." },
|
|
1538
|
-
schema: []
|
|
1539
|
-
},
|
|
1540
|
-
name: RULE_NAME$59,
|
|
1541
|
-
create: create$59,
|
|
1542
|
-
defaultOptions: []
|
|
1543
|
-
});
|
|
1544
|
-
function create$59(context) {
|
|
1545
|
-
const { jsx } = JsxInspector.from(context).jsxConfig;
|
|
1546
|
-
if (jsx !== JsxEmit.ReactJSX && jsx !== JsxEmit.ReactJSXDev) return {};
|
|
1547
|
-
return defineRuleListener({ JSXOpeningElement(node) {
|
|
1548
|
-
let firstSpreadPropIndex = null;
|
|
1549
|
-
for (const [index, prop] of node.attributes.entries()) {
|
|
1550
|
-
if (prop.type === AST_NODE_TYPES.JSXSpreadAttribute) {
|
|
1551
|
-
firstSpreadPropIndex ??= index;
|
|
1552
|
-
continue;
|
|
1553
|
-
}
|
|
1554
|
-
if (firstSpreadPropIndex == null) continue;
|
|
1555
|
-
if (prop.name.name === "key" && index > firstSpreadPropIndex) context.report({
|
|
1556
|
-
messageId: "default",
|
|
1557
|
-
node: prop
|
|
1558
|
-
});
|
|
1559
|
-
}
|
|
1560
|
-
} });
|
|
1561
|
-
}
|
|
1562
|
-
|
|
1563
|
-
//#endregion
|
|
1564
|
-
//#region src/rules/jsx-no-comment-textnodes/jsx-no-comment-textnodes.ts
|
|
1565
|
-
const RULE_NAME$58 = "jsx-no-comment-textnodes";
|
|
1566
|
-
var jsx_no_comment_textnodes_default = createRule({
|
|
1567
|
-
meta: {
|
|
1568
|
-
type: "problem",
|
|
1569
|
-
docs: { description: "Prevents comment strings (ex: beginning with '//' or '/*') from being accidentally inserted into a JSX element's text nodes." },
|
|
1570
|
-
messages: { default: "Possible misused comment in text node. Comments inside children section of tag should be placed inside braces." },
|
|
1571
|
-
schema: []
|
|
1572
|
-
},
|
|
1573
|
-
name: RULE_NAME$58,
|
|
1574
|
-
create: create$58,
|
|
1575
|
-
defaultOptions: []
|
|
1576
|
-
});
|
|
1577
|
-
function create$58(context) {
|
|
1578
|
-
function hasCommentLike(node) {
|
|
1579
|
-
if (ast.isOneOf([AST_NODE_TYPES.JSXAttribute, AST_NODE_TYPES.JSXExpressionContainer])(node.parent)) return false;
|
|
1580
|
-
return /^\s*\/(?:\/|\*)/mu.test(context.sourceCode.getText(node));
|
|
1581
|
-
}
|
|
1582
|
-
const visitorFunction = (node) => {
|
|
1583
|
-
if (!ast.isOneOf([AST_NODE_TYPES.JSXElement, AST_NODE_TYPES.JSXFragment])(node.parent)) return;
|
|
1584
|
-
if (!hasCommentLike(node)) return;
|
|
1585
|
-
context.report({
|
|
1586
|
-
messageId: "default",
|
|
1587
|
-
node
|
|
1588
|
-
});
|
|
1589
|
-
};
|
|
1590
|
-
return defineRuleListener({
|
|
1591
|
-
JSXText: visitorFunction,
|
|
1592
|
-
Literal: visitorFunction
|
|
1593
|
-
});
|
|
1594
|
-
}
|
|
1595
|
-
|
|
1596
|
-
//#endregion
|
|
1597
|
-
//#region src/rules/jsx-shorthand-boolean/jsx-shorthand-boolean.ts
|
|
1598
|
-
const RULE_NAME$57 = "jsx-shorthand-boolean";
|
|
1599
|
-
const defaultOptions$4 = [1];
|
|
1600
|
-
const schema$4 = [{
|
|
1601
|
-
type: "integer",
|
|
1602
|
-
enum: [-1, 1]
|
|
1603
|
-
}];
|
|
1604
|
-
var jsx_shorthand_boolean_default = createRule({
|
|
1605
|
-
meta: {
|
|
1606
|
-
type: "suggestion",
|
|
1607
|
-
docs: { description: "Enforces shorthand syntax for boolean props." },
|
|
1608
|
-
fixable: "code",
|
|
1609
|
-
messages: { default: "{{message}}" },
|
|
1610
|
-
schema: schema$4
|
|
1611
|
-
},
|
|
1612
|
-
name: RULE_NAME$57,
|
|
1613
|
-
create: create$57,
|
|
1614
|
-
defaultOptions: defaultOptions$4
|
|
1615
|
-
});
|
|
1616
|
-
function create$57(context) {
|
|
1617
|
-
const policy = context.options[0] ?? defaultOptions$4[0];
|
|
1618
|
-
const jsx = JsxInspector.from(context);
|
|
1619
|
-
return defineRuleListener({ JSXAttribute(node) {
|
|
1620
|
-
const { value } = node;
|
|
1621
|
-
const propName = jsx.getAttributeName(node);
|
|
1622
|
-
switch (true) {
|
|
1623
|
-
case policy === 1 && value?.type === AST_NODE_TYPES.JSXExpressionContainer && value.expression.type === AST_NODE_TYPES.Literal && value.expression.value === true:
|
|
1624
|
-
context.report({
|
|
1625
|
-
data: { message: `Omit attribute value for '${propName}'.` },
|
|
1626
|
-
fix: (fixer) => fixer.removeRange([node.name.range[1], value.range[1]]),
|
|
1627
|
-
messageId: "default",
|
|
1628
|
-
node
|
|
1629
|
-
});
|
|
1630
|
-
break;
|
|
1631
|
-
case policy === -1 && value == null:
|
|
1632
|
-
context.report({
|
|
1633
|
-
data: { message: `Set attribute value for '${propName}'.` },
|
|
1634
|
-
fix: (fixer) => fixer.insertTextAfter(node.name, `={true}`),
|
|
1635
|
-
messageId: "default",
|
|
1636
|
-
node: node.value ?? node
|
|
1637
|
-
});
|
|
1638
|
-
break;
|
|
1639
|
-
}
|
|
1640
|
-
} });
|
|
1641
|
-
}
|
|
1642
|
-
|
|
1643
|
-
//#endregion
|
|
1644
|
-
//#region src/rules/jsx-shorthand-fragment/jsx-shorthand-fragment.ts
|
|
1645
|
-
const RULE_NAME$56 = "jsx-shorthand-fragment";
|
|
1646
|
-
const defaultOptions$3 = [1];
|
|
1647
|
-
const schema$3 = [{
|
|
1648
|
-
type: "integer",
|
|
1649
|
-
enum: [-1, 1]
|
|
1650
|
-
}];
|
|
1651
|
-
var jsx_shorthand_fragment_default = createRule({
|
|
1652
|
-
meta: {
|
|
1653
|
-
type: "suggestion",
|
|
1654
|
-
docs: { description: "Enforces shorthand syntax for fragment elements." },
|
|
1655
|
-
fixable: "code",
|
|
1656
|
-
messages: { default: "{{message}}" },
|
|
1657
|
-
schema: schema$3
|
|
1658
|
-
},
|
|
1659
|
-
name: RULE_NAME$56,
|
|
1660
|
-
create: create$56,
|
|
1661
|
-
defaultOptions: defaultOptions$3
|
|
1662
|
-
});
|
|
1663
|
-
function create$56(context) {
|
|
1664
|
-
const policy = context.options[0] ?? defaultOptions$3[0];
|
|
1665
|
-
const jsx = JsxInspector.from(context);
|
|
1666
|
-
const { jsxFragmentFactory } = jsx.jsxConfig;
|
|
1667
|
-
return match(policy).with(1, () => defineRuleListener({ JSXElement(node) {
|
|
1668
|
-
if (!jsx.isFragmentElement(node)) return;
|
|
1669
|
-
if (node.openingElement.attributes.length > 0) return;
|
|
1670
|
-
context.report({
|
|
1671
|
-
data: { message: "Use fragment shorthand syntax instead of 'Fragment' component." },
|
|
1672
|
-
fix: (fixer) => {
|
|
1673
|
-
const { closingElement, openingElement } = node;
|
|
1674
|
-
if (closingElement == null) return [];
|
|
1675
|
-
return [fixer.replaceTextRange([openingElement.range[0], openingElement.range[1]], "<>"), fixer.replaceTextRange([closingElement.range[0], closingElement.range[1]], "</>")];
|
|
1676
|
-
},
|
|
1677
|
-
messageId: "default",
|
|
1678
|
-
node
|
|
1679
|
-
});
|
|
1680
|
-
} })).with(-1, () => defineRuleListener({ JSXFragment(node) {
|
|
1681
|
-
context.report({
|
|
1682
|
-
data: { message: "Use 'Fragment' component instead of fragment shorthand syntax." },
|
|
1683
|
-
fix: (fixer) => {
|
|
1684
|
-
const { closingFragment, openingFragment } = node;
|
|
1685
|
-
return [fixer.replaceTextRange([openingFragment.range[0], openingFragment.range[1]], `<${jsxFragmentFactory}>`), fixer.replaceTextRange([closingFragment.range[0], closingFragment.range[1]], `</${jsxFragmentFactory}>`)];
|
|
1686
|
-
},
|
|
1687
|
-
messageId: "default",
|
|
1688
|
-
node
|
|
1689
|
-
});
|
|
1690
|
-
} })).otherwise(() => ({}));
|
|
1691
|
-
}
|
|
1692
|
-
|
|
1693
1472
|
//#endregion
|
|
1694
1473
|
//#region ../../../.pkgs/eff/dist/index.js
|
|
1695
1474
|
function not(predicate) {
|
|
@@ -1877,7 +1656,7 @@ function getOrElseUpdate(map, key, callback) {
|
|
|
1877
1656
|
|
|
1878
1657
|
//#endregion
|
|
1879
1658
|
//#region src/rules/no-access-state-in-setstate/no-access-state-in-setstate.ts
|
|
1880
|
-
const RULE_NAME$
|
|
1659
|
+
const RULE_NAME$53 = "no-access-state-in-setstate";
|
|
1881
1660
|
function isKeyLiteral$2(node, key) {
|
|
1882
1661
|
return match(key).with({ type: AST_NODE_TYPES.Literal }, constTrue).with({
|
|
1883
1662
|
type: AST_NODE_TYPES.TemplateLiteral,
|
|
@@ -1891,11 +1670,11 @@ var no_access_state_in_setstate_default = createRule({
|
|
|
1891
1670
|
messages: { default: "Do not access 'this.state' within 'setState'. Use the update function instead." },
|
|
1892
1671
|
schema: []
|
|
1893
1672
|
},
|
|
1894
|
-
name: RULE_NAME$
|
|
1895
|
-
create: create$
|
|
1673
|
+
name: RULE_NAME$53,
|
|
1674
|
+
create: create$53,
|
|
1896
1675
|
defaultOptions: []
|
|
1897
1676
|
});
|
|
1898
|
-
function create$
|
|
1677
|
+
function create$53(context) {
|
|
1899
1678
|
if (!context.sourceCode.text.includes("setState")) return {};
|
|
1900
1679
|
const classStack = [];
|
|
1901
1680
|
const methodStack = [];
|
|
@@ -1966,7 +1745,7 @@ function create$55(context) {
|
|
|
1966
1745
|
|
|
1967
1746
|
//#endregion
|
|
1968
1747
|
//#region src/rules/no-array-index-key/no-array-index-key.ts
|
|
1969
|
-
const RULE_NAME$
|
|
1748
|
+
const RULE_NAME$52 = "no-array-index-key";
|
|
1970
1749
|
function getIndexParamPosition(methodName) {
|
|
1971
1750
|
switch (methodName) {
|
|
1972
1751
|
case "every":
|
|
@@ -2011,11 +1790,11 @@ var no_array_index_key_default = createRule({
|
|
|
2011
1790
|
messages: { default: "Do not use item index in the array as its key." },
|
|
2012
1791
|
schema: []
|
|
2013
1792
|
},
|
|
2014
|
-
name: RULE_NAME$
|
|
2015
|
-
create: create$
|
|
1793
|
+
name: RULE_NAME$52,
|
|
1794
|
+
create: create$52,
|
|
2016
1795
|
defaultOptions: []
|
|
2017
1796
|
});
|
|
2018
|
-
function create$
|
|
1797
|
+
function create$52(context) {
|
|
2019
1798
|
const indexParamNames = [];
|
|
2020
1799
|
function isArrayIndex(node) {
|
|
2021
1800
|
return node.type === AST_NODE_TYPES.Identifier && indexParamNames.some((name) => name != null && name === node.name);
|
|
@@ -2081,7 +1860,7 @@ function create$54(context) {
|
|
|
2081
1860
|
|
|
2082
1861
|
//#endregion
|
|
2083
1862
|
//#region src/rules/no-children-count/no-children-count.ts
|
|
2084
|
-
const RULE_NAME$
|
|
1863
|
+
const RULE_NAME$51 = "no-children-count";
|
|
2085
1864
|
var no_children_count_default = createRule({
|
|
2086
1865
|
meta: {
|
|
2087
1866
|
type: "suggestion",
|
|
@@ -2089,11 +1868,11 @@ var no_children_count_default = createRule({
|
|
|
2089
1868
|
messages: { default: "Using 'Children.count' is uncommon and can lead to fragile code. Use alternatives instead." },
|
|
2090
1869
|
schema: []
|
|
2091
1870
|
},
|
|
2092
|
-
name: RULE_NAME$
|
|
2093
|
-
create: create$
|
|
1871
|
+
name: RULE_NAME$51,
|
|
1872
|
+
create: create$51,
|
|
2094
1873
|
defaultOptions: []
|
|
2095
1874
|
});
|
|
2096
|
-
function create$
|
|
1875
|
+
function create$51(context) {
|
|
2097
1876
|
return defineRuleListener({ MemberExpression(node) {
|
|
2098
1877
|
if (core.isChildrenCount(context, node)) context.report({
|
|
2099
1878
|
messageId: "default",
|
|
@@ -2104,7 +1883,7 @@ function create$53(context) {
|
|
|
2104
1883
|
|
|
2105
1884
|
//#endregion
|
|
2106
1885
|
//#region src/rules/no-children-for-each/no-children-for-each.ts
|
|
2107
|
-
const RULE_NAME$
|
|
1886
|
+
const RULE_NAME$50 = "no-children-for-each";
|
|
2108
1887
|
var no_children_for_each_default = createRule({
|
|
2109
1888
|
meta: {
|
|
2110
1889
|
type: "suggestion",
|
|
@@ -2112,11 +1891,11 @@ var no_children_for_each_default = createRule({
|
|
|
2112
1891
|
messages: { default: "Using 'Children.forEach' is uncommon and can lead to fragile code. Use alternatives instead." },
|
|
2113
1892
|
schema: []
|
|
2114
1893
|
},
|
|
2115
|
-
name: RULE_NAME$
|
|
2116
|
-
create: create$
|
|
1894
|
+
name: RULE_NAME$50,
|
|
1895
|
+
create: create$50,
|
|
2117
1896
|
defaultOptions: []
|
|
2118
1897
|
});
|
|
2119
|
-
function create$
|
|
1898
|
+
function create$50(context) {
|
|
2120
1899
|
return defineRuleListener({ MemberExpression(node) {
|
|
2121
1900
|
if (core.isChildrenForEach(context, node)) context.report({
|
|
2122
1901
|
messageId: "default",
|
|
@@ -2127,7 +1906,7 @@ function create$52(context) {
|
|
|
2127
1906
|
|
|
2128
1907
|
//#endregion
|
|
2129
1908
|
//#region src/rules/no-children-map/no-children-map.ts
|
|
2130
|
-
const RULE_NAME$
|
|
1909
|
+
const RULE_NAME$49 = "no-children-map";
|
|
2131
1910
|
var no_children_map_default = createRule({
|
|
2132
1911
|
meta: {
|
|
2133
1912
|
type: "suggestion",
|
|
@@ -2135,11 +1914,11 @@ var no_children_map_default = createRule({
|
|
|
2135
1914
|
messages: { default: "Using 'Children.map' is uncommon and can lead to fragile code. Use alternatives instead." },
|
|
2136
1915
|
schema: []
|
|
2137
1916
|
},
|
|
2138
|
-
name: RULE_NAME$
|
|
2139
|
-
create: create$
|
|
1917
|
+
name: RULE_NAME$49,
|
|
1918
|
+
create: create$49,
|
|
2140
1919
|
defaultOptions: []
|
|
2141
1920
|
});
|
|
2142
|
-
function create$
|
|
1921
|
+
function create$49(context) {
|
|
2143
1922
|
return defineRuleListener({ MemberExpression(node) {
|
|
2144
1923
|
if (core.isChildrenMap(context, node)) context.report({
|
|
2145
1924
|
messageId: "default",
|
|
@@ -2150,7 +1929,7 @@ function create$51(context) {
|
|
|
2150
1929
|
|
|
2151
1930
|
//#endregion
|
|
2152
1931
|
//#region src/rules/no-children-only/no-children-only.ts
|
|
2153
|
-
const RULE_NAME$
|
|
1932
|
+
const RULE_NAME$48 = "no-children-only";
|
|
2154
1933
|
var no_children_only_default = createRule({
|
|
2155
1934
|
meta: {
|
|
2156
1935
|
type: "suggestion",
|
|
@@ -2158,11 +1937,11 @@ var no_children_only_default = createRule({
|
|
|
2158
1937
|
messages: { default: "Using 'Children.only' is uncommon and can lead to fragile code. Use alternatives instead." },
|
|
2159
1938
|
schema: []
|
|
2160
1939
|
},
|
|
2161
|
-
name: RULE_NAME$
|
|
2162
|
-
create: create$
|
|
1940
|
+
name: RULE_NAME$48,
|
|
1941
|
+
create: create$48,
|
|
2163
1942
|
defaultOptions: []
|
|
2164
1943
|
});
|
|
2165
|
-
function create$
|
|
1944
|
+
function create$48(context) {
|
|
2166
1945
|
return defineRuleListener({ MemberExpression(node) {
|
|
2167
1946
|
if (core.isChildrenOnly(context, node)) context.report({
|
|
2168
1947
|
messageId: "default",
|
|
@@ -2171,34 +1950,9 @@ function create$50(context) {
|
|
|
2171
1950
|
} });
|
|
2172
1951
|
}
|
|
2173
1952
|
|
|
2174
|
-
//#endregion
|
|
2175
|
-
//#region src/rules/no-children-prop/no-children-prop.ts
|
|
2176
|
-
const RULE_NAME$49 = "no-children-prop";
|
|
2177
|
-
var no_children_prop_default = createRule({
|
|
2178
|
-
meta: {
|
|
2179
|
-
type: "suggestion",
|
|
2180
|
-
docs: { description: "Disallows passing 'children' as a prop." },
|
|
2181
|
-
messages: { default: "Do not pass 'children' as props." },
|
|
2182
|
-
schema: []
|
|
2183
|
-
},
|
|
2184
|
-
name: RULE_NAME$49,
|
|
2185
|
-
create: create$49,
|
|
2186
|
-
defaultOptions: []
|
|
2187
|
-
});
|
|
2188
|
-
function create$49(context) {
|
|
2189
|
-
const jsx = JsxInspector.from(context);
|
|
2190
|
-
return defineRuleListener({ JSXElement(node) {
|
|
2191
|
-
const childrenProp = jsx.findAttribute(node, "children");
|
|
2192
|
-
if (childrenProp != null) context.report({
|
|
2193
|
-
messageId: "default",
|
|
2194
|
-
node: childrenProp
|
|
2195
|
-
});
|
|
2196
|
-
} });
|
|
2197
|
-
}
|
|
2198
|
-
|
|
2199
1953
|
//#endregion
|
|
2200
1954
|
//#region src/rules/no-children-to-array/no-children-to-array.ts
|
|
2201
|
-
const RULE_NAME$
|
|
1955
|
+
const RULE_NAME$47 = "no-children-to-array";
|
|
2202
1956
|
var no_children_to_array_default = createRule({
|
|
2203
1957
|
meta: {
|
|
2204
1958
|
type: "suggestion",
|
|
@@ -2206,11 +1960,11 @@ var no_children_to_array_default = createRule({
|
|
|
2206
1960
|
messages: { default: "Using 'Children.toArray' is uncommon and can lead to fragile code. Use alternatives instead." },
|
|
2207
1961
|
schema: []
|
|
2208
1962
|
},
|
|
2209
|
-
name: RULE_NAME$
|
|
2210
|
-
create: create$
|
|
1963
|
+
name: RULE_NAME$47,
|
|
1964
|
+
create: create$47,
|
|
2211
1965
|
defaultOptions: []
|
|
2212
1966
|
});
|
|
2213
|
-
function create$
|
|
1967
|
+
function create$47(context) {
|
|
2214
1968
|
return defineRuleListener({ MemberExpression(node) {
|
|
2215
1969
|
if (core.isChildrenToArray(context, node)) context.report({
|
|
2216
1970
|
messageId: "default",
|
|
@@ -2221,7 +1975,7 @@ function create$48(context) {
|
|
|
2221
1975
|
|
|
2222
1976
|
//#endregion
|
|
2223
1977
|
//#region src/rules/no-class-component/no-class-component.ts
|
|
2224
|
-
const RULE_NAME$
|
|
1978
|
+
const RULE_NAME$46 = "no-class-component";
|
|
2225
1979
|
var no_class_component_default = createRule({
|
|
2226
1980
|
meta: {
|
|
2227
1981
|
type: "suggestion",
|
|
@@ -2229,15 +1983,15 @@ var no_class_component_default = createRule({
|
|
|
2229
1983
|
messages: { default: "Avoid using class components. Use function components instead." },
|
|
2230
1984
|
schema: []
|
|
2231
1985
|
},
|
|
2232
|
-
name: RULE_NAME$
|
|
2233
|
-
create: create$
|
|
1986
|
+
name: RULE_NAME$46,
|
|
1987
|
+
create: create$46,
|
|
2234
1988
|
defaultOptions: []
|
|
2235
1989
|
});
|
|
2236
|
-
function create$
|
|
1990
|
+
function create$46(context) {
|
|
2237
1991
|
if (!context.sourceCode.text.includes("Component")) return {};
|
|
2238
|
-
const {
|
|
1992
|
+
const { api, visitor } = core.getComponentCollectorLegacy(context);
|
|
2239
1993
|
return defineRuleListener(visitor, { "Program:exit"(program) {
|
|
2240
|
-
for (const { name = "anonymous", node: component } of
|
|
1994
|
+
for (const { name = "anonymous", node: component } of api.getAllComponents(program)) {
|
|
2241
1995
|
if (component.body.body.some((m) => core.isComponentDidCatch(m) || core.isGetDerivedStateFromError(m))) continue;
|
|
2242
1996
|
context.report({
|
|
2243
1997
|
data: { name },
|
|
@@ -2250,7 +2004,7 @@ function create$47(context) {
|
|
|
2250
2004
|
|
|
2251
2005
|
//#endregion
|
|
2252
2006
|
//#region src/rules/no-clone-element/no-clone-element.ts
|
|
2253
|
-
const RULE_NAME$
|
|
2007
|
+
const RULE_NAME$45 = "no-clone-element";
|
|
2254
2008
|
var no_clone_element_default = createRule({
|
|
2255
2009
|
meta: {
|
|
2256
2010
|
type: "suggestion",
|
|
@@ -2258,11 +2012,11 @@ var no_clone_element_default = createRule({
|
|
|
2258
2012
|
messages: { default: "Using 'cloneElement' is uncommon and can lead to fragile code. Use alternatives instead." },
|
|
2259
2013
|
schema: []
|
|
2260
2014
|
},
|
|
2261
|
-
name: RULE_NAME$
|
|
2262
|
-
create: create$
|
|
2015
|
+
name: RULE_NAME$45,
|
|
2016
|
+
create: create$45,
|
|
2263
2017
|
defaultOptions: []
|
|
2264
2018
|
});
|
|
2265
|
-
function create$
|
|
2019
|
+
function create$45(context) {
|
|
2266
2020
|
return defineRuleListener({ CallExpression(node) {
|
|
2267
2021
|
if (core.isCloneElementCall(context, node)) context.report({
|
|
2268
2022
|
messageId: "default",
|
|
@@ -2273,7 +2027,7 @@ function create$46(context) {
|
|
|
2273
2027
|
|
|
2274
2028
|
//#endregion
|
|
2275
2029
|
//#region src/rules/no-component-will-mount/no-component-will-mount.ts
|
|
2276
|
-
const RULE_NAME$
|
|
2030
|
+
const RULE_NAME$44 = "no-component-will-mount";
|
|
2277
2031
|
var no_component_will_mount_default = createRule({
|
|
2278
2032
|
meta: {
|
|
2279
2033
|
type: "problem",
|
|
@@ -2282,15 +2036,15 @@ var no_component_will_mount_default = createRule({
|
|
|
2282
2036
|
messages: { default: "[Deprecated] Use 'UNSAFE_componentWillMount' instead." },
|
|
2283
2037
|
schema: []
|
|
2284
2038
|
},
|
|
2285
|
-
name: RULE_NAME$
|
|
2286
|
-
create: create$
|
|
2039
|
+
name: RULE_NAME$44,
|
|
2040
|
+
create: create$44,
|
|
2287
2041
|
defaultOptions: []
|
|
2288
2042
|
});
|
|
2289
|
-
function create$
|
|
2043
|
+
function create$44(context) {
|
|
2290
2044
|
if (!context.sourceCode.text.includes("componentWillMount")) return {};
|
|
2291
|
-
const {
|
|
2045
|
+
const { api, visitor } = core.getComponentCollectorLegacy(context);
|
|
2292
2046
|
return defineRuleListener(visitor, { "Program:exit"(program) {
|
|
2293
|
-
for (const { node: component } of
|
|
2047
|
+
for (const { node: component } of api.getAllComponents(program)) {
|
|
2294
2048
|
const { body } = component.body;
|
|
2295
2049
|
for (const member of body) if (core.isComponentWillMount(member)) context.report({
|
|
2296
2050
|
fix(fixer) {
|
|
@@ -2306,7 +2060,7 @@ function create$45(context) {
|
|
|
2306
2060
|
|
|
2307
2061
|
//#endregion
|
|
2308
2062
|
//#region src/rules/no-component-will-receive-props/no-component-will-receive-props.ts
|
|
2309
|
-
const RULE_NAME$
|
|
2063
|
+
const RULE_NAME$43 = "no-component-will-receive-props";
|
|
2310
2064
|
var no_component_will_receive_props_default = createRule({
|
|
2311
2065
|
meta: {
|
|
2312
2066
|
type: "problem",
|
|
@@ -2315,15 +2069,15 @@ var no_component_will_receive_props_default = createRule({
|
|
|
2315
2069
|
messages: { default: "[Deprecated] Use 'UNSAFE_componentWillReceiveProps' instead." },
|
|
2316
2070
|
schema: []
|
|
2317
2071
|
},
|
|
2318
|
-
name: RULE_NAME$
|
|
2319
|
-
create: create$
|
|
2072
|
+
name: RULE_NAME$43,
|
|
2073
|
+
create: create$43,
|
|
2320
2074
|
defaultOptions: []
|
|
2321
2075
|
});
|
|
2322
|
-
function create$
|
|
2076
|
+
function create$43(context) {
|
|
2323
2077
|
if (!context.sourceCode.text.includes("componentWillReceiveProps")) return {};
|
|
2324
|
-
const {
|
|
2078
|
+
const { api, visitor } = core.getComponentCollectorLegacy(context);
|
|
2325
2079
|
return defineRuleListener(visitor, { "Program:exit"(program) {
|
|
2326
|
-
for (const { node: component } of
|
|
2080
|
+
for (const { node: component } of api.getAllComponents(program)) {
|
|
2327
2081
|
const { body } = component.body;
|
|
2328
2082
|
for (const member of body) if (core.isComponentWillReceiveProps(member)) context.report({
|
|
2329
2083
|
fix(fixer) {
|
|
@@ -2339,7 +2093,7 @@ function create$44(context) {
|
|
|
2339
2093
|
|
|
2340
2094
|
//#endregion
|
|
2341
2095
|
//#region src/rules/no-component-will-update/no-component-will-update.ts
|
|
2342
|
-
const RULE_NAME$
|
|
2096
|
+
const RULE_NAME$42 = "no-component-will-update";
|
|
2343
2097
|
var no_component_will_update_default = createRule({
|
|
2344
2098
|
meta: {
|
|
2345
2099
|
type: "problem",
|
|
@@ -2348,15 +2102,15 @@ var no_component_will_update_default = createRule({
|
|
|
2348
2102
|
messages: { default: "[Deprecated] Use 'UNSAFE_componentWillUpdate' instead." },
|
|
2349
2103
|
schema: []
|
|
2350
2104
|
},
|
|
2351
|
-
name: RULE_NAME$
|
|
2352
|
-
create: create$
|
|
2105
|
+
name: RULE_NAME$42,
|
|
2106
|
+
create: create$42,
|
|
2353
2107
|
defaultOptions: []
|
|
2354
2108
|
});
|
|
2355
|
-
function create$
|
|
2109
|
+
function create$42(context) {
|
|
2356
2110
|
if (!context.sourceCode.text.includes("componentWillUpdate")) return {};
|
|
2357
|
-
const {
|
|
2111
|
+
const { api, visitor } = core.getComponentCollectorLegacy(context);
|
|
2358
2112
|
return defineRuleListener(visitor, { "Program:exit"(program) {
|
|
2359
|
-
for (const { node: component } of
|
|
2113
|
+
for (const { node: component } of api.getAllComponents(program)) {
|
|
2360
2114
|
const { body } = component.body;
|
|
2361
2115
|
for (const member of body) if (core.isComponentWillUpdate(member)) context.report({
|
|
2362
2116
|
fix(fixer) {
|
|
@@ -2372,7 +2126,7 @@ function create$43(context) {
|
|
|
2372
2126
|
|
|
2373
2127
|
//#endregion
|
|
2374
2128
|
//#region src/rules/no-context-provider/no-context-provider.ts
|
|
2375
|
-
const RULE_NAME$
|
|
2129
|
+
const RULE_NAME$41 = "no-context-provider";
|
|
2376
2130
|
var no_context_provider_default = createRule({
|
|
2377
2131
|
meta: {
|
|
2378
2132
|
type: "suggestion",
|
|
@@ -2385,17 +2139,16 @@ var no_context_provider_default = createRule({
|
|
|
2385
2139
|
},
|
|
2386
2140
|
schema: []
|
|
2387
2141
|
},
|
|
2388
|
-
name: RULE_NAME$
|
|
2389
|
-
create: create$
|
|
2142
|
+
name: RULE_NAME$41,
|
|
2143
|
+
create: create$41,
|
|
2390
2144
|
defaultOptions: []
|
|
2391
2145
|
});
|
|
2392
|
-
function create$
|
|
2146
|
+
function create$41(context) {
|
|
2393
2147
|
if (!context.sourceCode.text.includes("Provider")) return {};
|
|
2394
2148
|
const { version } = getSettingsFromContext(context);
|
|
2395
2149
|
if (compare(version, "19.0.0", "<")) return {};
|
|
2396
|
-
const jsx = JsxInspector.from(context);
|
|
2397
2150
|
return defineRuleListener({ JSXElement(node) {
|
|
2398
|
-
const parts =
|
|
2151
|
+
const parts = getElementFullType(node).split(".");
|
|
2399
2152
|
const selfName = parts.pop();
|
|
2400
2153
|
const contextFullName = parts.join(".");
|
|
2401
2154
|
const contextSelfName = parts.pop();
|
|
@@ -2420,7 +2173,7 @@ function create$42(context) {
|
|
|
2420
2173
|
|
|
2421
2174
|
//#endregion
|
|
2422
2175
|
//#region src/rules/no-create-ref/no-create-ref.ts
|
|
2423
|
-
const RULE_NAME$
|
|
2176
|
+
const RULE_NAME$40 = "no-create-ref";
|
|
2424
2177
|
var no_create_ref_default = createRule({
|
|
2425
2178
|
meta: {
|
|
2426
2179
|
type: "suggestion",
|
|
@@ -2428,13 +2181,13 @@ var no_create_ref_default = createRule({
|
|
|
2428
2181
|
messages: { default: "[Deprecated] Use 'useRef' instead." },
|
|
2429
2182
|
schema: []
|
|
2430
2183
|
},
|
|
2431
|
-
name: RULE_NAME$
|
|
2432
|
-
create: create$
|
|
2184
|
+
name: RULE_NAME$40,
|
|
2185
|
+
create: create$40,
|
|
2433
2186
|
defaultOptions: []
|
|
2434
2187
|
});
|
|
2435
|
-
function create$
|
|
2188
|
+
function create$40(context) {
|
|
2436
2189
|
return defineRuleListener({ CallExpression(node) {
|
|
2437
|
-
if (core.isCreateRefCall(context, node) && ast.
|
|
2190
|
+
if (core.isCreateRefCall(context, node) && ast.findParent(node, core.isClassComponent) == null) context.report({
|
|
2438
2191
|
messageId: "default",
|
|
2439
2192
|
node
|
|
2440
2193
|
});
|
|
@@ -2443,7 +2196,7 @@ function create$41(context) {
|
|
|
2443
2196
|
|
|
2444
2197
|
//#endregion
|
|
2445
2198
|
//#region src/rules/no-direct-mutation-state/no-direct-mutation-state.ts
|
|
2446
|
-
const RULE_NAME$
|
|
2199
|
+
const RULE_NAME$39 = "no-direct-mutation-state";
|
|
2447
2200
|
function isConstructorFunction(node) {
|
|
2448
2201
|
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";
|
|
2449
2202
|
}
|
|
@@ -2454,16 +2207,16 @@ var no_direct_mutation_state_default = createRule({
|
|
|
2454
2207
|
messages: { default: "Do not mutate state directly. Use 'setState()' instead." },
|
|
2455
2208
|
schema: []
|
|
2456
2209
|
},
|
|
2457
|
-
name: RULE_NAME$
|
|
2458
|
-
create: create$
|
|
2210
|
+
name: RULE_NAME$39,
|
|
2211
|
+
create: create$39,
|
|
2459
2212
|
defaultOptions: []
|
|
2460
2213
|
});
|
|
2461
|
-
function create$
|
|
2214
|
+
function create$39(context) {
|
|
2462
2215
|
return defineRuleListener({ AssignmentExpression(node) {
|
|
2463
2216
|
if (!core.isAssignmentToThisState(node)) return;
|
|
2464
|
-
const parentClass = ast.
|
|
2217
|
+
const parentClass = ast.findParent(node, ast.isOneOf([AST_NODE_TYPES.ClassDeclaration, AST_NODE_TYPES.ClassExpression]));
|
|
2465
2218
|
if (parentClass == null) return;
|
|
2466
|
-
if (core.isClassComponent(parentClass) && context.sourceCode.getScope(node).block !== ast.
|
|
2219
|
+
if (core.isClassComponent(parentClass) && context.sourceCode.getScope(node).block !== ast.findParent(node, isConstructorFunction)) context.report({
|
|
2467
2220
|
messageId: "default",
|
|
2468
2221
|
node
|
|
2469
2222
|
});
|
|
@@ -2472,7 +2225,7 @@ function create$40(context) {
|
|
|
2472
2225
|
|
|
2473
2226
|
//#endregion
|
|
2474
2227
|
//#region src/rules/no-duplicate-key/no-duplicate-key.ts
|
|
2475
|
-
const RULE_NAME$
|
|
2228
|
+
const RULE_NAME$38 = "no-duplicate-key";
|
|
2476
2229
|
var no_duplicate_key_default = createRule({
|
|
2477
2230
|
meta: {
|
|
2478
2231
|
type: "problem",
|
|
@@ -2480,11 +2233,11 @@ var no_duplicate_key_default = createRule({
|
|
|
2480
2233
|
messages: { default: "The 'key' prop must be unique to its sibling elements." },
|
|
2481
2234
|
schema: []
|
|
2482
2235
|
},
|
|
2483
|
-
name: RULE_NAME$
|
|
2484
|
-
create: create$
|
|
2236
|
+
name: RULE_NAME$38,
|
|
2237
|
+
create: create$38,
|
|
2485
2238
|
defaultOptions: []
|
|
2486
2239
|
});
|
|
2487
|
-
function create$
|
|
2240
|
+
function create$38(context) {
|
|
2488
2241
|
if (!context.sourceCode.text.includes("key=")) return {};
|
|
2489
2242
|
const keyedEntries = /* @__PURE__ */ new Map();
|
|
2490
2243
|
function isKeyValueEqual(a, b) {
|
|
@@ -2510,8 +2263,8 @@ function create$39(context) {
|
|
|
2510
2263
|
break;
|
|
2511
2264
|
}
|
|
2512
2265
|
default: {
|
|
2513
|
-
const call = ast.
|
|
2514
|
-
const iter = ast.
|
|
2266
|
+
const call = ast.findParent(jsxElement, (n) => n.type === AST_NODE_TYPES.CallExpression && n.callee.type === AST_NODE_TYPES.MemberExpression && n.callee.property.type === AST_NODE_TYPES.Identifier && n.callee.property.name === "map");
|
|
2267
|
+
const iter = ast.findParent(jsxElement, (n) => n === call || ast.isFunction(n));
|
|
2515
2268
|
if (!ast.isFunction(iter)) return;
|
|
2516
2269
|
const arg0 = call?.arguments[0];
|
|
2517
2270
|
if (call == null || arg0 == null) return;
|
|
@@ -2539,7 +2292,7 @@ function create$39(context) {
|
|
|
2539
2292
|
|
|
2540
2293
|
//#endregion
|
|
2541
2294
|
//#region src/rules/no-forward-ref/no-forward-ref.ts
|
|
2542
|
-
const RULE_NAME$
|
|
2295
|
+
const RULE_NAME$37 = "no-forward-ref";
|
|
2543
2296
|
var no_forward_ref_default = createRule({
|
|
2544
2297
|
meta: {
|
|
2545
2298
|
type: "suggestion",
|
|
@@ -2552,11 +2305,11 @@ var no_forward_ref_default = createRule({
|
|
|
2552
2305
|
},
|
|
2553
2306
|
schema: []
|
|
2554
2307
|
},
|
|
2555
|
-
name: RULE_NAME$
|
|
2556
|
-
create: create$
|
|
2308
|
+
name: RULE_NAME$37,
|
|
2309
|
+
create: create$37,
|
|
2557
2310
|
defaultOptions: []
|
|
2558
2311
|
});
|
|
2559
|
-
function create$
|
|
2312
|
+
function create$37(context) {
|
|
2560
2313
|
if (!context.sourceCode.text.includes("forwardRef")) return {};
|
|
2561
2314
|
const { version } = getSettingsFromContext(context);
|
|
2562
2315
|
if (compare(version, "19.0.0", "<")) return {};
|
|
@@ -2661,7 +2414,7 @@ function getComponentPropsFixes(context, fixer, node, typeArguments) {
|
|
|
2661
2414
|
|
|
2662
2415
|
//#endregion
|
|
2663
2416
|
//#region src/rules/no-implicit-children/no-implicit-children.ts
|
|
2664
|
-
const RULE_NAME$
|
|
2417
|
+
const RULE_NAME$36 = "no-implicit-children";
|
|
2665
2418
|
const RE_REACT_CHILDREN_TYPE = /react\.(reactnode|reactelement|reactportal)$/i;
|
|
2666
2419
|
var no_implicit_children_default = createRule({
|
|
2667
2420
|
meta: {
|
|
@@ -2670,11 +2423,11 @@ var no_implicit_children_default = createRule({
|
|
|
2670
2423
|
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}'." },
|
|
2671
2424
|
schema: []
|
|
2672
2425
|
},
|
|
2673
|
-
name: RULE_NAME$
|
|
2674
|
-
create: create$
|
|
2426
|
+
name: RULE_NAME$36,
|
|
2427
|
+
create: create$36,
|
|
2675
2428
|
defaultOptions: []
|
|
2676
2429
|
});
|
|
2677
|
-
function create$
|
|
2430
|
+
function create$36(context) {
|
|
2678
2431
|
const services = ESLintUtils.getParserServices(context, false);
|
|
2679
2432
|
const checker = services.program.getTypeChecker();
|
|
2680
2433
|
return defineRuleListener({ JSXSpreadAttribute(node) {
|
|
@@ -2699,7 +2452,7 @@ function create$37(context) {
|
|
|
2699
2452
|
|
|
2700
2453
|
//#endregion
|
|
2701
2454
|
//#region src/rules/no-implicit-key/no-implicit-key.ts
|
|
2702
|
-
const RULE_NAME$
|
|
2455
|
+
const RULE_NAME$35 = "no-implicit-key";
|
|
2703
2456
|
var no_implicit_key_default = createRule({
|
|
2704
2457
|
meta: {
|
|
2705
2458
|
type: "problem",
|
|
@@ -2707,11 +2460,11 @@ var no_implicit_key_default = createRule({
|
|
|
2707
2460
|
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}'." },
|
|
2708
2461
|
schema: []
|
|
2709
2462
|
},
|
|
2710
|
-
name: RULE_NAME$
|
|
2711
|
-
create: create$
|
|
2463
|
+
name: RULE_NAME$35,
|
|
2464
|
+
create: create$35,
|
|
2712
2465
|
defaultOptions: []
|
|
2713
2466
|
});
|
|
2714
|
-
function create$
|
|
2467
|
+
function create$35(context) {
|
|
2715
2468
|
const services = ESLintUtils.getParserServices(context, false);
|
|
2716
2469
|
const checker = services.program.getTypeChecker();
|
|
2717
2470
|
return defineRuleListener({ JSXSpreadAttribute(node) {
|
|
@@ -2733,7 +2486,7 @@ function create$36(context) {
|
|
|
2733
2486
|
|
|
2734
2487
|
//#endregion
|
|
2735
2488
|
//#region src/rules/no-implicit-ref/no-implicit-ref.ts
|
|
2736
|
-
const RULE_NAME$
|
|
2489
|
+
const RULE_NAME$34 = "no-implicit-ref";
|
|
2737
2490
|
const RE_REACT_REF_TYPE = /react\.(ref|legacyref|refcallback|refobject)$/i;
|
|
2738
2491
|
var no_implicit_ref_default = createRule({
|
|
2739
2492
|
meta: {
|
|
@@ -2742,11 +2495,11 @@ var no_implicit_ref_default = createRule({
|
|
|
2742
2495
|
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}'." },
|
|
2743
2496
|
schema: []
|
|
2744
2497
|
},
|
|
2745
|
-
name: RULE_NAME$
|
|
2746
|
-
create: create$
|
|
2498
|
+
name: RULE_NAME$34,
|
|
2499
|
+
create: create$34,
|
|
2747
2500
|
defaultOptions: []
|
|
2748
2501
|
});
|
|
2749
|
-
function create$
|
|
2502
|
+
function create$34(context) {
|
|
2750
2503
|
const services = ESLintUtils.getParserServices(context, false);
|
|
2751
2504
|
const checker = services.program.getTypeChecker();
|
|
2752
2505
|
return defineRuleListener({ JSXSpreadAttribute(node) {
|
|
@@ -2770,7 +2523,7 @@ function create$35(context) {
|
|
|
2770
2523
|
|
|
2771
2524
|
//#endregion
|
|
2772
2525
|
//#region src/rules/no-leaked-conditional-rendering/no-leaked-conditional-rendering.ts
|
|
2773
|
-
const RULE_NAME$
|
|
2526
|
+
const RULE_NAME$33 = "no-leaked-conditional-rendering";
|
|
2774
2527
|
var no_leaked_conditional_rendering_default = createRule({
|
|
2775
2528
|
meta: {
|
|
2776
2529
|
type: "problem",
|
|
@@ -2778,11 +2531,11 @@ var no_leaked_conditional_rendering_default = createRule({
|
|
|
2778
2531
|
messages: { default: "Potential leaked value {{value}} that might cause unintentionally rendered values or rendering crashes." },
|
|
2779
2532
|
schema: []
|
|
2780
2533
|
},
|
|
2781
|
-
name: RULE_NAME$
|
|
2782
|
-
create: create$
|
|
2534
|
+
name: RULE_NAME$33,
|
|
2535
|
+
create: create$33,
|
|
2783
2536
|
defaultOptions: []
|
|
2784
2537
|
});
|
|
2785
|
-
function create$
|
|
2538
|
+
function create$33(context) {
|
|
2786
2539
|
if (!context.sourceCode.text.includes("&&")) return {};
|
|
2787
2540
|
const { version } = getSettingsFromContext(context);
|
|
2788
2541
|
const allowedVariants = [
|
|
@@ -2839,7 +2592,7 @@ function create$34(context) {
|
|
|
2839
2592
|
|
|
2840
2593
|
//#endregion
|
|
2841
2594
|
//#region src/rules/no-missing-component-display-name/no-missing-component-display-name.ts
|
|
2842
|
-
const RULE_NAME$
|
|
2595
|
+
const RULE_NAME$32 = "no-missing-component-display-name";
|
|
2843
2596
|
var no_missing_component_display_name_default = createRule({
|
|
2844
2597
|
meta: {
|
|
2845
2598
|
type: "suggestion",
|
|
@@ -2847,18 +2600,18 @@ var no_missing_component_display_name_default = createRule({
|
|
|
2847
2600
|
messages: { default: "Add missing 'displayName' for component." },
|
|
2848
2601
|
schema: []
|
|
2849
2602
|
},
|
|
2850
|
-
name: RULE_NAME$
|
|
2851
|
-
create: create$
|
|
2603
|
+
name: RULE_NAME$32,
|
|
2604
|
+
create: create$32,
|
|
2852
2605
|
defaultOptions: []
|
|
2853
2606
|
});
|
|
2854
|
-
function create$
|
|
2607
|
+
function create$32(context) {
|
|
2855
2608
|
if (!context.sourceCode.text.includes("memo") && !context.sourceCode.text.includes("forwardRef")) return {};
|
|
2856
|
-
const {
|
|
2609
|
+
const { api, visitor } = core.getComponentCollector(context, {
|
|
2857
2610
|
collectDisplayName: true,
|
|
2858
2611
|
hint: core.DEFAULT_COMPONENT_DETECTION_HINT
|
|
2859
2612
|
});
|
|
2860
2613
|
return defineRuleListener(visitor, { "Program:exit"(program) {
|
|
2861
|
-
for (const { displayName, flag, node } of
|
|
2614
|
+
for (const { displayName, flag, node } of api.getAllComponents(program)) {
|
|
2862
2615
|
const id = ast.getFunctionId(node);
|
|
2863
2616
|
const isMemoOrForwardRef = (flag & (core.ComponentFlag.ForwardRef | core.ComponentFlag.Memo)) > 0n;
|
|
2864
2617
|
if (id != null) continue;
|
|
@@ -2873,7 +2626,7 @@ function create$33(context) {
|
|
|
2873
2626
|
|
|
2874
2627
|
//#endregion
|
|
2875
2628
|
//#region src/rules/no-missing-context-display-name/no-missing-context-display-name.ts
|
|
2876
|
-
const RULE_NAME$
|
|
2629
|
+
const RULE_NAME$31 = "no-missing-context-display-name";
|
|
2877
2630
|
var no_missing_context_display_name_default = createRule({
|
|
2878
2631
|
meta: {
|
|
2879
2632
|
type: "suggestion",
|
|
@@ -2882,11 +2635,11 @@ var no_missing_context_display_name_default = createRule({
|
|
|
2882
2635
|
messages: { default: "Add missing 'displayName' for context." },
|
|
2883
2636
|
schema: []
|
|
2884
2637
|
},
|
|
2885
|
-
name: RULE_NAME$
|
|
2886
|
-
create: create$
|
|
2638
|
+
name: RULE_NAME$31,
|
|
2639
|
+
create: create$31,
|
|
2887
2640
|
defaultOptions: []
|
|
2888
2641
|
});
|
|
2889
|
-
function create$
|
|
2642
|
+
function create$31(context) {
|
|
2890
2643
|
if (!context.sourceCode.text.includes("createContext")) return {};
|
|
2891
2644
|
const createCalls = [];
|
|
2892
2645
|
const displayNameAssignments = [];
|
|
@@ -2938,7 +2691,7 @@ function create$32(context) {
|
|
|
2938
2691
|
|
|
2939
2692
|
//#endregion
|
|
2940
2693
|
//#region src/rules/no-missing-key/no-missing-key.ts
|
|
2941
|
-
const RULE_NAME$
|
|
2694
|
+
const RULE_NAME$30 = "no-missing-key";
|
|
2942
2695
|
var no_missing_key_default = createRule({
|
|
2943
2696
|
meta: {
|
|
2944
2697
|
type: "problem",
|
|
@@ -2949,15 +2702,14 @@ var no_missing_key_default = createRule({
|
|
|
2949
2702
|
},
|
|
2950
2703
|
schema: []
|
|
2951
2704
|
},
|
|
2952
|
-
name: RULE_NAME$
|
|
2953
|
-
create: create$
|
|
2705
|
+
name: RULE_NAME$30,
|
|
2706
|
+
create: create$30,
|
|
2954
2707
|
defaultOptions: []
|
|
2955
2708
|
});
|
|
2956
|
-
function create$
|
|
2957
|
-
const jsx = JsxInspector.from(ctx);
|
|
2709
|
+
function create$30(ctx) {
|
|
2958
2710
|
let inChildrenToArray = false;
|
|
2959
2711
|
function check(node) {
|
|
2960
|
-
if (node.type === AST_NODE_TYPES.JSXElement) return !
|
|
2712
|
+
if (node.type === AST_NODE_TYPES.JSXElement) return !hasAttribute(ctx, node, "key") ? {
|
|
2961
2713
|
messageId: "default",
|
|
2962
2714
|
node
|
|
2963
2715
|
} : null;
|
|
@@ -2991,7 +2743,7 @@ function create$31(ctx) {
|
|
|
2991
2743
|
if (inChildrenToArray) return;
|
|
2992
2744
|
const elements = node.elements.filter(ast.is(AST_NODE_TYPES.JSXElement));
|
|
2993
2745
|
if (elements.length === 0) return;
|
|
2994
|
-
for (const el of elements) if (!
|
|
2746
|
+
for (const el of elements) if (!hasAttribute(ctx, el, "key")) ctx.report({
|
|
2995
2747
|
messageId: "default",
|
|
2996
2748
|
node: el
|
|
2997
2749
|
});
|
|
@@ -3024,7 +2776,7 @@ function create$31(ctx) {
|
|
|
3024
2776
|
|
|
3025
2777
|
//#endregion
|
|
3026
2778
|
//#region src/rules/no-misused-capture-owner-stack/no-misused-capture-owner-stack.ts
|
|
3027
|
-
const RULE_NAME$
|
|
2779
|
+
const RULE_NAME$29 = "no-misused-capture-owner-stack";
|
|
3028
2780
|
var no_misused_capture_owner_stack_default = createRule({
|
|
3029
2781
|
meta: {
|
|
3030
2782
|
type: "problem",
|
|
@@ -3035,17 +2787,17 @@ var no_misused_capture_owner_stack_default = createRule({
|
|
|
3035
2787
|
},
|
|
3036
2788
|
schema: []
|
|
3037
2789
|
},
|
|
3038
|
-
name: RULE_NAME$
|
|
3039
|
-
create: create$
|
|
2790
|
+
name: RULE_NAME$29,
|
|
2791
|
+
create: create$29,
|
|
3040
2792
|
defaultOptions: []
|
|
3041
2793
|
});
|
|
3042
|
-
function create$
|
|
2794
|
+
function create$29(context) {
|
|
3043
2795
|
if (!context.sourceCode.text.includes("captureOwnerStack")) return {};
|
|
3044
2796
|
const { importSource } = getSettingsFromContext(context);
|
|
3045
2797
|
return defineRuleListener({
|
|
3046
2798
|
CallExpression(node) {
|
|
3047
2799
|
if (!core.isCaptureOwnerStackCall(context, node)) return;
|
|
3048
|
-
if (ast.
|
|
2800
|
+
if (ast.findParent(node, isDevelopmentOnlyCheck) == null) context.report({
|
|
3049
2801
|
messageId: "missingDevelopmentOnlyCheck",
|
|
3050
2802
|
node
|
|
3051
2803
|
});
|
|
@@ -3070,7 +2822,7 @@ function isDevelopmentOnlyCheck(node) {
|
|
|
3070
2822
|
|
|
3071
2823
|
//#endregion
|
|
3072
2824
|
//#region src/rules/no-nested-component-definitions/no-nested-component-definitions.ts
|
|
3073
|
-
const RULE_NAME$
|
|
2825
|
+
const RULE_NAME$28 = "no-nested-component-definitions";
|
|
3074
2826
|
var no_nested_component_definitions_default = createRule({
|
|
3075
2827
|
meta: {
|
|
3076
2828
|
type: "problem",
|
|
@@ -3078,19 +2830,19 @@ var no_nested_component_definitions_default = createRule({
|
|
|
3078
2830
|
messages: { default: "Do not nest component definitions inside other components or props. {{suggestion}}" },
|
|
3079
2831
|
schema: []
|
|
3080
2832
|
},
|
|
3081
|
-
name: RULE_NAME$
|
|
3082
|
-
create: create$
|
|
2833
|
+
name: RULE_NAME$28,
|
|
2834
|
+
create: create$28,
|
|
3083
2835
|
defaultOptions: []
|
|
3084
2836
|
});
|
|
3085
|
-
function create$
|
|
3086
|
-
const hint = core.ComponentDetectionHint.DoNotIncludeJsxWithNumberValue | core.ComponentDetectionHint.DoNotIncludeJsxWithBooleanValue | core.ComponentDetectionHint.DoNotIncludeJsxWithNullValue | core.ComponentDetectionHint.DoNotIncludeJsxWithStringValue | core.ComponentDetectionHint.DoNotIncludeJsxWithUndefinedValue | core.ComponentDetectionHint.RequireBothSidesOfLogicalExpressionToBeJsx | core.ComponentDetectionHint.RequireBothBranchesOfConditionalExpressionToBeJsx | core.ComponentDetectionHint.
|
|
3087
|
-
const fCollector = core.
|
|
3088
|
-
const cCollector = core.
|
|
2837
|
+
function create$28(context) {
|
|
2838
|
+
const hint = core.ComponentDetectionHint.DoNotIncludeJsxWithNumberValue | core.ComponentDetectionHint.DoNotIncludeJsxWithBooleanValue | core.ComponentDetectionHint.DoNotIncludeJsxWithNullValue | core.ComponentDetectionHint.DoNotIncludeJsxWithStringValue | core.ComponentDetectionHint.DoNotIncludeJsxWithUndefinedValue | core.ComponentDetectionHint.RequireBothSidesOfLogicalExpressionToBeJsx | core.ComponentDetectionHint.RequireBothBranchesOfConditionalExpressionToBeJsx | core.ComponentDetectionHint.DoNotIncludeFunctionDefinedAsArrayPatternElement | core.ComponentDetectionHint.DoNotIncludeFunctionDefinedAsArrayExpressionElement | core.ComponentDetectionHint.DoNotIncludeFunctionDefinedAsArrayMapCallback;
|
|
2839
|
+
const fCollector = core.getComponentCollector(context, { hint });
|
|
2840
|
+
const cCollector = core.getComponentCollectorLegacy(context);
|
|
3089
2841
|
return defineRuleListener(fCollector.visitor, cCollector.visitor, { "Program:exit"(program) {
|
|
3090
|
-
const fComponents = [...fCollector.
|
|
3091
|
-
const cComponents = [...cCollector.
|
|
2842
|
+
const fComponents = [...fCollector.api.getAllComponents(program)];
|
|
2843
|
+
const cComponents = [...cCollector.api.getAllComponents(program)];
|
|
3092
2844
|
function findEnclosingComponent(node) {
|
|
3093
|
-
return ast.
|
|
2845
|
+
return ast.findParent(node, (n) => {
|
|
3094
2846
|
if (ast.isFunction(n)) return fComponents.some((c) => c.node === n);
|
|
3095
2847
|
if (ast.isClass(n)) return cComponents.some((c) => c.node === n);
|
|
3096
2848
|
return false;
|
|
@@ -3159,7 +2911,7 @@ function create$29(context) {
|
|
|
3159
2911
|
* @returns `true` if the node is inside JSX attribute value
|
|
3160
2912
|
*/
|
|
3161
2913
|
function isInsideJSXAttributeValue(node) {
|
|
3162
|
-
return node.parent.type === AST_NODE_TYPES.JSXAttribute ||
|
|
2914
|
+
return node.parent.type === AST_NODE_TYPES.JSXAttribute || findParentAttribute(node, (n) => n.value?.type === AST_NODE_TYPES.JSXExpressionContainer) != null;
|
|
3163
2915
|
}
|
|
3164
2916
|
/**
|
|
3165
2917
|
* Check whether a given node is declared inside a class component's render block
|
|
@@ -3168,7 +2920,7 @@ function isInsideJSXAttributeValue(node) {
|
|
|
3168
2920
|
* @returns `true` if the node is inside a class component's render block
|
|
3169
2921
|
*/
|
|
3170
2922
|
function isInsideRenderMethod(node) {
|
|
3171
|
-
return ast.
|
|
2923
|
+
return ast.findParent(node, (n) => core.isRenderMethodLike(n) && core.isClassComponent(n.parent.parent)) != null;
|
|
3172
2924
|
}
|
|
3173
2925
|
/**
|
|
3174
2926
|
* Determine whether the node is inside `createElement`'s props argument
|
|
@@ -3177,16 +2929,16 @@ function isInsideRenderMethod(node) {
|
|
|
3177
2929
|
* @returns `true` if the node is inside `createElement`'s props
|
|
3178
2930
|
*/
|
|
3179
2931
|
function isInsideCreateElementProps(context, node) {
|
|
3180
|
-
const call = ast.
|
|
2932
|
+
const call = ast.findParent(node, core.isCreateElementCall(context));
|
|
3181
2933
|
if (call == null) return false;
|
|
3182
|
-
const prop = ast.
|
|
2934
|
+
const prop = ast.findParent(node, ast.is(AST_NODE_TYPES.ObjectExpression));
|
|
3183
2935
|
if (prop == null) return false;
|
|
3184
2936
|
return prop === call.arguments[1];
|
|
3185
2937
|
}
|
|
3186
2938
|
|
|
3187
2939
|
//#endregion
|
|
3188
2940
|
//#region src/rules/no-nested-lazy-component-declarations/no-nested-lazy-component-declarations.ts
|
|
3189
|
-
const RULE_NAME$
|
|
2941
|
+
const RULE_NAME$27 = "no-nested-lazy-component-declarations";
|
|
3190
2942
|
var no_nested_lazy_component_declarations_default = createRule({
|
|
3191
2943
|
meta: {
|
|
3192
2944
|
type: "problem",
|
|
@@ -3194,24 +2946,24 @@ var no_nested_lazy_component_declarations_default = createRule({
|
|
|
3194
2946
|
messages: { default: "Do not declare lazy components inside other components. Instead, always declare them at the top level of your module." },
|
|
3195
2947
|
schema: []
|
|
3196
2948
|
},
|
|
3197
|
-
name: RULE_NAME$
|
|
3198
|
-
create: create$
|
|
2949
|
+
name: RULE_NAME$27,
|
|
2950
|
+
create: create$27,
|
|
3199
2951
|
defaultOptions: []
|
|
3200
2952
|
});
|
|
3201
|
-
function create$
|
|
2953
|
+
function create$27(context) {
|
|
3202
2954
|
const hint = core.ComponentDetectionHint.None;
|
|
3203
|
-
const collector = core.
|
|
3204
|
-
const collectorLegacy = core.
|
|
2955
|
+
const collector = core.getComponentCollector(context, { hint });
|
|
2956
|
+
const collectorLegacy = core.getComponentCollectorLegacy(context);
|
|
3205
2957
|
const lazyComponentDeclarations = /* @__PURE__ */ new Set();
|
|
3206
2958
|
return defineRuleListener(collector.visitor, collectorLegacy.visitor, {
|
|
3207
2959
|
ImportExpression(node) {
|
|
3208
|
-
const lazyCall = ast.
|
|
2960
|
+
const lazyCall = ast.findParent(node, (n) => core.isLazyCall(context, n));
|
|
3209
2961
|
if (lazyCall != null) lazyComponentDeclarations.add(lazyCall);
|
|
3210
2962
|
},
|
|
3211
2963
|
"Program:exit"(program) {
|
|
3212
|
-
const functionComponents = collector.
|
|
3213
|
-
const classComponents = collectorLegacy.
|
|
3214
|
-
for (const lazy of lazyComponentDeclarations) if (ast.
|
|
2964
|
+
const functionComponents = collector.api.getAllComponents(program);
|
|
2965
|
+
const classComponents = collectorLegacy.api.getAllComponents(program);
|
|
2966
|
+
for (const lazy of lazyComponentDeclarations) if (ast.findParent(lazy, (n) => {
|
|
3215
2967
|
if (ast.isJSX(n)) return true;
|
|
3216
2968
|
if (n.type === AST_NODE_TYPES.CallExpression) return core.isHookCall(n) || core.isCreateElementCall(context, n) || core.isCreateContextCall(context, n);
|
|
3217
2969
|
if (ast.isFunction(n)) return functionComponents.some((c) => c.node === n);
|
|
@@ -3227,7 +2979,7 @@ function create$28(context) {
|
|
|
3227
2979
|
|
|
3228
2980
|
//#endregion
|
|
3229
2981
|
//#region src/rules/no-redundant-should-component-update/no-redundant-should-component-update.ts
|
|
3230
|
-
const RULE_NAME$
|
|
2982
|
+
const RULE_NAME$26 = "no-redundant-should-component-update";
|
|
3231
2983
|
function isShouldComponentUpdate(node) {
|
|
3232
2984
|
return ast.isMethodOrProperty(node) && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === "shouldComponentUpdate";
|
|
3233
2985
|
}
|
|
@@ -3238,15 +2990,15 @@ var no_redundant_should_component_update_default = createRule({
|
|
|
3238
2990
|
messages: { default: "'{{componentName}}' does not need 'shouldComponentUpdate' when extending 'React.PureComponent'." },
|
|
3239
2991
|
schema: []
|
|
3240
2992
|
},
|
|
3241
|
-
name: RULE_NAME$
|
|
3242
|
-
create: create$
|
|
2993
|
+
name: RULE_NAME$26,
|
|
2994
|
+
create: create$26,
|
|
3243
2995
|
defaultOptions: []
|
|
3244
2996
|
});
|
|
3245
|
-
function create$
|
|
2997
|
+
function create$26(context) {
|
|
3246
2998
|
if (!context.sourceCode.text.includes("shouldComponentUpdate")) return {};
|
|
3247
|
-
const {
|
|
2999
|
+
const { api, visitor } = core.getComponentCollectorLegacy(context);
|
|
3248
3000
|
return defineRuleListener(visitor, { "Program:exit"(program) {
|
|
3249
|
-
for (const { name = "PureComponent", flag, node: component } of
|
|
3001
|
+
for (const { name = "PureComponent", flag, node: component } of api.getAllComponents(program)) {
|
|
3250
3002
|
if ((flag & core.ComponentFlag.PureComponent) === 0n) continue;
|
|
3251
3003
|
const { body } = component.body;
|
|
3252
3004
|
for (const member of body) if (isShouldComponentUpdate(member)) context.report({
|
|
@@ -3260,7 +3012,7 @@ function create$27(context) {
|
|
|
3260
3012
|
|
|
3261
3013
|
//#endregion
|
|
3262
3014
|
//#region src/rules/no-set-state-in-component-did-mount/no-set-state-in-component-did-mount.ts
|
|
3263
|
-
const RULE_NAME$
|
|
3015
|
+
const RULE_NAME$25 = "no-set-state-in-component-did-mount";
|
|
3264
3016
|
var no_set_state_in_component_did_mount_default = createRule({
|
|
3265
3017
|
meta: {
|
|
3266
3018
|
type: "problem",
|
|
@@ -3268,16 +3020,16 @@ var no_set_state_in_component_did_mount_default = createRule({
|
|
|
3268
3020
|
messages: { default: "Do not call `this.setState` in `componentDidMount` outside functions such as callbacks." },
|
|
3269
3021
|
schema: []
|
|
3270
3022
|
},
|
|
3271
|
-
name: RULE_NAME$
|
|
3272
|
-
create: create$
|
|
3023
|
+
name: RULE_NAME$25,
|
|
3024
|
+
create: create$25,
|
|
3273
3025
|
defaultOptions: []
|
|
3274
3026
|
});
|
|
3275
|
-
function create$
|
|
3027
|
+
function create$25(context) {
|
|
3276
3028
|
if (!context.sourceCode.text.includes("componentDidMount")) return {};
|
|
3277
3029
|
return defineRuleListener({ CallExpression(node) {
|
|
3278
3030
|
if (!core.isThisSetState(node)) return;
|
|
3279
|
-
const enclosingClassNode = ast.
|
|
3280
|
-
const enclosingMethodNode = ast.
|
|
3031
|
+
const enclosingClassNode = ast.findParent(node, core.isClassComponent);
|
|
3032
|
+
const enclosingMethodNode = ast.findParent(node, (n) => n === enclosingClassNode || core.isComponentDidMount(n));
|
|
3281
3033
|
if (enclosingClassNode == null || enclosingMethodNode == null || enclosingMethodNode === enclosingClassNode) return;
|
|
3282
3034
|
const enclosingMethodScope = context.sourceCode.getScope(enclosingMethodNode);
|
|
3283
3035
|
const setStateCallParentScope = context.sourceCode.getScope(node).upper;
|
|
@@ -3290,7 +3042,7 @@ function create$26(context) {
|
|
|
3290
3042
|
|
|
3291
3043
|
//#endregion
|
|
3292
3044
|
//#region src/rules/no-set-state-in-component-did-update/no-set-state-in-component-did-update.ts
|
|
3293
|
-
const RULE_NAME$
|
|
3045
|
+
const RULE_NAME$24 = "no-set-state-in-component-did-update";
|
|
3294
3046
|
var no_set_state_in_component_did_update_default = createRule({
|
|
3295
3047
|
meta: {
|
|
3296
3048
|
type: "problem",
|
|
@@ -3298,16 +3050,16 @@ var no_set_state_in_component_did_update_default = createRule({
|
|
|
3298
3050
|
messages: { default: "Do not call `this.setState` in `componentDidUpdate` outside functions such as callbacks." },
|
|
3299
3051
|
schema: []
|
|
3300
3052
|
},
|
|
3301
|
-
name: RULE_NAME$
|
|
3302
|
-
create: create$
|
|
3053
|
+
name: RULE_NAME$24,
|
|
3054
|
+
create: create$24,
|
|
3303
3055
|
defaultOptions: []
|
|
3304
3056
|
});
|
|
3305
|
-
function create$
|
|
3057
|
+
function create$24(context) {
|
|
3306
3058
|
if (!context.sourceCode.text.includes("componentDidUpdate")) return {};
|
|
3307
3059
|
return defineRuleListener({ CallExpression(node) {
|
|
3308
3060
|
if (!core.isThisSetState(node)) return;
|
|
3309
|
-
const enclosingClassNode = ast.
|
|
3310
|
-
const enclosingMethodNode = ast.
|
|
3061
|
+
const enclosingClassNode = ast.findParent(node, core.isClassComponent);
|
|
3062
|
+
const enclosingMethodNode = ast.findParent(node, (n) => n === enclosingClassNode || core.isComponentDidUpdate(n));
|
|
3311
3063
|
if (enclosingClassNode == null || enclosingMethodNode == null || enclosingMethodNode === enclosingClassNode) return;
|
|
3312
3064
|
const enclosingMethodScope = context.sourceCode.getScope(enclosingMethodNode);
|
|
3313
3065
|
const setStateCallParentScope = context.sourceCode.getScope(node).upper;
|
|
@@ -3320,7 +3072,7 @@ function create$25(context) {
|
|
|
3320
3072
|
|
|
3321
3073
|
//#endregion
|
|
3322
3074
|
//#region src/rules/no-set-state-in-component-will-update/no-set-state-in-component-will-update.ts
|
|
3323
|
-
const RULE_NAME$
|
|
3075
|
+
const RULE_NAME$23 = "no-set-state-in-component-will-update";
|
|
3324
3076
|
var no_set_state_in_component_will_update_default = createRule({
|
|
3325
3077
|
meta: {
|
|
3326
3078
|
type: "problem",
|
|
@@ -3328,16 +3080,16 @@ var no_set_state_in_component_will_update_default = createRule({
|
|
|
3328
3080
|
messages: { default: "Do not call `this.setState` in `componentWillUpdate` outside functions such as callbacks." },
|
|
3329
3081
|
schema: []
|
|
3330
3082
|
},
|
|
3331
|
-
name: RULE_NAME$
|
|
3332
|
-
create: create$
|
|
3083
|
+
name: RULE_NAME$23,
|
|
3084
|
+
create: create$23,
|
|
3333
3085
|
defaultOptions: []
|
|
3334
3086
|
});
|
|
3335
|
-
function create$
|
|
3087
|
+
function create$23(context) {
|
|
3336
3088
|
if (!context.sourceCode.text.includes("componentWillUpdate")) return {};
|
|
3337
3089
|
return defineRuleListener({ CallExpression(node) {
|
|
3338
3090
|
if (!core.isThisSetState(node)) return;
|
|
3339
|
-
const enclosingClassNode = ast.
|
|
3340
|
-
const enclosingMethodNode = ast.
|
|
3091
|
+
const enclosingClassNode = ast.findParent(node, core.isClassComponent);
|
|
3092
|
+
const enclosingMethodNode = ast.findParent(node, (n) => n === enclosingClassNode || core.isComponentWillUpdate(n));
|
|
3341
3093
|
if (enclosingClassNode == null || enclosingMethodNode == null || enclosingMethodNode === enclosingClassNode) return;
|
|
3342
3094
|
const enclosingMethodScope = context.sourceCode.getScope(enclosingMethodNode);
|
|
3343
3095
|
const setStateCallParentScope = context.sourceCode.getScope(node).upper;
|
|
@@ -3350,7 +3102,7 @@ function create$24(context) {
|
|
|
3350
3102
|
|
|
3351
3103
|
//#endregion
|
|
3352
3104
|
//#region src/rules/no-unnecessary-use-callback/no-unnecessary-use-callback.ts
|
|
3353
|
-
const RULE_NAME$
|
|
3105
|
+
const RULE_NAME$22 = "no-unnecessary-use-callback";
|
|
3354
3106
|
var no_unnecessary_use_callback_default = createRule({
|
|
3355
3107
|
meta: {
|
|
3356
3108
|
type: "suggestion",
|
|
@@ -3361,11 +3113,11 @@ var no_unnecessary_use_callback_default = createRule({
|
|
|
3361
3113
|
},
|
|
3362
3114
|
schema: []
|
|
3363
3115
|
},
|
|
3364
|
-
name: RULE_NAME$
|
|
3365
|
-
create: create$
|
|
3116
|
+
name: RULE_NAME$22,
|
|
3117
|
+
create: create$22,
|
|
3366
3118
|
defaultOptions: []
|
|
3367
3119
|
});
|
|
3368
|
-
function create$
|
|
3120
|
+
function create$22(context) {
|
|
3369
3121
|
if (!context.sourceCode.text.includes("useCallback")) return {};
|
|
3370
3122
|
return defineRuleListener({ VariableDeclarator(node) {
|
|
3371
3123
|
const { id, init } = node;
|
|
@@ -3416,7 +3168,7 @@ function checkForUsageInsideUseEffect$1(sourceCode, node) {
|
|
|
3416
3168
|
if (usages.length === 0) return null;
|
|
3417
3169
|
const effectSet = /* @__PURE__ */ new Set();
|
|
3418
3170
|
for (const usage of usages) {
|
|
3419
|
-
const effect = ast.
|
|
3171
|
+
const effect = ast.findParent(usage.identifier, core.isUseEffectLikeCall);
|
|
3420
3172
|
if (effect == null) return null;
|
|
3421
3173
|
effectSet.add(effect);
|
|
3422
3174
|
if (effectSet.size > 1) return null;
|
|
@@ -3430,7 +3182,7 @@ function checkForUsageInsideUseEffect$1(sourceCode, node) {
|
|
|
3430
3182
|
|
|
3431
3183
|
//#endregion
|
|
3432
3184
|
//#region src/rules/no-unnecessary-use-memo/no-unnecessary-use-memo.ts
|
|
3433
|
-
const RULE_NAME$
|
|
3185
|
+
const RULE_NAME$21 = "no-unnecessary-use-memo";
|
|
3434
3186
|
var no_unnecessary_use_memo_default = createRule({
|
|
3435
3187
|
meta: {
|
|
3436
3188
|
type: "suggestion",
|
|
@@ -3441,11 +3193,11 @@ var no_unnecessary_use_memo_default = createRule({
|
|
|
3441
3193
|
},
|
|
3442
3194
|
schema: []
|
|
3443
3195
|
},
|
|
3444
|
-
name: RULE_NAME$
|
|
3445
|
-
create: create$
|
|
3196
|
+
name: RULE_NAME$21,
|
|
3197
|
+
create: create$21,
|
|
3446
3198
|
defaultOptions: []
|
|
3447
3199
|
});
|
|
3448
|
-
function create$
|
|
3200
|
+
function create$21(context) {
|
|
3449
3201
|
if (!context.sourceCode.text.includes("useMemo")) return {};
|
|
3450
3202
|
return defineRuleListener({ VariableDeclarator(node) {
|
|
3451
3203
|
const { id, init } = node;
|
|
@@ -3499,7 +3251,7 @@ function checkForUsageInsideUseEffect(sourceCode, node) {
|
|
|
3499
3251
|
if (usages.length === 0) return null;
|
|
3500
3252
|
const effectSet = /* @__PURE__ */ new Set();
|
|
3501
3253
|
for (const usage of usages) {
|
|
3502
|
-
const effect = ast.
|
|
3254
|
+
const effect = ast.findParent(usage.identifier, core.isUseEffectLikeCall);
|
|
3503
3255
|
if (effect == null) return null;
|
|
3504
3256
|
effectSet.add(effect);
|
|
3505
3257
|
if (effectSet.size > 1) return null;
|
|
@@ -3513,7 +3265,7 @@ function checkForUsageInsideUseEffect(sourceCode, node) {
|
|
|
3513
3265
|
|
|
3514
3266
|
//#endregion
|
|
3515
3267
|
//#region src/rules/no-unnecessary-use-prefix/no-unnecessary-use-prefix.ts
|
|
3516
|
-
const RULE_NAME$
|
|
3268
|
+
const RULE_NAME$20 = "no-unnecessary-use-prefix";
|
|
3517
3269
|
const WELL_KNOWN_HOOKS = ["useMDXComponents"];
|
|
3518
3270
|
function containsUseComments(context, node) {
|
|
3519
3271
|
return context.sourceCode.getCommentsInside(node).some(({ value }) => /use\([\s\S]*?\)/u.test(value) || /use[A-Z0-9]\w*\([\s\S]*?\)/u.test(value));
|
|
@@ -3525,19 +3277,19 @@ var no_unnecessary_use_prefix_default = createRule({
|
|
|
3525
3277
|
messages: { default: "If your function doesn't call any Hooks, avoid the 'use' prefix. Instead, write it as a regular function without the 'use' prefix." },
|
|
3526
3278
|
schema: []
|
|
3527
3279
|
},
|
|
3528
|
-
name: RULE_NAME$
|
|
3529
|
-
create: create$
|
|
3280
|
+
name: RULE_NAME$20,
|
|
3281
|
+
create: create$20,
|
|
3530
3282
|
defaultOptions: []
|
|
3531
3283
|
});
|
|
3532
|
-
function create$
|
|
3533
|
-
const {
|
|
3284
|
+
function create$20(context) {
|
|
3285
|
+
const { api, visitor } = core.getHookCollector(context);
|
|
3534
3286
|
return defineRuleListener(visitor, { "Program:exit"(program) {
|
|
3535
|
-
for (const { id, name, hookCalls, node } of
|
|
3287
|
+
for (const { id, name, hookCalls, node } of api.getAllHooks(program)) {
|
|
3536
3288
|
if (hookCalls.length > 0) continue;
|
|
3537
3289
|
if (ast.isFunctionEmpty(node)) continue;
|
|
3538
3290
|
if (WELL_KNOWN_HOOKS.includes(name)) continue;
|
|
3539
3291
|
if (containsUseComments(context, node)) continue;
|
|
3540
|
-
if (ast.
|
|
3292
|
+
if (ast.findParent(node, ast.isViMockCallback) != null) continue;
|
|
3541
3293
|
context.report({
|
|
3542
3294
|
data: { name },
|
|
3543
3295
|
messageId: "default",
|
|
@@ -3549,7 +3301,7 @@ function create$21(context) {
|
|
|
3549
3301
|
|
|
3550
3302
|
//#endregion
|
|
3551
3303
|
//#region src/rules/no-unsafe-component-will-mount/no-unsafe-component-will-mount.ts
|
|
3552
|
-
const RULE_NAME$
|
|
3304
|
+
const RULE_NAME$19 = "no-unsafe-component-will-mount";
|
|
3553
3305
|
var no_unsafe_component_will_mount_default = createRule({
|
|
3554
3306
|
meta: {
|
|
3555
3307
|
type: "problem",
|
|
@@ -3557,15 +3309,15 @@ var no_unsafe_component_will_mount_default = createRule({
|
|
|
3557
3309
|
messages: { default: "Do not use 'UNSAFE_componentWillMount'." },
|
|
3558
3310
|
schema: []
|
|
3559
3311
|
},
|
|
3560
|
-
name: RULE_NAME$
|
|
3561
|
-
create: create$
|
|
3312
|
+
name: RULE_NAME$19,
|
|
3313
|
+
create: create$19,
|
|
3562
3314
|
defaultOptions: []
|
|
3563
3315
|
});
|
|
3564
|
-
function create$
|
|
3316
|
+
function create$19(context) {
|
|
3565
3317
|
if (!context.sourceCode.text.includes("UNSAFE_componentWillMount")) return {};
|
|
3566
|
-
const {
|
|
3318
|
+
const { api, visitor } = core.getComponentCollectorLegacy(context);
|
|
3567
3319
|
return defineRuleListener(visitor, { "Program:exit"(program) {
|
|
3568
|
-
for (const { node: component } of
|
|
3320
|
+
for (const { node: component } of api.getAllComponents(program)) {
|
|
3569
3321
|
const { body } = component.body;
|
|
3570
3322
|
for (const member of body) if (core.isUnsafeComponentWillMount(member)) context.report({
|
|
3571
3323
|
messageId: "default",
|
|
@@ -3577,7 +3329,7 @@ function create$20(context) {
|
|
|
3577
3329
|
|
|
3578
3330
|
//#endregion
|
|
3579
3331
|
//#region src/rules/no-unsafe-component-will-receive-props/no-unsafe-component-will-receive-props.ts
|
|
3580
|
-
const RULE_NAME$
|
|
3332
|
+
const RULE_NAME$18 = "no-unsafe-component-will-receive-props";
|
|
3581
3333
|
var no_unsafe_component_will_receive_props_default = createRule({
|
|
3582
3334
|
meta: {
|
|
3583
3335
|
type: "problem",
|
|
@@ -3585,15 +3337,15 @@ var no_unsafe_component_will_receive_props_default = createRule({
|
|
|
3585
3337
|
messages: { default: "Do not use 'UNSAFE_componentWillReceiveProps'." },
|
|
3586
3338
|
schema: []
|
|
3587
3339
|
},
|
|
3588
|
-
name: RULE_NAME$
|
|
3589
|
-
create: create$
|
|
3340
|
+
name: RULE_NAME$18,
|
|
3341
|
+
create: create$18,
|
|
3590
3342
|
defaultOptions: []
|
|
3591
3343
|
});
|
|
3592
|
-
function create$
|
|
3344
|
+
function create$18(context) {
|
|
3593
3345
|
if (!context.sourceCode.text.includes("UNSAFE_componentWillReceiveProps")) return {};
|
|
3594
|
-
const {
|
|
3346
|
+
const { api, visitor } = core.getComponentCollectorLegacy(context);
|
|
3595
3347
|
return defineRuleListener(visitor, { "Program:exit"(program) {
|
|
3596
|
-
for (const { node: component } of
|
|
3348
|
+
for (const { node: component } of api.getAllComponents(program)) {
|
|
3597
3349
|
const { body } = component.body;
|
|
3598
3350
|
for (const member of body) if (core.isUnsafeComponentWillReceiveProps(member)) context.report({
|
|
3599
3351
|
messageId: "default",
|
|
@@ -3605,7 +3357,7 @@ function create$19(context) {
|
|
|
3605
3357
|
|
|
3606
3358
|
//#endregion
|
|
3607
3359
|
//#region src/rules/no-unsafe-component-will-update/no-unsafe-component-will-update.ts
|
|
3608
|
-
const RULE_NAME$
|
|
3360
|
+
const RULE_NAME$17 = "no-unsafe-component-will-update";
|
|
3609
3361
|
var no_unsafe_component_will_update_default = createRule({
|
|
3610
3362
|
meta: {
|
|
3611
3363
|
type: "problem",
|
|
@@ -3613,15 +3365,15 @@ var no_unsafe_component_will_update_default = createRule({
|
|
|
3613
3365
|
messages: { default: "Do not use 'UNSAFE_componentWillUpdate'." },
|
|
3614
3366
|
schema: []
|
|
3615
3367
|
},
|
|
3616
|
-
name: RULE_NAME$
|
|
3617
|
-
create: create$
|
|
3368
|
+
name: RULE_NAME$17,
|
|
3369
|
+
create: create$17,
|
|
3618
3370
|
defaultOptions: []
|
|
3619
3371
|
});
|
|
3620
|
-
function create$
|
|
3372
|
+
function create$17(context) {
|
|
3621
3373
|
if (!context.sourceCode.text.includes("UNSAFE_componentWillUpdate")) return {};
|
|
3622
|
-
const {
|
|
3374
|
+
const { api, visitor } = core.getComponentCollectorLegacy(context);
|
|
3623
3375
|
return defineRuleListener(visitor, { "Program:exit"(program) {
|
|
3624
|
-
for (const { node: component } of
|
|
3376
|
+
for (const { node: component } of api.getAllComponents(program)) {
|
|
3625
3377
|
const { body } = component.body;
|
|
3626
3378
|
for (const member of body) if (core.isUnsafeComponentWillUpdate(member)) context.report({
|
|
3627
3379
|
messageId: "default",
|
|
@@ -3633,7 +3385,7 @@ function create$18(context) {
|
|
|
3633
3385
|
|
|
3634
3386
|
//#endregion
|
|
3635
3387
|
//#region src/rules/no-unstable-context-value/no-unstable-context-value.ts
|
|
3636
|
-
const RULE_NAME$
|
|
3388
|
+
const RULE_NAME$16 = "no-unstable-context-value";
|
|
3637
3389
|
var no_unstable_context_value_default = createRule({
|
|
3638
3390
|
meta: {
|
|
3639
3391
|
type: "problem",
|
|
@@ -3641,26 +3393,25 @@ var no_unstable_context_value_default = createRule({
|
|
|
3641
3393
|
messages: { unstableContextValue: "A/an '{{kind}}' passed as the value prop to the context provider should not be constructed. It will change on every render. {{suggestion}}" },
|
|
3642
3394
|
schema: []
|
|
3643
3395
|
},
|
|
3644
|
-
name: RULE_NAME$
|
|
3645
|
-
create: create$
|
|
3396
|
+
name: RULE_NAME$16,
|
|
3397
|
+
create: create$16,
|
|
3646
3398
|
defaultOptions: []
|
|
3647
3399
|
});
|
|
3648
|
-
function create$
|
|
3400
|
+
function create$16(context) {
|
|
3649
3401
|
const { compilationMode, version } = getSettingsFromContext(context);
|
|
3650
3402
|
if (compilationMode === "infer" || compilationMode === "all") return {};
|
|
3651
3403
|
if (compilationMode === "annotation" && ast.isDirectiveInFile(context.sourceCode.ast, "use memo")) return {};
|
|
3652
3404
|
const isReact18OrBelow = compare(version, "19.0.0", "<");
|
|
3653
|
-
const {
|
|
3405
|
+
const { api, visitor } = core.getComponentCollector(context);
|
|
3654
3406
|
const constructions = /* @__PURE__ */ new WeakMap();
|
|
3655
|
-
const jsx = JsxInspector.from(context);
|
|
3656
3407
|
return defineRuleListener(visitor, {
|
|
3657
3408
|
JSXOpeningElement(node) {
|
|
3658
|
-
const selfName =
|
|
3409
|
+
const selfName = getElementFullType(node.parent).split(".").at(-1);
|
|
3659
3410
|
if (selfName == null) return;
|
|
3660
3411
|
if (!isContextName(selfName, isReact18OrBelow)) return;
|
|
3661
|
-
const
|
|
3662
|
-
if (
|
|
3663
|
-
if (compilationMode === "annotation" && ast.isDirectiveInFunction(
|
|
3412
|
+
const enclosingFunction = ast.findParent(node, ast.isFunction);
|
|
3413
|
+
if (enclosingFunction == null) return;
|
|
3414
|
+
if (compilationMode === "annotation" && ast.isDirectiveInFunction(enclosingFunction, "use memo")) return;
|
|
3664
3415
|
const attribute = node.attributes.find((attribute) => attribute.type === AST_NODE_TYPES.JSXAttribute && attribute.name.name === "value");
|
|
3665
3416
|
if (attribute == null || !("value" in attribute)) return;
|
|
3666
3417
|
const value = attribute.value;
|
|
@@ -3669,10 +3420,10 @@ function create$17(context) {
|
|
|
3669
3420
|
const construction = computeObjectType(context, valueExpression);
|
|
3670
3421
|
if (construction == null) return;
|
|
3671
3422
|
if (core.isHookCall(construction.node)) return;
|
|
3672
|
-
getOrElseUpdate(constructions,
|
|
3423
|
+
getOrElseUpdate(constructions, enclosingFunction, () => []).push(construction);
|
|
3673
3424
|
},
|
|
3674
3425
|
"Program:exit"(program) {
|
|
3675
|
-
for (const { directives, node: component } of
|
|
3426
|
+
for (const { directives, node: component } of api.getAllComponents(program)) {
|
|
3676
3427
|
if (compilationMode === "annotation" && directives.some((d) => d.directive === "use memo")) continue;
|
|
3677
3428
|
for (const construction of constructions.get(component) ?? []) {
|
|
3678
3429
|
const { kind, node: constructionNode } = construction;
|
|
@@ -3698,9 +3449,9 @@ function isContextName(name, isReact18OrBelow) {
|
|
|
3698
3449
|
|
|
3699
3450
|
//#endregion
|
|
3700
3451
|
//#region src/rules/no-unstable-default-props/no-unstable-default-props.ts
|
|
3701
|
-
const RULE_NAME$
|
|
3702
|
-
const defaultOptions$
|
|
3703
|
-
const schema$
|
|
3452
|
+
const RULE_NAME$15 = "no-unstable-default-props";
|
|
3453
|
+
const defaultOptions$1 = [{ safeDefaultProps: [] }];
|
|
3454
|
+
const schema$1 = [{
|
|
3704
3455
|
type: "object",
|
|
3705
3456
|
additionalProperties: false,
|
|
3706
3457
|
properties: { safeDefaultProps: {
|
|
@@ -3713,11 +3464,11 @@ var no_unstable_default_props_default = createRule({
|
|
|
3713
3464
|
type: "problem",
|
|
3714
3465
|
docs: { description: "Prevents using referential-type values as default props in object destructuring." },
|
|
3715
3466
|
messages: { default: "A/an '{{kind}}' as default prop. This could lead to potential infinite render loop in React. Use a variable instead of '{{kind}}'." },
|
|
3716
|
-
schema: schema$
|
|
3467
|
+
schema: schema$1
|
|
3717
3468
|
},
|
|
3718
|
-
name: RULE_NAME$
|
|
3719
|
-
create: create$
|
|
3720
|
-
defaultOptions: defaultOptions$
|
|
3469
|
+
name: RULE_NAME$15,
|
|
3470
|
+
create: create$15,
|
|
3471
|
+
defaultOptions: defaultOptions$1
|
|
3721
3472
|
});
|
|
3722
3473
|
function extractIdentifier(node) {
|
|
3723
3474
|
if (node.type === AST_NODE_TYPES.NewExpression && node.callee.type === AST_NODE_TYPES.Identifier) return node.callee.name;
|
|
@@ -3727,22 +3478,22 @@ function extractIdentifier(node) {
|
|
|
3727
3478
|
}
|
|
3728
3479
|
return null;
|
|
3729
3480
|
}
|
|
3730
|
-
function create$
|
|
3481
|
+
function create$15(context, [options]) {
|
|
3731
3482
|
const { compilationMode } = getSettingsFromContext(context);
|
|
3732
3483
|
if (compilationMode === "infer" || compilationMode === "all") return {};
|
|
3733
3484
|
if (compilationMode === "annotation" && ast.isDirectiveInFile(context.sourceCode.ast, "use memo")) return {};
|
|
3734
|
-
const {
|
|
3485
|
+
const { api, visitor } = core.getComponentCollector(context);
|
|
3735
3486
|
const declarators = /* @__PURE__ */ new WeakMap();
|
|
3736
3487
|
const { safeDefaultProps = [] } = options;
|
|
3737
3488
|
const safePatterns = safeDefaultProps.map((s) => toRegExp(s));
|
|
3738
3489
|
return defineRuleListener(visitor, {
|
|
3739
3490
|
[ast.SEL_OBJECT_DESTRUCTURING_VARIABLE_DECLARATOR](node) {
|
|
3740
|
-
const
|
|
3741
|
-
if (
|
|
3742
|
-
getOrElseUpdate(declarators,
|
|
3491
|
+
const enclosingFunction = ast.findParent(node, ast.isFunction);
|
|
3492
|
+
if (enclosingFunction == null) return;
|
|
3493
|
+
getOrElseUpdate(declarators, enclosingFunction, () => []).push(node);
|
|
3743
3494
|
},
|
|
3744
3495
|
"Program:exit"(program) {
|
|
3745
|
-
for (const { node: component } of
|
|
3496
|
+
for (const { node: component } of api.getAllComponents(program)) {
|
|
3746
3497
|
const { params } = component;
|
|
3747
3498
|
const [props] = params;
|
|
3748
3499
|
if (props == null) continue;
|
|
@@ -3773,7 +3524,7 @@ function create$16(context, [options]) {
|
|
|
3773
3524
|
|
|
3774
3525
|
//#endregion
|
|
3775
3526
|
//#region src/rules/no-unused-class-component-members/no-unused-class-component-members.ts
|
|
3776
|
-
const RULE_NAME$
|
|
3527
|
+
const RULE_NAME$14 = "no-unused-class-component-members";
|
|
3777
3528
|
const LIFECYCLE_METHODS = new Set([
|
|
3778
3529
|
"componentDidCatch",
|
|
3779
3530
|
"componentDidMount",
|
|
@@ -3804,11 +3555,11 @@ var no_unused_class_component_members_default = createRule({
|
|
|
3804
3555
|
messages: { default: "Unused method or property '{{methodName}}'' of class '{{className}}'." },
|
|
3805
3556
|
schema: []
|
|
3806
3557
|
},
|
|
3807
|
-
name: RULE_NAME$
|
|
3808
|
-
create: create$
|
|
3558
|
+
name: RULE_NAME$14,
|
|
3559
|
+
create: create$14,
|
|
3809
3560
|
defaultOptions: []
|
|
3810
3561
|
});
|
|
3811
|
-
function create$
|
|
3562
|
+
function create$14(context) {
|
|
3812
3563
|
const classStack = [];
|
|
3813
3564
|
const methodStack = [];
|
|
3814
3565
|
const propertyDefs = /* @__PURE__ */ new WeakMap();
|
|
@@ -3889,7 +3640,7 @@ function create$15(context) {
|
|
|
3889
3640
|
|
|
3890
3641
|
//#endregion
|
|
3891
3642
|
//#region src/rules/no-unused-props/no-unused-props.ts
|
|
3892
|
-
const RULE_NAME$
|
|
3643
|
+
const RULE_NAME$13 = "no-unused-props";
|
|
3893
3644
|
var no_unused_props_default = createRule({
|
|
3894
3645
|
meta: {
|
|
3895
3646
|
type: "suggestion",
|
|
@@ -3897,18 +3648,18 @@ var no_unused_props_default = createRule({
|
|
|
3897
3648
|
messages: { default: "Prop `{{name}}` is declared but never used" },
|
|
3898
3649
|
schema: []
|
|
3899
3650
|
},
|
|
3900
|
-
name: RULE_NAME$
|
|
3901
|
-
create: create$
|
|
3651
|
+
name: RULE_NAME$13,
|
|
3652
|
+
create: create$13,
|
|
3902
3653
|
defaultOptions: []
|
|
3903
3654
|
});
|
|
3904
|
-
function create$
|
|
3655
|
+
function create$13(context) {
|
|
3905
3656
|
const services = ESLintUtils.getParserServices(context, false);
|
|
3906
3657
|
const checker = services.program.getTypeChecker();
|
|
3907
|
-
const {
|
|
3658
|
+
const { api, visitor } = core.getComponentCollector(context);
|
|
3908
3659
|
return defineRuleListener(visitor, { "Program:exit"(program) {
|
|
3909
3660
|
const totalDeclaredProps = /* @__PURE__ */ new Map();
|
|
3910
3661
|
const totalUsedDeclarations = /* @__PURE__ */ new Set();
|
|
3911
|
-
for (const component of
|
|
3662
|
+
for (const component of api.getAllComponents(program)) {
|
|
3912
3663
|
const [props] = component.node.params;
|
|
3913
3664
|
if (props == null) continue;
|
|
3914
3665
|
const usedPropKeys = /* @__PURE__ */ new Set();
|
|
@@ -4002,7 +3753,7 @@ function reportUnusedProp(context, services, prop) {
|
|
|
4002
3753
|
|
|
4003
3754
|
//#endregion
|
|
4004
3755
|
//#region src/rules/no-unused-state/no-unused-state.ts
|
|
4005
|
-
const RULE_NAME$
|
|
3756
|
+
const RULE_NAME$12 = "no-unused-state";
|
|
4006
3757
|
function isKeyLiteral(node, key) {
|
|
4007
3758
|
return match(key).with({ type: AST_NODE_TYPES.Literal }, constTrue).with({
|
|
4008
3759
|
type: AST_NODE_TYPES.TemplateLiteral,
|
|
@@ -4016,11 +3767,11 @@ var no_unused_state_default = createRule({
|
|
|
4016
3767
|
messages: { default: "Unused class component state in '{{className}}'" },
|
|
4017
3768
|
schema: []
|
|
4018
3769
|
},
|
|
4019
|
-
name: RULE_NAME$
|
|
4020
|
-
create: create$
|
|
3770
|
+
name: RULE_NAME$12,
|
|
3771
|
+
create: create$12,
|
|
4021
3772
|
defaultOptions: []
|
|
4022
3773
|
});
|
|
4023
|
-
function create$
|
|
3774
|
+
function create$12(context) {
|
|
4024
3775
|
const classStack = [];
|
|
4025
3776
|
const methodStack = [];
|
|
4026
3777
|
const constructorStack = [];
|
|
@@ -4129,7 +3880,7 @@ function create$13(context) {
|
|
|
4129
3880
|
|
|
4130
3881
|
//#endregion
|
|
4131
3882
|
//#region src/rules/no-use-context/no-use-context.ts
|
|
4132
|
-
const RULE_NAME$
|
|
3883
|
+
const RULE_NAME$11 = "no-use-context";
|
|
4133
3884
|
var no_use_context_default = createRule({
|
|
4134
3885
|
meta: {
|
|
4135
3886
|
type: "suggestion",
|
|
@@ -4142,11 +3893,11 @@ var no_use_context_default = createRule({
|
|
|
4142
3893
|
},
|
|
4143
3894
|
schema: []
|
|
4144
3895
|
},
|
|
4145
|
-
name: RULE_NAME$
|
|
4146
|
-
create: create$
|
|
3896
|
+
name: RULE_NAME$11,
|
|
3897
|
+
create: create$11,
|
|
4147
3898
|
defaultOptions: []
|
|
4148
3899
|
});
|
|
4149
|
-
function create$
|
|
3900
|
+
function create$11(context) {
|
|
4150
3901
|
if (!context.sourceCode.text.includes("useContext")) return {};
|
|
4151
3902
|
const { version } = getSettingsFromContext(context);
|
|
4152
3903
|
if (compare(version, "19.0.0", "<")) return {};
|
|
@@ -4169,144 +3920,6 @@ function create$12(context) {
|
|
|
4169
3920
|
} });
|
|
4170
3921
|
}
|
|
4171
3922
|
|
|
4172
|
-
//#endregion
|
|
4173
|
-
//#region src/rules/no-useless-fragment/no-useless-fragment.ts
|
|
4174
|
-
const RULE_NAME$11 = "no-useless-fragment";
|
|
4175
|
-
const defaultOptions$1 = [{
|
|
4176
|
-
allowEmptyFragment: false,
|
|
4177
|
-
allowExpressions: true
|
|
4178
|
-
}];
|
|
4179
|
-
const schema$1 = [{
|
|
4180
|
-
type: "object",
|
|
4181
|
-
additionalProperties: false,
|
|
4182
|
-
properties: {
|
|
4183
|
-
allowEmptyFragment: {
|
|
4184
|
-
type: "boolean",
|
|
4185
|
-
description: "Allow empty fragments"
|
|
4186
|
-
},
|
|
4187
|
-
allowExpressions: {
|
|
4188
|
-
type: "boolean",
|
|
4189
|
-
description: "Allow fragments with a single expression child"
|
|
4190
|
-
}
|
|
4191
|
-
}
|
|
4192
|
-
}];
|
|
4193
|
-
var no_useless_fragment_default = createRule({
|
|
4194
|
-
meta: {
|
|
4195
|
-
type: "suggestion",
|
|
4196
|
-
defaultOptions: [...defaultOptions$1],
|
|
4197
|
-
docs: { description: "Disallows useless fragment elements." },
|
|
4198
|
-
fixable: "code",
|
|
4199
|
-
messages: { default: "A fragment {{reason}} is useless." },
|
|
4200
|
-
schema: schema$1
|
|
4201
|
-
},
|
|
4202
|
-
name: RULE_NAME$11,
|
|
4203
|
-
create: create$11,
|
|
4204
|
-
defaultOptions: defaultOptions$1
|
|
4205
|
-
});
|
|
4206
|
-
function create$11(context, [option]) {
|
|
4207
|
-
const { allowEmptyFragment = false, allowExpressions = true } = option;
|
|
4208
|
-
const jsx = JsxInspector.from(context);
|
|
4209
|
-
/**
|
|
4210
|
-
* Check if a fragment node is useless and should be reported
|
|
4211
|
-
*/
|
|
4212
|
-
function checkNode(context, node) {
|
|
4213
|
-
if (jsx.isHostElement(node.parent)) context.report({
|
|
4214
|
-
data: { reason: "placed inside a host component" },
|
|
4215
|
-
fix: getFix(context, node),
|
|
4216
|
-
messageId: "default",
|
|
4217
|
-
node
|
|
4218
|
-
});
|
|
4219
|
-
if (node.children.length === 0) {
|
|
4220
|
-
if (allowEmptyFragment) return;
|
|
4221
|
-
context.report({
|
|
4222
|
-
data: { reason: "contains less than two children" },
|
|
4223
|
-
fix: getFix(context, node),
|
|
4224
|
-
messageId: "default",
|
|
4225
|
-
node
|
|
4226
|
-
});
|
|
4227
|
-
return;
|
|
4228
|
-
}
|
|
4229
|
-
const isChildElement = ast.isOneOf([AST_NODE_TYPES.JSXElement, AST_NODE_TYPES.JSXFragment])(node.parent);
|
|
4230
|
-
switch (true) {
|
|
4231
|
-
case allowExpressions && !isChildElement && node.children.length === 1 && JsxInspector.isJsxText(node.children.at(0) ?? null): return;
|
|
4232
|
-
case !allowExpressions && isChildElement:
|
|
4233
|
-
context.report({
|
|
4234
|
-
data: { reason: "contains less than two children" },
|
|
4235
|
-
fix: getFix(context, node),
|
|
4236
|
-
messageId: "default",
|
|
4237
|
-
node
|
|
4238
|
-
});
|
|
4239
|
-
return;
|
|
4240
|
-
case !allowExpressions && !isChildElement && node.children.length === 1:
|
|
4241
|
-
context.report({
|
|
4242
|
-
data: { reason: "contains less than two children" },
|
|
4243
|
-
fix: getFix(context, node),
|
|
4244
|
-
messageId: "default",
|
|
4245
|
-
node
|
|
4246
|
-
});
|
|
4247
|
-
return;
|
|
4248
|
-
}
|
|
4249
|
-
const nonPaddingChildren = node.children.filter((child) => !isPaddingSpaces(child));
|
|
4250
|
-
const firstNonPaddingChild = nonPaddingChildren.at(0);
|
|
4251
|
-
if (nonPaddingChildren.length === 0 || nonPaddingChildren.length === 1 && firstNonPaddingChild?.type !== AST_NODE_TYPES.JSXExpressionContainer) context.report({
|
|
4252
|
-
data: { reason: "contains less than two children" },
|
|
4253
|
-
fix: getFix(context, node),
|
|
4254
|
-
messageId: "default",
|
|
4255
|
-
node
|
|
4256
|
-
});
|
|
4257
|
-
}
|
|
4258
|
-
function getFix(context, node) {
|
|
4259
|
-
if (!canFix(context, node)) return null;
|
|
4260
|
-
return (fixer) => {
|
|
4261
|
-
const opener = node.type === AST_NODE_TYPES.JSXFragment ? node.openingFragment : node.openingElement;
|
|
4262
|
-
const closer = node.type === AST_NODE_TYPES.JSXFragment ? node.closingFragment : node.closingElement;
|
|
4263
|
-
const childrenText = opener.type === AST_NODE_TYPES.JSXOpeningElement && opener.selfClosing ? "" : context.sourceCode.getText().slice(opener.range[1], closer?.range[0]);
|
|
4264
|
-
return fixer.replaceText(node, trimLikeReact(childrenText));
|
|
4265
|
-
};
|
|
4266
|
-
}
|
|
4267
|
-
/**
|
|
4268
|
-
* Check if it's safe to automatically fix the fragment
|
|
4269
|
-
*/
|
|
4270
|
-
function canFix(context, node) {
|
|
4271
|
-
if (node.parent.type === AST_NODE_TYPES.JSXElement || node.parent.type === AST_NODE_TYPES.JSXFragment) return jsx.isHostElement(node.parent);
|
|
4272
|
-
if (node.children.length === 0) return false;
|
|
4273
|
-
return !node.children.some((child) => JsxInspector.isJsxText(child) && !isWhiteSpace(child) || ast.is(AST_NODE_TYPES.JSXExpressionContainer)(child));
|
|
4274
|
-
}
|
|
4275
|
-
return defineRuleListener({
|
|
4276
|
-
JSXElement(node) {
|
|
4277
|
-
if (!jsx.isFragmentElement(node)) return;
|
|
4278
|
-
if (jsx.hasAttribute(node, "key")) return;
|
|
4279
|
-
if (jsx.hasAttribute(node, "ref")) return;
|
|
4280
|
-
checkNode(context, node);
|
|
4281
|
-
},
|
|
4282
|
-
JSXFragment(node) {
|
|
4283
|
-
checkNode(context, node);
|
|
4284
|
-
}
|
|
4285
|
-
});
|
|
4286
|
-
}
|
|
4287
|
-
/**
|
|
4288
|
-
* Check if a Literal or JSXText node is whitespace
|
|
4289
|
-
*/
|
|
4290
|
-
function isWhiteSpace(node) {
|
|
4291
|
-
return typeof node.value === "string" && node.raw.trim() === "";
|
|
4292
|
-
}
|
|
4293
|
-
/**
|
|
4294
|
-
* Check if a node is padding spaces (whitespace with line breaks)
|
|
4295
|
-
*/
|
|
4296
|
-
function isPaddingSpaces(node) {
|
|
4297
|
-
return JsxInspector.isJsxText(node) && isWhiteSpace(node) && node.raw.includes("\n");
|
|
4298
|
-
}
|
|
4299
|
-
/**
|
|
4300
|
-
* Trim whitespace like React would in JSX
|
|
4301
|
-
*/
|
|
4302
|
-
function trimLikeReact(text) {
|
|
4303
|
-
const leadingSpaces = /^\s*/.exec(text)?.[0] ?? "";
|
|
4304
|
-
const trailingSpaces = /\s*$/.exec(text)?.[0] ?? "";
|
|
4305
|
-
const start = leadingSpaces.includes("\n") ? leadingSpaces.length : 0;
|
|
4306
|
-
const end = trailingSpaces.includes("\n") ? text.length - trailingSpaces.length : text.length;
|
|
4307
|
-
return text.slice(start, end);
|
|
4308
|
-
}
|
|
4309
|
-
|
|
4310
3923
|
//#endregion
|
|
4311
3924
|
//#region src/rules/prefer-destructuring-assignment/prefer-destructuring-assignment.ts
|
|
4312
3925
|
const RULE_NAME$10 = "prefer-destructuring-assignment";
|
|
@@ -4322,9 +3935,9 @@ var prefer_destructuring_assignment_default = createRule({
|
|
|
4322
3935
|
defaultOptions: []
|
|
4323
3936
|
});
|
|
4324
3937
|
function create$10(context) {
|
|
4325
|
-
const {
|
|
3938
|
+
const { api, visitor } = core.getComponentCollector(context);
|
|
4326
3939
|
return defineRuleListener(visitor, { "Program:exit"(program) {
|
|
4327
|
-
for (const component of
|
|
3940
|
+
for (const component of api.getAllComponents(program)) {
|
|
4328
3941
|
if (component.name == null || component.isExportDefaultDeclaration) continue;
|
|
4329
3942
|
const [props] = component.node.params;
|
|
4330
3943
|
if (props == null) continue;
|
|
@@ -4395,8 +4008,8 @@ var purity_default = createRule({
|
|
|
4395
4008
|
defaultOptions: []
|
|
4396
4009
|
});
|
|
4397
4010
|
function create$8(context) {
|
|
4398
|
-
const hCollector = core.
|
|
4399
|
-
const cCollector = core.
|
|
4011
|
+
const hCollector = core.getHookCollector(context);
|
|
4012
|
+
const cCollector = core.getComponentCollector(context);
|
|
4400
4013
|
const cEntries = [];
|
|
4401
4014
|
const nEntries = [];
|
|
4402
4015
|
return defineRuleListener(hCollector.visitor, cCollector.visitor, {
|
|
@@ -4405,7 +4018,7 @@ function create$8(context) {
|
|
|
4405
4018
|
switch (true) {
|
|
4406
4019
|
case expr.type === AST_NODE_TYPES.Identifier: {
|
|
4407
4020
|
if (!IMPURE_FUNCS.get("globalThis")?.has(expr.name)) return;
|
|
4408
|
-
const func = ast.
|
|
4021
|
+
const func = ast.findParent(node, ast.isFunction);
|
|
4409
4022
|
if (func == null) return;
|
|
4410
4023
|
cEntries.push({
|
|
4411
4024
|
func,
|
|
@@ -4417,7 +4030,7 @@ function create$8(context) {
|
|
|
4417
4030
|
const objectName = expr.object.name;
|
|
4418
4031
|
const propertyName = expr.property.name;
|
|
4419
4032
|
if (!IMPURE_FUNCS.get(objectName)?.has(propertyName)) return;
|
|
4420
|
-
const func = ast.
|
|
4033
|
+
const func = ast.findParent(node, ast.isFunction);
|
|
4421
4034
|
if (func == null) return;
|
|
4422
4035
|
cEntries.push({
|
|
4423
4036
|
func,
|
|
@@ -4431,7 +4044,7 @@ function create$8(context) {
|
|
|
4431
4044
|
const expr = ast.getUnderlyingExpression(node.callee);
|
|
4432
4045
|
if (expr.type !== AST_NODE_TYPES.Identifier) return;
|
|
4433
4046
|
if (!IMPURE_CTORS.has(expr.name)) return;
|
|
4434
|
-
const func = ast.
|
|
4047
|
+
const func = ast.findParent(node, ast.isFunction);
|
|
4435
4048
|
if (func == null) return;
|
|
4436
4049
|
nEntries.push({
|
|
4437
4050
|
func,
|
|
@@ -4439,8 +4052,8 @@ function create$8(context) {
|
|
|
4439
4052
|
});
|
|
4440
4053
|
},
|
|
4441
4054
|
"Program:exit"(node) {
|
|
4442
|
-
const comps = cCollector.
|
|
4443
|
-
const hooks = hCollector.
|
|
4055
|
+
const comps = cCollector.api.getAllComponents(node);
|
|
4056
|
+
const hooks = hCollector.api.getAllHooks(node);
|
|
4444
4057
|
const funcs = [...comps, ...hooks];
|
|
4445
4058
|
for (const { func, node } of [...cEntries, ...nEntries]) {
|
|
4446
4059
|
if (!funcs.some((f) => f.node === func)) continue;
|
|
@@ -4472,8 +4085,8 @@ var refs_default = createRule({
|
|
|
4472
4085
|
defaultOptions: []
|
|
4473
4086
|
});
|
|
4474
4087
|
function create$7(context) {
|
|
4475
|
-
const hCollector = core.
|
|
4476
|
-
const cCollector = core.
|
|
4088
|
+
const hCollector = core.getHookCollector(context);
|
|
4089
|
+
const cCollector = core.getComponentCollector(context);
|
|
4477
4090
|
const refAccesses = [];
|
|
4478
4091
|
const jsxRefIdentifiers = /* @__PURE__ */ new Set();
|
|
4479
4092
|
/**
|
|
@@ -4509,6 +4122,18 @@ function create$7(context) {
|
|
|
4509
4122
|
};
|
|
4510
4123
|
return checkSides(left, right) || checkSides(right, left);
|
|
4511
4124
|
}
|
|
4125
|
+
function isInitializedFromRef(name, initialScope) {
|
|
4126
|
+
for (const { node } of findVariable(initialScope, name)?.defs ?? []) {
|
|
4127
|
+
if (node.type !== AST_NODE_TYPES.VariableDeclarator) continue;
|
|
4128
|
+
const init = node.init;
|
|
4129
|
+
if (init == null) continue;
|
|
4130
|
+
switch (true) {
|
|
4131
|
+
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;
|
|
4132
|
+
case init.type === AST_NODE_TYPES.CallExpression && isUseRefCall(init): return true;
|
|
4133
|
+
}
|
|
4134
|
+
}
|
|
4135
|
+
return false;
|
|
4136
|
+
}
|
|
4512
4137
|
return defineRuleListener(hCollector.visitor, cCollector.visitor, {
|
|
4513
4138
|
JSXAttribute(node) {
|
|
4514
4139
|
switch (true) {
|
|
@@ -4529,22 +4154,22 @@ function create$7(context) {
|
|
|
4529
4154
|
});
|
|
4530
4155
|
},
|
|
4531
4156
|
"Program:exit"(program) {
|
|
4532
|
-
const comps = cCollector.
|
|
4533
|
-
const hooks = hCollector.
|
|
4157
|
+
const comps = cCollector.api.getAllComponents(program);
|
|
4158
|
+
const hooks = hCollector.api.getAllHooks(program);
|
|
4534
4159
|
const funcs = new Set([...comps.map((c) => c.node), ...hooks.map((h) => h.node)]);
|
|
4535
4160
|
const isCompOrHookFn = (n) => ast.isFunction(n) && funcs.has(n);
|
|
4536
4161
|
for (const { isWrite, node } of refAccesses) {
|
|
4537
4162
|
const obj = node.object;
|
|
4538
4163
|
if (obj.type !== AST_NODE_TYPES.Identifier) continue;
|
|
4539
4164
|
switch (true) {
|
|
4540
|
-
case
|
|
4165
|
+
case obj.name === "ref" || obj.name.endsWith("Ref"):
|
|
4541
4166
|
case jsxRefIdentifiers.has(obj.name):
|
|
4542
|
-
case
|
|
4167
|
+
case isInitializedFromRef(obj.name, context.sourceCode.getScope(node.object)): break;
|
|
4543
4168
|
default: continue;
|
|
4544
4169
|
}
|
|
4545
|
-
const boundary = ast.
|
|
4170
|
+
const boundary = ast.findParent(node, isCompOrHookFn);
|
|
4546
4171
|
if (boundary == null) continue;
|
|
4547
|
-
if (ast.
|
|
4172
|
+
if (ast.findParent(node, ast.isFunction) !== boundary) continue;
|
|
4548
4173
|
const refName = obj.name;
|
|
4549
4174
|
let isLazyInit = isInNullCheckTest(node);
|
|
4550
4175
|
if (!isLazyInit) {
|
|
@@ -6790,7 +6415,7 @@ function create$6(context) {
|
|
|
6790
6415
|
return match(node).when(isUseStateCall, () => "useState").when(isUseEffectCall, () => "useEffect").when(isSetStateCall, () => "setState").when(isThenCall, () => "then").otherwise(() => "other");
|
|
6791
6416
|
}
|
|
6792
6417
|
function getFunctionKind(node) {
|
|
6793
|
-
const parent = ast.
|
|
6418
|
+
const parent = ast.findParent(node, not(ast.isTypeExpression)) ?? node.parent;
|
|
6794
6419
|
switch (true) {
|
|
6795
6420
|
case node.async:
|
|
6796
6421
|
case parent.type === AST_NODE_TYPES.CallExpression && isThenCall(parent): return "deferred";
|
|
@@ -6839,6 +6464,18 @@ function create$6(context) {
|
|
|
6839
6464
|
default: return false;
|
|
6840
6465
|
}
|
|
6841
6466
|
}
|
|
6467
|
+
function isInitializedFromRef(name, initialScope) {
|
|
6468
|
+
for (const { node } of findVariable(initialScope, name)?.defs ?? []) {
|
|
6469
|
+
if (node.type !== AST_NODE_TYPES.VariableDeclarator) continue;
|
|
6470
|
+
const init = node.init;
|
|
6471
|
+
if (init == null) continue;
|
|
6472
|
+
switch (true) {
|
|
6473
|
+
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;
|
|
6474
|
+
case init.type === AST_NODE_TYPES.CallExpression && isUseRefCall(init): return true;
|
|
6475
|
+
}
|
|
6476
|
+
}
|
|
6477
|
+
return false;
|
|
6478
|
+
}
|
|
6842
6479
|
return defineRuleListener({
|
|
6843
6480
|
":function"(node) {
|
|
6844
6481
|
const kind = getFunctionKind(node);
|
|
@@ -6862,13 +6499,13 @@ function create$6(context) {
|
|
|
6862
6499
|
case entry.kind === "deferred":
|
|
6863
6500
|
case entry.node.async: break;
|
|
6864
6501
|
case entry.node === setupFunction:
|
|
6865
|
-
case entry.kind === "immediate" && ast.
|
|
6502
|
+
case entry.kind === "immediate" && ast.findParent(entry.node, ast.isFunction) === setupFunction: {
|
|
6866
6503
|
const args0 = node.arguments.at(0);
|
|
6867
6504
|
if (args0 == null) return;
|
|
6868
6505
|
function isArgumentUsingRefValue(context, node) {
|
|
6869
6506
|
const isUsingRefValue = (n) => {
|
|
6870
6507
|
switch (n.type) {
|
|
6871
|
-
case AST_NODE_TYPES.Identifier: return
|
|
6508
|
+
case AST_NODE_TYPES.Identifier: return isInitializedFromRef(n.name, context.sourceCode.getScope(n));
|
|
6872
6509
|
case AST_NODE_TYPES.MemberExpression: return isUsingRefValue(n.object);
|
|
6873
6510
|
case AST_NODE_TYPES.CallExpression: return isUsingRefValue(n.callee) || ast.getNestedIdentifiers(n).some(isUsingRefValue);
|
|
6874
6511
|
default: return false;
|
|
@@ -6886,7 +6523,7 @@ function create$6(context) {
|
|
|
6886
6523
|
return;
|
|
6887
6524
|
}
|
|
6888
6525
|
default: {
|
|
6889
|
-
const init = ast.
|
|
6526
|
+
const init = ast.findParent(node, isHookDecl)?.init;
|
|
6890
6527
|
if (init == null) getOrElseUpdate(setStateCallsByFn, entry.node, () => []).push(node);
|
|
6891
6528
|
else getOrElseUpdate(setStateInHookCallbacks, init, () => []).push(node);
|
|
6892
6529
|
}
|
|
@@ -6907,14 +6544,14 @@ function create$6(context) {
|
|
|
6907
6544
|
const parent = node.parent.parent;
|
|
6908
6545
|
if (parent.type !== AST_NODE_TYPES.CallExpression) break;
|
|
6909
6546
|
if (!core.isUseMemoCall(parent)) break;
|
|
6910
|
-
const init = ast.
|
|
6547
|
+
const init = ast.findParent(parent, isHookDecl)?.init;
|
|
6911
6548
|
if (init != null) getOrElseUpdate(setStateInEffectArg, init, () => []).push(node);
|
|
6912
6549
|
break;
|
|
6913
6550
|
}
|
|
6914
6551
|
case AST_NODE_TYPES.CallExpression:
|
|
6915
6552
|
if (node !== node.parent.arguments.at(0)) break;
|
|
6916
6553
|
if (core.isUseCallbackCall(node.parent)) {
|
|
6917
|
-
const init = ast.
|
|
6554
|
+
const init = ast.findParent(node.parent, isHookDecl)?.init;
|
|
6918
6555
|
if (init != null) getOrElseUpdate(setStateInEffectArg, init, () => []).push(node);
|
|
6919
6556
|
break;
|
|
6920
6557
|
}
|
|
@@ -7041,7 +6678,7 @@ function create$5(context) {
|
|
|
7041
6678
|
}
|
|
7042
6679
|
function getFunctionKind(node) {
|
|
7043
6680
|
if (isComponentOrHookLikeFunction(node)) return "component";
|
|
7044
|
-
const parent = ast.
|
|
6681
|
+
const parent = ast.findParent(node, not(ast.isTypeExpression)) ?? node.parent;
|
|
7045
6682
|
if (parent.type === AST_NODE_TYPES.CallExpression && parent.callee !== node) return "callback";
|
|
7046
6683
|
return "other";
|
|
7047
6684
|
}
|
|
@@ -7120,14 +6757,14 @@ function isIifeCall(node) {
|
|
|
7120
6757
|
return node.parent.type === AST_NODE_TYPES.CallExpression && node.parent.callee === node;
|
|
7121
6758
|
}
|
|
7122
6759
|
function create$4(context) {
|
|
7123
|
-
const hCollector = core.
|
|
7124
|
-
const cCollector = core.
|
|
6760
|
+
const hCollector = core.getHookCollector(context);
|
|
6761
|
+
const cCollector = core.getComponentCollector(context);
|
|
7125
6762
|
const evalCalls = [];
|
|
7126
6763
|
const withStmts = [];
|
|
7127
6764
|
return defineRuleListener(hCollector.visitor, cCollector.visitor, {
|
|
7128
6765
|
CallExpression(node) {
|
|
7129
6766
|
if (!isEvalCall(node)) return;
|
|
7130
|
-
const func = ast.
|
|
6767
|
+
const func = ast.findParent(node, ast.isFunction);
|
|
7131
6768
|
if (func == null) return;
|
|
7132
6769
|
evalCalls.push({
|
|
7133
6770
|
func,
|
|
@@ -7147,8 +6784,8 @@ function create$4(context) {
|
|
|
7147
6784
|
});
|
|
7148
6785
|
},
|
|
7149
6786
|
"Program:exit"(node) {
|
|
7150
|
-
const components = cCollector.
|
|
7151
|
-
const hooks = hCollector.
|
|
6787
|
+
const components = cCollector.api.getAllComponents(node);
|
|
6788
|
+
const hooks = hCollector.api.getAllHooks(node);
|
|
7152
6789
|
const funcs = [...components, ...hooks];
|
|
7153
6790
|
for (const { func, node } of evalCalls) {
|
|
7154
6791
|
if (!funcs.some((f) => f.node === func)) continue;
|
|
@@ -7166,7 +6803,7 @@ function create$4(context) {
|
|
|
7166
6803
|
}
|
|
7167
6804
|
},
|
|
7168
6805
|
WithStatement(node) {
|
|
7169
|
-
const func = ast.
|
|
6806
|
+
const func = ast.findParent(node, ast.isFunction);
|
|
7170
6807
|
if (func == null) return;
|
|
7171
6808
|
withStmts.push({
|
|
7172
6809
|
func,
|
|
@@ -7283,7 +6920,7 @@ function create$2(context) {
|
|
|
7283
6920
|
for (const expr of ast.getNestedNewExpressions(useStateInput)) {
|
|
7284
6921
|
if (!("name" in expr.callee)) continue;
|
|
7285
6922
|
if (LAZY_INIT_ALLOW_LIST.includes(expr.callee.name)) continue;
|
|
7286
|
-
if (ast.
|
|
6923
|
+
if (ast.findParent(expr, core.isUseCall) != null) continue;
|
|
7287
6924
|
context.report({
|
|
7288
6925
|
messageId: "invalidInitialization",
|
|
7289
6926
|
node: expr
|
|
@@ -7293,7 +6930,7 @@ function create$2(context) {
|
|
|
7293
6930
|
if (!("name" in expr.callee)) continue;
|
|
7294
6931
|
if (core.isHookName(expr.callee.name)) continue;
|
|
7295
6932
|
if (LAZY_INIT_ALLOW_LIST.includes(expr.callee.name)) continue;
|
|
7296
|
-
if (ast.
|
|
6933
|
+
if (ast.findParent(expr, core.isUseCall) != null) continue;
|
|
7297
6934
|
context.report({
|
|
7298
6935
|
messageId: "invalidInitialization",
|
|
7299
6936
|
node: expr
|
|
@@ -7479,18 +7116,12 @@ const plugin = {
|
|
|
7479
7116
|
"error-boundaries": error_boundaries_default,
|
|
7480
7117
|
"exhaustive-deps": rule$1,
|
|
7481
7118
|
immutability: immutability_default,
|
|
7482
|
-
"jsx-dollar": jsx_dollar_default,
|
|
7483
|
-
"jsx-key-before-spread": jsx_key_before_spread_default,
|
|
7484
|
-
"jsx-no-comment-textnodes": jsx_no_comment_textnodes_default,
|
|
7485
|
-
"jsx-shorthand-boolean": jsx_shorthand_boolean_default,
|
|
7486
|
-
"jsx-shorthand-fragment": jsx_shorthand_fragment_default,
|
|
7487
7119
|
"no-access-state-in-setstate": no_access_state_in_setstate_default,
|
|
7488
7120
|
"no-array-index-key": no_array_index_key_default,
|
|
7489
7121
|
"no-children-count": no_children_count_default,
|
|
7490
7122
|
"no-children-for-each": no_children_for_each_default,
|
|
7491
7123
|
"no-children-map": no_children_map_default,
|
|
7492
7124
|
"no-children-only": no_children_only_default,
|
|
7493
|
-
"no-children-prop": no_children_prop_default,
|
|
7494
7125
|
"no-children-to-array": no_children_to_array_default,
|
|
7495
7126
|
"no-class-component": no_class_component_default,
|
|
7496
7127
|
"no-clone-element": no_clone_element_default,
|
|
@@ -7528,7 +7159,6 @@ const plugin = {
|
|
|
7528
7159
|
"no-unused-props": no_unused_props_default,
|
|
7529
7160
|
"no-unused-state": no_unused_state_default,
|
|
7530
7161
|
"no-use-context": no_use_context_default,
|
|
7531
|
-
"no-useless-fragment": no_useless_fragment_default,
|
|
7532
7162
|
"prefer-destructuring-assignment": prefer_destructuring_assignment_default,
|
|
7533
7163
|
"prefer-namespace-import": prefer_namespace_import_default,
|
|
7534
7164
|
purity: purity_default,
|
|
@@ -7557,8 +7187,6 @@ const rules$6 = {
|
|
|
7557
7187
|
"react-x/component-hook-factories": "error",
|
|
7558
7188
|
"react-x/error-boundaries": "error",
|
|
7559
7189
|
"react-x/exhaustive-deps": "warn",
|
|
7560
|
-
"react-x/jsx-key-before-spread": "warn",
|
|
7561
|
-
"react-x/jsx-no-comment-textnodes": "warn",
|
|
7562
7190
|
"react-x/no-access-state-in-setstate": "error",
|
|
7563
7191
|
"react-x/no-array-index-key": "warn",
|
|
7564
7192
|
"react-x/no-children-count": "warn",
|
|
@@ -7648,7 +7276,6 @@ var strict_exports = /* @__PURE__ */ __exportAll({
|
|
|
7648
7276
|
const name$2 = "react-x/strict";
|
|
7649
7277
|
const rules$2 = {
|
|
7650
7278
|
...rules$6,
|
|
7651
|
-
"react-x/no-children-prop": "error",
|
|
7652
7279
|
"react-x/no-class-component": "error",
|
|
7653
7280
|
"react-x/no-misused-capture-owner-stack": "error",
|
|
7654
7281
|
"react-x/no-unnecessary-use-callback": "warn",
|
|
@@ -7656,7 +7283,6 @@ const rules$2 = {
|
|
|
7656
7283
|
"react-x/no-unstable-context-value": "warn",
|
|
7657
7284
|
"react-x/no-unstable-default-props": "warn",
|
|
7658
7285
|
"react-x/no-unused-state": "warn",
|
|
7659
|
-
"react-x/no-useless-fragment": "warn",
|
|
7660
7286
|
"react-x/prefer-destructuring-assignment": "warn"
|
|
7661
7287
|
};
|
|
7662
7288
|
const plugins$2 = { ...plugins$5 };
|