eslint-plugin-react-x 3.0.0-next.0 → 3.0.0-next.12
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 +702 -382
- package/package.json +10 -10
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DEFAULT_ESLINT_REACT_SETTINGS, WEBSITE_URL, coerceSettings, defineRuleListener, getConfigAdapters, getSettingsFromContext, report, toRegExp } from "@eslint-react/shared";
|
|
1
|
+
import { DEFAULT_ESLINT_REACT_SETTINGS, IMPURE_CONSTRUCTORS, IMPURE_FUNCTIONS, WEBSITE_URL, coerceSettings, defineRuleListener, getConfigAdapters, 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
4
|
import { ESLintUtils } from "@typescript-eslint/utils";
|
|
@@ -38,15 +38,17 @@ var disable_experimental_exports = /* @__PURE__ */ __exportAll({
|
|
|
38
38
|
});
|
|
39
39
|
const name$8 = "react-x/disable-experimental";
|
|
40
40
|
const rules$8 = {
|
|
41
|
+
"react-x/exhaustive-deps": "off",
|
|
41
42
|
"react-x/jsx-key-before-spread": "off",
|
|
42
|
-
"react-x/jsx-no-iife": "off",
|
|
43
43
|
"react-x/no-duplicate-key": "off",
|
|
44
44
|
"react-x/no-implicit-key": "off",
|
|
45
45
|
"react-x/no-misused-capture-owner-stack": "off",
|
|
46
46
|
"react-x/no-unnecessary-use-callback": "off",
|
|
47
47
|
"react-x/no-unnecessary-use-memo": "off",
|
|
48
48
|
"react-x/no-unused-props": "off",
|
|
49
|
-
"react-x/prefer-read-only-props": "off"
|
|
49
|
+
"react-x/prefer-read-only-props": "off",
|
|
50
|
+
"react-x/refs": "off",
|
|
51
|
+
"react-x/rules-of-hooks": "off"
|
|
50
52
|
};
|
|
51
53
|
|
|
52
54
|
//#endregion
|
|
@@ -66,7 +68,7 @@ const rules$7 = {
|
|
|
66
68
|
//#endregion
|
|
67
69
|
//#region package.json
|
|
68
70
|
var name$6 = "eslint-plugin-react-x";
|
|
69
|
-
var version = "3.0.0-next.
|
|
71
|
+
var version = "3.0.0-next.12";
|
|
70
72
|
|
|
71
73
|
//#endregion
|
|
72
74
|
//#region src/utils/create-rule.ts
|
|
@@ -136,7 +138,6 @@ function getFullyQualifiedNameEx(checker, symbol) {
|
|
|
136
138
|
let name = symbol.name;
|
|
137
139
|
let parent = symbol.declarations?.at(0)?.parent;
|
|
138
140
|
if (parent == null) return checker.getFullyQualifiedName(symbol);
|
|
139
|
-
const namespace = parent.getSourceFile().statements.find((n) => ts.isNamespaceExportDeclaration(n));
|
|
140
141
|
while (parent.kind !== ts.SyntaxKind.SourceFile) {
|
|
141
142
|
switch (true) {
|
|
142
143
|
case ts.isInterfaceDeclaration(parent):
|
|
@@ -168,11 +169,14 @@ function getFullyQualifiedNameEx(checker, symbol) {
|
|
|
168
169
|
case ts.isObjectLiteralExpression(parent):
|
|
169
170
|
case ts.isIntersectionTypeNode(parent):
|
|
170
171
|
case ts.isUnionTypeNode(parent): break;
|
|
172
|
+
default: break;
|
|
171
173
|
}
|
|
172
174
|
parent = parent.parent;
|
|
173
175
|
}
|
|
174
|
-
|
|
175
|
-
return name;
|
|
176
|
+
const namespace = parent.getSourceFile().statements.find((n) => ts.isNamespaceExportDeclaration(n))?.name.text;
|
|
177
|
+
if (namespace == null) return name;
|
|
178
|
+
if (name.startsWith(`${namespace}.`)) return name;
|
|
179
|
+
return `${namespace}.${name}`;
|
|
176
180
|
}
|
|
177
181
|
|
|
178
182
|
//#endregion
|
|
@@ -221,7 +225,7 @@ function getTypeVariants(types) {
|
|
|
221
225
|
|
|
222
226
|
//#endregion
|
|
223
227
|
//#region src/rules/component-hook-factories.ts
|
|
224
|
-
const RULE_NAME$
|
|
228
|
+
const RULE_NAME$65 = "component-hook-factories";
|
|
225
229
|
var component_hook_factories_default = createRule({
|
|
226
230
|
meta: {
|
|
227
231
|
type: "problem",
|
|
@@ -232,11 +236,11 @@ var component_hook_factories_default = createRule({
|
|
|
232
236
|
},
|
|
233
237
|
schema: []
|
|
234
238
|
},
|
|
235
|
-
name: RULE_NAME$
|
|
236
|
-
create: create$
|
|
239
|
+
name: RULE_NAME$65,
|
|
240
|
+
create: create$65,
|
|
237
241
|
defaultOptions: []
|
|
238
242
|
});
|
|
239
|
-
function create$
|
|
243
|
+
function create$65(context) {
|
|
240
244
|
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.DoNotIncludeFunctionDefinedInArrayPattern | core.ComponentDetectionHint.DoNotIncludeFunctionDefinedInArrayExpression | core.ComponentDetectionHint.DoNotIncludeFunctionDefinedAsArrayMapCallback;
|
|
241
245
|
const fCollector = core.useComponentCollector(context, { hint });
|
|
242
246
|
const cCollector = core.useComponentCollectorLegacy(context);
|
|
@@ -280,7 +284,7 @@ function create$63(context) {
|
|
|
280
284
|
|
|
281
285
|
//#endregion
|
|
282
286
|
//#region src/rules/error-boundaries.ts
|
|
283
|
-
const RULE_NAME$
|
|
287
|
+
const RULE_NAME$64 = "error-boundaries";
|
|
284
288
|
var error_boundaries_default = createRule({
|
|
285
289
|
meta: {
|
|
286
290
|
type: "problem",
|
|
@@ -291,11 +295,11 @@ var error_boundaries_default = createRule({
|
|
|
291
295
|
},
|
|
292
296
|
schema: []
|
|
293
297
|
},
|
|
294
|
-
name: RULE_NAME$
|
|
295
|
-
create: create$
|
|
298
|
+
name: RULE_NAME$64,
|
|
299
|
+
create: create$64,
|
|
296
300
|
defaultOptions: []
|
|
297
301
|
});
|
|
298
|
-
function create$
|
|
302
|
+
function create$64(context) {
|
|
299
303
|
if (!context.sourceCode.text.includes("try")) return {};
|
|
300
304
|
const { ctx, visitor } = core.useComponentCollector(context);
|
|
301
305
|
const reported = /* @__PURE__ */ new Set();
|
|
@@ -329,7 +333,7 @@ function create$62(context) {
|
|
|
329
333
|
|
|
330
334
|
//#endregion
|
|
331
335
|
//#region src/rules/exhaustive-deps.ts
|
|
332
|
-
const RULE_NAME$
|
|
336
|
+
const RULE_NAME$63 = "exhaustive-deps";
|
|
333
337
|
/**
|
|
334
338
|
* Built-in hooks that accept dependency arrays.
|
|
335
339
|
* Maps hook name to the index of the callback argument.
|
|
@@ -508,11 +512,11 @@ var exhaustive_deps_default = createRule({
|
|
|
508
512
|
properties: { additionalHooks: { type: "string" } }
|
|
509
513
|
}]
|
|
510
514
|
},
|
|
511
|
-
name: RULE_NAME$
|
|
512
|
-
create: create$
|
|
515
|
+
name: RULE_NAME$63,
|
|
516
|
+
create: create$63,
|
|
513
517
|
defaultOptions: [{}]
|
|
514
518
|
});
|
|
515
|
-
function create$
|
|
519
|
+
function create$63(context) {
|
|
516
520
|
const additionalHooks = context.options[0]?.additionalHooks;
|
|
517
521
|
const additionalHooksRegex = additionalHooks != null && additionalHooks.length > 0 ? new RegExp(additionalHooks) : null;
|
|
518
522
|
/** Collected hook calls for later analysis. */
|
|
@@ -692,7 +696,7 @@ function create$61(context) {
|
|
|
692
696
|
});
|
|
693
697
|
}
|
|
694
698
|
}
|
|
695
|
-
return {
|
|
699
|
+
return defineRuleListener({
|
|
696
700
|
CallExpression(node) {
|
|
697
701
|
if (!isHookWithDeps(node)) return;
|
|
698
702
|
const hookName = getHookName$1(node);
|
|
@@ -719,12 +723,12 @@ function create$61(context) {
|
|
|
719
723
|
"Program:exit"() {
|
|
720
724
|
for (const hookCall of collectedHookCalls) analyzeHookCall(hookCall);
|
|
721
725
|
}
|
|
722
|
-
};
|
|
726
|
+
});
|
|
723
727
|
}
|
|
724
728
|
|
|
725
729
|
//#endregion
|
|
726
730
|
//#region src/rules/jsx-dollar.ts
|
|
727
|
-
const RULE_NAME$
|
|
731
|
+
const RULE_NAME$62 = "jsx-dollar";
|
|
728
732
|
var jsx_dollar_default = createRule({
|
|
729
733
|
meta: {
|
|
730
734
|
type: "problem",
|
|
@@ -737,11 +741,11 @@ var jsx_dollar_default = createRule({
|
|
|
737
741
|
},
|
|
738
742
|
schema: []
|
|
739
743
|
},
|
|
740
|
-
name: RULE_NAME$
|
|
741
|
-
create: create$
|
|
744
|
+
name: RULE_NAME$62,
|
|
745
|
+
create: create$62,
|
|
742
746
|
defaultOptions: []
|
|
743
747
|
});
|
|
744
|
-
function create$
|
|
748
|
+
function create$62(context) {
|
|
745
749
|
/**
|
|
746
750
|
* Visitor function for JSXElement and JSXFragment nodes
|
|
747
751
|
* @param node The JSXElement or JSXFragment node to be checked
|
|
@@ -774,15 +778,15 @@ function create$60(context) {
|
|
|
774
778
|
});
|
|
775
779
|
}
|
|
776
780
|
};
|
|
777
|
-
return {
|
|
781
|
+
return defineRuleListener({
|
|
778
782
|
JSXElement: visitorFunction,
|
|
779
783
|
JSXFragment: visitorFunction
|
|
780
|
-
};
|
|
784
|
+
});
|
|
781
785
|
}
|
|
782
786
|
|
|
783
787
|
//#endregion
|
|
784
788
|
//#region src/rules/jsx-key-before-spread.ts
|
|
785
|
-
const RULE_NAME$
|
|
789
|
+
const RULE_NAME$61 = "jsx-key-before-spread";
|
|
786
790
|
var jsx_key_before_spread_default = createRule({
|
|
787
791
|
meta: {
|
|
788
792
|
type: "problem",
|
|
@@ -790,17 +794,17 @@ var jsx_key_before_spread_default = createRule({
|
|
|
790
794
|
messages: { default: "The 'key' prop must be placed before any spread props when using the new JSX transform." },
|
|
791
795
|
schema: []
|
|
792
796
|
},
|
|
793
|
-
name: RULE_NAME$
|
|
794
|
-
create: create$
|
|
797
|
+
name: RULE_NAME$61,
|
|
798
|
+
create: create$61,
|
|
795
799
|
defaultOptions: []
|
|
796
800
|
});
|
|
797
|
-
function create$
|
|
801
|
+
function create$61(context) {
|
|
798
802
|
const { jsx } = {
|
|
799
803
|
...core.getJsxConfigFromContext(context),
|
|
800
804
|
...core.getJsxConfigFromAnnotation(context)
|
|
801
805
|
};
|
|
802
806
|
if (jsx !== core.JsxEmit.ReactJSX && jsx !== core.JsxEmit.ReactJSXDev) return {};
|
|
803
|
-
return { JSXOpeningElement(node) {
|
|
807
|
+
return defineRuleListener({ JSXOpeningElement(node) {
|
|
804
808
|
let firstSpreadPropIndex = null;
|
|
805
809
|
for (const [index, prop] of node.attributes.entries()) {
|
|
806
810
|
if (prop.type === AST_NODE_TYPES.JSXSpreadAttribute) {
|
|
@@ -813,12 +817,12 @@ function create$59(context) {
|
|
|
813
817
|
node: prop
|
|
814
818
|
});
|
|
815
819
|
}
|
|
816
|
-
} };
|
|
820
|
+
} });
|
|
817
821
|
}
|
|
818
822
|
|
|
819
823
|
//#endregion
|
|
820
824
|
//#region src/rules/jsx-no-comment-textnodes.ts
|
|
821
|
-
const RULE_NAME$
|
|
825
|
+
const RULE_NAME$60 = "jsx-no-comment-textnodes";
|
|
822
826
|
var jsx_no_comment_textnodes_default = createRule({
|
|
823
827
|
meta: {
|
|
824
828
|
type: "problem",
|
|
@@ -826,11 +830,11 @@ var jsx_no_comment_textnodes_default = createRule({
|
|
|
826
830
|
messages: { default: "Possible misused comment in text node. Comments inside children section of tag should be placed inside braces." },
|
|
827
831
|
schema: []
|
|
828
832
|
},
|
|
829
|
-
name: RULE_NAME$
|
|
830
|
-
create: create$
|
|
833
|
+
name: RULE_NAME$60,
|
|
834
|
+
create: create$60,
|
|
831
835
|
defaultOptions: []
|
|
832
836
|
});
|
|
833
|
-
function create$
|
|
837
|
+
function create$60(context) {
|
|
834
838
|
function hasCommentLike(node) {
|
|
835
839
|
if (ast.isOneOf([AST_NODE_TYPES.JSXAttribute, AST_NODE_TYPES.JSXExpressionContainer])(node.parent)) return false;
|
|
836
840
|
return /^\s*\/(?:\/|\*)/mu.test(context.sourceCode.getText(node));
|
|
@@ -843,15 +847,15 @@ function create$58(context) {
|
|
|
843
847
|
node
|
|
844
848
|
});
|
|
845
849
|
};
|
|
846
|
-
return {
|
|
850
|
+
return defineRuleListener({
|
|
847
851
|
JSXText: visitorFunction,
|
|
848
852
|
Literal: visitorFunction
|
|
849
|
-
};
|
|
853
|
+
});
|
|
850
854
|
}
|
|
851
855
|
|
|
852
856
|
//#endregion
|
|
853
857
|
//#region src/rules/jsx-no-duplicate-props.ts
|
|
854
|
-
const RULE_NAME$
|
|
858
|
+
const RULE_NAME$59 = "jsx-no-duplicate-props";
|
|
855
859
|
var jsx_no_duplicate_props_default = createRule({
|
|
856
860
|
meta: {
|
|
857
861
|
type: "problem",
|
|
@@ -859,12 +863,12 @@ var jsx_no_duplicate_props_default = createRule({
|
|
|
859
863
|
messages: { default: "This JSX property is assigned multiple times." },
|
|
860
864
|
schema: []
|
|
861
865
|
},
|
|
862
|
-
name: RULE_NAME$
|
|
863
|
-
create: create$
|
|
866
|
+
name: RULE_NAME$59,
|
|
867
|
+
create: create$59,
|
|
864
868
|
defaultOptions: []
|
|
865
869
|
});
|
|
866
|
-
function create$
|
|
867
|
-
return { JSXOpeningElement(node) {
|
|
870
|
+
function create$59(context) {
|
|
871
|
+
return defineRuleListener({ JSXOpeningElement(node) {
|
|
868
872
|
const props = [];
|
|
869
873
|
for (const attr of node.attributes) {
|
|
870
874
|
if (attr.type === AST_NODE_TYPES.JSXSpreadAttribute) continue;
|
|
@@ -879,43 +883,12 @@ function create$57(context) {
|
|
|
879
883
|
node: attr
|
|
880
884
|
});
|
|
881
885
|
}
|
|
882
|
-
} };
|
|
883
|
-
}
|
|
884
|
-
|
|
885
|
-
//#endregion
|
|
886
|
-
//#region src/rules/jsx-no-iife.ts
|
|
887
|
-
const RULE_NAME$56 = "jsx-no-iife";
|
|
888
|
-
var jsx_no_iife_default = createRule({
|
|
889
|
-
meta: {
|
|
890
|
-
type: "problem",
|
|
891
|
-
docs: { description: "Disallows immediately-invoked function expressions in JSX." },
|
|
892
|
-
messages: { default: "Avoid using immediately-invoked function expressions in JSX." },
|
|
893
|
-
schema: []
|
|
894
|
-
},
|
|
895
|
-
name: RULE_NAME$56,
|
|
896
|
-
create: create$56,
|
|
897
|
-
defaultOptions: []
|
|
898
|
-
});
|
|
899
|
-
function create$56(context) {
|
|
900
|
-
return {
|
|
901
|
-
"JSXElement :function"(node) {
|
|
902
|
-
if (node.parent.type === AST_NODE_TYPES.CallExpression && node.parent.callee === node) context.report({
|
|
903
|
-
messageId: "default",
|
|
904
|
-
node: node.parent
|
|
905
|
-
});
|
|
906
|
-
},
|
|
907
|
-
"JSXFragment :function"(node) {
|
|
908
|
-
if (node.parent.type === AST_NODE_TYPES.CallExpression && node.parent.callee === node) context.report({
|
|
909
|
-
messageId: "default",
|
|
910
|
-
node: node.parent
|
|
911
|
-
});
|
|
912
|
-
}
|
|
913
|
-
};
|
|
886
|
+
} });
|
|
914
887
|
}
|
|
915
888
|
|
|
916
889
|
//#endregion
|
|
917
890
|
//#region src/rules/jsx-no-undef.ts
|
|
918
|
-
const RULE_NAME$
|
|
891
|
+
const RULE_NAME$58 = "jsx-no-undef";
|
|
919
892
|
var jsx_no_undef_default = createRule({
|
|
920
893
|
meta: {
|
|
921
894
|
type: "problem",
|
|
@@ -923,12 +896,12 @@ var jsx_no_undef_default = createRule({
|
|
|
923
896
|
messages: { default: "JSX variable '{{name}}' is not defined." },
|
|
924
897
|
schema: []
|
|
925
898
|
},
|
|
926
|
-
name: RULE_NAME$
|
|
927
|
-
create: create$
|
|
899
|
+
name: RULE_NAME$58,
|
|
900
|
+
create: create$58,
|
|
928
901
|
defaultOptions: []
|
|
929
902
|
});
|
|
930
|
-
function create$
|
|
931
|
-
return { JSXOpeningElement(node) {
|
|
903
|
+
function create$58(context) {
|
|
904
|
+
return defineRuleListener({ JSXOpeningElement(node) {
|
|
932
905
|
const name = match(node.name).with({ type: AST_NODE_TYPES.JSXIdentifier }, (n) => n.name).with({
|
|
933
906
|
type: AST_NODE_TYPES.JSXMemberExpression,
|
|
934
907
|
object: { type: AST_NODE_TYPES.JSXIdentifier }
|
|
@@ -941,12 +914,12 @@ function create$55(context) {
|
|
|
941
914
|
node,
|
|
942
915
|
data: { name }
|
|
943
916
|
});
|
|
944
|
-
} };
|
|
917
|
+
} });
|
|
945
918
|
}
|
|
946
919
|
|
|
947
920
|
//#endregion
|
|
948
921
|
//#region src/rules/jsx-shorthand-boolean.ts
|
|
949
|
-
const RULE_NAME$
|
|
922
|
+
const RULE_NAME$57 = "jsx-shorthand-boolean";
|
|
950
923
|
const defaultOptions$3 = [1];
|
|
951
924
|
const schema$3 = [{
|
|
952
925
|
type: "integer",
|
|
@@ -960,13 +933,13 @@ var jsx_shorthand_boolean_default = createRule({
|
|
|
960
933
|
messages: { default: "{{message}}" },
|
|
961
934
|
schema: schema$3
|
|
962
935
|
},
|
|
963
|
-
name: RULE_NAME$
|
|
964
|
-
create: create$
|
|
936
|
+
name: RULE_NAME$57,
|
|
937
|
+
create: create$57,
|
|
965
938
|
defaultOptions: defaultOptions$3
|
|
966
939
|
});
|
|
967
|
-
function create$
|
|
940
|
+
function create$57(context) {
|
|
968
941
|
const policy = context.options[0] ?? defaultOptions$3[0];
|
|
969
|
-
return { JSXAttribute(node) {
|
|
942
|
+
return defineRuleListener({ JSXAttribute(node) {
|
|
970
943
|
const { value } = node;
|
|
971
944
|
const propName = core.getJsxAttributeName(context, node);
|
|
972
945
|
switch (true) {
|
|
@@ -987,12 +960,12 @@ function create$54(context) {
|
|
|
987
960
|
});
|
|
988
961
|
break;
|
|
989
962
|
}
|
|
990
|
-
} };
|
|
963
|
+
} });
|
|
991
964
|
}
|
|
992
965
|
|
|
993
966
|
//#endregion
|
|
994
967
|
//#region src/rules/jsx-shorthand-fragment.ts
|
|
995
|
-
const RULE_NAME$
|
|
968
|
+
const RULE_NAME$56 = "jsx-shorthand-fragment";
|
|
996
969
|
const defaultOptions$2 = [1];
|
|
997
970
|
const schema$2 = [{
|
|
998
971
|
type: "integer",
|
|
@@ -1006,18 +979,18 @@ var jsx_shorthand_fragment_default = createRule({
|
|
|
1006
979
|
messages: { default: "{{message}}" },
|
|
1007
980
|
schema: schema$2
|
|
1008
981
|
},
|
|
1009
|
-
name: RULE_NAME$
|
|
1010
|
-
create: create$
|
|
982
|
+
name: RULE_NAME$56,
|
|
983
|
+
create: create$56,
|
|
1011
984
|
defaultOptions: defaultOptions$2
|
|
1012
985
|
});
|
|
1013
|
-
function create$
|
|
986
|
+
function create$56(context) {
|
|
1014
987
|
const policy = context.options[0] ?? defaultOptions$2[0];
|
|
1015
988
|
const jsxConfig = {
|
|
1016
989
|
...core.getJsxConfigFromContext(context),
|
|
1017
990
|
...core.getJsxConfigFromAnnotation(context)
|
|
1018
991
|
};
|
|
1019
992
|
const { jsxFragmentFactory } = jsxConfig;
|
|
1020
|
-
return match(policy).with(1, () => ({ JSXElement(node) {
|
|
993
|
+
return match(policy).with(1, () => defineRuleListener({ JSXElement(node) {
|
|
1021
994
|
if (!core.isJsxFragmentElement(context, node, jsxConfig)) return;
|
|
1022
995
|
if (node.openingElement.attributes.length > 0) return;
|
|
1023
996
|
context.report({
|
|
@@ -1030,7 +1003,7 @@ function create$53(context) {
|
|
|
1030
1003
|
return [fixer.replaceTextRange([openingElement.range[0], openingElement.range[1]], "<>"), fixer.replaceTextRange([closingElement.range[0], closingElement.range[1]], "</>")];
|
|
1031
1004
|
}
|
|
1032
1005
|
});
|
|
1033
|
-
} })).with(-1, () => ({ JSXFragment(node) {
|
|
1006
|
+
} })).with(-1, () => defineRuleListener({ JSXFragment(node) {
|
|
1034
1007
|
context.report({
|
|
1035
1008
|
messageId: "default",
|
|
1036
1009
|
node,
|
|
@@ -1045,7 +1018,7 @@ function create$53(context) {
|
|
|
1045
1018
|
|
|
1046
1019
|
//#endregion
|
|
1047
1020
|
//#region src/rules/jsx-uses-react.ts
|
|
1048
|
-
const RULE_NAME$
|
|
1021
|
+
const RULE_NAME$55 = "jsx-uses-react";
|
|
1049
1022
|
var jsx_uses_react_default = createRule({
|
|
1050
1023
|
meta: {
|
|
1051
1024
|
type: "problem",
|
|
@@ -1053,11 +1026,11 @@ var jsx_uses_react_default = createRule({
|
|
|
1053
1026
|
messages: { default: "Marked {{name}} as used." },
|
|
1054
1027
|
schema: []
|
|
1055
1028
|
},
|
|
1056
|
-
name: RULE_NAME$
|
|
1057
|
-
create: create$
|
|
1029
|
+
name: RULE_NAME$55,
|
|
1030
|
+
create: create$55,
|
|
1058
1031
|
defaultOptions: []
|
|
1059
1032
|
});
|
|
1060
|
-
function create$
|
|
1033
|
+
function create$55(context) {
|
|
1061
1034
|
const { jsx, jsxFactory, jsxFragmentFactory } = {
|
|
1062
1035
|
...core.getJsxConfigFromContext(context),
|
|
1063
1036
|
...core.getJsxConfigFromAnnotation(context)
|
|
@@ -1071,11 +1044,11 @@ function create$52(context) {
|
|
|
1071
1044
|
context.sourceCode.markVariableAsUsed(jsxFragmentFactory, node);
|
|
1072
1045
|
debugReport(context, node, jsxFragmentFactory);
|
|
1073
1046
|
}
|
|
1074
|
-
return {
|
|
1047
|
+
return defineRuleListener({
|
|
1075
1048
|
JSXFragment: handleJsxFragment,
|
|
1076
1049
|
JSXOpeningElement: handleJsxElement,
|
|
1077
1050
|
JSXOpeningFragment: handleJsxElement
|
|
1078
|
-
};
|
|
1051
|
+
});
|
|
1079
1052
|
}
|
|
1080
1053
|
function debugReport(context, node, name) {
|
|
1081
1054
|
if (process.env["ESLINT_REACT_DEBUG"] !== "1") return;
|
|
@@ -1088,7 +1061,7 @@ function debugReport(context, node, name) {
|
|
|
1088
1061
|
|
|
1089
1062
|
//#endregion
|
|
1090
1063
|
//#region src/rules/jsx-uses-vars.ts
|
|
1091
|
-
const RULE_NAME$
|
|
1064
|
+
const RULE_NAME$54 = "jsx-uses-vars";
|
|
1092
1065
|
var jsx_uses_vars_default = createRule({
|
|
1093
1066
|
meta: {
|
|
1094
1067
|
type: "problem",
|
|
@@ -1096,12 +1069,12 @@ var jsx_uses_vars_default = createRule({
|
|
|
1096
1069
|
messages: { default: "An identifier in JSX is marked as used." },
|
|
1097
1070
|
schema: []
|
|
1098
1071
|
},
|
|
1099
|
-
name: RULE_NAME$
|
|
1100
|
-
create: create$
|
|
1072
|
+
name: RULE_NAME$54,
|
|
1073
|
+
create: create$54,
|
|
1101
1074
|
defaultOptions: []
|
|
1102
1075
|
});
|
|
1103
|
-
function create$
|
|
1104
|
-
return { JSXOpeningElement(node) {
|
|
1076
|
+
function create$54(context) {
|
|
1077
|
+
return defineRuleListener({ JSXOpeningElement(node) {
|
|
1105
1078
|
switch (node.name.type) {
|
|
1106
1079
|
case AST_NODE_TYPES.JSXIdentifier:
|
|
1107
1080
|
if (/^[a-z]/u.test(node.name.name)) return;
|
|
@@ -1113,12 +1086,12 @@ function create$51(context) {
|
|
|
1113
1086
|
break;
|
|
1114
1087
|
}
|
|
1115
1088
|
}
|
|
1116
|
-
} };
|
|
1089
|
+
} });
|
|
1117
1090
|
}
|
|
1118
1091
|
|
|
1119
1092
|
//#endregion
|
|
1120
1093
|
//#region src/rules/no-access-state-in-setstate.ts
|
|
1121
|
-
const RULE_NAME$
|
|
1094
|
+
const RULE_NAME$53 = "no-access-state-in-setstate";
|
|
1122
1095
|
function isKeyLiteral$2(node, key) {
|
|
1123
1096
|
return match(key).with({ type: AST_NODE_TYPES.Literal }, constTrue).with({
|
|
1124
1097
|
type: AST_NODE_TYPES.TemplateLiteral,
|
|
@@ -1132,16 +1105,16 @@ var no_access_state_in_setstate_default = createRule({
|
|
|
1132
1105
|
messages: { default: "Do not access 'this.state' within 'setState'. Use the update function instead." },
|
|
1133
1106
|
schema: []
|
|
1134
1107
|
},
|
|
1135
|
-
name: RULE_NAME$
|
|
1136
|
-
create: create$
|
|
1108
|
+
name: RULE_NAME$53,
|
|
1109
|
+
create: create$53,
|
|
1137
1110
|
defaultOptions: []
|
|
1138
1111
|
});
|
|
1139
|
-
function create$
|
|
1112
|
+
function create$53(context) {
|
|
1140
1113
|
if (!context.sourceCode.text.includes("setState")) return {};
|
|
1141
1114
|
const classStack = [];
|
|
1142
1115
|
const methodStack = [];
|
|
1143
1116
|
const setStateStack = [];
|
|
1144
|
-
return {
|
|
1117
|
+
return defineRuleListener({
|
|
1145
1118
|
CallExpression(node) {
|
|
1146
1119
|
if (!core.isThisSetState(node)) return;
|
|
1147
1120
|
setStateStack.push([node, false]);
|
|
@@ -1202,12 +1175,12 @@ function create$50(context) {
|
|
|
1202
1175
|
node
|
|
1203
1176
|
});
|
|
1204
1177
|
}
|
|
1205
|
-
};
|
|
1178
|
+
});
|
|
1206
1179
|
}
|
|
1207
1180
|
|
|
1208
1181
|
//#endregion
|
|
1209
1182
|
//#region src/rules/no-array-index-key.ts
|
|
1210
|
-
const RULE_NAME$
|
|
1183
|
+
const RULE_NAME$52 = "no-array-index-key";
|
|
1211
1184
|
const REACT_CHILDREN_METHOD = ["forEach", "map"];
|
|
1212
1185
|
function getIndexParamPosition(methodName) {
|
|
1213
1186
|
switch (methodName) {
|
|
@@ -1266,11 +1239,11 @@ var no_array_index_key_default = createRule({
|
|
|
1266
1239
|
messages: { default: "Do not use item index in the array as its key." },
|
|
1267
1240
|
schema: []
|
|
1268
1241
|
},
|
|
1269
|
-
name: RULE_NAME$
|
|
1270
|
-
create: create$
|
|
1242
|
+
name: RULE_NAME$52,
|
|
1243
|
+
create: create$52,
|
|
1271
1244
|
defaultOptions: []
|
|
1272
1245
|
});
|
|
1273
|
-
function create$
|
|
1246
|
+
function create$52(context) {
|
|
1274
1247
|
const indexParamNames = [];
|
|
1275
1248
|
function isArrayIndex(node) {
|
|
1276
1249
|
return node.type === AST_NODE_TYPES.Identifier && indexParamNames.some((name) => name != null && name === node.name);
|
|
@@ -1309,7 +1282,7 @@ function create$49(context) {
|
|
|
1309
1282
|
}
|
|
1310
1283
|
return [];
|
|
1311
1284
|
}
|
|
1312
|
-
return {
|
|
1285
|
+
return defineRuleListener({
|
|
1313
1286
|
CallExpression(node) {
|
|
1314
1287
|
indexParamNames.push(getMapIndexParamName(context, node));
|
|
1315
1288
|
if (node.arguments.length === 0) return;
|
|
@@ -1331,12 +1304,12 @@ function create$49(context) {
|
|
|
1331
1304
|
if (node.value?.type !== AST_NODE_TYPES.JSXExpressionContainer) return;
|
|
1332
1305
|
for (const descriptor of getReportDescriptors(node.value.expression)) report(context)(descriptor);
|
|
1333
1306
|
}
|
|
1334
|
-
};
|
|
1307
|
+
});
|
|
1335
1308
|
}
|
|
1336
1309
|
|
|
1337
1310
|
//#endregion
|
|
1338
1311
|
//#region src/rules/no-children-count.ts
|
|
1339
|
-
const RULE_NAME$
|
|
1312
|
+
const RULE_NAME$51 = "no-children-count";
|
|
1340
1313
|
var no_children_count_default = createRule({
|
|
1341
1314
|
meta: {
|
|
1342
1315
|
type: "problem",
|
|
@@ -1344,22 +1317,22 @@ var no_children_count_default = createRule({
|
|
|
1344
1317
|
messages: { default: "Using 'Children.count' is uncommon and can lead to fragile code. Use alternatives instead." },
|
|
1345
1318
|
schema: []
|
|
1346
1319
|
},
|
|
1347
|
-
name: RULE_NAME$
|
|
1348
|
-
create: create$
|
|
1320
|
+
name: RULE_NAME$51,
|
|
1321
|
+
create: create$51,
|
|
1349
1322
|
defaultOptions: []
|
|
1350
1323
|
});
|
|
1351
|
-
function create$
|
|
1352
|
-
return { MemberExpression(node) {
|
|
1324
|
+
function create$51(context) {
|
|
1325
|
+
return defineRuleListener({ MemberExpression(node) {
|
|
1353
1326
|
if (core.isChildrenCount(context, node)) context.report({
|
|
1354
1327
|
messageId: "default",
|
|
1355
1328
|
node: node.property
|
|
1356
1329
|
});
|
|
1357
|
-
} };
|
|
1330
|
+
} });
|
|
1358
1331
|
}
|
|
1359
1332
|
|
|
1360
1333
|
//#endregion
|
|
1361
1334
|
//#region src/rules/no-children-for-each.ts
|
|
1362
|
-
const RULE_NAME$
|
|
1335
|
+
const RULE_NAME$50 = "no-children-for-each";
|
|
1363
1336
|
var no_children_for_each_default = createRule({
|
|
1364
1337
|
meta: {
|
|
1365
1338
|
type: "problem",
|
|
@@ -1367,22 +1340,22 @@ var no_children_for_each_default = createRule({
|
|
|
1367
1340
|
messages: { default: "Using 'Children.forEach' is uncommon and can lead to fragile code. Use alternatives instead." },
|
|
1368
1341
|
schema: []
|
|
1369
1342
|
},
|
|
1370
|
-
name: RULE_NAME$
|
|
1371
|
-
create: create$
|
|
1343
|
+
name: RULE_NAME$50,
|
|
1344
|
+
create: create$50,
|
|
1372
1345
|
defaultOptions: []
|
|
1373
1346
|
});
|
|
1374
|
-
function create$
|
|
1375
|
-
return { MemberExpression(node) {
|
|
1347
|
+
function create$50(context) {
|
|
1348
|
+
return defineRuleListener({ MemberExpression(node) {
|
|
1376
1349
|
if (core.isChildrenForEach(context, node)) context.report({
|
|
1377
1350
|
messageId: "default",
|
|
1378
1351
|
node: node.property
|
|
1379
1352
|
});
|
|
1380
|
-
} };
|
|
1353
|
+
} });
|
|
1381
1354
|
}
|
|
1382
1355
|
|
|
1383
1356
|
//#endregion
|
|
1384
1357
|
//#region src/rules/no-children-map.ts
|
|
1385
|
-
const RULE_NAME$
|
|
1358
|
+
const RULE_NAME$49 = "no-children-map";
|
|
1386
1359
|
var no_children_map_default = createRule({
|
|
1387
1360
|
meta: {
|
|
1388
1361
|
type: "problem",
|
|
@@ -1390,22 +1363,22 @@ var no_children_map_default = createRule({
|
|
|
1390
1363
|
messages: { default: "Using 'Children.map' is uncommon and can lead to fragile code. Use alternatives instead." },
|
|
1391
1364
|
schema: []
|
|
1392
1365
|
},
|
|
1393
|
-
name: RULE_NAME$
|
|
1394
|
-
create: create$
|
|
1366
|
+
name: RULE_NAME$49,
|
|
1367
|
+
create: create$49,
|
|
1395
1368
|
defaultOptions: []
|
|
1396
1369
|
});
|
|
1397
|
-
function create$
|
|
1398
|
-
return { MemberExpression(node) {
|
|
1370
|
+
function create$49(context) {
|
|
1371
|
+
return defineRuleListener({ MemberExpression(node) {
|
|
1399
1372
|
if (core.isChildrenMap(context, node)) context.report({
|
|
1400
1373
|
messageId: "default",
|
|
1401
1374
|
node: node.property
|
|
1402
1375
|
});
|
|
1403
|
-
} };
|
|
1376
|
+
} });
|
|
1404
1377
|
}
|
|
1405
1378
|
|
|
1406
1379
|
//#endregion
|
|
1407
1380
|
//#region src/rules/no-children-only.ts
|
|
1408
|
-
const RULE_NAME$
|
|
1381
|
+
const RULE_NAME$48 = "no-children-only";
|
|
1409
1382
|
var no_children_only_default = createRule({
|
|
1410
1383
|
meta: {
|
|
1411
1384
|
type: "problem",
|
|
@@ -1413,22 +1386,22 @@ var no_children_only_default = createRule({
|
|
|
1413
1386
|
messages: { default: "Using 'Children.only' is uncommon and can lead to fragile code. Use alternatives instead." },
|
|
1414
1387
|
schema: []
|
|
1415
1388
|
},
|
|
1416
|
-
name: RULE_NAME$
|
|
1417
|
-
create: create$
|
|
1389
|
+
name: RULE_NAME$48,
|
|
1390
|
+
create: create$48,
|
|
1418
1391
|
defaultOptions: []
|
|
1419
1392
|
});
|
|
1420
|
-
function create$
|
|
1421
|
-
return { MemberExpression(node) {
|
|
1393
|
+
function create$48(context) {
|
|
1394
|
+
return defineRuleListener({ MemberExpression(node) {
|
|
1422
1395
|
if (core.isChildrenOnly(context, node)) context.report({
|
|
1423
1396
|
messageId: "default",
|
|
1424
1397
|
node: node.property
|
|
1425
1398
|
});
|
|
1426
|
-
} };
|
|
1399
|
+
} });
|
|
1427
1400
|
}
|
|
1428
1401
|
|
|
1429
1402
|
//#endregion
|
|
1430
1403
|
//#region src/rules/no-children-prop.ts
|
|
1431
|
-
const RULE_NAME$
|
|
1404
|
+
const RULE_NAME$47 = "no-children-prop";
|
|
1432
1405
|
var no_children_prop_default = createRule({
|
|
1433
1406
|
meta: {
|
|
1434
1407
|
type: "problem",
|
|
@@ -1436,23 +1409,23 @@ var no_children_prop_default = createRule({
|
|
|
1436
1409
|
messages: { default: "Do not pass 'children' as props." },
|
|
1437
1410
|
schema: []
|
|
1438
1411
|
},
|
|
1439
|
-
name: RULE_NAME$
|
|
1440
|
-
create: create$
|
|
1412
|
+
name: RULE_NAME$47,
|
|
1413
|
+
create: create$47,
|
|
1441
1414
|
defaultOptions: []
|
|
1442
1415
|
});
|
|
1443
|
-
function create$
|
|
1444
|
-
return { JSXElement(node) {
|
|
1416
|
+
function create$47(context) {
|
|
1417
|
+
return defineRuleListener({ JSXElement(node) {
|
|
1445
1418
|
const childrenProp = core.getJsxAttribute(context, node)("children");
|
|
1446
1419
|
if (childrenProp != null) context.report({
|
|
1447
1420
|
messageId: "default",
|
|
1448
1421
|
node: childrenProp
|
|
1449
1422
|
});
|
|
1450
|
-
} };
|
|
1423
|
+
} });
|
|
1451
1424
|
}
|
|
1452
1425
|
|
|
1453
1426
|
//#endregion
|
|
1454
1427
|
//#region src/rules/no-children-to-array.ts
|
|
1455
|
-
const RULE_NAME$
|
|
1428
|
+
const RULE_NAME$46 = "no-children-to-array";
|
|
1456
1429
|
var no_children_to_array_default = createRule({
|
|
1457
1430
|
meta: {
|
|
1458
1431
|
type: "problem",
|
|
@@ -1460,22 +1433,22 @@ var no_children_to_array_default = createRule({
|
|
|
1460
1433
|
messages: { default: "Using 'Children.toArray' is uncommon and can lead to fragile code. Use alternatives instead." },
|
|
1461
1434
|
schema: []
|
|
1462
1435
|
},
|
|
1463
|
-
name: RULE_NAME$
|
|
1464
|
-
create: create$
|
|
1436
|
+
name: RULE_NAME$46,
|
|
1437
|
+
create: create$46,
|
|
1465
1438
|
defaultOptions: []
|
|
1466
1439
|
});
|
|
1467
|
-
function create$
|
|
1468
|
-
return { MemberExpression(node) {
|
|
1440
|
+
function create$46(context) {
|
|
1441
|
+
return defineRuleListener({ MemberExpression(node) {
|
|
1469
1442
|
if (core.isChildrenToArray(context, node)) context.report({
|
|
1470
1443
|
messageId: "default",
|
|
1471
1444
|
node: node.property
|
|
1472
1445
|
});
|
|
1473
|
-
} };
|
|
1446
|
+
} });
|
|
1474
1447
|
}
|
|
1475
1448
|
|
|
1476
1449
|
//#endregion
|
|
1477
1450
|
//#region src/rules/no-class-component.ts
|
|
1478
|
-
const RULE_NAME$
|
|
1451
|
+
const RULE_NAME$45 = "no-class-component";
|
|
1479
1452
|
var no_class_component_default = createRule({
|
|
1480
1453
|
meta: {
|
|
1481
1454
|
type: "problem",
|
|
@@ -1483,11 +1456,11 @@ var no_class_component_default = createRule({
|
|
|
1483
1456
|
messages: { default: "Avoid using class components. Use function components instead." },
|
|
1484
1457
|
schema: []
|
|
1485
1458
|
},
|
|
1486
|
-
name: RULE_NAME$
|
|
1487
|
-
create: create$
|
|
1459
|
+
name: RULE_NAME$45,
|
|
1460
|
+
create: create$45,
|
|
1488
1461
|
defaultOptions: []
|
|
1489
1462
|
});
|
|
1490
|
-
function create$
|
|
1463
|
+
function create$45(context) {
|
|
1491
1464
|
if (!context.sourceCode.text.includes("Component")) return {};
|
|
1492
1465
|
const { ctx, visitor } = core.useComponentCollectorLegacy(context);
|
|
1493
1466
|
return defineRuleListener(visitor, { "Program:exit"(program) {
|
|
@@ -1504,7 +1477,7 @@ function create$42(context) {
|
|
|
1504
1477
|
|
|
1505
1478
|
//#endregion
|
|
1506
1479
|
//#region src/rules/no-clone-element.ts
|
|
1507
|
-
const RULE_NAME$
|
|
1480
|
+
const RULE_NAME$44 = "no-clone-element";
|
|
1508
1481
|
var no_clone_element_default = createRule({
|
|
1509
1482
|
meta: {
|
|
1510
1483
|
type: "problem",
|
|
@@ -1512,22 +1485,22 @@ var no_clone_element_default = createRule({
|
|
|
1512
1485
|
messages: { default: "Using 'cloneElement' is uncommon and can lead to fragile code. Use alternatives instead." },
|
|
1513
1486
|
schema: []
|
|
1514
1487
|
},
|
|
1515
|
-
name: RULE_NAME$
|
|
1516
|
-
create: create$
|
|
1488
|
+
name: RULE_NAME$44,
|
|
1489
|
+
create: create$44,
|
|
1517
1490
|
defaultOptions: []
|
|
1518
1491
|
});
|
|
1519
|
-
function create$
|
|
1520
|
-
return { CallExpression(node) {
|
|
1492
|
+
function create$44(context) {
|
|
1493
|
+
return defineRuleListener({ CallExpression(node) {
|
|
1521
1494
|
if (core.isCloneElementCall(context, node)) context.report({
|
|
1522
1495
|
messageId: "default",
|
|
1523
1496
|
node
|
|
1524
1497
|
});
|
|
1525
|
-
} };
|
|
1498
|
+
} });
|
|
1526
1499
|
}
|
|
1527
1500
|
|
|
1528
1501
|
//#endregion
|
|
1529
1502
|
//#region src/rules/no-component-will-mount.ts
|
|
1530
|
-
const RULE_NAME$
|
|
1503
|
+
const RULE_NAME$43 = "no-component-will-mount";
|
|
1531
1504
|
var no_component_will_mount_default = createRule({
|
|
1532
1505
|
meta: {
|
|
1533
1506
|
type: "problem",
|
|
@@ -1536,11 +1509,11 @@ var no_component_will_mount_default = createRule({
|
|
|
1536
1509
|
messages: { default: "[Deprecated] Use 'UNSAFE_componentWillMount' instead." },
|
|
1537
1510
|
schema: []
|
|
1538
1511
|
},
|
|
1539
|
-
name: RULE_NAME$
|
|
1540
|
-
create: create$
|
|
1512
|
+
name: RULE_NAME$43,
|
|
1513
|
+
create: create$43,
|
|
1541
1514
|
defaultOptions: []
|
|
1542
1515
|
});
|
|
1543
|
-
function create$
|
|
1516
|
+
function create$43(context) {
|
|
1544
1517
|
if (!context.sourceCode.text.includes("componentWillMount")) return {};
|
|
1545
1518
|
const { ctx, visitor } = core.useComponentCollectorLegacy(context);
|
|
1546
1519
|
return defineRuleListener(visitor, { "Program:exit"(program) {
|
|
@@ -1560,7 +1533,7 @@ function create$40(context) {
|
|
|
1560
1533
|
|
|
1561
1534
|
//#endregion
|
|
1562
1535
|
//#region src/rules/no-component-will-receive-props.ts
|
|
1563
|
-
const RULE_NAME$
|
|
1536
|
+
const RULE_NAME$42 = "no-component-will-receive-props";
|
|
1564
1537
|
var no_component_will_receive_props_default = createRule({
|
|
1565
1538
|
meta: {
|
|
1566
1539
|
type: "problem",
|
|
@@ -1569,11 +1542,11 @@ var no_component_will_receive_props_default = createRule({
|
|
|
1569
1542
|
messages: { default: "[Deprecated] Use 'UNSAFE_componentWillReceiveProps' instead." },
|
|
1570
1543
|
schema: []
|
|
1571
1544
|
},
|
|
1572
|
-
name: RULE_NAME$
|
|
1573
|
-
create: create$
|
|
1545
|
+
name: RULE_NAME$42,
|
|
1546
|
+
create: create$42,
|
|
1574
1547
|
defaultOptions: []
|
|
1575
1548
|
});
|
|
1576
|
-
function create$
|
|
1549
|
+
function create$42(context) {
|
|
1577
1550
|
if (!context.sourceCode.text.includes("componentWillReceiveProps")) return {};
|
|
1578
1551
|
const { ctx, visitor } = core.useComponentCollectorLegacy(context);
|
|
1579
1552
|
return defineRuleListener(visitor, { "Program:exit"(program) {
|
|
@@ -1593,7 +1566,7 @@ function create$39(context) {
|
|
|
1593
1566
|
|
|
1594
1567
|
//#endregion
|
|
1595
1568
|
//#region src/rules/no-component-will-update.ts
|
|
1596
|
-
const RULE_NAME$
|
|
1569
|
+
const RULE_NAME$41 = "no-component-will-update";
|
|
1597
1570
|
var no_component_will_update_default = createRule({
|
|
1598
1571
|
meta: {
|
|
1599
1572
|
type: "problem",
|
|
@@ -1602,11 +1575,11 @@ var no_component_will_update_default = createRule({
|
|
|
1602
1575
|
messages: { default: "[Deprecated] Use 'UNSAFE_componentWillUpdate' instead." },
|
|
1603
1576
|
schema: []
|
|
1604
1577
|
},
|
|
1605
|
-
name: RULE_NAME$
|
|
1606
|
-
create: create$
|
|
1578
|
+
name: RULE_NAME$41,
|
|
1579
|
+
create: create$41,
|
|
1607
1580
|
defaultOptions: []
|
|
1608
1581
|
});
|
|
1609
|
-
function create$
|
|
1582
|
+
function create$41(context) {
|
|
1610
1583
|
if (!context.sourceCode.text.includes("componentWillUpdate")) return {};
|
|
1611
1584
|
const { ctx, visitor } = core.useComponentCollectorLegacy(context);
|
|
1612
1585
|
return defineRuleListener(visitor, { "Program:exit"(program) {
|
|
@@ -1626,7 +1599,7 @@ function create$38(context) {
|
|
|
1626
1599
|
|
|
1627
1600
|
//#endregion
|
|
1628
1601
|
//#region src/rules/no-context-provider.ts
|
|
1629
|
-
const RULE_NAME$
|
|
1602
|
+
const RULE_NAME$40 = "no-context-provider";
|
|
1630
1603
|
var no_context_provider_default = createRule({
|
|
1631
1604
|
meta: {
|
|
1632
1605
|
type: "problem",
|
|
@@ -1635,15 +1608,15 @@ var no_context_provider_default = createRule({
|
|
|
1635
1608
|
messages: { default: "In React 19, you can render '<Context>' as a provider instead of '<Context.Provider>'." },
|
|
1636
1609
|
schema: []
|
|
1637
1610
|
},
|
|
1638
|
-
name: RULE_NAME$
|
|
1639
|
-
create: create$
|
|
1611
|
+
name: RULE_NAME$40,
|
|
1612
|
+
create: create$40,
|
|
1640
1613
|
defaultOptions: []
|
|
1641
1614
|
});
|
|
1642
|
-
function create$
|
|
1615
|
+
function create$40(context) {
|
|
1643
1616
|
if (!context.sourceCode.text.includes("Provider")) return {};
|
|
1644
1617
|
const { version } = getSettingsFromContext(context);
|
|
1645
1618
|
if (compare(version, "19.0.0", "<")) return {};
|
|
1646
|
-
return { JSXElement(node) {
|
|
1619
|
+
return defineRuleListener({ JSXElement(node) {
|
|
1647
1620
|
const parts = core.getJsxElementType(context, node).split(".");
|
|
1648
1621
|
const selfName = parts.pop();
|
|
1649
1622
|
const contextFullName = parts.join(".");
|
|
@@ -1661,12 +1634,12 @@ function create$37(context) {
|
|
|
1661
1634
|
return [fixer.replaceText(openingElement.name, contextFullName), fixer.replaceText(closingElement.name, contextFullName)];
|
|
1662
1635
|
}
|
|
1663
1636
|
});
|
|
1664
|
-
} };
|
|
1637
|
+
} });
|
|
1665
1638
|
}
|
|
1666
1639
|
|
|
1667
1640
|
//#endregion
|
|
1668
1641
|
//#region src/rules/no-create-ref.ts
|
|
1669
|
-
const RULE_NAME$
|
|
1642
|
+
const RULE_NAME$39 = "no-create-ref";
|
|
1670
1643
|
var no_create_ref_default = createRule({
|
|
1671
1644
|
meta: {
|
|
1672
1645
|
type: "problem",
|
|
@@ -1674,22 +1647,22 @@ var no_create_ref_default = createRule({
|
|
|
1674
1647
|
messages: { default: "[Deprecated] Use 'useRef' instead." },
|
|
1675
1648
|
schema: []
|
|
1676
1649
|
},
|
|
1677
|
-
name: RULE_NAME$
|
|
1678
|
-
create: create$
|
|
1650
|
+
name: RULE_NAME$39,
|
|
1651
|
+
create: create$39,
|
|
1679
1652
|
defaultOptions: []
|
|
1680
1653
|
});
|
|
1681
|
-
function create$
|
|
1682
|
-
return { CallExpression(node) {
|
|
1654
|
+
function create$39(context) {
|
|
1655
|
+
return defineRuleListener({ CallExpression(node) {
|
|
1683
1656
|
if (core.isCreateRefCall(context, node) && ast.findParentNode(node, core.isClassComponent) == null) context.report({
|
|
1684
1657
|
messageId: "default",
|
|
1685
1658
|
node
|
|
1686
1659
|
});
|
|
1687
|
-
} };
|
|
1660
|
+
} });
|
|
1688
1661
|
}
|
|
1689
1662
|
|
|
1690
1663
|
//#endregion
|
|
1691
1664
|
//#region src/rules/no-direct-mutation-state.ts
|
|
1692
|
-
const RULE_NAME$
|
|
1665
|
+
const RULE_NAME$38 = "no-direct-mutation-state";
|
|
1693
1666
|
function isConstructorFunction(node) {
|
|
1694
1667
|
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";
|
|
1695
1668
|
}
|
|
@@ -1700,12 +1673,12 @@ var no_direct_mutation_state_default = createRule({
|
|
|
1700
1673
|
messages: { default: "Do not mutate state directly. Use 'setState()' instead." },
|
|
1701
1674
|
schema: []
|
|
1702
1675
|
},
|
|
1703
|
-
name: RULE_NAME$
|
|
1704
|
-
create: create$
|
|
1676
|
+
name: RULE_NAME$38,
|
|
1677
|
+
create: create$38,
|
|
1705
1678
|
defaultOptions: []
|
|
1706
1679
|
});
|
|
1707
|
-
function create$
|
|
1708
|
-
return { AssignmentExpression(node) {
|
|
1680
|
+
function create$38(context) {
|
|
1681
|
+
return defineRuleListener({ AssignmentExpression(node) {
|
|
1709
1682
|
if (!core.isAssignmentToThisState(node)) return;
|
|
1710
1683
|
const parentClass = ast.findParentNode(node, ast.isOneOf([AST_NODE_TYPES.ClassDeclaration, AST_NODE_TYPES.ClassExpression]));
|
|
1711
1684
|
if (parentClass == null) return;
|
|
@@ -1713,12 +1686,12 @@ function create$35(context) {
|
|
|
1713
1686
|
messageId: "default",
|
|
1714
1687
|
node
|
|
1715
1688
|
});
|
|
1716
|
-
} };
|
|
1689
|
+
} });
|
|
1717
1690
|
}
|
|
1718
1691
|
|
|
1719
1692
|
//#endregion
|
|
1720
1693
|
//#region src/rules/no-duplicate-key.ts
|
|
1721
|
-
const RULE_NAME$
|
|
1694
|
+
const RULE_NAME$37 = "no-duplicate-key";
|
|
1722
1695
|
var no_duplicate_key_default = createRule({
|
|
1723
1696
|
meta: {
|
|
1724
1697
|
type: "problem",
|
|
@@ -1726,11 +1699,11 @@ var no_duplicate_key_default = createRule({
|
|
|
1726
1699
|
messages: { default: "The 'key' prop must be unique to its sibling elements." },
|
|
1727
1700
|
schema: []
|
|
1728
1701
|
},
|
|
1729
|
-
name: RULE_NAME$
|
|
1730
|
-
create: create$
|
|
1702
|
+
name: RULE_NAME$37,
|
|
1703
|
+
create: create$37,
|
|
1731
1704
|
defaultOptions: []
|
|
1732
1705
|
});
|
|
1733
|
-
function create$
|
|
1706
|
+
function create$37(context) {
|
|
1734
1707
|
if (!context.sourceCode.text.includes("key=")) return {};
|
|
1735
1708
|
const keyedEntries = /* @__PURE__ */ new Map();
|
|
1736
1709
|
function isKeyValueEqual(a, b) {
|
|
@@ -1739,7 +1712,7 @@ function create$34(context) {
|
|
|
1739
1712
|
if (aValue == null || bValue == null) return false;
|
|
1740
1713
|
return ast.isNodeEqual(aValue, bValue);
|
|
1741
1714
|
}
|
|
1742
|
-
return {
|
|
1715
|
+
return defineRuleListener({
|
|
1743
1716
|
"JSXAttribute[name.name='key']"(node) {
|
|
1744
1717
|
const jsxElement = node.parent.parent;
|
|
1745
1718
|
switch (jsxElement.parent.type) {
|
|
@@ -1780,12 +1753,12 @@ function create$34(context) {
|
|
|
1780
1753
|
});
|
|
1781
1754
|
}
|
|
1782
1755
|
}
|
|
1783
|
-
};
|
|
1756
|
+
});
|
|
1784
1757
|
}
|
|
1785
1758
|
|
|
1786
1759
|
//#endregion
|
|
1787
1760
|
//#region src/rules/no-forward-ref.ts
|
|
1788
|
-
const RULE_NAME$
|
|
1761
|
+
const RULE_NAME$36 = "no-forward-ref";
|
|
1789
1762
|
var no_forward_ref_default = createRule({
|
|
1790
1763
|
meta: {
|
|
1791
1764
|
type: "problem",
|
|
@@ -1794,15 +1767,15 @@ var no_forward_ref_default = createRule({
|
|
|
1794
1767
|
messages: { default: "In React 19, 'forwardRef' is no longer necessary. Pass 'ref' as a prop instead." },
|
|
1795
1768
|
schema: []
|
|
1796
1769
|
},
|
|
1797
|
-
name: RULE_NAME$
|
|
1798
|
-
create: create$
|
|
1770
|
+
name: RULE_NAME$36,
|
|
1771
|
+
create: create$36,
|
|
1799
1772
|
defaultOptions: []
|
|
1800
1773
|
});
|
|
1801
|
-
function create$
|
|
1774
|
+
function create$36(context) {
|
|
1802
1775
|
if (!context.sourceCode.text.includes("forwardRef")) return {};
|
|
1803
1776
|
const { version } = getSettingsFromContext(context);
|
|
1804
1777
|
if (compare(version, "19.0.0", "<")) return {};
|
|
1805
|
-
return { CallExpression(node) {
|
|
1778
|
+
return defineRuleListener({ CallExpression(node) {
|
|
1806
1779
|
if (!core.isForwardRefCall(context, node)) return;
|
|
1807
1780
|
const id = ast.getFunctionId(node);
|
|
1808
1781
|
const fix = canFix(context, node) ? getFix(context, node) : null;
|
|
@@ -1811,7 +1784,7 @@ function create$33(context) {
|
|
|
1811
1784
|
node: id ?? node,
|
|
1812
1785
|
fix
|
|
1813
1786
|
});
|
|
1814
|
-
} };
|
|
1787
|
+
} });
|
|
1815
1788
|
}
|
|
1816
1789
|
/**
|
|
1817
1790
|
* Determine whether the given CallExpression can be safely auto-fixed by replacing
|
|
@@ -1893,7 +1866,7 @@ function getComponentPropsFixes(context, fixer, node, typeArguments) {
|
|
|
1893
1866
|
|
|
1894
1867
|
//#endregion
|
|
1895
1868
|
//#region src/rules/no-implicit-key.ts
|
|
1896
|
-
const RULE_NAME$
|
|
1869
|
+
const RULE_NAME$35 = "no-implicit-key";
|
|
1897
1870
|
var no_implicit_key_default = createRule({
|
|
1898
1871
|
meta: {
|
|
1899
1872
|
type: "problem",
|
|
@@ -1901,14 +1874,14 @@ var no_implicit_key_default = createRule({
|
|
|
1901
1874
|
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}'." },
|
|
1902
1875
|
schema: []
|
|
1903
1876
|
},
|
|
1904
|
-
name: RULE_NAME$
|
|
1905
|
-
create: create$
|
|
1877
|
+
name: RULE_NAME$35,
|
|
1878
|
+
create: create$35,
|
|
1906
1879
|
defaultOptions: []
|
|
1907
1880
|
});
|
|
1908
|
-
function create$
|
|
1881
|
+
function create$35(context) {
|
|
1909
1882
|
const services = ESLintUtils.getParserServices(context, false);
|
|
1910
1883
|
const checker = services.program.getTypeChecker();
|
|
1911
|
-
return { JSXSpreadAttribute(node) {
|
|
1884
|
+
return defineRuleListener({ JSXSpreadAttribute(node) {
|
|
1912
1885
|
for (const type of unionConstituents(getConstrainedTypeAtLocation(services, node.argument))) {
|
|
1913
1886
|
const key = type.getProperty("key");
|
|
1914
1887
|
if (key == null) continue;
|
|
@@ -1918,12 +1891,12 @@ function create$32(context) {
|
|
|
1918
1891
|
node
|
|
1919
1892
|
});
|
|
1920
1893
|
}
|
|
1921
|
-
} };
|
|
1894
|
+
} });
|
|
1922
1895
|
}
|
|
1923
1896
|
|
|
1924
1897
|
//#endregion
|
|
1925
1898
|
//#region src/rules/no-leaked-conditional-rendering.ts
|
|
1926
|
-
const RULE_NAME$
|
|
1899
|
+
const RULE_NAME$34 = "no-leaked-conditional-rendering";
|
|
1927
1900
|
var no_leaked_conditional_rendering_default = createRule({
|
|
1928
1901
|
meta: {
|
|
1929
1902
|
type: "problem",
|
|
@@ -1931,11 +1904,11 @@ var no_leaked_conditional_rendering_default = createRule({
|
|
|
1931
1904
|
messages: { default: "Potential leaked value {{value}} that might cause unintentionally rendered values or rendering crashes." },
|
|
1932
1905
|
schema: []
|
|
1933
1906
|
},
|
|
1934
|
-
name: RULE_NAME$
|
|
1935
|
-
create: create$
|
|
1907
|
+
name: RULE_NAME$34,
|
|
1908
|
+
create: create$34,
|
|
1936
1909
|
defaultOptions: []
|
|
1937
1910
|
});
|
|
1938
|
-
function create$
|
|
1911
|
+
function create$34(context) {
|
|
1939
1912
|
if (!context.sourceCode.text.includes("&&")) return {};
|
|
1940
1913
|
const { version } = getSettingsFromContext(context);
|
|
1941
1914
|
const allowedVariants = [
|
|
@@ -1987,12 +1960,12 @@ function create$31(context) {
|
|
|
1987
1960
|
return match(variableDefNode).with({ init: P.select({ type: P.not(AST_NODE_TYPES.VariableDeclaration) }) }, getReportDescriptor).otherwise(() => unit);
|
|
1988
1961
|
}).otherwise(() => unit);
|
|
1989
1962
|
}
|
|
1990
|
-
return { JSXExpressionContainer: flow(getReportDescriptor, report(context)) };
|
|
1963
|
+
return defineRuleListener({ JSXExpressionContainer: flow(getReportDescriptor, report(context)) });
|
|
1991
1964
|
}
|
|
1992
1965
|
|
|
1993
1966
|
//#endregion
|
|
1994
1967
|
//#region src/rules/no-missing-component-display-name.ts
|
|
1995
|
-
const RULE_NAME$
|
|
1968
|
+
const RULE_NAME$33 = "no-missing-component-display-name";
|
|
1996
1969
|
var no_missing_component_display_name_default = createRule({
|
|
1997
1970
|
meta: {
|
|
1998
1971
|
type: "problem",
|
|
@@ -2000,11 +1973,11 @@ var no_missing_component_display_name_default = createRule({
|
|
|
2000
1973
|
messages: { default: "Add missing 'displayName' for component." },
|
|
2001
1974
|
schema: []
|
|
2002
1975
|
},
|
|
2003
|
-
name: RULE_NAME$
|
|
2004
|
-
create: create$
|
|
1976
|
+
name: RULE_NAME$33,
|
|
1977
|
+
create: create$33,
|
|
2005
1978
|
defaultOptions: []
|
|
2006
1979
|
});
|
|
2007
|
-
function create$
|
|
1980
|
+
function create$33(context) {
|
|
2008
1981
|
if (!context.sourceCode.text.includes("memo") && !context.sourceCode.text.includes("forwardRef")) return {};
|
|
2009
1982
|
const { ctx, visitor } = core.useComponentCollector(context, {
|
|
2010
1983
|
collectDisplayName: true,
|
|
@@ -2026,7 +1999,7 @@ function create$30(context) {
|
|
|
2026
1999
|
|
|
2027
2000
|
//#endregion
|
|
2028
2001
|
//#region src/rules/no-missing-context-display-name.ts
|
|
2029
|
-
const RULE_NAME$
|
|
2002
|
+
const RULE_NAME$32 = "no-missing-context-display-name";
|
|
2030
2003
|
var no_missing_context_display_name_default = createRule({
|
|
2031
2004
|
meta: {
|
|
2032
2005
|
type: "problem",
|
|
@@ -2035,15 +2008,15 @@ var no_missing_context_display_name_default = createRule({
|
|
|
2035
2008
|
messages: { default: "Add missing 'displayName' for context." },
|
|
2036
2009
|
schema: []
|
|
2037
2010
|
},
|
|
2038
|
-
name: RULE_NAME$
|
|
2039
|
-
create: create$
|
|
2011
|
+
name: RULE_NAME$32,
|
|
2012
|
+
create: create$32,
|
|
2040
2013
|
defaultOptions: []
|
|
2041
2014
|
});
|
|
2042
|
-
function create$
|
|
2015
|
+
function create$32(context) {
|
|
2043
2016
|
if (!context.sourceCode.text.includes("createContext")) return {};
|
|
2044
2017
|
const createCalls = [];
|
|
2045
2018
|
const displayNameAssignments = [];
|
|
2046
|
-
return {
|
|
2019
|
+
return defineRuleListener({
|
|
2047
2020
|
[ast.SEL_DISPLAY_NAME_ASSIGNMENT_EXPRESSION](node) {
|
|
2048
2021
|
displayNameAssignments.push(node);
|
|
2049
2022
|
},
|
|
@@ -2086,12 +2059,12 @@ function create$29(context) {
|
|
|
2086
2059
|
});
|
|
2087
2060
|
}
|
|
2088
2061
|
}
|
|
2089
|
-
};
|
|
2062
|
+
});
|
|
2090
2063
|
}
|
|
2091
2064
|
|
|
2092
2065
|
//#endregion
|
|
2093
2066
|
//#region src/rules/no-missing-key.ts
|
|
2094
|
-
const RULE_NAME$
|
|
2067
|
+
const RULE_NAME$31 = "no-missing-key";
|
|
2095
2068
|
var no_missing_key_default = createRule({
|
|
2096
2069
|
meta: {
|
|
2097
2070
|
type: "problem",
|
|
@@ -2102,11 +2075,11 @@ var no_missing_key_default = createRule({
|
|
|
2102
2075
|
},
|
|
2103
2076
|
schema: []
|
|
2104
2077
|
},
|
|
2105
|
-
name: RULE_NAME$
|
|
2106
|
-
create: create$
|
|
2078
|
+
name: RULE_NAME$31,
|
|
2079
|
+
create: create$31,
|
|
2107
2080
|
defaultOptions: []
|
|
2108
2081
|
});
|
|
2109
|
-
function create$
|
|
2082
|
+
function create$31(ctx) {
|
|
2110
2083
|
let inChildrenToArray = false;
|
|
2111
2084
|
function check(node) {
|
|
2112
2085
|
if (node.type === AST_NODE_TYPES.JSXElement) return core.getJsxAttribute(ctx, node)("key") == null ? {
|
|
@@ -2131,7 +2104,7 @@ function create$28(ctx) {
|
|
|
2131
2104
|
function checkBlock(node) {
|
|
2132
2105
|
return ast.getNestedReturnStatements(node).filter((stmt) => stmt.argument != null).map((stmt) => check(stmt.argument)).filter((d) => d != null);
|
|
2133
2106
|
}
|
|
2134
|
-
return {
|
|
2107
|
+
return defineRuleListener({
|
|
2135
2108
|
ArrayExpression(node) {
|
|
2136
2109
|
if (inChildrenToArray) return;
|
|
2137
2110
|
const elements = node.elements.filter(ast.is(AST_NODE_TYPES.JSXElement));
|
|
@@ -2165,12 +2138,12 @@ function create$28(ctx) {
|
|
|
2165
2138
|
node
|
|
2166
2139
|
});
|
|
2167
2140
|
}
|
|
2168
|
-
};
|
|
2141
|
+
});
|
|
2169
2142
|
}
|
|
2170
2143
|
|
|
2171
2144
|
//#endregion
|
|
2172
2145
|
//#region src/rules/no-misused-capture-owner-stack.ts
|
|
2173
|
-
const RULE_NAME$
|
|
2146
|
+
const RULE_NAME$30 = "no-misused-capture-owner-stack";
|
|
2174
2147
|
var no_misused_capture_owner_stack_default = createRule({
|
|
2175
2148
|
meta: {
|
|
2176
2149
|
type: "problem",
|
|
@@ -2181,14 +2154,14 @@ var no_misused_capture_owner_stack_default = createRule({
|
|
|
2181
2154
|
},
|
|
2182
2155
|
schema: []
|
|
2183
2156
|
},
|
|
2184
|
-
name: RULE_NAME$
|
|
2185
|
-
create: create$
|
|
2157
|
+
name: RULE_NAME$30,
|
|
2158
|
+
create: create$30,
|
|
2186
2159
|
defaultOptions: []
|
|
2187
2160
|
});
|
|
2188
|
-
function create$
|
|
2161
|
+
function create$30(context) {
|
|
2189
2162
|
if (!context.sourceCode.text.includes("captureOwnerStack")) return {};
|
|
2190
2163
|
const { importSource } = getSettingsFromContext(context);
|
|
2191
|
-
return {
|
|
2164
|
+
return defineRuleListener({
|
|
2192
2165
|
CallExpression(node) {
|
|
2193
2166
|
if (!core.isCaptureOwnerStackCall(context, node)) return;
|
|
2194
2167
|
if (ast.findParentNode(node, isDevelopmentOnlyCheck) == null) context.report({
|
|
@@ -2207,7 +2180,7 @@ function create$27(context) {
|
|
|
2207
2180
|
});
|
|
2208
2181
|
}
|
|
2209
2182
|
}
|
|
2210
|
-
};
|
|
2183
|
+
});
|
|
2211
2184
|
}
|
|
2212
2185
|
function isDevelopmentOnlyCheck(node) {
|
|
2213
2186
|
if (node.type !== AST_NODE_TYPES.IfStatement) return false;
|
|
@@ -2216,7 +2189,7 @@ function isDevelopmentOnlyCheck(node) {
|
|
|
2216
2189
|
|
|
2217
2190
|
//#endregion
|
|
2218
2191
|
//#region src/rules/no-nested-component-definitions.ts
|
|
2219
|
-
const RULE_NAME$
|
|
2192
|
+
const RULE_NAME$29 = "no-nested-component-definitions";
|
|
2220
2193
|
var no_nested_component_definitions_default = createRule({
|
|
2221
2194
|
meta: {
|
|
2222
2195
|
type: "problem",
|
|
@@ -2224,11 +2197,11 @@ var no_nested_component_definitions_default = createRule({
|
|
|
2224
2197
|
messages: { default: "Do not nest component definitions inside other components or props. {{suggestion}}" },
|
|
2225
2198
|
schema: []
|
|
2226
2199
|
},
|
|
2227
|
-
name: RULE_NAME$
|
|
2228
|
-
create: create$
|
|
2200
|
+
name: RULE_NAME$29,
|
|
2201
|
+
create: create$29,
|
|
2229
2202
|
defaultOptions: []
|
|
2230
2203
|
});
|
|
2231
|
-
function create$
|
|
2204
|
+
function create$29(context) {
|
|
2232
2205
|
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.DoNotIncludeFunctionDefinedInArrayPattern | core.ComponentDetectionHint.DoNotIncludeFunctionDefinedInArrayExpression | core.ComponentDetectionHint.DoNotIncludeFunctionDefinedAsArrayMapCallback;
|
|
2233
2206
|
const fCollector = core.useComponentCollector(context, { hint });
|
|
2234
2207
|
const cCollector = core.useComponentCollectorLegacy(context);
|
|
@@ -2333,7 +2306,7 @@ function isInsideCreateElementProps(context, node) {
|
|
|
2333
2306
|
|
|
2334
2307
|
//#endregion
|
|
2335
2308
|
//#region src/rules/no-nested-lazy-component-declarations.ts
|
|
2336
|
-
const RULE_NAME$
|
|
2309
|
+
const RULE_NAME$28 = "no-nested-lazy-component-declarations";
|
|
2337
2310
|
var no_nested_lazy_component_declarations_default = createRule({
|
|
2338
2311
|
meta: {
|
|
2339
2312
|
type: "problem",
|
|
@@ -2341,11 +2314,11 @@ var no_nested_lazy_component_declarations_default = createRule({
|
|
|
2341
2314
|
messages: { default: "Do not declare lazy components inside other components. Instead, always declare them at the top level of your module." },
|
|
2342
2315
|
schema: []
|
|
2343
2316
|
},
|
|
2344
|
-
name: RULE_NAME$
|
|
2345
|
-
create: create$
|
|
2317
|
+
name: RULE_NAME$28,
|
|
2318
|
+
create: create$28,
|
|
2346
2319
|
defaultOptions: []
|
|
2347
2320
|
});
|
|
2348
|
-
function create$
|
|
2321
|
+
function create$28(context) {
|
|
2349
2322
|
const hint = core.ComponentDetectionHint.None;
|
|
2350
2323
|
const collector = core.useComponentCollector(context, { hint });
|
|
2351
2324
|
const collectorLegacy = core.useComponentCollectorLegacy(context);
|
|
@@ -2374,7 +2347,7 @@ function create$25(context) {
|
|
|
2374
2347
|
|
|
2375
2348
|
//#endregion
|
|
2376
2349
|
//#region src/rules/no-redundant-should-component-update.ts
|
|
2377
|
-
const RULE_NAME$
|
|
2350
|
+
const RULE_NAME$27 = "no-redundant-should-component-update";
|
|
2378
2351
|
function isShouldComponentUpdate(node) {
|
|
2379
2352
|
return ast.isMethodOrProperty(node) && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === "shouldComponentUpdate";
|
|
2380
2353
|
}
|
|
@@ -2385,11 +2358,11 @@ var no_redundant_should_component_update_default = createRule({
|
|
|
2385
2358
|
messages: { default: "'{{componentName}}' does not need 'shouldComponentUpdate' when extending 'React.PureComponent'." },
|
|
2386
2359
|
schema: []
|
|
2387
2360
|
},
|
|
2388
|
-
name: RULE_NAME$
|
|
2389
|
-
create: create$
|
|
2361
|
+
name: RULE_NAME$27,
|
|
2362
|
+
create: create$27,
|
|
2390
2363
|
defaultOptions: []
|
|
2391
2364
|
});
|
|
2392
|
-
function create$
|
|
2365
|
+
function create$27(context) {
|
|
2393
2366
|
if (!context.sourceCode.text.includes("shouldComponentUpdate")) return {};
|
|
2394
2367
|
const { ctx, visitor } = core.useComponentCollectorLegacy(context);
|
|
2395
2368
|
return defineRuleListener(visitor, { "Program:exit"(program) {
|
|
@@ -2407,7 +2380,7 @@ function create$24(context) {
|
|
|
2407
2380
|
|
|
2408
2381
|
//#endregion
|
|
2409
2382
|
//#region src/rules/no-set-state-in-component-did-mount.ts
|
|
2410
|
-
const RULE_NAME$
|
|
2383
|
+
const RULE_NAME$26 = "no-set-state-in-component-did-mount";
|
|
2411
2384
|
var no_set_state_in_component_did_mount_default = createRule({
|
|
2412
2385
|
meta: {
|
|
2413
2386
|
type: "problem",
|
|
@@ -2415,13 +2388,13 @@ var no_set_state_in_component_did_mount_default = createRule({
|
|
|
2415
2388
|
messages: { default: "Do not call `this.setState` in `componentDidMount` outside functions such as callbacks." },
|
|
2416
2389
|
schema: []
|
|
2417
2390
|
},
|
|
2418
|
-
name: RULE_NAME$
|
|
2419
|
-
create: create$
|
|
2391
|
+
name: RULE_NAME$26,
|
|
2392
|
+
create: create$26,
|
|
2420
2393
|
defaultOptions: []
|
|
2421
2394
|
});
|
|
2422
|
-
function create$
|
|
2395
|
+
function create$26(context) {
|
|
2423
2396
|
if (!context.sourceCode.text.includes("componentDidMount")) return {};
|
|
2424
|
-
return { CallExpression(node) {
|
|
2397
|
+
return defineRuleListener({ CallExpression(node) {
|
|
2425
2398
|
if (!core.isThisSetState(node)) return;
|
|
2426
2399
|
const enclosingClassNode = ast.findParentNode(node, core.isClassComponent);
|
|
2427
2400
|
const enclosingMethodNode = ast.findParentNode(node, (n) => n === enclosingClassNode || core.isComponentDidMount(n));
|
|
@@ -2432,12 +2405,12 @@ function create$23(context) {
|
|
|
2432
2405
|
messageId: "default",
|
|
2433
2406
|
node
|
|
2434
2407
|
});
|
|
2435
|
-
} };
|
|
2408
|
+
} });
|
|
2436
2409
|
}
|
|
2437
2410
|
|
|
2438
2411
|
//#endregion
|
|
2439
2412
|
//#region src/rules/no-set-state-in-component-did-update.ts
|
|
2440
|
-
const RULE_NAME$
|
|
2413
|
+
const RULE_NAME$25 = "no-set-state-in-component-did-update";
|
|
2441
2414
|
var no_set_state_in_component_did_update_default = createRule({
|
|
2442
2415
|
meta: {
|
|
2443
2416
|
type: "problem",
|
|
@@ -2445,13 +2418,13 @@ var no_set_state_in_component_did_update_default = createRule({
|
|
|
2445
2418
|
messages: { default: "Do not call `this.setState` in `componentDidUpdate` outside functions such as callbacks." },
|
|
2446
2419
|
schema: []
|
|
2447
2420
|
},
|
|
2448
|
-
name: RULE_NAME$
|
|
2449
|
-
create: create$
|
|
2421
|
+
name: RULE_NAME$25,
|
|
2422
|
+
create: create$25,
|
|
2450
2423
|
defaultOptions: []
|
|
2451
2424
|
});
|
|
2452
|
-
function create$
|
|
2425
|
+
function create$25(context) {
|
|
2453
2426
|
if (!context.sourceCode.text.includes("componentDidUpdate")) return {};
|
|
2454
|
-
return { CallExpression(node) {
|
|
2427
|
+
return defineRuleListener({ CallExpression(node) {
|
|
2455
2428
|
if (!core.isThisSetState(node)) return;
|
|
2456
2429
|
const enclosingClassNode = ast.findParentNode(node, core.isClassComponent);
|
|
2457
2430
|
const enclosingMethodNode = ast.findParentNode(node, (n) => n === enclosingClassNode || core.isComponentDidUpdate(n));
|
|
@@ -2462,12 +2435,12 @@ function create$22(context) {
|
|
|
2462
2435
|
messageId: "default",
|
|
2463
2436
|
node
|
|
2464
2437
|
});
|
|
2465
|
-
} };
|
|
2438
|
+
} });
|
|
2466
2439
|
}
|
|
2467
2440
|
|
|
2468
2441
|
//#endregion
|
|
2469
2442
|
//#region src/rules/no-set-state-in-component-will-update.ts
|
|
2470
|
-
const RULE_NAME$
|
|
2443
|
+
const RULE_NAME$24 = "no-set-state-in-component-will-update";
|
|
2471
2444
|
var no_set_state_in_component_will_update_default = createRule({
|
|
2472
2445
|
meta: {
|
|
2473
2446
|
type: "problem",
|
|
@@ -2475,13 +2448,13 @@ var no_set_state_in_component_will_update_default = createRule({
|
|
|
2475
2448
|
messages: { default: "Do not call `this.setState` in `componentWillUpdate` outside functions such as callbacks." },
|
|
2476
2449
|
schema: []
|
|
2477
2450
|
},
|
|
2478
|
-
name: RULE_NAME$
|
|
2479
|
-
create: create$
|
|
2451
|
+
name: RULE_NAME$24,
|
|
2452
|
+
create: create$24,
|
|
2480
2453
|
defaultOptions: []
|
|
2481
2454
|
});
|
|
2482
|
-
function create$
|
|
2455
|
+
function create$24(context) {
|
|
2483
2456
|
if (!context.sourceCode.text.includes("componentWillUpdate")) return {};
|
|
2484
|
-
return { CallExpression(node) {
|
|
2457
|
+
return defineRuleListener({ CallExpression(node) {
|
|
2485
2458
|
if (!core.isThisSetState(node)) return;
|
|
2486
2459
|
const enclosingClassNode = ast.findParentNode(node, core.isClassComponent);
|
|
2487
2460
|
const enclosingMethodNode = ast.findParentNode(node, (n) => n === enclosingClassNode || core.isComponentWillUpdate(n));
|
|
@@ -2492,12 +2465,12 @@ function create$21(context) {
|
|
|
2492
2465
|
messageId: "default",
|
|
2493
2466
|
node
|
|
2494
2467
|
});
|
|
2495
|
-
} };
|
|
2468
|
+
} });
|
|
2496
2469
|
}
|
|
2497
2470
|
|
|
2498
2471
|
//#endregion
|
|
2499
2472
|
//#region src/rules/no-unnecessary-use-callback.ts
|
|
2500
|
-
const RULE_NAME$
|
|
2473
|
+
const RULE_NAME$23 = "no-unnecessary-use-callback";
|
|
2501
2474
|
var no_unnecessary_use_callback_default = createRule({
|
|
2502
2475
|
meta: {
|
|
2503
2476
|
type: "problem",
|
|
@@ -2508,13 +2481,13 @@ var no_unnecessary_use_callback_default = createRule({
|
|
|
2508
2481
|
},
|
|
2509
2482
|
schema: []
|
|
2510
2483
|
},
|
|
2511
|
-
name: RULE_NAME$
|
|
2512
|
-
create: create$
|
|
2484
|
+
name: RULE_NAME$23,
|
|
2485
|
+
create: create$23,
|
|
2513
2486
|
defaultOptions: []
|
|
2514
2487
|
});
|
|
2515
|
-
function create$
|
|
2488
|
+
function create$23(context) {
|
|
2516
2489
|
if (!context.sourceCode.text.includes("useCallback")) return {};
|
|
2517
|
-
return { VariableDeclarator(node) {
|
|
2490
|
+
return defineRuleListener({ VariableDeclarator(node) {
|
|
2518
2491
|
const { id, init } = node;
|
|
2519
2492
|
if (id.type !== AST_NODE_TYPES.Identifier || init?.type !== AST_NODE_TYPES.CallExpression || !core.isUseCallbackCall(init)) return;
|
|
2520
2493
|
const [cbk, ...rest] = context.sourceCode.getDeclaredVariables(node);
|
|
@@ -2550,7 +2523,7 @@ function create$20(context) {
|
|
|
2550
2523
|
return;
|
|
2551
2524
|
}
|
|
2552
2525
|
report(context)(checkForUsageInsideUseEffectReport);
|
|
2553
|
-
} };
|
|
2526
|
+
} });
|
|
2554
2527
|
}
|
|
2555
2528
|
function checkForUsageInsideUseEffect$1(sourceCode, node) {
|
|
2556
2529
|
if (!/use\w*Effect/u.test(sourceCode.text)) return;
|
|
@@ -2574,7 +2547,7 @@ function checkForUsageInsideUseEffect$1(sourceCode, node) {
|
|
|
2574
2547
|
|
|
2575
2548
|
//#endregion
|
|
2576
2549
|
//#region src/rules/no-unnecessary-use-memo.ts
|
|
2577
|
-
const RULE_NAME$
|
|
2550
|
+
const RULE_NAME$22 = "no-unnecessary-use-memo";
|
|
2578
2551
|
var no_unnecessary_use_memo_default = createRule({
|
|
2579
2552
|
meta: {
|
|
2580
2553
|
type: "problem",
|
|
@@ -2585,13 +2558,13 @@ var no_unnecessary_use_memo_default = createRule({
|
|
|
2585
2558
|
},
|
|
2586
2559
|
schema: []
|
|
2587
2560
|
},
|
|
2588
|
-
name: RULE_NAME$
|
|
2589
|
-
create: create$
|
|
2561
|
+
name: RULE_NAME$22,
|
|
2562
|
+
create: create$22,
|
|
2590
2563
|
defaultOptions: []
|
|
2591
2564
|
});
|
|
2592
|
-
function create$
|
|
2565
|
+
function create$22(context) {
|
|
2593
2566
|
if (!context.sourceCode.text.includes("useMemo")) return {};
|
|
2594
|
-
return { VariableDeclarator(node) {
|
|
2567
|
+
return defineRuleListener({ VariableDeclarator(node) {
|
|
2595
2568
|
const { id, init } = node;
|
|
2596
2569
|
if (id.type !== AST_NODE_TYPES.Identifier || init?.type !== AST_NODE_TYPES.CallExpression || !core.isUseMemoCall(init)) return;
|
|
2597
2570
|
const [mem, ...rest] = context.sourceCode.getDeclaredVariables(node);
|
|
@@ -2631,7 +2604,7 @@ function create$19(context) {
|
|
|
2631
2604
|
return;
|
|
2632
2605
|
}
|
|
2633
2606
|
report(context)(checkForUsageInsideUseEffectReport);
|
|
2634
|
-
} };
|
|
2607
|
+
} });
|
|
2635
2608
|
}
|
|
2636
2609
|
function checkForUsageInsideUseEffect(sourceCode, node) {
|
|
2637
2610
|
if (!/use\w*Effect/u.test(sourceCode.text)) return;
|
|
@@ -2655,7 +2628,7 @@ function checkForUsageInsideUseEffect(sourceCode, node) {
|
|
|
2655
2628
|
|
|
2656
2629
|
//#endregion
|
|
2657
2630
|
//#region src/rules/no-unnecessary-use-prefix.ts
|
|
2658
|
-
const RULE_NAME$
|
|
2631
|
+
const RULE_NAME$21 = "no-unnecessary-use-prefix";
|
|
2659
2632
|
const WELL_KNOWN_HOOKS = ["useMDXComponents"];
|
|
2660
2633
|
function containsUseComments(context, node) {
|
|
2661
2634
|
return context.sourceCode.getCommentsInside(node).some(({ value }) => /use\([\s\S]*?\)/u.test(value) || /use[A-Z0-9]\w*\([\s\S]*?\)/u.test(value));
|
|
@@ -2667,11 +2640,11 @@ var no_unnecessary_use_prefix_default = createRule({
|
|
|
2667
2640
|
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." },
|
|
2668
2641
|
schema: []
|
|
2669
2642
|
},
|
|
2670
|
-
name: RULE_NAME$
|
|
2671
|
-
create: create$
|
|
2643
|
+
name: RULE_NAME$21,
|
|
2644
|
+
create: create$21,
|
|
2672
2645
|
defaultOptions: []
|
|
2673
2646
|
});
|
|
2674
|
-
function create$
|
|
2647
|
+
function create$21(context) {
|
|
2675
2648
|
const { ctx, visitor } = core.useHookCollector(context);
|
|
2676
2649
|
return defineRuleListener(visitor, { "Program:exit"(program) {
|
|
2677
2650
|
for (const { id, name, node, hookCalls } of ctx.getAllHooks(program)) {
|
|
@@ -2691,7 +2664,7 @@ function create$18(context) {
|
|
|
2691
2664
|
|
|
2692
2665
|
//#endregion
|
|
2693
2666
|
//#region src/rules/no-unsafe-component-will-mount.ts
|
|
2694
|
-
const RULE_NAME$
|
|
2667
|
+
const RULE_NAME$20 = "no-unsafe-component-will-mount";
|
|
2695
2668
|
var no_unsafe_component_will_mount_default = createRule({
|
|
2696
2669
|
meta: {
|
|
2697
2670
|
type: "problem",
|
|
@@ -2699,11 +2672,11 @@ var no_unsafe_component_will_mount_default = createRule({
|
|
|
2699
2672
|
messages: { default: "Do not use 'UNSAFE_componentWillMount'." },
|
|
2700
2673
|
schema: []
|
|
2701
2674
|
},
|
|
2702
|
-
name: RULE_NAME$
|
|
2703
|
-
create: create$
|
|
2675
|
+
name: RULE_NAME$20,
|
|
2676
|
+
create: create$20,
|
|
2704
2677
|
defaultOptions: []
|
|
2705
2678
|
});
|
|
2706
|
-
function create$
|
|
2679
|
+
function create$20(context) {
|
|
2707
2680
|
if (!context.sourceCode.text.includes("UNSAFE_componentWillMount")) return {};
|
|
2708
2681
|
const { ctx, visitor } = core.useComponentCollectorLegacy(context);
|
|
2709
2682
|
return defineRuleListener(visitor, { "Program:exit"(program) {
|
|
@@ -2719,7 +2692,7 @@ function create$17(context) {
|
|
|
2719
2692
|
|
|
2720
2693
|
//#endregion
|
|
2721
2694
|
//#region src/rules/no-unsafe-component-will-receive-props.ts
|
|
2722
|
-
const RULE_NAME$
|
|
2695
|
+
const RULE_NAME$19 = "no-unsafe-component-will-receive-props";
|
|
2723
2696
|
var no_unsafe_component_will_receive_props_default = createRule({
|
|
2724
2697
|
meta: {
|
|
2725
2698
|
type: "problem",
|
|
@@ -2727,11 +2700,11 @@ var no_unsafe_component_will_receive_props_default = createRule({
|
|
|
2727
2700
|
messages: { default: "Do not use 'UNSAFE_componentWillReceiveProps'." },
|
|
2728
2701
|
schema: []
|
|
2729
2702
|
},
|
|
2730
|
-
name: RULE_NAME$
|
|
2731
|
-
create: create$
|
|
2703
|
+
name: RULE_NAME$19,
|
|
2704
|
+
create: create$19,
|
|
2732
2705
|
defaultOptions: []
|
|
2733
2706
|
});
|
|
2734
|
-
function create$
|
|
2707
|
+
function create$19(context) {
|
|
2735
2708
|
if (!context.sourceCode.text.includes("UNSAFE_componentWillReceiveProps")) return {};
|
|
2736
2709
|
const { ctx, visitor } = core.useComponentCollectorLegacy(context);
|
|
2737
2710
|
return defineRuleListener(visitor, { "Program:exit"(program) {
|
|
@@ -2747,7 +2720,7 @@ function create$16(context) {
|
|
|
2747
2720
|
|
|
2748
2721
|
//#endregion
|
|
2749
2722
|
//#region src/rules/no-unsafe-component-will-update.ts
|
|
2750
|
-
const RULE_NAME$
|
|
2723
|
+
const RULE_NAME$18 = "no-unsafe-component-will-update";
|
|
2751
2724
|
var no_unsafe_component_will_update_default = createRule({
|
|
2752
2725
|
meta: {
|
|
2753
2726
|
type: "problem",
|
|
@@ -2755,11 +2728,11 @@ var no_unsafe_component_will_update_default = createRule({
|
|
|
2755
2728
|
messages: { default: "Do not use 'UNSAFE_componentWillUpdate'." },
|
|
2756
2729
|
schema: []
|
|
2757
2730
|
},
|
|
2758
|
-
name: RULE_NAME$
|
|
2759
|
-
create: create$
|
|
2731
|
+
name: RULE_NAME$18,
|
|
2732
|
+
create: create$18,
|
|
2760
2733
|
defaultOptions: []
|
|
2761
2734
|
});
|
|
2762
|
-
function create$
|
|
2735
|
+
function create$18(context) {
|
|
2763
2736
|
if (!context.sourceCode.text.includes("UNSAFE_componentWillUpdate")) return {};
|
|
2764
2737
|
const { ctx, visitor } = core.useComponentCollectorLegacy(context);
|
|
2765
2738
|
return defineRuleListener(visitor, { "Program:exit"(program) {
|
|
@@ -2775,7 +2748,7 @@ function create$15(context) {
|
|
|
2775
2748
|
|
|
2776
2749
|
//#endregion
|
|
2777
2750
|
//#region src/rules/no-unstable-context-value.ts
|
|
2778
|
-
const RULE_NAME$
|
|
2751
|
+
const RULE_NAME$17 = "no-unstable-context-value";
|
|
2779
2752
|
var no_unstable_context_value_default = createRule({
|
|
2780
2753
|
meta: {
|
|
2781
2754
|
type: "problem",
|
|
@@ -2783,11 +2756,11 @@ var no_unstable_context_value_default = createRule({
|
|
|
2783
2756
|
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}}" },
|
|
2784
2757
|
schema: []
|
|
2785
2758
|
},
|
|
2786
|
-
name: RULE_NAME$
|
|
2787
|
-
create: create$
|
|
2759
|
+
name: RULE_NAME$17,
|
|
2760
|
+
create: create$17,
|
|
2788
2761
|
defaultOptions: []
|
|
2789
2762
|
});
|
|
2790
|
-
function create$
|
|
2763
|
+
function create$17(context) {
|
|
2791
2764
|
const { isCompilerEnabled, version } = getSettingsFromContext(context);
|
|
2792
2765
|
if (isCompilerEnabled && ast.isDirectiveInFile(context.sourceCode.ast, "use memo")) return {};
|
|
2793
2766
|
const isReact18OrBelow = compare(version, "19.0.0", "<");
|
|
@@ -2836,7 +2809,7 @@ function isContextName(name, isReact18OrBelow) {
|
|
|
2836
2809
|
|
|
2837
2810
|
//#endregion
|
|
2838
2811
|
//#region src/rules/no-unstable-default-props.ts
|
|
2839
|
-
const RULE_NAME$
|
|
2812
|
+
const RULE_NAME$16 = "no-unstable-default-props";
|
|
2840
2813
|
const defaultOptions$1 = [{ safeDefaultProps: [] }];
|
|
2841
2814
|
const schema$1 = [{
|
|
2842
2815
|
type: "object",
|
|
@@ -2853,8 +2826,8 @@ var no_unstable_default_props_default = createRule({
|
|
|
2853
2826
|
messages: { default: "A/an '{{kind}}' as default prop. This could lead to potential infinite render loop in React. Use a variable instead of '{{kind}}'." },
|
|
2854
2827
|
schema: schema$1
|
|
2855
2828
|
},
|
|
2856
|
-
name: RULE_NAME$
|
|
2857
|
-
create: create$
|
|
2829
|
+
name: RULE_NAME$16,
|
|
2830
|
+
create: create$16,
|
|
2858
2831
|
defaultOptions: defaultOptions$1
|
|
2859
2832
|
});
|
|
2860
2833
|
function extractIdentifier(node) {
|
|
@@ -2865,7 +2838,7 @@ function extractIdentifier(node) {
|
|
|
2865
2838
|
}
|
|
2866
2839
|
return null;
|
|
2867
2840
|
}
|
|
2868
|
-
function create$
|
|
2841
|
+
function create$16(context, [options]) {
|
|
2869
2842
|
const { isCompilerEnabled } = getSettingsFromContext(context);
|
|
2870
2843
|
if (isCompilerEnabled && ast.isDirectiveInFile(context.sourceCode.ast, "use memo")) return {};
|
|
2871
2844
|
const { ctx, visitor } = core.useComponentCollector(context);
|
|
@@ -2910,7 +2883,7 @@ function create$13(context, [options]) {
|
|
|
2910
2883
|
|
|
2911
2884
|
//#endregion
|
|
2912
2885
|
//#region src/rules/no-unused-class-component-members.ts
|
|
2913
|
-
const RULE_NAME$
|
|
2886
|
+
const RULE_NAME$15 = "no-unused-class-component-members";
|
|
2914
2887
|
const LIFECYCLE_METHODS = new Set([
|
|
2915
2888
|
"componentDidCatch",
|
|
2916
2889
|
"componentDidMount",
|
|
@@ -2941,11 +2914,11 @@ var no_unused_class_component_members_default = createRule({
|
|
|
2941
2914
|
messages: { default: "Unused method or property '{{methodName}}'' of class '{{className}}'." },
|
|
2942
2915
|
schema: []
|
|
2943
2916
|
},
|
|
2944
|
-
name: RULE_NAME$
|
|
2945
|
-
create: create$
|
|
2917
|
+
name: RULE_NAME$15,
|
|
2918
|
+
create: create$15,
|
|
2946
2919
|
defaultOptions: []
|
|
2947
2920
|
});
|
|
2948
|
-
function create$
|
|
2921
|
+
function create$15(context) {
|
|
2949
2922
|
const classStack = [];
|
|
2950
2923
|
const methodStack = [];
|
|
2951
2924
|
const propertyDefs = /* @__PURE__ */ new WeakMap();
|
|
@@ -2987,7 +2960,7 @@ function create$12(context) {
|
|
|
2987
2960
|
function methodExit() {
|
|
2988
2961
|
methodStack.pop();
|
|
2989
2962
|
}
|
|
2990
|
-
return {
|
|
2963
|
+
return defineRuleListener({
|
|
2991
2964
|
ClassDeclaration: classEnter,
|
|
2992
2965
|
"ClassDeclaration:exit": classExit,
|
|
2993
2966
|
ClassExpression: classEnter,
|
|
@@ -3021,12 +2994,12 @@ function create$12(context) {
|
|
|
3021
2994
|
}
|
|
3022
2995
|
}
|
|
3023
2996
|
}
|
|
3024
|
-
};
|
|
2997
|
+
});
|
|
3025
2998
|
}
|
|
3026
2999
|
|
|
3027
3000
|
//#endregion
|
|
3028
3001
|
//#region src/rules/no-unused-props.ts
|
|
3029
|
-
const RULE_NAME$
|
|
3002
|
+
const RULE_NAME$14 = "no-unused-props";
|
|
3030
3003
|
var no_unused_props_default = createRule({
|
|
3031
3004
|
meta: {
|
|
3032
3005
|
type: "problem",
|
|
@@ -3034,11 +3007,11 @@ var no_unused_props_default = createRule({
|
|
|
3034
3007
|
messages: { default: "Prop `{{name}}` is declared but never used" },
|
|
3035
3008
|
schema: []
|
|
3036
3009
|
},
|
|
3037
|
-
name: RULE_NAME$
|
|
3038
|
-
create: create$
|
|
3010
|
+
name: RULE_NAME$14,
|
|
3011
|
+
create: create$14,
|
|
3039
3012
|
defaultOptions: []
|
|
3040
3013
|
});
|
|
3041
|
-
function create$
|
|
3014
|
+
function create$14(context) {
|
|
3042
3015
|
const services = ESLintUtils.getParserServices(context, false);
|
|
3043
3016
|
const { ctx, visitor } = core.useComponentCollector(context);
|
|
3044
3017
|
return defineRuleListener(visitor, { "Program:exit"(program) {
|
|
@@ -3136,7 +3109,7 @@ function reportUnusedProp(context, services, prop) {
|
|
|
3136
3109
|
|
|
3137
3110
|
//#endregion
|
|
3138
3111
|
//#region src/rules/no-unused-state.ts
|
|
3139
|
-
const RULE_NAME$
|
|
3112
|
+
const RULE_NAME$13 = "no-unused-state";
|
|
3140
3113
|
function isKeyLiteral(node, key) {
|
|
3141
3114
|
return match(key).with({ type: AST_NODE_TYPES.Literal }, constTrue).with({
|
|
3142
3115
|
type: AST_NODE_TYPES.TemplateLiteral,
|
|
@@ -3150,11 +3123,11 @@ var no_unused_state_default = createRule({
|
|
|
3150
3123
|
messages: { default: "Unused class component state in '{{className}}'" },
|
|
3151
3124
|
schema: []
|
|
3152
3125
|
},
|
|
3153
|
-
name: RULE_NAME$
|
|
3154
|
-
create: create$
|
|
3126
|
+
name: RULE_NAME$13,
|
|
3127
|
+
create: create$13,
|
|
3155
3128
|
defaultOptions: []
|
|
3156
3129
|
});
|
|
3157
|
-
function create$
|
|
3130
|
+
function create$13(context) {
|
|
3158
3131
|
const classStack = [];
|
|
3159
3132
|
const methodStack = [];
|
|
3160
3133
|
const constructorStack = [];
|
|
@@ -3202,7 +3175,7 @@ function create$10(context) {
|
|
|
3202
3175
|
function constructorExit() {
|
|
3203
3176
|
constructorStack.pop();
|
|
3204
3177
|
}
|
|
3205
|
-
return {
|
|
3178
|
+
return defineRuleListener({
|
|
3206
3179
|
AssignmentExpression(node) {
|
|
3207
3180
|
if (!core.isAssignmentToThisState(node)) return;
|
|
3208
3181
|
const currentClass = classStack.at(-1);
|
|
@@ -3258,12 +3231,12 @@ function create$10(context) {
|
|
|
3258
3231
|
isUsed: true
|
|
3259
3232
|
});
|
|
3260
3233
|
}
|
|
3261
|
-
};
|
|
3234
|
+
});
|
|
3262
3235
|
}
|
|
3263
3236
|
|
|
3264
3237
|
//#endregion
|
|
3265
3238
|
//#region src/rules/no-use-context.ts
|
|
3266
|
-
const RULE_NAME$
|
|
3239
|
+
const RULE_NAME$12 = "no-use-context";
|
|
3267
3240
|
var no_use_context_default = createRule({
|
|
3268
3241
|
meta: {
|
|
3269
3242
|
type: "problem",
|
|
@@ -3272,16 +3245,16 @@ var no_use_context_default = createRule({
|
|
|
3272
3245
|
messages: { default: "In React 19, 'use' is preferred over 'useContext' because it is more flexible." },
|
|
3273
3246
|
schema: []
|
|
3274
3247
|
},
|
|
3275
|
-
name: RULE_NAME$
|
|
3276
|
-
create: create$
|
|
3248
|
+
name: RULE_NAME$12,
|
|
3249
|
+
create: create$12,
|
|
3277
3250
|
defaultOptions: []
|
|
3278
3251
|
});
|
|
3279
|
-
function create$
|
|
3252
|
+
function create$12(context) {
|
|
3280
3253
|
if (!context.sourceCode.text.includes("useContext")) return {};
|
|
3281
3254
|
const settings = getSettingsFromContext(context);
|
|
3282
3255
|
if (compare(settings.version, "19.0.0", "<")) return {};
|
|
3283
3256
|
const hookCalls = /* @__PURE__ */ new Set();
|
|
3284
|
-
return {
|
|
3257
|
+
return defineRuleListener({
|
|
3285
3258
|
CallExpression(node) {
|
|
3286
3259
|
if (!core.isHookCall(node)) return;
|
|
3287
3260
|
hookCalls.add(node);
|
|
@@ -3328,7 +3301,7 @@ function create$9(context) {
|
|
|
3328
3301
|
});
|
|
3329
3302
|
}
|
|
3330
3303
|
}
|
|
3331
|
-
};
|
|
3304
|
+
});
|
|
3332
3305
|
}
|
|
3333
3306
|
function getCorrelativeTokens(context, node) {
|
|
3334
3307
|
const tokenBefore = context.sourceCode.getTokenBefore(node);
|
|
@@ -3341,7 +3314,7 @@ function getCorrelativeTokens(context, node) {
|
|
|
3341
3314
|
|
|
3342
3315
|
//#endregion
|
|
3343
3316
|
//#region src/rules/no-useless-forward-ref.ts
|
|
3344
|
-
const RULE_NAME$
|
|
3317
|
+
const RULE_NAME$11 = "no-useless-forward-ref";
|
|
3345
3318
|
var no_useless_forward_ref_default = createRule({
|
|
3346
3319
|
meta: {
|
|
3347
3320
|
type: "problem",
|
|
@@ -3349,12 +3322,12 @@ var no_useless_forward_ref_default = createRule({
|
|
|
3349
3322
|
messages: { default: "A 'forwardRef' is used with this component but no 'ref' parameter is set." },
|
|
3350
3323
|
schema: []
|
|
3351
3324
|
},
|
|
3352
|
-
name: RULE_NAME$
|
|
3353
|
-
create: create$
|
|
3325
|
+
name: RULE_NAME$11,
|
|
3326
|
+
create: create$11,
|
|
3354
3327
|
defaultOptions: []
|
|
3355
3328
|
});
|
|
3356
|
-
function create$
|
|
3357
|
-
return { CallExpression(node) {
|
|
3329
|
+
function create$11(context) {
|
|
3330
|
+
return defineRuleListener({ CallExpression(node) {
|
|
3358
3331
|
if (!core.isForwardRefCall(context, node)) return;
|
|
3359
3332
|
const [component] = node.arguments;
|
|
3360
3333
|
if (component == null || !ast.isFunction(component)) return;
|
|
@@ -3363,12 +3336,12 @@ function create$8(context) {
|
|
|
3363
3336
|
messageId: "default",
|
|
3364
3337
|
node: node.callee
|
|
3365
3338
|
});
|
|
3366
|
-
} };
|
|
3339
|
+
} });
|
|
3367
3340
|
}
|
|
3368
3341
|
|
|
3369
3342
|
//#endregion
|
|
3370
3343
|
//#region src/rules/no-useless-fragment.ts
|
|
3371
|
-
const RULE_NAME$
|
|
3344
|
+
const RULE_NAME$10 = "no-useless-fragment";
|
|
3372
3345
|
const defaultOptions = [{
|
|
3373
3346
|
allowEmptyFragment: false,
|
|
3374
3347
|
allowExpressions: true
|
|
@@ -3396,11 +3369,11 @@ var no_useless_fragment_default = createRule({
|
|
|
3396
3369
|
messages: { default: "A fragment {{reason}} is useless." },
|
|
3397
3370
|
schema
|
|
3398
3371
|
},
|
|
3399
|
-
name: RULE_NAME$
|
|
3400
|
-
create: create$
|
|
3372
|
+
name: RULE_NAME$10,
|
|
3373
|
+
create: create$10,
|
|
3401
3374
|
defaultOptions
|
|
3402
3375
|
});
|
|
3403
|
-
function create$
|
|
3376
|
+
function create$10(context, [option]) {
|
|
3404
3377
|
const { allowEmptyFragment = false, allowExpressions = true } = option;
|
|
3405
3378
|
const jsxConfig = {
|
|
3406
3379
|
...core.getJsxConfigFromContext(context),
|
|
@@ -3473,7 +3446,7 @@ function create$7(context, [option]) {
|
|
|
3473
3446
|
if (node.children.length === 0) return false;
|
|
3474
3447
|
return !node.children.some((child) => core.isJsxText(child) && !isWhiteSpace(child) || ast.is(AST_NODE_TYPES.JSXExpressionContainer)(child));
|
|
3475
3448
|
}
|
|
3476
|
-
return {
|
|
3449
|
+
return defineRuleListener({
|
|
3477
3450
|
JSXElement(node) {
|
|
3478
3451
|
if (!core.isJsxFragmentElement(context, node, jsxConfig)) return;
|
|
3479
3452
|
checkNode(context, node);
|
|
@@ -3481,7 +3454,7 @@ function create$7(context, [option]) {
|
|
|
3481
3454
|
JSXFragment(node) {
|
|
3482
3455
|
checkNode(context, node);
|
|
3483
3456
|
}
|
|
3484
|
-
};
|
|
3457
|
+
});
|
|
3485
3458
|
}
|
|
3486
3459
|
/**
|
|
3487
3460
|
* Check if a Literal or JSXText node is whitespace
|
|
@@ -3508,7 +3481,7 @@ function trimLikeReact(text) {
|
|
|
3508
3481
|
|
|
3509
3482
|
//#endregion
|
|
3510
3483
|
//#region src/rules/prefer-destructuring-assignment.ts
|
|
3511
|
-
const RULE_NAME$
|
|
3484
|
+
const RULE_NAME$9 = "prefer-destructuring-assignment";
|
|
3512
3485
|
var prefer_destructuring_assignment_default = createRule({
|
|
3513
3486
|
meta: {
|
|
3514
3487
|
type: "problem",
|
|
@@ -3516,11 +3489,11 @@ var prefer_destructuring_assignment_default = createRule({
|
|
|
3516
3489
|
messages: { default: "Use destructuring assignment for component props." },
|
|
3517
3490
|
schema: []
|
|
3518
3491
|
},
|
|
3519
|
-
name: RULE_NAME$
|
|
3520
|
-
create: create$
|
|
3492
|
+
name: RULE_NAME$9,
|
|
3493
|
+
create: create$9,
|
|
3521
3494
|
defaultOptions: []
|
|
3522
3495
|
});
|
|
3523
|
-
function create$
|
|
3496
|
+
function create$9(context) {
|
|
3524
3497
|
const { ctx, visitor } = core.useComponentCollector(context);
|
|
3525
3498
|
return defineRuleListener(visitor, { "Program:exit"(program) {
|
|
3526
3499
|
for (const component of ctx.getAllComponents(program)) {
|
|
@@ -3544,7 +3517,7 @@ function create$6(context) {
|
|
|
3544
3517
|
|
|
3545
3518
|
//#endregion
|
|
3546
3519
|
//#region src/rules/prefer-namespace-import.ts
|
|
3547
|
-
const RULE_NAME$
|
|
3520
|
+
const RULE_NAME$8 = "prefer-namespace-import";
|
|
3548
3521
|
var prefer_namespace_import_default = createRule({
|
|
3549
3522
|
meta: {
|
|
3550
3523
|
type: "problem",
|
|
@@ -3553,13 +3526,13 @@ var prefer_namespace_import_default = createRule({
|
|
|
3553
3526
|
messages: { default: "Prefer importing React as 'import * as React from \"{{importSource}}\"';" },
|
|
3554
3527
|
schema: []
|
|
3555
3528
|
},
|
|
3556
|
-
name: RULE_NAME$
|
|
3557
|
-
create: create$
|
|
3529
|
+
name: RULE_NAME$8,
|
|
3530
|
+
create: create$8,
|
|
3558
3531
|
defaultOptions: []
|
|
3559
3532
|
});
|
|
3560
|
-
function create$
|
|
3533
|
+
function create$8(context) {
|
|
3561
3534
|
const { importSource } = getSettingsFromContext(context);
|
|
3562
|
-
return { [`ImportDeclaration[source.value="${importSource}"] ImportDefaultSpecifier`](node) {
|
|
3535
|
+
return defineRuleListener({ [`ImportDeclaration[source.value="${importSource}"] ImportDefaultSpecifier`](node) {
|
|
3563
3536
|
const hasOtherSpecifiers = node.parent.specifiers.length > 1;
|
|
3564
3537
|
context.report({
|
|
3565
3538
|
messageId: "default",
|
|
@@ -3576,12 +3549,12 @@ function create$5(context) {
|
|
|
3576
3549
|
return fixer.replaceText(node.parent, [`${importStringPrefix} * as ${node.local.name} from ${importSourceQuoted}${semi}`, `${importStringPrefix} ${specifiers} from ${importSourceQuoted}${semi}`].join("\n"));
|
|
3577
3550
|
}
|
|
3578
3551
|
});
|
|
3579
|
-
} };
|
|
3552
|
+
} });
|
|
3580
3553
|
}
|
|
3581
3554
|
|
|
3582
3555
|
//#endregion
|
|
3583
3556
|
//#region src/rules/prefer-read-only-props.ts
|
|
3584
|
-
const RULE_NAME$
|
|
3557
|
+
const RULE_NAME$7 = "prefer-read-only-props";
|
|
3585
3558
|
var prefer_read_only_props_default = createRule({
|
|
3586
3559
|
meta: {
|
|
3587
3560
|
type: "problem",
|
|
@@ -3589,11 +3562,11 @@ var prefer_read_only_props_default = createRule({
|
|
|
3589
3562
|
messages: { default: "A function component's props should be read-only." },
|
|
3590
3563
|
schema: []
|
|
3591
3564
|
},
|
|
3592
|
-
name: RULE_NAME$
|
|
3593
|
-
create: create$
|
|
3565
|
+
name: RULE_NAME$7,
|
|
3566
|
+
create: create$7,
|
|
3594
3567
|
defaultOptions: []
|
|
3595
3568
|
});
|
|
3596
|
-
function create$
|
|
3569
|
+
function create$7(context) {
|
|
3597
3570
|
const services = ESLintUtils.getParserServices(context, false);
|
|
3598
3571
|
const checker = services.program.getTypeChecker();
|
|
3599
3572
|
const { ctx, visitor } = core.useComponentCollector(context);
|
|
@@ -3634,7 +3607,7 @@ function isClassOrInterfaceReadonlyLoose(checker, type) {
|
|
|
3634
3607
|
|
|
3635
3608
|
//#endregion
|
|
3636
3609
|
//#region src/rules/prefer-use-state-lazy-initialization.ts
|
|
3637
|
-
const RULE_NAME$
|
|
3610
|
+
const RULE_NAME$6 = "prefer-use-state-lazy-initialization";
|
|
3638
3611
|
const ALLOW_LIST = [
|
|
3639
3612
|
"Boolean",
|
|
3640
3613
|
"String",
|
|
@@ -3647,12 +3620,12 @@ var prefer_use_state_lazy_initialization_default = createRule({
|
|
|
3647
3620
|
messages: { default: "To prevent re-computation, consider using lazy initial state for useState calls that involve function calls. Ex: 'useState(() => getValue())'." },
|
|
3648
3621
|
schema: []
|
|
3649
3622
|
},
|
|
3650
|
-
name: RULE_NAME$
|
|
3651
|
-
create: create$
|
|
3623
|
+
name: RULE_NAME$6,
|
|
3624
|
+
create: create$6,
|
|
3652
3625
|
defaultOptions: []
|
|
3653
3626
|
});
|
|
3654
|
-
function create$
|
|
3655
|
-
return { CallExpression(node) {
|
|
3627
|
+
function create$6(context) {
|
|
3628
|
+
return defineRuleListener({ CallExpression(node) {
|
|
3656
3629
|
if (!core.isUseStateCall(node)) return;
|
|
3657
3630
|
const [useStateInput] = node.arguments;
|
|
3658
3631
|
if (useStateInput == null) return;
|
|
@@ -3675,12 +3648,275 @@ function create$3(context) {
|
|
|
3675
3648
|
node: expr
|
|
3676
3649
|
});
|
|
3677
3650
|
}
|
|
3678
|
-
} };
|
|
3651
|
+
} });
|
|
3652
|
+
}
|
|
3653
|
+
|
|
3654
|
+
//#endregion
|
|
3655
|
+
//#region src/rules/purity.ts
|
|
3656
|
+
const RULE_NAME$5 = "purity";
|
|
3657
|
+
function isImpureMemberCall(node) {
|
|
3658
|
+
if (node.callee.type !== AST_NODE_TYPES.MemberExpression) return false;
|
|
3659
|
+
const { object, property } = node.callee;
|
|
3660
|
+
if (object.type !== AST_NODE_TYPES.Identifier) return false;
|
|
3661
|
+
if (property.type !== AST_NODE_TYPES.Identifier) return false;
|
|
3662
|
+
const methods = IMPURE_FUNCTIONS.get(object.name);
|
|
3663
|
+
if (methods == null) return false;
|
|
3664
|
+
return methods.has(property.name);
|
|
3665
|
+
}
|
|
3666
|
+
function isImpureNewExpression(node) {
|
|
3667
|
+
if (node.callee.type !== AST_NODE_TYPES.Identifier) return false;
|
|
3668
|
+
return IMPURE_CONSTRUCTORS.has(node.callee.name);
|
|
3669
|
+
}
|
|
3670
|
+
function getImpureCallName(node) {
|
|
3671
|
+
if (node.callee.type !== AST_NODE_TYPES.MemberExpression) return null;
|
|
3672
|
+
const { object, property } = node.callee;
|
|
3673
|
+
if (object.type !== AST_NODE_TYPES.Identifier) return null;
|
|
3674
|
+
if (property.type !== AST_NODE_TYPES.Identifier) return null;
|
|
3675
|
+
return `${object.name}.${property.name}()`;
|
|
3676
|
+
}
|
|
3677
|
+
function getImpureNewName(node) {
|
|
3678
|
+
if (node.callee.type !== AST_NODE_TYPES.Identifier) return null;
|
|
3679
|
+
return `new ${node.callee.name}()`;
|
|
3680
|
+
}
|
|
3681
|
+
var purity_default = createRule({
|
|
3682
|
+
meta: {
|
|
3683
|
+
type: "problem",
|
|
3684
|
+
docs: { description: "Validates that components and hooks are pure by checking that they do not call known-impure functions during render." },
|
|
3685
|
+
messages: { default: "Do not call '{{name}}' during render. Components and hooks must be pure. Move this call into an event handler, effect, or state initializer." },
|
|
3686
|
+
schema: []
|
|
3687
|
+
},
|
|
3688
|
+
name: RULE_NAME$5,
|
|
3689
|
+
create: create$5,
|
|
3690
|
+
defaultOptions: []
|
|
3691
|
+
});
|
|
3692
|
+
function create$5(context) {
|
|
3693
|
+
const hCollector = core.useHookCollector(context);
|
|
3694
|
+
const cCollector = core.useComponentCollector(context);
|
|
3695
|
+
const cExprs = [];
|
|
3696
|
+
const nExprs = [];
|
|
3697
|
+
return defineRuleListener(hCollector.visitor, cCollector.visitor, {
|
|
3698
|
+
CallExpression(node) {
|
|
3699
|
+
if (!isImpureMemberCall(node)) return;
|
|
3700
|
+
const name = getImpureCallName(node);
|
|
3701
|
+
if (name == null) return;
|
|
3702
|
+
const func = ast.findParentNode(node, ast.isFunction);
|
|
3703
|
+
if (func == null) return;
|
|
3704
|
+
cExprs.push({
|
|
3705
|
+
name,
|
|
3706
|
+
node,
|
|
3707
|
+
func
|
|
3708
|
+
});
|
|
3709
|
+
},
|
|
3710
|
+
NewExpression(node) {
|
|
3711
|
+
if (!isImpureNewExpression(node)) return;
|
|
3712
|
+
const name = getImpureNewName(node);
|
|
3713
|
+
if (name == null) return;
|
|
3714
|
+
const func = ast.findParentNode(node, ast.isFunction);
|
|
3715
|
+
if (func == null) return;
|
|
3716
|
+
nExprs.push({
|
|
3717
|
+
name,
|
|
3718
|
+
node,
|
|
3719
|
+
func
|
|
3720
|
+
});
|
|
3721
|
+
},
|
|
3722
|
+
"Program:exit"(node) {
|
|
3723
|
+
const components = cCollector.ctx.getAllComponents(node);
|
|
3724
|
+
const hooks = hCollector.ctx.getAllHooks(node);
|
|
3725
|
+
const funcs = [...components, ...hooks];
|
|
3726
|
+
for (const { name, node, func } of [...cExprs, ...nExprs]) {
|
|
3727
|
+
if (!funcs.some((f) => f.node === func)) continue;
|
|
3728
|
+
context.report({
|
|
3729
|
+
messageId: "default",
|
|
3730
|
+
node,
|
|
3731
|
+
data: { name }
|
|
3732
|
+
});
|
|
3733
|
+
}
|
|
3734
|
+
}
|
|
3735
|
+
});
|
|
3736
|
+
}
|
|
3737
|
+
|
|
3738
|
+
//#endregion
|
|
3739
|
+
//#region src/rules/refs.ts
|
|
3740
|
+
const RULE_NAME$4 = "refs";
|
|
3741
|
+
function isWriteAccess(node) {
|
|
3742
|
+
const { parent } = node;
|
|
3743
|
+
if (parent.type === AST_NODE_TYPES.AssignmentExpression && parent.left === node) return true;
|
|
3744
|
+
if (parent.type === AST_NODE_TYPES.UpdateExpression && parent.argument === node) return true;
|
|
3745
|
+
return false;
|
|
3746
|
+
}
|
|
3747
|
+
function isInsideNestedFunction(node, boundary) {
|
|
3748
|
+
let current = node.parent;
|
|
3749
|
+
while (current != null && current !== boundary) {
|
|
3750
|
+
if (ast.isFunction(current)) return true;
|
|
3751
|
+
current = current.parent;
|
|
3752
|
+
}
|
|
3753
|
+
return false;
|
|
3754
|
+
}
|
|
3755
|
+
/**
|
|
3756
|
+
* Check if a ref.current access is part of a lazy initialization pattern.
|
|
3757
|
+
*
|
|
3758
|
+
* Standard:
|
|
3759
|
+
* if (ref.current === null) { ref.current = value; }
|
|
3760
|
+
*
|
|
3761
|
+
* Inverted (with early return):
|
|
3762
|
+
* if (ref.current !== null) { return ...; }
|
|
3763
|
+
* ref.current = computeValue();
|
|
3764
|
+
* @param node The MemberExpression node for ref.current
|
|
3765
|
+
* @param isWrite Whether this access is a write (assignment/update) or a read
|
|
3766
|
+
* @returns true if this access is part of a lazy initialization pattern and should be allowed during render
|
|
3767
|
+
*/
|
|
3768
|
+
function isPartOfLazyInitialization(node, isWrite) {
|
|
3769
|
+
if (node.object.type !== AST_NODE_TYPES.Identifier) return false;
|
|
3770
|
+
const refName = node.object.name;
|
|
3771
|
+
if (isInNullCheckTest(node)) return true;
|
|
3772
|
+
if (findEnclosingRefNullCheckIf(node, refName) != null) return true;
|
|
3773
|
+
if (isWrite && isWriteAfterNullCheckIf(node, refName)) return true;
|
|
3774
|
+
return false;
|
|
3775
|
+
}
|
|
3776
|
+
function isNullCheckOperator(operator) {
|
|
3777
|
+
return operator === "===" || operator === "==" || operator === "!==" || operator === "!=";
|
|
3778
|
+
}
|
|
3779
|
+
/**
|
|
3780
|
+
* Check if a test expression is a null check on `ref.current` for a given ref name.
|
|
3781
|
+
* @param test The test expression to check
|
|
3782
|
+
* @param refName The name of the ref variable (e.g. "myRef") to check against
|
|
3783
|
+
* @returns true if the test is of the form `ref.current === null` or `null === ref.current`
|
|
3784
|
+
*/
|
|
3785
|
+
function isRefCurrentNullCheck(test, refName) {
|
|
3786
|
+
if (test.type !== AST_NODE_TYPES.BinaryExpression) return false;
|
|
3787
|
+
if (!isNullCheckOperator(test.operator)) return false;
|
|
3788
|
+
const { left, right } = test;
|
|
3789
|
+
const isRefSide = (side) => side.type === AST_NODE_TYPES.MemberExpression && side.object.type === AST_NODE_TYPES.Identifier && side.object.name === refName && side.property.type === AST_NODE_TYPES.Identifier && side.property.name === "current";
|
|
3790
|
+
const isNullSide = (side) => side.type === AST_NODE_TYPES.Literal && side.value == null;
|
|
3791
|
+
return isRefSide(left) && isNullSide(right) || isRefSide(right) && isNullSide(left);
|
|
3792
|
+
}
|
|
3793
|
+
/**
|
|
3794
|
+
* Check if the node is the operand of a `ref.current === null` test inside an IfStatement.
|
|
3795
|
+
* @param node The MemberExpression node for ref.current
|
|
3796
|
+
* @returns true if the node is part of a null check test in an if statement
|
|
3797
|
+
*/
|
|
3798
|
+
function isInNullCheckTest(node) {
|
|
3799
|
+
const { parent } = node;
|
|
3800
|
+
if (parent.type !== AST_NODE_TYPES.BinaryExpression) return false;
|
|
3801
|
+
if (!isNullCheckOperator(parent.operator)) return false;
|
|
3802
|
+
const otherSide = parent.left === node ? parent.right : parent.left;
|
|
3803
|
+
if (otherSide.type !== AST_NODE_TYPES.Literal || otherSide.value != null) return false;
|
|
3804
|
+
return parent.parent.type === AST_NODE_TYPES.IfStatement && parent.parent.test === parent;
|
|
3805
|
+
}
|
|
3806
|
+
/**
|
|
3807
|
+
* Walk up from the node to find a containing IfStatement whose test is a null-check
|
|
3808
|
+
* on `ref.current` with the given ref name.
|
|
3809
|
+
* @param node The MemberExpression node for ref.current
|
|
3810
|
+
* @param refName The name of the ref variable (e.g. "myRef") to check against
|
|
3811
|
+
* @returns the enclosing IfStatement node if found, or null if not found
|
|
3812
|
+
*/
|
|
3813
|
+
function findEnclosingRefNullCheckIf(node, refName) {
|
|
3814
|
+
let current = node.parent;
|
|
3815
|
+
while (current != null) {
|
|
3816
|
+
if (current.type === AST_NODE_TYPES.IfStatement) return isRefCurrentNullCheck(current.test, refName) ? current : null;
|
|
3817
|
+
switch (current.type) {
|
|
3818
|
+
case AST_NODE_TYPES.ExpressionStatement:
|
|
3819
|
+
case AST_NODE_TYPES.BlockStatement:
|
|
3820
|
+
case AST_NODE_TYPES.ReturnStatement:
|
|
3821
|
+
case AST_NODE_TYPES.JSXExpressionContainer:
|
|
3822
|
+
case AST_NODE_TYPES.JSXElement:
|
|
3823
|
+
case AST_NODE_TYPES.JSXOpeningElement:
|
|
3824
|
+
case AST_NODE_TYPES.JSXClosingElement:
|
|
3825
|
+
case AST_NODE_TYPES.AssignmentExpression:
|
|
3826
|
+
case AST_NODE_TYPES.VariableDeclaration:
|
|
3827
|
+
case AST_NODE_TYPES.VariableDeclarator:
|
|
3828
|
+
case AST_NODE_TYPES.MemberExpression:
|
|
3829
|
+
case AST_NODE_TYPES.ChainExpression:
|
|
3830
|
+
case AST_NODE_TYPES.CallExpression: break;
|
|
3831
|
+
default: return null;
|
|
3832
|
+
}
|
|
3833
|
+
current = current.parent;
|
|
3834
|
+
}
|
|
3835
|
+
return null;
|
|
3836
|
+
}
|
|
3837
|
+
/**
|
|
3838
|
+
* Check if a write to `ref.current` comes after a sibling if-statement that null-checks
|
|
3839
|
+
* the same ref (inverted lazy init with early return pattern):
|
|
3840
|
+
*
|
|
3841
|
+
* if (ref.current !== null) { return ...; }
|
|
3842
|
+
* ref.current = value; // ← this write
|
|
3843
|
+
* @param node The MemberExpression node for ref.current being written to
|
|
3844
|
+
* @param refName The name of the ref variable (e.g. "myRef") to check against
|
|
3845
|
+
* @returns true if there is a preceding sibling if-statement that null-checks the same ref
|
|
3846
|
+
*/
|
|
3847
|
+
function isWriteAfterNullCheckIf(node, refName) {
|
|
3848
|
+
let stmt = node;
|
|
3849
|
+
while (stmt.parent != null && stmt.parent.type !== AST_NODE_TYPES.BlockStatement) stmt = stmt.parent;
|
|
3850
|
+
if (stmt.parent?.type !== AST_NODE_TYPES.BlockStatement) return false;
|
|
3851
|
+
const block = stmt.parent;
|
|
3852
|
+
const stmtIdx = block.body.indexOf(stmt);
|
|
3853
|
+
if (stmtIdx < 0) return false;
|
|
3854
|
+
for (let i = stmtIdx - 1; i >= 0; i--) {
|
|
3855
|
+
const sibling = block.body[i];
|
|
3856
|
+
if (sibling == null) continue;
|
|
3857
|
+
if (sibling.type === AST_NODE_TYPES.IfStatement && isRefCurrentNullCheck(sibling.test, refName)) return true;
|
|
3858
|
+
}
|
|
3859
|
+
return false;
|
|
3860
|
+
}
|
|
3861
|
+
var refs_default = createRule({
|
|
3862
|
+
meta: {
|
|
3863
|
+
type: "problem",
|
|
3864
|
+
docs: { description: "Validates correct usage of refs by checking that ref.current is not read or written during render." },
|
|
3865
|
+
messages: {
|
|
3866
|
+
readDuringRender: "Do not read 'ref.current' during render. Refs are not available during rendering and their values may be stale or inconsistent. Move this read into an effect or event handler.",
|
|
3867
|
+
writeDuringRender: "Do not write to 'ref.current' during render. Refs should only be mutated in effects or event handlers. Move this write into an effect or event handler."
|
|
3868
|
+
},
|
|
3869
|
+
schema: []
|
|
3870
|
+
},
|
|
3871
|
+
name: RULE_NAME$4,
|
|
3872
|
+
create: create$4,
|
|
3873
|
+
defaultOptions: []
|
|
3874
|
+
});
|
|
3875
|
+
function create$4(context) {
|
|
3876
|
+
const hCollector = core.useHookCollector(context);
|
|
3877
|
+
const cCollector = core.useComponentCollector(context);
|
|
3878
|
+
const refAccesses = [];
|
|
3879
|
+
const jsxRefIdentifiers = /* @__PURE__ */ new Set();
|
|
3880
|
+
function isRefIdentifier(node) {
|
|
3881
|
+
if (node.type !== AST_NODE_TYPES.Identifier) return false;
|
|
3882
|
+
if (core.isRefLikeName(node.name)) return true;
|
|
3883
|
+
if (jsxRefIdentifiers.has(node.name)) return true;
|
|
3884
|
+
return core.isInitializedFromRef(node.name, context.sourceCode.getScope(node));
|
|
3885
|
+
}
|
|
3886
|
+
return defineRuleListener(hCollector.visitor, cCollector.visitor, {
|
|
3887
|
+
JSXAttribute(node) {
|
|
3888
|
+
if (node.name.type === AST_NODE_TYPES.JSXIdentifier && node.name.name === "ref" && node.value?.type === AST_NODE_TYPES.JSXExpressionContainer && node.value.expression.type === AST_NODE_TYPES.Identifier) jsxRefIdentifiers.add(node.value.expression.name);
|
|
3889
|
+
},
|
|
3890
|
+
MemberExpression(node) {
|
|
3891
|
+
if (node.property.type !== AST_NODE_TYPES.Identifier || node.property.name !== "current") return;
|
|
3892
|
+
refAccesses.push({
|
|
3893
|
+
node,
|
|
3894
|
+
isWrite: isWriteAccess(node)
|
|
3895
|
+
});
|
|
3896
|
+
},
|
|
3897
|
+
"Program:exit"(program) {
|
|
3898
|
+
const components = cCollector.ctx.getAllComponents(program);
|
|
3899
|
+
const hooks = hCollector.ctx.getAllHooks(program);
|
|
3900
|
+
const componentAndHookFns = new Set([...components.map((c) => c.node), ...hooks.map((h) => h.node)]);
|
|
3901
|
+
const isComponentOrHookFn = (n) => ast.isFunction(n) && componentAndHookFns.has(n);
|
|
3902
|
+
for (const { node, isWrite } of refAccesses) {
|
|
3903
|
+
if (!isRefIdentifier(node.object)) continue;
|
|
3904
|
+
const boundary = ast.findParentNode(node, isComponentOrHookFn);
|
|
3905
|
+
if (boundary == null) continue;
|
|
3906
|
+
if (isInsideNestedFunction(node, boundary)) continue;
|
|
3907
|
+
if (isPartOfLazyInitialization(node, isWrite)) continue;
|
|
3908
|
+
context.report({
|
|
3909
|
+
messageId: isWrite ? "writeDuringRender" : "readDuringRender",
|
|
3910
|
+
node
|
|
3911
|
+
});
|
|
3912
|
+
}
|
|
3913
|
+
}
|
|
3914
|
+
});
|
|
3679
3915
|
}
|
|
3680
3916
|
|
|
3681
3917
|
//#endregion
|
|
3682
3918
|
//#region src/rules/rules-of-hooks.ts
|
|
3683
|
-
const RULE_NAME$
|
|
3919
|
+
const RULE_NAME$3 = "rules-of-hooks";
|
|
3684
3920
|
var rules_of_hooks_default = createRule({
|
|
3685
3921
|
meta: {
|
|
3686
3922
|
type: "problem",
|
|
@@ -3698,8 +3934,8 @@ var rules_of_hooks_default = createRule({
|
|
|
3698
3934
|
},
|
|
3699
3935
|
schema: []
|
|
3700
3936
|
},
|
|
3701
|
-
name: RULE_NAME$
|
|
3702
|
-
create: create$
|
|
3937
|
+
name: RULE_NAME$3,
|
|
3938
|
+
create: create$3,
|
|
3703
3939
|
defaultOptions: []
|
|
3704
3940
|
});
|
|
3705
3941
|
function getHookName(node) {
|
|
@@ -3734,7 +3970,7 @@ function isLoopNode(node) {
|
|
|
3734
3970
|
function isTryCatchNode(node) {
|
|
3735
3971
|
return node.type === AST_NODE_TYPES.TryStatement;
|
|
3736
3972
|
}
|
|
3737
|
-
function create$
|
|
3973
|
+
function create$3(context) {
|
|
3738
3974
|
const functionStack = [];
|
|
3739
3975
|
function findEnclosingComponentOrHook() {
|
|
3740
3976
|
for (let i = functionStack.length - 1; i >= 0; i--) {
|
|
@@ -3850,7 +4086,7 @@ function create$2(context) {
|
|
|
3850
4086
|
return;
|
|
3851
4087
|
}
|
|
3852
4088
|
}
|
|
3853
|
-
return {
|
|
4089
|
+
return defineRuleListener({
|
|
3854
4090
|
":function"(node) {
|
|
3855
4091
|
const kind = getFunctionEntryKind(node);
|
|
3856
4092
|
functionStack.push({
|
|
@@ -3882,24 +4118,24 @@ function create$2(context) {
|
|
|
3882
4118
|
const idx = body.indexOf(stmt);
|
|
3883
4119
|
if (idx !== -1 && idx < body.length - 1) entry.hasEarlyReturn = true;
|
|
3884
4120
|
}
|
|
3885
|
-
};
|
|
4121
|
+
});
|
|
3886
4122
|
}
|
|
3887
4123
|
|
|
3888
4124
|
//#endregion
|
|
3889
4125
|
//#region src/rules/set-state-in-effect.ts
|
|
3890
|
-
const RULE_NAME$
|
|
4126
|
+
const RULE_NAME$2 = "set-state-in-effect";
|
|
3891
4127
|
var set_state_in_effect_default = createRule({
|
|
3892
4128
|
meta: {
|
|
3893
4129
|
type: "problem",
|
|
3894
|
-
docs: { description: "Validates against
|
|
4130
|
+
docs: { description: "Validates against setting state synchronously in an effect, which can lead to re-renders that degrade performance." },
|
|
3895
4131
|
messages: { default: "Do not call the 'set' function '{{name}}' of 'useState' synchronously in an effect. This can lead to unnecessary re-renders and performance issues." },
|
|
3896
4132
|
schema: []
|
|
3897
4133
|
},
|
|
3898
|
-
name: RULE_NAME$
|
|
3899
|
-
create: create$
|
|
4134
|
+
name: RULE_NAME$2,
|
|
4135
|
+
create: create$2,
|
|
3900
4136
|
defaultOptions: []
|
|
3901
4137
|
});
|
|
3902
|
-
function create$
|
|
4138
|
+
function create$2(context) {
|
|
3903
4139
|
if (!/use\w*Effect/u.test(context.sourceCode.text)) return {};
|
|
3904
4140
|
const { additionalStateHooks } = getSettingsFromContext(context);
|
|
3905
4141
|
const functionEntries = [];
|
|
@@ -3972,7 +4208,7 @@ function create$1(context) {
|
|
|
3972
4208
|
default: return false;
|
|
3973
4209
|
}
|
|
3974
4210
|
}
|
|
3975
|
-
return {
|
|
4211
|
+
return defineRuleListener({
|
|
3976
4212
|
":function"(node) {
|
|
3977
4213
|
const kind = getFunctionKind(node);
|
|
3978
4214
|
functionEntries.push({
|
|
@@ -4073,7 +4309,7 @@ function create$1(context) {
|
|
|
4073
4309
|
});
|
|
4074
4310
|
}
|
|
4075
4311
|
}
|
|
4076
|
-
};
|
|
4312
|
+
});
|
|
4077
4313
|
}
|
|
4078
4314
|
function isInitFromHookCall(init) {
|
|
4079
4315
|
if (init?.type !== AST_NODE_TYPES.CallExpression) return false;
|
|
@@ -4091,7 +4327,7 @@ function isVariableDeclaratorFromHookCall(node) {
|
|
|
4091
4327
|
|
|
4092
4328
|
//#endregion
|
|
4093
4329
|
//#region src/rules/set-state-in-render.ts
|
|
4094
|
-
const RULE_NAME = "set-state-in-render";
|
|
4330
|
+
const RULE_NAME$1 = "set-state-in-render";
|
|
4095
4331
|
var set_state_in_render_default = createRule({
|
|
4096
4332
|
meta: {
|
|
4097
4333
|
type: "problem",
|
|
@@ -4099,11 +4335,11 @@ var set_state_in_render_default = createRule({
|
|
|
4099
4335
|
messages: { default: "Do not call the 'set' function '{{name}}' unconditionally during render. This will trigger an infinite render loop." },
|
|
4100
4336
|
schema: []
|
|
4101
4337
|
},
|
|
4102
|
-
name: RULE_NAME,
|
|
4103
|
-
create,
|
|
4338
|
+
name: RULE_NAME$1,
|
|
4339
|
+
create: create$1,
|
|
4104
4340
|
defaultOptions: []
|
|
4105
4341
|
});
|
|
4106
|
-
function create(context) {
|
|
4342
|
+
function create$1(context) {
|
|
4107
4343
|
const { additionalStateHooks } = getSettingsFromContext(context);
|
|
4108
4344
|
const functionEntries = [];
|
|
4109
4345
|
const componentFnRef = { current: null };
|
|
@@ -4176,7 +4412,7 @@ function create(context) {
|
|
|
4176
4412
|
if (parent.type === AST_NODE_TYPES.CallExpression && parent.callee !== node) return "callback";
|
|
4177
4413
|
return "other";
|
|
4178
4414
|
}
|
|
4179
|
-
return {
|
|
4415
|
+
return defineRuleListener({
|
|
4180
4416
|
":function"(node) {
|
|
4181
4417
|
const kind = getFunctionKind(node);
|
|
4182
4418
|
functionEntries.push({
|
|
@@ -4223,7 +4459,88 @@ function create(context) {
|
|
|
4223
4459
|
const idx = body.indexOf(stmt);
|
|
4224
4460
|
if (idx !== -1 && idx < body.length - 1) componentHasEarlyReturn.current = true;
|
|
4225
4461
|
}
|
|
4226
|
-
};
|
|
4462
|
+
});
|
|
4463
|
+
}
|
|
4464
|
+
|
|
4465
|
+
//#endregion
|
|
4466
|
+
//#region src/rules/unsupported-syntax.ts
|
|
4467
|
+
const RULE_NAME = "unsupported-syntax";
|
|
4468
|
+
var unsupported_syntax_default = createRule({
|
|
4469
|
+
meta: {
|
|
4470
|
+
type: "problem",
|
|
4471
|
+
docs: { description: "Validates against syntax that React Compiler does not support." },
|
|
4472
|
+
messages: {
|
|
4473
|
+
eval: "Do not use 'eval' inside components or hooks. 'eval' cannot be statically analyzed and is not supported by React Compiler.",
|
|
4474
|
+
iife: "Do not use immediately-invoked function expressions in JSX. IIFEs will not be optimized by React Compiler.",
|
|
4475
|
+
with: "Do not use 'with' statements inside components or hooks. 'with' changes scope dynamically and is not supported by React Compiler."
|
|
4476
|
+
},
|
|
4477
|
+
schema: []
|
|
4478
|
+
},
|
|
4479
|
+
name: RULE_NAME,
|
|
4480
|
+
create,
|
|
4481
|
+
defaultOptions: []
|
|
4482
|
+
});
|
|
4483
|
+
function isEvalCall(node) {
|
|
4484
|
+
return node.callee.type === AST_NODE_TYPES.Identifier && node.callee.name === "eval";
|
|
4485
|
+
}
|
|
4486
|
+
function isIifeCall(node) {
|
|
4487
|
+
return node.parent.type === AST_NODE_TYPES.CallExpression && node.parent.callee === node;
|
|
4488
|
+
}
|
|
4489
|
+
function create(context) {
|
|
4490
|
+
const hCollector = core.useHookCollector(context);
|
|
4491
|
+
const cCollector = core.useComponentCollector(context);
|
|
4492
|
+
const evalCalls = [];
|
|
4493
|
+
const withStmts = [];
|
|
4494
|
+
return defineRuleListener(hCollector.visitor, cCollector.visitor, {
|
|
4495
|
+
CallExpression(node) {
|
|
4496
|
+
if (!isEvalCall(node)) return;
|
|
4497
|
+
const func = ast.findParentNode(node, ast.isFunction);
|
|
4498
|
+
if (func == null) return;
|
|
4499
|
+
evalCalls.push({
|
|
4500
|
+
node,
|
|
4501
|
+
func
|
|
4502
|
+
});
|
|
4503
|
+
},
|
|
4504
|
+
"JSXElement :function"(node) {
|
|
4505
|
+
if (isIifeCall(node)) context.report({
|
|
4506
|
+
messageId: "iife",
|
|
4507
|
+
node: node.parent
|
|
4508
|
+
});
|
|
4509
|
+
},
|
|
4510
|
+
"JSXFragment :function"(node) {
|
|
4511
|
+
if (isIifeCall(node)) context.report({
|
|
4512
|
+
messageId: "iife",
|
|
4513
|
+
node: node.parent
|
|
4514
|
+
});
|
|
4515
|
+
},
|
|
4516
|
+
"Program:exit"(node) {
|
|
4517
|
+
const components = cCollector.ctx.getAllComponents(node);
|
|
4518
|
+
const hooks = hCollector.ctx.getAllHooks(node);
|
|
4519
|
+
const funcs = [...components, ...hooks];
|
|
4520
|
+
for (const { node, func } of evalCalls) {
|
|
4521
|
+
if (!funcs.some((f) => f.node === func)) continue;
|
|
4522
|
+
context.report({
|
|
4523
|
+
messageId: "eval",
|
|
4524
|
+
node
|
|
4525
|
+
});
|
|
4526
|
+
}
|
|
4527
|
+
for (const { node, func } of withStmts) {
|
|
4528
|
+
if (!funcs.some((f) => f.node === func)) continue;
|
|
4529
|
+
context.report({
|
|
4530
|
+
messageId: "with",
|
|
4531
|
+
node
|
|
4532
|
+
});
|
|
4533
|
+
}
|
|
4534
|
+
},
|
|
4535
|
+
WithStatement(node) {
|
|
4536
|
+
const func = ast.findParentNode(node, ast.isFunction);
|
|
4537
|
+
if (func == null) return;
|
|
4538
|
+
withStmts.push({
|
|
4539
|
+
node,
|
|
4540
|
+
func
|
|
4541
|
+
});
|
|
4542
|
+
}
|
|
4543
|
+
});
|
|
4227
4544
|
}
|
|
4228
4545
|
|
|
4229
4546
|
//#endregion
|
|
@@ -4241,7 +4558,6 @@ const plugin = {
|
|
|
4241
4558
|
"jsx-key-before-spread": jsx_key_before_spread_default,
|
|
4242
4559
|
"jsx-no-comment-textnodes": jsx_no_comment_textnodes_default,
|
|
4243
4560
|
"jsx-no-duplicate-props": jsx_no_duplicate_props_default,
|
|
4244
|
-
"jsx-no-iife": jsx_no_iife_default,
|
|
4245
4561
|
"jsx-no-undef": jsx_no_undef_default,
|
|
4246
4562
|
"jsx-shorthand-boolean": jsx_shorthand_boolean_default,
|
|
4247
4563
|
"jsx-shorthand-fragment": jsx_shorthand_fragment_default,
|
|
@@ -4295,9 +4611,12 @@ const plugin = {
|
|
|
4295
4611
|
"prefer-namespace-import": prefer_namespace_import_default,
|
|
4296
4612
|
"prefer-read-only-props": prefer_read_only_props_default,
|
|
4297
4613
|
"prefer-use-state-lazy-initialization": prefer_use_state_lazy_initialization_default,
|
|
4614
|
+
purity: purity_default,
|
|
4615
|
+
refs: refs_default,
|
|
4298
4616
|
"rules-of-hooks": rules_of_hooks_default,
|
|
4299
4617
|
"set-state-in-effect": set_state_in_effect_default,
|
|
4300
|
-
"set-state-in-render": set_state_in_render_default
|
|
4618
|
+
"set-state-in-render": set_state_in_render_default,
|
|
4619
|
+
"unsupported-syntax": unsupported_syntax_default
|
|
4301
4620
|
}
|
|
4302
4621
|
};
|
|
4303
4622
|
|
|
@@ -4348,9 +4667,11 @@ const rules$6 = {
|
|
|
4348
4667
|
"react-x/no-use-context": "warn",
|
|
4349
4668
|
"react-x/no-useless-forward-ref": "warn",
|
|
4350
4669
|
"react-x/prefer-use-state-lazy-initialization": "warn",
|
|
4670
|
+
"react-x/purity": "warn",
|
|
4351
4671
|
"react-x/rules-of-hooks": "error",
|
|
4352
4672
|
"react-x/set-state-in-effect": "warn",
|
|
4353
|
-
"react-x/set-state-in-render": "error"
|
|
4673
|
+
"react-x/set-state-in-render": "error",
|
|
4674
|
+
"react-x/unsupported-syntax": "error"
|
|
4354
4675
|
};
|
|
4355
4676
|
const plugins$5 = { "react-x": plugin };
|
|
4356
4677
|
const settings$5 = { "react-x": DEFAULT_ESLINT_REACT_SETTINGS };
|
|
@@ -4411,7 +4732,6 @@ var strict_exports = /* @__PURE__ */ __exportAll({
|
|
|
4411
4732
|
const name$2 = "react-x/strict";
|
|
4412
4733
|
const rules$2 = {
|
|
4413
4734
|
...rules$6,
|
|
4414
|
-
"react-x/jsx-no-iife": "error",
|
|
4415
4735
|
"react-x/no-children-prop": "error",
|
|
4416
4736
|
"react-x/no-class-component": "error",
|
|
4417
4737
|
"react-x/no-misused-capture-owner-stack": "error",
|