@sarj/eslint-plugin 7.0.0 → 8.0.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 +884 -456
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +32 -9
- package/dist/index.d.ts +32 -9
- package/dist/index.js +877 -450
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -12,25 +12,41 @@ var createRule = ESLintUtils.RuleCreator(evidenceUrl);
|
|
|
12
12
|
// src/rules/_paths.ts
|
|
13
13
|
var SCRIPT_FILE_RE = /([\\/]scripts[\\/])|(\.mjs$)/;
|
|
14
14
|
var STORY_FILE_RE = /\.stories\.[cm]?[jt]sx?$/i;
|
|
15
|
-
var
|
|
16
|
-
var GENERATED_FILE_RE = /([\\/](?:generated|openapi-gen|graphql[\\/]types|vendor|vendored|
|
|
17
|
-
var
|
|
18
|
-
|
|
15
|
+
var STORY_TREE_RE = /(^|\/)stories(?:[_-][^/]*)?\//i;
|
|
16
|
+
var GENERATED_FILE_RE = /([\\/](?:generated|openapi-gen|graphql[\\/]types|vendor|vendored|third[-_]?party)[\\/])|(\.gen\.[cm]?[jt]sx?$)|(\.generated\.[cm]?[jt]sx?$)|(\.d\.[cm]?ts$)|(\.types\.[cm]?ts$)/;
|
|
17
|
+
var EXTERNAL_TREE_RE = /[\\/]external[\\/]/;
|
|
18
|
+
var GENERATED_MARKER_RE = /(?:@generated\b|this file (?:is|was|has been)[\w\s,'-]{0,40}?generated|auto-?generated file\b|generated (?:with|by)|generated (?:graphql )?types|do not edit(?: directly| manually)?|do not (?:modify|change) this file)/i;
|
|
19
|
+
var TEST_BASENAME_RE = /[.\-_](test|spec|e2e)\.[cm]?[jt]sx?$/;
|
|
20
|
+
var TEST_INTEGRATION_BASENAME_RE = /\.integration\.[cm]?[jt]sx?$/;
|
|
21
|
+
var TEST_DIR_RE = /(^|\/)(tests?|__tests__|__mocks__|fixtures|__fixtures__|__testfixtures__|e2e|integration)\//;
|
|
22
|
+
var FIXTURE_TREE_RE = /(^|\/)fixture\//;
|
|
23
|
+
function isTestFile(filename, gates = []) {
|
|
19
24
|
const normalized = filename.replaceAll("\\", "/");
|
|
20
25
|
const base = normalized.slice(normalized.lastIndexOf("/") + 1);
|
|
21
|
-
if (
|
|
26
|
+
if (TEST_BASENAME_RE.test(base) || TEST_INTEGRATION_BASENAME_RE.test(base)) {
|
|
22
27
|
return true;
|
|
23
28
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
29
|
+
if (TEST_DIR_RE.test(normalized)) {
|
|
30
|
+
return true;
|
|
31
|
+
}
|
|
32
|
+
return gates.includes("fixtureTree") && FIXTURE_TREE_RE.test(normalized);
|
|
27
33
|
}
|
|
28
|
-
function isStoryFile(filename) {
|
|
34
|
+
function isStoryFile(filename, gates = []) {
|
|
29
35
|
const normalized = filename.replaceAll("\\", "/");
|
|
30
|
-
|
|
36
|
+
if (STORY_FILE_RE.test(normalized)) {
|
|
37
|
+
return true;
|
|
38
|
+
}
|
|
39
|
+
return gates.includes("storyTree") && STORY_TREE_RE.test(normalized);
|
|
31
40
|
}
|
|
32
|
-
function isGeneratedFile(filename, sourceText = "") {
|
|
33
|
-
|
|
41
|
+
function isGeneratedFile(filename, sourceText = "", gates = []) {
|
|
42
|
+
const normalized = filename.replaceAll("\\", "/");
|
|
43
|
+
if (GENERATED_FILE_RE.test(normalized)) {
|
|
44
|
+
return true;
|
|
45
|
+
}
|
|
46
|
+
if (gates.includes("externalTree") && EXTERNAL_TREE_RE.test(normalized)) {
|
|
47
|
+
return true;
|
|
48
|
+
}
|
|
49
|
+
return GENERATED_MARKER_RE.test(sourceText.slice(0, 2048));
|
|
34
50
|
}
|
|
35
51
|
function isScriptFile(filename) {
|
|
36
52
|
return SCRIPT_FILE_RE.test(filename);
|
|
@@ -115,6 +131,10 @@ var enforce_file_structure_default = createRule({
|
|
|
115
131
|
|
|
116
132
|
// src/rules/no-async-callback-in-wait-for.ts
|
|
117
133
|
import { AST_NODE_TYPES as AST_NODE_TYPES2 } from "@typescript-eslint/utils";
|
|
134
|
+
var isWaitForCallee = (callee) => {
|
|
135
|
+
if (callee.type === AST_NODE_TYPES2.Identifier) return callee.name === "waitFor";
|
|
136
|
+
return callee.type === AST_NODE_TYPES2.MemberExpression && !callee.computed && callee.property.type === AST_NODE_TYPES2.Identifier && callee.property.name === "waitFor";
|
|
137
|
+
};
|
|
118
138
|
var no_async_callback_in_wait_for_default = createRule({
|
|
119
139
|
name: "no-async-callback-in-wait-for",
|
|
120
140
|
meta: {
|
|
@@ -134,14 +154,13 @@ var no_async_callback_in_wait_for_default = createRule({
|
|
|
134
154
|
}
|
|
135
155
|
return {
|
|
136
156
|
CallExpression(node) {
|
|
137
|
-
if (node.callee
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
}
|
|
157
|
+
if (!isWaitForCallee(node.callee)) return;
|
|
158
|
+
const callback = node.arguments[0];
|
|
159
|
+
if (callback && (callback.type === AST_NODE_TYPES2.ArrowFunctionExpression || callback.type === AST_NODE_TYPES2.FunctionExpression) && callback.async) {
|
|
160
|
+
context.report({
|
|
161
|
+
node: callback,
|
|
162
|
+
messageId: "noAsyncCallbackInWaitFor"
|
|
163
|
+
});
|
|
145
164
|
}
|
|
146
165
|
}
|
|
147
166
|
};
|
|
@@ -769,6 +788,12 @@ var no_comment_cruft_default = createRule({
|
|
|
769
788
|
// src/rules/no-conditional-in-test.ts
|
|
770
789
|
import { AST_NODE_TYPES as AST_NODE_TYPES6 } from "@typescript-eslint/utils";
|
|
771
790
|
var TEST_CALLERS = /* @__PURE__ */ new Set(["it", "test"]);
|
|
791
|
+
var HOOK_MEMBERS = /* @__PURE__ */ new Set([
|
|
792
|
+
"afterAll",
|
|
793
|
+
"afterEach",
|
|
794
|
+
"beforeAll",
|
|
795
|
+
"beforeEach"
|
|
796
|
+
]);
|
|
772
797
|
var FUNCTION_TYPES = /* @__PURE__ */ new Set([
|
|
773
798
|
AST_NODE_TYPES6.FunctionDeclaration,
|
|
774
799
|
AST_NODE_TYPES6.FunctionExpression,
|
|
@@ -812,6 +837,9 @@ function isTestBody(fn) {
|
|
|
812
837
|
if (call?.type !== AST_NODE_TYPES6.CallExpression || !call.arguments.some((argument) => argument === fn)) {
|
|
813
838
|
return false;
|
|
814
839
|
}
|
|
840
|
+
if (call.callee.type === AST_NODE_TYPES6.MemberExpression && !call.callee.computed && call.callee.property.type === AST_NODE_TYPES6.Identifier && HOOK_MEMBERS.has(call.callee.property.name)) {
|
|
841
|
+
return false;
|
|
842
|
+
}
|
|
815
843
|
const name = testCallerName(call.callee);
|
|
816
844
|
return name !== null && TEST_CALLERS.has(name);
|
|
817
845
|
}
|
|
@@ -966,8 +994,26 @@ function isTypeLevelNarrowing(node) {
|
|
|
966
994
|
return isTypeAssertionBranch(node.consequent) && (node.alternate === null || isTypeAssertionBranch(node.alternate));
|
|
967
995
|
}
|
|
968
996
|
var isInertBranch = (branch) => !containsAssertion(branch) && !containsEscape(branch) && !containsSkipCall(branch);
|
|
997
|
+
function isNormalizationStatement(statement) {
|
|
998
|
+
if (statement.type === AST_NODE_TYPES6.VariableDeclaration) {
|
|
999
|
+
return true;
|
|
1000
|
+
}
|
|
1001
|
+
if (statement.type === AST_NODE_TYPES6.BlockStatement) {
|
|
1002
|
+
return statement.body.every(isNormalizationStatement);
|
|
1003
|
+
}
|
|
1004
|
+
if (statement.type !== AST_NODE_TYPES6.ExpressionStatement) {
|
|
1005
|
+
return false;
|
|
1006
|
+
}
|
|
1007
|
+
const { expression } = statement;
|
|
1008
|
+
return expression.type === AST_NODE_TYPES6.AssignmentExpression || expression.type === AST_NODE_TYPES6.UpdateExpression || expression.type === AST_NODE_TYPES6.UnaryExpression && expression.operator === "delete";
|
|
1009
|
+
}
|
|
969
1010
|
function isInertNormalization(node) {
|
|
970
|
-
|
|
1011
|
+
const branches = [node.consequent, node.alternate].filter(
|
|
1012
|
+
(branch) => branch !== null
|
|
1013
|
+
);
|
|
1014
|
+
return branches.every(
|
|
1015
|
+
(branch) => isInertBranch(branch) && isNormalizationStatement(branch)
|
|
1016
|
+
);
|
|
971
1017
|
}
|
|
972
1018
|
function isExemptIfStatement(node) {
|
|
973
1019
|
return isPinnedNarrowingGuard(node) || isThrowingGuard(node) || isTypeLevelNarrowing(node) || isInertNormalization(node);
|
|
@@ -1575,7 +1621,6 @@ var PURE_METHODS = /* @__PURE__ */ new Set([
|
|
|
1575
1621
|
"forEach",
|
|
1576
1622
|
"reduce",
|
|
1577
1623
|
"reduceRight",
|
|
1578
|
-
"find",
|
|
1579
1624
|
"findIndex",
|
|
1580
1625
|
"findLast",
|
|
1581
1626
|
"findLastIndex",
|
|
@@ -1598,15 +1643,6 @@ var PURE_METHODS = /* @__PURE__ */ new Set([
|
|
|
1598
1643
|
"indexOf",
|
|
1599
1644
|
"lastIndexOf",
|
|
1600
1645
|
"at",
|
|
1601
|
-
"keys",
|
|
1602
|
-
"values",
|
|
1603
|
-
"entries",
|
|
1604
|
-
"has",
|
|
1605
|
-
"get",
|
|
1606
|
-
"set",
|
|
1607
|
-
"add",
|
|
1608
|
-
"delete",
|
|
1609
|
-
"clear",
|
|
1610
1646
|
"toString",
|
|
1611
1647
|
"toLocaleString",
|
|
1612
1648
|
"valueOf",
|
|
@@ -1637,6 +1673,7 @@ var PURE_NAMESPACES = /* @__PURE__ */ new Set([
|
|
|
1637
1673
|
"Boolean",
|
|
1638
1674
|
"console"
|
|
1639
1675
|
]);
|
|
1676
|
+
var IMPURE_NAMESPACE_METHODS = /* @__PURE__ */ new Set(["JSON.parse"]);
|
|
1640
1677
|
var PURE_CONSTRUCTORS = /* @__PURE__ */ new Set([
|
|
1641
1678
|
"Map",
|
|
1642
1679
|
"Set",
|
|
@@ -1673,7 +1710,7 @@ function isPureCall(node) {
|
|
|
1673
1710
|
return false;
|
|
1674
1711
|
}
|
|
1675
1712
|
if (callee.object.type === AST_NODE_TYPES9.Identifier && PURE_NAMESPACES.has(callee.object.name)) {
|
|
1676
|
-
return
|
|
1713
|
+
return !IMPURE_NAMESPACE_METHODS.has(`${callee.object.name}.${property.name}`);
|
|
1677
1714
|
}
|
|
1678
1715
|
return PURE_METHODS.has(property.name);
|
|
1679
1716
|
}
|
|
@@ -4992,29 +5029,61 @@ var no_trailing_value_narration_default = createRule({
|
|
|
4992
5029
|
}
|
|
4993
5030
|
});
|
|
4994
5031
|
|
|
4995
|
-
// src/rules/no-
|
|
5032
|
+
// src/rules/no-declaration-comment-wall.ts
|
|
5033
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES23 } from "@typescript-eslint/utils";
|
|
5034
|
+
|
|
5035
|
+
// src/rules/_comment-wall.ts
|
|
4996
5036
|
import { AST_NODE_TYPES as AST_NODE_TYPES22 } from "@typescript-eslint/utils";
|
|
4997
|
-
var
|
|
5037
|
+
var WALL_DEFAULTS = {
|
|
4998
5038
|
// Below three rows "a wall" is not a fair description of what the reader sees.
|
|
4999
5039
|
minCommentedMembers: 3,
|
|
5000
5040
|
// A minority of commented members is a GROUP LABEL, not a wall.
|
|
5001
5041
|
minCommentedRatio: 0.6,
|
|
5002
|
-
// Room for one substantive row in four; a
|
|
5003
|
-
// say something real is
|
|
5042
|
+
// Room for one substantive row in four; a declaration where a quarter of the
|
|
5043
|
+
// comments say something real is one someone was documenting, not decorating.
|
|
5004
5044
|
minRestatedRatio: 0.75,
|
|
5005
|
-
// One word beyond the member's own text. Zero is `no-restated-jsdoc`'s
|
|
5006
|
-
//
|
|
5007
|
-
// beside "Exact match")
|
|
5045
|
+
// One word beyond the member's own text. Zero is `no-restated-jsdoc`'s test
|
|
5046
|
+
// and is already covered there; two admits definitions ("Partial match"
|
|
5047
|
+
// beside "Exact match").
|
|
5008
5048
|
maxNovelWords: 1
|
|
5009
5049
|
};
|
|
5050
|
+
var WALL_SCHEMA = {
|
|
5051
|
+
type: "object",
|
|
5052
|
+
additionalProperties: false,
|
|
5053
|
+
properties: {
|
|
5054
|
+
minCommentedMembers: {
|
|
5055
|
+
type: "integer",
|
|
5056
|
+
minimum: 2,
|
|
5057
|
+
description: "Fewest commented members that can count as a wall."
|
|
5058
|
+
},
|
|
5059
|
+
minCommentedRatio: {
|
|
5060
|
+
type: "number",
|
|
5061
|
+
minimum: 0,
|
|
5062
|
+
maximum: 1,
|
|
5063
|
+
description: "Least share of the members that must be commented; below it the comments are group labels."
|
|
5064
|
+
},
|
|
5065
|
+
minRestatedRatio: {
|
|
5066
|
+
type: "number",
|
|
5067
|
+
minimum: 0,
|
|
5068
|
+
maximum: 1,
|
|
5069
|
+
description: "Least share of the member comments that must be restatements."
|
|
5070
|
+
},
|
|
5071
|
+
maxNovelWords: {
|
|
5072
|
+
type: "integer",
|
|
5073
|
+
minimum: 0,
|
|
5074
|
+
description: "Most content words a comment may add beyond its member's own source and still count as a restatement."
|
|
5075
|
+
}
|
|
5076
|
+
}
|
|
5077
|
+
};
|
|
5010
5078
|
var VALUE_TAG_RE = /@(?:deprecated|see|example|throws|remarks|since|default|defaultvalue|link|internal|alpha|beta|experimental|template|typeparam|inheritdoc|todo|fixme|override)\b/i;
|
|
5011
5079
|
var DEFAULT_RE = /^\s*@?default\b|\bdefaults? (?:to|:)/i;
|
|
5012
5080
|
var DIGIT_RE = /\d/;
|
|
5013
5081
|
var UNIT_WORD_RE = /\b(?:ms|milliseconds?|seconds?|minutes?|hours?|days?|weeks?|months?|years?|bytes?|kb|mb|gb|percent|pixels?|px|utc|epoch)\b/i;
|
|
5014
5082
|
var EXAMPLE_RE = /["'`]|\be\.g\.|\bi\.e\./;
|
|
5083
|
+
var TAG_TOKEN_RE = /@\w+/g;
|
|
5015
5084
|
var BANNER_RE = /[=\-─-╿*#~_.]{3,}/;
|
|
5016
5085
|
var NON_ASCII_LETTER_RE2 = /[^\p{ASCII}\p{N}\p{P}\p{Z}]/u;
|
|
5017
|
-
var
|
|
5086
|
+
var WALL_STOPWORDS = new Set(
|
|
5018
5087
|
`the a an of to for in on with and or as at by is are was be been being
|
|
5019
5088
|
this that it its if whether when where which what will would can could should
|
|
5020
5089
|
must may into from over about not no does do done has have had used use uses
|
|
@@ -5029,15 +5098,22 @@ var BARE_LABEL_RE = /^[A-Za-z][A-Za-z0-9]*$/;
|
|
|
5029
5098
|
function labelStems(body) {
|
|
5030
5099
|
return splitIdentifier(body).map(stem).join(" ");
|
|
5031
5100
|
}
|
|
5032
|
-
function isNamedMember(node) {
|
|
5033
|
-
return (node.type === AST_NODE_TYPES22.TSPropertySignature || node.type === AST_NODE_TYPES22.TSMethodSignature) && !node.computed;
|
|
5034
|
-
}
|
|
5035
5101
|
function commentBody(comment) {
|
|
5036
5102
|
return comment.value.replace(/^\*+/, "").replace(/^[ \t]*\*[ \t]?/gm, "").trim();
|
|
5037
5103
|
}
|
|
5038
5104
|
function carriesValue(body) {
|
|
5039
5105
|
return isProtected(body) || VALUE_TAG_RE.test(body) || DEFAULT_RE.test(body) || DIGIT_RE.test(body) || UNIT_WORD_RE.test(body) || EXAMPLE_RE.test(body) || BANNER_RE.test(body) || NON_ASCII_LETTER_RE2.test(body);
|
|
5040
5106
|
}
|
|
5107
|
+
function isLabel(body) {
|
|
5108
|
+
let content = 0;
|
|
5109
|
+
for (const word of body.match(WORD_RE4) ?? []) {
|
|
5110
|
+
if (word.length >= 2 && !WALL_STOPWORDS.has(word.toLowerCase())) content += 1;
|
|
5111
|
+
}
|
|
5112
|
+
return content <= 1;
|
|
5113
|
+
}
|
|
5114
|
+
function isTagsOnly(body) {
|
|
5115
|
+
return body.length > 0 && body.replace(TAG_TOKEN_RE, "").trim().length === 0;
|
|
5116
|
+
}
|
|
5041
5117
|
function knownTokens(source) {
|
|
5042
5118
|
const tokens = /* @__PURE__ */ new Set();
|
|
5043
5119
|
for (const identifier of source.match(/[A-Za-z_$][\w$]*/g) ?? []) {
|
|
@@ -5052,11 +5128,146 @@ function novelWords(body, known) {
|
|
|
5052
5128
|
let novel = 0;
|
|
5053
5129
|
for (const word of body.match(WORD_RE4) ?? []) {
|
|
5054
5130
|
const lower = word.toLowerCase();
|
|
5055
|
-
if (lower.length < 2 ||
|
|
5131
|
+
if (lower.length < 2 || WALL_STOPWORDS.has(lower)) continue;
|
|
5056
5132
|
if (!known.has(lower) && !known.has(stem(lower))) novel += 1;
|
|
5057
5133
|
}
|
|
5058
5134
|
return novel;
|
|
5059
5135
|
}
|
|
5136
|
+
function isWall(members, commented, restated, options) {
|
|
5137
|
+
return commented >= options.minCommentedMembers && commented / members >= options.minCommentedRatio && restated / commented >= options.minRestatedRatio;
|
|
5138
|
+
}
|
|
5139
|
+
var OPAQUE_VALUE_TYPES = /* @__PURE__ */ new Set([
|
|
5140
|
+
AST_NODE_TYPES22.FunctionExpression,
|
|
5141
|
+
AST_NODE_TYPES22.ArrowFunctionExpression,
|
|
5142
|
+
AST_NODE_TYPES22.ObjectExpression,
|
|
5143
|
+
AST_NODE_TYPES22.ArrayExpression
|
|
5144
|
+
]);
|
|
5145
|
+
function declarationRange(member) {
|
|
5146
|
+
const body = bodyOf(member);
|
|
5147
|
+
if (body === void 0) return [member.range[0], member.range[1]];
|
|
5148
|
+
return [member.range[0], body.range[0]];
|
|
5149
|
+
}
|
|
5150
|
+
function bodyOf(member) {
|
|
5151
|
+
if (member.type === AST_NODE_TYPES22.MethodDefinition || member.type === AST_NODE_TYPES22.TSAbstractMethodDefinition) {
|
|
5152
|
+
return member.value.body ?? void 0;
|
|
5153
|
+
}
|
|
5154
|
+
if (member.type === AST_NODE_TYPES22.Property || member.type === AST_NODE_TYPES22.PropertyDefinition) {
|
|
5155
|
+
const value = member.value;
|
|
5156
|
+
if (value !== null && OPAQUE_VALUE_TYPES.has(value.type)) return value;
|
|
5157
|
+
}
|
|
5158
|
+
return void 0;
|
|
5159
|
+
}
|
|
5160
|
+
|
|
5161
|
+
// src/rules/no-declaration-comment-wall.ts
|
|
5162
|
+
function named(node) {
|
|
5163
|
+
switch (node.type) {
|
|
5164
|
+
case AST_NODE_TYPES23.TSEnumMember:
|
|
5165
|
+
return { node, key: node.id };
|
|
5166
|
+
case AST_NODE_TYPES23.PropertyDefinition:
|
|
5167
|
+
case AST_NODE_TYPES23.TSAbstractPropertyDefinition:
|
|
5168
|
+
case AST_NODE_TYPES23.MethodDefinition:
|
|
5169
|
+
case AST_NODE_TYPES23.TSAbstractMethodDefinition:
|
|
5170
|
+
return node.computed ? void 0 : { node, key: node.key };
|
|
5171
|
+
default:
|
|
5172
|
+
return void 0;
|
|
5173
|
+
}
|
|
5174
|
+
}
|
|
5175
|
+
var no_declaration_comment_wall_default = createRule({
|
|
5176
|
+
name: "no-declaration-comment-wall",
|
|
5177
|
+
meta: {
|
|
5178
|
+
type: "suggestion",
|
|
5179
|
+
docs: {
|
|
5180
|
+
description: "Flag an enum body or class body whose member comments mostly re-spell the members' own names."
|
|
5181
|
+
},
|
|
5182
|
+
schema: [WALL_SCHEMA],
|
|
5183
|
+
messages: {
|
|
5184
|
+
commentWall: "{{restated}} of this declaration's {{commented}} member comments only re-spell the member's own name \u2014 delete them, and keep the rows that say what the name cannot."
|
|
5185
|
+
}
|
|
5186
|
+
},
|
|
5187
|
+
defaultOptions: [WALL_DEFAULTS],
|
|
5188
|
+
create(context, [provided]) {
|
|
5189
|
+
const options = { ...WALL_DEFAULTS, ...provided };
|
|
5190
|
+
const sourceCode = context.sourceCode;
|
|
5191
|
+
if (isGeneratedFile(context.filename, sourceCode.text) || isTestFile(context.filename) || isStoryFile(context.filename)) {
|
|
5192
|
+
return {};
|
|
5193
|
+
}
|
|
5194
|
+
const endingOn = /* @__PURE__ */ new Map();
|
|
5195
|
+
const startingOn = /* @__PURE__ */ new Map();
|
|
5196
|
+
for (const comment of sourceCode.getAllComments()) {
|
|
5197
|
+
endingOn.set(comment.loc.end.line, comment);
|
|
5198
|
+
if (!startingOn.has(comment.loc.start.line)) startingOn.set(comment.loc.start.line, comment);
|
|
5199
|
+
}
|
|
5200
|
+
function documentingComment(member) {
|
|
5201
|
+
const beforeMember = sourceCode.getTokenBefore(member, { includeComments: false });
|
|
5202
|
+
const ownsItsLine = beforeMember === null || beforeMember.loc.end.line < member.loc.start.line;
|
|
5203
|
+
const lead = ownsItsLine ? endingOn.get(member.loc.start.line - 1) : void 0;
|
|
5204
|
+
if (lead !== void 0) {
|
|
5205
|
+
const before = sourceCode.getTokenBefore(lead, { includeComments: false });
|
|
5206
|
+
if (before === null || before.loc.end.line < lead.loc.start.line) return lead;
|
|
5207
|
+
}
|
|
5208
|
+
const trail = startingOn.get(member.loc.end.line);
|
|
5209
|
+
return trail !== void 0 && trail.range[0] > member.range[0] ? trail : void 0;
|
|
5210
|
+
}
|
|
5211
|
+
function isGroupLabel(comment, member, headsRun) {
|
|
5212
|
+
if (comment.loc.end.line >= member.node.loc.start.line) return false;
|
|
5213
|
+
const body = commentBody(comment);
|
|
5214
|
+
if (!BARE_LABEL_RE.test(body)) return false;
|
|
5215
|
+
if (labelStems(body) === labelStems(sourceCode.getText(member.key))) return false;
|
|
5216
|
+
const lineAbove = sourceCode.lines[comment.loc.start.line - 2];
|
|
5217
|
+
return headsRun || lineAbove !== void 0 && lineAbove.trim().length === 0;
|
|
5218
|
+
}
|
|
5219
|
+
function check(node, members) {
|
|
5220
|
+
const judged = members.map(named).filter((member) => member !== void 0);
|
|
5221
|
+
if (judged.length === 0) return;
|
|
5222
|
+
const documented = judged.map((member) => ({
|
|
5223
|
+
member,
|
|
5224
|
+
comment: documentingComment(member.node)
|
|
5225
|
+
}));
|
|
5226
|
+
let commented = 0;
|
|
5227
|
+
let restated = 0;
|
|
5228
|
+
for (const [index, { member, comment }] of documented.entries()) {
|
|
5229
|
+
if (comment === void 0) continue;
|
|
5230
|
+
const next = documented[index + 1];
|
|
5231
|
+
if (isGroupLabel(comment, member, next !== void 0 && next.comment === void 0)) {
|
|
5232
|
+
continue;
|
|
5233
|
+
}
|
|
5234
|
+
commented += 1;
|
|
5235
|
+
const body = commentBody(comment);
|
|
5236
|
+
if (body.length === 0 || carriesValue(body) || isTagsOnly(body) || isLabel(body)) {
|
|
5237
|
+
continue;
|
|
5238
|
+
}
|
|
5239
|
+
const [start, end] = declarationRange(member.node);
|
|
5240
|
+
if (novelWords(body, knownTokens(sourceCode.text.slice(start, end))) <= options.maxNovelWords) {
|
|
5241
|
+
restated += 1;
|
|
5242
|
+
}
|
|
5243
|
+
}
|
|
5244
|
+
if (!isWall(judged.length, commented, restated, options)) return;
|
|
5245
|
+
context.report({
|
|
5246
|
+
node,
|
|
5247
|
+
loc: {
|
|
5248
|
+
start: node.loc.start,
|
|
5249
|
+
end: { line: node.loc.start.line, column: node.loc.start.column + 1 }
|
|
5250
|
+
},
|
|
5251
|
+
messageId: "commentWall",
|
|
5252
|
+
data: { restated: String(restated), commented: String(commented) }
|
|
5253
|
+
});
|
|
5254
|
+
}
|
|
5255
|
+
return {
|
|
5256
|
+
ClassBody: (node) => {
|
|
5257
|
+
check(node, node.body);
|
|
5258
|
+
},
|
|
5259
|
+
TSEnumDeclaration: (node) => {
|
|
5260
|
+
check(node, node.body.members);
|
|
5261
|
+
}
|
|
5262
|
+
};
|
|
5263
|
+
}
|
|
5264
|
+
});
|
|
5265
|
+
|
|
5266
|
+
// src/rules/no-type-member-comment-wall.ts
|
|
5267
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES24 } from "@typescript-eslint/utils";
|
|
5268
|
+
function isNamedMember(node) {
|
|
5269
|
+
return (node.type === AST_NODE_TYPES24.TSPropertySignature || node.type === AST_NODE_TYPES24.TSMethodSignature) && !node.computed;
|
|
5270
|
+
}
|
|
5060
5271
|
var no_type_member_comment_wall_default = createRule({
|
|
5061
5272
|
name: "no-type-member-comment-wall",
|
|
5062
5273
|
meta: {
|
|
@@ -5064,45 +5275,16 @@ var no_type_member_comment_wall_default = createRule({
|
|
|
5064
5275
|
docs: {
|
|
5065
5276
|
description: "Flag an object type whose member comments mostly re-spell the members' own names and types."
|
|
5066
5277
|
},
|
|
5067
|
-
schema: [
|
|
5068
|
-
{
|
|
5069
|
-
type: "object",
|
|
5070
|
-
additionalProperties: false,
|
|
5071
|
-
properties: {
|
|
5072
|
-
minCommentedMembers: {
|
|
5073
|
-
type: "integer",
|
|
5074
|
-
minimum: 2,
|
|
5075
|
-
description: "Fewest commented members that can count as a wall."
|
|
5076
|
-
},
|
|
5077
|
-
minCommentedRatio: {
|
|
5078
|
-
type: "number",
|
|
5079
|
-
minimum: 0,
|
|
5080
|
-
maximum: 1,
|
|
5081
|
-
description: "Least share of the type's members that must be commented; below it the comments are group labels."
|
|
5082
|
-
},
|
|
5083
|
-
minRestatedRatio: {
|
|
5084
|
-
type: "number",
|
|
5085
|
-
minimum: 0,
|
|
5086
|
-
maximum: 1,
|
|
5087
|
-
description: "Least share of the member comments that must be restatements."
|
|
5088
|
-
},
|
|
5089
|
-
maxNovelWords: {
|
|
5090
|
-
type: "integer",
|
|
5091
|
-
minimum: 0,
|
|
5092
|
-
description: "Most content words a comment may add beyond its member's own source and still count as a restatement."
|
|
5093
|
-
}
|
|
5094
|
-
}
|
|
5095
|
-
}
|
|
5096
|
-
],
|
|
5278
|
+
schema: [WALL_SCHEMA],
|
|
5097
5279
|
messages: {
|
|
5098
5280
|
commentWall: "{{restated}} of this type's {{commented}} member comments only re-spell the member's own name and type \u2014 delete them, and keep the rows that say what the name cannot."
|
|
5099
5281
|
}
|
|
5100
5282
|
},
|
|
5101
|
-
defaultOptions: [
|
|
5283
|
+
defaultOptions: [WALL_DEFAULTS],
|
|
5102
5284
|
create(context, [provided]) {
|
|
5103
|
-
const options = { ...
|
|
5285
|
+
const options = { ...WALL_DEFAULTS, ...provided };
|
|
5104
5286
|
const sourceCode = context.sourceCode;
|
|
5105
|
-
if (isGeneratedFile(context.filename, sourceCode.text) || isTestFile(context.filename) || isStoryFile(context.filename)) {
|
|
5287
|
+
if (isGeneratedFile(context.filename, sourceCode.text, ["externalTree"]) || isTestFile(context.filename, ["fixtureTree"]) || isStoryFile(context.filename, ["storyTree"])) {
|
|
5106
5288
|
return {};
|
|
5107
5289
|
}
|
|
5108
5290
|
const endingOn = /* @__PURE__ */ new Map();
|
|
@@ -5131,10 +5313,10 @@ var no_type_member_comment_wall_default = createRule({
|
|
|
5131
5313
|
return headsRun || lineAbove !== void 0 && lineAbove.trim().length === 0;
|
|
5132
5314
|
}
|
|
5133
5315
|
function check(node) {
|
|
5134
|
-
const members = node.type ===
|
|
5135
|
-
const
|
|
5136
|
-
if (
|
|
5137
|
-
const documented =
|
|
5316
|
+
const members = node.type === AST_NODE_TYPES24.TSInterfaceBody ? node.body : node.members;
|
|
5317
|
+
const named2 = members.filter(isNamedMember);
|
|
5318
|
+
if (named2.length === 0) return;
|
|
5319
|
+
const documented = named2.map((member) => ({ member, comment: documentingComment(member) }));
|
|
5138
5320
|
let commented = 0;
|
|
5139
5321
|
let restated = 0;
|
|
5140
5322
|
const claimed = /* @__PURE__ */ new Set();
|
|
@@ -5152,9 +5334,7 @@ var no_type_member_comment_wall_default = createRule({
|
|
|
5152
5334
|
restated += 1;
|
|
5153
5335
|
}
|
|
5154
5336
|
}
|
|
5155
|
-
if (
|
|
5156
|
-
return;
|
|
5157
|
-
}
|
|
5337
|
+
if (!isWall(named2.length, commented, restated, options)) return;
|
|
5158
5338
|
context.report({
|
|
5159
5339
|
node,
|
|
5160
5340
|
loc: {
|
|
@@ -5173,7 +5353,7 @@ var no_type_member_comment_wall_default = createRule({
|
|
|
5173
5353
|
});
|
|
5174
5354
|
|
|
5175
5355
|
// src/rules/no-unnecessary-use-client.ts
|
|
5176
|
-
import { AST_NODE_TYPES as
|
|
5356
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES25 } from "@typescript-eslint/utils";
|
|
5177
5357
|
var HOOK_REGEX = /^use([A-Z]|$)/;
|
|
5178
5358
|
var EVENT_PROP_REGEX = /^on[A-Z]/;
|
|
5179
5359
|
var ERROR_FILE_REGEX = /\b(?:global-)?error\.[jt]sx?$/;
|
|
@@ -5199,13 +5379,13 @@ var CLIENT_ONLY_PACKAGES_REGEX = /^(?:@radix-ui\/|framer-motion|react-dom|react-
|
|
|
5199
5379
|
var isBareSpecifier = (source) => !source.startsWith(".") && !source.startsWith("/") && !source.startsWith("@/") && !source.startsWith("~");
|
|
5200
5380
|
var jsxRootName = (name) => {
|
|
5201
5381
|
let current = name;
|
|
5202
|
-
while (current.type ===
|
|
5382
|
+
while (current.type === AST_NODE_TYPES25.JSXMemberExpression) {
|
|
5203
5383
|
current = current.object;
|
|
5204
5384
|
}
|
|
5205
|
-
return current.type ===
|
|
5385
|
+
return current.type === AST_NODE_TYPES25.JSXIdentifier ? current.name : "";
|
|
5206
5386
|
};
|
|
5207
5387
|
var subtreeReadsImportedBinding = (node, imported) => {
|
|
5208
|
-
if (node.type ===
|
|
5388
|
+
if (node.type === AST_NODE_TYPES25.Identifier) {
|
|
5209
5389
|
return imported.has(node.name);
|
|
5210
5390
|
}
|
|
5211
5391
|
for (const key of Object.keys(node)) {
|
|
@@ -5220,16 +5400,16 @@ var subtreeReadsImportedBinding = (node, imported) => {
|
|
|
5220
5400
|
return false;
|
|
5221
5401
|
};
|
|
5222
5402
|
var isUseClientDirective = (node) => {
|
|
5223
|
-
return node.type ===
|
|
5403
|
+
return node.type === AST_NODE_TYPES25.ExpressionStatement && node.expression.type === AST_NODE_TYPES25.Literal && node.expression.value === "use client";
|
|
5224
5404
|
};
|
|
5225
5405
|
var isGlobalReference = (node, context) => {
|
|
5226
5406
|
if (!BROWSER_GLOBALS.has(node.name)) return false;
|
|
5227
5407
|
const parent = node.parent;
|
|
5228
5408
|
if (parent !== void 0) {
|
|
5229
|
-
if (parent.type ===
|
|
5409
|
+
if (parent.type === AST_NODE_TYPES25.MemberExpression && parent.property === node && !parent.computed) {
|
|
5230
5410
|
return false;
|
|
5231
5411
|
}
|
|
5232
|
-
if (parent.type ===
|
|
5412
|
+
if (parent.type === AST_NODE_TYPES25.Property && parent.key === node && !parent.computed) {
|
|
5233
5413
|
return false;
|
|
5234
5414
|
}
|
|
5235
5415
|
if (parent.type.startsWith("TS")) {
|
|
@@ -5269,13 +5449,13 @@ var no_unnecessary_use_client_default = createRule({
|
|
|
5269
5449
|
const importedLocals = /* @__PURE__ */ new Set();
|
|
5270
5450
|
const externalLocals = /* @__PURE__ */ new Set();
|
|
5271
5451
|
const markIfHookOrContext = (callee) => {
|
|
5272
|
-
if (callee.type ===
|
|
5452
|
+
if (callee.type === AST_NODE_TYPES25.Identifier) {
|
|
5273
5453
|
if (HOOK_REGEX.test(callee.name) || callee.name === "createContext") {
|
|
5274
5454
|
hasClientIndicator = true;
|
|
5275
5455
|
}
|
|
5276
5456
|
return;
|
|
5277
5457
|
}
|
|
5278
|
-
if (callee.type ===
|
|
5458
|
+
if (callee.type === AST_NODE_TYPES25.MemberExpression && callee.property.type === AST_NODE_TYPES25.Identifier) {
|
|
5279
5459
|
const name = callee.property.name;
|
|
5280
5460
|
if (HOOK_REGEX.test(name) || name === "createContext") {
|
|
5281
5461
|
hasClientIndicator = true;
|
|
@@ -5285,7 +5465,7 @@ var no_unnecessary_use_client_default = createRule({
|
|
|
5285
5465
|
return {
|
|
5286
5466
|
Program(node) {
|
|
5287
5467
|
for (const stmt of node.body) {
|
|
5288
|
-
if (stmt.type !==
|
|
5468
|
+
if (stmt.type !== AST_NODE_TYPES25.ExpressionStatement) break;
|
|
5289
5469
|
if (isUseClientDirective(stmt)) {
|
|
5290
5470
|
directiveNode = stmt;
|
|
5291
5471
|
break;
|
|
@@ -5298,7 +5478,7 @@ var no_unnecessary_use_client_default = createRule({
|
|
|
5298
5478
|
},
|
|
5299
5479
|
JSXAttribute(node) {
|
|
5300
5480
|
if (directiveNode === null) return;
|
|
5301
|
-
if (node.name.type ===
|
|
5481
|
+
if (node.name.type === AST_NODE_TYPES25.JSXIdentifier && EVENT_PROP_REGEX.test(node.name.name)) {
|
|
5302
5482
|
hasClientIndicator = true;
|
|
5303
5483
|
}
|
|
5304
5484
|
},
|
|
@@ -5366,17 +5546,17 @@ var no_unnecessary_use_client_default = createRule({
|
|
|
5366
5546
|
|
|
5367
5547
|
// src/rules/no-unsafe-mock-casting.ts
|
|
5368
5548
|
import "@typescript-eslint/utils";
|
|
5369
|
-
import { AST_NODE_TYPES as
|
|
5549
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES26 } from "@typescript-eslint/utils";
|
|
5370
5550
|
function isMockTypeReference(node) {
|
|
5371
|
-
if (node.type !==
|
|
5551
|
+
if (node.type !== AST_NODE_TYPES26.TSTypeReference) {
|
|
5372
5552
|
return false;
|
|
5373
5553
|
}
|
|
5374
5554
|
const typeName = node.typeName;
|
|
5375
|
-
if (typeName.type ===
|
|
5555
|
+
if (typeName.type === AST_NODE_TYPES26.Identifier) {
|
|
5376
5556
|
const name = typeName.name;
|
|
5377
5557
|
return name === "Mock" || name === "MockInstance" || name === "SpyInstance";
|
|
5378
5558
|
}
|
|
5379
|
-
if (typeName.type ===
|
|
5559
|
+
if (typeName.type === AST_NODE_TYPES26.TSQualifiedName) {
|
|
5380
5560
|
const rightName = typeName.right.name;
|
|
5381
5561
|
return rightName === "Mock" || rightName === "MockInstance" || rightName === "SpyInstance";
|
|
5382
5562
|
}
|
|
@@ -5414,7 +5594,7 @@ var no_unsafe_mock_casting_default = createRule({
|
|
|
5414
5594
|
// src/rules/no-zod-native-enum.ts
|
|
5415
5595
|
import {
|
|
5416
5596
|
ESLintUtils as ESLintUtils2,
|
|
5417
|
-
AST_NODE_TYPES as
|
|
5597
|
+
AST_NODE_TYPES as AST_NODE_TYPES27
|
|
5418
5598
|
} from "@typescript-eslint/utils";
|
|
5419
5599
|
import * as ts from "typescript";
|
|
5420
5600
|
var IGNORE_PATTERNS = [
|
|
@@ -5433,7 +5613,7 @@ function isZodModule(source) {
|
|
|
5433
5613
|
return /(^|[/@-])zod([/-]|$)/.test(source);
|
|
5434
5614
|
}
|
|
5435
5615
|
function unwrap2(node) {
|
|
5436
|
-
if (node.type ===
|
|
5616
|
+
if (node.type === AST_NODE_TYPES27.TSAsExpression || node.type === AST_NODE_TYPES27.TSSatisfiesExpression) {
|
|
5437
5617
|
return unwrap2(node.expression);
|
|
5438
5618
|
}
|
|
5439
5619
|
return node;
|
|
@@ -5441,14 +5621,14 @@ function unwrap2(node) {
|
|
|
5441
5621
|
function stringValueTexts(node, sourceCode) {
|
|
5442
5622
|
const texts = [];
|
|
5443
5623
|
for (const prop of node.properties) {
|
|
5444
|
-
if (prop.type !==
|
|
5624
|
+
if (prop.type !== AST_NODE_TYPES27.Property) {
|
|
5445
5625
|
return null;
|
|
5446
5626
|
}
|
|
5447
5627
|
if (prop.computed || prop.shorthand || prop.method || prop.kind !== "init") {
|
|
5448
5628
|
return null;
|
|
5449
5629
|
}
|
|
5450
5630
|
const value = prop.value;
|
|
5451
|
-
if (value.type !==
|
|
5631
|
+
if (value.type !== AST_NODE_TYPES27.Literal || typeof value.value !== "string") {
|
|
5452
5632
|
return null;
|
|
5453
5633
|
}
|
|
5454
5634
|
const text = sourceCode.getText(value);
|
|
@@ -5464,7 +5644,7 @@ function resolvesToLocalEnum(node, scope) {
|
|
|
5464
5644
|
const variable = current.variables.find((v) => v.name === node.name);
|
|
5465
5645
|
if (variable !== void 0) {
|
|
5466
5646
|
return variable.defs.some(
|
|
5467
|
-
(def) => def.node.type ===
|
|
5647
|
+
(def) => def.node.type === AST_NODE_TYPES27.TSEnumDeclaration
|
|
5468
5648
|
);
|
|
5469
5649
|
}
|
|
5470
5650
|
current = current.upper;
|
|
@@ -5516,25 +5696,25 @@ var no_zod_native_enum_default = createRule({
|
|
|
5516
5696
|
const zodImportedNames = /* @__PURE__ */ new Map();
|
|
5517
5697
|
function isZodMemberCall(node, api) {
|
|
5518
5698
|
const callee = node.callee;
|
|
5519
|
-
if (callee.type ===
|
|
5699
|
+
if (callee.type === AST_NODE_TYPES27.MemberExpression && !callee.computed && callee.property.type === AST_NODE_TYPES27.Identifier) {
|
|
5520
5700
|
return callee.property.name === api;
|
|
5521
5701
|
}
|
|
5522
|
-
if (callee.type ===
|
|
5702
|
+
if (callee.type === AST_NODE_TYPES27.Identifier) {
|
|
5523
5703
|
return zodImportedNames.get(callee.name) === api;
|
|
5524
5704
|
}
|
|
5525
5705
|
return false;
|
|
5526
5706
|
}
|
|
5527
5707
|
function buildFix(node) {
|
|
5528
5708
|
const callee = node.callee;
|
|
5529
|
-
if (callee.type !==
|
|
5709
|
+
if (callee.type !== AST_NODE_TYPES27.MemberExpression || callee.property.type !== AST_NODE_TYPES27.Identifier) {
|
|
5530
5710
|
return null;
|
|
5531
5711
|
}
|
|
5532
5712
|
const arg = node.arguments[0];
|
|
5533
|
-
if (arg === void 0 || node.arguments.length !== 1 || arg.type ===
|
|
5713
|
+
if (arg === void 0 || node.arguments.length !== 1 || arg.type === AST_NODE_TYPES27.SpreadElement) {
|
|
5534
5714
|
return null;
|
|
5535
5715
|
}
|
|
5536
5716
|
const inner = unwrap2(arg);
|
|
5537
|
-
if (inner.type !==
|
|
5717
|
+
if (inner.type !== AST_NODE_TYPES27.ObjectExpression) {
|
|
5538
5718
|
return null;
|
|
5539
5719
|
}
|
|
5540
5720
|
const values = stringValueTexts(inner, sourceCode);
|
|
@@ -5554,7 +5734,7 @@ var no_zod_native_enum_default = createRule({
|
|
|
5554
5734
|
return;
|
|
5555
5735
|
}
|
|
5556
5736
|
for (const spec of node.specifiers) {
|
|
5557
|
-
if (spec.type ===
|
|
5737
|
+
if (spec.type === AST_NODE_TYPES27.ImportSpecifier && spec.imported.type === AST_NODE_TYPES27.Identifier) {
|
|
5558
5738
|
zodImportedNames.set(spec.local.name, spec.imported.name);
|
|
5559
5739
|
}
|
|
5560
5740
|
}
|
|
@@ -5573,7 +5753,7 @@ var no_zod_native_enum_default = createRule({
|
|
|
5573
5753
|
return;
|
|
5574
5754
|
}
|
|
5575
5755
|
const arg = node.arguments[0];
|
|
5576
|
-
if (arg === void 0 || arg.type !==
|
|
5756
|
+
if (arg === void 0 || arg.type !== AST_NODE_TYPES27.Identifier) {
|
|
5577
5757
|
return;
|
|
5578
5758
|
}
|
|
5579
5759
|
const isEnum = resolvesToLocalEnum(arg, sourceCode.getScope(arg)) || services !== null && resolvesToImportedEnum(arg, services);
|
|
@@ -5590,7 +5770,7 @@ var no_zod_native_enum_default = createRule({
|
|
|
5590
5770
|
});
|
|
5591
5771
|
|
|
5592
5772
|
// src/rules/prefer-constant-time-secret-compare.ts
|
|
5593
|
-
import { AST_NODE_TYPES as
|
|
5773
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES28 } from "@typescript-eslint/utils";
|
|
5594
5774
|
var EQUALITY_OPERATORS = /* @__PURE__ */ new Set(["===", "!==", "==", "!="]);
|
|
5595
5775
|
var SENTINEL_IDENTIFIERS = /* @__PURE__ */ new Set(["undefined", "NaN"]);
|
|
5596
5776
|
var SENTINEL_WORDS = /(^|_)(SENTINEL|EMPTY|NONE|NULL|UNSET|MISSING|PLACEHOLDER|DUMMY|FAKE|EXAMPLE)(_|$)/;
|
|
@@ -5603,36 +5783,36 @@ function isConstantReference(identifier) {
|
|
|
5603
5783
|
}
|
|
5604
5784
|
function isExcludedOperand(node) {
|
|
5605
5785
|
switch (node.type) {
|
|
5606
|
-
case
|
|
5786
|
+
case AST_NODE_TYPES28.Literal:
|
|
5607
5787
|
return true;
|
|
5608
|
-
case
|
|
5788
|
+
case AST_NODE_TYPES28.TemplateLiteral:
|
|
5609
5789
|
return node.expressions.length === 0;
|
|
5610
|
-
case
|
|
5790
|
+
case AST_NODE_TYPES28.Identifier:
|
|
5611
5791
|
return SENTINEL_IDENTIFIERS.has(node.name) || SENTINEL_PREFIX_RE.test(node.name) || isConstantReference(node.name);
|
|
5612
|
-
case
|
|
5613
|
-
return !node.computed && node.property.type ===
|
|
5792
|
+
case AST_NODE_TYPES28.MemberExpression:
|
|
5793
|
+
return !node.computed && node.property.type === AST_NODE_TYPES28.Identifier && (SENTINEL_PREFIX_RE.test(node.property.name) || isConstantReference(node.property.name));
|
|
5614
5794
|
default:
|
|
5615
5795
|
return false;
|
|
5616
5796
|
}
|
|
5617
5797
|
}
|
|
5618
5798
|
function operandName(node) {
|
|
5619
|
-
if (node.type ===
|
|
5799
|
+
if (node.type === AST_NODE_TYPES28.Identifier) {
|
|
5620
5800
|
return node.name;
|
|
5621
5801
|
}
|
|
5622
|
-
if (node.type ===
|
|
5802
|
+
if (node.type === AST_NODE_TYPES28.MemberExpression && !node.computed && node.property.type === AST_NODE_TYPES28.Identifier) {
|
|
5623
5803
|
return node.property.name;
|
|
5624
5804
|
}
|
|
5625
5805
|
return null;
|
|
5626
5806
|
}
|
|
5627
5807
|
function isSecretOperand(node) {
|
|
5628
|
-
if (node.type ===
|
|
5808
|
+
if (node.type === AST_NODE_TYPES28.TemplateLiteral) {
|
|
5629
5809
|
return node.expressions.some((expression) => isSecretOperand(expression));
|
|
5630
5810
|
}
|
|
5631
5811
|
const name = operandName(node);
|
|
5632
5812
|
return name !== null && isAuthSecretName(name);
|
|
5633
5813
|
}
|
|
5634
5814
|
function secretNameOf(node) {
|
|
5635
|
-
if (node.type ===
|
|
5815
|
+
if (node.type === AST_NODE_TYPES28.TemplateLiteral) {
|
|
5636
5816
|
for (const expression of node.expressions) {
|
|
5637
5817
|
const nested = secretNameOf(expression);
|
|
5638
5818
|
if (nested !== null) {
|
|
@@ -5685,7 +5865,7 @@ var prefer_constant_time_secret_compare_default = createRule({
|
|
|
5685
5865
|
|
|
5686
5866
|
// src/rules/prefer-discriminated-union.ts
|
|
5687
5867
|
import "@typescript-eslint/utils";
|
|
5688
|
-
import { AST_NODE_TYPES as
|
|
5868
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES29 } from "@typescript-eslint/utils";
|
|
5689
5869
|
var STATUS_MEMBER_NAMES = /* @__PURE__ */ new Set([
|
|
5690
5870
|
"success",
|
|
5691
5871
|
"ok",
|
|
@@ -5695,27 +5875,27 @@ var STATUS_MEMBER_NAMES = /* @__PURE__ */ new Set([
|
|
|
5695
5875
|
]);
|
|
5696
5876
|
var MIN_OPTIONAL_MEMBERS = 2;
|
|
5697
5877
|
function getMemberName(member) {
|
|
5698
|
-
if (member.type !==
|
|
5878
|
+
if (member.type !== AST_NODE_TYPES29.TSPropertySignature) {
|
|
5699
5879
|
return null;
|
|
5700
5880
|
}
|
|
5701
5881
|
const { key } = member;
|
|
5702
|
-
if (key.type ===
|
|
5882
|
+
if (key.type === AST_NODE_TYPES29.Identifier) {
|
|
5703
5883
|
return key.name;
|
|
5704
5884
|
}
|
|
5705
|
-
if (key.type ===
|
|
5885
|
+
if (key.type === AST_NODE_TYPES29.Literal && typeof key.value === "string") {
|
|
5706
5886
|
return key.value;
|
|
5707
5887
|
}
|
|
5708
5888
|
return null;
|
|
5709
5889
|
}
|
|
5710
5890
|
function isBooleanTyped(member) {
|
|
5711
|
-
return member.typeAnnotation?.typeAnnotation.type ===
|
|
5891
|
+
return member.typeAnnotation?.typeAnnotation.type === AST_NODE_TYPES29.TSBooleanKeyword;
|
|
5712
5892
|
}
|
|
5713
5893
|
function looksLikeMutuallyExclusiveState(typeLiteral) {
|
|
5714
5894
|
let hasStatusBoolean = false;
|
|
5715
5895
|
let optionalCount = 0;
|
|
5716
5896
|
let optionalPayloadCount = 0;
|
|
5717
5897
|
for (const member of typeLiteral.members) {
|
|
5718
|
-
if (member.type !==
|
|
5898
|
+
if (member.type !== AST_NODE_TYPES29.TSPropertySignature) {
|
|
5719
5899
|
continue;
|
|
5720
5900
|
}
|
|
5721
5901
|
if (member.optional) {
|
|
@@ -5757,7 +5937,7 @@ var prefer_discriminated_union_default = createRule({
|
|
|
5757
5937
|
TSInterfaceDeclaration(node) {
|
|
5758
5938
|
const synthetic = {
|
|
5759
5939
|
...node.body,
|
|
5760
|
-
type:
|
|
5940
|
+
type: AST_NODE_TYPES29.TSTypeLiteral,
|
|
5761
5941
|
members: node.body.body
|
|
5762
5942
|
};
|
|
5763
5943
|
checkTypeLiteral(synthetic, node);
|
|
@@ -5770,7 +5950,7 @@ var prefer_discriminated_union_default = createRule({
|
|
|
5770
5950
|
});
|
|
5771
5951
|
|
|
5772
5952
|
// src/rules/prefer-module-level-constant.ts
|
|
5773
|
-
import { AST_NODE_TYPES as
|
|
5953
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES30 } from "@typescript-eslint/utils";
|
|
5774
5954
|
var DEFAULT_MIN_ELEMENTS = 3;
|
|
5775
5955
|
var MAX_LITERAL_DEPTH = 4;
|
|
5776
5956
|
var IGNORE_PATTERNS2 = [
|
|
@@ -5799,9 +5979,9 @@ var MUTATING_METHODS = /* @__PURE__ */ new Set([
|
|
|
5799
5979
|
"assign"
|
|
5800
5980
|
]);
|
|
5801
5981
|
var FUNCTION_TYPES5 = /* @__PURE__ */ new Set([
|
|
5802
|
-
|
|
5803
|
-
|
|
5804
|
-
|
|
5982
|
+
AST_NODE_TYPES30.FunctionDeclaration,
|
|
5983
|
+
AST_NODE_TYPES30.FunctionExpression,
|
|
5984
|
+
AST_NODE_TYPES30.ArrowFunctionExpression
|
|
5805
5985
|
]);
|
|
5806
5986
|
var COLLECTION_CONSTRUCTORS = /* @__PURE__ */ new Set(["Set", "Map"]);
|
|
5807
5987
|
function isIgnoredFile2(filename, sourceText) {
|
|
@@ -5814,14 +5994,14 @@ function isLocalFixtureFile(filename) {
|
|
|
5814
5994
|
return isTestFile(filename) || isStoryFile(filename);
|
|
5815
5995
|
}
|
|
5816
5996
|
function unwrap3(node) {
|
|
5817
|
-
if (node.type ===
|
|
5997
|
+
if (node.type === AST_NODE_TYPES30.TSAsExpression || node.type === AST_NODE_TYPES30.TSSatisfiesExpression || node.type === AST_NODE_TYPES30.TSNonNullExpression) {
|
|
5818
5998
|
return unwrap3(node.expression);
|
|
5819
5999
|
}
|
|
5820
6000
|
return node;
|
|
5821
6001
|
}
|
|
5822
6002
|
var HAS_STATEFUL_FLAG_RE = /[gy]/;
|
|
5823
6003
|
function isRegexLiteral(node) {
|
|
5824
|
-
return node.type ===
|
|
6004
|
+
return node.type === AST_NODE_TYPES30.Literal && "regex" in node && node.regex !== void 0;
|
|
5825
6005
|
}
|
|
5826
6006
|
function isLiteralOnly(node, depth) {
|
|
5827
6007
|
if (depth > MAX_LITERAL_DEPTH) {
|
|
@@ -5829,29 +6009,29 @@ function isLiteralOnly(node, depth) {
|
|
|
5829
6009
|
}
|
|
5830
6010
|
const inner = unwrap3(node);
|
|
5831
6011
|
switch (inner.type) {
|
|
5832
|
-
case
|
|
6012
|
+
case AST_NODE_TYPES30.Literal: {
|
|
5833
6013
|
return !(isRegexLiteral(inner) && HAS_STATEFUL_FLAG_RE.test(inner.regex.flags));
|
|
5834
6014
|
}
|
|
5835
|
-
case
|
|
6015
|
+
case AST_NODE_TYPES30.TemplateLiteral: {
|
|
5836
6016
|
return inner.expressions.length === 0;
|
|
5837
6017
|
}
|
|
5838
|
-
case
|
|
5839
|
-
return (inner.operator === "-" || inner.operator === "+") && inner.argument.type ===
|
|
6018
|
+
case AST_NODE_TYPES30.UnaryExpression: {
|
|
6019
|
+
return (inner.operator === "-" || inner.operator === "+") && inner.argument.type === AST_NODE_TYPES30.Literal && typeof inner.argument.value === "number";
|
|
5840
6020
|
}
|
|
5841
|
-
case
|
|
6021
|
+
case AST_NODE_TYPES30.ArrayExpression: {
|
|
5842
6022
|
return inner.elements.every(
|
|
5843
|
-
(el) => el !== null && el.type !==
|
|
6023
|
+
(el) => el !== null && el.type !== AST_NODE_TYPES30.SpreadElement && isLiteralOnly(el, depth + 1)
|
|
5844
6024
|
);
|
|
5845
6025
|
}
|
|
5846
|
-
case
|
|
6026
|
+
case AST_NODE_TYPES30.ObjectExpression: {
|
|
5847
6027
|
return inner.properties.every((prop) => {
|
|
5848
|
-
if (prop.type !==
|
|
6028
|
+
if (prop.type !== AST_NODE_TYPES30.Property) {
|
|
5849
6029
|
return false;
|
|
5850
6030
|
}
|
|
5851
6031
|
if (prop.shorthand || prop.method || prop.kind !== "init") {
|
|
5852
6032
|
return false;
|
|
5853
6033
|
}
|
|
5854
|
-
if (prop.computed && prop.key.type !==
|
|
6034
|
+
if (prop.computed && prop.key.type !== AST_NODE_TYPES30.Literal) {
|
|
5855
6035
|
return false;
|
|
5856
6036
|
}
|
|
5857
6037
|
return isLiteralOnly(prop.value, depth + 1);
|
|
@@ -5864,7 +6044,7 @@ function isLiteralOnly(node, depth) {
|
|
|
5864
6044
|
}
|
|
5865
6045
|
function unwrapObjectFreeze(node) {
|
|
5866
6046
|
const inner = unwrap3(node);
|
|
5867
|
-
if (inner.type ===
|
|
6047
|
+
if (inner.type === AST_NODE_TYPES30.CallExpression && inner.callee.type === AST_NODE_TYPES30.MemberExpression && !inner.callee.computed && inner.callee.object.type === AST_NODE_TYPES30.Identifier && inner.callee.object.name === "Object" && inner.callee.property.type === AST_NODE_TYPES30.Identifier && inner.callee.property.name === "freeze" && inner.arguments.length === 1 && inner.arguments[0] !== void 0 && inner.arguments[0].type !== AST_NODE_TYPES30.SpreadElement) {
|
|
5868
6048
|
return unwrap3(inner.arguments[0]);
|
|
5869
6049
|
}
|
|
5870
6050
|
return inner;
|
|
@@ -5880,19 +6060,19 @@ function classify(init, checkRegex) {
|
|
|
5880
6060
|
}
|
|
5881
6061
|
return { kind: "regex", size: 1 };
|
|
5882
6062
|
}
|
|
5883
|
-
if (node.type ===
|
|
6063
|
+
if (node.type === AST_NODE_TYPES30.ArrayExpression) {
|
|
5884
6064
|
return isLiteralOnly(node, 0) ? { kind: "array", size: node.elements.length } : null;
|
|
5885
6065
|
}
|
|
5886
|
-
if (node.type ===
|
|
6066
|
+
if (node.type === AST_NODE_TYPES30.ObjectExpression) {
|
|
5887
6067
|
return isLiteralOnly(node, 0) ? { kind: "object", size: node.properties.length } : null;
|
|
5888
6068
|
}
|
|
5889
|
-
if (node.type ===
|
|
6069
|
+
if (node.type === AST_NODE_TYPES30.NewExpression && node.callee.type === AST_NODE_TYPES30.Identifier && COLLECTION_CONSTRUCTORS.has(node.callee.name)) {
|
|
5890
6070
|
const arg = node.arguments[0];
|
|
5891
|
-
if (node.arguments.length !== 1 || arg === void 0 || arg.type ===
|
|
6071
|
+
if (node.arguments.length !== 1 || arg === void 0 || arg.type === AST_NODE_TYPES30.SpreadElement) {
|
|
5892
6072
|
return null;
|
|
5893
6073
|
}
|
|
5894
6074
|
const entries = unwrap3(arg);
|
|
5895
|
-
if (entries.type !==
|
|
6075
|
+
if (entries.type !== AST_NODE_TYPES30.ArrayExpression) {
|
|
5896
6076
|
return null;
|
|
5897
6077
|
}
|
|
5898
6078
|
return isLiteralOnly(entries, 0) ? { kind: node.callee.name === "Set" ? "Set" : "Map", size: entries.elements.length } : null;
|
|
@@ -5921,10 +6101,10 @@ var NON_RETAINING_BUILTINS = /* @__PURE__ */ new Map(
|
|
|
5921
6101
|
);
|
|
5922
6102
|
function isNonRetainingBuiltinCall(node, argument) {
|
|
5923
6103
|
const callee = node.callee;
|
|
5924
|
-
if (callee.type ===
|
|
6104
|
+
if (callee.type === AST_NODE_TYPES30.Identifier && callee.name === "structuredClone") {
|
|
5925
6105
|
return true;
|
|
5926
6106
|
}
|
|
5927
|
-
if (callee.type !==
|
|
6107
|
+
if (callee.type !== AST_NODE_TYPES30.MemberExpression || callee.computed || callee.object.type !== AST_NODE_TYPES30.Identifier || callee.property.type !== AST_NODE_TYPES30.Identifier) {
|
|
5928
6108
|
return false;
|
|
5929
6109
|
}
|
|
5930
6110
|
const members = NON_RETAINING_BUILTINS.get(callee.object.name);
|
|
@@ -5938,38 +6118,38 @@ function isNonRetainingBuiltinCall(node, argument) {
|
|
|
5938
6118
|
}
|
|
5939
6119
|
function isSafeRead(identifier) {
|
|
5940
6120
|
const parent = identifier.parent;
|
|
5941
|
-
if (parent.type ===
|
|
6121
|
+
if (parent.type === AST_NODE_TYPES30.MemberExpression) {
|
|
5942
6122
|
if (parent.object !== identifier) {
|
|
5943
6123
|
return true;
|
|
5944
6124
|
}
|
|
5945
6125
|
const grandparent = parent.parent;
|
|
5946
|
-
if (grandparent.type ===
|
|
6126
|
+
if (grandparent.type === AST_NODE_TYPES30.AssignmentExpression && grandparent.left === parent) {
|
|
5947
6127
|
return false;
|
|
5948
6128
|
}
|
|
5949
|
-
if (grandparent.type ===
|
|
6129
|
+
if (grandparent.type === AST_NODE_TYPES30.UpdateExpression) {
|
|
5950
6130
|
return false;
|
|
5951
6131
|
}
|
|
5952
|
-
if (grandparent.type ===
|
|
6132
|
+
if (grandparent.type === AST_NODE_TYPES30.UnaryExpression && grandparent.operator === "delete") {
|
|
5953
6133
|
return false;
|
|
5954
6134
|
}
|
|
5955
|
-
if (!parent.computed && parent.property.type ===
|
|
6135
|
+
if (!parent.computed && parent.property.type === AST_NODE_TYPES30.Identifier && MUTATING_METHODS.has(parent.property.name) && grandparent.type === AST_NODE_TYPES30.CallExpression && grandparent.callee === parent) {
|
|
5956
6136
|
return false;
|
|
5957
6137
|
}
|
|
5958
6138
|
return true;
|
|
5959
6139
|
}
|
|
5960
|
-
if (parent.type ===
|
|
6140
|
+
if (parent.type === AST_NODE_TYPES30.ForOfStatement && parent.right === identifier) {
|
|
5961
6141
|
return true;
|
|
5962
6142
|
}
|
|
5963
|
-
if (parent.type ===
|
|
6143
|
+
if (parent.type === AST_NODE_TYPES30.SpreadElement) {
|
|
5964
6144
|
return true;
|
|
5965
6145
|
}
|
|
5966
|
-
if (parent.type ===
|
|
6146
|
+
if (parent.type === AST_NODE_TYPES30.BinaryExpression) {
|
|
5967
6147
|
return true;
|
|
5968
6148
|
}
|
|
5969
|
-
if (parent.type ===
|
|
6149
|
+
if (parent.type === AST_NODE_TYPES30.CallExpression && parent.arguments.includes(identifier) && isNonRetainingBuiltinCall(parent, identifier)) {
|
|
5970
6150
|
return true;
|
|
5971
6151
|
}
|
|
5972
|
-
if (parent.type ===
|
|
6152
|
+
if (parent.type === AST_NODE_TYPES30.UnaryExpression && parent.operator !== "delete") {
|
|
5973
6153
|
return true;
|
|
5974
6154
|
}
|
|
5975
6155
|
return false;
|
|
@@ -6024,7 +6204,7 @@ var prefer_module_level_constant_default = createRule({
|
|
|
6024
6204
|
if (reference.isWrite()) {
|
|
6025
6205
|
return false;
|
|
6026
6206
|
}
|
|
6027
|
-
if (reference.identifier.type !==
|
|
6207
|
+
if (reference.identifier.type !== AST_NODE_TYPES30.Identifier) {
|
|
6028
6208
|
return false;
|
|
6029
6209
|
}
|
|
6030
6210
|
if (!isSafeRead(reference.identifier)) {
|
|
@@ -6036,10 +6216,10 @@ var prefer_module_level_constant_default = createRule({
|
|
|
6036
6216
|
return {
|
|
6037
6217
|
VariableDeclarator(node) {
|
|
6038
6218
|
const declaration = node.parent;
|
|
6039
|
-
if (declaration.type !==
|
|
6219
|
+
if (declaration.type !== AST_NODE_TYPES30.VariableDeclaration || declaration.kind !== "const" || declaration.declare === true) {
|
|
6040
6220
|
return;
|
|
6041
6221
|
}
|
|
6042
|
-
if (node.id.type !==
|
|
6222
|
+
if (node.id.type !== AST_NODE_TYPES30.Identifier || node.init === null) {
|
|
6043
6223
|
return;
|
|
6044
6224
|
}
|
|
6045
6225
|
if (enclosingFunction2(node) === null) {
|
|
@@ -6066,7 +6246,7 @@ var prefer_module_level_constant_default = createRule({
|
|
|
6066
6246
|
});
|
|
6067
6247
|
|
|
6068
6248
|
// src/rules/prefer-module-level-schema.ts
|
|
6069
|
-
import { AST_NODE_TYPES as
|
|
6249
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES31 } from "@typescript-eslint/utils";
|
|
6070
6250
|
|
|
6071
6251
|
// src/rules/_zod.ts
|
|
6072
6252
|
var ZOD_PREFIX_RE = /^Z[A-Z]/;
|
|
@@ -6087,7 +6267,7 @@ var DEFAULT_FACTORIES = [
|
|
|
6087
6267
|
"tuple",
|
|
6088
6268
|
"union"
|
|
6089
6269
|
];
|
|
6090
|
-
var DEFAULT_MIN_PROPERTIES =
|
|
6270
|
+
var DEFAULT_MIN_PROPERTIES = 2;
|
|
6091
6271
|
var MEMO_CALLEES = /* @__PURE__ */ new Set([
|
|
6092
6272
|
"lazy",
|
|
6093
6273
|
"memo",
|
|
@@ -6103,10 +6283,38 @@ var TERMINAL_METHODS = /* @__PURE__ */ new Set([
|
|
|
6103
6283
|
"safeParseAsync",
|
|
6104
6284
|
"spa"
|
|
6105
6285
|
]);
|
|
6286
|
+
var ZOD_COMBINATOR_METHODS = /* @__PURE__ */ new Set([
|
|
6287
|
+
"and",
|
|
6288
|
+
"array",
|
|
6289
|
+
"catch",
|
|
6290
|
+
"catchall",
|
|
6291
|
+
"default",
|
|
6292
|
+
"extend",
|
|
6293
|
+
"merge",
|
|
6294
|
+
"or",
|
|
6295
|
+
"pipe",
|
|
6296
|
+
"refine",
|
|
6297
|
+
"superRefine",
|
|
6298
|
+
"transform"
|
|
6299
|
+
]);
|
|
6300
|
+
var I18N_CALLEE_NAMES = /* @__PURE__ */ new Set([
|
|
6301
|
+
"$t",
|
|
6302
|
+
"defineMessage",
|
|
6303
|
+
"gettext",
|
|
6304
|
+
"msg",
|
|
6305
|
+
"ngettext",
|
|
6306
|
+
"t",
|
|
6307
|
+
"translate"
|
|
6308
|
+
]);
|
|
6309
|
+
var I18N_RECEIVER_NAMES = /* @__PURE__ */ new Set([
|
|
6310
|
+
"$i18n",
|
|
6311
|
+
"i18n",
|
|
6312
|
+
"intl"
|
|
6313
|
+
]);
|
|
6106
6314
|
var FUNCTION_TYPES6 = /* @__PURE__ */ new Set([
|
|
6107
|
-
|
|
6108
|
-
|
|
6109
|
-
|
|
6315
|
+
AST_NODE_TYPES31.ArrowFunctionExpression,
|
|
6316
|
+
AST_NODE_TYPES31.FunctionDeclaration,
|
|
6317
|
+
AST_NODE_TYPES31.FunctionExpression
|
|
6110
6318
|
]);
|
|
6111
6319
|
function schemaExpression(node) {
|
|
6112
6320
|
let current = node;
|
|
@@ -6115,10 +6323,10 @@ function schemaExpression(node) {
|
|
|
6115
6323
|
if (parent === void 0) {
|
|
6116
6324
|
return current;
|
|
6117
6325
|
}
|
|
6118
|
-
if (parent.type ===
|
|
6326
|
+
if (parent.type === AST_NODE_TYPES31.MemberExpression && parent.object === current && !parent.computed && parent.property.type === AST_NODE_TYPES31.Identifier && TERMINAL_METHODS.has(parent.property.name)) {
|
|
6119
6327
|
return current;
|
|
6120
6328
|
}
|
|
6121
|
-
if (parent.type ===
|
|
6329
|
+
if (parent.type === AST_NODE_TYPES31.MemberExpression && parent.object === current || parent.type === AST_NODE_TYPES31.CallExpression && parent.callee === current || parent.type === AST_NODE_TYPES31.TSAsExpression && parent.expression === current || parent.type === AST_NODE_TYPES31.TSNonNullExpression && parent.expression === current) {
|
|
6122
6330
|
current = parent;
|
|
6123
6331
|
continue;
|
|
6124
6332
|
}
|
|
@@ -6136,7 +6344,7 @@ function outermostEnclosingFunction(node) {
|
|
|
6136
6344
|
}
|
|
6137
6345
|
return outermost;
|
|
6138
6346
|
}
|
|
6139
|
-
function
|
|
6347
|
+
function subtreeSome(root, predicate) {
|
|
6140
6348
|
let found = false;
|
|
6141
6349
|
const visit = (value) => {
|
|
6142
6350
|
if (found || value === null || typeof value !== "object") {
|
|
@@ -6152,7 +6360,7 @@ function readsReceiver(node) {
|
|
|
6152
6360
|
if (typeof candidate.type !== "string") {
|
|
6153
6361
|
return;
|
|
6154
6362
|
}
|
|
6155
|
-
if (candidate
|
|
6363
|
+
if (predicate(candidate)) {
|
|
6156
6364
|
found = true;
|
|
6157
6365
|
return;
|
|
6158
6366
|
}
|
|
@@ -6163,9 +6371,30 @@ function readsReceiver(node) {
|
|
|
6163
6371
|
visit(candidate[key]);
|
|
6164
6372
|
}
|
|
6165
6373
|
};
|
|
6166
|
-
visit(
|
|
6374
|
+
visit(root);
|
|
6167
6375
|
return found;
|
|
6168
6376
|
}
|
|
6377
|
+
function readsReceiver(node) {
|
|
6378
|
+
return subtreeSome(
|
|
6379
|
+
node,
|
|
6380
|
+
(inner) => inner.type === AST_NODE_TYPES31.ThisExpression || inner.type === AST_NODE_TYPES31.Super || inner.type === AST_NODE_TYPES31.Identifier && inner.name === "arguments"
|
|
6381
|
+
);
|
|
6382
|
+
}
|
|
6383
|
+
function buildsLocalizedText(node) {
|
|
6384
|
+
return subtreeSome(node, (inner) => {
|
|
6385
|
+
if (inner.type === AST_NODE_TYPES31.TaggedTemplateExpression) {
|
|
6386
|
+
return true;
|
|
6387
|
+
}
|
|
6388
|
+
if (inner.type !== AST_NODE_TYPES31.CallExpression) {
|
|
6389
|
+
return false;
|
|
6390
|
+
}
|
|
6391
|
+
const { callee } = inner;
|
|
6392
|
+
if (callee.type === AST_NODE_TYPES31.Identifier) {
|
|
6393
|
+
return I18N_CALLEE_NAMES.has(callee.name);
|
|
6394
|
+
}
|
|
6395
|
+
return callee.type === AST_NODE_TYPES31.MemberExpression && !callee.computed && callee.object.type === AST_NODE_TYPES31.Identifier && I18N_RECEIVER_NAMES.has(callee.object.name);
|
|
6396
|
+
});
|
|
6397
|
+
}
|
|
6169
6398
|
function collectReferences(scope, out) {
|
|
6170
6399
|
out.push(...scope.references);
|
|
6171
6400
|
for (const child of scope.childScopes) {
|
|
@@ -6220,21 +6449,46 @@ var prefer_module_level_schema_default = createRule({
|
|
|
6220
6449
|
}
|
|
6221
6450
|
const zodNamespaces = /* @__PURE__ */ new Set();
|
|
6222
6451
|
function isZodCall(node) {
|
|
6223
|
-
return node.type ===
|
|
6452
|
+
return node.type === AST_NODE_TYPES31.CallExpression && node.callee.type === AST_NODE_TYPES31.MemberExpression && !node.callee.computed && node.callee.object.type === AST_NODE_TYPES31.Identifier && zodNamespaces.has(node.callee.object.name);
|
|
6224
6453
|
}
|
|
6225
6454
|
function isCovered(node) {
|
|
6226
6455
|
let current = node.parent ?? void 0;
|
|
6227
6456
|
while (current !== void 0) {
|
|
6228
|
-
if (current !== node && isZodCall(current) && current.callee.type ===
|
|
6457
|
+
if (current !== node && isZodCall(current) && current.callee.type === AST_NODE_TYPES31.MemberExpression && current.callee.property.type === AST_NODE_TYPES31.Identifier && factories.has(current.callee.property.name)) {
|
|
6229
6458
|
return true;
|
|
6230
6459
|
}
|
|
6231
|
-
if (current.type ===
|
|
6460
|
+
if (current.type === AST_NODE_TYPES31.CallExpression && (current.callee.type === AST_NODE_TYPES31.Identifier && MEMO_CALLEES.has(current.callee.name) || current.callee.type === AST_NODE_TYPES31.MemberExpression && !current.callee.computed && current.callee.property.type === AST_NODE_TYPES31.Identifier && MEMO_CALLEES.has(current.callee.property.name))) {
|
|
6232
6461
|
return true;
|
|
6233
6462
|
}
|
|
6234
6463
|
current = current.parent ?? void 0;
|
|
6235
6464
|
}
|
|
6236
6465
|
return false;
|
|
6237
6466
|
}
|
|
6467
|
+
function outermostSchemaExpression(expression) {
|
|
6468
|
+
let confirmed = expression;
|
|
6469
|
+
let current = expression;
|
|
6470
|
+
for (; ; ) {
|
|
6471
|
+
const parent = current.parent ?? void 0;
|
|
6472
|
+
if (parent === void 0) {
|
|
6473
|
+
return confirmed;
|
|
6474
|
+
}
|
|
6475
|
+
if (parent.type === AST_NODE_TYPES31.Property && parent.value === current || parent.type === AST_NODE_TYPES31.ObjectExpression || parent.type === AST_NODE_TYPES31.ArrayExpression) {
|
|
6476
|
+
current = parent;
|
|
6477
|
+
continue;
|
|
6478
|
+
}
|
|
6479
|
+
if (parent.type === AST_NODE_TYPES31.CallExpression && parent.arguments.includes(current) && isSchemaComposition(parent)) {
|
|
6480
|
+
current = schemaExpression(parent);
|
|
6481
|
+
confirmed = current;
|
|
6482
|
+
continue;
|
|
6483
|
+
}
|
|
6484
|
+
return confirmed;
|
|
6485
|
+
}
|
|
6486
|
+
}
|
|
6487
|
+
function isSchemaComposition(node) {
|
|
6488
|
+
const { callee } = node;
|
|
6489
|
+
const isCombinator = callee.type === AST_NODE_TYPES31.MemberExpression && !callee.computed && callee.property.type === AST_NODE_TYPES31.Identifier && ZOD_COMBINATOR_METHODS.has(callee.property.name);
|
|
6490
|
+
return isCombinator || isZodCall(node);
|
|
6491
|
+
}
|
|
6238
6492
|
function closesOverNothing(node, enclosing) {
|
|
6239
6493
|
const references = [];
|
|
6240
6494
|
collectReferences(sourceCode.getScope(node), references);
|
|
@@ -6254,6 +6508,9 @@ var prefer_module_level_schema_default = createRule({
|
|
|
6254
6508
|
continue;
|
|
6255
6509
|
}
|
|
6256
6510
|
const [defStart, defEnd] = definition.node.range;
|
|
6511
|
+
if (defStart >= schemaStart && defEnd <= schemaEnd) {
|
|
6512
|
+
continue;
|
|
6513
|
+
}
|
|
6257
6514
|
if (defStart >= functionStart && defEnd <= functionEnd) {
|
|
6258
6515
|
return false;
|
|
6259
6516
|
}
|
|
@@ -6263,13 +6520,13 @@ var prefer_module_level_schema_default = createRule({
|
|
|
6263
6520
|
}
|
|
6264
6521
|
function ownerName(enclosing) {
|
|
6265
6522
|
const parent = enclosing.parent ?? void 0;
|
|
6266
|
-
if (enclosing.type ===
|
|
6523
|
+
if (enclosing.type === AST_NODE_TYPES31.FunctionDeclaration && enclosing.id !== null) {
|
|
6267
6524
|
return enclosing.id.name;
|
|
6268
6525
|
}
|
|
6269
|
-
if (parent !== void 0 && parent.type ===
|
|
6526
|
+
if (parent !== void 0 && parent.type === AST_NODE_TYPES31.VariableDeclarator && parent.id.type === AST_NODE_TYPES31.Identifier) {
|
|
6270
6527
|
return parent.id.name;
|
|
6271
6528
|
}
|
|
6272
|
-
if (parent !== void 0 && (parent.type ===
|
|
6529
|
+
if (parent !== void 0 && (parent.type === AST_NODE_TYPES31.MethodDefinition || parent.type === AST_NODE_TYPES31.Property) && parent.key.type === AST_NODE_TYPES31.Identifier) {
|
|
6273
6530
|
return parent.key.name;
|
|
6274
6531
|
}
|
|
6275
6532
|
return "this function";
|
|
@@ -6280,7 +6537,7 @@ var prefer_module_level_schema_default = createRule({
|
|
|
6280
6537
|
return;
|
|
6281
6538
|
}
|
|
6282
6539
|
for (const specifier of node.specifiers) {
|
|
6283
|
-
if (specifier.type ===
|
|
6540
|
+
if (specifier.type === AST_NODE_TYPES31.ImportNamespaceSpecifier || specifier.type === AST_NODE_TYPES31.ImportDefaultSpecifier || specifier.type === AST_NODE_TYPES31.ImportSpecifier && specifier.imported.type === AST_NODE_TYPES31.Identifier && specifier.imported.name === "z") {
|
|
6284
6541
|
zodNamespaces.add(specifier.local.name);
|
|
6285
6542
|
}
|
|
6286
6543
|
}
|
|
@@ -6290,7 +6547,7 @@ var prefer_module_level_schema_default = createRule({
|
|
|
6290
6547
|
return;
|
|
6291
6548
|
}
|
|
6292
6549
|
const callee = node.callee;
|
|
6293
|
-
if (callee.property.type !==
|
|
6550
|
+
if (callee.property.type !== AST_NODE_TYPES31.Identifier) {
|
|
6294
6551
|
return;
|
|
6295
6552
|
}
|
|
6296
6553
|
const factory = callee.property.name;
|
|
@@ -6305,13 +6562,20 @@ var prefer_module_level_schema_default = createRule({
|
|
|
6305
6562
|
return;
|
|
6306
6563
|
}
|
|
6307
6564
|
const shape = node.arguments[0];
|
|
6308
|
-
if (shape !== void 0 && shape.type ===
|
|
6565
|
+
if (shape !== void 0 && shape.type === AST_NODE_TYPES31.ObjectExpression && shape.properties.length < minProperties) {
|
|
6309
6566
|
return;
|
|
6310
6567
|
}
|
|
6311
6568
|
const expression = schemaExpression(node);
|
|
6312
6569
|
if (readsReceiver(expression)) {
|
|
6313
6570
|
return;
|
|
6314
6571
|
}
|
|
6572
|
+
if (buildsLocalizedText(expression)) {
|
|
6573
|
+
return;
|
|
6574
|
+
}
|
|
6575
|
+
const outermost = outermostSchemaExpression(expression);
|
|
6576
|
+
if (outermost !== expression && (readsReceiver(outermost) || buildsLocalizedText(outermost) || !closesOverNothing(outermost, enclosing))) {
|
|
6577
|
+
return;
|
|
6578
|
+
}
|
|
6315
6579
|
if (!closesOverNothing(expression, enclosing)) {
|
|
6316
6580
|
return;
|
|
6317
6581
|
}
|
|
@@ -6326,20 +6590,20 @@ var prefer_module_level_schema_default = createRule({
|
|
|
6326
6590
|
});
|
|
6327
6591
|
|
|
6328
6592
|
// src/rules/prefer-non-nullable-collection.ts
|
|
6329
|
-
import { AST_NODE_TYPES as
|
|
6593
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES32 } from "@typescript-eslint/utils";
|
|
6330
6594
|
var ARRAY_TYPE_NAMES = /* @__PURE__ */ new Set(["Array", "ReadonlyArray"]);
|
|
6331
6595
|
function propertyName(node) {
|
|
6332
6596
|
const key = node.key;
|
|
6333
|
-
if (key.type ===
|
|
6334
|
-
if (key.type ===
|
|
6597
|
+
if (key.type === AST_NODE_TYPES32.Identifier) return key.name;
|
|
6598
|
+
if (key.type === AST_NODE_TYPES32.Literal) return String(key.value);
|
|
6335
6599
|
return "collection";
|
|
6336
6600
|
}
|
|
6337
6601
|
function isArrayType(node) {
|
|
6338
|
-
if (node.type ===
|
|
6339
|
-
return node.type ===
|
|
6602
|
+
if (node.type === AST_NODE_TYPES32.TSArrayType) return true;
|
|
6603
|
+
return node.type === AST_NODE_TYPES32.TSTypeReference && node.typeName.type === AST_NODE_TYPES32.Identifier && ARRAY_TYPE_NAMES.has(node.typeName.name);
|
|
6340
6604
|
}
|
|
6341
6605
|
function isNullishType(node) {
|
|
6342
|
-
return node.type ===
|
|
6606
|
+
return node.type === AST_NODE_TYPES32.TSNullKeyword || node.type === AST_NODE_TYPES32.TSUndefinedKeyword;
|
|
6343
6607
|
}
|
|
6344
6608
|
function isNullableArrayOnly(node) {
|
|
6345
6609
|
const values = node.types.filter((member) => !isNullishType(member));
|
|
@@ -6366,7 +6630,7 @@ var prefer_non_nullable_collection_default = createRule({
|
|
|
6366
6630
|
function checkOptionalProperty(node) {
|
|
6367
6631
|
const annotation = node.typeAnnotation?.typeAnnotation;
|
|
6368
6632
|
if (annotation === void 0) return;
|
|
6369
|
-
if (annotation.type !==
|
|
6633
|
+
if (annotation.type !== AST_NODE_TYPES32.TSUnionType || !isNullableArrayOnly(annotation)) {
|
|
6370
6634
|
return;
|
|
6371
6635
|
}
|
|
6372
6636
|
context.report({
|
|
@@ -6379,7 +6643,7 @@ var prefer_non_nullable_collection_default = createRule({
|
|
|
6379
6643
|
TSPropertySignature: checkOptionalProperty,
|
|
6380
6644
|
PropertyDefinition: checkOptionalProperty,
|
|
6381
6645
|
TSTypeAliasDeclaration(node) {
|
|
6382
|
-
if (node.typeAnnotation.type !==
|
|
6646
|
+
if (node.typeAnnotation.type !== AST_NODE_TYPES32.TSUnionType) return;
|
|
6383
6647
|
if (!isNullableArrayOnly(node.typeAnnotation)) return;
|
|
6384
6648
|
context.report({
|
|
6385
6649
|
node,
|
|
@@ -6392,13 +6656,13 @@ var prefer_non_nullable_collection_default = createRule({
|
|
|
6392
6656
|
});
|
|
6393
6657
|
|
|
6394
6658
|
// src/rules/prefer-schema-for-api-payload.ts
|
|
6395
|
-
import { AST_NODE_TYPES as
|
|
6659
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES33 } from "@typescript-eslint/utils";
|
|
6396
6660
|
var unwrap4 = (node) => {
|
|
6397
6661
|
let current = node;
|
|
6398
6662
|
while (current !== null && current !== void 0) {
|
|
6399
|
-
if (current.type ===
|
|
6663
|
+
if (current.type === AST_NODE_TYPES33.TSAsExpression || current.type === AST_NODE_TYPES33.TSTypeAssertion || current.type === AST_NODE_TYPES33.TSNonNullExpression || current.type === AST_NODE_TYPES33.TSSatisfiesExpression) {
|
|
6400
6664
|
current = current.expression;
|
|
6401
|
-
} else if (current.type ===
|
|
6665
|
+
} else if (current.type === AST_NODE_TYPES33.ChainExpression) {
|
|
6402
6666
|
current = current.expression;
|
|
6403
6667
|
} else {
|
|
6404
6668
|
break;
|
|
@@ -6413,23 +6677,23 @@ var PROMISE_CHAIN_METHODS = /* @__PURE__ */ new Set([
|
|
|
6413
6677
|
]);
|
|
6414
6678
|
var isSchemaParseReference = (node) => {
|
|
6415
6679
|
const inner = unwrap4(node);
|
|
6416
|
-
return inner !== null && inner.type ===
|
|
6680
|
+
return inner !== null && inner.type === AST_NODE_TYPES33.MemberExpression && !inner.computed && inner.property.type === AST_NODE_TYPES33.Identifier && (inner.property.name === "parse" || inner.property.name === "safeParse");
|
|
6417
6681
|
};
|
|
6418
6682
|
var isRawPayloadSource = (node) => {
|
|
6419
6683
|
let current = unwrap4(node);
|
|
6420
6684
|
if (current === null) return false;
|
|
6421
|
-
if (current.type ===
|
|
6685
|
+
if (current.type === AST_NODE_TYPES33.AwaitExpression) {
|
|
6422
6686
|
current = unwrap4(current.argument);
|
|
6423
6687
|
}
|
|
6424
|
-
if (current === null || current.type !==
|
|
6688
|
+
if (current === null || current.type !== AST_NODE_TYPES33.CallExpression) {
|
|
6425
6689
|
return false;
|
|
6426
6690
|
}
|
|
6427
6691
|
const callee = unwrap4(current.callee);
|
|
6428
|
-
if (callee === null || callee.type !==
|
|
6692
|
+
if (callee === null || callee.type !== AST_NODE_TYPES33.MemberExpression) {
|
|
6429
6693
|
return false;
|
|
6430
6694
|
}
|
|
6431
6695
|
const property = unwrap4(callee.property);
|
|
6432
|
-
if (property === null || property.type !==
|
|
6696
|
+
if (property === null || property.type !== AST_NODE_TYPES33.Identifier) {
|
|
6433
6697
|
return false;
|
|
6434
6698
|
}
|
|
6435
6699
|
if (property.name === "json") {
|
|
@@ -6439,7 +6703,7 @@ var isRawPayloadSource = (node) => {
|
|
|
6439
6703
|
return !current.arguments.some(isSchemaParseReference) && isRawPayloadSource(callee.object);
|
|
6440
6704
|
}
|
|
6441
6705
|
const object = unwrap4(callee.object);
|
|
6442
|
-
return property.name === "parse" && object !== null && object.type ===
|
|
6706
|
+
return property.name === "parse" && object !== null && object.type === AST_NODE_TYPES33.Identifier && object.name === "JSON" && // ...but not `JSON.parse(readFileSync(p, "utf8"))` — see isLocalFileRead.
|
|
6443
6707
|
!isLocalFileRead(current.arguments[0]);
|
|
6444
6708
|
};
|
|
6445
6709
|
var FILE_READ_RE = /^(readFile|readFileSync|readJson|readJsonSync|readJSON)$/;
|
|
@@ -6447,9 +6711,9 @@ var isLocalFileRead = (node) => {
|
|
|
6447
6711
|
let found = false;
|
|
6448
6712
|
const visit = (current) => {
|
|
6449
6713
|
if (found || current === null || current === void 0) return;
|
|
6450
|
-
if (current.type ===
|
|
6714
|
+
if (current.type === AST_NODE_TYPES33.CallExpression) {
|
|
6451
6715
|
const callee = unwrap4(current.callee);
|
|
6452
|
-
const name = callee?.type ===
|
|
6716
|
+
const name = callee?.type === AST_NODE_TYPES33.Identifier ? callee.name : callee?.type === AST_NODE_TYPES33.MemberExpression && !callee.computed && callee.property.type === AST_NODE_TYPES33.Identifier ? callee.property.name : null;
|
|
6453
6717
|
if (name !== null && FILE_READ_RE.test(name)) {
|
|
6454
6718
|
found = true;
|
|
6455
6719
|
return;
|
|
@@ -6471,15 +6735,15 @@ var isLocalFileRead = (node) => {
|
|
|
6471
6735
|
var ASSERTION_CALLEE_RE = /^(expect|assert|should|invariant)$/;
|
|
6472
6736
|
var isInsideAssertion = (node) => {
|
|
6473
6737
|
for (let current = node.parent; current !== void 0 && current !== null; current = current.parent) {
|
|
6474
|
-
if (current.type !==
|
|
6738
|
+
if (current.type !== AST_NODE_TYPES33.CallExpression) continue;
|
|
6475
6739
|
let callee = current.callee;
|
|
6476
|
-
while (callee.type ===
|
|
6740
|
+
while (callee.type === AST_NODE_TYPES33.MemberExpression) {
|
|
6477
6741
|
callee = callee.object;
|
|
6478
6742
|
}
|
|
6479
|
-
if (callee.type ===
|
|
6743
|
+
if (callee.type === AST_NODE_TYPES33.CallExpression) {
|
|
6480
6744
|
callee = callee.callee;
|
|
6481
6745
|
}
|
|
6482
|
-
if (callee.type ===
|
|
6746
|
+
if (callee.type === AST_NODE_TYPES33.Identifier && ASSERTION_CALLEE_RE.test(callee.name)) {
|
|
6483
6747
|
return true;
|
|
6484
6748
|
}
|
|
6485
6749
|
}
|
|
@@ -6498,39 +6762,39 @@ var GUARD_NAME_RE = /^(?:is|validate|parse|assert|decode|coerce)[A-Z]/;
|
|
|
6498
6762
|
var isValidationRead = (node) => {
|
|
6499
6763
|
let current = node;
|
|
6500
6764
|
let parent = current.parent;
|
|
6501
|
-
while (parent !== null && parent !== void 0 && (parent.type ===
|
|
6765
|
+
while (parent !== null && parent !== void 0 && (parent.type === AST_NODE_TYPES33.TSAsExpression || parent.type === AST_NODE_TYPES33.TSTypeAssertion || parent.type === AST_NODE_TYPES33.TSNonNullExpression || parent.type === AST_NODE_TYPES33.TSSatisfiesExpression || parent.type === AST_NODE_TYPES33.ChainExpression)) {
|
|
6502
6766
|
current = parent;
|
|
6503
6767
|
parent = parent.parent;
|
|
6504
6768
|
}
|
|
6505
6769
|
if (parent === null || parent === void 0) return false;
|
|
6506
|
-
if (parent.type ===
|
|
6770
|
+
if (parent.type === AST_NODE_TYPES33.UnaryExpression && parent.operator === "typeof" && parent.argument === current) {
|
|
6507
6771
|
return true;
|
|
6508
6772
|
}
|
|
6509
|
-
if (parent.type !==
|
|
6773
|
+
if (parent.type !== AST_NODE_TYPES33.CallExpression || !parent.arguments.some((arg) => arg === current)) {
|
|
6510
6774
|
return false;
|
|
6511
6775
|
}
|
|
6512
6776
|
const callee = parent.callee;
|
|
6513
|
-
if (callee.type ===
|
|
6777
|
+
if (callee.type === AST_NODE_TYPES33.MemberExpression && !callee.computed && callee.object.type === AST_NODE_TYPES33.Identifier && callee.object.name === "Array" && callee.property.type === AST_NODE_TYPES33.Identifier && callee.property.name === "isArray") {
|
|
6514
6778
|
return parent.arguments.length === 1;
|
|
6515
6779
|
}
|
|
6516
|
-
return callee.type ===
|
|
6780
|
+
return callee.type === AST_NODE_TYPES33.Identifier && GUARD_NAME_RE.test(callee.name);
|
|
6517
6781
|
};
|
|
6518
6782
|
var isGuardTestPosition = (node) => {
|
|
6519
6783
|
let current = node;
|
|
6520
6784
|
let parent = current.parent;
|
|
6521
6785
|
while (parent !== void 0 && parent !== null) {
|
|
6522
6786
|
switch (parent.type) {
|
|
6523
|
-
case
|
|
6524
|
-
case
|
|
6525
|
-
case
|
|
6787
|
+
case AST_NODE_TYPES33.UnaryExpression:
|
|
6788
|
+
case AST_NODE_TYPES33.LogicalExpression:
|
|
6789
|
+
case AST_NODE_TYPES33.ChainExpression:
|
|
6526
6790
|
current = parent;
|
|
6527
6791
|
parent = parent.parent;
|
|
6528
6792
|
continue;
|
|
6529
|
-
case
|
|
6530
|
-
case
|
|
6531
|
-
case
|
|
6532
|
-
case
|
|
6533
|
-
case
|
|
6793
|
+
case AST_NODE_TYPES33.IfStatement:
|
|
6794
|
+
case AST_NODE_TYPES33.ConditionalExpression:
|
|
6795
|
+
case AST_NODE_TYPES33.WhileStatement:
|
|
6796
|
+
case AST_NODE_TYPES33.DoWhileStatement:
|
|
6797
|
+
case AST_NODE_TYPES33.ForStatement:
|
|
6534
6798
|
return parent.test === current;
|
|
6535
6799
|
default:
|
|
6536
6800
|
return false;
|
|
@@ -6540,7 +6804,7 @@ var isGuardTestPosition = (node) => {
|
|
|
6540
6804
|
};
|
|
6541
6805
|
var isUnvalidatedVariableRef = (node, scope, tracked) => {
|
|
6542
6806
|
const unwrapped = unwrap4(node);
|
|
6543
|
-
if (unwrapped === null || unwrapped.type !==
|
|
6807
|
+
if (unwrapped === null || unwrapped.type !== AST_NODE_TYPES33.Identifier) {
|
|
6544
6808
|
return false;
|
|
6545
6809
|
}
|
|
6546
6810
|
const variable = findVariable2(scope, unwrapped.name);
|
|
@@ -6583,11 +6847,11 @@ var prefer_schema_for_api_payload_default = createRule({
|
|
|
6583
6847
|
return {
|
|
6584
6848
|
VariableDeclarator(node) {
|
|
6585
6849
|
const scope = context.sourceCode.getScope(node);
|
|
6586
|
-
if (node.id.type ===
|
|
6850
|
+
if (node.id.type === AST_NODE_TYPES33.Identifier) {
|
|
6587
6851
|
trackInitializer(node);
|
|
6588
6852
|
return;
|
|
6589
6853
|
}
|
|
6590
|
-
if (node.id.type ===
|
|
6854
|
+
if (node.id.type === AST_NODE_TYPES33.ObjectPattern || node.id.type === AST_NODE_TYPES33.ArrayPattern) {
|
|
6591
6855
|
if (isRawPayloadSource(node.init)) {
|
|
6592
6856
|
if (!isFullyNarrowedPattern(node)) {
|
|
6593
6857
|
context.report({ node: node.id, messageId: "unparsedJsonAccess" });
|
|
@@ -6601,7 +6865,7 @@ var prefer_schema_for_api_payload_default = createRule({
|
|
|
6601
6865
|
},
|
|
6602
6866
|
AssignmentExpression(node) {
|
|
6603
6867
|
const scope = context.sourceCode.getScope(node);
|
|
6604
|
-
if (node.left.type ===
|
|
6868
|
+
if (node.left.type === AST_NODE_TYPES33.Identifier) {
|
|
6605
6869
|
const variable = findVariable2(scope, node.left.name);
|
|
6606
6870
|
if (variable === null) return;
|
|
6607
6871
|
if (isRawPayloadSource(node.right)) {
|
|
@@ -6611,7 +6875,7 @@ var prefer_schema_for_api_payload_default = createRule({
|
|
|
6611
6875
|
}
|
|
6612
6876
|
return;
|
|
6613
6877
|
}
|
|
6614
|
-
if (node.left.type ===
|
|
6878
|
+
if (node.left.type === AST_NODE_TYPES33.ObjectPattern || node.left.type === AST_NODE_TYPES33.ArrayPattern) {
|
|
6615
6879
|
if (isRawPayloadSource(node.right)) {
|
|
6616
6880
|
context.report({
|
|
6617
6881
|
node: node.left,
|
|
@@ -6628,15 +6892,15 @@ var prefer_schema_for_api_payload_default = createRule({
|
|
|
6628
6892
|
}
|
|
6629
6893
|
},
|
|
6630
6894
|
CallExpression(node) {
|
|
6631
|
-
if (node.callee.type !==
|
|
6895
|
+
if (node.callee.type !== AST_NODE_TYPES33.Identifier) return;
|
|
6632
6896
|
if (!GUARD_NAME_RE.test(node.callee.name) && !isGuardTestPosition(node)) {
|
|
6633
6897
|
return;
|
|
6634
6898
|
}
|
|
6635
6899
|
const scope = context.sourceCode.getScope(node);
|
|
6636
6900
|
for (const arg of node.arguments) {
|
|
6637
|
-
if (arg.type ===
|
|
6901
|
+
if (arg.type === AST_NODE_TYPES33.SpreadElement) continue;
|
|
6638
6902
|
const unwrapped = unwrap4(arg);
|
|
6639
|
-
if (unwrapped === null || unwrapped.type !==
|
|
6903
|
+
if (unwrapped === null || unwrapped.type !== AST_NODE_TYPES33.Identifier) {
|
|
6640
6904
|
continue;
|
|
6641
6905
|
}
|
|
6642
6906
|
const variable = findVariable2(scope, unwrapped.name);
|
|
@@ -6650,13 +6914,13 @@ var prefer_schema_for_api_payload_default = createRule({
|
|
|
6650
6914
|
const obj = unwrap4(node.object);
|
|
6651
6915
|
if (isRawPayloadSource(obj)) {
|
|
6652
6916
|
const parent = node.parent;
|
|
6653
|
-
if (parent.type ===
|
|
6917
|
+
if (parent.type === AST_NODE_TYPES33.CallExpression && parent.callee === node && node.property.type === AST_NODE_TYPES33.Identifier && (node.property.name === "parse" || node.property.name === "safeParse" || PROMISE_CHAIN_METHODS.has(node.property.name))) {
|
|
6654
6918
|
return;
|
|
6655
6919
|
}
|
|
6656
6920
|
context.report({ node, messageId: "unparsedJsonAccess" });
|
|
6657
6921
|
return;
|
|
6658
6922
|
}
|
|
6659
|
-
if (obj !== null && obj.type ===
|
|
6923
|
+
if (obj !== null && obj.type === AST_NODE_TYPES33.Identifier && isUnvalidatedVariableRef(obj, scope, unvalidatedVariables)) {
|
|
6660
6924
|
context.report({ node, messageId: "unparsedJsonAccess" });
|
|
6661
6925
|
const variable = findVariable2(scope, obj.name);
|
|
6662
6926
|
if (variable !== null) {
|
|
@@ -6669,8 +6933,8 @@ var prefer_schema_for_api_payload_default = createRule({
|
|
|
6669
6933
|
});
|
|
6670
6934
|
|
|
6671
6935
|
// src/rules/prefer-semantic-colors.ts
|
|
6672
|
-
import { AST_NODE_TYPES as
|
|
6673
|
-
import { existsSync, readFileSync } from "fs";
|
|
6936
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES34 } from "@typescript-eslint/utils";
|
|
6937
|
+
import { existsSync, readdirSync, readFileSync } from "fs";
|
|
6674
6938
|
import { dirname, join, parse } from "path";
|
|
6675
6939
|
|
|
6676
6940
|
// src/rules/_tailwind.ts
|
|
@@ -6711,7 +6975,14 @@ var STYLE_COLOR_PROPS = /* @__PURE__ */ new Set([
|
|
|
6711
6975
|
var RAW_COLOR_VALUE_RE = new RegExp(`#[0-9a-fA-F]{3,8}\\b|\\b(?:${COLOR_FN})\\s*\\(`, "i");
|
|
6712
6976
|
var CSS_VAR_REFERENCE_RE = /var\(\s*--/;
|
|
6713
6977
|
var STORIES_FILE_RE = /\.stories\.[cm]?[jt]sx?$/i;
|
|
6714
|
-
var SEMANTIC_TOKEN_RE =
|
|
6978
|
+
var SEMANTIC_TOKEN_RE = /@theme\b|--(?:background|foreground|primary|secondary|muted|accent|destructive|border|card|popover)\b|(?:bg|text|border)-(?:background|foreground|primary|secondary|muted|accent|destructive|border|card|popover)\b/;
|
|
6979
|
+
var CONFIG_IS_SUFFICIENT = /* @__PURE__ */ new Set([
|
|
6980
|
+
"components.json",
|
|
6981
|
+
"tailwind.config.cjs",
|
|
6982
|
+
"tailwind.config.js",
|
|
6983
|
+
"tailwind.config.mjs",
|
|
6984
|
+
"tailwind.config.ts"
|
|
6985
|
+
]);
|
|
6715
6986
|
var DETECTION_FILES = [
|
|
6716
6987
|
"components.json",
|
|
6717
6988
|
"tailwind.config.js",
|
|
@@ -6724,8 +6995,17 @@ var DETECTION_FILES = [
|
|
|
6724
6995
|
"src/styles/globals.css",
|
|
6725
6996
|
"styles/globals.css"
|
|
6726
6997
|
];
|
|
6727
|
-
var
|
|
6728
|
-
|
|
6998
|
+
var WORKSPACE_ROOT_FILES = [
|
|
6999
|
+
"pnpm-workspace.yaml",
|
|
7000
|
+
"pnpm-workspace.yml",
|
|
7001
|
+
"turbo.json",
|
|
7002
|
+
"lerna.json"
|
|
7003
|
+
];
|
|
7004
|
+
var DEFAULT_WORKSPACE_GLOBS = ["packages/*", "apps/*"];
|
|
7005
|
+
var MAX_WORKSPACE_PACKAGES = 512;
|
|
7006
|
+
var ancestryCache = /* @__PURE__ */ new Map();
|
|
7007
|
+
var workspaceScanCache = /* @__PURE__ */ new Map();
|
|
7008
|
+
var workspaceRootCache = /* @__PURE__ */ new Map();
|
|
6729
7009
|
var SVG_DEFS_CONTAINERS = /* @__PURE__ */ new Set([
|
|
6730
7010
|
"mask",
|
|
6731
7011
|
"clipPath",
|
|
@@ -6746,8 +7026,8 @@ var SVG_EXEMPT_COLOR_VALUES = /* @__PURE__ */ new Set([
|
|
|
6746
7026
|
]);
|
|
6747
7027
|
function jsxElementName(node) {
|
|
6748
7028
|
const name = node.openingElement.name;
|
|
6749
|
-
if (name.type ===
|
|
6750
|
-
if (name.type ===
|
|
7029
|
+
if (name.type === AST_NODE_TYPES34.JSXIdentifier) return name.name;
|
|
7030
|
+
if (name.type === AST_NODE_TYPES34.JSXMemberExpression && name.property.type === AST_NODE_TYPES34.JSXIdentifier) {
|
|
6751
7031
|
return name.property.name;
|
|
6752
7032
|
}
|
|
6753
7033
|
return null;
|
|
@@ -6773,7 +7053,7 @@ var EMAIL_OR_PDF_IMPORT_RE = /@react-(?:email|pdf)\//;
|
|
|
6773
7053
|
var isInsideSvg = (node) => {
|
|
6774
7054
|
let current = node.parent;
|
|
6775
7055
|
while (current !== void 0 && current !== null) {
|
|
6776
|
-
if (current.type ===
|
|
7056
|
+
if (current.type === AST_NODE_TYPES34.JSXElement) {
|
|
6777
7057
|
const name = jsxElementName(current);
|
|
6778
7058
|
if (name !== null && isSvgLikeElementName(name)) return true;
|
|
6779
7059
|
}
|
|
@@ -6784,58 +7064,144 @@ var isInsideSvg = (node) => {
|
|
|
6784
7064
|
var isInsideIconFactoryPath = (node) => {
|
|
6785
7065
|
let current = node.parent;
|
|
6786
7066
|
while (current !== void 0 && current !== null) {
|
|
6787
|
-
if (current.type ===
|
|
7067
|
+
if (current.type === AST_NODE_TYPES34.Property && propName(current.key) === "path" && current.parent.type === AST_NODE_TYPES34.ObjectExpression && current.parent.parent.type === AST_NODE_TYPES34.CallExpression && current.parent.parent.callee.type === AST_NODE_TYPES34.Identifier && current.parent.parent.callee.name === "createIcon") {
|
|
6788
7068
|
return true;
|
|
6789
7069
|
}
|
|
6790
7070
|
current = current.parent;
|
|
6791
7071
|
}
|
|
6792
7072
|
return false;
|
|
6793
7073
|
};
|
|
6794
|
-
var
|
|
6795
|
-
|
|
7074
|
+
var hasMarkerAt = (dir) => {
|
|
7075
|
+
for (const rel of DETECTION_FILES) {
|
|
7076
|
+
const candidate = join(dir, rel);
|
|
7077
|
+
if (!existsSync(candidate)) continue;
|
|
7078
|
+
if (CONFIG_IS_SUFFICIENT.has(rel)) return true;
|
|
7079
|
+
try {
|
|
7080
|
+
if (SEMANTIC_TOKEN_RE.test(readFileSync(candidate, "utf8"))) return true;
|
|
7081
|
+
} catch {
|
|
7082
|
+
}
|
|
7083
|
+
}
|
|
7084
|
+
return false;
|
|
7085
|
+
};
|
|
7086
|
+
var hasMarkerAtOrAbove = (startDir) => {
|
|
7087
|
+
let dir = startDir;
|
|
6796
7088
|
const root = parse(dir).root;
|
|
6797
7089
|
const visited = [];
|
|
6798
7090
|
let answer;
|
|
6799
|
-
for (
|
|
6800
|
-
const cached =
|
|
7091
|
+
for (; ; ) {
|
|
7092
|
+
const cached = ancestryCache.get(dir);
|
|
6801
7093
|
if (cached !== void 0) {
|
|
6802
7094
|
answer = cached;
|
|
6803
7095
|
break;
|
|
6804
7096
|
}
|
|
6805
7097
|
visited.push(dir);
|
|
6806
|
-
|
|
6807
|
-
for (const rel of DETECTION_FILES) {
|
|
6808
|
-
const candidate = join(dir, rel);
|
|
6809
|
-
if (!existsSync(candidate)) continue;
|
|
6810
|
-
if (rel === "components.json") {
|
|
6811
|
-
found = true;
|
|
6812
|
-
break;
|
|
6813
|
-
}
|
|
6814
|
-
try {
|
|
6815
|
-
if (SEMANTIC_TOKEN_RE.test(readFileSync(candidate, "utf8"))) {
|
|
6816
|
-
found = true;
|
|
6817
|
-
break;
|
|
6818
|
-
}
|
|
6819
|
-
} catch {
|
|
6820
|
-
}
|
|
6821
|
-
}
|
|
6822
|
-
if (found) {
|
|
7098
|
+
if (hasMarkerAt(dir)) {
|
|
6823
7099
|
answer = true;
|
|
6824
7100
|
break;
|
|
6825
7101
|
}
|
|
6826
|
-
|
|
7102
|
+
const parent = dirname(dir);
|
|
7103
|
+
if (dir === root || parent === dir) {
|
|
6827
7104
|
answer = false;
|
|
6828
7105
|
break;
|
|
6829
7106
|
}
|
|
6830
|
-
dir =
|
|
7107
|
+
dir = parent;
|
|
6831
7108
|
}
|
|
6832
|
-
|
|
6833
|
-
for (const seen of visited) semanticTokenCache.set(seen, answer);
|
|
7109
|
+
for (const seen of visited) ancestryCache.set(seen, answer);
|
|
6834
7110
|
return answer;
|
|
6835
7111
|
};
|
|
7112
|
+
var readWorkspaceGlobs = (dir) => {
|
|
7113
|
+
const globs = [];
|
|
7114
|
+
const packageJson = join(dir, "package.json");
|
|
7115
|
+
if (existsSync(packageJson)) {
|
|
7116
|
+
try {
|
|
7117
|
+
const parsed = JSON.parse(readFileSync(packageJson, "utf8"));
|
|
7118
|
+
const declared = typeof parsed === "object" && parsed !== null && "workspaces" in parsed ? parsed.workspaces : void 0;
|
|
7119
|
+
const list = Array.isArray(declared) ? declared : typeof declared === "object" && declared !== null && Array.isArray(declared.packages) ? declared.packages : [];
|
|
7120
|
+
for (const entry of list) if (typeof entry === "string") globs.push(entry);
|
|
7121
|
+
} catch {
|
|
7122
|
+
}
|
|
7123
|
+
}
|
|
7124
|
+
for (const name of ["pnpm-workspace.yaml", "pnpm-workspace.yml"]) {
|
|
7125
|
+
const yaml = join(dir, name);
|
|
7126
|
+
if (!existsSync(yaml)) continue;
|
|
7127
|
+
try {
|
|
7128
|
+
for (const line of readFileSync(yaml, "utf8").split("\n")) {
|
|
7129
|
+
const match = /^\s*-\s*["']?([^"'#\s]+)["']?\s*$/u.exec(line);
|
|
7130
|
+
if (match?.[1] !== void 0) globs.push(match[1]);
|
|
7131
|
+
}
|
|
7132
|
+
} catch {
|
|
7133
|
+
}
|
|
7134
|
+
}
|
|
7135
|
+
return globs;
|
|
7136
|
+
};
|
|
7137
|
+
var expandWorkspaceGlob = (root, glob) => {
|
|
7138
|
+
const star = glob.indexOf("*");
|
|
7139
|
+
if (star === -1) return [join(root, glob)];
|
|
7140
|
+
const prefix = glob.slice(0, star).replace(/\/$/u, "");
|
|
7141
|
+
const parent = prefix === "" ? root : join(root, prefix);
|
|
7142
|
+
try {
|
|
7143
|
+
return readdirSync(parent, { withFileTypes: true }).filter((entry) => entry.isDirectory() && !entry.name.startsWith(".")).map((entry) => join(parent, entry.name));
|
|
7144
|
+
} catch {
|
|
7145
|
+
return [];
|
|
7146
|
+
}
|
|
7147
|
+
};
|
|
7148
|
+
var findWorkspaceRoot = (startDir) => {
|
|
7149
|
+
let dir = startDir;
|
|
7150
|
+
const root = parse(dir).root;
|
|
7151
|
+
const visited = [];
|
|
7152
|
+
let answer;
|
|
7153
|
+
for (; ; ) {
|
|
7154
|
+
const cached = workspaceRootCache.get(dir);
|
|
7155
|
+
if (cached !== void 0) {
|
|
7156
|
+
answer = cached;
|
|
7157
|
+
break;
|
|
7158
|
+
}
|
|
7159
|
+
visited.push(dir);
|
|
7160
|
+
if (WORKSPACE_ROOT_FILES.some((name) => existsSync(join(dir, name))) || readWorkspaceGlobs(dir).length > 0) {
|
|
7161
|
+
answer = dir;
|
|
7162
|
+
break;
|
|
7163
|
+
}
|
|
7164
|
+
const parent = dirname(dir);
|
|
7165
|
+
if (dir === root || parent === dir) {
|
|
7166
|
+
answer = null;
|
|
7167
|
+
break;
|
|
7168
|
+
}
|
|
7169
|
+
dir = parent;
|
|
7170
|
+
}
|
|
7171
|
+
for (const seen of visited) workspaceRootCache.set(seen, answer);
|
|
7172
|
+
return answer;
|
|
7173
|
+
};
|
|
7174
|
+
var workspaceHasMarker = (root) => {
|
|
7175
|
+
const cached = workspaceScanCache.get(root);
|
|
7176
|
+
if (cached !== void 0) return cached;
|
|
7177
|
+
const globs = readWorkspaceGlobs(root);
|
|
7178
|
+
const candidates = /* @__PURE__ */ new Set();
|
|
7179
|
+
for (const glob of globs.length > 0 ? globs : DEFAULT_WORKSPACE_GLOBS) {
|
|
7180
|
+
for (const dir of expandWorkspaceGlob(root, glob)) {
|
|
7181
|
+
candidates.add(dir);
|
|
7182
|
+
if (candidates.size >= MAX_WORKSPACE_PACKAGES) break;
|
|
7183
|
+
}
|
|
7184
|
+
if (candidates.size >= MAX_WORKSPACE_PACKAGES) break;
|
|
7185
|
+
}
|
|
7186
|
+
let found = false;
|
|
7187
|
+
for (const dir of candidates) {
|
|
7188
|
+
if (hasMarkerAt(dir)) {
|
|
7189
|
+
found = true;
|
|
7190
|
+
break;
|
|
7191
|
+
}
|
|
7192
|
+
}
|
|
7193
|
+
workspaceScanCache.set(root, found);
|
|
7194
|
+
return found;
|
|
7195
|
+
};
|
|
7196
|
+
var hasSemanticTokenSystem = (filename) => {
|
|
7197
|
+
const dir = dirname(filename);
|
|
7198
|
+
if (hasMarkerAtOrAbove(dir)) return true;
|
|
7199
|
+
const root = findWorkspaceRoot(dir);
|
|
7200
|
+
return root !== null && workspaceHasMarker(root);
|
|
7201
|
+
};
|
|
6836
7202
|
var propName = (key) => {
|
|
6837
|
-
if (key.type ===
|
|
6838
|
-
if (key.type ===
|
|
7203
|
+
if (key.type === AST_NODE_TYPES34.Identifier) return key.name;
|
|
7204
|
+
if (key.type === AST_NODE_TYPES34.Literal && typeof key.value === "string") return key.value;
|
|
6839
7205
|
return null;
|
|
6840
7206
|
};
|
|
6841
7207
|
var prefer_semantic_colors_default = createRule({
|
|
@@ -6880,27 +7246,27 @@ var prefer_semantic_colors_default = createRule({
|
|
|
6880
7246
|
const checkClassNode = (node) => {
|
|
6881
7247
|
if (node === null) return;
|
|
6882
7248
|
switch (node.type) {
|
|
6883
|
-
case
|
|
7249
|
+
case AST_NODE_TYPES34.Literal:
|
|
6884
7250
|
if (typeof node.value === "string") reportClasses(node.value, node);
|
|
6885
7251
|
break;
|
|
6886
|
-
case
|
|
7252
|
+
case AST_NODE_TYPES34.TemplateLiteral:
|
|
6887
7253
|
for (const quasi of node.quasis) reportClasses(quasi.value.cooked ?? "", quasi);
|
|
6888
7254
|
break;
|
|
6889
|
-
case
|
|
7255
|
+
case AST_NODE_TYPES34.ArrayExpression:
|
|
6890
7256
|
for (const element of node.elements) {
|
|
6891
|
-
if (element !== null && element.type !==
|
|
7257
|
+
if (element !== null && element.type !== AST_NODE_TYPES34.SpreadElement) checkClassNode(element);
|
|
6892
7258
|
}
|
|
6893
7259
|
break;
|
|
6894
|
-
case
|
|
7260
|
+
case AST_NODE_TYPES34.ObjectExpression:
|
|
6895
7261
|
for (const property of node.properties) {
|
|
6896
|
-
if (property.type ===
|
|
7262
|
+
if (property.type === AST_NODE_TYPES34.Property) checkClassNode(property.value);
|
|
6897
7263
|
}
|
|
6898
7264
|
break;
|
|
6899
|
-
case
|
|
7265
|
+
case AST_NODE_TYPES34.ConditionalExpression:
|
|
6900
7266
|
checkClassNode(node.consequent);
|
|
6901
7267
|
checkClassNode(node.alternate);
|
|
6902
7268
|
break;
|
|
6903
|
-
case
|
|
7269
|
+
case AST_NODE_TYPES34.LogicalExpression:
|
|
6904
7270
|
checkClassNode(node.right);
|
|
6905
7271
|
break;
|
|
6906
7272
|
default:
|
|
@@ -6908,29 +7274,29 @@ var prefer_semantic_colors_default = createRule({
|
|
|
6908
7274
|
}
|
|
6909
7275
|
};
|
|
6910
7276
|
const checkColorValueNode = (node) => {
|
|
6911
|
-
if (node.type ===
|
|
7277
|
+
if (node.type === AST_NODE_TYPES34.Literal && typeof node.value === "string" && RAW_COLOR_VALUE_RE.test(node.value) && !CSS_VAR_REFERENCE_RE.test(node.value)) {
|
|
6912
7278
|
context.report({ node, messageId: "inlineColor", data: { value: node.value } });
|
|
6913
7279
|
}
|
|
6914
7280
|
};
|
|
6915
7281
|
return {
|
|
6916
7282
|
"JSXAttribute[name.name='className']"(node) {
|
|
6917
7283
|
if (node.value === null) return;
|
|
6918
|
-
if (node.value.type ===
|
|
6919
|
-
else if (node.value.type ===
|
|
6920
|
-
if (node.value.expression.type !==
|
|
7284
|
+
if (node.value.type === AST_NODE_TYPES34.Literal) checkClassNode(node.value);
|
|
7285
|
+
else if (node.value.type === AST_NODE_TYPES34.JSXExpressionContainer) {
|
|
7286
|
+
if (node.value.expression.type !== AST_NODE_TYPES34.JSXEmptyExpression) {
|
|
6921
7287
|
checkClassNode(node.value.expression);
|
|
6922
7288
|
}
|
|
6923
7289
|
}
|
|
6924
7290
|
},
|
|
6925
7291
|
CallExpression(node) {
|
|
6926
|
-
if (node.callee.type ===
|
|
7292
|
+
if (node.callee.type === AST_NODE_TYPES34.Identifier && CLASS_FNS.has(node.callee.name)) {
|
|
6927
7293
|
for (const arg of node.arguments) {
|
|
6928
|
-
if (arg.type !==
|
|
7294
|
+
if (arg.type !== AST_NODE_TYPES34.SpreadElement) checkClassNode(arg);
|
|
6929
7295
|
}
|
|
6930
7296
|
}
|
|
6931
7297
|
},
|
|
6932
7298
|
VariableDeclarator(node) {
|
|
6933
|
-
if (node.id.type ===
|
|
7299
|
+
if (node.id.type === AST_NODE_TYPES34.Identifier && CLASS_NAME_RE.test(node.id.name)) {
|
|
6934
7300
|
checkClassNode(node.init);
|
|
6935
7301
|
}
|
|
6936
7302
|
},
|
|
@@ -6942,9 +7308,9 @@ var prefer_semantic_colors_default = createRule({
|
|
|
6942
7308
|
// Neutral drawing literals and anything inside an SVG defs container are
|
|
6943
7309
|
// structural, not UI tokens, so they never fire.
|
|
6944
7310
|
"JSXAttribute[name.name=/^(fill|stroke|color)$/]"(node) {
|
|
6945
|
-
if (node.value?.type !==
|
|
7311
|
+
if (node.value?.type !== AST_NODE_TYPES34.Literal) return;
|
|
6946
7312
|
const owner = node.parent.name;
|
|
6947
|
-
if (owner.type ===
|
|
7313
|
+
if (owner.type === AST_NODE_TYPES34.JSXIdentifier && SVG_SHAPE_PRIMITIVES.has(owner.name)) {
|
|
6948
7314
|
return;
|
|
6949
7315
|
}
|
|
6950
7316
|
if (typeof node.value.value === "string" && SVG_EXEMPT_COLOR_VALUES.has(node.value.value.toLowerCase())) {
|
|
@@ -7117,7 +7483,7 @@ var prefer_server_actions_default = createRule({
|
|
|
7117
7483
|
// src/rules/prefer-string-literal-union.ts
|
|
7118
7484
|
import {
|
|
7119
7485
|
ESLintUtils as ESLintUtils3,
|
|
7120
|
-
AST_NODE_TYPES as
|
|
7486
|
+
AST_NODE_TYPES as AST_NODE_TYPES35
|
|
7121
7487
|
} from "@typescript-eslint/utils";
|
|
7122
7488
|
import * as ts2 from "typescript";
|
|
7123
7489
|
var CHOICE_TOKENS = /* @__PURE__ */ new Set([
|
|
@@ -7161,19 +7527,19 @@ function isChoiceLikeName(name) {
|
|
|
7161
7527
|
return CHOICE_TOKENS.has(lastWord(name));
|
|
7162
7528
|
}
|
|
7163
7529
|
function keyName(key) {
|
|
7164
|
-
if (key.type ===
|
|
7530
|
+
if (key.type === AST_NODE_TYPES35.Identifier) {
|
|
7165
7531
|
return key.name;
|
|
7166
7532
|
}
|
|
7167
|
-
if (key.type ===
|
|
7533
|
+
if (key.type === AST_NODE_TYPES35.Literal && typeof key.value === "string") {
|
|
7168
7534
|
return key.value;
|
|
7169
7535
|
}
|
|
7170
7536
|
return null;
|
|
7171
7537
|
}
|
|
7172
7538
|
function isStringLiteralMember(t) {
|
|
7173
|
-
return t.type ===
|
|
7539
|
+
return t.type === AST_NODE_TYPES35.TSLiteralType && t.literal.type === AST_NODE_TYPES35.Literal && typeof t.literal.value === "string";
|
|
7174
7540
|
}
|
|
7175
7541
|
function isStringLiteralUnion(node) {
|
|
7176
|
-
if (node?.type !==
|
|
7542
|
+
if (node?.type !== AST_NODE_TYPES35.TSUnionType) {
|
|
7177
7543
|
return false;
|
|
7178
7544
|
}
|
|
7179
7545
|
return node.types.filter(isStringLiteralMember).length >= MIN_CLUSTER_SIZE;
|
|
@@ -7202,12 +7568,12 @@ function bindingSourceExpression(decl) {
|
|
|
7202
7568
|
return ts2.isForOfStatement(node) ? node.expression : node.initializer;
|
|
7203
7569
|
}
|
|
7204
7570
|
function refKey(node) {
|
|
7205
|
-
if (node.type ===
|
|
7571
|
+
if (node.type === AST_NODE_TYPES35.Identifier) {
|
|
7206
7572
|
return node.name;
|
|
7207
7573
|
}
|
|
7208
|
-
if (node.type ===
|
|
7574
|
+
if (node.type === AST_NODE_TYPES35.MemberExpression && !node.computed) {
|
|
7209
7575
|
const inner = refKey(node.object);
|
|
7210
|
-
if (inner === null || node.property.type !==
|
|
7576
|
+
if (inner === null || node.property.type !== AST_NODE_TYPES35.Identifier) {
|
|
7211
7577
|
return null;
|
|
7212
7578
|
}
|
|
7213
7579
|
return `${inner}.${node.property.name}`;
|
|
@@ -7215,7 +7581,7 @@ function refKey(node) {
|
|
|
7215
7581
|
return null;
|
|
7216
7582
|
}
|
|
7217
7583
|
function strLiteral(node) {
|
|
7218
|
-
if (node.type ===
|
|
7584
|
+
if (node.type === AST_NODE_TYPES35.Literal && typeof node.value === "string") {
|
|
7219
7585
|
return node.value;
|
|
7220
7586
|
}
|
|
7221
7587
|
return null;
|
|
@@ -7368,7 +7734,7 @@ var prefer_string_literal_union_default = createRule({
|
|
|
7368
7734
|
containersWithUnion.add(container);
|
|
7369
7735
|
return;
|
|
7370
7736
|
}
|
|
7371
|
-
if (typeNode?.type !==
|
|
7737
|
+
if (typeNode?.type !== AST_NODE_TYPES35.TSStringKeyword) {
|
|
7372
7738
|
return;
|
|
7373
7739
|
}
|
|
7374
7740
|
const name = keyName(key);
|
|
@@ -7456,10 +7822,10 @@ var prefer_string_literal_union_default = createRule({
|
|
|
7456
7822
|
}
|
|
7457
7823
|
};
|
|
7458
7824
|
function refKeyText(node) {
|
|
7459
|
-
if (node.type ===
|
|
7825
|
+
if (node.type === AST_NODE_TYPES35.BinaryExpression) {
|
|
7460
7826
|
return refKey(node.left) ?? refKey(node.right) ?? "value";
|
|
7461
7827
|
}
|
|
7462
|
-
if (node.type ===
|
|
7828
|
+
if (node.type === AST_NODE_TYPES35.SwitchStatement) {
|
|
7463
7829
|
return refKey(node.discriminant) ?? "value";
|
|
7464
7830
|
}
|
|
7465
7831
|
return "value";
|
|
@@ -7468,19 +7834,20 @@ var prefer_string_literal_union_default = createRule({
|
|
|
7468
7834
|
});
|
|
7469
7835
|
|
|
7470
7836
|
// src/rules/prefer-whole-object-assertion.ts
|
|
7471
|
-
import { AST_NODE_TYPES as
|
|
7837
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES36 } from "@typescript-eslint/utils";
|
|
7472
7838
|
var MERGEABLE_MATCHERS = /* @__PURE__ */ new Set(["toBe", "toEqual", "toStrictEqual"]);
|
|
7473
7839
|
var ARRAY_MATCHERS = /* @__PURE__ */ new Set(["toEqual", "toStrictEqual"]);
|
|
7474
7840
|
var COLLECTION_PROPERTIES = /* @__PURE__ */ new Set(["length", "size"]);
|
|
7841
|
+
var LITERAL_KEY_HAZARDS = /* @__PURE__ */ new Set(["__proto__"]);
|
|
7475
7842
|
var NUMERIC_SIGNS2 = /* @__PURE__ */ new Set(["-", "+"]);
|
|
7476
7843
|
var MIN_RUN_LENGTH = 2;
|
|
7477
7844
|
function literalText(node, getText) {
|
|
7478
7845
|
switch (node.type) {
|
|
7479
|
-
case
|
|
7846
|
+
case AST_NODE_TYPES36.Literal:
|
|
7480
7847
|
return "regex" in node ? null : getText(node);
|
|
7481
|
-
case
|
|
7848
|
+
case AST_NODE_TYPES36.TemplateLiteral:
|
|
7482
7849
|
return node.expressions.length === 0 ? getText(node) : null;
|
|
7483
|
-
case
|
|
7850
|
+
case AST_NODE_TYPES36.UnaryExpression:
|
|
7484
7851
|
return NUMERIC_SIGNS2.has(node.operator) && literalText(node.argument, getText) !== null ? getText(node) : null;
|
|
7485
7852
|
default:
|
|
7486
7853
|
return null;
|
|
@@ -7488,15 +7855,15 @@ function literalText(node, getText) {
|
|
|
7488
7855
|
}
|
|
7489
7856
|
function isPureReceiver(node) {
|
|
7490
7857
|
switch (node.type) {
|
|
7491
|
-
case
|
|
7492
|
-
case
|
|
7858
|
+
case AST_NODE_TYPES36.Identifier:
|
|
7859
|
+
case AST_NODE_TYPES36.ThisExpression:
|
|
7493
7860
|
return true;
|
|
7494
|
-
case
|
|
7861
|
+
case AST_NODE_TYPES36.MemberExpression:
|
|
7495
7862
|
if (node.optional) {
|
|
7496
7863
|
return false;
|
|
7497
7864
|
}
|
|
7498
7865
|
if (node.computed) {
|
|
7499
|
-
return node.property.type ===
|
|
7866
|
+
return node.property.type === AST_NODE_TYPES36.Literal && isPureReceiver(node.object);
|
|
7500
7867
|
}
|
|
7501
7868
|
return isPureReceiver(node.object);
|
|
7502
7869
|
default:
|
|
@@ -7504,7 +7871,7 @@ function isPureReceiver(node) {
|
|
|
7504
7871
|
}
|
|
7505
7872
|
}
|
|
7506
7873
|
function literalIndex(node) {
|
|
7507
|
-
if (node.type !==
|
|
7874
|
+
if (node.type !== AST_NODE_TYPES36.Literal || typeof node.value !== "number") {
|
|
7508
7875
|
return null;
|
|
7509
7876
|
}
|
|
7510
7877
|
return Number.isInteger(node.value) && node.value >= 0 ? node.value : null;
|
|
@@ -7530,24 +7897,24 @@ var prefer_whole_object_assertion_default = createRule({
|
|
|
7530
7897
|
}
|
|
7531
7898
|
const { sourceCode } = context;
|
|
7532
7899
|
function parseAssertion(statement) {
|
|
7533
|
-
if (statement.type !==
|
|
7900
|
+
if (statement.type !== AST_NODE_TYPES36.ExpressionStatement) {
|
|
7534
7901
|
return null;
|
|
7535
7902
|
}
|
|
7536
7903
|
const call = statement.expression;
|
|
7537
|
-
if (call.type !==
|
|
7904
|
+
if (call.type !== AST_NODE_TYPES36.CallExpression) {
|
|
7538
7905
|
return null;
|
|
7539
7906
|
}
|
|
7540
7907
|
const callee = call.callee;
|
|
7541
|
-
if (callee.type !==
|
|
7908
|
+
if (callee.type !== AST_NODE_TYPES36.MemberExpression || callee.computed || callee.property.type !== AST_NODE_TYPES36.Identifier) {
|
|
7542
7909
|
return null;
|
|
7543
7910
|
}
|
|
7544
7911
|
const matcher = callee.property.name;
|
|
7545
7912
|
const expectCall = callee.object;
|
|
7546
|
-
if (expectCall.type !==
|
|
7913
|
+
if (expectCall.type !== AST_NODE_TYPES36.CallExpression || expectCall.callee.type !== AST_NODE_TYPES36.Identifier || expectCall.callee.name !== "expect" || expectCall.arguments.length !== 1) {
|
|
7547
7914
|
return null;
|
|
7548
7915
|
}
|
|
7549
7916
|
const actual = expectCall.arguments[0];
|
|
7550
|
-
if (actual === void 0 || actual.type !==
|
|
7917
|
+
if (actual === void 0 || actual.type !== AST_NODE_TYPES36.MemberExpression || actual.optional) {
|
|
7551
7918
|
return null;
|
|
7552
7919
|
}
|
|
7553
7920
|
if (!isPureReceiver(actual.object)) {
|
|
@@ -7561,7 +7928,7 @@ var prefer_whole_object_assertion_default = createRule({
|
|
|
7561
7928
|
}
|
|
7562
7929
|
key = { kind: "index", index };
|
|
7563
7930
|
} else {
|
|
7564
|
-
if (actual.property.type !==
|
|
7931
|
+
if (actual.property.type !== AST_NODE_TYPES36.Identifier || COLLECTION_PROPERTIES.has(actual.property.name) || LITERAL_KEY_HAZARDS.has(actual.property.name)) {
|
|
7565
7932
|
return null;
|
|
7566
7933
|
}
|
|
7567
7934
|
key = { kind: "property", name: actual.property.name };
|
|
@@ -7573,7 +7940,7 @@ var prefer_whole_object_assertion_default = createRule({
|
|
|
7573
7940
|
return null;
|
|
7574
7941
|
}
|
|
7575
7942
|
const expected = call.arguments[0];
|
|
7576
|
-
if (call.arguments.length !== 1 || expected === void 0 || expected.type ===
|
|
7943
|
+
if (call.arguments.length !== 1 || expected === void 0 || expected.type === AST_NODE_TYPES36.SpreadElement) {
|
|
7577
7944
|
return null;
|
|
7578
7945
|
}
|
|
7579
7946
|
const literal = literalText(expected, (node) => sourceCode.getText(node));
|
|
@@ -7586,6 +7953,11 @@ var prefer_whole_object_assertion_default = createRule({
|
|
|
7586
7953
|
expectedIsLiteral: literal !== null
|
|
7587
7954
|
};
|
|
7588
7955
|
}
|
|
7956
|
+
function hasInterveningComment(run) {
|
|
7957
|
+
return run.some(
|
|
7958
|
+
(assertion, index) => sourceCode.getCommentsInside(assertion.statement).length > 0 || index > 0 && sourceCode.getCommentsBefore(assertion.statement).length > 0
|
|
7959
|
+
);
|
|
7960
|
+
}
|
|
7589
7961
|
function reportPropertyRun(run) {
|
|
7590
7962
|
const names = /* @__PURE__ */ new Set();
|
|
7591
7963
|
for (const assertion of run) {
|
|
@@ -7612,7 +7984,7 @@ var prefer_whole_object_assertion_default = createRule({
|
|
|
7612
7984
|
node: first.statement,
|
|
7613
7985
|
messageId: "combineAssertions",
|
|
7614
7986
|
data: { count: String(run.length), receiver: receiverText },
|
|
7615
|
-
fix: (fixer) => [
|
|
7987
|
+
fix: hasInterveningComment(run) ? null : (fixer) => [
|
|
7616
7988
|
fixer.replaceText(first.statement, `expect(${receiverText}).toMatchObject({ ${properties} });`),
|
|
7617
7989
|
...run.slice(1).map((assertion) => fixer.remove(assertion.statement))
|
|
7618
7990
|
]
|
|
@@ -7683,7 +8055,7 @@ var prefer_whole_object_assertion_default = createRule({
|
|
|
7683
8055
|
});
|
|
7684
8056
|
|
|
7685
8057
|
// src/rules/prefer-zod-enum.ts
|
|
7686
|
-
import { AST_NODE_TYPES as
|
|
8058
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES37 } from "@typescript-eslint/utils";
|
|
7687
8059
|
var prefer_zod_enum_default = createRule({
|
|
7688
8060
|
name: "prefer-zod-enum",
|
|
7689
8061
|
meta: {
|
|
@@ -7703,20 +8075,20 @@ var prefer_zod_enum_default = createRule({
|
|
|
7703
8075
|
const zodNamespaces = /* @__PURE__ */ new Set();
|
|
7704
8076
|
function enumValues(node) {
|
|
7705
8077
|
const callee = node.callee;
|
|
7706
|
-
if (callee.type !==
|
|
8078
|
+
if (callee.type !== AST_NODE_TYPES37.MemberExpression || callee.computed || callee.object.type !== AST_NODE_TYPES37.Identifier || !zodNamespaces.has(callee.object.name) || callee.property.type !== AST_NODE_TYPES37.Identifier || callee.property.name !== "union" || node.arguments.length !== 1) {
|
|
7707
8079
|
return null;
|
|
7708
8080
|
}
|
|
7709
8081
|
const argument = node.arguments[0];
|
|
7710
|
-
if (argument === void 0 || argument.type !==
|
|
8082
|
+
if (argument === void 0 || argument.type !== AST_NODE_TYPES37.ArrayExpression || argument.elements.length === 0) {
|
|
7711
8083
|
return null;
|
|
7712
8084
|
}
|
|
7713
8085
|
const values = [];
|
|
7714
8086
|
for (const element of argument.elements) {
|
|
7715
|
-
if (element === null || element.type !==
|
|
8087
|
+
if (element === null || element.type !== AST_NODE_TYPES37.CallExpression || element.arguments.length !== 1 || element.callee.type !== AST_NODE_TYPES37.MemberExpression || element.callee.computed || element.callee.object.type !== AST_NODE_TYPES37.Identifier || !zodNamespaces.has(element.callee.object.name) || element.callee.property.type !== AST_NODE_TYPES37.Identifier || element.callee.property.name !== "literal") {
|
|
7716
8088
|
return null;
|
|
7717
8089
|
}
|
|
7718
8090
|
const value = element.arguments[0];
|
|
7719
|
-
if (value === void 0 || value.type !==
|
|
8091
|
+
if (value === void 0 || value.type !== AST_NODE_TYPES37.Literal || typeof value.value !== "string") {
|
|
7720
8092
|
return null;
|
|
7721
8093
|
}
|
|
7722
8094
|
values.push(value);
|
|
@@ -7725,11 +8097,11 @@ var prefer_zod_enum_default = createRule({
|
|
|
7725
8097
|
}
|
|
7726
8098
|
function buildFix(node, values) {
|
|
7727
8099
|
const argument = node.arguments[0];
|
|
7728
|
-
if (argument === void 0 || argument.type !==
|
|
8100
|
+
if (argument === void 0 || argument.type !== AST_NODE_TYPES37.ArrayExpression || sourceCode.getCommentsInside(argument).length > 0) {
|
|
7729
8101
|
return void 0;
|
|
7730
8102
|
}
|
|
7731
8103
|
const callee = node.callee;
|
|
7732
|
-
if (callee.type !==
|
|
8104
|
+
if (callee.type !== AST_NODE_TYPES37.MemberExpression || callee.property.type !== AST_NODE_TYPES37.Identifier) {
|
|
7733
8105
|
return void 0;
|
|
7734
8106
|
}
|
|
7735
8107
|
return (fixer) => [
|
|
@@ -7746,7 +8118,7 @@ var prefer_zod_enum_default = createRule({
|
|
|
7746
8118
|
return;
|
|
7747
8119
|
}
|
|
7748
8120
|
for (const specifier of node.specifiers) {
|
|
7749
|
-
if (specifier.type ===
|
|
8121
|
+
if (specifier.type === AST_NODE_TYPES37.ImportNamespaceSpecifier || specifier.type === AST_NODE_TYPES37.ImportDefaultSpecifier || specifier.type === AST_NODE_TYPES37.ImportSpecifier && specifier.imported.type === AST_NODE_TYPES37.Identifier && specifier.imported.name === "z") {
|
|
7750
8122
|
zodNamespaces.add(specifier.local.name);
|
|
7751
8123
|
}
|
|
7752
8124
|
}
|
|
@@ -7768,7 +8140,7 @@ var prefer_zod_enum_default = createRule({
|
|
|
7768
8140
|
});
|
|
7769
8141
|
|
|
7770
8142
|
// src/rules/prefer-zod-infer.ts
|
|
7771
|
-
import { AST_NODE_TYPES as
|
|
8143
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES38 } from "@typescript-eslint/utils";
|
|
7772
8144
|
var SHAPE_PRESERVING_METHODS = /* @__PURE__ */ new Set([
|
|
7773
8145
|
"describe",
|
|
7774
8146
|
"refine",
|
|
@@ -7805,44 +8177,44 @@ var ZOD_TYPE_CONSTRAINTS = /* @__PURE__ */ new Set([
|
|
|
7805
8177
|
"Schema"
|
|
7806
8178
|
]);
|
|
7807
8179
|
var LEAF_NODE_TYPES = {
|
|
7808
|
-
string: [
|
|
7809
|
-
email: [
|
|
7810
|
-
url: [
|
|
7811
|
-
uuid: [
|
|
7812
|
-
ulid: [
|
|
7813
|
-
cuid: [
|
|
7814
|
-
cuid2: [
|
|
7815
|
-
nanoid: [
|
|
7816
|
-
iso: [
|
|
7817
|
-
number: [
|
|
7818
|
-
int: [
|
|
7819
|
-
float32: [
|
|
7820
|
-
float64: [
|
|
7821
|
-
boolean: [
|
|
7822
|
-
bigint: [
|
|
7823
|
-
symbol: [
|
|
7824
|
-
any: [
|
|
7825
|
-
unknown: [
|
|
7826
|
-
never: [
|
|
7827
|
-
void: [
|
|
7828
|
-
null: [
|
|
7829
|
-
undefined: [
|
|
7830
|
-
literal: [
|
|
7831
|
-
date: [
|
|
7832
|
-
array: [
|
|
7833
|
-
tuple: [
|
|
7834
|
-
object: [
|
|
7835
|
-
strictObject: [
|
|
7836
|
-
looseObject: [
|
|
7837
|
-
record: [
|
|
7838
|
-
map: [
|
|
7839
|
-
set: [
|
|
7840
|
-
promise: [
|
|
7841
|
-
enum: [
|
|
7842
|
-
nativeEnum: [
|
|
7843
|
-
union: [
|
|
7844
|
-
discriminatedUnion: [
|
|
7845
|
-
intersection: [
|
|
8180
|
+
string: [AST_NODE_TYPES38.TSStringKeyword],
|
|
8181
|
+
email: [AST_NODE_TYPES38.TSStringKeyword],
|
|
8182
|
+
url: [AST_NODE_TYPES38.TSStringKeyword],
|
|
8183
|
+
uuid: [AST_NODE_TYPES38.TSStringKeyword],
|
|
8184
|
+
ulid: [AST_NODE_TYPES38.TSStringKeyword],
|
|
8185
|
+
cuid: [AST_NODE_TYPES38.TSStringKeyword],
|
|
8186
|
+
cuid2: [AST_NODE_TYPES38.TSStringKeyword],
|
|
8187
|
+
nanoid: [AST_NODE_TYPES38.TSStringKeyword],
|
|
8188
|
+
iso: [AST_NODE_TYPES38.TSStringKeyword],
|
|
8189
|
+
number: [AST_NODE_TYPES38.TSNumberKeyword],
|
|
8190
|
+
int: [AST_NODE_TYPES38.TSNumberKeyword],
|
|
8191
|
+
float32: [AST_NODE_TYPES38.TSNumberKeyword],
|
|
8192
|
+
float64: [AST_NODE_TYPES38.TSNumberKeyword],
|
|
8193
|
+
boolean: [AST_NODE_TYPES38.TSBooleanKeyword],
|
|
8194
|
+
bigint: [AST_NODE_TYPES38.TSBigIntKeyword],
|
|
8195
|
+
symbol: [AST_NODE_TYPES38.TSSymbolKeyword],
|
|
8196
|
+
any: [AST_NODE_TYPES38.TSAnyKeyword],
|
|
8197
|
+
unknown: [AST_NODE_TYPES38.TSUnknownKeyword],
|
|
8198
|
+
never: [AST_NODE_TYPES38.TSNeverKeyword],
|
|
8199
|
+
void: [AST_NODE_TYPES38.TSVoidKeyword],
|
|
8200
|
+
null: [AST_NODE_TYPES38.TSNullKeyword],
|
|
8201
|
+
undefined: [AST_NODE_TYPES38.TSUndefinedKeyword],
|
|
8202
|
+
literal: [AST_NODE_TYPES38.TSLiteralType],
|
|
8203
|
+
date: [AST_NODE_TYPES38.TSTypeReference],
|
|
8204
|
+
array: [AST_NODE_TYPES38.TSArrayType, AST_NODE_TYPES38.TSTypeReference],
|
|
8205
|
+
tuple: [AST_NODE_TYPES38.TSTupleType],
|
|
8206
|
+
object: [AST_NODE_TYPES38.TSTypeLiteral, AST_NODE_TYPES38.TSTypeReference],
|
|
8207
|
+
strictObject: [AST_NODE_TYPES38.TSTypeLiteral, AST_NODE_TYPES38.TSTypeReference],
|
|
8208
|
+
looseObject: [AST_NODE_TYPES38.TSTypeLiteral, AST_NODE_TYPES38.TSTypeReference],
|
|
8209
|
+
record: [AST_NODE_TYPES38.TSTypeReference, AST_NODE_TYPES38.TSTypeLiteral],
|
|
8210
|
+
map: [AST_NODE_TYPES38.TSTypeReference],
|
|
8211
|
+
set: [AST_NODE_TYPES38.TSTypeReference],
|
|
8212
|
+
promise: [AST_NODE_TYPES38.TSTypeReference],
|
|
8213
|
+
enum: [AST_NODE_TYPES38.TSUnionType, AST_NODE_TYPES38.TSTypeReference, AST_NODE_TYPES38.TSLiteralType],
|
|
8214
|
+
nativeEnum: [AST_NODE_TYPES38.TSUnionType, AST_NODE_TYPES38.TSTypeReference, AST_NODE_TYPES38.TSLiteralType],
|
|
8215
|
+
union: [AST_NODE_TYPES38.TSUnionType, AST_NODE_TYPES38.TSTypeReference],
|
|
8216
|
+
discriminatedUnion: [AST_NODE_TYPES38.TSUnionType, AST_NODE_TYPES38.TSTypeReference],
|
|
8217
|
+
intersection: [AST_NODE_TYPES38.TSIntersectionType, AST_NODE_TYPES38.TSTypeReference]
|
|
7846
8218
|
};
|
|
7847
8219
|
function normalizeSchemaName(name) {
|
|
7848
8220
|
return name.replace(/Schema$/i, "").replace(/^Z(?=[A-Z])/, "").toLowerCase();
|
|
@@ -7851,20 +8223,20 @@ function normalizeTypeName(name) {
|
|
|
7851
8223
|
return name.replace(/Type$/, "").toLowerCase();
|
|
7852
8224
|
}
|
|
7853
8225
|
function unwrapNullish(annotation) {
|
|
7854
|
-
if (annotation.type !==
|
|
8226
|
+
if (annotation.type !== AST_NODE_TYPES38.TSUnionType) {
|
|
7855
8227
|
return {
|
|
7856
8228
|
core: annotation,
|
|
7857
|
-
nullable: annotation.type ===
|
|
8229
|
+
nullable: annotation.type === AST_NODE_TYPES38.TSNullKeyword
|
|
7858
8230
|
};
|
|
7859
8231
|
}
|
|
7860
8232
|
const rest = [];
|
|
7861
8233
|
let nullable = false;
|
|
7862
8234
|
for (const member of annotation.types) {
|
|
7863
|
-
if (member.type ===
|
|
8235
|
+
if (member.type === AST_NODE_TYPES38.TSNullKeyword) {
|
|
7864
8236
|
nullable = true;
|
|
7865
8237
|
continue;
|
|
7866
8238
|
}
|
|
7867
|
-
if (member.type ===
|
|
8239
|
+
if (member.type === AST_NODE_TYPES38.TSUndefinedKeyword) {
|
|
7868
8240
|
continue;
|
|
7869
8241
|
}
|
|
7870
8242
|
rest.push(member);
|
|
@@ -7929,14 +8301,14 @@ var prefer_zod_infer_default = createRule({
|
|
|
7929
8301
|
function zodCallChain(node) {
|
|
7930
8302
|
const chain = [];
|
|
7931
8303
|
let current = node;
|
|
7932
|
-
while (current.type ===
|
|
8304
|
+
while (current.type === AST_NODE_TYPES38.CallExpression) {
|
|
7933
8305
|
const callee = current.callee;
|
|
7934
|
-
if (callee.type !==
|
|
8306
|
+
if (callee.type !== AST_NODE_TYPES38.MemberExpression || callee.computed || callee.property.type !== AST_NODE_TYPES38.Identifier) {
|
|
7935
8307
|
return null;
|
|
7936
8308
|
}
|
|
7937
8309
|
chain.push(current);
|
|
7938
8310
|
const receiver = callee.object;
|
|
7939
|
-
if (receiver.type ===
|
|
8311
|
+
if (receiver.type === AST_NODE_TYPES38.Identifier) {
|
|
7940
8312
|
return zodNamespaces.has(receiver.name) ? chain.reverse() : null;
|
|
7941
8313
|
}
|
|
7942
8314
|
current = receiver;
|
|
@@ -7945,19 +8317,19 @@ var prefer_zod_infer_default = createRule({
|
|
|
7945
8317
|
}
|
|
7946
8318
|
function methodName(call) {
|
|
7947
8319
|
const callee = call.callee;
|
|
7948
|
-
return callee.type ===
|
|
8320
|
+
return callee.type === AST_NODE_TYPES38.MemberExpression && callee.property.type === AST_NODE_TYPES38.Identifier ? callee.property.name : "";
|
|
7949
8321
|
}
|
|
7950
8322
|
function schemaField(node) {
|
|
7951
8323
|
const modifiers = [];
|
|
7952
8324
|
let current = node;
|
|
7953
8325
|
let leaf = null;
|
|
7954
|
-
while (current.type ===
|
|
8326
|
+
while (current.type === AST_NODE_TYPES38.CallExpression) {
|
|
7955
8327
|
const callee = current.callee;
|
|
7956
|
-
if (callee.type !==
|
|
8328
|
+
if (callee.type !== AST_NODE_TYPES38.MemberExpression || callee.computed || callee.property.type !== AST_NODE_TYPES38.Identifier) {
|
|
7957
8329
|
break;
|
|
7958
8330
|
}
|
|
7959
8331
|
const receiver = callee.object;
|
|
7960
|
-
if (receiver.type ===
|
|
8332
|
+
if (receiver.type === AST_NODE_TYPES38.Identifier && zodNamespaces.has(receiver.name)) {
|
|
7961
8333
|
leaf = callee.property.name;
|
|
7962
8334
|
break;
|
|
7963
8335
|
}
|
|
@@ -7988,16 +8360,16 @@ var prefer_zod_infer_default = createRule({
|
|
|
7988
8360
|
return null;
|
|
7989
8361
|
}
|
|
7990
8362
|
const shape = base.arguments[0];
|
|
7991
|
-
if (shape === void 0 || shape.type !==
|
|
8363
|
+
if (shape === void 0 || shape.type !== AST_NODE_TYPES38.ObjectExpression) {
|
|
7992
8364
|
return null;
|
|
7993
8365
|
}
|
|
7994
8366
|
const fields = /* @__PURE__ */ new Map();
|
|
7995
8367
|
for (const property of shape.properties) {
|
|
7996
|
-
if (property.type !==
|
|
8368
|
+
if (property.type !== AST_NODE_TYPES38.Property || property.computed) {
|
|
7997
8369
|
return null;
|
|
7998
8370
|
}
|
|
7999
8371
|
const { key } = property;
|
|
8000
|
-
const name = key.type ===
|
|
8372
|
+
const name = key.type === AST_NODE_TYPES38.Identifier ? key.name : key.type === AST_NODE_TYPES38.Literal && typeof key.value === "string" ? key.value : null;
|
|
8001
8373
|
if (name === null) {
|
|
8002
8374
|
return null;
|
|
8003
8375
|
}
|
|
@@ -8008,11 +8380,11 @@ var prefer_zod_infer_default = createRule({
|
|
|
8008
8380
|
function typeMembers(members) {
|
|
8009
8381
|
const result = /* @__PURE__ */ new Map();
|
|
8010
8382
|
for (const member of members) {
|
|
8011
|
-
if (member.type !==
|
|
8383
|
+
if (member.type !== AST_NODE_TYPES38.TSPropertySignature || member.computed) {
|
|
8012
8384
|
return null;
|
|
8013
8385
|
}
|
|
8014
8386
|
const { key } = member;
|
|
8015
|
-
const name = key.type ===
|
|
8387
|
+
const name = key.type === AST_NODE_TYPES38.Identifier ? key.name : key.type === AST_NODE_TYPES38.Literal && typeof key.value === "string" ? key.value : null;
|
|
8016
8388
|
if (name === null) {
|
|
8017
8389
|
return null;
|
|
8018
8390
|
}
|
|
@@ -8026,8 +8398,8 @@ var prefer_zod_infer_default = createRule({
|
|
|
8026
8398
|
return result.size === 0 ? null : result;
|
|
8027
8399
|
}
|
|
8028
8400
|
function collectConstrainedNames(node) {
|
|
8029
|
-
if (node.type ===
|
|
8030
|
-
if (node.typeName.type ===
|
|
8401
|
+
if (node.type === AST_NODE_TYPES38.TSTypeReference) {
|
|
8402
|
+
if (node.typeName.type === AST_NODE_TYPES38.Identifier) {
|
|
8031
8403
|
constrainedTypeNames.add(node.typeName.name);
|
|
8032
8404
|
}
|
|
8033
8405
|
for (const argument of node.typeArguments?.params ?? []) {
|
|
@@ -8035,11 +8407,11 @@ var prefer_zod_infer_default = createRule({
|
|
|
8035
8407
|
}
|
|
8036
8408
|
return;
|
|
8037
8409
|
}
|
|
8038
|
-
if (node.type ===
|
|
8410
|
+
if (node.type === AST_NODE_TYPES38.TSArrayType) {
|
|
8039
8411
|
collectConstrainedNames(node.elementType);
|
|
8040
8412
|
return;
|
|
8041
8413
|
}
|
|
8042
|
-
if (node.type ===
|
|
8414
|
+
if (node.type === AST_NODE_TYPES38.TSUnionType || node.type === AST_NODE_TYPES38.TSIntersectionType) {
|
|
8043
8415
|
for (const member of node.types) {
|
|
8044
8416
|
collectConstrainedNames(member);
|
|
8045
8417
|
}
|
|
@@ -8083,13 +8455,13 @@ var prefer_zod_infer_default = createRule({
|
|
|
8083
8455
|
return;
|
|
8084
8456
|
}
|
|
8085
8457
|
for (const specifier of node.specifiers) {
|
|
8086
|
-
if (specifier.type ===
|
|
8458
|
+
if (specifier.type === AST_NODE_TYPES38.ImportNamespaceSpecifier || specifier.type === AST_NODE_TYPES38.ImportDefaultSpecifier || specifier.type === AST_NODE_TYPES38.ImportSpecifier && specifier.imported.type === AST_NODE_TYPES38.Identifier && specifier.imported.name === "z") {
|
|
8087
8459
|
zodNamespaces.add(specifier.local.name);
|
|
8088
8460
|
}
|
|
8089
8461
|
}
|
|
8090
8462
|
},
|
|
8091
8463
|
VariableDeclarator(node) {
|
|
8092
|
-
if (node.id.type !==
|
|
8464
|
+
if (node.id.type !== AST_NODE_TYPES38.Identifier || node.init == null) {
|
|
8093
8465
|
return;
|
|
8094
8466
|
}
|
|
8095
8467
|
const fields = schemaFields(node.init);
|
|
@@ -8099,14 +8471,14 @@ var prefer_zod_infer_default = createRule({
|
|
|
8099
8471
|
},
|
|
8100
8472
|
/** Guard (f): `XSchema.transform(...)` anywhere in the module. */
|
|
8101
8473
|
"MemberExpression[computed=false]"(node) {
|
|
8102
|
-
if (node.object.type ===
|
|
8474
|
+
if (node.object.type === AST_NODE_TYPES38.Identifier && node.property.type === AST_NODE_TYPES38.Identifier && MODULE_LEVEL_RESHAPERS.has(node.property.name)) {
|
|
8103
8475
|
reshapedSchemaNames.add(node.object.name);
|
|
8104
8476
|
}
|
|
8105
8477
|
},
|
|
8106
8478
|
/** Guard (c): `z.ZodType<T>` and every other type argument it carries. */
|
|
8107
8479
|
TSTypeReference(node) {
|
|
8108
8480
|
const { typeName } = node;
|
|
8109
|
-
const referenced = typeName.type ===
|
|
8481
|
+
const referenced = typeName.type === AST_NODE_TYPES38.Identifier ? typeName.name : typeName.type === AST_NODE_TYPES38.TSQualifiedName && typeName.right.type === AST_NODE_TYPES38.Identifier ? typeName.right.name : null;
|
|
8110
8482
|
if (referenced === null || !ZOD_TYPE_CONSTRAINTS.has(referenced)) {
|
|
8111
8483
|
return;
|
|
8112
8484
|
}
|
|
@@ -8124,7 +8496,7 @@ var prefer_zod_infer_default = createRule({
|
|
|
8124
8496
|
}
|
|
8125
8497
|
},
|
|
8126
8498
|
TSTypeAliasDeclaration(node) {
|
|
8127
|
-
if (node.typeParameters !== void 0 || node.typeAnnotation.type !==
|
|
8499
|
+
if (node.typeParameters !== void 0 || node.typeAnnotation.type !== AST_NODE_TYPES38.TSTypeLiteral) {
|
|
8128
8500
|
return;
|
|
8129
8501
|
}
|
|
8130
8502
|
const members = typeMembers(node.typeAnnotation.members);
|
|
@@ -8169,36 +8541,36 @@ var prefer_zod_infer_default = createRule({
|
|
|
8169
8541
|
});
|
|
8170
8542
|
|
|
8171
8543
|
// src/rules/require-assert-never.ts
|
|
8172
|
-
import { AST_NODE_TYPES as
|
|
8544
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES39 } from "@typescript-eslint/utils";
|
|
8173
8545
|
var isAssertNeverCall = (expression) => {
|
|
8174
|
-
if (expression.type !==
|
|
8546
|
+
if (expression.type !== AST_NODE_TYPES39.CallExpression) return false;
|
|
8175
8547
|
const callee = expression.callee;
|
|
8176
|
-
if (callee.type ===
|
|
8548
|
+
if (callee.type === AST_NODE_TYPES39.Identifier) {
|
|
8177
8549
|
return callee.name === "assertNever";
|
|
8178
8550
|
}
|
|
8179
|
-
if (callee.type ===
|
|
8551
|
+
if (callee.type === AST_NODE_TYPES39.MemberExpression && !callee.computed && callee.property.type === AST_NODE_TYPES39.Identifier) {
|
|
8180
8552
|
return callee.property.name === "assertNever";
|
|
8181
8553
|
}
|
|
8182
8554
|
return false;
|
|
8183
8555
|
};
|
|
8184
8556
|
var statementContainsAssertNever = (statement) => {
|
|
8185
|
-
if (statement.type ===
|
|
8557
|
+
if (statement.type === AST_NODE_TYPES39.ExpressionStatement) {
|
|
8186
8558
|
return isAssertNeverCall(statement.expression);
|
|
8187
8559
|
}
|
|
8188
|
-
if (statement.type ===
|
|
8560
|
+
if (statement.type === AST_NODE_TYPES39.ThrowStatement) {
|
|
8189
8561
|
return isAssertNeverCall(statement.argument);
|
|
8190
8562
|
}
|
|
8191
|
-
if (statement.type ===
|
|
8563
|
+
if (statement.type === AST_NODE_TYPES39.ReturnStatement) {
|
|
8192
8564
|
return statement.argument !== null && isAssertNeverCall(statement.argument);
|
|
8193
8565
|
}
|
|
8194
|
-
if (statement.type ===
|
|
8566
|
+
if (statement.type === AST_NODE_TYPES39.BlockStatement) {
|
|
8195
8567
|
return statement.body.some(statementContainsAssertNever);
|
|
8196
8568
|
}
|
|
8197
8569
|
return false;
|
|
8198
8570
|
};
|
|
8199
8571
|
var isRuntimeHandlingStatement = (statement) => {
|
|
8200
|
-
if (statement.type ===
|
|
8201
|
-
if (statement.type ===
|
|
8572
|
+
if (statement.type === AST_NODE_TYPES39.EmptyStatement) return false;
|
|
8573
|
+
if (statement.type === AST_NODE_TYPES39.BlockStatement) {
|
|
8202
8574
|
return statement.body.some(isRuntimeHandlingStatement);
|
|
8203
8575
|
}
|
|
8204
8576
|
return true;
|
|
@@ -8214,7 +8586,7 @@ var isCommentOnlyNoopDefault = (defaultCase, sourceCode) => {
|
|
|
8214
8586
|
return colonToken !== null && sourceCode.getCommentsAfter(colonToken).length > 0;
|
|
8215
8587
|
}
|
|
8216
8588
|
const only = defaultCase.consequent[0];
|
|
8217
|
-
if (only !== void 0 && defaultCase.consequent.length === 1 && only.type ===
|
|
8589
|
+
if (only !== void 0 && defaultCase.consequent.length === 1 && only.type === AST_NODE_TYPES39.BlockStatement && only.body.length === 0) {
|
|
8218
8590
|
return sourceCode.getCommentsInside(only).length > 0;
|
|
8219
8591
|
}
|
|
8220
8592
|
return false;
|
|
@@ -8255,7 +8627,7 @@ var require_assert_never_default = createRule({
|
|
|
8255
8627
|
});
|
|
8256
8628
|
|
|
8257
8629
|
// src/rules/require-fetch-timeout.ts
|
|
8258
|
-
import { AST_NODE_TYPES as
|
|
8630
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES40, ASTUtils as ASTUtils2 } from "@typescript-eslint/utils";
|
|
8259
8631
|
var CODEMOD_FIXTURE_RE = /[\\/]__testfixtures__[\\/]/;
|
|
8260
8632
|
var GLOBAL_OBJECTS2 = /* @__PURE__ */ new Set([
|
|
8261
8633
|
"globalThis",
|
|
@@ -8272,14 +8644,14 @@ function matchesAnyPattern3(filename, patterns) {
|
|
|
8272
8644
|
return false;
|
|
8273
8645
|
}
|
|
8274
8646
|
function initProvablyLacksSignal(init) {
|
|
8275
|
-
if (init.type !==
|
|
8647
|
+
if (init.type !== AST_NODE_TYPES40.ObjectExpression) {
|
|
8276
8648
|
return false;
|
|
8277
8649
|
}
|
|
8278
8650
|
for (const prop of init.properties) {
|
|
8279
|
-
if (prop.type ===
|
|
8651
|
+
if (prop.type === AST_NODE_TYPES40.SpreadElement) {
|
|
8280
8652
|
return false;
|
|
8281
8653
|
}
|
|
8282
|
-
if (prop.key.type ===
|
|
8654
|
+
if (prop.key.type === AST_NODE_TYPES40.Identifier && prop.key.name === "signal" || prop.key.type === AST_NODE_TYPES40.Literal && prop.key.value === "signal") {
|
|
8283
8655
|
return false;
|
|
8284
8656
|
}
|
|
8285
8657
|
if (prop.computed) {
|
|
@@ -8289,7 +8661,7 @@ function initProvablyLacksSignal(init) {
|
|
|
8289
8661
|
return true;
|
|
8290
8662
|
}
|
|
8291
8663
|
function isStringish(node) {
|
|
8292
|
-
return node.type ===
|
|
8664
|
+
return node.type === AST_NODE_TYPES40.Literal && typeof node.value === "string" || node.type === AST_NODE_TYPES40.TemplateLiteral;
|
|
8293
8665
|
}
|
|
8294
8666
|
var require_fetch_timeout_default = createRule({
|
|
8295
8667
|
name: "require-fetch-timeout",
|
|
@@ -8330,10 +8702,10 @@ var require_fetch_timeout_default = createRule({
|
|
|
8330
8702
|
return variable === null || variable.defs.length === 0;
|
|
8331
8703
|
}
|
|
8332
8704
|
function isGlobalFetchCall2(callee) {
|
|
8333
|
-
if (callee.type ===
|
|
8705
|
+
if (callee.type === AST_NODE_TYPES40.Identifier) {
|
|
8334
8706
|
return callee.name === "fetch" && resolvesToGlobal(callee);
|
|
8335
8707
|
}
|
|
8336
|
-
return callee.type ===
|
|
8708
|
+
return callee.type === AST_NODE_TYPES40.MemberExpression && !callee.computed && callee.property.type === AST_NODE_TYPES40.Identifier && callee.property.name === "fetch" && callee.object.type === AST_NODE_TYPES40.Identifier && GLOBAL_OBJECTS2.has(callee.object.name) && resolvesToGlobal(callee.object);
|
|
8337
8709
|
}
|
|
8338
8710
|
return {
|
|
8339
8711
|
CallExpression(node) {
|
|
@@ -8353,26 +8725,26 @@ var require_fetch_timeout_default = createRule({
|
|
|
8353
8725
|
});
|
|
8354
8726
|
|
|
8355
8727
|
// src/rules/require-interface-for-injected-service.ts
|
|
8356
|
-
import { AST_NODE_TYPES as
|
|
8728
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES41 } from "@typescript-eslint/utils";
|
|
8357
8729
|
var CONFIGISH_TYPE_RE = /(?:Options|Opts|Config|Configuration|Settings|Params|Props|Args|Env|Environment|Callbacks|Flags)$/;
|
|
8358
8730
|
var CONFIGISH_NAME_RE = /^(?:options|opts|config|configuration|settings|params|props|args|env|environment|callbacks|flags|logger|log|clock)$/i;
|
|
8359
8731
|
var HTTP_TRANSPORT_TYPE_RE = /^(?:KyInstance|AxiosInstance|Session)$/;
|
|
8360
8732
|
var TRANSPORT_WRAPPER_NAME_RE = /Client$/;
|
|
8361
8733
|
var ROUTER_FACTORY_NAME = "Router";
|
|
8362
8734
|
var FRAMEWORK_HTTP_TYPES = /* @__PURE__ */ new Set(["Request", "Response", "NextFunction"]);
|
|
8363
|
-
var isExportedClass = (node) => node.parent.type ===
|
|
8364
|
-
var qualifiedName = (name) => name.type ===
|
|
8735
|
+
var isExportedClass = (node) => node.parent.type === AST_NODE_TYPES41.ExportNamedDeclaration || node.parent.type === AST_NODE_TYPES41.ExportDefaultDeclaration;
|
|
8736
|
+
var qualifiedName = (name) => name.type === AST_NODE_TYPES41.Identifier ? name.name : name.type === AST_NODE_TYPES41.TSQualifiedName ? `${qualifiedName(name.left)}.${name.right.name}` : "";
|
|
8365
8737
|
var typeReferenceName = (annotated) => {
|
|
8366
8738
|
let target = annotated;
|
|
8367
|
-
if (target.type ===
|
|
8368
|
-
if (target.type ===
|
|
8369
|
-
if (target.type !==
|
|
8739
|
+
if (target.type === AST_NODE_TYPES41.TSParameterProperty) target = target.parameter;
|
|
8740
|
+
if (target.type === AST_NODE_TYPES41.AssignmentPattern) target = target.left;
|
|
8741
|
+
if (target.type !== AST_NODE_TYPES41.Identifier) return null;
|
|
8370
8742
|
const annotation = target.typeAnnotation?.typeAnnotation;
|
|
8371
|
-
if (annotation === void 0 || annotation.type !==
|
|
8743
|
+
if (annotation === void 0 || annotation.type !== AST_NODE_TYPES41.TSTypeReference) {
|
|
8372
8744
|
return null;
|
|
8373
8745
|
}
|
|
8374
8746
|
const { typeName } = annotation;
|
|
8375
|
-
const rightmost = typeName.type ===
|
|
8747
|
+
const rightmost = typeName.type === AST_NODE_TYPES41.Identifier ? typeName.name : typeName.type === AST_NODE_TYPES41.TSQualifiedName ? typeName.right.name : null;
|
|
8376
8748
|
if (rightmost === null) return null;
|
|
8377
8749
|
return { name: target.name, typeName: rightmost, display: qualifiedName(typeName) };
|
|
8378
8750
|
};
|
|
@@ -8382,17 +8754,17 @@ var readConstructor = (ctor) => {
|
|
|
8382
8754
|
let constructedFields = 0;
|
|
8383
8755
|
if (body !== null && body !== void 0) {
|
|
8384
8756
|
for (const statement of body.body) {
|
|
8385
|
-
if (statement.type !==
|
|
8757
|
+
if (statement.type !== AST_NODE_TYPES41.ExpressionStatement) continue;
|
|
8386
8758
|
const expression = statement.expression;
|
|
8387
|
-
if (expression.type !==
|
|
8759
|
+
if (expression.type !== AST_NODE_TYPES41.AssignmentExpression || expression.operator !== "=" || expression.left.type !== AST_NODE_TYPES41.MemberExpression || expression.left.object.type !== AST_NODE_TYPES41.ThisExpression) {
|
|
8388
8760
|
continue;
|
|
8389
8761
|
}
|
|
8390
8762
|
const source = expression.right;
|
|
8391
|
-
if (source.type ===
|
|
8763
|
+
if (source.type === AST_NODE_TYPES41.NewExpression) {
|
|
8392
8764
|
constructedFields += 1;
|
|
8393
|
-
} else if (source.type ===
|
|
8765
|
+
} else if (source.type === AST_NODE_TYPES41.Identifier) {
|
|
8394
8766
|
storedFrom.add(source.name);
|
|
8395
|
-
} else if (source.type ===
|
|
8767
|
+
} else if (source.type === AST_NODE_TYPES41.MemberExpression && source.object.type === AST_NODE_TYPES41.Identifier) {
|
|
8396
8768
|
storedFrom.add(source.object.name);
|
|
8397
8769
|
}
|
|
8398
8770
|
}
|
|
@@ -8401,7 +8773,7 @@ var readConstructor = (ctor) => {
|
|
|
8401
8773
|
for (const parameter of ctor.value.params) {
|
|
8402
8774
|
const reference = typeReferenceName(parameter);
|
|
8403
8775
|
if (reference === null) continue;
|
|
8404
|
-
const stored = parameter.type ===
|
|
8776
|
+
const stored = parameter.type === AST_NODE_TYPES41.TSParameterProperty || storedFrom.has(reference.name);
|
|
8405
8777
|
if (!stored) continue;
|
|
8406
8778
|
if (CONFIGISH_TYPE_RE.test(reference.typeName)) continue;
|
|
8407
8779
|
if (CONFIGISH_NAME_RE.test(reference.name)) continue;
|
|
@@ -8431,19 +8803,19 @@ var subtreeHas = (root, found) => {
|
|
|
8431
8803
|
return hit;
|
|
8432
8804
|
};
|
|
8433
8805
|
var isFrameworkWiring = (body) => subtreeHas(body, (node) => {
|
|
8434
|
-
if (node.type ===
|
|
8806
|
+
if (node.type === AST_NODE_TYPES41.CallExpression) {
|
|
8435
8807
|
const { callee } = node;
|
|
8436
|
-
if (callee.type ===
|
|
8437
|
-
return callee.type ===
|
|
8808
|
+
if (callee.type === AST_NODE_TYPES41.Identifier) return callee.name === ROUTER_FACTORY_NAME;
|
|
8809
|
+
return callee.type === AST_NODE_TYPES41.MemberExpression && !callee.computed && callee.property.type === AST_NODE_TYPES41.Identifier && callee.property.name === ROUTER_FACTORY_NAME;
|
|
8438
8810
|
}
|
|
8439
|
-
return node.type ===
|
|
8811
|
+
return node.type === AST_NODE_TYPES41.TSTypeReference && node.typeName.type === AST_NODE_TYPES41.TSQualifiedName && FRAMEWORK_HTTP_TYPES.has(node.typeName.right.name);
|
|
8440
8812
|
});
|
|
8441
8813
|
var stem2 = (name) => name.replace(/^I(?=[A-Z])/, "").replace(/Impl$/, "");
|
|
8442
8814
|
var fileInterfaceNames = (program) => {
|
|
8443
8815
|
const names = [];
|
|
8444
8816
|
for (const statement of program.body) {
|
|
8445
|
-
const declaration = statement.type ===
|
|
8446
|
-
if (declaration?.type ===
|
|
8817
|
+
const declaration = statement.type === AST_NODE_TYPES41.ExportNamedDeclaration ? statement.declaration : statement;
|
|
8818
|
+
if (declaration?.type === AST_NODE_TYPES41.TSInterfaceDeclaration) names.push(declaration.id.name);
|
|
8447
8819
|
}
|
|
8448
8820
|
return names;
|
|
8449
8821
|
};
|
|
@@ -8461,11 +8833,11 @@ var isTransportWrapper = (className, collaborators, program) => {
|
|
|
8461
8833
|
var publicMethodNames = (body) => {
|
|
8462
8834
|
const names = [];
|
|
8463
8835
|
for (const member of body.body) {
|
|
8464
|
-
if (member.type !==
|
|
8836
|
+
if (member.type !== AST_NODE_TYPES41.MethodDefinition) continue;
|
|
8465
8837
|
if (member.kind !== "method" || member.static) continue;
|
|
8466
8838
|
if (member.accessibility === "private" || member.accessibility === "protected") continue;
|
|
8467
|
-
if (member.key.type ===
|
|
8468
|
-
if (member.key.type ===
|
|
8839
|
+
if (member.key.type === AST_NODE_TYPES41.PrivateIdentifier) continue;
|
|
8840
|
+
if (member.key.type === AST_NODE_TYPES41.Identifier) names.push(member.key.name);
|
|
8469
8841
|
else names.push("\u2026");
|
|
8470
8842
|
}
|
|
8471
8843
|
return names;
|
|
@@ -8496,7 +8868,7 @@ var require_interface_for_injected_service_default = createRule({
|
|
|
8496
8868
|
if (node.implements.length > 0) return;
|
|
8497
8869
|
if (node.decorators.length > 0) return;
|
|
8498
8870
|
const ctor = node.body.body.find(
|
|
8499
|
-
(member) => member.type ===
|
|
8871
|
+
(member) => member.type === AST_NODE_TYPES41.MethodDefinition && member.kind === "constructor"
|
|
8500
8872
|
);
|
|
8501
8873
|
if (ctor === void 0) return;
|
|
8502
8874
|
const { collaborators, constructedFields } = readConstructor(ctor);
|
|
@@ -8521,18 +8893,18 @@ var require_interface_for_injected_service_default = createRule({
|
|
|
8521
8893
|
});
|
|
8522
8894
|
|
|
8523
8895
|
// src/rules/require-zod-form-validation.ts
|
|
8524
|
-
import { AST_NODE_TYPES as
|
|
8896
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES42 } from "@typescript-eslint/utils";
|
|
8525
8897
|
var looksLikeZodSchema = (node) => {
|
|
8526
8898
|
let current = node;
|
|
8527
8899
|
while (true) {
|
|
8528
|
-
if (current.type ===
|
|
8900
|
+
if (current.type === AST_NODE_TYPES42.Identifier) {
|
|
8529
8901
|
return current.name === "z" || ZOD_SCHEMA_NAME_RE.test(current.name);
|
|
8530
8902
|
}
|
|
8531
|
-
if (current.type ===
|
|
8903
|
+
if (current.type === AST_NODE_TYPES42.CallExpression) {
|
|
8532
8904
|
current = current.callee;
|
|
8533
8905
|
continue;
|
|
8534
8906
|
}
|
|
8535
|
-
if (current.type ===
|
|
8907
|
+
if (current.type === AST_NODE_TYPES42.MemberExpression) {
|
|
8536
8908
|
current = current.object;
|
|
8537
8909
|
continue;
|
|
8538
8910
|
}
|
|
@@ -8540,23 +8912,23 @@ var looksLikeZodSchema = (node) => {
|
|
|
8540
8912
|
}
|
|
8541
8913
|
};
|
|
8542
8914
|
var isZodParseCall = (node) => {
|
|
8543
|
-
if (node.type !==
|
|
8915
|
+
if (node.type !== AST_NODE_TYPES42.CallExpression) return false;
|
|
8544
8916
|
const callee = node.callee;
|
|
8545
|
-
if (callee.type !==
|
|
8917
|
+
if (callee.type !== AST_NODE_TYPES42.MemberExpression) return false;
|
|
8546
8918
|
if (callee.computed) return false;
|
|
8547
|
-
if (callee.property.type !==
|
|
8919
|
+
if (callee.property.type !== AST_NODE_TYPES42.Identifier) return false;
|
|
8548
8920
|
const method = callee.property.name;
|
|
8549
8921
|
if (method !== "parse" && method !== "safeParse") return false;
|
|
8550
8922
|
return looksLikeZodSchema(callee.object);
|
|
8551
8923
|
};
|
|
8552
8924
|
var isFormDataMethodCall = (node) => {
|
|
8553
8925
|
let current = node;
|
|
8554
|
-
if (current.type ===
|
|
8926
|
+
if (current.type === AST_NODE_TYPES42.AwaitExpression) {
|
|
8555
8927
|
current = current.argument;
|
|
8556
8928
|
}
|
|
8557
|
-
if (current.type !==
|
|
8929
|
+
if (current.type !== AST_NODE_TYPES42.CallExpression) return false;
|
|
8558
8930
|
const callee = current.callee;
|
|
8559
|
-
return callee.type ===
|
|
8931
|
+
return callee.type === AST_NODE_TYPES42.MemberExpression && !callee.computed && callee.property.type === AST_NODE_TYPES42.Identifier && callee.property.name === "formData";
|
|
8560
8932
|
};
|
|
8561
8933
|
var require_zod_form_validation_default = createRule({
|
|
8562
8934
|
name: "require-zod-form-validation",
|
|
@@ -8576,14 +8948,14 @@ var require_zod_form_validation_default = createRule({
|
|
|
8576
8948
|
return {};
|
|
8577
8949
|
}
|
|
8578
8950
|
const isFormSourceIdentifier = (node) => {
|
|
8579
|
-
if (node.type !==
|
|
8951
|
+
if (node.type !== AST_NODE_TYPES42.Identifier) return false;
|
|
8580
8952
|
if (/formdata/i.test(node.name)) return true;
|
|
8581
8953
|
let scope = context.sourceCode.getScope(node);
|
|
8582
8954
|
while (scope !== null) {
|
|
8583
8955
|
const variable = scope.set.get(node.name);
|
|
8584
8956
|
if (variable !== void 0 && variable.defs.length === 1) {
|
|
8585
8957
|
const def = variable.defs[0];
|
|
8586
|
-
if (def !== void 0 && def.type === "Variable" && def.node.type ===
|
|
8958
|
+
if (def !== void 0 && def.type === "Variable" && def.node.type === AST_NODE_TYPES42.VariableDeclarator && def.node.init !== null) {
|
|
8587
8959
|
return isFormDataMethodCall(def.node.init);
|
|
8588
8960
|
}
|
|
8589
8961
|
return false;
|
|
@@ -8594,8 +8966,8 @@ var require_zod_form_validation_default = createRule({
|
|
|
8594
8966
|
};
|
|
8595
8967
|
const isFormDataGetCall = (node) => {
|
|
8596
8968
|
const callee = node.callee;
|
|
8597
|
-
if (callee.type !==
|
|
8598
|
-
if (callee.property.type !==
|
|
8969
|
+
if (callee.type !== AST_NODE_TYPES42.MemberExpression) return false;
|
|
8970
|
+
if (callee.property.type !== AST_NODE_TYPES42.Identifier || callee.property.name !== "get") {
|
|
8599
8971
|
return false;
|
|
8600
8972
|
}
|
|
8601
8973
|
return isFormSourceIdentifier(callee.object);
|
|
@@ -8610,11 +8982,11 @@ var require_zod_form_validation_default = createRule({
|
|
|
8610
8982
|
};
|
|
8611
8983
|
const isInstanceofNarrowing = (node) => {
|
|
8612
8984
|
const parent = node.parent;
|
|
8613
|
-
return parent !== null && parent !== void 0 && parent.type ===
|
|
8985
|
+
return parent !== null && parent !== void 0 && parent.type === AST_NODE_TYPES42.BinaryExpression && parent.operator === "instanceof" && parent.left === node;
|
|
8614
8986
|
};
|
|
8615
8987
|
const boundDeclarator = (node) => {
|
|
8616
8988
|
const parent = node.parent;
|
|
8617
|
-
if (parent.type ===
|
|
8989
|
+
if (parent.type === AST_NODE_TYPES42.VariableDeclarator && parent.init === node && parent.id.type === AST_NODE_TYPES42.Identifier) {
|
|
8618
8990
|
return parent;
|
|
8619
8991
|
}
|
|
8620
8992
|
return null;
|
|
@@ -8673,7 +9045,7 @@ var store_insert_requires_on_conflict_default = createRule({
|
|
|
8673
9045
|
});
|
|
8674
9046
|
|
|
8675
9047
|
// src/rules/zod-naming-convention.ts
|
|
8676
|
-
import { AST_NODE_TYPES as
|
|
9048
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES43 } from "@typescript-eslint/utils";
|
|
8677
9049
|
var CONVENTIONS = {
|
|
8678
9050
|
prefix: { test: ZOD_PREFIX_RE, messageId: "zPrefix" },
|
|
8679
9051
|
suffix: { test: ZOD_SUFFIX_RE, messageId: "schemaSuffix" },
|
|
@@ -8698,15 +9070,15 @@ var NON_SCHEMA_TERMINALS = /* @__PURE__ */ new Set([
|
|
|
8698
9070
|
"registry",
|
|
8699
9071
|
"implement"
|
|
8700
9072
|
]);
|
|
8701
|
-
var terminalMethodName = (callee) => !callee.computed && callee.property.type ===
|
|
9073
|
+
var terminalMethodName = (callee) => !callee.computed && callee.property.type === AST_NODE_TYPES43.Identifier ? callee.property.name : null;
|
|
8702
9074
|
var calleeChainStartsWithZ = (node) => {
|
|
8703
9075
|
let current = node;
|
|
8704
|
-
while (current.type ===
|
|
9076
|
+
while (current.type === AST_NODE_TYPES43.MemberExpression) {
|
|
8705
9077
|
const receiver = current.object;
|
|
8706
|
-
if (receiver.type ===
|
|
9078
|
+
if (receiver.type === AST_NODE_TYPES43.Identifier && receiver.name === "z") {
|
|
8707
9079
|
return true;
|
|
8708
9080
|
}
|
|
8709
|
-
if (receiver.type ===
|
|
9081
|
+
if (receiver.type === AST_NODE_TYPES43.CallExpression) {
|
|
8710
9082
|
current = receiver.callee;
|
|
8711
9083
|
continue;
|
|
8712
9084
|
}
|
|
@@ -8751,13 +9123,13 @@ var zod_naming_convention_default = createRule({
|
|
|
8751
9123
|
VariableDeclarator(node) {
|
|
8752
9124
|
const init = node.init;
|
|
8753
9125
|
if (init === null || init === void 0) return;
|
|
8754
|
-
if (init.type !==
|
|
9126
|
+
if (init.type !== AST_NODE_TYPES43.CallExpression) return;
|
|
8755
9127
|
const callee = init.callee;
|
|
8756
|
-
if (callee.type !==
|
|
9128
|
+
if (callee.type !== AST_NODE_TYPES43.MemberExpression) return;
|
|
8757
9129
|
if (!calleeChainStartsWithZ(callee)) return;
|
|
8758
9130
|
const terminal = terminalMethodName(callee);
|
|
8759
9131
|
if (terminal !== null && NON_SCHEMA_TERMINALS.has(terminal)) return;
|
|
8760
|
-
if (node.id.type !==
|
|
9132
|
+
if (node.id.type !== AST_NODE_TYPES43.Identifier) return;
|
|
8761
9133
|
if (test.test(node.id.name)) return;
|
|
8762
9134
|
if (acceptsSchemaWord && CONTAINS_SCHEMA_RE.test(node.id.name)) return;
|
|
8763
9135
|
context.report({
|
|
@@ -8777,6 +9149,54 @@ var renamedRules = {
|
|
|
8777
9149
|
"trailing-value-narration": "no-trailing-value-narration"
|
|
8778
9150
|
};
|
|
8779
9151
|
|
|
9152
|
+
// src/rules/_retired.ts
|
|
9153
|
+
var retiredRules = {
|
|
9154
|
+
"ban-loose-type-guards-in-tests": {
|
|
9155
|
+
removedIn: "5.0.0",
|
|
9156
|
+
reason: "Read at 39 findings with 0 true positives in the #183 corpus audit. Delete the config entry; no replacement."
|
|
9157
|
+
},
|
|
9158
|
+
"no-implicit-attribute-access": {
|
|
9159
|
+
removedIn: "5.0.0",
|
|
9160
|
+
reason: "Read at 50 findings with 0 true positives in the #183 corpus audit. Delete the config entry; no replacement."
|
|
9161
|
+
},
|
|
9162
|
+
"no-sequential-await": {
|
|
9163
|
+
removedIn: "3.0.0",
|
|
9164
|
+
reason: "218 findings, 100% range-contained in core `no-await-in-loop`, which the shipped config already enables. Delete the entry; `no-await-in-loop` covers it."
|
|
9165
|
+
},
|
|
9166
|
+
"no-template-literal-in-log": {
|
|
9167
|
+
removedIn: "2.3.1",
|
|
9168
|
+
reason: "Withdrawn. Delete the config entry; no replacement."
|
|
9169
|
+
},
|
|
9170
|
+
"no-unsafe-cast": {
|
|
9171
|
+
removedIn: "3.0.0",
|
|
9172
|
+
reason: '1,089 findings, matching `@typescript-eslint/consistent-type-assertions` ("never") at the identical line and column with zero residue. Delete the entry; keep that rule enabled.'
|
|
9173
|
+
},
|
|
9174
|
+
"prefer-setup-file-mocks": {
|
|
9175
|
+
removedIn: "5.0.0",
|
|
9176
|
+
reason: "Read at 50 findings with 0 true positives in the #183 corpus audit. Delete the config entry; no replacement."
|
|
9177
|
+
},
|
|
9178
|
+
"prefer-shadcn": {
|
|
9179
|
+
removedIn: "3.0.0",
|
|
9180
|
+
reason: "645 findings, a subset of `react/forbid-elements`; its 24-position residue was all design-system primitives being told not to be the design system. Delete the entry."
|
|
9181
|
+
},
|
|
9182
|
+
"primary-export-file-name": {
|
|
9183
|
+
removedIn: "4.0.0",
|
|
9184
|
+
reason: "Renamed files after one of their exports \u2014 316 findings over 1,966 files sampled 11 harmful / 15 useless / 4 valuable, including telling `next.config.ts` to become `next-config.ts`. Delete the config entry."
|
|
9185
|
+
},
|
|
9186
|
+
"require-parameterized-tests": {
|
|
9187
|
+
removedIn: "4.0.0",
|
|
9188
|
+
reason: "Landed in #153 and never wired up: absent from the `rules` record, every preset, and eslint.strict.mjs. Nothing to migrate."
|
|
9189
|
+
},
|
|
9190
|
+
"require-schema-validate-search": {
|
|
9191
|
+
removedIn: "3.0.0",
|
|
9192
|
+
reason: "14 findings, all matched line-and-column by `@typescript-eslint/consistent-type-assertions`. Delete the entry."
|
|
9193
|
+
},
|
|
9194
|
+
"single-public-export": {
|
|
9195
|
+
removedIn: "3.0.0",
|
|
9196
|
+
reason: "3 findings, all also reported by the then-live `primary-export-file-name` (itself withdrawn in 4.0.0). Delete the entry."
|
|
9197
|
+
}
|
|
9198
|
+
};
|
|
9199
|
+
|
|
8780
9200
|
// src/index.ts
|
|
8781
9201
|
var rules = {
|
|
8782
9202
|
"enforce-file-structure": enforce_file_structure_default,
|
|
@@ -8808,6 +9228,7 @@ var rules = {
|
|
|
8808
9228
|
"no-string-concat-in-loop": no_string_concat_in_loop_default,
|
|
8809
9229
|
"no-tautological-expect": no_tautological_expect_default,
|
|
8810
9230
|
"no-trailing-value-narration": no_trailing_value_narration_default,
|
|
9231
|
+
"no-declaration-comment-wall": no_declaration_comment_wall_default,
|
|
8811
9232
|
"no-type-member-comment-wall": no_type_member_comment_wall_default,
|
|
8812
9233
|
"no-unnecessary-use-client": no_unnecessary_use_client_default,
|
|
8813
9234
|
"no-unsafe-mock-casting": no_unsafe_mock_casting_default,
|
|
@@ -8833,7 +9254,7 @@ var rules = {
|
|
|
8833
9254
|
};
|
|
8834
9255
|
var meta = {
|
|
8835
9256
|
name: "@sarj/eslint-plugin",
|
|
8836
|
-
version: "
|
|
9257
|
+
version: "8.0.0"
|
|
8837
9258
|
};
|
|
8838
9259
|
var renames = renamedRules;
|
|
8839
9260
|
var deprecatedAliases = Object.fromEntries(
|
|
@@ -8882,6 +9303,7 @@ var recommendedRules = {
|
|
|
8882
9303
|
"@sarj/no-string-concat-in-loop": "warn",
|
|
8883
9304
|
"@sarj/no-tautological-expect": "warn",
|
|
8884
9305
|
"@sarj/no-trailing-value-narration": "warn",
|
|
9306
|
+
"@sarj/no-declaration-comment-wall": "warn",
|
|
8885
9307
|
"@sarj/no-type-member-comment-wall": "warn",
|
|
8886
9308
|
"@sarj/no-unnecessary-use-client": "warn",
|
|
8887
9309
|
"@sarj/no-unsafe-mock-casting": "warn",
|
|
@@ -8935,6 +9357,7 @@ var strictRules = {
|
|
|
8935
9357
|
"@sarj/no-string-concat-in-loop": "error",
|
|
8936
9358
|
"@sarj/no-tautological-expect": "error",
|
|
8937
9359
|
"@sarj/no-trailing-value-narration": "error",
|
|
9360
|
+
"@sarj/no-declaration-comment-wall": "error",
|
|
8938
9361
|
"@sarj/no-type-member-comment-wall": "error",
|
|
8939
9362
|
"@sarj/no-unnecessary-use-client": "error",
|
|
8940
9363
|
"@sarj/no-unsafe-mock-casting": "error",
|
|
@@ -8961,6 +9384,9 @@ var strictRules = {
|
|
|
8961
9384
|
var plugin = {
|
|
8962
9385
|
meta,
|
|
8963
9386
|
rules: allRules,
|
|
9387
|
+
// Withdrawn names travel WITH the plugin so a consumer's migration script and
|
|
9388
|
+
// this repo's gates read one map, not two. See src/rules/_retired.ts.
|
|
9389
|
+
retiredRules,
|
|
8964
9390
|
configs: {
|
|
8965
9391
|
recommended: {},
|
|
8966
9392
|
strict: {}
|
|
@@ -8981,6 +9407,7 @@ export {
|
|
|
8981
9407
|
index_default as default,
|
|
8982
9408
|
recommendedRules,
|
|
8983
9409
|
renamedRules,
|
|
9410
|
+
retiredRules,
|
|
8984
9411
|
rules,
|
|
8985
9412
|
strictRules
|
|
8986
9413
|
};
|