@sarj/eslint-plugin 9.10.0 → 9.12.1
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 +15 -0
- package/dist/index.cjs +475 -338
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +8 -2
- package/dist/index.d.ts +8 -2
- package/dist/index.js +470 -333
- package/dist/index.js.map +1 -1
- package/package.json +9 -2
package/dist/index.js
CHANGED
|
@@ -641,6 +641,7 @@ var CODE_KEYWORD_RE = /^(import |export |const |let |var |function\b|class |inte
|
|
|
641
641
|
var CODE_TAIL_RE = /[;{}()]\s*$|=>\s*$|,\s*$/;
|
|
642
642
|
var ASSIGN_RE = /^[A-Za-z_$][\w.$[\]]*\s*(?:=(?![=>])|\+=|-=|\*=)\s*\S.*[;)}\]]\s*$/;
|
|
643
643
|
var CALL_RE = /^[A-Za-z_$][\w.$]*\([^)]*\)\s*;?\s*$/;
|
|
644
|
+
var ASSERTION_CODE_RE = /^(?:await\s+)?(?:expect(?:TypeOf)?\s*\(.+\)\s*(?:\.\w+(?:<[^\n]*>)?)+(?:\s*\(.*\))?|assert(?:\.\w+)?\s*\(.+\))\s*;?\s*$/;
|
|
644
645
|
var PSEUDOCODE_RE = /%\w+%|\[opt\]|(?:^|\s)<[A-Za-z]\w*>|…|\.\.\./;
|
|
645
646
|
function stripCommentMarker(line) {
|
|
646
647
|
return line.replace(/^\s*\/{1,2}/, "").replace(/^\s*\*+/, "").trim();
|
|
@@ -659,6 +660,7 @@ function looksLikeCode(text, allowCall = true) {
|
|
|
659
660
|
if (!t) return false;
|
|
660
661
|
if (CODE_KEYWORD_RE.test(t) && CODE_TAIL_RE.test(t)) return true;
|
|
661
662
|
if (ASSIGN_RE.test(t)) return true;
|
|
663
|
+
if (ASSERTION_CODE_RE.test(t)) return true;
|
|
662
664
|
return allowCall && CALL_RE.test(t);
|
|
663
665
|
}
|
|
664
666
|
function hasPseudocode(text) {
|
|
@@ -6706,8 +6708,141 @@ var prefer_input_group_search_default = createRule({
|
|
|
6706
6708
|
}
|
|
6707
6709
|
});
|
|
6708
6710
|
|
|
6709
|
-
// src/rules/prefer-
|
|
6711
|
+
// src/rules/prefer-shadcn-primitives.ts
|
|
6710
6712
|
import { AST_NODE_TYPES as AST_NODE_TYPES35 } from "@typescript-eslint/utils";
|
|
6713
|
+
var SHADCN_PRIMITIVES = {
|
|
6714
|
+
button: "Button",
|
|
6715
|
+
dialog: "Dialog or AlertDialog family",
|
|
6716
|
+
input: "Input",
|
|
6717
|
+
label: "Label",
|
|
6718
|
+
progress: "Progress",
|
|
6719
|
+
select: "Select family",
|
|
6720
|
+
table: "Table family",
|
|
6721
|
+
textarea: "Textarea"
|
|
6722
|
+
};
|
|
6723
|
+
var LABELABLE_ELEMENTS = /* @__PURE__ */ new Set([
|
|
6724
|
+
"button",
|
|
6725
|
+
"input",
|
|
6726
|
+
"meter",
|
|
6727
|
+
"output",
|
|
6728
|
+
"progress",
|
|
6729
|
+
"select",
|
|
6730
|
+
"textarea"
|
|
6731
|
+
]);
|
|
6732
|
+
function rawElementName(node) {
|
|
6733
|
+
if (node.name.type !== AST_NODE_TYPES35.JSXIdentifier) return null;
|
|
6734
|
+
const name = node.name.name;
|
|
6735
|
+
return Object.hasOwn(SHADCN_PRIMITIVES, name) ? name : null;
|
|
6736
|
+
}
|
|
6737
|
+
function staticExpressionString(expression) {
|
|
6738
|
+
if (expression.type === AST_NODE_TYPES35.Literal) {
|
|
6739
|
+
return typeof expression.value === "string" ? expression.value : null;
|
|
6740
|
+
}
|
|
6741
|
+
if (expression.type === AST_NODE_TYPES35.TemplateLiteral) {
|
|
6742
|
+
let value = expression.quasis[0]?.value.cooked ?? "";
|
|
6743
|
+
for (const [index, substitution] of expression.expressions.entries()) {
|
|
6744
|
+
const staticSubstitution = staticExpressionString(substitution);
|
|
6745
|
+
if (staticSubstitution === null) return null;
|
|
6746
|
+
value += staticSubstitution;
|
|
6747
|
+
value += expression.quasis[index + 1]?.value.cooked ?? "";
|
|
6748
|
+
}
|
|
6749
|
+
return value;
|
|
6750
|
+
}
|
|
6751
|
+
if (expression.type === AST_NODE_TYPES35.TSAsExpression || expression.type === AST_NODE_TYPES35.TSNonNullExpression || expression.type === AST_NODE_TYPES35.TSSatisfiesExpression || expression.type === AST_NODE_TYPES35.TSTypeAssertion) {
|
|
6752
|
+
return staticExpressionString(expression.expression);
|
|
6753
|
+
}
|
|
6754
|
+
return null;
|
|
6755
|
+
}
|
|
6756
|
+
function staticString(value) {
|
|
6757
|
+
if (value?.type === AST_NODE_TYPES35.Literal) {
|
|
6758
|
+
return typeof value.value === "string" ? value.value : null;
|
|
6759
|
+
}
|
|
6760
|
+
if (value?.type !== AST_NODE_TYPES35.JSXExpressionContainer) return null;
|
|
6761
|
+
return staticExpressionString(value.expression);
|
|
6762
|
+
}
|
|
6763
|
+
function effectiveAttribute(node, attributeName) {
|
|
6764
|
+
for (const attribute of node.attributes.toReversed()) {
|
|
6765
|
+
if (attribute.type === AST_NODE_TYPES35.JSXSpreadAttribute) {
|
|
6766
|
+
return { kind: "unknown" };
|
|
6767
|
+
}
|
|
6768
|
+
if (attribute.name.type !== AST_NODE_TYPES35.JSXIdentifier || attribute.name.name !== attributeName) {
|
|
6769
|
+
continue;
|
|
6770
|
+
}
|
|
6771
|
+
const value = staticString(attribute.value);
|
|
6772
|
+
return value === null ? { kind: "unknown" } : { kind: "known", value };
|
|
6773
|
+
}
|
|
6774
|
+
return { kind: "missing" };
|
|
6775
|
+
}
|
|
6776
|
+
function isLabelableElement(node) {
|
|
6777
|
+
if (node.openingElement.name.type !== AST_NODE_TYPES35.JSXIdentifier) {
|
|
6778
|
+
return false;
|
|
6779
|
+
}
|
|
6780
|
+
const name = node.openingElement.name.name;
|
|
6781
|
+
if (!LABELABLE_ELEMENTS.has(name)) return false;
|
|
6782
|
+
if (name !== "input") return true;
|
|
6783
|
+
const typeAttribute = effectiveAttribute(node.openingElement, "type");
|
|
6784
|
+
if (typeAttribute.kind === "unknown") return false;
|
|
6785
|
+
return !(typeAttribute.kind === "known" && typeAttribute.value.toLowerCase() === "hidden");
|
|
6786
|
+
}
|
|
6787
|
+
function containsLabelableElement(node) {
|
|
6788
|
+
return node.children.some((child) => {
|
|
6789
|
+
if (child.type === AST_NODE_TYPES35.JSXElement) {
|
|
6790
|
+
return isLabelableElement(child) || containsLabelableElement(child);
|
|
6791
|
+
}
|
|
6792
|
+
if (child.type === AST_NODE_TYPES35.JSXFragment) {
|
|
6793
|
+
return containsLabelableElement(child);
|
|
6794
|
+
}
|
|
6795
|
+
return false;
|
|
6796
|
+
});
|
|
6797
|
+
}
|
|
6798
|
+
function isStaticallyAssociatedLabel(node) {
|
|
6799
|
+
const htmlFor = effectiveAttribute(node, "htmlFor");
|
|
6800
|
+
if (htmlFor.kind === "known" && htmlFor.value.trim().length > 0) return true;
|
|
6801
|
+
return node.parent.type === AST_NODE_TYPES35.JSXElement && containsLabelableElement(node.parent);
|
|
6802
|
+
}
|
|
6803
|
+
function replacementFor(node, element) {
|
|
6804
|
+
if (element !== "input") return SHADCN_PRIMITIVES[element];
|
|
6805
|
+
const typeAttribute = effectiveAttribute(node, "type");
|
|
6806
|
+
if (typeAttribute.kind === "unknown") return null;
|
|
6807
|
+
const inputType = typeAttribute.kind === "known" ? typeAttribute.value.toLowerCase() : "text";
|
|
6808
|
+
if (inputType === "hidden" || inputType === "file") return null;
|
|
6809
|
+
if (inputType === "checkbox") return "Checkbox";
|
|
6810
|
+
if (inputType === "radio") return "RadioGroup family";
|
|
6811
|
+
return "Input";
|
|
6812
|
+
}
|
|
6813
|
+
var prefer_shadcn_primitives_default = createRule({
|
|
6814
|
+
name: "prefer-shadcn-primitives",
|
|
6815
|
+
meta: {
|
|
6816
|
+
type: "suggestion",
|
|
6817
|
+
docs: {
|
|
6818
|
+
description: "Require visible raw JSX controls to use the corresponding shared shadcn primitive."
|
|
6819
|
+
},
|
|
6820
|
+
schema: [],
|
|
6821
|
+
messages: {
|
|
6822
|
+
preferShadcnPrimitive: "Use the shared {{ replacement }} shadcn primitive instead of raw <{{ element }}> markup."
|
|
6823
|
+
}
|
|
6824
|
+
},
|
|
6825
|
+
defaultOptions: [],
|
|
6826
|
+
create(context) {
|
|
6827
|
+
return {
|
|
6828
|
+
JSXOpeningElement(node) {
|
|
6829
|
+
const element = rawElementName(node);
|
|
6830
|
+
if (element === null) return;
|
|
6831
|
+
if (element === "label" && !isStaticallyAssociatedLabel(node)) return;
|
|
6832
|
+
const replacement = replacementFor(node, element);
|
|
6833
|
+
if (replacement === null) return;
|
|
6834
|
+
context.report({
|
|
6835
|
+
node,
|
|
6836
|
+
messageId: "preferShadcnPrimitive",
|
|
6837
|
+
data: { element, replacement }
|
|
6838
|
+
});
|
|
6839
|
+
}
|
|
6840
|
+
};
|
|
6841
|
+
}
|
|
6842
|
+
});
|
|
6843
|
+
|
|
6844
|
+
// src/rules/prefer-module-level-constant.ts
|
|
6845
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES36 } from "@typescript-eslint/utils";
|
|
6711
6846
|
var DEFAULT_MIN_ELEMENTS = 3;
|
|
6712
6847
|
var MAX_LITERAL_DEPTH = 4;
|
|
6713
6848
|
var IGNORE_PATTERNS2 = [
|
|
@@ -6736,9 +6871,9 @@ var MUTATING_METHODS = /* @__PURE__ */ new Set([
|
|
|
6736
6871
|
"assign"
|
|
6737
6872
|
]);
|
|
6738
6873
|
var FUNCTION_TYPES5 = /* @__PURE__ */ new Set([
|
|
6739
|
-
|
|
6740
|
-
|
|
6741
|
-
|
|
6874
|
+
AST_NODE_TYPES36.FunctionDeclaration,
|
|
6875
|
+
AST_NODE_TYPES36.FunctionExpression,
|
|
6876
|
+
AST_NODE_TYPES36.ArrowFunctionExpression
|
|
6742
6877
|
]);
|
|
6743
6878
|
var COLLECTION_CONSTRUCTORS = /* @__PURE__ */ new Set(["Set", "Map"]);
|
|
6744
6879
|
function isIgnoredFile2(filename, sourceText) {
|
|
@@ -6751,14 +6886,14 @@ function isLocalFixtureFile(filename) {
|
|
|
6751
6886
|
return isTestFile(filename) || isStoryFile(filename);
|
|
6752
6887
|
}
|
|
6753
6888
|
function unwrap3(node) {
|
|
6754
|
-
if (node.type ===
|
|
6889
|
+
if (node.type === AST_NODE_TYPES36.TSAsExpression || node.type === AST_NODE_TYPES36.TSSatisfiesExpression || node.type === AST_NODE_TYPES36.TSNonNullExpression) {
|
|
6755
6890
|
return unwrap3(node.expression);
|
|
6756
6891
|
}
|
|
6757
6892
|
return node;
|
|
6758
6893
|
}
|
|
6759
6894
|
var HAS_STATEFUL_FLAG_RE = /[gy]/;
|
|
6760
6895
|
function isRegexLiteral(node) {
|
|
6761
|
-
return node.type ===
|
|
6896
|
+
return node.type === AST_NODE_TYPES36.Literal && "regex" in node && node.regex !== void 0;
|
|
6762
6897
|
}
|
|
6763
6898
|
function isLiteralOnly(node, depth) {
|
|
6764
6899
|
if (depth > MAX_LITERAL_DEPTH) {
|
|
@@ -6766,29 +6901,29 @@ function isLiteralOnly(node, depth) {
|
|
|
6766
6901
|
}
|
|
6767
6902
|
const inner = unwrap3(node);
|
|
6768
6903
|
switch (inner.type) {
|
|
6769
|
-
case
|
|
6904
|
+
case AST_NODE_TYPES36.Literal: {
|
|
6770
6905
|
return !(isRegexLiteral(inner) && HAS_STATEFUL_FLAG_RE.test(inner.regex.flags));
|
|
6771
6906
|
}
|
|
6772
|
-
case
|
|
6907
|
+
case AST_NODE_TYPES36.TemplateLiteral: {
|
|
6773
6908
|
return inner.expressions.length === 0;
|
|
6774
6909
|
}
|
|
6775
|
-
case
|
|
6776
|
-
return (inner.operator === "-" || inner.operator === "+") && inner.argument.type ===
|
|
6910
|
+
case AST_NODE_TYPES36.UnaryExpression: {
|
|
6911
|
+
return (inner.operator === "-" || inner.operator === "+") && inner.argument.type === AST_NODE_TYPES36.Literal && typeof inner.argument.value === "number";
|
|
6777
6912
|
}
|
|
6778
|
-
case
|
|
6913
|
+
case AST_NODE_TYPES36.ArrayExpression: {
|
|
6779
6914
|
return inner.elements.every(
|
|
6780
|
-
(el) => el !== null && el.type !==
|
|
6915
|
+
(el) => el !== null && el.type !== AST_NODE_TYPES36.SpreadElement && isLiteralOnly(el, depth + 1)
|
|
6781
6916
|
);
|
|
6782
6917
|
}
|
|
6783
|
-
case
|
|
6918
|
+
case AST_NODE_TYPES36.ObjectExpression: {
|
|
6784
6919
|
return inner.properties.every((prop) => {
|
|
6785
|
-
if (prop.type !==
|
|
6920
|
+
if (prop.type !== AST_NODE_TYPES36.Property) {
|
|
6786
6921
|
return false;
|
|
6787
6922
|
}
|
|
6788
6923
|
if (prop.shorthand || prop.method || prop.kind !== "init") {
|
|
6789
6924
|
return false;
|
|
6790
6925
|
}
|
|
6791
|
-
if (prop.computed && prop.key.type !==
|
|
6926
|
+
if (prop.computed && prop.key.type !== AST_NODE_TYPES36.Literal) {
|
|
6792
6927
|
return false;
|
|
6793
6928
|
}
|
|
6794
6929
|
return isLiteralOnly(prop.value, depth + 1);
|
|
@@ -6801,7 +6936,7 @@ function isLiteralOnly(node, depth) {
|
|
|
6801
6936
|
}
|
|
6802
6937
|
function unwrapObjectFreeze(node) {
|
|
6803
6938
|
const inner = unwrap3(node);
|
|
6804
|
-
if (inner.type ===
|
|
6939
|
+
if (inner.type === AST_NODE_TYPES36.CallExpression && inner.callee.type === AST_NODE_TYPES36.MemberExpression && !inner.callee.computed && inner.callee.object.type === AST_NODE_TYPES36.Identifier && inner.callee.object.name === "Object" && inner.callee.property.type === AST_NODE_TYPES36.Identifier && inner.callee.property.name === "freeze" && inner.arguments.length === 1 && inner.arguments[0] !== void 0 && inner.arguments[0].type !== AST_NODE_TYPES36.SpreadElement) {
|
|
6805
6940
|
return unwrap3(inner.arguments[0]);
|
|
6806
6941
|
}
|
|
6807
6942
|
return inner;
|
|
@@ -6817,19 +6952,19 @@ function classify(init, checkRegex) {
|
|
|
6817
6952
|
}
|
|
6818
6953
|
return { kind: "regex", size: 1 };
|
|
6819
6954
|
}
|
|
6820
|
-
if (node.type ===
|
|
6955
|
+
if (node.type === AST_NODE_TYPES36.ArrayExpression) {
|
|
6821
6956
|
return isLiteralOnly(node, 0) ? { kind: "array", size: node.elements.length } : null;
|
|
6822
6957
|
}
|
|
6823
|
-
if (node.type ===
|
|
6958
|
+
if (node.type === AST_NODE_TYPES36.ObjectExpression) {
|
|
6824
6959
|
return isLiteralOnly(node, 0) ? { kind: "object", size: node.properties.length } : null;
|
|
6825
6960
|
}
|
|
6826
|
-
if (node.type ===
|
|
6961
|
+
if (node.type === AST_NODE_TYPES36.NewExpression && node.callee.type === AST_NODE_TYPES36.Identifier && COLLECTION_CONSTRUCTORS.has(node.callee.name)) {
|
|
6827
6962
|
const arg = node.arguments[0];
|
|
6828
|
-
if (node.arguments.length !== 1 || arg === void 0 || arg.type ===
|
|
6963
|
+
if (node.arguments.length !== 1 || arg === void 0 || arg.type === AST_NODE_TYPES36.SpreadElement) {
|
|
6829
6964
|
return null;
|
|
6830
6965
|
}
|
|
6831
6966
|
const entries = unwrap3(arg);
|
|
6832
|
-
if (entries.type !==
|
|
6967
|
+
if (entries.type !== AST_NODE_TYPES36.ArrayExpression) {
|
|
6833
6968
|
return null;
|
|
6834
6969
|
}
|
|
6835
6970
|
return isLiteralOnly(entries, 0) ? { kind: node.callee.name === "Set" ? "Set" : "Map", size: entries.elements.length } : null;
|
|
@@ -6858,10 +6993,10 @@ var NON_RETAINING_BUILTINS = /* @__PURE__ */ new Map(
|
|
|
6858
6993
|
);
|
|
6859
6994
|
function isNonRetainingBuiltinCall(node, argument) {
|
|
6860
6995
|
const callee = node.callee;
|
|
6861
|
-
if (callee.type ===
|
|
6996
|
+
if (callee.type === AST_NODE_TYPES36.Identifier && callee.name === "structuredClone") {
|
|
6862
6997
|
return true;
|
|
6863
6998
|
}
|
|
6864
|
-
if (callee.type !==
|
|
6999
|
+
if (callee.type !== AST_NODE_TYPES36.MemberExpression || callee.computed || callee.object.type !== AST_NODE_TYPES36.Identifier || callee.property.type !== AST_NODE_TYPES36.Identifier) {
|
|
6865
7000
|
return false;
|
|
6866
7001
|
}
|
|
6867
7002
|
const members = NON_RETAINING_BUILTINS.get(callee.object.name);
|
|
@@ -6875,38 +7010,38 @@ function isNonRetainingBuiltinCall(node, argument) {
|
|
|
6875
7010
|
}
|
|
6876
7011
|
function isSafeRead(identifier) {
|
|
6877
7012
|
const parent = identifier.parent;
|
|
6878
|
-
if (parent.type ===
|
|
7013
|
+
if (parent.type === AST_NODE_TYPES36.MemberExpression) {
|
|
6879
7014
|
if (parent.object !== identifier) {
|
|
6880
7015
|
return true;
|
|
6881
7016
|
}
|
|
6882
7017
|
const grandparent = parent.parent;
|
|
6883
|
-
if (grandparent.type ===
|
|
7018
|
+
if (grandparent.type === AST_NODE_TYPES36.AssignmentExpression && grandparent.left === parent) {
|
|
6884
7019
|
return false;
|
|
6885
7020
|
}
|
|
6886
|
-
if (grandparent.type ===
|
|
7021
|
+
if (grandparent.type === AST_NODE_TYPES36.UpdateExpression) {
|
|
6887
7022
|
return false;
|
|
6888
7023
|
}
|
|
6889
|
-
if (grandparent.type ===
|
|
7024
|
+
if (grandparent.type === AST_NODE_TYPES36.UnaryExpression && grandparent.operator === "delete") {
|
|
6890
7025
|
return false;
|
|
6891
7026
|
}
|
|
6892
|
-
if (!parent.computed && parent.property.type ===
|
|
7027
|
+
if (!parent.computed && parent.property.type === AST_NODE_TYPES36.Identifier && MUTATING_METHODS.has(parent.property.name) && grandparent.type === AST_NODE_TYPES36.CallExpression && grandparent.callee === parent) {
|
|
6893
7028
|
return false;
|
|
6894
7029
|
}
|
|
6895
7030
|
return true;
|
|
6896
7031
|
}
|
|
6897
|
-
if (parent.type ===
|
|
7032
|
+
if (parent.type === AST_NODE_TYPES36.ForOfStatement && parent.right === identifier) {
|
|
6898
7033
|
return true;
|
|
6899
7034
|
}
|
|
6900
|
-
if (parent.type ===
|
|
7035
|
+
if (parent.type === AST_NODE_TYPES36.SpreadElement) {
|
|
6901
7036
|
return true;
|
|
6902
7037
|
}
|
|
6903
|
-
if (parent.type ===
|
|
7038
|
+
if (parent.type === AST_NODE_TYPES36.BinaryExpression) {
|
|
6904
7039
|
return true;
|
|
6905
7040
|
}
|
|
6906
|
-
if (parent.type ===
|
|
7041
|
+
if (parent.type === AST_NODE_TYPES36.CallExpression && parent.arguments.includes(identifier) && isNonRetainingBuiltinCall(parent, identifier)) {
|
|
6907
7042
|
return true;
|
|
6908
7043
|
}
|
|
6909
|
-
if (parent.type ===
|
|
7044
|
+
if (parent.type === AST_NODE_TYPES36.UnaryExpression && parent.operator !== "delete") {
|
|
6910
7045
|
return true;
|
|
6911
7046
|
}
|
|
6912
7047
|
return false;
|
|
@@ -6961,7 +7096,7 @@ var prefer_module_level_constant_default = createRule({
|
|
|
6961
7096
|
if (reference.isWrite()) {
|
|
6962
7097
|
return false;
|
|
6963
7098
|
}
|
|
6964
|
-
if (reference.identifier.type !==
|
|
7099
|
+
if (reference.identifier.type !== AST_NODE_TYPES36.Identifier) {
|
|
6965
7100
|
return false;
|
|
6966
7101
|
}
|
|
6967
7102
|
if (!isSafeRead(reference.identifier)) {
|
|
@@ -6973,10 +7108,10 @@ var prefer_module_level_constant_default = createRule({
|
|
|
6973
7108
|
return {
|
|
6974
7109
|
VariableDeclarator(node) {
|
|
6975
7110
|
const declaration = node.parent;
|
|
6976
|
-
if (declaration.type !==
|
|
7111
|
+
if (declaration.type !== AST_NODE_TYPES36.VariableDeclaration || declaration.kind !== "const" || declaration.declare === true) {
|
|
6977
7112
|
return;
|
|
6978
7113
|
}
|
|
6979
|
-
if (node.id.type !==
|
|
7114
|
+
if (node.id.type !== AST_NODE_TYPES36.Identifier || node.init === null) {
|
|
6980
7115
|
return;
|
|
6981
7116
|
}
|
|
6982
7117
|
if (enclosingFunction2(node) === null) {
|
|
@@ -7003,7 +7138,7 @@ var prefer_module_level_constant_default = createRule({
|
|
|
7003
7138
|
});
|
|
7004
7139
|
|
|
7005
7140
|
// src/rules/prefer-module-level-schema.ts
|
|
7006
|
-
import { AST_NODE_TYPES as
|
|
7141
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES37 } from "@typescript-eslint/utils";
|
|
7007
7142
|
|
|
7008
7143
|
// src/rules/_zod.ts
|
|
7009
7144
|
var ZOD_PREFIX_RE = /^Z[A-Z]/;
|
|
@@ -7069,9 +7204,9 @@ var I18N_RECEIVER_NAMES = /* @__PURE__ */ new Set([
|
|
|
7069
7204
|
"intl"
|
|
7070
7205
|
]);
|
|
7071
7206
|
var FUNCTION_TYPES6 = /* @__PURE__ */ new Set([
|
|
7072
|
-
|
|
7073
|
-
|
|
7074
|
-
|
|
7207
|
+
AST_NODE_TYPES37.ArrowFunctionExpression,
|
|
7208
|
+
AST_NODE_TYPES37.FunctionDeclaration,
|
|
7209
|
+
AST_NODE_TYPES37.FunctionExpression
|
|
7075
7210
|
]);
|
|
7076
7211
|
function schemaExpression(node) {
|
|
7077
7212
|
let current = node;
|
|
@@ -7080,10 +7215,10 @@ function schemaExpression(node) {
|
|
|
7080
7215
|
if (parent === void 0) {
|
|
7081
7216
|
return current;
|
|
7082
7217
|
}
|
|
7083
|
-
if (parent.type ===
|
|
7218
|
+
if (parent.type === AST_NODE_TYPES37.MemberExpression && parent.object === current && !parent.computed && parent.property.type === AST_NODE_TYPES37.Identifier && TERMINAL_METHODS.has(parent.property.name)) {
|
|
7084
7219
|
return current;
|
|
7085
7220
|
}
|
|
7086
|
-
if (parent.type ===
|
|
7221
|
+
if (parent.type === AST_NODE_TYPES37.MemberExpression && parent.object === current || parent.type === AST_NODE_TYPES37.CallExpression && parent.callee === current || parent.type === AST_NODE_TYPES37.TSAsExpression && parent.expression === current || parent.type === AST_NODE_TYPES37.TSNonNullExpression && parent.expression === current) {
|
|
7087
7222
|
current = parent;
|
|
7088
7223
|
continue;
|
|
7089
7224
|
}
|
|
@@ -7134,22 +7269,22 @@ function subtreeSome(root, predicate) {
|
|
|
7134
7269
|
function readsReceiver(node) {
|
|
7135
7270
|
return subtreeSome(
|
|
7136
7271
|
node,
|
|
7137
|
-
(inner) => inner.type ===
|
|
7272
|
+
(inner) => inner.type === AST_NODE_TYPES37.ThisExpression || inner.type === AST_NODE_TYPES37.Super || inner.type === AST_NODE_TYPES37.Identifier && inner.name === "arguments"
|
|
7138
7273
|
);
|
|
7139
7274
|
}
|
|
7140
7275
|
function buildsLocalizedText(node) {
|
|
7141
7276
|
return subtreeSome(node, (inner) => {
|
|
7142
|
-
if (inner.type ===
|
|
7277
|
+
if (inner.type === AST_NODE_TYPES37.TaggedTemplateExpression) {
|
|
7143
7278
|
return true;
|
|
7144
7279
|
}
|
|
7145
|
-
if (inner.type !==
|
|
7280
|
+
if (inner.type !== AST_NODE_TYPES37.CallExpression) {
|
|
7146
7281
|
return false;
|
|
7147
7282
|
}
|
|
7148
7283
|
const { callee } = inner;
|
|
7149
|
-
if (callee.type ===
|
|
7284
|
+
if (callee.type === AST_NODE_TYPES37.Identifier) {
|
|
7150
7285
|
return I18N_CALLEE_NAMES.has(callee.name);
|
|
7151
7286
|
}
|
|
7152
|
-
return callee.type ===
|
|
7287
|
+
return callee.type === AST_NODE_TYPES37.MemberExpression && !callee.computed && callee.object.type === AST_NODE_TYPES37.Identifier && I18N_RECEIVER_NAMES.has(callee.object.name);
|
|
7153
7288
|
});
|
|
7154
7289
|
}
|
|
7155
7290
|
function collectReferences(scope, out) {
|
|
@@ -7206,15 +7341,15 @@ var prefer_module_level_schema_default = createRule({
|
|
|
7206
7341
|
}
|
|
7207
7342
|
const zodNamespaces = /* @__PURE__ */ new Set();
|
|
7208
7343
|
function isZodCall(node) {
|
|
7209
|
-
return node.type ===
|
|
7344
|
+
return node.type === AST_NODE_TYPES37.CallExpression && node.callee.type === AST_NODE_TYPES37.MemberExpression && !node.callee.computed && node.callee.object.type === AST_NODE_TYPES37.Identifier && zodNamespaces.has(node.callee.object.name);
|
|
7210
7345
|
}
|
|
7211
7346
|
function isCovered(node) {
|
|
7212
7347
|
let current = node.parent ?? void 0;
|
|
7213
7348
|
while (current !== void 0) {
|
|
7214
|
-
if (current !== node && isZodCall(current) && current.callee.type ===
|
|
7349
|
+
if (current !== node && isZodCall(current) && current.callee.type === AST_NODE_TYPES37.MemberExpression && current.callee.property.type === AST_NODE_TYPES37.Identifier && factories.has(current.callee.property.name)) {
|
|
7215
7350
|
return true;
|
|
7216
7351
|
}
|
|
7217
|
-
if (current.type ===
|
|
7352
|
+
if (current.type === AST_NODE_TYPES37.CallExpression && (current.callee.type === AST_NODE_TYPES37.Identifier && MEMO_CALLEES.has(current.callee.name) || current.callee.type === AST_NODE_TYPES37.MemberExpression && !current.callee.computed && current.callee.property.type === AST_NODE_TYPES37.Identifier && MEMO_CALLEES.has(current.callee.property.name))) {
|
|
7218
7353
|
return true;
|
|
7219
7354
|
}
|
|
7220
7355
|
current = current.parent ?? void 0;
|
|
@@ -7229,11 +7364,11 @@ var prefer_module_level_schema_default = createRule({
|
|
|
7229
7364
|
if (parent === void 0) {
|
|
7230
7365
|
return confirmed;
|
|
7231
7366
|
}
|
|
7232
|
-
if (parent.type ===
|
|
7367
|
+
if (parent.type === AST_NODE_TYPES37.Property && parent.value === current || parent.type === AST_NODE_TYPES37.ObjectExpression || parent.type === AST_NODE_TYPES37.ArrayExpression) {
|
|
7233
7368
|
current = parent;
|
|
7234
7369
|
continue;
|
|
7235
7370
|
}
|
|
7236
|
-
if (parent.type ===
|
|
7371
|
+
if (parent.type === AST_NODE_TYPES37.CallExpression && parent.arguments.includes(current) && isSchemaComposition(parent)) {
|
|
7237
7372
|
current = schemaExpression(parent);
|
|
7238
7373
|
confirmed = current;
|
|
7239
7374
|
continue;
|
|
@@ -7243,7 +7378,7 @@ var prefer_module_level_schema_default = createRule({
|
|
|
7243
7378
|
}
|
|
7244
7379
|
function isSchemaComposition(node) {
|
|
7245
7380
|
const { callee } = node;
|
|
7246
|
-
const isCombinator = callee.type ===
|
|
7381
|
+
const isCombinator = callee.type === AST_NODE_TYPES37.MemberExpression && !callee.computed && callee.property.type === AST_NODE_TYPES37.Identifier && ZOD_COMBINATOR_METHODS.has(callee.property.name);
|
|
7247
7382
|
return isCombinator || isZodCall(node);
|
|
7248
7383
|
}
|
|
7249
7384
|
function closesOverNothing(node, enclosing) {
|
|
@@ -7277,13 +7412,13 @@ var prefer_module_level_schema_default = createRule({
|
|
|
7277
7412
|
}
|
|
7278
7413
|
function ownerName(enclosing) {
|
|
7279
7414
|
const parent = enclosing.parent ?? void 0;
|
|
7280
|
-
if (enclosing.type ===
|
|
7415
|
+
if (enclosing.type === AST_NODE_TYPES37.FunctionDeclaration && enclosing.id !== null) {
|
|
7281
7416
|
return enclosing.id.name;
|
|
7282
7417
|
}
|
|
7283
|
-
if (parent !== void 0 && parent.type ===
|
|
7418
|
+
if (parent !== void 0 && parent.type === AST_NODE_TYPES37.VariableDeclarator && parent.id.type === AST_NODE_TYPES37.Identifier) {
|
|
7284
7419
|
return parent.id.name;
|
|
7285
7420
|
}
|
|
7286
|
-
if (parent !== void 0 && (parent.type ===
|
|
7421
|
+
if (parent !== void 0 && (parent.type === AST_NODE_TYPES37.MethodDefinition || parent.type === AST_NODE_TYPES37.Property) && parent.key.type === AST_NODE_TYPES37.Identifier) {
|
|
7287
7422
|
return parent.key.name;
|
|
7288
7423
|
}
|
|
7289
7424
|
return "this function";
|
|
@@ -7294,7 +7429,7 @@ var prefer_module_level_schema_default = createRule({
|
|
|
7294
7429
|
return;
|
|
7295
7430
|
}
|
|
7296
7431
|
for (const specifier of node.specifiers) {
|
|
7297
|
-
if (specifier.type ===
|
|
7432
|
+
if (specifier.type === AST_NODE_TYPES37.ImportNamespaceSpecifier || specifier.type === AST_NODE_TYPES37.ImportDefaultSpecifier || specifier.type === AST_NODE_TYPES37.ImportSpecifier && specifier.imported.type === AST_NODE_TYPES37.Identifier && specifier.imported.name === "z") {
|
|
7298
7433
|
zodNamespaces.add(specifier.local.name);
|
|
7299
7434
|
}
|
|
7300
7435
|
}
|
|
@@ -7304,7 +7439,7 @@ var prefer_module_level_schema_default = createRule({
|
|
|
7304
7439
|
return;
|
|
7305
7440
|
}
|
|
7306
7441
|
const callee = node.callee;
|
|
7307
|
-
if (callee.property.type !==
|
|
7442
|
+
if (callee.property.type !== AST_NODE_TYPES37.Identifier) {
|
|
7308
7443
|
return;
|
|
7309
7444
|
}
|
|
7310
7445
|
const factory = callee.property.name;
|
|
@@ -7319,7 +7454,7 @@ var prefer_module_level_schema_default = createRule({
|
|
|
7319
7454
|
return;
|
|
7320
7455
|
}
|
|
7321
7456
|
const shape = node.arguments[0];
|
|
7322
|
-
if (shape !== void 0 && shape.type ===
|
|
7457
|
+
if (shape !== void 0 && shape.type === AST_NODE_TYPES37.ObjectExpression && shape.properties.length < minProperties) {
|
|
7323
7458
|
return;
|
|
7324
7459
|
}
|
|
7325
7460
|
const expression = schemaExpression(node);
|
|
@@ -7347,9 +7482,9 @@ var prefer_module_level_schema_default = createRule({
|
|
|
7347
7482
|
});
|
|
7348
7483
|
|
|
7349
7484
|
// src/rules/prefer-native-random-uuid.ts
|
|
7350
|
-
import { AST_NODE_TYPES as
|
|
7485
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES38, ASTUtils as ASTUtils3 } from "@typescript-eslint/utils";
|
|
7351
7486
|
function requireUuid(node) {
|
|
7352
|
-
return node?.type ===
|
|
7487
|
+
return node?.type === AST_NODE_TYPES38.CallExpression && node.callee.type === AST_NODE_TYPES38.Identifier && node.callee.name === "require" && node.arguments.length === 1 && node.arguments[0]?.type === AST_NODE_TYPES38.Literal && node.arguments[0].value === "uuid";
|
|
7353
7488
|
}
|
|
7354
7489
|
var prefer_native_random_uuid_default = createRule({
|
|
7355
7490
|
name: "prefer-native-random-uuid",
|
|
@@ -7392,37 +7527,37 @@ var prefer_native_random_uuid_default = createRule({
|
|
|
7392
7527
|
ImportDeclaration(node) {
|
|
7393
7528
|
if (node.source.value !== "uuid") return;
|
|
7394
7529
|
for (const specifier of node.specifiers) {
|
|
7395
|
-
if (specifier.type ===
|
|
7530
|
+
if (specifier.type === AST_NODE_TYPES38.ImportSpecifier && (specifier.imported.type === AST_NODE_TYPES38.Identifier ? specifier.imported.name === "v4" : specifier.imported.value === "v4")) {
|
|
7396
7531
|
record(specifier.local, directBindings);
|
|
7397
|
-
} else if (specifier.type ===
|
|
7532
|
+
} else if (specifier.type === AST_NODE_TYPES38.ImportNamespaceSpecifier) {
|
|
7398
7533
|
record(specifier.local, namespaceBindings);
|
|
7399
7534
|
}
|
|
7400
7535
|
}
|
|
7401
7536
|
},
|
|
7402
7537
|
VariableDeclarator(node) {
|
|
7403
7538
|
if (node.parent.kind !== "const" || !requireUuid(node.init)) return;
|
|
7404
|
-
if (node.init?.type !==
|
|
7539
|
+
if (node.init?.type !== AST_NODE_TYPES38.CallExpression || node.init.callee.type !== AST_NODE_TYPES38.Identifier || (resolve(node.init.callee)?.defs.length ?? 0) > 0) {
|
|
7405
7540
|
return;
|
|
7406
7541
|
}
|
|
7407
|
-
if (node.id.type ===
|
|
7542
|
+
if (node.id.type === AST_NODE_TYPES38.Identifier) {
|
|
7408
7543
|
record(node.id, namespaceBindings);
|
|
7409
7544
|
return;
|
|
7410
7545
|
}
|
|
7411
|
-
if (node.id.type !==
|
|
7546
|
+
if (node.id.type !== AST_NODE_TYPES38.ObjectPattern) return;
|
|
7412
7547
|
for (const property of node.id.properties) {
|
|
7413
|
-
if (property.type ===
|
|
7548
|
+
if (property.type === AST_NODE_TYPES38.Property && !property.computed && (property.key.type === AST_NODE_TYPES38.Identifier && property.key.name === "v4" || property.key.type === AST_NODE_TYPES38.Literal && property.key.value === "v4") && property.value.type === AST_NODE_TYPES38.Identifier) {
|
|
7414
7549
|
record(property.value, directBindings);
|
|
7415
7550
|
}
|
|
7416
7551
|
}
|
|
7417
7552
|
},
|
|
7418
7553
|
"CallExpression:exit"(node) {
|
|
7419
7554
|
if (node.arguments.length !== 0) return;
|
|
7420
|
-
if (node.callee.type ===
|
|
7555
|
+
if (node.callee.type === AST_NODE_TYPES38.Identifier) {
|
|
7421
7556
|
const variable2 = resolve(node.callee);
|
|
7422
7557
|
if (variable2 !== null && directBindings.has(variable2)) report(node);
|
|
7423
7558
|
return;
|
|
7424
7559
|
}
|
|
7425
|
-
if (node.callee.type !==
|
|
7560
|
+
if (node.callee.type !== AST_NODE_TYPES38.MemberExpression || node.callee.computed || node.callee.object.type !== AST_NODE_TYPES38.Identifier || node.callee.property.type !== AST_NODE_TYPES38.Identifier || node.callee.property.name !== "v4") {
|
|
7426
7561
|
return;
|
|
7427
7562
|
}
|
|
7428
7563
|
const variable = resolve(node.callee.object);
|
|
@@ -7433,20 +7568,20 @@ var prefer_native_random_uuid_default = createRule({
|
|
|
7433
7568
|
});
|
|
7434
7569
|
|
|
7435
7570
|
// src/rules/prefer-non-nullable-collection.ts
|
|
7436
|
-
import { AST_NODE_TYPES as
|
|
7571
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES39 } from "@typescript-eslint/utils";
|
|
7437
7572
|
var ARRAY_TYPE_NAMES = /* @__PURE__ */ new Set(["Array", "ReadonlyArray"]);
|
|
7438
7573
|
function propertyName(node) {
|
|
7439
7574
|
const key = node.key;
|
|
7440
|
-
if (key.type ===
|
|
7441
|
-
if (key.type ===
|
|
7575
|
+
if (key.type === AST_NODE_TYPES39.Identifier) return key.name;
|
|
7576
|
+
if (key.type === AST_NODE_TYPES39.Literal) return String(key.value);
|
|
7442
7577
|
return "collection";
|
|
7443
7578
|
}
|
|
7444
7579
|
function isArrayType(node) {
|
|
7445
|
-
if (node.type ===
|
|
7446
|
-
return node.type ===
|
|
7580
|
+
if (node.type === AST_NODE_TYPES39.TSArrayType) return true;
|
|
7581
|
+
return node.type === AST_NODE_TYPES39.TSTypeReference && node.typeName.type === AST_NODE_TYPES39.Identifier && ARRAY_TYPE_NAMES.has(node.typeName.name);
|
|
7447
7582
|
}
|
|
7448
7583
|
function isNullishType(node) {
|
|
7449
|
-
return node.type ===
|
|
7584
|
+
return node.type === AST_NODE_TYPES39.TSNullKeyword || node.type === AST_NODE_TYPES39.TSUndefinedKeyword;
|
|
7450
7585
|
}
|
|
7451
7586
|
function isNullableArrayOnly(node) {
|
|
7452
7587
|
const values = node.types.filter((member) => !isNullishType(member));
|
|
@@ -7474,7 +7609,7 @@ var prefer_non_nullable_collection_default = createRule({
|
|
|
7474
7609
|
if (node.optional) return;
|
|
7475
7610
|
const annotation = node.typeAnnotation?.typeAnnotation;
|
|
7476
7611
|
if (annotation === void 0) return;
|
|
7477
|
-
if (annotation.type !==
|
|
7612
|
+
if (annotation.type !== AST_NODE_TYPES39.TSUnionType || !isNullableArrayOnly(annotation)) {
|
|
7478
7613
|
return;
|
|
7479
7614
|
}
|
|
7480
7615
|
context.report({
|
|
@@ -7487,7 +7622,7 @@ var prefer_non_nullable_collection_default = createRule({
|
|
|
7487
7622
|
TSPropertySignature: checkOptionalProperty,
|
|
7488
7623
|
PropertyDefinition: checkOptionalProperty,
|
|
7489
7624
|
TSTypeAliasDeclaration(node) {
|
|
7490
|
-
if (node.typeAnnotation.type !==
|
|
7625
|
+
if (node.typeAnnotation.type !== AST_NODE_TYPES39.TSUnionType) return;
|
|
7491
7626
|
if (!isNullableArrayOnly(node.typeAnnotation)) return;
|
|
7492
7627
|
context.report({
|
|
7493
7628
|
node,
|
|
@@ -7500,13 +7635,13 @@ var prefer_non_nullable_collection_default = createRule({
|
|
|
7500
7635
|
});
|
|
7501
7636
|
|
|
7502
7637
|
// src/rules/prefer-schema-for-api-payload.ts
|
|
7503
|
-
import { AST_NODE_TYPES as
|
|
7638
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES40 } from "@typescript-eslint/utils";
|
|
7504
7639
|
var unwrap4 = (node) => {
|
|
7505
7640
|
let current = node;
|
|
7506
7641
|
while (current !== null && current !== void 0) {
|
|
7507
|
-
if (current.type ===
|
|
7642
|
+
if (current.type === AST_NODE_TYPES40.TSAsExpression || current.type === AST_NODE_TYPES40.TSTypeAssertion || current.type === AST_NODE_TYPES40.TSNonNullExpression || current.type === AST_NODE_TYPES40.TSSatisfiesExpression) {
|
|
7508
7643
|
current = current.expression;
|
|
7509
|
-
} else if (current.type ===
|
|
7644
|
+
} else if (current.type === AST_NODE_TYPES40.ChainExpression) {
|
|
7510
7645
|
current = current.expression;
|
|
7511
7646
|
} else {
|
|
7512
7647
|
break;
|
|
@@ -7521,23 +7656,23 @@ var PROMISE_CHAIN_METHODS = /* @__PURE__ */ new Set([
|
|
|
7521
7656
|
]);
|
|
7522
7657
|
var isSchemaParseReference = (node) => {
|
|
7523
7658
|
const inner = unwrap4(node);
|
|
7524
|
-
return inner !== null && inner.type ===
|
|
7659
|
+
return inner !== null && inner.type === AST_NODE_TYPES40.MemberExpression && !inner.computed && inner.property.type === AST_NODE_TYPES40.Identifier && (inner.property.name === "parse" || inner.property.name === "safeParse");
|
|
7525
7660
|
};
|
|
7526
7661
|
var isRawPayloadSource = (node) => {
|
|
7527
7662
|
let current = unwrap4(node);
|
|
7528
7663
|
if (current === null) return false;
|
|
7529
|
-
if (current.type ===
|
|
7664
|
+
if (current.type === AST_NODE_TYPES40.AwaitExpression) {
|
|
7530
7665
|
current = unwrap4(current.argument);
|
|
7531
7666
|
}
|
|
7532
|
-
if (current === null || current.type !==
|
|
7667
|
+
if (current === null || current.type !== AST_NODE_TYPES40.CallExpression) {
|
|
7533
7668
|
return false;
|
|
7534
7669
|
}
|
|
7535
7670
|
const callee = unwrap4(current.callee);
|
|
7536
|
-
if (callee === null || callee.type !==
|
|
7671
|
+
if (callee === null || callee.type !== AST_NODE_TYPES40.MemberExpression) {
|
|
7537
7672
|
return false;
|
|
7538
7673
|
}
|
|
7539
7674
|
const property = unwrap4(callee.property);
|
|
7540
|
-
if (property === null || property.type !==
|
|
7675
|
+
if (property === null || property.type !== AST_NODE_TYPES40.Identifier) {
|
|
7541
7676
|
return false;
|
|
7542
7677
|
}
|
|
7543
7678
|
if (property.name === "json") {
|
|
@@ -7547,16 +7682,16 @@ var isRawPayloadSource = (node) => {
|
|
|
7547
7682
|
return !current.arguments.some(isSchemaParseReference) && isRawPayloadSource(callee.object);
|
|
7548
7683
|
}
|
|
7549
7684
|
const object = unwrap4(callee.object);
|
|
7550
|
-
return property.name === "parse" && object !== null && object.type ===
|
|
7685
|
+
return property.name === "parse" && object !== null && object.type === AST_NODE_TYPES40.Identifier && object.name === "JSON" && !isLocalFileRead(current.arguments[0]);
|
|
7551
7686
|
};
|
|
7552
7687
|
var FILE_READ_RE = /^(readFile|readFileSync|readJson|readJsonSync|readJSON)$/;
|
|
7553
7688
|
var isLocalFileRead = (node) => {
|
|
7554
7689
|
let found = false;
|
|
7555
7690
|
const visit = (current) => {
|
|
7556
7691
|
if (found || current === null || current === void 0) return;
|
|
7557
|
-
if (current.type ===
|
|
7692
|
+
if (current.type === AST_NODE_TYPES40.CallExpression) {
|
|
7558
7693
|
const callee = unwrap4(current.callee);
|
|
7559
|
-
const name = callee?.type ===
|
|
7694
|
+
const name = callee?.type === AST_NODE_TYPES40.Identifier ? callee.name : callee?.type === AST_NODE_TYPES40.MemberExpression && !callee.computed && callee.property.type === AST_NODE_TYPES40.Identifier ? callee.property.name : null;
|
|
7560
7695
|
if (name !== null && FILE_READ_RE.test(name)) {
|
|
7561
7696
|
found = true;
|
|
7562
7697
|
return;
|
|
@@ -7578,15 +7713,15 @@ var isLocalFileRead = (node) => {
|
|
|
7578
7713
|
var ASSERTION_CALLEE_RE = /^(expect|assert|should|invariant)$/;
|
|
7579
7714
|
var isInsideAssertion = (node) => {
|
|
7580
7715
|
for (let current = node.parent; current !== void 0 && current !== null; current = current.parent) {
|
|
7581
|
-
if (current.type !==
|
|
7716
|
+
if (current.type !== AST_NODE_TYPES40.CallExpression) continue;
|
|
7582
7717
|
let callee = current.callee;
|
|
7583
|
-
while (callee.type ===
|
|
7718
|
+
while (callee.type === AST_NODE_TYPES40.MemberExpression) {
|
|
7584
7719
|
callee = callee.object;
|
|
7585
7720
|
}
|
|
7586
|
-
if (callee.type ===
|
|
7721
|
+
if (callee.type === AST_NODE_TYPES40.CallExpression) {
|
|
7587
7722
|
callee = callee.callee;
|
|
7588
7723
|
}
|
|
7589
|
-
if (callee.type ===
|
|
7724
|
+
if (callee.type === AST_NODE_TYPES40.Identifier && ASSERTION_CALLEE_RE.test(callee.name)) {
|
|
7590
7725
|
return true;
|
|
7591
7726
|
}
|
|
7592
7727
|
}
|
|
@@ -7605,39 +7740,39 @@ var GUARD_NAME_RE = /^(?:is|validate|parse|assert|decode|coerce)[A-Z]/;
|
|
|
7605
7740
|
var isValidationRead = (node) => {
|
|
7606
7741
|
let current = node;
|
|
7607
7742
|
let parent = current.parent;
|
|
7608
|
-
while (parent !== null && parent !== void 0 && (parent.type ===
|
|
7743
|
+
while (parent !== null && parent !== void 0 && (parent.type === AST_NODE_TYPES40.TSAsExpression || parent.type === AST_NODE_TYPES40.TSTypeAssertion || parent.type === AST_NODE_TYPES40.TSNonNullExpression || parent.type === AST_NODE_TYPES40.TSSatisfiesExpression || parent.type === AST_NODE_TYPES40.ChainExpression)) {
|
|
7609
7744
|
current = parent;
|
|
7610
7745
|
parent = parent.parent;
|
|
7611
7746
|
}
|
|
7612
7747
|
if (parent === null || parent === void 0) return false;
|
|
7613
|
-
if (parent.type ===
|
|
7748
|
+
if (parent.type === AST_NODE_TYPES40.UnaryExpression && parent.operator === "typeof" && parent.argument === current) {
|
|
7614
7749
|
return true;
|
|
7615
7750
|
}
|
|
7616
|
-
if (parent.type !==
|
|
7751
|
+
if (parent.type !== AST_NODE_TYPES40.CallExpression || !parent.arguments.some((arg) => arg === current)) {
|
|
7617
7752
|
return false;
|
|
7618
7753
|
}
|
|
7619
7754
|
const callee = parent.callee;
|
|
7620
|
-
if (callee.type ===
|
|
7755
|
+
if (callee.type === AST_NODE_TYPES40.MemberExpression && !callee.computed && callee.object.type === AST_NODE_TYPES40.Identifier && callee.object.name === "Array" && callee.property.type === AST_NODE_TYPES40.Identifier && callee.property.name === "isArray") {
|
|
7621
7756
|
return parent.arguments.length === 1;
|
|
7622
7757
|
}
|
|
7623
|
-
return callee.type ===
|
|
7758
|
+
return callee.type === AST_NODE_TYPES40.Identifier && GUARD_NAME_RE.test(callee.name);
|
|
7624
7759
|
};
|
|
7625
7760
|
var isGuardTestPosition = (node) => {
|
|
7626
7761
|
let current = node;
|
|
7627
7762
|
let parent = current.parent;
|
|
7628
7763
|
while (parent !== void 0 && parent !== null) {
|
|
7629
7764
|
switch (parent.type) {
|
|
7630
|
-
case
|
|
7631
|
-
case
|
|
7632
|
-
case
|
|
7765
|
+
case AST_NODE_TYPES40.UnaryExpression:
|
|
7766
|
+
case AST_NODE_TYPES40.LogicalExpression:
|
|
7767
|
+
case AST_NODE_TYPES40.ChainExpression:
|
|
7633
7768
|
current = parent;
|
|
7634
7769
|
parent = parent.parent;
|
|
7635
7770
|
continue;
|
|
7636
|
-
case
|
|
7637
|
-
case
|
|
7638
|
-
case
|
|
7639
|
-
case
|
|
7640
|
-
case
|
|
7771
|
+
case AST_NODE_TYPES40.IfStatement:
|
|
7772
|
+
case AST_NODE_TYPES40.ConditionalExpression:
|
|
7773
|
+
case AST_NODE_TYPES40.WhileStatement:
|
|
7774
|
+
case AST_NODE_TYPES40.DoWhileStatement:
|
|
7775
|
+
case AST_NODE_TYPES40.ForStatement:
|
|
7641
7776
|
return parent.test === current;
|
|
7642
7777
|
default:
|
|
7643
7778
|
return false;
|
|
@@ -7647,7 +7782,7 @@ var isGuardTestPosition = (node) => {
|
|
|
7647
7782
|
};
|
|
7648
7783
|
var isUnvalidatedVariableRef = (node, scope, tracked) => {
|
|
7649
7784
|
const unwrapped = unwrap4(node);
|
|
7650
|
-
if (unwrapped === null || unwrapped.type !==
|
|
7785
|
+
if (unwrapped === null || unwrapped.type !== AST_NODE_TYPES40.Identifier) {
|
|
7651
7786
|
return false;
|
|
7652
7787
|
}
|
|
7653
7788
|
const variable = findVariable2(scope, unwrapped.name);
|
|
@@ -7690,11 +7825,11 @@ var prefer_schema_for_api_payload_default = createRule({
|
|
|
7690
7825
|
return {
|
|
7691
7826
|
VariableDeclarator(node) {
|
|
7692
7827
|
const scope = context.sourceCode.getScope(node);
|
|
7693
|
-
if (node.id.type ===
|
|
7828
|
+
if (node.id.type === AST_NODE_TYPES40.Identifier) {
|
|
7694
7829
|
trackInitializer(node);
|
|
7695
7830
|
return;
|
|
7696
7831
|
}
|
|
7697
|
-
if (node.id.type ===
|
|
7832
|
+
if (node.id.type === AST_NODE_TYPES40.ObjectPattern || node.id.type === AST_NODE_TYPES40.ArrayPattern) {
|
|
7698
7833
|
if (isRawPayloadSource(node.init)) {
|
|
7699
7834
|
if (!isFullyNarrowedPattern(node)) {
|
|
7700
7835
|
context.report({ node: node.id, messageId: "unparsedJsonAccess" });
|
|
@@ -7708,7 +7843,7 @@ var prefer_schema_for_api_payload_default = createRule({
|
|
|
7708
7843
|
},
|
|
7709
7844
|
AssignmentExpression(node) {
|
|
7710
7845
|
const scope = context.sourceCode.getScope(node);
|
|
7711
|
-
if (node.left.type ===
|
|
7846
|
+
if (node.left.type === AST_NODE_TYPES40.Identifier) {
|
|
7712
7847
|
const variable = findVariable2(scope, node.left.name);
|
|
7713
7848
|
if (variable === null) return;
|
|
7714
7849
|
if (isRawPayloadSource(node.right)) {
|
|
@@ -7718,7 +7853,7 @@ var prefer_schema_for_api_payload_default = createRule({
|
|
|
7718
7853
|
}
|
|
7719
7854
|
return;
|
|
7720
7855
|
}
|
|
7721
|
-
if (node.left.type ===
|
|
7856
|
+
if (node.left.type === AST_NODE_TYPES40.ObjectPattern || node.left.type === AST_NODE_TYPES40.ArrayPattern) {
|
|
7722
7857
|
if (isRawPayloadSource(node.right)) {
|
|
7723
7858
|
context.report({
|
|
7724
7859
|
node: node.left,
|
|
@@ -7735,15 +7870,15 @@ var prefer_schema_for_api_payload_default = createRule({
|
|
|
7735
7870
|
}
|
|
7736
7871
|
},
|
|
7737
7872
|
CallExpression(node) {
|
|
7738
|
-
if (node.callee.type !==
|
|
7873
|
+
if (node.callee.type !== AST_NODE_TYPES40.Identifier) return;
|
|
7739
7874
|
if (!GUARD_NAME_RE.test(node.callee.name) && !isGuardTestPosition(node)) {
|
|
7740
7875
|
return;
|
|
7741
7876
|
}
|
|
7742
7877
|
const scope = context.sourceCode.getScope(node);
|
|
7743
7878
|
for (const arg of node.arguments) {
|
|
7744
|
-
if (arg.type ===
|
|
7879
|
+
if (arg.type === AST_NODE_TYPES40.SpreadElement) continue;
|
|
7745
7880
|
const unwrapped = unwrap4(arg);
|
|
7746
|
-
if (unwrapped === null || unwrapped.type !==
|
|
7881
|
+
if (unwrapped === null || unwrapped.type !== AST_NODE_TYPES40.Identifier) {
|
|
7747
7882
|
continue;
|
|
7748
7883
|
}
|
|
7749
7884
|
const variable = findVariable2(scope, unwrapped.name);
|
|
@@ -7757,13 +7892,13 @@ var prefer_schema_for_api_payload_default = createRule({
|
|
|
7757
7892
|
const obj = unwrap4(node.object);
|
|
7758
7893
|
if (isRawPayloadSource(obj)) {
|
|
7759
7894
|
const parent = node.parent;
|
|
7760
|
-
if (parent.type ===
|
|
7895
|
+
if (parent.type === AST_NODE_TYPES40.CallExpression && parent.callee === node && node.property.type === AST_NODE_TYPES40.Identifier && (node.property.name === "parse" || node.property.name === "safeParse" || PROMISE_CHAIN_METHODS.has(node.property.name))) {
|
|
7761
7896
|
return;
|
|
7762
7897
|
}
|
|
7763
7898
|
context.report({ node, messageId: "unparsedJsonAccess" });
|
|
7764
7899
|
return;
|
|
7765
7900
|
}
|
|
7766
|
-
if (obj !== null && obj.type ===
|
|
7901
|
+
if (obj !== null && obj.type === AST_NODE_TYPES40.Identifier && isUnvalidatedVariableRef(obj, scope, unvalidatedVariables)) {
|
|
7767
7902
|
context.report({ node, messageId: "unparsedJsonAccess" });
|
|
7768
7903
|
const variable = findVariable2(scope, obj.name);
|
|
7769
7904
|
if (variable !== null) {
|
|
@@ -7776,7 +7911,7 @@ var prefer_schema_for_api_payload_default = createRule({
|
|
|
7776
7911
|
});
|
|
7777
7912
|
|
|
7778
7913
|
// src/rules/prefer-semantic-colors.ts
|
|
7779
|
-
import { AST_NODE_TYPES as
|
|
7914
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES41 } from "@typescript-eslint/utils";
|
|
7780
7915
|
import { existsSync, readdirSync, readFileSync } from "fs";
|
|
7781
7916
|
import { dirname, join, parse } from "path";
|
|
7782
7917
|
|
|
@@ -7876,8 +8011,8 @@ var SVG_EXEMPT_COLOR_VALUES = /* @__PURE__ */ new Set([
|
|
|
7876
8011
|
]);
|
|
7877
8012
|
function jsxElementName(node) {
|
|
7878
8013
|
const name = node.openingElement.name;
|
|
7879
|
-
if (name.type ===
|
|
7880
|
-
if (name.type ===
|
|
8014
|
+
if (name.type === AST_NODE_TYPES41.JSXIdentifier) return name.name;
|
|
8015
|
+
if (name.type === AST_NODE_TYPES41.JSXMemberExpression && name.property.type === AST_NODE_TYPES41.JSXIdentifier) {
|
|
7881
8016
|
return name.property.name;
|
|
7882
8017
|
}
|
|
7883
8018
|
return null;
|
|
@@ -7903,7 +8038,7 @@ var EMAIL_OR_PDF_MODULE_RE = /^@react-(?:email|pdf)\//;
|
|
|
7903
8038
|
var isInsideSvg = (node) => {
|
|
7904
8039
|
let current = node.parent;
|
|
7905
8040
|
while (current !== void 0 && current !== null) {
|
|
7906
|
-
if (current.type ===
|
|
8041
|
+
if (current.type === AST_NODE_TYPES41.JSXElement) {
|
|
7907
8042
|
const name = jsxElementName(current);
|
|
7908
8043
|
if (name !== null && isSvgLikeElementName(name)) return true;
|
|
7909
8044
|
}
|
|
@@ -7914,7 +8049,7 @@ var isInsideSvg = (node) => {
|
|
|
7914
8049
|
var isInsideIconFactoryPath = (node) => {
|
|
7915
8050
|
let current = node.parent;
|
|
7916
8051
|
while (current !== void 0 && current !== null) {
|
|
7917
|
-
if (current.type ===
|
|
8052
|
+
if (current.type === AST_NODE_TYPES41.Property && propName(current.key) === "path" && current.parent.type === AST_NODE_TYPES41.ObjectExpression && current.parent.parent.type === AST_NODE_TYPES41.CallExpression && current.parent.parent.callee.type === AST_NODE_TYPES41.Identifier && current.parent.parent.callee.name === "createIcon") {
|
|
7918
8053
|
return true;
|
|
7919
8054
|
}
|
|
7920
8055
|
current = current.parent;
|
|
@@ -8051,12 +8186,12 @@ var hasSemanticTokenSystem = (filename) => {
|
|
|
8051
8186
|
return root !== null && workspaceHasMarker(root);
|
|
8052
8187
|
};
|
|
8053
8188
|
var propName = (key) => {
|
|
8054
|
-
if (key.type ===
|
|
8055
|
-
if (key.type ===
|
|
8189
|
+
if (key.type === AST_NODE_TYPES41.Identifier) return key.name;
|
|
8190
|
+
if (key.type === AST_NODE_TYPES41.Literal && typeof key.value === "string") return key.value;
|
|
8056
8191
|
return null;
|
|
8057
8192
|
};
|
|
8058
8193
|
var staticallyImportsEmailOrPdfRenderer = (program) => program.body.some((statement) => {
|
|
8059
|
-
if (statement.type !==
|
|
8194
|
+
if (statement.type !== AST_NODE_TYPES41.ImportDeclaration && statement.type !== AST_NODE_TYPES41.ExportNamedDeclaration && statement.type !== AST_NODE_TYPES41.ExportAllDeclaration) {
|
|
8060
8195
|
return false;
|
|
8061
8196
|
}
|
|
8062
8197
|
return statement.source !== null && typeof statement.source.value === "string" && EMAIL_OR_PDF_MODULE_RE.test(statement.source.value);
|
|
@@ -8108,27 +8243,27 @@ var prefer_semantic_colors_default = createRule({
|
|
|
8108
8243
|
const checkClassNode = (node) => {
|
|
8109
8244
|
if (node === null) return;
|
|
8110
8245
|
switch (node.type) {
|
|
8111
|
-
case
|
|
8246
|
+
case AST_NODE_TYPES41.Literal:
|
|
8112
8247
|
if (typeof node.value === "string") reportClasses(node.value, node);
|
|
8113
8248
|
break;
|
|
8114
|
-
case
|
|
8249
|
+
case AST_NODE_TYPES41.TemplateLiteral:
|
|
8115
8250
|
for (const quasi of node.quasis) reportClasses(quasi.value.cooked ?? "", quasi);
|
|
8116
8251
|
break;
|
|
8117
|
-
case
|
|
8252
|
+
case AST_NODE_TYPES41.ArrayExpression:
|
|
8118
8253
|
for (const element of node.elements) {
|
|
8119
|
-
if (element !== null && element.type !==
|
|
8254
|
+
if (element !== null && element.type !== AST_NODE_TYPES41.SpreadElement) checkClassNode(element);
|
|
8120
8255
|
}
|
|
8121
8256
|
break;
|
|
8122
|
-
case
|
|
8257
|
+
case AST_NODE_TYPES41.ObjectExpression:
|
|
8123
8258
|
for (const property of node.properties) {
|
|
8124
|
-
if (property.type ===
|
|
8259
|
+
if (property.type === AST_NODE_TYPES41.Property) checkClassNode(property.value);
|
|
8125
8260
|
}
|
|
8126
8261
|
break;
|
|
8127
|
-
case
|
|
8262
|
+
case AST_NODE_TYPES41.ConditionalExpression:
|
|
8128
8263
|
checkClassNode(node.consequent);
|
|
8129
8264
|
checkClassNode(node.alternate);
|
|
8130
8265
|
break;
|
|
8131
|
-
case
|
|
8266
|
+
case AST_NODE_TYPES41.LogicalExpression:
|
|
8132
8267
|
checkClassNode(node.right);
|
|
8133
8268
|
break;
|
|
8134
8269
|
default:
|
|
@@ -8136,32 +8271,32 @@ var prefer_semantic_colors_default = createRule({
|
|
|
8136
8271
|
}
|
|
8137
8272
|
};
|
|
8138
8273
|
const checkColorValueNode = (node) => {
|
|
8139
|
-
if (node.type ===
|
|
8274
|
+
if (node.type === AST_NODE_TYPES41.Literal && typeof node.value === "string" && RAW_COLOR_VALUE_RE.test(node.value) && !CSS_VAR_REFERENCE_RE.test(node.value)) {
|
|
8140
8275
|
report(node, "inlineColor", { value: node.value });
|
|
8141
8276
|
}
|
|
8142
8277
|
};
|
|
8143
8278
|
return {
|
|
8144
8279
|
"JSXAttribute[name.name='className']"(node) {
|
|
8145
8280
|
if (node.value === null) return;
|
|
8146
|
-
if (node.value.type ===
|
|
8147
|
-
else if (node.value.type ===
|
|
8148
|
-
if (node.value.expression.type !==
|
|
8281
|
+
if (node.value.type === AST_NODE_TYPES41.Literal) checkClassNode(node.value);
|
|
8282
|
+
else if (node.value.type === AST_NODE_TYPES41.JSXExpressionContainer) {
|
|
8283
|
+
if (node.value.expression.type !== AST_NODE_TYPES41.JSXEmptyExpression) {
|
|
8149
8284
|
checkClassNode(node.value.expression);
|
|
8150
8285
|
}
|
|
8151
8286
|
}
|
|
8152
8287
|
},
|
|
8153
8288
|
CallExpression(node) {
|
|
8154
|
-
if (node.callee.type ===
|
|
8289
|
+
if (node.callee.type === AST_NODE_TYPES41.Identifier && node.callee.name === "require" && node.arguments[0]?.type === AST_NODE_TYPES41.Literal && typeof node.arguments[0].value === "string" && EMAIL_OR_PDF_MODULE_RE.test(node.arguments[0].value)) {
|
|
8155
8290
|
importsEmailOrPdfRenderer = true;
|
|
8156
8291
|
}
|
|
8157
|
-
if (node.callee.type ===
|
|
8292
|
+
if (node.callee.type === AST_NODE_TYPES41.Identifier && CLASS_FNS.has(node.callee.name)) {
|
|
8158
8293
|
for (const arg of node.arguments) {
|
|
8159
|
-
if (arg.type !==
|
|
8294
|
+
if (arg.type !== AST_NODE_TYPES41.SpreadElement) checkClassNode(arg);
|
|
8160
8295
|
}
|
|
8161
8296
|
}
|
|
8162
8297
|
},
|
|
8163
8298
|
VariableDeclarator(node) {
|
|
8164
|
-
if (node.id.type ===
|
|
8299
|
+
if (node.id.type === AST_NODE_TYPES41.Identifier && CLASS_NAME_RE.test(node.id.name)) {
|
|
8165
8300
|
checkClassNode(node.init);
|
|
8166
8301
|
}
|
|
8167
8302
|
},
|
|
@@ -8171,9 +8306,9 @@ var prefer_semantic_colors_default = createRule({
|
|
|
8171
8306
|
},
|
|
8172
8307
|
// SVG artwork colors are exempt; component presentation colors still report.
|
|
8173
8308
|
"JSXAttribute[name.name=/^(fill|stroke|color)$/]"(node) {
|
|
8174
|
-
if (node.value?.type !==
|
|
8309
|
+
if (node.value?.type !== AST_NODE_TYPES41.Literal) return;
|
|
8175
8310
|
const owner = node.parent.name;
|
|
8176
|
-
if (owner.type ===
|
|
8311
|
+
if (owner.type === AST_NODE_TYPES41.JSXIdentifier && SVG_SHAPE_PRIMITIVES.has(owner.name)) {
|
|
8177
8312
|
return;
|
|
8178
8313
|
}
|
|
8179
8314
|
if (typeof node.value.value === "string" && SVG_EXEMPT_COLOR_VALUES.has(node.value.value.toLowerCase())) {
|
|
@@ -8187,7 +8322,7 @@ var prefer_semantic_colors_default = createRule({
|
|
|
8187
8322
|
if (name !== null && STYLE_COLOR_PROPS.has(name)) checkColorValueNode(node.value);
|
|
8188
8323
|
},
|
|
8189
8324
|
ImportExpression(node) {
|
|
8190
|
-
if (node.source.type ===
|
|
8325
|
+
if (node.source.type === AST_NODE_TYPES41.Literal && typeof node.source.value === "string" && EMAIL_OR_PDF_MODULE_RE.test(node.source.value)) {
|
|
8191
8326
|
importsEmailOrPdfRenderer = true;
|
|
8192
8327
|
}
|
|
8193
8328
|
},
|
|
@@ -8393,7 +8528,7 @@ var prefer_single_sentence_comment_default = createRule({
|
|
|
8393
8528
|
// src/rules/prefer-string-literal-union.ts
|
|
8394
8529
|
import {
|
|
8395
8530
|
ESLintUtils as ESLintUtils3,
|
|
8396
|
-
AST_NODE_TYPES as
|
|
8531
|
+
AST_NODE_TYPES as AST_NODE_TYPES42
|
|
8397
8532
|
} from "@typescript-eslint/utils";
|
|
8398
8533
|
import * as ts2 from "typescript";
|
|
8399
8534
|
var CHOICE_TOKENS = /* @__PURE__ */ new Set([
|
|
@@ -8437,19 +8572,19 @@ function isChoiceLikeName(name) {
|
|
|
8437
8572
|
return CHOICE_TOKENS.has(lastWord(name));
|
|
8438
8573
|
}
|
|
8439
8574
|
function keyName(key) {
|
|
8440
|
-
if (key.type ===
|
|
8575
|
+
if (key.type === AST_NODE_TYPES42.Identifier) {
|
|
8441
8576
|
return key.name;
|
|
8442
8577
|
}
|
|
8443
|
-
if (key.type ===
|
|
8578
|
+
if (key.type === AST_NODE_TYPES42.Literal && typeof key.value === "string") {
|
|
8444
8579
|
return key.value;
|
|
8445
8580
|
}
|
|
8446
8581
|
return null;
|
|
8447
8582
|
}
|
|
8448
8583
|
function isStringLiteralMember(t) {
|
|
8449
|
-
return t.type ===
|
|
8584
|
+
return t.type === AST_NODE_TYPES42.TSLiteralType && t.literal.type === AST_NODE_TYPES42.Literal && typeof t.literal.value === "string";
|
|
8450
8585
|
}
|
|
8451
8586
|
function isStringLiteralUnion(node) {
|
|
8452
|
-
if (node?.type !==
|
|
8587
|
+
if (node?.type !== AST_NODE_TYPES42.TSUnionType) {
|
|
8453
8588
|
return false;
|
|
8454
8589
|
}
|
|
8455
8590
|
return node.types.filter(isStringLiteralMember).length >= MIN_CLUSTER_SIZE;
|
|
@@ -8478,12 +8613,12 @@ function bindingSourceExpression(decl) {
|
|
|
8478
8613
|
return ts2.isForOfStatement(node) ? node.expression : node.initializer;
|
|
8479
8614
|
}
|
|
8480
8615
|
function refKey(node) {
|
|
8481
|
-
if (node.type ===
|
|
8616
|
+
if (node.type === AST_NODE_TYPES42.Identifier) {
|
|
8482
8617
|
return node.name;
|
|
8483
8618
|
}
|
|
8484
|
-
if (node.type ===
|
|
8619
|
+
if (node.type === AST_NODE_TYPES42.MemberExpression && !node.computed) {
|
|
8485
8620
|
const inner = refKey(node.object);
|
|
8486
|
-
if (inner === null || node.property.type !==
|
|
8621
|
+
if (inner === null || node.property.type !== AST_NODE_TYPES42.Identifier) {
|
|
8487
8622
|
return null;
|
|
8488
8623
|
}
|
|
8489
8624
|
return `${inner}.${node.property.name}`;
|
|
@@ -8491,7 +8626,7 @@ function refKey(node) {
|
|
|
8491
8626
|
return null;
|
|
8492
8627
|
}
|
|
8493
8628
|
function strLiteral(node) {
|
|
8494
|
-
if (node.type ===
|
|
8629
|
+
if (node.type === AST_NODE_TYPES42.Literal && typeof node.value === "string") {
|
|
8495
8630
|
return node.value;
|
|
8496
8631
|
}
|
|
8497
8632
|
return null;
|
|
@@ -8644,7 +8779,7 @@ var prefer_string_literal_union_default = createRule({
|
|
|
8644
8779
|
containersWithUnion.add(container);
|
|
8645
8780
|
return;
|
|
8646
8781
|
}
|
|
8647
|
-
if (typeNode?.type !==
|
|
8782
|
+
if (typeNode?.type !== AST_NODE_TYPES42.TSStringKeyword) {
|
|
8648
8783
|
return;
|
|
8649
8784
|
}
|
|
8650
8785
|
const name = keyName(key);
|
|
@@ -8732,10 +8867,10 @@ var prefer_string_literal_union_default = createRule({
|
|
|
8732
8867
|
}
|
|
8733
8868
|
};
|
|
8734
8869
|
function refKeyText(node) {
|
|
8735
|
-
if (node.type ===
|
|
8870
|
+
if (node.type === AST_NODE_TYPES42.BinaryExpression) {
|
|
8736
8871
|
return refKey(node.left) ?? refKey(node.right) ?? "value";
|
|
8737
8872
|
}
|
|
8738
|
-
if (node.type ===
|
|
8873
|
+
if (node.type === AST_NODE_TYPES42.SwitchStatement) {
|
|
8739
8874
|
return refKey(node.discriminant) ?? "value";
|
|
8740
8875
|
}
|
|
8741
8876
|
return "value";
|
|
@@ -8744,7 +8879,7 @@ var prefer_string_literal_union_default = createRule({
|
|
|
8744
8879
|
});
|
|
8745
8880
|
|
|
8746
8881
|
// src/rules/prefer-whole-object-assertion.ts
|
|
8747
|
-
import { AST_NODE_TYPES as
|
|
8882
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES43 } from "@typescript-eslint/utils";
|
|
8748
8883
|
var MERGEABLE_MATCHERS = /* @__PURE__ */ new Set(["toBe", "toEqual", "toStrictEqual"]);
|
|
8749
8884
|
var ARRAY_MATCHERS = /* @__PURE__ */ new Set(["toEqual", "toStrictEqual"]);
|
|
8750
8885
|
var COLLECTION_PROPERTIES = /* @__PURE__ */ new Set(["length", "size"]);
|
|
@@ -8753,11 +8888,11 @@ var NUMERIC_SIGNS2 = /* @__PURE__ */ new Set(["-", "+"]);
|
|
|
8753
8888
|
var MIN_RUN_LENGTH = 2;
|
|
8754
8889
|
function literalText(node, getText) {
|
|
8755
8890
|
switch (node.type) {
|
|
8756
|
-
case
|
|
8891
|
+
case AST_NODE_TYPES43.Literal:
|
|
8757
8892
|
return "regex" in node ? null : getText(node);
|
|
8758
|
-
case
|
|
8893
|
+
case AST_NODE_TYPES43.TemplateLiteral:
|
|
8759
8894
|
return node.expressions.length === 0 ? getText(node) : null;
|
|
8760
|
-
case
|
|
8895
|
+
case AST_NODE_TYPES43.UnaryExpression:
|
|
8761
8896
|
return NUMERIC_SIGNS2.has(node.operator) && literalText(node.argument, getText) !== null ? getText(node) : null;
|
|
8762
8897
|
default:
|
|
8763
8898
|
return null;
|
|
@@ -8765,15 +8900,15 @@ function literalText(node, getText) {
|
|
|
8765
8900
|
}
|
|
8766
8901
|
function isPureReceiver(node) {
|
|
8767
8902
|
switch (node.type) {
|
|
8768
|
-
case
|
|
8769
|
-
case
|
|
8903
|
+
case AST_NODE_TYPES43.Identifier:
|
|
8904
|
+
case AST_NODE_TYPES43.ThisExpression:
|
|
8770
8905
|
return true;
|
|
8771
|
-
case
|
|
8906
|
+
case AST_NODE_TYPES43.MemberExpression:
|
|
8772
8907
|
if (node.optional) {
|
|
8773
8908
|
return false;
|
|
8774
8909
|
}
|
|
8775
8910
|
if (node.computed) {
|
|
8776
|
-
return node.property.type ===
|
|
8911
|
+
return node.property.type === AST_NODE_TYPES43.Literal && isPureReceiver(node.object);
|
|
8777
8912
|
}
|
|
8778
8913
|
return isPureReceiver(node.object);
|
|
8779
8914
|
default:
|
|
@@ -8781,7 +8916,7 @@ function isPureReceiver(node) {
|
|
|
8781
8916
|
}
|
|
8782
8917
|
}
|
|
8783
8918
|
function literalIndex(node) {
|
|
8784
|
-
if (node.type !==
|
|
8919
|
+
if (node.type !== AST_NODE_TYPES43.Literal || typeof node.value !== "number") {
|
|
8785
8920
|
return null;
|
|
8786
8921
|
}
|
|
8787
8922
|
return Number.isInteger(node.value) && node.value >= 0 ? node.value : null;
|
|
@@ -8807,24 +8942,24 @@ var prefer_whole_object_assertion_default = createRule({
|
|
|
8807
8942
|
}
|
|
8808
8943
|
const { sourceCode } = context;
|
|
8809
8944
|
function parseAssertion(statement) {
|
|
8810
|
-
if (statement.type !==
|
|
8945
|
+
if (statement.type !== AST_NODE_TYPES43.ExpressionStatement) {
|
|
8811
8946
|
return null;
|
|
8812
8947
|
}
|
|
8813
8948
|
const call = statement.expression;
|
|
8814
|
-
if (call.type !==
|
|
8949
|
+
if (call.type !== AST_NODE_TYPES43.CallExpression) {
|
|
8815
8950
|
return null;
|
|
8816
8951
|
}
|
|
8817
8952
|
const callee = call.callee;
|
|
8818
|
-
if (callee.type !==
|
|
8953
|
+
if (callee.type !== AST_NODE_TYPES43.MemberExpression || callee.computed || callee.property.type !== AST_NODE_TYPES43.Identifier) {
|
|
8819
8954
|
return null;
|
|
8820
8955
|
}
|
|
8821
8956
|
const matcher = callee.property.name;
|
|
8822
8957
|
const expectCall = callee.object;
|
|
8823
|
-
if (expectCall.type !==
|
|
8958
|
+
if (expectCall.type !== AST_NODE_TYPES43.CallExpression || expectCall.callee.type !== AST_NODE_TYPES43.Identifier || expectCall.callee.name !== "expect" || expectCall.arguments.length !== 1) {
|
|
8824
8959
|
return null;
|
|
8825
8960
|
}
|
|
8826
8961
|
const actual = expectCall.arguments[0];
|
|
8827
|
-
if (actual === void 0 || actual.type !==
|
|
8962
|
+
if (actual === void 0 || actual.type !== AST_NODE_TYPES43.MemberExpression || actual.optional) {
|
|
8828
8963
|
return null;
|
|
8829
8964
|
}
|
|
8830
8965
|
if (!isPureReceiver(actual.object)) {
|
|
@@ -8838,7 +8973,7 @@ var prefer_whole_object_assertion_default = createRule({
|
|
|
8838
8973
|
}
|
|
8839
8974
|
key = { kind: "index", index };
|
|
8840
8975
|
} else {
|
|
8841
|
-
if (actual.property.type !==
|
|
8976
|
+
if (actual.property.type !== AST_NODE_TYPES43.Identifier || COLLECTION_PROPERTIES.has(actual.property.name) || LITERAL_KEY_HAZARDS.has(actual.property.name)) {
|
|
8842
8977
|
return null;
|
|
8843
8978
|
}
|
|
8844
8979
|
key = { kind: "property", name: actual.property.name };
|
|
@@ -8850,7 +8985,7 @@ var prefer_whole_object_assertion_default = createRule({
|
|
|
8850
8985
|
return null;
|
|
8851
8986
|
}
|
|
8852
8987
|
const expected = call.arguments[0];
|
|
8853
|
-
if (call.arguments.length !== 1 || expected === void 0 || expected.type ===
|
|
8988
|
+
if (call.arguments.length !== 1 || expected === void 0 || expected.type === AST_NODE_TYPES43.SpreadElement) {
|
|
8854
8989
|
return null;
|
|
8855
8990
|
}
|
|
8856
8991
|
const literal = literalText(expected, (node) => sourceCode.getText(node));
|
|
@@ -8965,7 +9100,7 @@ var prefer_whole_object_assertion_default = createRule({
|
|
|
8965
9100
|
});
|
|
8966
9101
|
|
|
8967
9102
|
// src/rules/prefer-zod-enum.ts
|
|
8968
|
-
import { AST_NODE_TYPES as
|
|
9103
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES44 } from "@typescript-eslint/utils";
|
|
8969
9104
|
var prefer_zod_enum_default = createRule({
|
|
8970
9105
|
name: "prefer-zod-enum",
|
|
8971
9106
|
meta: {
|
|
@@ -8985,25 +9120,25 @@ var prefer_zod_enum_default = createRule({
|
|
|
8985
9120
|
const zodNamespaces = /* @__PURE__ */ new Set();
|
|
8986
9121
|
function enumValues(node) {
|
|
8987
9122
|
const callee = node.callee;
|
|
8988
|
-
if (callee.type !==
|
|
9123
|
+
if (callee.type !== AST_NODE_TYPES44.MemberExpression || callee.computed || callee.object.type !== AST_NODE_TYPES44.Identifier || !zodNamespaces.has(callee.object.name) || callee.property.type !== AST_NODE_TYPES44.Identifier || callee.property.name !== "union" || node.arguments.length !== 1) {
|
|
8989
9124
|
return null;
|
|
8990
9125
|
}
|
|
8991
9126
|
const argument = node.arguments[0];
|
|
8992
|
-
if (argument === void 0 || argument.type !==
|
|
9127
|
+
if (argument === void 0 || argument.type !== AST_NODE_TYPES44.ArrayExpression || argument.elements.length === 0) {
|
|
8993
9128
|
return null;
|
|
8994
9129
|
}
|
|
8995
9130
|
const values = [];
|
|
8996
9131
|
let canFix = true;
|
|
8997
9132
|
for (const element of argument.elements) {
|
|
8998
|
-
if (element?.type ===
|
|
9133
|
+
if (element?.type === AST_NODE_TYPES44.SpreadElement) {
|
|
8999
9134
|
canFix = false;
|
|
9000
9135
|
continue;
|
|
9001
9136
|
}
|
|
9002
|
-
if (element === null || element.type !==
|
|
9137
|
+
if (element === null || element.type !== AST_NODE_TYPES44.CallExpression || element.callee.type !== AST_NODE_TYPES44.MemberExpression || element.callee.computed || element.callee.object.type !== AST_NODE_TYPES44.Identifier || !zodNamespaces.has(element.callee.object.name) || element.callee.property.type !== AST_NODE_TYPES44.Identifier || element.callee.property.name !== "literal") {
|
|
9003
9138
|
return null;
|
|
9004
9139
|
}
|
|
9005
9140
|
const value = element.arguments[0];
|
|
9006
|
-
if (element.arguments.length !== 1 || value === void 0 || value.type !==
|
|
9141
|
+
if (element.arguments.length !== 1 || value === void 0 || value.type !== AST_NODE_TYPES44.Literal || typeof value.value !== "string") {
|
|
9007
9142
|
canFix = false;
|
|
9008
9143
|
continue;
|
|
9009
9144
|
}
|
|
@@ -9013,11 +9148,11 @@ var prefer_zod_enum_default = createRule({
|
|
|
9013
9148
|
}
|
|
9014
9149
|
function buildFix(node, values) {
|
|
9015
9150
|
const argument = node.arguments[0];
|
|
9016
|
-
if (argument === void 0 || argument.type !==
|
|
9151
|
+
if (argument === void 0 || argument.type !== AST_NODE_TYPES44.ArrayExpression || sourceCode.getCommentsInside(argument).length > 0) {
|
|
9017
9152
|
return void 0;
|
|
9018
9153
|
}
|
|
9019
9154
|
const callee = node.callee;
|
|
9020
|
-
if (callee.type !==
|
|
9155
|
+
if (callee.type !== AST_NODE_TYPES44.MemberExpression || callee.property.type !== AST_NODE_TYPES44.Identifier) {
|
|
9021
9156
|
return void 0;
|
|
9022
9157
|
}
|
|
9023
9158
|
return (fixer) => [
|
|
@@ -9034,7 +9169,7 @@ var prefer_zod_enum_default = createRule({
|
|
|
9034
9169
|
return;
|
|
9035
9170
|
}
|
|
9036
9171
|
for (const specifier of node.specifiers) {
|
|
9037
|
-
if (specifier.type ===
|
|
9172
|
+
if (specifier.type === AST_NODE_TYPES44.ImportNamespaceSpecifier || specifier.type === AST_NODE_TYPES44.ImportDefaultSpecifier || specifier.type === AST_NODE_TYPES44.ImportSpecifier && specifier.imported.type === AST_NODE_TYPES44.Identifier && specifier.imported.name === "z") {
|
|
9038
9173
|
zodNamespaces.add(specifier.local.name);
|
|
9039
9174
|
}
|
|
9040
9175
|
}
|
|
@@ -9056,7 +9191,7 @@ var prefer_zod_enum_default = createRule({
|
|
|
9056
9191
|
});
|
|
9057
9192
|
|
|
9058
9193
|
// src/rules/prefer-zod-infer.ts
|
|
9059
|
-
import { AST_NODE_TYPES as
|
|
9194
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES45 } from "@typescript-eslint/utils";
|
|
9060
9195
|
var SHAPE_PRESERVING_METHODS = /* @__PURE__ */ new Set([
|
|
9061
9196
|
"describe",
|
|
9062
9197
|
"refine",
|
|
@@ -9093,44 +9228,44 @@ var ZOD_TYPE_CONSTRAINTS = /* @__PURE__ */ new Set([
|
|
|
9093
9228
|
"Schema"
|
|
9094
9229
|
]);
|
|
9095
9230
|
var LEAF_NODE_TYPES = {
|
|
9096
|
-
string: [
|
|
9097
|
-
email: [
|
|
9098
|
-
url: [
|
|
9099
|
-
uuid: [
|
|
9100
|
-
ulid: [
|
|
9101
|
-
cuid: [
|
|
9102
|
-
cuid2: [
|
|
9103
|
-
nanoid: [
|
|
9104
|
-
iso: [
|
|
9105
|
-
number: [
|
|
9106
|
-
int: [
|
|
9107
|
-
float32: [
|
|
9108
|
-
float64: [
|
|
9109
|
-
boolean: [
|
|
9110
|
-
bigint: [
|
|
9111
|
-
symbol: [
|
|
9112
|
-
any: [
|
|
9113
|
-
unknown: [
|
|
9114
|
-
never: [
|
|
9115
|
-
void: [
|
|
9116
|
-
null: [
|
|
9117
|
-
undefined: [
|
|
9118
|
-
literal: [
|
|
9119
|
-
date: [
|
|
9120
|
-
array: [
|
|
9121
|
-
tuple: [
|
|
9122
|
-
object: [
|
|
9123
|
-
strictObject: [
|
|
9124
|
-
looseObject: [
|
|
9125
|
-
record: [
|
|
9126
|
-
map: [
|
|
9127
|
-
set: [
|
|
9128
|
-
promise: [
|
|
9129
|
-
enum: [
|
|
9130
|
-
nativeEnum: [
|
|
9131
|
-
union: [
|
|
9132
|
-
discriminatedUnion: [
|
|
9133
|
-
intersection: [
|
|
9231
|
+
string: [AST_NODE_TYPES45.TSStringKeyword],
|
|
9232
|
+
email: [AST_NODE_TYPES45.TSStringKeyword],
|
|
9233
|
+
url: [AST_NODE_TYPES45.TSStringKeyword],
|
|
9234
|
+
uuid: [AST_NODE_TYPES45.TSStringKeyword],
|
|
9235
|
+
ulid: [AST_NODE_TYPES45.TSStringKeyword],
|
|
9236
|
+
cuid: [AST_NODE_TYPES45.TSStringKeyword],
|
|
9237
|
+
cuid2: [AST_NODE_TYPES45.TSStringKeyword],
|
|
9238
|
+
nanoid: [AST_NODE_TYPES45.TSStringKeyword],
|
|
9239
|
+
iso: [AST_NODE_TYPES45.TSStringKeyword],
|
|
9240
|
+
number: [AST_NODE_TYPES45.TSNumberKeyword],
|
|
9241
|
+
int: [AST_NODE_TYPES45.TSNumberKeyword],
|
|
9242
|
+
float32: [AST_NODE_TYPES45.TSNumberKeyword],
|
|
9243
|
+
float64: [AST_NODE_TYPES45.TSNumberKeyword],
|
|
9244
|
+
boolean: [AST_NODE_TYPES45.TSBooleanKeyword],
|
|
9245
|
+
bigint: [AST_NODE_TYPES45.TSBigIntKeyword],
|
|
9246
|
+
symbol: [AST_NODE_TYPES45.TSSymbolKeyword],
|
|
9247
|
+
any: [AST_NODE_TYPES45.TSAnyKeyword],
|
|
9248
|
+
unknown: [AST_NODE_TYPES45.TSUnknownKeyword],
|
|
9249
|
+
never: [AST_NODE_TYPES45.TSNeverKeyword],
|
|
9250
|
+
void: [AST_NODE_TYPES45.TSVoidKeyword],
|
|
9251
|
+
null: [AST_NODE_TYPES45.TSNullKeyword],
|
|
9252
|
+
undefined: [AST_NODE_TYPES45.TSUndefinedKeyword],
|
|
9253
|
+
literal: [AST_NODE_TYPES45.TSLiteralType],
|
|
9254
|
+
date: [AST_NODE_TYPES45.TSTypeReference],
|
|
9255
|
+
array: [AST_NODE_TYPES45.TSArrayType, AST_NODE_TYPES45.TSTypeReference],
|
|
9256
|
+
tuple: [AST_NODE_TYPES45.TSTupleType],
|
|
9257
|
+
object: [AST_NODE_TYPES45.TSTypeLiteral, AST_NODE_TYPES45.TSTypeReference],
|
|
9258
|
+
strictObject: [AST_NODE_TYPES45.TSTypeLiteral, AST_NODE_TYPES45.TSTypeReference],
|
|
9259
|
+
looseObject: [AST_NODE_TYPES45.TSTypeLiteral, AST_NODE_TYPES45.TSTypeReference],
|
|
9260
|
+
record: [AST_NODE_TYPES45.TSTypeReference, AST_NODE_TYPES45.TSTypeLiteral],
|
|
9261
|
+
map: [AST_NODE_TYPES45.TSTypeReference],
|
|
9262
|
+
set: [AST_NODE_TYPES45.TSTypeReference],
|
|
9263
|
+
promise: [AST_NODE_TYPES45.TSTypeReference],
|
|
9264
|
+
enum: [AST_NODE_TYPES45.TSUnionType, AST_NODE_TYPES45.TSTypeReference, AST_NODE_TYPES45.TSLiteralType],
|
|
9265
|
+
nativeEnum: [AST_NODE_TYPES45.TSUnionType, AST_NODE_TYPES45.TSTypeReference, AST_NODE_TYPES45.TSLiteralType],
|
|
9266
|
+
union: [AST_NODE_TYPES45.TSUnionType, AST_NODE_TYPES45.TSTypeReference],
|
|
9267
|
+
discriminatedUnion: [AST_NODE_TYPES45.TSUnionType, AST_NODE_TYPES45.TSTypeReference],
|
|
9268
|
+
intersection: [AST_NODE_TYPES45.TSIntersectionType, AST_NODE_TYPES45.TSTypeReference]
|
|
9134
9269
|
};
|
|
9135
9270
|
function normalizeSchemaName(name) {
|
|
9136
9271
|
return name.replace(/Schema$/i, "").replace(/^Z(?=[A-Z])/, "").toLowerCase();
|
|
@@ -9139,20 +9274,20 @@ function normalizeTypeName(name) {
|
|
|
9139
9274
|
return name.replace(/Type$/, "").toLowerCase();
|
|
9140
9275
|
}
|
|
9141
9276
|
function unwrapNullish(annotation) {
|
|
9142
|
-
if (annotation.type !==
|
|
9277
|
+
if (annotation.type !== AST_NODE_TYPES45.TSUnionType) {
|
|
9143
9278
|
return {
|
|
9144
9279
|
core: annotation,
|
|
9145
|
-
nullable: annotation.type ===
|
|
9280
|
+
nullable: annotation.type === AST_NODE_TYPES45.TSNullKeyword
|
|
9146
9281
|
};
|
|
9147
9282
|
}
|
|
9148
9283
|
const rest = [];
|
|
9149
9284
|
let nullable = false;
|
|
9150
9285
|
for (const member of annotation.types) {
|
|
9151
|
-
if (member.type ===
|
|
9286
|
+
if (member.type === AST_NODE_TYPES45.TSNullKeyword) {
|
|
9152
9287
|
nullable = true;
|
|
9153
9288
|
continue;
|
|
9154
9289
|
}
|
|
9155
|
-
if (member.type ===
|
|
9290
|
+
if (member.type === AST_NODE_TYPES45.TSUndefinedKeyword) {
|
|
9156
9291
|
continue;
|
|
9157
9292
|
}
|
|
9158
9293
|
rest.push(member);
|
|
@@ -9217,14 +9352,14 @@ var prefer_zod_infer_default = createRule({
|
|
|
9217
9352
|
function zodCallChain(node) {
|
|
9218
9353
|
const chain = [];
|
|
9219
9354
|
let current = node;
|
|
9220
|
-
while (current.type ===
|
|
9355
|
+
while (current.type === AST_NODE_TYPES45.CallExpression) {
|
|
9221
9356
|
const callee = current.callee;
|
|
9222
|
-
if (callee.type !==
|
|
9357
|
+
if (callee.type !== AST_NODE_TYPES45.MemberExpression || callee.computed || callee.property.type !== AST_NODE_TYPES45.Identifier) {
|
|
9223
9358
|
return null;
|
|
9224
9359
|
}
|
|
9225
9360
|
chain.push(current);
|
|
9226
9361
|
const receiver = callee.object;
|
|
9227
|
-
if (receiver.type ===
|
|
9362
|
+
if (receiver.type === AST_NODE_TYPES45.Identifier) {
|
|
9228
9363
|
return zodNamespaces.has(receiver.name) ? chain.reverse() : null;
|
|
9229
9364
|
}
|
|
9230
9365
|
current = receiver;
|
|
@@ -9233,19 +9368,19 @@ var prefer_zod_infer_default = createRule({
|
|
|
9233
9368
|
}
|
|
9234
9369
|
function methodName(call) {
|
|
9235
9370
|
const callee = call.callee;
|
|
9236
|
-
return callee.type ===
|
|
9371
|
+
return callee.type === AST_NODE_TYPES45.MemberExpression && callee.property.type === AST_NODE_TYPES45.Identifier ? callee.property.name : "";
|
|
9237
9372
|
}
|
|
9238
9373
|
function schemaField(node) {
|
|
9239
9374
|
const modifiers = [];
|
|
9240
9375
|
let current = node;
|
|
9241
9376
|
let leaf = null;
|
|
9242
|
-
while (current.type ===
|
|
9377
|
+
while (current.type === AST_NODE_TYPES45.CallExpression) {
|
|
9243
9378
|
const callee = current.callee;
|
|
9244
|
-
if (callee.type !==
|
|
9379
|
+
if (callee.type !== AST_NODE_TYPES45.MemberExpression || callee.computed || callee.property.type !== AST_NODE_TYPES45.Identifier) {
|
|
9245
9380
|
break;
|
|
9246
9381
|
}
|
|
9247
9382
|
const receiver = callee.object;
|
|
9248
|
-
if (receiver.type ===
|
|
9383
|
+
if (receiver.type === AST_NODE_TYPES45.Identifier && zodNamespaces.has(receiver.name)) {
|
|
9249
9384
|
leaf = callee.property.name;
|
|
9250
9385
|
break;
|
|
9251
9386
|
}
|
|
@@ -9276,16 +9411,16 @@ var prefer_zod_infer_default = createRule({
|
|
|
9276
9411
|
return null;
|
|
9277
9412
|
}
|
|
9278
9413
|
const shape = base.arguments[0];
|
|
9279
|
-
if (shape === void 0 || shape.type !==
|
|
9414
|
+
if (shape === void 0 || shape.type !== AST_NODE_TYPES45.ObjectExpression) {
|
|
9280
9415
|
return null;
|
|
9281
9416
|
}
|
|
9282
9417
|
const fields = /* @__PURE__ */ new Map();
|
|
9283
9418
|
for (const property of shape.properties) {
|
|
9284
|
-
if (property.type !==
|
|
9419
|
+
if (property.type !== AST_NODE_TYPES45.Property || property.computed) {
|
|
9285
9420
|
return null;
|
|
9286
9421
|
}
|
|
9287
9422
|
const { key } = property;
|
|
9288
|
-
const name = key.type ===
|
|
9423
|
+
const name = key.type === AST_NODE_TYPES45.Identifier ? key.name : key.type === AST_NODE_TYPES45.Literal && typeof key.value === "string" ? key.value : null;
|
|
9289
9424
|
if (name === null) {
|
|
9290
9425
|
return null;
|
|
9291
9426
|
}
|
|
@@ -9296,11 +9431,11 @@ var prefer_zod_infer_default = createRule({
|
|
|
9296
9431
|
function typeMembers(members) {
|
|
9297
9432
|
const result = /* @__PURE__ */ new Map();
|
|
9298
9433
|
for (const member of members) {
|
|
9299
|
-
if (member.type !==
|
|
9434
|
+
if (member.type !== AST_NODE_TYPES45.TSPropertySignature || member.computed) {
|
|
9300
9435
|
return null;
|
|
9301
9436
|
}
|
|
9302
9437
|
const { key } = member;
|
|
9303
|
-
const name = key.type ===
|
|
9438
|
+
const name = key.type === AST_NODE_TYPES45.Identifier ? key.name : key.type === AST_NODE_TYPES45.Literal && typeof key.value === "string" ? key.value : null;
|
|
9304
9439
|
if (name === null) {
|
|
9305
9440
|
return null;
|
|
9306
9441
|
}
|
|
@@ -9314,8 +9449,8 @@ var prefer_zod_infer_default = createRule({
|
|
|
9314
9449
|
return result.size === 0 ? null : result;
|
|
9315
9450
|
}
|
|
9316
9451
|
function collectConstrainedNames(node) {
|
|
9317
|
-
if (node.type ===
|
|
9318
|
-
if (node.typeName.type ===
|
|
9452
|
+
if (node.type === AST_NODE_TYPES45.TSTypeReference) {
|
|
9453
|
+
if (node.typeName.type === AST_NODE_TYPES45.Identifier) {
|
|
9319
9454
|
constrainedTypeNames.add(node.typeName.name);
|
|
9320
9455
|
}
|
|
9321
9456
|
for (const argument of node.typeArguments?.params ?? []) {
|
|
@@ -9323,11 +9458,11 @@ var prefer_zod_infer_default = createRule({
|
|
|
9323
9458
|
}
|
|
9324
9459
|
return;
|
|
9325
9460
|
}
|
|
9326
|
-
if (node.type ===
|
|
9461
|
+
if (node.type === AST_NODE_TYPES45.TSArrayType) {
|
|
9327
9462
|
collectConstrainedNames(node.elementType);
|
|
9328
9463
|
return;
|
|
9329
9464
|
}
|
|
9330
|
-
if (node.type ===
|
|
9465
|
+
if (node.type === AST_NODE_TYPES45.TSUnionType || node.type === AST_NODE_TYPES45.TSIntersectionType) {
|
|
9331
9466
|
for (const member of node.types) {
|
|
9332
9467
|
collectConstrainedNames(member);
|
|
9333
9468
|
}
|
|
@@ -9371,13 +9506,13 @@ var prefer_zod_infer_default = createRule({
|
|
|
9371
9506
|
return;
|
|
9372
9507
|
}
|
|
9373
9508
|
for (const specifier of node.specifiers) {
|
|
9374
|
-
if (specifier.type ===
|
|
9509
|
+
if (specifier.type === AST_NODE_TYPES45.ImportNamespaceSpecifier || specifier.type === AST_NODE_TYPES45.ImportDefaultSpecifier || specifier.type === AST_NODE_TYPES45.ImportSpecifier && specifier.imported.type === AST_NODE_TYPES45.Identifier && specifier.imported.name === "z") {
|
|
9375
9510
|
zodNamespaces.add(specifier.local.name);
|
|
9376
9511
|
}
|
|
9377
9512
|
}
|
|
9378
9513
|
},
|
|
9379
9514
|
VariableDeclarator(node) {
|
|
9380
|
-
if (node.id.type !==
|
|
9515
|
+
if (node.id.type !== AST_NODE_TYPES45.Identifier || node.init == null) {
|
|
9381
9516
|
return;
|
|
9382
9517
|
}
|
|
9383
9518
|
const fields = schemaFields(node.init);
|
|
@@ -9387,14 +9522,14 @@ var prefer_zod_infer_default = createRule({
|
|
|
9387
9522
|
},
|
|
9388
9523
|
/** Records `XSchema.transform(...)` and equivalent module-level reshaping. */
|
|
9389
9524
|
"MemberExpression[computed=false]"(node) {
|
|
9390
|
-
if (node.object.type ===
|
|
9525
|
+
if (node.object.type === AST_NODE_TYPES45.Identifier && node.property.type === AST_NODE_TYPES45.Identifier && MODULE_LEVEL_RESHAPERS.has(node.property.name)) {
|
|
9391
9526
|
reshapedSchemaNames.add(node.object.name);
|
|
9392
9527
|
}
|
|
9393
9528
|
},
|
|
9394
9529
|
/** Records every type argument carried by a Zod constraint. */
|
|
9395
9530
|
TSTypeReference(node) {
|
|
9396
9531
|
const { typeName } = node;
|
|
9397
|
-
const referenced = typeName.type ===
|
|
9532
|
+
const referenced = typeName.type === AST_NODE_TYPES45.Identifier ? typeName.name : typeName.type === AST_NODE_TYPES45.TSQualifiedName && typeName.right.type === AST_NODE_TYPES45.Identifier ? typeName.right.name : null;
|
|
9398
9533
|
if (referenced === null || !ZOD_TYPE_CONSTRAINTS.has(referenced)) {
|
|
9399
9534
|
return;
|
|
9400
9535
|
}
|
|
@@ -9412,7 +9547,7 @@ var prefer_zod_infer_default = createRule({
|
|
|
9412
9547
|
}
|
|
9413
9548
|
},
|
|
9414
9549
|
TSTypeAliasDeclaration(node) {
|
|
9415
|
-
if (node.typeParameters !== void 0 || node.typeAnnotation.type !==
|
|
9550
|
+
if (node.typeParameters !== void 0 || node.typeAnnotation.type !== AST_NODE_TYPES45.TSTypeLiteral) {
|
|
9416
9551
|
return;
|
|
9417
9552
|
}
|
|
9418
9553
|
const members = typeMembers(node.typeAnnotation.members);
|
|
@@ -9457,10 +9592,10 @@ var prefer_zod_infer_default = createRule({
|
|
|
9457
9592
|
});
|
|
9458
9593
|
|
|
9459
9594
|
// src/rules/require-assert-never.ts
|
|
9460
|
-
import { AST_NODE_TYPES as
|
|
9595
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES46 } from "@typescript-eslint/utils";
|
|
9461
9596
|
var isRuntimeHandlingStatement = (statement) => {
|
|
9462
|
-
if (statement.type ===
|
|
9463
|
-
if (statement.type ===
|
|
9597
|
+
if (statement.type === AST_NODE_TYPES46.EmptyStatement) return false;
|
|
9598
|
+
if (statement.type === AST_NODE_TYPES46.BlockStatement) {
|
|
9464
9599
|
return statement.body.some(isRuntimeHandlingStatement);
|
|
9465
9600
|
}
|
|
9466
9601
|
return true;
|
|
@@ -9476,7 +9611,7 @@ var isCommentOnlyNoopDefault = (defaultCase, sourceCode) => {
|
|
|
9476
9611
|
return colonToken !== null && sourceCode.getCommentsAfter(colonToken).length > 0;
|
|
9477
9612
|
}
|
|
9478
9613
|
const only = defaultCase.consequent[0];
|
|
9479
|
-
if (only !== void 0 && defaultCase.consequent.length === 1 && only.type ===
|
|
9614
|
+
if (only !== void 0 && defaultCase.consequent.length === 1 && only.type === AST_NODE_TYPES46.BlockStatement && only.body.length === 0) {
|
|
9480
9615
|
return sourceCode.getCommentsInside(only).length > 0;
|
|
9481
9616
|
}
|
|
9482
9617
|
return false;
|
|
@@ -9516,7 +9651,7 @@ var require_assert_never_default = createRule({
|
|
|
9516
9651
|
});
|
|
9517
9652
|
|
|
9518
9653
|
// src/rules/require-fetch-timeout.ts
|
|
9519
|
-
import { AST_NODE_TYPES as
|
|
9654
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES47, ASTUtils as ASTUtils4 } from "@typescript-eslint/utils";
|
|
9520
9655
|
var GLOBAL_OBJECTS2 = /* @__PURE__ */ new Set([
|
|
9521
9656
|
"globalThis",
|
|
9522
9657
|
"window",
|
|
@@ -9532,14 +9667,14 @@ function matchesAnyPattern3(filename, patterns) {
|
|
|
9532
9667
|
return false;
|
|
9533
9668
|
}
|
|
9534
9669
|
function initProvablyLacksSignal(init) {
|
|
9535
|
-
if (init.type !==
|
|
9670
|
+
if (init.type !== AST_NODE_TYPES47.ObjectExpression) {
|
|
9536
9671
|
return false;
|
|
9537
9672
|
}
|
|
9538
9673
|
for (const prop of init.properties) {
|
|
9539
|
-
if (prop.type ===
|
|
9674
|
+
if (prop.type === AST_NODE_TYPES47.SpreadElement) {
|
|
9540
9675
|
return false;
|
|
9541
9676
|
}
|
|
9542
|
-
if (prop.key.type ===
|
|
9677
|
+
if (prop.key.type === AST_NODE_TYPES47.Identifier && prop.key.name === "signal" || prop.key.type === AST_NODE_TYPES47.Literal && prop.key.value === "signal") {
|
|
9543
9678
|
return false;
|
|
9544
9679
|
}
|
|
9545
9680
|
if (prop.computed) {
|
|
@@ -9549,7 +9684,7 @@ function initProvablyLacksSignal(init) {
|
|
|
9549
9684
|
return true;
|
|
9550
9685
|
}
|
|
9551
9686
|
function isStringish(node) {
|
|
9552
|
-
return node.type ===
|
|
9687
|
+
return node.type === AST_NODE_TYPES47.Literal && typeof node.value === "string" || node.type === AST_NODE_TYPES47.TemplateLiteral;
|
|
9553
9688
|
}
|
|
9554
9689
|
var require_fetch_timeout_default = createRule({
|
|
9555
9690
|
name: "require-fetch-timeout",
|
|
@@ -9590,10 +9725,10 @@ var require_fetch_timeout_default = createRule({
|
|
|
9590
9725
|
return variable === null || variable.defs.length === 0;
|
|
9591
9726
|
}
|
|
9592
9727
|
function isGlobalFetchCall2(callee) {
|
|
9593
|
-
if (callee.type ===
|
|
9728
|
+
if (callee.type === AST_NODE_TYPES47.Identifier) {
|
|
9594
9729
|
return callee.name === "fetch" && resolvesToGlobal(callee);
|
|
9595
9730
|
}
|
|
9596
|
-
return callee.type ===
|
|
9731
|
+
return callee.type === AST_NODE_TYPES47.MemberExpression && !callee.computed && callee.property.type === AST_NODE_TYPES47.Identifier && callee.property.name === "fetch" && callee.object.type === AST_NODE_TYPES47.Identifier && GLOBAL_OBJECTS2.has(callee.object.name) && resolvesToGlobal(callee.object);
|
|
9597
9732
|
}
|
|
9598
9733
|
return {
|
|
9599
9734
|
CallExpression(node) {
|
|
@@ -9613,7 +9748,7 @@ var require_fetch_timeout_default = createRule({
|
|
|
9613
9748
|
});
|
|
9614
9749
|
|
|
9615
9750
|
// src/rules/require-interface-for-injected-service.ts
|
|
9616
|
-
import { AST_NODE_TYPES as
|
|
9751
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES48 } from "@typescript-eslint/utils";
|
|
9617
9752
|
var CONFIGISH_TYPE_RE = /(?:Options|Opts|Config|Configuration|Settings|Params|Props|Args|Env|Environment|Callbacks|Flags)$/;
|
|
9618
9753
|
var CONFIGISH_NAME_RE = /^(?:options|opts|config|configuration|settings|params|props|args|env|environment|callbacks|flags|logger|log|clock)$/i;
|
|
9619
9754
|
var HTTP_TRANSPORT_TYPE_RE = /^(?:KyInstance|AxiosInstance|Session)$/;
|
|
@@ -9621,20 +9756,20 @@ var BUILTIN_CONTAINER_TYPE_RE = /^(?:Record|Map|WeakMap|Set|WeakSet|Array|Readon
|
|
|
9621
9756
|
var TRANSPORT_WRAPPER_NAME_RE = /Client$/;
|
|
9622
9757
|
var ROUTER_FACTORY_NAME = "Router";
|
|
9623
9758
|
var FRAMEWORK_HTTP_TYPES = /* @__PURE__ */ new Set(["Request", "Response", "NextFunction"]);
|
|
9624
|
-
var isExportedClass = (node) => node.parent.type ===
|
|
9625
|
-
var qualifiedName = (name) => name.type ===
|
|
9759
|
+
var isExportedClass = (node) => node.parent.type === AST_NODE_TYPES48.ExportNamedDeclaration || node.parent.type === AST_NODE_TYPES48.ExportDefaultDeclaration;
|
|
9760
|
+
var qualifiedName = (name) => name.type === AST_NODE_TYPES48.Identifier ? name.name : name.type === AST_NODE_TYPES48.TSQualifiedName ? `${qualifiedName(name.left)}.${name.right.name}` : "";
|
|
9626
9761
|
var readTypeReference = (annotation) => {
|
|
9627
|
-
if (annotation === void 0 || annotation.type !==
|
|
9762
|
+
if (annotation === void 0 || annotation.type !== AST_NODE_TYPES48.TSTypeReference) return null;
|
|
9628
9763
|
const { typeName } = annotation;
|
|
9629
|
-
const rightmost = typeName.type ===
|
|
9764
|
+
const rightmost = typeName.type === AST_NODE_TYPES48.Identifier ? typeName.name : typeName.type === AST_NODE_TYPES48.TSQualifiedName ? typeName.right.name : null;
|
|
9630
9765
|
if (rightmost === null) return null;
|
|
9631
9766
|
return { typeName: rightmost, display: qualifiedName(typeName) };
|
|
9632
9767
|
};
|
|
9633
9768
|
var namedParameterCollaborator = (annotated) => {
|
|
9634
9769
|
let target = annotated;
|
|
9635
|
-
if (target.type ===
|
|
9636
|
-
if (target.type ===
|
|
9637
|
-
if (target.type !==
|
|
9770
|
+
if (target.type === AST_NODE_TYPES48.TSParameterProperty) target = target.parameter;
|
|
9771
|
+
if (target.type === AST_NODE_TYPES48.AssignmentPattern) target = target.left;
|
|
9772
|
+
if (target.type !== AST_NODE_TYPES48.Identifier) return null;
|
|
9638
9773
|
const reference = readTypeReference(target.typeAnnotation?.typeAnnotation);
|
|
9639
9774
|
if (reference === null) return null;
|
|
9640
9775
|
return { name: target.name, ...reference };
|
|
@@ -9642,8 +9777,8 @@ var namedParameterCollaborator = (annotated) => {
|
|
|
9642
9777
|
var propertySignatureTypes = (members) => {
|
|
9643
9778
|
const types = /* @__PURE__ */ new Map();
|
|
9644
9779
|
for (const member of members) {
|
|
9645
|
-
if (member.type !==
|
|
9646
|
-
if (member.computed || member.key.type !==
|
|
9780
|
+
if (member.type !== AST_NODE_TYPES48.TSPropertySignature) continue;
|
|
9781
|
+
if (member.computed || member.key.type !== AST_NODE_TYPES48.Identifier) continue;
|
|
9647
9782
|
const reference = readTypeReference(member.typeAnnotation?.typeAnnotation);
|
|
9648
9783
|
if (reference === null) continue;
|
|
9649
9784
|
types.set(member.key.name, reference);
|
|
@@ -9654,18 +9789,18 @@ var fileTypeIndex = (program) => {
|
|
|
9654
9789
|
const objects = /* @__PURE__ */ new Map();
|
|
9655
9790
|
const functionAliases = /* @__PURE__ */ new Set();
|
|
9656
9791
|
for (const statement of program.body) {
|
|
9657
|
-
const declaration = statement.type ===
|
|
9658
|
-
if (declaration?.type ===
|
|
9792
|
+
const declaration = statement.type === AST_NODE_TYPES48.ExportNamedDeclaration ? statement.declaration : statement;
|
|
9793
|
+
if (declaration?.type === AST_NODE_TYPES48.TSInterfaceDeclaration) {
|
|
9659
9794
|
objects.set(declaration.id.name, propertySignatureTypes(declaration.body.body));
|
|
9660
9795
|
continue;
|
|
9661
9796
|
}
|
|
9662
|
-
if (declaration?.type !==
|
|
9797
|
+
if (declaration?.type !== AST_NODE_TYPES48.TSTypeAliasDeclaration) continue;
|
|
9663
9798
|
const aliased = declaration.typeAnnotation;
|
|
9664
|
-
if (aliased.type ===
|
|
9799
|
+
if (aliased.type === AST_NODE_TYPES48.TSFunctionType || aliased.type === AST_NODE_TYPES48.TSConstructorType) {
|
|
9665
9800
|
functionAliases.add(declaration.id.name);
|
|
9666
9801
|
continue;
|
|
9667
9802
|
}
|
|
9668
|
-
const literals = aliased.type ===
|
|
9803
|
+
const literals = aliased.type === AST_NODE_TYPES48.TSTypeLiteral ? [aliased] : aliased.type === AST_NODE_TYPES48.TSIntersectionType ? aliased.types.filter((part) => part.type === AST_NODE_TYPES48.TSTypeLiteral) : [];
|
|
9669
9804
|
if (literals.length === 0) continue;
|
|
9670
9805
|
const merged = /* @__PURE__ */ new Map();
|
|
9671
9806
|
for (const literal of literals) {
|
|
@@ -9678,10 +9813,10 @@ var fileTypeIndex = (program) => {
|
|
|
9678
9813
|
return { objects, functionAliases };
|
|
9679
9814
|
};
|
|
9680
9815
|
var bagMemberTypes = (annotation, declared) => {
|
|
9681
|
-
if (annotation.type ===
|
|
9816
|
+
if (annotation.type === AST_NODE_TYPES48.TSTypeLiteral) {
|
|
9682
9817
|
return propertySignatureTypes(annotation.members);
|
|
9683
9818
|
}
|
|
9684
|
-
if (annotation.type !==
|
|
9819
|
+
if (annotation.type !== AST_NODE_TYPES48.TSTypeReference || annotation.typeName.type !== AST_NODE_TYPES48.Identifier) {
|
|
9685
9820
|
return null;
|
|
9686
9821
|
}
|
|
9687
9822
|
return declared().objects.get(annotation.typeName.name) ?? null;
|
|
@@ -9693,11 +9828,11 @@ var objectPatternCollaborators = (pattern, declared) => {
|
|
|
9693
9828
|
if (members === null) return [];
|
|
9694
9829
|
const collaborators = [];
|
|
9695
9830
|
for (const property of pattern.properties) {
|
|
9696
|
-
if (property.type !==
|
|
9697
|
-
if (property.key.type !==
|
|
9831
|
+
if (property.type !== AST_NODE_TYPES48.Property || property.computed) continue;
|
|
9832
|
+
if (property.key.type !== AST_NODE_TYPES48.Identifier) continue;
|
|
9698
9833
|
const key = property.key.name;
|
|
9699
|
-
const bound = property.value.type ===
|
|
9700
|
-
if (bound.type !==
|
|
9834
|
+
const bound = property.value.type === AST_NODE_TYPES48.AssignmentPattern ? property.value.left : property.value;
|
|
9835
|
+
if (bound.type !== AST_NODE_TYPES48.Identifier) continue;
|
|
9701
9836
|
if (CONFIGISH_NAME_RE.test(key)) continue;
|
|
9702
9837
|
const reference = members.get(key);
|
|
9703
9838
|
if (reference === void 0) continue;
|
|
@@ -9707,8 +9842,8 @@ var objectPatternCollaborators = (pattern, declared) => {
|
|
|
9707
9842
|
};
|
|
9708
9843
|
var parameterCollaborators = (parameter, declared) => {
|
|
9709
9844
|
let target = parameter;
|
|
9710
|
-
if (target.type ===
|
|
9711
|
-
if (target.type ===
|
|
9845
|
+
if (target.type === AST_NODE_TYPES48.AssignmentPattern) target = target.left;
|
|
9846
|
+
if (target.type === AST_NODE_TYPES48.ObjectPattern) {
|
|
9712
9847
|
return objectPatternCollaborators(target, declared);
|
|
9713
9848
|
}
|
|
9714
9849
|
const named2 = namedParameterCollaborator(parameter);
|
|
@@ -9727,17 +9862,17 @@ var readConstructor = (ctor, declared, typeParameters) => {
|
|
|
9727
9862
|
let constructedFields = 0;
|
|
9728
9863
|
if (body2 !== null && body2 !== void 0) {
|
|
9729
9864
|
for (const statement of body2.body) {
|
|
9730
|
-
if (statement.type !==
|
|
9865
|
+
if (statement.type !== AST_NODE_TYPES48.ExpressionStatement) continue;
|
|
9731
9866
|
const expression = statement.expression;
|
|
9732
|
-
if (expression.type !==
|
|
9867
|
+
if (expression.type !== AST_NODE_TYPES48.AssignmentExpression || expression.operator !== "=" || expression.left.type !== AST_NODE_TYPES48.MemberExpression || expression.left.object.type !== AST_NODE_TYPES48.ThisExpression) {
|
|
9733
9868
|
continue;
|
|
9734
9869
|
}
|
|
9735
9870
|
const source = expression.right;
|
|
9736
|
-
if (source.type ===
|
|
9871
|
+
if (source.type === AST_NODE_TYPES48.NewExpression) {
|
|
9737
9872
|
constructedFields += 1;
|
|
9738
|
-
} else if (source.type ===
|
|
9873
|
+
} else if (source.type === AST_NODE_TYPES48.Identifier) {
|
|
9739
9874
|
storedFrom.add(source.name);
|
|
9740
|
-
} else if (source.type ===
|
|
9875
|
+
} else if (source.type === AST_NODE_TYPES48.MemberExpression && source.object.type === AST_NODE_TYPES48.Identifier) {
|
|
9741
9876
|
storedFrom.add(source.object.name);
|
|
9742
9877
|
}
|
|
9743
9878
|
}
|
|
@@ -9745,7 +9880,7 @@ var readConstructor = (ctor, declared, typeParameters) => {
|
|
|
9745
9880
|
const collaborators = [];
|
|
9746
9881
|
for (const parameter of ctor.value.params) {
|
|
9747
9882
|
for (const reference of parameterCollaborators(parameter, declared)) {
|
|
9748
|
-
const stored = parameter.type ===
|
|
9883
|
+
const stored = parameter.type === AST_NODE_TYPES48.TSParameterProperty || storedFrom.has(reference.name);
|
|
9749
9884
|
if (!stored) continue;
|
|
9750
9885
|
if (CONFIGISH_TYPE_RE.test(reference.typeName)) continue;
|
|
9751
9886
|
if (CONFIGISH_NAME_RE.test(reference.name)) continue;
|
|
@@ -9779,19 +9914,19 @@ var subtreeHas = (root, found) => {
|
|
|
9779
9914
|
return hit;
|
|
9780
9915
|
};
|
|
9781
9916
|
var isFrameworkWiring = (body2) => subtreeHas(body2, (node) => {
|
|
9782
|
-
if (node.type ===
|
|
9917
|
+
if (node.type === AST_NODE_TYPES48.CallExpression) {
|
|
9783
9918
|
const { callee } = node;
|
|
9784
|
-
if (callee.type ===
|
|
9785
|
-
return callee.type ===
|
|
9919
|
+
if (callee.type === AST_NODE_TYPES48.Identifier) return callee.name === ROUTER_FACTORY_NAME;
|
|
9920
|
+
return callee.type === AST_NODE_TYPES48.MemberExpression && !callee.computed && callee.property.type === AST_NODE_TYPES48.Identifier && callee.property.name === ROUTER_FACTORY_NAME;
|
|
9786
9921
|
}
|
|
9787
|
-
return node.type ===
|
|
9922
|
+
return node.type === AST_NODE_TYPES48.TSTypeReference && node.typeName.type === AST_NODE_TYPES48.TSQualifiedName && FRAMEWORK_HTTP_TYPES.has(node.typeName.right.name);
|
|
9788
9923
|
});
|
|
9789
9924
|
var stem2 = (name) => name.replace(/^I(?=[A-Z])/, "").replace(/Impl$/, "");
|
|
9790
9925
|
var fileInterfaceNames = (program) => {
|
|
9791
9926
|
const names = [];
|
|
9792
9927
|
for (const statement of program.body) {
|
|
9793
|
-
const declaration = statement.type ===
|
|
9794
|
-
if (declaration?.type ===
|
|
9928
|
+
const declaration = statement.type === AST_NODE_TYPES48.ExportNamedDeclaration ? statement.declaration : statement;
|
|
9929
|
+
if (declaration?.type === AST_NODE_TYPES48.TSInterfaceDeclaration) names.push(declaration.id.name);
|
|
9795
9930
|
}
|
|
9796
9931
|
return names;
|
|
9797
9932
|
};
|
|
@@ -9809,11 +9944,11 @@ var isTransportWrapper = (className, collaborators, program) => {
|
|
|
9809
9944
|
var publicMethodNames = (body2) => {
|
|
9810
9945
|
const names = [];
|
|
9811
9946
|
for (const member of body2.body) {
|
|
9812
|
-
if (member.type !==
|
|
9947
|
+
if (member.type !== AST_NODE_TYPES48.MethodDefinition) continue;
|
|
9813
9948
|
if (member.kind !== "method" || member.static) continue;
|
|
9814
9949
|
if (member.accessibility === "private" || member.accessibility === "protected") continue;
|
|
9815
|
-
if (member.key.type ===
|
|
9816
|
-
if (member.key.type ===
|
|
9950
|
+
if (member.key.type === AST_NODE_TYPES48.PrivateIdentifier) continue;
|
|
9951
|
+
if (member.key.type === AST_NODE_TYPES48.Identifier) names.push(member.key.name);
|
|
9817
9952
|
else names.push("\u2026");
|
|
9818
9953
|
}
|
|
9819
9954
|
return names;
|
|
@@ -9846,7 +9981,7 @@ var require_interface_for_injected_service_default = createRule({
|
|
|
9846
9981
|
if (node.implements.length > 0) return;
|
|
9847
9982
|
if (node.decorators.length > 0) return;
|
|
9848
9983
|
const ctor = node.body.body.find(
|
|
9849
|
-
(member) => member.type ===
|
|
9984
|
+
(member) => member.type === AST_NODE_TYPES48.MethodDefinition && member.kind === "constructor"
|
|
9850
9985
|
);
|
|
9851
9986
|
if (ctor === void 0) return;
|
|
9852
9987
|
const { collaborators, constructedFields } = readConstructor(
|
|
@@ -9875,37 +10010,37 @@ var require_interface_for_injected_service_default = createRule({
|
|
|
9875
10010
|
});
|
|
9876
10011
|
|
|
9877
10012
|
// src/rules/require-static-next-matcher.ts
|
|
9878
|
-
import { AST_NODE_TYPES as
|
|
10013
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES49 } from "@typescript-eslint/utils";
|
|
9879
10014
|
var NEXT_ENTRY_FILE = /(?:^|[/\\])(?:middleware|proxy)\.[cm]?[jt]sx?$/u;
|
|
9880
10015
|
function unwrapExpression(node) {
|
|
9881
|
-
if (node.type ===
|
|
10016
|
+
if (node.type === AST_NODE_TYPES49.TSAsExpression || node.type === AST_NODE_TYPES49.TSSatisfiesExpression || node.type === AST_NODE_TYPES49.TSNonNullExpression || node.type === AST_NODE_TYPES49.TSTypeAssertion) {
|
|
9882
10017
|
return unwrapExpression(node.expression);
|
|
9883
10018
|
}
|
|
9884
10019
|
return node;
|
|
9885
10020
|
}
|
|
9886
10021
|
function isStaticValue(node) {
|
|
9887
10022
|
const value = unwrapExpression(node);
|
|
9888
|
-
if (value.type ===
|
|
10023
|
+
if (value.type === AST_NODE_TYPES49.Literal) {
|
|
9889
10024
|
return true;
|
|
9890
10025
|
}
|
|
9891
|
-
if (value.type ===
|
|
10026
|
+
if (value.type === AST_NODE_TYPES49.TemplateLiteral) {
|
|
9892
10027
|
return value.expressions.length === 0;
|
|
9893
10028
|
}
|
|
9894
|
-
if (value.type ===
|
|
10029
|
+
if (value.type === AST_NODE_TYPES49.ArrayExpression) {
|
|
9895
10030
|
return value.elements.every(
|
|
9896
|
-
(element) => element !== null && element.type !==
|
|
10031
|
+
(element) => element !== null && element.type !== AST_NODE_TYPES49.SpreadElement && isStaticValue(element)
|
|
9897
10032
|
);
|
|
9898
10033
|
}
|
|
9899
|
-
if (value.type ===
|
|
10034
|
+
if (value.type === AST_NODE_TYPES49.ObjectExpression) {
|
|
9900
10035
|
return value.properties.every(
|
|
9901
|
-
(property) => property.type ===
|
|
10036
|
+
(property) => property.type === AST_NODE_TYPES49.Property && property.kind === "init" && !property.computed && property.value.type !== AST_NODE_TYPES49.AssignmentPattern && isStaticValue(property.value)
|
|
9902
10037
|
);
|
|
9903
10038
|
}
|
|
9904
10039
|
return false;
|
|
9905
10040
|
}
|
|
9906
10041
|
function propertyName2(property) {
|
|
9907
10042
|
if (property.computed) return null;
|
|
9908
|
-
if (property.key.type ===
|
|
10043
|
+
if (property.key.type === AST_NODE_TYPES49.Identifier) return property.key.name;
|
|
9909
10044
|
return typeof property.key.value === "string" ? property.key.value : null;
|
|
9910
10045
|
}
|
|
9911
10046
|
var require_static_next_matcher_default = createRule({
|
|
@@ -9927,19 +10062,19 @@ var require_static_next_matcher_default = createRule({
|
|
|
9927
10062
|
}
|
|
9928
10063
|
return {
|
|
9929
10064
|
ExportNamedDeclaration(node) {
|
|
9930
|
-
if (node.declaration?.type !==
|
|
10065
|
+
if (node.declaration?.type !== AST_NODE_TYPES49.VariableDeclaration) {
|
|
9931
10066
|
return;
|
|
9932
10067
|
}
|
|
9933
10068
|
for (const declaration of node.declaration.declarations) {
|
|
9934
|
-
if (declaration.id.type !==
|
|
10069
|
+
if (declaration.id.type !== AST_NODE_TYPES49.Identifier || declaration.id.name !== "config" || declaration.init === null) {
|
|
9935
10070
|
continue;
|
|
9936
10071
|
}
|
|
9937
10072
|
const config = unwrapExpression(declaration.init);
|
|
9938
|
-
if (config.type !==
|
|
10073
|
+
if (config.type !== AST_NODE_TYPES49.ObjectExpression) {
|
|
9939
10074
|
continue;
|
|
9940
10075
|
}
|
|
9941
10076
|
for (const property of config.properties) {
|
|
9942
|
-
if (property.type !==
|
|
10077
|
+
if (property.type !== AST_NODE_TYPES49.Property || propertyName2(property) !== "matcher" || property.value.type === AST_NODE_TYPES49.AssignmentPattern) {
|
|
9943
10078
|
continue;
|
|
9944
10079
|
}
|
|
9945
10080
|
if (!isStaticValue(property.value)) {
|
|
@@ -9953,18 +10088,18 @@ var require_static_next_matcher_default = createRule({
|
|
|
9953
10088
|
});
|
|
9954
10089
|
|
|
9955
10090
|
// src/rules/require-zod-form-validation.ts
|
|
9956
|
-
import { AST_NODE_TYPES as
|
|
10091
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES50 } from "@typescript-eslint/utils";
|
|
9957
10092
|
var looksLikeZodSchema = (node) => {
|
|
9958
10093
|
let current = node;
|
|
9959
10094
|
while (true) {
|
|
9960
|
-
if (current.type ===
|
|
10095
|
+
if (current.type === AST_NODE_TYPES50.Identifier) {
|
|
9961
10096
|
return current.name === "z" || ZOD_SCHEMA_NAME_RE.test(current.name);
|
|
9962
10097
|
}
|
|
9963
|
-
if (current.type ===
|
|
10098
|
+
if (current.type === AST_NODE_TYPES50.CallExpression) {
|
|
9964
10099
|
current = current.callee;
|
|
9965
10100
|
continue;
|
|
9966
10101
|
}
|
|
9967
|
-
if (current.type ===
|
|
10102
|
+
if (current.type === AST_NODE_TYPES50.MemberExpression) {
|
|
9968
10103
|
current = current.object;
|
|
9969
10104
|
continue;
|
|
9970
10105
|
}
|
|
@@ -9972,23 +10107,23 @@ var looksLikeZodSchema = (node) => {
|
|
|
9972
10107
|
}
|
|
9973
10108
|
};
|
|
9974
10109
|
var isZodParseCall = (node) => {
|
|
9975
|
-
if (node.type !==
|
|
10110
|
+
if (node.type !== AST_NODE_TYPES50.CallExpression) return false;
|
|
9976
10111
|
const callee = node.callee;
|
|
9977
|
-
if (callee.type !==
|
|
10112
|
+
if (callee.type !== AST_NODE_TYPES50.MemberExpression) return false;
|
|
9978
10113
|
if (callee.computed) return false;
|
|
9979
|
-
if (callee.property.type !==
|
|
10114
|
+
if (callee.property.type !== AST_NODE_TYPES50.Identifier) return false;
|
|
9980
10115
|
const method = callee.property.name;
|
|
9981
10116
|
if (method !== "parse" && method !== "safeParse") return false;
|
|
9982
10117
|
return looksLikeZodSchema(callee.object);
|
|
9983
10118
|
};
|
|
9984
10119
|
var isFormDataMethodCall = (node) => {
|
|
9985
10120
|
let current = node;
|
|
9986
|
-
if (current.type ===
|
|
10121
|
+
if (current.type === AST_NODE_TYPES50.AwaitExpression) {
|
|
9987
10122
|
current = current.argument;
|
|
9988
10123
|
}
|
|
9989
|
-
if (current.type !==
|
|
10124
|
+
if (current.type !== AST_NODE_TYPES50.CallExpression) return false;
|
|
9990
10125
|
const callee = current.callee;
|
|
9991
|
-
return callee.type ===
|
|
10126
|
+
return callee.type === AST_NODE_TYPES50.MemberExpression && !callee.computed && callee.property.type === AST_NODE_TYPES50.Identifier && callee.property.name === "formData";
|
|
9992
10127
|
};
|
|
9993
10128
|
var require_zod_form_validation_default = createRule({
|
|
9994
10129
|
name: "require-zod-form-validation",
|
|
@@ -10008,14 +10143,14 @@ var require_zod_form_validation_default = createRule({
|
|
|
10008
10143
|
return {};
|
|
10009
10144
|
}
|
|
10010
10145
|
const isFormSourceIdentifier = (node) => {
|
|
10011
|
-
if (node.type !==
|
|
10146
|
+
if (node.type !== AST_NODE_TYPES50.Identifier) return false;
|
|
10012
10147
|
if (/formdata/i.test(node.name)) return true;
|
|
10013
10148
|
let scope = context.sourceCode.getScope(node);
|
|
10014
10149
|
while (scope !== null) {
|
|
10015
10150
|
const variable = scope.set.get(node.name);
|
|
10016
10151
|
if (variable !== void 0 && variable.defs.length === 1) {
|
|
10017
10152
|
const def = variable.defs[0];
|
|
10018
|
-
if (def !== void 0 && def.type === "Variable" && def.node.type ===
|
|
10153
|
+
if (def !== void 0 && def.type === "Variable" && def.node.type === AST_NODE_TYPES50.VariableDeclarator && def.node.init !== null) {
|
|
10019
10154
|
return isFormDataMethodCall(def.node.init);
|
|
10020
10155
|
}
|
|
10021
10156
|
return false;
|
|
@@ -10026,8 +10161,8 @@ var require_zod_form_validation_default = createRule({
|
|
|
10026
10161
|
};
|
|
10027
10162
|
const isFormDataGetCall = (node) => {
|
|
10028
10163
|
const callee = node.callee;
|
|
10029
|
-
if (callee.type !==
|
|
10030
|
-
if (callee.property.type !==
|
|
10164
|
+
if (callee.type !== AST_NODE_TYPES50.MemberExpression) return false;
|
|
10165
|
+
if (callee.property.type !== AST_NODE_TYPES50.Identifier || callee.property.name !== "get") {
|
|
10031
10166
|
return false;
|
|
10032
10167
|
}
|
|
10033
10168
|
return isFormSourceIdentifier(callee.object);
|
|
@@ -10042,11 +10177,11 @@ var require_zod_form_validation_default = createRule({
|
|
|
10042
10177
|
};
|
|
10043
10178
|
const isInstanceofNarrowing = (node) => {
|
|
10044
10179
|
const parent = node.parent;
|
|
10045
|
-
return parent !== null && parent !== void 0 && parent.type ===
|
|
10180
|
+
return parent !== null && parent !== void 0 && parent.type === AST_NODE_TYPES50.BinaryExpression && parent.operator === "instanceof" && parent.left === node && parent.right.type === AST_NODE_TYPES50.Identifier && (parent.right.name === "File" || parent.right.name === "Blob");
|
|
10046
10181
|
};
|
|
10047
10182
|
const boundDeclarator = (node) => {
|
|
10048
10183
|
const parent = node.parent;
|
|
10049
|
-
if (parent.type ===
|
|
10184
|
+
if (parent.type === AST_NODE_TYPES50.VariableDeclarator && parent.init === node && parent.id.type === AST_NODE_TYPES50.Identifier) {
|
|
10050
10185
|
return parent;
|
|
10051
10186
|
}
|
|
10052
10187
|
return null;
|
|
@@ -10105,7 +10240,7 @@ var store_insert_requires_on_conflict_default = createRule({
|
|
|
10105
10240
|
});
|
|
10106
10241
|
|
|
10107
10242
|
// src/rules/zod-naming-convention.ts
|
|
10108
|
-
import { AST_NODE_TYPES as
|
|
10243
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES51 } from "@typescript-eslint/utils";
|
|
10109
10244
|
var CONVENTIONS = {
|
|
10110
10245
|
prefix: { test: ZOD_PREFIX_RE, messageId: "zPrefix" },
|
|
10111
10246
|
suffix: { test: ZOD_SUFFIX_RE, messageId: "schemaSuffix" },
|
|
@@ -10130,15 +10265,15 @@ var NON_SCHEMA_TERMINALS = /* @__PURE__ */ new Set([
|
|
|
10130
10265
|
"registry",
|
|
10131
10266
|
"implement"
|
|
10132
10267
|
]);
|
|
10133
|
-
var terminalMethodName = (callee) => !callee.computed && callee.property.type ===
|
|
10268
|
+
var terminalMethodName = (callee) => !callee.computed && callee.property.type === AST_NODE_TYPES51.Identifier ? callee.property.name : null;
|
|
10134
10269
|
var calleeChainStartsWithZ = (node) => {
|
|
10135
10270
|
let current = node;
|
|
10136
|
-
while (current.type ===
|
|
10271
|
+
while (current.type === AST_NODE_TYPES51.MemberExpression) {
|
|
10137
10272
|
const receiver = current.object;
|
|
10138
|
-
if (receiver.type ===
|
|
10273
|
+
if (receiver.type === AST_NODE_TYPES51.Identifier && receiver.name === "z") {
|
|
10139
10274
|
return true;
|
|
10140
10275
|
}
|
|
10141
|
-
if (receiver.type ===
|
|
10276
|
+
if (receiver.type === AST_NODE_TYPES51.CallExpression) {
|
|
10142
10277
|
current = receiver.callee;
|
|
10143
10278
|
continue;
|
|
10144
10279
|
}
|
|
@@ -10183,13 +10318,13 @@ var zod_naming_convention_default = createRule({
|
|
|
10183
10318
|
VariableDeclarator(node) {
|
|
10184
10319
|
const init = node.init;
|
|
10185
10320
|
if (init === null || init === void 0) return;
|
|
10186
|
-
if (init.type !==
|
|
10321
|
+
if (init.type !== AST_NODE_TYPES51.CallExpression) return;
|
|
10187
10322
|
const callee = init.callee;
|
|
10188
|
-
if (callee.type !==
|
|
10323
|
+
if (callee.type !== AST_NODE_TYPES51.MemberExpression) return;
|
|
10189
10324
|
if (!calleeChainStartsWithZ(callee)) return;
|
|
10190
10325
|
const terminal = terminalMethodName(callee);
|
|
10191
10326
|
if (terminal !== null && NON_SCHEMA_TERMINALS.has(terminal)) return;
|
|
10192
|
-
if (node.id.type !==
|
|
10327
|
+
if (node.id.type !== AST_NODE_TYPES51.Identifier) return;
|
|
10193
10328
|
if (test.test(node.id.name)) return;
|
|
10194
10329
|
if (acceptsSchemaWord && CONTAINS_SCHEMA_RE.test(node.id.name)) return;
|
|
10195
10330
|
context.report({
|
|
@@ -10237,7 +10372,7 @@ var retiredRules = {
|
|
|
10237
10372
|
},
|
|
10238
10373
|
"prefer-shadcn": {
|
|
10239
10374
|
removedIn: "3.0.0",
|
|
10240
|
-
reason: "Delete the entry;
|
|
10375
|
+
reason: "Delete the retired entry; application-profile consumers can separately adopt `@sarj/prefer-shadcn-primitives`."
|
|
10241
10376
|
},
|
|
10242
10377
|
"primary-export-file-name": {
|
|
10243
10378
|
removedIn: "4.0.0",
|
|
@@ -10301,6 +10436,7 @@ var rules = {
|
|
|
10301
10436
|
"prefer-constant-time-secret-compare": prefer_constant_time_secret_compare_default,
|
|
10302
10437
|
"prefer-discriminated-union": prefer_discriminated_union_default,
|
|
10303
10438
|
"prefer-input-group-search": prefer_input_group_search_default,
|
|
10439
|
+
"prefer-shadcn-primitives": prefer_shadcn_primitives_default,
|
|
10304
10440
|
"prefer-module-level-constant": prefer_module_level_constant_default,
|
|
10305
10441
|
"prefer-module-level-schema": prefer_module_level_schema_default,
|
|
10306
10442
|
"prefer-native-random-uuid": prefer_native_random_uuid_default,
|
|
@@ -10323,11 +10459,12 @@ var rules = {
|
|
|
10323
10459
|
};
|
|
10324
10460
|
var meta = {
|
|
10325
10461
|
name: "@sarj/eslint-plugin",
|
|
10326
|
-
version: "9.
|
|
10462
|
+
version: "9.12.1"
|
|
10327
10463
|
};
|
|
10328
10464
|
var applicationOnlyRules = [
|
|
10329
10465
|
"no-restricted-library-load",
|
|
10330
|
-
"prefer-native-random-uuid"
|
|
10466
|
+
"prefer-native-random-uuid",
|
|
10467
|
+
"prefer-shadcn-primitives"
|
|
10331
10468
|
];
|
|
10332
10469
|
var recommendedRules = {
|
|
10333
10470
|
"@sarj/enforce-file-structure": "warn",
|