@sarj/eslint-plugin 9.9.0 → 9.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -0
- package/dist/index.cjs +503 -385
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +13 -5
- package/dist/index.d.ts +13 -5
- package/dist/index.js +499 -381
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -641,6 +641,7 @@ var CODE_KEYWORD_RE = /^(import |export |const |let |var |function\b|class |inte
|
|
|
641
641
|
var CODE_TAIL_RE = /[;{}()]\s*$|=>\s*$|,\s*$/;
|
|
642
642
|
var ASSIGN_RE = /^[A-Za-z_$][\w.$[\]]*\s*(?:=(?![=>])|\+=|-=|\*=)\s*\S.*[;)}\]]\s*$/;
|
|
643
643
|
var CALL_RE = /^[A-Za-z_$][\w.$]*\([^)]*\)\s*;?\s*$/;
|
|
644
|
+
var ASSERTION_CODE_RE = /^(?:await\s+)?(?:expect(?:TypeOf)?\s*\(.+\)\s*(?:\.\w+(?:<[^;()]*>)?)+(?:\s*\(.*\))?|assert(?:\.\w+)?\s*\(.+\))\s*;?\s*$/;
|
|
644
645
|
var PSEUDOCODE_RE = /%\w+%|\[opt\]|(?:^|\s)<[A-Za-z]\w*>|…|\.\.\./;
|
|
645
646
|
function stripCommentMarker(line) {
|
|
646
647
|
return line.replace(/^\s*\/{1,2}/, "").replace(/^\s*\*+/, "").trim();
|
|
@@ -659,6 +660,7 @@ function looksLikeCode(text, allowCall = true) {
|
|
|
659
660
|
if (!t) return false;
|
|
660
661
|
if (CODE_KEYWORD_RE.test(t) && CODE_TAIL_RE.test(t)) return true;
|
|
661
662
|
if (ASSIGN_RE.test(t)) return true;
|
|
663
|
+
if (ASSERTION_CODE_RE.test(t)) return true;
|
|
662
664
|
return allowCall && CALL_RE.test(t);
|
|
663
665
|
}
|
|
664
666
|
function hasPseudocode(text) {
|
|
@@ -6593,8 +6595,121 @@ var prefer_discriminated_union_default = createRule({
|
|
|
6593
6595
|
}
|
|
6594
6596
|
});
|
|
6595
6597
|
|
|
6596
|
-
// src/rules/prefer-
|
|
6598
|
+
// src/rules/prefer-input-group-search.ts
|
|
6597
6599
|
import { AST_NODE_TYPES as AST_NODE_TYPES34 } from "@typescript-eslint/utils";
|
|
6600
|
+
var INPUT_MODULE = /(?:^|\/)components\/ui\/input$/u;
|
|
6601
|
+
var INPUT_GROUP_MODULE = /(?:^|\/)components\/ui\/input-group$/u;
|
|
6602
|
+
var MAX_JSX_DISTANCE = 2;
|
|
6603
|
+
function localNamedImports(node, importedName) {
|
|
6604
|
+
return node.specifiers.filter(
|
|
6605
|
+
(specifier) => specifier.type === AST_NODE_TYPES34.ImportSpecifier && (specifier.imported.type === AST_NODE_TYPES34.Identifier ? specifier.imported.name : specifier.imported.value) === importedName
|
|
6606
|
+
).map((specifier) => specifier.local.name);
|
|
6607
|
+
}
|
|
6608
|
+
function elementName(node) {
|
|
6609
|
+
return node.name.type === AST_NODE_TYPES34.JSXIdentifier ? node.name.name : null;
|
|
6610
|
+
}
|
|
6611
|
+
function jsxAncestors(occurrence) {
|
|
6612
|
+
return occurrence.ancestors.filter(
|
|
6613
|
+
(ancestor) => ancestor.type === AST_NODE_TYPES34.JSXElement
|
|
6614
|
+
);
|
|
6615
|
+
}
|
|
6616
|
+
function isWithinInputGroup(occurrence, inputGroupNames) {
|
|
6617
|
+
return jsxAncestors(occurrence).some(
|
|
6618
|
+
(ancestor) => inputGroupNames.has(elementName(ancestor.openingElement) ?? "")
|
|
6619
|
+
);
|
|
6620
|
+
}
|
|
6621
|
+
function nearestEligibleCommonAncestor(search, input, inputGroupNames) {
|
|
6622
|
+
const searchAncestors = jsxAncestors(search);
|
|
6623
|
+
const inputAncestorList = jsxAncestors(input);
|
|
6624
|
+
const inputAncestors = new Set(inputAncestorList);
|
|
6625
|
+
for (let index = searchAncestors.length - 1; index >= 0; index -= 1) {
|
|
6626
|
+
const ancestor = searchAncestors[index];
|
|
6627
|
+
if (ancestor === void 0) continue;
|
|
6628
|
+
if (!inputAncestors.has(ancestor)) continue;
|
|
6629
|
+
const searchDistance = searchAncestors.length - index - 1;
|
|
6630
|
+
const inputDistance = inputAncestorList.length - inputAncestorList.indexOf(ancestor) - 1;
|
|
6631
|
+
if (searchDistance > MAX_JSX_DISTANCE || inputDistance > MAX_JSX_DISTANCE) {
|
|
6632
|
+
return null;
|
|
6633
|
+
}
|
|
6634
|
+
if (inputGroupNames.has(elementName(ancestor.openingElement) ?? "")) {
|
|
6635
|
+
return null;
|
|
6636
|
+
}
|
|
6637
|
+
return ancestor;
|
|
6638
|
+
}
|
|
6639
|
+
return null;
|
|
6640
|
+
}
|
|
6641
|
+
var prefer_input_group_search_default = createRule({
|
|
6642
|
+
name: "prefer-input-group-search",
|
|
6643
|
+
meta: {
|
|
6644
|
+
type: "suggestion",
|
|
6645
|
+
docs: {
|
|
6646
|
+
description: "Require search icons and shared Input controls in the same visual wrapper to use InputGroup."
|
|
6647
|
+
},
|
|
6648
|
+
schema: [],
|
|
6649
|
+
messages: {
|
|
6650
|
+
preferInputGroup: "Use InputGroup with InputGroupAddon and InputGroupInput for this search field."
|
|
6651
|
+
}
|
|
6652
|
+
},
|
|
6653
|
+
defaultOptions: [],
|
|
6654
|
+
create(context) {
|
|
6655
|
+
const inputNames = /* @__PURE__ */ new Set();
|
|
6656
|
+
const inputGroupNames = /* @__PURE__ */ new Set();
|
|
6657
|
+
const searchNames = /* @__PURE__ */ new Set();
|
|
6658
|
+
const inputs = [];
|
|
6659
|
+
const searches = [];
|
|
6660
|
+
return {
|
|
6661
|
+
ImportDeclaration(node) {
|
|
6662
|
+
const source = String(node.source.value);
|
|
6663
|
+
if (source === "lucide-react") {
|
|
6664
|
+
localNamedImports(node, "Search").forEach(
|
|
6665
|
+
(name) => searchNames.add(name)
|
|
6666
|
+
);
|
|
6667
|
+
} else if (INPUT_MODULE.test(source)) {
|
|
6668
|
+
localNamedImports(node, "Input").forEach(
|
|
6669
|
+
(name) => inputNames.add(name)
|
|
6670
|
+
);
|
|
6671
|
+
} else if (INPUT_GROUP_MODULE.test(source)) {
|
|
6672
|
+
localNamedImports(node, "InputGroup").forEach(
|
|
6673
|
+
(name) => inputGroupNames.add(name)
|
|
6674
|
+
);
|
|
6675
|
+
}
|
|
6676
|
+
},
|
|
6677
|
+
JSXOpeningElement(node) {
|
|
6678
|
+
const name = elementName(node);
|
|
6679
|
+
if (name === null) return;
|
|
6680
|
+
const occurrence = {
|
|
6681
|
+
ancestors: context.sourceCode.getAncestors(node),
|
|
6682
|
+
node
|
|
6683
|
+
};
|
|
6684
|
+
if (searchNames.has(name)) searches.push(occurrence);
|
|
6685
|
+
if (inputNames.has(name)) inputs.push(occurrence);
|
|
6686
|
+
},
|
|
6687
|
+
"Program:exit"() {
|
|
6688
|
+
const reported = /* @__PURE__ */ new Set();
|
|
6689
|
+
for (const search of searches) {
|
|
6690
|
+
if (isWithinInputGroup(search, inputGroupNames)) continue;
|
|
6691
|
+
for (const input of inputs) {
|
|
6692
|
+
if (isWithinInputGroup(input, inputGroupNames)) continue;
|
|
6693
|
+
const wrapper = nearestEligibleCommonAncestor(
|
|
6694
|
+
search,
|
|
6695
|
+
input,
|
|
6696
|
+
inputGroupNames
|
|
6697
|
+
);
|
|
6698
|
+
if (wrapper === null || reported.has(wrapper)) continue;
|
|
6699
|
+
reported.add(wrapper);
|
|
6700
|
+
context.report({
|
|
6701
|
+
node: wrapper.openingElement,
|
|
6702
|
+
messageId: "preferInputGroup"
|
|
6703
|
+
});
|
|
6704
|
+
}
|
|
6705
|
+
}
|
|
6706
|
+
}
|
|
6707
|
+
};
|
|
6708
|
+
}
|
|
6709
|
+
});
|
|
6710
|
+
|
|
6711
|
+
// src/rules/prefer-module-level-constant.ts
|
|
6712
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES35 } from "@typescript-eslint/utils";
|
|
6598
6713
|
var DEFAULT_MIN_ELEMENTS = 3;
|
|
6599
6714
|
var MAX_LITERAL_DEPTH = 4;
|
|
6600
6715
|
var IGNORE_PATTERNS2 = [
|
|
@@ -6623,9 +6738,9 @@ var MUTATING_METHODS = /* @__PURE__ */ new Set([
|
|
|
6623
6738
|
"assign"
|
|
6624
6739
|
]);
|
|
6625
6740
|
var FUNCTION_TYPES5 = /* @__PURE__ */ new Set([
|
|
6626
|
-
|
|
6627
|
-
|
|
6628
|
-
|
|
6741
|
+
AST_NODE_TYPES35.FunctionDeclaration,
|
|
6742
|
+
AST_NODE_TYPES35.FunctionExpression,
|
|
6743
|
+
AST_NODE_TYPES35.ArrowFunctionExpression
|
|
6629
6744
|
]);
|
|
6630
6745
|
var COLLECTION_CONSTRUCTORS = /* @__PURE__ */ new Set(["Set", "Map"]);
|
|
6631
6746
|
function isIgnoredFile2(filename, sourceText) {
|
|
@@ -6638,14 +6753,14 @@ function isLocalFixtureFile(filename) {
|
|
|
6638
6753
|
return isTestFile(filename) || isStoryFile(filename);
|
|
6639
6754
|
}
|
|
6640
6755
|
function unwrap3(node) {
|
|
6641
|
-
if (node.type ===
|
|
6756
|
+
if (node.type === AST_NODE_TYPES35.TSAsExpression || node.type === AST_NODE_TYPES35.TSSatisfiesExpression || node.type === AST_NODE_TYPES35.TSNonNullExpression) {
|
|
6642
6757
|
return unwrap3(node.expression);
|
|
6643
6758
|
}
|
|
6644
6759
|
return node;
|
|
6645
6760
|
}
|
|
6646
6761
|
var HAS_STATEFUL_FLAG_RE = /[gy]/;
|
|
6647
6762
|
function isRegexLiteral(node) {
|
|
6648
|
-
return node.type ===
|
|
6763
|
+
return node.type === AST_NODE_TYPES35.Literal && "regex" in node && node.regex !== void 0;
|
|
6649
6764
|
}
|
|
6650
6765
|
function isLiteralOnly(node, depth) {
|
|
6651
6766
|
if (depth > MAX_LITERAL_DEPTH) {
|
|
@@ -6653,29 +6768,29 @@ function isLiteralOnly(node, depth) {
|
|
|
6653
6768
|
}
|
|
6654
6769
|
const inner = unwrap3(node);
|
|
6655
6770
|
switch (inner.type) {
|
|
6656
|
-
case
|
|
6771
|
+
case AST_NODE_TYPES35.Literal: {
|
|
6657
6772
|
return !(isRegexLiteral(inner) && HAS_STATEFUL_FLAG_RE.test(inner.regex.flags));
|
|
6658
6773
|
}
|
|
6659
|
-
case
|
|
6774
|
+
case AST_NODE_TYPES35.TemplateLiteral: {
|
|
6660
6775
|
return inner.expressions.length === 0;
|
|
6661
6776
|
}
|
|
6662
|
-
case
|
|
6663
|
-
return (inner.operator === "-" || inner.operator === "+") && inner.argument.type ===
|
|
6777
|
+
case AST_NODE_TYPES35.UnaryExpression: {
|
|
6778
|
+
return (inner.operator === "-" || inner.operator === "+") && inner.argument.type === AST_NODE_TYPES35.Literal && typeof inner.argument.value === "number";
|
|
6664
6779
|
}
|
|
6665
|
-
case
|
|
6780
|
+
case AST_NODE_TYPES35.ArrayExpression: {
|
|
6666
6781
|
return inner.elements.every(
|
|
6667
|
-
(el) => el !== null && el.type !==
|
|
6782
|
+
(el) => el !== null && el.type !== AST_NODE_TYPES35.SpreadElement && isLiteralOnly(el, depth + 1)
|
|
6668
6783
|
);
|
|
6669
6784
|
}
|
|
6670
|
-
case
|
|
6785
|
+
case AST_NODE_TYPES35.ObjectExpression: {
|
|
6671
6786
|
return inner.properties.every((prop) => {
|
|
6672
|
-
if (prop.type !==
|
|
6787
|
+
if (prop.type !== AST_NODE_TYPES35.Property) {
|
|
6673
6788
|
return false;
|
|
6674
6789
|
}
|
|
6675
6790
|
if (prop.shorthand || prop.method || prop.kind !== "init") {
|
|
6676
6791
|
return false;
|
|
6677
6792
|
}
|
|
6678
|
-
if (prop.computed && prop.key.type !==
|
|
6793
|
+
if (prop.computed && prop.key.type !== AST_NODE_TYPES35.Literal) {
|
|
6679
6794
|
return false;
|
|
6680
6795
|
}
|
|
6681
6796
|
return isLiteralOnly(prop.value, depth + 1);
|
|
@@ -6688,7 +6803,7 @@ function isLiteralOnly(node, depth) {
|
|
|
6688
6803
|
}
|
|
6689
6804
|
function unwrapObjectFreeze(node) {
|
|
6690
6805
|
const inner = unwrap3(node);
|
|
6691
|
-
if (inner.type ===
|
|
6806
|
+
if (inner.type === AST_NODE_TYPES35.CallExpression && inner.callee.type === AST_NODE_TYPES35.MemberExpression && !inner.callee.computed && inner.callee.object.type === AST_NODE_TYPES35.Identifier && inner.callee.object.name === "Object" && inner.callee.property.type === AST_NODE_TYPES35.Identifier && inner.callee.property.name === "freeze" && inner.arguments.length === 1 && inner.arguments[0] !== void 0 && inner.arguments[0].type !== AST_NODE_TYPES35.SpreadElement) {
|
|
6692
6807
|
return unwrap3(inner.arguments[0]);
|
|
6693
6808
|
}
|
|
6694
6809
|
return inner;
|
|
@@ -6704,19 +6819,19 @@ function classify(init, checkRegex) {
|
|
|
6704
6819
|
}
|
|
6705
6820
|
return { kind: "regex", size: 1 };
|
|
6706
6821
|
}
|
|
6707
|
-
if (node.type ===
|
|
6822
|
+
if (node.type === AST_NODE_TYPES35.ArrayExpression) {
|
|
6708
6823
|
return isLiteralOnly(node, 0) ? { kind: "array", size: node.elements.length } : null;
|
|
6709
6824
|
}
|
|
6710
|
-
if (node.type ===
|
|
6825
|
+
if (node.type === AST_NODE_TYPES35.ObjectExpression) {
|
|
6711
6826
|
return isLiteralOnly(node, 0) ? { kind: "object", size: node.properties.length } : null;
|
|
6712
6827
|
}
|
|
6713
|
-
if (node.type ===
|
|
6828
|
+
if (node.type === AST_NODE_TYPES35.NewExpression && node.callee.type === AST_NODE_TYPES35.Identifier && COLLECTION_CONSTRUCTORS.has(node.callee.name)) {
|
|
6714
6829
|
const arg = node.arguments[0];
|
|
6715
|
-
if (node.arguments.length !== 1 || arg === void 0 || arg.type ===
|
|
6830
|
+
if (node.arguments.length !== 1 || arg === void 0 || arg.type === AST_NODE_TYPES35.SpreadElement) {
|
|
6716
6831
|
return null;
|
|
6717
6832
|
}
|
|
6718
6833
|
const entries = unwrap3(arg);
|
|
6719
|
-
if (entries.type !==
|
|
6834
|
+
if (entries.type !== AST_NODE_TYPES35.ArrayExpression) {
|
|
6720
6835
|
return null;
|
|
6721
6836
|
}
|
|
6722
6837
|
return isLiteralOnly(entries, 0) ? { kind: node.callee.name === "Set" ? "Set" : "Map", size: entries.elements.length } : null;
|
|
@@ -6745,10 +6860,10 @@ var NON_RETAINING_BUILTINS = /* @__PURE__ */ new Map(
|
|
|
6745
6860
|
);
|
|
6746
6861
|
function isNonRetainingBuiltinCall(node, argument) {
|
|
6747
6862
|
const callee = node.callee;
|
|
6748
|
-
if (callee.type ===
|
|
6863
|
+
if (callee.type === AST_NODE_TYPES35.Identifier && callee.name === "structuredClone") {
|
|
6749
6864
|
return true;
|
|
6750
6865
|
}
|
|
6751
|
-
if (callee.type !==
|
|
6866
|
+
if (callee.type !== AST_NODE_TYPES35.MemberExpression || callee.computed || callee.object.type !== AST_NODE_TYPES35.Identifier || callee.property.type !== AST_NODE_TYPES35.Identifier) {
|
|
6752
6867
|
return false;
|
|
6753
6868
|
}
|
|
6754
6869
|
const members = NON_RETAINING_BUILTINS.get(callee.object.name);
|
|
@@ -6762,38 +6877,38 @@ function isNonRetainingBuiltinCall(node, argument) {
|
|
|
6762
6877
|
}
|
|
6763
6878
|
function isSafeRead(identifier) {
|
|
6764
6879
|
const parent = identifier.parent;
|
|
6765
|
-
if (parent.type ===
|
|
6880
|
+
if (parent.type === AST_NODE_TYPES35.MemberExpression) {
|
|
6766
6881
|
if (parent.object !== identifier) {
|
|
6767
6882
|
return true;
|
|
6768
6883
|
}
|
|
6769
6884
|
const grandparent = parent.parent;
|
|
6770
|
-
if (grandparent.type ===
|
|
6885
|
+
if (grandparent.type === AST_NODE_TYPES35.AssignmentExpression && grandparent.left === parent) {
|
|
6771
6886
|
return false;
|
|
6772
6887
|
}
|
|
6773
|
-
if (grandparent.type ===
|
|
6888
|
+
if (grandparent.type === AST_NODE_TYPES35.UpdateExpression) {
|
|
6774
6889
|
return false;
|
|
6775
6890
|
}
|
|
6776
|
-
if (grandparent.type ===
|
|
6891
|
+
if (grandparent.type === AST_NODE_TYPES35.UnaryExpression && grandparent.operator === "delete") {
|
|
6777
6892
|
return false;
|
|
6778
6893
|
}
|
|
6779
|
-
if (!parent.computed && parent.property.type ===
|
|
6894
|
+
if (!parent.computed && parent.property.type === AST_NODE_TYPES35.Identifier && MUTATING_METHODS.has(parent.property.name) && grandparent.type === AST_NODE_TYPES35.CallExpression && grandparent.callee === parent) {
|
|
6780
6895
|
return false;
|
|
6781
6896
|
}
|
|
6782
6897
|
return true;
|
|
6783
6898
|
}
|
|
6784
|
-
if (parent.type ===
|
|
6899
|
+
if (parent.type === AST_NODE_TYPES35.ForOfStatement && parent.right === identifier) {
|
|
6785
6900
|
return true;
|
|
6786
6901
|
}
|
|
6787
|
-
if (parent.type ===
|
|
6902
|
+
if (parent.type === AST_NODE_TYPES35.SpreadElement) {
|
|
6788
6903
|
return true;
|
|
6789
6904
|
}
|
|
6790
|
-
if (parent.type ===
|
|
6905
|
+
if (parent.type === AST_NODE_TYPES35.BinaryExpression) {
|
|
6791
6906
|
return true;
|
|
6792
6907
|
}
|
|
6793
|
-
if (parent.type ===
|
|
6908
|
+
if (parent.type === AST_NODE_TYPES35.CallExpression && parent.arguments.includes(identifier) && isNonRetainingBuiltinCall(parent, identifier)) {
|
|
6794
6909
|
return true;
|
|
6795
6910
|
}
|
|
6796
|
-
if (parent.type ===
|
|
6911
|
+
if (parent.type === AST_NODE_TYPES35.UnaryExpression && parent.operator !== "delete") {
|
|
6797
6912
|
return true;
|
|
6798
6913
|
}
|
|
6799
6914
|
return false;
|
|
@@ -6848,7 +6963,7 @@ var prefer_module_level_constant_default = createRule({
|
|
|
6848
6963
|
if (reference.isWrite()) {
|
|
6849
6964
|
return false;
|
|
6850
6965
|
}
|
|
6851
|
-
if (reference.identifier.type !==
|
|
6966
|
+
if (reference.identifier.type !== AST_NODE_TYPES35.Identifier) {
|
|
6852
6967
|
return false;
|
|
6853
6968
|
}
|
|
6854
6969
|
if (!isSafeRead(reference.identifier)) {
|
|
@@ -6860,10 +6975,10 @@ var prefer_module_level_constant_default = createRule({
|
|
|
6860
6975
|
return {
|
|
6861
6976
|
VariableDeclarator(node) {
|
|
6862
6977
|
const declaration = node.parent;
|
|
6863
|
-
if (declaration.type !==
|
|
6978
|
+
if (declaration.type !== AST_NODE_TYPES35.VariableDeclaration || declaration.kind !== "const" || declaration.declare === true) {
|
|
6864
6979
|
return;
|
|
6865
6980
|
}
|
|
6866
|
-
if (node.id.type !==
|
|
6981
|
+
if (node.id.type !== AST_NODE_TYPES35.Identifier || node.init === null) {
|
|
6867
6982
|
return;
|
|
6868
6983
|
}
|
|
6869
6984
|
if (enclosingFunction2(node) === null) {
|
|
@@ -6890,7 +7005,7 @@ var prefer_module_level_constant_default = createRule({
|
|
|
6890
7005
|
});
|
|
6891
7006
|
|
|
6892
7007
|
// src/rules/prefer-module-level-schema.ts
|
|
6893
|
-
import { AST_NODE_TYPES as
|
|
7008
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES36 } from "@typescript-eslint/utils";
|
|
6894
7009
|
|
|
6895
7010
|
// src/rules/_zod.ts
|
|
6896
7011
|
var ZOD_PREFIX_RE = /^Z[A-Z]/;
|
|
@@ -6956,9 +7071,9 @@ var I18N_RECEIVER_NAMES = /* @__PURE__ */ new Set([
|
|
|
6956
7071
|
"intl"
|
|
6957
7072
|
]);
|
|
6958
7073
|
var FUNCTION_TYPES6 = /* @__PURE__ */ new Set([
|
|
6959
|
-
|
|
6960
|
-
|
|
6961
|
-
|
|
7074
|
+
AST_NODE_TYPES36.ArrowFunctionExpression,
|
|
7075
|
+
AST_NODE_TYPES36.FunctionDeclaration,
|
|
7076
|
+
AST_NODE_TYPES36.FunctionExpression
|
|
6962
7077
|
]);
|
|
6963
7078
|
function schemaExpression(node) {
|
|
6964
7079
|
let current = node;
|
|
@@ -6967,10 +7082,10 @@ function schemaExpression(node) {
|
|
|
6967
7082
|
if (parent === void 0) {
|
|
6968
7083
|
return current;
|
|
6969
7084
|
}
|
|
6970
|
-
if (parent.type ===
|
|
7085
|
+
if (parent.type === AST_NODE_TYPES36.MemberExpression && parent.object === current && !parent.computed && parent.property.type === AST_NODE_TYPES36.Identifier && TERMINAL_METHODS.has(parent.property.name)) {
|
|
6971
7086
|
return current;
|
|
6972
7087
|
}
|
|
6973
|
-
if (parent.type ===
|
|
7088
|
+
if (parent.type === AST_NODE_TYPES36.MemberExpression && parent.object === current || parent.type === AST_NODE_TYPES36.CallExpression && parent.callee === current || parent.type === AST_NODE_TYPES36.TSAsExpression && parent.expression === current || parent.type === AST_NODE_TYPES36.TSNonNullExpression && parent.expression === current) {
|
|
6974
7089
|
current = parent;
|
|
6975
7090
|
continue;
|
|
6976
7091
|
}
|
|
@@ -7021,22 +7136,22 @@ function subtreeSome(root, predicate) {
|
|
|
7021
7136
|
function readsReceiver(node) {
|
|
7022
7137
|
return subtreeSome(
|
|
7023
7138
|
node,
|
|
7024
|
-
(inner) => inner.type ===
|
|
7139
|
+
(inner) => inner.type === AST_NODE_TYPES36.ThisExpression || inner.type === AST_NODE_TYPES36.Super || inner.type === AST_NODE_TYPES36.Identifier && inner.name === "arguments"
|
|
7025
7140
|
);
|
|
7026
7141
|
}
|
|
7027
7142
|
function buildsLocalizedText(node) {
|
|
7028
7143
|
return subtreeSome(node, (inner) => {
|
|
7029
|
-
if (inner.type ===
|
|
7144
|
+
if (inner.type === AST_NODE_TYPES36.TaggedTemplateExpression) {
|
|
7030
7145
|
return true;
|
|
7031
7146
|
}
|
|
7032
|
-
if (inner.type !==
|
|
7147
|
+
if (inner.type !== AST_NODE_TYPES36.CallExpression) {
|
|
7033
7148
|
return false;
|
|
7034
7149
|
}
|
|
7035
7150
|
const { callee } = inner;
|
|
7036
|
-
if (callee.type ===
|
|
7151
|
+
if (callee.type === AST_NODE_TYPES36.Identifier) {
|
|
7037
7152
|
return I18N_CALLEE_NAMES.has(callee.name);
|
|
7038
7153
|
}
|
|
7039
|
-
return callee.type ===
|
|
7154
|
+
return callee.type === AST_NODE_TYPES36.MemberExpression && !callee.computed && callee.object.type === AST_NODE_TYPES36.Identifier && I18N_RECEIVER_NAMES.has(callee.object.name);
|
|
7040
7155
|
});
|
|
7041
7156
|
}
|
|
7042
7157
|
function collectReferences(scope, out) {
|
|
@@ -7093,15 +7208,15 @@ var prefer_module_level_schema_default = createRule({
|
|
|
7093
7208
|
}
|
|
7094
7209
|
const zodNamespaces = /* @__PURE__ */ new Set();
|
|
7095
7210
|
function isZodCall(node) {
|
|
7096
|
-
return node.type ===
|
|
7211
|
+
return node.type === AST_NODE_TYPES36.CallExpression && node.callee.type === AST_NODE_TYPES36.MemberExpression && !node.callee.computed && node.callee.object.type === AST_NODE_TYPES36.Identifier && zodNamespaces.has(node.callee.object.name);
|
|
7097
7212
|
}
|
|
7098
7213
|
function isCovered(node) {
|
|
7099
7214
|
let current = node.parent ?? void 0;
|
|
7100
7215
|
while (current !== void 0) {
|
|
7101
|
-
if (current !== node && isZodCall(current) && current.callee.type ===
|
|
7216
|
+
if (current !== node && isZodCall(current) && current.callee.type === AST_NODE_TYPES36.MemberExpression && current.callee.property.type === AST_NODE_TYPES36.Identifier && factories.has(current.callee.property.name)) {
|
|
7102
7217
|
return true;
|
|
7103
7218
|
}
|
|
7104
|
-
if (current.type ===
|
|
7219
|
+
if (current.type === AST_NODE_TYPES36.CallExpression && (current.callee.type === AST_NODE_TYPES36.Identifier && MEMO_CALLEES.has(current.callee.name) || current.callee.type === AST_NODE_TYPES36.MemberExpression && !current.callee.computed && current.callee.property.type === AST_NODE_TYPES36.Identifier && MEMO_CALLEES.has(current.callee.property.name))) {
|
|
7105
7220
|
return true;
|
|
7106
7221
|
}
|
|
7107
7222
|
current = current.parent ?? void 0;
|
|
@@ -7116,11 +7231,11 @@ var prefer_module_level_schema_default = createRule({
|
|
|
7116
7231
|
if (parent === void 0) {
|
|
7117
7232
|
return confirmed;
|
|
7118
7233
|
}
|
|
7119
|
-
if (parent.type ===
|
|
7234
|
+
if (parent.type === AST_NODE_TYPES36.Property && parent.value === current || parent.type === AST_NODE_TYPES36.ObjectExpression || parent.type === AST_NODE_TYPES36.ArrayExpression) {
|
|
7120
7235
|
current = parent;
|
|
7121
7236
|
continue;
|
|
7122
7237
|
}
|
|
7123
|
-
if (parent.type ===
|
|
7238
|
+
if (parent.type === AST_NODE_TYPES36.CallExpression && parent.arguments.includes(current) && isSchemaComposition(parent)) {
|
|
7124
7239
|
current = schemaExpression(parent);
|
|
7125
7240
|
confirmed = current;
|
|
7126
7241
|
continue;
|
|
@@ -7130,7 +7245,7 @@ var prefer_module_level_schema_default = createRule({
|
|
|
7130
7245
|
}
|
|
7131
7246
|
function isSchemaComposition(node) {
|
|
7132
7247
|
const { callee } = node;
|
|
7133
|
-
const isCombinator = callee.type ===
|
|
7248
|
+
const isCombinator = callee.type === AST_NODE_TYPES36.MemberExpression && !callee.computed && callee.property.type === AST_NODE_TYPES36.Identifier && ZOD_COMBINATOR_METHODS.has(callee.property.name);
|
|
7134
7249
|
return isCombinator || isZodCall(node);
|
|
7135
7250
|
}
|
|
7136
7251
|
function closesOverNothing(node, enclosing) {
|
|
@@ -7164,13 +7279,13 @@ var prefer_module_level_schema_default = createRule({
|
|
|
7164
7279
|
}
|
|
7165
7280
|
function ownerName(enclosing) {
|
|
7166
7281
|
const parent = enclosing.parent ?? void 0;
|
|
7167
|
-
if (enclosing.type ===
|
|
7282
|
+
if (enclosing.type === AST_NODE_TYPES36.FunctionDeclaration && enclosing.id !== null) {
|
|
7168
7283
|
return enclosing.id.name;
|
|
7169
7284
|
}
|
|
7170
|
-
if (parent !== void 0 && parent.type ===
|
|
7285
|
+
if (parent !== void 0 && parent.type === AST_NODE_TYPES36.VariableDeclarator && parent.id.type === AST_NODE_TYPES36.Identifier) {
|
|
7171
7286
|
return parent.id.name;
|
|
7172
7287
|
}
|
|
7173
|
-
if (parent !== void 0 && (parent.type ===
|
|
7288
|
+
if (parent !== void 0 && (parent.type === AST_NODE_TYPES36.MethodDefinition || parent.type === AST_NODE_TYPES36.Property) && parent.key.type === AST_NODE_TYPES36.Identifier) {
|
|
7174
7289
|
return parent.key.name;
|
|
7175
7290
|
}
|
|
7176
7291
|
return "this function";
|
|
@@ -7181,7 +7296,7 @@ var prefer_module_level_schema_default = createRule({
|
|
|
7181
7296
|
return;
|
|
7182
7297
|
}
|
|
7183
7298
|
for (const specifier of node.specifiers) {
|
|
7184
|
-
if (specifier.type ===
|
|
7299
|
+
if (specifier.type === AST_NODE_TYPES36.ImportNamespaceSpecifier || specifier.type === AST_NODE_TYPES36.ImportDefaultSpecifier || specifier.type === AST_NODE_TYPES36.ImportSpecifier && specifier.imported.type === AST_NODE_TYPES36.Identifier && specifier.imported.name === "z") {
|
|
7185
7300
|
zodNamespaces.add(specifier.local.name);
|
|
7186
7301
|
}
|
|
7187
7302
|
}
|
|
@@ -7191,7 +7306,7 @@ var prefer_module_level_schema_default = createRule({
|
|
|
7191
7306
|
return;
|
|
7192
7307
|
}
|
|
7193
7308
|
const callee = node.callee;
|
|
7194
|
-
if (callee.property.type !==
|
|
7309
|
+
if (callee.property.type !== AST_NODE_TYPES36.Identifier) {
|
|
7195
7310
|
return;
|
|
7196
7311
|
}
|
|
7197
7312
|
const factory = callee.property.name;
|
|
@@ -7206,7 +7321,7 @@ var prefer_module_level_schema_default = createRule({
|
|
|
7206
7321
|
return;
|
|
7207
7322
|
}
|
|
7208
7323
|
const shape = node.arguments[0];
|
|
7209
|
-
if (shape !== void 0 && shape.type ===
|
|
7324
|
+
if (shape !== void 0 && shape.type === AST_NODE_TYPES36.ObjectExpression && shape.properties.length < minProperties) {
|
|
7210
7325
|
return;
|
|
7211
7326
|
}
|
|
7212
7327
|
const expression = schemaExpression(node);
|
|
@@ -7233,73 +7348,6 @@ var prefer_module_level_schema_default = createRule({
|
|
|
7233
7348
|
}
|
|
7234
7349
|
});
|
|
7235
7350
|
|
|
7236
|
-
// src/rules/prefer-non-nullable-collection.ts
|
|
7237
|
-
import { AST_NODE_TYPES as AST_NODE_TYPES36 } from "@typescript-eslint/utils";
|
|
7238
|
-
var ARRAY_TYPE_NAMES = /* @__PURE__ */ new Set(["Array", "ReadonlyArray"]);
|
|
7239
|
-
function propertyName(node) {
|
|
7240
|
-
const key = node.key;
|
|
7241
|
-
if (key.type === AST_NODE_TYPES36.Identifier) return key.name;
|
|
7242
|
-
if (key.type === AST_NODE_TYPES36.Literal) return String(key.value);
|
|
7243
|
-
return "collection";
|
|
7244
|
-
}
|
|
7245
|
-
function isArrayType(node) {
|
|
7246
|
-
if (node.type === AST_NODE_TYPES36.TSArrayType) return true;
|
|
7247
|
-
return node.type === AST_NODE_TYPES36.TSTypeReference && node.typeName.type === AST_NODE_TYPES36.Identifier && ARRAY_TYPE_NAMES.has(node.typeName.name);
|
|
7248
|
-
}
|
|
7249
|
-
function isNullishType(node) {
|
|
7250
|
-
return node.type === AST_NODE_TYPES36.TSNullKeyword || node.type === AST_NODE_TYPES36.TSUndefinedKeyword;
|
|
7251
|
-
}
|
|
7252
|
-
function isNullableArrayOnly(node) {
|
|
7253
|
-
const values = node.types.filter((member) => !isNullishType(member));
|
|
7254
|
-
return values.length > 0 && values.length < node.types.length && values.every(isArrayType);
|
|
7255
|
-
}
|
|
7256
|
-
var prefer_non_nullable_collection_default = createRule({
|
|
7257
|
-
name: "prefer-non-nullable-collection",
|
|
7258
|
-
meta: {
|
|
7259
|
-
type: "suggestion",
|
|
7260
|
-
docs: {
|
|
7261
|
-
description: "Require declared data-shape properties and direct aliases to use non-null arrays instead of explicit nullish unions."
|
|
7262
|
-
},
|
|
7263
|
-
schema: [],
|
|
7264
|
-
messages: {
|
|
7265
|
-
preferNonNullableCollection: "`{{name}}` is a nullable array, so nullish and `[]` represent the same empty collection. Use a non-null array and default omitted values to `[]`."
|
|
7266
|
-
}
|
|
7267
|
-
},
|
|
7268
|
-
defaultOptions: [],
|
|
7269
|
-
create(context) {
|
|
7270
|
-
const normalizedFilename = context.filename.replaceAll("\\", "/");
|
|
7271
|
-
if (isTestFile(context.filename) || isGeneratedFile(context.filename, context.sourceCode.text) || /\/(?:vendor|vendored)\//u.test(normalizedFilename)) {
|
|
7272
|
-
return {};
|
|
7273
|
-
}
|
|
7274
|
-
function checkOptionalProperty(node) {
|
|
7275
|
-
if (node.optional) return;
|
|
7276
|
-
const annotation = node.typeAnnotation?.typeAnnotation;
|
|
7277
|
-
if (annotation === void 0) return;
|
|
7278
|
-
if (annotation.type !== AST_NODE_TYPES36.TSUnionType || !isNullableArrayOnly(annotation)) {
|
|
7279
|
-
return;
|
|
7280
|
-
}
|
|
7281
|
-
context.report({
|
|
7282
|
-
node,
|
|
7283
|
-
messageId: "preferNonNullableCollection",
|
|
7284
|
-
data: { name: propertyName(node) }
|
|
7285
|
-
});
|
|
7286
|
-
}
|
|
7287
|
-
return {
|
|
7288
|
-
TSPropertySignature: checkOptionalProperty,
|
|
7289
|
-
PropertyDefinition: checkOptionalProperty,
|
|
7290
|
-
TSTypeAliasDeclaration(node) {
|
|
7291
|
-
if (node.typeAnnotation.type !== AST_NODE_TYPES36.TSUnionType) return;
|
|
7292
|
-
if (!isNullableArrayOnly(node.typeAnnotation)) return;
|
|
7293
|
-
context.report({
|
|
7294
|
-
node,
|
|
7295
|
-
messageId: "preferNonNullableCollection",
|
|
7296
|
-
data: { name: node.id.name }
|
|
7297
|
-
});
|
|
7298
|
-
}
|
|
7299
|
-
};
|
|
7300
|
-
}
|
|
7301
|
-
});
|
|
7302
|
-
|
|
7303
7351
|
// src/rules/prefer-native-random-uuid.ts
|
|
7304
7352
|
import { AST_NODE_TYPES as AST_NODE_TYPES37, ASTUtils as ASTUtils3 } from "@typescript-eslint/utils";
|
|
7305
7353
|
function requireUuid(node) {
|
|
@@ -7386,14 +7434,81 @@ var prefer_native_random_uuid_default = createRule({
|
|
|
7386
7434
|
}
|
|
7387
7435
|
});
|
|
7388
7436
|
|
|
7389
|
-
// src/rules/prefer-
|
|
7437
|
+
// src/rules/prefer-non-nullable-collection.ts
|
|
7390
7438
|
import { AST_NODE_TYPES as AST_NODE_TYPES38 } from "@typescript-eslint/utils";
|
|
7439
|
+
var ARRAY_TYPE_NAMES = /* @__PURE__ */ new Set(["Array", "ReadonlyArray"]);
|
|
7440
|
+
function propertyName(node) {
|
|
7441
|
+
const key = node.key;
|
|
7442
|
+
if (key.type === AST_NODE_TYPES38.Identifier) return key.name;
|
|
7443
|
+
if (key.type === AST_NODE_TYPES38.Literal) return String(key.value);
|
|
7444
|
+
return "collection";
|
|
7445
|
+
}
|
|
7446
|
+
function isArrayType(node) {
|
|
7447
|
+
if (node.type === AST_NODE_TYPES38.TSArrayType) return true;
|
|
7448
|
+
return node.type === AST_NODE_TYPES38.TSTypeReference && node.typeName.type === AST_NODE_TYPES38.Identifier && ARRAY_TYPE_NAMES.has(node.typeName.name);
|
|
7449
|
+
}
|
|
7450
|
+
function isNullishType(node) {
|
|
7451
|
+
return node.type === AST_NODE_TYPES38.TSNullKeyword || node.type === AST_NODE_TYPES38.TSUndefinedKeyword;
|
|
7452
|
+
}
|
|
7453
|
+
function isNullableArrayOnly(node) {
|
|
7454
|
+
const values = node.types.filter((member) => !isNullishType(member));
|
|
7455
|
+
return values.length > 0 && values.length < node.types.length && values.every(isArrayType);
|
|
7456
|
+
}
|
|
7457
|
+
var prefer_non_nullable_collection_default = createRule({
|
|
7458
|
+
name: "prefer-non-nullable-collection",
|
|
7459
|
+
meta: {
|
|
7460
|
+
type: "suggestion",
|
|
7461
|
+
docs: {
|
|
7462
|
+
description: "Require declared data-shape properties and direct aliases to use non-null arrays instead of explicit nullish unions."
|
|
7463
|
+
},
|
|
7464
|
+
schema: [],
|
|
7465
|
+
messages: {
|
|
7466
|
+
preferNonNullableCollection: "`{{name}}` is a nullable array, so nullish and `[]` represent the same empty collection. Use a non-null array and default omitted values to `[]`."
|
|
7467
|
+
}
|
|
7468
|
+
},
|
|
7469
|
+
defaultOptions: [],
|
|
7470
|
+
create(context) {
|
|
7471
|
+
const normalizedFilename = context.filename.replaceAll("\\", "/");
|
|
7472
|
+
if (isTestFile(context.filename) || isGeneratedFile(context.filename, context.sourceCode.text) || /\/(?:vendor|vendored)\//u.test(normalizedFilename)) {
|
|
7473
|
+
return {};
|
|
7474
|
+
}
|
|
7475
|
+
function checkOptionalProperty(node) {
|
|
7476
|
+
if (node.optional) return;
|
|
7477
|
+
const annotation = node.typeAnnotation?.typeAnnotation;
|
|
7478
|
+
if (annotation === void 0) return;
|
|
7479
|
+
if (annotation.type !== AST_NODE_TYPES38.TSUnionType || !isNullableArrayOnly(annotation)) {
|
|
7480
|
+
return;
|
|
7481
|
+
}
|
|
7482
|
+
context.report({
|
|
7483
|
+
node,
|
|
7484
|
+
messageId: "preferNonNullableCollection",
|
|
7485
|
+
data: { name: propertyName(node) }
|
|
7486
|
+
});
|
|
7487
|
+
}
|
|
7488
|
+
return {
|
|
7489
|
+
TSPropertySignature: checkOptionalProperty,
|
|
7490
|
+
PropertyDefinition: checkOptionalProperty,
|
|
7491
|
+
TSTypeAliasDeclaration(node) {
|
|
7492
|
+
if (node.typeAnnotation.type !== AST_NODE_TYPES38.TSUnionType) return;
|
|
7493
|
+
if (!isNullableArrayOnly(node.typeAnnotation)) return;
|
|
7494
|
+
context.report({
|
|
7495
|
+
node,
|
|
7496
|
+
messageId: "preferNonNullableCollection",
|
|
7497
|
+
data: { name: node.id.name }
|
|
7498
|
+
});
|
|
7499
|
+
}
|
|
7500
|
+
};
|
|
7501
|
+
}
|
|
7502
|
+
});
|
|
7503
|
+
|
|
7504
|
+
// src/rules/prefer-schema-for-api-payload.ts
|
|
7505
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES39 } from "@typescript-eslint/utils";
|
|
7391
7506
|
var unwrap4 = (node) => {
|
|
7392
7507
|
let current = node;
|
|
7393
7508
|
while (current !== null && current !== void 0) {
|
|
7394
|
-
if (current.type ===
|
|
7509
|
+
if (current.type === AST_NODE_TYPES39.TSAsExpression || current.type === AST_NODE_TYPES39.TSTypeAssertion || current.type === AST_NODE_TYPES39.TSNonNullExpression || current.type === AST_NODE_TYPES39.TSSatisfiesExpression) {
|
|
7395
7510
|
current = current.expression;
|
|
7396
|
-
} else if (current.type ===
|
|
7511
|
+
} else if (current.type === AST_NODE_TYPES39.ChainExpression) {
|
|
7397
7512
|
current = current.expression;
|
|
7398
7513
|
} else {
|
|
7399
7514
|
break;
|
|
@@ -7408,23 +7523,23 @@ var PROMISE_CHAIN_METHODS = /* @__PURE__ */ new Set([
|
|
|
7408
7523
|
]);
|
|
7409
7524
|
var isSchemaParseReference = (node) => {
|
|
7410
7525
|
const inner = unwrap4(node);
|
|
7411
|
-
return inner !== null && inner.type ===
|
|
7526
|
+
return inner !== null && inner.type === AST_NODE_TYPES39.MemberExpression && !inner.computed && inner.property.type === AST_NODE_TYPES39.Identifier && (inner.property.name === "parse" || inner.property.name === "safeParse");
|
|
7412
7527
|
};
|
|
7413
7528
|
var isRawPayloadSource = (node) => {
|
|
7414
7529
|
let current = unwrap4(node);
|
|
7415
7530
|
if (current === null) return false;
|
|
7416
|
-
if (current.type ===
|
|
7531
|
+
if (current.type === AST_NODE_TYPES39.AwaitExpression) {
|
|
7417
7532
|
current = unwrap4(current.argument);
|
|
7418
7533
|
}
|
|
7419
|
-
if (current === null || current.type !==
|
|
7534
|
+
if (current === null || current.type !== AST_NODE_TYPES39.CallExpression) {
|
|
7420
7535
|
return false;
|
|
7421
7536
|
}
|
|
7422
7537
|
const callee = unwrap4(current.callee);
|
|
7423
|
-
if (callee === null || callee.type !==
|
|
7538
|
+
if (callee === null || callee.type !== AST_NODE_TYPES39.MemberExpression) {
|
|
7424
7539
|
return false;
|
|
7425
7540
|
}
|
|
7426
7541
|
const property = unwrap4(callee.property);
|
|
7427
|
-
if (property === null || property.type !==
|
|
7542
|
+
if (property === null || property.type !== AST_NODE_TYPES39.Identifier) {
|
|
7428
7543
|
return false;
|
|
7429
7544
|
}
|
|
7430
7545
|
if (property.name === "json") {
|
|
@@ -7434,16 +7549,16 @@ var isRawPayloadSource = (node) => {
|
|
|
7434
7549
|
return !current.arguments.some(isSchemaParseReference) && isRawPayloadSource(callee.object);
|
|
7435
7550
|
}
|
|
7436
7551
|
const object = unwrap4(callee.object);
|
|
7437
|
-
return property.name === "parse" && object !== null && object.type ===
|
|
7552
|
+
return property.name === "parse" && object !== null && object.type === AST_NODE_TYPES39.Identifier && object.name === "JSON" && !isLocalFileRead(current.arguments[0]);
|
|
7438
7553
|
};
|
|
7439
7554
|
var FILE_READ_RE = /^(readFile|readFileSync|readJson|readJsonSync|readJSON)$/;
|
|
7440
7555
|
var isLocalFileRead = (node) => {
|
|
7441
7556
|
let found = false;
|
|
7442
7557
|
const visit = (current) => {
|
|
7443
7558
|
if (found || current === null || current === void 0) return;
|
|
7444
|
-
if (current.type ===
|
|
7559
|
+
if (current.type === AST_NODE_TYPES39.CallExpression) {
|
|
7445
7560
|
const callee = unwrap4(current.callee);
|
|
7446
|
-
const name = callee?.type ===
|
|
7561
|
+
const name = callee?.type === AST_NODE_TYPES39.Identifier ? callee.name : callee?.type === AST_NODE_TYPES39.MemberExpression && !callee.computed && callee.property.type === AST_NODE_TYPES39.Identifier ? callee.property.name : null;
|
|
7447
7562
|
if (name !== null && FILE_READ_RE.test(name)) {
|
|
7448
7563
|
found = true;
|
|
7449
7564
|
return;
|
|
@@ -7465,15 +7580,15 @@ var isLocalFileRead = (node) => {
|
|
|
7465
7580
|
var ASSERTION_CALLEE_RE = /^(expect|assert|should|invariant)$/;
|
|
7466
7581
|
var isInsideAssertion = (node) => {
|
|
7467
7582
|
for (let current = node.parent; current !== void 0 && current !== null; current = current.parent) {
|
|
7468
|
-
if (current.type !==
|
|
7583
|
+
if (current.type !== AST_NODE_TYPES39.CallExpression) continue;
|
|
7469
7584
|
let callee = current.callee;
|
|
7470
|
-
while (callee.type ===
|
|
7585
|
+
while (callee.type === AST_NODE_TYPES39.MemberExpression) {
|
|
7471
7586
|
callee = callee.object;
|
|
7472
7587
|
}
|
|
7473
|
-
if (callee.type ===
|
|
7588
|
+
if (callee.type === AST_NODE_TYPES39.CallExpression) {
|
|
7474
7589
|
callee = callee.callee;
|
|
7475
7590
|
}
|
|
7476
|
-
if (callee.type ===
|
|
7591
|
+
if (callee.type === AST_NODE_TYPES39.Identifier && ASSERTION_CALLEE_RE.test(callee.name)) {
|
|
7477
7592
|
return true;
|
|
7478
7593
|
}
|
|
7479
7594
|
}
|
|
@@ -7492,39 +7607,39 @@ var GUARD_NAME_RE = /^(?:is|validate|parse|assert|decode|coerce)[A-Z]/;
|
|
|
7492
7607
|
var isValidationRead = (node) => {
|
|
7493
7608
|
let current = node;
|
|
7494
7609
|
let parent = current.parent;
|
|
7495
|
-
while (parent !== null && parent !== void 0 && (parent.type ===
|
|
7610
|
+
while (parent !== null && parent !== void 0 && (parent.type === AST_NODE_TYPES39.TSAsExpression || parent.type === AST_NODE_TYPES39.TSTypeAssertion || parent.type === AST_NODE_TYPES39.TSNonNullExpression || parent.type === AST_NODE_TYPES39.TSSatisfiesExpression || parent.type === AST_NODE_TYPES39.ChainExpression)) {
|
|
7496
7611
|
current = parent;
|
|
7497
7612
|
parent = parent.parent;
|
|
7498
7613
|
}
|
|
7499
7614
|
if (parent === null || parent === void 0) return false;
|
|
7500
|
-
if (parent.type ===
|
|
7615
|
+
if (parent.type === AST_NODE_TYPES39.UnaryExpression && parent.operator === "typeof" && parent.argument === current) {
|
|
7501
7616
|
return true;
|
|
7502
7617
|
}
|
|
7503
|
-
if (parent.type !==
|
|
7618
|
+
if (parent.type !== AST_NODE_TYPES39.CallExpression || !parent.arguments.some((arg) => arg === current)) {
|
|
7504
7619
|
return false;
|
|
7505
7620
|
}
|
|
7506
7621
|
const callee = parent.callee;
|
|
7507
|
-
if (callee.type ===
|
|
7622
|
+
if (callee.type === AST_NODE_TYPES39.MemberExpression && !callee.computed && callee.object.type === AST_NODE_TYPES39.Identifier && callee.object.name === "Array" && callee.property.type === AST_NODE_TYPES39.Identifier && callee.property.name === "isArray") {
|
|
7508
7623
|
return parent.arguments.length === 1;
|
|
7509
7624
|
}
|
|
7510
|
-
return callee.type ===
|
|
7625
|
+
return callee.type === AST_NODE_TYPES39.Identifier && GUARD_NAME_RE.test(callee.name);
|
|
7511
7626
|
};
|
|
7512
7627
|
var isGuardTestPosition = (node) => {
|
|
7513
7628
|
let current = node;
|
|
7514
7629
|
let parent = current.parent;
|
|
7515
7630
|
while (parent !== void 0 && parent !== null) {
|
|
7516
7631
|
switch (parent.type) {
|
|
7517
|
-
case
|
|
7518
|
-
case
|
|
7519
|
-
case
|
|
7632
|
+
case AST_NODE_TYPES39.UnaryExpression:
|
|
7633
|
+
case AST_NODE_TYPES39.LogicalExpression:
|
|
7634
|
+
case AST_NODE_TYPES39.ChainExpression:
|
|
7520
7635
|
current = parent;
|
|
7521
7636
|
parent = parent.parent;
|
|
7522
7637
|
continue;
|
|
7523
|
-
case
|
|
7524
|
-
case
|
|
7525
|
-
case
|
|
7526
|
-
case
|
|
7527
|
-
case
|
|
7638
|
+
case AST_NODE_TYPES39.IfStatement:
|
|
7639
|
+
case AST_NODE_TYPES39.ConditionalExpression:
|
|
7640
|
+
case AST_NODE_TYPES39.WhileStatement:
|
|
7641
|
+
case AST_NODE_TYPES39.DoWhileStatement:
|
|
7642
|
+
case AST_NODE_TYPES39.ForStatement:
|
|
7528
7643
|
return parent.test === current;
|
|
7529
7644
|
default:
|
|
7530
7645
|
return false;
|
|
@@ -7534,7 +7649,7 @@ var isGuardTestPosition = (node) => {
|
|
|
7534
7649
|
};
|
|
7535
7650
|
var isUnvalidatedVariableRef = (node, scope, tracked) => {
|
|
7536
7651
|
const unwrapped = unwrap4(node);
|
|
7537
|
-
if (unwrapped === null || unwrapped.type !==
|
|
7652
|
+
if (unwrapped === null || unwrapped.type !== AST_NODE_TYPES39.Identifier) {
|
|
7538
7653
|
return false;
|
|
7539
7654
|
}
|
|
7540
7655
|
const variable = findVariable2(scope, unwrapped.name);
|
|
@@ -7577,11 +7692,11 @@ var prefer_schema_for_api_payload_default = createRule({
|
|
|
7577
7692
|
return {
|
|
7578
7693
|
VariableDeclarator(node) {
|
|
7579
7694
|
const scope = context.sourceCode.getScope(node);
|
|
7580
|
-
if (node.id.type ===
|
|
7695
|
+
if (node.id.type === AST_NODE_TYPES39.Identifier) {
|
|
7581
7696
|
trackInitializer(node);
|
|
7582
7697
|
return;
|
|
7583
7698
|
}
|
|
7584
|
-
if (node.id.type ===
|
|
7699
|
+
if (node.id.type === AST_NODE_TYPES39.ObjectPattern || node.id.type === AST_NODE_TYPES39.ArrayPattern) {
|
|
7585
7700
|
if (isRawPayloadSource(node.init)) {
|
|
7586
7701
|
if (!isFullyNarrowedPattern(node)) {
|
|
7587
7702
|
context.report({ node: node.id, messageId: "unparsedJsonAccess" });
|
|
@@ -7595,7 +7710,7 @@ var prefer_schema_for_api_payload_default = createRule({
|
|
|
7595
7710
|
},
|
|
7596
7711
|
AssignmentExpression(node) {
|
|
7597
7712
|
const scope = context.sourceCode.getScope(node);
|
|
7598
|
-
if (node.left.type ===
|
|
7713
|
+
if (node.left.type === AST_NODE_TYPES39.Identifier) {
|
|
7599
7714
|
const variable = findVariable2(scope, node.left.name);
|
|
7600
7715
|
if (variable === null) return;
|
|
7601
7716
|
if (isRawPayloadSource(node.right)) {
|
|
@@ -7605,7 +7720,7 @@ var prefer_schema_for_api_payload_default = createRule({
|
|
|
7605
7720
|
}
|
|
7606
7721
|
return;
|
|
7607
7722
|
}
|
|
7608
|
-
if (node.left.type ===
|
|
7723
|
+
if (node.left.type === AST_NODE_TYPES39.ObjectPattern || node.left.type === AST_NODE_TYPES39.ArrayPattern) {
|
|
7609
7724
|
if (isRawPayloadSource(node.right)) {
|
|
7610
7725
|
context.report({
|
|
7611
7726
|
node: node.left,
|
|
@@ -7622,15 +7737,15 @@ var prefer_schema_for_api_payload_default = createRule({
|
|
|
7622
7737
|
}
|
|
7623
7738
|
},
|
|
7624
7739
|
CallExpression(node) {
|
|
7625
|
-
if (node.callee.type !==
|
|
7740
|
+
if (node.callee.type !== AST_NODE_TYPES39.Identifier) return;
|
|
7626
7741
|
if (!GUARD_NAME_RE.test(node.callee.name) && !isGuardTestPosition(node)) {
|
|
7627
7742
|
return;
|
|
7628
7743
|
}
|
|
7629
7744
|
const scope = context.sourceCode.getScope(node);
|
|
7630
7745
|
for (const arg of node.arguments) {
|
|
7631
|
-
if (arg.type ===
|
|
7746
|
+
if (arg.type === AST_NODE_TYPES39.SpreadElement) continue;
|
|
7632
7747
|
const unwrapped = unwrap4(arg);
|
|
7633
|
-
if (unwrapped === null || unwrapped.type !==
|
|
7748
|
+
if (unwrapped === null || unwrapped.type !== AST_NODE_TYPES39.Identifier) {
|
|
7634
7749
|
continue;
|
|
7635
7750
|
}
|
|
7636
7751
|
const variable = findVariable2(scope, unwrapped.name);
|
|
@@ -7644,13 +7759,13 @@ var prefer_schema_for_api_payload_default = createRule({
|
|
|
7644
7759
|
const obj = unwrap4(node.object);
|
|
7645
7760
|
if (isRawPayloadSource(obj)) {
|
|
7646
7761
|
const parent = node.parent;
|
|
7647
|
-
if (parent.type ===
|
|
7762
|
+
if (parent.type === AST_NODE_TYPES39.CallExpression && parent.callee === node && node.property.type === AST_NODE_TYPES39.Identifier && (node.property.name === "parse" || node.property.name === "safeParse" || PROMISE_CHAIN_METHODS.has(node.property.name))) {
|
|
7648
7763
|
return;
|
|
7649
7764
|
}
|
|
7650
7765
|
context.report({ node, messageId: "unparsedJsonAccess" });
|
|
7651
7766
|
return;
|
|
7652
7767
|
}
|
|
7653
|
-
if (obj !== null && obj.type ===
|
|
7768
|
+
if (obj !== null && obj.type === AST_NODE_TYPES39.Identifier && isUnvalidatedVariableRef(obj, scope, unvalidatedVariables)) {
|
|
7654
7769
|
context.report({ node, messageId: "unparsedJsonAccess" });
|
|
7655
7770
|
const variable = findVariable2(scope, obj.name);
|
|
7656
7771
|
if (variable !== null) {
|
|
@@ -7663,7 +7778,7 @@ var prefer_schema_for_api_payload_default = createRule({
|
|
|
7663
7778
|
});
|
|
7664
7779
|
|
|
7665
7780
|
// src/rules/prefer-semantic-colors.ts
|
|
7666
|
-
import { AST_NODE_TYPES as
|
|
7781
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES40 } from "@typescript-eslint/utils";
|
|
7667
7782
|
import { existsSync, readdirSync, readFileSync } from "fs";
|
|
7668
7783
|
import { dirname, join, parse } from "path";
|
|
7669
7784
|
|
|
@@ -7763,8 +7878,8 @@ var SVG_EXEMPT_COLOR_VALUES = /* @__PURE__ */ new Set([
|
|
|
7763
7878
|
]);
|
|
7764
7879
|
function jsxElementName(node) {
|
|
7765
7880
|
const name = node.openingElement.name;
|
|
7766
|
-
if (name.type ===
|
|
7767
|
-
if (name.type ===
|
|
7881
|
+
if (name.type === AST_NODE_TYPES40.JSXIdentifier) return name.name;
|
|
7882
|
+
if (name.type === AST_NODE_TYPES40.JSXMemberExpression && name.property.type === AST_NODE_TYPES40.JSXIdentifier) {
|
|
7768
7883
|
return name.property.name;
|
|
7769
7884
|
}
|
|
7770
7885
|
return null;
|
|
@@ -7790,7 +7905,7 @@ var EMAIL_OR_PDF_MODULE_RE = /^@react-(?:email|pdf)\//;
|
|
|
7790
7905
|
var isInsideSvg = (node) => {
|
|
7791
7906
|
let current = node.parent;
|
|
7792
7907
|
while (current !== void 0 && current !== null) {
|
|
7793
|
-
if (current.type ===
|
|
7908
|
+
if (current.type === AST_NODE_TYPES40.JSXElement) {
|
|
7794
7909
|
const name = jsxElementName(current);
|
|
7795
7910
|
if (name !== null && isSvgLikeElementName(name)) return true;
|
|
7796
7911
|
}
|
|
@@ -7801,7 +7916,7 @@ var isInsideSvg = (node) => {
|
|
|
7801
7916
|
var isInsideIconFactoryPath = (node) => {
|
|
7802
7917
|
let current = node.parent;
|
|
7803
7918
|
while (current !== void 0 && current !== null) {
|
|
7804
|
-
if (current.type ===
|
|
7919
|
+
if (current.type === AST_NODE_TYPES40.Property && propName(current.key) === "path" && current.parent.type === AST_NODE_TYPES40.ObjectExpression && current.parent.parent.type === AST_NODE_TYPES40.CallExpression && current.parent.parent.callee.type === AST_NODE_TYPES40.Identifier && current.parent.parent.callee.name === "createIcon") {
|
|
7805
7920
|
return true;
|
|
7806
7921
|
}
|
|
7807
7922
|
current = current.parent;
|
|
@@ -7938,12 +8053,12 @@ var hasSemanticTokenSystem = (filename) => {
|
|
|
7938
8053
|
return root !== null && workspaceHasMarker(root);
|
|
7939
8054
|
};
|
|
7940
8055
|
var propName = (key) => {
|
|
7941
|
-
if (key.type ===
|
|
7942
|
-
if (key.type ===
|
|
8056
|
+
if (key.type === AST_NODE_TYPES40.Identifier) return key.name;
|
|
8057
|
+
if (key.type === AST_NODE_TYPES40.Literal && typeof key.value === "string") return key.value;
|
|
7943
8058
|
return null;
|
|
7944
8059
|
};
|
|
7945
8060
|
var staticallyImportsEmailOrPdfRenderer = (program) => program.body.some((statement) => {
|
|
7946
|
-
if (statement.type !==
|
|
8061
|
+
if (statement.type !== AST_NODE_TYPES40.ImportDeclaration && statement.type !== AST_NODE_TYPES40.ExportNamedDeclaration && statement.type !== AST_NODE_TYPES40.ExportAllDeclaration) {
|
|
7947
8062
|
return false;
|
|
7948
8063
|
}
|
|
7949
8064
|
return statement.source !== null && typeof statement.source.value === "string" && EMAIL_OR_PDF_MODULE_RE.test(statement.source.value);
|
|
@@ -7995,27 +8110,27 @@ var prefer_semantic_colors_default = createRule({
|
|
|
7995
8110
|
const checkClassNode = (node) => {
|
|
7996
8111
|
if (node === null) return;
|
|
7997
8112
|
switch (node.type) {
|
|
7998
|
-
case
|
|
8113
|
+
case AST_NODE_TYPES40.Literal:
|
|
7999
8114
|
if (typeof node.value === "string") reportClasses(node.value, node);
|
|
8000
8115
|
break;
|
|
8001
|
-
case
|
|
8116
|
+
case AST_NODE_TYPES40.TemplateLiteral:
|
|
8002
8117
|
for (const quasi of node.quasis) reportClasses(quasi.value.cooked ?? "", quasi);
|
|
8003
8118
|
break;
|
|
8004
|
-
case
|
|
8119
|
+
case AST_NODE_TYPES40.ArrayExpression:
|
|
8005
8120
|
for (const element of node.elements) {
|
|
8006
|
-
if (element !== null && element.type !==
|
|
8121
|
+
if (element !== null && element.type !== AST_NODE_TYPES40.SpreadElement) checkClassNode(element);
|
|
8007
8122
|
}
|
|
8008
8123
|
break;
|
|
8009
|
-
case
|
|
8124
|
+
case AST_NODE_TYPES40.ObjectExpression:
|
|
8010
8125
|
for (const property of node.properties) {
|
|
8011
|
-
if (property.type ===
|
|
8126
|
+
if (property.type === AST_NODE_TYPES40.Property) checkClassNode(property.value);
|
|
8012
8127
|
}
|
|
8013
8128
|
break;
|
|
8014
|
-
case
|
|
8129
|
+
case AST_NODE_TYPES40.ConditionalExpression:
|
|
8015
8130
|
checkClassNode(node.consequent);
|
|
8016
8131
|
checkClassNode(node.alternate);
|
|
8017
8132
|
break;
|
|
8018
|
-
case
|
|
8133
|
+
case AST_NODE_TYPES40.LogicalExpression:
|
|
8019
8134
|
checkClassNode(node.right);
|
|
8020
8135
|
break;
|
|
8021
8136
|
default:
|
|
@@ -8023,32 +8138,32 @@ var prefer_semantic_colors_default = createRule({
|
|
|
8023
8138
|
}
|
|
8024
8139
|
};
|
|
8025
8140
|
const checkColorValueNode = (node) => {
|
|
8026
|
-
if (node.type ===
|
|
8141
|
+
if (node.type === AST_NODE_TYPES40.Literal && typeof node.value === "string" && RAW_COLOR_VALUE_RE.test(node.value) && !CSS_VAR_REFERENCE_RE.test(node.value)) {
|
|
8027
8142
|
report(node, "inlineColor", { value: node.value });
|
|
8028
8143
|
}
|
|
8029
8144
|
};
|
|
8030
8145
|
return {
|
|
8031
8146
|
"JSXAttribute[name.name='className']"(node) {
|
|
8032
8147
|
if (node.value === null) return;
|
|
8033
|
-
if (node.value.type ===
|
|
8034
|
-
else if (node.value.type ===
|
|
8035
|
-
if (node.value.expression.type !==
|
|
8148
|
+
if (node.value.type === AST_NODE_TYPES40.Literal) checkClassNode(node.value);
|
|
8149
|
+
else if (node.value.type === AST_NODE_TYPES40.JSXExpressionContainer) {
|
|
8150
|
+
if (node.value.expression.type !== AST_NODE_TYPES40.JSXEmptyExpression) {
|
|
8036
8151
|
checkClassNode(node.value.expression);
|
|
8037
8152
|
}
|
|
8038
8153
|
}
|
|
8039
8154
|
},
|
|
8040
8155
|
CallExpression(node) {
|
|
8041
|
-
if (node.callee.type ===
|
|
8156
|
+
if (node.callee.type === AST_NODE_TYPES40.Identifier && node.callee.name === "require" && node.arguments[0]?.type === AST_NODE_TYPES40.Literal && typeof node.arguments[0].value === "string" && EMAIL_OR_PDF_MODULE_RE.test(node.arguments[0].value)) {
|
|
8042
8157
|
importsEmailOrPdfRenderer = true;
|
|
8043
8158
|
}
|
|
8044
|
-
if (node.callee.type ===
|
|
8159
|
+
if (node.callee.type === AST_NODE_TYPES40.Identifier && CLASS_FNS.has(node.callee.name)) {
|
|
8045
8160
|
for (const arg of node.arguments) {
|
|
8046
|
-
if (arg.type !==
|
|
8161
|
+
if (arg.type !== AST_NODE_TYPES40.SpreadElement) checkClassNode(arg);
|
|
8047
8162
|
}
|
|
8048
8163
|
}
|
|
8049
8164
|
},
|
|
8050
8165
|
VariableDeclarator(node) {
|
|
8051
|
-
if (node.id.type ===
|
|
8166
|
+
if (node.id.type === AST_NODE_TYPES40.Identifier && CLASS_NAME_RE.test(node.id.name)) {
|
|
8052
8167
|
checkClassNode(node.init);
|
|
8053
8168
|
}
|
|
8054
8169
|
},
|
|
@@ -8058,9 +8173,9 @@ var prefer_semantic_colors_default = createRule({
|
|
|
8058
8173
|
},
|
|
8059
8174
|
// SVG artwork colors are exempt; component presentation colors still report.
|
|
8060
8175
|
"JSXAttribute[name.name=/^(fill|stroke|color)$/]"(node) {
|
|
8061
|
-
if (node.value?.type !==
|
|
8176
|
+
if (node.value?.type !== AST_NODE_TYPES40.Literal) return;
|
|
8062
8177
|
const owner = node.parent.name;
|
|
8063
|
-
if (owner.type ===
|
|
8178
|
+
if (owner.type === AST_NODE_TYPES40.JSXIdentifier && SVG_SHAPE_PRIMITIVES.has(owner.name)) {
|
|
8064
8179
|
return;
|
|
8065
8180
|
}
|
|
8066
8181
|
if (typeof node.value.value === "string" && SVG_EXEMPT_COLOR_VALUES.has(node.value.value.toLowerCase())) {
|
|
@@ -8074,7 +8189,7 @@ var prefer_semantic_colors_default = createRule({
|
|
|
8074
8189
|
if (name !== null && STYLE_COLOR_PROPS.has(name)) checkColorValueNode(node.value);
|
|
8075
8190
|
},
|
|
8076
8191
|
ImportExpression(node) {
|
|
8077
|
-
if (node.source.type ===
|
|
8192
|
+
if (node.source.type === AST_NODE_TYPES40.Literal && typeof node.source.value === "string" && EMAIL_OR_PDF_MODULE_RE.test(node.source.value)) {
|
|
8078
8193
|
importsEmailOrPdfRenderer = true;
|
|
8079
8194
|
}
|
|
8080
8195
|
},
|
|
@@ -8280,7 +8395,7 @@ var prefer_single_sentence_comment_default = createRule({
|
|
|
8280
8395
|
// src/rules/prefer-string-literal-union.ts
|
|
8281
8396
|
import {
|
|
8282
8397
|
ESLintUtils as ESLintUtils3,
|
|
8283
|
-
AST_NODE_TYPES as
|
|
8398
|
+
AST_NODE_TYPES as AST_NODE_TYPES41
|
|
8284
8399
|
} from "@typescript-eslint/utils";
|
|
8285
8400
|
import * as ts2 from "typescript";
|
|
8286
8401
|
var CHOICE_TOKENS = /* @__PURE__ */ new Set([
|
|
@@ -8324,19 +8439,19 @@ function isChoiceLikeName(name) {
|
|
|
8324
8439
|
return CHOICE_TOKENS.has(lastWord(name));
|
|
8325
8440
|
}
|
|
8326
8441
|
function keyName(key) {
|
|
8327
|
-
if (key.type ===
|
|
8442
|
+
if (key.type === AST_NODE_TYPES41.Identifier) {
|
|
8328
8443
|
return key.name;
|
|
8329
8444
|
}
|
|
8330
|
-
if (key.type ===
|
|
8445
|
+
if (key.type === AST_NODE_TYPES41.Literal && typeof key.value === "string") {
|
|
8331
8446
|
return key.value;
|
|
8332
8447
|
}
|
|
8333
8448
|
return null;
|
|
8334
8449
|
}
|
|
8335
8450
|
function isStringLiteralMember(t) {
|
|
8336
|
-
return t.type ===
|
|
8451
|
+
return t.type === AST_NODE_TYPES41.TSLiteralType && t.literal.type === AST_NODE_TYPES41.Literal && typeof t.literal.value === "string";
|
|
8337
8452
|
}
|
|
8338
8453
|
function isStringLiteralUnion(node) {
|
|
8339
|
-
if (node?.type !==
|
|
8454
|
+
if (node?.type !== AST_NODE_TYPES41.TSUnionType) {
|
|
8340
8455
|
return false;
|
|
8341
8456
|
}
|
|
8342
8457
|
return node.types.filter(isStringLiteralMember).length >= MIN_CLUSTER_SIZE;
|
|
@@ -8365,12 +8480,12 @@ function bindingSourceExpression(decl) {
|
|
|
8365
8480
|
return ts2.isForOfStatement(node) ? node.expression : node.initializer;
|
|
8366
8481
|
}
|
|
8367
8482
|
function refKey(node) {
|
|
8368
|
-
if (node.type ===
|
|
8483
|
+
if (node.type === AST_NODE_TYPES41.Identifier) {
|
|
8369
8484
|
return node.name;
|
|
8370
8485
|
}
|
|
8371
|
-
if (node.type ===
|
|
8486
|
+
if (node.type === AST_NODE_TYPES41.MemberExpression && !node.computed) {
|
|
8372
8487
|
const inner = refKey(node.object);
|
|
8373
|
-
if (inner === null || node.property.type !==
|
|
8488
|
+
if (inner === null || node.property.type !== AST_NODE_TYPES41.Identifier) {
|
|
8374
8489
|
return null;
|
|
8375
8490
|
}
|
|
8376
8491
|
return `${inner}.${node.property.name}`;
|
|
@@ -8378,7 +8493,7 @@ function refKey(node) {
|
|
|
8378
8493
|
return null;
|
|
8379
8494
|
}
|
|
8380
8495
|
function strLiteral(node) {
|
|
8381
|
-
if (node.type ===
|
|
8496
|
+
if (node.type === AST_NODE_TYPES41.Literal && typeof node.value === "string") {
|
|
8382
8497
|
return node.value;
|
|
8383
8498
|
}
|
|
8384
8499
|
return null;
|
|
@@ -8531,7 +8646,7 @@ var prefer_string_literal_union_default = createRule({
|
|
|
8531
8646
|
containersWithUnion.add(container);
|
|
8532
8647
|
return;
|
|
8533
8648
|
}
|
|
8534
|
-
if (typeNode?.type !==
|
|
8649
|
+
if (typeNode?.type !== AST_NODE_TYPES41.TSStringKeyword) {
|
|
8535
8650
|
return;
|
|
8536
8651
|
}
|
|
8537
8652
|
const name = keyName(key);
|
|
@@ -8619,10 +8734,10 @@ var prefer_string_literal_union_default = createRule({
|
|
|
8619
8734
|
}
|
|
8620
8735
|
};
|
|
8621
8736
|
function refKeyText(node) {
|
|
8622
|
-
if (node.type ===
|
|
8737
|
+
if (node.type === AST_NODE_TYPES41.BinaryExpression) {
|
|
8623
8738
|
return refKey(node.left) ?? refKey(node.right) ?? "value";
|
|
8624
8739
|
}
|
|
8625
|
-
if (node.type ===
|
|
8740
|
+
if (node.type === AST_NODE_TYPES41.SwitchStatement) {
|
|
8626
8741
|
return refKey(node.discriminant) ?? "value";
|
|
8627
8742
|
}
|
|
8628
8743
|
return "value";
|
|
@@ -8631,7 +8746,7 @@ var prefer_string_literal_union_default = createRule({
|
|
|
8631
8746
|
});
|
|
8632
8747
|
|
|
8633
8748
|
// src/rules/prefer-whole-object-assertion.ts
|
|
8634
|
-
import { AST_NODE_TYPES as
|
|
8749
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES42 } from "@typescript-eslint/utils";
|
|
8635
8750
|
var MERGEABLE_MATCHERS = /* @__PURE__ */ new Set(["toBe", "toEqual", "toStrictEqual"]);
|
|
8636
8751
|
var ARRAY_MATCHERS = /* @__PURE__ */ new Set(["toEqual", "toStrictEqual"]);
|
|
8637
8752
|
var COLLECTION_PROPERTIES = /* @__PURE__ */ new Set(["length", "size"]);
|
|
@@ -8640,11 +8755,11 @@ var NUMERIC_SIGNS2 = /* @__PURE__ */ new Set(["-", "+"]);
|
|
|
8640
8755
|
var MIN_RUN_LENGTH = 2;
|
|
8641
8756
|
function literalText(node, getText) {
|
|
8642
8757
|
switch (node.type) {
|
|
8643
|
-
case
|
|
8758
|
+
case AST_NODE_TYPES42.Literal:
|
|
8644
8759
|
return "regex" in node ? null : getText(node);
|
|
8645
|
-
case
|
|
8760
|
+
case AST_NODE_TYPES42.TemplateLiteral:
|
|
8646
8761
|
return node.expressions.length === 0 ? getText(node) : null;
|
|
8647
|
-
case
|
|
8762
|
+
case AST_NODE_TYPES42.UnaryExpression:
|
|
8648
8763
|
return NUMERIC_SIGNS2.has(node.operator) && literalText(node.argument, getText) !== null ? getText(node) : null;
|
|
8649
8764
|
default:
|
|
8650
8765
|
return null;
|
|
@@ -8652,15 +8767,15 @@ function literalText(node, getText) {
|
|
|
8652
8767
|
}
|
|
8653
8768
|
function isPureReceiver(node) {
|
|
8654
8769
|
switch (node.type) {
|
|
8655
|
-
case
|
|
8656
|
-
case
|
|
8770
|
+
case AST_NODE_TYPES42.Identifier:
|
|
8771
|
+
case AST_NODE_TYPES42.ThisExpression:
|
|
8657
8772
|
return true;
|
|
8658
|
-
case
|
|
8773
|
+
case AST_NODE_TYPES42.MemberExpression:
|
|
8659
8774
|
if (node.optional) {
|
|
8660
8775
|
return false;
|
|
8661
8776
|
}
|
|
8662
8777
|
if (node.computed) {
|
|
8663
|
-
return node.property.type ===
|
|
8778
|
+
return node.property.type === AST_NODE_TYPES42.Literal && isPureReceiver(node.object);
|
|
8664
8779
|
}
|
|
8665
8780
|
return isPureReceiver(node.object);
|
|
8666
8781
|
default:
|
|
@@ -8668,7 +8783,7 @@ function isPureReceiver(node) {
|
|
|
8668
8783
|
}
|
|
8669
8784
|
}
|
|
8670
8785
|
function literalIndex(node) {
|
|
8671
|
-
if (node.type !==
|
|
8786
|
+
if (node.type !== AST_NODE_TYPES42.Literal || typeof node.value !== "number") {
|
|
8672
8787
|
return null;
|
|
8673
8788
|
}
|
|
8674
8789
|
return Number.isInteger(node.value) && node.value >= 0 ? node.value : null;
|
|
@@ -8694,24 +8809,24 @@ var prefer_whole_object_assertion_default = createRule({
|
|
|
8694
8809
|
}
|
|
8695
8810
|
const { sourceCode } = context;
|
|
8696
8811
|
function parseAssertion(statement) {
|
|
8697
|
-
if (statement.type !==
|
|
8812
|
+
if (statement.type !== AST_NODE_TYPES42.ExpressionStatement) {
|
|
8698
8813
|
return null;
|
|
8699
8814
|
}
|
|
8700
8815
|
const call = statement.expression;
|
|
8701
|
-
if (call.type !==
|
|
8816
|
+
if (call.type !== AST_NODE_TYPES42.CallExpression) {
|
|
8702
8817
|
return null;
|
|
8703
8818
|
}
|
|
8704
8819
|
const callee = call.callee;
|
|
8705
|
-
if (callee.type !==
|
|
8820
|
+
if (callee.type !== AST_NODE_TYPES42.MemberExpression || callee.computed || callee.property.type !== AST_NODE_TYPES42.Identifier) {
|
|
8706
8821
|
return null;
|
|
8707
8822
|
}
|
|
8708
8823
|
const matcher = callee.property.name;
|
|
8709
8824
|
const expectCall = callee.object;
|
|
8710
|
-
if (expectCall.type !==
|
|
8825
|
+
if (expectCall.type !== AST_NODE_TYPES42.CallExpression || expectCall.callee.type !== AST_NODE_TYPES42.Identifier || expectCall.callee.name !== "expect" || expectCall.arguments.length !== 1) {
|
|
8711
8826
|
return null;
|
|
8712
8827
|
}
|
|
8713
8828
|
const actual = expectCall.arguments[0];
|
|
8714
|
-
if (actual === void 0 || actual.type !==
|
|
8829
|
+
if (actual === void 0 || actual.type !== AST_NODE_TYPES42.MemberExpression || actual.optional) {
|
|
8715
8830
|
return null;
|
|
8716
8831
|
}
|
|
8717
8832
|
if (!isPureReceiver(actual.object)) {
|
|
@@ -8725,7 +8840,7 @@ var prefer_whole_object_assertion_default = createRule({
|
|
|
8725
8840
|
}
|
|
8726
8841
|
key = { kind: "index", index };
|
|
8727
8842
|
} else {
|
|
8728
|
-
if (actual.property.type !==
|
|
8843
|
+
if (actual.property.type !== AST_NODE_TYPES42.Identifier || COLLECTION_PROPERTIES.has(actual.property.name) || LITERAL_KEY_HAZARDS.has(actual.property.name)) {
|
|
8729
8844
|
return null;
|
|
8730
8845
|
}
|
|
8731
8846
|
key = { kind: "property", name: actual.property.name };
|
|
@@ -8737,7 +8852,7 @@ var prefer_whole_object_assertion_default = createRule({
|
|
|
8737
8852
|
return null;
|
|
8738
8853
|
}
|
|
8739
8854
|
const expected = call.arguments[0];
|
|
8740
|
-
if (call.arguments.length !== 1 || expected === void 0 || expected.type ===
|
|
8855
|
+
if (call.arguments.length !== 1 || expected === void 0 || expected.type === AST_NODE_TYPES42.SpreadElement) {
|
|
8741
8856
|
return null;
|
|
8742
8857
|
}
|
|
8743
8858
|
const literal = literalText(expected, (node) => sourceCode.getText(node));
|
|
@@ -8852,7 +8967,7 @@ var prefer_whole_object_assertion_default = createRule({
|
|
|
8852
8967
|
});
|
|
8853
8968
|
|
|
8854
8969
|
// src/rules/prefer-zod-enum.ts
|
|
8855
|
-
import { AST_NODE_TYPES as
|
|
8970
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES43 } from "@typescript-eslint/utils";
|
|
8856
8971
|
var prefer_zod_enum_default = createRule({
|
|
8857
8972
|
name: "prefer-zod-enum",
|
|
8858
8973
|
meta: {
|
|
@@ -8872,25 +8987,25 @@ var prefer_zod_enum_default = createRule({
|
|
|
8872
8987
|
const zodNamespaces = /* @__PURE__ */ new Set();
|
|
8873
8988
|
function enumValues(node) {
|
|
8874
8989
|
const callee = node.callee;
|
|
8875
|
-
if (callee.type !==
|
|
8990
|
+
if (callee.type !== AST_NODE_TYPES43.MemberExpression || callee.computed || callee.object.type !== AST_NODE_TYPES43.Identifier || !zodNamespaces.has(callee.object.name) || callee.property.type !== AST_NODE_TYPES43.Identifier || callee.property.name !== "union" || node.arguments.length !== 1) {
|
|
8876
8991
|
return null;
|
|
8877
8992
|
}
|
|
8878
8993
|
const argument = node.arguments[0];
|
|
8879
|
-
if (argument === void 0 || argument.type !==
|
|
8994
|
+
if (argument === void 0 || argument.type !== AST_NODE_TYPES43.ArrayExpression || argument.elements.length === 0) {
|
|
8880
8995
|
return null;
|
|
8881
8996
|
}
|
|
8882
8997
|
const values = [];
|
|
8883
8998
|
let canFix = true;
|
|
8884
8999
|
for (const element of argument.elements) {
|
|
8885
|
-
if (element?.type ===
|
|
9000
|
+
if (element?.type === AST_NODE_TYPES43.SpreadElement) {
|
|
8886
9001
|
canFix = false;
|
|
8887
9002
|
continue;
|
|
8888
9003
|
}
|
|
8889
|
-
if (element === null || element.type !==
|
|
9004
|
+
if (element === null || element.type !== AST_NODE_TYPES43.CallExpression || element.callee.type !== AST_NODE_TYPES43.MemberExpression || element.callee.computed || element.callee.object.type !== AST_NODE_TYPES43.Identifier || !zodNamespaces.has(element.callee.object.name) || element.callee.property.type !== AST_NODE_TYPES43.Identifier || element.callee.property.name !== "literal") {
|
|
8890
9005
|
return null;
|
|
8891
9006
|
}
|
|
8892
9007
|
const value = element.arguments[0];
|
|
8893
|
-
if (element.arguments.length !== 1 || value === void 0 || value.type !==
|
|
9008
|
+
if (element.arguments.length !== 1 || value === void 0 || value.type !== AST_NODE_TYPES43.Literal || typeof value.value !== "string") {
|
|
8894
9009
|
canFix = false;
|
|
8895
9010
|
continue;
|
|
8896
9011
|
}
|
|
@@ -8900,11 +9015,11 @@ var prefer_zod_enum_default = createRule({
|
|
|
8900
9015
|
}
|
|
8901
9016
|
function buildFix(node, values) {
|
|
8902
9017
|
const argument = node.arguments[0];
|
|
8903
|
-
if (argument === void 0 || argument.type !==
|
|
9018
|
+
if (argument === void 0 || argument.type !== AST_NODE_TYPES43.ArrayExpression || sourceCode.getCommentsInside(argument).length > 0) {
|
|
8904
9019
|
return void 0;
|
|
8905
9020
|
}
|
|
8906
9021
|
const callee = node.callee;
|
|
8907
|
-
if (callee.type !==
|
|
9022
|
+
if (callee.type !== AST_NODE_TYPES43.MemberExpression || callee.property.type !== AST_NODE_TYPES43.Identifier) {
|
|
8908
9023
|
return void 0;
|
|
8909
9024
|
}
|
|
8910
9025
|
return (fixer) => [
|
|
@@ -8921,7 +9036,7 @@ var prefer_zod_enum_default = createRule({
|
|
|
8921
9036
|
return;
|
|
8922
9037
|
}
|
|
8923
9038
|
for (const specifier of node.specifiers) {
|
|
8924
|
-
if (specifier.type ===
|
|
9039
|
+
if (specifier.type === AST_NODE_TYPES43.ImportNamespaceSpecifier || specifier.type === AST_NODE_TYPES43.ImportDefaultSpecifier || specifier.type === AST_NODE_TYPES43.ImportSpecifier && specifier.imported.type === AST_NODE_TYPES43.Identifier && specifier.imported.name === "z") {
|
|
8925
9040
|
zodNamespaces.add(specifier.local.name);
|
|
8926
9041
|
}
|
|
8927
9042
|
}
|
|
@@ -8943,7 +9058,7 @@ var prefer_zod_enum_default = createRule({
|
|
|
8943
9058
|
});
|
|
8944
9059
|
|
|
8945
9060
|
// src/rules/prefer-zod-infer.ts
|
|
8946
|
-
import { AST_NODE_TYPES as
|
|
9061
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES44 } from "@typescript-eslint/utils";
|
|
8947
9062
|
var SHAPE_PRESERVING_METHODS = /* @__PURE__ */ new Set([
|
|
8948
9063
|
"describe",
|
|
8949
9064
|
"refine",
|
|
@@ -8980,44 +9095,44 @@ var ZOD_TYPE_CONSTRAINTS = /* @__PURE__ */ new Set([
|
|
|
8980
9095
|
"Schema"
|
|
8981
9096
|
]);
|
|
8982
9097
|
var LEAF_NODE_TYPES = {
|
|
8983
|
-
string: [
|
|
8984
|
-
email: [
|
|
8985
|
-
url: [
|
|
8986
|
-
uuid: [
|
|
8987
|
-
ulid: [
|
|
8988
|
-
cuid: [
|
|
8989
|
-
cuid2: [
|
|
8990
|
-
nanoid: [
|
|
8991
|
-
iso: [
|
|
8992
|
-
number: [
|
|
8993
|
-
int: [
|
|
8994
|
-
float32: [
|
|
8995
|
-
float64: [
|
|
8996
|
-
boolean: [
|
|
8997
|
-
bigint: [
|
|
8998
|
-
symbol: [
|
|
8999
|
-
any: [
|
|
9000
|
-
unknown: [
|
|
9001
|
-
never: [
|
|
9002
|
-
void: [
|
|
9003
|
-
null: [
|
|
9004
|
-
undefined: [
|
|
9005
|
-
literal: [
|
|
9006
|
-
date: [
|
|
9007
|
-
array: [
|
|
9008
|
-
tuple: [
|
|
9009
|
-
object: [
|
|
9010
|
-
strictObject: [
|
|
9011
|
-
looseObject: [
|
|
9012
|
-
record: [
|
|
9013
|
-
map: [
|
|
9014
|
-
set: [
|
|
9015
|
-
promise: [
|
|
9016
|
-
enum: [
|
|
9017
|
-
nativeEnum: [
|
|
9018
|
-
union: [
|
|
9019
|
-
discriminatedUnion: [
|
|
9020
|
-
intersection: [
|
|
9098
|
+
string: [AST_NODE_TYPES44.TSStringKeyword],
|
|
9099
|
+
email: [AST_NODE_TYPES44.TSStringKeyword],
|
|
9100
|
+
url: [AST_NODE_TYPES44.TSStringKeyword],
|
|
9101
|
+
uuid: [AST_NODE_TYPES44.TSStringKeyword],
|
|
9102
|
+
ulid: [AST_NODE_TYPES44.TSStringKeyword],
|
|
9103
|
+
cuid: [AST_NODE_TYPES44.TSStringKeyword],
|
|
9104
|
+
cuid2: [AST_NODE_TYPES44.TSStringKeyword],
|
|
9105
|
+
nanoid: [AST_NODE_TYPES44.TSStringKeyword],
|
|
9106
|
+
iso: [AST_NODE_TYPES44.TSStringKeyword],
|
|
9107
|
+
number: [AST_NODE_TYPES44.TSNumberKeyword],
|
|
9108
|
+
int: [AST_NODE_TYPES44.TSNumberKeyword],
|
|
9109
|
+
float32: [AST_NODE_TYPES44.TSNumberKeyword],
|
|
9110
|
+
float64: [AST_NODE_TYPES44.TSNumberKeyword],
|
|
9111
|
+
boolean: [AST_NODE_TYPES44.TSBooleanKeyword],
|
|
9112
|
+
bigint: [AST_NODE_TYPES44.TSBigIntKeyword],
|
|
9113
|
+
symbol: [AST_NODE_TYPES44.TSSymbolKeyword],
|
|
9114
|
+
any: [AST_NODE_TYPES44.TSAnyKeyword],
|
|
9115
|
+
unknown: [AST_NODE_TYPES44.TSUnknownKeyword],
|
|
9116
|
+
never: [AST_NODE_TYPES44.TSNeverKeyword],
|
|
9117
|
+
void: [AST_NODE_TYPES44.TSVoidKeyword],
|
|
9118
|
+
null: [AST_NODE_TYPES44.TSNullKeyword],
|
|
9119
|
+
undefined: [AST_NODE_TYPES44.TSUndefinedKeyword],
|
|
9120
|
+
literal: [AST_NODE_TYPES44.TSLiteralType],
|
|
9121
|
+
date: [AST_NODE_TYPES44.TSTypeReference],
|
|
9122
|
+
array: [AST_NODE_TYPES44.TSArrayType, AST_NODE_TYPES44.TSTypeReference],
|
|
9123
|
+
tuple: [AST_NODE_TYPES44.TSTupleType],
|
|
9124
|
+
object: [AST_NODE_TYPES44.TSTypeLiteral, AST_NODE_TYPES44.TSTypeReference],
|
|
9125
|
+
strictObject: [AST_NODE_TYPES44.TSTypeLiteral, AST_NODE_TYPES44.TSTypeReference],
|
|
9126
|
+
looseObject: [AST_NODE_TYPES44.TSTypeLiteral, AST_NODE_TYPES44.TSTypeReference],
|
|
9127
|
+
record: [AST_NODE_TYPES44.TSTypeReference, AST_NODE_TYPES44.TSTypeLiteral],
|
|
9128
|
+
map: [AST_NODE_TYPES44.TSTypeReference],
|
|
9129
|
+
set: [AST_NODE_TYPES44.TSTypeReference],
|
|
9130
|
+
promise: [AST_NODE_TYPES44.TSTypeReference],
|
|
9131
|
+
enum: [AST_NODE_TYPES44.TSUnionType, AST_NODE_TYPES44.TSTypeReference, AST_NODE_TYPES44.TSLiteralType],
|
|
9132
|
+
nativeEnum: [AST_NODE_TYPES44.TSUnionType, AST_NODE_TYPES44.TSTypeReference, AST_NODE_TYPES44.TSLiteralType],
|
|
9133
|
+
union: [AST_NODE_TYPES44.TSUnionType, AST_NODE_TYPES44.TSTypeReference],
|
|
9134
|
+
discriminatedUnion: [AST_NODE_TYPES44.TSUnionType, AST_NODE_TYPES44.TSTypeReference],
|
|
9135
|
+
intersection: [AST_NODE_TYPES44.TSIntersectionType, AST_NODE_TYPES44.TSTypeReference]
|
|
9021
9136
|
};
|
|
9022
9137
|
function normalizeSchemaName(name) {
|
|
9023
9138
|
return name.replace(/Schema$/i, "").replace(/^Z(?=[A-Z])/, "").toLowerCase();
|
|
@@ -9026,20 +9141,20 @@ function normalizeTypeName(name) {
|
|
|
9026
9141
|
return name.replace(/Type$/, "").toLowerCase();
|
|
9027
9142
|
}
|
|
9028
9143
|
function unwrapNullish(annotation) {
|
|
9029
|
-
if (annotation.type !==
|
|
9144
|
+
if (annotation.type !== AST_NODE_TYPES44.TSUnionType) {
|
|
9030
9145
|
return {
|
|
9031
9146
|
core: annotation,
|
|
9032
|
-
nullable: annotation.type ===
|
|
9147
|
+
nullable: annotation.type === AST_NODE_TYPES44.TSNullKeyword
|
|
9033
9148
|
};
|
|
9034
9149
|
}
|
|
9035
9150
|
const rest = [];
|
|
9036
9151
|
let nullable = false;
|
|
9037
9152
|
for (const member of annotation.types) {
|
|
9038
|
-
if (member.type ===
|
|
9153
|
+
if (member.type === AST_NODE_TYPES44.TSNullKeyword) {
|
|
9039
9154
|
nullable = true;
|
|
9040
9155
|
continue;
|
|
9041
9156
|
}
|
|
9042
|
-
if (member.type ===
|
|
9157
|
+
if (member.type === AST_NODE_TYPES44.TSUndefinedKeyword) {
|
|
9043
9158
|
continue;
|
|
9044
9159
|
}
|
|
9045
9160
|
rest.push(member);
|
|
@@ -9104,14 +9219,14 @@ var prefer_zod_infer_default = createRule({
|
|
|
9104
9219
|
function zodCallChain(node) {
|
|
9105
9220
|
const chain = [];
|
|
9106
9221
|
let current = node;
|
|
9107
|
-
while (current.type ===
|
|
9222
|
+
while (current.type === AST_NODE_TYPES44.CallExpression) {
|
|
9108
9223
|
const callee = current.callee;
|
|
9109
|
-
if (callee.type !==
|
|
9224
|
+
if (callee.type !== AST_NODE_TYPES44.MemberExpression || callee.computed || callee.property.type !== AST_NODE_TYPES44.Identifier) {
|
|
9110
9225
|
return null;
|
|
9111
9226
|
}
|
|
9112
9227
|
chain.push(current);
|
|
9113
9228
|
const receiver = callee.object;
|
|
9114
|
-
if (receiver.type ===
|
|
9229
|
+
if (receiver.type === AST_NODE_TYPES44.Identifier) {
|
|
9115
9230
|
return zodNamespaces.has(receiver.name) ? chain.reverse() : null;
|
|
9116
9231
|
}
|
|
9117
9232
|
current = receiver;
|
|
@@ -9120,19 +9235,19 @@ var prefer_zod_infer_default = createRule({
|
|
|
9120
9235
|
}
|
|
9121
9236
|
function methodName(call) {
|
|
9122
9237
|
const callee = call.callee;
|
|
9123
|
-
return callee.type ===
|
|
9238
|
+
return callee.type === AST_NODE_TYPES44.MemberExpression && callee.property.type === AST_NODE_TYPES44.Identifier ? callee.property.name : "";
|
|
9124
9239
|
}
|
|
9125
9240
|
function schemaField(node) {
|
|
9126
9241
|
const modifiers = [];
|
|
9127
9242
|
let current = node;
|
|
9128
9243
|
let leaf = null;
|
|
9129
|
-
while (current.type ===
|
|
9244
|
+
while (current.type === AST_NODE_TYPES44.CallExpression) {
|
|
9130
9245
|
const callee = current.callee;
|
|
9131
|
-
if (callee.type !==
|
|
9246
|
+
if (callee.type !== AST_NODE_TYPES44.MemberExpression || callee.computed || callee.property.type !== AST_NODE_TYPES44.Identifier) {
|
|
9132
9247
|
break;
|
|
9133
9248
|
}
|
|
9134
9249
|
const receiver = callee.object;
|
|
9135
|
-
if (receiver.type ===
|
|
9250
|
+
if (receiver.type === AST_NODE_TYPES44.Identifier && zodNamespaces.has(receiver.name)) {
|
|
9136
9251
|
leaf = callee.property.name;
|
|
9137
9252
|
break;
|
|
9138
9253
|
}
|
|
@@ -9163,16 +9278,16 @@ var prefer_zod_infer_default = createRule({
|
|
|
9163
9278
|
return null;
|
|
9164
9279
|
}
|
|
9165
9280
|
const shape = base.arguments[0];
|
|
9166
|
-
if (shape === void 0 || shape.type !==
|
|
9281
|
+
if (shape === void 0 || shape.type !== AST_NODE_TYPES44.ObjectExpression) {
|
|
9167
9282
|
return null;
|
|
9168
9283
|
}
|
|
9169
9284
|
const fields = /* @__PURE__ */ new Map();
|
|
9170
9285
|
for (const property of shape.properties) {
|
|
9171
|
-
if (property.type !==
|
|
9286
|
+
if (property.type !== AST_NODE_TYPES44.Property || property.computed) {
|
|
9172
9287
|
return null;
|
|
9173
9288
|
}
|
|
9174
9289
|
const { key } = property;
|
|
9175
|
-
const name = key.type ===
|
|
9290
|
+
const name = key.type === AST_NODE_TYPES44.Identifier ? key.name : key.type === AST_NODE_TYPES44.Literal && typeof key.value === "string" ? key.value : null;
|
|
9176
9291
|
if (name === null) {
|
|
9177
9292
|
return null;
|
|
9178
9293
|
}
|
|
@@ -9183,11 +9298,11 @@ var prefer_zod_infer_default = createRule({
|
|
|
9183
9298
|
function typeMembers(members) {
|
|
9184
9299
|
const result = /* @__PURE__ */ new Map();
|
|
9185
9300
|
for (const member of members) {
|
|
9186
|
-
if (member.type !==
|
|
9301
|
+
if (member.type !== AST_NODE_TYPES44.TSPropertySignature || member.computed) {
|
|
9187
9302
|
return null;
|
|
9188
9303
|
}
|
|
9189
9304
|
const { key } = member;
|
|
9190
|
-
const name = key.type ===
|
|
9305
|
+
const name = key.type === AST_NODE_TYPES44.Identifier ? key.name : key.type === AST_NODE_TYPES44.Literal && typeof key.value === "string" ? key.value : null;
|
|
9191
9306
|
if (name === null) {
|
|
9192
9307
|
return null;
|
|
9193
9308
|
}
|
|
@@ -9201,8 +9316,8 @@ var prefer_zod_infer_default = createRule({
|
|
|
9201
9316
|
return result.size === 0 ? null : result;
|
|
9202
9317
|
}
|
|
9203
9318
|
function collectConstrainedNames(node) {
|
|
9204
|
-
if (node.type ===
|
|
9205
|
-
if (node.typeName.type ===
|
|
9319
|
+
if (node.type === AST_NODE_TYPES44.TSTypeReference) {
|
|
9320
|
+
if (node.typeName.type === AST_NODE_TYPES44.Identifier) {
|
|
9206
9321
|
constrainedTypeNames.add(node.typeName.name);
|
|
9207
9322
|
}
|
|
9208
9323
|
for (const argument of node.typeArguments?.params ?? []) {
|
|
@@ -9210,11 +9325,11 @@ var prefer_zod_infer_default = createRule({
|
|
|
9210
9325
|
}
|
|
9211
9326
|
return;
|
|
9212
9327
|
}
|
|
9213
|
-
if (node.type ===
|
|
9328
|
+
if (node.type === AST_NODE_TYPES44.TSArrayType) {
|
|
9214
9329
|
collectConstrainedNames(node.elementType);
|
|
9215
9330
|
return;
|
|
9216
9331
|
}
|
|
9217
|
-
if (node.type ===
|
|
9332
|
+
if (node.type === AST_NODE_TYPES44.TSUnionType || node.type === AST_NODE_TYPES44.TSIntersectionType) {
|
|
9218
9333
|
for (const member of node.types) {
|
|
9219
9334
|
collectConstrainedNames(member);
|
|
9220
9335
|
}
|
|
@@ -9258,13 +9373,13 @@ var prefer_zod_infer_default = createRule({
|
|
|
9258
9373
|
return;
|
|
9259
9374
|
}
|
|
9260
9375
|
for (const specifier of node.specifiers) {
|
|
9261
|
-
if (specifier.type ===
|
|
9376
|
+
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") {
|
|
9262
9377
|
zodNamespaces.add(specifier.local.name);
|
|
9263
9378
|
}
|
|
9264
9379
|
}
|
|
9265
9380
|
},
|
|
9266
9381
|
VariableDeclarator(node) {
|
|
9267
|
-
if (node.id.type !==
|
|
9382
|
+
if (node.id.type !== AST_NODE_TYPES44.Identifier || node.init == null) {
|
|
9268
9383
|
return;
|
|
9269
9384
|
}
|
|
9270
9385
|
const fields = schemaFields(node.init);
|
|
@@ -9274,14 +9389,14 @@ var prefer_zod_infer_default = createRule({
|
|
|
9274
9389
|
},
|
|
9275
9390
|
/** Records `XSchema.transform(...)` and equivalent module-level reshaping. */
|
|
9276
9391
|
"MemberExpression[computed=false]"(node) {
|
|
9277
|
-
if (node.object.type ===
|
|
9392
|
+
if (node.object.type === AST_NODE_TYPES44.Identifier && node.property.type === AST_NODE_TYPES44.Identifier && MODULE_LEVEL_RESHAPERS.has(node.property.name)) {
|
|
9278
9393
|
reshapedSchemaNames.add(node.object.name);
|
|
9279
9394
|
}
|
|
9280
9395
|
},
|
|
9281
9396
|
/** Records every type argument carried by a Zod constraint. */
|
|
9282
9397
|
TSTypeReference(node) {
|
|
9283
9398
|
const { typeName } = node;
|
|
9284
|
-
const referenced = typeName.type ===
|
|
9399
|
+
const referenced = typeName.type === AST_NODE_TYPES44.Identifier ? typeName.name : typeName.type === AST_NODE_TYPES44.TSQualifiedName && typeName.right.type === AST_NODE_TYPES44.Identifier ? typeName.right.name : null;
|
|
9285
9400
|
if (referenced === null || !ZOD_TYPE_CONSTRAINTS.has(referenced)) {
|
|
9286
9401
|
return;
|
|
9287
9402
|
}
|
|
@@ -9299,7 +9414,7 @@ var prefer_zod_infer_default = createRule({
|
|
|
9299
9414
|
}
|
|
9300
9415
|
},
|
|
9301
9416
|
TSTypeAliasDeclaration(node) {
|
|
9302
|
-
if (node.typeParameters !== void 0 || node.typeAnnotation.type !==
|
|
9417
|
+
if (node.typeParameters !== void 0 || node.typeAnnotation.type !== AST_NODE_TYPES44.TSTypeLiteral) {
|
|
9303
9418
|
return;
|
|
9304
9419
|
}
|
|
9305
9420
|
const members = typeMembers(node.typeAnnotation.members);
|
|
@@ -9344,10 +9459,10 @@ var prefer_zod_infer_default = createRule({
|
|
|
9344
9459
|
});
|
|
9345
9460
|
|
|
9346
9461
|
// src/rules/require-assert-never.ts
|
|
9347
|
-
import { AST_NODE_TYPES as
|
|
9462
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES45 } from "@typescript-eslint/utils";
|
|
9348
9463
|
var isRuntimeHandlingStatement = (statement) => {
|
|
9349
|
-
if (statement.type ===
|
|
9350
|
-
if (statement.type ===
|
|
9464
|
+
if (statement.type === AST_NODE_TYPES45.EmptyStatement) return false;
|
|
9465
|
+
if (statement.type === AST_NODE_TYPES45.BlockStatement) {
|
|
9351
9466
|
return statement.body.some(isRuntimeHandlingStatement);
|
|
9352
9467
|
}
|
|
9353
9468
|
return true;
|
|
@@ -9363,7 +9478,7 @@ var isCommentOnlyNoopDefault = (defaultCase, sourceCode) => {
|
|
|
9363
9478
|
return colonToken !== null && sourceCode.getCommentsAfter(colonToken).length > 0;
|
|
9364
9479
|
}
|
|
9365
9480
|
const only = defaultCase.consequent[0];
|
|
9366
|
-
if (only !== void 0 && defaultCase.consequent.length === 1 && only.type ===
|
|
9481
|
+
if (only !== void 0 && defaultCase.consequent.length === 1 && only.type === AST_NODE_TYPES45.BlockStatement && only.body.length === 0) {
|
|
9367
9482
|
return sourceCode.getCommentsInside(only).length > 0;
|
|
9368
9483
|
}
|
|
9369
9484
|
return false;
|
|
@@ -9403,7 +9518,7 @@ var require_assert_never_default = createRule({
|
|
|
9403
9518
|
});
|
|
9404
9519
|
|
|
9405
9520
|
// src/rules/require-fetch-timeout.ts
|
|
9406
|
-
import { AST_NODE_TYPES as
|
|
9521
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES46, ASTUtils as ASTUtils4 } from "@typescript-eslint/utils";
|
|
9407
9522
|
var GLOBAL_OBJECTS2 = /* @__PURE__ */ new Set([
|
|
9408
9523
|
"globalThis",
|
|
9409
9524
|
"window",
|
|
@@ -9419,14 +9534,14 @@ function matchesAnyPattern3(filename, patterns) {
|
|
|
9419
9534
|
return false;
|
|
9420
9535
|
}
|
|
9421
9536
|
function initProvablyLacksSignal(init) {
|
|
9422
|
-
if (init.type !==
|
|
9537
|
+
if (init.type !== AST_NODE_TYPES46.ObjectExpression) {
|
|
9423
9538
|
return false;
|
|
9424
9539
|
}
|
|
9425
9540
|
for (const prop of init.properties) {
|
|
9426
|
-
if (prop.type ===
|
|
9541
|
+
if (prop.type === AST_NODE_TYPES46.SpreadElement) {
|
|
9427
9542
|
return false;
|
|
9428
9543
|
}
|
|
9429
|
-
if (prop.key.type ===
|
|
9544
|
+
if (prop.key.type === AST_NODE_TYPES46.Identifier && prop.key.name === "signal" || prop.key.type === AST_NODE_TYPES46.Literal && prop.key.value === "signal") {
|
|
9430
9545
|
return false;
|
|
9431
9546
|
}
|
|
9432
9547
|
if (prop.computed) {
|
|
@@ -9436,7 +9551,7 @@ function initProvablyLacksSignal(init) {
|
|
|
9436
9551
|
return true;
|
|
9437
9552
|
}
|
|
9438
9553
|
function isStringish(node) {
|
|
9439
|
-
return node.type ===
|
|
9554
|
+
return node.type === AST_NODE_TYPES46.Literal && typeof node.value === "string" || node.type === AST_NODE_TYPES46.TemplateLiteral;
|
|
9440
9555
|
}
|
|
9441
9556
|
var require_fetch_timeout_default = createRule({
|
|
9442
9557
|
name: "require-fetch-timeout",
|
|
@@ -9477,10 +9592,10 @@ var require_fetch_timeout_default = createRule({
|
|
|
9477
9592
|
return variable === null || variable.defs.length === 0;
|
|
9478
9593
|
}
|
|
9479
9594
|
function isGlobalFetchCall2(callee) {
|
|
9480
|
-
if (callee.type ===
|
|
9595
|
+
if (callee.type === AST_NODE_TYPES46.Identifier) {
|
|
9481
9596
|
return callee.name === "fetch" && resolvesToGlobal(callee);
|
|
9482
9597
|
}
|
|
9483
|
-
return callee.type ===
|
|
9598
|
+
return callee.type === AST_NODE_TYPES46.MemberExpression && !callee.computed && callee.property.type === AST_NODE_TYPES46.Identifier && callee.property.name === "fetch" && callee.object.type === AST_NODE_TYPES46.Identifier && GLOBAL_OBJECTS2.has(callee.object.name) && resolvesToGlobal(callee.object);
|
|
9484
9599
|
}
|
|
9485
9600
|
return {
|
|
9486
9601
|
CallExpression(node) {
|
|
@@ -9500,7 +9615,7 @@ var require_fetch_timeout_default = createRule({
|
|
|
9500
9615
|
});
|
|
9501
9616
|
|
|
9502
9617
|
// src/rules/require-interface-for-injected-service.ts
|
|
9503
|
-
import { AST_NODE_TYPES as
|
|
9618
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES47 } from "@typescript-eslint/utils";
|
|
9504
9619
|
var CONFIGISH_TYPE_RE = /(?:Options|Opts|Config|Configuration|Settings|Params|Props|Args|Env|Environment|Callbacks|Flags)$/;
|
|
9505
9620
|
var CONFIGISH_NAME_RE = /^(?:options|opts|config|configuration|settings|params|props|args|env|environment|callbacks|flags|logger|log|clock)$/i;
|
|
9506
9621
|
var HTTP_TRANSPORT_TYPE_RE = /^(?:KyInstance|AxiosInstance|Session)$/;
|
|
@@ -9508,20 +9623,20 @@ var BUILTIN_CONTAINER_TYPE_RE = /^(?:Record|Map|WeakMap|Set|WeakSet|Array|Readon
|
|
|
9508
9623
|
var TRANSPORT_WRAPPER_NAME_RE = /Client$/;
|
|
9509
9624
|
var ROUTER_FACTORY_NAME = "Router";
|
|
9510
9625
|
var FRAMEWORK_HTTP_TYPES = /* @__PURE__ */ new Set(["Request", "Response", "NextFunction"]);
|
|
9511
|
-
var isExportedClass = (node) => node.parent.type ===
|
|
9512
|
-
var qualifiedName = (name) => name.type ===
|
|
9626
|
+
var isExportedClass = (node) => node.parent.type === AST_NODE_TYPES47.ExportNamedDeclaration || node.parent.type === AST_NODE_TYPES47.ExportDefaultDeclaration;
|
|
9627
|
+
var qualifiedName = (name) => name.type === AST_NODE_TYPES47.Identifier ? name.name : name.type === AST_NODE_TYPES47.TSQualifiedName ? `${qualifiedName(name.left)}.${name.right.name}` : "";
|
|
9513
9628
|
var readTypeReference = (annotation) => {
|
|
9514
|
-
if (annotation === void 0 || annotation.type !==
|
|
9629
|
+
if (annotation === void 0 || annotation.type !== AST_NODE_TYPES47.TSTypeReference) return null;
|
|
9515
9630
|
const { typeName } = annotation;
|
|
9516
|
-
const rightmost = typeName.type ===
|
|
9631
|
+
const rightmost = typeName.type === AST_NODE_TYPES47.Identifier ? typeName.name : typeName.type === AST_NODE_TYPES47.TSQualifiedName ? typeName.right.name : null;
|
|
9517
9632
|
if (rightmost === null) return null;
|
|
9518
9633
|
return { typeName: rightmost, display: qualifiedName(typeName) };
|
|
9519
9634
|
};
|
|
9520
9635
|
var namedParameterCollaborator = (annotated) => {
|
|
9521
9636
|
let target = annotated;
|
|
9522
|
-
if (target.type ===
|
|
9523
|
-
if (target.type ===
|
|
9524
|
-
if (target.type !==
|
|
9637
|
+
if (target.type === AST_NODE_TYPES47.TSParameterProperty) target = target.parameter;
|
|
9638
|
+
if (target.type === AST_NODE_TYPES47.AssignmentPattern) target = target.left;
|
|
9639
|
+
if (target.type !== AST_NODE_TYPES47.Identifier) return null;
|
|
9525
9640
|
const reference = readTypeReference(target.typeAnnotation?.typeAnnotation);
|
|
9526
9641
|
if (reference === null) return null;
|
|
9527
9642
|
return { name: target.name, ...reference };
|
|
@@ -9529,8 +9644,8 @@ var namedParameterCollaborator = (annotated) => {
|
|
|
9529
9644
|
var propertySignatureTypes = (members) => {
|
|
9530
9645
|
const types = /* @__PURE__ */ new Map();
|
|
9531
9646
|
for (const member of members) {
|
|
9532
|
-
if (member.type !==
|
|
9533
|
-
if (member.computed || member.key.type !==
|
|
9647
|
+
if (member.type !== AST_NODE_TYPES47.TSPropertySignature) continue;
|
|
9648
|
+
if (member.computed || member.key.type !== AST_NODE_TYPES47.Identifier) continue;
|
|
9534
9649
|
const reference = readTypeReference(member.typeAnnotation?.typeAnnotation);
|
|
9535
9650
|
if (reference === null) continue;
|
|
9536
9651
|
types.set(member.key.name, reference);
|
|
@@ -9541,18 +9656,18 @@ var fileTypeIndex = (program) => {
|
|
|
9541
9656
|
const objects = /* @__PURE__ */ new Map();
|
|
9542
9657
|
const functionAliases = /* @__PURE__ */ new Set();
|
|
9543
9658
|
for (const statement of program.body) {
|
|
9544
|
-
const declaration = statement.type ===
|
|
9545
|
-
if (declaration?.type ===
|
|
9659
|
+
const declaration = statement.type === AST_NODE_TYPES47.ExportNamedDeclaration ? statement.declaration : statement;
|
|
9660
|
+
if (declaration?.type === AST_NODE_TYPES47.TSInterfaceDeclaration) {
|
|
9546
9661
|
objects.set(declaration.id.name, propertySignatureTypes(declaration.body.body));
|
|
9547
9662
|
continue;
|
|
9548
9663
|
}
|
|
9549
|
-
if (declaration?.type !==
|
|
9664
|
+
if (declaration?.type !== AST_NODE_TYPES47.TSTypeAliasDeclaration) continue;
|
|
9550
9665
|
const aliased = declaration.typeAnnotation;
|
|
9551
|
-
if (aliased.type ===
|
|
9666
|
+
if (aliased.type === AST_NODE_TYPES47.TSFunctionType || aliased.type === AST_NODE_TYPES47.TSConstructorType) {
|
|
9552
9667
|
functionAliases.add(declaration.id.name);
|
|
9553
9668
|
continue;
|
|
9554
9669
|
}
|
|
9555
|
-
const literals = aliased.type ===
|
|
9670
|
+
const literals = aliased.type === AST_NODE_TYPES47.TSTypeLiteral ? [aliased] : aliased.type === AST_NODE_TYPES47.TSIntersectionType ? aliased.types.filter((part) => part.type === AST_NODE_TYPES47.TSTypeLiteral) : [];
|
|
9556
9671
|
if (literals.length === 0) continue;
|
|
9557
9672
|
const merged = /* @__PURE__ */ new Map();
|
|
9558
9673
|
for (const literal of literals) {
|
|
@@ -9565,10 +9680,10 @@ var fileTypeIndex = (program) => {
|
|
|
9565
9680
|
return { objects, functionAliases };
|
|
9566
9681
|
};
|
|
9567
9682
|
var bagMemberTypes = (annotation, declared) => {
|
|
9568
|
-
if (annotation.type ===
|
|
9683
|
+
if (annotation.type === AST_NODE_TYPES47.TSTypeLiteral) {
|
|
9569
9684
|
return propertySignatureTypes(annotation.members);
|
|
9570
9685
|
}
|
|
9571
|
-
if (annotation.type !==
|
|
9686
|
+
if (annotation.type !== AST_NODE_TYPES47.TSTypeReference || annotation.typeName.type !== AST_NODE_TYPES47.Identifier) {
|
|
9572
9687
|
return null;
|
|
9573
9688
|
}
|
|
9574
9689
|
return declared().objects.get(annotation.typeName.name) ?? null;
|
|
@@ -9580,11 +9695,11 @@ var objectPatternCollaborators = (pattern, declared) => {
|
|
|
9580
9695
|
if (members === null) return [];
|
|
9581
9696
|
const collaborators = [];
|
|
9582
9697
|
for (const property of pattern.properties) {
|
|
9583
|
-
if (property.type !==
|
|
9584
|
-
if (property.key.type !==
|
|
9698
|
+
if (property.type !== AST_NODE_TYPES47.Property || property.computed) continue;
|
|
9699
|
+
if (property.key.type !== AST_NODE_TYPES47.Identifier) continue;
|
|
9585
9700
|
const key = property.key.name;
|
|
9586
|
-
const bound = property.value.type ===
|
|
9587
|
-
if (bound.type !==
|
|
9701
|
+
const bound = property.value.type === AST_NODE_TYPES47.AssignmentPattern ? property.value.left : property.value;
|
|
9702
|
+
if (bound.type !== AST_NODE_TYPES47.Identifier) continue;
|
|
9588
9703
|
if (CONFIGISH_NAME_RE.test(key)) continue;
|
|
9589
9704
|
const reference = members.get(key);
|
|
9590
9705
|
if (reference === void 0) continue;
|
|
@@ -9594,8 +9709,8 @@ var objectPatternCollaborators = (pattern, declared) => {
|
|
|
9594
9709
|
};
|
|
9595
9710
|
var parameterCollaborators = (parameter, declared) => {
|
|
9596
9711
|
let target = parameter;
|
|
9597
|
-
if (target.type ===
|
|
9598
|
-
if (target.type ===
|
|
9712
|
+
if (target.type === AST_NODE_TYPES47.AssignmentPattern) target = target.left;
|
|
9713
|
+
if (target.type === AST_NODE_TYPES47.ObjectPattern) {
|
|
9599
9714
|
return objectPatternCollaborators(target, declared);
|
|
9600
9715
|
}
|
|
9601
9716
|
const named2 = namedParameterCollaborator(parameter);
|
|
@@ -9614,17 +9729,17 @@ var readConstructor = (ctor, declared, typeParameters) => {
|
|
|
9614
9729
|
let constructedFields = 0;
|
|
9615
9730
|
if (body2 !== null && body2 !== void 0) {
|
|
9616
9731
|
for (const statement of body2.body) {
|
|
9617
|
-
if (statement.type !==
|
|
9732
|
+
if (statement.type !== AST_NODE_TYPES47.ExpressionStatement) continue;
|
|
9618
9733
|
const expression = statement.expression;
|
|
9619
|
-
if (expression.type !==
|
|
9734
|
+
if (expression.type !== AST_NODE_TYPES47.AssignmentExpression || expression.operator !== "=" || expression.left.type !== AST_NODE_TYPES47.MemberExpression || expression.left.object.type !== AST_NODE_TYPES47.ThisExpression) {
|
|
9620
9735
|
continue;
|
|
9621
9736
|
}
|
|
9622
9737
|
const source = expression.right;
|
|
9623
|
-
if (source.type ===
|
|
9738
|
+
if (source.type === AST_NODE_TYPES47.NewExpression) {
|
|
9624
9739
|
constructedFields += 1;
|
|
9625
|
-
} else if (source.type ===
|
|
9740
|
+
} else if (source.type === AST_NODE_TYPES47.Identifier) {
|
|
9626
9741
|
storedFrom.add(source.name);
|
|
9627
|
-
} else if (source.type ===
|
|
9742
|
+
} else if (source.type === AST_NODE_TYPES47.MemberExpression && source.object.type === AST_NODE_TYPES47.Identifier) {
|
|
9628
9743
|
storedFrom.add(source.object.name);
|
|
9629
9744
|
}
|
|
9630
9745
|
}
|
|
@@ -9632,7 +9747,7 @@ var readConstructor = (ctor, declared, typeParameters) => {
|
|
|
9632
9747
|
const collaborators = [];
|
|
9633
9748
|
for (const parameter of ctor.value.params) {
|
|
9634
9749
|
for (const reference of parameterCollaborators(parameter, declared)) {
|
|
9635
|
-
const stored = parameter.type ===
|
|
9750
|
+
const stored = parameter.type === AST_NODE_TYPES47.TSParameterProperty || storedFrom.has(reference.name);
|
|
9636
9751
|
if (!stored) continue;
|
|
9637
9752
|
if (CONFIGISH_TYPE_RE.test(reference.typeName)) continue;
|
|
9638
9753
|
if (CONFIGISH_NAME_RE.test(reference.name)) continue;
|
|
@@ -9666,19 +9781,19 @@ var subtreeHas = (root, found) => {
|
|
|
9666
9781
|
return hit;
|
|
9667
9782
|
};
|
|
9668
9783
|
var isFrameworkWiring = (body2) => subtreeHas(body2, (node) => {
|
|
9669
|
-
if (node.type ===
|
|
9784
|
+
if (node.type === AST_NODE_TYPES47.CallExpression) {
|
|
9670
9785
|
const { callee } = node;
|
|
9671
|
-
if (callee.type ===
|
|
9672
|
-
return callee.type ===
|
|
9786
|
+
if (callee.type === AST_NODE_TYPES47.Identifier) return callee.name === ROUTER_FACTORY_NAME;
|
|
9787
|
+
return callee.type === AST_NODE_TYPES47.MemberExpression && !callee.computed && callee.property.type === AST_NODE_TYPES47.Identifier && callee.property.name === ROUTER_FACTORY_NAME;
|
|
9673
9788
|
}
|
|
9674
|
-
return node.type ===
|
|
9789
|
+
return node.type === AST_NODE_TYPES47.TSTypeReference && node.typeName.type === AST_NODE_TYPES47.TSQualifiedName && FRAMEWORK_HTTP_TYPES.has(node.typeName.right.name);
|
|
9675
9790
|
});
|
|
9676
9791
|
var stem2 = (name) => name.replace(/^I(?=[A-Z])/, "").replace(/Impl$/, "");
|
|
9677
9792
|
var fileInterfaceNames = (program) => {
|
|
9678
9793
|
const names = [];
|
|
9679
9794
|
for (const statement of program.body) {
|
|
9680
|
-
const declaration = statement.type ===
|
|
9681
|
-
if (declaration?.type ===
|
|
9795
|
+
const declaration = statement.type === AST_NODE_TYPES47.ExportNamedDeclaration ? statement.declaration : statement;
|
|
9796
|
+
if (declaration?.type === AST_NODE_TYPES47.TSInterfaceDeclaration) names.push(declaration.id.name);
|
|
9682
9797
|
}
|
|
9683
9798
|
return names;
|
|
9684
9799
|
};
|
|
@@ -9696,11 +9811,11 @@ var isTransportWrapper = (className, collaborators, program) => {
|
|
|
9696
9811
|
var publicMethodNames = (body2) => {
|
|
9697
9812
|
const names = [];
|
|
9698
9813
|
for (const member of body2.body) {
|
|
9699
|
-
if (member.type !==
|
|
9814
|
+
if (member.type !== AST_NODE_TYPES47.MethodDefinition) continue;
|
|
9700
9815
|
if (member.kind !== "method" || member.static) continue;
|
|
9701
9816
|
if (member.accessibility === "private" || member.accessibility === "protected") continue;
|
|
9702
|
-
if (member.key.type ===
|
|
9703
|
-
if (member.key.type ===
|
|
9817
|
+
if (member.key.type === AST_NODE_TYPES47.PrivateIdentifier) continue;
|
|
9818
|
+
if (member.key.type === AST_NODE_TYPES47.Identifier) names.push(member.key.name);
|
|
9704
9819
|
else names.push("\u2026");
|
|
9705
9820
|
}
|
|
9706
9821
|
return names;
|
|
@@ -9733,7 +9848,7 @@ var require_interface_for_injected_service_default = createRule({
|
|
|
9733
9848
|
if (node.implements.length > 0) return;
|
|
9734
9849
|
if (node.decorators.length > 0) return;
|
|
9735
9850
|
const ctor = node.body.body.find(
|
|
9736
|
-
(member) => member.type ===
|
|
9851
|
+
(member) => member.type === AST_NODE_TYPES47.MethodDefinition && member.kind === "constructor"
|
|
9737
9852
|
);
|
|
9738
9853
|
if (ctor === void 0) return;
|
|
9739
9854
|
const { collaborators, constructedFields } = readConstructor(
|
|
@@ -9762,37 +9877,37 @@ var require_interface_for_injected_service_default = createRule({
|
|
|
9762
9877
|
});
|
|
9763
9878
|
|
|
9764
9879
|
// src/rules/require-static-next-matcher.ts
|
|
9765
|
-
import { AST_NODE_TYPES as
|
|
9880
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES48 } from "@typescript-eslint/utils";
|
|
9766
9881
|
var NEXT_ENTRY_FILE = /(?:^|[/\\])(?:middleware|proxy)\.[cm]?[jt]sx?$/u;
|
|
9767
9882
|
function unwrapExpression(node) {
|
|
9768
|
-
if (node.type ===
|
|
9883
|
+
if (node.type === AST_NODE_TYPES48.TSAsExpression || node.type === AST_NODE_TYPES48.TSSatisfiesExpression || node.type === AST_NODE_TYPES48.TSNonNullExpression || node.type === AST_NODE_TYPES48.TSTypeAssertion) {
|
|
9769
9884
|
return unwrapExpression(node.expression);
|
|
9770
9885
|
}
|
|
9771
9886
|
return node;
|
|
9772
9887
|
}
|
|
9773
9888
|
function isStaticValue(node) {
|
|
9774
9889
|
const value = unwrapExpression(node);
|
|
9775
|
-
if (value.type ===
|
|
9890
|
+
if (value.type === AST_NODE_TYPES48.Literal) {
|
|
9776
9891
|
return true;
|
|
9777
9892
|
}
|
|
9778
|
-
if (value.type ===
|
|
9893
|
+
if (value.type === AST_NODE_TYPES48.TemplateLiteral) {
|
|
9779
9894
|
return value.expressions.length === 0;
|
|
9780
9895
|
}
|
|
9781
|
-
if (value.type ===
|
|
9896
|
+
if (value.type === AST_NODE_TYPES48.ArrayExpression) {
|
|
9782
9897
|
return value.elements.every(
|
|
9783
|
-
(element) => element !== null && element.type !==
|
|
9898
|
+
(element) => element !== null && element.type !== AST_NODE_TYPES48.SpreadElement && isStaticValue(element)
|
|
9784
9899
|
);
|
|
9785
9900
|
}
|
|
9786
|
-
if (value.type ===
|
|
9901
|
+
if (value.type === AST_NODE_TYPES48.ObjectExpression) {
|
|
9787
9902
|
return value.properties.every(
|
|
9788
|
-
(property) => property.type ===
|
|
9903
|
+
(property) => property.type === AST_NODE_TYPES48.Property && property.kind === "init" && !property.computed && property.value.type !== AST_NODE_TYPES48.AssignmentPattern && isStaticValue(property.value)
|
|
9789
9904
|
);
|
|
9790
9905
|
}
|
|
9791
9906
|
return false;
|
|
9792
9907
|
}
|
|
9793
9908
|
function propertyName2(property) {
|
|
9794
9909
|
if (property.computed) return null;
|
|
9795
|
-
if (property.key.type ===
|
|
9910
|
+
if (property.key.type === AST_NODE_TYPES48.Identifier) return property.key.name;
|
|
9796
9911
|
return typeof property.key.value === "string" ? property.key.value : null;
|
|
9797
9912
|
}
|
|
9798
9913
|
var require_static_next_matcher_default = createRule({
|
|
@@ -9814,19 +9929,19 @@ var require_static_next_matcher_default = createRule({
|
|
|
9814
9929
|
}
|
|
9815
9930
|
return {
|
|
9816
9931
|
ExportNamedDeclaration(node) {
|
|
9817
|
-
if (node.declaration?.type !==
|
|
9932
|
+
if (node.declaration?.type !== AST_NODE_TYPES48.VariableDeclaration) {
|
|
9818
9933
|
return;
|
|
9819
9934
|
}
|
|
9820
9935
|
for (const declaration of node.declaration.declarations) {
|
|
9821
|
-
if (declaration.id.type !==
|
|
9936
|
+
if (declaration.id.type !== AST_NODE_TYPES48.Identifier || declaration.id.name !== "config" || declaration.init === null) {
|
|
9822
9937
|
continue;
|
|
9823
9938
|
}
|
|
9824
9939
|
const config = unwrapExpression(declaration.init);
|
|
9825
|
-
if (config.type !==
|
|
9940
|
+
if (config.type !== AST_NODE_TYPES48.ObjectExpression) {
|
|
9826
9941
|
continue;
|
|
9827
9942
|
}
|
|
9828
9943
|
for (const property of config.properties) {
|
|
9829
|
-
if (property.type !==
|
|
9944
|
+
if (property.type !== AST_NODE_TYPES48.Property || propertyName2(property) !== "matcher" || property.value.type === AST_NODE_TYPES48.AssignmentPattern) {
|
|
9830
9945
|
continue;
|
|
9831
9946
|
}
|
|
9832
9947
|
if (!isStaticValue(property.value)) {
|
|
@@ -9840,18 +9955,18 @@ var require_static_next_matcher_default = createRule({
|
|
|
9840
9955
|
});
|
|
9841
9956
|
|
|
9842
9957
|
// src/rules/require-zod-form-validation.ts
|
|
9843
|
-
import { AST_NODE_TYPES as
|
|
9958
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES49 } from "@typescript-eslint/utils";
|
|
9844
9959
|
var looksLikeZodSchema = (node) => {
|
|
9845
9960
|
let current = node;
|
|
9846
9961
|
while (true) {
|
|
9847
|
-
if (current.type ===
|
|
9962
|
+
if (current.type === AST_NODE_TYPES49.Identifier) {
|
|
9848
9963
|
return current.name === "z" || ZOD_SCHEMA_NAME_RE.test(current.name);
|
|
9849
9964
|
}
|
|
9850
|
-
if (current.type ===
|
|
9965
|
+
if (current.type === AST_NODE_TYPES49.CallExpression) {
|
|
9851
9966
|
current = current.callee;
|
|
9852
9967
|
continue;
|
|
9853
9968
|
}
|
|
9854
|
-
if (current.type ===
|
|
9969
|
+
if (current.type === AST_NODE_TYPES49.MemberExpression) {
|
|
9855
9970
|
current = current.object;
|
|
9856
9971
|
continue;
|
|
9857
9972
|
}
|
|
@@ -9859,23 +9974,23 @@ var looksLikeZodSchema = (node) => {
|
|
|
9859
9974
|
}
|
|
9860
9975
|
};
|
|
9861
9976
|
var isZodParseCall = (node) => {
|
|
9862
|
-
if (node.type !==
|
|
9977
|
+
if (node.type !== AST_NODE_TYPES49.CallExpression) return false;
|
|
9863
9978
|
const callee = node.callee;
|
|
9864
|
-
if (callee.type !==
|
|
9979
|
+
if (callee.type !== AST_NODE_TYPES49.MemberExpression) return false;
|
|
9865
9980
|
if (callee.computed) return false;
|
|
9866
|
-
if (callee.property.type !==
|
|
9981
|
+
if (callee.property.type !== AST_NODE_TYPES49.Identifier) return false;
|
|
9867
9982
|
const method = callee.property.name;
|
|
9868
9983
|
if (method !== "parse" && method !== "safeParse") return false;
|
|
9869
9984
|
return looksLikeZodSchema(callee.object);
|
|
9870
9985
|
};
|
|
9871
9986
|
var isFormDataMethodCall = (node) => {
|
|
9872
9987
|
let current = node;
|
|
9873
|
-
if (current.type ===
|
|
9988
|
+
if (current.type === AST_NODE_TYPES49.AwaitExpression) {
|
|
9874
9989
|
current = current.argument;
|
|
9875
9990
|
}
|
|
9876
|
-
if (current.type !==
|
|
9991
|
+
if (current.type !== AST_NODE_TYPES49.CallExpression) return false;
|
|
9877
9992
|
const callee = current.callee;
|
|
9878
|
-
return callee.type ===
|
|
9993
|
+
return callee.type === AST_NODE_TYPES49.MemberExpression && !callee.computed && callee.property.type === AST_NODE_TYPES49.Identifier && callee.property.name === "formData";
|
|
9879
9994
|
};
|
|
9880
9995
|
var require_zod_form_validation_default = createRule({
|
|
9881
9996
|
name: "require-zod-form-validation",
|
|
@@ -9895,14 +10010,14 @@ var require_zod_form_validation_default = createRule({
|
|
|
9895
10010
|
return {};
|
|
9896
10011
|
}
|
|
9897
10012
|
const isFormSourceIdentifier = (node) => {
|
|
9898
|
-
if (node.type !==
|
|
10013
|
+
if (node.type !== AST_NODE_TYPES49.Identifier) return false;
|
|
9899
10014
|
if (/formdata/i.test(node.name)) return true;
|
|
9900
10015
|
let scope = context.sourceCode.getScope(node);
|
|
9901
10016
|
while (scope !== null) {
|
|
9902
10017
|
const variable = scope.set.get(node.name);
|
|
9903
10018
|
if (variable !== void 0 && variable.defs.length === 1) {
|
|
9904
10019
|
const def = variable.defs[0];
|
|
9905
|
-
if (def !== void 0 && def.type === "Variable" && def.node.type ===
|
|
10020
|
+
if (def !== void 0 && def.type === "Variable" && def.node.type === AST_NODE_TYPES49.VariableDeclarator && def.node.init !== null) {
|
|
9906
10021
|
return isFormDataMethodCall(def.node.init);
|
|
9907
10022
|
}
|
|
9908
10023
|
return false;
|
|
@@ -9913,8 +10028,8 @@ var require_zod_form_validation_default = createRule({
|
|
|
9913
10028
|
};
|
|
9914
10029
|
const isFormDataGetCall = (node) => {
|
|
9915
10030
|
const callee = node.callee;
|
|
9916
|
-
if (callee.type !==
|
|
9917
|
-
if (callee.property.type !==
|
|
10031
|
+
if (callee.type !== AST_NODE_TYPES49.MemberExpression) return false;
|
|
10032
|
+
if (callee.property.type !== AST_NODE_TYPES49.Identifier || callee.property.name !== "get") {
|
|
9918
10033
|
return false;
|
|
9919
10034
|
}
|
|
9920
10035
|
return isFormSourceIdentifier(callee.object);
|
|
@@ -9929,11 +10044,11 @@ var require_zod_form_validation_default = createRule({
|
|
|
9929
10044
|
};
|
|
9930
10045
|
const isInstanceofNarrowing = (node) => {
|
|
9931
10046
|
const parent = node.parent;
|
|
9932
|
-
return parent !== null && parent !== void 0 && parent.type ===
|
|
10047
|
+
return parent !== null && parent !== void 0 && parent.type === AST_NODE_TYPES49.BinaryExpression && parent.operator === "instanceof" && parent.left === node && parent.right.type === AST_NODE_TYPES49.Identifier && (parent.right.name === "File" || parent.right.name === "Blob");
|
|
9933
10048
|
};
|
|
9934
10049
|
const boundDeclarator = (node) => {
|
|
9935
10050
|
const parent = node.parent;
|
|
9936
|
-
if (parent.type ===
|
|
10051
|
+
if (parent.type === AST_NODE_TYPES49.VariableDeclarator && parent.init === node && parent.id.type === AST_NODE_TYPES49.Identifier) {
|
|
9937
10052
|
return parent;
|
|
9938
10053
|
}
|
|
9939
10054
|
return null;
|
|
@@ -9992,7 +10107,7 @@ var store_insert_requires_on_conflict_default = createRule({
|
|
|
9992
10107
|
});
|
|
9993
10108
|
|
|
9994
10109
|
// src/rules/zod-naming-convention.ts
|
|
9995
|
-
import { AST_NODE_TYPES as
|
|
10110
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES50 } from "@typescript-eslint/utils";
|
|
9996
10111
|
var CONVENTIONS = {
|
|
9997
10112
|
prefix: { test: ZOD_PREFIX_RE, messageId: "zPrefix" },
|
|
9998
10113
|
suffix: { test: ZOD_SUFFIX_RE, messageId: "schemaSuffix" },
|
|
@@ -10017,15 +10132,15 @@ var NON_SCHEMA_TERMINALS = /* @__PURE__ */ new Set([
|
|
|
10017
10132
|
"registry",
|
|
10018
10133
|
"implement"
|
|
10019
10134
|
]);
|
|
10020
|
-
var terminalMethodName = (callee) => !callee.computed && callee.property.type ===
|
|
10135
|
+
var terminalMethodName = (callee) => !callee.computed && callee.property.type === AST_NODE_TYPES50.Identifier ? callee.property.name : null;
|
|
10021
10136
|
var calleeChainStartsWithZ = (node) => {
|
|
10022
10137
|
let current = node;
|
|
10023
|
-
while (current.type ===
|
|
10138
|
+
while (current.type === AST_NODE_TYPES50.MemberExpression) {
|
|
10024
10139
|
const receiver = current.object;
|
|
10025
|
-
if (receiver.type ===
|
|
10140
|
+
if (receiver.type === AST_NODE_TYPES50.Identifier && receiver.name === "z") {
|
|
10026
10141
|
return true;
|
|
10027
10142
|
}
|
|
10028
|
-
if (receiver.type ===
|
|
10143
|
+
if (receiver.type === AST_NODE_TYPES50.CallExpression) {
|
|
10029
10144
|
current = receiver.callee;
|
|
10030
10145
|
continue;
|
|
10031
10146
|
}
|
|
@@ -10070,13 +10185,13 @@ var zod_naming_convention_default = createRule({
|
|
|
10070
10185
|
VariableDeclarator(node) {
|
|
10071
10186
|
const init = node.init;
|
|
10072
10187
|
if (init === null || init === void 0) return;
|
|
10073
|
-
if (init.type !==
|
|
10188
|
+
if (init.type !== AST_NODE_TYPES50.CallExpression) return;
|
|
10074
10189
|
const callee = init.callee;
|
|
10075
|
-
if (callee.type !==
|
|
10190
|
+
if (callee.type !== AST_NODE_TYPES50.MemberExpression) return;
|
|
10076
10191
|
if (!calleeChainStartsWithZ(callee)) return;
|
|
10077
10192
|
const terminal = terminalMethodName(callee);
|
|
10078
10193
|
if (terminal !== null && NON_SCHEMA_TERMINALS.has(terminal)) return;
|
|
10079
|
-
if (node.id.type !==
|
|
10194
|
+
if (node.id.type !== AST_NODE_TYPES50.Identifier) return;
|
|
10080
10195
|
if (test.test(node.id.name)) return;
|
|
10081
10196
|
if (acceptsSchemaWord && CONTAINS_SCHEMA_RE.test(node.id.name)) return;
|
|
10082
10197
|
context.report({
|
|
@@ -10187,10 +10302,11 @@ var rules = {
|
|
|
10187
10302
|
"no-zod-native-enum": no_zod_native_enum_default,
|
|
10188
10303
|
"prefer-constant-time-secret-compare": prefer_constant_time_secret_compare_default,
|
|
10189
10304
|
"prefer-discriminated-union": prefer_discriminated_union_default,
|
|
10305
|
+
"prefer-input-group-search": prefer_input_group_search_default,
|
|
10190
10306
|
"prefer-module-level-constant": prefer_module_level_constant_default,
|
|
10191
10307
|
"prefer-module-level-schema": prefer_module_level_schema_default,
|
|
10192
|
-
"prefer-non-nullable-collection": prefer_non_nullable_collection_default,
|
|
10193
10308
|
"prefer-native-random-uuid": prefer_native_random_uuid_default,
|
|
10309
|
+
"prefer-non-nullable-collection": prefer_non_nullable_collection_default,
|
|
10194
10310
|
"prefer-schema-for-api-payload": prefer_schema_for_api_payload_default,
|
|
10195
10311
|
"prefer-semantic-colors": prefer_semantic_colors_default,
|
|
10196
10312
|
"prefer-server-actions": prefer_server_actions_default,
|
|
@@ -10209,7 +10325,7 @@ var rules = {
|
|
|
10209
10325
|
};
|
|
10210
10326
|
var meta = {
|
|
10211
10327
|
name: "@sarj/eslint-plugin",
|
|
10212
|
-
version: "9.
|
|
10328
|
+
version: "9.11.0"
|
|
10213
10329
|
};
|
|
10214
10330
|
var applicationOnlyRules = [
|
|
10215
10331
|
"no-restricted-library-load",
|
|
@@ -10252,6 +10368,7 @@ var recommendedRules = {
|
|
|
10252
10368
|
"@sarj/no-zod-native-enum": "warn",
|
|
10253
10369
|
"@sarj/prefer-constant-time-secret-compare": "error",
|
|
10254
10370
|
"@sarj/prefer-discriminated-union": "warn",
|
|
10371
|
+
"@sarj/prefer-input-group-search": "error",
|
|
10255
10372
|
"@sarj/prefer-module-level-constant": "warn",
|
|
10256
10373
|
"@sarj/prefer-module-level-schema": "warn",
|
|
10257
10374
|
"@sarj/prefer-non-nullable-collection": "warn",
|
|
@@ -10312,6 +10429,7 @@ var strictRules = {
|
|
|
10312
10429
|
"@sarj/no-zod-native-enum": "error",
|
|
10313
10430
|
"@sarj/prefer-constant-time-secret-compare": "error",
|
|
10314
10431
|
"@sarj/prefer-discriminated-union": "error",
|
|
10432
|
+
"@sarj/prefer-input-group-search": "error",
|
|
10315
10433
|
"@sarj/prefer-module-level-constant": "error",
|
|
10316
10434
|
"@sarj/prefer-module-level-schema": "error",
|
|
10317
10435
|
"@sarj/prefer-non-nullable-collection": "error",
|