@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.cjs
CHANGED
|
@@ -6632,8 +6632,121 @@ var prefer_discriminated_union_default = createRule({
|
|
|
6632
6632
|
}
|
|
6633
6633
|
});
|
|
6634
6634
|
|
|
6635
|
-
// src/rules/prefer-
|
|
6635
|
+
// src/rules/prefer-input-group-search.ts
|
|
6636
6636
|
var import_utils48 = require("@typescript-eslint/utils");
|
|
6637
|
+
var INPUT_MODULE = /(?:^|\/)components\/ui\/input$/u;
|
|
6638
|
+
var INPUT_GROUP_MODULE = /(?:^|\/)components\/ui\/input-group$/u;
|
|
6639
|
+
var MAX_JSX_DISTANCE = 2;
|
|
6640
|
+
function localNamedImports(node, importedName) {
|
|
6641
|
+
return node.specifiers.filter(
|
|
6642
|
+
(specifier) => specifier.type === import_utils48.AST_NODE_TYPES.ImportSpecifier && (specifier.imported.type === import_utils48.AST_NODE_TYPES.Identifier ? specifier.imported.name : specifier.imported.value) === importedName
|
|
6643
|
+
).map((specifier) => specifier.local.name);
|
|
6644
|
+
}
|
|
6645
|
+
function elementName(node) {
|
|
6646
|
+
return node.name.type === import_utils48.AST_NODE_TYPES.JSXIdentifier ? node.name.name : null;
|
|
6647
|
+
}
|
|
6648
|
+
function jsxAncestors(occurrence) {
|
|
6649
|
+
return occurrence.ancestors.filter(
|
|
6650
|
+
(ancestor) => ancestor.type === import_utils48.AST_NODE_TYPES.JSXElement
|
|
6651
|
+
);
|
|
6652
|
+
}
|
|
6653
|
+
function isWithinInputGroup(occurrence, inputGroupNames) {
|
|
6654
|
+
return jsxAncestors(occurrence).some(
|
|
6655
|
+
(ancestor) => inputGroupNames.has(elementName(ancestor.openingElement) ?? "")
|
|
6656
|
+
);
|
|
6657
|
+
}
|
|
6658
|
+
function nearestEligibleCommonAncestor(search, input, inputGroupNames) {
|
|
6659
|
+
const searchAncestors = jsxAncestors(search);
|
|
6660
|
+
const inputAncestorList = jsxAncestors(input);
|
|
6661
|
+
const inputAncestors = new Set(inputAncestorList);
|
|
6662
|
+
for (let index = searchAncestors.length - 1; index >= 0; index -= 1) {
|
|
6663
|
+
const ancestor = searchAncestors[index];
|
|
6664
|
+
if (ancestor === void 0) continue;
|
|
6665
|
+
if (!inputAncestors.has(ancestor)) continue;
|
|
6666
|
+
const searchDistance = searchAncestors.length - index - 1;
|
|
6667
|
+
const inputDistance = inputAncestorList.length - inputAncestorList.indexOf(ancestor) - 1;
|
|
6668
|
+
if (searchDistance > MAX_JSX_DISTANCE || inputDistance > MAX_JSX_DISTANCE) {
|
|
6669
|
+
return null;
|
|
6670
|
+
}
|
|
6671
|
+
if (inputGroupNames.has(elementName(ancestor.openingElement) ?? "")) {
|
|
6672
|
+
return null;
|
|
6673
|
+
}
|
|
6674
|
+
return ancestor;
|
|
6675
|
+
}
|
|
6676
|
+
return null;
|
|
6677
|
+
}
|
|
6678
|
+
var prefer_input_group_search_default = createRule({
|
|
6679
|
+
name: "prefer-input-group-search",
|
|
6680
|
+
meta: {
|
|
6681
|
+
type: "suggestion",
|
|
6682
|
+
docs: {
|
|
6683
|
+
description: "Require search icons and shared Input controls in the same visual wrapper to use InputGroup."
|
|
6684
|
+
},
|
|
6685
|
+
schema: [],
|
|
6686
|
+
messages: {
|
|
6687
|
+
preferInputGroup: "Use InputGroup with InputGroupAddon and InputGroupInput for this search field."
|
|
6688
|
+
}
|
|
6689
|
+
},
|
|
6690
|
+
defaultOptions: [],
|
|
6691
|
+
create(context) {
|
|
6692
|
+
const inputNames = /* @__PURE__ */ new Set();
|
|
6693
|
+
const inputGroupNames = /* @__PURE__ */ new Set();
|
|
6694
|
+
const searchNames = /* @__PURE__ */ new Set();
|
|
6695
|
+
const inputs = [];
|
|
6696
|
+
const searches = [];
|
|
6697
|
+
return {
|
|
6698
|
+
ImportDeclaration(node) {
|
|
6699
|
+
const source = String(node.source.value);
|
|
6700
|
+
if (source === "lucide-react") {
|
|
6701
|
+
localNamedImports(node, "Search").forEach(
|
|
6702
|
+
(name) => searchNames.add(name)
|
|
6703
|
+
);
|
|
6704
|
+
} else if (INPUT_MODULE.test(source)) {
|
|
6705
|
+
localNamedImports(node, "Input").forEach(
|
|
6706
|
+
(name) => inputNames.add(name)
|
|
6707
|
+
);
|
|
6708
|
+
} else if (INPUT_GROUP_MODULE.test(source)) {
|
|
6709
|
+
localNamedImports(node, "InputGroup").forEach(
|
|
6710
|
+
(name) => inputGroupNames.add(name)
|
|
6711
|
+
);
|
|
6712
|
+
}
|
|
6713
|
+
},
|
|
6714
|
+
JSXOpeningElement(node) {
|
|
6715
|
+
const name = elementName(node);
|
|
6716
|
+
if (name === null) return;
|
|
6717
|
+
const occurrence = {
|
|
6718
|
+
ancestors: context.sourceCode.getAncestors(node),
|
|
6719
|
+
node
|
|
6720
|
+
};
|
|
6721
|
+
if (searchNames.has(name)) searches.push(occurrence);
|
|
6722
|
+
if (inputNames.has(name)) inputs.push(occurrence);
|
|
6723
|
+
},
|
|
6724
|
+
"Program:exit"() {
|
|
6725
|
+
const reported = /* @__PURE__ */ new Set();
|
|
6726
|
+
for (const search of searches) {
|
|
6727
|
+
if (isWithinInputGroup(search, inputGroupNames)) continue;
|
|
6728
|
+
for (const input of inputs) {
|
|
6729
|
+
if (isWithinInputGroup(input, inputGroupNames)) continue;
|
|
6730
|
+
const wrapper = nearestEligibleCommonAncestor(
|
|
6731
|
+
search,
|
|
6732
|
+
input,
|
|
6733
|
+
inputGroupNames
|
|
6734
|
+
);
|
|
6735
|
+
if (wrapper === null || reported.has(wrapper)) continue;
|
|
6736
|
+
reported.add(wrapper);
|
|
6737
|
+
context.report({
|
|
6738
|
+
node: wrapper.openingElement,
|
|
6739
|
+
messageId: "preferInputGroup"
|
|
6740
|
+
});
|
|
6741
|
+
}
|
|
6742
|
+
}
|
|
6743
|
+
}
|
|
6744
|
+
};
|
|
6745
|
+
}
|
|
6746
|
+
});
|
|
6747
|
+
|
|
6748
|
+
// src/rules/prefer-module-level-constant.ts
|
|
6749
|
+
var import_utils49 = require("@typescript-eslint/utils");
|
|
6637
6750
|
var DEFAULT_MIN_ELEMENTS = 3;
|
|
6638
6751
|
var MAX_LITERAL_DEPTH = 4;
|
|
6639
6752
|
var IGNORE_PATTERNS2 = [
|
|
@@ -6662,9 +6775,9 @@ var MUTATING_METHODS = /* @__PURE__ */ new Set([
|
|
|
6662
6775
|
"assign"
|
|
6663
6776
|
]);
|
|
6664
6777
|
var FUNCTION_TYPES5 = /* @__PURE__ */ new Set([
|
|
6665
|
-
|
|
6666
|
-
|
|
6667
|
-
|
|
6778
|
+
import_utils49.AST_NODE_TYPES.FunctionDeclaration,
|
|
6779
|
+
import_utils49.AST_NODE_TYPES.FunctionExpression,
|
|
6780
|
+
import_utils49.AST_NODE_TYPES.ArrowFunctionExpression
|
|
6668
6781
|
]);
|
|
6669
6782
|
var COLLECTION_CONSTRUCTORS = /* @__PURE__ */ new Set(["Set", "Map"]);
|
|
6670
6783
|
function isIgnoredFile2(filename, sourceText) {
|
|
@@ -6677,14 +6790,14 @@ function isLocalFixtureFile(filename) {
|
|
|
6677
6790
|
return isTestFile(filename) || isStoryFile(filename);
|
|
6678
6791
|
}
|
|
6679
6792
|
function unwrap3(node) {
|
|
6680
|
-
if (node.type ===
|
|
6793
|
+
if (node.type === import_utils49.AST_NODE_TYPES.TSAsExpression || node.type === import_utils49.AST_NODE_TYPES.TSSatisfiesExpression || node.type === import_utils49.AST_NODE_TYPES.TSNonNullExpression) {
|
|
6681
6794
|
return unwrap3(node.expression);
|
|
6682
6795
|
}
|
|
6683
6796
|
return node;
|
|
6684
6797
|
}
|
|
6685
6798
|
var HAS_STATEFUL_FLAG_RE = /[gy]/;
|
|
6686
6799
|
function isRegexLiteral(node) {
|
|
6687
|
-
return node.type ===
|
|
6800
|
+
return node.type === import_utils49.AST_NODE_TYPES.Literal && "regex" in node && node.regex !== void 0;
|
|
6688
6801
|
}
|
|
6689
6802
|
function isLiteralOnly(node, depth) {
|
|
6690
6803
|
if (depth > MAX_LITERAL_DEPTH) {
|
|
@@ -6692,29 +6805,29 @@ function isLiteralOnly(node, depth) {
|
|
|
6692
6805
|
}
|
|
6693
6806
|
const inner = unwrap3(node);
|
|
6694
6807
|
switch (inner.type) {
|
|
6695
|
-
case
|
|
6808
|
+
case import_utils49.AST_NODE_TYPES.Literal: {
|
|
6696
6809
|
return !(isRegexLiteral(inner) && HAS_STATEFUL_FLAG_RE.test(inner.regex.flags));
|
|
6697
6810
|
}
|
|
6698
|
-
case
|
|
6811
|
+
case import_utils49.AST_NODE_TYPES.TemplateLiteral: {
|
|
6699
6812
|
return inner.expressions.length === 0;
|
|
6700
6813
|
}
|
|
6701
|
-
case
|
|
6702
|
-
return (inner.operator === "-" || inner.operator === "+") && inner.argument.type ===
|
|
6814
|
+
case import_utils49.AST_NODE_TYPES.UnaryExpression: {
|
|
6815
|
+
return (inner.operator === "-" || inner.operator === "+") && inner.argument.type === import_utils49.AST_NODE_TYPES.Literal && typeof inner.argument.value === "number";
|
|
6703
6816
|
}
|
|
6704
|
-
case
|
|
6817
|
+
case import_utils49.AST_NODE_TYPES.ArrayExpression: {
|
|
6705
6818
|
return inner.elements.every(
|
|
6706
|
-
(el) => el !== null && el.type !==
|
|
6819
|
+
(el) => el !== null && el.type !== import_utils49.AST_NODE_TYPES.SpreadElement && isLiteralOnly(el, depth + 1)
|
|
6707
6820
|
);
|
|
6708
6821
|
}
|
|
6709
|
-
case
|
|
6822
|
+
case import_utils49.AST_NODE_TYPES.ObjectExpression: {
|
|
6710
6823
|
return inner.properties.every((prop) => {
|
|
6711
|
-
if (prop.type !==
|
|
6824
|
+
if (prop.type !== import_utils49.AST_NODE_TYPES.Property) {
|
|
6712
6825
|
return false;
|
|
6713
6826
|
}
|
|
6714
6827
|
if (prop.shorthand || prop.method || prop.kind !== "init") {
|
|
6715
6828
|
return false;
|
|
6716
6829
|
}
|
|
6717
|
-
if (prop.computed && prop.key.type !==
|
|
6830
|
+
if (prop.computed && prop.key.type !== import_utils49.AST_NODE_TYPES.Literal) {
|
|
6718
6831
|
return false;
|
|
6719
6832
|
}
|
|
6720
6833
|
return isLiteralOnly(prop.value, depth + 1);
|
|
@@ -6727,7 +6840,7 @@ function isLiteralOnly(node, depth) {
|
|
|
6727
6840
|
}
|
|
6728
6841
|
function unwrapObjectFreeze(node) {
|
|
6729
6842
|
const inner = unwrap3(node);
|
|
6730
|
-
if (inner.type ===
|
|
6843
|
+
if (inner.type === import_utils49.AST_NODE_TYPES.CallExpression && inner.callee.type === import_utils49.AST_NODE_TYPES.MemberExpression && !inner.callee.computed && inner.callee.object.type === import_utils49.AST_NODE_TYPES.Identifier && inner.callee.object.name === "Object" && inner.callee.property.type === import_utils49.AST_NODE_TYPES.Identifier && inner.callee.property.name === "freeze" && inner.arguments.length === 1 && inner.arguments[0] !== void 0 && inner.arguments[0].type !== import_utils49.AST_NODE_TYPES.SpreadElement) {
|
|
6731
6844
|
return unwrap3(inner.arguments[0]);
|
|
6732
6845
|
}
|
|
6733
6846
|
return inner;
|
|
@@ -6743,19 +6856,19 @@ function classify(init, checkRegex) {
|
|
|
6743
6856
|
}
|
|
6744
6857
|
return { kind: "regex", size: 1 };
|
|
6745
6858
|
}
|
|
6746
|
-
if (node.type ===
|
|
6859
|
+
if (node.type === import_utils49.AST_NODE_TYPES.ArrayExpression) {
|
|
6747
6860
|
return isLiteralOnly(node, 0) ? { kind: "array", size: node.elements.length } : null;
|
|
6748
6861
|
}
|
|
6749
|
-
if (node.type ===
|
|
6862
|
+
if (node.type === import_utils49.AST_NODE_TYPES.ObjectExpression) {
|
|
6750
6863
|
return isLiteralOnly(node, 0) ? { kind: "object", size: node.properties.length } : null;
|
|
6751
6864
|
}
|
|
6752
|
-
if (node.type ===
|
|
6865
|
+
if (node.type === import_utils49.AST_NODE_TYPES.NewExpression && node.callee.type === import_utils49.AST_NODE_TYPES.Identifier && COLLECTION_CONSTRUCTORS.has(node.callee.name)) {
|
|
6753
6866
|
const arg = node.arguments[0];
|
|
6754
|
-
if (node.arguments.length !== 1 || arg === void 0 || arg.type ===
|
|
6867
|
+
if (node.arguments.length !== 1 || arg === void 0 || arg.type === import_utils49.AST_NODE_TYPES.SpreadElement) {
|
|
6755
6868
|
return null;
|
|
6756
6869
|
}
|
|
6757
6870
|
const entries = unwrap3(arg);
|
|
6758
|
-
if (entries.type !==
|
|
6871
|
+
if (entries.type !== import_utils49.AST_NODE_TYPES.ArrayExpression) {
|
|
6759
6872
|
return null;
|
|
6760
6873
|
}
|
|
6761
6874
|
return isLiteralOnly(entries, 0) ? { kind: node.callee.name === "Set" ? "Set" : "Map", size: entries.elements.length } : null;
|
|
@@ -6784,10 +6897,10 @@ var NON_RETAINING_BUILTINS = /* @__PURE__ */ new Map(
|
|
|
6784
6897
|
);
|
|
6785
6898
|
function isNonRetainingBuiltinCall(node, argument) {
|
|
6786
6899
|
const callee = node.callee;
|
|
6787
|
-
if (callee.type ===
|
|
6900
|
+
if (callee.type === import_utils49.AST_NODE_TYPES.Identifier && callee.name === "structuredClone") {
|
|
6788
6901
|
return true;
|
|
6789
6902
|
}
|
|
6790
|
-
if (callee.type !==
|
|
6903
|
+
if (callee.type !== import_utils49.AST_NODE_TYPES.MemberExpression || callee.computed || callee.object.type !== import_utils49.AST_NODE_TYPES.Identifier || callee.property.type !== import_utils49.AST_NODE_TYPES.Identifier) {
|
|
6791
6904
|
return false;
|
|
6792
6905
|
}
|
|
6793
6906
|
const members = NON_RETAINING_BUILTINS.get(callee.object.name);
|
|
@@ -6801,38 +6914,38 @@ function isNonRetainingBuiltinCall(node, argument) {
|
|
|
6801
6914
|
}
|
|
6802
6915
|
function isSafeRead(identifier) {
|
|
6803
6916
|
const parent = identifier.parent;
|
|
6804
|
-
if (parent.type ===
|
|
6917
|
+
if (parent.type === import_utils49.AST_NODE_TYPES.MemberExpression) {
|
|
6805
6918
|
if (parent.object !== identifier) {
|
|
6806
6919
|
return true;
|
|
6807
6920
|
}
|
|
6808
6921
|
const grandparent = parent.parent;
|
|
6809
|
-
if (grandparent.type ===
|
|
6922
|
+
if (grandparent.type === import_utils49.AST_NODE_TYPES.AssignmentExpression && grandparent.left === parent) {
|
|
6810
6923
|
return false;
|
|
6811
6924
|
}
|
|
6812
|
-
if (grandparent.type ===
|
|
6925
|
+
if (grandparent.type === import_utils49.AST_NODE_TYPES.UpdateExpression) {
|
|
6813
6926
|
return false;
|
|
6814
6927
|
}
|
|
6815
|
-
if (grandparent.type ===
|
|
6928
|
+
if (grandparent.type === import_utils49.AST_NODE_TYPES.UnaryExpression && grandparent.operator === "delete") {
|
|
6816
6929
|
return false;
|
|
6817
6930
|
}
|
|
6818
|
-
if (!parent.computed && parent.property.type ===
|
|
6931
|
+
if (!parent.computed && parent.property.type === import_utils49.AST_NODE_TYPES.Identifier && MUTATING_METHODS.has(parent.property.name) && grandparent.type === import_utils49.AST_NODE_TYPES.CallExpression && grandparent.callee === parent) {
|
|
6819
6932
|
return false;
|
|
6820
6933
|
}
|
|
6821
6934
|
return true;
|
|
6822
6935
|
}
|
|
6823
|
-
if (parent.type ===
|
|
6936
|
+
if (parent.type === import_utils49.AST_NODE_TYPES.ForOfStatement && parent.right === identifier) {
|
|
6824
6937
|
return true;
|
|
6825
6938
|
}
|
|
6826
|
-
if (parent.type ===
|
|
6939
|
+
if (parent.type === import_utils49.AST_NODE_TYPES.SpreadElement) {
|
|
6827
6940
|
return true;
|
|
6828
6941
|
}
|
|
6829
|
-
if (parent.type ===
|
|
6942
|
+
if (parent.type === import_utils49.AST_NODE_TYPES.BinaryExpression) {
|
|
6830
6943
|
return true;
|
|
6831
6944
|
}
|
|
6832
|
-
if (parent.type ===
|
|
6945
|
+
if (parent.type === import_utils49.AST_NODE_TYPES.CallExpression && parent.arguments.includes(identifier) && isNonRetainingBuiltinCall(parent, identifier)) {
|
|
6833
6946
|
return true;
|
|
6834
6947
|
}
|
|
6835
|
-
if (parent.type ===
|
|
6948
|
+
if (parent.type === import_utils49.AST_NODE_TYPES.UnaryExpression && parent.operator !== "delete") {
|
|
6836
6949
|
return true;
|
|
6837
6950
|
}
|
|
6838
6951
|
return false;
|
|
@@ -6887,7 +7000,7 @@ var prefer_module_level_constant_default = createRule({
|
|
|
6887
7000
|
if (reference.isWrite()) {
|
|
6888
7001
|
return false;
|
|
6889
7002
|
}
|
|
6890
|
-
if (reference.identifier.type !==
|
|
7003
|
+
if (reference.identifier.type !== import_utils49.AST_NODE_TYPES.Identifier) {
|
|
6891
7004
|
return false;
|
|
6892
7005
|
}
|
|
6893
7006
|
if (!isSafeRead(reference.identifier)) {
|
|
@@ -6899,10 +7012,10 @@ var prefer_module_level_constant_default = createRule({
|
|
|
6899
7012
|
return {
|
|
6900
7013
|
VariableDeclarator(node) {
|
|
6901
7014
|
const declaration = node.parent;
|
|
6902
|
-
if (declaration.type !==
|
|
7015
|
+
if (declaration.type !== import_utils49.AST_NODE_TYPES.VariableDeclaration || declaration.kind !== "const" || declaration.declare === true) {
|
|
6903
7016
|
return;
|
|
6904
7017
|
}
|
|
6905
|
-
if (node.id.type !==
|
|
7018
|
+
if (node.id.type !== import_utils49.AST_NODE_TYPES.Identifier || node.init === null) {
|
|
6906
7019
|
return;
|
|
6907
7020
|
}
|
|
6908
7021
|
if (enclosingFunction2(node) === null) {
|
|
@@ -6929,7 +7042,7 @@ var prefer_module_level_constant_default = createRule({
|
|
|
6929
7042
|
});
|
|
6930
7043
|
|
|
6931
7044
|
// src/rules/prefer-module-level-schema.ts
|
|
6932
|
-
var
|
|
7045
|
+
var import_utils50 = require("@typescript-eslint/utils");
|
|
6933
7046
|
|
|
6934
7047
|
// src/rules/_zod.ts
|
|
6935
7048
|
var ZOD_PREFIX_RE = /^Z[A-Z]/;
|
|
@@ -6995,9 +7108,9 @@ var I18N_RECEIVER_NAMES = /* @__PURE__ */ new Set([
|
|
|
6995
7108
|
"intl"
|
|
6996
7109
|
]);
|
|
6997
7110
|
var FUNCTION_TYPES6 = /* @__PURE__ */ new Set([
|
|
6998
|
-
|
|
6999
|
-
|
|
7000
|
-
|
|
7111
|
+
import_utils50.AST_NODE_TYPES.ArrowFunctionExpression,
|
|
7112
|
+
import_utils50.AST_NODE_TYPES.FunctionDeclaration,
|
|
7113
|
+
import_utils50.AST_NODE_TYPES.FunctionExpression
|
|
7001
7114
|
]);
|
|
7002
7115
|
function schemaExpression(node) {
|
|
7003
7116
|
let current = node;
|
|
@@ -7006,10 +7119,10 @@ function schemaExpression(node) {
|
|
|
7006
7119
|
if (parent === void 0) {
|
|
7007
7120
|
return current;
|
|
7008
7121
|
}
|
|
7009
|
-
if (parent.type ===
|
|
7122
|
+
if (parent.type === import_utils50.AST_NODE_TYPES.MemberExpression && parent.object === current && !parent.computed && parent.property.type === import_utils50.AST_NODE_TYPES.Identifier && TERMINAL_METHODS.has(parent.property.name)) {
|
|
7010
7123
|
return current;
|
|
7011
7124
|
}
|
|
7012
|
-
if (parent.type ===
|
|
7125
|
+
if (parent.type === import_utils50.AST_NODE_TYPES.MemberExpression && parent.object === current || parent.type === import_utils50.AST_NODE_TYPES.CallExpression && parent.callee === current || parent.type === import_utils50.AST_NODE_TYPES.TSAsExpression && parent.expression === current || parent.type === import_utils50.AST_NODE_TYPES.TSNonNullExpression && parent.expression === current) {
|
|
7013
7126
|
current = parent;
|
|
7014
7127
|
continue;
|
|
7015
7128
|
}
|
|
@@ -7060,22 +7173,22 @@ function subtreeSome(root, predicate) {
|
|
|
7060
7173
|
function readsReceiver(node) {
|
|
7061
7174
|
return subtreeSome(
|
|
7062
7175
|
node,
|
|
7063
|
-
(inner) => inner.type ===
|
|
7176
|
+
(inner) => inner.type === import_utils50.AST_NODE_TYPES.ThisExpression || inner.type === import_utils50.AST_NODE_TYPES.Super || inner.type === import_utils50.AST_NODE_TYPES.Identifier && inner.name === "arguments"
|
|
7064
7177
|
);
|
|
7065
7178
|
}
|
|
7066
7179
|
function buildsLocalizedText(node) {
|
|
7067
7180
|
return subtreeSome(node, (inner) => {
|
|
7068
|
-
if (inner.type ===
|
|
7181
|
+
if (inner.type === import_utils50.AST_NODE_TYPES.TaggedTemplateExpression) {
|
|
7069
7182
|
return true;
|
|
7070
7183
|
}
|
|
7071
|
-
if (inner.type !==
|
|
7184
|
+
if (inner.type !== import_utils50.AST_NODE_TYPES.CallExpression) {
|
|
7072
7185
|
return false;
|
|
7073
7186
|
}
|
|
7074
7187
|
const { callee } = inner;
|
|
7075
|
-
if (callee.type ===
|
|
7188
|
+
if (callee.type === import_utils50.AST_NODE_TYPES.Identifier) {
|
|
7076
7189
|
return I18N_CALLEE_NAMES.has(callee.name);
|
|
7077
7190
|
}
|
|
7078
|
-
return callee.type ===
|
|
7191
|
+
return callee.type === import_utils50.AST_NODE_TYPES.MemberExpression && !callee.computed && callee.object.type === import_utils50.AST_NODE_TYPES.Identifier && I18N_RECEIVER_NAMES.has(callee.object.name);
|
|
7079
7192
|
});
|
|
7080
7193
|
}
|
|
7081
7194
|
function collectReferences(scope, out) {
|
|
@@ -7132,15 +7245,15 @@ var prefer_module_level_schema_default = createRule({
|
|
|
7132
7245
|
}
|
|
7133
7246
|
const zodNamespaces = /* @__PURE__ */ new Set();
|
|
7134
7247
|
function isZodCall(node) {
|
|
7135
|
-
return node.type ===
|
|
7248
|
+
return node.type === import_utils50.AST_NODE_TYPES.CallExpression && node.callee.type === import_utils50.AST_NODE_TYPES.MemberExpression && !node.callee.computed && node.callee.object.type === import_utils50.AST_NODE_TYPES.Identifier && zodNamespaces.has(node.callee.object.name);
|
|
7136
7249
|
}
|
|
7137
7250
|
function isCovered(node) {
|
|
7138
7251
|
let current = node.parent ?? void 0;
|
|
7139
7252
|
while (current !== void 0) {
|
|
7140
|
-
if (current !== node && isZodCall(current) && current.callee.type ===
|
|
7253
|
+
if (current !== node && isZodCall(current) && current.callee.type === import_utils50.AST_NODE_TYPES.MemberExpression && current.callee.property.type === import_utils50.AST_NODE_TYPES.Identifier && factories.has(current.callee.property.name)) {
|
|
7141
7254
|
return true;
|
|
7142
7255
|
}
|
|
7143
|
-
if (current.type ===
|
|
7256
|
+
if (current.type === import_utils50.AST_NODE_TYPES.CallExpression && (current.callee.type === import_utils50.AST_NODE_TYPES.Identifier && MEMO_CALLEES.has(current.callee.name) || current.callee.type === import_utils50.AST_NODE_TYPES.MemberExpression && !current.callee.computed && current.callee.property.type === import_utils50.AST_NODE_TYPES.Identifier && MEMO_CALLEES.has(current.callee.property.name))) {
|
|
7144
7257
|
return true;
|
|
7145
7258
|
}
|
|
7146
7259
|
current = current.parent ?? void 0;
|
|
@@ -7155,11 +7268,11 @@ var prefer_module_level_schema_default = createRule({
|
|
|
7155
7268
|
if (parent === void 0) {
|
|
7156
7269
|
return confirmed;
|
|
7157
7270
|
}
|
|
7158
|
-
if (parent.type ===
|
|
7271
|
+
if (parent.type === import_utils50.AST_NODE_TYPES.Property && parent.value === current || parent.type === import_utils50.AST_NODE_TYPES.ObjectExpression || parent.type === import_utils50.AST_NODE_TYPES.ArrayExpression) {
|
|
7159
7272
|
current = parent;
|
|
7160
7273
|
continue;
|
|
7161
7274
|
}
|
|
7162
|
-
if (parent.type ===
|
|
7275
|
+
if (parent.type === import_utils50.AST_NODE_TYPES.CallExpression && parent.arguments.includes(current) && isSchemaComposition(parent)) {
|
|
7163
7276
|
current = schemaExpression(parent);
|
|
7164
7277
|
confirmed = current;
|
|
7165
7278
|
continue;
|
|
@@ -7169,7 +7282,7 @@ var prefer_module_level_schema_default = createRule({
|
|
|
7169
7282
|
}
|
|
7170
7283
|
function isSchemaComposition(node) {
|
|
7171
7284
|
const { callee } = node;
|
|
7172
|
-
const isCombinator = callee.type ===
|
|
7285
|
+
const isCombinator = callee.type === import_utils50.AST_NODE_TYPES.MemberExpression && !callee.computed && callee.property.type === import_utils50.AST_NODE_TYPES.Identifier && ZOD_COMBINATOR_METHODS.has(callee.property.name);
|
|
7173
7286
|
return isCombinator || isZodCall(node);
|
|
7174
7287
|
}
|
|
7175
7288
|
function closesOverNothing(node, enclosing) {
|
|
@@ -7203,13 +7316,13 @@ var prefer_module_level_schema_default = createRule({
|
|
|
7203
7316
|
}
|
|
7204
7317
|
function ownerName(enclosing) {
|
|
7205
7318
|
const parent = enclosing.parent ?? void 0;
|
|
7206
|
-
if (enclosing.type ===
|
|
7319
|
+
if (enclosing.type === import_utils50.AST_NODE_TYPES.FunctionDeclaration && enclosing.id !== null) {
|
|
7207
7320
|
return enclosing.id.name;
|
|
7208
7321
|
}
|
|
7209
|
-
if (parent !== void 0 && parent.type ===
|
|
7322
|
+
if (parent !== void 0 && parent.type === import_utils50.AST_NODE_TYPES.VariableDeclarator && parent.id.type === import_utils50.AST_NODE_TYPES.Identifier) {
|
|
7210
7323
|
return parent.id.name;
|
|
7211
7324
|
}
|
|
7212
|
-
if (parent !== void 0 && (parent.type ===
|
|
7325
|
+
if (parent !== void 0 && (parent.type === import_utils50.AST_NODE_TYPES.MethodDefinition || parent.type === import_utils50.AST_NODE_TYPES.Property) && parent.key.type === import_utils50.AST_NODE_TYPES.Identifier) {
|
|
7213
7326
|
return parent.key.name;
|
|
7214
7327
|
}
|
|
7215
7328
|
return "this function";
|
|
@@ -7220,7 +7333,7 @@ var prefer_module_level_schema_default = createRule({
|
|
|
7220
7333
|
return;
|
|
7221
7334
|
}
|
|
7222
7335
|
for (const specifier of node.specifiers) {
|
|
7223
|
-
if (specifier.type ===
|
|
7336
|
+
if (specifier.type === import_utils50.AST_NODE_TYPES.ImportNamespaceSpecifier || specifier.type === import_utils50.AST_NODE_TYPES.ImportDefaultSpecifier || specifier.type === import_utils50.AST_NODE_TYPES.ImportSpecifier && specifier.imported.type === import_utils50.AST_NODE_TYPES.Identifier && specifier.imported.name === "z") {
|
|
7224
7337
|
zodNamespaces.add(specifier.local.name);
|
|
7225
7338
|
}
|
|
7226
7339
|
}
|
|
@@ -7230,7 +7343,7 @@ var prefer_module_level_schema_default = createRule({
|
|
|
7230
7343
|
return;
|
|
7231
7344
|
}
|
|
7232
7345
|
const callee = node.callee;
|
|
7233
|
-
if (callee.property.type !==
|
|
7346
|
+
if (callee.property.type !== import_utils50.AST_NODE_TYPES.Identifier) {
|
|
7234
7347
|
return;
|
|
7235
7348
|
}
|
|
7236
7349
|
const factory = callee.property.name;
|
|
@@ -7245,7 +7358,7 @@ var prefer_module_level_schema_default = createRule({
|
|
|
7245
7358
|
return;
|
|
7246
7359
|
}
|
|
7247
7360
|
const shape = node.arguments[0];
|
|
7248
|
-
if (shape !== void 0 && shape.type ===
|
|
7361
|
+
if (shape !== void 0 && shape.type === import_utils50.AST_NODE_TYPES.ObjectExpression && shape.properties.length < minProperties) {
|
|
7249
7362
|
return;
|
|
7250
7363
|
}
|
|
7251
7364
|
const expression = schemaExpression(node);
|
|
@@ -7272,73 +7385,6 @@ var prefer_module_level_schema_default = createRule({
|
|
|
7272
7385
|
}
|
|
7273
7386
|
});
|
|
7274
7387
|
|
|
7275
|
-
// src/rules/prefer-non-nullable-collection.ts
|
|
7276
|
-
var import_utils50 = require("@typescript-eslint/utils");
|
|
7277
|
-
var ARRAY_TYPE_NAMES = /* @__PURE__ */ new Set(["Array", "ReadonlyArray"]);
|
|
7278
|
-
function propertyName(node) {
|
|
7279
|
-
const key = node.key;
|
|
7280
|
-
if (key.type === import_utils50.AST_NODE_TYPES.Identifier) return key.name;
|
|
7281
|
-
if (key.type === import_utils50.AST_NODE_TYPES.Literal) return String(key.value);
|
|
7282
|
-
return "collection";
|
|
7283
|
-
}
|
|
7284
|
-
function isArrayType(node) {
|
|
7285
|
-
if (node.type === import_utils50.AST_NODE_TYPES.TSArrayType) return true;
|
|
7286
|
-
return node.type === import_utils50.AST_NODE_TYPES.TSTypeReference && node.typeName.type === import_utils50.AST_NODE_TYPES.Identifier && ARRAY_TYPE_NAMES.has(node.typeName.name);
|
|
7287
|
-
}
|
|
7288
|
-
function isNullishType(node) {
|
|
7289
|
-
return node.type === import_utils50.AST_NODE_TYPES.TSNullKeyword || node.type === import_utils50.AST_NODE_TYPES.TSUndefinedKeyword;
|
|
7290
|
-
}
|
|
7291
|
-
function isNullableArrayOnly(node) {
|
|
7292
|
-
const values = node.types.filter((member) => !isNullishType(member));
|
|
7293
|
-
return values.length > 0 && values.length < node.types.length && values.every(isArrayType);
|
|
7294
|
-
}
|
|
7295
|
-
var prefer_non_nullable_collection_default = createRule({
|
|
7296
|
-
name: "prefer-non-nullable-collection",
|
|
7297
|
-
meta: {
|
|
7298
|
-
type: "suggestion",
|
|
7299
|
-
docs: {
|
|
7300
|
-
description: "Require declared data-shape properties and direct aliases to use non-null arrays instead of explicit nullish unions."
|
|
7301
|
-
},
|
|
7302
|
-
schema: [],
|
|
7303
|
-
messages: {
|
|
7304
|
-
preferNonNullableCollection: "`{{name}}` is a nullable array, so nullish and `[]` represent the same empty collection. Use a non-null array and default omitted values to `[]`."
|
|
7305
|
-
}
|
|
7306
|
-
},
|
|
7307
|
-
defaultOptions: [],
|
|
7308
|
-
create(context) {
|
|
7309
|
-
const normalizedFilename = context.filename.replaceAll("\\", "/");
|
|
7310
|
-
if (isTestFile(context.filename) || isGeneratedFile(context.filename, context.sourceCode.text) || /\/(?:vendor|vendored)\//u.test(normalizedFilename)) {
|
|
7311
|
-
return {};
|
|
7312
|
-
}
|
|
7313
|
-
function checkOptionalProperty(node) {
|
|
7314
|
-
if (node.optional) return;
|
|
7315
|
-
const annotation = node.typeAnnotation?.typeAnnotation;
|
|
7316
|
-
if (annotation === void 0) return;
|
|
7317
|
-
if (annotation.type !== import_utils50.AST_NODE_TYPES.TSUnionType || !isNullableArrayOnly(annotation)) {
|
|
7318
|
-
return;
|
|
7319
|
-
}
|
|
7320
|
-
context.report({
|
|
7321
|
-
node,
|
|
7322
|
-
messageId: "preferNonNullableCollection",
|
|
7323
|
-
data: { name: propertyName(node) }
|
|
7324
|
-
});
|
|
7325
|
-
}
|
|
7326
|
-
return {
|
|
7327
|
-
TSPropertySignature: checkOptionalProperty,
|
|
7328
|
-
PropertyDefinition: checkOptionalProperty,
|
|
7329
|
-
TSTypeAliasDeclaration(node) {
|
|
7330
|
-
if (node.typeAnnotation.type !== import_utils50.AST_NODE_TYPES.TSUnionType) return;
|
|
7331
|
-
if (!isNullableArrayOnly(node.typeAnnotation)) return;
|
|
7332
|
-
context.report({
|
|
7333
|
-
node,
|
|
7334
|
-
messageId: "preferNonNullableCollection",
|
|
7335
|
-
data: { name: node.id.name }
|
|
7336
|
-
});
|
|
7337
|
-
}
|
|
7338
|
-
};
|
|
7339
|
-
}
|
|
7340
|
-
});
|
|
7341
|
-
|
|
7342
7388
|
// src/rules/prefer-native-random-uuid.ts
|
|
7343
7389
|
var import_utils51 = require("@typescript-eslint/utils");
|
|
7344
7390
|
function requireUuid(node) {
|
|
@@ -7425,14 +7471,81 @@ var prefer_native_random_uuid_default = createRule({
|
|
|
7425
7471
|
}
|
|
7426
7472
|
});
|
|
7427
7473
|
|
|
7428
|
-
// src/rules/prefer-
|
|
7474
|
+
// src/rules/prefer-non-nullable-collection.ts
|
|
7429
7475
|
var import_utils52 = require("@typescript-eslint/utils");
|
|
7476
|
+
var ARRAY_TYPE_NAMES = /* @__PURE__ */ new Set(["Array", "ReadonlyArray"]);
|
|
7477
|
+
function propertyName(node) {
|
|
7478
|
+
const key = node.key;
|
|
7479
|
+
if (key.type === import_utils52.AST_NODE_TYPES.Identifier) return key.name;
|
|
7480
|
+
if (key.type === import_utils52.AST_NODE_TYPES.Literal) return String(key.value);
|
|
7481
|
+
return "collection";
|
|
7482
|
+
}
|
|
7483
|
+
function isArrayType(node) {
|
|
7484
|
+
if (node.type === import_utils52.AST_NODE_TYPES.TSArrayType) return true;
|
|
7485
|
+
return node.type === import_utils52.AST_NODE_TYPES.TSTypeReference && node.typeName.type === import_utils52.AST_NODE_TYPES.Identifier && ARRAY_TYPE_NAMES.has(node.typeName.name);
|
|
7486
|
+
}
|
|
7487
|
+
function isNullishType(node) {
|
|
7488
|
+
return node.type === import_utils52.AST_NODE_TYPES.TSNullKeyword || node.type === import_utils52.AST_NODE_TYPES.TSUndefinedKeyword;
|
|
7489
|
+
}
|
|
7490
|
+
function isNullableArrayOnly(node) {
|
|
7491
|
+
const values = node.types.filter((member) => !isNullishType(member));
|
|
7492
|
+
return values.length > 0 && values.length < node.types.length && values.every(isArrayType);
|
|
7493
|
+
}
|
|
7494
|
+
var prefer_non_nullable_collection_default = createRule({
|
|
7495
|
+
name: "prefer-non-nullable-collection",
|
|
7496
|
+
meta: {
|
|
7497
|
+
type: "suggestion",
|
|
7498
|
+
docs: {
|
|
7499
|
+
description: "Require declared data-shape properties and direct aliases to use non-null arrays instead of explicit nullish unions."
|
|
7500
|
+
},
|
|
7501
|
+
schema: [],
|
|
7502
|
+
messages: {
|
|
7503
|
+
preferNonNullableCollection: "`{{name}}` is a nullable array, so nullish and `[]` represent the same empty collection. Use a non-null array and default omitted values to `[]`."
|
|
7504
|
+
}
|
|
7505
|
+
},
|
|
7506
|
+
defaultOptions: [],
|
|
7507
|
+
create(context) {
|
|
7508
|
+
const normalizedFilename = context.filename.replaceAll("\\", "/");
|
|
7509
|
+
if (isTestFile(context.filename) || isGeneratedFile(context.filename, context.sourceCode.text) || /\/(?:vendor|vendored)\//u.test(normalizedFilename)) {
|
|
7510
|
+
return {};
|
|
7511
|
+
}
|
|
7512
|
+
function checkOptionalProperty(node) {
|
|
7513
|
+
if (node.optional) return;
|
|
7514
|
+
const annotation = node.typeAnnotation?.typeAnnotation;
|
|
7515
|
+
if (annotation === void 0) return;
|
|
7516
|
+
if (annotation.type !== import_utils52.AST_NODE_TYPES.TSUnionType || !isNullableArrayOnly(annotation)) {
|
|
7517
|
+
return;
|
|
7518
|
+
}
|
|
7519
|
+
context.report({
|
|
7520
|
+
node,
|
|
7521
|
+
messageId: "preferNonNullableCollection",
|
|
7522
|
+
data: { name: propertyName(node) }
|
|
7523
|
+
});
|
|
7524
|
+
}
|
|
7525
|
+
return {
|
|
7526
|
+
TSPropertySignature: checkOptionalProperty,
|
|
7527
|
+
PropertyDefinition: checkOptionalProperty,
|
|
7528
|
+
TSTypeAliasDeclaration(node) {
|
|
7529
|
+
if (node.typeAnnotation.type !== import_utils52.AST_NODE_TYPES.TSUnionType) return;
|
|
7530
|
+
if (!isNullableArrayOnly(node.typeAnnotation)) return;
|
|
7531
|
+
context.report({
|
|
7532
|
+
node,
|
|
7533
|
+
messageId: "preferNonNullableCollection",
|
|
7534
|
+
data: { name: node.id.name }
|
|
7535
|
+
});
|
|
7536
|
+
}
|
|
7537
|
+
};
|
|
7538
|
+
}
|
|
7539
|
+
});
|
|
7540
|
+
|
|
7541
|
+
// src/rules/prefer-schema-for-api-payload.ts
|
|
7542
|
+
var import_utils53 = require("@typescript-eslint/utils");
|
|
7430
7543
|
var unwrap4 = (node) => {
|
|
7431
7544
|
let current = node;
|
|
7432
7545
|
while (current !== null && current !== void 0) {
|
|
7433
|
-
if (current.type ===
|
|
7546
|
+
if (current.type === import_utils53.AST_NODE_TYPES.TSAsExpression || current.type === import_utils53.AST_NODE_TYPES.TSTypeAssertion || current.type === import_utils53.AST_NODE_TYPES.TSNonNullExpression || current.type === import_utils53.AST_NODE_TYPES.TSSatisfiesExpression) {
|
|
7434
7547
|
current = current.expression;
|
|
7435
|
-
} else if (current.type ===
|
|
7548
|
+
} else if (current.type === import_utils53.AST_NODE_TYPES.ChainExpression) {
|
|
7436
7549
|
current = current.expression;
|
|
7437
7550
|
} else {
|
|
7438
7551
|
break;
|
|
@@ -7447,23 +7560,23 @@ var PROMISE_CHAIN_METHODS = /* @__PURE__ */ new Set([
|
|
|
7447
7560
|
]);
|
|
7448
7561
|
var isSchemaParseReference = (node) => {
|
|
7449
7562
|
const inner = unwrap4(node);
|
|
7450
|
-
return inner !== null && inner.type ===
|
|
7563
|
+
return inner !== null && inner.type === import_utils53.AST_NODE_TYPES.MemberExpression && !inner.computed && inner.property.type === import_utils53.AST_NODE_TYPES.Identifier && (inner.property.name === "parse" || inner.property.name === "safeParse");
|
|
7451
7564
|
};
|
|
7452
7565
|
var isRawPayloadSource = (node) => {
|
|
7453
7566
|
let current = unwrap4(node);
|
|
7454
7567
|
if (current === null) return false;
|
|
7455
|
-
if (current.type ===
|
|
7568
|
+
if (current.type === import_utils53.AST_NODE_TYPES.AwaitExpression) {
|
|
7456
7569
|
current = unwrap4(current.argument);
|
|
7457
7570
|
}
|
|
7458
|
-
if (current === null || current.type !==
|
|
7571
|
+
if (current === null || current.type !== import_utils53.AST_NODE_TYPES.CallExpression) {
|
|
7459
7572
|
return false;
|
|
7460
7573
|
}
|
|
7461
7574
|
const callee = unwrap4(current.callee);
|
|
7462
|
-
if (callee === null || callee.type !==
|
|
7575
|
+
if (callee === null || callee.type !== import_utils53.AST_NODE_TYPES.MemberExpression) {
|
|
7463
7576
|
return false;
|
|
7464
7577
|
}
|
|
7465
7578
|
const property = unwrap4(callee.property);
|
|
7466
|
-
if (property === null || property.type !==
|
|
7579
|
+
if (property === null || property.type !== import_utils53.AST_NODE_TYPES.Identifier) {
|
|
7467
7580
|
return false;
|
|
7468
7581
|
}
|
|
7469
7582
|
if (property.name === "json") {
|
|
@@ -7473,16 +7586,16 @@ var isRawPayloadSource = (node) => {
|
|
|
7473
7586
|
return !current.arguments.some(isSchemaParseReference) && isRawPayloadSource(callee.object);
|
|
7474
7587
|
}
|
|
7475
7588
|
const object = unwrap4(callee.object);
|
|
7476
|
-
return property.name === "parse" && object !== null && object.type ===
|
|
7589
|
+
return property.name === "parse" && object !== null && object.type === import_utils53.AST_NODE_TYPES.Identifier && object.name === "JSON" && !isLocalFileRead(current.arguments[0]);
|
|
7477
7590
|
};
|
|
7478
7591
|
var FILE_READ_RE = /^(readFile|readFileSync|readJson|readJsonSync|readJSON)$/;
|
|
7479
7592
|
var isLocalFileRead = (node) => {
|
|
7480
7593
|
let found = false;
|
|
7481
7594
|
const visit = (current) => {
|
|
7482
7595
|
if (found || current === null || current === void 0) return;
|
|
7483
|
-
if (current.type ===
|
|
7596
|
+
if (current.type === import_utils53.AST_NODE_TYPES.CallExpression) {
|
|
7484
7597
|
const callee = unwrap4(current.callee);
|
|
7485
|
-
const name = callee?.type ===
|
|
7598
|
+
const name = callee?.type === import_utils53.AST_NODE_TYPES.Identifier ? callee.name : callee?.type === import_utils53.AST_NODE_TYPES.MemberExpression && !callee.computed && callee.property.type === import_utils53.AST_NODE_TYPES.Identifier ? callee.property.name : null;
|
|
7486
7599
|
if (name !== null && FILE_READ_RE.test(name)) {
|
|
7487
7600
|
found = true;
|
|
7488
7601
|
return;
|
|
@@ -7504,15 +7617,15 @@ var isLocalFileRead = (node) => {
|
|
|
7504
7617
|
var ASSERTION_CALLEE_RE = /^(expect|assert|should|invariant)$/;
|
|
7505
7618
|
var isInsideAssertion = (node) => {
|
|
7506
7619
|
for (let current = node.parent; current !== void 0 && current !== null; current = current.parent) {
|
|
7507
|
-
if (current.type !==
|
|
7620
|
+
if (current.type !== import_utils53.AST_NODE_TYPES.CallExpression) continue;
|
|
7508
7621
|
let callee = current.callee;
|
|
7509
|
-
while (callee.type ===
|
|
7622
|
+
while (callee.type === import_utils53.AST_NODE_TYPES.MemberExpression) {
|
|
7510
7623
|
callee = callee.object;
|
|
7511
7624
|
}
|
|
7512
|
-
if (callee.type ===
|
|
7625
|
+
if (callee.type === import_utils53.AST_NODE_TYPES.CallExpression) {
|
|
7513
7626
|
callee = callee.callee;
|
|
7514
7627
|
}
|
|
7515
|
-
if (callee.type ===
|
|
7628
|
+
if (callee.type === import_utils53.AST_NODE_TYPES.Identifier && ASSERTION_CALLEE_RE.test(callee.name)) {
|
|
7516
7629
|
return true;
|
|
7517
7630
|
}
|
|
7518
7631
|
}
|
|
@@ -7531,39 +7644,39 @@ var GUARD_NAME_RE = /^(?:is|validate|parse|assert|decode|coerce)[A-Z]/;
|
|
|
7531
7644
|
var isValidationRead = (node) => {
|
|
7532
7645
|
let current = node;
|
|
7533
7646
|
let parent = current.parent;
|
|
7534
|
-
while (parent !== null && parent !== void 0 && (parent.type ===
|
|
7647
|
+
while (parent !== null && parent !== void 0 && (parent.type === import_utils53.AST_NODE_TYPES.TSAsExpression || parent.type === import_utils53.AST_NODE_TYPES.TSTypeAssertion || parent.type === import_utils53.AST_NODE_TYPES.TSNonNullExpression || parent.type === import_utils53.AST_NODE_TYPES.TSSatisfiesExpression || parent.type === import_utils53.AST_NODE_TYPES.ChainExpression)) {
|
|
7535
7648
|
current = parent;
|
|
7536
7649
|
parent = parent.parent;
|
|
7537
7650
|
}
|
|
7538
7651
|
if (parent === null || parent === void 0) return false;
|
|
7539
|
-
if (parent.type ===
|
|
7652
|
+
if (parent.type === import_utils53.AST_NODE_TYPES.UnaryExpression && parent.operator === "typeof" && parent.argument === current) {
|
|
7540
7653
|
return true;
|
|
7541
7654
|
}
|
|
7542
|
-
if (parent.type !==
|
|
7655
|
+
if (parent.type !== import_utils53.AST_NODE_TYPES.CallExpression || !parent.arguments.some((arg) => arg === current)) {
|
|
7543
7656
|
return false;
|
|
7544
7657
|
}
|
|
7545
7658
|
const callee = parent.callee;
|
|
7546
|
-
if (callee.type ===
|
|
7659
|
+
if (callee.type === import_utils53.AST_NODE_TYPES.MemberExpression && !callee.computed && callee.object.type === import_utils53.AST_NODE_TYPES.Identifier && callee.object.name === "Array" && callee.property.type === import_utils53.AST_NODE_TYPES.Identifier && callee.property.name === "isArray") {
|
|
7547
7660
|
return parent.arguments.length === 1;
|
|
7548
7661
|
}
|
|
7549
|
-
return callee.type ===
|
|
7662
|
+
return callee.type === import_utils53.AST_NODE_TYPES.Identifier && GUARD_NAME_RE.test(callee.name);
|
|
7550
7663
|
};
|
|
7551
7664
|
var isGuardTestPosition = (node) => {
|
|
7552
7665
|
let current = node;
|
|
7553
7666
|
let parent = current.parent;
|
|
7554
7667
|
while (parent !== void 0 && parent !== null) {
|
|
7555
7668
|
switch (parent.type) {
|
|
7556
|
-
case
|
|
7557
|
-
case
|
|
7558
|
-
case
|
|
7669
|
+
case import_utils53.AST_NODE_TYPES.UnaryExpression:
|
|
7670
|
+
case import_utils53.AST_NODE_TYPES.LogicalExpression:
|
|
7671
|
+
case import_utils53.AST_NODE_TYPES.ChainExpression:
|
|
7559
7672
|
current = parent;
|
|
7560
7673
|
parent = parent.parent;
|
|
7561
7674
|
continue;
|
|
7562
|
-
case
|
|
7563
|
-
case
|
|
7564
|
-
case
|
|
7565
|
-
case
|
|
7566
|
-
case
|
|
7675
|
+
case import_utils53.AST_NODE_TYPES.IfStatement:
|
|
7676
|
+
case import_utils53.AST_NODE_TYPES.ConditionalExpression:
|
|
7677
|
+
case import_utils53.AST_NODE_TYPES.WhileStatement:
|
|
7678
|
+
case import_utils53.AST_NODE_TYPES.DoWhileStatement:
|
|
7679
|
+
case import_utils53.AST_NODE_TYPES.ForStatement:
|
|
7567
7680
|
return parent.test === current;
|
|
7568
7681
|
default:
|
|
7569
7682
|
return false;
|
|
@@ -7573,7 +7686,7 @@ var isGuardTestPosition = (node) => {
|
|
|
7573
7686
|
};
|
|
7574
7687
|
var isUnvalidatedVariableRef = (node, scope, tracked) => {
|
|
7575
7688
|
const unwrapped = unwrap4(node);
|
|
7576
|
-
if (unwrapped === null || unwrapped.type !==
|
|
7689
|
+
if (unwrapped === null || unwrapped.type !== import_utils53.AST_NODE_TYPES.Identifier) {
|
|
7577
7690
|
return false;
|
|
7578
7691
|
}
|
|
7579
7692
|
const variable = findVariable2(scope, unwrapped.name);
|
|
@@ -7616,11 +7729,11 @@ var prefer_schema_for_api_payload_default = createRule({
|
|
|
7616
7729
|
return {
|
|
7617
7730
|
VariableDeclarator(node) {
|
|
7618
7731
|
const scope = context.sourceCode.getScope(node);
|
|
7619
|
-
if (node.id.type ===
|
|
7732
|
+
if (node.id.type === import_utils53.AST_NODE_TYPES.Identifier) {
|
|
7620
7733
|
trackInitializer(node);
|
|
7621
7734
|
return;
|
|
7622
7735
|
}
|
|
7623
|
-
if (node.id.type ===
|
|
7736
|
+
if (node.id.type === import_utils53.AST_NODE_TYPES.ObjectPattern || node.id.type === import_utils53.AST_NODE_TYPES.ArrayPattern) {
|
|
7624
7737
|
if (isRawPayloadSource(node.init)) {
|
|
7625
7738
|
if (!isFullyNarrowedPattern(node)) {
|
|
7626
7739
|
context.report({ node: node.id, messageId: "unparsedJsonAccess" });
|
|
@@ -7634,7 +7747,7 @@ var prefer_schema_for_api_payload_default = createRule({
|
|
|
7634
7747
|
},
|
|
7635
7748
|
AssignmentExpression(node) {
|
|
7636
7749
|
const scope = context.sourceCode.getScope(node);
|
|
7637
|
-
if (node.left.type ===
|
|
7750
|
+
if (node.left.type === import_utils53.AST_NODE_TYPES.Identifier) {
|
|
7638
7751
|
const variable = findVariable2(scope, node.left.name);
|
|
7639
7752
|
if (variable === null) return;
|
|
7640
7753
|
if (isRawPayloadSource(node.right)) {
|
|
@@ -7644,7 +7757,7 @@ var prefer_schema_for_api_payload_default = createRule({
|
|
|
7644
7757
|
}
|
|
7645
7758
|
return;
|
|
7646
7759
|
}
|
|
7647
|
-
if (node.left.type ===
|
|
7760
|
+
if (node.left.type === import_utils53.AST_NODE_TYPES.ObjectPattern || node.left.type === import_utils53.AST_NODE_TYPES.ArrayPattern) {
|
|
7648
7761
|
if (isRawPayloadSource(node.right)) {
|
|
7649
7762
|
context.report({
|
|
7650
7763
|
node: node.left,
|
|
@@ -7661,15 +7774,15 @@ var prefer_schema_for_api_payload_default = createRule({
|
|
|
7661
7774
|
}
|
|
7662
7775
|
},
|
|
7663
7776
|
CallExpression(node) {
|
|
7664
|
-
if (node.callee.type !==
|
|
7777
|
+
if (node.callee.type !== import_utils53.AST_NODE_TYPES.Identifier) return;
|
|
7665
7778
|
if (!GUARD_NAME_RE.test(node.callee.name) && !isGuardTestPosition(node)) {
|
|
7666
7779
|
return;
|
|
7667
7780
|
}
|
|
7668
7781
|
const scope = context.sourceCode.getScope(node);
|
|
7669
7782
|
for (const arg of node.arguments) {
|
|
7670
|
-
if (arg.type ===
|
|
7783
|
+
if (arg.type === import_utils53.AST_NODE_TYPES.SpreadElement) continue;
|
|
7671
7784
|
const unwrapped = unwrap4(arg);
|
|
7672
|
-
if (unwrapped === null || unwrapped.type !==
|
|
7785
|
+
if (unwrapped === null || unwrapped.type !== import_utils53.AST_NODE_TYPES.Identifier) {
|
|
7673
7786
|
continue;
|
|
7674
7787
|
}
|
|
7675
7788
|
const variable = findVariable2(scope, unwrapped.name);
|
|
@@ -7683,13 +7796,13 @@ var prefer_schema_for_api_payload_default = createRule({
|
|
|
7683
7796
|
const obj = unwrap4(node.object);
|
|
7684
7797
|
if (isRawPayloadSource(obj)) {
|
|
7685
7798
|
const parent = node.parent;
|
|
7686
|
-
if (parent.type ===
|
|
7799
|
+
if (parent.type === import_utils53.AST_NODE_TYPES.CallExpression && parent.callee === node && node.property.type === import_utils53.AST_NODE_TYPES.Identifier && (node.property.name === "parse" || node.property.name === "safeParse" || PROMISE_CHAIN_METHODS.has(node.property.name))) {
|
|
7687
7800
|
return;
|
|
7688
7801
|
}
|
|
7689
7802
|
context.report({ node, messageId: "unparsedJsonAccess" });
|
|
7690
7803
|
return;
|
|
7691
7804
|
}
|
|
7692
|
-
if (obj !== null && obj.type ===
|
|
7805
|
+
if (obj !== null && obj.type === import_utils53.AST_NODE_TYPES.Identifier && isUnvalidatedVariableRef(obj, scope, unvalidatedVariables)) {
|
|
7693
7806
|
context.report({ node, messageId: "unparsedJsonAccess" });
|
|
7694
7807
|
const variable = findVariable2(scope, obj.name);
|
|
7695
7808
|
if (variable !== null) {
|
|
@@ -7702,7 +7815,7 @@ var prefer_schema_for_api_payload_default = createRule({
|
|
|
7702
7815
|
});
|
|
7703
7816
|
|
|
7704
7817
|
// src/rules/prefer-semantic-colors.ts
|
|
7705
|
-
var
|
|
7818
|
+
var import_utils54 = require("@typescript-eslint/utils");
|
|
7706
7819
|
var import_fs = require("fs");
|
|
7707
7820
|
var import_path = require("path");
|
|
7708
7821
|
|
|
@@ -7802,8 +7915,8 @@ var SVG_EXEMPT_COLOR_VALUES = /* @__PURE__ */ new Set([
|
|
|
7802
7915
|
]);
|
|
7803
7916
|
function jsxElementName(node) {
|
|
7804
7917
|
const name = node.openingElement.name;
|
|
7805
|
-
if (name.type ===
|
|
7806
|
-
if (name.type ===
|
|
7918
|
+
if (name.type === import_utils54.AST_NODE_TYPES.JSXIdentifier) return name.name;
|
|
7919
|
+
if (name.type === import_utils54.AST_NODE_TYPES.JSXMemberExpression && name.property.type === import_utils54.AST_NODE_TYPES.JSXIdentifier) {
|
|
7807
7920
|
return name.property.name;
|
|
7808
7921
|
}
|
|
7809
7922
|
return null;
|
|
@@ -7829,7 +7942,7 @@ var EMAIL_OR_PDF_MODULE_RE = /^@react-(?:email|pdf)\//;
|
|
|
7829
7942
|
var isInsideSvg = (node) => {
|
|
7830
7943
|
let current = node.parent;
|
|
7831
7944
|
while (current !== void 0 && current !== null) {
|
|
7832
|
-
if (current.type ===
|
|
7945
|
+
if (current.type === import_utils54.AST_NODE_TYPES.JSXElement) {
|
|
7833
7946
|
const name = jsxElementName(current);
|
|
7834
7947
|
if (name !== null && isSvgLikeElementName(name)) return true;
|
|
7835
7948
|
}
|
|
@@ -7840,7 +7953,7 @@ var isInsideSvg = (node) => {
|
|
|
7840
7953
|
var isInsideIconFactoryPath = (node) => {
|
|
7841
7954
|
let current = node.parent;
|
|
7842
7955
|
while (current !== void 0 && current !== null) {
|
|
7843
|
-
if (current.type ===
|
|
7956
|
+
if (current.type === import_utils54.AST_NODE_TYPES.Property && propName(current.key) === "path" && current.parent.type === import_utils54.AST_NODE_TYPES.ObjectExpression && current.parent.parent.type === import_utils54.AST_NODE_TYPES.CallExpression && current.parent.parent.callee.type === import_utils54.AST_NODE_TYPES.Identifier && current.parent.parent.callee.name === "createIcon") {
|
|
7844
7957
|
return true;
|
|
7845
7958
|
}
|
|
7846
7959
|
current = current.parent;
|
|
@@ -7977,12 +8090,12 @@ var hasSemanticTokenSystem = (filename) => {
|
|
|
7977
8090
|
return root !== null && workspaceHasMarker(root);
|
|
7978
8091
|
};
|
|
7979
8092
|
var propName = (key) => {
|
|
7980
|
-
if (key.type ===
|
|
7981
|
-
if (key.type ===
|
|
8093
|
+
if (key.type === import_utils54.AST_NODE_TYPES.Identifier) return key.name;
|
|
8094
|
+
if (key.type === import_utils54.AST_NODE_TYPES.Literal && typeof key.value === "string") return key.value;
|
|
7982
8095
|
return null;
|
|
7983
8096
|
};
|
|
7984
8097
|
var staticallyImportsEmailOrPdfRenderer = (program) => program.body.some((statement) => {
|
|
7985
|
-
if (statement.type !==
|
|
8098
|
+
if (statement.type !== import_utils54.AST_NODE_TYPES.ImportDeclaration && statement.type !== import_utils54.AST_NODE_TYPES.ExportNamedDeclaration && statement.type !== import_utils54.AST_NODE_TYPES.ExportAllDeclaration) {
|
|
7986
8099
|
return false;
|
|
7987
8100
|
}
|
|
7988
8101
|
return statement.source !== null && typeof statement.source.value === "string" && EMAIL_OR_PDF_MODULE_RE.test(statement.source.value);
|
|
@@ -8034,27 +8147,27 @@ var prefer_semantic_colors_default = createRule({
|
|
|
8034
8147
|
const checkClassNode = (node) => {
|
|
8035
8148
|
if (node === null) return;
|
|
8036
8149
|
switch (node.type) {
|
|
8037
|
-
case
|
|
8150
|
+
case import_utils54.AST_NODE_TYPES.Literal:
|
|
8038
8151
|
if (typeof node.value === "string") reportClasses(node.value, node);
|
|
8039
8152
|
break;
|
|
8040
|
-
case
|
|
8153
|
+
case import_utils54.AST_NODE_TYPES.TemplateLiteral:
|
|
8041
8154
|
for (const quasi of node.quasis) reportClasses(quasi.value.cooked ?? "", quasi);
|
|
8042
8155
|
break;
|
|
8043
|
-
case
|
|
8156
|
+
case import_utils54.AST_NODE_TYPES.ArrayExpression:
|
|
8044
8157
|
for (const element of node.elements) {
|
|
8045
|
-
if (element !== null && element.type !==
|
|
8158
|
+
if (element !== null && element.type !== import_utils54.AST_NODE_TYPES.SpreadElement) checkClassNode(element);
|
|
8046
8159
|
}
|
|
8047
8160
|
break;
|
|
8048
|
-
case
|
|
8161
|
+
case import_utils54.AST_NODE_TYPES.ObjectExpression:
|
|
8049
8162
|
for (const property of node.properties) {
|
|
8050
|
-
if (property.type ===
|
|
8163
|
+
if (property.type === import_utils54.AST_NODE_TYPES.Property) checkClassNode(property.value);
|
|
8051
8164
|
}
|
|
8052
8165
|
break;
|
|
8053
|
-
case
|
|
8166
|
+
case import_utils54.AST_NODE_TYPES.ConditionalExpression:
|
|
8054
8167
|
checkClassNode(node.consequent);
|
|
8055
8168
|
checkClassNode(node.alternate);
|
|
8056
8169
|
break;
|
|
8057
|
-
case
|
|
8170
|
+
case import_utils54.AST_NODE_TYPES.LogicalExpression:
|
|
8058
8171
|
checkClassNode(node.right);
|
|
8059
8172
|
break;
|
|
8060
8173
|
default:
|
|
@@ -8062,32 +8175,32 @@ var prefer_semantic_colors_default = createRule({
|
|
|
8062
8175
|
}
|
|
8063
8176
|
};
|
|
8064
8177
|
const checkColorValueNode = (node) => {
|
|
8065
|
-
if (node.type ===
|
|
8178
|
+
if (node.type === import_utils54.AST_NODE_TYPES.Literal && typeof node.value === "string" && RAW_COLOR_VALUE_RE.test(node.value) && !CSS_VAR_REFERENCE_RE.test(node.value)) {
|
|
8066
8179
|
report(node, "inlineColor", { value: node.value });
|
|
8067
8180
|
}
|
|
8068
8181
|
};
|
|
8069
8182
|
return {
|
|
8070
8183
|
"JSXAttribute[name.name='className']"(node) {
|
|
8071
8184
|
if (node.value === null) return;
|
|
8072
|
-
if (node.value.type ===
|
|
8073
|
-
else if (node.value.type ===
|
|
8074
|
-
if (node.value.expression.type !==
|
|
8185
|
+
if (node.value.type === import_utils54.AST_NODE_TYPES.Literal) checkClassNode(node.value);
|
|
8186
|
+
else if (node.value.type === import_utils54.AST_NODE_TYPES.JSXExpressionContainer) {
|
|
8187
|
+
if (node.value.expression.type !== import_utils54.AST_NODE_TYPES.JSXEmptyExpression) {
|
|
8075
8188
|
checkClassNode(node.value.expression);
|
|
8076
8189
|
}
|
|
8077
8190
|
}
|
|
8078
8191
|
},
|
|
8079
8192
|
CallExpression(node) {
|
|
8080
|
-
if (node.callee.type ===
|
|
8193
|
+
if (node.callee.type === import_utils54.AST_NODE_TYPES.Identifier && node.callee.name === "require" && node.arguments[0]?.type === import_utils54.AST_NODE_TYPES.Literal && typeof node.arguments[0].value === "string" && EMAIL_OR_PDF_MODULE_RE.test(node.arguments[0].value)) {
|
|
8081
8194
|
importsEmailOrPdfRenderer = true;
|
|
8082
8195
|
}
|
|
8083
|
-
if (node.callee.type ===
|
|
8196
|
+
if (node.callee.type === import_utils54.AST_NODE_TYPES.Identifier && CLASS_FNS.has(node.callee.name)) {
|
|
8084
8197
|
for (const arg of node.arguments) {
|
|
8085
|
-
if (arg.type !==
|
|
8198
|
+
if (arg.type !== import_utils54.AST_NODE_TYPES.SpreadElement) checkClassNode(arg);
|
|
8086
8199
|
}
|
|
8087
8200
|
}
|
|
8088
8201
|
},
|
|
8089
8202
|
VariableDeclarator(node) {
|
|
8090
|
-
if (node.id.type ===
|
|
8203
|
+
if (node.id.type === import_utils54.AST_NODE_TYPES.Identifier && CLASS_NAME_RE.test(node.id.name)) {
|
|
8091
8204
|
checkClassNode(node.init);
|
|
8092
8205
|
}
|
|
8093
8206
|
},
|
|
@@ -8097,9 +8210,9 @@ var prefer_semantic_colors_default = createRule({
|
|
|
8097
8210
|
},
|
|
8098
8211
|
// SVG artwork colors are exempt; component presentation colors still report.
|
|
8099
8212
|
"JSXAttribute[name.name=/^(fill|stroke|color)$/]"(node) {
|
|
8100
|
-
if (node.value?.type !==
|
|
8213
|
+
if (node.value?.type !== import_utils54.AST_NODE_TYPES.Literal) return;
|
|
8101
8214
|
const owner = node.parent.name;
|
|
8102
|
-
if (owner.type ===
|
|
8215
|
+
if (owner.type === import_utils54.AST_NODE_TYPES.JSXIdentifier && SVG_SHAPE_PRIMITIVES.has(owner.name)) {
|
|
8103
8216
|
return;
|
|
8104
8217
|
}
|
|
8105
8218
|
if (typeof node.value.value === "string" && SVG_EXEMPT_COLOR_VALUES.has(node.value.value.toLowerCase())) {
|
|
@@ -8113,7 +8226,7 @@ var prefer_semantic_colors_default = createRule({
|
|
|
8113
8226
|
if (name !== null && STYLE_COLOR_PROPS.has(name)) checkColorValueNode(node.value);
|
|
8114
8227
|
},
|
|
8115
8228
|
ImportExpression(node) {
|
|
8116
|
-
if (node.source.type ===
|
|
8229
|
+
if (node.source.type === import_utils54.AST_NODE_TYPES.Literal && typeof node.source.value === "string" && EMAIL_OR_PDF_MODULE_RE.test(node.source.value)) {
|
|
8117
8230
|
importsEmailOrPdfRenderer = true;
|
|
8118
8231
|
}
|
|
8119
8232
|
},
|
|
@@ -8126,7 +8239,7 @@ var prefer_semantic_colors_default = createRule({
|
|
|
8126
8239
|
});
|
|
8127
8240
|
|
|
8128
8241
|
// src/rules/prefer-server-actions.ts
|
|
8129
|
-
var
|
|
8242
|
+
var import_utils55 = require("@typescript-eslint/utils");
|
|
8130
8243
|
var MUTATION_METHODS = /* @__PURE__ */ new Set(["POST", "PUT", "DELETE", "PATCH"]);
|
|
8131
8244
|
var AXIOS_MUTATION_METHODS = /* @__PURE__ */ new Set(["post", "put", "delete", "patch"]);
|
|
8132
8245
|
var SKIP_FILE_REGEX = /(?:\.test\.[jt]sx?$|\.spec\.[jt]sx?$|-(?:test|spec)\.[jt]sx?$|\/tests?\/|\/__tests__\/|\/__testfixtures__\/|\/scripts?\/|\/app\/api\/.*\/route\.[jt]sx?$|\/pages\/api\/)/;
|
|
@@ -8317,7 +8430,7 @@ var prefer_single_sentence_comment_default = createRule({
|
|
|
8317
8430
|
});
|
|
8318
8431
|
|
|
8319
8432
|
// src/rules/prefer-string-literal-union.ts
|
|
8320
|
-
var
|
|
8433
|
+
var import_utils56 = require("@typescript-eslint/utils");
|
|
8321
8434
|
var ts2 = __toESM(require("typescript"), 1);
|
|
8322
8435
|
var CHOICE_TOKENS = /* @__PURE__ */ new Set([
|
|
8323
8436
|
"status",
|
|
@@ -8360,19 +8473,19 @@ function isChoiceLikeName(name) {
|
|
|
8360
8473
|
return CHOICE_TOKENS.has(lastWord(name));
|
|
8361
8474
|
}
|
|
8362
8475
|
function keyName(key) {
|
|
8363
|
-
if (key.type ===
|
|
8476
|
+
if (key.type === import_utils56.AST_NODE_TYPES.Identifier) {
|
|
8364
8477
|
return key.name;
|
|
8365
8478
|
}
|
|
8366
|
-
if (key.type ===
|
|
8479
|
+
if (key.type === import_utils56.AST_NODE_TYPES.Literal && typeof key.value === "string") {
|
|
8367
8480
|
return key.value;
|
|
8368
8481
|
}
|
|
8369
8482
|
return null;
|
|
8370
8483
|
}
|
|
8371
8484
|
function isStringLiteralMember(t) {
|
|
8372
|
-
return t.type ===
|
|
8485
|
+
return t.type === import_utils56.AST_NODE_TYPES.TSLiteralType && t.literal.type === import_utils56.AST_NODE_TYPES.Literal && typeof t.literal.value === "string";
|
|
8373
8486
|
}
|
|
8374
8487
|
function isStringLiteralUnion(node) {
|
|
8375
|
-
if (node?.type !==
|
|
8488
|
+
if (node?.type !== import_utils56.AST_NODE_TYPES.TSUnionType) {
|
|
8376
8489
|
return false;
|
|
8377
8490
|
}
|
|
8378
8491
|
return node.types.filter(isStringLiteralMember).length >= MIN_CLUSTER_SIZE;
|
|
@@ -8401,12 +8514,12 @@ function bindingSourceExpression(decl) {
|
|
|
8401
8514
|
return ts2.isForOfStatement(node) ? node.expression : node.initializer;
|
|
8402
8515
|
}
|
|
8403
8516
|
function refKey(node) {
|
|
8404
|
-
if (node.type ===
|
|
8517
|
+
if (node.type === import_utils56.AST_NODE_TYPES.Identifier) {
|
|
8405
8518
|
return node.name;
|
|
8406
8519
|
}
|
|
8407
|
-
if (node.type ===
|
|
8520
|
+
if (node.type === import_utils56.AST_NODE_TYPES.MemberExpression && !node.computed) {
|
|
8408
8521
|
const inner = refKey(node.object);
|
|
8409
|
-
if (inner === null || node.property.type !==
|
|
8522
|
+
if (inner === null || node.property.type !== import_utils56.AST_NODE_TYPES.Identifier) {
|
|
8410
8523
|
return null;
|
|
8411
8524
|
}
|
|
8412
8525
|
return `${inner}.${node.property.name}`;
|
|
@@ -8414,7 +8527,7 @@ function refKey(node) {
|
|
|
8414
8527
|
return null;
|
|
8415
8528
|
}
|
|
8416
8529
|
function strLiteral(node) {
|
|
8417
|
-
if (node.type ===
|
|
8530
|
+
if (node.type === import_utils56.AST_NODE_TYPES.Literal && typeof node.value === "string") {
|
|
8418
8531
|
return node.value;
|
|
8419
8532
|
}
|
|
8420
8533
|
return null;
|
|
@@ -8455,7 +8568,7 @@ var prefer_string_literal_union_default = createRule({
|
|
|
8455
8568
|
);
|
|
8456
8569
|
let services;
|
|
8457
8570
|
try {
|
|
8458
|
-
services =
|
|
8571
|
+
services = import_utils56.ESLintUtils.getParserServices(context);
|
|
8459
8572
|
} catch {
|
|
8460
8573
|
services = null;
|
|
8461
8574
|
}
|
|
@@ -8567,7 +8680,7 @@ var prefer_string_literal_union_default = createRule({
|
|
|
8567
8680
|
containersWithUnion.add(container);
|
|
8568
8681
|
return;
|
|
8569
8682
|
}
|
|
8570
|
-
if (typeNode?.type !==
|
|
8683
|
+
if (typeNode?.type !== import_utils56.AST_NODE_TYPES.TSStringKeyword) {
|
|
8571
8684
|
return;
|
|
8572
8685
|
}
|
|
8573
8686
|
const name = keyName(key);
|
|
@@ -8655,10 +8768,10 @@ var prefer_string_literal_union_default = createRule({
|
|
|
8655
8768
|
}
|
|
8656
8769
|
};
|
|
8657
8770
|
function refKeyText(node) {
|
|
8658
|
-
if (node.type ===
|
|
8771
|
+
if (node.type === import_utils56.AST_NODE_TYPES.BinaryExpression) {
|
|
8659
8772
|
return refKey(node.left) ?? refKey(node.right) ?? "value";
|
|
8660
8773
|
}
|
|
8661
|
-
if (node.type ===
|
|
8774
|
+
if (node.type === import_utils56.AST_NODE_TYPES.SwitchStatement) {
|
|
8662
8775
|
return refKey(node.discriminant) ?? "value";
|
|
8663
8776
|
}
|
|
8664
8777
|
return "value";
|
|
@@ -8667,7 +8780,7 @@ var prefer_string_literal_union_default = createRule({
|
|
|
8667
8780
|
});
|
|
8668
8781
|
|
|
8669
8782
|
// src/rules/prefer-whole-object-assertion.ts
|
|
8670
|
-
var
|
|
8783
|
+
var import_utils57 = require("@typescript-eslint/utils");
|
|
8671
8784
|
var MERGEABLE_MATCHERS = /* @__PURE__ */ new Set(["toBe", "toEqual", "toStrictEqual"]);
|
|
8672
8785
|
var ARRAY_MATCHERS = /* @__PURE__ */ new Set(["toEqual", "toStrictEqual"]);
|
|
8673
8786
|
var COLLECTION_PROPERTIES = /* @__PURE__ */ new Set(["length", "size"]);
|
|
@@ -8676,11 +8789,11 @@ var NUMERIC_SIGNS2 = /* @__PURE__ */ new Set(["-", "+"]);
|
|
|
8676
8789
|
var MIN_RUN_LENGTH = 2;
|
|
8677
8790
|
function literalText(node, getText) {
|
|
8678
8791
|
switch (node.type) {
|
|
8679
|
-
case
|
|
8792
|
+
case import_utils57.AST_NODE_TYPES.Literal:
|
|
8680
8793
|
return "regex" in node ? null : getText(node);
|
|
8681
|
-
case
|
|
8794
|
+
case import_utils57.AST_NODE_TYPES.TemplateLiteral:
|
|
8682
8795
|
return node.expressions.length === 0 ? getText(node) : null;
|
|
8683
|
-
case
|
|
8796
|
+
case import_utils57.AST_NODE_TYPES.UnaryExpression:
|
|
8684
8797
|
return NUMERIC_SIGNS2.has(node.operator) && literalText(node.argument, getText) !== null ? getText(node) : null;
|
|
8685
8798
|
default:
|
|
8686
8799
|
return null;
|
|
@@ -8688,15 +8801,15 @@ function literalText(node, getText) {
|
|
|
8688
8801
|
}
|
|
8689
8802
|
function isPureReceiver(node) {
|
|
8690
8803
|
switch (node.type) {
|
|
8691
|
-
case
|
|
8692
|
-
case
|
|
8804
|
+
case import_utils57.AST_NODE_TYPES.Identifier:
|
|
8805
|
+
case import_utils57.AST_NODE_TYPES.ThisExpression:
|
|
8693
8806
|
return true;
|
|
8694
|
-
case
|
|
8807
|
+
case import_utils57.AST_NODE_TYPES.MemberExpression:
|
|
8695
8808
|
if (node.optional) {
|
|
8696
8809
|
return false;
|
|
8697
8810
|
}
|
|
8698
8811
|
if (node.computed) {
|
|
8699
|
-
return node.property.type ===
|
|
8812
|
+
return node.property.type === import_utils57.AST_NODE_TYPES.Literal && isPureReceiver(node.object);
|
|
8700
8813
|
}
|
|
8701
8814
|
return isPureReceiver(node.object);
|
|
8702
8815
|
default:
|
|
@@ -8704,7 +8817,7 @@ function isPureReceiver(node) {
|
|
|
8704
8817
|
}
|
|
8705
8818
|
}
|
|
8706
8819
|
function literalIndex(node) {
|
|
8707
|
-
if (node.type !==
|
|
8820
|
+
if (node.type !== import_utils57.AST_NODE_TYPES.Literal || typeof node.value !== "number") {
|
|
8708
8821
|
return null;
|
|
8709
8822
|
}
|
|
8710
8823
|
return Number.isInteger(node.value) && node.value >= 0 ? node.value : null;
|
|
@@ -8730,24 +8843,24 @@ var prefer_whole_object_assertion_default = createRule({
|
|
|
8730
8843
|
}
|
|
8731
8844
|
const { sourceCode } = context;
|
|
8732
8845
|
function parseAssertion(statement) {
|
|
8733
|
-
if (statement.type !==
|
|
8846
|
+
if (statement.type !== import_utils57.AST_NODE_TYPES.ExpressionStatement) {
|
|
8734
8847
|
return null;
|
|
8735
8848
|
}
|
|
8736
8849
|
const call = statement.expression;
|
|
8737
|
-
if (call.type !==
|
|
8850
|
+
if (call.type !== import_utils57.AST_NODE_TYPES.CallExpression) {
|
|
8738
8851
|
return null;
|
|
8739
8852
|
}
|
|
8740
8853
|
const callee = call.callee;
|
|
8741
|
-
if (callee.type !==
|
|
8854
|
+
if (callee.type !== import_utils57.AST_NODE_TYPES.MemberExpression || callee.computed || callee.property.type !== import_utils57.AST_NODE_TYPES.Identifier) {
|
|
8742
8855
|
return null;
|
|
8743
8856
|
}
|
|
8744
8857
|
const matcher = callee.property.name;
|
|
8745
8858
|
const expectCall = callee.object;
|
|
8746
|
-
if (expectCall.type !==
|
|
8859
|
+
if (expectCall.type !== import_utils57.AST_NODE_TYPES.CallExpression || expectCall.callee.type !== import_utils57.AST_NODE_TYPES.Identifier || expectCall.callee.name !== "expect" || expectCall.arguments.length !== 1) {
|
|
8747
8860
|
return null;
|
|
8748
8861
|
}
|
|
8749
8862
|
const actual = expectCall.arguments[0];
|
|
8750
|
-
if (actual === void 0 || actual.type !==
|
|
8863
|
+
if (actual === void 0 || actual.type !== import_utils57.AST_NODE_TYPES.MemberExpression || actual.optional) {
|
|
8751
8864
|
return null;
|
|
8752
8865
|
}
|
|
8753
8866
|
if (!isPureReceiver(actual.object)) {
|
|
@@ -8761,7 +8874,7 @@ var prefer_whole_object_assertion_default = createRule({
|
|
|
8761
8874
|
}
|
|
8762
8875
|
key = { kind: "index", index };
|
|
8763
8876
|
} else {
|
|
8764
|
-
if (actual.property.type !==
|
|
8877
|
+
if (actual.property.type !== import_utils57.AST_NODE_TYPES.Identifier || COLLECTION_PROPERTIES.has(actual.property.name) || LITERAL_KEY_HAZARDS.has(actual.property.name)) {
|
|
8765
8878
|
return null;
|
|
8766
8879
|
}
|
|
8767
8880
|
key = { kind: "property", name: actual.property.name };
|
|
@@ -8773,7 +8886,7 @@ var prefer_whole_object_assertion_default = createRule({
|
|
|
8773
8886
|
return null;
|
|
8774
8887
|
}
|
|
8775
8888
|
const expected = call.arguments[0];
|
|
8776
|
-
if (call.arguments.length !== 1 || expected === void 0 || expected.type ===
|
|
8889
|
+
if (call.arguments.length !== 1 || expected === void 0 || expected.type === import_utils57.AST_NODE_TYPES.SpreadElement) {
|
|
8777
8890
|
return null;
|
|
8778
8891
|
}
|
|
8779
8892
|
const literal = literalText(expected, (node) => sourceCode.getText(node));
|
|
@@ -8888,7 +9001,7 @@ var prefer_whole_object_assertion_default = createRule({
|
|
|
8888
9001
|
});
|
|
8889
9002
|
|
|
8890
9003
|
// src/rules/prefer-zod-enum.ts
|
|
8891
|
-
var
|
|
9004
|
+
var import_utils58 = require("@typescript-eslint/utils");
|
|
8892
9005
|
var prefer_zod_enum_default = createRule({
|
|
8893
9006
|
name: "prefer-zod-enum",
|
|
8894
9007
|
meta: {
|
|
@@ -8908,25 +9021,25 @@ var prefer_zod_enum_default = createRule({
|
|
|
8908
9021
|
const zodNamespaces = /* @__PURE__ */ new Set();
|
|
8909
9022
|
function enumValues(node) {
|
|
8910
9023
|
const callee = node.callee;
|
|
8911
|
-
if (callee.type !==
|
|
9024
|
+
if (callee.type !== import_utils58.AST_NODE_TYPES.MemberExpression || callee.computed || callee.object.type !== import_utils58.AST_NODE_TYPES.Identifier || !zodNamespaces.has(callee.object.name) || callee.property.type !== import_utils58.AST_NODE_TYPES.Identifier || callee.property.name !== "union" || node.arguments.length !== 1) {
|
|
8912
9025
|
return null;
|
|
8913
9026
|
}
|
|
8914
9027
|
const argument = node.arguments[0];
|
|
8915
|
-
if (argument === void 0 || argument.type !==
|
|
9028
|
+
if (argument === void 0 || argument.type !== import_utils58.AST_NODE_TYPES.ArrayExpression || argument.elements.length === 0) {
|
|
8916
9029
|
return null;
|
|
8917
9030
|
}
|
|
8918
9031
|
const values = [];
|
|
8919
9032
|
let canFix = true;
|
|
8920
9033
|
for (const element of argument.elements) {
|
|
8921
|
-
if (element?.type ===
|
|
9034
|
+
if (element?.type === import_utils58.AST_NODE_TYPES.SpreadElement) {
|
|
8922
9035
|
canFix = false;
|
|
8923
9036
|
continue;
|
|
8924
9037
|
}
|
|
8925
|
-
if (element === null || element.type !==
|
|
9038
|
+
if (element === null || element.type !== import_utils58.AST_NODE_TYPES.CallExpression || element.callee.type !== import_utils58.AST_NODE_TYPES.MemberExpression || element.callee.computed || element.callee.object.type !== import_utils58.AST_NODE_TYPES.Identifier || !zodNamespaces.has(element.callee.object.name) || element.callee.property.type !== import_utils58.AST_NODE_TYPES.Identifier || element.callee.property.name !== "literal") {
|
|
8926
9039
|
return null;
|
|
8927
9040
|
}
|
|
8928
9041
|
const value = element.arguments[0];
|
|
8929
|
-
if (element.arguments.length !== 1 || value === void 0 || value.type !==
|
|
9042
|
+
if (element.arguments.length !== 1 || value === void 0 || value.type !== import_utils58.AST_NODE_TYPES.Literal || typeof value.value !== "string") {
|
|
8930
9043
|
canFix = false;
|
|
8931
9044
|
continue;
|
|
8932
9045
|
}
|
|
@@ -8936,11 +9049,11 @@ var prefer_zod_enum_default = createRule({
|
|
|
8936
9049
|
}
|
|
8937
9050
|
function buildFix(node, values) {
|
|
8938
9051
|
const argument = node.arguments[0];
|
|
8939
|
-
if (argument === void 0 || argument.type !==
|
|
9052
|
+
if (argument === void 0 || argument.type !== import_utils58.AST_NODE_TYPES.ArrayExpression || sourceCode.getCommentsInside(argument).length > 0) {
|
|
8940
9053
|
return void 0;
|
|
8941
9054
|
}
|
|
8942
9055
|
const callee = node.callee;
|
|
8943
|
-
if (callee.type !==
|
|
9056
|
+
if (callee.type !== import_utils58.AST_NODE_TYPES.MemberExpression || callee.property.type !== import_utils58.AST_NODE_TYPES.Identifier) {
|
|
8944
9057
|
return void 0;
|
|
8945
9058
|
}
|
|
8946
9059
|
return (fixer) => [
|
|
@@ -8957,7 +9070,7 @@ var prefer_zod_enum_default = createRule({
|
|
|
8957
9070
|
return;
|
|
8958
9071
|
}
|
|
8959
9072
|
for (const specifier of node.specifiers) {
|
|
8960
|
-
if (specifier.type ===
|
|
9073
|
+
if (specifier.type === import_utils58.AST_NODE_TYPES.ImportNamespaceSpecifier || specifier.type === import_utils58.AST_NODE_TYPES.ImportDefaultSpecifier || specifier.type === import_utils58.AST_NODE_TYPES.ImportSpecifier && specifier.imported.type === import_utils58.AST_NODE_TYPES.Identifier && specifier.imported.name === "z") {
|
|
8961
9074
|
zodNamespaces.add(specifier.local.name);
|
|
8962
9075
|
}
|
|
8963
9076
|
}
|
|
@@ -8979,7 +9092,7 @@ var prefer_zod_enum_default = createRule({
|
|
|
8979
9092
|
});
|
|
8980
9093
|
|
|
8981
9094
|
// src/rules/prefer-zod-infer.ts
|
|
8982
|
-
var
|
|
9095
|
+
var import_utils59 = require("@typescript-eslint/utils");
|
|
8983
9096
|
var SHAPE_PRESERVING_METHODS = /* @__PURE__ */ new Set([
|
|
8984
9097
|
"describe",
|
|
8985
9098
|
"refine",
|
|
@@ -9016,44 +9129,44 @@ var ZOD_TYPE_CONSTRAINTS = /* @__PURE__ */ new Set([
|
|
|
9016
9129
|
"Schema"
|
|
9017
9130
|
]);
|
|
9018
9131
|
var LEAF_NODE_TYPES = {
|
|
9019
|
-
string: [
|
|
9020
|
-
email: [
|
|
9021
|
-
url: [
|
|
9022
|
-
uuid: [
|
|
9023
|
-
ulid: [
|
|
9024
|
-
cuid: [
|
|
9025
|
-
cuid2: [
|
|
9026
|
-
nanoid: [
|
|
9027
|
-
iso: [
|
|
9028
|
-
number: [
|
|
9029
|
-
int: [
|
|
9030
|
-
float32: [
|
|
9031
|
-
float64: [
|
|
9032
|
-
boolean: [
|
|
9033
|
-
bigint: [
|
|
9034
|
-
symbol: [
|
|
9035
|
-
any: [
|
|
9036
|
-
unknown: [
|
|
9037
|
-
never: [
|
|
9038
|
-
void: [
|
|
9039
|
-
null: [
|
|
9040
|
-
undefined: [
|
|
9041
|
-
literal: [
|
|
9042
|
-
date: [
|
|
9043
|
-
array: [
|
|
9044
|
-
tuple: [
|
|
9045
|
-
object: [
|
|
9046
|
-
strictObject: [
|
|
9047
|
-
looseObject: [
|
|
9048
|
-
record: [
|
|
9049
|
-
map: [
|
|
9050
|
-
set: [
|
|
9051
|
-
promise: [
|
|
9052
|
-
enum: [
|
|
9053
|
-
nativeEnum: [
|
|
9054
|
-
union: [
|
|
9055
|
-
discriminatedUnion: [
|
|
9056
|
-
intersection: [
|
|
9132
|
+
string: [import_utils59.AST_NODE_TYPES.TSStringKeyword],
|
|
9133
|
+
email: [import_utils59.AST_NODE_TYPES.TSStringKeyword],
|
|
9134
|
+
url: [import_utils59.AST_NODE_TYPES.TSStringKeyword],
|
|
9135
|
+
uuid: [import_utils59.AST_NODE_TYPES.TSStringKeyword],
|
|
9136
|
+
ulid: [import_utils59.AST_NODE_TYPES.TSStringKeyword],
|
|
9137
|
+
cuid: [import_utils59.AST_NODE_TYPES.TSStringKeyword],
|
|
9138
|
+
cuid2: [import_utils59.AST_NODE_TYPES.TSStringKeyword],
|
|
9139
|
+
nanoid: [import_utils59.AST_NODE_TYPES.TSStringKeyword],
|
|
9140
|
+
iso: [import_utils59.AST_NODE_TYPES.TSStringKeyword],
|
|
9141
|
+
number: [import_utils59.AST_NODE_TYPES.TSNumberKeyword],
|
|
9142
|
+
int: [import_utils59.AST_NODE_TYPES.TSNumberKeyword],
|
|
9143
|
+
float32: [import_utils59.AST_NODE_TYPES.TSNumberKeyword],
|
|
9144
|
+
float64: [import_utils59.AST_NODE_TYPES.TSNumberKeyword],
|
|
9145
|
+
boolean: [import_utils59.AST_NODE_TYPES.TSBooleanKeyword],
|
|
9146
|
+
bigint: [import_utils59.AST_NODE_TYPES.TSBigIntKeyword],
|
|
9147
|
+
symbol: [import_utils59.AST_NODE_TYPES.TSSymbolKeyword],
|
|
9148
|
+
any: [import_utils59.AST_NODE_TYPES.TSAnyKeyword],
|
|
9149
|
+
unknown: [import_utils59.AST_NODE_TYPES.TSUnknownKeyword],
|
|
9150
|
+
never: [import_utils59.AST_NODE_TYPES.TSNeverKeyword],
|
|
9151
|
+
void: [import_utils59.AST_NODE_TYPES.TSVoidKeyword],
|
|
9152
|
+
null: [import_utils59.AST_NODE_TYPES.TSNullKeyword],
|
|
9153
|
+
undefined: [import_utils59.AST_NODE_TYPES.TSUndefinedKeyword],
|
|
9154
|
+
literal: [import_utils59.AST_NODE_TYPES.TSLiteralType],
|
|
9155
|
+
date: [import_utils59.AST_NODE_TYPES.TSTypeReference],
|
|
9156
|
+
array: [import_utils59.AST_NODE_TYPES.TSArrayType, import_utils59.AST_NODE_TYPES.TSTypeReference],
|
|
9157
|
+
tuple: [import_utils59.AST_NODE_TYPES.TSTupleType],
|
|
9158
|
+
object: [import_utils59.AST_NODE_TYPES.TSTypeLiteral, import_utils59.AST_NODE_TYPES.TSTypeReference],
|
|
9159
|
+
strictObject: [import_utils59.AST_NODE_TYPES.TSTypeLiteral, import_utils59.AST_NODE_TYPES.TSTypeReference],
|
|
9160
|
+
looseObject: [import_utils59.AST_NODE_TYPES.TSTypeLiteral, import_utils59.AST_NODE_TYPES.TSTypeReference],
|
|
9161
|
+
record: [import_utils59.AST_NODE_TYPES.TSTypeReference, import_utils59.AST_NODE_TYPES.TSTypeLiteral],
|
|
9162
|
+
map: [import_utils59.AST_NODE_TYPES.TSTypeReference],
|
|
9163
|
+
set: [import_utils59.AST_NODE_TYPES.TSTypeReference],
|
|
9164
|
+
promise: [import_utils59.AST_NODE_TYPES.TSTypeReference],
|
|
9165
|
+
enum: [import_utils59.AST_NODE_TYPES.TSUnionType, import_utils59.AST_NODE_TYPES.TSTypeReference, import_utils59.AST_NODE_TYPES.TSLiteralType],
|
|
9166
|
+
nativeEnum: [import_utils59.AST_NODE_TYPES.TSUnionType, import_utils59.AST_NODE_TYPES.TSTypeReference, import_utils59.AST_NODE_TYPES.TSLiteralType],
|
|
9167
|
+
union: [import_utils59.AST_NODE_TYPES.TSUnionType, import_utils59.AST_NODE_TYPES.TSTypeReference],
|
|
9168
|
+
discriminatedUnion: [import_utils59.AST_NODE_TYPES.TSUnionType, import_utils59.AST_NODE_TYPES.TSTypeReference],
|
|
9169
|
+
intersection: [import_utils59.AST_NODE_TYPES.TSIntersectionType, import_utils59.AST_NODE_TYPES.TSTypeReference]
|
|
9057
9170
|
};
|
|
9058
9171
|
function normalizeSchemaName(name) {
|
|
9059
9172
|
return name.replace(/Schema$/i, "").replace(/^Z(?=[A-Z])/, "").toLowerCase();
|
|
@@ -9062,20 +9175,20 @@ function normalizeTypeName(name) {
|
|
|
9062
9175
|
return name.replace(/Type$/, "").toLowerCase();
|
|
9063
9176
|
}
|
|
9064
9177
|
function unwrapNullish(annotation) {
|
|
9065
|
-
if (annotation.type !==
|
|
9178
|
+
if (annotation.type !== import_utils59.AST_NODE_TYPES.TSUnionType) {
|
|
9066
9179
|
return {
|
|
9067
9180
|
core: annotation,
|
|
9068
|
-
nullable: annotation.type ===
|
|
9181
|
+
nullable: annotation.type === import_utils59.AST_NODE_TYPES.TSNullKeyword
|
|
9069
9182
|
};
|
|
9070
9183
|
}
|
|
9071
9184
|
const rest = [];
|
|
9072
9185
|
let nullable = false;
|
|
9073
9186
|
for (const member of annotation.types) {
|
|
9074
|
-
if (member.type ===
|
|
9187
|
+
if (member.type === import_utils59.AST_NODE_TYPES.TSNullKeyword) {
|
|
9075
9188
|
nullable = true;
|
|
9076
9189
|
continue;
|
|
9077
9190
|
}
|
|
9078
|
-
if (member.type ===
|
|
9191
|
+
if (member.type === import_utils59.AST_NODE_TYPES.TSUndefinedKeyword) {
|
|
9079
9192
|
continue;
|
|
9080
9193
|
}
|
|
9081
9194
|
rest.push(member);
|
|
@@ -9140,14 +9253,14 @@ var prefer_zod_infer_default = createRule({
|
|
|
9140
9253
|
function zodCallChain(node) {
|
|
9141
9254
|
const chain = [];
|
|
9142
9255
|
let current = node;
|
|
9143
|
-
while (current.type ===
|
|
9256
|
+
while (current.type === import_utils59.AST_NODE_TYPES.CallExpression) {
|
|
9144
9257
|
const callee = current.callee;
|
|
9145
|
-
if (callee.type !==
|
|
9258
|
+
if (callee.type !== import_utils59.AST_NODE_TYPES.MemberExpression || callee.computed || callee.property.type !== import_utils59.AST_NODE_TYPES.Identifier) {
|
|
9146
9259
|
return null;
|
|
9147
9260
|
}
|
|
9148
9261
|
chain.push(current);
|
|
9149
9262
|
const receiver = callee.object;
|
|
9150
|
-
if (receiver.type ===
|
|
9263
|
+
if (receiver.type === import_utils59.AST_NODE_TYPES.Identifier) {
|
|
9151
9264
|
return zodNamespaces.has(receiver.name) ? chain.reverse() : null;
|
|
9152
9265
|
}
|
|
9153
9266
|
current = receiver;
|
|
@@ -9156,19 +9269,19 @@ var prefer_zod_infer_default = createRule({
|
|
|
9156
9269
|
}
|
|
9157
9270
|
function methodName(call) {
|
|
9158
9271
|
const callee = call.callee;
|
|
9159
|
-
return callee.type ===
|
|
9272
|
+
return callee.type === import_utils59.AST_NODE_TYPES.MemberExpression && callee.property.type === import_utils59.AST_NODE_TYPES.Identifier ? callee.property.name : "";
|
|
9160
9273
|
}
|
|
9161
9274
|
function schemaField(node) {
|
|
9162
9275
|
const modifiers = [];
|
|
9163
9276
|
let current = node;
|
|
9164
9277
|
let leaf = null;
|
|
9165
|
-
while (current.type ===
|
|
9278
|
+
while (current.type === import_utils59.AST_NODE_TYPES.CallExpression) {
|
|
9166
9279
|
const callee = current.callee;
|
|
9167
|
-
if (callee.type !==
|
|
9280
|
+
if (callee.type !== import_utils59.AST_NODE_TYPES.MemberExpression || callee.computed || callee.property.type !== import_utils59.AST_NODE_TYPES.Identifier) {
|
|
9168
9281
|
break;
|
|
9169
9282
|
}
|
|
9170
9283
|
const receiver = callee.object;
|
|
9171
|
-
if (receiver.type ===
|
|
9284
|
+
if (receiver.type === import_utils59.AST_NODE_TYPES.Identifier && zodNamespaces.has(receiver.name)) {
|
|
9172
9285
|
leaf = callee.property.name;
|
|
9173
9286
|
break;
|
|
9174
9287
|
}
|
|
@@ -9199,16 +9312,16 @@ var prefer_zod_infer_default = createRule({
|
|
|
9199
9312
|
return null;
|
|
9200
9313
|
}
|
|
9201
9314
|
const shape = base.arguments[0];
|
|
9202
|
-
if (shape === void 0 || shape.type !==
|
|
9315
|
+
if (shape === void 0 || shape.type !== import_utils59.AST_NODE_TYPES.ObjectExpression) {
|
|
9203
9316
|
return null;
|
|
9204
9317
|
}
|
|
9205
9318
|
const fields = /* @__PURE__ */ new Map();
|
|
9206
9319
|
for (const property of shape.properties) {
|
|
9207
|
-
if (property.type !==
|
|
9320
|
+
if (property.type !== import_utils59.AST_NODE_TYPES.Property || property.computed) {
|
|
9208
9321
|
return null;
|
|
9209
9322
|
}
|
|
9210
9323
|
const { key } = property;
|
|
9211
|
-
const name = key.type ===
|
|
9324
|
+
const name = key.type === import_utils59.AST_NODE_TYPES.Identifier ? key.name : key.type === import_utils59.AST_NODE_TYPES.Literal && typeof key.value === "string" ? key.value : null;
|
|
9212
9325
|
if (name === null) {
|
|
9213
9326
|
return null;
|
|
9214
9327
|
}
|
|
@@ -9219,11 +9332,11 @@ var prefer_zod_infer_default = createRule({
|
|
|
9219
9332
|
function typeMembers(members) {
|
|
9220
9333
|
const result = /* @__PURE__ */ new Map();
|
|
9221
9334
|
for (const member of members) {
|
|
9222
|
-
if (member.type !==
|
|
9335
|
+
if (member.type !== import_utils59.AST_NODE_TYPES.TSPropertySignature || member.computed) {
|
|
9223
9336
|
return null;
|
|
9224
9337
|
}
|
|
9225
9338
|
const { key } = member;
|
|
9226
|
-
const name = key.type ===
|
|
9339
|
+
const name = key.type === import_utils59.AST_NODE_TYPES.Identifier ? key.name : key.type === import_utils59.AST_NODE_TYPES.Literal && typeof key.value === "string" ? key.value : null;
|
|
9227
9340
|
if (name === null) {
|
|
9228
9341
|
return null;
|
|
9229
9342
|
}
|
|
@@ -9237,8 +9350,8 @@ var prefer_zod_infer_default = createRule({
|
|
|
9237
9350
|
return result.size === 0 ? null : result;
|
|
9238
9351
|
}
|
|
9239
9352
|
function collectConstrainedNames(node) {
|
|
9240
|
-
if (node.type ===
|
|
9241
|
-
if (node.typeName.type ===
|
|
9353
|
+
if (node.type === import_utils59.AST_NODE_TYPES.TSTypeReference) {
|
|
9354
|
+
if (node.typeName.type === import_utils59.AST_NODE_TYPES.Identifier) {
|
|
9242
9355
|
constrainedTypeNames.add(node.typeName.name);
|
|
9243
9356
|
}
|
|
9244
9357
|
for (const argument of node.typeArguments?.params ?? []) {
|
|
@@ -9246,11 +9359,11 @@ var prefer_zod_infer_default = createRule({
|
|
|
9246
9359
|
}
|
|
9247
9360
|
return;
|
|
9248
9361
|
}
|
|
9249
|
-
if (node.type ===
|
|
9362
|
+
if (node.type === import_utils59.AST_NODE_TYPES.TSArrayType) {
|
|
9250
9363
|
collectConstrainedNames(node.elementType);
|
|
9251
9364
|
return;
|
|
9252
9365
|
}
|
|
9253
|
-
if (node.type ===
|
|
9366
|
+
if (node.type === import_utils59.AST_NODE_TYPES.TSUnionType || node.type === import_utils59.AST_NODE_TYPES.TSIntersectionType) {
|
|
9254
9367
|
for (const member of node.types) {
|
|
9255
9368
|
collectConstrainedNames(member);
|
|
9256
9369
|
}
|
|
@@ -9294,13 +9407,13 @@ var prefer_zod_infer_default = createRule({
|
|
|
9294
9407
|
return;
|
|
9295
9408
|
}
|
|
9296
9409
|
for (const specifier of node.specifiers) {
|
|
9297
|
-
if (specifier.type ===
|
|
9410
|
+
if (specifier.type === import_utils59.AST_NODE_TYPES.ImportNamespaceSpecifier || specifier.type === import_utils59.AST_NODE_TYPES.ImportDefaultSpecifier || specifier.type === import_utils59.AST_NODE_TYPES.ImportSpecifier && specifier.imported.type === import_utils59.AST_NODE_TYPES.Identifier && specifier.imported.name === "z") {
|
|
9298
9411
|
zodNamespaces.add(specifier.local.name);
|
|
9299
9412
|
}
|
|
9300
9413
|
}
|
|
9301
9414
|
},
|
|
9302
9415
|
VariableDeclarator(node) {
|
|
9303
|
-
if (node.id.type !==
|
|
9416
|
+
if (node.id.type !== import_utils59.AST_NODE_TYPES.Identifier || node.init == null) {
|
|
9304
9417
|
return;
|
|
9305
9418
|
}
|
|
9306
9419
|
const fields = schemaFields(node.init);
|
|
@@ -9310,14 +9423,14 @@ var prefer_zod_infer_default = createRule({
|
|
|
9310
9423
|
},
|
|
9311
9424
|
/** Records `XSchema.transform(...)` and equivalent module-level reshaping. */
|
|
9312
9425
|
"MemberExpression[computed=false]"(node) {
|
|
9313
|
-
if (node.object.type ===
|
|
9426
|
+
if (node.object.type === import_utils59.AST_NODE_TYPES.Identifier && node.property.type === import_utils59.AST_NODE_TYPES.Identifier && MODULE_LEVEL_RESHAPERS.has(node.property.name)) {
|
|
9314
9427
|
reshapedSchemaNames.add(node.object.name);
|
|
9315
9428
|
}
|
|
9316
9429
|
},
|
|
9317
9430
|
/** Records every type argument carried by a Zod constraint. */
|
|
9318
9431
|
TSTypeReference(node) {
|
|
9319
9432
|
const { typeName } = node;
|
|
9320
|
-
const referenced = typeName.type ===
|
|
9433
|
+
const referenced = typeName.type === import_utils59.AST_NODE_TYPES.Identifier ? typeName.name : typeName.type === import_utils59.AST_NODE_TYPES.TSQualifiedName && typeName.right.type === import_utils59.AST_NODE_TYPES.Identifier ? typeName.right.name : null;
|
|
9321
9434
|
if (referenced === null || !ZOD_TYPE_CONSTRAINTS.has(referenced)) {
|
|
9322
9435
|
return;
|
|
9323
9436
|
}
|
|
@@ -9335,7 +9448,7 @@ var prefer_zod_infer_default = createRule({
|
|
|
9335
9448
|
}
|
|
9336
9449
|
},
|
|
9337
9450
|
TSTypeAliasDeclaration(node) {
|
|
9338
|
-
if (node.typeParameters !== void 0 || node.typeAnnotation.type !==
|
|
9451
|
+
if (node.typeParameters !== void 0 || node.typeAnnotation.type !== import_utils59.AST_NODE_TYPES.TSTypeLiteral) {
|
|
9339
9452
|
return;
|
|
9340
9453
|
}
|
|
9341
9454
|
const members = typeMembers(node.typeAnnotation.members);
|
|
@@ -9380,10 +9493,10 @@ var prefer_zod_infer_default = createRule({
|
|
|
9380
9493
|
});
|
|
9381
9494
|
|
|
9382
9495
|
// src/rules/require-assert-never.ts
|
|
9383
|
-
var
|
|
9496
|
+
var import_utils60 = require("@typescript-eslint/utils");
|
|
9384
9497
|
var isRuntimeHandlingStatement = (statement) => {
|
|
9385
|
-
if (statement.type ===
|
|
9386
|
-
if (statement.type ===
|
|
9498
|
+
if (statement.type === import_utils60.AST_NODE_TYPES.EmptyStatement) return false;
|
|
9499
|
+
if (statement.type === import_utils60.AST_NODE_TYPES.BlockStatement) {
|
|
9387
9500
|
return statement.body.some(isRuntimeHandlingStatement);
|
|
9388
9501
|
}
|
|
9389
9502
|
return true;
|
|
@@ -9399,7 +9512,7 @@ var isCommentOnlyNoopDefault = (defaultCase, sourceCode) => {
|
|
|
9399
9512
|
return colonToken !== null && sourceCode.getCommentsAfter(colonToken).length > 0;
|
|
9400
9513
|
}
|
|
9401
9514
|
const only = defaultCase.consequent[0];
|
|
9402
|
-
if (only !== void 0 && defaultCase.consequent.length === 1 && only.type ===
|
|
9515
|
+
if (only !== void 0 && defaultCase.consequent.length === 1 && only.type === import_utils60.AST_NODE_TYPES.BlockStatement && only.body.length === 0) {
|
|
9403
9516
|
return sourceCode.getCommentsInside(only).length > 0;
|
|
9404
9517
|
}
|
|
9405
9518
|
return false;
|
|
@@ -9439,7 +9552,7 @@ var require_assert_never_default = createRule({
|
|
|
9439
9552
|
});
|
|
9440
9553
|
|
|
9441
9554
|
// src/rules/require-fetch-timeout.ts
|
|
9442
|
-
var
|
|
9555
|
+
var import_utils61 = require("@typescript-eslint/utils");
|
|
9443
9556
|
var GLOBAL_OBJECTS2 = /* @__PURE__ */ new Set([
|
|
9444
9557
|
"globalThis",
|
|
9445
9558
|
"window",
|
|
@@ -9455,14 +9568,14 @@ function matchesAnyPattern3(filename, patterns) {
|
|
|
9455
9568
|
return false;
|
|
9456
9569
|
}
|
|
9457
9570
|
function initProvablyLacksSignal(init) {
|
|
9458
|
-
if (init.type !==
|
|
9571
|
+
if (init.type !== import_utils61.AST_NODE_TYPES.ObjectExpression) {
|
|
9459
9572
|
return false;
|
|
9460
9573
|
}
|
|
9461
9574
|
for (const prop of init.properties) {
|
|
9462
|
-
if (prop.type ===
|
|
9575
|
+
if (prop.type === import_utils61.AST_NODE_TYPES.SpreadElement) {
|
|
9463
9576
|
return false;
|
|
9464
9577
|
}
|
|
9465
|
-
if (prop.key.type ===
|
|
9578
|
+
if (prop.key.type === import_utils61.AST_NODE_TYPES.Identifier && prop.key.name === "signal" || prop.key.type === import_utils61.AST_NODE_TYPES.Literal && prop.key.value === "signal") {
|
|
9466
9579
|
return false;
|
|
9467
9580
|
}
|
|
9468
9581
|
if (prop.computed) {
|
|
@@ -9472,7 +9585,7 @@ function initProvablyLacksSignal(init) {
|
|
|
9472
9585
|
return true;
|
|
9473
9586
|
}
|
|
9474
9587
|
function isStringish(node) {
|
|
9475
|
-
return node.type ===
|
|
9588
|
+
return node.type === import_utils61.AST_NODE_TYPES.Literal && typeof node.value === "string" || node.type === import_utils61.AST_NODE_TYPES.TemplateLiteral;
|
|
9476
9589
|
}
|
|
9477
9590
|
var require_fetch_timeout_default = createRule({
|
|
9478
9591
|
name: "require-fetch-timeout",
|
|
@@ -9509,14 +9622,14 @@ var require_fetch_timeout_default = createRule({
|
|
|
9509
9622
|
}
|
|
9510
9623
|
function resolvesToGlobal(identifier) {
|
|
9511
9624
|
const scope = context.sourceCode.getScope(identifier);
|
|
9512
|
-
const variable =
|
|
9625
|
+
const variable = import_utils61.ASTUtils.findVariable(scope, identifier.name);
|
|
9513
9626
|
return variable === null || variable.defs.length === 0;
|
|
9514
9627
|
}
|
|
9515
9628
|
function isGlobalFetchCall2(callee) {
|
|
9516
|
-
if (callee.type ===
|
|
9629
|
+
if (callee.type === import_utils61.AST_NODE_TYPES.Identifier) {
|
|
9517
9630
|
return callee.name === "fetch" && resolvesToGlobal(callee);
|
|
9518
9631
|
}
|
|
9519
|
-
return callee.type ===
|
|
9632
|
+
return callee.type === import_utils61.AST_NODE_TYPES.MemberExpression && !callee.computed && callee.property.type === import_utils61.AST_NODE_TYPES.Identifier && callee.property.name === "fetch" && callee.object.type === import_utils61.AST_NODE_TYPES.Identifier && GLOBAL_OBJECTS2.has(callee.object.name) && resolvesToGlobal(callee.object);
|
|
9520
9633
|
}
|
|
9521
9634
|
return {
|
|
9522
9635
|
CallExpression(node) {
|
|
@@ -9536,7 +9649,7 @@ var require_fetch_timeout_default = createRule({
|
|
|
9536
9649
|
});
|
|
9537
9650
|
|
|
9538
9651
|
// src/rules/require-interface-for-injected-service.ts
|
|
9539
|
-
var
|
|
9652
|
+
var import_utils62 = require("@typescript-eslint/utils");
|
|
9540
9653
|
var CONFIGISH_TYPE_RE = /(?:Options|Opts|Config|Configuration|Settings|Params|Props|Args|Env|Environment|Callbacks|Flags)$/;
|
|
9541
9654
|
var CONFIGISH_NAME_RE = /^(?:options|opts|config|configuration|settings|params|props|args|env|environment|callbacks|flags|logger|log|clock)$/i;
|
|
9542
9655
|
var HTTP_TRANSPORT_TYPE_RE = /^(?:KyInstance|AxiosInstance|Session)$/;
|
|
@@ -9544,20 +9657,20 @@ var BUILTIN_CONTAINER_TYPE_RE = /^(?:Record|Map|WeakMap|Set|WeakSet|Array|Readon
|
|
|
9544
9657
|
var TRANSPORT_WRAPPER_NAME_RE = /Client$/;
|
|
9545
9658
|
var ROUTER_FACTORY_NAME = "Router";
|
|
9546
9659
|
var FRAMEWORK_HTTP_TYPES = /* @__PURE__ */ new Set(["Request", "Response", "NextFunction"]);
|
|
9547
|
-
var isExportedClass = (node) => node.parent.type ===
|
|
9548
|
-
var qualifiedName = (name) => name.type ===
|
|
9660
|
+
var isExportedClass = (node) => node.parent.type === import_utils62.AST_NODE_TYPES.ExportNamedDeclaration || node.parent.type === import_utils62.AST_NODE_TYPES.ExportDefaultDeclaration;
|
|
9661
|
+
var qualifiedName = (name) => name.type === import_utils62.AST_NODE_TYPES.Identifier ? name.name : name.type === import_utils62.AST_NODE_TYPES.TSQualifiedName ? `${qualifiedName(name.left)}.${name.right.name}` : "";
|
|
9549
9662
|
var readTypeReference = (annotation) => {
|
|
9550
|
-
if (annotation === void 0 || annotation.type !==
|
|
9663
|
+
if (annotation === void 0 || annotation.type !== import_utils62.AST_NODE_TYPES.TSTypeReference) return null;
|
|
9551
9664
|
const { typeName } = annotation;
|
|
9552
|
-
const rightmost = typeName.type ===
|
|
9665
|
+
const rightmost = typeName.type === import_utils62.AST_NODE_TYPES.Identifier ? typeName.name : typeName.type === import_utils62.AST_NODE_TYPES.TSQualifiedName ? typeName.right.name : null;
|
|
9553
9666
|
if (rightmost === null) return null;
|
|
9554
9667
|
return { typeName: rightmost, display: qualifiedName(typeName) };
|
|
9555
9668
|
};
|
|
9556
9669
|
var namedParameterCollaborator = (annotated) => {
|
|
9557
9670
|
let target = annotated;
|
|
9558
|
-
if (target.type ===
|
|
9559
|
-
if (target.type ===
|
|
9560
|
-
if (target.type !==
|
|
9671
|
+
if (target.type === import_utils62.AST_NODE_TYPES.TSParameterProperty) target = target.parameter;
|
|
9672
|
+
if (target.type === import_utils62.AST_NODE_TYPES.AssignmentPattern) target = target.left;
|
|
9673
|
+
if (target.type !== import_utils62.AST_NODE_TYPES.Identifier) return null;
|
|
9561
9674
|
const reference = readTypeReference(target.typeAnnotation?.typeAnnotation);
|
|
9562
9675
|
if (reference === null) return null;
|
|
9563
9676
|
return { name: target.name, ...reference };
|
|
@@ -9565,8 +9678,8 @@ var namedParameterCollaborator = (annotated) => {
|
|
|
9565
9678
|
var propertySignatureTypes = (members) => {
|
|
9566
9679
|
const types = /* @__PURE__ */ new Map();
|
|
9567
9680
|
for (const member of members) {
|
|
9568
|
-
if (member.type !==
|
|
9569
|
-
if (member.computed || member.key.type !==
|
|
9681
|
+
if (member.type !== import_utils62.AST_NODE_TYPES.TSPropertySignature) continue;
|
|
9682
|
+
if (member.computed || member.key.type !== import_utils62.AST_NODE_TYPES.Identifier) continue;
|
|
9570
9683
|
const reference = readTypeReference(member.typeAnnotation?.typeAnnotation);
|
|
9571
9684
|
if (reference === null) continue;
|
|
9572
9685
|
types.set(member.key.name, reference);
|
|
@@ -9577,18 +9690,18 @@ var fileTypeIndex = (program) => {
|
|
|
9577
9690
|
const objects = /* @__PURE__ */ new Map();
|
|
9578
9691
|
const functionAliases = /* @__PURE__ */ new Set();
|
|
9579
9692
|
for (const statement of program.body) {
|
|
9580
|
-
const declaration = statement.type ===
|
|
9581
|
-
if (declaration?.type ===
|
|
9693
|
+
const declaration = statement.type === import_utils62.AST_NODE_TYPES.ExportNamedDeclaration ? statement.declaration : statement;
|
|
9694
|
+
if (declaration?.type === import_utils62.AST_NODE_TYPES.TSInterfaceDeclaration) {
|
|
9582
9695
|
objects.set(declaration.id.name, propertySignatureTypes(declaration.body.body));
|
|
9583
9696
|
continue;
|
|
9584
9697
|
}
|
|
9585
|
-
if (declaration?.type !==
|
|
9698
|
+
if (declaration?.type !== import_utils62.AST_NODE_TYPES.TSTypeAliasDeclaration) continue;
|
|
9586
9699
|
const aliased = declaration.typeAnnotation;
|
|
9587
|
-
if (aliased.type ===
|
|
9700
|
+
if (aliased.type === import_utils62.AST_NODE_TYPES.TSFunctionType || aliased.type === import_utils62.AST_NODE_TYPES.TSConstructorType) {
|
|
9588
9701
|
functionAliases.add(declaration.id.name);
|
|
9589
9702
|
continue;
|
|
9590
9703
|
}
|
|
9591
|
-
const literals = aliased.type ===
|
|
9704
|
+
const literals = aliased.type === import_utils62.AST_NODE_TYPES.TSTypeLiteral ? [aliased] : aliased.type === import_utils62.AST_NODE_TYPES.TSIntersectionType ? aliased.types.filter((part) => part.type === import_utils62.AST_NODE_TYPES.TSTypeLiteral) : [];
|
|
9592
9705
|
if (literals.length === 0) continue;
|
|
9593
9706
|
const merged = /* @__PURE__ */ new Map();
|
|
9594
9707
|
for (const literal of literals) {
|
|
@@ -9601,10 +9714,10 @@ var fileTypeIndex = (program) => {
|
|
|
9601
9714
|
return { objects, functionAliases };
|
|
9602
9715
|
};
|
|
9603
9716
|
var bagMemberTypes = (annotation, declared) => {
|
|
9604
|
-
if (annotation.type ===
|
|
9717
|
+
if (annotation.type === import_utils62.AST_NODE_TYPES.TSTypeLiteral) {
|
|
9605
9718
|
return propertySignatureTypes(annotation.members);
|
|
9606
9719
|
}
|
|
9607
|
-
if (annotation.type !==
|
|
9720
|
+
if (annotation.type !== import_utils62.AST_NODE_TYPES.TSTypeReference || annotation.typeName.type !== import_utils62.AST_NODE_TYPES.Identifier) {
|
|
9608
9721
|
return null;
|
|
9609
9722
|
}
|
|
9610
9723
|
return declared().objects.get(annotation.typeName.name) ?? null;
|
|
@@ -9616,11 +9729,11 @@ var objectPatternCollaborators = (pattern, declared) => {
|
|
|
9616
9729
|
if (members === null) return [];
|
|
9617
9730
|
const collaborators = [];
|
|
9618
9731
|
for (const property of pattern.properties) {
|
|
9619
|
-
if (property.type !==
|
|
9620
|
-
if (property.key.type !==
|
|
9732
|
+
if (property.type !== import_utils62.AST_NODE_TYPES.Property || property.computed) continue;
|
|
9733
|
+
if (property.key.type !== import_utils62.AST_NODE_TYPES.Identifier) continue;
|
|
9621
9734
|
const key = property.key.name;
|
|
9622
|
-
const bound = property.value.type ===
|
|
9623
|
-
if (bound.type !==
|
|
9735
|
+
const bound = property.value.type === import_utils62.AST_NODE_TYPES.AssignmentPattern ? property.value.left : property.value;
|
|
9736
|
+
if (bound.type !== import_utils62.AST_NODE_TYPES.Identifier) continue;
|
|
9624
9737
|
if (CONFIGISH_NAME_RE.test(key)) continue;
|
|
9625
9738
|
const reference = members.get(key);
|
|
9626
9739
|
if (reference === void 0) continue;
|
|
@@ -9630,8 +9743,8 @@ var objectPatternCollaborators = (pattern, declared) => {
|
|
|
9630
9743
|
};
|
|
9631
9744
|
var parameterCollaborators = (parameter, declared) => {
|
|
9632
9745
|
let target = parameter;
|
|
9633
|
-
if (target.type ===
|
|
9634
|
-
if (target.type ===
|
|
9746
|
+
if (target.type === import_utils62.AST_NODE_TYPES.AssignmentPattern) target = target.left;
|
|
9747
|
+
if (target.type === import_utils62.AST_NODE_TYPES.ObjectPattern) {
|
|
9635
9748
|
return objectPatternCollaborators(target, declared);
|
|
9636
9749
|
}
|
|
9637
9750
|
const named2 = namedParameterCollaborator(parameter);
|
|
@@ -9650,17 +9763,17 @@ var readConstructor = (ctor, declared, typeParameters) => {
|
|
|
9650
9763
|
let constructedFields = 0;
|
|
9651
9764
|
if (body2 !== null && body2 !== void 0) {
|
|
9652
9765
|
for (const statement of body2.body) {
|
|
9653
|
-
if (statement.type !==
|
|
9766
|
+
if (statement.type !== import_utils62.AST_NODE_TYPES.ExpressionStatement) continue;
|
|
9654
9767
|
const expression = statement.expression;
|
|
9655
|
-
if (expression.type !==
|
|
9768
|
+
if (expression.type !== import_utils62.AST_NODE_TYPES.AssignmentExpression || expression.operator !== "=" || expression.left.type !== import_utils62.AST_NODE_TYPES.MemberExpression || expression.left.object.type !== import_utils62.AST_NODE_TYPES.ThisExpression) {
|
|
9656
9769
|
continue;
|
|
9657
9770
|
}
|
|
9658
9771
|
const source = expression.right;
|
|
9659
|
-
if (source.type ===
|
|
9772
|
+
if (source.type === import_utils62.AST_NODE_TYPES.NewExpression) {
|
|
9660
9773
|
constructedFields += 1;
|
|
9661
|
-
} else if (source.type ===
|
|
9774
|
+
} else if (source.type === import_utils62.AST_NODE_TYPES.Identifier) {
|
|
9662
9775
|
storedFrom.add(source.name);
|
|
9663
|
-
} else if (source.type ===
|
|
9776
|
+
} else if (source.type === import_utils62.AST_NODE_TYPES.MemberExpression && source.object.type === import_utils62.AST_NODE_TYPES.Identifier) {
|
|
9664
9777
|
storedFrom.add(source.object.name);
|
|
9665
9778
|
}
|
|
9666
9779
|
}
|
|
@@ -9668,7 +9781,7 @@ var readConstructor = (ctor, declared, typeParameters) => {
|
|
|
9668
9781
|
const collaborators = [];
|
|
9669
9782
|
for (const parameter of ctor.value.params) {
|
|
9670
9783
|
for (const reference of parameterCollaborators(parameter, declared)) {
|
|
9671
|
-
const stored = parameter.type ===
|
|
9784
|
+
const stored = parameter.type === import_utils62.AST_NODE_TYPES.TSParameterProperty || storedFrom.has(reference.name);
|
|
9672
9785
|
if (!stored) continue;
|
|
9673
9786
|
if (CONFIGISH_TYPE_RE.test(reference.typeName)) continue;
|
|
9674
9787
|
if (CONFIGISH_NAME_RE.test(reference.name)) continue;
|
|
@@ -9702,19 +9815,19 @@ var subtreeHas = (root, found) => {
|
|
|
9702
9815
|
return hit;
|
|
9703
9816
|
};
|
|
9704
9817
|
var isFrameworkWiring = (body2) => subtreeHas(body2, (node) => {
|
|
9705
|
-
if (node.type ===
|
|
9818
|
+
if (node.type === import_utils62.AST_NODE_TYPES.CallExpression) {
|
|
9706
9819
|
const { callee } = node;
|
|
9707
|
-
if (callee.type ===
|
|
9708
|
-
return callee.type ===
|
|
9820
|
+
if (callee.type === import_utils62.AST_NODE_TYPES.Identifier) return callee.name === ROUTER_FACTORY_NAME;
|
|
9821
|
+
return callee.type === import_utils62.AST_NODE_TYPES.MemberExpression && !callee.computed && callee.property.type === import_utils62.AST_NODE_TYPES.Identifier && callee.property.name === ROUTER_FACTORY_NAME;
|
|
9709
9822
|
}
|
|
9710
|
-
return node.type ===
|
|
9823
|
+
return node.type === import_utils62.AST_NODE_TYPES.TSTypeReference && node.typeName.type === import_utils62.AST_NODE_TYPES.TSQualifiedName && FRAMEWORK_HTTP_TYPES.has(node.typeName.right.name);
|
|
9711
9824
|
});
|
|
9712
9825
|
var stem2 = (name) => name.replace(/^I(?=[A-Z])/, "").replace(/Impl$/, "");
|
|
9713
9826
|
var fileInterfaceNames = (program) => {
|
|
9714
9827
|
const names = [];
|
|
9715
9828
|
for (const statement of program.body) {
|
|
9716
|
-
const declaration = statement.type ===
|
|
9717
|
-
if (declaration?.type ===
|
|
9829
|
+
const declaration = statement.type === import_utils62.AST_NODE_TYPES.ExportNamedDeclaration ? statement.declaration : statement;
|
|
9830
|
+
if (declaration?.type === import_utils62.AST_NODE_TYPES.TSInterfaceDeclaration) names.push(declaration.id.name);
|
|
9718
9831
|
}
|
|
9719
9832
|
return names;
|
|
9720
9833
|
};
|
|
@@ -9732,11 +9845,11 @@ var isTransportWrapper = (className, collaborators, program) => {
|
|
|
9732
9845
|
var publicMethodNames = (body2) => {
|
|
9733
9846
|
const names = [];
|
|
9734
9847
|
for (const member of body2.body) {
|
|
9735
|
-
if (member.type !==
|
|
9848
|
+
if (member.type !== import_utils62.AST_NODE_TYPES.MethodDefinition) continue;
|
|
9736
9849
|
if (member.kind !== "method" || member.static) continue;
|
|
9737
9850
|
if (member.accessibility === "private" || member.accessibility === "protected") continue;
|
|
9738
|
-
if (member.key.type ===
|
|
9739
|
-
if (member.key.type ===
|
|
9851
|
+
if (member.key.type === import_utils62.AST_NODE_TYPES.PrivateIdentifier) continue;
|
|
9852
|
+
if (member.key.type === import_utils62.AST_NODE_TYPES.Identifier) names.push(member.key.name);
|
|
9740
9853
|
else names.push("\u2026");
|
|
9741
9854
|
}
|
|
9742
9855
|
return names;
|
|
@@ -9769,7 +9882,7 @@ var require_interface_for_injected_service_default = createRule({
|
|
|
9769
9882
|
if (node.implements.length > 0) return;
|
|
9770
9883
|
if (node.decorators.length > 0) return;
|
|
9771
9884
|
const ctor = node.body.body.find(
|
|
9772
|
-
(member) => member.type ===
|
|
9885
|
+
(member) => member.type === import_utils62.AST_NODE_TYPES.MethodDefinition && member.kind === "constructor"
|
|
9773
9886
|
);
|
|
9774
9887
|
if (ctor === void 0) return;
|
|
9775
9888
|
const { collaborators, constructedFields } = readConstructor(
|
|
@@ -9798,37 +9911,37 @@ var require_interface_for_injected_service_default = createRule({
|
|
|
9798
9911
|
});
|
|
9799
9912
|
|
|
9800
9913
|
// src/rules/require-static-next-matcher.ts
|
|
9801
|
-
var
|
|
9914
|
+
var import_utils63 = require("@typescript-eslint/utils");
|
|
9802
9915
|
var NEXT_ENTRY_FILE = /(?:^|[/\\])(?:middleware|proxy)\.[cm]?[jt]sx?$/u;
|
|
9803
9916
|
function unwrapExpression(node) {
|
|
9804
|
-
if (node.type ===
|
|
9917
|
+
if (node.type === import_utils63.AST_NODE_TYPES.TSAsExpression || node.type === import_utils63.AST_NODE_TYPES.TSSatisfiesExpression || node.type === import_utils63.AST_NODE_TYPES.TSNonNullExpression || node.type === import_utils63.AST_NODE_TYPES.TSTypeAssertion) {
|
|
9805
9918
|
return unwrapExpression(node.expression);
|
|
9806
9919
|
}
|
|
9807
9920
|
return node;
|
|
9808
9921
|
}
|
|
9809
9922
|
function isStaticValue(node) {
|
|
9810
9923
|
const value = unwrapExpression(node);
|
|
9811
|
-
if (value.type ===
|
|
9924
|
+
if (value.type === import_utils63.AST_NODE_TYPES.Literal) {
|
|
9812
9925
|
return true;
|
|
9813
9926
|
}
|
|
9814
|
-
if (value.type ===
|
|
9927
|
+
if (value.type === import_utils63.AST_NODE_TYPES.TemplateLiteral) {
|
|
9815
9928
|
return value.expressions.length === 0;
|
|
9816
9929
|
}
|
|
9817
|
-
if (value.type ===
|
|
9930
|
+
if (value.type === import_utils63.AST_NODE_TYPES.ArrayExpression) {
|
|
9818
9931
|
return value.elements.every(
|
|
9819
|
-
(element) => element !== null && element.type !==
|
|
9932
|
+
(element) => element !== null && element.type !== import_utils63.AST_NODE_TYPES.SpreadElement && isStaticValue(element)
|
|
9820
9933
|
);
|
|
9821
9934
|
}
|
|
9822
|
-
if (value.type ===
|
|
9935
|
+
if (value.type === import_utils63.AST_NODE_TYPES.ObjectExpression) {
|
|
9823
9936
|
return value.properties.every(
|
|
9824
|
-
(property) => property.type ===
|
|
9937
|
+
(property) => property.type === import_utils63.AST_NODE_TYPES.Property && property.kind === "init" && !property.computed && property.value.type !== import_utils63.AST_NODE_TYPES.AssignmentPattern && isStaticValue(property.value)
|
|
9825
9938
|
);
|
|
9826
9939
|
}
|
|
9827
9940
|
return false;
|
|
9828
9941
|
}
|
|
9829
9942
|
function propertyName2(property) {
|
|
9830
9943
|
if (property.computed) return null;
|
|
9831
|
-
if (property.key.type ===
|
|
9944
|
+
if (property.key.type === import_utils63.AST_NODE_TYPES.Identifier) return property.key.name;
|
|
9832
9945
|
return typeof property.key.value === "string" ? property.key.value : null;
|
|
9833
9946
|
}
|
|
9834
9947
|
var require_static_next_matcher_default = createRule({
|
|
@@ -9850,19 +9963,19 @@ var require_static_next_matcher_default = createRule({
|
|
|
9850
9963
|
}
|
|
9851
9964
|
return {
|
|
9852
9965
|
ExportNamedDeclaration(node) {
|
|
9853
|
-
if (node.declaration?.type !==
|
|
9966
|
+
if (node.declaration?.type !== import_utils63.AST_NODE_TYPES.VariableDeclaration) {
|
|
9854
9967
|
return;
|
|
9855
9968
|
}
|
|
9856
9969
|
for (const declaration of node.declaration.declarations) {
|
|
9857
|
-
if (declaration.id.type !==
|
|
9970
|
+
if (declaration.id.type !== import_utils63.AST_NODE_TYPES.Identifier || declaration.id.name !== "config" || declaration.init === null) {
|
|
9858
9971
|
continue;
|
|
9859
9972
|
}
|
|
9860
9973
|
const config = unwrapExpression(declaration.init);
|
|
9861
|
-
if (config.type !==
|
|
9974
|
+
if (config.type !== import_utils63.AST_NODE_TYPES.ObjectExpression) {
|
|
9862
9975
|
continue;
|
|
9863
9976
|
}
|
|
9864
9977
|
for (const property of config.properties) {
|
|
9865
|
-
if (property.type !==
|
|
9978
|
+
if (property.type !== import_utils63.AST_NODE_TYPES.Property || propertyName2(property) !== "matcher" || property.value.type === import_utils63.AST_NODE_TYPES.AssignmentPattern) {
|
|
9866
9979
|
continue;
|
|
9867
9980
|
}
|
|
9868
9981
|
if (!isStaticValue(property.value)) {
|
|
@@ -9876,18 +9989,18 @@ var require_static_next_matcher_default = createRule({
|
|
|
9876
9989
|
});
|
|
9877
9990
|
|
|
9878
9991
|
// src/rules/require-zod-form-validation.ts
|
|
9879
|
-
var
|
|
9992
|
+
var import_utils64 = require("@typescript-eslint/utils");
|
|
9880
9993
|
var looksLikeZodSchema = (node) => {
|
|
9881
9994
|
let current = node;
|
|
9882
9995
|
while (true) {
|
|
9883
|
-
if (current.type ===
|
|
9996
|
+
if (current.type === import_utils64.AST_NODE_TYPES.Identifier) {
|
|
9884
9997
|
return current.name === "z" || ZOD_SCHEMA_NAME_RE.test(current.name);
|
|
9885
9998
|
}
|
|
9886
|
-
if (current.type ===
|
|
9999
|
+
if (current.type === import_utils64.AST_NODE_TYPES.CallExpression) {
|
|
9887
10000
|
current = current.callee;
|
|
9888
10001
|
continue;
|
|
9889
10002
|
}
|
|
9890
|
-
if (current.type ===
|
|
10003
|
+
if (current.type === import_utils64.AST_NODE_TYPES.MemberExpression) {
|
|
9891
10004
|
current = current.object;
|
|
9892
10005
|
continue;
|
|
9893
10006
|
}
|
|
@@ -9895,23 +10008,23 @@ var looksLikeZodSchema = (node) => {
|
|
|
9895
10008
|
}
|
|
9896
10009
|
};
|
|
9897
10010
|
var isZodParseCall = (node) => {
|
|
9898
|
-
if (node.type !==
|
|
10011
|
+
if (node.type !== import_utils64.AST_NODE_TYPES.CallExpression) return false;
|
|
9899
10012
|
const callee = node.callee;
|
|
9900
|
-
if (callee.type !==
|
|
10013
|
+
if (callee.type !== import_utils64.AST_NODE_TYPES.MemberExpression) return false;
|
|
9901
10014
|
if (callee.computed) return false;
|
|
9902
|
-
if (callee.property.type !==
|
|
10015
|
+
if (callee.property.type !== import_utils64.AST_NODE_TYPES.Identifier) return false;
|
|
9903
10016
|
const method = callee.property.name;
|
|
9904
10017
|
if (method !== "parse" && method !== "safeParse") return false;
|
|
9905
10018
|
return looksLikeZodSchema(callee.object);
|
|
9906
10019
|
};
|
|
9907
10020
|
var isFormDataMethodCall = (node) => {
|
|
9908
10021
|
let current = node;
|
|
9909
|
-
if (current.type ===
|
|
10022
|
+
if (current.type === import_utils64.AST_NODE_TYPES.AwaitExpression) {
|
|
9910
10023
|
current = current.argument;
|
|
9911
10024
|
}
|
|
9912
|
-
if (current.type !==
|
|
10025
|
+
if (current.type !== import_utils64.AST_NODE_TYPES.CallExpression) return false;
|
|
9913
10026
|
const callee = current.callee;
|
|
9914
|
-
return callee.type ===
|
|
10027
|
+
return callee.type === import_utils64.AST_NODE_TYPES.MemberExpression && !callee.computed && callee.property.type === import_utils64.AST_NODE_TYPES.Identifier && callee.property.name === "formData";
|
|
9915
10028
|
};
|
|
9916
10029
|
var require_zod_form_validation_default = createRule({
|
|
9917
10030
|
name: "require-zod-form-validation",
|
|
@@ -9931,14 +10044,14 @@ var require_zod_form_validation_default = createRule({
|
|
|
9931
10044
|
return {};
|
|
9932
10045
|
}
|
|
9933
10046
|
const isFormSourceIdentifier = (node) => {
|
|
9934
|
-
if (node.type !==
|
|
10047
|
+
if (node.type !== import_utils64.AST_NODE_TYPES.Identifier) return false;
|
|
9935
10048
|
if (/formdata/i.test(node.name)) return true;
|
|
9936
10049
|
let scope = context.sourceCode.getScope(node);
|
|
9937
10050
|
while (scope !== null) {
|
|
9938
10051
|
const variable = scope.set.get(node.name);
|
|
9939
10052
|
if (variable !== void 0 && variable.defs.length === 1) {
|
|
9940
10053
|
const def = variable.defs[0];
|
|
9941
|
-
if (def !== void 0 && def.type === "Variable" && def.node.type ===
|
|
10054
|
+
if (def !== void 0 && def.type === "Variable" && def.node.type === import_utils64.AST_NODE_TYPES.VariableDeclarator && def.node.init !== null) {
|
|
9942
10055
|
return isFormDataMethodCall(def.node.init);
|
|
9943
10056
|
}
|
|
9944
10057
|
return false;
|
|
@@ -9949,8 +10062,8 @@ var require_zod_form_validation_default = createRule({
|
|
|
9949
10062
|
};
|
|
9950
10063
|
const isFormDataGetCall = (node) => {
|
|
9951
10064
|
const callee = node.callee;
|
|
9952
|
-
if (callee.type !==
|
|
9953
|
-
if (callee.property.type !==
|
|
10065
|
+
if (callee.type !== import_utils64.AST_NODE_TYPES.MemberExpression) return false;
|
|
10066
|
+
if (callee.property.type !== import_utils64.AST_NODE_TYPES.Identifier || callee.property.name !== "get") {
|
|
9954
10067
|
return false;
|
|
9955
10068
|
}
|
|
9956
10069
|
return isFormSourceIdentifier(callee.object);
|
|
@@ -9965,11 +10078,11 @@ var require_zod_form_validation_default = createRule({
|
|
|
9965
10078
|
};
|
|
9966
10079
|
const isInstanceofNarrowing = (node) => {
|
|
9967
10080
|
const parent = node.parent;
|
|
9968
|
-
return parent !== null && parent !== void 0 && parent.type ===
|
|
10081
|
+
return parent !== null && parent !== void 0 && parent.type === import_utils64.AST_NODE_TYPES.BinaryExpression && parent.operator === "instanceof" && parent.left === node && parent.right.type === import_utils64.AST_NODE_TYPES.Identifier && (parent.right.name === "File" || parent.right.name === "Blob");
|
|
9969
10082
|
};
|
|
9970
10083
|
const boundDeclarator = (node) => {
|
|
9971
10084
|
const parent = node.parent;
|
|
9972
|
-
if (parent.type ===
|
|
10085
|
+
if (parent.type === import_utils64.AST_NODE_TYPES.VariableDeclarator && parent.init === node && parent.id.type === import_utils64.AST_NODE_TYPES.Identifier) {
|
|
9973
10086
|
return parent;
|
|
9974
10087
|
}
|
|
9975
10088
|
return null;
|
|
@@ -9997,7 +10110,7 @@ var require_zod_form_validation_default = createRule({
|
|
|
9997
10110
|
});
|
|
9998
10111
|
|
|
9999
10112
|
// src/rules/store-insert-requires-on-conflict.ts
|
|
10000
|
-
var
|
|
10113
|
+
var import_utils65 = require("@typescript-eslint/utils");
|
|
10001
10114
|
var INSERT_WRITE = /\bINSERT\s+(?:OR\s+\w+\s+)?INTO\s+[\w."'`?$:@-]+\s*(?:\([^)]*\)\s*)?(?:VALUES|SELECT|DEFAULT\s+VALUES)\b/i;
|
|
10002
10115
|
var CONFLICT_HANDLED = /\bON\s+CONFLICT\b|\bON\s+DUPLICATE\s+KEY\b|\bINSERT\s+OR\s+(?:IGNORE|REPLACE)\b/i;
|
|
10003
10116
|
var INSERT_GATE = /insert/i;
|
|
@@ -10028,7 +10141,7 @@ var store_insert_requires_on_conflict_default = createRule({
|
|
|
10028
10141
|
});
|
|
10029
10142
|
|
|
10030
10143
|
// src/rules/zod-naming-convention.ts
|
|
10031
|
-
var
|
|
10144
|
+
var import_utils66 = require("@typescript-eslint/utils");
|
|
10032
10145
|
var CONVENTIONS = {
|
|
10033
10146
|
prefix: { test: ZOD_PREFIX_RE, messageId: "zPrefix" },
|
|
10034
10147
|
suffix: { test: ZOD_SUFFIX_RE, messageId: "schemaSuffix" },
|
|
@@ -10053,15 +10166,15 @@ var NON_SCHEMA_TERMINALS = /* @__PURE__ */ new Set([
|
|
|
10053
10166
|
"registry",
|
|
10054
10167
|
"implement"
|
|
10055
10168
|
]);
|
|
10056
|
-
var terminalMethodName = (callee) => !callee.computed && callee.property.type ===
|
|
10169
|
+
var terminalMethodName = (callee) => !callee.computed && callee.property.type === import_utils66.AST_NODE_TYPES.Identifier ? callee.property.name : null;
|
|
10057
10170
|
var calleeChainStartsWithZ = (node) => {
|
|
10058
10171
|
let current = node;
|
|
10059
|
-
while (current.type ===
|
|
10172
|
+
while (current.type === import_utils66.AST_NODE_TYPES.MemberExpression) {
|
|
10060
10173
|
const receiver = current.object;
|
|
10061
|
-
if (receiver.type ===
|
|
10174
|
+
if (receiver.type === import_utils66.AST_NODE_TYPES.Identifier && receiver.name === "z") {
|
|
10062
10175
|
return true;
|
|
10063
10176
|
}
|
|
10064
|
-
if (receiver.type ===
|
|
10177
|
+
if (receiver.type === import_utils66.AST_NODE_TYPES.CallExpression) {
|
|
10065
10178
|
current = receiver.callee;
|
|
10066
10179
|
continue;
|
|
10067
10180
|
}
|
|
@@ -10106,13 +10219,13 @@ var zod_naming_convention_default = createRule({
|
|
|
10106
10219
|
VariableDeclarator(node) {
|
|
10107
10220
|
const init = node.init;
|
|
10108
10221
|
if (init === null || init === void 0) return;
|
|
10109
|
-
if (init.type !==
|
|
10222
|
+
if (init.type !== import_utils66.AST_NODE_TYPES.CallExpression) return;
|
|
10110
10223
|
const callee = init.callee;
|
|
10111
|
-
if (callee.type !==
|
|
10224
|
+
if (callee.type !== import_utils66.AST_NODE_TYPES.MemberExpression) return;
|
|
10112
10225
|
if (!calleeChainStartsWithZ(callee)) return;
|
|
10113
10226
|
const terminal = terminalMethodName(callee);
|
|
10114
10227
|
if (terminal !== null && NON_SCHEMA_TERMINALS.has(terminal)) return;
|
|
10115
|
-
if (node.id.type !==
|
|
10228
|
+
if (node.id.type !== import_utils66.AST_NODE_TYPES.Identifier) return;
|
|
10116
10229
|
if (test.test(node.id.name)) return;
|
|
10117
10230
|
if (acceptsSchemaWord && CONTAINS_SCHEMA_RE.test(node.id.name)) return;
|
|
10118
10231
|
context.report({
|
|
@@ -10223,10 +10336,11 @@ var rules = {
|
|
|
10223
10336
|
"no-zod-native-enum": no_zod_native_enum_default,
|
|
10224
10337
|
"prefer-constant-time-secret-compare": prefer_constant_time_secret_compare_default,
|
|
10225
10338
|
"prefer-discriminated-union": prefer_discriminated_union_default,
|
|
10339
|
+
"prefer-input-group-search": prefer_input_group_search_default,
|
|
10226
10340
|
"prefer-module-level-constant": prefer_module_level_constant_default,
|
|
10227
10341
|
"prefer-module-level-schema": prefer_module_level_schema_default,
|
|
10228
|
-
"prefer-non-nullable-collection": prefer_non_nullable_collection_default,
|
|
10229
10342
|
"prefer-native-random-uuid": prefer_native_random_uuid_default,
|
|
10343
|
+
"prefer-non-nullable-collection": prefer_non_nullable_collection_default,
|
|
10230
10344
|
"prefer-schema-for-api-payload": prefer_schema_for_api_payload_default,
|
|
10231
10345
|
"prefer-semantic-colors": prefer_semantic_colors_default,
|
|
10232
10346
|
"prefer-server-actions": prefer_server_actions_default,
|
|
@@ -10245,7 +10359,7 @@ var rules = {
|
|
|
10245
10359
|
};
|
|
10246
10360
|
var meta = {
|
|
10247
10361
|
name: "@sarj/eslint-plugin",
|
|
10248
|
-
version: "9.
|
|
10362
|
+
version: "9.10.0"
|
|
10249
10363
|
};
|
|
10250
10364
|
var applicationOnlyRules = [
|
|
10251
10365
|
"no-restricted-library-load",
|
|
@@ -10288,6 +10402,7 @@ var recommendedRules = {
|
|
|
10288
10402
|
"@sarj/no-zod-native-enum": "warn",
|
|
10289
10403
|
"@sarj/prefer-constant-time-secret-compare": "error",
|
|
10290
10404
|
"@sarj/prefer-discriminated-union": "warn",
|
|
10405
|
+
"@sarj/prefer-input-group-search": "error",
|
|
10291
10406
|
"@sarj/prefer-module-level-constant": "warn",
|
|
10292
10407
|
"@sarj/prefer-module-level-schema": "warn",
|
|
10293
10408
|
"@sarj/prefer-non-nullable-collection": "warn",
|
|
@@ -10348,6 +10463,7 @@ var strictRules = {
|
|
|
10348
10463
|
"@sarj/no-zod-native-enum": "error",
|
|
10349
10464
|
"@sarj/prefer-constant-time-secret-compare": "error",
|
|
10350
10465
|
"@sarj/prefer-discriminated-union": "error",
|
|
10466
|
+
"@sarj/prefer-input-group-search": "error",
|
|
10351
10467
|
"@sarj/prefer-module-level-constant": "error",
|
|
10352
10468
|
"@sarj/prefer-module-level-schema": "error",
|
|
10353
10469
|
"@sarj/prefer-non-nullable-collection": "error",
|