@sarj/eslint-plugin 4.2.0 → 5.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 +6 -3
- package/dist/index.cjs +1342 -894
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +46 -26
- package/dist/index.d.ts +46 -26
- package/dist/index.js +1311 -863
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -35,7 +35,7 @@ __export(index_exports, {
|
|
|
35
35
|
});
|
|
36
36
|
module.exports = __toCommonJS(index_exports);
|
|
37
37
|
|
|
38
|
-
// src/rules/
|
|
38
|
+
// src/rules/enforce-file-structure.ts
|
|
39
39
|
var import_utils = require("@typescript-eslint/utils");
|
|
40
40
|
|
|
41
41
|
// src/rules/_paths.ts
|
|
@@ -61,63 +61,27 @@ function isScriptFile(filename) {
|
|
|
61
61
|
return SCRIPT_FILE_RE.test(filename);
|
|
62
62
|
}
|
|
63
63
|
|
|
64
|
-
// src/rules/ban-loose-type-guards-in-tests.ts
|
|
65
|
-
var ban_loose_type_guards_in_tests_default = import_utils.ESLintUtils.RuleCreator(
|
|
66
|
-
(name) => `https://github.com/sarj-ai/standards/blob/main/packages/typescript/src/rules/${name}.ts`
|
|
67
|
-
)({
|
|
68
|
-
name: "ban-loose-type-guards-in-tests",
|
|
69
|
-
meta: {
|
|
70
|
-
type: "problem",
|
|
71
|
-
docs: {
|
|
72
|
-
description: "Disallow loose type guards (`typeof` and `in`) in test files. Enforce Zod schemas or strict matchers for type validation."
|
|
73
|
-
},
|
|
74
|
-
schema: [],
|
|
75
|
-
messages: {
|
|
76
|
-
banLooseTypeGuardsInTests: "Do not use `typeof` or `in` for type validation in tests. Use Zod schemas or strict assertion matchers instead."
|
|
77
|
-
}
|
|
78
|
-
},
|
|
79
|
-
defaultOptions: [],
|
|
80
|
-
create(context) {
|
|
81
|
-
if (!isTestFile(context.filename)) {
|
|
82
|
-
return {};
|
|
83
|
-
}
|
|
84
|
-
return {
|
|
85
|
-
UnaryExpression(node) {
|
|
86
|
-
if (node.operator === "typeof") {
|
|
87
|
-
context.report({ node, messageId: "banLooseTypeGuardsInTests" });
|
|
88
|
-
}
|
|
89
|
-
},
|
|
90
|
-
BinaryExpression(node) {
|
|
91
|
-
if (node.operator === "in") {
|
|
92
|
-
context.report({ node, messageId: "banLooseTypeGuardsInTests" });
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
};
|
|
96
|
-
}
|
|
97
|
-
});
|
|
98
|
-
|
|
99
64
|
// src/rules/enforce-file-structure.ts
|
|
100
|
-
var import_utils2 = require("@typescript-eslint/utils");
|
|
101
65
|
var classifyStatement = (statement) => {
|
|
102
66
|
switch (statement.type) {
|
|
103
|
-
case
|
|
67
|
+
case import_utils.AST_NODE_TYPES.ImportDeclaration:
|
|
104
68
|
return "import";
|
|
105
|
-
case
|
|
69
|
+
case import_utils.AST_NODE_TYPES.ExportAllDeclaration:
|
|
106
70
|
return "reexport";
|
|
107
|
-
case
|
|
71
|
+
case import_utils.AST_NODE_TYPES.ExportNamedDeclaration:
|
|
108
72
|
return statement.declaration === null ? "reexport" : "body";
|
|
109
73
|
default:
|
|
110
74
|
return "body";
|
|
111
75
|
}
|
|
112
76
|
};
|
|
113
|
-
var isStringDirective = (statement) => statement.type ===
|
|
77
|
+
var isStringDirective = (statement) => statement.type === import_utils.AST_NODE_TYPES.ExpressionStatement && statement.expression.type === import_utils.AST_NODE_TYPES.Literal && typeof statement.expression.value === "string" && statement.expression.value.startsWith("use ");
|
|
114
78
|
var isUseServerDirective = (statement) => {
|
|
115
|
-
if (statement.type !==
|
|
79
|
+
if (statement.type !== import_utils.AST_NODE_TYPES.ExpressionStatement) return false;
|
|
116
80
|
const expr = statement.expression;
|
|
117
|
-
if (expr.type !==
|
|
81
|
+
if (expr.type !== import_utils.AST_NODE_TYPES.Literal) return false;
|
|
118
82
|
return expr.value === "use server";
|
|
119
83
|
};
|
|
120
|
-
var enforce_file_structure_default =
|
|
84
|
+
var enforce_file_structure_default = import_utils.ESLintUtils.RuleCreator(
|
|
121
85
|
(name) => `https://github.com/sarj-ai/linting/blob/main/packages/typescript/src/rules/${name}.ts`
|
|
122
86
|
)({
|
|
123
87
|
name: "enforce-file-structure",
|
|
@@ -177,7 +141,7 @@ var enforce_file_structure_default = import_utils2.ESLintUtils.RuleCreator(
|
|
|
177
141
|
});
|
|
178
142
|
|
|
179
143
|
// src/rules/no-client-side-data-fetching.ts
|
|
180
|
-
var
|
|
144
|
+
var import_utils2 = require("@typescript-eslint/utils");
|
|
181
145
|
var FETCH_LIBS = /* @__PURE__ */ new Set(["axios", "ky", "superagent"]);
|
|
182
146
|
var HTTP_METHOD_NAMES = /* @__PURE__ */ new Set([
|
|
183
147
|
"get",
|
|
@@ -201,25 +165,25 @@ var ANALYTICS_SEGMENTS = /* @__PURE__ */ new Set([
|
|
|
201
165
|
]);
|
|
202
166
|
function isEffectHookCall(node) {
|
|
203
167
|
const callee = node.callee;
|
|
204
|
-
if (callee.type ===
|
|
168
|
+
if (callee.type === import_utils2.AST_NODE_TYPES.Identifier) {
|
|
205
169
|
return callee.name === "useEffect" || callee.name === "useLayoutEffect";
|
|
206
170
|
}
|
|
207
|
-
if (callee.type ===
|
|
171
|
+
if (callee.type === import_utils2.AST_NODE_TYPES.MemberExpression && !callee.computed && callee.object.type === import_utils2.AST_NODE_TYPES.Identifier && callee.object.name === "React" && callee.property.type === import_utils2.AST_NODE_TYPES.Identifier) {
|
|
208
172
|
return callee.property.name === "useEffect" || callee.property.name === "useLayoutEffect";
|
|
209
173
|
}
|
|
210
174
|
return false;
|
|
211
175
|
}
|
|
212
176
|
function readMethodProperty(optionsArg) {
|
|
213
|
-
if (!optionsArg || optionsArg.type !==
|
|
177
|
+
if (!optionsArg || optionsArg.type !== import_utils2.AST_NODE_TYPES.ObjectExpression) {
|
|
214
178
|
return null;
|
|
215
179
|
}
|
|
216
180
|
for (const prop of optionsArg.properties) {
|
|
217
|
-
if (prop.type !==
|
|
181
|
+
if (prop.type !== import_utils2.AST_NODE_TYPES.Property) continue;
|
|
218
182
|
if (prop.computed) continue;
|
|
219
183
|
const key = prop.key;
|
|
220
|
-
const matchesMethodKey = key.type ===
|
|
184
|
+
const matchesMethodKey = key.type === import_utils2.AST_NODE_TYPES.Identifier && key.name === "method" || key.type === import_utils2.AST_NODE_TYPES.Literal && key.value === "method";
|
|
221
185
|
if (!matchesMethodKey) continue;
|
|
222
|
-
if (prop.value.type ===
|
|
186
|
+
if (prop.value.type === import_utils2.AST_NODE_TYPES.Literal && typeof prop.value.value === "string") {
|
|
223
187
|
return prop.value.value.toUpperCase();
|
|
224
188
|
}
|
|
225
189
|
return null;
|
|
@@ -228,23 +192,23 @@ function readMethodProperty(optionsArg) {
|
|
|
228
192
|
}
|
|
229
193
|
function isFetchCall(node) {
|
|
230
194
|
const callee = node.callee;
|
|
231
|
-
if (callee.type ===
|
|
195
|
+
if (callee.type === import_utils2.AST_NODE_TYPES.Identifier && callee.name === "fetch") {
|
|
232
196
|
const method = readMethodProperty(node.arguments[1]);
|
|
233
197
|
if (method !== null && method !== "GET") {
|
|
234
198
|
return false;
|
|
235
199
|
}
|
|
236
200
|
return true;
|
|
237
201
|
}
|
|
238
|
-
if (callee.type ===
|
|
202
|
+
if (callee.type === import_utils2.AST_NODE_TYPES.MemberExpression && !callee.computed && callee.object.type === import_utils2.AST_NODE_TYPES.Identifier && FETCH_LIBS.has(callee.object.name) && callee.property.type === import_utils2.AST_NODE_TYPES.Identifier) {
|
|
239
203
|
return HTTP_METHOD_NAMES.has(callee.property.name);
|
|
240
204
|
}
|
|
241
|
-
if (callee.type ===
|
|
205
|
+
if (callee.type === import_utils2.AST_NODE_TYPES.Identifier && (callee.name === "axios" || callee.name === "ky")) {
|
|
242
206
|
const firstArg = node.arguments[0];
|
|
243
207
|
const secondArg = node.arguments[1];
|
|
244
208
|
let configArg;
|
|
245
|
-
if (firstArg?.type ===
|
|
209
|
+
if (firstArg?.type === import_utils2.AST_NODE_TYPES.ObjectExpression) {
|
|
246
210
|
configArg = firstArg;
|
|
247
|
-
} else if (secondArg?.type ===
|
|
211
|
+
} else if (secondArg?.type === import_utils2.AST_NODE_TYPES.ObjectExpression) {
|
|
248
212
|
configArg = secondArg;
|
|
249
213
|
}
|
|
250
214
|
const method = readMethodProperty(configArg);
|
|
@@ -258,13 +222,13 @@ function isFetchCall(node) {
|
|
|
258
222
|
function extractUrlString(node) {
|
|
259
223
|
const firstArg = node.arguments[0];
|
|
260
224
|
if (!firstArg) return "";
|
|
261
|
-
if (firstArg.type ===
|
|
225
|
+
if (firstArg.type === import_utils2.AST_NODE_TYPES.Literal && typeof firstArg.value === "string") {
|
|
262
226
|
return firstArg.value;
|
|
263
227
|
}
|
|
264
|
-
if (firstArg.type ===
|
|
228
|
+
if (firstArg.type === import_utils2.AST_NODE_TYPES.TemplateLiteral) {
|
|
265
229
|
return firstArg.quasis.map((q) => q.value.cooked).join("");
|
|
266
230
|
}
|
|
267
|
-
if (firstArg.type ===
|
|
231
|
+
if (firstArg.type === import_utils2.AST_NODE_TYPES.Identifier) {
|
|
268
232
|
return firstArg.name;
|
|
269
233
|
}
|
|
270
234
|
return "";
|
|
@@ -274,7 +238,7 @@ function isAnalyticsCall(node) {
|
|
|
274
238
|
if (url === "") return false;
|
|
275
239
|
return url.split(/[/.]/).some((segment) => ANALYTICS_SEGMENTS.has(segment));
|
|
276
240
|
}
|
|
277
|
-
var no_client_side_data_fetching_default =
|
|
241
|
+
var no_client_side_data_fetching_default = import_utils2.ESLintUtils.RuleCreator(
|
|
278
242
|
(name) => `https://github.com/sarj-ai/linting/blob/main/packages/typescript/src/rules/${name}.ts`
|
|
279
243
|
)({
|
|
280
244
|
name: "no-client-side-data-fetching",
|
|
@@ -312,10 +276,10 @@ var no_client_side_data_fetching_default = import_utils3.ESLintUtils.RuleCreator
|
|
|
312
276
|
});
|
|
313
277
|
|
|
314
278
|
// src/rules/no-comment-cruft.ts
|
|
315
|
-
var
|
|
279
|
+
var import_utils4 = require("@typescript-eslint/utils");
|
|
316
280
|
|
|
317
281
|
// src/rules/_comments.ts
|
|
318
|
-
var
|
|
282
|
+
var import_utils3 = require("@typescript-eslint/utils");
|
|
319
283
|
var REF_RE = /https?:\/\/|\bRFC[- ]?\d+|\bPEP[- ]?\d+|\bCVE-\d{4}|\b(?!UTF-|SHA-|ISO-|AES-|CRC-|MD-|PCM-|EOF-|API-|BASE-)[A-Z][A-Z0-9]{1,9}-\d[A-Z0-9]{0,5}\b|(?<![&\w])#\d{2,6}\b|@[a-z][\w.-]*\.(?:us|com|ai|io|net|org|dev)\b/;
|
|
320
284
|
var VERSION_RE = /(?:>=|<=|==|<|>)\s*v?\d+\.\d+|\bv\d+\.\d+|\b(?:since|until|as of)\s+(?:v?\d+\.\d+|Python\s*\d)/i;
|
|
321
285
|
var UNITS_RE = /[~<>]?\d+(?:\.\d+)?\s?(?:ms|s\b|sec\b|seconds?\b|min\b|minutes?\b|hours?\b|days?\b|KB|MB|MiB|GiB|kHz|Hz|bytes?\b|bit\b|-bit\b|%|px\b|rps\b|qps\b)|\b[1-5]xx\b|\b(?:301|302|304|307|308|400|401|403|404|405|409|410|412|422|425|429|500|501|502|503|504)\b/;
|
|
@@ -401,10 +365,10 @@ var NARRATION_MAX_WORDS = 6;
|
|
|
401
365
|
var NARRATION_MIN_CONTENT = 1;
|
|
402
366
|
var TOKEN_PLURAL_MIN = 4;
|
|
403
367
|
var RESTATABLE_STATEMENTS = /* @__PURE__ */ new Set([
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
368
|
+
import_utils3.AST_NODE_TYPES.ExpressionStatement,
|
|
369
|
+
import_utils3.AST_NODE_TYPES.ReturnStatement,
|
|
370
|
+
import_utils3.AST_NODE_TYPES.ThrowStatement,
|
|
371
|
+
import_utils3.AST_NODE_TYPES.VariableDeclaration
|
|
408
372
|
]);
|
|
409
373
|
var NARRATION_VERB_RE = /^(?:add|append|assign|build|calculate|call|check|clear|close|compute|convert|copy|count|create|declare|decrement|define|delete|extract|fetch|filter|find|format|generate|get|handle|increment|init|initialise|initialize|insert|iterate|join|load|log|loop|make|map|merge|open|parse|print|process|push|read|remove|render|reset|return|save|send|set|setup|sort|split|start|stop|store|update|validate|wrap|write)(?:s|es|d|ed|ing)?$/i;
|
|
410
374
|
var NARRATION_STOPWORDS = /* @__PURE__ */ new Set([
|
|
@@ -469,19 +433,19 @@ function headTokens(source) {
|
|
|
469
433
|
function isTrivialInitializer(node) {
|
|
470
434
|
return node.declarations.every((declarator) => {
|
|
471
435
|
const init = declarator.init;
|
|
472
|
-
if (init == null || init.type ===
|
|
473
|
-
return init.type ===
|
|
436
|
+
if (init == null || init.type === import_utils3.AST_NODE_TYPES.Literal) return true;
|
|
437
|
+
return init.type === import_utils3.AST_NODE_TYPES.ArrayExpression && init.elements.length === 0 || init.type === import_utils3.AST_NODE_TYPES.ObjectExpression && init.properties.length === 0;
|
|
474
438
|
});
|
|
475
439
|
}
|
|
476
440
|
function restatableStatementBelow(comment, sourceCode) {
|
|
477
441
|
const token = sourceCode.getTokenAfter(comment, { includeComments: false });
|
|
478
442
|
if (token === null || token.loc.start.line !== comment.loc.end.line + 1) return null;
|
|
479
|
-
for (let node = sourceCode.getNodeByRangeIndex(token.range[0]); node != null && node.type !==
|
|
443
|
+
for (let node = sourceCode.getNodeByRangeIndex(token.range[0]); node != null && node.type !== import_utils3.AST_NODE_TYPES.Program; node = node.parent) {
|
|
480
444
|
if (!RESTATABLE_STATEMENTS.has(node.type)) continue;
|
|
481
445
|
if (node.loc.start.line !== token.loc.start.line || node.loc.end.line !== node.loc.start.line) {
|
|
482
446
|
return null;
|
|
483
447
|
}
|
|
484
|
-
if (node.type ===
|
|
448
|
+
if (node.type === import_utils3.AST_NODE_TYPES.VariableDeclaration && isTrivialInitializer(node)) {
|
|
485
449
|
return null;
|
|
486
450
|
}
|
|
487
451
|
return sourceCode.getText(node);
|
|
@@ -576,7 +540,8 @@ var DUMMY_TRANSLATION_RE = /^(?:increment|return|returns|get|gets|set\b(?! up\b)
|
|
|
576
540
|
var DIAGRAM_ARROW_RE = /[-=~]{2,}>|<[-=~]{2,}/;
|
|
577
541
|
var CODE_KEYWORD_RE = /^(import |export |const |let |var |function\b|class |interface |type \w|enum |return\b|throw |await |async |if\s*\(|for\s*\(|while\s*\(|switch\s*\(|new |console\.)/;
|
|
578
542
|
var CODE_TAIL_RE = /[;{}()]\s*$|=>\s*$|,\s*$/;
|
|
579
|
-
var
|
|
543
|
+
var ASSIGN_RE = /^[A-Za-z_$][\w.$[\]]*\s*(?:=(?![=>])|\+=|-=|\*=)\s*\S.*[;)}\]]\s*$/;
|
|
544
|
+
var CALL_RE = /^[A-Za-z_$][\w.$]*\([^)]*\)\s*;?\s*$/;
|
|
580
545
|
var PSEUDOCODE_RE = /%\w+%|\[opt\]|(?:^|\s)<[A-Za-z]\w*>|…|\.\.\./;
|
|
581
546
|
function stripCommentMarker(line) {
|
|
582
547
|
return line.replace(/^\s*\/{1,2}/, "").replace(/^\s*\*+/, "").trim();
|
|
@@ -590,11 +555,12 @@ function isBanner(text) {
|
|
|
590
555
|
if (BANNER_FULL_RE.test(t) || isRegionMarker(t)) return true;
|
|
591
556
|
return BANNER_RUN_RE.test(t) && !DIAGRAM_ARROW_RE.test(t);
|
|
592
557
|
}
|
|
593
|
-
function looksLikeCode(text) {
|
|
558
|
+
function looksLikeCode(text, allowCall = true) {
|
|
594
559
|
const t = text.trim();
|
|
595
560
|
if (!t) return false;
|
|
596
561
|
if (CODE_KEYWORD_RE.test(t) && CODE_TAIL_RE.test(t)) return true;
|
|
597
|
-
|
|
562
|
+
if (ASSIGN_RE.test(t)) return true;
|
|
563
|
+
return allowCall && CALL_RE.test(t);
|
|
598
564
|
}
|
|
599
565
|
function hasPseudocode(text) {
|
|
600
566
|
return PSEUDOCODE_RE.test(text);
|
|
@@ -612,20 +578,24 @@ function isProse(text) {
|
|
|
612
578
|
}
|
|
613
579
|
return false;
|
|
614
580
|
}
|
|
615
|
-
var JUSTIFICATION_RE = /\b(?:because|since|until|due to|so that|otherwise|which is why|in order to|to avoid|to work around|to prevent)\b/i;
|
|
581
|
+
var JUSTIFICATION_RE = /\b(?:because|since|until|due to|so that|so we|so it|so the|otherwise|which is why|in order to|to avoid|to work around|to prevent|backwards? compat(?:ibility)?|for compatibility)\b/i;
|
|
582
|
+
function restatesWholeStatement(body, statement) {
|
|
583
|
+
return statement !== null && restatesStatementHead(body, statement.replaceAll("(", " "));
|
|
584
|
+
}
|
|
616
585
|
function isRedundantNarration(body, statementBelow, standalone, isolatedEnumeration, nested) {
|
|
617
586
|
const t = body.trim();
|
|
618
587
|
if (!t || looksLikeCode(t) || hasPseudocode(t)) return false;
|
|
619
588
|
if (standalone) {
|
|
620
|
-
|
|
621
|
-
if (
|
|
589
|
+
const justified = JUSTIFICATION_RE.test(t);
|
|
590
|
+
if (STEP_NARRATION_RE.test(t) && !justified) return true;
|
|
591
|
+
if (META_COMMENTARY_RE.test(t) && !justified) return true;
|
|
622
592
|
if (HELPER_OPENER_RE.test(t) || LETS_RE.test(t)) return true;
|
|
623
593
|
const words = t.split(/\s+/);
|
|
624
|
-
if (words.length <= 4 && DUMMY_TRANSLATION_RE.test(t) && !/[():=]/.test(t)) {
|
|
594
|
+
if (words.length > 1 && words.length <= 4 && DUMMY_TRANSLATION_RE.test(t) && !/[():=]/.test(t)) {
|
|
625
595
|
const lowerT = t.toLowerCase();
|
|
626
596
|
const rationaleWords = ["when", "because", "if", "so that", "due to", "for", "instead of", "to prevent", "to avoid", "only"];
|
|
627
|
-
if (!rationaleWords.some((w) => lowerT.includes(w))) {
|
|
628
|
-
|
|
597
|
+
if (!rationaleWords.some((w) => lowerT.includes(w)) && restatesWholeStatement(t, statementBelow)) {
|
|
598
|
+
return true;
|
|
629
599
|
}
|
|
630
600
|
}
|
|
631
601
|
if (!nested && isSectionLabel(t)) return true;
|
|
@@ -634,13 +604,17 @@ function isRedundantNarration(body, statementBelow, standalone, isolatedEnumerat
|
|
|
634
604
|
return restatesStatementHead(t, statementBelow);
|
|
635
605
|
}
|
|
636
606
|
var STATEMENT_CONTAINERS = /* @__PURE__ */ new Set([
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
607
|
+
import_utils4.AST_NODE_TYPES.Program,
|
|
608
|
+
import_utils4.AST_NODE_TYPES.BlockStatement,
|
|
609
|
+
import_utils4.AST_NODE_TYPES.ClassBody,
|
|
610
|
+
import_utils4.AST_NODE_TYPES.StaticBlock,
|
|
611
|
+
import_utils4.AST_NODE_TYPES.SwitchCase,
|
|
612
|
+
import_utils4.AST_NODE_TYPES.TSModuleBlock,
|
|
613
|
+
import_utils4.AST_NODE_TYPES.TSInterfaceBody
|
|
614
|
+
]);
|
|
615
|
+
var TYPE_MEMBER_CONTAINERS = /* @__PURE__ */ new Set([
|
|
616
|
+
import_utils4.AST_NODE_TYPES.TSInterfaceBody,
|
|
617
|
+
import_utils4.AST_NODE_TYPES.TSTypeLiteral
|
|
644
618
|
]);
|
|
645
619
|
function runCitesAReference(comments, index) {
|
|
646
620
|
for (let i = index; i >= 0; i--) {
|
|
@@ -669,10 +643,10 @@ function hasIllustrationLeadInAbove(comments, index) {
|
|
|
669
643
|
}
|
|
670
644
|
return false;
|
|
671
645
|
}
|
|
672
|
-
function hasCommentedOutCode(texts, precedingProse) {
|
|
646
|
+
function hasCommentedOutCode(texts, precedingProse, allowCall) {
|
|
673
647
|
for (let i = 0; i < texts.length; i++) {
|
|
674
648
|
const line = texts[i];
|
|
675
|
-
if (line === void 0 || !looksLikeCode(line) || hasPseudocode(line)) {
|
|
649
|
+
if (line === void 0 || !looksLikeCode(line, allowCall) || hasPseudocode(line)) {
|
|
676
650
|
continue;
|
|
677
651
|
}
|
|
678
652
|
const prev = i > 0 ? texts[i - 1] : void 0;
|
|
@@ -681,7 +655,7 @@ function hasCommentedOutCode(texts, precedingProse) {
|
|
|
681
655
|
}
|
|
682
656
|
return false;
|
|
683
657
|
}
|
|
684
|
-
var no_comment_cruft_default =
|
|
658
|
+
var no_comment_cruft_default = import_utils4.ESLintUtils.RuleCreator(
|
|
685
659
|
(name) => `https://github.com/sarj-ai/standards/blob/main/packages/typescript/src/rules/${name}.ts`
|
|
686
660
|
)({
|
|
687
661
|
name: "no-comment-cruft",
|
|
@@ -766,7 +740,9 @@ var no_comment_cruft_default = import_utils5.ESLintUtils.RuleCreator(
|
|
|
766
740
|
}
|
|
767
741
|
const prev = comments[i - 1];
|
|
768
742
|
const precedingProse = prev !== void 0 && prev.type === "Line" && prev.loc.end.line === comment.loc.start.line - 1 && isProse(stripCommentMarker(prev.value));
|
|
769
|
-
|
|
743
|
+
const container = sourceCode.getNodeByRangeIndex(comment.range[0]);
|
|
744
|
+
const inTypeMembers = container !== null && TYPE_MEMBER_CONTAINERS.has(container.type);
|
|
745
|
+
if (hasCommentedOutCode(texts, precedingProse, !inTypeMembers) && !hasIllustrationLeadInAbove(comments, i)) {
|
|
770
746
|
context.report({ node: comment, messageId: "commentedOutCode" });
|
|
771
747
|
continue;
|
|
772
748
|
}
|
|
@@ -774,7 +750,6 @@ var no_comment_cruft_default = import_utils5.ESLintUtils.RuleCreator(
|
|
|
774
750
|
const body = texts[0];
|
|
775
751
|
const statement = restatableStatementBelow(comment, sourceCode);
|
|
776
752
|
const standalone = !isInsideCommentRun(comments, i);
|
|
777
|
-
const container = sourceCode.getNodeByRangeIndex(comment.range[0]);
|
|
778
753
|
const nested = container !== null && !STATEMENT_CONTAINERS.has(container.type);
|
|
779
754
|
if (body !== void 0 && !runCitesAReference(comments, i) && isRedundantNarration(body, statement, standalone, enumerated.length === 1, nested)) {
|
|
780
755
|
context.report({ node: comment, messageId: "redundantNarration" });
|
|
@@ -788,7 +763,7 @@ var no_comment_cruft_default = import_utils5.ESLintUtils.RuleCreator(
|
|
|
788
763
|
});
|
|
789
764
|
|
|
790
765
|
// src/rules/no-enum.ts
|
|
791
|
-
var
|
|
766
|
+
var import_utils5 = require("@typescript-eslint/utils");
|
|
792
767
|
var DEFAULT_IGNORE_PATTERNS = [
|
|
793
768
|
/[\\/]generated[\\/]/,
|
|
794
769
|
/[\\/]openapi-gen[\\/]/,
|
|
@@ -808,7 +783,7 @@ function hasGeneratedMarker(sourceText) {
|
|
|
808
783
|
const head = sourceText.slice(0, 1024);
|
|
809
784
|
return /@generated\b/.test(head);
|
|
810
785
|
}
|
|
811
|
-
var no_enum_default =
|
|
786
|
+
var no_enum_default = import_utils5.ESLintUtils.RuleCreator(
|
|
812
787
|
(name) => `https://github.com/sarj-ai/linting/blob/main/packages/typescript/src/rules/${name}.ts`
|
|
813
788
|
)({
|
|
814
789
|
name: "no-enum",
|
|
@@ -859,7 +834,7 @@ var no_enum_default = import_utils6.ESLintUtils.RuleCreator(
|
|
|
859
834
|
});
|
|
860
835
|
|
|
861
836
|
// src/rules/no-insecure-random-id.ts
|
|
862
|
-
var
|
|
837
|
+
var import_utils6 = require("@typescript-eslint/utils");
|
|
863
838
|
var STRONG_SECURITY_PATTERN = /token|secret|csrf|password|passwd|apikey|api[-_]?key|nonce|salt|uuid|authid/i;
|
|
864
839
|
var NON_SECURITY_ID_PATTERN = /temp|tmp|cache|correlation|request|req|trace|execution|dev|hmr|mock|test|perf|marker/i;
|
|
865
840
|
var PATH_OR_DOM_MARKER = /[\\/#]|\.[A-Za-z0-9]/;
|
|
@@ -1000,7 +975,7 @@ function isConcatenatedIntoPathOrDomId(node) {
|
|
|
1000
975
|
collectStaticStringParts(top, parts);
|
|
1001
976
|
return parts.some((part) => PATH_OR_DOM_MARKER.test(part));
|
|
1002
977
|
}
|
|
1003
|
-
var no_insecure_random_id_default =
|
|
978
|
+
var no_insecure_random_id_default = import_utils6.ESLintUtils.RuleCreator(
|
|
1004
979
|
(name) => `https://github.com/sarj-ai/linting/blob/main/packages/typescript/src/rules/${name}.ts`
|
|
1005
980
|
)({
|
|
1006
981
|
name: "no-insecure-random-id",
|
|
@@ -1044,7 +1019,7 @@ var no_insecure_random_id_default = import_utils7.ESLintUtils.RuleCreator(
|
|
|
1044
1019
|
});
|
|
1045
1020
|
|
|
1046
1021
|
// src/rules/no-json-stringify-error.ts
|
|
1047
|
-
var
|
|
1022
|
+
var import_utils7 = require("@typescript-eslint/utils");
|
|
1048
1023
|
var ERROR_NAME_PATTERN = /^(e|err|error|ex|exc)$/i;
|
|
1049
1024
|
var ERROR_PROP_PATTERN = /^(cause|lastError|error|err|exception|originalError|innerError)$/i;
|
|
1050
1025
|
var SAFE_STRING_PROPS = /* @__PURE__ */ new Set(["message", "stack", "name"]);
|
|
@@ -1178,7 +1153,7 @@ function isGuardedByInstanceofError(node, argExpr, sourceCode) {
|
|
|
1178
1153
|
function isJsonStringify(callee) {
|
|
1179
1154
|
return callee.type === "MemberExpression" && !callee.computed && callee.object.type === "Identifier" && callee.object.name === "JSON" && callee.property.type === "Identifier" && callee.property.name === "stringify";
|
|
1180
1155
|
}
|
|
1181
|
-
var no_json_stringify_error_default =
|
|
1156
|
+
var no_json_stringify_error_default = import_utils7.ESLintUtils.RuleCreator(
|
|
1182
1157
|
(name) => `https://github.com/sarj-ai/linting/blob/main/packages/typescript/src/rules/${name}.ts`
|
|
1183
1158
|
)({
|
|
1184
1159
|
name: "no-json-stringify-error",
|
|
@@ -1228,10 +1203,10 @@ var no_json_stringify_error_default = import_utils8.ESLintUtils.RuleCreator(
|
|
|
1228
1203
|
});
|
|
1229
1204
|
|
|
1230
1205
|
// src/rules/no-log-only-catch.ts
|
|
1231
|
-
var
|
|
1206
|
+
var import_utils9 = require("@typescript-eslint/utils");
|
|
1232
1207
|
|
|
1233
1208
|
// src/rules/_logging.ts
|
|
1234
|
-
var
|
|
1209
|
+
var import_utils8 = require("@typescript-eslint/utils");
|
|
1235
1210
|
var LOG_METHODS = /* @__PURE__ */ new Set([
|
|
1236
1211
|
"debug",
|
|
1237
1212
|
"info",
|
|
@@ -1333,12 +1308,92 @@ function createLogMatcher(options = {}) {
|
|
|
1333
1308
|
}
|
|
1334
1309
|
|
|
1335
1310
|
// src/rules/no-log-only-catch.ts
|
|
1336
|
-
var
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1311
|
+
var BENCHMARK_DIR_RE = /(?:^|[\\/])benchmarks?[\\/]/;
|
|
1312
|
+
var SINGLE_STATEMENT_HOSTS = /* @__PURE__ */ new Set([
|
|
1313
|
+
import_utils9.AST_NODE_TYPES.DoWhileStatement,
|
|
1314
|
+
import_utils9.AST_NODE_TYPES.ForInStatement,
|
|
1315
|
+
import_utils9.AST_NODE_TYPES.ForOfStatement,
|
|
1316
|
+
import_utils9.AST_NODE_TYPES.ForStatement,
|
|
1317
|
+
import_utils9.AST_NODE_TYPES.IfStatement,
|
|
1318
|
+
import_utils9.AST_NODE_TYPES.WhileStatement
|
|
1319
|
+
]);
|
|
1320
|
+
var FUNCTION_TYPES = /* @__PURE__ */ new Set([
|
|
1321
|
+
import_utils9.AST_NODE_TYPES.ArrowFunctionExpression,
|
|
1322
|
+
import_utils9.AST_NODE_TYPES.FunctionDeclaration,
|
|
1323
|
+
import_utils9.AST_NODE_TYPES.FunctionExpression
|
|
1324
|
+
]);
|
|
1325
|
+
function statementSlot(node) {
|
|
1326
|
+
const parent = node.parent;
|
|
1327
|
+
if (parent === void 0) return null;
|
|
1328
|
+
let list;
|
|
1329
|
+
switch (parent.type) {
|
|
1330
|
+
case import_utils9.AST_NODE_TYPES.BlockStatement:
|
|
1331
|
+
case import_utils9.AST_NODE_TYPES.Program:
|
|
1332
|
+
case import_utils9.AST_NODE_TYPES.StaticBlock:
|
|
1333
|
+
list = parent.body;
|
|
1334
|
+
break;
|
|
1335
|
+
case import_utils9.AST_NODE_TYPES.SwitchCase:
|
|
1336
|
+
list = parent.consequent;
|
|
1337
|
+
break;
|
|
1338
|
+
default:
|
|
1339
|
+
return null;
|
|
1340
|
+
}
|
|
1341
|
+
const index = list.indexOf(node);
|
|
1342
|
+
return index === -1 ? null : { list, index };
|
|
1343
|
+
}
|
|
1344
|
+
function hasFollowingStatement(node) {
|
|
1345
|
+
for (let current = node; current !== void 0 && !FUNCTION_TYPES.has(current.type); current = current.parent) {
|
|
1346
|
+
const slot = statementSlot(current);
|
|
1347
|
+
if (slot !== null && slot.index < slot.list.length - 1) return true;
|
|
1348
|
+
}
|
|
1349
|
+
return false;
|
|
1350
|
+
}
|
|
1351
|
+
function fallbackFollowsTry(tryStatement) {
|
|
1352
|
+
const body = tryStatement.block.body;
|
|
1353
|
+
const last = body.at(-1);
|
|
1354
|
+
return last?.type === import_utils9.AST_NODE_TYPES.ReturnStatement && hasFollowingStatement(tryStatement);
|
|
1355
|
+
}
|
|
1356
|
+
function isSeedValue(node) {
|
|
1357
|
+
const inner = node.type === import_utils9.AST_NODE_TYPES.TSAsExpression ? node.expression : node;
|
|
1358
|
+
switch (inner.type) {
|
|
1359
|
+
case import_utils9.AST_NODE_TYPES.Literal:
|
|
1360
|
+
return true;
|
|
1361
|
+
case import_utils9.AST_NODE_TYPES.Identifier:
|
|
1362
|
+
return inner.name === "undefined";
|
|
1363
|
+
case import_utils9.AST_NODE_TYPES.UnaryExpression:
|
|
1364
|
+
return inner.argument.type === import_utils9.AST_NODE_TYPES.Literal;
|
|
1365
|
+
case import_utils9.AST_NODE_TYPES.ArrayExpression:
|
|
1366
|
+
return inner.elements.length === 0;
|
|
1367
|
+
case import_utils9.AST_NODE_TYPES.ObjectExpression:
|
|
1368
|
+
return inner.properties.length === 0;
|
|
1369
|
+
default:
|
|
1370
|
+
return false;
|
|
1371
|
+
}
|
|
1372
|
+
}
|
|
1373
|
+
function seededFallbackHandled(tryStatement, scope) {
|
|
1374
|
+
const slot = statementSlot(tryStatement);
|
|
1375
|
+
if (slot === null || slot.index === 0) return false;
|
|
1376
|
+
const previous = slot.list[slot.index - 1];
|
|
1377
|
+
if (previous?.type !== import_utils9.AST_NODE_TYPES.VariableDeclaration || previous.kind === "const") {
|
|
1378
|
+
return false;
|
|
1379
|
+
}
|
|
1380
|
+
const declarator = previous.declarations[0];
|
|
1381
|
+
if (previous.declarations.length !== 1 || declarator === void 0) return false;
|
|
1382
|
+
if (declarator.id.type !== import_utils9.AST_NODE_TYPES.Identifier) return false;
|
|
1383
|
+
if (declarator.init == null || !isSeedValue(declarator.init)) return false;
|
|
1384
|
+
const variable = import_utils9.ASTUtils.findVariable(scope, declarator.id.name);
|
|
1385
|
+
if (variable === null) return false;
|
|
1386
|
+
const [tryStart, tryEnd] = tryStatement.block.range;
|
|
1387
|
+
let writtenInTry = false;
|
|
1388
|
+
let readAfter = false;
|
|
1389
|
+
for (const reference of variable.references) {
|
|
1390
|
+
const [start] = reference.identifier.range;
|
|
1391
|
+
if (reference.isWrite() && start >= tryStart && start < tryEnd) writtenInTry = true;
|
|
1392
|
+
if (reference.isRead() && start >= tryStatement.range[1]) readAfter = true;
|
|
1393
|
+
}
|
|
1394
|
+
return writtenInTry && readAfter;
|
|
1395
|
+
}
|
|
1396
|
+
var no_log_only_catch_default = import_utils9.ESLintUtils.RuleCreator(
|
|
1342
1397
|
(name) => `https://github.com/sarj-ai/linting/blob/main/packages/typescript/src/rules/${name}.ts`
|
|
1343
1398
|
)({
|
|
1344
1399
|
name: "no-log-only-catch",
|
|
@@ -1363,26 +1418,40 @@ var no_log_only_catch_default = import_utils10.ESLintUtils.RuleCreator(
|
|
|
1363
1418
|
create(context, [loggingOptions]) {
|
|
1364
1419
|
const matcher = createLogMatcher(loggingOptions);
|
|
1365
1420
|
const filename = context.filename;
|
|
1421
|
+
const sourceCode = context.sourceCode;
|
|
1366
1422
|
function isLoggingCallStatement(statement) {
|
|
1367
1423
|
if (statement.type !== "ExpressionStatement") {
|
|
1368
1424
|
return false;
|
|
1369
1425
|
}
|
|
1370
1426
|
return matcher.isLoggingCall(statement.expression);
|
|
1371
1427
|
}
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1428
|
+
function hasCommentDirectlyAbove(node) {
|
|
1429
|
+
const above = sourceCode.getCommentsBefore(node).at(-1);
|
|
1430
|
+
return above !== void 0 && above.loc.end.line === node.loc.start.line - 1;
|
|
1431
|
+
}
|
|
1432
|
+
function hasAdjacentRationale(node) {
|
|
1433
|
+
const tryStatement = node.parent;
|
|
1434
|
+
if (hasCommentDirectlyAbove(tryStatement) || hasCommentDirectlyAbove(node)) return true;
|
|
1435
|
+
const block = tryStatement.parent;
|
|
1436
|
+
if (block?.type !== import_utils9.AST_NODE_TYPES.BlockStatement || block.body.length !== 1 || block.parent === void 0 || !SINGLE_STATEMENT_HOSTS.has(block.parent.type)) {
|
|
1437
|
+
return false;
|
|
1438
|
+
}
|
|
1439
|
+
return hasCommentDirectlyAbove(block.parent);
|
|
1440
|
+
}
|
|
1441
|
+
if (isTestFile(filename) || BENCHMARK_DIR_RE.test(filename.replaceAll("\\", "/"))) {
|
|
1376
1442
|
return {};
|
|
1377
1443
|
}
|
|
1378
1444
|
return {
|
|
1379
1445
|
CatchClause(node) {
|
|
1380
1446
|
const statements = node.body.body;
|
|
1381
|
-
const isDocumented =
|
|
1447
|
+
const isDocumented = sourceCode.getCommentsInside(node.body).length > 0 || hasAdjacentRationale(node);
|
|
1382
1448
|
if (statements.length === 0) {
|
|
1383
1449
|
if (isDocumented) {
|
|
1384
1450
|
return;
|
|
1385
1451
|
}
|
|
1452
|
+
if (fallbackFollowsTry(node.parent) || seededFallbackHandled(node.parent, sourceCode.getScope(node))) {
|
|
1453
|
+
return;
|
|
1454
|
+
}
|
|
1386
1455
|
context.report({ node, messageId: "emptyCatch" });
|
|
1387
1456
|
return;
|
|
1388
1457
|
}
|
|
@@ -1401,11 +1470,12 @@ var no_log_only_catch_default = import_utils10.ESLintUtils.RuleCreator(
|
|
|
1401
1470
|
});
|
|
1402
1471
|
|
|
1403
1472
|
// src/rules/no-raw-env.ts
|
|
1404
|
-
var
|
|
1473
|
+
var import_utils10 = require("@typescript-eslint/utils");
|
|
1405
1474
|
var CONFIG_FILE_RE = /(^|[\\/])[\w.-]+\.config\.[cm]?[jt]sx?$/;
|
|
1406
1475
|
var ENV_BOUNDARY_FILE_RE = /(^|[\\/])(?:env|client-env|server-env|client-settings|server-settings)\.[cm]?[jt]sx?$/;
|
|
1476
|
+
var ENV_VALIDATION_MARKER_RE = /\bcreateEnv\s*\(|\bz\.object\s*\(|\.(?:safeParse|parse)\s*\(/;
|
|
1407
1477
|
function isValidatedEnvBoundary(filename, sourceText) {
|
|
1408
|
-
return ENV_BOUNDARY_FILE_RE.test(filename.replaceAll("\\", "/")) &&
|
|
1478
|
+
return ENV_BOUNDARY_FILE_RE.test(filename.replaceAll("\\", "/")) && ENV_VALIDATION_MARKER_RE.test(sourceText);
|
|
1409
1479
|
}
|
|
1410
1480
|
function isProcessEnv(node) {
|
|
1411
1481
|
return !node.computed && node.object.type === "Identifier" && node.object.name === "process" && node.property.type === "Identifier" && node.property.name === "env";
|
|
@@ -1420,9 +1490,15 @@ var BUILD_TIME_CONSTANTS = /* @__PURE__ */ new Set([
|
|
|
1420
1490
|
"PROD",
|
|
1421
1491
|
"SSR"
|
|
1422
1492
|
]);
|
|
1423
|
-
|
|
1493
|
+
var PLATFORM_MARKERS = /* @__PURE__ */ new Set([
|
|
1494
|
+
"NEXT_RUNTIME",
|
|
1495
|
+
"VERCEL",
|
|
1496
|
+
"VERCEL_ENV",
|
|
1497
|
+
"CI"
|
|
1498
|
+
]);
|
|
1499
|
+
function isExemptVariableAccess(node) {
|
|
1424
1500
|
const parent = node.parent;
|
|
1425
|
-
return parent.type === "MemberExpression" && parent.object === node && !parent.computed && parent.property.type === "Identifier" && BUILD_TIME_CONSTANTS.has(parent.property.name);
|
|
1501
|
+
return parent.type === "MemberExpression" && parent.object === node && !parent.computed && parent.property.type === "Identifier" && (BUILD_TIME_CONSTANTS.has(parent.property.name) || PLATFORM_MARKERS.has(parent.property.name));
|
|
1426
1502
|
}
|
|
1427
1503
|
function isWriteTarget(node) {
|
|
1428
1504
|
const access = node.parent.type === "MemberExpression" && node.parent.object === node ? node.parent : node;
|
|
@@ -1439,7 +1515,7 @@ function isWholeEnvSpread(node) {
|
|
|
1439
1515
|
const parent = node.parent;
|
|
1440
1516
|
return parent.type === "SpreadElement" && parent.argument === node;
|
|
1441
1517
|
}
|
|
1442
|
-
var no_raw_env_default =
|
|
1518
|
+
var no_raw_env_default = import_utils10.ESLintUtils.RuleCreator(
|
|
1443
1519
|
(name) => `https://github.com/sarj-ai/linting/blob/main/packages/typescript/src/rules/${name}.ts`
|
|
1444
1520
|
)({
|
|
1445
1521
|
name: "no-raw-env",
|
|
@@ -1461,7 +1537,7 @@ var no_raw_env_default = import_utils11.ESLintUtils.RuleCreator(
|
|
|
1461
1537
|
}
|
|
1462
1538
|
return {
|
|
1463
1539
|
MemberExpression(node) {
|
|
1464
|
-
if ((isProcessEnv(node) || isImportMetaEnv(node)) && !
|
|
1540
|
+
if ((isProcessEnv(node) || isImportMetaEnv(node)) && !isExemptVariableAccess(node) && !isWriteTarget(node) && !isWholeEnvSpread(node)) {
|
|
1465
1541
|
context.report({
|
|
1466
1542
|
node,
|
|
1467
1543
|
messageId: "noRawEnv"
|
|
@@ -1473,12 +1549,12 @@ var no_raw_env_default = import_utils11.ESLintUtils.RuleCreator(
|
|
|
1473
1549
|
});
|
|
1474
1550
|
|
|
1475
1551
|
// src/rules/no-sentinel-return-on-catch.ts
|
|
1476
|
-
var
|
|
1552
|
+
var import_utils11 = require("@typescript-eslint/utils");
|
|
1477
1553
|
function sentinelKind(arg) {
|
|
1478
1554
|
if (arg === null) {
|
|
1479
1555
|
return null;
|
|
1480
1556
|
}
|
|
1481
|
-
if (arg.type ===
|
|
1557
|
+
if (arg.type === import_utils11.AST_NODE_TYPES.Literal) {
|
|
1482
1558
|
if (arg.value === null) {
|
|
1483
1559
|
return "nullish";
|
|
1484
1560
|
}
|
|
@@ -1490,13 +1566,13 @@ function sentinelKind(arg) {
|
|
|
1490
1566
|
}
|
|
1491
1567
|
return null;
|
|
1492
1568
|
}
|
|
1493
|
-
if (arg.type ===
|
|
1569
|
+
if (arg.type === import_utils11.AST_NODE_TYPES.Identifier && arg.name === "undefined") {
|
|
1494
1570
|
return "nullish";
|
|
1495
1571
|
}
|
|
1496
|
-
if (arg.type ===
|
|
1572
|
+
if (arg.type === import_utils11.AST_NODE_TYPES.ArrayExpression) {
|
|
1497
1573
|
return "array";
|
|
1498
1574
|
}
|
|
1499
|
-
if (arg.type ===
|
|
1575
|
+
if (arg.type === import_utils11.AST_NODE_TYPES.ObjectExpression) {
|
|
1500
1576
|
return "object";
|
|
1501
1577
|
}
|
|
1502
1578
|
return null;
|
|
@@ -1505,25 +1581,25 @@ function isSentinelArgument(arg) {
|
|
|
1505
1581
|
if (arg === null) {
|
|
1506
1582
|
return false;
|
|
1507
1583
|
}
|
|
1508
|
-
if (arg.type ===
|
|
1584
|
+
if (arg.type === import_utils11.AST_NODE_TYPES.Literal && arg.value === null) {
|
|
1509
1585
|
return true;
|
|
1510
1586
|
}
|
|
1511
|
-
if (arg.type ===
|
|
1587
|
+
if (arg.type === import_utils11.AST_NODE_TYPES.Literal && arg.value === false) {
|
|
1512
1588
|
return true;
|
|
1513
1589
|
}
|
|
1514
|
-
if (arg.type ===
|
|
1590
|
+
if (arg.type === import_utils11.AST_NODE_TYPES.Identifier && arg.name === "undefined") {
|
|
1515
1591
|
return true;
|
|
1516
1592
|
}
|
|
1517
|
-
if (arg.type ===
|
|
1593
|
+
if (arg.type === import_utils11.AST_NODE_TYPES.ArrayExpression && arg.elements.length === 0) {
|
|
1518
1594
|
return true;
|
|
1519
1595
|
}
|
|
1520
|
-
if (arg.type ===
|
|
1596
|
+
if (arg.type === import_utils11.AST_NODE_TYPES.ObjectExpression && arg.properties.length === 0) {
|
|
1521
1597
|
return true;
|
|
1522
1598
|
}
|
|
1523
1599
|
return false;
|
|
1524
1600
|
}
|
|
1525
1601
|
function isFunctionNode(node) {
|
|
1526
|
-
return node.type ===
|
|
1602
|
+
return node.type === import_utils11.AST_NODE_TYPES.FunctionDeclaration || node.type === import_utils11.AST_NODE_TYPES.FunctionExpression || node.type === import_utils11.AST_NODE_TYPES.ArrowFunctionExpression;
|
|
1527
1603
|
}
|
|
1528
1604
|
function isNode(value) {
|
|
1529
1605
|
return typeof value === "object" && value !== null && typeof value.type === "string";
|
|
@@ -1563,24 +1639,24 @@ function walkWithinScope(node, visit) {
|
|
|
1563
1639
|
function containsThrow(node) {
|
|
1564
1640
|
return walkWithinScope(
|
|
1565
1641
|
node,
|
|
1566
|
-
(current) => current.type ===
|
|
1642
|
+
(current) => current.type === import_utils11.AST_NODE_TYPES.ThrowStatement
|
|
1567
1643
|
);
|
|
1568
1644
|
}
|
|
1569
1645
|
function bindsName(param, name) {
|
|
1570
1646
|
switch (param.type) {
|
|
1571
|
-
case
|
|
1647
|
+
case import_utils11.AST_NODE_TYPES.Identifier:
|
|
1572
1648
|
return param.name === name;
|
|
1573
|
-
case
|
|
1649
|
+
case import_utils11.AST_NODE_TYPES.AssignmentPattern:
|
|
1574
1650
|
return bindsName(param.left, name);
|
|
1575
|
-
case
|
|
1651
|
+
case import_utils11.AST_NODE_TYPES.RestElement:
|
|
1576
1652
|
return bindsName(param.argument, name);
|
|
1577
|
-
case
|
|
1653
|
+
case import_utils11.AST_NODE_TYPES.ArrayPattern:
|
|
1578
1654
|
return param.elements.some(
|
|
1579
1655
|
(element) => element !== null && bindsName(element, name)
|
|
1580
1656
|
);
|
|
1581
|
-
case
|
|
1657
|
+
case import_utils11.AST_NODE_TYPES.ObjectPattern:
|
|
1582
1658
|
return param.properties.some(
|
|
1583
|
-
(property) => property.type ===
|
|
1659
|
+
(property) => property.type === import_utils11.AST_NODE_TYPES.RestElement ? bindsName(property.argument, name) : bindsName(property.value, name)
|
|
1584
1660
|
);
|
|
1585
1661
|
default:
|
|
1586
1662
|
return false;
|
|
@@ -1595,7 +1671,7 @@ function subtreeReadsName(node, name) {
|
|
|
1595
1671
|
if (found) {
|
|
1596
1672
|
return;
|
|
1597
1673
|
}
|
|
1598
|
-
if (current.type ===
|
|
1674
|
+
if (current.type === import_utils11.AST_NODE_TYPES.Identifier && current.name === name) {
|
|
1599
1675
|
found = true;
|
|
1600
1676
|
return;
|
|
1601
1677
|
}
|
|
@@ -1606,10 +1682,10 @@ function subtreeReadsName(node, name) {
|
|
|
1606
1682
|
if (key === "parent") {
|
|
1607
1683
|
continue;
|
|
1608
1684
|
}
|
|
1609
|
-
if (key === "key" && current.type ===
|
|
1685
|
+
if (key === "key" && current.type === import_utils11.AST_NODE_TYPES.Property && !current.computed) {
|
|
1610
1686
|
continue;
|
|
1611
1687
|
}
|
|
1612
|
-
if (key === "property" && current.type ===
|
|
1688
|
+
if (key === "property" && current.type === import_utils11.AST_NODE_TYPES.MemberExpression && !current.computed) {
|
|
1613
1689
|
continue;
|
|
1614
1690
|
}
|
|
1615
1691
|
const value = current[key];
|
|
@@ -1642,10 +1718,10 @@ var SAFE_PARSE_CONSTRUCTORS = /* @__PURE__ */ new Set([
|
|
|
1642
1718
|
"URLPattern"
|
|
1643
1719
|
]);
|
|
1644
1720
|
function isParseShapedNode(node) {
|
|
1645
|
-
if (node.type ===
|
|
1721
|
+
if (node.type === import_utils11.AST_NODE_TYPES.CallExpression && node.callee.type === import_utils11.AST_NODE_TYPES.MemberExpression && !node.callee.computed && node.callee.property.type === import_utils11.AST_NODE_TYPES.Identifier) {
|
|
1646
1722
|
return node.callee.property.name === "parse";
|
|
1647
1723
|
}
|
|
1648
|
-
if (node.type ===
|
|
1724
|
+
if (node.type === import_utils11.AST_NODE_TYPES.NewExpression && node.callee.type === import_utils11.AST_NODE_TYPES.Identifier) {
|
|
1649
1725
|
return SAFE_PARSE_CONSTRUCTORS.has(node.callee.name);
|
|
1650
1726
|
}
|
|
1651
1727
|
return false;
|
|
@@ -1656,10 +1732,10 @@ var BODY_DECODE_METHODS = /* @__PURE__ */ new Set([
|
|
|
1656
1732
|
"arrayBuffer"
|
|
1657
1733
|
]);
|
|
1658
1734
|
function isBodyDecodeNode(node) {
|
|
1659
|
-
return node.type ===
|
|
1735
|
+
return node.type === import_utils11.AST_NODE_TYPES.CallExpression && node.callee.type === import_utils11.AST_NODE_TYPES.MemberExpression && !node.callee.computed && node.callee.property.type === import_utils11.AST_NODE_TYPES.Identifier && BODY_DECODE_METHODS.has(node.callee.property.name);
|
|
1660
1736
|
}
|
|
1661
1737
|
function returnsMatching(stmt, predicate) {
|
|
1662
|
-
return stmt.type ===
|
|
1738
|
+
return stmt.type === import_utils11.AST_NODE_TYPES.ReturnStatement && stmt.argument !== null && walkWithinScope(stmt.argument, predicate);
|
|
1663
1739
|
}
|
|
1664
1740
|
function enclosingReturnTypeNode(node) {
|
|
1665
1741
|
let current = node.parent;
|
|
@@ -1677,11 +1753,11 @@ function enclosingFunctionName(node) {
|
|
|
1677
1753
|
let current = node.parent;
|
|
1678
1754
|
while (current !== void 0 && current !== null) {
|
|
1679
1755
|
if (isFunctionNode(current)) {
|
|
1680
|
-
if ("id" in current && isNode(current.id) && current.id.type ===
|
|
1756
|
+
if ("id" in current && isNode(current.id) && current.id.type === import_utils11.AST_NODE_TYPES.Identifier) {
|
|
1681
1757
|
return current.id.name;
|
|
1682
1758
|
}
|
|
1683
1759
|
const parent = current.parent;
|
|
1684
|
-
if (parent?.type ===
|
|
1760
|
+
if (parent?.type === import_utils11.AST_NODE_TYPES.VariableDeclarator && parent.id.type === import_utils11.AST_NODE_TYPES.Identifier) {
|
|
1685
1761
|
return parent.id.name;
|
|
1686
1762
|
}
|
|
1687
1763
|
return null;
|
|
@@ -1702,10 +1778,10 @@ function isDeclaredBooleanPredicate(catchNode, kind) {
|
|
|
1702
1778
|
return false;
|
|
1703
1779
|
}
|
|
1704
1780
|
let declared = enclosingReturnTypeNode(catchNode);
|
|
1705
|
-
if (declared?.type ===
|
|
1781
|
+
if (declared?.type === import_utils11.AST_NODE_TYPES.TSTypeReference && declared.typeName.type === import_utils11.AST_NODE_TYPES.Identifier && declared.typeName.name === "Promise") {
|
|
1706
1782
|
declared = declared.typeArguments?.params[0] ?? null;
|
|
1707
1783
|
}
|
|
1708
|
-
return declared?.type ===
|
|
1784
|
+
return declared?.type === import_utils11.AST_NODE_TYPES.TSBooleanKeyword;
|
|
1709
1785
|
}
|
|
1710
1786
|
function tryReturnsSafeParse(catchNode) {
|
|
1711
1787
|
const tryBlock = tryBlockOf(catchNode);
|
|
@@ -1721,7 +1797,7 @@ function tryReturnsSafeParse(catchNode) {
|
|
|
1721
1797
|
function enclosingFunctionBody(node) {
|
|
1722
1798
|
let current = node.parent;
|
|
1723
1799
|
while (current !== void 0 && current !== null) {
|
|
1724
|
-
if (isFunctionNode(current) && "body" in current && isNode(current.body) && current.body.type ===
|
|
1800
|
+
if (isFunctionNode(current) && "body" in current && isNode(current.body) && current.body.type === import_utils11.AST_NODE_TYPES.BlockStatement) {
|
|
1725
1801
|
return current.body;
|
|
1726
1802
|
}
|
|
1727
1803
|
current = current.parent;
|
|
@@ -1734,7 +1810,7 @@ function functionReturnsSameSentinelKindElsewhere(catchNode, kind) {
|
|
|
1734
1810
|
return false;
|
|
1735
1811
|
}
|
|
1736
1812
|
return walkWithinScope(functionBody, (current) => {
|
|
1737
|
-
if (current.type !==
|
|
1813
|
+
if (current.type !== import_utils11.AST_NODE_TYPES.ReturnStatement) {
|
|
1738
1814
|
return false;
|
|
1739
1815
|
}
|
|
1740
1816
|
if (isWithin(current, catchNode.body)) {
|
|
@@ -1753,13 +1829,13 @@ function returnedSentinelKinds(arg) {
|
|
|
1753
1829
|
kinds.add(direct);
|
|
1754
1830
|
return kinds;
|
|
1755
1831
|
}
|
|
1756
|
-
if (arg.type ===
|
|
1832
|
+
if (arg.type === import_utils11.AST_NODE_TYPES.ConditionalExpression) {
|
|
1757
1833
|
for (const branch of [arg.consequent, arg.alternate]) {
|
|
1758
1834
|
for (const nested of returnedSentinelKinds(branch)) {
|
|
1759
1835
|
kinds.add(nested);
|
|
1760
1836
|
}
|
|
1761
1837
|
}
|
|
1762
|
-
} else if (arg.type ===
|
|
1838
|
+
} else if (arg.type === import_utils11.AST_NODE_TYPES.LogicalExpression && (arg.operator === "??" || arg.operator === "||")) {
|
|
1763
1839
|
for (const nested of returnedSentinelKinds(arg.right)) {
|
|
1764
1840
|
kinds.add(nested);
|
|
1765
1841
|
}
|
|
@@ -1776,7 +1852,7 @@ function isWithin(node, ancestor) {
|
|
|
1776
1852
|
}
|
|
1777
1853
|
return false;
|
|
1778
1854
|
}
|
|
1779
|
-
var no_sentinel_return_on_catch_default =
|
|
1855
|
+
var no_sentinel_return_on_catch_default = import_utils11.ESLintUtils.RuleCreator(
|
|
1780
1856
|
(name) => `https://github.com/sarj-ai/linting/blob/main/packages/typescript/src/rules/${name}.ts`
|
|
1781
1857
|
)({
|
|
1782
1858
|
name: "no-sentinel-return-on-catch",
|
|
@@ -1804,7 +1880,7 @@ var no_sentinel_return_on_catch_default = import_utils12.ESLintUtils.RuleCreator
|
|
|
1804
1880
|
const matcher = createLogMatcher(loggingOptions);
|
|
1805
1881
|
function logsOrReportsError(catchBody, caughtName) {
|
|
1806
1882
|
return walkWithinScope(catchBody, (current) => {
|
|
1807
|
-
if (current.type !==
|
|
1883
|
+
if (current.type !== import_utils11.AST_NODE_TYPES.CallExpression) {
|
|
1808
1884
|
return false;
|
|
1809
1885
|
}
|
|
1810
1886
|
if (matcher.isLoggingCall(current)) {
|
|
@@ -1821,7 +1897,7 @@ var no_sentinel_return_on_catch_default = import_utils12.ESLintUtils.RuleCreator
|
|
|
1821
1897
|
return;
|
|
1822
1898
|
}
|
|
1823
1899
|
const last = body[body.length - 1];
|
|
1824
|
-
if (last === void 0 || last.type !==
|
|
1900
|
+
if (last === void 0 || last.type !== import_utils11.AST_NODE_TYPES.ReturnStatement) {
|
|
1825
1901
|
return;
|
|
1826
1902
|
}
|
|
1827
1903
|
if (!isSentinelArgument(last.argument)) {
|
|
@@ -1830,7 +1906,7 @@ var no_sentinel_return_on_catch_default = import_utils12.ESLintUtils.RuleCreator
|
|
|
1830
1906
|
if (containsThrow(node.body)) {
|
|
1831
1907
|
return;
|
|
1832
1908
|
}
|
|
1833
|
-
const caughtName = node.param?.type ===
|
|
1909
|
+
const caughtName = node.param?.type === import_utils11.AST_NODE_TYPES.Identifier ? node.param.name : null;
|
|
1834
1910
|
if (logsOrReportsError(node.body, caughtName)) {
|
|
1835
1911
|
return;
|
|
1836
1912
|
}
|
|
@@ -1857,7 +1933,7 @@ var no_sentinel_return_on_catch_default = import_utils12.ESLintUtils.RuleCreator
|
|
|
1857
1933
|
});
|
|
1858
1934
|
|
|
1859
1935
|
// src/rules/no-string-concat-in-loop.ts
|
|
1860
|
-
var
|
|
1936
|
+
var import_utils12 = require("@typescript-eslint/utils");
|
|
1861
1937
|
var LOOP_NODE_TYPES = /* @__PURE__ */ new Set([
|
|
1862
1938
|
"ForStatement",
|
|
1863
1939
|
"ForOfStatement",
|
|
@@ -1942,7 +2018,7 @@ function enclosingLoop(node) {
|
|
|
1942
2018
|
}
|
|
1943
2019
|
return null;
|
|
1944
2020
|
}
|
|
1945
|
-
var no_string_concat_in_loop_default =
|
|
2021
|
+
var no_string_concat_in_loop_default = import_utils12.ESLintUtils.RuleCreator(
|
|
1946
2022
|
(name) => `https://github.com/sarj-ai/linting/blob/main/packages/typescript/src/rules/${name}.ts`
|
|
1947
2023
|
)({
|
|
1948
2024
|
name: "no-string-concat-in-loop",
|
|
@@ -2005,7 +2081,7 @@ var no_string_concat_in_loop_default = import_utils13.ESLintUtils.RuleCreator(
|
|
|
2005
2081
|
});
|
|
2006
2082
|
|
|
2007
2083
|
// src/rules/no-unnecessary-use-client.ts
|
|
2008
|
-
var
|
|
2084
|
+
var import_utils13 = require("@typescript-eslint/utils");
|
|
2009
2085
|
var HOOK_REGEX = /^use([A-Z]|$)/;
|
|
2010
2086
|
var EVENT_PROP_REGEX = /^on[A-Z]/;
|
|
2011
2087
|
var ERROR_FILE_REGEX = /\b(?:global-)?error\.[jt]sx?$/;
|
|
@@ -2031,13 +2107,13 @@ var CLIENT_ONLY_PACKAGES_REGEX = /^(?:@radix-ui\/|framer-motion|react-dom|react-
|
|
|
2031
2107
|
var isBareSpecifier = (source) => !source.startsWith(".") && !source.startsWith("/") && !source.startsWith("@/") && !source.startsWith("~");
|
|
2032
2108
|
var jsxRootName = (name) => {
|
|
2033
2109
|
let current = name;
|
|
2034
|
-
while (current.type ===
|
|
2110
|
+
while (current.type === import_utils13.AST_NODE_TYPES.JSXMemberExpression) {
|
|
2035
2111
|
current = current.object;
|
|
2036
2112
|
}
|
|
2037
|
-
return current.type ===
|
|
2113
|
+
return current.type === import_utils13.AST_NODE_TYPES.JSXIdentifier ? current.name : "";
|
|
2038
2114
|
};
|
|
2039
2115
|
var subtreeReadsImportedBinding = (node, imported) => {
|
|
2040
|
-
if (node.type ===
|
|
2116
|
+
if (node.type === import_utils13.AST_NODE_TYPES.Identifier) {
|
|
2041
2117
|
return imported.has(node.name);
|
|
2042
2118
|
}
|
|
2043
2119
|
for (const key of Object.keys(node)) {
|
|
@@ -2052,16 +2128,16 @@ var subtreeReadsImportedBinding = (node, imported) => {
|
|
|
2052
2128
|
return false;
|
|
2053
2129
|
};
|
|
2054
2130
|
var isUseClientDirective = (node) => {
|
|
2055
|
-
return node.type ===
|
|
2131
|
+
return node.type === import_utils13.AST_NODE_TYPES.ExpressionStatement && node.expression.type === import_utils13.AST_NODE_TYPES.Literal && node.expression.value === "use client";
|
|
2056
2132
|
};
|
|
2057
2133
|
var isGlobalReference = (node, context) => {
|
|
2058
2134
|
if (!BROWSER_GLOBALS.has(node.name)) return false;
|
|
2059
2135
|
const parent = node.parent;
|
|
2060
2136
|
if (parent !== void 0) {
|
|
2061
|
-
if (parent.type ===
|
|
2137
|
+
if (parent.type === import_utils13.AST_NODE_TYPES.MemberExpression && parent.property === node && !parent.computed) {
|
|
2062
2138
|
return false;
|
|
2063
2139
|
}
|
|
2064
|
-
if (parent.type ===
|
|
2140
|
+
if (parent.type === import_utils13.AST_NODE_TYPES.Property && parent.key === node && !parent.computed) {
|
|
2065
2141
|
return false;
|
|
2066
2142
|
}
|
|
2067
2143
|
if (parent.type.startsWith("TS")) {
|
|
@@ -2078,7 +2154,7 @@ var isGlobalReference = (node, context) => {
|
|
|
2078
2154
|
}
|
|
2079
2155
|
return true;
|
|
2080
2156
|
};
|
|
2081
|
-
var no_unnecessary_use_client_default =
|
|
2157
|
+
var no_unnecessary_use_client_default = import_utils13.ESLintUtils.RuleCreator(
|
|
2082
2158
|
(name) => `https://github.com/sarj-ai/linting/blob/main/packages/typescript/src/rules/${name}.ts`
|
|
2083
2159
|
)({
|
|
2084
2160
|
name: "no-unnecessary-use-client",
|
|
@@ -2103,13 +2179,13 @@ var no_unnecessary_use_client_default = import_utils14.ESLintUtils.RuleCreator(
|
|
|
2103
2179
|
const importedLocals = /* @__PURE__ */ new Set();
|
|
2104
2180
|
const externalLocals = /* @__PURE__ */ new Set();
|
|
2105
2181
|
const markIfHookOrContext = (callee) => {
|
|
2106
|
-
if (callee.type ===
|
|
2182
|
+
if (callee.type === import_utils13.AST_NODE_TYPES.Identifier) {
|
|
2107
2183
|
if (HOOK_REGEX.test(callee.name) || callee.name === "createContext") {
|
|
2108
2184
|
hasClientIndicator = true;
|
|
2109
2185
|
}
|
|
2110
2186
|
return;
|
|
2111
2187
|
}
|
|
2112
|
-
if (callee.type ===
|
|
2188
|
+
if (callee.type === import_utils13.AST_NODE_TYPES.MemberExpression && callee.property.type === import_utils13.AST_NODE_TYPES.Identifier) {
|
|
2113
2189
|
const name = callee.property.name;
|
|
2114
2190
|
if (HOOK_REGEX.test(name) || name === "createContext") {
|
|
2115
2191
|
hasClientIndicator = true;
|
|
@@ -2119,7 +2195,7 @@ var no_unnecessary_use_client_default = import_utils14.ESLintUtils.RuleCreator(
|
|
|
2119
2195
|
return {
|
|
2120
2196
|
Program(node) {
|
|
2121
2197
|
for (const stmt of node.body) {
|
|
2122
|
-
if (stmt.type !==
|
|
2198
|
+
if (stmt.type !== import_utils13.AST_NODE_TYPES.ExpressionStatement) break;
|
|
2123
2199
|
if (isUseClientDirective(stmt)) {
|
|
2124
2200
|
directiveNode = stmt;
|
|
2125
2201
|
break;
|
|
@@ -2132,7 +2208,7 @@ var no_unnecessary_use_client_default = import_utils14.ESLintUtils.RuleCreator(
|
|
|
2132
2208
|
},
|
|
2133
2209
|
JSXAttribute(node) {
|
|
2134
2210
|
if (directiveNode === null) return;
|
|
2135
|
-
if (node.name.type ===
|
|
2211
|
+
if (node.name.type === import_utils13.AST_NODE_TYPES.JSXIdentifier && EVENT_PROP_REGEX.test(node.name.name)) {
|
|
2136
2212
|
hasClientIndicator = true;
|
|
2137
2213
|
}
|
|
2138
2214
|
},
|
|
@@ -2199,8 +2275,8 @@ var no_unnecessary_use_client_default = import_utils14.ESLintUtils.RuleCreator(
|
|
|
2199
2275
|
});
|
|
2200
2276
|
|
|
2201
2277
|
// src/rules/prefer-discriminated-union.ts
|
|
2278
|
+
var import_utils14 = require("@typescript-eslint/utils");
|
|
2202
2279
|
var import_utils15 = require("@typescript-eslint/utils");
|
|
2203
|
-
var import_utils16 = require("@typescript-eslint/utils");
|
|
2204
2280
|
var STATUS_MEMBER_NAMES = /* @__PURE__ */ new Set([
|
|
2205
2281
|
"success",
|
|
2206
2282
|
"ok",
|
|
@@ -2210,27 +2286,27 @@ var STATUS_MEMBER_NAMES = /* @__PURE__ */ new Set([
|
|
|
2210
2286
|
]);
|
|
2211
2287
|
var MIN_OPTIONAL_MEMBERS = 2;
|
|
2212
2288
|
function getMemberName(member) {
|
|
2213
|
-
if (member.type !==
|
|
2289
|
+
if (member.type !== import_utils15.AST_NODE_TYPES.TSPropertySignature) {
|
|
2214
2290
|
return null;
|
|
2215
2291
|
}
|
|
2216
2292
|
const { key } = member;
|
|
2217
|
-
if (key.type ===
|
|
2293
|
+
if (key.type === import_utils15.AST_NODE_TYPES.Identifier) {
|
|
2218
2294
|
return key.name;
|
|
2219
2295
|
}
|
|
2220
|
-
if (key.type ===
|
|
2296
|
+
if (key.type === import_utils15.AST_NODE_TYPES.Literal && typeof key.value === "string") {
|
|
2221
2297
|
return key.value;
|
|
2222
2298
|
}
|
|
2223
2299
|
return null;
|
|
2224
2300
|
}
|
|
2225
2301
|
function isBooleanTyped(member) {
|
|
2226
|
-
return member.typeAnnotation?.typeAnnotation.type ===
|
|
2302
|
+
return member.typeAnnotation?.typeAnnotation.type === import_utils15.AST_NODE_TYPES.TSBooleanKeyword;
|
|
2227
2303
|
}
|
|
2228
2304
|
function looksLikeMutuallyExclusiveState(typeLiteral) {
|
|
2229
2305
|
let hasStatusBoolean = false;
|
|
2230
2306
|
let optionalCount = 0;
|
|
2231
2307
|
let optionalPayloadCount = 0;
|
|
2232
2308
|
for (const member of typeLiteral.members) {
|
|
2233
|
-
if (member.type !==
|
|
2309
|
+
if (member.type !== import_utils15.AST_NODE_TYPES.TSPropertySignature) {
|
|
2234
2310
|
continue;
|
|
2235
2311
|
}
|
|
2236
2312
|
if (member.optional) {
|
|
@@ -2246,7 +2322,7 @@ function looksLikeMutuallyExclusiveState(typeLiteral) {
|
|
|
2246
2322
|
}
|
|
2247
2323
|
return hasStatusBoolean && optionalCount >= MIN_OPTIONAL_MEMBERS && optionalPayloadCount >= 1;
|
|
2248
2324
|
}
|
|
2249
|
-
var prefer_discriminated_union_default =
|
|
2325
|
+
var prefer_discriminated_union_default = import_utils14.ESLintUtils.RuleCreator(
|
|
2250
2326
|
(name) => `https://github.com/sarj-ai/linting/blob/main/packages/typescript/src/rules/${name}.ts`
|
|
2251
2327
|
)({
|
|
2252
2328
|
name: "prefer-discriminated-union",
|
|
@@ -2274,7 +2350,7 @@ var prefer_discriminated_union_default = import_utils15.ESLintUtils.RuleCreator(
|
|
|
2274
2350
|
TSInterfaceDeclaration(node) {
|
|
2275
2351
|
const synthetic = {
|
|
2276
2352
|
...node.body,
|
|
2277
|
-
type:
|
|
2353
|
+
type: import_utils15.AST_NODE_TYPES.TSTypeLiteral,
|
|
2278
2354
|
members: node.body.body
|
|
2279
2355
|
};
|
|
2280
2356
|
checkTypeLiteral(synthetic, node);
|
|
@@ -2287,13 +2363,13 @@ var prefer_discriminated_union_default = import_utils15.ESLintUtils.RuleCreator(
|
|
|
2287
2363
|
});
|
|
2288
2364
|
|
|
2289
2365
|
// src/rules/prefer-schema-for-api-payload.ts
|
|
2290
|
-
var
|
|
2366
|
+
var import_utils16 = require("@typescript-eslint/utils");
|
|
2291
2367
|
var unwrap = (node) => {
|
|
2292
2368
|
let current = node;
|
|
2293
2369
|
while (current !== null && current !== void 0) {
|
|
2294
|
-
if (current.type ===
|
|
2370
|
+
if (current.type === import_utils16.AST_NODE_TYPES.TSAsExpression || current.type === import_utils16.AST_NODE_TYPES.TSTypeAssertion || current.type === import_utils16.AST_NODE_TYPES.TSNonNullExpression || current.type === import_utils16.AST_NODE_TYPES.TSSatisfiesExpression) {
|
|
2295
2371
|
current = current.expression;
|
|
2296
|
-
} else if (current.type ===
|
|
2372
|
+
} else if (current.type === import_utils16.AST_NODE_TYPES.ChainExpression) {
|
|
2297
2373
|
current = current.expression;
|
|
2298
2374
|
} else {
|
|
2299
2375
|
break;
|
|
@@ -2301,28 +2377,40 @@ var unwrap = (node) => {
|
|
|
2301
2377
|
}
|
|
2302
2378
|
return current ?? null;
|
|
2303
2379
|
};
|
|
2380
|
+
var PROMISE_CHAIN_METHODS = /* @__PURE__ */ new Set([
|
|
2381
|
+
"then",
|
|
2382
|
+
"catch",
|
|
2383
|
+
"finally"
|
|
2384
|
+
]);
|
|
2385
|
+
var isSchemaParseReference = (node) => {
|
|
2386
|
+
const inner = unwrap(node);
|
|
2387
|
+
return inner !== null && inner.type === import_utils16.AST_NODE_TYPES.MemberExpression && !inner.computed && inner.property.type === import_utils16.AST_NODE_TYPES.Identifier && (inner.property.name === "parse" || inner.property.name === "safeParse");
|
|
2388
|
+
};
|
|
2304
2389
|
var isRawPayloadSource = (node) => {
|
|
2305
2390
|
let current = unwrap(node);
|
|
2306
2391
|
if (current === null) return false;
|
|
2307
|
-
if (current.type ===
|
|
2392
|
+
if (current.type === import_utils16.AST_NODE_TYPES.AwaitExpression) {
|
|
2308
2393
|
current = unwrap(current.argument);
|
|
2309
2394
|
}
|
|
2310
|
-
if (current === null || current.type !==
|
|
2395
|
+
if (current === null || current.type !== import_utils16.AST_NODE_TYPES.CallExpression) {
|
|
2311
2396
|
return false;
|
|
2312
2397
|
}
|
|
2313
2398
|
const callee = unwrap(current.callee);
|
|
2314
|
-
if (callee === null || callee.type !==
|
|
2399
|
+
if (callee === null || callee.type !== import_utils16.AST_NODE_TYPES.MemberExpression) {
|
|
2315
2400
|
return false;
|
|
2316
2401
|
}
|
|
2317
2402
|
const property = unwrap(callee.property);
|
|
2318
|
-
if (property === null || property.type !==
|
|
2403
|
+
if (property === null || property.type !== import_utils16.AST_NODE_TYPES.Identifier) {
|
|
2319
2404
|
return false;
|
|
2320
2405
|
}
|
|
2321
2406
|
if (property.name === "json") {
|
|
2322
2407
|
return true;
|
|
2323
2408
|
}
|
|
2409
|
+
if (PROMISE_CHAIN_METHODS.has(property.name)) {
|
|
2410
|
+
return !current.arguments.some(isSchemaParseReference) && isRawPayloadSource(callee.object);
|
|
2411
|
+
}
|
|
2324
2412
|
const object = unwrap(callee.object);
|
|
2325
|
-
return property.name === "parse" && object !== null && object.type ===
|
|
2413
|
+
return property.name === "parse" && object !== null && object.type === import_utils16.AST_NODE_TYPES.Identifier && object.name === "JSON" && // ...but not `JSON.parse(readFileSync(p, "utf8"))` — see isLocalFileRead.
|
|
2326
2414
|
!isLocalFileRead(current.arguments[0]);
|
|
2327
2415
|
};
|
|
2328
2416
|
var FILE_READ_RE = /^(readFile|readFileSync|readJson|readJsonSync|readJSON)$/;
|
|
@@ -2330,9 +2418,9 @@ var isLocalFileRead = (node) => {
|
|
|
2330
2418
|
let found = false;
|
|
2331
2419
|
const visit = (current) => {
|
|
2332
2420
|
if (found || current === null || current === void 0) return;
|
|
2333
|
-
if (current.type ===
|
|
2421
|
+
if (current.type === import_utils16.AST_NODE_TYPES.CallExpression) {
|
|
2334
2422
|
const callee = unwrap(current.callee);
|
|
2335
|
-
const name = callee?.type ===
|
|
2423
|
+
const name = callee?.type === import_utils16.AST_NODE_TYPES.Identifier ? callee.name : callee?.type === import_utils16.AST_NODE_TYPES.MemberExpression && !callee.computed && callee.property.type === import_utils16.AST_NODE_TYPES.Identifier ? callee.property.name : null;
|
|
2336
2424
|
if (name !== null && FILE_READ_RE.test(name)) {
|
|
2337
2425
|
found = true;
|
|
2338
2426
|
return;
|
|
@@ -2354,15 +2442,15 @@ var isLocalFileRead = (node) => {
|
|
|
2354
2442
|
var ASSERTION_CALLEE_RE = /^(expect|assert|should|invariant)$/;
|
|
2355
2443
|
var isInsideAssertion = (node) => {
|
|
2356
2444
|
for (let current = node.parent; current !== void 0 && current !== null; current = current.parent) {
|
|
2357
|
-
if (current.type !==
|
|
2445
|
+
if (current.type !== import_utils16.AST_NODE_TYPES.CallExpression) continue;
|
|
2358
2446
|
let callee = current.callee;
|
|
2359
|
-
while (callee.type ===
|
|
2447
|
+
while (callee.type === import_utils16.AST_NODE_TYPES.MemberExpression) {
|
|
2360
2448
|
callee = callee.object;
|
|
2361
2449
|
}
|
|
2362
|
-
if (callee.type ===
|
|
2450
|
+
if (callee.type === import_utils16.AST_NODE_TYPES.CallExpression) {
|
|
2363
2451
|
callee = callee.callee;
|
|
2364
2452
|
}
|
|
2365
|
-
if (callee.type ===
|
|
2453
|
+
if (callee.type === import_utils16.AST_NODE_TYPES.Identifier && ASSERTION_CALLEE_RE.test(callee.name)) {
|
|
2366
2454
|
return true;
|
|
2367
2455
|
}
|
|
2368
2456
|
}
|
|
@@ -2377,23 +2465,43 @@ var findVariable2 = (scope, name) => {
|
|
|
2377
2465
|
}
|
|
2378
2466
|
return null;
|
|
2379
2467
|
};
|
|
2380
|
-
var GUARD_NAME_RE = /^is[A-Z]/;
|
|
2468
|
+
var GUARD_NAME_RE = /^(?:is|validate|parse|assert|decode|coerce)[A-Z]/;
|
|
2469
|
+
var isValidationRead = (node) => {
|
|
2470
|
+
let current = node;
|
|
2471
|
+
let parent = current.parent;
|
|
2472
|
+
while (parent !== null && parent !== void 0 && (parent.type === import_utils16.AST_NODE_TYPES.TSAsExpression || parent.type === import_utils16.AST_NODE_TYPES.TSTypeAssertion || parent.type === import_utils16.AST_NODE_TYPES.TSNonNullExpression || parent.type === import_utils16.AST_NODE_TYPES.TSSatisfiesExpression || parent.type === import_utils16.AST_NODE_TYPES.ChainExpression)) {
|
|
2473
|
+
current = parent;
|
|
2474
|
+
parent = parent.parent;
|
|
2475
|
+
}
|
|
2476
|
+
if (parent === null || parent === void 0) return false;
|
|
2477
|
+
if (parent.type === import_utils16.AST_NODE_TYPES.UnaryExpression && parent.operator === "typeof" && parent.argument === current) {
|
|
2478
|
+
return true;
|
|
2479
|
+
}
|
|
2480
|
+
if (parent.type !== import_utils16.AST_NODE_TYPES.CallExpression || !parent.arguments.some((arg) => arg === current)) {
|
|
2481
|
+
return false;
|
|
2482
|
+
}
|
|
2483
|
+
const callee = parent.callee;
|
|
2484
|
+
if (callee.type === import_utils16.AST_NODE_TYPES.MemberExpression && !callee.computed && callee.object.type === import_utils16.AST_NODE_TYPES.Identifier && callee.object.name === "Array" && callee.property.type === import_utils16.AST_NODE_TYPES.Identifier && callee.property.name === "isArray") {
|
|
2485
|
+
return parent.arguments.length === 1;
|
|
2486
|
+
}
|
|
2487
|
+
return callee.type === import_utils16.AST_NODE_TYPES.Identifier && GUARD_NAME_RE.test(callee.name);
|
|
2488
|
+
};
|
|
2381
2489
|
var isGuardTestPosition = (node) => {
|
|
2382
2490
|
let current = node;
|
|
2383
2491
|
let parent = current.parent;
|
|
2384
2492
|
while (parent !== void 0 && parent !== null) {
|
|
2385
2493
|
switch (parent.type) {
|
|
2386
|
-
case
|
|
2387
|
-
case
|
|
2388
|
-
case
|
|
2494
|
+
case import_utils16.AST_NODE_TYPES.UnaryExpression:
|
|
2495
|
+
case import_utils16.AST_NODE_TYPES.LogicalExpression:
|
|
2496
|
+
case import_utils16.AST_NODE_TYPES.ChainExpression:
|
|
2389
2497
|
current = parent;
|
|
2390
2498
|
parent = parent.parent;
|
|
2391
2499
|
continue;
|
|
2392
|
-
case
|
|
2393
|
-
case
|
|
2394
|
-
case
|
|
2395
|
-
case
|
|
2396
|
-
case
|
|
2500
|
+
case import_utils16.AST_NODE_TYPES.IfStatement:
|
|
2501
|
+
case import_utils16.AST_NODE_TYPES.ConditionalExpression:
|
|
2502
|
+
case import_utils16.AST_NODE_TYPES.WhileStatement:
|
|
2503
|
+
case import_utils16.AST_NODE_TYPES.DoWhileStatement:
|
|
2504
|
+
case import_utils16.AST_NODE_TYPES.ForStatement:
|
|
2397
2505
|
return parent.test === current;
|
|
2398
2506
|
default:
|
|
2399
2507
|
return false;
|
|
@@ -2403,13 +2511,13 @@ var isGuardTestPosition = (node) => {
|
|
|
2403
2511
|
};
|
|
2404
2512
|
var isUnvalidatedVariableRef = (node, scope, tracked) => {
|
|
2405
2513
|
const unwrapped = unwrap(node);
|
|
2406
|
-
if (unwrapped === null || unwrapped.type !==
|
|
2514
|
+
if (unwrapped === null || unwrapped.type !== import_utils16.AST_NODE_TYPES.Identifier) {
|
|
2407
2515
|
return false;
|
|
2408
2516
|
}
|
|
2409
2517
|
const variable = findVariable2(scope, unwrapped.name);
|
|
2410
2518
|
return variable !== null && tracked.has(variable);
|
|
2411
2519
|
};
|
|
2412
|
-
var prefer_schema_for_api_payload_default =
|
|
2520
|
+
var prefer_schema_for_api_payload_default = import_utils16.ESLintUtils.RuleCreator(
|
|
2413
2521
|
(name) => `https://github.com/sarj-ai/linting/blob/main/packages/typescript/src/rules/${name}.ts`
|
|
2414
2522
|
)({
|
|
2415
2523
|
name: "prefer-schema-for-api-payload",
|
|
@@ -2429,6 +2537,14 @@ var prefer_schema_for_api_payload_default = import_utils17.ESLintUtils.RuleCreat
|
|
|
2429
2537
|
return {};
|
|
2430
2538
|
}
|
|
2431
2539
|
const unvalidatedVariables = /* @__PURE__ */ new Set();
|
|
2540
|
+
const isFullyNarrowedPattern = (declarator) => {
|
|
2541
|
+
const declared = context.sourceCode.getDeclaredVariables(declarator);
|
|
2542
|
+
return declared.length > 0 && declared.every(
|
|
2543
|
+
(variable) => variable.references.some(
|
|
2544
|
+
(reference) => isValidationRead(reference.identifier)
|
|
2545
|
+
)
|
|
2546
|
+
);
|
|
2547
|
+
};
|
|
2432
2548
|
const trackInitializer = (declarator) => {
|
|
2433
2549
|
if (!isRawPayloadSource(declarator.init)) return;
|
|
2434
2550
|
const declaredVars = context.sourceCode.getDeclaredVariables(declarator);
|
|
@@ -2440,13 +2556,15 @@ var prefer_schema_for_api_payload_default = import_utils17.ESLintUtils.RuleCreat
|
|
|
2440
2556
|
return {
|
|
2441
2557
|
VariableDeclarator(node) {
|
|
2442
2558
|
const scope = context.sourceCode.getScope(node);
|
|
2443
|
-
if (node.id.type ===
|
|
2559
|
+
if (node.id.type === import_utils16.AST_NODE_TYPES.Identifier) {
|
|
2444
2560
|
trackInitializer(node);
|
|
2445
2561
|
return;
|
|
2446
2562
|
}
|
|
2447
|
-
if (node.id.type ===
|
|
2563
|
+
if (node.id.type === import_utils16.AST_NODE_TYPES.ObjectPattern || node.id.type === import_utils16.AST_NODE_TYPES.ArrayPattern) {
|
|
2448
2564
|
if (isRawPayloadSource(node.init)) {
|
|
2449
|
-
|
|
2565
|
+
if (!isFullyNarrowedPattern(node)) {
|
|
2566
|
+
context.report({ node: node.id, messageId: "unparsedJsonAccess" });
|
|
2567
|
+
}
|
|
2450
2568
|
return;
|
|
2451
2569
|
}
|
|
2452
2570
|
if (isUnvalidatedVariableRef(node.init, scope, unvalidatedVariables)) {
|
|
@@ -2456,7 +2574,7 @@ var prefer_schema_for_api_payload_default = import_utils17.ESLintUtils.RuleCreat
|
|
|
2456
2574
|
},
|
|
2457
2575
|
AssignmentExpression(node) {
|
|
2458
2576
|
const scope = context.sourceCode.getScope(node);
|
|
2459
|
-
if (node.left.type ===
|
|
2577
|
+
if (node.left.type === import_utils16.AST_NODE_TYPES.Identifier) {
|
|
2460
2578
|
const variable = findVariable2(scope, node.left.name);
|
|
2461
2579
|
if (variable === null) return;
|
|
2462
2580
|
if (isRawPayloadSource(node.right)) {
|
|
@@ -2466,7 +2584,7 @@ var prefer_schema_for_api_payload_default = import_utils17.ESLintUtils.RuleCreat
|
|
|
2466
2584
|
}
|
|
2467
2585
|
return;
|
|
2468
2586
|
}
|
|
2469
|
-
if (node.left.type ===
|
|
2587
|
+
if (node.left.type === import_utils16.AST_NODE_TYPES.ObjectPattern || node.left.type === import_utils16.AST_NODE_TYPES.ArrayPattern) {
|
|
2470
2588
|
if (isRawPayloadSource(node.right)) {
|
|
2471
2589
|
context.report({
|
|
2472
2590
|
node: node.left,
|
|
@@ -2483,15 +2601,15 @@ var prefer_schema_for_api_payload_default = import_utils17.ESLintUtils.RuleCreat
|
|
|
2483
2601
|
}
|
|
2484
2602
|
},
|
|
2485
2603
|
CallExpression(node) {
|
|
2486
|
-
if (node.callee.type !==
|
|
2604
|
+
if (node.callee.type !== import_utils16.AST_NODE_TYPES.Identifier) return;
|
|
2487
2605
|
if (!GUARD_NAME_RE.test(node.callee.name) && !isGuardTestPosition(node)) {
|
|
2488
2606
|
return;
|
|
2489
2607
|
}
|
|
2490
2608
|
const scope = context.sourceCode.getScope(node);
|
|
2491
2609
|
for (const arg of node.arguments) {
|
|
2492
|
-
if (arg.type ===
|
|
2610
|
+
if (arg.type === import_utils16.AST_NODE_TYPES.SpreadElement) continue;
|
|
2493
2611
|
const unwrapped = unwrap(arg);
|
|
2494
|
-
if (unwrapped === null || unwrapped.type !==
|
|
2612
|
+
if (unwrapped === null || unwrapped.type !== import_utils16.AST_NODE_TYPES.Identifier) {
|
|
2495
2613
|
continue;
|
|
2496
2614
|
}
|
|
2497
2615
|
const variable = findVariable2(scope, unwrapped.name);
|
|
@@ -2500,17 +2618,18 @@ var prefer_schema_for_api_payload_default = import_utils17.ESLintUtils.RuleCreat
|
|
|
2500
2618
|
},
|
|
2501
2619
|
MemberExpression(node) {
|
|
2502
2620
|
if (isInsideAssertion(node)) return;
|
|
2621
|
+
if (isValidationRead(node)) return;
|
|
2503
2622
|
const scope = context.sourceCode.getScope(node);
|
|
2504
2623
|
const obj = unwrap(node.object);
|
|
2505
2624
|
if (isRawPayloadSource(obj)) {
|
|
2506
2625
|
const parent = node.parent;
|
|
2507
|
-
if (parent.type ===
|
|
2626
|
+
if (parent.type === import_utils16.AST_NODE_TYPES.CallExpression && parent.callee === node && node.property.type === import_utils16.AST_NODE_TYPES.Identifier && (node.property.name === "parse" || node.property.name === "safeParse" || PROMISE_CHAIN_METHODS.has(node.property.name))) {
|
|
2508
2627
|
return;
|
|
2509
2628
|
}
|
|
2510
2629
|
context.report({ node, messageId: "unparsedJsonAccess" });
|
|
2511
2630
|
return;
|
|
2512
2631
|
}
|
|
2513
|
-
if (obj !== null && obj.type ===
|
|
2632
|
+
if (obj !== null && obj.type === import_utils16.AST_NODE_TYPES.Identifier && isUnvalidatedVariableRef(obj, scope, unvalidatedVariables)) {
|
|
2514
2633
|
context.report({ node, messageId: "unparsedJsonAccess" });
|
|
2515
2634
|
const variable = findVariable2(scope, obj.name);
|
|
2516
2635
|
if (variable !== null) {
|
|
@@ -2523,7 +2642,7 @@ var prefer_schema_for_api_payload_default = import_utils17.ESLintUtils.RuleCreat
|
|
|
2523
2642
|
});
|
|
2524
2643
|
|
|
2525
2644
|
// src/rules/prefer-semantic-colors.ts
|
|
2526
|
-
var
|
|
2645
|
+
var import_utils17 = require("@typescript-eslint/utils");
|
|
2527
2646
|
var import_fs = require("fs");
|
|
2528
2647
|
var import_path = require("path");
|
|
2529
2648
|
|
|
@@ -2535,7 +2654,8 @@ var classTokens = (value) => value.split(/\s+/).filter(Boolean);
|
|
|
2535
2654
|
var COLOR_PREFIXES = "text|bg|border(?:-[trblxyse])?|ring(?:-offset)?|fill|stroke|from|via|to|divide|decoration|placeholder|accent|caret|shadow|outline";
|
|
2536
2655
|
var PALETTE = "red|orange|amber|yellow|lime|green|emerald|teal|cyan|sky|blue|indigo|violet|purple|fuchsia|pink|rose|slate|gray|zinc|neutral|stone";
|
|
2537
2656
|
var COLOR_FN = "rgba?|hsla?|hwb|oklch|oklab|lab|lch|color";
|
|
2538
|
-
var
|
|
2657
|
+
var PALETTE_STEP = "50|[1-9]00|950";
|
|
2658
|
+
var RAW_PALETTE_RE = new RegExp(`^(?:${COLOR_PREFIXES})-(?:${PALETTE})-(?:${PALETTE_STEP})(?:/\\d{1,3})?$`);
|
|
2539
2659
|
var ARBITRARY_COLOR_RE = new RegExp(
|
|
2540
2660
|
`^(?:${COLOR_PREFIXES})-\\[(?:#[0-9a-fA-F]{3,8}|(?:${COLOR_FN})\\([^\\]]*\\))\\]$`,
|
|
2541
2661
|
"i"
|
|
@@ -2562,6 +2682,7 @@ var STYLE_COLOR_PROPS = /* @__PURE__ */ new Set([
|
|
|
2562
2682
|
"lightingColor"
|
|
2563
2683
|
]);
|
|
2564
2684
|
var RAW_COLOR_VALUE_RE = new RegExp(`#[0-9a-fA-F]{3,8}\\b|\\b(?:${COLOR_FN})\\s*\\(`, "i");
|
|
2685
|
+
var CSS_VAR_REFERENCE_RE = /var\(\s*--/;
|
|
2565
2686
|
var STORIES_FILE_RE = /\.stories\.[cm]?[jt]sx?$/i;
|
|
2566
2687
|
var SEMANTIC_TOKEN_RE = /--(?: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/;
|
|
2567
2688
|
var DETECTION_FILES = [
|
|
@@ -2598,8 +2719,8 @@ var SVG_EXEMPT_COLOR_VALUES = /* @__PURE__ */ new Set([
|
|
|
2598
2719
|
]);
|
|
2599
2720
|
function jsxElementName(node) {
|
|
2600
2721
|
const name = node.openingElement.name;
|
|
2601
|
-
if (name.type ===
|
|
2602
|
-
if (name.type ===
|
|
2722
|
+
if (name.type === import_utils17.AST_NODE_TYPES.JSXIdentifier) return name.name;
|
|
2723
|
+
if (name.type === import_utils17.AST_NODE_TYPES.JSXMemberExpression && name.property.type === import_utils17.AST_NODE_TYPES.JSXIdentifier) {
|
|
2603
2724
|
return name.property.name;
|
|
2604
2725
|
}
|
|
2605
2726
|
return null;
|
|
@@ -2607,10 +2728,25 @@ function jsxElementName(node) {
|
|
|
2607
2728
|
function isSvgLikeElementName(name) {
|
|
2608
2729
|
return name === "svg" || SVG_DEFS_CONTAINERS.has(name) || /svg$/i.test(name);
|
|
2609
2730
|
}
|
|
2731
|
+
var SVG_SHAPE_PRIMITIVES = /* @__PURE__ */ new Set([
|
|
2732
|
+
"circle",
|
|
2733
|
+
"ellipse",
|
|
2734
|
+
"g",
|
|
2735
|
+
"line",
|
|
2736
|
+
"path",
|
|
2737
|
+
"polygon",
|
|
2738
|
+
"polyline",
|
|
2739
|
+
"rect",
|
|
2740
|
+
"stop",
|
|
2741
|
+
"text",
|
|
2742
|
+
"tspan",
|
|
2743
|
+
"use"
|
|
2744
|
+
]);
|
|
2745
|
+
var EMAIL_OR_PDF_IMPORT_RE = /@react-(?:email|pdf)\//;
|
|
2610
2746
|
var isInsideSvg = (node) => {
|
|
2611
2747
|
let current = node.parent;
|
|
2612
2748
|
while (current !== void 0 && current !== null) {
|
|
2613
|
-
if (current.type ===
|
|
2749
|
+
if (current.type === import_utils17.AST_NODE_TYPES.JSXElement) {
|
|
2614
2750
|
const name = jsxElementName(current);
|
|
2615
2751
|
if (name !== null && isSvgLikeElementName(name)) return true;
|
|
2616
2752
|
}
|
|
@@ -2621,7 +2757,7 @@ var isInsideSvg = (node) => {
|
|
|
2621
2757
|
var isInsideIconFactoryPath = (node) => {
|
|
2622
2758
|
let current = node.parent;
|
|
2623
2759
|
while (current !== void 0 && current !== null) {
|
|
2624
|
-
if (current.type ===
|
|
2760
|
+
if (current.type === import_utils17.AST_NODE_TYPES.Property && propName(current.key) === "path" && current.parent.type === import_utils17.AST_NODE_TYPES.ObjectExpression && current.parent.parent.type === import_utils17.AST_NODE_TYPES.CallExpression && current.parent.parent.callee.type === import_utils17.AST_NODE_TYPES.Identifier && current.parent.parent.callee.name === "createIcon") {
|
|
2625
2761
|
return true;
|
|
2626
2762
|
}
|
|
2627
2763
|
current = current.parent;
|
|
@@ -2671,11 +2807,11 @@ var hasSemanticTokenSystem = (filename) => {
|
|
|
2671
2807
|
return answer;
|
|
2672
2808
|
};
|
|
2673
2809
|
var propName = (key) => {
|
|
2674
|
-
if (key.type ===
|
|
2675
|
-
if (key.type ===
|
|
2810
|
+
if (key.type === import_utils17.AST_NODE_TYPES.Identifier) return key.name;
|
|
2811
|
+
if (key.type === import_utils17.AST_NODE_TYPES.Literal && typeof key.value === "string") return key.value;
|
|
2676
2812
|
return null;
|
|
2677
2813
|
};
|
|
2678
|
-
var prefer_semantic_colors_default =
|
|
2814
|
+
var prefer_semantic_colors_default = import_utils17.ESLintUtils.RuleCreator(
|
|
2679
2815
|
(name) => `https://github.com/sarj-ai/standards/blob/main/packages/typescript/src/rules/${name}.ts`
|
|
2680
2816
|
)({
|
|
2681
2817
|
name: "prefer-semantic-colors",
|
|
@@ -2702,6 +2838,7 @@ var prefer_semantic_colors_default = import_utils18.ESLintUtils.RuleCreator(
|
|
|
2702
2838
|
defaultOptions: [{}],
|
|
2703
2839
|
create(context, [options]) {
|
|
2704
2840
|
if (STORIES_FILE_RE.test(context.filename)) return {};
|
|
2841
|
+
if (EMAIL_OR_PDF_IMPORT_RE.test(context.sourceCode.getText())) return {};
|
|
2705
2842
|
if (options?.requireSemanticTokens === true && !hasSemanticTokenSystem(context.filename)) {
|
|
2706
2843
|
return {};
|
|
2707
2844
|
}
|
|
@@ -2710,7 +2847,7 @@ var prefer_semantic_colors_default = import_utils18.ESLintUtils.RuleCreator(
|
|
|
2710
2847
|
const base = tailwindBase(token);
|
|
2711
2848
|
if (RAW_PALETTE_RE.test(base)) {
|
|
2712
2849
|
context.report({ node, messageId: "rawPalette", data: { class: token } });
|
|
2713
|
-
} else if (ARBITRARY_COLOR_RE.test(base)) {
|
|
2850
|
+
} else if (ARBITRARY_COLOR_RE.test(base) && !CSS_VAR_REFERENCE_RE.test(base)) {
|
|
2714
2851
|
context.report({ node, messageId: "arbitraryColor", data: { class: token } });
|
|
2715
2852
|
}
|
|
2716
2853
|
}
|
|
@@ -2718,27 +2855,27 @@ var prefer_semantic_colors_default = import_utils18.ESLintUtils.RuleCreator(
|
|
|
2718
2855
|
const checkClassNode = (node) => {
|
|
2719
2856
|
if (node === null) return;
|
|
2720
2857
|
switch (node.type) {
|
|
2721
|
-
case
|
|
2858
|
+
case import_utils17.AST_NODE_TYPES.Literal:
|
|
2722
2859
|
if (typeof node.value === "string") reportClasses(node.value, node);
|
|
2723
2860
|
break;
|
|
2724
|
-
case
|
|
2861
|
+
case import_utils17.AST_NODE_TYPES.TemplateLiteral:
|
|
2725
2862
|
for (const quasi of node.quasis) reportClasses(quasi.value.cooked ?? "", quasi);
|
|
2726
2863
|
break;
|
|
2727
|
-
case
|
|
2864
|
+
case import_utils17.AST_NODE_TYPES.ArrayExpression:
|
|
2728
2865
|
for (const element of node.elements) {
|
|
2729
|
-
if (element !== null && element.type !==
|
|
2866
|
+
if (element !== null && element.type !== import_utils17.AST_NODE_TYPES.SpreadElement) checkClassNode(element);
|
|
2730
2867
|
}
|
|
2731
2868
|
break;
|
|
2732
|
-
case
|
|
2869
|
+
case import_utils17.AST_NODE_TYPES.ObjectExpression:
|
|
2733
2870
|
for (const property of node.properties) {
|
|
2734
|
-
if (property.type ===
|
|
2871
|
+
if (property.type === import_utils17.AST_NODE_TYPES.Property) checkClassNode(property.value);
|
|
2735
2872
|
}
|
|
2736
2873
|
break;
|
|
2737
|
-
case
|
|
2874
|
+
case import_utils17.AST_NODE_TYPES.ConditionalExpression:
|
|
2738
2875
|
checkClassNode(node.consequent);
|
|
2739
2876
|
checkClassNode(node.alternate);
|
|
2740
2877
|
break;
|
|
2741
|
-
case
|
|
2878
|
+
case import_utils17.AST_NODE_TYPES.LogicalExpression:
|
|
2742
2879
|
checkClassNode(node.right);
|
|
2743
2880
|
break;
|
|
2744
2881
|
default:
|
|
@@ -2746,29 +2883,29 @@ var prefer_semantic_colors_default = import_utils18.ESLintUtils.RuleCreator(
|
|
|
2746
2883
|
}
|
|
2747
2884
|
};
|
|
2748
2885
|
const checkColorValueNode = (node) => {
|
|
2749
|
-
if (node.type ===
|
|
2886
|
+
if (node.type === import_utils17.AST_NODE_TYPES.Literal && typeof node.value === "string" && RAW_COLOR_VALUE_RE.test(node.value) && !CSS_VAR_REFERENCE_RE.test(node.value)) {
|
|
2750
2887
|
context.report({ node, messageId: "inlineColor", data: { value: node.value } });
|
|
2751
2888
|
}
|
|
2752
2889
|
};
|
|
2753
2890
|
return {
|
|
2754
2891
|
"JSXAttribute[name.name='className']"(node) {
|
|
2755
2892
|
if (node.value === null) return;
|
|
2756
|
-
if (node.value.type ===
|
|
2757
|
-
else if (node.value.type ===
|
|
2758
|
-
if (node.value.expression.type !==
|
|
2893
|
+
if (node.value.type === import_utils17.AST_NODE_TYPES.Literal) checkClassNode(node.value);
|
|
2894
|
+
else if (node.value.type === import_utils17.AST_NODE_TYPES.JSXExpressionContainer) {
|
|
2895
|
+
if (node.value.expression.type !== import_utils17.AST_NODE_TYPES.JSXEmptyExpression) {
|
|
2759
2896
|
checkClassNode(node.value.expression);
|
|
2760
2897
|
}
|
|
2761
2898
|
}
|
|
2762
2899
|
},
|
|
2763
2900
|
CallExpression(node) {
|
|
2764
|
-
if (node.callee.type ===
|
|
2901
|
+
if (node.callee.type === import_utils17.AST_NODE_TYPES.Identifier && CLASS_FNS.has(node.callee.name)) {
|
|
2765
2902
|
for (const arg of node.arguments) {
|
|
2766
|
-
if (arg.type !==
|
|
2903
|
+
if (arg.type !== import_utils17.AST_NODE_TYPES.SpreadElement) checkClassNode(arg);
|
|
2767
2904
|
}
|
|
2768
2905
|
}
|
|
2769
2906
|
},
|
|
2770
2907
|
VariableDeclarator(node) {
|
|
2771
|
-
if (node.id.type ===
|
|
2908
|
+
if (node.id.type === import_utils17.AST_NODE_TYPES.Identifier && CLASS_NAME_RE.test(node.id.name)) {
|
|
2772
2909
|
checkClassNode(node.init);
|
|
2773
2910
|
}
|
|
2774
2911
|
},
|
|
@@ -2780,7 +2917,11 @@ var prefer_semantic_colors_default = import_utils18.ESLintUtils.RuleCreator(
|
|
|
2780
2917
|
// Neutral drawing literals and anything inside an SVG defs container are
|
|
2781
2918
|
// structural, not UI tokens, so they never fire.
|
|
2782
2919
|
"JSXAttribute[name.name=/^(fill|stroke|color)$/]"(node) {
|
|
2783
|
-
if (node.value?.type !==
|
|
2920
|
+
if (node.value?.type !== import_utils17.AST_NODE_TYPES.Literal) return;
|
|
2921
|
+
const owner = node.parent.name;
|
|
2922
|
+
if (owner.type === import_utils17.AST_NODE_TYPES.JSXIdentifier && SVG_SHAPE_PRIMITIVES.has(owner.name)) {
|
|
2923
|
+
return;
|
|
2924
|
+
}
|
|
2784
2925
|
if (typeof node.value.value === "string" && SVG_EXEMPT_COLOR_VALUES.has(node.value.value.toLowerCase())) {
|
|
2785
2926
|
return;
|
|
2786
2927
|
}
|
|
@@ -2797,7 +2938,7 @@ var prefer_semantic_colors_default = import_utils18.ESLintUtils.RuleCreator(
|
|
|
2797
2938
|
});
|
|
2798
2939
|
|
|
2799
2940
|
// src/rules/prefer-server-actions.ts
|
|
2800
|
-
var
|
|
2941
|
+
var import_utils18 = require("@typescript-eslint/utils");
|
|
2801
2942
|
var MUTATION_METHODS = /* @__PURE__ */ new Set(["POST", "PUT", "DELETE", "PATCH"]);
|
|
2802
2943
|
var AXIOS_MUTATION_METHODS = /* @__PURE__ */ new Set(["post", "put", "delete", "patch"]);
|
|
2803
2944
|
var SKIP_FILE_REGEX = /(?:\.test\.[jt]sx?$|\.spec\.[jt]sx?$|-(?:test|spec)\.[jt]sx?$|\/tests?\/|\/__tests__\/|\/__testfixtures__\/|\/scripts?\/|\/app\/api\/.*\/route\.[jt]sx?$|\/pages\/api\/)/;
|
|
@@ -2877,7 +3018,7 @@ function getPropertyNode(objNode, propName2) {
|
|
|
2877
3018
|
}
|
|
2878
3019
|
return null;
|
|
2879
3020
|
}
|
|
2880
|
-
var prefer_server_actions_default =
|
|
3021
|
+
var prefer_server_actions_default = import_utils18.ESLintUtils.RuleCreator(
|
|
2881
3022
|
(name) => `https://github.com/sarj-ai/linting/blob/main/packages/typescript/src/rules/${name}.ts`
|
|
2882
3023
|
)({
|
|
2883
3024
|
name: "prefer-server-actions",
|
|
@@ -2952,36 +3093,36 @@ var prefer_server_actions_default = import_utils19.ESLintUtils.RuleCreator(
|
|
|
2952
3093
|
});
|
|
2953
3094
|
|
|
2954
3095
|
// src/rules/require-assert-never.ts
|
|
2955
|
-
var
|
|
3096
|
+
var import_utils19 = require("@typescript-eslint/utils");
|
|
2956
3097
|
var isAssertNeverCall = (expression) => {
|
|
2957
|
-
if (expression.type !==
|
|
3098
|
+
if (expression.type !== import_utils19.AST_NODE_TYPES.CallExpression) return false;
|
|
2958
3099
|
const callee = expression.callee;
|
|
2959
|
-
if (callee.type ===
|
|
3100
|
+
if (callee.type === import_utils19.AST_NODE_TYPES.Identifier) {
|
|
2960
3101
|
return callee.name === "assertNever";
|
|
2961
3102
|
}
|
|
2962
|
-
if (callee.type ===
|
|
3103
|
+
if (callee.type === import_utils19.AST_NODE_TYPES.MemberExpression && !callee.computed && callee.property.type === import_utils19.AST_NODE_TYPES.Identifier) {
|
|
2963
3104
|
return callee.property.name === "assertNever";
|
|
2964
3105
|
}
|
|
2965
3106
|
return false;
|
|
2966
3107
|
};
|
|
2967
3108
|
var statementContainsAssertNever = (statement) => {
|
|
2968
|
-
if (statement.type ===
|
|
3109
|
+
if (statement.type === import_utils19.AST_NODE_TYPES.ExpressionStatement) {
|
|
2969
3110
|
return isAssertNeverCall(statement.expression);
|
|
2970
3111
|
}
|
|
2971
|
-
if (statement.type ===
|
|
3112
|
+
if (statement.type === import_utils19.AST_NODE_TYPES.ThrowStatement) {
|
|
2972
3113
|
return isAssertNeverCall(statement.argument);
|
|
2973
3114
|
}
|
|
2974
|
-
if (statement.type ===
|
|
3115
|
+
if (statement.type === import_utils19.AST_NODE_TYPES.ReturnStatement) {
|
|
2975
3116
|
return statement.argument !== null && isAssertNeverCall(statement.argument);
|
|
2976
3117
|
}
|
|
2977
|
-
if (statement.type ===
|
|
3118
|
+
if (statement.type === import_utils19.AST_NODE_TYPES.BlockStatement) {
|
|
2978
3119
|
return statement.body.some(statementContainsAssertNever);
|
|
2979
3120
|
}
|
|
2980
3121
|
return false;
|
|
2981
3122
|
};
|
|
2982
3123
|
var isRuntimeHandlingStatement = (statement) => {
|
|
2983
|
-
if (statement.type ===
|
|
2984
|
-
if (statement.type ===
|
|
3124
|
+
if (statement.type === import_utils19.AST_NODE_TYPES.EmptyStatement) return false;
|
|
3125
|
+
if (statement.type === import_utils19.AST_NODE_TYPES.BlockStatement) {
|
|
2985
3126
|
return statement.body.some(isRuntimeHandlingStatement);
|
|
2986
3127
|
}
|
|
2987
3128
|
return true;
|
|
@@ -2997,12 +3138,12 @@ var isCommentOnlyNoopDefault = (defaultCase, sourceCode) => {
|
|
|
2997
3138
|
return colonToken !== null && sourceCode.getCommentsAfter(colonToken).length > 0;
|
|
2998
3139
|
}
|
|
2999
3140
|
const only = defaultCase.consequent[0];
|
|
3000
|
-
if (only !== void 0 && defaultCase.consequent.length === 1 && only.type ===
|
|
3141
|
+
if (only !== void 0 && defaultCase.consequent.length === 1 && only.type === import_utils19.AST_NODE_TYPES.BlockStatement && only.body.length === 0) {
|
|
3001
3142
|
return sourceCode.getCommentsInside(only).length > 0;
|
|
3002
3143
|
}
|
|
3003
3144
|
return false;
|
|
3004
3145
|
};
|
|
3005
|
-
var require_assert_never_default =
|
|
3146
|
+
var require_assert_never_default = import_utils19.ESLintUtils.RuleCreator(
|
|
3006
3147
|
(name) => `https://github.com/sarj-ai/linting/blob/main/packages/typescript/src/rules/${name}.ts`
|
|
3007
3148
|
)({
|
|
3008
3149
|
name: "require-assert-never",
|
|
@@ -3040,7 +3181,7 @@ var require_assert_never_default = import_utils20.ESLintUtils.RuleCreator(
|
|
|
3040
3181
|
});
|
|
3041
3182
|
|
|
3042
3183
|
// src/rules/require-zod-form-validation.ts
|
|
3043
|
-
var
|
|
3184
|
+
var import_utils20 = require("@typescript-eslint/utils");
|
|
3044
3185
|
|
|
3045
3186
|
// src/rules/_zod.ts
|
|
3046
3187
|
var ZOD_PREFIX_RE = /^Z[A-Z]/;
|
|
@@ -3054,14 +3195,14 @@ function isZodModule(source) {
|
|
|
3054
3195
|
var looksLikeZodSchema = (node) => {
|
|
3055
3196
|
let current = node;
|
|
3056
3197
|
while (true) {
|
|
3057
|
-
if (current.type ===
|
|
3198
|
+
if (current.type === import_utils20.AST_NODE_TYPES.Identifier) {
|
|
3058
3199
|
return current.name === "z" || ZOD_SCHEMA_NAME_RE.test(current.name);
|
|
3059
3200
|
}
|
|
3060
|
-
if (current.type ===
|
|
3201
|
+
if (current.type === import_utils20.AST_NODE_TYPES.CallExpression) {
|
|
3061
3202
|
current = current.callee;
|
|
3062
3203
|
continue;
|
|
3063
3204
|
}
|
|
3064
|
-
if (current.type ===
|
|
3205
|
+
if (current.type === import_utils20.AST_NODE_TYPES.MemberExpression) {
|
|
3065
3206
|
current = current.object;
|
|
3066
3207
|
continue;
|
|
3067
3208
|
}
|
|
@@ -3069,25 +3210,25 @@ var looksLikeZodSchema = (node) => {
|
|
|
3069
3210
|
}
|
|
3070
3211
|
};
|
|
3071
3212
|
var isZodParseCall = (node) => {
|
|
3072
|
-
if (node.type !==
|
|
3213
|
+
if (node.type !== import_utils20.AST_NODE_TYPES.CallExpression) return false;
|
|
3073
3214
|
const callee = node.callee;
|
|
3074
|
-
if (callee.type !==
|
|
3215
|
+
if (callee.type !== import_utils20.AST_NODE_TYPES.MemberExpression) return false;
|
|
3075
3216
|
if (callee.computed) return false;
|
|
3076
|
-
if (callee.property.type !==
|
|
3217
|
+
if (callee.property.type !== import_utils20.AST_NODE_TYPES.Identifier) return false;
|
|
3077
3218
|
const method = callee.property.name;
|
|
3078
3219
|
if (method !== "parse" && method !== "safeParse") return false;
|
|
3079
3220
|
return looksLikeZodSchema(callee.object);
|
|
3080
3221
|
};
|
|
3081
3222
|
var isFormDataMethodCall = (node) => {
|
|
3082
3223
|
let current = node;
|
|
3083
|
-
if (current.type ===
|
|
3224
|
+
if (current.type === import_utils20.AST_NODE_TYPES.AwaitExpression) {
|
|
3084
3225
|
current = current.argument;
|
|
3085
3226
|
}
|
|
3086
|
-
if (current.type !==
|
|
3227
|
+
if (current.type !== import_utils20.AST_NODE_TYPES.CallExpression) return false;
|
|
3087
3228
|
const callee = current.callee;
|
|
3088
|
-
return callee.type ===
|
|
3229
|
+
return callee.type === import_utils20.AST_NODE_TYPES.MemberExpression && !callee.computed && callee.property.type === import_utils20.AST_NODE_TYPES.Identifier && callee.property.name === "formData";
|
|
3089
3230
|
};
|
|
3090
|
-
var require_zod_form_validation_default =
|
|
3231
|
+
var require_zod_form_validation_default = import_utils20.ESLintUtils.RuleCreator(
|
|
3091
3232
|
(name) => `https://github.com/sarj-ai/linting/blob/main/packages/typescript/src/rules/${name}.ts`
|
|
3092
3233
|
)({
|
|
3093
3234
|
name: "require-zod-form-validation",
|
|
@@ -3107,14 +3248,14 @@ var require_zod_form_validation_default = import_utils21.ESLintUtils.RuleCreator
|
|
|
3107
3248
|
return {};
|
|
3108
3249
|
}
|
|
3109
3250
|
const isFormSourceIdentifier = (node) => {
|
|
3110
|
-
if (node.type !==
|
|
3251
|
+
if (node.type !== import_utils20.AST_NODE_TYPES.Identifier) return false;
|
|
3111
3252
|
if (/formdata/i.test(node.name)) return true;
|
|
3112
3253
|
let scope = context.sourceCode.getScope(node);
|
|
3113
3254
|
while (scope !== null) {
|
|
3114
3255
|
const variable = scope.set.get(node.name);
|
|
3115
3256
|
if (variable !== void 0 && variable.defs.length === 1) {
|
|
3116
3257
|
const def = variable.defs[0];
|
|
3117
|
-
if (def !== void 0 && def.type === "Variable" && def.node.type ===
|
|
3258
|
+
if (def !== void 0 && def.type === "Variable" && def.node.type === import_utils20.AST_NODE_TYPES.VariableDeclarator && def.node.init !== null) {
|
|
3118
3259
|
return isFormDataMethodCall(def.node.init);
|
|
3119
3260
|
}
|
|
3120
3261
|
return false;
|
|
@@ -3125,8 +3266,8 @@ var require_zod_form_validation_default = import_utils21.ESLintUtils.RuleCreator
|
|
|
3125
3266
|
};
|
|
3126
3267
|
const isFormDataGetCall = (node) => {
|
|
3127
3268
|
const callee = node.callee;
|
|
3128
|
-
if (callee.type !==
|
|
3129
|
-
if (callee.property.type !==
|
|
3269
|
+
if (callee.type !== import_utils20.AST_NODE_TYPES.MemberExpression) return false;
|
|
3270
|
+
if (callee.property.type !== import_utils20.AST_NODE_TYPES.Identifier || callee.property.name !== "get") {
|
|
3130
3271
|
return false;
|
|
3131
3272
|
}
|
|
3132
3273
|
return isFormSourceIdentifier(callee.object);
|
|
@@ -3141,11 +3282,11 @@ var require_zod_form_validation_default = import_utils21.ESLintUtils.RuleCreator
|
|
|
3141
3282
|
};
|
|
3142
3283
|
const isInstanceofNarrowing = (node) => {
|
|
3143
3284
|
const parent = node.parent;
|
|
3144
|
-
return parent !== null && parent !== void 0 && parent.type ===
|
|
3285
|
+
return parent !== null && parent !== void 0 && parent.type === import_utils20.AST_NODE_TYPES.BinaryExpression && parent.operator === "instanceof" && parent.left === node;
|
|
3145
3286
|
};
|
|
3146
3287
|
const boundDeclarator = (node) => {
|
|
3147
3288
|
const parent = node.parent;
|
|
3148
|
-
if (parent.type ===
|
|
3289
|
+
if (parent.type === import_utils20.AST_NODE_TYPES.VariableDeclarator && parent.init === node && parent.id.type === import_utils20.AST_NODE_TYPES.Identifier) {
|
|
3149
3290
|
return parent;
|
|
3150
3291
|
}
|
|
3151
3292
|
return null;
|
|
@@ -3173,13 +3314,14 @@ var require_zod_form_validation_default = import_utils21.ESLintUtils.RuleCreator
|
|
|
3173
3314
|
});
|
|
3174
3315
|
|
|
3175
3316
|
// src/rules/zod-naming-convention.ts
|
|
3176
|
-
var
|
|
3317
|
+
var import_utils21 = require("@typescript-eslint/utils");
|
|
3177
3318
|
var CONVENTIONS = {
|
|
3178
3319
|
prefix: { test: ZOD_PREFIX_RE, messageId: "zPrefix" },
|
|
3179
3320
|
suffix: { test: ZOD_SUFFIX_RE, messageId: "schemaSuffix" },
|
|
3180
3321
|
either: { test: ZOD_SCHEMA_NAME_RE, messageId: "zodSchemaName" }
|
|
3181
3322
|
};
|
|
3182
3323
|
var CONTAINS_SCHEMA_RE = /schema/i;
|
|
3324
|
+
var BENCHMARK_PATH_RE = /(^|[\\/])(?:benchmarks?|bench)[\\/]/;
|
|
3183
3325
|
var NON_SCHEMA_TERMINALS = /* @__PURE__ */ new Set([
|
|
3184
3326
|
"parse",
|
|
3185
3327
|
"parseAsync",
|
|
@@ -3197,15 +3339,15 @@ var NON_SCHEMA_TERMINALS = /* @__PURE__ */ new Set([
|
|
|
3197
3339
|
"registry",
|
|
3198
3340
|
"implement"
|
|
3199
3341
|
]);
|
|
3200
|
-
var terminalMethodName = (callee) => !callee.computed && callee.property.type ===
|
|
3342
|
+
var terminalMethodName = (callee) => !callee.computed && callee.property.type === import_utils21.AST_NODE_TYPES.Identifier ? callee.property.name : null;
|
|
3201
3343
|
var calleeChainStartsWithZ = (node) => {
|
|
3202
3344
|
let current = node;
|
|
3203
|
-
while (current.type ===
|
|
3345
|
+
while (current.type === import_utils21.AST_NODE_TYPES.MemberExpression) {
|
|
3204
3346
|
const receiver = current.object;
|
|
3205
|
-
if (receiver.type ===
|
|
3347
|
+
if (receiver.type === import_utils21.AST_NODE_TYPES.Identifier && receiver.name === "z") {
|
|
3206
3348
|
return true;
|
|
3207
3349
|
}
|
|
3208
|
-
if (receiver.type ===
|
|
3350
|
+
if (receiver.type === import_utils21.AST_NODE_TYPES.CallExpression) {
|
|
3209
3351
|
current = receiver.callee;
|
|
3210
3352
|
continue;
|
|
3211
3353
|
}
|
|
@@ -3213,7 +3355,7 @@ var calleeChainStartsWithZ = (node) => {
|
|
|
3213
3355
|
}
|
|
3214
3356
|
return false;
|
|
3215
3357
|
};
|
|
3216
|
-
var zod_naming_convention_default =
|
|
3358
|
+
var zod_naming_convention_default = import_utils21.ESLintUtils.RuleCreator(
|
|
3217
3359
|
(name) => `https://github.com/sarj-ai/linting/blob/main/packages/typescript/src/rules/${name}.ts`
|
|
3218
3360
|
)({
|
|
3219
3361
|
name: "zod-naming-convention",
|
|
@@ -3245,20 +3387,20 @@ var zod_naming_convention_default = import_utils22.ESLintUtils.RuleCreator(
|
|
|
3245
3387
|
const convention = optionsArg?.convention ?? "either";
|
|
3246
3388
|
const { test, messageId } = CONVENTIONS[convention];
|
|
3247
3389
|
const acceptsSchemaWord = convention !== "prefix";
|
|
3248
|
-
if (isTestFile(context.filename) || isGeneratedFile(context.filename, context.sourceCode.text)) {
|
|
3390
|
+
if (isTestFile(context.filename) || BENCHMARK_PATH_RE.test(context.filename.replaceAll("\\", "/")) || isGeneratedFile(context.filename, context.sourceCode.text)) {
|
|
3249
3391
|
return {};
|
|
3250
3392
|
}
|
|
3251
3393
|
return {
|
|
3252
3394
|
VariableDeclarator(node) {
|
|
3253
3395
|
const init = node.init;
|
|
3254
3396
|
if (init === null || init === void 0) return;
|
|
3255
|
-
if (init.type !==
|
|
3397
|
+
if (init.type !== import_utils21.AST_NODE_TYPES.CallExpression) return;
|
|
3256
3398
|
const callee = init.callee;
|
|
3257
|
-
if (callee.type !==
|
|
3399
|
+
if (callee.type !== import_utils21.AST_NODE_TYPES.MemberExpression) return;
|
|
3258
3400
|
if (!calleeChainStartsWithZ(callee)) return;
|
|
3259
3401
|
const terminal = terminalMethodName(callee);
|
|
3260
3402
|
if (terminal !== null && NON_SCHEMA_TERMINALS.has(terminal)) return;
|
|
3261
|
-
if (node.id.type !==
|
|
3403
|
+
if (node.id.type !== import_utils21.AST_NODE_TYPES.Identifier) return;
|
|
3262
3404
|
if (test.test(node.id.name)) return;
|
|
3263
3405
|
if (acceptsSchemaWord && CONTAINS_SCHEMA_RE.test(node.id.name)) return;
|
|
3264
3406
|
context.report({
|
|
@@ -3271,7 +3413,7 @@ var zod_naming_convention_default = import_utils22.ESLintUtils.RuleCreator(
|
|
|
3271
3413
|
});
|
|
3272
3414
|
|
|
3273
3415
|
// src/rules/no-cors-wildcard-with-credentials.ts
|
|
3274
|
-
var
|
|
3416
|
+
var import_utils22 = require("@typescript-eslint/utils");
|
|
3275
3417
|
var ACAO_HEADER = "access-control-allow-origin";
|
|
3276
3418
|
var ACAC_HEADER = "access-control-allow-credentials";
|
|
3277
3419
|
var HEADER_SET_METHODS = /* @__PURE__ */ new Set(["setheader", "set", "append"]);
|
|
@@ -3413,7 +3555,7 @@ function enclosingScope(node) {
|
|
|
3413
3555
|
}
|
|
3414
3556
|
return void 0;
|
|
3415
3557
|
}
|
|
3416
|
-
var no_cors_wildcard_with_credentials_default =
|
|
3558
|
+
var no_cors_wildcard_with_credentials_default = import_utils22.ESLintUtils.RuleCreator(
|
|
3417
3559
|
(name) => `https://github.com/sarj-ai/linting/blob/main/packages/typescript/src/rules/${name}.ts`
|
|
3418
3560
|
)({
|
|
3419
3561
|
name: "no-cors-wildcard-with-credentials",
|
|
@@ -3481,9 +3623,9 @@ var no_cors_wildcard_with_credentials_default = import_utils23.ESLintUtils.RuleC
|
|
|
3481
3623
|
});
|
|
3482
3624
|
|
|
3483
3625
|
// src/rules/no-silent-promise-catch.ts
|
|
3484
|
-
var
|
|
3626
|
+
var import_utils23 = require("@typescript-eslint/utils");
|
|
3485
3627
|
function isBodyParseCall(node) {
|
|
3486
|
-
return node.type ===
|
|
3628
|
+
return node.type === import_utils23.AST_NODE_TYPES.CallExpression && node.arguments.length === 0 && node.callee.type === import_utils23.AST_NODE_TYPES.MemberExpression && !node.callee.computed && node.callee.property.type === import_utils23.AST_NODE_TYPES.Identifier && (node.callee.property.name === "json" || node.callee.property.name === "text");
|
|
3487
3629
|
}
|
|
3488
3630
|
var TEARDOWN_METHODS = /* @__PURE__ */ new Set([
|
|
3489
3631
|
"cancel",
|
|
@@ -3498,21 +3640,21 @@ var TEARDOWN_METHODS = /* @__PURE__ */ new Set([
|
|
|
3498
3640
|
var DIRECTIVE_COMMENT_RE = /^\s*(eslint-|@ts-|prettier-ignore|biome-ignore|c8 |v8 |istanbul )/;
|
|
3499
3641
|
var isExplanatory = (comment) => !DIRECTIVE_COMMENT_RE.test(comment.value);
|
|
3500
3642
|
function isTeardownCall(node) {
|
|
3501
|
-
return node.type ===
|
|
3643
|
+
return node.type === import_utils23.AST_NODE_TYPES.CallExpression && node.callee.type === import_utils23.AST_NODE_TYPES.MemberExpression && !node.callee.computed && node.callee.property.type === import_utils23.AST_NODE_TYPES.Identifier && TEARDOWN_METHODS.has(node.callee.property.name);
|
|
3502
3644
|
}
|
|
3503
3645
|
function isSilentExpression(node) {
|
|
3504
3646
|
switch (node.type) {
|
|
3505
|
-
case
|
|
3647
|
+
case import_utils23.AST_NODE_TYPES.Literal:
|
|
3506
3648
|
return !("regex" in node);
|
|
3507
|
-
case
|
|
3649
|
+
case import_utils23.AST_NODE_TYPES.Identifier:
|
|
3508
3650
|
return node.name === "undefined";
|
|
3509
|
-
case
|
|
3510
|
-
return node.operator === "void" && node.argument.type ===
|
|
3511
|
-
case
|
|
3651
|
+
case import_utils23.AST_NODE_TYPES.UnaryExpression:
|
|
3652
|
+
return node.operator === "void" && node.argument.type === import_utils23.AST_NODE_TYPES.Literal;
|
|
3653
|
+
case import_utils23.AST_NODE_TYPES.ObjectExpression:
|
|
3512
3654
|
return node.properties.length === 0;
|
|
3513
|
-
case
|
|
3655
|
+
case import_utils23.AST_NODE_TYPES.ArrayExpression:
|
|
3514
3656
|
return node.elements.length === 0;
|
|
3515
|
-
case
|
|
3657
|
+
case import_utils23.AST_NODE_TYPES.TSAsExpression:
|
|
3516
3658
|
return isSilentExpression(node.expression);
|
|
3517
3659
|
default:
|
|
3518
3660
|
return false;
|
|
@@ -3520,7 +3662,7 @@ function isSilentExpression(node) {
|
|
|
3520
3662
|
}
|
|
3521
3663
|
function isSilentHandler(handler) {
|
|
3522
3664
|
const body = handler.body;
|
|
3523
|
-
if (body.type !==
|
|
3665
|
+
if (body.type !== import_utils23.AST_NODE_TYPES.BlockStatement) {
|
|
3524
3666
|
return isSilentExpression(body);
|
|
3525
3667
|
}
|
|
3526
3668
|
if (body.body.length === 0) {
|
|
@@ -3528,13 +3670,13 @@ function isSilentHandler(handler) {
|
|
|
3528
3670
|
}
|
|
3529
3671
|
if (body.body.length === 1) {
|
|
3530
3672
|
const only = body.body[0];
|
|
3531
|
-
if (only !== void 0 && only.type ===
|
|
3673
|
+
if (only !== void 0 && only.type === import_utils23.AST_NODE_TYPES.ReturnStatement) {
|
|
3532
3674
|
return only.argument === null || isSilentExpression(only.argument);
|
|
3533
3675
|
}
|
|
3534
3676
|
}
|
|
3535
3677
|
return false;
|
|
3536
3678
|
}
|
|
3537
|
-
var no_silent_promise_catch_default =
|
|
3679
|
+
var no_silent_promise_catch_default = import_utils23.ESLintUtils.RuleCreator(
|
|
3538
3680
|
(name) => `https://github.com/sarj-ai/linting/blob/main/packages/typescript/src/rules/${name}.ts`
|
|
3539
3681
|
)({
|
|
3540
3682
|
name: "no-silent-promise-catch",
|
|
@@ -3559,7 +3701,7 @@ var no_silent_promise_catch_default = import_utils24.ESLintUtils.RuleCreator(
|
|
|
3559
3701
|
return true;
|
|
3560
3702
|
}
|
|
3561
3703
|
let statement = call;
|
|
3562
|
-
while (statement.parent !== void 0 && statement.parent !== null && !statement.type.endsWith("Statement") && statement.type !==
|
|
3704
|
+
while (statement.parent !== void 0 && statement.parent !== null && !statement.type.endsWith("Statement") && statement.type !== import_utils23.AST_NODE_TYPES.VariableDeclaration) {
|
|
3563
3705
|
statement = statement.parent;
|
|
3564
3706
|
}
|
|
3565
3707
|
if (sourceCode.getCommentsBefore(statement).some(isExplanatory)) {
|
|
@@ -3571,7 +3713,7 @@ var no_silent_promise_catch_default = import_utils24.ESLintUtils.RuleCreator(
|
|
|
3571
3713
|
};
|
|
3572
3714
|
return {
|
|
3573
3715
|
CallExpression(node) {
|
|
3574
|
-
if (node.callee.type !==
|
|
3716
|
+
if (node.callee.type !== import_utils23.AST_NODE_TYPES.MemberExpression || node.callee.computed || node.callee.property.type !== import_utils23.AST_NODE_TYPES.Identifier || node.callee.property.name !== "catch") {
|
|
3575
3717
|
return;
|
|
3576
3718
|
}
|
|
3577
3719
|
if (isBodyParseCall(node.callee.object)) {
|
|
@@ -3580,14 +3722,14 @@ var no_silent_promise_catch_default = import_utils24.ESLintUtils.RuleCreator(
|
|
|
3580
3722
|
if (isTeardownCall(node.callee.object)) {
|
|
3581
3723
|
return;
|
|
3582
3724
|
}
|
|
3583
|
-
if (node.parent.type ===
|
|
3725
|
+
if (node.parent.type === import_utils23.AST_NODE_TYPES.MemberExpression && node.parent.object === node) {
|
|
3584
3726
|
return;
|
|
3585
3727
|
}
|
|
3586
3728
|
if (node.arguments.length !== 1) {
|
|
3587
3729
|
return;
|
|
3588
3730
|
}
|
|
3589
3731
|
const handler = node.arguments[0];
|
|
3590
|
-
if (handler === void 0 || handler.type !==
|
|
3732
|
+
if (handler === void 0 || handler.type !== import_utils23.AST_NODE_TYPES.ArrowFunctionExpression && handler.type !== import_utils23.AST_NODE_TYPES.FunctionExpression) {
|
|
3591
3733
|
return;
|
|
3592
3734
|
}
|
|
3593
3735
|
if (hasExplanatoryComment(node, handler)) {
|
|
@@ -3602,7 +3744,7 @@ var no_silent_promise_catch_default = import_utils24.ESLintUtils.RuleCreator(
|
|
|
3602
3744
|
});
|
|
3603
3745
|
|
|
3604
3746
|
// src/rules/require-fetch-timeout.ts
|
|
3605
|
-
var
|
|
3747
|
+
var import_utils24 = require("@typescript-eslint/utils");
|
|
3606
3748
|
var CODEMOD_FIXTURE_RE = /[\\/]__testfixtures__[\\/]/;
|
|
3607
3749
|
var GLOBAL_OBJECTS = /* @__PURE__ */ new Set([
|
|
3608
3750
|
"globalThis",
|
|
@@ -3619,14 +3761,14 @@ function matchesAnyPattern2(filename, patterns) {
|
|
|
3619
3761
|
return false;
|
|
3620
3762
|
}
|
|
3621
3763
|
function initProvablyLacksSignal(init) {
|
|
3622
|
-
if (init.type !==
|
|
3764
|
+
if (init.type !== import_utils24.AST_NODE_TYPES.ObjectExpression) {
|
|
3623
3765
|
return false;
|
|
3624
3766
|
}
|
|
3625
3767
|
for (const prop of init.properties) {
|
|
3626
|
-
if (prop.type ===
|
|
3768
|
+
if (prop.type === import_utils24.AST_NODE_TYPES.SpreadElement) {
|
|
3627
3769
|
return false;
|
|
3628
3770
|
}
|
|
3629
|
-
if (prop.key.type ===
|
|
3771
|
+
if (prop.key.type === import_utils24.AST_NODE_TYPES.Identifier && prop.key.name === "signal" || prop.key.type === import_utils24.AST_NODE_TYPES.Literal && prop.key.value === "signal") {
|
|
3630
3772
|
return false;
|
|
3631
3773
|
}
|
|
3632
3774
|
if (prop.computed) {
|
|
@@ -3636,9 +3778,9 @@ function initProvablyLacksSignal(init) {
|
|
|
3636
3778
|
return true;
|
|
3637
3779
|
}
|
|
3638
3780
|
function isStringish(node) {
|
|
3639
|
-
return node.type ===
|
|
3781
|
+
return node.type === import_utils24.AST_NODE_TYPES.Literal && typeof node.value === "string" || node.type === import_utils24.AST_NODE_TYPES.TemplateLiteral;
|
|
3640
3782
|
}
|
|
3641
|
-
var require_fetch_timeout_default =
|
|
3783
|
+
var require_fetch_timeout_default = import_utils24.ESLintUtils.RuleCreator(
|
|
3642
3784
|
(name) => `https://github.com/sarj-ai/linting/blob/main/packages/typescript/src/rules/${name}.ts`
|
|
3643
3785
|
)({
|
|
3644
3786
|
name: "require-fetch-timeout",
|
|
@@ -3675,14 +3817,14 @@ var require_fetch_timeout_default = import_utils25.ESLintUtils.RuleCreator(
|
|
|
3675
3817
|
}
|
|
3676
3818
|
function resolvesToGlobal(identifier) {
|
|
3677
3819
|
const scope = context.sourceCode.getScope(identifier);
|
|
3678
|
-
const variable =
|
|
3820
|
+
const variable = import_utils24.ASTUtils.findVariable(scope, identifier.name);
|
|
3679
3821
|
return variable === null || variable.defs.length === 0;
|
|
3680
3822
|
}
|
|
3681
3823
|
function isGlobalFetchCall2(callee) {
|
|
3682
|
-
if (callee.type ===
|
|
3824
|
+
if (callee.type === import_utils24.AST_NODE_TYPES.Identifier) {
|
|
3683
3825
|
return callee.name === "fetch" && resolvesToGlobal(callee);
|
|
3684
3826
|
}
|
|
3685
|
-
return callee.type ===
|
|
3827
|
+
return callee.type === import_utils24.AST_NODE_TYPES.MemberExpression && !callee.computed && callee.property.type === import_utils24.AST_NODE_TYPES.Identifier && callee.property.name === "fetch" && callee.object.type === import_utils24.AST_NODE_TYPES.Identifier && GLOBAL_OBJECTS.has(callee.object.name) && resolvesToGlobal(callee.object);
|
|
3686
3828
|
}
|
|
3687
3829
|
return {
|
|
3688
3830
|
CallExpression(node) {
|
|
@@ -3702,12 +3844,12 @@ var require_fetch_timeout_default = import_utils25.ESLintUtils.RuleCreator(
|
|
|
3702
3844
|
});
|
|
3703
3845
|
|
|
3704
3846
|
// src/rules/no-fat-try-blocks.ts
|
|
3705
|
-
var
|
|
3847
|
+
var import_utils25 = require("@typescript-eslint/utils");
|
|
3706
3848
|
var MAX_TRY_BODY_STATEMENTS = 3;
|
|
3707
3849
|
var NESTED_FUNCTION_TYPES = /* @__PURE__ */ new Set([
|
|
3708
|
-
|
|
3709
|
-
|
|
3710
|
-
|
|
3850
|
+
import_utils25.AST_NODE_TYPES.FunctionDeclaration,
|
|
3851
|
+
import_utils25.AST_NODE_TYPES.FunctionExpression,
|
|
3852
|
+
import_utils25.AST_NODE_TYPES.ArrowFunctionExpression
|
|
3711
3853
|
]);
|
|
3712
3854
|
var PURE_METHODS = /* @__PURE__ */ new Set([
|
|
3713
3855
|
"map",
|
|
@@ -3805,22 +3947,22 @@ function isNode3(value) {
|
|
|
3805
3947
|
}
|
|
3806
3948
|
function isPureCall(node) {
|
|
3807
3949
|
const callee = node.callee;
|
|
3808
|
-
if (callee.type !==
|
|
3950
|
+
if (callee.type !== import_utils25.AST_NODE_TYPES.MemberExpression) {
|
|
3809
3951
|
return false;
|
|
3810
3952
|
}
|
|
3811
3953
|
const property = callee.property;
|
|
3812
|
-
if (property.type !==
|
|
3954
|
+
if (property.type !== import_utils25.AST_NODE_TYPES.Identifier) {
|
|
3813
3955
|
return false;
|
|
3814
3956
|
}
|
|
3815
|
-
if (callee.object.type ===
|
|
3957
|
+
if (callee.object.type === import_utils25.AST_NODE_TYPES.Identifier && PURE_NAMESPACES.has(callee.object.name)) {
|
|
3816
3958
|
return true;
|
|
3817
3959
|
}
|
|
3818
3960
|
return PURE_METHODS.has(property.name);
|
|
3819
3961
|
}
|
|
3820
3962
|
function isPureNew(node) {
|
|
3821
|
-
return node.callee.type ===
|
|
3963
|
+
return node.callee.type === import_utils25.AST_NODE_TYPES.Identifier && PURE_CONSTRUCTORS.has(node.callee.name);
|
|
3822
3964
|
}
|
|
3823
|
-
function subtreeMatches(stmt, predicate) {
|
|
3965
|
+
function subtreeMatches(stmt, predicate, descendIntoFunctions = false) {
|
|
3824
3966
|
let found = false;
|
|
3825
3967
|
const visit = (current) => {
|
|
3826
3968
|
if (found) {
|
|
@@ -3834,7 +3976,7 @@ function subtreeMatches(stmt, predicate) {
|
|
|
3834
3976
|
if (key === "parent") {
|
|
3835
3977
|
continue;
|
|
3836
3978
|
}
|
|
3837
|
-
if (NESTED_FUNCTION_TYPES.has(current.type) && key === "body") {
|
|
3979
|
+
if (!descendIntoFunctions && NESTED_FUNCTION_TYPES.has(current.type) && key === "body") {
|
|
3838
3980
|
continue;
|
|
3839
3981
|
}
|
|
3840
3982
|
const value = current[key];
|
|
@@ -3855,20 +3997,20 @@ function subtreeMatches(stmt, predicate) {
|
|
|
3855
3997
|
visit(stmt);
|
|
3856
3998
|
return found;
|
|
3857
3999
|
}
|
|
3858
|
-
var hasAwait = (node) => subtreeMatches(node, (n) => n.type ===
|
|
4000
|
+
var hasAwait = (node) => subtreeMatches(node, (n) => n.type === import_utils25.AST_NODE_TYPES.AwaitExpression);
|
|
3859
4001
|
var hasThrowingCallOrNew = (node) => subtreeMatches(
|
|
3860
4002
|
node,
|
|
3861
|
-
(n) => n.type ===
|
|
4003
|
+
(n) => n.type === import_utils25.AST_NODE_TYPES.CallExpression && !isPureCall(n) || n.type === import_utils25.AST_NODE_TYPES.NewExpression && !isPureNew(n)
|
|
3862
4004
|
);
|
|
3863
4005
|
function unwrap2(expr) {
|
|
3864
4006
|
let current = expr;
|
|
3865
|
-
while (current.type ===
|
|
4007
|
+
while (current.type === import_utils25.AST_NODE_TYPES.ChainExpression || current.type === import_utils25.AST_NODE_TYPES.TSNonNullExpression) {
|
|
3866
4008
|
current = current.expression;
|
|
3867
4009
|
}
|
|
3868
4010
|
return current;
|
|
3869
4011
|
}
|
|
3870
4012
|
function isBareCallStatement(stmt) {
|
|
3871
|
-
return stmt.type ===
|
|
4013
|
+
return stmt.type === import_utils25.AST_NODE_TYPES.ExpressionStatement && unwrap2(stmt.expression).type === import_utils25.AST_NODE_TYPES.CallExpression;
|
|
3872
4014
|
}
|
|
3873
4015
|
function canThrow(stmt) {
|
|
3874
4016
|
if (hasAwait(stmt)) {
|
|
@@ -3877,10 +4019,10 @@ function canThrow(stmt) {
|
|
|
3877
4019
|
if (isBareCallStatement(stmt)) {
|
|
3878
4020
|
return false;
|
|
3879
4021
|
}
|
|
3880
|
-
if (stmt.type ===
|
|
4022
|
+
if (stmt.type === import_utils25.AST_NODE_TYPES.BlockStatement) {
|
|
3881
4023
|
return stmt.body.some(canThrow);
|
|
3882
4024
|
}
|
|
3883
|
-
if (stmt.type ===
|
|
4025
|
+
if (stmt.type === import_utils25.AST_NODE_TYPES.IfStatement) {
|
|
3884
4026
|
return hasThrowingCallOrNew(stmt.test) || canThrow(stmt.consequent) || stmt.alternate !== null && canThrow(stmt.alternate);
|
|
3885
4027
|
}
|
|
3886
4028
|
return hasThrowingCallOrNew(stmt);
|
|
@@ -3891,9 +4033,137 @@ function handlerRethrows(handler) {
|
|
|
3891
4033
|
}
|
|
3892
4034
|
const body = handler.body.body;
|
|
3893
4035
|
const last = body[body.length - 1];
|
|
3894
|
-
return last !== void 0 && last.type ===
|
|
4036
|
+
return last !== void 0 && last.type === import_utils25.AST_NODE_TYPES.ThrowStatement;
|
|
4037
|
+
}
|
|
4038
|
+
var PASS_THROUGH_PARENTS = /* @__PURE__ */ new Set([
|
|
4039
|
+
import_utils25.AST_NODE_TYPES.IfStatement,
|
|
4040
|
+
import_utils25.AST_NODE_TYPES.TryStatement,
|
|
4041
|
+
import_utils25.AST_NODE_TYPES.CatchClause,
|
|
4042
|
+
import_utils25.AST_NODE_TYPES.LabeledStatement
|
|
4043
|
+
]);
|
|
4044
|
+
function isTerminalInFunction(node) {
|
|
4045
|
+
let current = node;
|
|
4046
|
+
let parent = current.parent;
|
|
4047
|
+
while (parent !== void 0) {
|
|
4048
|
+
if (parent.type === import_utils25.AST_NODE_TYPES.BlockStatement) {
|
|
4049
|
+
if (parent.body[parent.body.length - 1] !== current) {
|
|
4050
|
+
return false;
|
|
4051
|
+
}
|
|
4052
|
+
} else if (parent.type === import_utils25.AST_NODE_TYPES.Program) {
|
|
4053
|
+
return parent.body[parent.body.length - 1] === current;
|
|
4054
|
+
} else if (NESTED_FUNCTION_TYPES.has(parent.type)) {
|
|
4055
|
+
return true;
|
|
4056
|
+
} else if (!PASS_THROUGH_PARENTS.has(parent.type)) {
|
|
4057
|
+
return false;
|
|
4058
|
+
}
|
|
4059
|
+
current = parent;
|
|
4060
|
+
parent = current.parent;
|
|
4061
|
+
}
|
|
4062
|
+
return false;
|
|
4063
|
+
}
|
|
4064
|
+
function unwrapAwait(expr) {
|
|
4065
|
+
const inner = unwrap2(expr);
|
|
4066
|
+
return inner.type === import_utils25.AST_NODE_TYPES.AwaitExpression ? unwrap2(inner.argument) : inner;
|
|
4067
|
+
}
|
|
4068
|
+
function handlerEndsByHandingOff(handler) {
|
|
4069
|
+
const body = handler.body.body;
|
|
4070
|
+
const last = body[body.length - 1];
|
|
4071
|
+
if (last === void 0) {
|
|
4072
|
+
return false;
|
|
4073
|
+
}
|
|
4074
|
+
if (last.type === import_utils25.AST_NODE_TYPES.ReturnStatement || last.type === import_utils25.AST_NODE_TYPES.ThrowStatement) {
|
|
4075
|
+
return true;
|
|
4076
|
+
}
|
|
4077
|
+
return last.type === import_utils25.AST_NODE_TYPES.ExpressionStatement && unwrapAwait(last.expression).type === import_utils25.AST_NODE_TYPES.CallExpression;
|
|
4078
|
+
}
|
|
4079
|
+
function collectBindingNames(pattern, names) {
|
|
4080
|
+
if (pattern.type === import_utils25.AST_NODE_TYPES.Identifier) {
|
|
4081
|
+
names.add(pattern.name);
|
|
4082
|
+
return;
|
|
4083
|
+
}
|
|
4084
|
+
if (pattern.type === import_utils25.AST_NODE_TYPES.ObjectPattern) {
|
|
4085
|
+
for (const property of pattern.properties) {
|
|
4086
|
+
collectBindingNames(
|
|
4087
|
+
property.type === import_utils25.AST_NODE_TYPES.RestElement ? property.argument : property.value,
|
|
4088
|
+
names
|
|
4089
|
+
);
|
|
4090
|
+
}
|
|
4091
|
+
return;
|
|
4092
|
+
}
|
|
4093
|
+
if (pattern.type === import_utils25.AST_NODE_TYPES.ArrayPattern) {
|
|
4094
|
+
for (const element of pattern.elements) {
|
|
4095
|
+
if (element !== null) {
|
|
4096
|
+
collectBindingNames(element, names);
|
|
4097
|
+
}
|
|
4098
|
+
}
|
|
4099
|
+
return;
|
|
4100
|
+
}
|
|
4101
|
+
if (pattern.type === import_utils25.AST_NODE_TYPES.AssignmentPattern || pattern.type === import_utils25.AST_NODE_TYPES.RestElement) {
|
|
4102
|
+
collectBindingNames(
|
|
4103
|
+
pattern.type === import_utils25.AST_NODE_TYPES.AssignmentPattern ? pattern.left : pattern.argument,
|
|
4104
|
+
names
|
|
4105
|
+
);
|
|
4106
|
+
}
|
|
4107
|
+
}
|
|
4108
|
+
function caughtBindingNames(handler) {
|
|
4109
|
+
const names = /* @__PURE__ */ new Set();
|
|
4110
|
+
if (handler.param !== null) {
|
|
4111
|
+
collectBindingNames(handler.param, names);
|
|
4112
|
+
}
|
|
4113
|
+
return names;
|
|
4114
|
+
}
|
|
4115
|
+
function isPropertyName(node) {
|
|
4116
|
+
const parent = node.parent;
|
|
4117
|
+
if (parent.type === import_utils25.AST_NODE_TYPES.MemberExpression) {
|
|
4118
|
+
return parent.property === node && !parent.computed;
|
|
4119
|
+
}
|
|
4120
|
+
if (parent.type === import_utils25.AST_NODE_TYPES.Property) {
|
|
4121
|
+
return parent.key === node && !parent.computed;
|
|
4122
|
+
}
|
|
4123
|
+
return false;
|
|
4124
|
+
}
|
|
4125
|
+
function handlerMentionsCaughtBinding(handler) {
|
|
4126
|
+
const names = caughtBindingNames(handler);
|
|
4127
|
+
if (names.size === 0) {
|
|
4128
|
+
return false;
|
|
4129
|
+
}
|
|
4130
|
+
return subtreeMatches(
|
|
4131
|
+
handler.body,
|
|
4132
|
+
(n) => n.type === import_utils25.AST_NODE_TYPES.Identifier && names.has(n.name) && !isPropertyName(n),
|
|
4133
|
+
true
|
|
4134
|
+
);
|
|
4135
|
+
}
|
|
4136
|
+
function isSuccessShapedValue(expr) {
|
|
4137
|
+
let current = expr;
|
|
4138
|
+
while (current.type === import_utils25.AST_NODE_TYPES.TSAsExpression || current.type === import_utils25.AST_NODE_TYPES.TSNonNullExpression) {
|
|
4139
|
+
current = current.expression;
|
|
4140
|
+
}
|
|
4141
|
+
if (current.type === import_utils25.AST_NODE_TYPES.Literal) {
|
|
4142
|
+
return current.value === null || current.value === false;
|
|
4143
|
+
}
|
|
4144
|
+
if (current.type === import_utils25.AST_NODE_TYPES.Identifier) {
|
|
4145
|
+
return current.name === "undefined";
|
|
4146
|
+
}
|
|
4147
|
+
if (current.type === import_utils25.AST_NODE_TYPES.UnaryExpression) {
|
|
4148
|
+
return current.operator === "void";
|
|
4149
|
+
}
|
|
4150
|
+
if (current.type === import_utils25.AST_NODE_TYPES.ArrayExpression) {
|
|
4151
|
+
return current.elements.length === 0;
|
|
4152
|
+
}
|
|
4153
|
+
if (current.type === import_utils25.AST_NODE_TYPES.ObjectExpression) {
|
|
4154
|
+
return current.properties.length === 0;
|
|
4155
|
+
}
|
|
4156
|
+
return false;
|
|
3895
4157
|
}
|
|
3896
|
-
var
|
|
4158
|
+
var handlerReturnsSuccessShaped = (handler) => subtreeMatches(
|
|
4159
|
+
handler.body,
|
|
4160
|
+
(n) => n.type === import_utils25.AST_NODE_TYPES.ReturnStatement && n.argument !== null && isSuccessShapedValue(n.argument)
|
|
4161
|
+
);
|
|
4162
|
+
function isTerminalErrorBoundary(node) {
|
|
4163
|
+
const handler = node.handler;
|
|
4164
|
+
return handler !== null && isTerminalInFunction(node) && handlerEndsByHandingOff(handler) && handlerMentionsCaughtBinding(handler) && !handlerReturnsSuccessShaped(handler);
|
|
4165
|
+
}
|
|
4166
|
+
var no_fat_try_blocks_default = import_utils25.ESLintUtils.RuleCreator(
|
|
3897
4167
|
(name) => `https://github.com/sarj-ai/standards/blob/main/packages/typescript/src/rules/${name}.ts`
|
|
3898
4168
|
)({
|
|
3899
4169
|
name: "no-fat-try-blocks",
|
|
@@ -3921,6 +4191,9 @@ var no_fat_try_blocks_default = import_utils26.ESLintUtils.RuleCreator(
|
|
|
3921
4191
|
if (handlerRethrows(node.handler)) {
|
|
3922
4192
|
return;
|
|
3923
4193
|
}
|
|
4194
|
+
if (isTerminalErrorBoundary(node)) {
|
|
4195
|
+
return;
|
|
4196
|
+
}
|
|
3924
4197
|
const count = node.block.body.filter(canThrow).length;
|
|
3925
4198
|
if (count <= MAX_TRY_BODY_STATEMENTS) {
|
|
3926
4199
|
return;
|
|
@@ -3937,7 +4210,7 @@ var no_fat_try_blocks_default = import_utils26.ESLintUtils.RuleCreator(
|
|
|
3937
4210
|
});
|
|
3938
4211
|
|
|
3939
4212
|
// src/rules/no-secret-in-log.ts
|
|
3940
|
-
var
|
|
4213
|
+
var import_utils26 = require("@typescript-eslint/utils");
|
|
3941
4214
|
|
|
3942
4215
|
// src/rules/_secret_names.ts
|
|
3943
4216
|
var SECRET_WORDS = /* @__PURE__ */ new Set([
|
|
@@ -4199,7 +4472,7 @@ function propertyKeyName2(prop) {
|
|
|
4199
4472
|
}
|
|
4200
4473
|
return null;
|
|
4201
4474
|
}
|
|
4202
|
-
var no_secret_in_log_default =
|
|
4475
|
+
var no_secret_in_log_default = import_utils26.ESLintUtils.RuleCreator(
|
|
4203
4476
|
(name) => `https://github.com/sarj-ai/standards/blob/main/packages/typescript/src/rules/${name}.ts`
|
|
4204
4477
|
)({
|
|
4205
4478
|
name: "no-secret-in-log",
|
|
@@ -4276,24 +4549,24 @@ var no_secret_in_log_default = import_utils27.ESLintUtils.RuleCreator(
|
|
|
4276
4549
|
});
|
|
4277
4550
|
|
|
4278
4551
|
// src/rules/no-unsafe-mock-casting.ts
|
|
4552
|
+
var import_utils27 = require("@typescript-eslint/utils");
|
|
4279
4553
|
var import_utils28 = require("@typescript-eslint/utils");
|
|
4280
|
-
var import_utils29 = require("@typescript-eslint/utils");
|
|
4281
4554
|
function isMockTypeReference(node) {
|
|
4282
|
-
if (node.type !==
|
|
4555
|
+
if (node.type !== import_utils28.AST_NODE_TYPES.TSTypeReference) {
|
|
4283
4556
|
return false;
|
|
4284
4557
|
}
|
|
4285
4558
|
const typeName = node.typeName;
|
|
4286
|
-
if (typeName.type ===
|
|
4559
|
+
if (typeName.type === import_utils28.AST_NODE_TYPES.Identifier) {
|
|
4287
4560
|
const name = typeName.name;
|
|
4288
4561
|
return name === "Mock" || name === "MockInstance" || name === "SpyInstance";
|
|
4289
4562
|
}
|
|
4290
|
-
if (typeName.type ===
|
|
4563
|
+
if (typeName.type === import_utils28.AST_NODE_TYPES.TSQualifiedName) {
|
|
4291
4564
|
const rightName = typeName.right.name;
|
|
4292
4565
|
return rightName === "Mock" || rightName === "MockInstance" || rightName === "SpyInstance";
|
|
4293
4566
|
}
|
|
4294
4567
|
return false;
|
|
4295
4568
|
}
|
|
4296
|
-
var no_unsafe_mock_casting_default =
|
|
4569
|
+
var no_unsafe_mock_casting_default = import_utils27.ESLintUtils.RuleCreator(
|
|
4297
4570
|
(name) => `https://github.com/sarj-ai/linting/blob/main/packages/typescript/src/rules/${name}.ts`
|
|
4298
4571
|
)({
|
|
4299
4572
|
name: "no-unsafe-mock-casting",
|
|
@@ -4325,7 +4598,7 @@ var no_unsafe_mock_casting_default = import_utils28.ESLintUtils.RuleCreator(
|
|
|
4325
4598
|
});
|
|
4326
4599
|
|
|
4327
4600
|
// src/rules/prefer-string-literal-union.ts
|
|
4328
|
-
var
|
|
4601
|
+
var import_utils29 = require("@typescript-eslint/utils");
|
|
4329
4602
|
var ts = __toESM(require("typescript"), 1);
|
|
4330
4603
|
var CHOICE_TOKENS = /* @__PURE__ */ new Set([
|
|
4331
4604
|
"status",
|
|
@@ -4368,19 +4641,19 @@ function isChoiceLikeName(name) {
|
|
|
4368
4641
|
return CHOICE_TOKENS.has(lastWord(name));
|
|
4369
4642
|
}
|
|
4370
4643
|
function keyName(key) {
|
|
4371
|
-
if (key.type ===
|
|
4644
|
+
if (key.type === import_utils29.AST_NODE_TYPES.Identifier) {
|
|
4372
4645
|
return key.name;
|
|
4373
4646
|
}
|
|
4374
|
-
if (key.type ===
|
|
4647
|
+
if (key.type === import_utils29.AST_NODE_TYPES.Literal && typeof key.value === "string") {
|
|
4375
4648
|
return key.value;
|
|
4376
4649
|
}
|
|
4377
4650
|
return null;
|
|
4378
4651
|
}
|
|
4379
4652
|
function isStringLiteralMember(t) {
|
|
4380
|
-
return t.type ===
|
|
4653
|
+
return t.type === import_utils29.AST_NODE_TYPES.TSLiteralType && t.literal.type === import_utils29.AST_NODE_TYPES.Literal && typeof t.literal.value === "string";
|
|
4381
4654
|
}
|
|
4382
4655
|
function isStringLiteralUnion(node) {
|
|
4383
|
-
if (node?.type !==
|
|
4656
|
+
if (node?.type !== import_utils29.AST_NODE_TYPES.TSUnionType) {
|
|
4384
4657
|
return false;
|
|
4385
4658
|
}
|
|
4386
4659
|
return node.types.filter(isStringLiteralMember).length >= MIN_CLUSTER_SIZE;
|
|
@@ -4409,12 +4682,12 @@ function bindingSourceExpression(decl) {
|
|
|
4409
4682
|
return ts.isForOfStatement(node) ? node.expression : node.initializer;
|
|
4410
4683
|
}
|
|
4411
4684
|
function refKey(node) {
|
|
4412
|
-
if (node.type ===
|
|
4685
|
+
if (node.type === import_utils29.AST_NODE_TYPES.Identifier) {
|
|
4413
4686
|
return node.name;
|
|
4414
4687
|
}
|
|
4415
|
-
if (node.type ===
|
|
4688
|
+
if (node.type === import_utils29.AST_NODE_TYPES.MemberExpression && !node.computed) {
|
|
4416
4689
|
const inner = refKey(node.object);
|
|
4417
|
-
if (inner === null || node.property.type !==
|
|
4690
|
+
if (inner === null || node.property.type !== import_utils29.AST_NODE_TYPES.Identifier) {
|
|
4418
4691
|
return null;
|
|
4419
4692
|
}
|
|
4420
4693
|
return `${inner}.${node.property.name}`;
|
|
@@ -4422,12 +4695,12 @@ function refKey(node) {
|
|
|
4422
4695
|
return null;
|
|
4423
4696
|
}
|
|
4424
4697
|
function strLiteral(node) {
|
|
4425
|
-
if (node.type ===
|
|
4698
|
+
if (node.type === import_utils29.AST_NODE_TYPES.Literal && typeof node.value === "string") {
|
|
4426
4699
|
return node.value;
|
|
4427
4700
|
}
|
|
4428
4701
|
return null;
|
|
4429
4702
|
}
|
|
4430
|
-
var prefer_string_literal_union_default =
|
|
4703
|
+
var prefer_string_literal_union_default = import_utils29.ESLintUtils.RuleCreator(
|
|
4431
4704
|
(name) => `https://github.com/sarj-ai/linting/blob/main/packages/typescript/src/rules/${name}.ts`
|
|
4432
4705
|
)({
|
|
4433
4706
|
name: "prefer-string-literal-union",
|
|
@@ -4465,7 +4738,7 @@ var prefer_string_literal_union_default = import_utils30.ESLintUtils.RuleCreator
|
|
|
4465
4738
|
);
|
|
4466
4739
|
let services;
|
|
4467
4740
|
try {
|
|
4468
|
-
services =
|
|
4741
|
+
services = import_utils29.ESLintUtils.getParserServices(context);
|
|
4469
4742
|
} catch {
|
|
4470
4743
|
services = null;
|
|
4471
4744
|
}
|
|
@@ -4577,7 +4850,7 @@ var prefer_string_literal_union_default = import_utils30.ESLintUtils.RuleCreator
|
|
|
4577
4850
|
containersWithUnion.add(container);
|
|
4578
4851
|
return;
|
|
4579
4852
|
}
|
|
4580
|
-
if (typeNode?.type !==
|
|
4853
|
+
if (typeNode?.type !== import_utils29.AST_NODE_TYPES.TSStringKeyword) {
|
|
4581
4854
|
return;
|
|
4582
4855
|
}
|
|
4583
4856
|
const name = keyName(key);
|
|
@@ -4665,10 +4938,10 @@ var prefer_string_literal_union_default = import_utils30.ESLintUtils.RuleCreator
|
|
|
4665
4938
|
}
|
|
4666
4939
|
};
|
|
4667
4940
|
function refKeyText(node) {
|
|
4668
|
-
if (node.type ===
|
|
4941
|
+
if (node.type === import_utils29.AST_NODE_TYPES.BinaryExpression) {
|
|
4669
4942
|
return refKey(node.left) ?? refKey(node.right) ?? "value";
|
|
4670
4943
|
}
|
|
4671
|
-
if (node.type ===
|
|
4944
|
+
if (node.type === import_utils29.AST_NODE_TYPES.SwitchStatement) {
|
|
4672
4945
|
return refKey(node.discriminant) ?? "value";
|
|
4673
4946
|
}
|
|
4674
4947
|
return "value";
|
|
@@ -4677,8 +4950,8 @@ var prefer_string_literal_union_default = import_utils30.ESLintUtils.RuleCreator
|
|
|
4677
4950
|
});
|
|
4678
4951
|
|
|
4679
4952
|
// src/rules/prefer-zod-enum.ts
|
|
4680
|
-
var
|
|
4681
|
-
var prefer_zod_enum_default =
|
|
4953
|
+
var import_utils30 = require("@typescript-eslint/utils");
|
|
4954
|
+
var prefer_zod_enum_default = import_utils30.ESLintUtils.RuleCreator(
|
|
4682
4955
|
(name) => `https://github.com/sarj-ai/standards/tree/main/packages/typescript#${name}`
|
|
4683
4956
|
)({
|
|
4684
4957
|
name: "prefer-zod-enum",
|
|
@@ -4699,20 +4972,20 @@ var prefer_zod_enum_default = import_utils31.ESLintUtils.RuleCreator(
|
|
|
4699
4972
|
const zodNamespaces = /* @__PURE__ */ new Set();
|
|
4700
4973
|
function enumValues(node) {
|
|
4701
4974
|
const callee = node.callee;
|
|
4702
|
-
if (callee.type !==
|
|
4975
|
+
if (callee.type !== import_utils30.AST_NODE_TYPES.MemberExpression || callee.computed || callee.object.type !== import_utils30.AST_NODE_TYPES.Identifier || !zodNamespaces.has(callee.object.name) || callee.property.type !== import_utils30.AST_NODE_TYPES.Identifier || callee.property.name !== "union" || node.arguments.length !== 1) {
|
|
4703
4976
|
return null;
|
|
4704
4977
|
}
|
|
4705
4978
|
const argument = node.arguments[0];
|
|
4706
|
-
if (argument === void 0 || argument.type !==
|
|
4979
|
+
if (argument === void 0 || argument.type !== import_utils30.AST_NODE_TYPES.ArrayExpression || argument.elements.length === 0) {
|
|
4707
4980
|
return null;
|
|
4708
4981
|
}
|
|
4709
4982
|
const values = [];
|
|
4710
4983
|
for (const element of argument.elements) {
|
|
4711
|
-
if (element === null || element.type !==
|
|
4984
|
+
if (element === null || element.type !== import_utils30.AST_NODE_TYPES.CallExpression || element.arguments.length !== 1 || element.callee.type !== import_utils30.AST_NODE_TYPES.MemberExpression || element.callee.computed || element.callee.object.type !== import_utils30.AST_NODE_TYPES.Identifier || !zodNamespaces.has(element.callee.object.name) || element.callee.property.type !== import_utils30.AST_NODE_TYPES.Identifier || element.callee.property.name !== "literal") {
|
|
4712
4985
|
return null;
|
|
4713
4986
|
}
|
|
4714
4987
|
const value = element.arguments[0];
|
|
4715
|
-
if (value === void 0 || value.type !==
|
|
4988
|
+
if (value === void 0 || value.type !== import_utils30.AST_NODE_TYPES.Literal || typeof value.value !== "string") {
|
|
4716
4989
|
return null;
|
|
4717
4990
|
}
|
|
4718
4991
|
values.push(value);
|
|
@@ -4721,11 +4994,11 @@ var prefer_zod_enum_default = import_utils31.ESLintUtils.RuleCreator(
|
|
|
4721
4994
|
}
|
|
4722
4995
|
function buildFix(node, values) {
|
|
4723
4996
|
const argument = node.arguments[0];
|
|
4724
|
-
if (argument === void 0 || argument.type !==
|
|
4997
|
+
if (argument === void 0 || argument.type !== import_utils30.AST_NODE_TYPES.ArrayExpression || sourceCode.getCommentsInside(argument).length > 0) {
|
|
4725
4998
|
return void 0;
|
|
4726
4999
|
}
|
|
4727
5000
|
const callee = node.callee;
|
|
4728
|
-
if (callee.type !==
|
|
5001
|
+
if (callee.type !== import_utils30.AST_NODE_TYPES.MemberExpression || callee.property.type !== import_utils30.AST_NODE_TYPES.Identifier) {
|
|
4729
5002
|
return void 0;
|
|
4730
5003
|
}
|
|
4731
5004
|
return (fixer) => [
|
|
@@ -4742,7 +5015,7 @@ var prefer_zod_enum_default = import_utils31.ESLintUtils.RuleCreator(
|
|
|
4742
5015
|
return;
|
|
4743
5016
|
}
|
|
4744
5017
|
for (const specifier of node.specifiers) {
|
|
4745
|
-
if (specifier.type ===
|
|
5018
|
+
if (specifier.type === import_utils30.AST_NODE_TYPES.ImportNamespaceSpecifier || specifier.type === import_utils30.AST_NODE_TYPES.ImportDefaultSpecifier || specifier.type === import_utils30.AST_NODE_TYPES.ImportSpecifier && specifier.imported.type === import_utils30.AST_NODE_TYPES.Identifier && specifier.imported.name === "z") {
|
|
4746
5019
|
zodNamespaces.add(specifier.local.name);
|
|
4747
5020
|
}
|
|
4748
5021
|
}
|
|
@@ -4764,7 +5037,7 @@ var prefer_zod_enum_default = import_utils31.ESLintUtils.RuleCreator(
|
|
|
4764
5037
|
});
|
|
4765
5038
|
|
|
4766
5039
|
// src/rules/prefer-zod-infer.ts
|
|
4767
|
-
var
|
|
5040
|
+
var import_utils31 = require("@typescript-eslint/utils");
|
|
4768
5041
|
var SHAPE_PRESERVING_METHODS = /* @__PURE__ */ new Set([
|
|
4769
5042
|
"describe",
|
|
4770
5043
|
"refine",
|
|
@@ -4801,44 +5074,44 @@ var ZOD_TYPE_CONSTRAINTS = /* @__PURE__ */ new Set([
|
|
|
4801
5074
|
"Schema"
|
|
4802
5075
|
]);
|
|
4803
5076
|
var LEAF_NODE_TYPES = {
|
|
4804
|
-
string: [
|
|
4805
|
-
email: [
|
|
4806
|
-
url: [
|
|
4807
|
-
uuid: [
|
|
4808
|
-
ulid: [
|
|
4809
|
-
cuid: [
|
|
4810
|
-
cuid2: [
|
|
4811
|
-
nanoid: [
|
|
4812
|
-
iso: [
|
|
4813
|
-
number: [
|
|
4814
|
-
int: [
|
|
4815
|
-
float32: [
|
|
4816
|
-
float64: [
|
|
4817
|
-
boolean: [
|
|
4818
|
-
bigint: [
|
|
4819
|
-
symbol: [
|
|
4820
|
-
any: [
|
|
4821
|
-
unknown: [
|
|
4822
|
-
never: [
|
|
4823
|
-
void: [
|
|
4824
|
-
null: [
|
|
4825
|
-
undefined: [
|
|
4826
|
-
literal: [
|
|
4827
|
-
date: [
|
|
4828
|
-
array: [
|
|
4829
|
-
tuple: [
|
|
4830
|
-
object: [
|
|
4831
|
-
strictObject: [
|
|
4832
|
-
looseObject: [
|
|
4833
|
-
record: [
|
|
4834
|
-
map: [
|
|
4835
|
-
set: [
|
|
4836
|
-
promise: [
|
|
4837
|
-
enum: [
|
|
4838
|
-
nativeEnum: [
|
|
4839
|
-
union: [
|
|
4840
|
-
discriminatedUnion: [
|
|
4841
|
-
intersection: [
|
|
5077
|
+
string: [import_utils31.AST_NODE_TYPES.TSStringKeyword],
|
|
5078
|
+
email: [import_utils31.AST_NODE_TYPES.TSStringKeyword],
|
|
5079
|
+
url: [import_utils31.AST_NODE_TYPES.TSStringKeyword],
|
|
5080
|
+
uuid: [import_utils31.AST_NODE_TYPES.TSStringKeyword],
|
|
5081
|
+
ulid: [import_utils31.AST_NODE_TYPES.TSStringKeyword],
|
|
5082
|
+
cuid: [import_utils31.AST_NODE_TYPES.TSStringKeyword],
|
|
5083
|
+
cuid2: [import_utils31.AST_NODE_TYPES.TSStringKeyword],
|
|
5084
|
+
nanoid: [import_utils31.AST_NODE_TYPES.TSStringKeyword],
|
|
5085
|
+
iso: [import_utils31.AST_NODE_TYPES.TSStringKeyword],
|
|
5086
|
+
number: [import_utils31.AST_NODE_TYPES.TSNumberKeyword],
|
|
5087
|
+
int: [import_utils31.AST_NODE_TYPES.TSNumberKeyword],
|
|
5088
|
+
float32: [import_utils31.AST_NODE_TYPES.TSNumberKeyword],
|
|
5089
|
+
float64: [import_utils31.AST_NODE_TYPES.TSNumberKeyword],
|
|
5090
|
+
boolean: [import_utils31.AST_NODE_TYPES.TSBooleanKeyword],
|
|
5091
|
+
bigint: [import_utils31.AST_NODE_TYPES.TSBigIntKeyword],
|
|
5092
|
+
symbol: [import_utils31.AST_NODE_TYPES.TSSymbolKeyword],
|
|
5093
|
+
any: [import_utils31.AST_NODE_TYPES.TSAnyKeyword],
|
|
5094
|
+
unknown: [import_utils31.AST_NODE_TYPES.TSUnknownKeyword],
|
|
5095
|
+
never: [import_utils31.AST_NODE_TYPES.TSNeverKeyword],
|
|
5096
|
+
void: [import_utils31.AST_NODE_TYPES.TSVoidKeyword],
|
|
5097
|
+
null: [import_utils31.AST_NODE_TYPES.TSNullKeyword],
|
|
5098
|
+
undefined: [import_utils31.AST_NODE_TYPES.TSUndefinedKeyword],
|
|
5099
|
+
literal: [import_utils31.AST_NODE_TYPES.TSLiteralType],
|
|
5100
|
+
date: [import_utils31.AST_NODE_TYPES.TSTypeReference],
|
|
5101
|
+
array: [import_utils31.AST_NODE_TYPES.TSArrayType, import_utils31.AST_NODE_TYPES.TSTypeReference],
|
|
5102
|
+
tuple: [import_utils31.AST_NODE_TYPES.TSTupleType],
|
|
5103
|
+
object: [import_utils31.AST_NODE_TYPES.TSTypeLiteral, import_utils31.AST_NODE_TYPES.TSTypeReference],
|
|
5104
|
+
strictObject: [import_utils31.AST_NODE_TYPES.TSTypeLiteral, import_utils31.AST_NODE_TYPES.TSTypeReference],
|
|
5105
|
+
looseObject: [import_utils31.AST_NODE_TYPES.TSTypeLiteral, import_utils31.AST_NODE_TYPES.TSTypeReference],
|
|
5106
|
+
record: [import_utils31.AST_NODE_TYPES.TSTypeReference, import_utils31.AST_NODE_TYPES.TSTypeLiteral],
|
|
5107
|
+
map: [import_utils31.AST_NODE_TYPES.TSTypeReference],
|
|
5108
|
+
set: [import_utils31.AST_NODE_TYPES.TSTypeReference],
|
|
5109
|
+
promise: [import_utils31.AST_NODE_TYPES.TSTypeReference],
|
|
5110
|
+
enum: [import_utils31.AST_NODE_TYPES.TSUnionType, import_utils31.AST_NODE_TYPES.TSTypeReference, import_utils31.AST_NODE_TYPES.TSLiteralType],
|
|
5111
|
+
nativeEnum: [import_utils31.AST_NODE_TYPES.TSUnionType, import_utils31.AST_NODE_TYPES.TSTypeReference, import_utils31.AST_NODE_TYPES.TSLiteralType],
|
|
5112
|
+
union: [import_utils31.AST_NODE_TYPES.TSUnionType, import_utils31.AST_NODE_TYPES.TSTypeReference],
|
|
5113
|
+
discriminatedUnion: [import_utils31.AST_NODE_TYPES.TSUnionType, import_utils31.AST_NODE_TYPES.TSTypeReference],
|
|
5114
|
+
intersection: [import_utils31.AST_NODE_TYPES.TSIntersectionType, import_utils31.AST_NODE_TYPES.TSTypeReference]
|
|
4842
5115
|
};
|
|
4843
5116
|
function normalizeSchemaName(name) {
|
|
4844
5117
|
return name.replace(/Schema$/i, "").replace(/^Z(?=[A-Z])/, "").toLowerCase();
|
|
@@ -4847,20 +5120,20 @@ function normalizeTypeName(name) {
|
|
|
4847
5120
|
return name.replace(/Type$/, "").toLowerCase();
|
|
4848
5121
|
}
|
|
4849
5122
|
function unwrapNullish(annotation) {
|
|
4850
|
-
if (annotation.type !==
|
|
5123
|
+
if (annotation.type !== import_utils31.AST_NODE_TYPES.TSUnionType) {
|
|
4851
5124
|
return {
|
|
4852
5125
|
core: annotation,
|
|
4853
|
-
nullable: annotation.type ===
|
|
5126
|
+
nullable: annotation.type === import_utils31.AST_NODE_TYPES.TSNullKeyword
|
|
4854
5127
|
};
|
|
4855
5128
|
}
|
|
4856
5129
|
const rest = [];
|
|
4857
5130
|
let nullable = false;
|
|
4858
5131
|
for (const member of annotation.types) {
|
|
4859
|
-
if (member.type ===
|
|
5132
|
+
if (member.type === import_utils31.AST_NODE_TYPES.TSNullKeyword) {
|
|
4860
5133
|
nullable = true;
|
|
4861
5134
|
continue;
|
|
4862
5135
|
}
|
|
4863
|
-
if (member.type ===
|
|
5136
|
+
if (member.type === import_utils31.AST_NODE_TYPES.TSUndefinedKeyword) {
|
|
4864
5137
|
continue;
|
|
4865
5138
|
}
|
|
4866
5139
|
rest.push(member);
|
|
@@ -4884,7 +5157,7 @@ function leafAgrees(leaf, annotation) {
|
|
|
4884
5157
|
}
|
|
4885
5158
|
return expected.includes(core.type);
|
|
4886
5159
|
}
|
|
4887
|
-
var prefer_zod_infer_default =
|
|
5160
|
+
var prefer_zod_infer_default = import_utils31.ESLintUtils.RuleCreator(
|
|
4888
5161
|
(name) => `https://github.com/sarj-ai/standards/tree/main/packages/typescript#${name}`
|
|
4889
5162
|
)({
|
|
4890
5163
|
name: "prefer-zod-infer",
|
|
@@ -4927,14 +5200,14 @@ var prefer_zod_infer_default = import_utils32.ESLintUtils.RuleCreator(
|
|
|
4927
5200
|
function zodCallChain(node) {
|
|
4928
5201
|
const chain = [];
|
|
4929
5202
|
let current = node;
|
|
4930
|
-
while (current.type ===
|
|
5203
|
+
while (current.type === import_utils31.AST_NODE_TYPES.CallExpression) {
|
|
4931
5204
|
const callee = current.callee;
|
|
4932
|
-
if (callee.type !==
|
|
5205
|
+
if (callee.type !== import_utils31.AST_NODE_TYPES.MemberExpression || callee.computed || callee.property.type !== import_utils31.AST_NODE_TYPES.Identifier) {
|
|
4933
5206
|
return null;
|
|
4934
5207
|
}
|
|
4935
5208
|
chain.push(current);
|
|
4936
5209
|
const receiver = callee.object;
|
|
4937
|
-
if (receiver.type ===
|
|
5210
|
+
if (receiver.type === import_utils31.AST_NODE_TYPES.Identifier) {
|
|
4938
5211
|
return zodNamespaces.has(receiver.name) ? chain.reverse() : null;
|
|
4939
5212
|
}
|
|
4940
5213
|
current = receiver;
|
|
@@ -4943,19 +5216,19 @@ var prefer_zod_infer_default = import_utils32.ESLintUtils.RuleCreator(
|
|
|
4943
5216
|
}
|
|
4944
5217
|
function methodName(call) {
|
|
4945
5218
|
const callee = call.callee;
|
|
4946
|
-
return callee.type ===
|
|
5219
|
+
return callee.type === import_utils31.AST_NODE_TYPES.MemberExpression && callee.property.type === import_utils31.AST_NODE_TYPES.Identifier ? callee.property.name : "";
|
|
4947
5220
|
}
|
|
4948
5221
|
function schemaField(node) {
|
|
4949
5222
|
const modifiers = [];
|
|
4950
5223
|
let current = node;
|
|
4951
5224
|
let leaf = null;
|
|
4952
|
-
while (current.type ===
|
|
5225
|
+
while (current.type === import_utils31.AST_NODE_TYPES.CallExpression) {
|
|
4953
5226
|
const callee = current.callee;
|
|
4954
|
-
if (callee.type !==
|
|
5227
|
+
if (callee.type !== import_utils31.AST_NODE_TYPES.MemberExpression || callee.computed || callee.property.type !== import_utils31.AST_NODE_TYPES.Identifier) {
|
|
4955
5228
|
break;
|
|
4956
5229
|
}
|
|
4957
5230
|
const receiver = callee.object;
|
|
4958
|
-
if (receiver.type ===
|
|
5231
|
+
if (receiver.type === import_utils31.AST_NODE_TYPES.Identifier && zodNamespaces.has(receiver.name)) {
|
|
4959
5232
|
leaf = callee.property.name;
|
|
4960
5233
|
break;
|
|
4961
5234
|
}
|
|
@@ -4986,16 +5259,16 @@ var prefer_zod_infer_default = import_utils32.ESLintUtils.RuleCreator(
|
|
|
4986
5259
|
return null;
|
|
4987
5260
|
}
|
|
4988
5261
|
const shape = base.arguments[0];
|
|
4989
|
-
if (shape === void 0 || shape.type !==
|
|
5262
|
+
if (shape === void 0 || shape.type !== import_utils31.AST_NODE_TYPES.ObjectExpression) {
|
|
4990
5263
|
return null;
|
|
4991
5264
|
}
|
|
4992
5265
|
const fields = /* @__PURE__ */ new Map();
|
|
4993
5266
|
for (const property of shape.properties) {
|
|
4994
|
-
if (property.type !==
|
|
5267
|
+
if (property.type !== import_utils31.AST_NODE_TYPES.Property || property.computed) {
|
|
4995
5268
|
return null;
|
|
4996
5269
|
}
|
|
4997
5270
|
const { key } = property;
|
|
4998
|
-
const name = key.type ===
|
|
5271
|
+
const name = key.type === import_utils31.AST_NODE_TYPES.Identifier ? key.name : key.type === import_utils31.AST_NODE_TYPES.Literal && typeof key.value === "string" ? key.value : null;
|
|
4999
5272
|
if (name === null) {
|
|
5000
5273
|
return null;
|
|
5001
5274
|
}
|
|
@@ -5006,11 +5279,11 @@ var prefer_zod_infer_default = import_utils32.ESLintUtils.RuleCreator(
|
|
|
5006
5279
|
function typeMembers(members) {
|
|
5007
5280
|
const result = /* @__PURE__ */ new Map();
|
|
5008
5281
|
for (const member of members) {
|
|
5009
|
-
if (member.type !==
|
|
5282
|
+
if (member.type !== import_utils31.AST_NODE_TYPES.TSPropertySignature || member.computed) {
|
|
5010
5283
|
return null;
|
|
5011
5284
|
}
|
|
5012
5285
|
const { key } = member;
|
|
5013
|
-
const name = key.type ===
|
|
5286
|
+
const name = key.type === import_utils31.AST_NODE_TYPES.Identifier ? key.name : key.type === import_utils31.AST_NODE_TYPES.Literal && typeof key.value === "string" ? key.value : null;
|
|
5014
5287
|
if (name === null) {
|
|
5015
5288
|
return null;
|
|
5016
5289
|
}
|
|
@@ -5024,8 +5297,8 @@ var prefer_zod_infer_default = import_utils32.ESLintUtils.RuleCreator(
|
|
|
5024
5297
|
return result.size === 0 ? null : result;
|
|
5025
5298
|
}
|
|
5026
5299
|
function collectConstrainedNames(node) {
|
|
5027
|
-
if (node.type ===
|
|
5028
|
-
if (node.typeName.type ===
|
|
5300
|
+
if (node.type === import_utils31.AST_NODE_TYPES.TSTypeReference) {
|
|
5301
|
+
if (node.typeName.type === import_utils31.AST_NODE_TYPES.Identifier) {
|
|
5029
5302
|
constrainedTypeNames.add(node.typeName.name);
|
|
5030
5303
|
}
|
|
5031
5304
|
for (const argument of node.typeArguments?.params ?? []) {
|
|
@@ -5033,11 +5306,11 @@ var prefer_zod_infer_default = import_utils32.ESLintUtils.RuleCreator(
|
|
|
5033
5306
|
}
|
|
5034
5307
|
return;
|
|
5035
5308
|
}
|
|
5036
|
-
if (node.type ===
|
|
5309
|
+
if (node.type === import_utils31.AST_NODE_TYPES.TSArrayType) {
|
|
5037
5310
|
collectConstrainedNames(node.elementType);
|
|
5038
5311
|
return;
|
|
5039
5312
|
}
|
|
5040
|
-
if (node.type ===
|
|
5313
|
+
if (node.type === import_utils31.AST_NODE_TYPES.TSUnionType || node.type === import_utils31.AST_NODE_TYPES.TSIntersectionType) {
|
|
5041
5314
|
for (const member of node.types) {
|
|
5042
5315
|
collectConstrainedNames(member);
|
|
5043
5316
|
}
|
|
@@ -5081,13 +5354,13 @@ var prefer_zod_infer_default = import_utils32.ESLintUtils.RuleCreator(
|
|
|
5081
5354
|
return;
|
|
5082
5355
|
}
|
|
5083
5356
|
for (const specifier of node.specifiers) {
|
|
5084
|
-
if (specifier.type ===
|
|
5357
|
+
if (specifier.type === import_utils31.AST_NODE_TYPES.ImportNamespaceSpecifier || specifier.type === import_utils31.AST_NODE_TYPES.ImportDefaultSpecifier || specifier.type === import_utils31.AST_NODE_TYPES.ImportSpecifier && specifier.imported.type === import_utils31.AST_NODE_TYPES.Identifier && specifier.imported.name === "z") {
|
|
5085
5358
|
zodNamespaces.add(specifier.local.name);
|
|
5086
5359
|
}
|
|
5087
5360
|
}
|
|
5088
5361
|
},
|
|
5089
5362
|
VariableDeclarator(node) {
|
|
5090
|
-
if (node.id.type !==
|
|
5363
|
+
if (node.id.type !== import_utils31.AST_NODE_TYPES.Identifier || node.init == null) {
|
|
5091
5364
|
return;
|
|
5092
5365
|
}
|
|
5093
5366
|
const fields = schemaFields(node.init);
|
|
@@ -5097,14 +5370,14 @@ var prefer_zod_infer_default = import_utils32.ESLintUtils.RuleCreator(
|
|
|
5097
5370
|
},
|
|
5098
5371
|
/** Guard (f): `XSchema.transform(...)` anywhere in the module. */
|
|
5099
5372
|
"MemberExpression[computed=false]"(node) {
|
|
5100
|
-
if (node.object.type ===
|
|
5373
|
+
if (node.object.type === import_utils31.AST_NODE_TYPES.Identifier && node.property.type === import_utils31.AST_NODE_TYPES.Identifier && MODULE_LEVEL_RESHAPERS.has(node.property.name)) {
|
|
5101
5374
|
reshapedSchemaNames.add(node.object.name);
|
|
5102
5375
|
}
|
|
5103
5376
|
},
|
|
5104
5377
|
/** Guard (c): `z.ZodType<T>` and every other type argument it carries. */
|
|
5105
5378
|
TSTypeReference(node) {
|
|
5106
5379
|
const { typeName } = node;
|
|
5107
|
-
const referenced = typeName.type ===
|
|
5380
|
+
const referenced = typeName.type === import_utils31.AST_NODE_TYPES.Identifier ? typeName.name : typeName.type === import_utils31.AST_NODE_TYPES.TSQualifiedName && typeName.right.type === import_utils31.AST_NODE_TYPES.Identifier ? typeName.right.name : null;
|
|
5108
5381
|
if (referenced === null || !ZOD_TYPE_CONSTRAINTS.has(referenced)) {
|
|
5109
5382
|
return;
|
|
5110
5383
|
}
|
|
@@ -5122,7 +5395,7 @@ var prefer_zod_infer_default = import_utils32.ESLintUtils.RuleCreator(
|
|
|
5122
5395
|
}
|
|
5123
5396
|
},
|
|
5124
5397
|
TSTypeAliasDeclaration(node) {
|
|
5125
|
-
if (node.typeParameters !== void 0 || node.typeAnnotation.type !==
|
|
5398
|
+
if (node.typeParameters !== void 0 || node.typeAnnotation.type !== import_utils31.AST_NODE_TYPES.TSTypeLiteral) {
|
|
5126
5399
|
return;
|
|
5127
5400
|
}
|
|
5128
5401
|
const members = typeMembers(node.typeAnnotation.members);
|
|
@@ -5167,10 +5440,10 @@ var prefer_zod_infer_default = import_utils32.ESLintUtils.RuleCreator(
|
|
|
5167
5440
|
});
|
|
5168
5441
|
|
|
5169
5442
|
// src/rules/no-offset-pagination.ts
|
|
5170
|
-
var
|
|
5443
|
+
var import_utils33 = require("@typescript-eslint/utils");
|
|
5171
5444
|
|
|
5172
5445
|
// src/rules/_sql.ts
|
|
5173
|
-
var
|
|
5446
|
+
var import_utils32 = require("@typescript-eslint/utils");
|
|
5174
5447
|
function stripSqlNoise(text) {
|
|
5175
5448
|
const out = [...text];
|
|
5176
5449
|
const n = text.length;
|
|
@@ -5231,13 +5504,13 @@ function stripSqlNoise(text) {
|
|
|
5231
5504
|
var SUBSTITUTION_MARKER = "?";
|
|
5232
5505
|
function sqlTextOf(node) {
|
|
5233
5506
|
switch (node.type) {
|
|
5234
|
-
case
|
|
5507
|
+
case import_utils32.AST_NODE_TYPES.Literal:
|
|
5235
5508
|
return typeof node.value === "string" ? node.value : null;
|
|
5236
|
-
case
|
|
5509
|
+
case import_utils32.AST_NODE_TYPES.TemplateLiteral:
|
|
5237
5510
|
return node.quasis.map((q) => q.value.cooked ?? q.value.raw).join(SUBSTITUTION_MARKER);
|
|
5238
|
-
case
|
|
5511
|
+
case import_utils32.AST_NODE_TYPES.TaggedTemplateExpression:
|
|
5239
5512
|
return sqlTextOf(node.quasi);
|
|
5240
|
-
case
|
|
5513
|
+
case import_utils32.AST_NODE_TYPES.BinaryExpression: {
|
|
5241
5514
|
if (node.operator !== "+") {
|
|
5242
5515
|
return null;
|
|
5243
5516
|
}
|
|
@@ -5245,7 +5518,7 @@ function sqlTextOf(node) {
|
|
|
5245
5518
|
const right = sqlTextOf(node.right);
|
|
5246
5519
|
return left !== null && right !== null ? left + right : null;
|
|
5247
5520
|
}
|
|
5248
|
-
case
|
|
5521
|
+
case import_utils32.AST_NODE_TYPES.ArrayExpression: {
|
|
5249
5522
|
const parts = [];
|
|
5250
5523
|
for (const element of node.elements) {
|
|
5251
5524
|
if (element === null) {
|
|
@@ -5265,7 +5538,7 @@ function sqlTextOf(node) {
|
|
|
5265
5538
|
}
|
|
5266
5539
|
function isJoinedFragmentArray(node) {
|
|
5267
5540
|
const parent = node.parent;
|
|
5268
|
-
return parent?.type ===
|
|
5541
|
+
return parent?.type === import_utils32.AST_NODE_TYPES.MemberExpression && parent.object === node && !parent.computed && parent.property.type === import_utils32.AST_NODE_TYPES.Identifier && parent.property.name === "join" && parent.parent?.type === import_utils32.AST_NODE_TYPES.CallExpression;
|
|
5269
5542
|
}
|
|
5270
5543
|
function markConsumed(node, consumed) {
|
|
5271
5544
|
consumed.add(node);
|
|
@@ -5315,7 +5588,7 @@ function createSqlListener(handler) {
|
|
|
5315
5588
|
// src/rules/no-offset-pagination.ts
|
|
5316
5589
|
var OFFSET_PAGINATION = /\bOFFSET\s+(?:%s|%\(\w+\)s|\?\d*|:\w+|@\w+|\$\d+|\d+)/i;
|
|
5317
5590
|
var OFFSET_GATE = /offset/i;
|
|
5318
|
-
var no_offset_pagination_default =
|
|
5591
|
+
var no_offset_pagination_default = import_utils33.ESLintUtils.RuleCreator(
|
|
5319
5592
|
(name) => `https://github.com/sarj-ai/standards/blob/main/packages/typescript/src/rules/${name}.ts`
|
|
5320
5593
|
)({
|
|
5321
5594
|
name: "no-offset-pagination",
|
|
@@ -5344,15 +5617,15 @@ var no_offset_pagination_default = import_utils34.ESLintUtils.RuleCreator(
|
|
|
5344
5617
|
});
|
|
5345
5618
|
|
|
5346
5619
|
// src/rules/no-positional-tuple-return.ts
|
|
5347
|
-
var
|
|
5620
|
+
var import_utils34 = require("@typescript-eslint/utils");
|
|
5348
5621
|
var MIN_ELEMENTS = 2;
|
|
5349
5622
|
var ACCESSOR_PAIR_LENGTH = 2;
|
|
5350
5623
|
var AWAITABLE_TYPES = /* @__PURE__ */ new Set(["Promise", "PromiseLike", "Awaited"]);
|
|
5351
5624
|
function tupleReturnType(node) {
|
|
5352
|
-
if (node.type ===
|
|
5625
|
+
if (node.type === import_utils34.AST_NODE_TYPES.TSTupleType) {
|
|
5353
5626
|
return node;
|
|
5354
5627
|
}
|
|
5355
|
-
if (node.type ===
|
|
5628
|
+
if (node.type === import_utils34.AST_NODE_TYPES.TSTypeReference && node.typeName.type === import_utils34.AST_NODE_TYPES.Identifier && AWAITABLE_TYPES.has(node.typeName.name)) {
|
|
5356
5629
|
const argument = node.typeArguments?.params[0];
|
|
5357
5630
|
return argument === void 0 ? null : tupleReturnType(argument);
|
|
5358
5631
|
}
|
|
@@ -5366,30 +5639,30 @@ function isPermittedTuple(tuple, sourceCode) {
|
|
|
5366
5639
|
if (elements.length < MIN_ELEMENTS) {
|
|
5367
5640
|
return true;
|
|
5368
5641
|
}
|
|
5369
|
-
if (elements.some((element) => element.type ===
|
|
5642
|
+
if (elements.some((element) => element.type === import_utils34.AST_NODE_TYPES.TSRestType)) {
|
|
5370
5643
|
return true;
|
|
5371
5644
|
}
|
|
5372
|
-
if (elements.some((element) => element.type ===
|
|
5645
|
+
if (elements.some((element) => element.type === import_utils34.AST_NODE_TYPES.TSNamedTupleMember)) {
|
|
5373
5646
|
return true;
|
|
5374
5647
|
}
|
|
5375
|
-
if (elements[0]?.type ===
|
|
5648
|
+
if (elements[0]?.type === import_utils34.AST_NODE_TYPES.TSLiteralType) {
|
|
5376
5649
|
return true;
|
|
5377
5650
|
}
|
|
5378
|
-
if (elements.length === ACCESSOR_PAIR_LENGTH && elements.some((element) => element.type ===
|
|
5651
|
+
if (elements.length === ACCESSOR_PAIR_LENGTH && elements.some((element) => element.type === import_utils34.AST_NODE_TYPES.TSFunctionType)) {
|
|
5379
5652
|
return true;
|
|
5380
5653
|
}
|
|
5381
5654
|
const texts = new Set(elements.map((element) => normalizedText(sourceCode, element)));
|
|
5382
5655
|
return texts.size === 1;
|
|
5383
5656
|
}
|
|
5384
5657
|
function functionName(node) {
|
|
5385
|
-
if (node.type ===
|
|
5658
|
+
if (node.type === import_utils34.AST_NODE_TYPES.FunctionDeclaration) {
|
|
5386
5659
|
return node.id?.name ?? null;
|
|
5387
5660
|
}
|
|
5388
5661
|
const parent = node.parent;
|
|
5389
|
-
if (parent?.type ===
|
|
5662
|
+
if (parent?.type === import_utils34.AST_NODE_TYPES.VariableDeclarator && parent.id.type === import_utils34.AST_NODE_TYPES.Identifier) {
|
|
5390
5663
|
return parent.id.name;
|
|
5391
5664
|
}
|
|
5392
|
-
if ((parent?.type ===
|
|
5665
|
+
if ((parent?.type === import_utils34.AST_NODE_TYPES.MethodDefinition || parent?.type === import_utils34.AST_NODE_TYPES.PropertyDefinition || parent?.type === import_utils34.AST_NODE_TYPES.Property) && parent.key.type === import_utils34.AST_NODE_TYPES.Identifier) {
|
|
5393
5666
|
return parent.key.name;
|
|
5394
5667
|
}
|
|
5395
5668
|
return null;
|
|
@@ -5397,7 +5670,7 @@ function functionName(node) {
|
|
|
5397
5670
|
function isInlineExported(node) {
|
|
5398
5671
|
for (let current = node; current != null; current = current.parent) {
|
|
5399
5672
|
const parent = current.parent;
|
|
5400
|
-
if (parent?.type ===
|
|
5673
|
+
if (parent?.type === import_utils34.AST_NODE_TYPES.ExportNamedDeclaration || parent?.type === import_utils34.AST_NODE_TYPES.ExportDefaultDeclaration) {
|
|
5401
5674
|
return true;
|
|
5402
5675
|
}
|
|
5403
5676
|
}
|
|
@@ -5406,18 +5679,18 @@ function isInlineExported(node) {
|
|
|
5406
5679
|
function moduleScopeBindingName(node) {
|
|
5407
5680
|
let current = node;
|
|
5408
5681
|
let child = node;
|
|
5409
|
-
while (current.parent != null && current.parent.type !==
|
|
5682
|
+
while (current.parent != null && current.parent.type !== import_utils34.AST_NODE_TYPES.Program) {
|
|
5410
5683
|
child = current;
|
|
5411
5684
|
current = current.parent;
|
|
5412
5685
|
}
|
|
5413
|
-
if (current.parent?.type !==
|
|
5686
|
+
if (current.parent?.type !== import_utils34.AST_NODE_TYPES.Program) {
|
|
5414
5687
|
return null;
|
|
5415
5688
|
}
|
|
5416
|
-
if (current.type ===
|
|
5689
|
+
if (current.type === import_utils34.AST_NODE_TYPES.FunctionDeclaration || current.type === import_utils34.AST_NODE_TYPES.ClassDeclaration) {
|
|
5417
5690
|
return current.id?.name ?? null;
|
|
5418
5691
|
}
|
|
5419
|
-
if (current.type ===
|
|
5420
|
-
if (child.type !==
|
|
5692
|
+
if (current.type === import_utils34.AST_NODE_TYPES.VariableDeclaration) {
|
|
5693
|
+
if (child.type !== import_utils34.AST_NODE_TYPES.VariableDeclarator || child.id.type !== import_utils34.AST_NODE_TYPES.Identifier) {
|
|
5421
5694
|
return null;
|
|
5422
5695
|
}
|
|
5423
5696
|
return child.id.name;
|
|
@@ -5427,19 +5700,19 @@ function moduleScopeBindingName(node) {
|
|
|
5427
5700
|
function specifierExportedNames(program) {
|
|
5428
5701
|
const names = /* @__PURE__ */ new Set();
|
|
5429
5702
|
for (const statement of program.body) {
|
|
5430
|
-
if (statement.type ===
|
|
5703
|
+
if (statement.type === import_utils34.AST_NODE_TYPES.ExportNamedDeclaration && statement.declaration == null && statement.source == null && statement.exportKind !== "type") {
|
|
5431
5704
|
for (const specifier of statement.specifiers) {
|
|
5432
|
-
if (specifier.exportKind !== "type" && specifier.local.type ===
|
|
5705
|
+
if (specifier.exportKind !== "type" && specifier.local.type === import_utils34.AST_NODE_TYPES.Identifier) {
|
|
5433
5706
|
names.add(specifier.local.name);
|
|
5434
5707
|
}
|
|
5435
5708
|
}
|
|
5436
5709
|
continue;
|
|
5437
5710
|
}
|
|
5438
|
-
if (statement.type ===
|
|
5711
|
+
if (statement.type === import_utils34.AST_NODE_TYPES.ExportDefaultDeclaration && statement.declaration.type === import_utils34.AST_NODE_TYPES.Identifier) {
|
|
5439
5712
|
names.add(statement.declaration.name);
|
|
5440
5713
|
continue;
|
|
5441
5714
|
}
|
|
5442
|
-
if (statement.type ===
|
|
5715
|
+
if (statement.type === import_utils34.AST_NODE_TYPES.TSExportAssignment && statement.expression.type === import_utils34.AST_NODE_TYPES.Identifier) {
|
|
5443
5716
|
names.add(statement.expression.name);
|
|
5444
5717
|
}
|
|
5445
5718
|
}
|
|
@@ -5455,7 +5728,7 @@ function isExported(node, specifierExports) {
|
|
|
5455
5728
|
const binding = moduleScopeBindingName(node);
|
|
5456
5729
|
return binding !== null && specifierExports.has(binding);
|
|
5457
5730
|
}
|
|
5458
|
-
var no_positional_tuple_return_default =
|
|
5731
|
+
var no_positional_tuple_return_default = import_utils34.ESLintUtils.RuleCreator(
|
|
5459
5732
|
(name) => `https://github.com/sarj-ai/standards/blob/main/packages/typescript/src/rules/${name}.ts`
|
|
5460
5733
|
)({
|
|
5461
5734
|
name: "no-positional-tuple-return",
|
|
@@ -5503,16 +5776,16 @@ var no_positional_tuple_return_default = import_utils35.ESLintUtils.RuleCreator(
|
|
|
5503
5776
|
});
|
|
5504
5777
|
|
|
5505
5778
|
// src/rules/no-repeated-string-literal.ts
|
|
5506
|
-
var
|
|
5779
|
+
var import_utils35 = require("@typescript-eslint/utils");
|
|
5507
5780
|
var MIN_LENGTH = 40;
|
|
5508
5781
|
var MIN_DISTINCT_SCOPES = 2;
|
|
5509
5782
|
var PREVIEW_LENGTH = 40;
|
|
5510
5783
|
var SQL_KEYWORD_RE = /\b(SELECT|INSERT|UPDATE|DELETE|FROM|WHERE|JOIN|VALUES|ON CONFLICT|RETURNING|GROUP BY|ORDER BY)\b/;
|
|
5511
5784
|
var IDENTIFIER_RE = /^[a-z_][a-z0-9_.]*$/;
|
|
5512
|
-
var
|
|
5513
|
-
|
|
5514
|
-
|
|
5515
|
-
|
|
5785
|
+
var FUNCTION_TYPES2 = /* @__PURE__ */ new Set([
|
|
5786
|
+
import_utils35.AST_NODE_TYPES.FunctionDeclaration,
|
|
5787
|
+
import_utils35.AST_NODE_TYPES.FunctionExpression,
|
|
5788
|
+
import_utils35.AST_NODE_TYPES.ArrowFunctionExpression
|
|
5516
5789
|
]);
|
|
5517
5790
|
function isStructured(value) {
|
|
5518
5791
|
return value.includes("\n") || SQL_KEYWORD_RE.test(value) || IDENTIFIER_RE.test(value);
|
|
@@ -5523,7 +5796,7 @@ function preview(value) {
|
|
|
5523
5796
|
}
|
|
5524
5797
|
function enclosingFunction(node) {
|
|
5525
5798
|
for (let current = node.parent; current != null; current = current.parent) {
|
|
5526
|
-
if (
|
|
5799
|
+
if (FUNCTION_TYPES2.has(current.type)) {
|
|
5527
5800
|
return current;
|
|
5528
5801
|
}
|
|
5529
5802
|
}
|
|
@@ -5534,9 +5807,9 @@ function isScaffolding(node) {
|
|
|
5534
5807
|
if (parent === void 0) {
|
|
5535
5808
|
return true;
|
|
5536
5809
|
}
|
|
5537
|
-
return parent.type ===
|
|
5810
|
+
return parent.type === import_utils35.AST_NODE_TYPES.ImportDeclaration || parent.type === import_utils35.AST_NODE_TYPES.ExportNamedDeclaration || parent.type === import_utils35.AST_NODE_TYPES.ExportAllDeclaration || parent.type === import_utils35.AST_NODE_TYPES.TSImportType || parent.type === import_utils35.AST_NODE_TYPES.JSXAttribute || parent.type === import_utils35.AST_NODE_TYPES.TSLiteralType;
|
|
5538
5811
|
}
|
|
5539
|
-
var no_repeated_string_literal_default =
|
|
5812
|
+
var no_repeated_string_literal_default = import_utils35.ESLintUtils.RuleCreator(
|
|
5540
5813
|
(name) => `https://github.com/sarj-ai/standards/blob/main/packages/typescript/src/rules/${name}.ts`
|
|
5541
5814
|
)({
|
|
5542
5815
|
name: "no-repeated-string-literal",
|
|
@@ -5576,7 +5849,7 @@ var no_repeated_string_literal_default = import_utils36.ESLintUtils.RuleCreator(
|
|
|
5576
5849
|
}
|
|
5577
5850
|
},
|
|
5578
5851
|
TemplateLiteral(node) {
|
|
5579
|
-
if (node.parent.type ===
|
|
5852
|
+
if (node.parent.type === import_utils35.AST_NODE_TYPES.TaggedTemplateExpression) {
|
|
5580
5853
|
return;
|
|
5581
5854
|
}
|
|
5582
5855
|
const [only] = node.quasis;
|
|
@@ -5610,7 +5883,7 @@ var no_repeated_string_literal_default = import_utils36.ESLintUtils.RuleCreator(
|
|
|
5610
5883
|
});
|
|
5611
5884
|
|
|
5612
5885
|
// src/rules/no-select-star.ts
|
|
5613
|
-
var
|
|
5886
|
+
var import_utils36 = require("@typescript-eslint/utils");
|
|
5614
5887
|
var QUERY_SHAPE = /\bSELECT\b[\s\S]*?\bFROM\b/i;
|
|
5615
5888
|
var SELECT_KEYWORD = /\bSELECT\b/gi;
|
|
5616
5889
|
var FROM_KEYWORD = /^FROM\b/i;
|
|
@@ -5650,7 +5923,7 @@ function hasRealSelectStar(sql) {
|
|
|
5650
5923
|
}
|
|
5651
5924
|
return false;
|
|
5652
5925
|
}
|
|
5653
|
-
var no_select_star_default =
|
|
5926
|
+
var no_select_star_default = import_utils36.ESLintUtils.RuleCreator(
|
|
5654
5927
|
(name) => `https://github.com/sarj-ai/standards/blob/main/packages/typescript/src/rules/${name}.ts`
|
|
5655
5928
|
)({
|
|
5656
5929
|
name: "no-select-star",
|
|
@@ -5679,7 +5952,7 @@ var no_select_star_default = import_utils37.ESLintUtils.RuleCreator(
|
|
|
5679
5952
|
});
|
|
5680
5953
|
|
|
5681
5954
|
// src/rules/no-sleep-in-test-body.ts
|
|
5682
|
-
var
|
|
5955
|
+
var import_utils37 = require("@typescript-eslint/utils");
|
|
5683
5956
|
var SLEEP_HELPERS = /* @__PURE__ */ new Set(["sleep", "delay", "wait", "pause"]);
|
|
5684
5957
|
var TEST_CALLERS = /* @__PURE__ */ new Set([
|
|
5685
5958
|
"it",
|
|
@@ -5687,43 +5960,43 @@ var TEST_CALLERS = /* @__PURE__ */ new Set([
|
|
|
5687
5960
|
"beforeEach",
|
|
5688
5961
|
"afterEach"
|
|
5689
5962
|
]);
|
|
5690
|
-
var
|
|
5691
|
-
|
|
5692
|
-
|
|
5693
|
-
|
|
5963
|
+
var FUNCTION_TYPES3 = /* @__PURE__ */ new Set([
|
|
5964
|
+
import_utils37.AST_NODE_TYPES.FunctionDeclaration,
|
|
5965
|
+
import_utils37.AST_NODE_TYPES.FunctionExpression,
|
|
5966
|
+
import_utils37.AST_NODE_TYPES.ArrowFunctionExpression
|
|
5694
5967
|
]);
|
|
5695
5968
|
function isNonzeroNumericLiteral(node) {
|
|
5696
|
-
return node?.type ===
|
|
5969
|
+
return node?.type === import_utils37.AST_NODE_TYPES.Literal && typeof node.value === "number" && node.value !== 0;
|
|
5697
5970
|
}
|
|
5698
5971
|
function isTimedSetTimeout(node) {
|
|
5699
|
-
return node.type ===
|
|
5972
|
+
return node.type === import_utils37.AST_NODE_TYPES.CallExpression && node.callee.type === import_utils37.AST_NODE_TYPES.Identifier && node.callee.name === "setTimeout" && node.arguments.length >= 2 && isNonzeroNumericLiteral(node.arguments[1]);
|
|
5700
5973
|
}
|
|
5701
5974
|
function isPromiseSleep(node) {
|
|
5702
|
-
if (node.callee.type !==
|
|
5975
|
+
if (node.callee.type !== import_utils37.AST_NODE_TYPES.Identifier || node.callee.name !== "Promise") {
|
|
5703
5976
|
return false;
|
|
5704
5977
|
}
|
|
5705
5978
|
const executor = node.arguments[0];
|
|
5706
|
-
if (executor?.type !==
|
|
5979
|
+
if (executor?.type !== import_utils37.AST_NODE_TYPES.ArrowFunctionExpression && executor?.type !== import_utils37.AST_NODE_TYPES.FunctionExpression) {
|
|
5707
5980
|
return false;
|
|
5708
5981
|
}
|
|
5709
5982
|
const body = executor.body;
|
|
5710
|
-
if (body.type !==
|
|
5983
|
+
if (body.type !== import_utils37.AST_NODE_TYPES.BlockStatement) {
|
|
5711
5984
|
return isTimedSetTimeout(body);
|
|
5712
5985
|
}
|
|
5713
5986
|
return body.body.some(
|
|
5714
|
-
(stmt) => stmt.type ===
|
|
5987
|
+
(stmt) => stmt.type === import_utils37.AST_NODE_TYPES.ExpressionStatement && isTimedSetTimeout(stmt.expression)
|
|
5715
5988
|
);
|
|
5716
5989
|
}
|
|
5717
5990
|
function isHelperSleep(node) {
|
|
5718
|
-
return node.callee.type ===
|
|
5991
|
+
return node.callee.type === import_utils37.AST_NODE_TYPES.Identifier && SLEEP_HELPERS.has(node.callee.name) && node.arguments.length >= 1 && isNonzeroNumericLiteral(node.arguments[0]);
|
|
5719
5992
|
}
|
|
5720
5993
|
function nearestEnclosingFunction(node) {
|
|
5721
5994
|
for (let current = node.parent; current != null; current = current.parent) {
|
|
5722
|
-
if (!
|
|
5995
|
+
if (!FUNCTION_TYPES3.has(current.type)) {
|
|
5723
5996
|
continue;
|
|
5724
5997
|
}
|
|
5725
5998
|
const grandparent = current.parent;
|
|
5726
|
-
const isPromiseExecutor = grandparent?.type ===
|
|
5999
|
+
const isPromiseExecutor = grandparent?.type === import_utils37.AST_NODE_TYPES.NewExpression && isPromiseSleep(grandparent);
|
|
5727
6000
|
if (!isPromiseExecutor) {
|
|
5728
6001
|
return current;
|
|
5729
6002
|
}
|
|
@@ -5731,29 +6004,29 @@ function nearestEnclosingFunction(node) {
|
|
|
5731
6004
|
return null;
|
|
5732
6005
|
}
|
|
5733
6006
|
function testCallerName(callee) {
|
|
5734
|
-
if (callee.type ===
|
|
6007
|
+
if (callee.type === import_utils37.AST_NODE_TYPES.Identifier) {
|
|
5735
6008
|
return callee.name;
|
|
5736
6009
|
}
|
|
5737
|
-
if (callee.type ===
|
|
6010
|
+
if (callee.type === import_utils37.AST_NODE_TYPES.MemberExpression) {
|
|
5738
6011
|
return testCallerName(callee.object);
|
|
5739
6012
|
}
|
|
5740
|
-
if (callee.type ===
|
|
6013
|
+
if (callee.type === import_utils37.AST_NODE_TYPES.CallExpression) {
|
|
5741
6014
|
return testCallerName(callee.callee);
|
|
5742
6015
|
}
|
|
5743
|
-
if (callee.type ===
|
|
6016
|
+
if (callee.type === import_utils37.AST_NODE_TYPES.TaggedTemplateExpression) {
|
|
5744
6017
|
return testCallerName(callee.tag);
|
|
5745
6018
|
}
|
|
5746
6019
|
return null;
|
|
5747
6020
|
}
|
|
5748
6021
|
function isTestBody(fn) {
|
|
5749
6022
|
const call = fn.parent;
|
|
5750
|
-
if (call?.type !==
|
|
6023
|
+
if (call?.type !== import_utils37.AST_NODE_TYPES.CallExpression || !call.arguments.some((argument) => argument === fn)) {
|
|
5751
6024
|
return false;
|
|
5752
6025
|
}
|
|
5753
6026
|
const name = testCallerName(call.callee);
|
|
5754
6027
|
return name !== null && TEST_CALLERS.has(name);
|
|
5755
6028
|
}
|
|
5756
|
-
var no_sleep_in_test_body_default =
|
|
6029
|
+
var no_sleep_in_test_body_default = import_utils37.ESLintUtils.RuleCreator(
|
|
5757
6030
|
(name) => `https://github.com/sarj-ai/standards/blob/main/packages/typescript/src/rules/${name}.ts`
|
|
5758
6031
|
)({
|
|
5759
6032
|
name: "no-sleep-in-test-body",
|
|
@@ -5795,54 +6068,224 @@ var no_sleep_in_test_body_default = import_utils38.ESLintUtils.RuleCreator(
|
|
|
5795
6068
|
});
|
|
5796
6069
|
|
|
5797
6070
|
// src/rules/no-conditional-in-test.ts
|
|
5798
|
-
var
|
|
6071
|
+
var import_utils38 = require("@typescript-eslint/utils");
|
|
5799
6072
|
var TEST_CALLERS2 = /* @__PURE__ */ new Set(["it", "test"]);
|
|
5800
|
-
var
|
|
5801
|
-
|
|
5802
|
-
|
|
5803
|
-
|
|
6073
|
+
var FUNCTION_TYPES4 = /* @__PURE__ */ new Set([
|
|
6074
|
+
import_utils38.AST_NODE_TYPES.FunctionDeclaration,
|
|
6075
|
+
import_utils38.AST_NODE_TYPES.FunctionExpression,
|
|
6076
|
+
import_utils38.AST_NODE_TYPES.ArrowFunctionExpression
|
|
6077
|
+
]);
|
|
6078
|
+
var ASSERTION_ROOTS = /* @__PURE__ */ new Set([
|
|
6079
|
+
"expect",
|
|
6080
|
+
"expectTypeOf",
|
|
6081
|
+
"assert",
|
|
6082
|
+
"assertType"
|
|
6083
|
+
]);
|
|
6084
|
+
var TYPE_ASSERTION_ROOTS = /* @__PURE__ */ new Set([
|
|
6085
|
+
"expectTypeOf",
|
|
6086
|
+
"assertType"
|
|
5804
6087
|
]);
|
|
5805
6088
|
function nearestEnclosingFunction2(node) {
|
|
5806
6089
|
for (let current = node.parent; current != null; current = current.parent) {
|
|
5807
|
-
if (
|
|
6090
|
+
if (FUNCTION_TYPES4.has(current.type)) {
|
|
5808
6091
|
return current;
|
|
5809
6092
|
}
|
|
5810
6093
|
}
|
|
5811
6094
|
return null;
|
|
5812
6095
|
}
|
|
5813
6096
|
function testCallerName2(callee) {
|
|
5814
|
-
if (callee.type ===
|
|
6097
|
+
if (callee.type === import_utils38.AST_NODE_TYPES.Identifier) {
|
|
5815
6098
|
return callee.name;
|
|
5816
6099
|
}
|
|
5817
|
-
if (callee.type ===
|
|
6100
|
+
if (callee.type === import_utils38.AST_NODE_TYPES.MemberExpression) {
|
|
5818
6101
|
return testCallerName2(callee.object);
|
|
5819
6102
|
}
|
|
5820
|
-
if (callee.type ===
|
|
6103
|
+
if (callee.type === import_utils38.AST_NODE_TYPES.CallExpression) {
|
|
5821
6104
|
return testCallerName2(callee.callee);
|
|
5822
6105
|
}
|
|
5823
|
-
if (callee.type ===
|
|
6106
|
+
if (callee.type === import_utils38.AST_NODE_TYPES.TaggedTemplateExpression) {
|
|
5824
6107
|
return testCallerName2(callee.tag);
|
|
5825
6108
|
}
|
|
5826
6109
|
return null;
|
|
5827
6110
|
}
|
|
5828
6111
|
function isTestBody2(fn) {
|
|
5829
6112
|
const call = fn.parent;
|
|
5830
|
-
if (call?.type !==
|
|
6113
|
+
if (call?.type !== import_utils38.AST_NODE_TYPES.CallExpression || !call.arguments.some((argument) => argument === fn)) {
|
|
5831
6114
|
return false;
|
|
5832
6115
|
}
|
|
5833
6116
|
const name = testCallerName2(call.callee);
|
|
5834
6117
|
return name !== null && TEST_CALLERS2.has(name);
|
|
5835
6118
|
}
|
|
5836
|
-
|
|
5837
|
-
|
|
5838
|
-
)
|
|
5839
|
-
|
|
5840
|
-
|
|
5841
|
-
|
|
5842
|
-
|
|
5843
|
-
|
|
5844
|
-
|
|
5845
|
-
|
|
6119
|
+
function subtreeMatches2(node, predicate, descendIntoFunctions = true) {
|
|
6120
|
+
let found = false;
|
|
6121
|
+
const visit = (current) => {
|
|
6122
|
+
if (found) {
|
|
6123
|
+
return;
|
|
6124
|
+
}
|
|
6125
|
+
if (predicate(current)) {
|
|
6126
|
+
found = true;
|
|
6127
|
+
return;
|
|
6128
|
+
}
|
|
6129
|
+
for (const key of Object.keys(current)) {
|
|
6130
|
+
if (key === "parent") {
|
|
6131
|
+
continue;
|
|
6132
|
+
}
|
|
6133
|
+
if (!descendIntoFunctions && FUNCTION_TYPES4.has(current.type) && key === "body") {
|
|
6134
|
+
continue;
|
|
6135
|
+
}
|
|
6136
|
+
const value = current[key];
|
|
6137
|
+
if (Array.isArray(value)) {
|
|
6138
|
+
for (const child of value) {
|
|
6139
|
+
if (typeof child === "object" && child !== null && typeof child.type === "string") {
|
|
6140
|
+
visit(child);
|
|
6141
|
+
}
|
|
6142
|
+
}
|
|
6143
|
+
} else if (typeof value === "object" && value !== null && typeof value.type === "string") {
|
|
6144
|
+
visit(value);
|
|
6145
|
+
}
|
|
6146
|
+
if (found) {
|
|
6147
|
+
return;
|
|
6148
|
+
}
|
|
6149
|
+
}
|
|
6150
|
+
};
|
|
6151
|
+
visit(node);
|
|
6152
|
+
return found;
|
|
6153
|
+
}
|
|
6154
|
+
function rootIdentifier(node) {
|
|
6155
|
+
switch (node.type) {
|
|
6156
|
+
case import_utils38.AST_NODE_TYPES.Identifier:
|
|
6157
|
+
return node.name;
|
|
6158
|
+
case import_utils38.AST_NODE_TYPES.MemberExpression:
|
|
6159
|
+
return rootIdentifier(node.object);
|
|
6160
|
+
case import_utils38.AST_NODE_TYPES.UnaryExpression:
|
|
6161
|
+
return rootIdentifier(node.argument);
|
|
6162
|
+
case import_utils38.AST_NODE_TYPES.AwaitExpression:
|
|
6163
|
+
return rootIdentifier(node.argument);
|
|
6164
|
+
case import_utils38.AST_NODE_TYPES.ChainExpression:
|
|
6165
|
+
case import_utils38.AST_NODE_TYPES.TSNonNullExpression:
|
|
6166
|
+
case import_utils38.AST_NODE_TYPES.TSAsExpression:
|
|
6167
|
+
return rootIdentifier(node.expression);
|
|
6168
|
+
case import_utils38.AST_NODE_TYPES.BinaryExpression:
|
|
6169
|
+
case import_utils38.AST_NODE_TYPES.LogicalExpression:
|
|
6170
|
+
return rootIdentifier(node.left);
|
|
6171
|
+
case import_utils38.AST_NODE_TYPES.CallExpression:
|
|
6172
|
+
return rootIdentifier(node.callee);
|
|
6173
|
+
default:
|
|
6174
|
+
return null;
|
|
6175
|
+
}
|
|
6176
|
+
}
|
|
6177
|
+
function calleeRootName(call) {
|
|
6178
|
+
let current = call.callee;
|
|
6179
|
+
for (; ; ) {
|
|
6180
|
+
if (current.type === import_utils38.AST_NODE_TYPES.Identifier) {
|
|
6181
|
+
return current.name;
|
|
6182
|
+
}
|
|
6183
|
+
if (current.type === import_utils38.AST_NODE_TYPES.MemberExpression) {
|
|
6184
|
+
current = current.object;
|
|
6185
|
+
continue;
|
|
6186
|
+
}
|
|
6187
|
+
if (current.type === import_utils38.AST_NODE_TYPES.CallExpression) {
|
|
6188
|
+
current = current.callee;
|
|
6189
|
+
continue;
|
|
6190
|
+
}
|
|
6191
|
+
if (current.type === import_utils38.AST_NODE_TYPES.ChainExpression || current.type === import_utils38.AST_NODE_TYPES.TSNonNullExpression) {
|
|
6192
|
+
current = current.expression;
|
|
6193
|
+
continue;
|
|
6194
|
+
}
|
|
6195
|
+
return null;
|
|
6196
|
+
}
|
|
6197
|
+
}
|
|
6198
|
+
var isAssertionCall = (node) => node.type === import_utils38.AST_NODE_TYPES.CallExpression && ASSERTION_ROOTS.has(calleeRootName(node) ?? "");
|
|
6199
|
+
var isTypeAssertionCall = (node) => node.type === import_utils38.AST_NODE_TYPES.CallExpression && TYPE_ASSERTION_ROOTS.has(calleeRootName(node) ?? "");
|
|
6200
|
+
var containsAssertion = (node) => subtreeMatches2(node, isAssertionCall);
|
|
6201
|
+
var containsSkipCall = (node) => subtreeMatches2(
|
|
6202
|
+
node,
|
|
6203
|
+
(current) => current.type === import_utils38.AST_NODE_TYPES.CallExpression && current.callee.type === import_utils38.AST_NODE_TYPES.MemberExpression && !current.callee.computed && current.callee.property.type === import_utils38.AST_NODE_TYPES.Identifier && current.callee.property.name === "skip"
|
|
6204
|
+
);
|
|
6205
|
+
var containsEscape = (node) => subtreeMatches2(
|
|
6206
|
+
node,
|
|
6207
|
+
(current) => current.type === import_utils38.AST_NODE_TYPES.ReturnStatement || current.type === import_utils38.AST_NODE_TYPES.ContinueStatement || current.type === import_utils38.AST_NODE_TYPES.BreakStatement,
|
|
6208
|
+
false
|
|
6209
|
+
);
|
|
6210
|
+
function branchStatements(branch) {
|
|
6211
|
+
return branch.type === import_utils38.AST_NODE_TYPES.BlockStatement ? branch.body : [branch];
|
|
6212
|
+
}
|
|
6213
|
+
function previousSibling(node) {
|
|
6214
|
+
const parent = node.parent;
|
|
6215
|
+
let siblings = null;
|
|
6216
|
+
if (parent.type === import_utils38.AST_NODE_TYPES.BlockStatement || parent.type === import_utils38.AST_NODE_TYPES.Program || parent.type === import_utils38.AST_NODE_TYPES.StaticBlock) {
|
|
6217
|
+
siblings = parent.body;
|
|
6218
|
+
} else if (parent.type === import_utils38.AST_NODE_TYPES.SwitchCase) {
|
|
6219
|
+
siblings = parent.consequent;
|
|
6220
|
+
}
|
|
6221
|
+
if (siblings === null) {
|
|
6222
|
+
return null;
|
|
6223
|
+
}
|
|
6224
|
+
const index = siblings.indexOf(node);
|
|
6225
|
+
return index > 0 ? siblings[index - 1] ?? null : null;
|
|
6226
|
+
}
|
|
6227
|
+
function isPinnedNarrowingGuard(node) {
|
|
6228
|
+
const testRoot = rootIdentifier(node.test);
|
|
6229
|
+
if (testRoot === null) {
|
|
6230
|
+
return false;
|
|
6231
|
+
}
|
|
6232
|
+
const previous = previousSibling(node);
|
|
6233
|
+
if (previous === null || previous.type !== import_utils38.AST_NODE_TYPES.ExpressionStatement) {
|
|
6234
|
+
return false;
|
|
6235
|
+
}
|
|
6236
|
+
let matched = false;
|
|
6237
|
+
subtreeMatches2(previous, (current) => {
|
|
6238
|
+
if (current.type !== import_utils38.AST_NODE_TYPES.CallExpression || current.callee.type !== import_utils38.AST_NODE_TYPES.Identifier || current.callee.name !== "expect") {
|
|
6239
|
+
return false;
|
|
6240
|
+
}
|
|
6241
|
+
const subject = current.arguments[0];
|
|
6242
|
+
if (subject === void 0) {
|
|
6243
|
+
return false;
|
|
6244
|
+
}
|
|
6245
|
+
if (rootIdentifier(subject) === testRoot) {
|
|
6246
|
+
matched = true;
|
|
6247
|
+
return true;
|
|
6248
|
+
}
|
|
6249
|
+
return false;
|
|
6250
|
+
});
|
|
6251
|
+
return matched;
|
|
6252
|
+
}
|
|
6253
|
+
function isThrowingGuard(node) {
|
|
6254
|
+
if (node.alternate !== null) {
|
|
6255
|
+
return false;
|
|
6256
|
+
}
|
|
6257
|
+
const statements = branchStatements(node.consequent);
|
|
6258
|
+
return statements.length === 1 && statements[0]?.type === import_utils38.AST_NODE_TYPES.ThrowStatement;
|
|
6259
|
+
}
|
|
6260
|
+
function isTypeAssertionBranch(branch) {
|
|
6261
|
+
const statements = branchStatements(branch);
|
|
6262
|
+
return statements.length > 0 && statements.every(
|
|
6263
|
+
(statement) => statement.type === import_utils38.AST_NODE_TYPES.ExpressionStatement && isTypeAssertionCall(statement.expression)
|
|
6264
|
+
);
|
|
6265
|
+
}
|
|
6266
|
+
function isTypeLevelNarrowing(node) {
|
|
6267
|
+
return isTypeAssertionBranch(node.consequent) && (node.alternate === null || isTypeAssertionBranch(node.alternate));
|
|
6268
|
+
}
|
|
6269
|
+
var isInertBranch = (branch) => !containsAssertion(branch) && !containsEscape(branch) && !containsSkipCall(branch);
|
|
6270
|
+
function isInertNormalization(node) {
|
|
6271
|
+
return isInertBranch(node.consequent) && (node.alternate === null || isInertBranch(node.alternate));
|
|
6272
|
+
}
|
|
6273
|
+
function isExemptIfStatement(node) {
|
|
6274
|
+
return isPinnedNarrowingGuard(node) || isThrowingGuard(node) || isTypeLevelNarrowing(node) || isInertNormalization(node);
|
|
6275
|
+
}
|
|
6276
|
+
function isShortCircuitedAssertion(node) {
|
|
6277
|
+
return node.operator !== "??" && node.parent.type === import_utils38.AST_NODE_TYPES.ExpressionStatement && containsAssertion(node.right);
|
|
6278
|
+
}
|
|
6279
|
+
var no_conditional_in_test_default = import_utils38.ESLintUtils.RuleCreator(
|
|
6280
|
+
(name) => `https://github.com/sarj-ai/standards/blob/main/packages/typescript/src/rules/${name}.ts`
|
|
6281
|
+
)({
|
|
6282
|
+
name: "no-conditional-in-test",
|
|
6283
|
+
meta: {
|
|
6284
|
+
type: "problem",
|
|
6285
|
+
docs: {
|
|
6286
|
+
description: "Disallow conditional logic (if, switch, ternary) in test bodies, which can hide missing assertions or test multiple code paths."
|
|
6287
|
+
},
|
|
6288
|
+
schema: [],
|
|
5846
6289
|
messages: {
|
|
5847
6290
|
noConditionalInTest: "Avoid using conditional logic in tests. It can obscure intent and hide unexecuted assertions. Split the test instead."
|
|
5848
6291
|
}
|
|
@@ -5861,6 +6304,9 @@ var no_conditional_in_test_default = import_utils39.ESLintUtils.RuleCreator(
|
|
|
5861
6304
|
};
|
|
5862
6305
|
return {
|
|
5863
6306
|
IfStatement(node) {
|
|
6307
|
+
if (isExemptIfStatement(node)) {
|
|
6308
|
+
return;
|
|
6309
|
+
}
|
|
5864
6310
|
report(node);
|
|
5865
6311
|
},
|
|
5866
6312
|
SwitchStatement(node) {
|
|
@@ -5870,6 +6316,9 @@ var no_conditional_in_test_default = import_utils39.ESLintUtils.RuleCreator(
|
|
|
5870
6316
|
report(node);
|
|
5871
6317
|
},
|
|
5872
6318
|
LogicalExpression(node) {
|
|
6319
|
+
if (!isShortCircuitedAssertion(node)) {
|
|
6320
|
+
return;
|
|
6321
|
+
}
|
|
5873
6322
|
report(node);
|
|
5874
6323
|
}
|
|
5875
6324
|
};
|
|
@@ -5877,7 +6326,7 @@ var no_conditional_in_test_default = import_utils39.ESLintUtils.RuleCreator(
|
|
|
5877
6326
|
});
|
|
5878
6327
|
|
|
5879
6328
|
// src/rules/prefer-constant-time-secret-compare.ts
|
|
5880
|
-
var
|
|
6329
|
+
var import_utils39 = require("@typescript-eslint/utils");
|
|
5881
6330
|
var EQUALITY_OPERATORS = /* @__PURE__ */ new Set(["===", "!==", "==", "!="]);
|
|
5882
6331
|
var SENTINEL_IDENTIFIERS = /* @__PURE__ */ new Set(["undefined", "NaN"]);
|
|
5883
6332
|
var SENTINEL_WORDS = /(^|_)(SENTINEL|EMPTY|NONE|NULL|UNSET|MISSING|PLACEHOLDER|DUMMY|FAKE|EXAMPLE)(_|$)/;
|
|
@@ -5890,36 +6339,36 @@ function isConstantReference(identifier) {
|
|
|
5890
6339
|
}
|
|
5891
6340
|
function isExcludedOperand(node) {
|
|
5892
6341
|
switch (node.type) {
|
|
5893
|
-
case
|
|
6342
|
+
case import_utils39.AST_NODE_TYPES.Literal:
|
|
5894
6343
|
return true;
|
|
5895
|
-
case
|
|
6344
|
+
case import_utils39.AST_NODE_TYPES.TemplateLiteral:
|
|
5896
6345
|
return node.expressions.length === 0;
|
|
5897
|
-
case
|
|
6346
|
+
case import_utils39.AST_NODE_TYPES.Identifier:
|
|
5898
6347
|
return SENTINEL_IDENTIFIERS.has(node.name) || SENTINEL_PREFIX_RE.test(node.name) || isConstantReference(node.name);
|
|
5899
|
-
case
|
|
5900
|
-
return !node.computed && node.property.type ===
|
|
6348
|
+
case import_utils39.AST_NODE_TYPES.MemberExpression:
|
|
6349
|
+
return !node.computed && node.property.type === import_utils39.AST_NODE_TYPES.Identifier && (SENTINEL_PREFIX_RE.test(node.property.name) || isConstantReference(node.property.name));
|
|
5901
6350
|
default:
|
|
5902
6351
|
return false;
|
|
5903
6352
|
}
|
|
5904
6353
|
}
|
|
5905
6354
|
function operandName(node) {
|
|
5906
|
-
if (node.type ===
|
|
6355
|
+
if (node.type === import_utils39.AST_NODE_TYPES.Identifier) {
|
|
5907
6356
|
return node.name;
|
|
5908
6357
|
}
|
|
5909
|
-
if (node.type ===
|
|
6358
|
+
if (node.type === import_utils39.AST_NODE_TYPES.MemberExpression && !node.computed && node.property.type === import_utils39.AST_NODE_TYPES.Identifier) {
|
|
5910
6359
|
return node.property.name;
|
|
5911
6360
|
}
|
|
5912
6361
|
return null;
|
|
5913
6362
|
}
|
|
5914
6363
|
function isSecretOperand(node) {
|
|
5915
|
-
if (node.type ===
|
|
6364
|
+
if (node.type === import_utils39.AST_NODE_TYPES.TemplateLiteral) {
|
|
5916
6365
|
return node.expressions.some((expression) => isSecretOperand(expression));
|
|
5917
6366
|
}
|
|
5918
6367
|
const name = operandName(node);
|
|
5919
6368
|
return name !== null && isAuthSecretName(name);
|
|
5920
6369
|
}
|
|
5921
6370
|
function secretNameOf(node) {
|
|
5922
|
-
if (node.type ===
|
|
6371
|
+
if (node.type === import_utils39.AST_NODE_TYPES.TemplateLiteral) {
|
|
5923
6372
|
for (const expression of node.expressions) {
|
|
5924
6373
|
const nested = secretNameOf(expression);
|
|
5925
6374
|
if (nested !== null) {
|
|
@@ -5930,7 +6379,7 @@ function secretNameOf(node) {
|
|
|
5930
6379
|
}
|
|
5931
6380
|
return operandName(node);
|
|
5932
6381
|
}
|
|
5933
|
-
var prefer_constant_time_secret_compare_default =
|
|
6382
|
+
var prefer_constant_time_secret_compare_default = import_utils39.ESLintUtils.RuleCreator(
|
|
5934
6383
|
(name) => `https://github.com/sarj-ai/standards/blob/main/packages/typescript/src/rules/${name}.ts`
|
|
5935
6384
|
)({
|
|
5936
6385
|
name: "prefer-constant-time-secret-compare",
|
|
@@ -5973,11 +6422,11 @@ var prefer_constant_time_secret_compare_default = import_utils40.ESLintUtils.Rul
|
|
|
5973
6422
|
});
|
|
5974
6423
|
|
|
5975
6424
|
// src/rules/store-insert-requires-on-conflict.ts
|
|
5976
|
-
var
|
|
6425
|
+
var import_utils40 = require("@typescript-eslint/utils");
|
|
5977
6426
|
var INSERT_WRITE = /\bINSERT\s+(?:OR\s+\w+\s+)?INTO\s+[\w."'`?$:@-]+\s*(?:\([^)]*\)\s*)?(?:VALUES|SELECT|DEFAULT\s+VALUES)\b/i;
|
|
5978
6427
|
var CONFLICT_HANDLED = /\bON\s+CONFLICT\b|\bON\s+DUPLICATE\s+KEY\b|\bINSERT\s+OR\s+(?:IGNORE|REPLACE)\b/i;
|
|
5979
6428
|
var INSERT_GATE = /insert/i;
|
|
5980
|
-
var store_insert_requires_on_conflict_default =
|
|
6429
|
+
var store_insert_requires_on_conflict_default = import_utils40.ESLintUtils.RuleCreator(
|
|
5981
6430
|
(name) => `https://github.com/sarj-ai/standards/blob/main/packages/typescript/src/rules/${name}.ts`
|
|
5982
6431
|
)({
|
|
5983
6432
|
name: "store-insert-requires-on-conflict",
|
|
@@ -6006,17 +6455,17 @@ var store_insert_requires_on_conflict_default = import_utils41.ESLintUtils.RuleC
|
|
|
6006
6455
|
});
|
|
6007
6456
|
|
|
6008
6457
|
// src/rules/no-dynamic-sql.ts
|
|
6009
|
-
var
|
|
6458
|
+
var import_utils41 = require("@typescript-eslint/utils");
|
|
6010
6459
|
var DEFAULT_METHODS = ["prepare", "exec", "query"];
|
|
6011
6460
|
var CONSTANT_CASE_RE = /^[A-Z][A-Z0-9_]*$/;
|
|
6012
6461
|
function isStaticFragment(expression) {
|
|
6013
|
-
if (expression.type ===
|
|
6462
|
+
if (expression.type === import_utils41.AST_NODE_TYPES.Identifier) {
|
|
6014
6463
|
return CONSTANT_CASE_RE.test(expression.name);
|
|
6015
6464
|
}
|
|
6016
|
-
if (expression.type ===
|
|
6465
|
+
if (expression.type === import_utils41.AST_NODE_TYPES.MemberExpression && !expression.computed && expression.property.type === import_utils41.AST_NODE_TYPES.Identifier) {
|
|
6017
6466
|
return CONSTANT_CASE_RE.test(expression.property.name);
|
|
6018
6467
|
}
|
|
6019
|
-
if (expression.type ===
|
|
6468
|
+
if (expression.type === import_utils41.AST_NODE_TYPES.Literal) {
|
|
6020
6469
|
return typeof expression.value === "string";
|
|
6021
6470
|
}
|
|
6022
6471
|
return false;
|
|
@@ -6027,36 +6476,36 @@ function runtimeInterpolations(template) {
|
|
|
6027
6476
|
);
|
|
6028
6477
|
}
|
|
6029
6478
|
function concatOperands(node) {
|
|
6030
|
-
if (node.type ===
|
|
6479
|
+
if (node.type === import_utils41.AST_NODE_TYPES.BinaryExpression && node.operator === "+") {
|
|
6031
6480
|
return [...concatOperands(node.left), ...concatOperands(node.right)];
|
|
6032
6481
|
}
|
|
6033
6482
|
return [node];
|
|
6034
6483
|
}
|
|
6035
6484
|
function runtimeConcatOperands(node) {
|
|
6036
|
-
if (node.type !==
|
|
6485
|
+
if (node.type !== import_utils41.AST_NODE_TYPES.BinaryExpression || node.operator !== "+") {
|
|
6037
6486
|
return [];
|
|
6038
6487
|
}
|
|
6039
6488
|
const operands = concatOperands(node);
|
|
6040
6489
|
const hasStringLiteral = operands.some(
|
|
6041
|
-
(operand) => operand.type ===
|
|
6490
|
+
(operand) => operand.type === import_utils41.AST_NODE_TYPES.Literal && typeof operand.value === "string"
|
|
6042
6491
|
);
|
|
6043
6492
|
if (!hasStringLiteral) {
|
|
6044
6493
|
return [];
|
|
6045
6494
|
}
|
|
6046
6495
|
return operands.filter(
|
|
6047
|
-
(operand) => operand.type !==
|
|
6496
|
+
(operand) => operand.type !== import_utils41.AST_NODE_TYPES.Literal && !isStaticFragment(operand)
|
|
6048
6497
|
);
|
|
6049
6498
|
}
|
|
6050
6499
|
var SQL_STATEMENT_RE = /\b(?:select\s|insert\s+into\b|insert\s+or\b|update\s+\w|delete\s+from\b|replace\s+into\b|merge\s+into\b|upsert\s+into\b|create\s+(?:temp(?:orary)?\s+)?(?:table|index|view|trigger|schema|database)\b|alter\s+table\b|drop\s+(?:table|index|view|trigger)\b|truncate\s+table\b|pragma\s+\w|with\s+\w+\s+as\s*\(|from\s+\w+\s+where\b)/i;
|
|
6051
6500
|
var RUNTIME_MARKER = " ? ";
|
|
6052
6501
|
function staticStatementText(node) {
|
|
6053
|
-
if (node.type ===
|
|
6502
|
+
if (node.type === import_utils41.AST_NODE_TYPES.TemplateLiteral) {
|
|
6054
6503
|
return node.quasis.map((quasi) => quasi.value.cooked ?? quasi.value.raw).join(RUNTIME_MARKER);
|
|
6055
6504
|
}
|
|
6056
|
-
if (node.type ===
|
|
6505
|
+
if (node.type === import_utils41.AST_NODE_TYPES.Literal) {
|
|
6057
6506
|
return typeof node.value === "string" ? node.value : RUNTIME_MARKER;
|
|
6058
6507
|
}
|
|
6059
|
-
if (node.type ===
|
|
6508
|
+
if (node.type === import_utils41.AST_NODE_TYPES.BinaryExpression && node.operator === "+") {
|
|
6060
6509
|
return staticStatementText(node.left) + staticStatementText(node.right);
|
|
6061
6510
|
}
|
|
6062
6511
|
return RUNTIME_MARKER;
|
|
@@ -6066,13 +6515,13 @@ function looksLikeSql(node) {
|
|
|
6066
6515
|
}
|
|
6067
6516
|
function statementMethodName(node, methods) {
|
|
6068
6517
|
const callee = node.callee;
|
|
6069
|
-
if (callee.type !==
|
|
6518
|
+
if (callee.type !== import_utils41.AST_NODE_TYPES.MemberExpression || callee.computed || callee.property.type !== import_utils41.AST_NODE_TYPES.Identifier) {
|
|
6070
6519
|
return null;
|
|
6071
6520
|
}
|
|
6072
6521
|
const name = callee.property.name;
|
|
6073
6522
|
return methods.has(name) ? name : null;
|
|
6074
6523
|
}
|
|
6075
|
-
var no_dynamic_sql_default =
|
|
6524
|
+
var no_dynamic_sql_default = import_utils41.ESLintUtils.RuleCreator(
|
|
6076
6525
|
(name) => `https://github.com/sarj-ai/standards/blob/main/packages/typescript/src/rules/${name}.ts`
|
|
6077
6526
|
)({
|
|
6078
6527
|
name: "no-dynamic-sql",
|
|
@@ -6111,7 +6560,7 @@ var no_dynamic_sql_default = import_utils42.ESLintUtils.RuleCreator(
|
|
|
6111
6560
|
if (statement === void 0 || !looksLikeSql(statement)) {
|
|
6112
6561
|
return;
|
|
6113
6562
|
}
|
|
6114
|
-
const offenders = statement.type ===
|
|
6563
|
+
const offenders = statement.type === import_utils41.AST_NODE_TYPES.TemplateLiteral ? runtimeInterpolations(statement) : runtimeConcatOperands(statement);
|
|
6115
6564
|
for (const offender of offenders) {
|
|
6116
6565
|
context.report({
|
|
6117
6566
|
node: offender,
|
|
@@ -6125,7 +6574,7 @@ var no_dynamic_sql_default = import_utils42.ESLintUtils.RuleCreator(
|
|
|
6125
6574
|
});
|
|
6126
6575
|
|
|
6127
6576
|
// src/rules/no-raw-fetch-outside-clients.ts
|
|
6128
|
-
var
|
|
6577
|
+
var import_utils42 = require("@typescript-eslint/utils");
|
|
6129
6578
|
var DEFAULT_ALLOW = [
|
|
6130
6579
|
"[\\\\/]clients?[\\\\/]",
|
|
6131
6580
|
"-client\\.[cm]?[jt]sx?$",
|
|
@@ -6135,17 +6584,15 @@ var DEFAULT_ALLOW = [
|
|
|
6135
6584
|
"[\\\\/]api[\\\\/]",
|
|
6136
6585
|
"[\\\\/]api\\.[cm]?[jt]sx?$",
|
|
6137
6586
|
"[-.]api\\.[cm]?[jt]sx?$",
|
|
6138
|
-
|
|
6139
|
-
|
|
6140
|
-
|
|
6141
|
-
"
|
|
6142
|
-
"
|
|
6143
|
-
"[
|
|
6144
|
-
"[
|
|
6145
|
-
"[\\\\/]tests?[\\\\/]",
|
|
6146
|
-
// jscodeshift input/output fixtures — text a codemod transforms, not code.
|
|
6147
|
-
"[\\\\/]__testfixtures__[\\\\/]"
|
|
6587
|
+
// Vendor wrapper conventions: a module that exists to own one third-party
|
|
6588
|
+
// origin's HTTP. See the SECOND SWEEP note in the file header.
|
|
6589
|
+
"[\\\\/]services?[\\\\/]",
|
|
6590
|
+
"[\\\\/](connectors|providers|integrations|adapters|fetchers)[\\\\/]",
|
|
6591
|
+
"[\\\\/]notifications[\\\\/]",
|
|
6592
|
+
"[Ss]ervice\\.[cm]?[jt]sx?$",
|
|
6593
|
+
"-(service|connector|adapter|sdk|fetcher)\\.[cm]?[jt]sx?$"
|
|
6148
6594
|
];
|
|
6595
|
+
var NON_PRODUCTION_TREE_RE = /[\\/](playwright|cypress|__testfixtures__)[\\/]/;
|
|
6149
6596
|
var GLOBAL_RECEIVERS = /* @__PURE__ */ new Set([
|
|
6150
6597
|
"globalThis",
|
|
6151
6598
|
"window",
|
|
@@ -6171,6 +6618,10 @@ function identifierLikeName(node) {
|
|
|
6171
6618
|
}
|
|
6172
6619
|
return null;
|
|
6173
6620
|
}
|
|
6621
|
+
function isConstructedArgumentHandoff(node) {
|
|
6622
|
+
const [first] = node.arguments;
|
|
6623
|
+
return node.arguments.length === 1 && first !== void 0 && first.type === import_utils42.AST_NODE_TYPES.NewExpression;
|
|
6624
|
+
}
|
|
6174
6625
|
function isPresignedUrlTransfer(node) {
|
|
6175
6626
|
const first = node.arguments[0];
|
|
6176
6627
|
if (first === void 0) {
|
|
@@ -6189,7 +6640,7 @@ function compile(patterns) {
|
|
|
6189
6640
|
}
|
|
6190
6641
|
return compiled;
|
|
6191
6642
|
}
|
|
6192
|
-
var no_raw_fetch_outside_clients_default =
|
|
6643
|
+
var no_raw_fetch_outside_clients_default = import_utils42.ESLintUtils.RuleCreator(
|
|
6193
6644
|
(name) => `https://github.com/sarj-ai/standards/blob/main/packages/typescript/src/rules/${name}.ts`
|
|
6194
6645
|
)({
|
|
6195
6646
|
name: "no-raw-fetch-outside-clients",
|
|
@@ -6217,15 +6668,18 @@ var no_raw_fetch_outside_clients_default = import_utils43.ESLintUtils.RuleCreato
|
|
|
6217
6668
|
},
|
|
6218
6669
|
defaultOptions: [{}],
|
|
6219
6670
|
create(context, [options]) {
|
|
6671
|
+
const filename = context.filename;
|
|
6672
|
+
if (isTestFile(filename) || NON_PRODUCTION_TREE_RE.test(filename)) {
|
|
6673
|
+
return {};
|
|
6674
|
+
}
|
|
6220
6675
|
const patterns = options?.allow ?? DEFAULT_ALLOW;
|
|
6221
6676
|
const allowed = compile(patterns);
|
|
6222
|
-
const filename = context.filename;
|
|
6223
6677
|
if (allowed.some((re) => re.test(filename))) {
|
|
6224
6678
|
return {};
|
|
6225
6679
|
}
|
|
6226
6680
|
return {
|
|
6227
6681
|
CallExpression(node) {
|
|
6228
|
-
if (isPresignedUrlTransfer(node)) {
|
|
6682
|
+
if (isPresignedUrlTransfer(node) || isConstructedArgumentHandoff(node)) {
|
|
6229
6683
|
return;
|
|
6230
6684
|
}
|
|
6231
6685
|
if (isGlobalFetchCall(node)) {
|
|
@@ -6237,7 +6691,7 @@ var no_raw_fetch_outside_clients_default = import_utils43.ESLintUtils.RuleCreato
|
|
|
6237
6691
|
});
|
|
6238
6692
|
|
|
6239
6693
|
// src/rules/no-storage-in-stateless-modules.ts
|
|
6240
|
-
var
|
|
6694
|
+
var import_utils43 = require("@typescript-eslint/utils");
|
|
6241
6695
|
var DEFAULT_METHODS2 = [
|
|
6242
6696
|
"prepare",
|
|
6243
6697
|
"put",
|
|
@@ -6256,7 +6710,7 @@ function compile2(patterns) {
|
|
|
6256
6710
|
}
|
|
6257
6711
|
function storageMethodName(node, methods) {
|
|
6258
6712
|
const callee = node.callee;
|
|
6259
|
-
if (callee.type !==
|
|
6713
|
+
if (callee.type !== import_utils43.AST_NODE_TYPES.MemberExpression || callee.computed || callee.property.type !== import_utils43.AST_NODE_TYPES.Identifier) {
|
|
6260
6714
|
return null;
|
|
6261
6715
|
}
|
|
6262
6716
|
const name = callee.property.name;
|
|
@@ -6268,7 +6722,7 @@ function storageMethodName(node, methods) {
|
|
|
6268
6722
|
}
|
|
6269
6723
|
return name;
|
|
6270
6724
|
}
|
|
6271
|
-
var no_storage_in_stateless_modules_default =
|
|
6725
|
+
var no_storage_in_stateless_modules_default = import_utils43.ESLintUtils.RuleCreator(
|
|
6272
6726
|
(name) => `https://github.com/sarj-ai/standards/blob/main/packages/typescript/src/rules/${name}.ts`
|
|
6273
6727
|
)({
|
|
6274
6728
|
name: "no-storage-in-stateless-modules",
|
|
@@ -6326,7 +6780,7 @@ var no_storage_in_stateless_modules_default = import_utils44.ESLintUtils.RuleCre
|
|
|
6326
6780
|
});
|
|
6327
6781
|
|
|
6328
6782
|
// src/rules/no-zod-native-enum.ts
|
|
6329
|
-
var
|
|
6783
|
+
var import_utils44 = require("@typescript-eslint/utils");
|
|
6330
6784
|
var ts2 = __toESM(require("typescript"), 1);
|
|
6331
6785
|
var IGNORE_PATTERNS2 = [
|
|
6332
6786
|
/[\\/]generated[\\/]/,
|
|
@@ -6344,7 +6798,7 @@ function isZodModule2(source) {
|
|
|
6344
6798
|
return /(^|[/@-])zod([/-]|$)/.test(source);
|
|
6345
6799
|
}
|
|
6346
6800
|
function unwrap3(node) {
|
|
6347
|
-
if (node.type ===
|
|
6801
|
+
if (node.type === import_utils44.AST_NODE_TYPES.TSAsExpression || node.type === import_utils44.AST_NODE_TYPES.TSSatisfiesExpression) {
|
|
6348
6802
|
return unwrap3(node.expression);
|
|
6349
6803
|
}
|
|
6350
6804
|
return node;
|
|
@@ -6352,14 +6806,14 @@ function unwrap3(node) {
|
|
|
6352
6806
|
function stringValueTexts(node, sourceCode) {
|
|
6353
6807
|
const texts = [];
|
|
6354
6808
|
for (const prop of node.properties) {
|
|
6355
|
-
if (prop.type !==
|
|
6809
|
+
if (prop.type !== import_utils44.AST_NODE_TYPES.Property) {
|
|
6356
6810
|
return null;
|
|
6357
6811
|
}
|
|
6358
6812
|
if (prop.computed || prop.shorthand || prop.method || prop.kind !== "init") {
|
|
6359
6813
|
return null;
|
|
6360
6814
|
}
|
|
6361
6815
|
const value = prop.value;
|
|
6362
|
-
if (value.type !==
|
|
6816
|
+
if (value.type !== import_utils44.AST_NODE_TYPES.Literal || typeof value.value !== "string") {
|
|
6363
6817
|
return null;
|
|
6364
6818
|
}
|
|
6365
6819
|
const text = sourceCode.getText(value);
|
|
@@ -6375,7 +6829,7 @@ function resolvesToLocalEnum(node, scope) {
|
|
|
6375
6829
|
const variable = current.variables.find((v) => v.name === node.name);
|
|
6376
6830
|
if (variable !== void 0) {
|
|
6377
6831
|
return variable.defs.some(
|
|
6378
|
-
(def) => def.node.type ===
|
|
6832
|
+
(def) => def.node.type === import_utils44.AST_NODE_TYPES.TSEnumDeclaration
|
|
6379
6833
|
);
|
|
6380
6834
|
}
|
|
6381
6835
|
current = current.upper;
|
|
@@ -6395,7 +6849,7 @@ function resolvesToImportedEnum(node, services) {
|
|
|
6395
6849
|
}
|
|
6396
6850
|
return (symbol.flags & ENUM_SYMBOL_FLAGS) !== 0;
|
|
6397
6851
|
}
|
|
6398
|
-
var no_zod_native_enum_default =
|
|
6852
|
+
var no_zod_native_enum_default = import_utils44.ESLintUtils.RuleCreator(
|
|
6399
6853
|
(name) => `https://github.com/sarj-ai/linting/blob/main/packages/typescript/src/rules/${name}.ts`
|
|
6400
6854
|
)({
|
|
6401
6855
|
name: "no-zod-native-enum",
|
|
@@ -6422,32 +6876,32 @@ var no_zod_native_enum_default = import_utils45.ESLintUtils.RuleCreator(
|
|
|
6422
6876
|
}
|
|
6423
6877
|
let services;
|
|
6424
6878
|
try {
|
|
6425
|
-
services =
|
|
6879
|
+
services = import_utils44.ESLintUtils.getParserServices(context);
|
|
6426
6880
|
} catch {
|
|
6427
6881
|
services = null;
|
|
6428
6882
|
}
|
|
6429
6883
|
const zodImportedNames = /* @__PURE__ */ new Map();
|
|
6430
6884
|
function isZodMemberCall(node, api) {
|
|
6431
6885
|
const callee = node.callee;
|
|
6432
|
-
if (callee.type ===
|
|
6886
|
+
if (callee.type === import_utils44.AST_NODE_TYPES.MemberExpression && !callee.computed && callee.property.type === import_utils44.AST_NODE_TYPES.Identifier) {
|
|
6433
6887
|
return callee.property.name === api;
|
|
6434
6888
|
}
|
|
6435
|
-
if (callee.type ===
|
|
6889
|
+
if (callee.type === import_utils44.AST_NODE_TYPES.Identifier) {
|
|
6436
6890
|
return zodImportedNames.get(callee.name) === api;
|
|
6437
6891
|
}
|
|
6438
6892
|
return false;
|
|
6439
6893
|
}
|
|
6440
6894
|
function buildFix(node) {
|
|
6441
6895
|
const callee = node.callee;
|
|
6442
|
-
if (callee.type !==
|
|
6896
|
+
if (callee.type !== import_utils44.AST_NODE_TYPES.MemberExpression || callee.property.type !== import_utils44.AST_NODE_TYPES.Identifier) {
|
|
6443
6897
|
return null;
|
|
6444
6898
|
}
|
|
6445
6899
|
const arg = node.arguments[0];
|
|
6446
|
-
if (arg === void 0 || node.arguments.length !== 1 || arg.type ===
|
|
6900
|
+
if (arg === void 0 || node.arguments.length !== 1 || arg.type === import_utils44.AST_NODE_TYPES.SpreadElement) {
|
|
6447
6901
|
return null;
|
|
6448
6902
|
}
|
|
6449
6903
|
const inner = unwrap3(arg);
|
|
6450
|
-
if (inner.type !==
|
|
6904
|
+
if (inner.type !== import_utils44.AST_NODE_TYPES.ObjectExpression) {
|
|
6451
6905
|
return null;
|
|
6452
6906
|
}
|
|
6453
6907
|
const values = stringValueTexts(inner, sourceCode);
|
|
@@ -6467,7 +6921,7 @@ var no_zod_native_enum_default = import_utils45.ESLintUtils.RuleCreator(
|
|
|
6467
6921
|
return;
|
|
6468
6922
|
}
|
|
6469
6923
|
for (const spec of node.specifiers) {
|
|
6470
|
-
if (spec.type ===
|
|
6924
|
+
if (spec.type === import_utils44.AST_NODE_TYPES.ImportSpecifier && spec.imported.type === import_utils44.AST_NODE_TYPES.Identifier) {
|
|
6471
6925
|
zodImportedNames.set(spec.local.name, spec.imported.name);
|
|
6472
6926
|
}
|
|
6473
6927
|
}
|
|
@@ -6486,7 +6940,7 @@ var no_zod_native_enum_default = import_utils45.ESLintUtils.RuleCreator(
|
|
|
6486
6940
|
return;
|
|
6487
6941
|
}
|
|
6488
6942
|
const arg = node.arguments[0];
|
|
6489
|
-
if (arg === void 0 || arg.type !==
|
|
6943
|
+
if (arg === void 0 || arg.type !== import_utils44.AST_NODE_TYPES.Identifier) {
|
|
6490
6944
|
return;
|
|
6491
6945
|
}
|
|
6492
6946
|
const isEnum = resolvesToLocalEnum(arg, sourceCode.getScope(arg)) || services !== null && resolvesToImportedEnum(arg, services);
|
|
@@ -6503,7 +6957,7 @@ var no_zod_native_enum_default = import_utils45.ESLintUtils.RuleCreator(
|
|
|
6503
6957
|
});
|
|
6504
6958
|
|
|
6505
6959
|
// src/rules/prefer-module-level-constant.ts
|
|
6506
|
-
var
|
|
6960
|
+
var import_utils45 = require("@typescript-eslint/utils");
|
|
6507
6961
|
var DEFAULT_MIN_ELEMENTS = 3;
|
|
6508
6962
|
var MAX_LITERAL_DEPTH = 4;
|
|
6509
6963
|
var IGNORE_PATTERNS3 = [
|
|
@@ -6512,13 +6966,6 @@ var IGNORE_PATTERNS3 = [
|
|
|
6512
6966
|
/\.generated\.tsx?$/,
|
|
6513
6967
|
/\.d\.ts$/
|
|
6514
6968
|
];
|
|
6515
|
-
var TEST_FILE_PATTERNS = [
|
|
6516
|
-
/\.(?:test|spec)\.[cm]?[jt]sx?$/,
|
|
6517
|
-
/[\\/]__tests__[\\/]/,
|
|
6518
|
-
/[\\/]__mocks__[\\/]/,
|
|
6519
|
-
/[\\/]tests?[\\/]/,
|
|
6520
|
-
/\.stories\.[cm]?[jt]sx?$/
|
|
6521
|
-
];
|
|
6522
6969
|
var MUTATING_METHODS = /* @__PURE__ */ new Set([
|
|
6523
6970
|
// Array
|
|
6524
6971
|
"push",
|
|
@@ -6538,10 +6985,10 @@ var MUTATING_METHODS = /* @__PURE__ */ new Set([
|
|
|
6538
6985
|
// Object-ish escape hatches
|
|
6539
6986
|
"assign"
|
|
6540
6987
|
]);
|
|
6541
|
-
var
|
|
6542
|
-
|
|
6543
|
-
|
|
6544
|
-
|
|
6988
|
+
var FUNCTION_TYPES5 = /* @__PURE__ */ new Set([
|
|
6989
|
+
import_utils45.AST_NODE_TYPES.FunctionDeclaration,
|
|
6990
|
+
import_utils45.AST_NODE_TYPES.FunctionExpression,
|
|
6991
|
+
import_utils45.AST_NODE_TYPES.ArrowFunctionExpression
|
|
6545
6992
|
]);
|
|
6546
6993
|
var COLLECTION_CONSTRUCTORS = /* @__PURE__ */ new Set(["Set", "Map"]);
|
|
6547
6994
|
function isIgnoredFile3(filename, sourceText) {
|
|
@@ -6550,17 +6997,18 @@ function isIgnoredFile3(filename, sourceText) {
|
|
|
6550
6997
|
}
|
|
6551
6998
|
return /@generated\b/.test(sourceText.slice(0, 1024));
|
|
6552
6999
|
}
|
|
6553
|
-
function
|
|
6554
|
-
return
|
|
7000
|
+
function isLocalFixtureFile(filename) {
|
|
7001
|
+
return isTestFile(filename) || isStoryFile(filename);
|
|
6555
7002
|
}
|
|
6556
7003
|
function unwrap4(node) {
|
|
6557
|
-
if (node.type ===
|
|
7004
|
+
if (node.type === import_utils45.AST_NODE_TYPES.TSAsExpression || node.type === import_utils45.AST_NODE_TYPES.TSSatisfiesExpression || node.type === import_utils45.AST_NODE_TYPES.TSNonNullExpression) {
|
|
6558
7005
|
return unwrap4(node.expression);
|
|
6559
7006
|
}
|
|
6560
7007
|
return node;
|
|
6561
7008
|
}
|
|
7009
|
+
var HAS_STATEFUL_FLAG_RE = /[gy]/;
|
|
6562
7010
|
function isRegexLiteral(node) {
|
|
6563
|
-
return node.type ===
|
|
7011
|
+
return node.type === import_utils45.AST_NODE_TYPES.Literal && "regex" in node && node.regex !== void 0;
|
|
6564
7012
|
}
|
|
6565
7013
|
function isLiteralOnly(node, depth) {
|
|
6566
7014
|
if (depth > MAX_LITERAL_DEPTH) {
|
|
@@ -6568,29 +7016,29 @@ function isLiteralOnly(node, depth) {
|
|
|
6568
7016
|
}
|
|
6569
7017
|
const inner = unwrap4(node);
|
|
6570
7018
|
switch (inner.type) {
|
|
6571
|
-
case
|
|
6572
|
-
return
|
|
7019
|
+
case import_utils45.AST_NODE_TYPES.Literal: {
|
|
7020
|
+
return !(isRegexLiteral(inner) && HAS_STATEFUL_FLAG_RE.test(inner.regex.flags));
|
|
6573
7021
|
}
|
|
6574
|
-
case
|
|
7022
|
+
case import_utils45.AST_NODE_TYPES.TemplateLiteral: {
|
|
6575
7023
|
return inner.expressions.length === 0;
|
|
6576
7024
|
}
|
|
6577
|
-
case
|
|
6578
|
-
return (inner.operator === "-" || inner.operator === "+") && inner.argument.type ===
|
|
7025
|
+
case import_utils45.AST_NODE_TYPES.UnaryExpression: {
|
|
7026
|
+
return (inner.operator === "-" || inner.operator === "+") && inner.argument.type === import_utils45.AST_NODE_TYPES.Literal && typeof inner.argument.value === "number";
|
|
6579
7027
|
}
|
|
6580
|
-
case
|
|
7028
|
+
case import_utils45.AST_NODE_TYPES.ArrayExpression: {
|
|
6581
7029
|
return inner.elements.every(
|
|
6582
|
-
(el) => el !== null && el.type !==
|
|
7030
|
+
(el) => el !== null && el.type !== import_utils45.AST_NODE_TYPES.SpreadElement && isLiteralOnly(el, depth + 1)
|
|
6583
7031
|
);
|
|
6584
7032
|
}
|
|
6585
|
-
case
|
|
7033
|
+
case import_utils45.AST_NODE_TYPES.ObjectExpression: {
|
|
6586
7034
|
return inner.properties.every((prop) => {
|
|
6587
|
-
if (prop.type !==
|
|
7035
|
+
if (prop.type !== import_utils45.AST_NODE_TYPES.Property) {
|
|
6588
7036
|
return false;
|
|
6589
7037
|
}
|
|
6590
7038
|
if (prop.shorthand || prop.method || prop.kind !== "init") {
|
|
6591
7039
|
return false;
|
|
6592
7040
|
}
|
|
6593
|
-
if (prop.computed && prop.key.type !==
|
|
7041
|
+
if (prop.computed && prop.key.type !== import_utils45.AST_NODE_TYPES.Literal) {
|
|
6594
7042
|
return false;
|
|
6595
7043
|
}
|
|
6596
7044
|
return isLiteralOnly(prop.value, depth + 1);
|
|
@@ -6603,7 +7051,7 @@ function isLiteralOnly(node, depth) {
|
|
|
6603
7051
|
}
|
|
6604
7052
|
function unwrapObjectFreeze(node) {
|
|
6605
7053
|
const inner = unwrap4(node);
|
|
6606
|
-
if (inner.type ===
|
|
7054
|
+
if (inner.type === import_utils45.AST_NODE_TYPES.CallExpression && inner.callee.type === import_utils45.AST_NODE_TYPES.MemberExpression && !inner.callee.computed && inner.callee.object.type === import_utils45.AST_NODE_TYPES.Identifier && inner.callee.object.name === "Object" && inner.callee.property.type === import_utils45.AST_NODE_TYPES.Identifier && inner.callee.property.name === "freeze" && inner.arguments.length === 1 && inner.arguments[0] !== void 0 && inner.arguments[0].type !== import_utils45.AST_NODE_TYPES.SpreadElement) {
|
|
6607
7055
|
return unwrap4(inner.arguments[0]);
|
|
6608
7056
|
}
|
|
6609
7057
|
return inner;
|
|
@@ -6614,24 +7062,24 @@ function classify(init, checkRegex) {
|
|
|
6614
7062
|
if (!checkRegex) {
|
|
6615
7063
|
return null;
|
|
6616
7064
|
}
|
|
6617
|
-
if (
|
|
7065
|
+
if (HAS_STATEFUL_FLAG_RE.test(node.regex.flags)) {
|
|
6618
7066
|
return null;
|
|
6619
7067
|
}
|
|
6620
7068
|
return { kind: "regex", size: 1 };
|
|
6621
7069
|
}
|
|
6622
|
-
if (node.type ===
|
|
7070
|
+
if (node.type === import_utils45.AST_NODE_TYPES.ArrayExpression) {
|
|
6623
7071
|
return isLiteralOnly(node, 0) ? { kind: "array", size: node.elements.length } : null;
|
|
6624
7072
|
}
|
|
6625
|
-
if (node.type ===
|
|
7073
|
+
if (node.type === import_utils45.AST_NODE_TYPES.ObjectExpression) {
|
|
6626
7074
|
return isLiteralOnly(node, 0) ? { kind: "object", size: node.properties.length } : null;
|
|
6627
7075
|
}
|
|
6628
|
-
if (node.type ===
|
|
7076
|
+
if (node.type === import_utils45.AST_NODE_TYPES.NewExpression && node.callee.type === import_utils45.AST_NODE_TYPES.Identifier && COLLECTION_CONSTRUCTORS.has(node.callee.name)) {
|
|
6629
7077
|
const arg = node.arguments[0];
|
|
6630
|
-
if (node.arguments.length !== 1 || arg === void 0 || arg.type ===
|
|
7078
|
+
if (node.arguments.length !== 1 || arg === void 0 || arg.type === import_utils45.AST_NODE_TYPES.SpreadElement) {
|
|
6631
7079
|
return null;
|
|
6632
7080
|
}
|
|
6633
7081
|
const entries = unwrap4(arg);
|
|
6634
|
-
if (entries.type !==
|
|
7082
|
+
if (entries.type !== import_utils45.AST_NODE_TYPES.ArrayExpression) {
|
|
6635
7083
|
return null;
|
|
6636
7084
|
}
|
|
6637
7085
|
return isLiteralOnly(entries, 0) ? { kind: node.callee.name === "Set" ? "Set" : "Map", size: entries.elements.length } : null;
|
|
@@ -6641,7 +7089,7 @@ function classify(init, checkRegex) {
|
|
|
6641
7089
|
function enclosingFunction2(node) {
|
|
6642
7090
|
let current = node.parent;
|
|
6643
7091
|
while (current !== void 0 && current !== null) {
|
|
6644
|
-
if (
|
|
7092
|
+
if (FUNCTION_TYPES5.has(current.type)) {
|
|
6645
7093
|
return current;
|
|
6646
7094
|
}
|
|
6647
7095
|
current = current.parent;
|
|
@@ -6660,10 +7108,10 @@ var NON_RETAINING_BUILTINS = /* @__PURE__ */ new Map(
|
|
|
6660
7108
|
);
|
|
6661
7109
|
function isNonRetainingBuiltinCall(node, argument) {
|
|
6662
7110
|
const callee = node.callee;
|
|
6663
|
-
if (callee.type ===
|
|
7111
|
+
if (callee.type === import_utils45.AST_NODE_TYPES.Identifier && callee.name === "structuredClone") {
|
|
6664
7112
|
return true;
|
|
6665
7113
|
}
|
|
6666
|
-
if (callee.type !==
|
|
7114
|
+
if (callee.type !== import_utils45.AST_NODE_TYPES.MemberExpression || callee.computed || callee.object.type !== import_utils45.AST_NODE_TYPES.Identifier || callee.property.type !== import_utils45.AST_NODE_TYPES.Identifier) {
|
|
6667
7115
|
return false;
|
|
6668
7116
|
}
|
|
6669
7117
|
const members = NON_RETAINING_BUILTINS.get(callee.object.name);
|
|
@@ -6677,43 +7125,43 @@ function isNonRetainingBuiltinCall(node, argument) {
|
|
|
6677
7125
|
}
|
|
6678
7126
|
function isSafeRead(identifier) {
|
|
6679
7127
|
const parent = identifier.parent;
|
|
6680
|
-
if (parent.type ===
|
|
7128
|
+
if (parent.type === import_utils45.AST_NODE_TYPES.MemberExpression) {
|
|
6681
7129
|
if (parent.object !== identifier) {
|
|
6682
7130
|
return true;
|
|
6683
7131
|
}
|
|
6684
7132
|
const grandparent = parent.parent;
|
|
6685
|
-
if (grandparent.type ===
|
|
7133
|
+
if (grandparent.type === import_utils45.AST_NODE_TYPES.AssignmentExpression && grandparent.left === parent) {
|
|
6686
7134
|
return false;
|
|
6687
7135
|
}
|
|
6688
|
-
if (grandparent.type ===
|
|
7136
|
+
if (grandparent.type === import_utils45.AST_NODE_TYPES.UpdateExpression) {
|
|
6689
7137
|
return false;
|
|
6690
7138
|
}
|
|
6691
|
-
if (grandparent.type ===
|
|
7139
|
+
if (grandparent.type === import_utils45.AST_NODE_TYPES.UnaryExpression && grandparent.operator === "delete") {
|
|
6692
7140
|
return false;
|
|
6693
7141
|
}
|
|
6694
|
-
if (!parent.computed && parent.property.type ===
|
|
7142
|
+
if (!parent.computed && parent.property.type === import_utils45.AST_NODE_TYPES.Identifier && MUTATING_METHODS.has(parent.property.name) && grandparent.type === import_utils45.AST_NODE_TYPES.CallExpression && grandparent.callee === parent) {
|
|
6695
7143
|
return false;
|
|
6696
7144
|
}
|
|
6697
7145
|
return true;
|
|
6698
7146
|
}
|
|
6699
|
-
if (parent.type ===
|
|
7147
|
+
if (parent.type === import_utils45.AST_NODE_TYPES.ForOfStatement && parent.right === identifier) {
|
|
6700
7148
|
return true;
|
|
6701
7149
|
}
|
|
6702
|
-
if (parent.type ===
|
|
7150
|
+
if (parent.type === import_utils45.AST_NODE_TYPES.SpreadElement) {
|
|
6703
7151
|
return true;
|
|
6704
7152
|
}
|
|
6705
|
-
if (parent.type ===
|
|
7153
|
+
if (parent.type === import_utils45.AST_NODE_TYPES.BinaryExpression) {
|
|
6706
7154
|
return true;
|
|
6707
7155
|
}
|
|
6708
|
-
if (parent.type ===
|
|
7156
|
+
if (parent.type === import_utils45.AST_NODE_TYPES.CallExpression && parent.arguments.includes(identifier) && isNonRetainingBuiltinCall(parent, identifier)) {
|
|
6709
7157
|
return true;
|
|
6710
7158
|
}
|
|
6711
|
-
if (parent.type ===
|
|
7159
|
+
if (parent.type === import_utils45.AST_NODE_TYPES.UnaryExpression && parent.operator !== "delete") {
|
|
6712
7160
|
return true;
|
|
6713
7161
|
}
|
|
6714
7162
|
return false;
|
|
6715
7163
|
}
|
|
6716
|
-
var prefer_module_level_constant_default =
|
|
7164
|
+
var prefer_module_level_constant_default = import_utils45.ESLintUtils.RuleCreator(
|
|
6717
7165
|
(name) => `https://github.com/sarj-ai/linting/blob/main/packages/typescript/src/rules/${name}.ts`
|
|
6718
7166
|
)({
|
|
6719
7167
|
name: "prefer-module-level-constant",
|
|
@@ -6749,7 +7197,7 @@ var prefer_module_level_constant_default = import_utils46.ESLintUtils.RuleCreato
|
|
|
6749
7197
|
if (isIgnoredFile3(filename, sourceCode.getText())) {
|
|
6750
7198
|
return {};
|
|
6751
7199
|
}
|
|
6752
|
-
if (ignoreTestFiles &&
|
|
7200
|
+
if (ignoreTestFiles && isLocalFixtureFile(filename)) {
|
|
6753
7201
|
return {};
|
|
6754
7202
|
}
|
|
6755
7203
|
function allReferencesAreSafeReads(declarator) {
|
|
@@ -6765,7 +7213,7 @@ var prefer_module_level_constant_default = import_utils46.ESLintUtils.RuleCreato
|
|
|
6765
7213
|
if (reference.isWrite()) {
|
|
6766
7214
|
return false;
|
|
6767
7215
|
}
|
|
6768
|
-
if (reference.identifier.type !==
|
|
7216
|
+
if (reference.identifier.type !== import_utils45.AST_NODE_TYPES.Identifier) {
|
|
6769
7217
|
return false;
|
|
6770
7218
|
}
|
|
6771
7219
|
if (!isSafeRead(reference.identifier)) {
|
|
@@ -6777,10 +7225,10 @@ var prefer_module_level_constant_default = import_utils46.ESLintUtils.RuleCreato
|
|
|
6777
7225
|
return {
|
|
6778
7226
|
VariableDeclarator(node) {
|
|
6779
7227
|
const declaration = node.parent;
|
|
6780
|
-
if (declaration.type !==
|
|
7228
|
+
if (declaration.type !== import_utils45.AST_NODE_TYPES.VariableDeclaration || declaration.kind !== "const" || declaration.declare === true) {
|
|
6781
7229
|
return;
|
|
6782
7230
|
}
|
|
6783
|
-
if (node.id.type !==
|
|
7231
|
+
if (node.id.type !== import_utils45.AST_NODE_TYPES.Identifier || node.init === null) {
|
|
6784
7232
|
return;
|
|
6785
7233
|
}
|
|
6786
7234
|
if (enclosingFunction2(node) === null) {
|
|
@@ -6807,7 +7255,7 @@ var prefer_module_level_constant_default = import_utils46.ESLintUtils.RuleCreato
|
|
|
6807
7255
|
});
|
|
6808
7256
|
|
|
6809
7257
|
// src/rules/jsdoc-restates-signature.ts
|
|
6810
|
-
var
|
|
7258
|
+
var import_utils46 = require("@typescript-eslint/utils");
|
|
6811
7259
|
var VALUE_TAGS = /* @__PURE__ */ new Set([
|
|
6812
7260
|
"alpha",
|
|
6813
7261
|
"author",
|
|
@@ -6890,30 +7338,30 @@ function declarationNames(node) {
|
|
|
6890
7338
|
switch (node.type) {
|
|
6891
7339
|
// `export function f()` — the JSDoc sits above the `export`, so the token
|
|
6892
7340
|
// after it resolves to the wrapper, not to the thing being documented.
|
|
6893
|
-
case
|
|
6894
|
-
case
|
|
7341
|
+
case import_utils46.AST_NODE_TYPES.ExportNamedDeclaration:
|
|
7342
|
+
case import_utils46.AST_NODE_TYPES.ExportDefaultDeclaration:
|
|
6895
7343
|
return node.declaration == null ? null : declarationNames(node.declaration);
|
|
6896
|
-
case
|
|
6897
|
-
case
|
|
7344
|
+
case import_utils46.AST_NODE_TYPES.FunctionDeclaration:
|
|
7345
|
+
case import_utils46.AST_NODE_TYPES.TSDeclareFunction:
|
|
6898
7346
|
return node.id === null ? null : { name: node.id.name, params: paramNames(node.params) };
|
|
6899
|
-
case
|
|
6900
|
-
case
|
|
6901
|
-
case
|
|
6902
|
-
case
|
|
7347
|
+
case import_utils46.AST_NODE_TYPES.ClassDeclaration:
|
|
7348
|
+
case import_utils46.AST_NODE_TYPES.TSInterfaceDeclaration:
|
|
7349
|
+
case import_utils46.AST_NODE_TYPES.TSTypeAliasDeclaration:
|
|
7350
|
+
case import_utils46.AST_NODE_TYPES.TSEnumDeclaration:
|
|
6903
7351
|
return node.id === null ? null : { name: node.id.name, params: [] };
|
|
6904
|
-
case
|
|
7352
|
+
case import_utils46.AST_NODE_TYPES.VariableDeclaration: {
|
|
6905
7353
|
const declarator = node.declarations[0];
|
|
6906
|
-
if (declarator === void 0 || declarator.id.type !==
|
|
7354
|
+
if (declarator === void 0 || declarator.id.type !== import_utils46.AST_NODE_TYPES.Identifier) return null;
|
|
6907
7355
|
const init = declarator.init;
|
|
6908
|
-
const params = init != null && (init.type ===
|
|
7356
|
+
const params = init != null && (init.type === import_utils46.AST_NODE_TYPES.ArrowFunctionExpression || init.type === import_utils46.AST_NODE_TYPES.FunctionExpression) ? paramNames(init.params) : [];
|
|
6909
7357
|
return { name: declarator.id.name, params };
|
|
6910
7358
|
}
|
|
6911
|
-
case
|
|
6912
|
-
case
|
|
6913
|
-
case
|
|
6914
|
-
case
|
|
6915
|
-
if (node.key.type !==
|
|
6916
|
-
const params = node.type ===
|
|
7359
|
+
case import_utils46.AST_NODE_TYPES.MethodDefinition:
|
|
7360
|
+
case import_utils46.AST_NODE_TYPES.PropertyDefinition:
|
|
7361
|
+
case import_utils46.AST_NODE_TYPES.TSMethodSignature:
|
|
7362
|
+
case import_utils46.AST_NODE_TYPES.TSPropertySignature: {
|
|
7363
|
+
if (node.key.type !== import_utils46.AST_NODE_TYPES.Identifier) return null;
|
|
7364
|
+
const params = node.type === import_utils46.AST_NODE_TYPES.MethodDefinition ? paramNames(node.value.params) : node.type === import_utils46.AST_NODE_TYPES.TSMethodSignature ? paramNames(node.params) : [];
|
|
6917
7365
|
return { name: node.key.name, params };
|
|
6918
7366
|
}
|
|
6919
7367
|
default:
|
|
@@ -6923,9 +7371,9 @@ function declarationNames(node) {
|
|
|
6923
7371
|
function paramNames(params) {
|
|
6924
7372
|
const names = [];
|
|
6925
7373
|
for (const param of params) {
|
|
6926
|
-
const target = param.type ===
|
|
6927
|
-
if (target.type ===
|
|
6928
|
-
else if (target.type ===
|
|
7374
|
+
const target = param.type === import_utils46.AST_NODE_TYPES.AssignmentPattern ? param.left : param;
|
|
7375
|
+
if (target.type === import_utils46.AST_NODE_TYPES.Identifier) names.push(target.name);
|
|
7376
|
+
else if (target.type === import_utils46.AST_NODE_TYPES.TSParameterProperty) continue;
|
|
6929
7377
|
}
|
|
6930
7378
|
return names;
|
|
6931
7379
|
}
|
|
@@ -6934,7 +7382,7 @@ function tokensOf(names) {
|
|
|
6934
7382
|
for (const name of names) for (const part of splitIdentifier(name)) tokens.add(part);
|
|
6935
7383
|
return tokens;
|
|
6936
7384
|
}
|
|
6937
|
-
var jsdoc_restates_signature_default =
|
|
7385
|
+
var jsdoc_restates_signature_default = import_utils46.ESLintUtils.RuleCreator(
|
|
6938
7386
|
(name) => `https://github.com/sarj-ai/standards/blob/main/packages/typescript/src/rules/${name}.ts`
|
|
6939
7387
|
)({
|
|
6940
7388
|
name: "jsdoc-restates-signature",
|
|
@@ -6970,7 +7418,7 @@ var jsdoc_restates_signature_default = import_utils47.ESLintUtils.RuleCreator(
|
|
|
6970
7418
|
if (token === null || token.loc.start.line !== comment.loc.end.line + 1) continue;
|
|
6971
7419
|
let node = sourceCode.getNodeByRangeIndex(token.range[0]);
|
|
6972
7420
|
let declaration = null;
|
|
6973
|
-
while (node != null && node.type !==
|
|
7421
|
+
while (node != null && node.type !== import_utils46.AST_NODE_TYPES.Program) {
|
|
6974
7422
|
declaration = declarationNames(node);
|
|
6975
7423
|
if (declaration !== null) break;
|
|
6976
7424
|
node = node.parent ?? null;
|
|
@@ -7025,7 +7473,7 @@ var jsdoc_restates_signature_default = import_utils47.ESLintUtils.RuleCreator(
|
|
|
7025
7473
|
});
|
|
7026
7474
|
|
|
7027
7475
|
// src/rules/no-restated-comment.ts
|
|
7028
|
-
var
|
|
7476
|
+
var import_utils47 = require("@typescript-eslint/utils");
|
|
7029
7477
|
var MAX_WORDS = 8;
|
|
7030
7478
|
var MIN_CONTENT_TOKENS = 2;
|
|
7031
7479
|
var DIRECTIVE_RE3 = /^(eslint\b|eslint-|sarj-noqa\b|@ts-|prettier-ignore|prettier\b|biome-|c8\b|v8\b|istanbul\b|@type\b|@vite|webpack|<reference|<amd|global\b|noinspection|todo\b|fixme\b|hack\b|xxx\b)/i;
|
|
@@ -7049,7 +7497,7 @@ function headsSiblingRun(node) {
|
|
|
7049
7497
|
const next = index >= 0 ? body[index + 1] : void 0;
|
|
7050
7498
|
return next !== void 0 && next.type === node.type;
|
|
7051
7499
|
}
|
|
7052
|
-
var no_restated_comment_default =
|
|
7500
|
+
var no_restated_comment_default = import_utils47.ESLintUtils.RuleCreator(
|
|
7053
7501
|
(name) => `https://github.com/sarj-ai/standards/blob/main/packages/typescript/src/rules/${name}.ts`
|
|
7054
7502
|
)({
|
|
7055
7503
|
name: "no-restated-comment",
|
|
@@ -7077,7 +7525,7 @@ var no_restated_comment_default = import_utils48.ESLintUtils.RuleCreator(
|
|
|
7077
7525
|
function labelsASiblingRun(comment) {
|
|
7078
7526
|
const token = sourceCode.getTokenAfter(comment, { includeComments: false });
|
|
7079
7527
|
if (token === null) return false;
|
|
7080
|
-
for (let node = sourceCode.getNodeByRangeIndex(token.range[0]); node != null && node.type !==
|
|
7528
|
+
for (let node = sourceCode.getNodeByRangeIndex(token.range[0]); node != null && node.type !== import_utils47.AST_NODE_TYPES.Program; node = node.parent) {
|
|
7081
7529
|
if (headsSiblingRun(node)) return true;
|
|
7082
7530
|
}
|
|
7083
7531
|
return false;
|
|
@@ -7117,7 +7565,7 @@ var no_restated_comment_default = import_utils48.ESLintUtils.RuleCreator(
|
|
|
7117
7565
|
});
|
|
7118
7566
|
|
|
7119
7567
|
// src/rules/trailing-value-narration.ts
|
|
7120
|
-
var
|
|
7568
|
+
var import_utils48 = require("@typescript-eslint/utils");
|
|
7121
7569
|
var NUMBER_RE = /(?<![\w.])(\d+(?:\.\d+)?)(?![\w.])/g;
|
|
7122
7570
|
var WORD_RE3 = /[A-Za-z]+(?:'[a-z]+)?|\d+(?:\.\d+)?/g;
|
|
7123
7571
|
var UNIT_WORDS = /* @__PURE__ */ new Set([
|
|
@@ -7201,7 +7649,7 @@ function narratesValue(body, code) {
|
|
|
7201
7649
|
(word) => STOPWORDS3.has(word) || UNIT_WORDS.has(word) || commentNumbers.has(word) || identifiers.has(word) || stems.has(stem(word))
|
|
7202
7650
|
);
|
|
7203
7651
|
}
|
|
7204
|
-
var trailing_value_narration_default =
|
|
7652
|
+
var trailing_value_narration_default = import_utils48.ESLintUtils.RuleCreator(
|
|
7205
7653
|
(name) => `https://github.com/sarj-ai/standards/blob/main/packages/typescript/src/rules/${name}.ts`
|
|
7206
7654
|
)({
|
|
7207
7655
|
name: "trailing-value-narration",
|
|
@@ -7242,7 +7690,7 @@ var trailing_value_narration_default = import_utils49.ESLintUtils.RuleCreator(
|
|
|
7242
7690
|
});
|
|
7243
7691
|
|
|
7244
7692
|
// src/rules/no-tautological-expect.ts
|
|
7245
|
-
var
|
|
7693
|
+
var import_utils49 = require("@typescript-eslint/utils");
|
|
7246
7694
|
var EQUALITY_MATCHERS = /* @__PURE__ */ new Set(["toBe", "toEqual", "toStrictEqual"]);
|
|
7247
7695
|
var ZERO_ARG_MATCHERS = /* @__PURE__ */ new Set([
|
|
7248
7696
|
"toBeDefined",
|
|
@@ -7256,17 +7704,17 @@ var OPERAND_PREVIEW_CHARS = 40;
|
|
|
7256
7704
|
var NUMERIC_SIGNS = /* @__PURE__ */ new Set(["-", "+"]);
|
|
7257
7705
|
function isLiteral(node) {
|
|
7258
7706
|
switch (node.type) {
|
|
7259
|
-
case
|
|
7707
|
+
case import_utils49.AST_NODE_TYPES.Literal:
|
|
7260
7708
|
return true;
|
|
7261
|
-
case
|
|
7709
|
+
case import_utils49.AST_NODE_TYPES.TemplateLiteral:
|
|
7262
7710
|
return node.expressions.length === 0;
|
|
7263
|
-
case
|
|
7711
|
+
case import_utils49.AST_NODE_TYPES.UnaryExpression:
|
|
7264
7712
|
return NUMERIC_SIGNS.has(node.operator) && isLiteral(node.argument);
|
|
7265
|
-
case
|
|
7713
|
+
case import_utils49.AST_NODE_TYPES.ArrayExpression:
|
|
7266
7714
|
return node.elements.every((element) => element !== null && isLiteral(element));
|
|
7267
|
-
case
|
|
7715
|
+
case import_utils49.AST_NODE_TYPES.ObjectExpression:
|
|
7268
7716
|
return node.properties.every(
|
|
7269
|
-
(property) => property.type ===
|
|
7717
|
+
(property) => property.type === import_utils49.AST_NODE_TYPES.Property && !property.computed && isLiteral(property.value)
|
|
7270
7718
|
);
|
|
7271
7719
|
default:
|
|
7272
7720
|
return false;
|
|
@@ -7274,12 +7722,12 @@ function isLiteral(node) {
|
|
|
7274
7722
|
}
|
|
7275
7723
|
function expectOperand(callee) {
|
|
7276
7724
|
const receiver = callee.object;
|
|
7277
|
-
if (receiver.type !==
|
|
7725
|
+
if (receiver.type !== import_utils49.AST_NODE_TYPES.CallExpression || receiver.callee.type !== import_utils49.AST_NODE_TYPES.Identifier || receiver.callee.name !== "expect" || receiver.arguments.length !== 1) {
|
|
7278
7726
|
return null;
|
|
7279
7727
|
}
|
|
7280
7728
|
return receiver.arguments[0] ?? null;
|
|
7281
7729
|
}
|
|
7282
|
-
var no_tautological_expect_default =
|
|
7730
|
+
var no_tautological_expect_default = import_utils49.ESLintUtils.RuleCreator(
|
|
7283
7731
|
(name) => `https://github.com/sarj-ai/standards/blob/main/packages/typescript/src/rules/${name}.ts`
|
|
7284
7732
|
)({
|
|
7285
7733
|
name: "no-tautological-expect",
|
|
@@ -7306,10 +7754,10 @@ var no_tautological_expect_default = import_utils50.ESLintUtils.RuleCreator(
|
|
|
7306
7754
|
return {
|
|
7307
7755
|
CallExpression(node) {
|
|
7308
7756
|
const callee = node.callee;
|
|
7309
|
-
if (callee.type !==
|
|
7757
|
+
if (callee.type !== import_utils49.AST_NODE_TYPES.MemberExpression || callee.computed) {
|
|
7310
7758
|
return;
|
|
7311
7759
|
}
|
|
7312
|
-
if (callee.property.type !==
|
|
7760
|
+
if (callee.property.type !== import_utils49.AST_NODE_TYPES.Identifier) {
|
|
7313
7761
|
return;
|
|
7314
7762
|
}
|
|
7315
7763
|
const matcher = callee.property.name;
|
|
@@ -7343,26 +7791,26 @@ var no_tautological_expect_default = import_utils50.ESLintUtils.RuleCreator(
|
|
|
7343
7791
|
});
|
|
7344
7792
|
|
|
7345
7793
|
// src/rules/require-interface-for-injected-service.ts
|
|
7346
|
-
var
|
|
7794
|
+
var import_utils50 = require("@typescript-eslint/utils");
|
|
7347
7795
|
var CONFIGISH_TYPE_RE = /(?:Options|Opts|Config|Configuration|Settings|Params|Props|Args|Env|Environment|Callbacks|Flags)$/;
|
|
7348
7796
|
var CONFIGISH_NAME_RE = /^(?:options|opts|config|configuration|settings|params|props|args|env|environment|callbacks|flags|logger|log|clock)$/i;
|
|
7349
7797
|
var HTTP_TRANSPORT_TYPE_RE = /^(?:KyInstance|AxiosInstance|Session)$/;
|
|
7350
7798
|
var TRANSPORT_WRAPPER_NAME_RE = /Client$/;
|
|
7351
7799
|
var ROUTER_FACTORY_NAME = "Router";
|
|
7352
7800
|
var FRAMEWORK_HTTP_TYPES = /* @__PURE__ */ new Set(["Request", "Response", "NextFunction"]);
|
|
7353
|
-
var isExportedClass = (node) => node.parent.type ===
|
|
7354
|
-
var qualifiedName = (name) => name.type ===
|
|
7801
|
+
var isExportedClass = (node) => node.parent.type === import_utils50.AST_NODE_TYPES.ExportNamedDeclaration || node.parent.type === import_utils50.AST_NODE_TYPES.ExportDefaultDeclaration;
|
|
7802
|
+
var qualifiedName = (name) => name.type === import_utils50.AST_NODE_TYPES.Identifier ? name.name : name.type === import_utils50.AST_NODE_TYPES.TSQualifiedName ? `${qualifiedName(name.left)}.${name.right.name}` : "";
|
|
7355
7803
|
var typeReferenceName = (annotated) => {
|
|
7356
7804
|
let target = annotated;
|
|
7357
|
-
if (target.type ===
|
|
7358
|
-
if (target.type ===
|
|
7359
|
-
if (target.type !==
|
|
7805
|
+
if (target.type === import_utils50.AST_NODE_TYPES.TSParameterProperty) target = target.parameter;
|
|
7806
|
+
if (target.type === import_utils50.AST_NODE_TYPES.AssignmentPattern) target = target.left;
|
|
7807
|
+
if (target.type !== import_utils50.AST_NODE_TYPES.Identifier) return null;
|
|
7360
7808
|
const annotation = target.typeAnnotation?.typeAnnotation;
|
|
7361
|
-
if (annotation === void 0 || annotation.type !==
|
|
7809
|
+
if (annotation === void 0 || annotation.type !== import_utils50.AST_NODE_TYPES.TSTypeReference) {
|
|
7362
7810
|
return null;
|
|
7363
7811
|
}
|
|
7364
7812
|
const { typeName } = annotation;
|
|
7365
|
-
const rightmost = typeName.type ===
|
|
7813
|
+
const rightmost = typeName.type === import_utils50.AST_NODE_TYPES.Identifier ? typeName.name : typeName.type === import_utils50.AST_NODE_TYPES.TSQualifiedName ? typeName.right.name : null;
|
|
7366
7814
|
if (rightmost === null) return null;
|
|
7367
7815
|
return { name: target.name, typeName: rightmost, display: qualifiedName(typeName) };
|
|
7368
7816
|
};
|
|
@@ -7372,17 +7820,17 @@ var readConstructor = (ctor) => {
|
|
|
7372
7820
|
let constructedFields = 0;
|
|
7373
7821
|
if (body !== null && body !== void 0) {
|
|
7374
7822
|
for (const statement of body.body) {
|
|
7375
|
-
if (statement.type !==
|
|
7823
|
+
if (statement.type !== import_utils50.AST_NODE_TYPES.ExpressionStatement) continue;
|
|
7376
7824
|
const expression = statement.expression;
|
|
7377
|
-
if (expression.type !==
|
|
7825
|
+
if (expression.type !== import_utils50.AST_NODE_TYPES.AssignmentExpression || expression.operator !== "=" || expression.left.type !== import_utils50.AST_NODE_TYPES.MemberExpression || expression.left.object.type !== import_utils50.AST_NODE_TYPES.ThisExpression) {
|
|
7378
7826
|
continue;
|
|
7379
7827
|
}
|
|
7380
7828
|
const source = expression.right;
|
|
7381
|
-
if (source.type ===
|
|
7829
|
+
if (source.type === import_utils50.AST_NODE_TYPES.NewExpression) {
|
|
7382
7830
|
constructedFields += 1;
|
|
7383
|
-
} else if (source.type ===
|
|
7831
|
+
} else if (source.type === import_utils50.AST_NODE_TYPES.Identifier) {
|
|
7384
7832
|
storedFrom.add(source.name);
|
|
7385
|
-
} else if (source.type ===
|
|
7833
|
+
} else if (source.type === import_utils50.AST_NODE_TYPES.MemberExpression && source.object.type === import_utils50.AST_NODE_TYPES.Identifier) {
|
|
7386
7834
|
storedFrom.add(source.object.name);
|
|
7387
7835
|
}
|
|
7388
7836
|
}
|
|
@@ -7391,7 +7839,7 @@ var readConstructor = (ctor) => {
|
|
|
7391
7839
|
for (const parameter of ctor.value.params) {
|
|
7392
7840
|
const reference = typeReferenceName(parameter);
|
|
7393
7841
|
if (reference === null) continue;
|
|
7394
|
-
const stored = parameter.type ===
|
|
7842
|
+
const stored = parameter.type === import_utils50.AST_NODE_TYPES.TSParameterProperty || storedFrom.has(reference.name);
|
|
7395
7843
|
if (!stored) continue;
|
|
7396
7844
|
if (CONFIGISH_TYPE_RE.test(reference.typeName)) continue;
|
|
7397
7845
|
if (CONFIGISH_NAME_RE.test(reference.name)) continue;
|
|
@@ -7421,19 +7869,19 @@ var subtreeHas = (root, found) => {
|
|
|
7421
7869
|
return hit;
|
|
7422
7870
|
};
|
|
7423
7871
|
var isFrameworkWiring = (body) => subtreeHas(body, (node) => {
|
|
7424
|
-
if (node.type ===
|
|
7872
|
+
if (node.type === import_utils50.AST_NODE_TYPES.CallExpression) {
|
|
7425
7873
|
const { callee } = node;
|
|
7426
|
-
if (callee.type ===
|
|
7427
|
-
return callee.type ===
|
|
7874
|
+
if (callee.type === import_utils50.AST_NODE_TYPES.Identifier) return callee.name === ROUTER_FACTORY_NAME;
|
|
7875
|
+
return callee.type === import_utils50.AST_NODE_TYPES.MemberExpression && !callee.computed && callee.property.type === import_utils50.AST_NODE_TYPES.Identifier && callee.property.name === ROUTER_FACTORY_NAME;
|
|
7428
7876
|
}
|
|
7429
|
-
return node.type ===
|
|
7877
|
+
return node.type === import_utils50.AST_NODE_TYPES.TSTypeReference && node.typeName.type === import_utils50.AST_NODE_TYPES.TSQualifiedName && FRAMEWORK_HTTP_TYPES.has(node.typeName.right.name);
|
|
7430
7878
|
});
|
|
7431
7879
|
var stem2 = (name) => name.replace(/^I(?=[A-Z])/, "").replace(/Impl$/, "");
|
|
7432
7880
|
var fileInterfaceNames = (program) => {
|
|
7433
7881
|
const names = [];
|
|
7434
7882
|
for (const statement of program.body) {
|
|
7435
|
-
const declaration = statement.type ===
|
|
7436
|
-
if (declaration?.type ===
|
|
7883
|
+
const declaration = statement.type === import_utils50.AST_NODE_TYPES.ExportNamedDeclaration ? statement.declaration : statement;
|
|
7884
|
+
if (declaration?.type === import_utils50.AST_NODE_TYPES.TSInterfaceDeclaration) names.push(declaration.id.name);
|
|
7437
7885
|
}
|
|
7438
7886
|
return names;
|
|
7439
7887
|
};
|
|
@@ -7451,16 +7899,16 @@ var isTransportWrapper = (className, collaborators, program) => {
|
|
|
7451
7899
|
var publicMethodNames = (body) => {
|
|
7452
7900
|
const names = [];
|
|
7453
7901
|
for (const member of body.body) {
|
|
7454
|
-
if (member.type !==
|
|
7902
|
+
if (member.type !== import_utils50.AST_NODE_TYPES.MethodDefinition) continue;
|
|
7455
7903
|
if (member.kind !== "method" || member.static) continue;
|
|
7456
7904
|
if (member.accessibility === "private" || member.accessibility === "protected") continue;
|
|
7457
|
-
if (member.key.type ===
|
|
7458
|
-
if (member.key.type ===
|
|
7905
|
+
if (member.key.type === import_utils50.AST_NODE_TYPES.PrivateIdentifier) continue;
|
|
7906
|
+
if (member.key.type === import_utils50.AST_NODE_TYPES.Identifier) names.push(member.key.name);
|
|
7459
7907
|
else names.push("\u2026");
|
|
7460
7908
|
}
|
|
7461
7909
|
return names;
|
|
7462
7910
|
};
|
|
7463
|
-
var require_interface_for_injected_service_default =
|
|
7911
|
+
var require_interface_for_injected_service_default = import_utils50.ESLintUtils.RuleCreator(
|
|
7464
7912
|
(name) => `https://github.com/sarj-ai/standards/blob/main/packages/typescript/src/rules/${name}.ts`
|
|
7465
7913
|
)({
|
|
7466
7914
|
name: "require-interface-for-injected-service",
|
|
@@ -7488,7 +7936,7 @@ var require_interface_for_injected_service_default = import_utils51.ESLintUtils.
|
|
|
7488
7936
|
if (node.implements.length > 0) return;
|
|
7489
7937
|
if (node.decorators.length > 0) return;
|
|
7490
7938
|
const ctor = node.body.body.find(
|
|
7491
|
-
(member) => member.type ===
|
|
7939
|
+
(member) => member.type === import_utils50.AST_NODE_TYPES.MethodDefinition && member.kind === "constructor"
|
|
7492
7940
|
);
|
|
7493
7941
|
if (ctor === void 0) return;
|
|
7494
7942
|
const { collaborators, constructedFields } = readConstructor(ctor);
|
|
@@ -7513,26 +7961,26 @@ var require_interface_for_injected_service_default = import_utils51.ESLintUtils.
|
|
|
7513
7961
|
});
|
|
7514
7962
|
|
|
7515
7963
|
// src/rules/prefer-non-nullable-collection.ts
|
|
7516
|
-
var
|
|
7964
|
+
var import_utils51 = require("@typescript-eslint/utils");
|
|
7517
7965
|
var ARRAY_TYPE_NAMES = /* @__PURE__ */ new Set(["Array", "ReadonlyArray"]);
|
|
7518
7966
|
function propertyName(node) {
|
|
7519
7967
|
const key = node.key;
|
|
7520
|
-
if (key.type ===
|
|
7521
|
-
if (key.type ===
|
|
7968
|
+
if (key.type === import_utils51.AST_NODE_TYPES.Identifier) return key.name;
|
|
7969
|
+
if (key.type === import_utils51.AST_NODE_TYPES.Literal) return String(key.value);
|
|
7522
7970
|
return "collection";
|
|
7523
7971
|
}
|
|
7524
7972
|
function isArrayType(node) {
|
|
7525
|
-
if (node.type ===
|
|
7526
|
-
return node.type ===
|
|
7973
|
+
if (node.type === import_utils51.AST_NODE_TYPES.TSArrayType) return true;
|
|
7974
|
+
return node.type === import_utils51.AST_NODE_TYPES.TSTypeReference && node.typeName.type === import_utils51.AST_NODE_TYPES.Identifier && ARRAY_TYPE_NAMES.has(node.typeName.name);
|
|
7527
7975
|
}
|
|
7528
7976
|
function isNullishType(node) {
|
|
7529
|
-
return node.type ===
|
|
7977
|
+
return node.type === import_utils51.AST_NODE_TYPES.TSNullKeyword || node.type === import_utils51.AST_NODE_TYPES.TSUndefinedKeyword;
|
|
7530
7978
|
}
|
|
7531
7979
|
function isNullableArrayOnly(node) {
|
|
7532
7980
|
const values = node.types.filter((member) => !isNullishType(member));
|
|
7533
7981
|
return values.length > 0 && values.length < node.types.length && values.every(isArrayType);
|
|
7534
7982
|
}
|
|
7535
|
-
var prefer_non_nullable_collection_default =
|
|
7983
|
+
var prefer_non_nullable_collection_default = import_utils51.ESLintUtils.RuleCreator(
|
|
7536
7984
|
(name) => `https://github.com/sarj-ai/standards/tree/main/packages/typescript#${name}`
|
|
7537
7985
|
)({
|
|
7538
7986
|
name: "prefer-non-nullable-collection",
|
|
@@ -7555,7 +8003,7 @@ var prefer_non_nullable_collection_default = import_utils52.ESLintUtils.RuleCrea
|
|
|
7555
8003
|
function checkOptionalProperty(node) {
|
|
7556
8004
|
const annotation = node.typeAnnotation?.typeAnnotation;
|
|
7557
8005
|
if (annotation === void 0) return;
|
|
7558
|
-
if (annotation.type !==
|
|
8006
|
+
if (annotation.type !== import_utils51.AST_NODE_TYPES.TSUnionType || !isNullableArrayOnly(annotation)) {
|
|
7559
8007
|
return;
|
|
7560
8008
|
}
|
|
7561
8009
|
context.report({
|
|
@@ -7568,7 +8016,7 @@ var prefer_non_nullable_collection_default = import_utils52.ESLintUtils.RuleCrea
|
|
|
7568
8016
|
TSPropertySignature: checkOptionalProperty,
|
|
7569
8017
|
PropertyDefinition: checkOptionalProperty,
|
|
7570
8018
|
TSTypeAliasDeclaration(node) {
|
|
7571
|
-
if (node.typeAnnotation.type !==
|
|
8019
|
+
if (node.typeAnnotation.type !== import_utils51.AST_NODE_TYPES.TSUnionType) return;
|
|
7572
8020
|
if (!isNullableArrayOnly(node.typeAnnotation)) return;
|
|
7573
8021
|
context.report({
|
|
7574
8022
|
node,
|
|
@@ -7580,174 +8028,217 @@ var prefer_non_nullable_collection_default = import_utils52.ESLintUtils.RuleCrea
|
|
|
7580
8028
|
}
|
|
7581
8029
|
});
|
|
7582
8030
|
|
|
7583
|
-
// src/rules/
|
|
7584
|
-
var
|
|
7585
|
-
var
|
|
7586
|
-
|
|
7587
|
-
|
|
7588
|
-
|
|
7589
|
-
|
|
7590
|
-
|
|
7591
|
-
|
|
7592
|
-
|
|
7593
|
-
|
|
7594
|
-
|
|
7595
|
-
|
|
7596
|
-
|
|
7597
|
-
|
|
7598
|
-
|
|
7599
|
-
|
|
7600
|
-
if (node.type === import_utils53.AST_NODE_TYPES.Identifier) {
|
|
7601
|
-
return node.name;
|
|
8031
|
+
// src/rules/strict-test-assertions.ts
|
|
8032
|
+
var import_utils52 = require("@typescript-eslint/utils");
|
|
8033
|
+
var MERGEABLE_MATCHERS = /* @__PURE__ */ new Set(["toBe", "toEqual", "toStrictEqual"]);
|
|
8034
|
+
var ARRAY_MATCHERS = /* @__PURE__ */ new Set(["toEqual", "toStrictEqual"]);
|
|
8035
|
+
var COLLECTION_PROPERTIES = /* @__PURE__ */ new Set(["length", "size"]);
|
|
8036
|
+
var NUMERIC_SIGNS2 = /* @__PURE__ */ new Set(["-", "+"]);
|
|
8037
|
+
var MIN_RUN_LENGTH = 2;
|
|
8038
|
+
function literalText(node, getText) {
|
|
8039
|
+
switch (node.type) {
|
|
8040
|
+
case import_utils52.AST_NODE_TYPES.Literal:
|
|
8041
|
+
return "regex" in node ? null : getText(node);
|
|
8042
|
+
case import_utils52.AST_NODE_TYPES.TemplateLiteral:
|
|
8043
|
+
return node.expressions.length === 0 ? getText(node) : null;
|
|
8044
|
+
case import_utils52.AST_NODE_TYPES.UnaryExpression:
|
|
8045
|
+
return NUMERIC_SIGNS2.has(node.operator) && literalText(node.argument, getText) !== null ? getText(node) : null;
|
|
8046
|
+
default:
|
|
8047
|
+
return null;
|
|
7602
8048
|
}
|
|
7603
|
-
|
|
7604
|
-
|
|
8049
|
+
}
|
|
8050
|
+
function isPureReceiver(node) {
|
|
8051
|
+
switch (node.type) {
|
|
8052
|
+
case import_utils52.AST_NODE_TYPES.Identifier:
|
|
8053
|
+
case import_utils52.AST_NODE_TYPES.ThisExpression:
|
|
8054
|
+
return true;
|
|
8055
|
+
case import_utils52.AST_NODE_TYPES.MemberExpression:
|
|
8056
|
+
if (node.optional) {
|
|
8057
|
+
return false;
|
|
8058
|
+
}
|
|
8059
|
+
if (node.computed) {
|
|
8060
|
+
return node.property.type === import_utils52.AST_NODE_TYPES.Literal && isPureReceiver(node.object);
|
|
8061
|
+
}
|
|
8062
|
+
return isPureReceiver(node.object);
|
|
8063
|
+
default:
|
|
8064
|
+
return false;
|
|
7605
8065
|
}
|
|
7606
|
-
return null;
|
|
7607
8066
|
}
|
|
7608
|
-
|
|
8067
|
+
function literalIndex(node) {
|
|
8068
|
+
if (node.type !== import_utils52.AST_NODE_TYPES.Literal || typeof node.value !== "number") {
|
|
8069
|
+
return null;
|
|
8070
|
+
}
|
|
8071
|
+
return Number.isInteger(node.value) && node.value >= 0 ? node.value : null;
|
|
8072
|
+
}
|
|
8073
|
+
var strict_test_assertions_default = import_utils52.ESLintUtils.RuleCreator(
|
|
7609
8074
|
(name) => `https://github.com/sarj-ai/standards/blob/main/packages/typescript/src/rules/${name}.ts`
|
|
7610
8075
|
)({
|
|
7611
|
-
name: "
|
|
7612
|
-
meta: {
|
|
7613
|
-
type: "problem",
|
|
7614
|
-
docs: {
|
|
7615
|
-
description: "Disallow imperative dictionary access with string literals; use declarative Zod schemas."
|
|
7616
|
-
},
|
|
7617
|
-
schema: [],
|
|
7618
|
-
messages: {
|
|
7619
|
-
noImplicitAttributeAccess: "Imperative lookup for '{{key}}' \u2014 if the key is known, parse the object declaratively with a Zod schema instead."
|
|
7620
|
-
}
|
|
7621
|
-
},
|
|
7622
|
-
defaultOptions: [],
|
|
7623
|
-
create(context) {
|
|
7624
|
-
return {
|
|
7625
|
-
MemberExpression(node) {
|
|
7626
|
-
if (!node.computed) {
|
|
7627
|
-
return;
|
|
7628
|
-
}
|
|
7629
|
-
if (node.property.type === import_utils53.AST_NODE_TYPES.Literal && typeof node.property.value === "string") {
|
|
7630
|
-
const baseName = getBaseName(node.object);
|
|
7631
|
-
if (!baseName || !EXCLUDED_BASES.has(baseName)) {
|
|
7632
|
-
context.report({
|
|
7633
|
-
node,
|
|
7634
|
-
messageId: "noImplicitAttributeAccess",
|
|
7635
|
-
data: { key: node.property.value }
|
|
7636
|
-
});
|
|
7637
|
-
}
|
|
7638
|
-
}
|
|
7639
|
-
},
|
|
7640
|
-
CallExpression(node) {
|
|
7641
|
-
const callee = node.callee;
|
|
7642
|
-
if (callee.type === import_utils53.AST_NODE_TYPES.MemberExpression) {
|
|
7643
|
-
const method = callee.property.type === import_utils53.AST_NODE_TYPES.Identifier ? callee.property.name : null;
|
|
7644
|
-
if (method === "get") {
|
|
7645
|
-
const arg = node.arguments[0];
|
|
7646
|
-
if (arg && arg.type === import_utils53.AST_NODE_TYPES.Literal && typeof arg.value === "string") {
|
|
7647
|
-
const baseName = getBaseName(callee.object);
|
|
7648
|
-
if (!baseName || !EXCLUDED_BASES.has(baseName)) {
|
|
7649
|
-
context.report({
|
|
7650
|
-
node,
|
|
7651
|
-
messageId: "noImplicitAttributeAccess",
|
|
7652
|
-
data: { key: arg.value }
|
|
7653
|
-
});
|
|
7654
|
-
}
|
|
7655
|
-
}
|
|
7656
|
-
}
|
|
7657
|
-
}
|
|
7658
|
-
}
|
|
7659
|
-
};
|
|
7660
|
-
}
|
|
7661
|
-
});
|
|
7662
|
-
|
|
7663
|
-
// src/rules/strict-test-assertions.ts
|
|
7664
|
-
var import_utils54 = require("@typescript-eslint/utils");
|
|
7665
|
-
var strict_test_assertions_default = import_utils54.ESLintUtils.RuleCreator.withoutDocs({
|
|
8076
|
+
name: "strict-test-assertions",
|
|
7666
8077
|
meta: {
|
|
7667
8078
|
type: "suggestion",
|
|
7668
8079
|
docs: {
|
|
7669
|
-
description: "
|
|
8080
|
+
description: "Collapse a run of consecutive assertions on the same object into one assertion about the whole object, so every mismatch is reported and nothing outside the asserted keys goes unchecked."
|
|
7670
8081
|
},
|
|
7671
8082
|
fixable: "code",
|
|
7672
8083
|
messages: {
|
|
7673
|
-
combineAssertions: "
|
|
8084
|
+
combineAssertions: "These {{count}} assertions each check one property of `{{receiver}}` against a literal, so the first mismatch hides the rest. Assert the object once: `expect({{receiver}}).toMatchObject({ \u2026 })`.",
|
|
8085
|
+
assertArrayOnce: "These {{count}} assertions check `{{receiver}}[0]`\u2026`{{receiver}}[{{last}}]` one at a time, which never checks how long `{{receiver}}` is \u2014 extra elements pass unnoticed. Assert the array once: `expect({{receiver}}).{{matcher}}([ \u2026 ])`."
|
|
7674
8086
|
},
|
|
7675
8087
|
schema: []
|
|
7676
8088
|
},
|
|
7677
8089
|
defaultOptions: [],
|
|
7678
8090
|
create(context) {
|
|
7679
|
-
|
|
7680
|
-
|
|
7681
|
-
|
|
7682
|
-
|
|
7683
|
-
|
|
7684
|
-
|
|
7685
|
-
|
|
7686
|
-
|
|
7687
|
-
|
|
8091
|
+
if (!isTestFile(context.filename) || isGeneratedFile(context.filename, context.sourceCode.text)) {
|
|
8092
|
+
return {};
|
|
8093
|
+
}
|
|
8094
|
+
const { sourceCode } = context;
|
|
8095
|
+
function parseAssertion(statement) {
|
|
8096
|
+
if (statement.type !== import_utils52.AST_NODE_TYPES.ExpressionStatement) {
|
|
8097
|
+
return null;
|
|
8098
|
+
}
|
|
8099
|
+
const call = statement.expression;
|
|
8100
|
+
if (call.type !== import_utils52.AST_NODE_TYPES.CallExpression) {
|
|
8101
|
+
return null;
|
|
8102
|
+
}
|
|
8103
|
+
const callee = call.callee;
|
|
8104
|
+
if (callee.type !== import_utils52.AST_NODE_TYPES.MemberExpression || callee.computed || callee.property.type !== import_utils52.AST_NODE_TYPES.Identifier) {
|
|
8105
|
+
return null;
|
|
8106
|
+
}
|
|
8107
|
+
const matcher = callee.property.name;
|
|
8108
|
+
const expectCall = callee.object;
|
|
8109
|
+
if (expectCall.type !== import_utils52.AST_NODE_TYPES.CallExpression || expectCall.callee.type !== import_utils52.AST_NODE_TYPES.Identifier || expectCall.callee.name !== "expect" || expectCall.arguments.length !== 1) {
|
|
8110
|
+
return null;
|
|
8111
|
+
}
|
|
8112
|
+
const actual = expectCall.arguments[0];
|
|
8113
|
+
if (actual === void 0 || actual.type !== import_utils52.AST_NODE_TYPES.MemberExpression || actual.optional) {
|
|
8114
|
+
return null;
|
|
8115
|
+
}
|
|
8116
|
+
if (!isPureReceiver(actual.object)) {
|
|
8117
|
+
return null;
|
|
8118
|
+
}
|
|
8119
|
+
let key;
|
|
8120
|
+
if (actual.computed) {
|
|
8121
|
+
const index = literalIndex(actual.property);
|
|
8122
|
+
if (index === null) {
|
|
8123
|
+
return null;
|
|
7688
8124
|
}
|
|
8125
|
+
key = { kind: "index", index };
|
|
8126
|
+
} else {
|
|
8127
|
+
if (actual.property.type !== import_utils52.AST_NODE_TYPES.Identifier || COLLECTION_PROPERTIES.has(actual.property.name)) {
|
|
8128
|
+
return null;
|
|
8129
|
+
}
|
|
8130
|
+
key = { kind: "property", name: actual.property.name };
|
|
8131
|
+
}
|
|
8132
|
+
if (matcher === "toBeNull" && call.arguments.length === 0) {
|
|
8133
|
+
return { statement, receiver: actual.object, key, matcher, expectedText: "null", expectedIsLiteral: true };
|
|
8134
|
+
}
|
|
8135
|
+
if (!MERGEABLE_MATCHERS.has(matcher)) {
|
|
7689
8136
|
return null;
|
|
7690
8137
|
}
|
|
7691
|
-
|
|
7692
|
-
|
|
7693
|
-
|
|
7694
|
-
|
|
7695
|
-
|
|
7696
|
-
|
|
7697
|
-
|
|
7698
|
-
|
|
7699
|
-
|
|
7700
|
-
|
|
7701
|
-
|
|
7702
|
-
|
|
7703
|
-
|
|
7704
|
-
|
|
7705
|
-
|
|
7706
|
-
|
|
7707
|
-
|
|
7708
|
-
|
|
7709
|
-
|
|
7710
|
-
}
|
|
7711
|
-
return null;
|
|
7712
|
-
});
|
|
7713
|
-
if (props.some((p) => p === null)) return null;
|
|
7714
|
-
const replacement = `expect(${objectText}).toMatchObject({ ${props.join(", ")} });`;
|
|
7715
|
-
return [
|
|
7716
|
-
fixer.replaceText(first, replacement),
|
|
7717
|
-
...sequence.slice(1).map((stmt) => fixer.remove(stmt))
|
|
7718
|
-
];
|
|
7719
|
-
}
|
|
7720
|
-
});
|
|
8138
|
+
const expected = call.arguments[0];
|
|
8139
|
+
if (call.arguments.length !== 1 || expected === void 0 || expected.type === import_utils52.AST_NODE_TYPES.SpreadElement) {
|
|
8140
|
+
return null;
|
|
8141
|
+
}
|
|
8142
|
+
const literal = literalText(expected, (node) => sourceCode.getText(node));
|
|
8143
|
+
return {
|
|
8144
|
+
statement,
|
|
8145
|
+
receiver: actual.object,
|
|
8146
|
+
key,
|
|
8147
|
+
matcher,
|
|
8148
|
+
expectedText: literal ?? sourceCode.getText(expected),
|
|
8149
|
+
expectedIsLiteral: literal !== null
|
|
8150
|
+
};
|
|
8151
|
+
}
|
|
8152
|
+
function reportPropertyRun(run) {
|
|
8153
|
+
const names = /* @__PURE__ */ new Set();
|
|
8154
|
+
for (const assertion of run) {
|
|
8155
|
+
if (assertion.key.kind !== "property" || !assertion.expectedIsLiteral) {
|
|
8156
|
+
return;
|
|
7721
8157
|
}
|
|
8158
|
+
if (!MERGEABLE_MATCHERS.has(assertion.matcher) && assertion.matcher !== "toBeNull") {
|
|
8159
|
+
return;
|
|
8160
|
+
}
|
|
8161
|
+
if (names.has(assertion.key.name)) {
|
|
8162
|
+
return;
|
|
8163
|
+
}
|
|
8164
|
+
names.add(assertion.key.name);
|
|
7722
8165
|
}
|
|
7723
|
-
|
|
7724
|
-
|
|
7725
|
-
|
|
7726
|
-
|
|
7727
|
-
|
|
8166
|
+
const first = run[0];
|
|
8167
|
+
if (first === void 0) {
|
|
8168
|
+
return;
|
|
8169
|
+
}
|
|
8170
|
+
const receiverText = sourceCode.getText(first.receiver);
|
|
8171
|
+
const properties = run.map(
|
|
8172
|
+
(assertion) => assertion.key.kind === "property" ? `${assertion.key.name}: ${assertion.expectedText}` : ""
|
|
8173
|
+
).join(", ");
|
|
8174
|
+
context.report({
|
|
8175
|
+
node: first.statement,
|
|
8176
|
+
messageId: "combineAssertions",
|
|
8177
|
+
data: { count: String(run.length), receiver: receiverText },
|
|
8178
|
+
fix: (fixer) => [
|
|
8179
|
+
fixer.replaceText(first.statement, `expect(${receiverText}).toMatchObject({ ${properties} });`),
|
|
8180
|
+
...run.slice(1).map((assertion) => fixer.remove(assertion.statement))
|
|
8181
|
+
]
|
|
8182
|
+
});
|
|
8183
|
+
}
|
|
8184
|
+
function reportIndexRun(run) {
|
|
8185
|
+
const first = run[0];
|
|
8186
|
+
if (first === void 0 || !ARRAY_MATCHERS.has(first.matcher)) {
|
|
8187
|
+
return;
|
|
8188
|
+
}
|
|
8189
|
+
const indices = /* @__PURE__ */ new Set();
|
|
8190
|
+
for (const assertion of run) {
|
|
8191
|
+
if (assertion.key.kind !== "index" || assertion.matcher !== first.matcher) {
|
|
8192
|
+
return;
|
|
8193
|
+
}
|
|
8194
|
+
indices.add(assertion.key.index);
|
|
8195
|
+
}
|
|
8196
|
+
if (indices.size !== run.length || Math.max(...indices) !== run.length - 1) {
|
|
8197
|
+
return;
|
|
8198
|
+
}
|
|
8199
|
+
context.report({
|
|
8200
|
+
node: first.statement,
|
|
8201
|
+
messageId: "assertArrayOnce",
|
|
8202
|
+
data: {
|
|
8203
|
+
count: String(run.length),
|
|
8204
|
+
receiver: sourceCode.getText(first.receiver),
|
|
8205
|
+
last: String(run.length - 1),
|
|
8206
|
+
matcher: first.matcher
|
|
8207
|
+
}
|
|
8208
|
+
});
|
|
8209
|
+
}
|
|
8210
|
+
function checkBody(body) {
|
|
8211
|
+
let run = [];
|
|
8212
|
+
const flush = () => {
|
|
8213
|
+
const first = run[0];
|
|
8214
|
+
if (first !== void 0 && run.length >= MIN_RUN_LENGTH) {
|
|
8215
|
+
if (first.key.kind === "property") {
|
|
8216
|
+
reportPropertyRun(run);
|
|
7728
8217
|
} else {
|
|
7729
|
-
|
|
7730
|
-
if (obj) {
|
|
7731
|
-
currentObject = obj;
|
|
7732
|
-
sequence = [statement];
|
|
7733
|
-
} else {
|
|
7734
|
-
currentObject = null;
|
|
7735
|
-
sequence = [];
|
|
7736
|
-
}
|
|
8218
|
+
reportIndexRun(run);
|
|
7737
8219
|
}
|
|
7738
|
-
}
|
|
7739
|
-
|
|
7740
|
-
|
|
7741
|
-
|
|
8220
|
+
}
|
|
8221
|
+
run = [];
|
|
8222
|
+
};
|
|
8223
|
+
for (const statement of body) {
|
|
8224
|
+
const assertion = parseAssertion(statement);
|
|
8225
|
+
const previous = run.at(-1);
|
|
8226
|
+
if (assertion !== null && previous !== void 0 && previous.key.kind === assertion.key.kind && sourceCode.getText(previous.receiver) === sourceCode.getText(assertion.receiver)) {
|
|
8227
|
+
run.push(assertion);
|
|
8228
|
+
continue;
|
|
8229
|
+
}
|
|
8230
|
+
flush();
|
|
8231
|
+
if (assertion !== null) {
|
|
8232
|
+
run = [assertion];
|
|
7742
8233
|
}
|
|
7743
8234
|
}
|
|
7744
|
-
|
|
8235
|
+
flush();
|
|
7745
8236
|
}
|
|
7746
8237
|
return {
|
|
7747
|
-
BlockStatement(node) {
|
|
8238
|
+
BlockStatement: (node) => {
|
|
7748
8239
|
checkBody(node.body);
|
|
7749
8240
|
},
|
|
7750
|
-
Program(node) {
|
|
8241
|
+
Program: (node) => {
|
|
7751
8242
|
checkBody(node.body);
|
|
7752
8243
|
}
|
|
7753
8244
|
};
|
|
@@ -7755,8 +8246,8 @@ var strict_test_assertions_default = import_utils54.ESLintUtils.RuleCreator.with
|
|
|
7755
8246
|
});
|
|
7756
8247
|
|
|
7757
8248
|
// src/rules/no-async-callback-in-waitfor.ts
|
|
7758
|
-
var
|
|
7759
|
-
var no_async_callback_in_waitfor_default =
|
|
8249
|
+
var import_utils53 = require("@typescript-eslint/utils");
|
|
8250
|
+
var no_async_callback_in_waitfor_default = import_utils53.ESLintUtils.RuleCreator(
|
|
7760
8251
|
(name) => `https://github.com/sarj-ai/standards/blob/main/packages/typescript/src/rules/${name}.ts`
|
|
7761
8252
|
)({
|
|
7762
8253
|
name: "no-async-callback-in-waitfor",
|
|
@@ -7777,9 +8268,9 @@ var no_async_callback_in_waitfor_default = import_utils55.ESLintUtils.RuleCreato
|
|
|
7777
8268
|
}
|
|
7778
8269
|
return {
|
|
7779
8270
|
CallExpression(node) {
|
|
7780
|
-
if (node.callee.type ===
|
|
8271
|
+
if (node.callee.type === import_utils53.AST_NODE_TYPES.Identifier && node.callee.name === "waitFor") {
|
|
7781
8272
|
const callback = node.arguments[0];
|
|
7782
|
-
if (callback && (callback.type ===
|
|
8273
|
+
if (callback && (callback.type === import_utils53.AST_NODE_TYPES.ArrowFunctionExpression || callback.type === import_utils53.AST_NODE_TYPES.FunctionExpression) && callback.async) {
|
|
7783
8274
|
context.report({
|
|
7784
8275
|
node: callback,
|
|
7785
8276
|
messageId: "noAsyncCallbackInWaitFor"
|
|
@@ -7792,7 +8283,7 @@ var no_async_callback_in_waitfor_default = import_utils55.ESLintUtils.RuleCreato
|
|
|
7792
8283
|
});
|
|
7793
8284
|
|
|
7794
8285
|
// src/rules/no-hand-rolled-sleep.ts
|
|
7795
|
-
var
|
|
8286
|
+
var import_utils54 = require("@typescript-eslint/utils");
|
|
7796
8287
|
var GLOBAL_OBJECTS2 = /* @__PURE__ */ new Set([
|
|
7797
8288
|
"globalThis",
|
|
7798
8289
|
"window",
|
|
@@ -7811,66 +8302,66 @@ function matchesAnyPattern3(filename, patterns) {
|
|
|
7811
8302
|
return false;
|
|
7812
8303
|
}
|
|
7813
8304
|
function isSetTimeoutCallee(callee) {
|
|
7814
|
-
if (callee.type ===
|
|
8305
|
+
if (callee.type === import_utils54.AST_NODE_TYPES.Identifier) {
|
|
7815
8306
|
return callee.name === "setTimeout";
|
|
7816
8307
|
}
|
|
7817
|
-
return callee.type ===
|
|
8308
|
+
return callee.type === import_utils54.AST_NODE_TYPES.MemberExpression && !callee.computed && callee.property.type === import_utils54.AST_NODE_TYPES.Identifier && callee.property.name === "setTimeout" && callee.object.type === import_utils54.AST_NODE_TYPES.Identifier && GLOBAL_OBJECTS2.has(callee.object.name);
|
|
7818
8309
|
}
|
|
7819
8310
|
function soleCall(fn) {
|
|
7820
|
-
if (fn.body.type !==
|
|
7821
|
-
return fn.body.type ===
|
|
8311
|
+
if (fn.body.type !== import_utils54.AST_NODE_TYPES.BlockStatement) {
|
|
8312
|
+
return fn.body.type === import_utils54.AST_NODE_TYPES.CallExpression ? fn.body : null;
|
|
7822
8313
|
}
|
|
7823
8314
|
if (fn.body.body.length !== 1) {
|
|
7824
8315
|
return null;
|
|
7825
8316
|
}
|
|
7826
8317
|
const [only] = fn.body.body;
|
|
7827
|
-
if (only?.type !==
|
|
8318
|
+
if (only?.type !== import_utils54.AST_NODE_TYPES.ExpressionStatement) {
|
|
7828
8319
|
return null;
|
|
7829
8320
|
}
|
|
7830
|
-
return only.expression.type ===
|
|
8321
|
+
return only.expression.type === import_utils54.AST_NODE_TYPES.CallExpression ? only.expression : null;
|
|
7831
8322
|
}
|
|
7832
8323
|
function isTimedDelay(delay) {
|
|
7833
8324
|
if (delay === void 0) {
|
|
7834
8325
|
return false;
|
|
7835
8326
|
}
|
|
7836
|
-
if (delay.type ===
|
|
8327
|
+
if (delay.type === import_utils54.AST_NODE_TYPES.Literal && typeof delay.value === "number") {
|
|
7837
8328
|
return delay.value !== 0;
|
|
7838
8329
|
}
|
|
7839
8330
|
return true;
|
|
7840
8331
|
}
|
|
7841
8332
|
function settlesWithoutValue(callback, name) {
|
|
7842
|
-
if (callback.type ===
|
|
8333
|
+
if (callback.type === import_utils54.AST_NODE_TYPES.Identifier) {
|
|
7843
8334
|
return callback.name === name;
|
|
7844
8335
|
}
|
|
7845
|
-
if (callback.type !==
|
|
8336
|
+
if (callback.type !== import_utils54.AST_NODE_TYPES.ArrowFunctionExpression && callback.type !== import_utils54.AST_NODE_TYPES.FunctionExpression) {
|
|
7846
8337
|
return false;
|
|
7847
8338
|
}
|
|
7848
8339
|
const call = soleCall(callback);
|
|
7849
|
-
return call !== null && call.arguments.length === 0 && call.callee.type ===
|
|
8340
|
+
return call !== null && call.arguments.length === 0 && call.callee.type === import_utils54.AST_NODE_TYPES.Identifier && call.callee.name === name;
|
|
7850
8341
|
}
|
|
7851
8342
|
function rejectsInCallback(callback, name) {
|
|
7852
|
-
if (callback.type ===
|
|
8343
|
+
if (callback.type === import_utils54.AST_NODE_TYPES.Identifier) {
|
|
7853
8344
|
return callback.name === name;
|
|
7854
8345
|
}
|
|
7855
|
-
if (callback.type !==
|
|
8346
|
+
if (callback.type !== import_utils54.AST_NODE_TYPES.ArrowFunctionExpression && callback.type !== import_utils54.AST_NODE_TYPES.FunctionExpression) {
|
|
7856
8347
|
return false;
|
|
7857
8348
|
}
|
|
7858
8349
|
const call = soleCall(callback);
|
|
7859
|
-
return call !== null && call.callee.type ===
|
|
8350
|
+
return call !== null && call.callee.type === import_utils54.AST_NODE_TYPES.Identifier && call.callee.name === name;
|
|
7860
8351
|
}
|
|
7861
8352
|
function parameterName(fn, index) {
|
|
7862
8353
|
const parameter = fn.params[index];
|
|
7863
|
-
return parameter?.type ===
|
|
8354
|
+
return parameter?.type === import_utils54.AST_NODE_TYPES.Identifier ? parameter.name : null;
|
|
7864
8355
|
}
|
|
7865
8356
|
function isRaceArm(node) {
|
|
7866
8357
|
const array = node.parent;
|
|
7867
|
-
if (array?.type !==
|
|
8358
|
+
if (array?.type !== import_utils54.AST_NODE_TYPES.ArrayExpression) {
|
|
7868
8359
|
return false;
|
|
7869
8360
|
}
|
|
7870
8361
|
const call = array.parent;
|
|
7871
|
-
return call?.type ===
|
|
8362
|
+
return call?.type === import_utils54.AST_NODE_TYPES.CallExpression && call.arguments[0] === array && call.callee.type === import_utils54.AST_NODE_TYPES.MemberExpression && !call.callee.computed && call.callee.object.type === import_utils54.AST_NODE_TYPES.Identifier && call.callee.object.name === "Promise" && call.callee.property.type === import_utils54.AST_NODE_TYPES.Identifier && RACE_METHODS.has(call.callee.property.name);
|
|
7872
8363
|
}
|
|
7873
|
-
var no_hand_rolled_sleep_default =
|
|
8364
|
+
var no_hand_rolled_sleep_default = import_utils54.ESLintUtils.RuleCreator(
|
|
7874
8365
|
(name) => `https://github.com/sarj-ai/standards/blob/main/packages/typescript/src/rules/${name}.ts`
|
|
7875
8366
|
)({
|
|
7876
8367
|
name: "no-hand-rolled-sleep",
|
|
@@ -7918,10 +8409,10 @@ var no_hand_rolled_sleep_default = import_utils56.ESLintUtils.RuleCreator(
|
|
|
7918
8409
|
}
|
|
7919
8410
|
const program = sourceCode.ast;
|
|
7920
8411
|
for (const statement of program.body) {
|
|
7921
|
-
if (statement.type ===
|
|
8412
|
+
if (statement.type === import_utils54.AST_NODE_TYPES.ExpressionStatement && statement.expression.type === import_utils54.AST_NODE_TYPES.Literal && statement.expression.value === "use client") {
|
|
7922
8413
|
return true;
|
|
7923
8414
|
}
|
|
7924
|
-
if (statement.type ===
|
|
8415
|
+
if (statement.type === import_utils54.AST_NODE_TYPES.ImportDeclaration && typeof statement.source.value === "string" && CLIENT_ONLY_MODULES.test(statement.source.value)) {
|
|
7925
8416
|
return true;
|
|
7926
8417
|
}
|
|
7927
8418
|
}
|
|
@@ -7937,11 +8428,11 @@ var no_hand_rolled_sleep_default = import_utils56.ESLintUtils.RuleCreator(
|
|
|
7937
8428
|
};
|
|
7938
8429
|
return {
|
|
7939
8430
|
NewExpression(node) {
|
|
7940
|
-
if (node.callee.type !==
|
|
8431
|
+
if (node.callee.type !== import_utils54.AST_NODE_TYPES.Identifier || node.callee.name !== "Promise") {
|
|
7941
8432
|
return;
|
|
7942
8433
|
}
|
|
7943
8434
|
const executor = node.arguments[0];
|
|
7944
|
-
if (executor?.type !==
|
|
8435
|
+
if (executor?.type !== import_utils54.AST_NODE_TYPES.ArrowFunctionExpression && executor?.type !== import_utils54.AST_NODE_TYPES.FunctionExpression) {
|
|
7945
8436
|
return;
|
|
7946
8437
|
}
|
|
7947
8438
|
const call = soleCall(executor);
|
|
@@ -7968,43 +8459,8 @@ var no_hand_rolled_sleep_default = import_utils56.ESLintUtils.RuleCreator(
|
|
|
7968
8459
|
}
|
|
7969
8460
|
});
|
|
7970
8461
|
|
|
7971
|
-
// src/rules/prefer-setup-file-mocks.ts
|
|
7972
|
-
var import_utils57 = require("@typescript-eslint/utils");
|
|
7973
|
-
var prefer_setup_file_mocks_default = import_utils57.ESLintUtils.RuleCreator(
|
|
7974
|
-
(name) => `https://github.com/sarj-ai/standards/blob/main/packages/typescript/src/rules/${name}.ts`
|
|
7975
|
-
)({
|
|
7976
|
-
name: "prefer-setup-file-mocks",
|
|
7977
|
-
meta: {
|
|
7978
|
-
type: "suggestion",
|
|
7979
|
-
docs: {
|
|
7980
|
-
description: "Prefer defining module mocks in setup files rather than using vi.mock or jest.mock inline in test files."
|
|
7981
|
-
},
|
|
7982
|
-
schema: [],
|
|
7983
|
-
messages: {
|
|
7984
|
-
preferSetupFileMocks: "Define module mocks in a setup file (e.g. vitest.setup.ts) instead of using vi.mock or jest.mock directly in test files."
|
|
7985
|
-
}
|
|
7986
|
-
},
|
|
7987
|
-
defaultOptions: [],
|
|
7988
|
-
create(context) {
|
|
7989
|
-
if (!isTestFile(context.filename)) {
|
|
7990
|
-
return {};
|
|
7991
|
-
}
|
|
7992
|
-
return {
|
|
7993
|
-
CallExpression(node) {
|
|
7994
|
-
if (node.callee.type === import_utils57.AST_NODE_TYPES.MemberExpression && node.callee.object.type === import_utils57.AST_NODE_TYPES.Identifier && (node.callee.object.name === "vi" || node.callee.object.name === "jest") && node.callee.property.type === import_utils57.AST_NODE_TYPES.Identifier && node.callee.property.name === "mock") {
|
|
7995
|
-
context.report({
|
|
7996
|
-
node,
|
|
7997
|
-
messageId: "preferSetupFileMocks"
|
|
7998
|
-
});
|
|
7999
|
-
}
|
|
8000
|
-
}
|
|
8001
|
-
};
|
|
8002
|
-
}
|
|
8003
|
-
});
|
|
8004
|
-
|
|
8005
8462
|
// src/index.ts
|
|
8006
8463
|
var rules = {
|
|
8007
|
-
"ban-loose-type-guards-in-tests": ban_loose_type_guards_in_tests_default,
|
|
8008
8464
|
"enforce-file-structure": enforce_file_structure_default,
|
|
8009
8465
|
"no-client-side-data-fetching": no_client_side_data_fetching_default,
|
|
8010
8466
|
"no-comment-cruft": no_comment_cruft_default,
|
|
@@ -8053,14 +8509,12 @@ var rules = {
|
|
|
8053
8509
|
"require-interface-for-injected-service": require_interface_for_injected_service_default,
|
|
8054
8510
|
"strict-test-assertions": strict_test_assertions_default,
|
|
8055
8511
|
"prefer-non-nullable-collection": prefer_non_nullable_collection_default,
|
|
8056
|
-
"no-
|
|
8057
|
-
"no-async-callback-in-waitfor": no_async_callback_in_waitfor_default,
|
|
8058
|
-
"prefer-setup-file-mocks": prefer_setup_file_mocks_default
|
|
8512
|
+
"no-async-callback-in-waitfor": no_async_callback_in_waitfor_default
|
|
8059
8513
|
};
|
|
8060
8514
|
var plugin = {
|
|
8061
8515
|
meta: {
|
|
8062
8516
|
name: "@sarj/eslint-plugin",
|
|
8063
|
-
version: "
|
|
8517
|
+
version: "5.0.0"
|
|
8064
8518
|
},
|
|
8065
8519
|
rules,
|
|
8066
8520
|
configs: {
|
|
@@ -8070,7 +8524,6 @@ var plugin = {
|
|
|
8070
8524
|
"@sarj/zod-naming-convention": "warn",
|
|
8071
8525
|
"@sarj/require-assert-never": "error",
|
|
8072
8526
|
"@sarj/require-zod-form-validation": "error",
|
|
8073
|
-
"@sarj/ban-loose-type-guards-in-tests": "error",
|
|
8074
8527
|
"@sarj/enforce-file-structure": "warn",
|
|
8075
8528
|
"@sarj/no-client-side-data-fetching": "warn",
|
|
8076
8529
|
"@sarj/prefer-server-actions": "warn",
|
|
@@ -8155,9 +8608,7 @@ var plugin = {
|
|
|
8155
8608
|
// port, 29 fire, 28 of them true positives.
|
|
8156
8609
|
"@sarj/require-interface-for-injected-service": "warn",
|
|
8157
8610
|
"@sarj/prefer-non-nullable-collection": "warn",
|
|
8158
|
-
"@sarj/no-
|
|
8159
|
-
"@sarj/no-async-callback-in-waitfor": "warn",
|
|
8160
|
-
"@sarj/prefer-setup-file-mocks": "warn"
|
|
8611
|
+
"@sarj/no-async-callback-in-waitfor": "warn"
|
|
8161
8612
|
}
|
|
8162
8613
|
},
|
|
8163
8614
|
strict: {
|
|
@@ -8166,7 +8617,6 @@ var plugin = {
|
|
|
8166
8617
|
"@sarj/zod-naming-convention": "error",
|
|
8167
8618
|
"@sarj/require-assert-never": "error",
|
|
8168
8619
|
"@sarj/require-zod-form-validation": "error",
|
|
8169
|
-
"@sarj/ban-loose-type-guards-in-tests": "error",
|
|
8170
8620
|
"@sarj/enforce-file-structure": "error",
|
|
8171
8621
|
"@sarj/no-raw-env": "error",
|
|
8172
8622
|
"@sarj/no-enum": "error",
|
|
@@ -8241,9 +8691,7 @@ var plugin = {
|
|
|
8241
8691
|
// corpus (175 `implements` clauses vs 29 hits), so strict enforces it.
|
|
8242
8692
|
"@sarj/require-interface-for-injected-service": "error",
|
|
8243
8693
|
"@sarj/prefer-non-nullable-collection": "error",
|
|
8244
|
-
"@sarj/no-
|
|
8245
|
-
"@sarj/no-async-callback-in-waitfor": "error",
|
|
8246
|
-
"@sarj/prefer-setup-file-mocks": "error"
|
|
8694
|
+
"@sarj/no-async-callback-in-waitfor": "error"
|
|
8247
8695
|
}
|
|
8248
8696
|
}
|
|
8249
8697
|
}
|