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