eslint-plugin-react-x 2.0.0-beta.177 → 2.0.0-beta.179
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/dist/index.js +44 -50
- package/package.json +7 -7
package/dist/index.js
CHANGED
|
@@ -5,28 +5,29 @@ import * as AST from "@eslint-react/ast";
|
|
|
5
5
|
import * as VAR from "@eslint-react/var";
|
|
6
6
|
import { P, isMatching, match } from "ts-pattern";
|
|
7
7
|
import * as ER from "@eslint-react/core";
|
|
8
|
-
import {
|
|
8
|
+
import { SEL_DISPLAY_NAME_ASSIGNMENT_EXPRESSION, SEL_OBJECT_DESTRUCTURING_VARIABLE_DECLARATOR, isProcessEnvNodeEnvCompare, isViMockCallback, report, toRegExp } from "@eslint-react/kit";
|
|
9
9
|
import { constFalse, constTrue, flow, getOrElseUpdate, identity, unit } from "@eslint-react/eff";
|
|
10
10
|
import { compare } from "compare-versions";
|
|
11
11
|
import { camelCase } from "string-ts";
|
|
12
12
|
import { getConstrainedTypeAtLocation, isTypeReadonly } from "@typescript-eslint/type-utils";
|
|
13
|
-
import { unionConstituents } from "ts-api-utils";
|
|
14
13
|
import { getStaticValue } from "@typescript-eslint/utils/ast-utils";
|
|
14
|
+
import { unionConstituents } from "ts-api-utils";
|
|
15
15
|
import { getTypeImmutability, isImmutable, isReadonlyDeep, isReadonlyShallow, isUnknown } from "is-immutable-type";
|
|
16
16
|
|
|
17
17
|
//#region rolldown:runtime
|
|
18
18
|
var __defProp = Object.defineProperty;
|
|
19
|
-
var __export = (
|
|
19
|
+
var __export = (all) => {
|
|
20
|
+
let target = {};
|
|
20
21
|
for (var name$4 in all) __defProp(target, name$4, {
|
|
21
22
|
get: all[name$4],
|
|
22
23
|
enumerable: true
|
|
23
24
|
});
|
|
25
|
+
return target;
|
|
24
26
|
};
|
|
25
27
|
|
|
26
28
|
//#endregion
|
|
27
29
|
//#region src/configs/recommended.ts
|
|
28
|
-
var recommended_exports = {
|
|
29
|
-
__export(recommended_exports, {
|
|
30
|
+
var recommended_exports = __export({
|
|
30
31
|
name: () => name$3,
|
|
31
32
|
rules: () => rules$2,
|
|
32
33
|
settings: () => settings$2
|
|
@@ -80,8 +81,7 @@ const settings$2 = { "react-x": DEFAULT_ESLINT_REACT_SETTINGS };
|
|
|
80
81
|
|
|
81
82
|
//#endregion
|
|
82
83
|
//#region src/configs/recommended-typescript.ts
|
|
83
|
-
var recommended_typescript_exports = {
|
|
84
|
-
__export(recommended_typescript_exports, {
|
|
84
|
+
var recommended_typescript_exports = __export({
|
|
85
85
|
name: () => name$2,
|
|
86
86
|
rules: () => rules$1,
|
|
87
87
|
settings: () => settings$1
|
|
@@ -98,8 +98,7 @@ const settings$1 = { ...settings$2 };
|
|
|
98
98
|
|
|
99
99
|
//#endregion
|
|
100
100
|
//#region src/configs/recommended-type-checked.ts
|
|
101
|
-
var recommended_type_checked_exports = {
|
|
102
|
-
__export(recommended_type_checked_exports, {
|
|
101
|
+
var recommended_type_checked_exports = __export({
|
|
103
102
|
name: () => name$1,
|
|
104
103
|
rules: () => rules,
|
|
105
104
|
settings: () => settings
|
|
@@ -115,7 +114,7 @@ const settings = { ...settings$1 };
|
|
|
115
114
|
//#endregion
|
|
116
115
|
//#region package.json
|
|
117
116
|
var name = "eslint-plugin-react-x";
|
|
118
|
-
var version = "2.0.0-beta.
|
|
117
|
+
var version = "2.0.0-beta.179";
|
|
119
118
|
|
|
120
119
|
//#endregion
|
|
121
120
|
//#region src/utils/create-rule.ts
|
|
@@ -379,8 +378,8 @@ var jsx_shorthand_fragment_default = createRule({
|
|
|
379
378
|
function create$55(context) {
|
|
380
379
|
const policy = context.options[0] ?? defaultOptions$2[0];
|
|
381
380
|
const { jsxFragmentFactory } = {
|
|
382
|
-
...
|
|
383
|
-
...
|
|
381
|
+
...ER.getJsxConfigFromContext(context),
|
|
382
|
+
...ER.getJsxConfigFromAnnotation(context)
|
|
384
383
|
};
|
|
385
384
|
return match(policy).with(1, () => ({ JSXElement(node) {
|
|
386
385
|
if (!ER.isFragmentElement(context, node)) return;
|
|
@@ -410,7 +409,7 @@ function create$55(context) {
|
|
|
410
409
|
|
|
411
410
|
//#endregion
|
|
412
411
|
//#region src/rules/jsx-uses-react.ts
|
|
413
|
-
const
|
|
412
|
+
const JsxEmit = ER.JsxEmit;
|
|
414
413
|
const RULE_NAME$54 = "jsx-uses-react";
|
|
415
414
|
const RULE_FEATURES$52 = [];
|
|
416
415
|
var jsx_uses_react_default = createRule({
|
|
@@ -429,8 +428,8 @@ var jsx_uses_react_default = createRule({
|
|
|
429
428
|
});
|
|
430
429
|
function create$54(context) {
|
|
431
430
|
const { jsx, jsxFactory, jsxFragmentFactory } = {
|
|
432
|
-
...
|
|
433
|
-
...
|
|
431
|
+
...ER.getJsxConfigFromContext(context),
|
|
432
|
+
...ER.getJsxConfigFromAnnotation(context)
|
|
434
433
|
};
|
|
435
434
|
if (jsx === JsxEmit.ReactJSX || jsx === JsxEmit.ReactJSXDev) return {};
|
|
436
435
|
function handleJsxElement(node) {
|
|
@@ -636,7 +635,6 @@ var no_array_index_key_default = createRule({
|
|
|
636
635
|
defaultOptions: []
|
|
637
636
|
});
|
|
638
637
|
function create$51(context) {
|
|
639
|
-
const report = Reporter.make(context);
|
|
640
638
|
const indexParamNames = [];
|
|
641
639
|
function isArrayIndex(node) {
|
|
642
640
|
return node.type === AST_NODE_TYPES.Identifier && indexParamNames.some((name$4) => name$4 != null && name$4 === node.name);
|
|
@@ -685,7 +683,7 @@ function create$51(context) {
|
|
|
685
683
|
for (const prop of props.properties) {
|
|
686
684
|
if (!isMatching({ key: { name: "key" } })(prop)) continue;
|
|
687
685
|
if (!("value" in prop)) continue;
|
|
688
|
-
for (const descriptor of getReportDescriptors(prop.value)) report
|
|
686
|
+
for (const descriptor of getReportDescriptors(prop.value)) report(context)(descriptor);
|
|
689
687
|
}
|
|
690
688
|
},
|
|
691
689
|
"CallExpression:exit"() {
|
|
@@ -695,7 +693,7 @@ function create$51(context) {
|
|
|
695
693
|
if (node.name.name !== "key") return;
|
|
696
694
|
if (indexParamNames.length === 0) return;
|
|
697
695
|
if (node.value?.type !== AST_NODE_TYPES.JSXExpressionContainer) return;
|
|
698
|
-
for (const descriptor of getReportDescriptors(node.value.expression)) report
|
|
696
|
+
for (const descriptor of getReportDescriptors(node.value.expression)) report(context)(descriptor);
|
|
699
697
|
}
|
|
700
698
|
};
|
|
701
699
|
}
|
|
@@ -1329,7 +1327,7 @@ function create$34(context, [option]) {
|
|
|
1329
1327
|
if ("includedNodes" in forbiddenPropItem && !forbiddenPropItem.includedNodes.includes(nodeName)) continue;
|
|
1330
1328
|
}
|
|
1331
1329
|
const forbiddenProp = typeof forbiddenPropItem === "string" ? forbiddenPropItem : forbiddenPropItem.prop;
|
|
1332
|
-
if (
|
|
1330
|
+
if (toRegExp(forbiddenProp).test(name$4)) context.report({
|
|
1333
1331
|
messageId,
|
|
1334
1332
|
node: attr,
|
|
1335
1333
|
data: { name: name$4 }
|
|
@@ -1532,7 +1530,7 @@ function create$31(context) {
|
|
|
1532
1530
|
return match(variableDefNode).with({ init: P.select({ type: P.not(AST_NODE_TYPES.VariableDeclaration) }) }, getReportDescriptor).otherwise(() => unit);
|
|
1533
1531
|
}).otherwise(() => unit);
|
|
1534
1532
|
}
|
|
1535
|
-
return { JSXExpressionContainer: flow(getReportDescriptor,
|
|
1533
|
+
return { JSXExpressionContainer: flow(getReportDescriptor, report(context)) };
|
|
1536
1534
|
}
|
|
1537
1535
|
|
|
1538
1536
|
//#endregion
|
|
@@ -1623,30 +1621,27 @@ function create$29(context) {
|
|
|
1623
1621
|
if (left.type !== AST_NODE_TYPES.MemberExpression) return false;
|
|
1624
1622
|
const object = left.object;
|
|
1625
1623
|
return ER.isInstanceIdEqual(context, id, object);
|
|
1626
|
-
})) {
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
}
|
|
1645
|
-
});
|
|
1646
|
-
}
|
|
1624
|
+
})) context.report({
|
|
1625
|
+
messageId: "noMissingContextDisplayName",
|
|
1626
|
+
node: id,
|
|
1627
|
+
fix(fixer) {
|
|
1628
|
+
if (id.type !== AST_NODE_TYPES.Identifier || id.parent !== call.parent) return [];
|
|
1629
|
+
return fixer.insertTextAfter(context.sourceCode.getTokenAfter(call) ?? call, [
|
|
1630
|
+
"\n",
|
|
1631
|
+
id.name,
|
|
1632
|
+
".",
|
|
1633
|
+
"displayName",
|
|
1634
|
+
" ",
|
|
1635
|
+
"=",
|
|
1636
|
+
" ",
|
|
1637
|
+
JSON.stringify(id.name),
|
|
1638
|
+
";"
|
|
1639
|
+
].join(""));
|
|
1640
|
+
}
|
|
1641
|
+
});
|
|
1647
1642
|
}
|
|
1648
1643
|
},
|
|
1649
|
-
[
|
|
1644
|
+
[SEL_DISPLAY_NAME_ASSIGNMENT_EXPRESSION](node) {
|
|
1650
1645
|
displayNameAssignments.push(node);
|
|
1651
1646
|
}
|
|
1652
1647
|
};
|
|
@@ -1674,7 +1669,6 @@ var no_missing_key_default = createRule({
|
|
|
1674
1669
|
defaultOptions: []
|
|
1675
1670
|
});
|
|
1676
1671
|
function create$28(context) {
|
|
1677
|
-
const report = Reporter.make(context);
|
|
1678
1672
|
const state = { isWithinChildrenToArray: false };
|
|
1679
1673
|
function checkIteratorElement(node) {
|
|
1680
1674
|
switch (node.type) {
|
|
@@ -1721,7 +1715,7 @@ function create$28(context) {
|
|
|
1721
1715
|
const elements = node.elements.filter(AST.is(AST_NODE_TYPES.JSXElement));
|
|
1722
1716
|
if (elements.length === 0) return;
|
|
1723
1717
|
const initialScope = context.sourceCode.getScope(node);
|
|
1724
|
-
for (const element of elements) if (!ER.hasAttribute(context, "key", element.openingElement.attributes, initialScope)) report
|
|
1718
|
+
for (const element of elements) if (!ER.hasAttribute(context, "key", element.openingElement.attributes, initialScope)) context.report({
|
|
1725
1719
|
messageId: "missingKey",
|
|
1726
1720
|
node: element
|
|
1727
1721
|
});
|
|
@@ -1733,10 +1727,10 @@ function create$28(context) {
|
|
|
1733
1727
|
if (!AST.isFunction(callback)) return;
|
|
1734
1728
|
const body = callback.body;
|
|
1735
1729
|
if (body.type === AST_NODE_TYPES.BlockStatement) {
|
|
1736
|
-
checkBlockStatement(body).forEach(report
|
|
1730
|
+
checkBlockStatement(body).forEach(report(context));
|
|
1737
1731
|
return;
|
|
1738
1732
|
}
|
|
1739
|
-
report
|
|
1733
|
+
report(context)(checkExpression(body));
|
|
1740
1734
|
},
|
|
1741
1735
|
"CallExpression:exit"(node) {
|
|
1742
1736
|
if (!ER.isChildrenToArrayCall(context, node)) return;
|
|
@@ -1744,7 +1738,7 @@ function create$28(context) {
|
|
|
1744
1738
|
},
|
|
1745
1739
|
JSXFragment(node) {
|
|
1746
1740
|
if (state.isWithinChildrenToArray) return;
|
|
1747
|
-
if (node.parent.type === AST_NODE_TYPES.ArrayExpression) report
|
|
1741
|
+
if (node.parent.type === AST_NODE_TYPES.ArrayExpression) context.report({
|
|
1748
1742
|
messageId: "unexpectedFragmentSyntax",
|
|
1749
1743
|
node
|
|
1750
1744
|
});
|
|
@@ -1800,7 +1794,7 @@ function create$27(context) {
|
|
|
1800
1794
|
}
|
|
1801
1795
|
function isDevelopmentOnlyCheck(node) {
|
|
1802
1796
|
if (node.type !== AST_NODE_TYPES.IfStatement) return false;
|
|
1803
|
-
if (
|
|
1797
|
+
if (isProcessEnvNodeEnvCompare(node.test, "!==", "production")) return true;
|
|
1804
1798
|
return false;
|
|
1805
1799
|
}
|
|
1806
1800
|
|
|
@@ -2408,7 +2402,7 @@ function create$15(context) {
|
|
|
2408
2402
|
if (AST.isFunctionEmpty(node)) continue;
|
|
2409
2403
|
if (WELL_KNOWN_HOOKS.includes(name$4)) continue;
|
|
2410
2404
|
if (containsUseComments(context, node)) continue;
|
|
2411
|
-
if (AST.findParentNode(node,
|
|
2405
|
+
if (AST.findParentNode(node, isViMockCallback) != null) continue;
|
|
2412
2406
|
context.report({
|
|
2413
2407
|
messageId: "noUnnecessaryUsePrefix",
|
|
2414
2408
|
node: id ?? node,
|
|
@@ -2641,7 +2635,7 @@ function create$10(context) {
|
|
|
2641
2635
|
}
|
|
2642
2636
|
}
|
|
2643
2637
|
},
|
|
2644
|
-
[
|
|
2638
|
+
[SEL_OBJECT_DESTRUCTURING_VARIABLE_DECLARATOR](node) {
|
|
2645
2639
|
const functionEntry = ctx.getCurrentEntry();
|
|
2646
2640
|
if (functionEntry == null) return;
|
|
2647
2641
|
getOrElseUpdate(declarators, functionEntry.node, () => []).push(node);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-react-x",
|
|
3
|
-
"version": "2.0.0-beta.
|
|
3
|
+
"version": "2.0.0-beta.179",
|
|
4
4
|
"description": "A set of composable ESLint rules for for libraries and frameworks that use React as a UI runtime.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -42,12 +42,12 @@
|
|
|
42
42
|
"is-immutable-type": "^5.0.1",
|
|
43
43
|
"string-ts": "^2.2.1",
|
|
44
44
|
"ts-pattern": "^5.8.0",
|
|
45
|
-
"@eslint-react/ast": "2.0.0-beta.
|
|
46
|
-
"@eslint-react/core": "2.0.0-beta.
|
|
47
|
-
"@eslint-react/
|
|
48
|
-
"@eslint-react/
|
|
49
|
-
"@eslint-react/
|
|
50
|
-
"@eslint-react/
|
|
45
|
+
"@eslint-react/ast": "2.0.0-beta.179",
|
|
46
|
+
"@eslint-react/core": "2.0.0-beta.179",
|
|
47
|
+
"@eslint-react/kit": "2.0.0-beta.179",
|
|
48
|
+
"@eslint-react/shared": "2.0.0-beta.179",
|
|
49
|
+
"@eslint-react/var": "2.0.0-beta.179",
|
|
50
|
+
"@eslint-react/eff": "2.0.0-beta.179"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
53
|
"@types/react": "^19.1.12",
|