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