@pobammer-ts/eslint-cease-nonsense-rules 1.5.3 → 1.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +594 -505
- package/dist/build-metadata.json +3 -3
- package/dist/index.d.ts +7 -1
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1374 -436
- package/dist/index.js.map +41 -35
- package/dist/oxfmt-sync.d.ts +4 -0
- package/dist/oxfmt-sync.d.ts.map +1 -0
- package/dist/oxfmt-worker.d.ts +12 -0
- package/dist/oxfmt-worker.d.ts.map +1 -0
- package/dist/oxfmt-worker.js +172786 -0
- package/dist/oxfmt-worker.js.map +27 -0
- package/dist/recognizers/camel-case-detector.d.ts +2 -2
- package/dist/recognizers/camel-case-detector.d.ts.map +1 -0
- package/dist/recognizers/code-recognizer.d.ts +6 -6
- package/dist/recognizers/code-recognizer.d.ts.map +1 -0
- package/dist/recognizers/contains-detector.d.ts +2 -2
- package/dist/recognizers/contains-detector.d.ts.map +1 -0
- package/dist/recognizers/detector.d.ts +3 -4
- package/dist/recognizers/detector.d.ts.map +1 -0
- package/dist/recognizers/end-with-detector.d.ts +2 -2
- package/dist/recognizers/end-with-detector.d.ts.map +1 -0
- package/dist/recognizers/javascript-footprint.d.ts +2 -2
- package/dist/recognizers/javascript-footprint.d.ts.map +1 -0
- package/dist/recognizers/keywords-detector.d.ts +2 -2
- package/dist/recognizers/keywords-detector.d.ts.map +1 -0
- package/dist/rules/ban-instances.d.ts +1 -0
- package/dist/rules/ban-instances.d.ts.map +1 -0
- package/dist/rules/ban-react-fc.d.ts +1 -0
- package/dist/rules/ban-react-fc.d.ts.map +1 -0
- package/dist/rules/enforce-ianitor-check-type.d.ts +2 -1
- package/dist/rules/enforce-ianitor-check-type.d.ts.map +1 -0
- package/dist/rules/fast-format.d.ts +36 -0
- package/dist/rules/fast-format.d.ts.map +1 -0
- package/dist/rules/no-async-constructor.d.ts +1 -0
- package/dist/rules/no-async-constructor.d.ts.map +1 -0
- package/dist/rules/no-color3-constructor.d.ts +1 -0
- package/dist/rules/no-color3-constructor.d.ts.map +1 -0
- package/dist/rules/no-commented-code.d.ts +1 -0
- package/dist/rules/no-commented-code.d.ts.map +1 -0
- package/dist/rules/no-god-components.d.ts +14 -0
- package/dist/rules/no-god-components.d.ts.map +1 -0
- package/dist/rules/no-identity-map.d.ts +9 -0
- package/dist/rules/no-identity-map.d.ts.map +1 -0
- package/dist/rules/no-instance-methods-without-this.d.ts +1 -0
- package/dist/rules/no-instance-methods-without-this.d.ts.map +1 -0
- package/dist/rules/no-print.d.ts +1 -0
- package/dist/rules/no-print.d.ts.map +1 -0
- package/dist/rules/no-shorthand-names.d.ts +1 -0
- package/dist/rules/no-shorthand-names.d.ts.map +1 -0
- package/dist/rules/no-useless-use-spring.d.ts +1 -0
- package/dist/rules/no-useless-use-spring.d.ts.map +1 -0
- package/dist/rules/no-warn.d.ts +1 -0
- package/dist/rules/no-warn.d.ts.map +1 -0
- package/dist/rules/prefer-sequence-overloads.d.ts +1 -0
- package/dist/rules/prefer-sequence-overloads.d.ts.map +1 -0
- package/dist/rules/prefer-udim2-shorthand.d.ts +1 -0
- package/dist/rules/prefer-udim2-shorthand.d.ts.map +1 -0
- package/dist/rules/require-named-effect-functions.d.ts +4 -3
- package/dist/rules/require-named-effect-functions.d.ts.map +1 -0
- package/dist/rules/require-paired-calls.d.ts +1 -0
- package/dist/rules/require-paired-calls.d.ts.map +1 -0
- package/dist/rules/require-react-component-keys.d.ts +1 -0
- package/dist/rules/require-react-component-keys.d.ts.map +1 -0
- package/dist/rules/use-exhaustive-dependencies.d.ts +1 -0
- package/dist/rules/use-exhaustive-dependencies.d.ts.map +1 -0
- package/dist/rules/use-hook-at-top-level.d.ts +1 -0
- package/dist/rules/use-hook-at-top-level.d.ts.map +1 -0
- package/dist/types/oxfmt.d.ts +88 -0
- package/dist/types/oxfmt.d.ts.map +1 -0
- package/dist/{configure-utilities.d.ts → utilities/configure-utilities.d.ts} +18 -10
- package/dist/utilities/configure-utilities.d.ts.map +1 -0
- package/dist/utilities/error-utilities.d.ts +25 -0
- package/dist/utilities/error-utilities.d.ts.map +1 -0
- package/dist/utilities/format-utilities.d.ts +20 -0
- package/dist/utilities/format-utilities.d.ts.map +1 -0
- package/dist/utilities/typebox-utilities.d.ts +4 -0
- package/dist/utilities/typebox-utilities.d.ts.map +1 -0
- package/package.json +32 -19
package/dist/index.js
CHANGED
|
@@ -25,6 +25,7 @@ var __export = (target, all) => {
|
|
|
25
25
|
set: (newValue) => all[name] = () => newValue
|
|
26
26
|
});
|
|
27
27
|
};
|
|
28
|
+
var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
|
|
28
29
|
var __require = /* @__PURE__ */ createRequire(import.meta.url);
|
|
29
30
|
|
|
30
31
|
// node_modules/eslint-visitor-keys/dist/eslint-visitor-keys.cjs
|
|
@@ -5663,7 +5664,7 @@ var require_ScopeBase = __commonJS((exports) => {
|
|
|
5663
5664
|
}
|
|
5664
5665
|
};
|
|
5665
5666
|
#staticCloseRef = (ref6) => {
|
|
5666
|
-
const
|
|
5667
|
+
const resolve3 = () => {
|
|
5667
5668
|
const name = ref6.identifier.name;
|
|
5668
5669
|
const variable = this.set.get(name);
|
|
5669
5670
|
if (!variable) {
|
|
@@ -5681,7 +5682,7 @@ var require_ScopeBase = __commonJS((exports) => {
|
|
|
5681
5682
|
ref6.resolved = variable;
|
|
5682
5683
|
return true;
|
|
5683
5684
|
};
|
|
5684
|
-
if (!
|
|
5685
|
+
if (!resolve3()) {
|
|
5685
5686
|
this.delegateToUpperScope(ref6);
|
|
5686
5687
|
}
|
|
5687
5688
|
};
|
|
@@ -6163,7 +6164,7 @@ var require_VisitorBase = __commonJS((exports) => {
|
|
|
6163
6164
|
function isObject(obj) {
|
|
6164
6165
|
return typeof obj === "object" && obj != null;
|
|
6165
6166
|
}
|
|
6166
|
-
function
|
|
6167
|
+
function isNode2(node) {
|
|
6167
6168
|
return isObject(node) && typeof node.type === "string";
|
|
6168
6169
|
}
|
|
6169
6170
|
|
|
@@ -6190,11 +6191,11 @@ var require_VisitorBase = __commonJS((exports) => {
|
|
|
6190
6191
|
}
|
|
6191
6192
|
if (Array.isArray(child)) {
|
|
6192
6193
|
for (const subChild of child) {
|
|
6193
|
-
if (
|
|
6194
|
+
if (isNode2(subChild)) {
|
|
6194
6195
|
this.visit(subChild);
|
|
6195
6196
|
}
|
|
6196
6197
|
}
|
|
6197
|
-
} else if (
|
|
6198
|
+
} else if (isNode2(child)) {
|
|
6198
6199
|
this.visit(child);
|
|
6199
6200
|
}
|
|
6200
6201
|
}
|
|
@@ -7399,7 +7400,7 @@ var require_analyze = __commonJS((exports) => {
|
|
|
7399
7400
|
var visitor_keys_1 = require_dist();
|
|
7400
7401
|
var referencer_1 = require_referencer();
|
|
7401
7402
|
var ScopeManager_1 = require_ScopeManager();
|
|
7402
|
-
var
|
|
7403
|
+
var DEFAULT_OPTIONS = {
|
|
7403
7404
|
childVisitorKeys: visitor_keys_1.visitorKeys,
|
|
7404
7405
|
emitDecoratorMetadata: false,
|
|
7405
7406
|
globalReturn: false,
|
|
@@ -7411,14 +7412,14 @@ var require_analyze = __commonJS((exports) => {
|
|
|
7411
7412
|
};
|
|
7412
7413
|
function analyze(tree, providedOptions) {
|
|
7413
7414
|
const options3 = {
|
|
7414
|
-
childVisitorKeys: providedOptions?.childVisitorKeys ??
|
|
7415
|
+
childVisitorKeys: providedOptions?.childVisitorKeys ?? DEFAULT_OPTIONS.childVisitorKeys,
|
|
7415
7416
|
emitDecoratorMetadata: false,
|
|
7416
|
-
globalReturn: providedOptions?.globalReturn ??
|
|
7417
|
-
impliedStrict: providedOptions?.impliedStrict ??
|
|
7418
|
-
jsxFragmentName: providedOptions?.jsxFragmentName ??
|
|
7419
|
-
jsxPragma: providedOptions?.jsxPragma === undefined ?
|
|
7417
|
+
globalReturn: providedOptions?.globalReturn ?? DEFAULT_OPTIONS.globalReturn,
|
|
7418
|
+
impliedStrict: providedOptions?.impliedStrict ?? DEFAULT_OPTIONS.impliedStrict,
|
|
7419
|
+
jsxFragmentName: providedOptions?.jsxFragmentName ?? DEFAULT_OPTIONS.jsxFragmentName,
|
|
7420
|
+
jsxPragma: providedOptions?.jsxPragma === undefined ? DEFAULT_OPTIONS.jsxPragma : providedOptions.jsxPragma,
|
|
7420
7421
|
lib: providedOptions?.lib ?? ["esnext"],
|
|
7421
|
-
sourceType: providedOptions?.sourceType ??
|
|
7422
|
+
sourceType: providedOptions?.sourceType ?? DEFAULT_OPTIONS.sourceType
|
|
7422
7423
|
};
|
|
7423
7424
|
options3.lib = options3.lib.map((l) => l.toLowerCase());
|
|
7424
7425
|
const scopeManager = new ScopeManager_1.ScopeManager(options3);
|
|
@@ -7700,7 +7701,8 @@ function EveryAll(value, offset, callback) {
|
|
|
7700
7701
|
return result;
|
|
7701
7702
|
}
|
|
7702
7703
|
function HasPropertyKey(value, key) {
|
|
7703
|
-
|
|
7704
|
+
const isProtoField = IsEqual(key, "__proto__") || IsEqual(key, "constructor");
|
|
7705
|
+
return isProtoField ? Object.prototype.hasOwnProperty.call(value, key) : (key in value);
|
|
7704
7706
|
}
|
|
7705
7707
|
function EntriesRegExp(value) {
|
|
7706
7708
|
return Keys(value).map((key) => [new RegExp(`^${key}$`), value[key]]);
|
|
@@ -7817,7 +7819,7 @@ function Keys2(value) {
|
|
|
7817
7819
|
return `Object.getOwnPropertyNames(${value})`;
|
|
7818
7820
|
}
|
|
7819
7821
|
function HasPropertyKey2(value, key) {
|
|
7820
|
-
const isProtoField = IsEqual(key, '"__proto__"') || IsEqual(key, '"
|
|
7822
|
+
const isProtoField = IsEqual(key, '"__proto__"') || IsEqual(key, '"constructor"');
|
|
7821
7823
|
return isProtoField ? `Object.prototype.hasOwnProperty.call(${value}, ${key})` : `${key} in ${value}`;
|
|
7822
7824
|
}
|
|
7823
7825
|
function IsDeepEqual2(left, right) {
|
|
@@ -14762,7 +14764,7 @@ function FromObject13(context, type3, value) {
|
|
|
14762
14764
|
continue;
|
|
14763
14765
|
value[key] = FromType16(context, type3.properties[key], value[key]);
|
|
14764
14766
|
}
|
|
14765
|
-
if (!IsAdditionalProperties(type3))
|
|
14767
|
+
if (!IsAdditionalProperties(type3) || exports_guard.IsBoolean(type3.additionalProperties))
|
|
14766
14768
|
return value;
|
|
14767
14769
|
for (const key of exports_guard.Keys(value)) {
|
|
14768
14770
|
if (knownPropertyKeys.includes(key))
|
|
@@ -15424,7 +15426,10 @@ function Compile(...args) {
|
|
|
15424
15426
|
var isArrayConfig = Compile(build_default.Array(build_default.String()));
|
|
15425
15427
|
var isObjectConfig = Compile(build_default.Record(build_default.String(), build_default.String()));
|
|
15426
15428
|
var isOptionsObject = Compile(build_default.Object({
|
|
15427
|
-
bannedInstances: build_default.Union([
|
|
15429
|
+
bannedInstances: build_default.Union([
|
|
15430
|
+
build_default.Array(build_default.String()),
|
|
15431
|
+
build_default.Record(build_default.String(), build_default.String())
|
|
15432
|
+
])
|
|
15428
15433
|
}));
|
|
15429
15434
|
function normalizeConfig(options3) {
|
|
15430
15435
|
if (!isOptionsObject.Check(options3))
|
|
@@ -15433,13 +15438,13 @@ function normalizeConfig(options3) {
|
|
|
15433
15438
|
if (isArrayConfig.Check(bannedInstances)) {
|
|
15434
15439
|
const map = new Map;
|
|
15435
15440
|
for (const className of bannedInstances)
|
|
15436
|
-
map.set(className.toLowerCase(), {
|
|
15441
|
+
map.set(className.toLowerCase(), { message: undefined, originalName: className });
|
|
15437
15442
|
return { bannedClasses: map };
|
|
15438
15443
|
}
|
|
15439
15444
|
if (isObjectConfig.Check(bannedInstances)) {
|
|
15440
15445
|
const map = new Map;
|
|
15441
15446
|
for (const [className, message] of Object.entries(bannedInstances))
|
|
15442
|
-
map.set(className.toLowerCase(), { originalName: className
|
|
15447
|
+
map.set(className.toLowerCase(), { message, originalName: className });
|
|
15443
15448
|
return { bannedClasses: map };
|
|
15444
15449
|
}
|
|
15445
15450
|
return { bannedClasses: new Map };
|
|
@@ -15596,9 +15601,9 @@ function hasTypeAnnotationProperty(node) {
|
|
|
15596
15601
|
}
|
|
15597
15602
|
function hasTypeAnnotation(node) {
|
|
15598
15603
|
if (node.type === TSESTree3.AST_NODE_TYPES.VariableDeclarator && node.id && typeof node.id === "object" && hasTypeAnnotationProperty(node.id))
|
|
15599
|
-
return
|
|
15604
|
+
return Boolean(node.id.typeAnnotation);
|
|
15600
15605
|
if (SHOULD_NOT_NOT_RETURN_TYPE.has(node.type))
|
|
15601
|
-
return
|
|
15606
|
+
return Boolean(node.returnType);
|
|
15602
15607
|
return false;
|
|
15603
15608
|
}
|
|
15604
15609
|
function getTypeName(node) {
|
|
@@ -15609,35 +15614,39 @@ function isIanitorValidator(node) {
|
|
|
15609
15614
|
}
|
|
15610
15615
|
function extractIanitorStaticVariable(typeAnnotation) {
|
|
15611
15616
|
let currentType = typeAnnotation;
|
|
15612
|
-
if (currentType.type === TSESTree3.AST_NODE_TYPES.TSTypeReference && currentType.typeName.type === TSESTree3.AST_NODE_TYPES.Identifier && currentType.typeName.name === "Readonly" && currentType.typeArguments?.params[0])
|
|
15613
|
-
currentType = currentType.typeArguments.params
|
|
15617
|
+
if (currentType.type === TSESTree3.AST_NODE_TYPES.TSTypeReference && currentType.typeName.type === TSESTree3.AST_NODE_TYPES.Identifier && currentType.typeName.name === "Readonly" && currentType.typeArguments?.params[0]) {
|
|
15618
|
+
[currentType] = currentType.typeArguments.params;
|
|
15619
|
+
}
|
|
15614
15620
|
if (currentType.type !== TSESTree3.AST_NODE_TYPES.TSTypeReference)
|
|
15615
15621
|
return;
|
|
15616
15622
|
const { typeName, typeArguments } = currentType;
|
|
15617
15623
|
const firstParam = typeArguments?.params[0];
|
|
15618
|
-
if (typeName.type === TSESTree3.AST_NODE_TYPES.TSQualifiedName && typeName.left.type === TSESTree3.AST_NODE_TYPES.Identifier && typeName.left.name === "Ianitor" && typeName.right.type === TSESTree3.AST_NODE_TYPES.Identifier && typeName.right.name === "Static" && firstParam?.type === TSESTree3.AST_NODE_TYPES.TSTypeQuery && firstParam.exprName.type === TSESTree3.AST_NODE_TYPES.Identifier)
|
|
15624
|
+
if (typeName.type === TSESTree3.AST_NODE_TYPES.TSQualifiedName && typeName.left.type === TSESTree3.AST_NODE_TYPES.Identifier && typeName.left.name === "Ianitor" && typeName.right.type === TSESTree3.AST_NODE_TYPES.Identifier && typeName.right.name === "Static" && firstParam?.type === TSESTree3.AST_NODE_TYPES.TSTypeQuery && firstParam.exprName.type === TSESTree3.AST_NODE_TYPES.Identifier) {
|
|
15619
15625
|
return firstParam.exprName.name;
|
|
15626
|
+
}
|
|
15620
15627
|
return;
|
|
15621
15628
|
}
|
|
15622
15629
|
function hasIanitorStaticType(typeAnnotation) {
|
|
15623
15630
|
let currentType = typeAnnotation;
|
|
15624
|
-
if (currentType.type === TSESTree3.AST_NODE_TYPES.TSTypeReference && currentType.typeName.type === TSESTree3.AST_NODE_TYPES.Identifier && currentType.typeName.name === "Readonly" && currentType.typeArguments?.params[0])
|
|
15625
|
-
currentType = currentType.typeArguments.params
|
|
15631
|
+
if (currentType.type === TSESTree3.AST_NODE_TYPES.TSTypeReference && currentType.typeName.type === TSESTree3.AST_NODE_TYPES.Identifier && currentType.typeName.name === "Readonly" && currentType.typeArguments?.params[0]) {
|
|
15632
|
+
[currentType] = currentType.typeArguments.params;
|
|
15633
|
+
}
|
|
15626
15634
|
if (currentType.type !== TSESTree3.AST_NODE_TYPES.TSTypeReference)
|
|
15627
15635
|
return false;
|
|
15628
15636
|
const { typeName, typeArguments } = currentType;
|
|
15629
15637
|
return typeName.type === TSESTree3.AST_NODE_TYPES.TSQualifiedName && typeName.left.type === TSESTree3.AST_NODE_TYPES.Identifier && typeName.left.name === "Ianitor" && typeName.right.type === TSESTree3.AST_NODE_TYPES.Identifier && typeName.right.name === "Static" && typeArguments?.params[0]?.type === TSESTree3.AST_NODE_TYPES.TSTypeQuery;
|
|
15630
15638
|
}
|
|
15631
15639
|
function calculateIanitorComplexity(node) {
|
|
15632
|
-
const callee = node
|
|
15633
|
-
if (callee?.type !== TSESTree3.AST_NODE_TYPES.MemberExpression || callee.property?.type !== TSESTree3.AST_NODE_TYPES.Identifier)
|
|
15640
|
+
const { callee } = node;
|
|
15641
|
+
if (callee?.type !== TSESTree3.AST_NODE_TYPES.MemberExpression || callee.property?.type !== TSESTree3.AST_NODE_TYPES.Identifier) {
|
|
15634
15642
|
return 0;
|
|
15643
|
+
}
|
|
15635
15644
|
const method = callee.property.name;
|
|
15636
15645
|
switch (method) {
|
|
15637
15646
|
case "interface":
|
|
15638
15647
|
case "strictInterface": {
|
|
15639
15648
|
const properties4 = node.arguments?.[0];
|
|
15640
|
-
return properties4?.type === TSESTree3.AST_NODE_TYPES.ObjectExpression ? 10 + (properties4.properties?.length
|
|
15649
|
+
return properties4?.type === TSESTree3.AST_NODE_TYPES.ObjectExpression ? 10 + (properties4.properties?.length ?? 0) * 3 : 0;
|
|
15641
15650
|
}
|
|
15642
15651
|
case "optional":
|
|
15643
15652
|
case "array":
|
|
@@ -15649,7 +15658,7 @@ function calculateIanitorComplexity(node) {
|
|
|
15649
15658
|
return 3;
|
|
15650
15659
|
case "union":
|
|
15651
15660
|
case "intersection":
|
|
15652
|
-
return (node.arguments?.length
|
|
15661
|
+
return (node.arguments?.length ?? 0) * 2;
|
|
15653
15662
|
case "string":
|
|
15654
15663
|
case "number":
|
|
15655
15664
|
case "boolean":
|
|
@@ -15661,7 +15670,8 @@ function calculateIanitorComplexity(node) {
|
|
|
15661
15670
|
var createRule = ESLintUtils.RuleCreator((name) => `https://github.com/howmanysmall/eslint-cease-nonsense-rules/blob/main/docs/rules/${name}.md`);
|
|
15662
15671
|
var enforceIanitorCheckType = createRule({
|
|
15663
15672
|
create(context) {
|
|
15664
|
-
const
|
|
15673
|
+
const [rawOptions] = context.options;
|
|
15674
|
+
const config = { ...DEFAULT_CONFIGURATION, ...rawOptions };
|
|
15665
15675
|
const cache = {
|
|
15666
15676
|
nodeCache: new WeakMap,
|
|
15667
15677
|
visitedNodes: new WeakSet
|
|
@@ -15788,15 +15798,14 @@ var enforceIanitorCheckType = createRule({
|
|
|
15788
15798
|
}
|
|
15789
15799
|
case TSESTree3.AST_NODE_TYPES.TSFunctionType:
|
|
15790
15800
|
case TSESTree3.AST_NODE_TYPES.TSMethodSignature: {
|
|
15791
|
-
const func = node;
|
|
15792
15801
|
score = 2;
|
|
15793
|
-
for (const param of
|
|
15802
|
+
for (const param of node.params) {
|
|
15794
15803
|
const typeAnnotation = "typeAnnotation" in param ? param.typeAnnotation : undefined;
|
|
15795
15804
|
if (typeAnnotation)
|
|
15796
15805
|
score = addScore(score, calculateStructuralComplexity(typeAnnotation.typeAnnotation, nextDepth));
|
|
15797
15806
|
}
|
|
15798
|
-
if (
|
|
15799
|
-
score = addScore(score, calculateStructuralComplexity(
|
|
15807
|
+
if (node.returnType)
|
|
15808
|
+
score = addScore(score, calculateStructuralComplexity(node.returnType.typeAnnotation, nextDepth));
|
|
15800
15809
|
break;
|
|
15801
15810
|
}
|
|
15802
15811
|
default:
|
|
@@ -15810,8 +15819,7 @@ var enforceIanitorCheckType = createRule({
|
|
|
15810
15819
|
const variableDeclaratorsToCheck = new Map;
|
|
15811
15820
|
return {
|
|
15812
15821
|
"Program:exit"() {
|
|
15813
|
-
for (const [
|
|
15814
|
-
const node = nodeKey;
|
|
15822
|
+
for (const [node, data] of variableDeclaratorsToCheck.entries()) {
|
|
15815
15823
|
if (node.id.type === TSESTree3.AST_NODE_TYPES.Identifier && ianitorStaticVariables.has(node.id.name))
|
|
15816
15824
|
continue;
|
|
15817
15825
|
context.report({
|
|
@@ -15826,7 +15834,7 @@ var enforceIanitorCheckType = createRule({
|
|
|
15826
15834
|
const name = getTypeName(node);
|
|
15827
15835
|
if (complexity >= config.interfacePenalty) {
|
|
15828
15836
|
context.report({
|
|
15829
|
-
data: { name: name
|
|
15837
|
+
data: { name: name ?? "unknown" },
|
|
15830
15838
|
messageId: "complexInterfaceNeedsCheck",
|
|
15831
15839
|
node
|
|
15832
15840
|
});
|
|
@@ -15889,6 +15897,283 @@ var enforceIanitorCheckType = createRule({
|
|
|
15889
15897
|
});
|
|
15890
15898
|
var enforce_ianitor_check_type_default = enforceIanitorCheckType;
|
|
15891
15899
|
|
|
15900
|
+
// src/utilities/format-utilities.ts
|
|
15901
|
+
import { readFileSync } from "node:fs";
|
|
15902
|
+
import { resolve as resolve2 } from "node:path";
|
|
15903
|
+
|
|
15904
|
+
// node_modules/arkregex/out/regex.js
|
|
15905
|
+
var regex2 = (src, flags) => new RegExp(src, flags);
|
|
15906
|
+
Object.assign(regex2, { as: regex2 });
|
|
15907
|
+
// src/oxfmt-sync.ts
|
|
15908
|
+
import { existsSync } from "node:fs";
|
|
15909
|
+
import { fileURLToPath } from "node:url";
|
|
15910
|
+
import { MessageChannel, receiveMessageOnPort, Worker } from "node:worker_threads";
|
|
15911
|
+
var FORMAT_TIMEOUT = 30000;
|
|
15912
|
+
var workerState;
|
|
15913
|
+
function resolveWorkerPath() {
|
|
15914
|
+
const jsPath = new URL("./oxfmt-worker.js", import.meta.url);
|
|
15915
|
+
const jsFilePath = fileURLToPath(jsPath);
|
|
15916
|
+
if (existsSync(jsFilePath))
|
|
15917
|
+
return jsPath;
|
|
15918
|
+
const tsPath = new URL("./oxfmt-worker.ts", import.meta.url);
|
|
15919
|
+
const tsFilePath = fileURLToPath(tsPath);
|
|
15920
|
+
if (existsSync(tsFilePath))
|
|
15921
|
+
return tsPath;
|
|
15922
|
+
throw new Error(`Oxfmt worker not found at ${jsFilePath} or ${tsFilePath}. Did you run 'bun run build'?`);
|
|
15923
|
+
}
|
|
15924
|
+
function getWorker() {
|
|
15925
|
+
if (workerState !== undefined)
|
|
15926
|
+
return workerState;
|
|
15927
|
+
const controlBuffer = new SharedArrayBuffer(4);
|
|
15928
|
+
const workerPath = resolveWorkerPath();
|
|
15929
|
+
const { port1: responsePort, port2: requestPort } = new MessageChannel;
|
|
15930
|
+
const worker = new Worker(workerPath, {
|
|
15931
|
+
stderr: true,
|
|
15932
|
+
stdout: true,
|
|
15933
|
+
transferList: [requestPort],
|
|
15934
|
+
workerData: { requestPort }
|
|
15935
|
+
});
|
|
15936
|
+
worker.unref();
|
|
15937
|
+
workerState = { controlBuffer, responsePort, worker };
|
|
15938
|
+
return workerState;
|
|
15939
|
+
}
|
|
15940
|
+
function formatSync(fileName, sourceText, options3 = {}) {
|
|
15941
|
+
const { controlBuffer, responsePort } = getWorker();
|
|
15942
|
+
const control = new Int32Array(controlBuffer);
|
|
15943
|
+
Atomics.store(control, 0, 0);
|
|
15944
|
+
const request = {
|
|
15945
|
+
controlBuffer,
|
|
15946
|
+
fileName,
|
|
15947
|
+
options: options3,
|
|
15948
|
+
sourceText
|
|
15949
|
+
};
|
|
15950
|
+
responsePort.postMessage(request);
|
|
15951
|
+
const waitResult = Atomics.wait(control, 0, 0, FORMAT_TIMEOUT);
|
|
15952
|
+
if (waitResult === "timed-out")
|
|
15953
|
+
throw new Error(`Oxfmt timed out after ${FORMAT_TIMEOUT}ms`);
|
|
15954
|
+
const received = receiveMessageOnPort(responsePort);
|
|
15955
|
+
if (received === undefined)
|
|
15956
|
+
throw new Error("No response received from oxfmt worker");
|
|
15957
|
+
const response = received.message;
|
|
15958
|
+
if (response.error !== undefined)
|
|
15959
|
+
throw new Error(response.error);
|
|
15960
|
+
if (response.code === undefined)
|
|
15961
|
+
throw new Error("Oxfmt returned undefined code");
|
|
15962
|
+
return response.code;
|
|
15963
|
+
}
|
|
15964
|
+
|
|
15965
|
+
// src/utilities/format-utilities.ts
|
|
15966
|
+
var cachedConfig;
|
|
15967
|
+
function loadOxfmtConfig() {
|
|
15968
|
+
if (cachedConfig !== undefined)
|
|
15969
|
+
return cachedConfig;
|
|
15970
|
+
try {
|
|
15971
|
+
const configPath = resolve2(process.cwd(), ".oxfmtrc.json");
|
|
15972
|
+
const configText = readFileSync(configPath, "utf8");
|
|
15973
|
+
const parsed = JSON.parse(configText);
|
|
15974
|
+
if (typeof parsed !== "object" || parsed === null) {
|
|
15975
|
+
cachedConfig = {};
|
|
15976
|
+
return cachedConfig;
|
|
15977
|
+
}
|
|
15978
|
+
const config = parsed;
|
|
15979
|
+
const { $schema: _schema, ignorePatterns: _ignore, ...formatOptions } = config;
|
|
15980
|
+
cachedConfig = formatOptions;
|
|
15981
|
+
return cachedConfig;
|
|
15982
|
+
} catch {
|
|
15983
|
+
cachedConfig = {};
|
|
15984
|
+
return cachedConfig;
|
|
15985
|
+
}
|
|
15986
|
+
}
|
|
15987
|
+
function getExtension(filePath) {
|
|
15988
|
+
if (filePath.endsWith(".tsx"))
|
|
15989
|
+
return ".tsx";
|
|
15990
|
+
if (filePath.endsWith(".ts"))
|
|
15991
|
+
return ".ts";
|
|
15992
|
+
if (filePath.endsWith(".jsx"))
|
|
15993
|
+
return ".jsx";
|
|
15994
|
+
if (filePath.endsWith(".js"))
|
|
15995
|
+
return ".js";
|
|
15996
|
+
if (filePath.endsWith(".mts"))
|
|
15997
|
+
return ".mts";
|
|
15998
|
+
if (filePath.endsWith(".mjs"))
|
|
15999
|
+
return ".mjs";
|
|
16000
|
+
if (filePath.endsWith(".cts"))
|
|
16001
|
+
return ".cts";
|
|
16002
|
+
if (filePath.endsWith(".cjs"))
|
|
16003
|
+
return ".cjs";
|
|
16004
|
+
return;
|
|
16005
|
+
}
|
|
16006
|
+
function formatWithOxfmtSync(source, filePath) {
|
|
16007
|
+
const extension = getExtension(filePath);
|
|
16008
|
+
if (extension === undefined)
|
|
16009
|
+
throw new Error(`Unsupported file extension for ${filePath}`);
|
|
16010
|
+
const config = loadOxfmtConfig();
|
|
16011
|
+
return formatSync(filePath, source, config);
|
|
16012
|
+
}
|
|
16013
|
+
function generateDifferences(original, formatted) {
|
|
16014
|
+
if (original === formatted)
|
|
16015
|
+
return [];
|
|
16016
|
+
return [
|
|
16017
|
+
{
|
|
16018
|
+
deleteText: original,
|
|
16019
|
+
insertText: formatted,
|
|
16020
|
+
offset: 0,
|
|
16021
|
+
operation: "REPLACE"
|
|
16022
|
+
}
|
|
16023
|
+
];
|
|
16024
|
+
}
|
|
16025
|
+
var MAX_LENGTH = 60;
|
|
16026
|
+
var SYMBOLS = {
|
|
16027
|
+
" ": "·",
|
|
16028
|
+
"\n": "␊",
|
|
16029
|
+
"\r": "␍",
|
|
16030
|
+
"\t": "→"
|
|
16031
|
+
};
|
|
16032
|
+
var WHITESPACE_REGEXP = regex2(`[\r
|
|
16033
|
+
]`, "g");
|
|
16034
|
+
function toSymbol(character) {
|
|
16035
|
+
return SYMBOLS[character] ?? character;
|
|
16036
|
+
}
|
|
16037
|
+
function showInvisibles(text) {
|
|
16038
|
+
let result = text;
|
|
16039
|
+
if (result.length > MAX_LENGTH)
|
|
16040
|
+
result = `${result.slice(0, MAX_LENGTH)}…`;
|
|
16041
|
+
return result.replaceAll(WHITESPACE_REGEXP, toSymbol);
|
|
16042
|
+
}
|
|
16043
|
+
|
|
16044
|
+
// src/rules/fast-format.ts
|
|
16045
|
+
var INSERT = "INSERT";
|
|
16046
|
+
var DELETE = "DELETE";
|
|
16047
|
+
var REPLACE = "REPLACE";
|
|
16048
|
+
var DEFAULT_CACHE_CAPACITY = 32;
|
|
16049
|
+
function getLocFromIndex(sourceCode, index2) {
|
|
16050
|
+
if (typeof sourceCode.getLocFromIndex === "function")
|
|
16051
|
+
return sourceCode.getLocFromIndex(index2);
|
|
16052
|
+
return { column: index2, line: 1 };
|
|
16053
|
+
}
|
|
16054
|
+
function createCacheKey(filename, source) {
|
|
16055
|
+
return `${filename}::${source}`;
|
|
16056
|
+
}
|
|
16057
|
+
function createLruCache(limit) {
|
|
16058
|
+
const entries = new Map;
|
|
16059
|
+
const capacity = Math.max(limit, 1);
|
|
16060
|
+
function clear() {
|
|
16061
|
+
entries.clear();
|
|
16062
|
+
}
|
|
16063
|
+
function get(key) {
|
|
16064
|
+
const value = entries.get(key);
|
|
16065
|
+
if (value === undefined)
|
|
16066
|
+
return;
|
|
16067
|
+
entries.delete(key);
|
|
16068
|
+
entries.set(key, value);
|
|
16069
|
+
return value;
|
|
16070
|
+
}
|
|
16071
|
+
function set(key, value) {
|
|
16072
|
+
entries.set(key, value);
|
|
16073
|
+
if (entries.size > capacity) {
|
|
16074
|
+
const oldestKey = entries.keys().next().value;
|
|
16075
|
+
if (oldestKey !== undefined)
|
|
16076
|
+
entries.delete(oldestKey);
|
|
16077
|
+
}
|
|
16078
|
+
return value;
|
|
16079
|
+
}
|
|
16080
|
+
return { clear, get, set };
|
|
16081
|
+
}
|
|
16082
|
+
function cacheFormattedResult(cache, filename, source, formatted) {
|
|
16083
|
+
const entry = { formatted, kind: "formatted" };
|
|
16084
|
+
const sourceKey = createCacheKey(filename, source);
|
|
16085
|
+
cache.set(sourceKey, entry);
|
|
16086
|
+
if (formatted !== source) {
|
|
16087
|
+
const formattedKey = createCacheKey(filename, formatted);
|
|
16088
|
+
cache.set(formattedKey, entry);
|
|
16089
|
+
}
|
|
16090
|
+
return entry;
|
|
16091
|
+
}
|
|
16092
|
+
function formatWithCaching(cache, filename, source, services) {
|
|
16093
|
+
const cacheKey = createCacheKey(filename, source);
|
|
16094
|
+
const cached = cache.get(cacheKey);
|
|
16095
|
+
if (cached !== undefined)
|
|
16096
|
+
return cached;
|
|
16097
|
+
try {
|
|
16098
|
+
const formatted = services.format(source, filename);
|
|
16099
|
+
return cacheFormattedResult(cache, filename, source, formatted);
|
|
16100
|
+
} catch (error2) {
|
|
16101
|
+
const message = error2 instanceof Error ? error2.message : String(error2);
|
|
16102
|
+
return cache.set(cacheKey, { kind: "error", message: `Oxfmt error: ${message}` });
|
|
16103
|
+
}
|
|
16104
|
+
}
|
|
16105
|
+
function createFormatCache(limit = DEFAULT_CACHE_CAPACITY) {
|
|
16106
|
+
return createLruCache(limit);
|
|
16107
|
+
}
|
|
16108
|
+
var defaultServices = {
|
|
16109
|
+
format: formatWithOxfmtSync,
|
|
16110
|
+
generate: generateDifferences,
|
|
16111
|
+
show: showInvisibles
|
|
16112
|
+
};
|
|
16113
|
+
var defaultCache = createFormatCache();
|
|
16114
|
+
function createFastFormatRule(options3 = {}) {
|
|
16115
|
+
const cache = options3.cache ?? defaultCache;
|
|
16116
|
+
const services = {
|
|
16117
|
+
format: options3.services?.format ?? defaultServices.format,
|
|
16118
|
+
generate: options3.services?.generate ?? defaultServices.generate,
|
|
16119
|
+
show: options3.services?.show ?? defaultServices.show
|
|
16120
|
+
};
|
|
16121
|
+
return {
|
|
16122
|
+
create(context) {
|
|
16123
|
+
const { filename, sourceCode } = context;
|
|
16124
|
+
if (getExtension(filename) === undefined)
|
|
16125
|
+
return {};
|
|
16126
|
+
return {
|
|
16127
|
+
Program() {
|
|
16128
|
+
const source = sourceCode.text;
|
|
16129
|
+
const outcome = formatWithCaching(cache, filename, source, services);
|
|
16130
|
+
if (outcome.kind === "error") {
|
|
16131
|
+
context.report({
|
|
16132
|
+
loc: { column: 0, line: 1 },
|
|
16133
|
+
message: outcome.message
|
|
16134
|
+
});
|
|
16135
|
+
return;
|
|
16136
|
+
}
|
|
16137
|
+
if (source === outcome.formatted)
|
|
16138
|
+
return;
|
|
16139
|
+
const differences = services.generate(source, outcome.formatted);
|
|
16140
|
+
for (const { operation, offset, deleteText, insertText } of differences) {
|
|
16141
|
+
const range = [offset, offset + (deleteText?.length ?? 0)];
|
|
16142
|
+
context.report({
|
|
16143
|
+
data: {
|
|
16144
|
+
deleteText: services.show(deleteText ?? ""),
|
|
16145
|
+
insertText: services.show(insertText ?? "")
|
|
16146
|
+
},
|
|
16147
|
+
fix: (fixer) => fixer.replaceTextRange(range, insertText ?? ""),
|
|
16148
|
+
loc: {
|
|
16149
|
+
end: getLocFromIndex(sourceCode, range[1]),
|
|
16150
|
+
start: getLocFromIndex(sourceCode, range[0])
|
|
16151
|
+
},
|
|
16152
|
+
messageId: operation
|
|
16153
|
+
});
|
|
16154
|
+
}
|
|
16155
|
+
}
|
|
16156
|
+
};
|
|
16157
|
+
},
|
|
16158
|
+
meta: {
|
|
16159
|
+
docs: {
|
|
16160
|
+
description: "Enforce oxfmt code formatting",
|
|
16161
|
+
recommended: true
|
|
16162
|
+
},
|
|
16163
|
+
fixable: "code",
|
|
16164
|
+
messages: {
|
|
16165
|
+
[INSERT]: "Insert `{{ insertText }}`",
|
|
16166
|
+
[DELETE]: "Delete `{{ deleteText }}`",
|
|
16167
|
+
[REPLACE]: "Replace `{{ deleteText }}` with `{{ insertText }}`"
|
|
16168
|
+
},
|
|
16169
|
+
schema: [],
|
|
16170
|
+
type: "layout"
|
|
16171
|
+
}
|
|
16172
|
+
};
|
|
16173
|
+
}
|
|
16174
|
+
var fastFormat = createFastFormatRule();
|
|
16175
|
+
var fast_format_default = fastFormat;
|
|
16176
|
+
|
|
15892
16177
|
// src/rules/no-async-constructor.ts
|
|
15893
16178
|
import { AST_NODE_TYPES } from "@typescript-eslint/types";
|
|
15894
16179
|
var PROMISE_CHAIN_METHODS = new Set(["then", "catch", "finally"]);
|
|
@@ -15990,9 +16275,8 @@ function isNonIIFEFunction(node, parent) {
|
|
|
15990
16275
|
if (node.type !== AST_NODE_TYPES.ArrowFunctionExpression && node.type !== AST_NODE_TYPES.FunctionExpression) {
|
|
15991
16276
|
return false;
|
|
15992
16277
|
}
|
|
15993
|
-
if (parent?.type === AST_NODE_TYPES.CallExpression && parent.callee === node)
|
|
16278
|
+
if (parent?.type === AST_NODE_TYPES.CallExpression && parent.callee === node)
|
|
15994
16279
|
return false;
|
|
15995
|
-
}
|
|
15996
16280
|
return true;
|
|
15997
16281
|
}
|
|
15998
16282
|
function findConstructorViolations(constructorBody, asyncMethods) {
|
|
@@ -16023,22 +16307,24 @@ function findConstructorViolations(constructorBody, asyncMethods) {
|
|
|
16023
16307
|
if (!hasDynamicProperties(current))
|
|
16024
16308
|
return;
|
|
16025
16309
|
for (const key in current) {
|
|
16026
|
-
|
|
16027
|
-
|
|
16028
|
-
|
|
16029
|
-
|
|
16030
|
-
|
|
16031
|
-
|
|
16032
|
-
|
|
16033
|
-
|
|
16034
|
-
|
|
16310
|
+
if (Object.hasOwn(current, key)) {
|
|
16311
|
+
const childValue = current[key];
|
|
16312
|
+
if (childValue === undefined)
|
|
16313
|
+
continue;
|
|
16314
|
+
if (Array.isArray(childValue)) {
|
|
16315
|
+
for (const item of childValue) {
|
|
16316
|
+
if (!isNode(item))
|
|
16317
|
+
continue;
|
|
16318
|
+
parentMap.set(item, current);
|
|
16319
|
+
traverse(item);
|
|
16320
|
+
}
|
|
16321
|
+
continue;
|
|
16035
16322
|
}
|
|
16036
|
-
|
|
16323
|
+
if (!isNode(childValue))
|
|
16324
|
+
continue;
|
|
16325
|
+
parentMap.set(childValue, current);
|
|
16326
|
+
traverse(childValue);
|
|
16037
16327
|
}
|
|
16038
|
-
if (!isNode(childValue))
|
|
16039
|
-
continue;
|
|
16040
|
-
parentMap.set(childValue, current);
|
|
16041
|
-
traverse(childValue);
|
|
16042
16328
|
}
|
|
16043
16329
|
}
|
|
16044
16330
|
traverse(constructorBody);
|
|
@@ -16182,7 +16468,7 @@ import { createRequire as createRequire4 } from "node:module";
|
|
|
16182
16468
|
import { createRequire as createRequire2 } from "node:module";
|
|
16183
16469
|
var require2 = createRequire2(import.meta.url);
|
|
16184
16470
|
var __dirname2 = new URL(".", import.meta.url).pathname;
|
|
16185
|
-
var { readFileSync } = require2("node:fs");
|
|
16471
|
+
var { readFileSync: readFileSync2 } = require2("node:fs");
|
|
16186
16472
|
var nativeBinding = null;
|
|
16187
16473
|
var loadErrors = [];
|
|
16188
16474
|
var isMusl = () => {
|
|
@@ -16201,7 +16487,7 @@ var isMusl = () => {
|
|
|
16201
16487
|
var isFileMusl = (f) => f.includes("libc.musl-") || f.includes("ld-musl-");
|
|
16202
16488
|
var isMuslFromFilesystem = () => {
|
|
16203
16489
|
try {
|
|
16204
|
-
return
|
|
16490
|
+
return readFileSync2("/usr/bin/ldd", "utf-8").includes("musl");
|
|
16205
16491
|
} catch {
|
|
16206
16492
|
return null;
|
|
16207
16493
|
}
|
|
@@ -16249,8 +16535,8 @@ function requireNative() {
|
|
|
16249
16535
|
try {
|
|
16250
16536
|
const binding = require2("@oxc-parser/binding-android-arm64");
|
|
16251
16537
|
const bindingPackageVersion = require2("@oxc-parser/binding-android-arm64/package.json").version;
|
|
16252
|
-
if (bindingPackageVersion !== "0.
|
|
16253
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
16538
|
+
if (bindingPackageVersion !== "0.104.0" && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0") {
|
|
16539
|
+
throw new Error(`Native binding package version mismatch, expected 0.104.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`);
|
|
16254
16540
|
}
|
|
16255
16541
|
return binding;
|
|
16256
16542
|
} catch (e) {
|
|
@@ -16265,8 +16551,8 @@ function requireNative() {
|
|
|
16265
16551
|
try {
|
|
16266
16552
|
const binding = require2("@oxc-parser/binding-android-arm-eabi");
|
|
16267
16553
|
const bindingPackageVersion = require2("@oxc-parser/binding-android-arm-eabi/package.json").version;
|
|
16268
|
-
if (bindingPackageVersion !== "0.
|
|
16269
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
16554
|
+
if (bindingPackageVersion !== "0.104.0" && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0") {
|
|
16555
|
+
throw new Error(`Native binding package version mismatch, expected 0.104.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`);
|
|
16270
16556
|
}
|
|
16271
16557
|
return binding;
|
|
16272
16558
|
} catch (e) {
|
|
@@ -16286,8 +16572,8 @@ function requireNative() {
|
|
|
16286
16572
|
try {
|
|
16287
16573
|
const binding = require2("@oxc-parser/binding-win32-x64-gnu");
|
|
16288
16574
|
const bindingPackageVersion = require2("@oxc-parser/binding-win32-x64-gnu/package.json").version;
|
|
16289
|
-
if (bindingPackageVersion !== "0.
|
|
16290
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
16575
|
+
if (bindingPackageVersion !== "0.104.0" && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0") {
|
|
16576
|
+
throw new Error(`Native binding package version mismatch, expected 0.104.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`);
|
|
16291
16577
|
}
|
|
16292
16578
|
return binding;
|
|
16293
16579
|
} catch (e) {
|
|
@@ -16302,8 +16588,8 @@ function requireNative() {
|
|
|
16302
16588
|
try {
|
|
16303
16589
|
const binding = require2("@oxc-parser/binding-win32-x64-msvc");
|
|
16304
16590
|
const bindingPackageVersion = require2("@oxc-parser/binding-win32-x64-msvc/package.json").version;
|
|
16305
|
-
if (bindingPackageVersion !== "0.
|
|
16306
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
16591
|
+
if (bindingPackageVersion !== "0.104.0" && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0") {
|
|
16592
|
+
throw new Error(`Native binding package version mismatch, expected 0.104.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`);
|
|
16307
16593
|
}
|
|
16308
16594
|
return binding;
|
|
16309
16595
|
} catch (e) {
|
|
@@ -16319,8 +16605,8 @@ function requireNative() {
|
|
|
16319
16605
|
try {
|
|
16320
16606
|
const binding = require2("@oxc-parser/binding-win32-ia32-msvc");
|
|
16321
16607
|
const bindingPackageVersion = require2("@oxc-parser/binding-win32-ia32-msvc/package.json").version;
|
|
16322
|
-
if (bindingPackageVersion !== "0.
|
|
16323
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
16608
|
+
if (bindingPackageVersion !== "0.104.0" && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0") {
|
|
16609
|
+
throw new Error(`Native binding package version mismatch, expected 0.104.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`);
|
|
16324
16610
|
}
|
|
16325
16611
|
return binding;
|
|
16326
16612
|
} catch (e) {
|
|
@@ -16335,8 +16621,8 @@ function requireNative() {
|
|
|
16335
16621
|
try {
|
|
16336
16622
|
const binding = require2("@oxc-parser/binding-win32-arm64-msvc");
|
|
16337
16623
|
const bindingPackageVersion = require2("@oxc-parser/binding-win32-arm64-msvc/package.json").version;
|
|
16338
|
-
if (bindingPackageVersion !== "0.
|
|
16339
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
16624
|
+
if (bindingPackageVersion !== "0.104.0" && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0") {
|
|
16625
|
+
throw new Error(`Native binding package version mismatch, expected 0.104.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`);
|
|
16340
16626
|
}
|
|
16341
16627
|
return binding;
|
|
16342
16628
|
} catch (e) {
|
|
@@ -16354,8 +16640,8 @@ function requireNative() {
|
|
|
16354
16640
|
try {
|
|
16355
16641
|
const binding = require2("@oxc-parser/binding-darwin-universal");
|
|
16356
16642
|
const bindingPackageVersion = require2("@oxc-parser/binding-darwin-universal/package.json").version;
|
|
16357
|
-
if (bindingPackageVersion !== "0.
|
|
16358
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
16643
|
+
if (bindingPackageVersion !== "0.104.0" && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0") {
|
|
16644
|
+
throw new Error(`Native binding package version mismatch, expected 0.104.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`);
|
|
16359
16645
|
}
|
|
16360
16646
|
return binding;
|
|
16361
16647
|
} catch (e) {
|
|
@@ -16370,8 +16656,8 @@ function requireNative() {
|
|
|
16370
16656
|
try {
|
|
16371
16657
|
const binding = require2("@oxc-parser/binding-darwin-x64");
|
|
16372
16658
|
const bindingPackageVersion = require2("@oxc-parser/binding-darwin-x64/package.json").version;
|
|
16373
|
-
if (bindingPackageVersion !== "0.
|
|
16374
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
16659
|
+
if (bindingPackageVersion !== "0.104.0" && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0") {
|
|
16660
|
+
throw new Error(`Native binding package version mismatch, expected 0.104.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`);
|
|
16375
16661
|
}
|
|
16376
16662
|
return binding;
|
|
16377
16663
|
} catch (e) {
|
|
@@ -16386,8 +16672,8 @@ function requireNative() {
|
|
|
16386
16672
|
try {
|
|
16387
16673
|
const binding = require2("@oxc-parser/binding-darwin-arm64");
|
|
16388
16674
|
const bindingPackageVersion = require2("@oxc-parser/binding-darwin-arm64/package.json").version;
|
|
16389
|
-
if (bindingPackageVersion !== "0.
|
|
16390
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
16675
|
+
if (bindingPackageVersion !== "0.104.0" && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0") {
|
|
16676
|
+
throw new Error(`Native binding package version mismatch, expected 0.104.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`);
|
|
16391
16677
|
}
|
|
16392
16678
|
return binding;
|
|
16393
16679
|
} catch (e) {
|
|
@@ -16406,8 +16692,8 @@ function requireNative() {
|
|
|
16406
16692
|
try {
|
|
16407
16693
|
const binding = require2("@oxc-parser/binding-freebsd-x64");
|
|
16408
16694
|
const bindingPackageVersion = require2("@oxc-parser/binding-freebsd-x64/package.json").version;
|
|
16409
|
-
if (bindingPackageVersion !== "0.
|
|
16410
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
16695
|
+
if (bindingPackageVersion !== "0.104.0" && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0") {
|
|
16696
|
+
throw new Error(`Native binding package version mismatch, expected 0.104.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`);
|
|
16411
16697
|
}
|
|
16412
16698
|
return binding;
|
|
16413
16699
|
} catch (e) {
|
|
@@ -16422,8 +16708,8 @@ function requireNative() {
|
|
|
16422
16708
|
try {
|
|
16423
16709
|
const binding = require2("@oxc-parser/binding-freebsd-arm64");
|
|
16424
16710
|
const bindingPackageVersion = require2("@oxc-parser/binding-freebsd-arm64/package.json").version;
|
|
16425
|
-
if (bindingPackageVersion !== "0.
|
|
16426
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
16711
|
+
if (bindingPackageVersion !== "0.104.0" && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0") {
|
|
16712
|
+
throw new Error(`Native binding package version mismatch, expected 0.104.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`);
|
|
16427
16713
|
}
|
|
16428
16714
|
return binding;
|
|
16429
16715
|
} catch (e) {
|
|
@@ -16443,8 +16729,8 @@ function requireNative() {
|
|
|
16443
16729
|
try {
|
|
16444
16730
|
const binding = require2("@oxc-parser/binding-linux-x64-musl");
|
|
16445
16731
|
const bindingPackageVersion = require2("@oxc-parser/binding-linux-x64-musl/package.json").version;
|
|
16446
|
-
if (bindingPackageVersion !== "0.
|
|
16447
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
16732
|
+
if (bindingPackageVersion !== "0.104.0" && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0") {
|
|
16733
|
+
throw new Error(`Native binding package version mismatch, expected 0.104.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`);
|
|
16448
16734
|
}
|
|
16449
16735
|
return binding;
|
|
16450
16736
|
} catch (e) {
|
|
@@ -16459,8 +16745,8 @@ function requireNative() {
|
|
|
16459
16745
|
try {
|
|
16460
16746
|
const binding = require2("@oxc-parser/binding-linux-x64-gnu");
|
|
16461
16747
|
const bindingPackageVersion = require2("@oxc-parser/binding-linux-x64-gnu/package.json").version;
|
|
16462
|
-
if (bindingPackageVersion !== "0.
|
|
16463
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
16748
|
+
if (bindingPackageVersion !== "0.104.0" && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0") {
|
|
16749
|
+
throw new Error(`Native binding package version mismatch, expected 0.104.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`);
|
|
16464
16750
|
}
|
|
16465
16751
|
return binding;
|
|
16466
16752
|
} catch (e) {
|
|
@@ -16477,8 +16763,8 @@ function requireNative() {
|
|
|
16477
16763
|
try {
|
|
16478
16764
|
const binding = require2("@oxc-parser/binding-linux-arm64-musl");
|
|
16479
16765
|
const bindingPackageVersion = require2("@oxc-parser/binding-linux-arm64-musl/package.json").version;
|
|
16480
|
-
if (bindingPackageVersion !== "0.
|
|
16481
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
16766
|
+
if (bindingPackageVersion !== "0.104.0" && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0") {
|
|
16767
|
+
throw new Error(`Native binding package version mismatch, expected 0.104.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`);
|
|
16482
16768
|
}
|
|
16483
16769
|
return binding;
|
|
16484
16770
|
} catch (e) {
|
|
@@ -16493,8 +16779,8 @@ function requireNative() {
|
|
|
16493
16779
|
try {
|
|
16494
16780
|
const binding = require2("@oxc-parser/binding-linux-arm64-gnu");
|
|
16495
16781
|
const bindingPackageVersion = require2("@oxc-parser/binding-linux-arm64-gnu/package.json").version;
|
|
16496
|
-
if (bindingPackageVersion !== "0.
|
|
16497
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
16782
|
+
if (bindingPackageVersion !== "0.104.0" && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0") {
|
|
16783
|
+
throw new Error(`Native binding package version mismatch, expected 0.104.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`);
|
|
16498
16784
|
}
|
|
16499
16785
|
return binding;
|
|
16500
16786
|
} catch (e) {
|
|
@@ -16511,8 +16797,8 @@ function requireNative() {
|
|
|
16511
16797
|
try {
|
|
16512
16798
|
const binding = require2("@oxc-parser/binding-linux-arm-musleabihf");
|
|
16513
16799
|
const bindingPackageVersion = require2("@oxc-parser/binding-linux-arm-musleabihf/package.json").version;
|
|
16514
|
-
if (bindingPackageVersion !== "0.
|
|
16515
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
16800
|
+
if (bindingPackageVersion !== "0.104.0" && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0") {
|
|
16801
|
+
throw new Error(`Native binding package version mismatch, expected 0.104.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`);
|
|
16516
16802
|
}
|
|
16517
16803
|
return binding;
|
|
16518
16804
|
} catch (e) {
|
|
@@ -16527,8 +16813,8 @@ function requireNative() {
|
|
|
16527
16813
|
try {
|
|
16528
16814
|
const binding = require2("@oxc-parser/binding-linux-arm-gnueabihf");
|
|
16529
16815
|
const bindingPackageVersion = require2("@oxc-parser/binding-linux-arm-gnueabihf/package.json").version;
|
|
16530
|
-
if (bindingPackageVersion !== "0.
|
|
16531
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
16816
|
+
if (bindingPackageVersion !== "0.104.0" && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0") {
|
|
16817
|
+
throw new Error(`Native binding package version mismatch, expected 0.104.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`);
|
|
16532
16818
|
}
|
|
16533
16819
|
return binding;
|
|
16534
16820
|
} catch (e) {
|
|
@@ -16545,8 +16831,8 @@ function requireNative() {
|
|
|
16545
16831
|
try {
|
|
16546
16832
|
const binding = require2("@oxc-parser/binding-linux-loong64-musl");
|
|
16547
16833
|
const bindingPackageVersion = require2("@oxc-parser/binding-linux-loong64-musl/package.json").version;
|
|
16548
|
-
if (bindingPackageVersion !== "0.
|
|
16549
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
16834
|
+
if (bindingPackageVersion !== "0.104.0" && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0") {
|
|
16835
|
+
throw new Error(`Native binding package version mismatch, expected 0.104.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`);
|
|
16550
16836
|
}
|
|
16551
16837
|
return binding;
|
|
16552
16838
|
} catch (e) {
|
|
@@ -16561,8 +16847,8 @@ function requireNative() {
|
|
|
16561
16847
|
try {
|
|
16562
16848
|
const binding = require2("@oxc-parser/binding-linux-loong64-gnu");
|
|
16563
16849
|
const bindingPackageVersion = require2("@oxc-parser/binding-linux-loong64-gnu/package.json").version;
|
|
16564
|
-
if (bindingPackageVersion !== "0.
|
|
16565
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
16850
|
+
if (bindingPackageVersion !== "0.104.0" && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0") {
|
|
16851
|
+
throw new Error(`Native binding package version mismatch, expected 0.104.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`);
|
|
16566
16852
|
}
|
|
16567
16853
|
return binding;
|
|
16568
16854
|
} catch (e) {
|
|
@@ -16579,8 +16865,8 @@ function requireNative() {
|
|
|
16579
16865
|
try {
|
|
16580
16866
|
const binding = require2("@oxc-parser/binding-linux-riscv64-musl");
|
|
16581
16867
|
const bindingPackageVersion = require2("@oxc-parser/binding-linux-riscv64-musl/package.json").version;
|
|
16582
|
-
if (bindingPackageVersion !== "0.
|
|
16583
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
16868
|
+
if (bindingPackageVersion !== "0.104.0" && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0") {
|
|
16869
|
+
throw new Error(`Native binding package version mismatch, expected 0.104.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`);
|
|
16584
16870
|
}
|
|
16585
16871
|
return binding;
|
|
16586
16872
|
} catch (e) {
|
|
@@ -16595,8 +16881,8 @@ function requireNative() {
|
|
|
16595
16881
|
try {
|
|
16596
16882
|
const binding = require2("@oxc-parser/binding-linux-riscv64-gnu");
|
|
16597
16883
|
const bindingPackageVersion = require2("@oxc-parser/binding-linux-riscv64-gnu/package.json").version;
|
|
16598
|
-
if (bindingPackageVersion !== "0.
|
|
16599
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
16884
|
+
if (bindingPackageVersion !== "0.104.0" && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0") {
|
|
16885
|
+
throw new Error(`Native binding package version mismatch, expected 0.104.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`);
|
|
16600
16886
|
}
|
|
16601
16887
|
return binding;
|
|
16602
16888
|
} catch (e) {
|
|
@@ -16612,8 +16898,8 @@ function requireNative() {
|
|
|
16612
16898
|
try {
|
|
16613
16899
|
const binding = require2("@oxc-parser/binding-linux-ppc64-gnu");
|
|
16614
16900
|
const bindingPackageVersion = require2("@oxc-parser/binding-linux-ppc64-gnu/package.json").version;
|
|
16615
|
-
if (bindingPackageVersion !== "0.
|
|
16616
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
16901
|
+
if (bindingPackageVersion !== "0.104.0" && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0") {
|
|
16902
|
+
throw new Error(`Native binding package version mismatch, expected 0.104.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`);
|
|
16617
16903
|
}
|
|
16618
16904
|
return binding;
|
|
16619
16905
|
} catch (e) {
|
|
@@ -16628,8 +16914,8 @@ function requireNative() {
|
|
|
16628
16914
|
try {
|
|
16629
16915
|
const binding = require2("@oxc-parser/binding-linux-s390x-gnu");
|
|
16630
16916
|
const bindingPackageVersion = require2("@oxc-parser/binding-linux-s390x-gnu/package.json").version;
|
|
16631
|
-
if (bindingPackageVersion !== "0.
|
|
16632
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
16917
|
+
if (bindingPackageVersion !== "0.104.0" && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0") {
|
|
16918
|
+
throw new Error(`Native binding package version mismatch, expected 0.104.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`);
|
|
16633
16919
|
}
|
|
16634
16920
|
return binding;
|
|
16635
16921
|
} catch (e) {
|
|
@@ -16648,8 +16934,8 @@ function requireNative() {
|
|
|
16648
16934
|
try {
|
|
16649
16935
|
const binding = require2("@oxc-parser/binding-openharmony-arm64");
|
|
16650
16936
|
const bindingPackageVersion = require2("@oxc-parser/binding-openharmony-arm64/package.json").version;
|
|
16651
|
-
if (bindingPackageVersion !== "0.
|
|
16652
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
16937
|
+
if (bindingPackageVersion !== "0.104.0" && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0") {
|
|
16938
|
+
throw new Error(`Native binding package version mismatch, expected 0.104.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`);
|
|
16653
16939
|
}
|
|
16654
16940
|
return binding;
|
|
16655
16941
|
} catch (e) {
|
|
@@ -16664,8 +16950,8 @@ function requireNative() {
|
|
|
16664
16950
|
try {
|
|
16665
16951
|
const binding = require2("@oxc-parser/binding-openharmony-x64");
|
|
16666
16952
|
const bindingPackageVersion = require2("@oxc-parser/binding-openharmony-x64/package.json").version;
|
|
16667
|
-
if (bindingPackageVersion !== "0.
|
|
16668
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
16953
|
+
if (bindingPackageVersion !== "0.104.0" && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0") {
|
|
16954
|
+
throw new Error(`Native binding package version mismatch, expected 0.104.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`);
|
|
16669
16955
|
}
|
|
16670
16956
|
return binding;
|
|
16671
16957
|
} catch (e) {
|
|
@@ -16680,8 +16966,8 @@ function requireNative() {
|
|
|
16680
16966
|
try {
|
|
16681
16967
|
const binding = require2("@oxc-parser/binding-openharmony-arm");
|
|
16682
16968
|
const bindingPackageVersion = require2("@oxc-parser/binding-openharmony-arm/package.json").version;
|
|
16683
|
-
if (bindingPackageVersion !== "0.
|
|
16684
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
16969
|
+
if (bindingPackageVersion !== "0.104.0" && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0") {
|
|
16970
|
+
throw new Error(`Native binding package version mismatch, expected 0.104.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`);
|
|
16685
16971
|
}
|
|
16686
16972
|
return binding;
|
|
16687
16973
|
} catch (e) {
|
|
@@ -16790,7 +17076,7 @@ function applyFix(program, fixPath) {
|
|
|
16790
17076
|
}
|
|
16791
17077
|
}
|
|
16792
17078
|
|
|
16793
|
-
// node_modules/oxc-parser/generated/visit/keys.js
|
|
17079
|
+
// node_modules/oxc-parser/src-js/generated/visit/keys.js
|
|
16794
17080
|
var { freeze } = Object;
|
|
16795
17081
|
var $EMPTY = freeze([]);
|
|
16796
17082
|
var DECORATORS__KEY__TYPE_ANNOTATION__VALUE = freeze([
|
|
@@ -16961,7 +17247,7 @@ var keys_default = freeze({
|
|
|
16961
17247
|
TSExternalModuleReference: EXPRESSION,
|
|
16962
17248
|
TSFunctionType: TYPE_PARAMETERS__PARAMS__RETURN_TYPE,
|
|
16963
17249
|
TSImportEqualsDeclaration: freeze(["id", "moduleReference"]),
|
|
16964
|
-
TSImportType: freeze(["
|
|
17250
|
+
TSImportType: freeze(["source", "options", "qualifier", "typeArguments"]),
|
|
16965
17251
|
TSIndexSignature: freeze(["parameters", "typeAnnotation"]),
|
|
16966
17252
|
TSIndexedAccessType: freeze(["objectType", "indexType"]),
|
|
16967
17253
|
TSInferType: freeze(["typeParameter"]),
|
|
@@ -17014,7 +17300,7 @@ class Visitor {
|
|
|
17014
17300
|
constructor(visitor) {
|
|
17015
17301
|
if (walkProgram === null) {
|
|
17016
17302
|
const require3 = createRequire3(import.meta.url);
|
|
17017
|
-
({ walkProgram } = require3("
|
|
17303
|
+
({ walkProgram } = require3("../generated/visit/walk.js"));
|
|
17018
17304
|
({
|
|
17019
17305
|
addVisitorToCompiled,
|
|
17020
17306
|
createCompiledVisitor,
|
|
@@ -17106,8 +17392,8 @@ function createCamelCaseDetector(probability) {
|
|
|
17106
17392
|
}
|
|
17107
17393
|
|
|
17108
17394
|
// src/recognizers/contains-detector.ts
|
|
17109
|
-
var WHITESPACE_GLOBAL_REGEX =
|
|
17110
|
-
var ESCAPE =
|
|
17395
|
+
var WHITESPACE_GLOBAL_REGEX = regex2("\\s+", "g");
|
|
17396
|
+
var ESCAPE = regex2("[-/\\^$*+?.()|[\\]{}]", "g");
|
|
17111
17397
|
function escapeForRegex(value) {
|
|
17112
17398
|
return value.replaceAll(ESCAPE, String.raw`\$&`);
|
|
17113
17399
|
}
|
|
@@ -17130,17 +17416,17 @@ function createContainsDetector(probability, patterns2) {
|
|
|
17130
17416
|
}
|
|
17131
17417
|
|
|
17132
17418
|
// src/recognizers/end-with-detector.ts
|
|
17133
|
-
var WHITESPACE_REGEX =
|
|
17419
|
+
var WHITESPACE_REGEX = regex2("\\s");
|
|
17134
17420
|
function createEndWithDetector(probability, endings) {
|
|
17135
17421
|
const endingsSet = new Set(endings);
|
|
17136
17422
|
return {
|
|
17137
17423
|
probability,
|
|
17138
17424
|
scan(line) {
|
|
17139
17425
|
for (let index2 = line.length - 1;index2 >= 0; index2 -= 1) {
|
|
17140
|
-
const
|
|
17141
|
-
if (endingsSet.has(
|
|
17426
|
+
const character = line.charAt(index2);
|
|
17427
|
+
if (endingsSet.has(character))
|
|
17142
17428
|
return 1;
|
|
17143
|
-
if (!WHITESPACE_REGEX.test(
|
|
17429
|
+
if (!WHITESPACE_REGEX.test(character) && character !== "*" && character !== "/")
|
|
17144
17430
|
return 0;
|
|
17145
17431
|
}
|
|
17146
17432
|
return 0;
|
|
@@ -17258,7 +17544,7 @@ function groupComments(comments, sourceCode) {
|
|
|
17258
17544
|
if (size > 0) {
|
|
17259
17545
|
groups[groupsSize++] = {
|
|
17260
17546
|
comments: currentLineComments,
|
|
17261
|
-
value: currentLineComments.map((
|
|
17547
|
+
value: currentLineComments.map(({ value }) => value).join(`
|
|
17262
17548
|
`)
|
|
17263
17549
|
};
|
|
17264
17550
|
currentLineComments = [];
|
|
@@ -17341,7 +17627,7 @@ function toParsedStatements(body) {
|
|
|
17341
17627
|
function isExpressionExclusion(statement, codeText) {
|
|
17342
17628
|
if (statement.type !== "ExpressionStatement")
|
|
17343
17629
|
return false;
|
|
17344
|
-
const expression = statement
|
|
17630
|
+
const { expression } = statement;
|
|
17345
17631
|
if (!expression)
|
|
17346
17632
|
return false;
|
|
17347
17633
|
if (expression.type === "Identifier")
|
|
@@ -17418,7 +17704,7 @@ var noCommentedCode = {
|
|
|
17418
17704
|
if (containsCode(balanced, context.filename)) {
|
|
17419
17705
|
const firstComment = group.comments.at(0);
|
|
17420
17706
|
const lastComment = group.comments.at(-1);
|
|
17421
|
-
if (!firstComment
|
|
17707
|
+
if (!(firstComment && lastComment))
|
|
17422
17708
|
continue;
|
|
17423
17709
|
context.report({
|
|
17424
17710
|
loc: {
|
|
@@ -17455,8 +17741,544 @@ var noCommentedCode = {
|
|
|
17455
17741
|
};
|
|
17456
17742
|
var no_commented_code_default = noCommentedCode;
|
|
17457
17743
|
|
|
17744
|
+
// src/rules/no-god-components.ts
|
|
17745
|
+
import { TSESTree as TSESTree5 } from "@typescript-eslint/types";
|
|
17746
|
+
var COMPONENT_NAME_PATTERN = /^[A-Z]/;
|
|
17747
|
+
var FUNCTION_BOUNDARIES = new Set([
|
|
17748
|
+
TSESTree5.AST_NODE_TYPES.FunctionDeclaration,
|
|
17749
|
+
TSESTree5.AST_NODE_TYPES.FunctionExpression,
|
|
17750
|
+
TSESTree5.AST_NODE_TYPES.ArrowFunctionExpression
|
|
17751
|
+
]);
|
|
17752
|
+
var RUNTIME_TS_WRAPPERS = new Set([
|
|
17753
|
+
"ParenthesizedExpression",
|
|
17754
|
+
"TSAsExpression",
|
|
17755
|
+
"TSSatisfiesExpression",
|
|
17756
|
+
"TSTypeAssertion",
|
|
17757
|
+
"TSNonNullExpression",
|
|
17758
|
+
"TSInstantiationExpression",
|
|
17759
|
+
"ChainExpression"
|
|
17760
|
+
]);
|
|
17761
|
+
function isComponentName(name) {
|
|
17762
|
+
return COMPONENT_NAME_PATTERN.test(name);
|
|
17763
|
+
}
|
|
17764
|
+
function isReactComponentHOC(callExpr) {
|
|
17765
|
+
const { callee } = callExpr;
|
|
17766
|
+
if (callee.type === TSESTree5.AST_NODE_TYPES.Identifier)
|
|
17767
|
+
return callee.name === "forwardRef" || callee.name === "memo";
|
|
17768
|
+
if (callee.type === TSESTree5.AST_NODE_TYPES.MemberExpression && callee.object.type === TSESTree5.AST_NODE_TYPES.Identifier && callee.object.name === "React" && callee.property.type === TSESTree5.AST_NODE_TYPES.Identifier)
|
|
17769
|
+
return callee.property.name === "forwardRef" || callee.property.name === "memo";
|
|
17770
|
+
return false;
|
|
17771
|
+
}
|
|
17772
|
+
function getComponentNameFromFunction(node) {
|
|
17773
|
+
if (node.type === TSESTree5.AST_NODE_TYPES.FunctionDeclaration && node.id && isComponentName(node.id.name)) {
|
|
17774
|
+
return node.id.name;
|
|
17775
|
+
}
|
|
17776
|
+
if (node.type === TSESTree5.AST_NODE_TYPES.FunctionExpression || node.type === TSESTree5.AST_NODE_TYPES.ArrowFunctionExpression) {
|
|
17777
|
+
const { parent } = node;
|
|
17778
|
+
if (parent === null || parent === undefined)
|
|
17779
|
+
return;
|
|
17780
|
+
if (parent.type === TSESTree5.AST_NODE_TYPES.VariableDeclarator && parent.id.type === TSESTree5.AST_NODE_TYPES.Identifier && isComponentName(parent.id.name)) {
|
|
17781
|
+
return parent.id.name;
|
|
17782
|
+
}
|
|
17783
|
+
if (parent.type === TSESTree5.AST_NODE_TYPES.Property && parent.key.type === TSESTree5.AST_NODE_TYPES.Identifier && isComponentName(parent.key.name)) {
|
|
17784
|
+
return parent.key.name;
|
|
17785
|
+
}
|
|
17786
|
+
if (parent.type === TSESTree5.AST_NODE_TYPES.MethodDefinition && parent.key.type === TSESTree5.AST_NODE_TYPES.Identifier && isComponentName(parent.key.name)) {
|
|
17787
|
+
return parent.key.name;
|
|
17788
|
+
}
|
|
17789
|
+
}
|
|
17790
|
+
return;
|
|
17791
|
+
}
|
|
17792
|
+
function getComponentNameFromCallParent(callExpr) {
|
|
17793
|
+
const { parent } = callExpr;
|
|
17794
|
+
if (parent === null || parent === undefined)
|
|
17795
|
+
return;
|
|
17796
|
+
if (parent.type === TSESTree5.AST_NODE_TYPES.VariableDeclarator && parent.id.type === TSESTree5.AST_NODE_TYPES.Identifier && isComponentName(parent.id.name)) {
|
|
17797
|
+
return parent.id.name;
|
|
17798
|
+
}
|
|
17799
|
+
if (parent.type === TSESTree5.AST_NODE_TYPES.AssignmentExpression && parent.left.type === TSESTree5.AST_NODE_TYPES.Identifier && isComponentName(parent.left.name)) {
|
|
17800
|
+
return parent.left.name;
|
|
17801
|
+
}
|
|
17802
|
+
if (parent.type === TSESTree5.AST_NODE_TYPES.ExportDefaultDeclaration && callExpr.arguments.length > 0) {
|
|
17803
|
+
const [firstArg] = callExpr.arguments;
|
|
17804
|
+
if (firstArg && firstArg.type === TSESTree5.AST_NODE_TYPES.FunctionExpression && firstArg.id && isComponentName(firstArg.id.name)) {
|
|
17805
|
+
return firstArg.id.name;
|
|
17806
|
+
}
|
|
17807
|
+
}
|
|
17808
|
+
return;
|
|
17809
|
+
}
|
|
17810
|
+
function getHookName(callExpression) {
|
|
17811
|
+
const { callee } = callExpression;
|
|
17812
|
+
if (callee.type === TSESTree5.AST_NODE_TYPES.Identifier)
|
|
17813
|
+
return callee.name;
|
|
17814
|
+
if (callee.type === TSESTree5.AST_NODE_TYPES.MemberExpression && callee.property.type === TSESTree5.AST_NODE_TYPES.Identifier) {
|
|
17815
|
+
return callee.property.name;
|
|
17816
|
+
}
|
|
17817
|
+
return;
|
|
17818
|
+
}
|
|
17819
|
+
function countDestructuredProps(node) {
|
|
17820
|
+
const [firstParam] = node.params;
|
|
17821
|
+
if (!firstParam)
|
|
17822
|
+
return;
|
|
17823
|
+
let pattern4;
|
|
17824
|
+
if (firstParam.type === TSESTree5.AST_NODE_TYPES.ObjectPattern)
|
|
17825
|
+
pattern4 = firstParam;
|
|
17826
|
+
if (firstParam.type === TSESTree5.AST_NODE_TYPES.AssignmentPattern && firstParam.left.type === TSESTree5.AST_NODE_TYPES.ObjectPattern) {
|
|
17827
|
+
pattern4 = firstParam.left;
|
|
17828
|
+
}
|
|
17829
|
+
if (!pattern4)
|
|
17830
|
+
return;
|
|
17831
|
+
let count = 0;
|
|
17832
|
+
for (const { type: type3 } of pattern4.properties)
|
|
17833
|
+
if (type3 === TSESTree5.AST_NODE_TYPES.Property)
|
|
17834
|
+
count += 1;
|
|
17835
|
+
return count;
|
|
17836
|
+
}
|
|
17837
|
+
function isTypeOnlyNullLiteral(node) {
|
|
17838
|
+
const { parent } = node;
|
|
17839
|
+
if (parent === null || parent === undefined)
|
|
17840
|
+
return false;
|
|
17841
|
+
if (typeof parent.type === "string" && parent.type.startsWith("TS") && !RUNTIME_TS_WRAPPERS.has(parent.type))
|
|
17842
|
+
return true;
|
|
17843
|
+
if (parent.type === TSESTree5.AST_NODE_TYPES.TSLiteralType)
|
|
17844
|
+
return true;
|
|
17845
|
+
return false;
|
|
17846
|
+
}
|
|
17847
|
+
function analyzeComponentBody(functionNode, sourceCode, stateHooks) {
|
|
17848
|
+
let maxJsxDepth = 0;
|
|
17849
|
+
let stateHookCount = 0;
|
|
17850
|
+
const nullLiterals = new Array;
|
|
17851
|
+
function visit(current, jsxDepth) {
|
|
17852
|
+
if (FUNCTION_BOUNDARIES.has(current.type) && current !== functionNode)
|
|
17853
|
+
return;
|
|
17854
|
+
let nextDepth = jsxDepth;
|
|
17855
|
+
if (current.type === TSESTree5.AST_NODE_TYPES.JSXElement || current.type === TSESTree5.AST_NODE_TYPES.JSXFragment) {
|
|
17856
|
+
nextDepth = jsxDepth + 1;
|
|
17857
|
+
if (nextDepth > maxJsxDepth)
|
|
17858
|
+
maxJsxDepth = nextDepth;
|
|
17859
|
+
}
|
|
17860
|
+
if (current.type === TSESTree5.AST_NODE_TYPES.CallExpression) {
|
|
17861
|
+
const hookName = getHookName(current);
|
|
17862
|
+
if (typeof hookName === "string" && hookName.length > 0 && stateHooks.has(hookName))
|
|
17863
|
+
stateHookCount += 1;
|
|
17864
|
+
}
|
|
17865
|
+
if (current.type === TSESTree5.AST_NODE_TYPES.Literal && current.value === null) {
|
|
17866
|
+
const literalNode = current;
|
|
17867
|
+
if (!isTypeOnlyNullLiteral(literalNode))
|
|
17868
|
+
nullLiterals.push(literalNode);
|
|
17869
|
+
}
|
|
17870
|
+
function getVisitorKeysForNodeType(nodeType) {
|
|
17871
|
+
const visitorKeysUnknown = sourceCode.visitorKeys;
|
|
17872
|
+
if (visitorKeysUnknown === null || visitorKeysUnknown === undefined || typeof visitorKeysUnknown !== "object")
|
|
17873
|
+
return [];
|
|
17874
|
+
const visitorKeysRecord = visitorKeysUnknown;
|
|
17875
|
+
const keysUnknown = visitorKeysRecord[nodeType];
|
|
17876
|
+
if (!Array.isArray(keysUnknown))
|
|
17877
|
+
return [];
|
|
17878
|
+
const keys3 = new Array;
|
|
17879
|
+
for (const key of keysUnknown)
|
|
17880
|
+
if (typeof key === "string")
|
|
17881
|
+
keys3.push(key);
|
|
17882
|
+
return keys3;
|
|
17883
|
+
}
|
|
17884
|
+
const keys2 = getVisitorKeysForNodeType(current.type);
|
|
17885
|
+
const currentRecord = current;
|
|
17886
|
+
for (const key of keys2) {
|
|
17887
|
+
const value = currentRecord[key];
|
|
17888
|
+
if (Array.isArray(value)) {
|
|
17889
|
+
for (const item of value) {
|
|
17890
|
+
if (typeof item === "object" && item !== null && "type" in item) {
|
|
17891
|
+
visit(item, nextDepth);
|
|
17892
|
+
}
|
|
17893
|
+
}
|
|
17894
|
+
continue;
|
|
17895
|
+
}
|
|
17896
|
+
if (typeof value === "object" && value !== null && "type" in value) {
|
|
17897
|
+
visit(value, nextDepth);
|
|
17898
|
+
}
|
|
17899
|
+
}
|
|
17900
|
+
}
|
|
17901
|
+
visit(functionNode.body, 0);
|
|
17902
|
+
return { maxJsxDepth, nullLiterals, stateHookCount };
|
|
17903
|
+
}
|
|
17904
|
+
function parseOptions(options3) {
|
|
17905
|
+
const defaults = {
|
|
17906
|
+
enforceTargetLines: true,
|
|
17907
|
+
ignoreComponents: [],
|
|
17908
|
+
maxDestructuredProps: 5,
|
|
17909
|
+
maxLines: 200,
|
|
17910
|
+
maxStateHooks: 5,
|
|
17911
|
+
maxTsxNesting: 3,
|
|
17912
|
+
stateHooks: ["useState", "useReducer", "useBinding"],
|
|
17913
|
+
targetLines: 120
|
|
17914
|
+
};
|
|
17915
|
+
if (typeof options3 !== "object" || options3 === null)
|
|
17916
|
+
return defaults;
|
|
17917
|
+
const cast = options3;
|
|
17918
|
+
return {
|
|
17919
|
+
enforceTargetLines: typeof cast.enforceTargetLines === "boolean" ? cast.enforceTargetLines : defaults.enforceTargetLines,
|
|
17920
|
+
ignoreComponents: Array.isArray(cast.ignoreComponents) ? cast.ignoreComponents : defaults.ignoreComponents,
|
|
17921
|
+
maxDestructuredProps: typeof cast.maxDestructuredProps === "number" ? cast.maxDestructuredProps : defaults.maxDestructuredProps,
|
|
17922
|
+
maxLines: typeof cast.maxLines === "number" ? cast.maxLines : defaults.maxLines,
|
|
17923
|
+
maxStateHooks: typeof cast.maxStateHooks === "number" ? cast.maxStateHooks : defaults.maxStateHooks,
|
|
17924
|
+
maxTsxNesting: typeof cast.maxTsxNesting === "number" ? cast.maxTsxNesting : defaults.maxTsxNesting,
|
|
17925
|
+
stateHooks: Array.isArray(cast.stateHooks) ? cast.stateHooks : defaults.stateHooks,
|
|
17926
|
+
targetLines: typeof cast.targetLines === "number" ? cast.targetLines : defaults.targetLines
|
|
17927
|
+
};
|
|
17928
|
+
}
|
|
17929
|
+
var noGodComponents = {
|
|
17930
|
+
create(context) {
|
|
17931
|
+
const configuration = parseOptions(context.options[0]);
|
|
17932
|
+
const ignoreSet = new Set(configuration.ignoreComponents);
|
|
17933
|
+
const stateHooks = new Set(configuration.stateHooks);
|
|
17934
|
+
const checked = new WeakSet;
|
|
17935
|
+
const { sourceCode } = context;
|
|
17936
|
+
function checkComponent(node, name) {
|
|
17937
|
+
if (ignoreSet.has(name))
|
|
17938
|
+
return;
|
|
17939
|
+
if (checked.has(node))
|
|
17940
|
+
return;
|
|
17941
|
+
checked.add(node);
|
|
17942
|
+
const location = node.loc;
|
|
17943
|
+
if (location !== null && location !== undefined) {
|
|
17944
|
+
const lines = location.end.line - location.start.line + 1;
|
|
17945
|
+
if (lines > configuration.maxLines) {
|
|
17946
|
+
context.report({
|
|
17947
|
+
data: { lines, max: configuration.maxLines, name, target: configuration.targetLines },
|
|
17948
|
+
messageId: "exceedsMaxLines",
|
|
17949
|
+
node
|
|
17950
|
+
});
|
|
17951
|
+
} else if (configuration.enforceTargetLines && lines > configuration.targetLines) {
|
|
17952
|
+
context.report({
|
|
17953
|
+
data: { lines, max: configuration.maxLines, name, target: configuration.targetLines },
|
|
17954
|
+
messageId: "exceedsTargetLines",
|
|
17955
|
+
node
|
|
17956
|
+
});
|
|
17957
|
+
}
|
|
17958
|
+
}
|
|
17959
|
+
const propsCount = countDestructuredProps(node);
|
|
17960
|
+
if (typeof propsCount === "number" && propsCount > configuration.maxDestructuredProps) {
|
|
17961
|
+
context.report({
|
|
17962
|
+
data: { count: propsCount, max: configuration.maxDestructuredProps, name },
|
|
17963
|
+
messageId: "tooManyProps",
|
|
17964
|
+
node
|
|
17965
|
+
});
|
|
17966
|
+
}
|
|
17967
|
+
const analysis = analyzeComponentBody(node, sourceCode, stateHooks);
|
|
17968
|
+
if (analysis.maxJsxDepth > configuration.maxTsxNesting) {
|
|
17969
|
+
context.report({
|
|
17970
|
+
data: { depth: analysis.maxJsxDepth, max: configuration.maxTsxNesting, name },
|
|
17971
|
+
messageId: "tsxNestingTooDeep",
|
|
17972
|
+
node
|
|
17973
|
+
});
|
|
17974
|
+
}
|
|
17975
|
+
if (analysis.stateHookCount > configuration.maxStateHooks) {
|
|
17976
|
+
context.report({
|
|
17977
|
+
data: {
|
|
17978
|
+
count: analysis.stateHookCount,
|
|
17979
|
+
hooks: configuration.stateHooks.join(", "),
|
|
17980
|
+
max: configuration.maxStateHooks,
|
|
17981
|
+
name
|
|
17982
|
+
},
|
|
17983
|
+
messageId: "tooManyStateHooks",
|
|
17984
|
+
node
|
|
17985
|
+
});
|
|
17986
|
+
}
|
|
17987
|
+
for (const literal2 of analysis.nullLiterals) {
|
|
17988
|
+
context.report({
|
|
17989
|
+
messageId: "nullLiteral",
|
|
17990
|
+
node: literal2
|
|
17991
|
+
});
|
|
17992
|
+
}
|
|
17993
|
+
}
|
|
17994
|
+
function maybeCheckFunction(node) {
|
|
17995
|
+
const name = getComponentNameFromFunction(node);
|
|
17996
|
+
if (typeof name !== "string" || name.length === 0)
|
|
17997
|
+
return;
|
|
17998
|
+
checkComponent(node, name);
|
|
17999
|
+
}
|
|
18000
|
+
return {
|
|
18001
|
+
ArrowFunctionExpression(node) {
|
|
18002
|
+
maybeCheckFunction(node);
|
|
18003
|
+
},
|
|
18004
|
+
CallExpression(node) {
|
|
18005
|
+
const callExpr = node;
|
|
18006
|
+
if (!isReactComponentHOC(callExpr))
|
|
18007
|
+
return;
|
|
18008
|
+
const [firstArg] = callExpr.arguments;
|
|
18009
|
+
if (!firstArg || firstArg.type !== TSESTree5.AST_NODE_TYPES.FunctionExpression && firstArg.type !== TSESTree5.AST_NODE_TYPES.ArrowFunctionExpression) {
|
|
18010
|
+
return;
|
|
18011
|
+
}
|
|
18012
|
+
const nameFromParent = getComponentNameFromCallParent(callExpr);
|
|
18013
|
+
const nameFromArg = getComponentNameFromFunction(firstArg);
|
|
18014
|
+
const name = nameFromParent ?? nameFromArg;
|
|
18015
|
+
if (typeof name !== "string" || name.length === 0)
|
|
18016
|
+
return;
|
|
18017
|
+
checkComponent(firstArg, name);
|
|
18018
|
+
},
|
|
18019
|
+
FunctionDeclaration(node) {
|
|
18020
|
+
maybeCheckFunction(node);
|
|
18021
|
+
},
|
|
18022
|
+
FunctionExpression(node) {
|
|
18023
|
+
maybeCheckFunction(node);
|
|
18024
|
+
}
|
|
18025
|
+
};
|
|
18026
|
+
},
|
|
18027
|
+
meta: {
|
|
18028
|
+
docs: {
|
|
18029
|
+
description: "Enforce React component size and complexity limits inspired by the 'Refactor God Component' checklist.",
|
|
18030
|
+
recommended: false
|
|
18031
|
+
},
|
|
18032
|
+
messages: {
|
|
18033
|
+
exceedsMaxLines: "Component '{{name}}' is {{lines}} lines; max allowed is {{max}}. Split into smaller components/hooks.",
|
|
18034
|
+
exceedsTargetLines: "Component '{{name}}' is {{lines}} lines; target is {{target}} (max {{max}}). Consider extracting hooks/components.",
|
|
18035
|
+
nullLiteral: "Avoid `null` in components; use `undefined` instead.",
|
|
18036
|
+
tooManyProps: "Component '{{name}}' destructures {{count}} props; max allowed is {{max}}. Group props or split the component.",
|
|
18037
|
+
tooManyStateHooks: "Component '{{name}}' has {{count}} state hooks ({{hooks}}); max allowed is {{max}}. Extract cohesive state into a custom hook.",
|
|
18038
|
+
tsxNestingTooDeep: "Component '{{name}}' has TSX nesting depth {{depth}}; max allowed is {{max}}. Extract child components."
|
|
18039
|
+
},
|
|
18040
|
+
schema: [
|
|
18041
|
+
{
|
|
18042
|
+
additionalProperties: false,
|
|
18043
|
+
properties: {
|
|
18044
|
+
enforceTargetLines: {
|
|
18045
|
+
default: true,
|
|
18046
|
+
description: "Whether to report when exceeding targetLines (soft limit).",
|
|
18047
|
+
type: "boolean"
|
|
18048
|
+
},
|
|
18049
|
+
ignoreComponents: {
|
|
18050
|
+
description: "Component names to ignore.",
|
|
18051
|
+
items: { type: "string" },
|
|
18052
|
+
type: "array"
|
|
18053
|
+
},
|
|
18054
|
+
maxDestructuredProps: {
|
|
18055
|
+
default: 5,
|
|
18056
|
+
description: "Maximum number of destructured props in a component parameter.",
|
|
18057
|
+
type: "number"
|
|
18058
|
+
},
|
|
18059
|
+
maxLines: {
|
|
18060
|
+
default: 200,
|
|
18061
|
+
description: "Hard maximum lines for a component.",
|
|
18062
|
+
type: "number"
|
|
18063
|
+
},
|
|
18064
|
+
maxStateHooks: {
|
|
18065
|
+
default: 5,
|
|
18066
|
+
description: "Maximum number of stateful hook calls in a component.",
|
|
18067
|
+
type: "number"
|
|
18068
|
+
},
|
|
18069
|
+
maxTsxNesting: {
|
|
18070
|
+
default: 3,
|
|
18071
|
+
description: "Maximum JSX/TSX nesting depth in a component.",
|
|
18072
|
+
type: "number"
|
|
18073
|
+
},
|
|
18074
|
+
stateHooks: {
|
|
18075
|
+
default: ["useState", "useReducer", "useBinding"],
|
|
18076
|
+
description: "Hook names to count toward state complexity.",
|
|
18077
|
+
items: { type: "string" },
|
|
18078
|
+
type: "array"
|
|
18079
|
+
},
|
|
18080
|
+
targetLines: {
|
|
18081
|
+
default: 120,
|
|
18082
|
+
description: "Soft target lines for a component.",
|
|
18083
|
+
type: "number"
|
|
18084
|
+
}
|
|
18085
|
+
},
|
|
18086
|
+
type: "object"
|
|
18087
|
+
}
|
|
18088
|
+
],
|
|
18089
|
+
type: "problem"
|
|
18090
|
+
}
|
|
18091
|
+
};
|
|
18092
|
+
var no_god_components_default = noGodComponents;
|
|
18093
|
+
|
|
18094
|
+
// src/rules/no-identity-map.ts
|
|
18095
|
+
var import_scope_manager = __toESM(require_dist2(), 1);
|
|
18096
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES2 } from "@typescript-eslint/utils";
|
|
18097
|
+
var DEFAULT_BINDING_PATTERNS = ["binding"];
|
|
18098
|
+
function getParameterName(param) {
|
|
18099
|
+
if (param.type === AST_NODE_TYPES2.Identifier)
|
|
18100
|
+
return param.name;
|
|
18101
|
+
if (param.type === AST_NODE_TYPES2.AssignmentPattern && param.left.type === AST_NODE_TYPES2.Identifier) {
|
|
18102
|
+
return param.left.name;
|
|
18103
|
+
}
|
|
18104
|
+
return;
|
|
18105
|
+
}
|
|
18106
|
+
function isBlockReturningIdentity(body, paramName) {
|
|
18107
|
+
if (body.body.length !== 1)
|
|
18108
|
+
return false;
|
|
18109
|
+
const [statement] = body.body;
|
|
18110
|
+
if (statement?.type !== AST_NODE_TYPES2.ReturnStatement)
|
|
18111
|
+
return false;
|
|
18112
|
+
if (!statement.argument)
|
|
18113
|
+
return false;
|
|
18114
|
+
if (statement.argument.type !== AST_NODE_TYPES2.Identifier)
|
|
18115
|
+
return false;
|
|
18116
|
+
return statement.argument.name === paramName;
|
|
18117
|
+
}
|
|
18118
|
+
function isIdentityCallback(callback) {
|
|
18119
|
+
if (callback.type === AST_NODE_TYPES2.ArrowFunctionExpression) {
|
|
18120
|
+
if (callback.params.length !== 1)
|
|
18121
|
+
return false;
|
|
18122
|
+
const [param] = callback.params;
|
|
18123
|
+
if (param === undefined)
|
|
18124
|
+
return false;
|
|
18125
|
+
const paramName = getParameterName(param);
|
|
18126
|
+
if (paramName === undefined || paramName === "")
|
|
18127
|
+
return false;
|
|
18128
|
+
if (callback.body.type === AST_NODE_TYPES2.Identifier) {
|
|
18129
|
+
return callback.body.name === paramName;
|
|
18130
|
+
}
|
|
18131
|
+
if (callback.body.type === AST_NODE_TYPES2.BlockStatement) {
|
|
18132
|
+
return isBlockReturningIdentity(callback.body, paramName);
|
|
18133
|
+
}
|
|
18134
|
+
return false;
|
|
18135
|
+
}
|
|
18136
|
+
if (callback.type === AST_NODE_TYPES2.FunctionExpression) {
|
|
18137
|
+
if (callback.params.length !== 1)
|
|
18138
|
+
return false;
|
|
18139
|
+
const [param] = callback.params;
|
|
18140
|
+
if (param === undefined)
|
|
18141
|
+
return false;
|
|
18142
|
+
const paramName = getParameterName(param);
|
|
18143
|
+
if (paramName === undefined || paramName === "")
|
|
18144
|
+
return false;
|
|
18145
|
+
return isBlockReturningIdentity(callback.body, paramName);
|
|
18146
|
+
}
|
|
18147
|
+
return false;
|
|
18148
|
+
}
|
|
18149
|
+
function findVariable(context, identifier3) {
|
|
18150
|
+
let scope = context.sourceCode.getScope(identifier3);
|
|
18151
|
+
while (scope) {
|
|
18152
|
+
const variable = scope.set.get(identifier3.name);
|
|
18153
|
+
if (variable)
|
|
18154
|
+
return variable;
|
|
18155
|
+
scope = scope.upper ?? undefined;
|
|
18156
|
+
}
|
|
18157
|
+
return;
|
|
18158
|
+
}
|
|
18159
|
+
function getHookName2(node) {
|
|
18160
|
+
const { callee } = node;
|
|
18161
|
+
if (callee.type === AST_NODE_TYPES2.Identifier) {
|
|
18162
|
+
return callee.name;
|
|
18163
|
+
}
|
|
18164
|
+
if (callee.type === AST_NODE_TYPES2.MemberExpression && callee.property.type === AST_NODE_TYPES2.Identifier) {
|
|
18165
|
+
return callee.property.name;
|
|
18166
|
+
}
|
|
18167
|
+
return;
|
|
18168
|
+
}
|
|
18169
|
+
function isJoinBindingsCall(node) {
|
|
18170
|
+
const { callee } = node;
|
|
18171
|
+
if (callee.type === AST_NODE_TYPES2.Identifier) {
|
|
18172
|
+
return callee.name === "joinBindings";
|
|
18173
|
+
}
|
|
18174
|
+
if (callee.type === AST_NODE_TYPES2.MemberExpression && callee.property.type === AST_NODE_TYPES2.Identifier) {
|
|
18175
|
+
return callee.property.name === "joinBindings";
|
|
18176
|
+
}
|
|
18177
|
+
return false;
|
|
18178
|
+
}
|
|
18179
|
+
function isBindingInitialization(variable) {
|
|
18180
|
+
for (const def of variable.defs) {
|
|
18181
|
+
if (def.type !== import_scope_manager.DefinitionType.Variable)
|
|
18182
|
+
continue;
|
|
18183
|
+
const { init } = def.node;
|
|
18184
|
+
if (!init || init.type !== AST_NODE_TYPES2.CallExpression)
|
|
18185
|
+
continue;
|
|
18186
|
+
const hookName = getHookName2(init);
|
|
18187
|
+
if (hookName === "useBinding")
|
|
18188
|
+
return true;
|
|
18189
|
+
if (isJoinBindingsCall(init))
|
|
18190
|
+
return true;
|
|
18191
|
+
if (init.callee.type === AST_NODE_TYPES2.MemberExpression && init.callee.property.type === AST_NODE_TYPES2.Identifier && init.callee.property.name === "map") {
|
|
18192
|
+
return true;
|
|
18193
|
+
}
|
|
18194
|
+
}
|
|
18195
|
+
return false;
|
|
18196
|
+
}
|
|
18197
|
+
function isLikelyBinding(context, callee, patterns2) {
|
|
18198
|
+
const { object: object3 } = callee;
|
|
18199
|
+
if (object3.type === AST_NODE_TYPES2.Identifier) {
|
|
18200
|
+
const lowerName = object3.name.toLowerCase();
|
|
18201
|
+
for (const pattern4 of patterns2) {
|
|
18202
|
+
if (lowerName.includes(pattern4.toLowerCase()))
|
|
18203
|
+
return true;
|
|
18204
|
+
}
|
|
18205
|
+
const variable = findVariable(context, object3);
|
|
18206
|
+
if (variable && isBindingInitialization(variable))
|
|
18207
|
+
return true;
|
|
18208
|
+
}
|
|
18209
|
+
if (object3.type === AST_NODE_TYPES2.CallExpression && object3.callee.type === AST_NODE_TYPES2.MemberExpression && object3.callee.property.type === AST_NODE_TYPES2.Identifier && object3.callee.property.name === "map") {
|
|
18210
|
+
return true;
|
|
18211
|
+
}
|
|
18212
|
+
if (object3.type === AST_NODE_TYPES2.CallExpression && isJoinBindingsCall(object3)) {
|
|
18213
|
+
return true;
|
|
18214
|
+
}
|
|
18215
|
+
return false;
|
|
18216
|
+
}
|
|
18217
|
+
var noIdentityMap = {
|
|
18218
|
+
create(context) {
|
|
18219
|
+
const [rawOptions] = context.options;
|
|
18220
|
+
const patterns2 = rawOptions?.bindingPatterns ?? DEFAULT_BINDING_PATTERNS;
|
|
18221
|
+
return {
|
|
18222
|
+
CallExpression(node) {
|
|
18223
|
+
const { callee } = node;
|
|
18224
|
+
if (callee.type !== AST_NODE_TYPES2.MemberExpression)
|
|
18225
|
+
return;
|
|
18226
|
+
if (callee.computed)
|
|
18227
|
+
return;
|
|
18228
|
+
if (callee.property.type !== AST_NODE_TYPES2.Identifier)
|
|
18229
|
+
return;
|
|
18230
|
+
if (callee.property.name !== "map")
|
|
18231
|
+
return;
|
|
18232
|
+
if (node.arguments.length !== 1)
|
|
18233
|
+
return;
|
|
18234
|
+
const [callback] = node.arguments;
|
|
18235
|
+
if (!callback || callback.type === AST_NODE_TYPES2.SpreadElement)
|
|
18236
|
+
return;
|
|
18237
|
+
if (!isIdentityCallback(callback))
|
|
18238
|
+
return;
|
|
18239
|
+
const isBinding = isLikelyBinding(context, callee, patterns2);
|
|
18240
|
+
context.report({
|
|
18241
|
+
fix(fixer) {
|
|
18242
|
+
const objectText = context.sourceCode.getText(callee.object);
|
|
18243
|
+
return fixer.replaceText(node, objectText);
|
|
18244
|
+
},
|
|
18245
|
+
messageId: isBinding ? "identityBindingMap" : "identityArrayMap",
|
|
18246
|
+
node
|
|
18247
|
+
});
|
|
18248
|
+
}
|
|
18249
|
+
};
|
|
18250
|
+
},
|
|
18251
|
+
defaultOptions: [{}],
|
|
18252
|
+
meta: {
|
|
18253
|
+
docs: {
|
|
18254
|
+
description: "Disallow pointless identity `.map()` calls that return the parameter unchanged"
|
|
18255
|
+
},
|
|
18256
|
+
fixable: "code",
|
|
18257
|
+
messages: {
|
|
18258
|
+
identityArrayMap: "Pointless identity `.map()` call on Array. Use `table.clone(array)` or `[...array]` instead.",
|
|
18259
|
+
identityBindingMap: "Pointless identity `.map()` call on Binding. Use the original binding directly."
|
|
18260
|
+
},
|
|
18261
|
+
schema: [
|
|
18262
|
+
{
|
|
18263
|
+
additionalProperties: false,
|
|
18264
|
+
properties: {
|
|
18265
|
+
bindingPatterns: {
|
|
18266
|
+
default: [...DEFAULT_BINDING_PATTERNS],
|
|
18267
|
+
description: "Variable name patterns to recognize as Bindings (case insensitive)",
|
|
18268
|
+
items: { type: "string" },
|
|
18269
|
+
type: "array"
|
|
18270
|
+
}
|
|
18271
|
+
},
|
|
18272
|
+
type: "object"
|
|
18273
|
+
}
|
|
18274
|
+
],
|
|
18275
|
+
type: "suggestion"
|
|
18276
|
+
}
|
|
18277
|
+
};
|
|
18278
|
+
var no_identity_map_default = noIdentityMap;
|
|
18279
|
+
|
|
17458
18280
|
// src/rules/no-instance-methods-without-this.ts
|
|
17459
|
-
import { AST_NODE_TYPES as
|
|
18281
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES3 } from "@typescript-eslint/types";
|
|
17460
18282
|
var DEFAULT_OPTIONS = {
|
|
17461
18283
|
checkPrivate: true,
|
|
17462
18284
|
checkProtected: true,
|
|
@@ -17496,11 +18318,13 @@ function traverseForThis(currentNode, visited2) {
|
|
|
17496
18318
|
if (visited2.has(currentNode))
|
|
17497
18319
|
return false;
|
|
17498
18320
|
visited2.add(currentNode);
|
|
17499
|
-
if (currentNode.type ===
|
|
18321
|
+
if (currentNode.type === AST_NODE_TYPES3.ThisExpression || currentNode.type === AST_NODE_TYPES3.Super)
|
|
17500
18322
|
return true;
|
|
17501
18323
|
if (!hasDynamicProperties2(currentNode))
|
|
17502
18324
|
return false;
|
|
17503
18325
|
for (const key in currentNode) {
|
|
18326
|
+
if (!Object.hasOwn(currentNode, key))
|
|
18327
|
+
continue;
|
|
17504
18328
|
const childValue = currentNode[key];
|
|
17505
18329
|
if (childValue === null || childValue === undefined)
|
|
17506
18330
|
continue;
|
|
@@ -17516,14 +18340,14 @@ function traverseForThis(currentNode, visited2) {
|
|
|
17516
18340
|
return false;
|
|
17517
18341
|
}
|
|
17518
18342
|
function methodUsesThis(node) {
|
|
17519
|
-
const value = node
|
|
17520
|
-
if (value === undefined || value.type !==
|
|
18343
|
+
const { value } = node;
|
|
18344
|
+
if (value === undefined || value.type !== AST_NODE_TYPES3.FunctionExpression)
|
|
17521
18345
|
return false;
|
|
17522
18346
|
return traverseForThis(value, new WeakSet);
|
|
17523
18347
|
}
|
|
17524
18348
|
var noInstanceMethodsWithoutThis = {
|
|
17525
18349
|
create(context) {
|
|
17526
|
-
const rawOptions = context.options
|
|
18350
|
+
const [rawOptions] = context.options;
|
|
17527
18351
|
const options3 = normalizeOptions(rawOptions);
|
|
17528
18352
|
return {
|
|
17529
18353
|
MethodDefinition(node) {
|
|
@@ -17531,7 +18355,7 @@ var noInstanceMethodsWithoutThis = {
|
|
|
17531
18355
|
return;
|
|
17532
18356
|
if (methodUsesThis(node))
|
|
17533
18357
|
return;
|
|
17534
|
-
const methodName = node.key.type ===
|
|
18358
|
+
const methodName = node.key.type === AST_NODE_TYPES3.Identifier ? node.key.name : "unknown";
|
|
17535
18359
|
context.report({
|
|
17536
18360
|
data: { methodName },
|
|
17537
18361
|
messageId: "noInstanceMethodWithoutThis",
|
|
@@ -17604,12 +18428,14 @@ var noPrint = {
|
|
|
17604
18428
|
var no_print_default = noPrint;
|
|
17605
18429
|
|
|
17606
18430
|
// src/rules/no-shorthand-names.ts
|
|
17607
|
-
import { TSESTree as
|
|
18431
|
+
import { TSESTree as TSESTree6 } from "@typescript-eslint/types";
|
|
17608
18432
|
var isRuleOptions = Compile(build_default.Object({
|
|
17609
18433
|
allowPropertyAccess: build_default.Optional(build_default.Array(build_default.String())),
|
|
17610
18434
|
shorthands: build_default.Optional(build_default.Record(build_default.String(), build_default.String()))
|
|
17611
18435
|
}));
|
|
17612
|
-
|
|
18436
|
+
function isRecord2(value) {
|
|
18437
|
+
return value !== null && typeof value === "object";
|
|
18438
|
+
}
|
|
17613
18439
|
var DEFAULT_OPTIONS2 = {
|
|
17614
18440
|
allowPropertyAccess: ["char"],
|
|
17615
18441
|
shorthands: {
|
|
@@ -17619,52 +18445,138 @@ var DEFAULT_OPTIONS2 = {
|
|
|
17619
18445
|
plr: "player"
|
|
17620
18446
|
}
|
|
17621
18447
|
};
|
|
17622
|
-
var
|
|
17623
|
-
var
|
|
18448
|
+
var REGEX_PATTERN_MATCHER = regex2("^/(?<first>.+)/(?<second>[gimsuy]*)$");
|
|
18449
|
+
var WORD_BOUNDARY_REGEX = /(?<=[a-z])(?=[A-Z])|(?<=[A-Z])(?=[A-Z][a-z])|(?<=[a-zA-Z])(?=\d)|(?<=\d)(?=[a-zA-Z])/;
|
|
18450
|
+
function splitIdentifierIntoWords(identifier3) {
|
|
18451
|
+
return identifier3.split(WORD_BOUNDARY_REGEX);
|
|
18452
|
+
}
|
|
18453
|
+
function createMatcher(key, replacement) {
|
|
18454
|
+
if (key.startsWith("/")) {
|
|
18455
|
+
const match = REGEX_PATTERN_MATCHER.exec(key);
|
|
18456
|
+
if (match) {
|
|
18457
|
+
return {
|
|
18458
|
+
matcher: {
|
|
18459
|
+
original: key,
|
|
18460
|
+
pattern: new RegExp(`^${match.groups.first}$`, match.groups.second),
|
|
18461
|
+
replacement
|
|
18462
|
+
},
|
|
18463
|
+
type: "pattern"
|
|
18464
|
+
};
|
|
18465
|
+
}
|
|
18466
|
+
}
|
|
18467
|
+
if (key.includes("*") || key.includes("?")) {
|
|
18468
|
+
const regexPattern = key.replaceAll(/[.+^${}()|[\]\\]/g, String.raw`\$&`).replaceAll("*", "(.*)").replaceAll("?", "(.)");
|
|
18469
|
+
let captureIndex = 0;
|
|
18470
|
+
const regexReplacement = replacement.replaceAll("*", () => `$${++captureIndex}`);
|
|
18471
|
+
return {
|
|
18472
|
+
matcher: {
|
|
18473
|
+
original: key,
|
|
18474
|
+
pattern: new RegExp(`^${regexPattern}$`),
|
|
18475
|
+
replacement: regexReplacement
|
|
18476
|
+
},
|
|
18477
|
+
type: "pattern"
|
|
18478
|
+
};
|
|
18479
|
+
}
|
|
18480
|
+
return {
|
|
18481
|
+
original: key,
|
|
18482
|
+
replacement,
|
|
18483
|
+
type: "exact"
|
|
18484
|
+
};
|
|
18485
|
+
}
|
|
18486
|
+
function matchWord(word, matchers, exactMatchers) {
|
|
18487
|
+
const exactReplacement = exactMatchers.get(word);
|
|
18488
|
+
if (exactReplacement !== undefined) {
|
|
18489
|
+
return {
|
|
18490
|
+
replacement: exactReplacement,
|
|
18491
|
+
shorthand: word
|
|
18492
|
+
};
|
|
18493
|
+
}
|
|
18494
|
+
for (const matcher of matchers) {
|
|
18495
|
+
const match = word.match(matcher.pattern);
|
|
18496
|
+
if (match) {
|
|
18497
|
+
let replaced = matcher.replacement;
|
|
18498
|
+
for (let index2 = 1;index2 < match.length; index2 += 1) {
|
|
18499
|
+
replaced = replaced.replaceAll(new RegExp(`\\$${index2}`, "g"), match[index2] ?? "");
|
|
18500
|
+
}
|
|
18501
|
+
return {
|
|
18502
|
+
replacement: replaced,
|
|
18503
|
+
shorthand: matcher.original
|
|
18504
|
+
};
|
|
18505
|
+
}
|
|
18506
|
+
}
|
|
18507
|
+
return;
|
|
18508
|
+
}
|
|
18509
|
+
function buildReplacementIdentifier(identifier3, options3) {
|
|
18510
|
+
const words = splitIdentifierIntoWords(identifier3);
|
|
18511
|
+
const matches = new Array;
|
|
18512
|
+
let hasMatch = false;
|
|
18513
|
+
const newWords = words.map((word) => {
|
|
18514
|
+
const match = matchWord(word, options3.matchers, options3.exactMatchers);
|
|
18515
|
+
if (match) {
|
|
18516
|
+
hasMatch = true;
|
|
18517
|
+
matches.push(match);
|
|
18518
|
+
return match.replacement;
|
|
18519
|
+
}
|
|
18520
|
+
return word;
|
|
18521
|
+
});
|
|
18522
|
+
if (!hasMatch)
|
|
18523
|
+
return;
|
|
18524
|
+
return { matches, replaced: newWords.join("") };
|
|
18525
|
+
}
|
|
17624
18526
|
function normalizeOptions2(rawOptions) {
|
|
17625
18527
|
const mergedShorthands = { ...DEFAULT_OPTIONS2.shorthands };
|
|
17626
|
-
if (rawOptions?.shorthands)
|
|
18528
|
+
if (rawOptions?.shorthands) {
|
|
17627
18529
|
for (const [key, value] of Object.entries(rawOptions.shorthands))
|
|
17628
18530
|
mergedShorthands[key] = value;
|
|
17629
|
-
|
|
18531
|
+
}
|
|
18532
|
+
const matchers = new Array;
|
|
18533
|
+
const exactMatchers = new Map;
|
|
18534
|
+
for (const [key, value] of Object.entries(mergedShorthands)) {
|
|
18535
|
+
const result = createMatcher(key, value);
|
|
18536
|
+
if (result.type === "exact")
|
|
18537
|
+
exactMatchers.set(result.original, result.replacement);
|
|
18538
|
+
else
|
|
18539
|
+
matchers.push(result.matcher);
|
|
18540
|
+
}
|
|
17630
18541
|
const allowPropertyAccessSource = rawOptions?.allowPropertyAccess ?? DEFAULT_OPTIONS2.allowPropertyAccess;
|
|
17631
|
-
const escapedKeys = new Array;
|
|
17632
|
-
let length = 0;
|
|
17633
|
-
for (const key of shorthandsMap.keys())
|
|
17634
|
-
escapedKeys[length++] = key.replaceAll(ESCAPE_REGEXP, ESCAPE_WITH);
|
|
17635
|
-
const selector = `Identifier[name=/^(${escapedKeys.join("|")})$/]`;
|
|
17636
18542
|
return {
|
|
17637
18543
|
allowPropertyAccess: new Set(allowPropertyAccessSource),
|
|
17638
|
-
|
|
17639
|
-
|
|
18544
|
+
exactMatchers,
|
|
18545
|
+
matchers,
|
|
18546
|
+
selector: "Identifier"
|
|
17640
18547
|
};
|
|
17641
18548
|
}
|
|
17642
18549
|
var noShorthandNames = {
|
|
17643
18550
|
create(context) {
|
|
17644
18551
|
const validatedOptions = isRuleOptions.Check(context.options[0]) ? context.options[0] : undefined;
|
|
17645
|
-
const
|
|
18552
|
+
const normalized = normalizeOptions2(validatedOptions);
|
|
18553
|
+
const { allowPropertyAccess, selector } = normalized;
|
|
17646
18554
|
return {
|
|
17647
18555
|
[selector](node) {
|
|
17648
|
-
const
|
|
17649
|
-
const
|
|
17650
|
-
if (
|
|
18556
|
+
const identifierName = node.name;
|
|
18557
|
+
const result = buildReplacementIdentifier(identifierName, normalized);
|
|
18558
|
+
if (result === undefined)
|
|
17651
18559
|
return;
|
|
18560
|
+
const { replaced, matches } = result;
|
|
17652
18561
|
const { parent } = node;
|
|
17653
|
-
|
|
18562
|
+
const [match] = matches;
|
|
18563
|
+
if (matches.length === 1 && match !== undefined && allowPropertyAccess.has(match.shorthand) && parent !== undefined && isRecord2(parent) && parent.type === TSESTree6.AST_NODE_TYPES.MemberExpression && parent.property === node) {
|
|
17654
18564
|
return;
|
|
17655
|
-
|
|
18565
|
+
}
|
|
18566
|
+
if (identifierName === "plr" && parent?.type === TSESTree6.AST_NODE_TYPES.VariableDeclarator && parent.id === node) {
|
|
17656
18567
|
const { init } = parent;
|
|
17657
|
-
if (init &&
|
|
18568
|
+
if (init && isRecord2(init) && init.type === TSESTree6.AST_NODE_TYPES.MemberExpression && init.object !== undefined && isRecord2(init.object) && init.object.type === TSESTree6.AST_NODE_TYPES.Identifier && init.object.name === "Players" && init.property !== undefined && isRecord2(init.property) && init.property.type === TSESTree6.AST_NODE_TYPES.Identifier && init.property.name === "LocalPlayer") {
|
|
17658
18569
|
context.report({
|
|
17659
|
-
data: { replacement: "localPlayer", shorthand:
|
|
18570
|
+
data: { replacement: "localPlayer", shorthand: "plr" },
|
|
17660
18571
|
messageId: "useReplacement",
|
|
17661
18572
|
node
|
|
17662
18573
|
});
|
|
17663
18574
|
return;
|
|
17664
18575
|
}
|
|
17665
18576
|
}
|
|
18577
|
+
const shorthandList = matches.map(({ shorthand }) => shorthand).join(", ");
|
|
17666
18578
|
context.report({
|
|
17667
|
-
data: { replacement, shorthand:
|
|
18579
|
+
data: { replacement: replaced, shorthand: shorthandList },
|
|
17668
18580
|
messageId: "useReplacement",
|
|
17669
18581
|
node
|
|
17670
18582
|
});
|
|
@@ -17703,8 +18615,8 @@ var noShorthandNames = {
|
|
|
17703
18615
|
var no_shorthand_names_default = noShorthandNames;
|
|
17704
18616
|
|
|
17705
18617
|
// src/rules/no-useless-use-spring.ts
|
|
17706
|
-
var
|
|
17707
|
-
import { AST_NODE_TYPES as
|
|
18618
|
+
var import_scope_manager2 = __toESM(require_dist2(), 1);
|
|
18619
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES4 } from "@typescript-eslint/utils";
|
|
17708
18620
|
var DEFAULT_STATIC_GLOBAL_FACTORIES = [
|
|
17709
18621
|
"Axes",
|
|
17710
18622
|
"BrickColor",
|
|
@@ -17740,34 +18652,34 @@ var STATIC_UNARY_OPERATORS = new Set(["-", "+", "!", "~", "typeof", "void", "del
|
|
|
17740
18652
|
function unwrapExpression(expression) {
|
|
17741
18653
|
let current = expression;
|
|
17742
18654
|
while (true) {
|
|
17743
|
-
if (current.type ===
|
|
18655
|
+
if (current.type === AST_NODE_TYPES4.TSAsExpression) {
|
|
17744
18656
|
current = current.expression;
|
|
17745
18657
|
continue;
|
|
17746
18658
|
}
|
|
17747
|
-
if (current.type ===
|
|
18659
|
+
if (current.type === AST_NODE_TYPES4.TSTypeAssertion) {
|
|
17748
18660
|
current = current.expression;
|
|
17749
18661
|
continue;
|
|
17750
18662
|
}
|
|
17751
|
-
if (current.type ===
|
|
18663
|
+
if (current.type === AST_NODE_TYPES4.TSNonNullExpression) {
|
|
17752
18664
|
current = current.expression;
|
|
17753
18665
|
continue;
|
|
17754
18666
|
}
|
|
17755
|
-
if (current.type ===
|
|
18667
|
+
if (current.type === AST_NODE_TYPES4.TSSatisfiesExpression) {
|
|
17756
18668
|
current = current.expression;
|
|
17757
18669
|
continue;
|
|
17758
18670
|
}
|
|
17759
|
-
if (current.type ===
|
|
18671
|
+
if (current.type === AST_NODE_TYPES4.TSInstantiationExpression) {
|
|
17760
18672
|
current = current.expression;
|
|
17761
18673
|
continue;
|
|
17762
18674
|
}
|
|
17763
|
-
if (current.type ===
|
|
18675
|
+
if (current.type === AST_NODE_TYPES4.ChainExpression) {
|
|
17764
18676
|
current = current.expression;
|
|
17765
18677
|
continue;
|
|
17766
18678
|
}
|
|
17767
18679
|
return current;
|
|
17768
18680
|
}
|
|
17769
18681
|
}
|
|
17770
|
-
function
|
|
18682
|
+
function findVariable2(context, identifier3) {
|
|
17771
18683
|
let scope = context.sourceCode.getScope(identifier3);
|
|
17772
18684
|
while (scope) {
|
|
17773
18685
|
const variable = scope.set.get(identifier3.name);
|
|
@@ -17778,29 +18690,29 @@ function findVariable(context, identifier3) {
|
|
|
17778
18690
|
return;
|
|
17779
18691
|
}
|
|
17780
18692
|
function isModuleLevelScope(scope) {
|
|
17781
|
-
return scope.type ===
|
|
18693
|
+
return scope.type === import_scope_manager2.ScopeType.module || scope.type === import_scope_manager2.ScopeType.global;
|
|
17782
18694
|
}
|
|
17783
18695
|
function isImport(variable) {
|
|
17784
18696
|
for (const definition of variable.defs)
|
|
17785
|
-
if (definition.type ===
|
|
18697
|
+
if (definition.type === import_scope_manager2.DefinitionType.ImportBinding)
|
|
17786
18698
|
return true;
|
|
17787
18699
|
return false;
|
|
17788
18700
|
}
|
|
17789
18701
|
function getConstInitializer(definition) {
|
|
17790
|
-
if (definition === undefined || definition.type !==
|
|
18702
|
+
if (definition === undefined || definition.type !== import_scope_manager2.DefinitionType.Variable)
|
|
17791
18703
|
return;
|
|
17792
18704
|
const declarator = definition.node;
|
|
17793
|
-
if (declarator.type !==
|
|
18705
|
+
if (declarator.type !== AST_NODE_TYPES4.VariableDeclarator)
|
|
17794
18706
|
return;
|
|
17795
18707
|
const declaration = definition.parent;
|
|
17796
|
-
if (declaration?.type !==
|
|
18708
|
+
if (declaration?.type !== AST_NODE_TYPES4.VariableDeclaration)
|
|
17797
18709
|
return;
|
|
17798
18710
|
if (declaration.kind !== "const")
|
|
17799
18711
|
return;
|
|
17800
18712
|
return declarator.init ?? undefined;
|
|
17801
18713
|
}
|
|
17802
18714
|
function isStaticIdentifier(context, identifier3, seen, options3) {
|
|
17803
|
-
const variable =
|
|
18715
|
+
const variable = findVariable2(context, identifier3);
|
|
17804
18716
|
if (variable === undefined)
|
|
17805
18717
|
return options3.staticGlobalFactories.has(identifier3.name);
|
|
17806
18718
|
if (!isModuleLevelScope(variable.scope))
|
|
@@ -17817,34 +18729,34 @@ function isStaticIdentifier(context, identifier3, seen, options3) {
|
|
|
17817
18729
|
return false;
|
|
17818
18730
|
}
|
|
17819
18731
|
function isStaticMemberProperty(property, seen, options3) {
|
|
17820
|
-
if (property.type ===
|
|
18732
|
+
if (property.type === AST_NODE_TYPES4.PrivateIdentifier)
|
|
17821
18733
|
return false;
|
|
17822
|
-
if (property.type ===
|
|
18734
|
+
if (property.type === AST_NODE_TYPES4.Identifier)
|
|
17823
18735
|
return true;
|
|
17824
18736
|
return isStaticExpressionInner(property, seen, options3);
|
|
17825
18737
|
}
|
|
17826
18738
|
function isStaticCallCallee(context, callee, seen, options3) {
|
|
17827
18739
|
const unwrapped = unwrapExpression(callee);
|
|
17828
|
-
if (unwrapped.type ===
|
|
18740
|
+
if (unwrapped.type === AST_NODE_TYPES4.Identifier)
|
|
17829
18741
|
return isStaticIdentifier(context, unwrapped, seen, options3);
|
|
17830
|
-
if (unwrapped.type ===
|
|
18742
|
+
if (unwrapped.type === AST_NODE_TYPES4.MemberExpression) {
|
|
17831
18743
|
if (!isStaticExpression(context, unwrapped.object, seen, options3))
|
|
17832
18744
|
return false;
|
|
17833
18745
|
if (unwrapped.computed)
|
|
17834
18746
|
return isStaticMemberProperty(unwrapped.property, seen, options3);
|
|
17835
|
-
return unwrapped.property.type ===
|
|
18747
|
+
return unwrapped.property.type === AST_NODE_TYPES4.Identifier;
|
|
17836
18748
|
}
|
|
17837
18749
|
return false;
|
|
17838
18750
|
}
|
|
17839
18751
|
function isStaticObjectExpression(context, objectExpr, seen, options3) {
|
|
17840
18752
|
for (const property of objectExpr.properties) {
|
|
17841
|
-
if (property.type !==
|
|
18753
|
+
if (property.type !== AST_NODE_TYPES4.Property)
|
|
17842
18754
|
return false;
|
|
17843
18755
|
if (property.kind !== "init")
|
|
17844
18756
|
return false;
|
|
17845
18757
|
if (property.computed && !isStaticExpressionInner(property.key, seen, options3))
|
|
17846
18758
|
return false;
|
|
17847
|
-
const value = property
|
|
18759
|
+
const { value } = property;
|
|
17848
18760
|
if (!isNonPatternExpression(value))
|
|
17849
18761
|
return false;
|
|
17850
18762
|
if (!isStaticExpression(context, value, seen, options3))
|
|
@@ -17853,20 +18765,20 @@ function isStaticObjectExpression(context, objectExpr, seen, options3) {
|
|
|
17853
18765
|
return true;
|
|
17854
18766
|
}
|
|
17855
18767
|
function isNonPatternExpression(value) {
|
|
17856
|
-
return value.type !==
|
|
18768
|
+
return value.type !== AST_NODE_TYPES4.PrivateIdentifier && value.type !== AST_NODE_TYPES4.AssignmentPattern && value.type !== AST_NODE_TYPES4.ArrayPattern && value.type !== AST_NODE_TYPES4.ObjectPattern && value.type !== AST_NODE_TYPES4.RestElement && value.type !== AST_NODE_TYPES4.TSEmptyBodyFunctionExpression;
|
|
17857
18769
|
}
|
|
17858
18770
|
function isNonPrivateExpression(value) {
|
|
17859
|
-
return value.type !==
|
|
18771
|
+
return value.type !== AST_NODE_TYPES4.PrivateIdentifier;
|
|
17860
18772
|
}
|
|
17861
18773
|
function objectHasFromAndTo(objectExpr) {
|
|
17862
18774
|
let hasFrom = false;
|
|
17863
18775
|
let hasTo = false;
|
|
17864
18776
|
for (const property of objectExpr.properties) {
|
|
17865
|
-
if (property.type !==
|
|
18777
|
+
if (property.type !== AST_NODE_TYPES4.Property)
|
|
17866
18778
|
continue;
|
|
17867
18779
|
if (property.computed)
|
|
17868
18780
|
continue;
|
|
17869
|
-
if (property.key.type !==
|
|
18781
|
+
if (property.key.type !== AST_NODE_TYPES4.Identifier)
|
|
17870
18782
|
continue;
|
|
17871
18783
|
if (property.key.name === "from")
|
|
17872
18784
|
hasFrom = true;
|
|
@@ -17879,10 +18791,10 @@ function objectHasFromAndTo(objectExpr) {
|
|
|
17879
18791
|
}
|
|
17880
18792
|
function hasFromAndToProperties(context, expression) {
|
|
17881
18793
|
const unwrapped = unwrapExpression(expression);
|
|
17882
|
-
if (unwrapped.type ===
|
|
18794
|
+
if (unwrapped.type === AST_NODE_TYPES4.ObjectExpression)
|
|
17883
18795
|
return objectHasFromAndTo(unwrapped);
|
|
17884
|
-
if (unwrapped.type ===
|
|
17885
|
-
const variable =
|
|
18796
|
+
if (unwrapped.type === AST_NODE_TYPES4.Identifier) {
|
|
18797
|
+
const variable = findVariable2(context, unwrapped);
|
|
17886
18798
|
if (variable === undefined)
|
|
17887
18799
|
return false;
|
|
17888
18800
|
if (!isModuleLevelScope(variable.scope))
|
|
@@ -17894,7 +18806,7 @@ function hasFromAndToProperties(context, expression) {
|
|
|
17894
18806
|
if (initializer === undefined)
|
|
17895
18807
|
continue;
|
|
17896
18808
|
const normalizedInitializer = unwrapExpression(initializer);
|
|
17897
|
-
if (normalizedInitializer.type !==
|
|
18809
|
+
if (normalizedInitializer.type !== AST_NODE_TYPES4.ObjectExpression)
|
|
17898
18810
|
continue;
|
|
17899
18811
|
if (objectHasFromAndTo(normalizedInitializer))
|
|
17900
18812
|
return true;
|
|
@@ -17904,10 +18816,10 @@ function hasFromAndToProperties(context, expression) {
|
|
|
17904
18816
|
}
|
|
17905
18817
|
function isStaticObjectLikeConfig(context, expression, seen, options3) {
|
|
17906
18818
|
const unwrapped = unwrapExpression(expression);
|
|
17907
|
-
if (unwrapped.type ===
|
|
18819
|
+
if (unwrapped.type === AST_NODE_TYPES4.ObjectExpression)
|
|
17908
18820
|
return isStaticObjectExpression(context, unwrapped, seen, options3);
|
|
17909
|
-
if (unwrapped.type ===
|
|
17910
|
-
const variable =
|
|
18821
|
+
if (unwrapped.type === AST_NODE_TYPES4.Identifier) {
|
|
18822
|
+
const variable = findVariable2(context, unwrapped);
|
|
17911
18823
|
if (variable === undefined)
|
|
17912
18824
|
return false;
|
|
17913
18825
|
if (!isModuleLevelScope(variable.scope))
|
|
@@ -17919,7 +18831,7 @@ function isStaticObjectLikeConfig(context, expression, seen, options3) {
|
|
|
17919
18831
|
if (initializer === undefined)
|
|
17920
18832
|
continue;
|
|
17921
18833
|
const normalizedInitializer = unwrapExpression(initializer);
|
|
17922
|
-
if (normalizedInitializer.type !==
|
|
18834
|
+
if (normalizedInitializer.type !== AST_NODE_TYPES4.ObjectExpression)
|
|
17923
18835
|
continue;
|
|
17924
18836
|
if (isStaticObjectExpression(context, normalizedInitializer, seen, options3))
|
|
17925
18837
|
return true;
|
|
@@ -17931,7 +18843,7 @@ function isStaticArrayExpression(context, arrayExpr, seen, options3) {
|
|
|
17931
18843
|
for (const element of arrayExpr.elements) {
|
|
17932
18844
|
if (!element)
|
|
17933
18845
|
continue;
|
|
17934
|
-
if (element.type ===
|
|
18846
|
+
if (element.type === AST_NODE_TYPES4.SpreadElement)
|
|
17935
18847
|
return false;
|
|
17936
18848
|
if (!isStaticExpression(context, element, seen, options3))
|
|
17937
18849
|
return false;
|
|
@@ -17947,36 +18859,36 @@ function isStaticExpression(context, expression, seen, options3) {
|
|
|
17947
18859
|
return true;
|
|
17948
18860
|
seen.add(unwrapped);
|
|
17949
18861
|
switch (unwrapped.type) {
|
|
17950
|
-
case
|
|
18862
|
+
case AST_NODE_TYPES4.Literal:
|
|
17951
18863
|
return true;
|
|
17952
|
-
case
|
|
18864
|
+
case AST_NODE_TYPES4.TemplateLiteral:
|
|
17953
18865
|
return unwrapped.expressions.length === 0;
|
|
17954
|
-
case
|
|
18866
|
+
case AST_NODE_TYPES4.UnaryExpression:
|
|
17955
18867
|
return STATIC_UNARY_OPERATORS.has(unwrapped.operator) && isStaticExpression(context, unwrapped.argument, seen, options3);
|
|
17956
|
-
case
|
|
17957
|
-
case
|
|
17958
|
-
if (!isNonPrivateExpression(unwrapped.left)
|
|
18868
|
+
case AST_NODE_TYPES4.BinaryExpression:
|
|
18869
|
+
case AST_NODE_TYPES4.LogicalExpression:
|
|
18870
|
+
if (!(isNonPrivateExpression(unwrapped.left) && isNonPrivateExpression(unwrapped.right)))
|
|
17959
18871
|
return false;
|
|
17960
18872
|
return isStaticExpression(context, unwrapped.left, seen, options3) && isStaticExpression(context, unwrapped.right, seen, options3);
|
|
17961
|
-
case
|
|
18873
|
+
case AST_NODE_TYPES4.ConditionalExpression:
|
|
17962
18874
|
return isStaticExpression(context, unwrapped.test, seen, options3) && isStaticExpression(context, unwrapped.consequent, seen, options3) && isStaticExpression(context, unwrapped.alternate, seen, options3);
|
|
17963
|
-
case
|
|
18875
|
+
case AST_NODE_TYPES4.ArrayExpression:
|
|
17964
18876
|
return context !== undefined && isStaticArrayExpression(context, unwrapped, seen, options3);
|
|
17965
|
-
case
|
|
18877
|
+
case AST_NODE_TYPES4.ObjectExpression:
|
|
17966
18878
|
return context !== undefined && isStaticObjectExpression(context, unwrapped, seen, options3);
|
|
17967
|
-
case
|
|
18879
|
+
case AST_NODE_TYPES4.Identifier:
|
|
17968
18880
|
return context !== undefined && isStaticIdentifier(context, unwrapped, seen, options3);
|
|
17969
|
-
case
|
|
18881
|
+
case AST_NODE_TYPES4.MemberExpression:
|
|
17970
18882
|
return isStaticExpression(context, unwrapped.object, seen, options3) && (!unwrapped.computed || isStaticMemberProperty(unwrapped.property, seen, options3));
|
|
17971
|
-
case
|
|
18883
|
+
case AST_NODE_TYPES4.ChainExpression:
|
|
17972
18884
|
return isStaticExpression(context, unwrapped.expression, seen, options3);
|
|
17973
|
-
case
|
|
17974
|
-
return context !== undefined && isStaticCallCallee(context, unwrapped.callee, seen, options3) && unwrapped.arguments.every((arg) => arg.type !==
|
|
17975
|
-
case
|
|
17976
|
-
return context !== undefined && isStaticCallCallee(context, unwrapped.callee, seen, options3) && (unwrapped.arguments ?? []).every((arg) => arg.type !==
|
|
17977
|
-
case
|
|
18885
|
+
case AST_NODE_TYPES4.CallExpression:
|
|
18886
|
+
return context !== undefined && isStaticCallCallee(context, unwrapped.callee, seen, options3) && unwrapped.arguments.every((arg) => arg.type !== AST_NODE_TYPES4.SpreadElement && isStaticExpression(context, arg, seen, options3));
|
|
18887
|
+
case AST_NODE_TYPES4.NewExpression:
|
|
18888
|
+
return context !== undefined && isStaticCallCallee(context, unwrapped.callee, seen, options3) && (unwrapped.arguments ?? []).every((arg) => arg.type !== AST_NODE_TYPES4.SpreadElement && isStaticExpression(context, arg, seen, options3));
|
|
18889
|
+
case AST_NODE_TYPES4.SequenceExpression:
|
|
17978
18890
|
return unwrapped.expressions.length > 0 && unwrapped.expressions.every((expr) => isStaticExpression(context, expr, seen, options3));
|
|
17979
|
-
case
|
|
18891
|
+
case AST_NODE_TYPES4.AssignmentExpression:
|
|
17980
18892
|
return isStaticExpression(context, unwrapped.right, seen, options3);
|
|
17981
18893
|
default:
|
|
17982
18894
|
return false;
|
|
@@ -17985,10 +18897,10 @@ function isStaticExpression(context, expression, seen, options3) {
|
|
|
17985
18897
|
function classifyDependencies(context, argument, seen, options3) {
|
|
17986
18898
|
if (argument === undefined)
|
|
17987
18899
|
return 0 /* MissingOrOmitted */;
|
|
17988
|
-
if (argument.type ===
|
|
18900
|
+
if (argument.type === AST_NODE_TYPES4.SpreadElement)
|
|
17989
18901
|
return 3 /* DynamicOrUnknown */;
|
|
17990
18902
|
const expr = unwrapExpression(argument);
|
|
17991
|
-
if (expr.type !==
|
|
18903
|
+
if (expr.type !== AST_NODE_TYPES4.ArrayExpression)
|
|
17992
18904
|
return 3 /* DynamicOrUnknown */;
|
|
17993
18905
|
if (expr.elements.length === 0)
|
|
17994
18906
|
return 1 /* EmptyArray */;
|
|
@@ -18005,18 +18917,18 @@ function depsAreNonUpdating(kind, options3) {
|
|
|
18005
18917
|
}
|
|
18006
18918
|
function isSpringHookCall(node, options3) {
|
|
18007
18919
|
const { callee } = node;
|
|
18008
|
-
if (callee.type ===
|
|
18920
|
+
if (callee.type === AST_NODE_TYPES4.Identifier)
|
|
18009
18921
|
return options3.springHooks.has(callee.name);
|
|
18010
|
-
if (callee.type ===
|
|
18922
|
+
if (callee.type === AST_NODE_TYPES4.MemberExpression && !callee.computed) {
|
|
18011
18923
|
const { property } = callee;
|
|
18012
|
-
if (property.type ===
|
|
18924
|
+
if (property.type === AST_NODE_TYPES4.Identifier)
|
|
18013
18925
|
return options3.springHooks.has(property.name);
|
|
18014
18926
|
}
|
|
18015
18927
|
return false;
|
|
18016
18928
|
}
|
|
18017
18929
|
var noUselessUseSpring = {
|
|
18018
18930
|
create(context) {
|
|
18019
|
-
const rawOptions = context.options
|
|
18931
|
+
const [rawOptions] = context.options;
|
|
18020
18932
|
const normalized = {
|
|
18021
18933
|
...DEFAULT_OPTION_VALUES,
|
|
18022
18934
|
...rawOptions,
|
|
@@ -18029,10 +18941,10 @@ var noUselessUseSpring = {
|
|
|
18029
18941
|
return;
|
|
18030
18942
|
if (node.arguments.length === 0)
|
|
18031
18943
|
return;
|
|
18032
|
-
const configArgument = node.arguments
|
|
18944
|
+
const [configArgument] = node.arguments;
|
|
18033
18945
|
if (!configArgument)
|
|
18034
18946
|
return;
|
|
18035
|
-
if (configArgument.type ===
|
|
18947
|
+
if (configArgument.type === AST_NODE_TYPES4.SpreadElement)
|
|
18036
18948
|
return;
|
|
18037
18949
|
const seen = new Set;
|
|
18038
18950
|
if (!isStaticObjectLikeConfig(context, configArgument, seen, normalized))
|
|
@@ -18113,13 +19025,13 @@ var noWarn = {
|
|
|
18113
19025
|
var no_warn_default = noWarn;
|
|
18114
19026
|
|
|
18115
19027
|
// src/rules/prefer-sequence-overloads.ts
|
|
18116
|
-
import { AST_NODE_TYPES as
|
|
19028
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES5 } from "@typescript-eslint/types";
|
|
18117
19029
|
var sequenceDescriptors = [
|
|
18118
19030
|
{ keypointName: "ColorSequenceKeypoint", sequenceName: "ColorSequence" },
|
|
18119
19031
|
{ keypointName: "NumberSequenceKeypoint", sequenceName: "NumberSequence" }
|
|
18120
19032
|
];
|
|
18121
19033
|
function isSequenceIdentifier(node) {
|
|
18122
|
-
if (node.type !==
|
|
19034
|
+
if (node.type !== AST_NODE_TYPES5.Identifier)
|
|
18123
19035
|
return false;
|
|
18124
19036
|
for (const { sequenceName } of sequenceDescriptors)
|
|
18125
19037
|
if (sequenceName === node.name)
|
|
@@ -18133,16 +19045,16 @@ function findDescriptor(sequenceName) {
|
|
|
18133
19045
|
return;
|
|
18134
19046
|
}
|
|
18135
19047
|
var isNumericLiteral = Compile(build_default.Object({
|
|
18136
|
-
type: build_default.Literal(
|
|
19048
|
+
type: build_default.Literal(AST_NODE_TYPES5.Literal),
|
|
18137
19049
|
value: build_default.Number()
|
|
18138
19050
|
}));
|
|
18139
19051
|
function isExpressionArgument(argument) {
|
|
18140
|
-
return argument !== undefined && argument.type !==
|
|
19052
|
+
return argument !== undefined && argument.type !== AST_NODE_TYPES5.SpreadElement;
|
|
18141
19053
|
}
|
|
18142
19054
|
function extractKeypoint(element, descriptor) {
|
|
18143
|
-
if (element === undefined || element.type !==
|
|
19055
|
+
if (element === undefined || element.type !== AST_NODE_TYPES5.NewExpression)
|
|
18144
19056
|
return;
|
|
18145
|
-
if (element.callee.type !==
|
|
19057
|
+
if (element.callee.type !== AST_NODE_TYPES5.Identifier || element.callee.name !== descriptor.keypointName)
|
|
18146
19058
|
return;
|
|
18147
19059
|
if (element.arguments.length !== 2)
|
|
18148
19060
|
return;
|
|
@@ -18172,7 +19084,7 @@ var preferSequenceOverloads = {
|
|
|
18172
19084
|
if (descriptor === undefined || node.arguments.length !== 1)
|
|
18173
19085
|
return;
|
|
18174
19086
|
const [argument] = node.arguments;
|
|
18175
|
-
if (argument === undefined || argument.type !==
|
|
19087
|
+
if (argument === undefined || argument.type !== AST_NODE_TYPES5.ArrayExpression || argument.elements.length !== 2)
|
|
18176
19088
|
return;
|
|
18177
19089
|
const firstElement = argument.elements[0] ?? undefined;
|
|
18178
19090
|
const secondElement = argument.elements[1] ?? undefined;
|
|
@@ -18219,11 +19131,11 @@ var preferSequenceOverloads = {
|
|
|
18219
19131
|
var prefer_sequence_overloads_default = preferSequenceOverloads;
|
|
18220
19132
|
|
|
18221
19133
|
// src/rules/prefer-udim2-shorthand.ts
|
|
18222
|
-
import { TSESTree as
|
|
19134
|
+
import { TSESTree as TSESTree7 } from "@typescript-eslint/utils";
|
|
18223
19135
|
function isNumber(value) {
|
|
18224
19136
|
return typeof value === "number" && !Number.isNaN(value);
|
|
18225
19137
|
}
|
|
18226
|
-
function
|
|
19138
|
+
function isRecord3(node) {
|
|
18227
19139
|
return typeof node === "object" && node !== null;
|
|
18228
19140
|
}
|
|
18229
19141
|
function hasTypeProperty(object3) {
|
|
@@ -18232,30 +19144,30 @@ function hasTypeProperty(object3) {
|
|
|
18232
19144
|
var OPERATORS2 = new Set(["+", "-", "*", "/", "%"]);
|
|
18233
19145
|
function reconstructText(node) {
|
|
18234
19146
|
const nodeType = node.type;
|
|
18235
|
-
if (nodeType ===
|
|
19147
|
+
if (nodeType === TSESTree7.AST_NODE_TYPES.Literal) {
|
|
18236
19148
|
const { value } = node;
|
|
18237
19149
|
return isNumber(value) ? String(value) : undefined;
|
|
18238
19150
|
}
|
|
18239
|
-
if (nodeType ===
|
|
19151
|
+
if (nodeType === TSESTree7.AST_NODE_TYPES.Identifier) {
|
|
18240
19152
|
const { name } = node;
|
|
18241
19153
|
return typeof name === "string" ? name : undefined;
|
|
18242
19154
|
}
|
|
18243
|
-
if (nodeType ===
|
|
19155
|
+
if (nodeType === TSESTree7.AST_NODE_TYPES.UnaryExpression) {
|
|
18244
19156
|
const { operator } = node;
|
|
18245
19157
|
if (typeof operator !== "string")
|
|
18246
19158
|
return;
|
|
18247
19159
|
const { argument } = node;
|
|
18248
|
-
if (!
|
|
19160
|
+
if (!isRecord3(argument))
|
|
18249
19161
|
return;
|
|
18250
19162
|
const text = reconstructText(argument);
|
|
18251
19163
|
return text === undefined ? undefined : `${operator}${text}`;
|
|
18252
19164
|
}
|
|
18253
|
-
if (nodeType ===
|
|
19165
|
+
if (nodeType === TSESTree7.AST_NODE_TYPES.BinaryExpression) {
|
|
18254
19166
|
const { operator } = node;
|
|
18255
19167
|
if (typeof operator !== "string" || !OPERATORS2.has(operator))
|
|
18256
19168
|
return;
|
|
18257
19169
|
const { left, right } = node;
|
|
18258
|
-
if (!
|
|
19170
|
+
if (!(isRecord3(left) && isRecord3(right)))
|
|
18259
19171
|
return;
|
|
18260
19172
|
const leftText = reconstructText(left);
|
|
18261
19173
|
const rightText = reconstructText(right);
|
|
@@ -18264,14 +19176,14 @@ function reconstructText(node) {
|
|
|
18264
19176
|
return;
|
|
18265
19177
|
}
|
|
18266
19178
|
function evaluateExpression(node) {
|
|
18267
|
-
if (!
|
|
19179
|
+
if (!isRecord3(node))
|
|
18268
19180
|
return;
|
|
18269
19181
|
const nodeType = node.type;
|
|
18270
|
-
if (nodeType ===
|
|
19182
|
+
if (nodeType === TSESTree7.AST_NODE_TYPES.Literal) {
|
|
18271
19183
|
const { value } = node;
|
|
18272
19184
|
return isNumber(value) ? value : undefined;
|
|
18273
19185
|
}
|
|
18274
|
-
if (nodeType ===
|
|
19186
|
+
if (nodeType === TSESTree7.AST_NODE_TYPES.UnaryExpression) {
|
|
18275
19187
|
const { argument, operator } = node;
|
|
18276
19188
|
if (typeof argument === "object" && argument !== null) {
|
|
18277
19189
|
const value = evaluateExpression(argument);
|
|
@@ -18284,7 +19196,7 @@ function evaluateExpression(node) {
|
|
|
18284
19196
|
}
|
|
18285
19197
|
return;
|
|
18286
19198
|
}
|
|
18287
|
-
if (nodeType ===
|
|
19199
|
+
if (nodeType === TSESTree7.AST_NODE_TYPES.BinaryExpression) {
|
|
18288
19200
|
const { right, left, operator } = node;
|
|
18289
19201
|
if (typeof left === "object" && left !== null && typeof right === "object" && right !== null) {
|
|
18290
19202
|
const leftValue = evaluateExpression(left);
|
|
@@ -18316,9 +19228,9 @@ function collectArguments(_context2, parameters3) {
|
|
|
18316
19228
|
const texts = [undefined, undefined, undefined, undefined];
|
|
18317
19229
|
for (let index2 = 0;index2 < 4; index2++) {
|
|
18318
19230
|
const parameter2 = parameters3[index2];
|
|
18319
|
-
if (!
|
|
19231
|
+
if (!(isRecord3(parameter2) && hasTypeProperty(parameter2)))
|
|
18320
19232
|
return;
|
|
18321
|
-
if (parameter2.type ===
|
|
19233
|
+
if (parameter2.type === TSESTree7.AST_NODE_TYPES.SpreadElement)
|
|
18322
19234
|
return;
|
|
18323
19235
|
const text = reconstructText(parameter2);
|
|
18324
19236
|
if (text === undefined)
|
|
@@ -18334,7 +19246,7 @@ var preferUDim2Shorthand = {
|
|
|
18334
19246
|
create(context) {
|
|
18335
19247
|
return {
|
|
18336
19248
|
NewExpression(node) {
|
|
18337
|
-
if (node.callee.type !==
|
|
19249
|
+
if (node.callee.type !== TSESTree7.AST_NODE_TYPES.Identifier || node.callee.name !== "UDim2")
|
|
18338
19250
|
return;
|
|
18339
19251
|
const collected = collectArguments(context, node.arguments);
|
|
18340
19252
|
if (!collected)
|
|
@@ -18381,7 +19293,7 @@ var preferUDim2Shorthand = {
|
|
|
18381
19293
|
var prefer_udim2_shorthand_default = preferUDim2Shorthand;
|
|
18382
19294
|
|
|
18383
19295
|
// src/rules/require-named-effect-functions.ts
|
|
18384
|
-
import { TSESTree as
|
|
19296
|
+
import { TSESTree as TSESTree8 } from "@typescript-eslint/types";
|
|
18385
19297
|
var DEFAULT_HOOKS = [
|
|
18386
19298
|
{ allowAsync: false, name: "useEffect" },
|
|
18387
19299
|
{ allowAsync: false, name: "useLayoutEffect" },
|
|
@@ -18396,7 +19308,7 @@ var isRuleOptions2 = Compile(build_default.Object({
|
|
|
18396
19308
|
environment: isEnvironmentMode,
|
|
18397
19309
|
hooks: build_default.Array(isHookConfiguration)
|
|
18398
19310
|
}, { additionalProperties: true }));
|
|
18399
|
-
function
|
|
19311
|
+
function parseOptions2(options3) {
|
|
18400
19312
|
if (options3 === undefined) {
|
|
18401
19313
|
return {
|
|
18402
19314
|
environment: "roblox-ts",
|
|
@@ -18414,12 +19326,14 @@ function parseOptions(options3) {
|
|
|
18414
19326
|
hooks: options3.hooks
|
|
18415
19327
|
};
|
|
18416
19328
|
}
|
|
18417
|
-
function
|
|
19329
|
+
function getHookName3(callExpression) {
|
|
18418
19330
|
const { callee } = callExpression;
|
|
18419
|
-
if (callee.type ===
|
|
19331
|
+
if (callee.type === TSESTree8.AST_NODE_TYPES.Identifier && typeof callee.name === "string" && callee.name.length > 0) {
|
|
18420
19332
|
return callee.name;
|
|
18421
|
-
|
|
19333
|
+
}
|
|
19334
|
+
if (callee.type === TSESTree8.AST_NODE_TYPES.MemberExpression && callee.property?.type === TSESTree8.AST_NODE_TYPES.Identifier && typeof callee.property.name === "string" && callee.property.name.length > 0) {
|
|
18422
19335
|
return callee.property.name;
|
|
19336
|
+
}
|
|
18423
19337
|
return;
|
|
18424
19338
|
}
|
|
18425
19339
|
function resolveIdentifierToFunction(identifier3, context) {
|
|
@@ -18449,20 +19363,20 @@ function resolveIdentifierToFunction(identifier3, context) {
|
|
|
18449
19363
|
if (typeof definition !== "object" || definition === null)
|
|
18450
19364
|
continue;
|
|
18451
19365
|
const castDefinition = definition;
|
|
18452
|
-
const node = castDefinition
|
|
19366
|
+
const { node } = castDefinition;
|
|
18453
19367
|
if (typeof node !== "object" || node === null)
|
|
18454
19368
|
continue;
|
|
18455
19369
|
const castNode = node;
|
|
18456
|
-
if (castNode.type ===
|
|
19370
|
+
if (castNode.type === TSESTree8.AST_NODE_TYPES.FunctionDeclaration) {
|
|
18457
19371
|
return {
|
|
18458
19372
|
isAsync: Boolean(castNode.async),
|
|
18459
19373
|
node,
|
|
18460
19374
|
type: "function-declaration"
|
|
18461
19375
|
};
|
|
18462
19376
|
}
|
|
18463
|
-
if (castNode.type ===
|
|
19377
|
+
if (castNode.type === TSESTree8.AST_NODE_TYPES.VariableDeclarator && typeof castNode.init === "object" && castNode.init !== null) {
|
|
18464
19378
|
const castInit = castNode.init;
|
|
18465
|
-
if (castInit.type ===
|
|
19379
|
+
if (castInit.type === TSESTree8.AST_NODE_TYPES.ArrowFunctionExpression) {
|
|
18466
19380
|
const arrowNode = castNode.init;
|
|
18467
19381
|
return {
|
|
18468
19382
|
isAsync: Boolean(arrowNode.async),
|
|
@@ -18470,7 +19384,7 @@ function resolveIdentifierToFunction(identifier3, context) {
|
|
|
18470
19384
|
type: "arrow"
|
|
18471
19385
|
};
|
|
18472
19386
|
}
|
|
18473
|
-
if (castInit.type ===
|
|
19387
|
+
if (castInit.type === TSESTree8.AST_NODE_TYPES.FunctionExpression) {
|
|
18474
19388
|
const castInitNode = castNode.init;
|
|
18475
19389
|
return {
|
|
18476
19390
|
isAsync: Boolean(castInitNode.async),
|
|
@@ -18512,18 +19426,18 @@ function isCallbackHookResult(identifier3, context) {
|
|
|
18512
19426
|
if (typeof definition !== "object" || definition === null)
|
|
18513
19427
|
continue;
|
|
18514
19428
|
const castDefinition = definition;
|
|
18515
|
-
const node = castDefinition
|
|
19429
|
+
const { node } = castDefinition;
|
|
18516
19430
|
if (typeof node !== "object" || node === null)
|
|
18517
19431
|
continue;
|
|
18518
19432
|
const castNode = node;
|
|
18519
|
-
if (castNode.type !==
|
|
19433
|
+
if (castNode.type !== TSESTree8.AST_NODE_TYPES.VariableDeclarator)
|
|
18520
19434
|
continue;
|
|
18521
19435
|
if (typeof castNode.init !== "object" || castNode.init === null)
|
|
18522
19436
|
continue;
|
|
18523
19437
|
const init = castNode.init;
|
|
18524
|
-
if (init.type !==
|
|
19438
|
+
if (init.type !== TSESTree8.AST_NODE_TYPES.CallExpression)
|
|
18525
19439
|
continue;
|
|
18526
|
-
const calleeHookName =
|
|
19440
|
+
const calleeHookName = getHookName3(init);
|
|
18527
19441
|
if (calleeHookName === "useCallback" || calleeHookName === "useMemo")
|
|
18528
19442
|
return true;
|
|
18529
19443
|
}
|
|
@@ -18534,7 +19448,7 @@ function isCallbackHookResult(identifier3, context) {
|
|
|
18534
19448
|
}
|
|
18535
19449
|
var requireNamedEffectFunctions = {
|
|
18536
19450
|
create(context) {
|
|
18537
|
-
const { hooks, environment: environment2 } =
|
|
19451
|
+
const { hooks, environment: environment2 } = parseOptions2(context.options[0]);
|
|
18538
19452
|
const hookAsyncConfig = new Map(hooks.map((hookConfig) => [hookConfig.name, hookConfig.allowAsync]));
|
|
18539
19453
|
const effectHooks = new Set(hookAsyncConfig.keys());
|
|
18540
19454
|
const isRobloxTsMode = environment2 === "roblox-ts";
|
|
@@ -18545,14 +19459,14 @@ var requireNamedEffectFunctions = {
|
|
|
18545
19459
|
return {
|
|
18546
19460
|
CallExpression(node) {
|
|
18547
19461
|
const callExpression = node;
|
|
18548
|
-
const hookName =
|
|
19462
|
+
const hookName = getHookName3(callExpression);
|
|
18549
19463
|
if (typeof hookName !== "string" || !effectHooks.has(hookName))
|
|
18550
19464
|
return;
|
|
18551
19465
|
const firstArgument = callExpression.arguments?.[0];
|
|
18552
19466
|
if (firstArgument === undefined)
|
|
18553
19467
|
return;
|
|
18554
19468
|
const argumentNode = firstArgument;
|
|
18555
|
-
if (argumentNode.type ===
|
|
19469
|
+
if (argumentNode.type === TSESTree8.AST_NODE_TYPES.Identifier) {
|
|
18556
19470
|
const identifier3 = argumentNode;
|
|
18557
19471
|
const resolved = resolveIdentifierToFunction(identifier3, context);
|
|
18558
19472
|
if (resolved === undefined) {
|
|
@@ -18605,7 +19519,7 @@ var requireNamedEffectFunctions = {
|
|
|
18605
19519
|
}
|
|
18606
19520
|
return;
|
|
18607
19521
|
}
|
|
18608
|
-
if (argumentNode.type ===
|
|
19522
|
+
if (argumentNode.type === TSESTree8.AST_NODE_TYPES.ArrowFunctionExpression) {
|
|
18609
19523
|
if (argumentNode.async) {
|
|
18610
19524
|
context.report({
|
|
18611
19525
|
data: { hook: hookName },
|
|
@@ -18621,7 +19535,7 @@ var requireNamedEffectFunctions = {
|
|
|
18621
19535
|
}
|
|
18622
19536
|
return;
|
|
18623
19537
|
}
|
|
18624
|
-
if (argumentNode.type ===
|
|
19538
|
+
if (argumentNode.type === TSESTree8.AST_NODE_TYPES.FunctionExpression) {
|
|
18625
19539
|
const functionExpressionNode = argumentNode;
|
|
18626
19540
|
const functionHasId = Boolean(functionExpressionNode.id);
|
|
18627
19541
|
if (functionHasId && argumentNode.async) {
|
|
@@ -18649,7 +19563,6 @@ var requireNamedEffectFunctions = {
|
|
|
18649
19563
|
node
|
|
18650
19564
|
});
|
|
18651
19565
|
}
|
|
18652
|
-
return;
|
|
18653
19566
|
}
|
|
18654
19567
|
}
|
|
18655
19568
|
};
|
|
@@ -18712,7 +19625,7 @@ var requireNamedEffectFunctions = {
|
|
|
18712
19625
|
var require_named_effect_functions_default = requireNamedEffectFunctions;
|
|
18713
19626
|
|
|
18714
19627
|
// src/rules/require-paired-calls.ts
|
|
18715
|
-
import { AST_NODE_TYPES as
|
|
19628
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES6 } from "@typescript-eslint/types";
|
|
18716
19629
|
var isStringArray = Compile(build_default.Readonly(build_default.Array(build_default.String())));
|
|
18717
19630
|
var isPairConfiguration = Compile(build_default.Readonly(build_default.Object({
|
|
18718
19631
|
alternatives: build_default.Optional(isStringArray),
|
|
@@ -18730,20 +19643,20 @@ var isRuleOptions3 = Compile(build_default.Partial(build_default.Readonly(build_
|
|
|
18730
19643
|
pairs: build_default.Readonly(build_default.Array(isPairConfiguration))
|
|
18731
19644
|
}))));
|
|
18732
19645
|
var LOOP_NODE_TYPES = new Set([
|
|
18733
|
-
|
|
18734
|
-
|
|
18735
|
-
|
|
18736
|
-
|
|
18737
|
-
|
|
19646
|
+
AST_NODE_TYPES6.DoWhileStatement,
|
|
19647
|
+
AST_NODE_TYPES6.ForInStatement,
|
|
19648
|
+
AST_NODE_TYPES6.ForOfStatement,
|
|
19649
|
+
AST_NODE_TYPES6.ForStatement,
|
|
19650
|
+
AST_NODE_TYPES6.WhileStatement
|
|
18738
19651
|
]);
|
|
18739
19652
|
var DEFAULT_ROBLOX_YIELDING_FUNCTIONS = ["task.wait", "wait", "*.WaitForChild", "*.*Async"];
|
|
18740
19653
|
function getCallName(node) {
|
|
18741
19654
|
const { callee } = node;
|
|
18742
|
-
if (callee.type ===
|
|
19655
|
+
if (callee.type === AST_NODE_TYPES6.Identifier)
|
|
18743
19656
|
return callee.name;
|
|
18744
|
-
if (callee.type ===
|
|
18745
|
-
const object3 = callee.object.type ===
|
|
18746
|
-
const property = callee.property.type ===
|
|
19657
|
+
if (callee.type === AST_NODE_TYPES6.MemberExpression) {
|
|
19658
|
+
const object3 = callee.object.type === AST_NODE_TYPES6.Identifier ? callee.object.name : undefined;
|
|
19659
|
+
const property = callee.property.type === AST_NODE_TYPES6.Identifier ? callee.property.name : undefined;
|
|
18747
19660
|
if (object3 !== undefined && property !== undefined)
|
|
18748
19661
|
return `${object3}.${property}`;
|
|
18749
19662
|
}
|
|
@@ -18779,12 +19692,12 @@ function isLoopLikeStatement(node) {
|
|
|
18779
19692
|
return LOOP_NODE_TYPES.has(node.type);
|
|
18780
19693
|
}
|
|
18781
19694
|
function isSwitchStatement(node) {
|
|
18782
|
-
return node?.type ===
|
|
19695
|
+
return node?.type === AST_NODE_TYPES6.SwitchStatement;
|
|
18783
19696
|
}
|
|
18784
19697
|
function findLabeledStatementBody(label, startingNode) {
|
|
18785
19698
|
let current = startingNode;
|
|
18786
19699
|
while (current) {
|
|
18787
|
-
if (current.type ===
|
|
19700
|
+
if (current.type === AST_NODE_TYPES6.LabeledStatement && current.label.name === label.name)
|
|
18788
19701
|
return current.body;
|
|
18789
19702
|
current = current.parent ?? undefined;
|
|
18790
19703
|
}
|
|
@@ -18821,7 +19734,7 @@ function cloneEntry(value) {
|
|
|
18821
19734
|
}
|
|
18822
19735
|
var rule = {
|
|
18823
19736
|
create(context) {
|
|
18824
|
-
const rawOptions = context.options
|
|
19737
|
+
const [rawOptions] = context.options;
|
|
18825
19738
|
const baseOptions = isRuleOptions3.Check(rawOptions) ? rawOptions : {};
|
|
18826
19739
|
const options3 = {
|
|
18827
19740
|
allowConditionalClosers: baseOptions.allowConditionalClosers ?? false,
|
|
@@ -18987,7 +19900,7 @@ var rule = {
|
|
|
18987
19900
|
const hasCompleteElse = ifNode.alternate !== undefined && ifNode.alternate !== null;
|
|
18988
19901
|
for (const branchStack of branches) {
|
|
18989
19902
|
for (const entry of branchStack) {
|
|
18990
|
-
const wasInOriginal = originalStack.some((
|
|
19903
|
+
const wasInOriginal = originalStack.some(({ index: index2 }) => index2 === entry.index);
|
|
18991
19904
|
if (!wasInOriginal) {
|
|
18992
19905
|
const validClosers = getValidClosers(entry.config);
|
|
18993
19906
|
const closer = validClosers.length === 1 ? validClosers[0] ?? "closer" : validClosers.join("' or '");
|
|
@@ -19036,8 +19949,8 @@ var rule = {
|
|
|
19036
19949
|
}
|
|
19037
19950
|
function onIfConsequentExit(node) {
|
|
19038
19951
|
const consequentNode = node;
|
|
19039
|
-
const parent = consequentNode
|
|
19040
|
-
if (parent?.type ===
|
|
19952
|
+
const { parent } = consequentNode;
|
|
19953
|
+
if (parent?.type === AST_NODE_TYPES6.IfStatement) {
|
|
19041
19954
|
const branches = branchStacks.get(parent) ?? [];
|
|
19042
19955
|
branches.push(cloneStack());
|
|
19043
19956
|
branchStacks.set(parent, branches);
|
|
@@ -19051,8 +19964,8 @@ var rule = {
|
|
|
19051
19964
|
}
|
|
19052
19965
|
function onIfAlternateExit(node) {
|
|
19053
19966
|
const alternateNode = node;
|
|
19054
|
-
const parent = alternateNode
|
|
19055
|
-
if (parent?.type ===
|
|
19967
|
+
const { parent } = alternateNode;
|
|
19968
|
+
if (parent?.type === AST_NODE_TYPES6.IfStatement) {
|
|
19056
19969
|
const branches = branchStacks.get(parent) ?? [];
|
|
19057
19970
|
branches.push(cloneStack());
|
|
19058
19971
|
branchStacks.set(parent, branches);
|
|
@@ -19101,7 +20014,7 @@ var rule = {
|
|
|
19101
20014
|
function onTryBlockExit(node) {
|
|
19102
20015
|
const blockNode = node;
|
|
19103
20016
|
const { parent } = blockNode;
|
|
19104
|
-
if (parent?.type ===
|
|
20017
|
+
if (parent?.type === AST_NODE_TYPES6.TryStatement) {
|
|
19105
20018
|
const branches = branchStacks.get(parent) ?? [];
|
|
19106
20019
|
branches.push(cloneStack());
|
|
19107
20020
|
branchStacks.set(parent, branches);
|
|
@@ -19120,7 +20033,7 @@ var rule = {
|
|
|
19120
20033
|
function onCatchClauseExit(node) {
|
|
19121
20034
|
const catchNode = node;
|
|
19122
20035
|
const { parent } = catchNode;
|
|
19123
|
-
if (parent?.type ===
|
|
20036
|
+
if (parent?.type === AST_NODE_TYPES6.TryStatement) {
|
|
19124
20037
|
const branches = branchStacks.get(parent) ?? [];
|
|
19125
20038
|
branches.push(cloneStack());
|
|
19126
20039
|
branchStacks.set(parent, branches);
|
|
@@ -19183,7 +20096,7 @@ var rule = {
|
|
|
19183
20096
|
function onSwitchCaseExit(node) {
|
|
19184
20097
|
const caseNode = node;
|
|
19185
20098
|
const { parent } = caseNode;
|
|
19186
|
-
if (parent?.type ===
|
|
20099
|
+
if (parent?.type === AST_NODE_TYPES6.SwitchStatement) {
|
|
19187
20100
|
const branches = branchStacks.get(parent) ?? [];
|
|
19188
20101
|
branches.push(cloneStack());
|
|
19189
20102
|
branchStacks.set(parent, branches);
|
|
@@ -19214,7 +20127,7 @@ var rule = {
|
|
|
19214
20127
|
for (const { opener, config, node: node2 } of openerStack) {
|
|
19215
20128
|
const validClosers = getValidClosers(config);
|
|
19216
20129
|
const closer = validClosers.length === 1 ? validClosers[0] ?? "closer" : validClosers.join("' or '");
|
|
19217
|
-
const statementType = statementNode.type ===
|
|
20130
|
+
const statementType = statementNode.type === AST_NODE_TYPES6.ReturnStatement ? "return" : "throw";
|
|
19218
20131
|
const lineNumber = statementNode.loc?.start.line ?? 0;
|
|
19219
20132
|
context.report({
|
|
19220
20133
|
data: {
|
|
@@ -19231,7 +20144,7 @@ var rule = {
|
|
|
19231
20144
|
const statementNode = node;
|
|
19232
20145
|
if (openerStack.length === 0)
|
|
19233
20146
|
return;
|
|
19234
|
-
const targetLoop = statementNode.type ===
|
|
20147
|
+
const targetLoop = statementNode.type === AST_NODE_TYPES6.ContinueStatement ? resolveContinueTargetLoop(statementNode) : resolveBreakTargetLoop(statementNode);
|
|
19235
20148
|
if (!targetLoop)
|
|
19236
20149
|
return;
|
|
19237
20150
|
for (const { node: openerNode, config, opener, loopAncestors } of openerStack) {
|
|
@@ -19239,7 +20152,7 @@ var rule = {
|
|
|
19239
20152
|
continue;
|
|
19240
20153
|
const validClosers = getValidClosers(config);
|
|
19241
20154
|
const closer = validClosers.length === 1 ? validClosers[0] ?? "closer" : validClosers.join("' or '");
|
|
19242
|
-
const statementType = statementNode.type ===
|
|
20155
|
+
const statementType = statementNode.type === AST_NODE_TYPES6.BreakStatement ? "break" : "continue";
|
|
19243
20156
|
const lineNumber = statementNode.loc?.start.line ?? 0;
|
|
19244
20157
|
context.report({
|
|
19245
20158
|
data: {
|
|
@@ -19377,7 +20290,7 @@ var rule = {
|
|
|
19377
20290
|
continue;
|
|
19378
20291
|
const validClosers = getValidClosers(config);
|
|
19379
20292
|
const closer = validClosers.length === 1 ? validClosers[0] ?? "closer" : validClosers.join("' or '");
|
|
19380
|
-
const asyncType = asyncNode.type ===
|
|
20293
|
+
const asyncType = asyncNode.type === AST_NODE_TYPES6.AwaitExpression ? "await" : "yield";
|
|
19381
20294
|
context.report({
|
|
19382
20295
|
data: { asyncType, closer, opener },
|
|
19383
20296
|
messageId: "asyncViolation",
|
|
@@ -19522,7 +20435,7 @@ var rule = {
|
|
|
19522
20435
|
var require_paired_calls_default = rule;
|
|
19523
20436
|
|
|
19524
20437
|
// src/rules/require-react-component-keys.ts
|
|
19525
|
-
import { TSESTree as
|
|
20438
|
+
import { TSESTree as TSESTree9 } from "@typescript-eslint/types";
|
|
19526
20439
|
var DEFAULT_OPTIONS3 = {
|
|
19527
20440
|
allowRootKeys: false,
|
|
19528
20441
|
ignoreCallExpressions: ["ReactTree.mount", "CreateReactStory"],
|
|
@@ -19565,22 +20478,22 @@ function ascendPastWrappers(node) {
|
|
|
19565
20478
|
}
|
|
19566
20479
|
function hasKeyAttribute(node) {
|
|
19567
20480
|
for (const attribute of node.openingElement.attributes)
|
|
19568
|
-
if (attribute.type ===
|
|
20481
|
+
if (attribute.type === TSESTree9.AST_NODE_TYPES.JSXAttribute && attribute.name.name === "key")
|
|
19569
20482
|
return true;
|
|
19570
20483
|
return false;
|
|
19571
20484
|
}
|
|
19572
|
-
function
|
|
20485
|
+
function isReactComponentHOC2(callExpr) {
|
|
19573
20486
|
const { callee } = callExpr;
|
|
19574
|
-
if (callee.type ===
|
|
20487
|
+
if (callee.type === TSESTree9.AST_NODE_TYPES.Identifier)
|
|
19575
20488
|
return callee.name === "forwardRef" || callee.name === "memo";
|
|
19576
|
-
if (callee.type ===
|
|
20489
|
+
if (callee.type === TSESTree9.AST_NODE_TYPES.MemberExpression && callee.object.type === TSESTree9.AST_NODE_TYPES.Identifier && callee.object.name === "React" && callee.property.type === TSESTree9.AST_NODE_TYPES.Identifier)
|
|
19577
20490
|
return callee.property.name === "forwardRef" || callee.property.name === "memo";
|
|
19578
20491
|
return false;
|
|
19579
20492
|
}
|
|
19580
20493
|
function getEnclosingFunctionLike(node) {
|
|
19581
20494
|
let current = node.parent;
|
|
19582
20495
|
while (current) {
|
|
19583
|
-
if (current.type ===
|
|
20496
|
+
if (current.type === TSESTree9.AST_NODE_TYPES.ArrowFunctionExpression || current.type === TSESTree9.AST_NODE_TYPES.FunctionExpression || current.type === TSESTree9.AST_NODE_TYPES.FunctionDeclaration)
|
|
19584
20497
|
return current;
|
|
19585
20498
|
current = current.parent;
|
|
19586
20499
|
}
|
|
@@ -19588,16 +20501,18 @@ function getEnclosingFunctionLike(node) {
|
|
|
19588
20501
|
}
|
|
19589
20502
|
function isIterationOrMemoCallback(callExpr, iterationMethods, memoizationHooks) {
|
|
19590
20503
|
const { callee } = callExpr;
|
|
19591
|
-
if (callee.type ===
|
|
20504
|
+
if (callee.type === TSESTree9.AST_NODE_TYPES.Identifier && memoizationHooks.has(callee.name))
|
|
19592
20505
|
return true;
|
|
19593
|
-
if (callee.type ===
|
|
20506
|
+
if (callee.type === TSESTree9.AST_NODE_TYPES.MemberExpression && callee.property.type === TSESTree9.AST_NODE_TYPES.Identifier) {
|
|
19594
20507
|
const methodName = callee.property.name;
|
|
19595
20508
|
if (iterationMethods.has(methodName))
|
|
19596
20509
|
return true;
|
|
19597
|
-
if (methodName === "from" && callee.object.type ===
|
|
20510
|
+
if (methodName === "from" && callee.object.type === TSESTree9.AST_NODE_TYPES.MemberExpression && callee.object.object.type === TSESTree9.AST_NODE_TYPES.Identifier && callee.object.object.name === "Array" && callExpr.arguments.length >= 2) {
|
|
19598
20511
|
return true;
|
|
19599
|
-
|
|
20512
|
+
}
|
|
20513
|
+
if (methodName === "call" && callee.object.type === TSESTree9.AST_NODE_TYPES.MemberExpression && callee.object.object.type === TSESTree9.AST_NODE_TYPES.MemberExpression && callee.object.object.property.type === TSESTree9.AST_NODE_TYPES.Identifier && iterationMethods.has(callee.object.object.property.name)) {
|
|
19600
20514
|
return true;
|
|
20515
|
+
}
|
|
19601
20516
|
}
|
|
19602
20517
|
return false;
|
|
19603
20518
|
}
|
|
@@ -19605,18 +20520,19 @@ function findEnclosingCallExpression(node) {
|
|
|
19605
20520
|
let current = node;
|
|
19606
20521
|
let { parent } = node;
|
|
19607
20522
|
while (parent) {
|
|
19608
|
-
if (parent.type ===
|
|
20523
|
+
if (parent.type === TSESTree9.AST_NODE_TYPES.CallExpression) {
|
|
19609
20524
|
for (const argument of parent.arguments) {
|
|
19610
20525
|
if (argument === current)
|
|
19611
20526
|
return parent;
|
|
19612
|
-
if (argument.type ===
|
|
20527
|
+
if (argument.type === TSESTree9.AST_NODE_TYPES.SpreadElement && argument.argument === current) {
|
|
19613
20528
|
return parent;
|
|
20529
|
+
}
|
|
19614
20530
|
}
|
|
19615
20531
|
return;
|
|
19616
20532
|
}
|
|
19617
20533
|
if (ARGUMENT_WRAPPER_TYPES.has(parent.type)) {
|
|
19618
20534
|
current = parent;
|
|
19619
|
-
parent = parent
|
|
20535
|
+
({ parent } = parent);
|
|
19620
20536
|
continue;
|
|
19621
20537
|
}
|
|
19622
20538
|
break;
|
|
@@ -19624,7 +20540,7 @@ function findEnclosingCallExpression(node) {
|
|
|
19624
20540
|
return;
|
|
19625
20541
|
}
|
|
19626
20542
|
function getVariableForFunction(context, functionLike) {
|
|
19627
|
-
if (functionLike.type ===
|
|
20543
|
+
if (functionLike.type === TSESTree9.AST_NODE_TYPES.FunctionDeclaration) {
|
|
19628
20544
|
const declared = context.sourceCode.getDeclaredVariables(functionLike);
|
|
19629
20545
|
if (declared.length > 0)
|
|
19630
20546
|
return declared[0];
|
|
@@ -19633,7 +20549,7 @@ function getVariableForFunction(context, functionLike) {
|
|
|
19633
20549
|
const { parent } = functionLike;
|
|
19634
20550
|
if (!parent)
|
|
19635
20551
|
return;
|
|
19636
|
-
if (parent.type ===
|
|
20552
|
+
if (parent.type === TSESTree9.AST_NODE_TYPES.VariableDeclarator || parent.type === TSESTree9.AST_NODE_TYPES.AssignmentExpression) {
|
|
19637
20553
|
const declared = context.sourceCode.getDeclaredVariables(parent);
|
|
19638
20554
|
if (declared.length > 0)
|
|
19639
20555
|
return declared[0];
|
|
@@ -19646,14 +20562,14 @@ function referenceActsAsCallback(reference, iterationMethods, memoizationHooks)
|
|
|
19646
20562
|
const callExpression = findEnclosingCallExpression(reference.identifier);
|
|
19647
20563
|
if (!callExpression)
|
|
19648
20564
|
return false;
|
|
19649
|
-
if (
|
|
20565
|
+
if (isReactComponentHOC2(callExpression))
|
|
19650
20566
|
return false;
|
|
19651
20567
|
return isIterationOrMemoCallback(callExpression, iterationMethods, memoizationHooks);
|
|
19652
20568
|
}
|
|
19653
20569
|
function isFunctionUsedAsCallback(context, functionLike, iterationMethods, memoizationHooks) {
|
|
19654
20570
|
const inlineCall = findEnclosingCallExpression(functionLike);
|
|
19655
20571
|
if (inlineCall) {
|
|
19656
|
-
if (
|
|
20572
|
+
if (isReactComponentHOC2(inlineCall))
|
|
19657
20573
|
return false;
|
|
19658
20574
|
return isIterationOrMemoCallback(inlineCall, iterationMethods, memoizationHooks);
|
|
19659
20575
|
}
|
|
@@ -19666,33 +20582,33 @@ function isFunctionUsedAsCallback(context, functionLike, iterationMethods, memoi
|
|
|
19666
20582
|
return false;
|
|
19667
20583
|
}
|
|
19668
20584
|
var SHOULD_ASCEND_TYPES = new Set([
|
|
19669
|
-
|
|
19670
|
-
|
|
20585
|
+
TSESTree9.AST_NODE_TYPES.ConditionalExpression,
|
|
20586
|
+
TSESTree9.AST_NODE_TYPES.LogicalExpression
|
|
19671
20587
|
]);
|
|
19672
20588
|
var IS_FUNCTION_EXPRESSION = new Set([
|
|
19673
|
-
|
|
19674
|
-
|
|
20589
|
+
TSESTree9.AST_NODE_TYPES.FunctionExpression,
|
|
20590
|
+
TSESTree9.AST_NODE_TYPES.ArrowFunctionExpression
|
|
19675
20591
|
]);
|
|
19676
20592
|
var CONTROL_FLOW_TYPES = new Set([
|
|
19677
|
-
|
|
19678
|
-
|
|
19679
|
-
|
|
19680
|
-
|
|
19681
|
-
|
|
19682
|
-
|
|
19683
|
-
|
|
19684
|
-
|
|
19685
|
-
|
|
19686
|
-
|
|
19687
|
-
|
|
19688
|
-
|
|
19689
|
-
|
|
20593
|
+
TSESTree9.AST_NODE_TYPES.BlockStatement,
|
|
20594
|
+
TSESTree9.AST_NODE_TYPES.IfStatement,
|
|
20595
|
+
TSESTree9.AST_NODE_TYPES.SwitchStatement,
|
|
20596
|
+
TSESTree9.AST_NODE_TYPES.SwitchCase,
|
|
20597
|
+
TSESTree9.AST_NODE_TYPES.TryStatement,
|
|
20598
|
+
TSESTree9.AST_NODE_TYPES.CatchClause,
|
|
20599
|
+
TSESTree9.AST_NODE_TYPES.WhileStatement,
|
|
20600
|
+
TSESTree9.AST_NODE_TYPES.DoWhileStatement,
|
|
20601
|
+
TSESTree9.AST_NODE_TYPES.ForStatement,
|
|
20602
|
+
TSESTree9.AST_NODE_TYPES.ForInStatement,
|
|
20603
|
+
TSESTree9.AST_NODE_TYPES.ForOfStatement,
|
|
20604
|
+
TSESTree9.AST_NODE_TYPES.LabeledStatement,
|
|
20605
|
+
TSESTree9.AST_NODE_TYPES.WithStatement
|
|
19690
20606
|
]);
|
|
19691
20607
|
function isTopLevelReturn(node) {
|
|
19692
20608
|
let parent = ascendPastWrappers(node.parent);
|
|
19693
20609
|
if (!parent)
|
|
19694
20610
|
return false;
|
|
19695
|
-
if (parent.type ===
|
|
20611
|
+
if (parent.type === TSESTree9.AST_NODE_TYPES.JSXExpressionContainer)
|
|
19696
20612
|
parent = ascendPastWrappers(parent.parent);
|
|
19697
20613
|
if (!parent)
|
|
19698
20614
|
return false;
|
|
@@ -19700,28 +20616,30 @@ function isTopLevelReturn(node) {
|
|
|
19700
20616
|
parent = ascendPastWrappers(parent.parent);
|
|
19701
20617
|
if (!parent)
|
|
19702
20618
|
return false;
|
|
19703
|
-
if (parent.type ===
|
|
20619
|
+
if (parent.type === TSESTree9.AST_NODE_TYPES.JSXExpressionContainer)
|
|
19704
20620
|
parent = ascendPastWrappers(parent.parent);
|
|
19705
20621
|
if (!parent)
|
|
19706
20622
|
return false;
|
|
19707
|
-
if (parent.type ===
|
|
20623
|
+
if (parent.type === TSESTree9.AST_NODE_TYPES.ReturnStatement) {
|
|
19708
20624
|
let currentNode = ascendPastWrappers(parent.parent);
|
|
19709
|
-
while (currentNode && CONTROL_FLOW_TYPES.has(currentNode.type))
|
|
20625
|
+
while (currentNode && CONTROL_FLOW_TYPES.has(currentNode.type)) {
|
|
19710
20626
|
currentNode = ascendPastWrappers(currentNode.parent);
|
|
20627
|
+
}
|
|
19711
20628
|
if (!currentNode)
|
|
19712
20629
|
return false;
|
|
19713
20630
|
if (IS_FUNCTION_EXPRESSION.has(currentNode.type)) {
|
|
19714
20631
|
const functionParent = ascendPastWrappers(currentNode.parent);
|
|
19715
|
-
if (functionParent?.type ===
|
|
19716
|
-
return
|
|
20632
|
+
if (functionParent?.type === TSESTree9.AST_NODE_TYPES.CallExpression) {
|
|
20633
|
+
return isReactComponentHOC2(functionParent);
|
|
20634
|
+
}
|
|
19717
20635
|
return true;
|
|
19718
20636
|
}
|
|
19719
|
-
return currentNode.type ===
|
|
20637
|
+
return currentNode.type === TSESTree9.AST_NODE_TYPES.FunctionDeclaration;
|
|
19720
20638
|
}
|
|
19721
|
-
if (parent.type ===
|
|
20639
|
+
if (parent.type === TSESTree9.AST_NODE_TYPES.ArrowFunctionExpression) {
|
|
19722
20640
|
const functionParent = ascendPastWrappers(parent.parent);
|
|
19723
|
-
if (functionParent?.type ===
|
|
19724
|
-
return
|
|
20641
|
+
if (functionParent?.type === TSESTree9.AST_NODE_TYPES.CallExpression)
|
|
20642
|
+
return isReactComponentHOC2(functionParent);
|
|
19725
20643
|
return true;
|
|
19726
20644
|
}
|
|
19727
20645
|
return false;
|
|
@@ -19730,23 +20648,24 @@ function isIgnoredCallExpression(node, ignoreList) {
|
|
|
19730
20648
|
let parent = node.parent;
|
|
19731
20649
|
if (!parent)
|
|
19732
20650
|
return false;
|
|
19733
|
-
if (parent.type ===
|
|
19734
|
-
parent = parent
|
|
20651
|
+
if (parent.type === TSESTree9.AST_NODE_TYPES.JSXExpressionContainer) {
|
|
20652
|
+
({ parent } = parent);
|
|
19735
20653
|
if (!parent)
|
|
19736
20654
|
return false;
|
|
19737
20655
|
}
|
|
19738
20656
|
const maxDepth = 20;
|
|
19739
20657
|
for (let depth = 0;depth < maxDepth && parent; depth += 1) {
|
|
19740
20658
|
const { type: type3 } = parent;
|
|
19741
|
-
if (type3 ===
|
|
20659
|
+
if (type3 === TSESTree9.AST_NODE_TYPES.CallExpression) {
|
|
19742
20660
|
const { callee } = parent;
|
|
19743
|
-
if (callee.type ===
|
|
20661
|
+
if (callee.type === TSESTree9.AST_NODE_TYPES.Identifier)
|
|
19744
20662
|
return ignoreList.includes(callee.name);
|
|
19745
|
-
if (callee.type ===
|
|
20663
|
+
if (callee.type === TSESTree9.AST_NODE_TYPES.MemberExpression && callee.object.type === TSESTree9.AST_NODE_TYPES.Identifier && callee.property.type === TSESTree9.AST_NODE_TYPES.Identifier) {
|
|
19746
20664
|
return ignoreList.includes(`${callee.object.name}.${callee.property.name}`);
|
|
20665
|
+
}
|
|
19747
20666
|
return false;
|
|
19748
20667
|
}
|
|
19749
|
-
parent = parent
|
|
20668
|
+
({ parent } = parent);
|
|
19750
20669
|
}
|
|
19751
20670
|
return false;
|
|
19752
20671
|
}
|
|
@@ -19754,35 +20673,36 @@ function isJSXPropValue(node) {
|
|
|
19754
20673
|
let { parent } = node;
|
|
19755
20674
|
if (!parent)
|
|
19756
20675
|
return false;
|
|
19757
|
-
while (parent && (parent.type ===
|
|
19758
|
-
parent = parent
|
|
20676
|
+
while (parent && (parent.type === TSESTree9.AST_NODE_TYPES.ConditionalExpression || parent.type === TSESTree9.AST_NODE_TYPES.LogicalExpression)) {
|
|
20677
|
+
({ parent } = parent);
|
|
20678
|
+
}
|
|
19759
20679
|
if (!parent)
|
|
19760
20680
|
return false;
|
|
19761
|
-
if (parent.type ===
|
|
19762
|
-
parent = parent
|
|
20681
|
+
if (parent.type === TSESTree9.AST_NODE_TYPES.JSXExpressionContainer) {
|
|
20682
|
+
({ parent } = parent);
|
|
19763
20683
|
if (!parent)
|
|
19764
20684
|
return false;
|
|
19765
20685
|
}
|
|
19766
|
-
return parent.type ===
|
|
20686
|
+
return parent.type === TSESTree9.AST_NODE_TYPES.JSXAttribute;
|
|
19767
20687
|
}
|
|
19768
20688
|
function isTernaryJSXChild(node) {
|
|
19769
20689
|
let current = node.parent;
|
|
19770
20690
|
if (!current)
|
|
19771
20691
|
return false;
|
|
19772
20692
|
let foundTernary = false;
|
|
19773
|
-
while (current && (current.type ===
|
|
19774
|
-
if (current.type ===
|
|
20693
|
+
while (current && (current.type === TSESTree9.AST_NODE_TYPES.ConditionalExpression || WRAPPER_PARENT_TYPES.has(current.type))) {
|
|
20694
|
+
if (current.type === TSESTree9.AST_NODE_TYPES.ConditionalExpression)
|
|
19775
20695
|
foundTernary = true;
|
|
19776
20696
|
current = current.parent;
|
|
19777
20697
|
}
|
|
19778
|
-
if (!foundTernary
|
|
20698
|
+
if (!(foundTernary && current))
|
|
19779
20699
|
return false;
|
|
19780
|
-
if (current.type !==
|
|
20700
|
+
if (current.type !== TSESTree9.AST_NODE_TYPES.JSXExpressionContainer)
|
|
19781
20701
|
return false;
|
|
19782
20702
|
const containerParent = current.parent;
|
|
19783
20703
|
if (!containerParent)
|
|
19784
20704
|
return false;
|
|
19785
|
-
return containerParent.type ===
|
|
20705
|
+
return containerParent.type === TSESTree9.AST_NODE_TYPES.JSXElement || containerParent.type === TSESTree9.AST_NODE_TYPES.JSXFragment;
|
|
19786
20706
|
}
|
|
19787
20707
|
var docs3 = {
|
|
19788
20708
|
description: "Enforce key props on all React elements except top-level returns",
|
|
@@ -19801,7 +20721,7 @@ var requireReactComponentKeys = {
|
|
|
19801
20721
|
const isCallback = functionLike ? isFunctionUsedAsCallback(context, functionLike, iterationMethods, memoizationHooks) : false;
|
|
19802
20722
|
const isRoot = isTopLevelReturn(node);
|
|
19803
20723
|
if (isRoot && !isCallback) {
|
|
19804
|
-
if (!options3.allowRootKeys && node.type ===
|
|
20724
|
+
if (!options3.allowRootKeys && node.type === TSESTree9.AST_NODE_TYPES.JSXElement && hasKeyAttribute(node)) {
|
|
19805
20725
|
context.report({
|
|
19806
20726
|
messageId: "rootComponentWithKey",
|
|
19807
20727
|
node
|
|
@@ -19815,7 +20735,7 @@ var requireReactComponentKeys = {
|
|
|
19815
20735
|
return;
|
|
19816
20736
|
if (isTernaryJSXChild(node))
|
|
19817
20737
|
return;
|
|
19818
|
-
if (node.type ===
|
|
20738
|
+
if (node.type === TSESTree9.AST_NODE_TYPES.JSXFragment) {
|
|
19819
20739
|
context.report({
|
|
19820
20740
|
messageId: "missingKey",
|
|
19821
20741
|
node
|
|
@@ -19893,16 +20813,16 @@ var requireReactComponentKeys = {
|
|
|
19893
20813
|
var require_react_component_keys_default = requireReactComponentKeys;
|
|
19894
20814
|
|
|
19895
20815
|
// src/rules/use-exhaustive-dependencies.ts
|
|
19896
|
-
import { TSESTree as
|
|
20816
|
+
import { TSESTree as TSESTree10 } from "@typescript-eslint/types";
|
|
19897
20817
|
var FUNCTION_DECLARATIONS = new Set([
|
|
19898
|
-
|
|
19899
|
-
|
|
19900
|
-
|
|
20818
|
+
TSESTree10.AST_NODE_TYPES.FunctionExpression,
|
|
20819
|
+
TSESTree10.AST_NODE_TYPES.ArrowFunctionExpression,
|
|
20820
|
+
TSESTree10.AST_NODE_TYPES.FunctionDeclaration
|
|
19901
20821
|
]);
|
|
19902
20822
|
var UNSTABLE_VALUES = new Set([
|
|
19903
20823
|
...FUNCTION_DECLARATIONS,
|
|
19904
|
-
|
|
19905
|
-
|
|
20824
|
+
TSESTree10.AST_NODE_TYPES.ObjectExpression,
|
|
20825
|
+
TSESTree10.AST_NODE_TYPES.ArrayExpression
|
|
19906
20826
|
]);
|
|
19907
20827
|
var testingMetrics = {
|
|
19908
20828
|
moduleLevelStableConst: 0,
|
|
@@ -19984,11 +20904,11 @@ var GLOBAL_BUILTINS = new Set([
|
|
|
19984
20904
|
"Window",
|
|
19985
20905
|
"Event"
|
|
19986
20906
|
]);
|
|
19987
|
-
function
|
|
20907
|
+
function getHookName4(node) {
|
|
19988
20908
|
const { callee } = node;
|
|
19989
|
-
if (callee.type ===
|
|
20909
|
+
if (callee.type === TSESTree10.AST_NODE_TYPES.Identifier)
|
|
19990
20910
|
return callee.name;
|
|
19991
|
-
if (callee.type ===
|
|
20911
|
+
if (callee.type === TSESTree10.AST_NODE_TYPES.MemberExpression && callee.property.type === TSESTree10.AST_NODE_TYPES.Identifier) {
|
|
19992
20912
|
return callee.property.name;
|
|
19993
20913
|
}
|
|
19994
20914
|
return;
|
|
@@ -19996,9 +20916,9 @@ function getHookName2(node) {
|
|
|
19996
20916
|
function getMemberExpressionDepth(node) {
|
|
19997
20917
|
let depth = 0;
|
|
19998
20918
|
let current = node;
|
|
19999
|
-
if (current.type ===
|
|
20919
|
+
if (current.type === TSESTree10.AST_NODE_TYPES.ChainExpression)
|
|
20000
20920
|
current = current.expression;
|
|
20001
|
-
while (current.type ===
|
|
20921
|
+
while (current.type === TSESTree10.AST_NODE_TYPES.MemberExpression) {
|
|
20002
20922
|
depth += 1;
|
|
20003
20923
|
current = current.object;
|
|
20004
20924
|
}
|
|
@@ -20006,36 +20926,36 @@ function getMemberExpressionDepth(node) {
|
|
|
20006
20926
|
}
|
|
20007
20927
|
function getRootIdentifier(node) {
|
|
20008
20928
|
let current = node;
|
|
20009
|
-
if (current.type ===
|
|
20929
|
+
if (current.type === TSESTree10.AST_NODE_TYPES.ChainExpression)
|
|
20010
20930
|
current = current.expression;
|
|
20011
|
-
while (current.type ===
|
|
20012
|
-
if (current.type ===
|
|
20931
|
+
while (current.type === TSESTree10.AST_NODE_TYPES.MemberExpression || current.type === TSESTree10.AST_NODE_TYPES.TSNonNullExpression) {
|
|
20932
|
+
if (current.type === TSESTree10.AST_NODE_TYPES.MemberExpression)
|
|
20013
20933
|
current = current.object;
|
|
20014
20934
|
else
|
|
20015
20935
|
current = current.expression;
|
|
20016
20936
|
}
|
|
20017
|
-
return current.type ===
|
|
20937
|
+
return current.type === TSESTree10.AST_NODE_TYPES.Identifier ? current : undefined;
|
|
20018
20938
|
}
|
|
20019
20939
|
function nodeToDependencyString(node, sourceCode) {
|
|
20020
20940
|
return sourceCode.getText(node);
|
|
20021
20941
|
}
|
|
20022
20942
|
function nodeToSafeDependencyPath(node, sourceCode) {
|
|
20023
|
-
if (node.type ===
|
|
20943
|
+
if (node.type === TSESTree10.AST_NODE_TYPES.Identifier)
|
|
20024
20944
|
return node.name;
|
|
20025
|
-
if (node.type ===
|
|
20945
|
+
if (node.type === TSESTree10.AST_NODE_TYPES.ChainExpression) {
|
|
20026
20946
|
return nodeToSafeDependencyPath(node.expression, sourceCode);
|
|
20027
20947
|
}
|
|
20028
20948
|
if (TS_RUNTIME_EXPRESSIONS.has(node.type)) {
|
|
20029
20949
|
const expr = node;
|
|
20030
20950
|
return nodeToSafeDependencyPath(expr.expression, sourceCode);
|
|
20031
20951
|
}
|
|
20032
|
-
if (node.type ===
|
|
20952
|
+
if (node.type === TSESTree10.AST_NODE_TYPES.MemberExpression) {
|
|
20033
20953
|
const objectPath = nodeToSafeDependencyPath(node.object, sourceCode);
|
|
20034
20954
|
if (node.computed) {
|
|
20035
20955
|
const propertyText = sourceCode.getText(node.property);
|
|
20036
20956
|
return `${objectPath}[${propertyText}]`;
|
|
20037
20957
|
}
|
|
20038
|
-
const propertyName = node.property.type ===
|
|
20958
|
+
const propertyName = node.property.type === TSESTree10.AST_NODE_TYPES.Identifier ? node.property.name : "";
|
|
20039
20959
|
const separator = node.optional ? "?." : ".";
|
|
20040
20960
|
return `${objectPath}${separator}${propertyName}`;
|
|
20041
20961
|
}
|
|
@@ -20044,13 +20964,13 @@ function nodeToSafeDependencyPath(node, sourceCode) {
|
|
|
20044
20964
|
function isStableArrayIndex(stableResult, node, identifierName) {
|
|
20045
20965
|
if (!stableResult)
|
|
20046
20966
|
return false;
|
|
20047
|
-
if (!(stableResult instanceof Set) || node.type !==
|
|
20967
|
+
if (!(stableResult instanceof Set) || node.type !== TSESTree10.AST_NODE_TYPES.VariableDeclarator || node.id.type !== TSESTree10.AST_NODE_TYPES.ArrayPattern) {
|
|
20048
20968
|
return false;
|
|
20049
20969
|
}
|
|
20050
|
-
const elements = node.id
|
|
20970
|
+
const { elements } = node.id;
|
|
20051
20971
|
let index2 = 0;
|
|
20052
20972
|
for (const element of elements) {
|
|
20053
|
-
if (element.type ===
|
|
20973
|
+
if (element.type === TSESTree10.AST_NODE_TYPES.Identifier && element.name === identifierName) {
|
|
20054
20974
|
return stableResult.has(index2);
|
|
20055
20975
|
}
|
|
20056
20976
|
index2 += 1;
|
|
@@ -20059,9 +20979,9 @@ function isStableArrayIndex(stableResult, node, identifierName) {
|
|
|
20059
20979
|
}
|
|
20060
20980
|
function isStableHookValue(init, node, identifierName, stableHooks) {
|
|
20061
20981
|
const castInit = init;
|
|
20062
|
-
if (castInit.type !==
|
|
20982
|
+
if (castInit.type !== TSESTree10.AST_NODE_TYPES.CallExpression)
|
|
20063
20983
|
return false;
|
|
20064
|
-
const hookName =
|
|
20984
|
+
const hookName = getHookName4(castInit);
|
|
20065
20985
|
if (!hookName)
|
|
20066
20986
|
return false;
|
|
20067
20987
|
const stableResult = stableHooks.get(hookName);
|
|
@@ -20079,34 +20999,34 @@ function isStableValue(variable, identifierName, stableHooks) {
|
|
|
20079
20999
|
const { node, type: type3 } = definition;
|
|
20080
21000
|
if (STABLE_VALUE_TYPES.has(type3))
|
|
20081
21001
|
return true;
|
|
20082
|
-
if (type3 === "Variable" && node.type ===
|
|
20083
|
-
const parent = node
|
|
20084
|
-
if (!parent || parent.type !==
|
|
21002
|
+
if (type3 === "Variable" && node.type === TSESTree10.AST_NODE_TYPES.VariableDeclarator) {
|
|
21003
|
+
const { parent } = node;
|
|
21004
|
+
if (!parent || parent.type !== TSESTree10.AST_NODE_TYPES.VariableDeclaration || parent.kind !== "const")
|
|
20085
21005
|
continue;
|
|
20086
21006
|
const init = node.init;
|
|
20087
21007
|
if (init && isStableHookValue(init, node, identifierName, stableHooks))
|
|
20088
21008
|
return true;
|
|
20089
|
-
if (init?.type ===
|
|
21009
|
+
if (init?.type === TSESTree10.AST_NODE_TYPES.CallExpression) {
|
|
20090
21010
|
const { callee } = init;
|
|
20091
|
-
if (callee.type ===
|
|
21011
|
+
if (callee.type === TSESTree10.AST_NODE_TYPES.MemberExpression && callee.object.type === TSESTree10.AST_NODE_TYPES.Identifier && callee.object.name === "React" && callee.property.type === TSESTree10.AST_NODE_TYPES.Identifier && callee.property.name === "joinBindings") {
|
|
20092
21012
|
return true;
|
|
20093
21013
|
}
|
|
20094
|
-
if (callee.type ===
|
|
21014
|
+
if (callee.type === TSESTree10.AST_NODE_TYPES.MemberExpression && callee.property.type === TSESTree10.AST_NODE_TYPES.Identifier && callee.property.name === "map") {
|
|
20095
21015
|
return true;
|
|
20096
21016
|
}
|
|
20097
21017
|
}
|
|
20098
21018
|
if (init) {
|
|
20099
|
-
if (init.type ===
|
|
21019
|
+
if (init.type === TSESTree10.AST_NODE_TYPES.Literal || init.type === TSESTree10.AST_NODE_TYPES.TemplateLiteral) {
|
|
20100
21020
|
return true;
|
|
20101
21021
|
}
|
|
20102
|
-
if (init.type ===
|
|
21022
|
+
if (init.type === TSESTree10.AST_NODE_TYPES.UnaryExpression && init.argument.type === TSESTree10.AST_NODE_TYPES.Literal) {
|
|
20103
21023
|
return true;
|
|
20104
21024
|
}
|
|
20105
21025
|
}
|
|
20106
21026
|
const variableDefinition = variable.defs.find((definition2) => definition2.node === node);
|
|
20107
|
-
if (variableDefinition && variableDefinition.node.type ===
|
|
21027
|
+
if (variableDefinition && variableDefinition.node.type === TSESTree10.AST_NODE_TYPES.VariableDeclarator) {
|
|
20108
21028
|
const declarationParent = variableDefinition.node.parent?.parent;
|
|
20109
|
-
if (declarationParent && (declarationParent.type ===
|
|
21029
|
+
if (declarationParent && (declarationParent.type === TSESTree10.AST_NODE_TYPES.Program || declarationParent.type === TSESTree10.AST_NODE_TYPES.ExportNamedDeclaration)) {
|
|
20110
21030
|
testingMetrics.moduleLevelStableConst += 1;
|
|
20111
21031
|
return true;
|
|
20112
21032
|
}
|
|
@@ -20119,50 +21039,50 @@ function findTopmostMemberExpression(node) {
|
|
|
20119
21039
|
let current = node;
|
|
20120
21040
|
let { parent } = node;
|
|
20121
21041
|
while (parent) {
|
|
20122
|
-
if (parent.type ===
|
|
20123
|
-
if (current.type ===
|
|
21042
|
+
if (parent.type === TSESTree10.AST_NODE_TYPES.CallExpression && parent.callee === current) {
|
|
21043
|
+
if (current.type === TSESTree10.AST_NODE_TYPES.MemberExpression)
|
|
20124
21044
|
return current.object;
|
|
20125
21045
|
break;
|
|
20126
21046
|
}
|
|
20127
|
-
const isMemberParent = parent.type ===
|
|
20128
|
-
const isChainParent = parent.type ===
|
|
20129
|
-
const isNonNullParent = parent.type ===
|
|
20130
|
-
if (!isMemberParent
|
|
21047
|
+
const isMemberParent = parent.type === TSESTree10.AST_NODE_TYPES.MemberExpression && parent.object === current;
|
|
21048
|
+
const isChainParent = parent.type === TSESTree10.AST_NODE_TYPES.ChainExpression;
|
|
21049
|
+
const isNonNullParent = parent.type === TSESTree10.AST_NODE_TYPES.TSNonNullExpression;
|
|
21050
|
+
if (!(isMemberParent || isChainParent || isNonNullParent))
|
|
20131
21051
|
break;
|
|
20132
21052
|
current = parent;
|
|
20133
|
-
parent = parent
|
|
21053
|
+
({ parent } = parent);
|
|
20134
21054
|
}
|
|
20135
21055
|
return current;
|
|
20136
21056
|
}
|
|
20137
21057
|
var IS_CEASE_BOUNDARY = new Set([
|
|
20138
|
-
|
|
20139
|
-
|
|
20140
|
-
|
|
20141
|
-
|
|
21058
|
+
TSESTree10.AST_NODE_TYPES.FunctionDeclaration,
|
|
21059
|
+
TSESTree10.AST_NODE_TYPES.FunctionExpression,
|
|
21060
|
+
TSESTree10.AST_NODE_TYPES.ArrowFunctionExpression,
|
|
21061
|
+
TSESTree10.AST_NODE_TYPES.VariableDeclarator
|
|
20142
21062
|
]);
|
|
20143
21063
|
var TS_RUNTIME_EXPRESSIONS = new Set([
|
|
20144
|
-
|
|
20145
|
-
|
|
20146
|
-
|
|
20147
|
-
|
|
20148
|
-
|
|
21064
|
+
TSESTree10.AST_NODE_TYPES.TSNonNullExpression,
|
|
21065
|
+
TSESTree10.AST_NODE_TYPES.TSAsExpression,
|
|
21066
|
+
TSESTree10.AST_NODE_TYPES.TSSatisfiesExpression,
|
|
21067
|
+
TSESTree10.AST_NODE_TYPES.TSTypeAssertion,
|
|
21068
|
+
TSESTree10.AST_NODE_TYPES.TSInstantiationExpression
|
|
20149
21069
|
]);
|
|
20150
21070
|
function isComputedPropertyIdentifier(identifier3) {
|
|
20151
|
-
const parent = identifier3
|
|
20152
|
-
return parent?.type ===
|
|
21071
|
+
const { parent } = identifier3;
|
|
21072
|
+
return parent?.type === TSESTree10.AST_NODE_TYPES.Property && parent.computed && parent.key === identifier3;
|
|
20153
21073
|
}
|
|
20154
21074
|
function isInTypePosition(identifier3) {
|
|
20155
21075
|
let parent = identifier3.parent;
|
|
20156
21076
|
while (parent) {
|
|
20157
21077
|
if (TS_RUNTIME_EXPRESSIONS.has(parent.type)) {
|
|
20158
|
-
parent = parent
|
|
21078
|
+
({ parent } = parent);
|
|
20159
21079
|
continue;
|
|
20160
21080
|
}
|
|
20161
21081
|
if (parent.type.startsWith("TS"))
|
|
20162
21082
|
return true;
|
|
20163
21083
|
if (IS_CEASE_BOUNDARY.has(parent.type))
|
|
20164
21084
|
return false;
|
|
20165
|
-
parent = parent
|
|
21085
|
+
({ parent } = parent);
|
|
20166
21086
|
}
|
|
20167
21087
|
return false;
|
|
20168
21088
|
}
|
|
@@ -20186,7 +21106,7 @@ function isDeclaredInComponentBody(variable, closureNode) {
|
|
|
20186
21106
|
return node === functionParent;
|
|
20187
21107
|
});
|
|
20188
21108
|
}
|
|
20189
|
-
parent = parent
|
|
21109
|
+
({ parent } = parent);
|
|
20190
21110
|
}
|
|
20191
21111
|
return false;
|
|
20192
21112
|
}
|
|
@@ -20203,10 +21123,10 @@ function resolveFunctionReference(identifier3, scope) {
|
|
|
20203
21123
|
return;
|
|
20204
21124
|
for (const definition of variable.defs) {
|
|
20205
21125
|
const { node } = definition;
|
|
20206
|
-
if (node.type ===
|
|
21126
|
+
if (node.type === TSESTree10.AST_NODE_TYPES.FunctionDeclaration) {
|
|
20207
21127
|
return node;
|
|
20208
21128
|
}
|
|
20209
|
-
if (node.type ===
|
|
21129
|
+
if (node.type === TSESTree10.AST_NODE_TYPES.VariableDeclarator && node.init && (node.init.type === TSESTree10.AST_NODE_TYPES.ArrowFunctionExpression || node.init.type === TSESTree10.AST_NODE_TYPES.FunctionExpression)) {
|
|
20210
21130
|
return node.init;
|
|
20211
21131
|
}
|
|
20212
21132
|
}
|
|
@@ -20216,7 +21136,7 @@ function collectCaptures(node, sourceCode) {
|
|
|
20216
21136
|
const captures = new Array;
|
|
20217
21137
|
const captureSet = new Set;
|
|
20218
21138
|
function visit(current) {
|
|
20219
|
-
if (current.type ===
|
|
21139
|
+
if (current.type === TSESTree10.AST_NODE_TYPES.Identifier) {
|
|
20220
21140
|
const { name } = current;
|
|
20221
21141
|
if (captureSet.has(name) || GLOBAL_BUILTINS.has(name) || isInTypePosition(current))
|
|
20222
21142
|
return;
|
|
@@ -20258,21 +21178,21 @@ function collectCaptures(node, sourceCode) {
|
|
|
20258
21178
|
}
|
|
20259
21179
|
}
|
|
20260
21180
|
}
|
|
20261
|
-
if (current.type ===
|
|
21181
|
+
if (current.type === TSESTree10.AST_NODE_TYPES.TSSatisfiesExpression || current.type === TSESTree10.AST_NODE_TYPES.TSAsExpression || current.type === TSESTree10.AST_NODE_TYPES.TSTypeAssertion || current.type === TSESTree10.AST_NODE_TYPES.TSNonNullExpression) {
|
|
20262
21182
|
visit(current.expression);
|
|
20263
21183
|
return;
|
|
20264
21184
|
}
|
|
20265
|
-
if (current.type ===
|
|
21185
|
+
if (current.type === TSESTree10.AST_NODE_TYPES.MemberExpression) {
|
|
20266
21186
|
visit(current.object);
|
|
20267
21187
|
if (current.computed)
|
|
20268
21188
|
visit(current.property);
|
|
20269
21189
|
return;
|
|
20270
21190
|
}
|
|
20271
|
-
if (current.type ===
|
|
21191
|
+
if (current.type === TSESTree10.AST_NODE_TYPES.ChainExpression) {
|
|
20272
21192
|
visit(current.expression);
|
|
20273
21193
|
return;
|
|
20274
21194
|
}
|
|
20275
|
-
if (current.type ===
|
|
21195
|
+
if (current.type === TSESTree10.AST_NODE_TYPES.Property) {
|
|
20276
21196
|
if (current.computed)
|
|
20277
21197
|
visit(current.key);
|
|
20278
21198
|
visit(current.value);
|
|
@@ -20297,7 +21217,7 @@ function parseDependencies(node, sourceCode) {
|
|
|
20297
21217
|
for (const element of node.elements) {
|
|
20298
21218
|
if (!element)
|
|
20299
21219
|
continue;
|
|
20300
|
-
const actualNode = element.type ===
|
|
21220
|
+
const actualNode = element.type === TSESTree10.AST_NODE_TYPES.SpreadElement ? element.argument : element;
|
|
20301
21221
|
const name = nodeToDependencyString(actualNode, sourceCode);
|
|
20302
21222
|
const depth = getMemberExpressionDepth(actualNode);
|
|
20303
21223
|
dependencies4.push({
|
|
@@ -20362,7 +21282,7 @@ var useExhaustiveDependencies = {
|
|
|
20362
21282
|
return {
|
|
20363
21283
|
CallExpression(node) {
|
|
20364
21284
|
const callNode = node;
|
|
20365
|
-
const hookName =
|
|
21285
|
+
const hookName = getHookName4(callNode);
|
|
20366
21286
|
if (hookName === undefined || hookName === "")
|
|
20367
21287
|
return;
|
|
20368
21288
|
const hookConfig = hookConfigs.get(hookName);
|
|
@@ -20374,9 +21294,9 @@ var useExhaustiveDependencies = {
|
|
|
20374
21294
|
if (closureArgument === undefined)
|
|
20375
21295
|
return;
|
|
20376
21296
|
let closureFunction;
|
|
20377
|
-
if (closureArgument.type ===
|
|
21297
|
+
if (closureArgument.type === TSESTree10.AST_NODE_TYPES.ArrowFunctionExpression || closureArgument.type === TSESTree10.AST_NODE_TYPES.FunctionExpression) {
|
|
20378
21298
|
closureFunction = closureArgument;
|
|
20379
|
-
} else if (closureArgument.type ===
|
|
21299
|
+
} else if (closureArgument.type === TSESTree10.AST_NODE_TYPES.Identifier) {
|
|
20380
21300
|
const scope = getScope(callNode);
|
|
20381
21301
|
closureFunction = resolveFunctionReference(closureArgument, scope);
|
|
20382
21302
|
}
|
|
@@ -20410,7 +21330,7 @@ var useExhaustiveDependencies = {
|
|
|
20410
21330
|
}
|
|
20411
21331
|
if (!dependenciesArgument)
|
|
20412
21332
|
return;
|
|
20413
|
-
if (dependenciesArgument.type !==
|
|
21333
|
+
if (dependenciesArgument.type !== TSESTree10.AST_NODE_TYPES.ArrayExpression)
|
|
20414
21334
|
return;
|
|
20415
21335
|
const dependenciesArray = dependenciesArgument;
|
|
20416
21336
|
const captures = collectCaptures(closureFunction, context.sourceCode);
|
|
@@ -20491,7 +21411,7 @@ var useExhaustiveDependencies = {
|
|
|
20491
21411
|
context.report({
|
|
20492
21412
|
data: { name: firstMissing.usagePath },
|
|
20493
21413
|
messageId: "missingDependency",
|
|
20494
|
-
node: lastDependency?.node
|
|
21414
|
+
node: lastDependency?.node ?? dependenciesArray,
|
|
20495
21415
|
suggest: [
|
|
20496
21416
|
{
|
|
20497
21417
|
desc: `Add '${firstMissing.usagePath}' to dependencies array`,
|
|
@@ -20506,7 +21426,7 @@ var useExhaustiveDependencies = {
|
|
|
20506
21426
|
context.report({
|
|
20507
21427
|
data: { names: missingNames },
|
|
20508
21428
|
messageId: "missingDependencies",
|
|
20509
|
-
node: lastDependency?.node
|
|
21429
|
+
node: lastDependency?.node ?? dependenciesArray,
|
|
20510
21430
|
suggest: [
|
|
20511
21431
|
{
|
|
20512
21432
|
desc: "Add missing dependencies to array",
|
|
@@ -20620,33 +21540,33 @@ var useExhaustiveDependencies = {
|
|
|
20620
21540
|
var use_exhaustive_dependencies_default = useExhaustiveDependencies;
|
|
20621
21541
|
|
|
20622
21542
|
// src/rules/use-hook-at-top-level.ts
|
|
20623
|
-
import { TSESTree as
|
|
21543
|
+
import { TSESTree as TSESTree11 } from "@typescript-eslint/types";
|
|
20624
21544
|
var HOOK_NAME_PATTERN = /^use[A-Z]/;
|
|
20625
|
-
var
|
|
21545
|
+
var COMPONENT_NAME_PATTERN2 = /^[A-Z]/;
|
|
20626
21546
|
function isReactHook(name) {
|
|
20627
21547
|
return HOOK_NAME_PATTERN.test(name);
|
|
20628
21548
|
}
|
|
20629
21549
|
function isComponent(name) {
|
|
20630
|
-
return
|
|
21550
|
+
return COMPONENT_NAME_PATTERN2.test(name);
|
|
20631
21551
|
}
|
|
20632
21552
|
function isComponentOrHook(node) {
|
|
20633
|
-
if (node.type ===
|
|
21553
|
+
if (node.type === TSESTree11.AST_NODE_TYPES.FunctionDeclaration && node.id) {
|
|
20634
21554
|
const { name } = node.id;
|
|
20635
21555
|
return isComponent(name) || isReactHook(name);
|
|
20636
21556
|
}
|
|
20637
|
-
if (node.type ===
|
|
21557
|
+
if (node.type === TSESTree11.AST_NODE_TYPES.FunctionExpression || node.type === TSESTree11.AST_NODE_TYPES.ArrowFunctionExpression) {
|
|
20638
21558
|
const { parent } = node;
|
|
20639
21559
|
if (!parent)
|
|
20640
21560
|
return false;
|
|
20641
|
-
if (parent.type ===
|
|
21561
|
+
if (parent.type === TSESTree11.AST_NODE_TYPES.VariableDeclarator && parent.id.type === TSESTree11.AST_NODE_TYPES.Identifier) {
|
|
20642
21562
|
const { name } = parent.id;
|
|
20643
21563
|
return isComponent(name) || isReactHook(name);
|
|
20644
21564
|
}
|
|
20645
|
-
if (parent.type ===
|
|
21565
|
+
if (parent.type === TSESTree11.AST_NODE_TYPES.Property && parent.key.type === TSESTree11.AST_NODE_TYPES.Identifier) {
|
|
20646
21566
|
const { name } = parent.key;
|
|
20647
21567
|
return isComponent(name) || isReactHook(name);
|
|
20648
21568
|
}
|
|
20649
|
-
if (parent.type ===
|
|
21569
|
+
if (parent.type === TSESTree11.AST_NODE_TYPES.MethodDefinition && parent.key.type === TSESTree11.AST_NODE_TYPES.Identifier) {
|
|
20650
21570
|
const { name } = parent.key;
|
|
20651
21571
|
return isComponent(name) || isReactHook(name);
|
|
20652
21572
|
}
|
|
@@ -20655,24 +21575,24 @@ function isComponentOrHook(node) {
|
|
|
20655
21575
|
}
|
|
20656
21576
|
function isHookCall(node) {
|
|
20657
21577
|
const { callee } = node;
|
|
20658
|
-
if (callee.type ===
|
|
21578
|
+
if (callee.type === TSESTree11.AST_NODE_TYPES.Identifier)
|
|
20659
21579
|
return isReactHook(callee.name);
|
|
20660
|
-
if (callee.type ===
|
|
21580
|
+
if (callee.type === TSESTree11.AST_NODE_TYPES.MemberExpression && callee.property.type === TSESTree11.AST_NODE_TYPES.Identifier)
|
|
20661
21581
|
return isReactHook(callee.property.name);
|
|
20662
21582
|
return false;
|
|
20663
21583
|
}
|
|
20664
|
-
var
|
|
20665
|
-
|
|
20666
|
-
|
|
20667
|
-
|
|
21584
|
+
var FUNCTION_BOUNDARIES2 = new Set([
|
|
21585
|
+
TSESTree11.AST_NODE_TYPES.FunctionDeclaration,
|
|
21586
|
+
TSESTree11.AST_NODE_TYPES.FunctionExpression,
|
|
21587
|
+
TSESTree11.AST_NODE_TYPES.ArrowFunctionExpression
|
|
20668
21588
|
]);
|
|
20669
21589
|
function isInFinallyBlock(node) {
|
|
20670
21590
|
let current = node.parent;
|
|
20671
21591
|
const maxDepth = 20;
|
|
20672
21592
|
for (let depth = 0;depth < maxDepth && current; depth += 1) {
|
|
20673
|
-
if (
|
|
21593
|
+
if (FUNCTION_BOUNDARIES2.has(current.type))
|
|
20674
21594
|
return false;
|
|
20675
|
-
if (current.type ===
|
|
21595
|
+
if (current.type === TSESTree11.AST_NODE_TYPES.TryStatement) {
|
|
20676
21596
|
let checkNode = node;
|
|
20677
21597
|
while (checkNode && checkNode !== current) {
|
|
20678
21598
|
if (checkNode === current.finalizer)
|
|
@@ -20695,7 +21615,7 @@ function isRecursiveCall(node, functionName) {
|
|
|
20695
21615
|
}
|
|
20696
21616
|
var useHookAtTopLevel = {
|
|
20697
21617
|
create(context) {
|
|
20698
|
-
const configuration = context.options[0]
|
|
21618
|
+
const configuration = context.options[0] ?? {};
|
|
20699
21619
|
const contextStack = new Array;
|
|
20700
21620
|
let currentFunctionName;
|
|
20701
21621
|
const importSourceMap = new Map;
|
|
@@ -20720,14 +21640,14 @@ var useHookAtTopLevel = {
|
|
|
20720
21640
|
if (ignoreHooks?.includes(hookName))
|
|
20721
21641
|
return true;
|
|
20722
21642
|
if (importSources && Object.keys(importSources).length > 0) {
|
|
20723
|
-
if (node.callee.type ===
|
|
20724
|
-
const objectName = node.callee.object.type ===
|
|
21643
|
+
if (node.callee.type === TSESTree11.AST_NODE_TYPES.MemberExpression) {
|
|
21644
|
+
const objectName = node.callee.object.type === TSESTree11.AST_NODE_TYPES.Identifier ? node.callee.object.name : undefined;
|
|
20725
21645
|
if (objectName && importSources[objectName] === false)
|
|
20726
21646
|
return true;
|
|
20727
21647
|
if (objectName && importSources[objectName] === true)
|
|
20728
21648
|
return false;
|
|
20729
21649
|
}
|
|
20730
|
-
if (node.callee.type ===
|
|
21650
|
+
if (node.callee.type === TSESTree11.AST_NODE_TYPES.Identifier) {
|
|
20731
21651
|
const importSource = importSourceMap.get(hookName);
|
|
20732
21652
|
if (importSource && importSources[importSource] === false)
|
|
20733
21653
|
return true;
|
|
@@ -20742,7 +21662,7 @@ var useHookAtTopLevel = {
|
|
|
20742
21662
|
const current = getCurrentContext();
|
|
20743
21663
|
const depth = current ? current.functionDepth + 1 : 0;
|
|
20744
21664
|
const isComponentOrHookFlag = isComponentOrHook(functionNode);
|
|
20745
|
-
if (functionNode.type ===
|
|
21665
|
+
if (functionNode.type === TSESTree11.AST_NODE_TYPES.FunctionDeclaration && functionNode.id)
|
|
20746
21666
|
currentFunctionName = functionNode.id.name;
|
|
20747
21667
|
if (current?.isComponentOrHook) {
|
|
20748
21668
|
pushContext({
|
|
@@ -20780,13 +21700,13 @@ var useHookAtTopLevel = {
|
|
|
20780
21700
|
if (!isHookCall(callNode))
|
|
20781
21701
|
return;
|
|
20782
21702
|
const { callee } = callNode;
|
|
20783
|
-
const hookName = callee.type ===
|
|
21703
|
+
const hookName = callee.type === TSESTree11.AST_NODE_TYPES.Identifier ? callee.name : callee.type === TSESTree11.AST_NODE_TYPES.MemberExpression && callee.property.type === TSESTree11.AST_NODE_TYPES.Identifier ? callee.property.name : undefined;
|
|
20784
21704
|
if (!hookName || shouldIgnoreHook(hookName, callNode))
|
|
20785
21705
|
return;
|
|
20786
21706
|
const current = getCurrentContext();
|
|
20787
21707
|
if (!current)
|
|
20788
21708
|
return;
|
|
20789
|
-
if (!current.isComponentOrHook
|
|
21709
|
+
if (!(current.isComponentOrHook || current.inNestedFunction))
|
|
20790
21710
|
return;
|
|
20791
21711
|
if (isInFinallyBlock(callNode))
|
|
20792
21712
|
return;
|
|
@@ -20878,10 +21798,10 @@ var useHookAtTopLevel = {
|
|
|
20878
21798
|
if (!configuration.importSources || Object.keys(configuration.importSources).length === 0)
|
|
20879
21799
|
return;
|
|
20880
21800
|
for (const specifier of importNode.specifiers) {
|
|
20881
|
-
if (specifier.type !==
|
|
21801
|
+
if (specifier.type !== TSESTree11.AST_NODE_TYPES.ImportSpecifier)
|
|
20882
21802
|
continue;
|
|
20883
21803
|
const { imported } = specifier;
|
|
20884
|
-
if (imported.type !==
|
|
21804
|
+
if (imported.type !== TSESTree11.AST_NODE_TYPES.Identifier)
|
|
20885
21805
|
continue;
|
|
20886
21806
|
if (isReactHook(imported.name))
|
|
20887
21807
|
importSourceMap.set(specifier.local.name, source);
|
|
@@ -20958,7 +21878,7 @@ var useHookAtTopLevel = {
|
|
|
20958
21878
|
};
|
|
20959
21879
|
var use_hook_at_top_level_default = useHookAtTopLevel;
|
|
20960
21880
|
|
|
20961
|
-
// src/configure-utilities.ts
|
|
21881
|
+
// src/utilities/configure-utilities.ts
|
|
20962
21882
|
function createPairConfiguration(opener, closer, options3 = {}) {
|
|
20963
21883
|
return { closer, opener, ...options3 };
|
|
20964
21884
|
}
|
|
@@ -21017,6 +21937,19 @@ function createReactKeysOptions(options3 = {}) {
|
|
|
21017
21937
|
...options3
|
|
21018
21938
|
};
|
|
21019
21939
|
}
|
|
21940
|
+
function createNoGodComponentsOptions(options3 = {}) {
|
|
21941
|
+
return {
|
|
21942
|
+
enforceTargetLines: true,
|
|
21943
|
+
ignoreComponents: [],
|
|
21944
|
+
maxDestructuredProps: 5,
|
|
21945
|
+
maxLines: 200,
|
|
21946
|
+
maxStateHooks: 5,
|
|
21947
|
+
maxTsxNesting: 3,
|
|
21948
|
+
stateHooks: ["useState", "useReducer", "useBinding"],
|
|
21949
|
+
targetLines: 120,
|
|
21950
|
+
...options3
|
|
21951
|
+
};
|
|
21952
|
+
}
|
|
21020
21953
|
function createUseExhaustiveDependenciesOptions(options3 = {}) {
|
|
21021
21954
|
return {
|
|
21022
21955
|
hooks: [],
|
|
@@ -21047,9 +21980,12 @@ var rules = {
|
|
|
21047
21980
|
"ban-instances": ban_instances_default,
|
|
21048
21981
|
"ban-react-fc": ban_react_fc_default,
|
|
21049
21982
|
"enforce-ianitor-check-type": enforce_ianitor_check_type_default,
|
|
21983
|
+
"fast-format": fast_format_default,
|
|
21050
21984
|
"no-async-constructor": no_async_constructor_default,
|
|
21051
21985
|
"no-color3-constructor": no_color3_constructor_default,
|
|
21052
21986
|
"no-commented-code": no_commented_code_default,
|
|
21987
|
+
"no-god-components": no_god_components_default,
|
|
21988
|
+
"no-identity-map": no_identity_map_default,
|
|
21053
21989
|
"no-instance-methods-without-this": no_instance_methods_without_this_default,
|
|
21054
21990
|
"no-print": no_print_default,
|
|
21055
21991
|
"no-shorthand-names": no_shorthand_names_default,
|
|
@@ -21065,15 +22001,16 @@ var rules = {
|
|
|
21065
22001
|
};
|
|
21066
22002
|
var recommended = {
|
|
21067
22003
|
plugins: {
|
|
21068
|
-
"cease-nonsense": {
|
|
21069
|
-
rules
|
|
21070
|
-
}
|
|
22004
|
+
"cease-nonsense": { rules }
|
|
21071
22005
|
},
|
|
21072
22006
|
rules: {
|
|
21073
22007
|
"cease-nonsense/ban-react-fc": "error",
|
|
21074
22008
|
"cease-nonsense/enforce-ianitor-check-type": "error",
|
|
22009
|
+
"cease-nonsense/fast-format": "error",
|
|
21075
22010
|
"cease-nonsense/no-async-constructor": "error",
|
|
21076
22011
|
"cease-nonsense/no-color3-constructor": "error",
|
|
22012
|
+
"cease-nonsense/no-god-components": "error",
|
|
22013
|
+
"cease-nonsense/no-identity-map": "error",
|
|
21077
22014
|
"cease-nonsense/no-instance-methods-without-this": "error",
|
|
21078
22015
|
"cease-nonsense/no-print": "error",
|
|
21079
22016
|
"cease-nonsense/no-shorthand-names": "error",
|
|
@@ -21102,10 +22039,11 @@ export {
|
|
|
21102
22039
|
createNoUselessUseSpringOptions,
|
|
21103
22040
|
createNoShorthandOptions,
|
|
21104
22041
|
createNoInstanceMethodsOptions,
|
|
22042
|
+
createNoGodComponentsOptions,
|
|
21105
22043
|
createHookConfiguration,
|
|
21106
22044
|
createEffectFunctionOptions,
|
|
21107
22045
|
createComplexityConfiguration,
|
|
21108
22046
|
createBanInstancesOptions
|
|
21109
22047
|
};
|
|
21110
22048
|
|
|
21111
|
-
//# debugId=
|
|
22049
|
+
//# debugId=F65B81A39A5D507164756E2164756E21
|