@sarj/eslint-plugin 2.12.2 → 2.14.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 +45 -1
- package/dist/index.cjs +1198 -459
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +32 -0
- package/dist/index.d.ts +32 -0
- package/dist/index.js +1142 -403
- package/dist/index.js.map +1 -1
- package/package.json +4 -1
package/dist/index.js
CHANGED
|
@@ -242,56 +242,90 @@ var no_client_side_data_fetching_default = ESLintUtils2.RuleCreator(
|
|
|
242
242
|
});
|
|
243
243
|
|
|
244
244
|
// src/rules/no-comment-cruft.ts
|
|
245
|
-
import { AST_NODE_TYPES as
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
var
|
|
250
|
-
var
|
|
251
|
-
var
|
|
252
|
-
var
|
|
253
|
-
var
|
|
254
|
-
var
|
|
255
|
-
var
|
|
256
|
-
var
|
|
257
|
-
var
|
|
258
|
-
var
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
245
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES4, ESLintUtils as ESLintUtils3 } from "@typescript-eslint/utils";
|
|
246
|
+
|
|
247
|
+
// src/rules/_comments.ts
|
|
248
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES3 } from "@typescript-eslint/utils";
|
|
249
|
+
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/;
|
|
250
|
+
var VERSION_RE = /(?:>=|<=|==|<|>)\s*v?\d+\.\d+|\bv\d+\.\d+|\b(?:since|until|as of)\s+(?:v?\d+\.\d+|Python\s*\d)/i;
|
|
251
|
+
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/;
|
|
252
|
+
var CAUSAL_RE = /\b(?:because|otherwise|so that|or else|would (?:break|fail|race|deadlock|leak|clobber|loop|crash|page|stall)|breaks?\b|so we don'?t|to avoid\b|caused\b|causes\b|gets? clobbered|keeps? (?:us|it|them) from|doesn'?t\b.{0,24}\b(?:page|fire|break|leak|loop)|eat into|would otherwise|trade-?offs?\b)\b/i;
|
|
253
|
+
var NEGATION_RE = /\b(?:must not|must never|do(?:es)? not\b|don'?t\b.{0,30}\b(?:leak|log|cache|retry|block|steal|wipe)|never\b|deliberately|intentionally|counterintuitiv|NOT\b)|(?<!based )\bon purpose\b|\(not\s|\binstead of\b|\brather than\b/;
|
|
254
|
+
var UPSTREAM_RE = /\b(?:upstream|workaround|quirk|backport|vendored|regression|fixed upstream|requires?\b|convention\b|rate.?limit|deprecat|opts? in(?:to)?\b|raises?\b.{0,60}\b(?:when|if|unless)\b)/i;
|
|
255
|
+
var INVARIANT_RE = /\b(?:invariant|idempotent|race\b|deadlock|re-?entran|atomic|thread-?safe|signal-?safe|lexicographic(?:al(?:ly)?)?|monotonic|must (?:run|be|happen|come|stay|hit|converge|configure)|before any\b|lost the (?:claim )?race)\b/i;
|
|
256
|
+
var SECURITY_RE = /\b(?:timing attack|constant-?time|replay|PII\b|redact|secret|injection|spoof|fail-?closed|fail-?open|auth bypass|early-?exit timing)\b/i;
|
|
257
|
+
var VENDOR_RE = /\b(?:GitHub|Slack|Twilio|LiveKit|Kamailio|Groq|OpenAI|Anthropic|Cloudflare|FastAPI|Starlette|Sentry|Zoho|Salla|Ashby|Linear|BigQuery|Postgres|Neon|Drizzle|Vertex|Gemini|Firestore|Stripe|Next\.js|React Compiler|pydantic|ruff|loguru|Lexical|Farasa|Orpheus|Whisper|schemathesis)(?:'s\b|\s+(?:requires?|returns?|expects?|allows?|rejects?|accepts?|sends?|caps?|limits?|wraps?|silently|outputs?|stores?|treats?|doesn'?t|does not|won'?t|can'?t|only|models)\b)/;
|
|
258
|
+
var PROTECTED_SIGNALS = [
|
|
259
|
+
REF_RE,
|
|
260
|
+
VERSION_RE,
|
|
261
|
+
UNITS_RE,
|
|
262
|
+
CAUSAL_RE,
|
|
263
|
+
NEGATION_RE,
|
|
264
|
+
UPSTREAM_RE,
|
|
265
|
+
INVARIANT_RE,
|
|
266
|
+
SECURITY_RE,
|
|
267
|
+
VENDOR_RE
|
|
268
|
+
];
|
|
269
|
+
function isProtected(body) {
|
|
270
|
+
return PROTECTED_SIGNALS.some((signal) => signal.test(body));
|
|
271
|
+
}
|
|
272
|
+
function hasExternalReference(body) {
|
|
273
|
+
return REF_RE.test(body);
|
|
274
|
+
}
|
|
275
|
+
var STOPWORDS = new Set(
|
|
276
|
+
`a an the this that these those it its their his her our your my
|
|
277
|
+
is are was were be been being am do does did done doing has have had having
|
|
278
|
+
will would shall should can could may might must
|
|
279
|
+
and or but nor so yet not no none
|
|
280
|
+
to of for in on at by with from into onto out up down over under about
|
|
281
|
+
as if then than when where which who whom whose what how why while
|
|
282
|
+
we you they i he she them him us me
|
|
283
|
+
also just only even still already again there here
|
|
284
|
+
all any each every some
|
|
285
|
+
via per etc eg ie vs
|
|
286
|
+
need needs needed want wants make makes making let lets
|
|
287
|
+
please note see above below`.split(/\s+/)
|
|
288
|
+
);
|
|
289
|
+
var CAMEL_PART_RE = /[A-Z]+(?=[A-Z][a-z])|[A-Z]?[a-z]+|[A-Z]+|\d+/g;
|
|
290
|
+
var WORD_RE = /[A-Za-z_$][\w$]*|\d+/g;
|
|
291
|
+
function splitIdentifier(token) {
|
|
292
|
+
const parts = [];
|
|
293
|
+
for (const chunk of token.split(/[_$]/)) {
|
|
294
|
+
for (const match of chunk.match(CAMEL_PART_RE) ?? []) {
|
|
295
|
+
parts.push(match.toLowerCase());
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
return parts;
|
|
279
299
|
}
|
|
280
|
-
function
|
|
281
|
-
|
|
300
|
+
function stem(word) {
|
|
301
|
+
let base = word;
|
|
302
|
+
for (const suffix of ["ing", "ied", "ies", "ers", "er", "ed", "es", "s"]) {
|
|
303
|
+
if (word.endsWith(suffix) && word.length - suffix.length >= 3) {
|
|
304
|
+
base = word.slice(0, word.length - suffix.length);
|
|
305
|
+
if (suffix === "ied" || suffix === "ies") return `${base}y`;
|
|
306
|
+
break;
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
return base.endsWith("e") && base.length - 1 >= 3 ? base.slice(0, -1) : base;
|
|
282
310
|
}
|
|
283
|
-
function
|
|
284
|
-
const
|
|
285
|
-
|
|
311
|
+
function contentTokens(text) {
|
|
312
|
+
const tokens = [];
|
|
313
|
+
for (const match of text.match(WORD_RE) ?? []) {
|
|
314
|
+
tokens.push(...splitIdentifier(match));
|
|
315
|
+
}
|
|
316
|
+
return tokens.filter((token) => !STOPWORDS.has(token));
|
|
286
317
|
}
|
|
287
|
-
function
|
|
288
|
-
const
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
if (/[.!?]$/.test(t) && /\s/.test(t) && /[a-z]/.test(t) && !looksLikeCode(t) && t.split(/\s+/).length >= 3) {
|
|
292
|
-
return true;
|
|
318
|
+
function codeTokens(text) {
|
|
319
|
+
const tokens = /* @__PURE__ */ new Set();
|
|
320
|
+
for (const match of text.match(WORD_RE) ?? []) {
|
|
321
|
+
for (const part of splitIdentifier(match)) tokens.add(part);
|
|
293
322
|
}
|
|
294
|
-
return
|
|
323
|
+
return tokens;
|
|
324
|
+
}
|
|
325
|
+
function restates(commentTokens, code) {
|
|
326
|
+
const stems = /* @__PURE__ */ new Set();
|
|
327
|
+
for (const token of code) stems.add(stem(token));
|
|
328
|
+
return commentTokens.every((token) => code.has(token) || stems.has(stem(token)));
|
|
295
329
|
}
|
|
296
330
|
var NARRATION_MAX_WORDS = 6;
|
|
297
331
|
var NARRATION_MIN_CONTENT = 1;
|
|
@@ -352,7 +386,7 @@ function normalizeToken(word) {
|
|
|
352
386
|
const lower = word.toLowerCase();
|
|
353
387
|
return lower.length > TOKEN_PLURAL_MIN && lower.endsWith("s") && !lower.endsWith("ss") ? lower.slice(0, -1) : lower;
|
|
354
388
|
}
|
|
355
|
-
function
|
|
389
|
+
function headTokens(source) {
|
|
356
390
|
const tokens = /* @__PURE__ */ new Set();
|
|
357
391
|
for (const identifier of source.match(/[A-Za-z_$][\w$]*/g) ?? []) {
|
|
358
392
|
tokens.add(normalizeToken(identifier));
|
|
@@ -384,7 +418,7 @@ function restatableStatementBelow(comment, sourceCode) {
|
|
|
384
418
|
}
|
|
385
419
|
return null;
|
|
386
420
|
}
|
|
387
|
-
function
|
|
421
|
+
function restatesStatementHead(body, statement) {
|
|
388
422
|
if (statement === null) return false;
|
|
389
423
|
const words = body.match(/[A-Za-z][\w$]*/g) ?? [];
|
|
390
424
|
const opener = words[0];
|
|
@@ -393,18 +427,152 @@ function restatesNextLine(body, statement) {
|
|
|
393
427
|
const content = words.slice(1).map(normalizeToken).filter((word) => !NARRATION_STOPWORDS.has(word));
|
|
394
428
|
if (content.length < NARRATION_MIN_CONTENT) return false;
|
|
395
429
|
const head = statement.split("(")[0] ?? statement;
|
|
396
|
-
const code =
|
|
430
|
+
const code = headTokens(head);
|
|
397
431
|
return content.every((word) => code.has(word));
|
|
398
432
|
}
|
|
433
|
+
|
|
434
|
+
// src/rules/no-comment-cruft.ts
|
|
435
|
+
var LEADING_PREAMBLE_MIN = 4;
|
|
436
|
+
var STEP_NARRATION_RE = /^(?:first(?:ly)?|second(?:ly)?|third(?:ly)?|then|next|after(?:wards| that)?|finally|lastly|now)\s*[,:]\s*\S|^step\s+\d+\b/i;
|
|
437
|
+
var META_COMMENTARY_RE = /\b(?:for now|keeping (?:it|this) simple|could be (?:refactored|improved|cleaned up|simplified)|refactor(?:ed|ing)? (?:later|this)|not sure (?:if|whether|why|how)|quick[- ](?:and[- ]dirty|fix)|(?:a |bit of a )?hacky|is a hack|temporary (?:solution|workaround|fix|hack)|revisit (?:this|later|below)|clean (?:this|it) up|not ideal|placeholder for now)\b/i;
|
|
438
|
+
var DIRECTIVE_RE = /^(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;
|
|
439
|
+
var LICENSE_RE = /copyright|licen[cs]ed?|spdx|permission is hereby granted|all rights reserved/i;
|
|
440
|
+
var ENUMERATED_ITEM_RE = /^(?:\d+[.):]|[-*•])\s+\S/;
|
|
441
|
+
var ENUMERATED_ITEM_MIN_WORDS = 3;
|
|
442
|
+
var ENUMERATED_PREAMBLE_MIN_ITEMS = 2;
|
|
443
|
+
var BANNER_FULL_RE = /^[\s\-=*#~_+.]{4,}$/;
|
|
444
|
+
var BANNER_RUN_RE = /={4,}|-{4,}|#{4,}|\*{4,}|~{4,}|[\u2500-\u257f]{4,}/;
|
|
445
|
+
var REGION_MARKER_RE = /^#?(?:end)?region\b(.*)$/i;
|
|
446
|
+
var REGION_TITLE_RE = /^[\s:\-\u2013\u2014]*\w[\w \-/&+]*$/;
|
|
447
|
+
var REGION_TITLE_MAX_WORDS = 5;
|
|
448
|
+
function isRegionMarker(text) {
|
|
449
|
+
const match = REGION_MARKER_RE.exec(text);
|
|
450
|
+
if (match === null) return false;
|
|
451
|
+
const title = (match[1] ?? "").trim();
|
|
452
|
+
if (title.length === 0) return true;
|
|
453
|
+
if (!REGION_TITLE_RE.test(title)) return false;
|
|
454
|
+
return title.split(/\s+/).length <= REGION_TITLE_MAX_WORDS;
|
|
455
|
+
}
|
|
456
|
+
var SECTION_LABEL_WORDS = /* @__PURE__ */ new Set([
|
|
457
|
+
"actions",
|
|
458
|
+
"components",
|
|
459
|
+
"config",
|
|
460
|
+
"configuration",
|
|
461
|
+
"constant",
|
|
462
|
+
"constants",
|
|
463
|
+
"enums",
|
|
464
|
+
"exports",
|
|
465
|
+
"fixtures",
|
|
466
|
+
"getters",
|
|
467
|
+
"globals",
|
|
468
|
+
"handler",
|
|
469
|
+
"handlers",
|
|
470
|
+
"helper",
|
|
471
|
+
"helpers",
|
|
472
|
+
"hook",
|
|
473
|
+
"hooks",
|
|
474
|
+
"imports",
|
|
475
|
+
"interfaces",
|
|
476
|
+
"main",
|
|
477
|
+
"mocks",
|
|
478
|
+
"models",
|
|
479
|
+
"mutations",
|
|
480
|
+
"props",
|
|
481
|
+
"queries",
|
|
482
|
+
"reducers",
|
|
483
|
+
"routes",
|
|
484
|
+
"schemas",
|
|
485
|
+
"selectors",
|
|
486
|
+
"setters",
|
|
487
|
+
"setup",
|
|
488
|
+
"state",
|
|
489
|
+
"styles",
|
|
490
|
+
"teardown",
|
|
491
|
+
"type",
|
|
492
|
+
"types",
|
|
493
|
+
"util",
|
|
494
|
+
"utilities",
|
|
495
|
+
"utils"
|
|
496
|
+
]);
|
|
497
|
+
var SECTION_LABEL_RE = /^([A-Za-z]+)\s*:?\s*$/;
|
|
498
|
+
function isSectionLabel(text) {
|
|
499
|
+
const match = SECTION_LABEL_RE.exec(text);
|
|
500
|
+
return match !== null && SECTION_LABEL_WORDS.has((match[1] ?? "").toLowerCase());
|
|
501
|
+
}
|
|
502
|
+
var HELPER_OPENER_RE = /^(?:a\s+)?helper\s+(?:function|method|component|hook|class|type|util(?:ity)?)\b/i;
|
|
503
|
+
var LETS_RE = /^let'?s\s+(?:not\s+|just\s+|now\s+|first\s+)?(?:add|append|assign|await|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|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|ed|ing)?\b/i;
|
|
504
|
+
var ENUMERATION_RE = /^(?:\d+[.)]\s+\S|phase\s+\d+\b)/i;
|
|
505
|
+
var DIAGRAM_ARROW_RE = /[-=~]{2,}>|<[-=~]{2,}/;
|
|
506
|
+
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\.)/;
|
|
507
|
+
var CODE_TAIL_RE = /[;{}()]\s*$|=>\s*$|,\s*$/;
|
|
508
|
+
var CALL_OR_ASSIGN_RE = /^[A-Za-z_$][\w.$[\]]*\s*(?:=(?![=>])|\+=|-=|\*=)\s*\S.*[;)}\]]\s*$|^[A-Za-z_$][\w.$]*\([^)]*\)\s*;?\s*$/;
|
|
509
|
+
var PSEUDOCODE_RE = /%\w+%|\[opt\]|(?:^|\s)<[A-Za-z]\w*>|…|\.\.\./;
|
|
510
|
+
function stripCommentMarker(line) {
|
|
511
|
+
return line.replace(/^\s*\/{1,2}/, "").replace(/^\s*\*+/, "").trim();
|
|
512
|
+
}
|
|
513
|
+
function isDirective(text) {
|
|
514
|
+
return DIRECTIVE_RE.test(text.trim());
|
|
515
|
+
}
|
|
516
|
+
function isBanner(text) {
|
|
517
|
+
const t = text.trim();
|
|
518
|
+
if (!t) return false;
|
|
519
|
+
if (BANNER_FULL_RE.test(t) || isRegionMarker(t)) return true;
|
|
520
|
+
return BANNER_RUN_RE.test(t) && !DIAGRAM_ARROW_RE.test(t);
|
|
521
|
+
}
|
|
522
|
+
function looksLikeCode(text) {
|
|
523
|
+
const t = text.trim();
|
|
524
|
+
if (!t) return false;
|
|
525
|
+
if (CODE_KEYWORD_RE.test(t) && CODE_TAIL_RE.test(t)) return true;
|
|
526
|
+
return CALL_OR_ASSIGN_RE.test(t);
|
|
527
|
+
}
|
|
528
|
+
function hasPseudocode(text) {
|
|
529
|
+
return PSEUDOCODE_RE.test(text);
|
|
530
|
+
}
|
|
531
|
+
function isEnumeratedProseItem(text) {
|
|
532
|
+
const t = text.trim();
|
|
533
|
+
return ENUMERATED_ITEM_RE.test(t) && t.split(/\s+/).length >= ENUMERATED_ITEM_MIN_WORDS;
|
|
534
|
+
}
|
|
535
|
+
function isProse(text) {
|
|
536
|
+
const t = text.trim();
|
|
537
|
+
if (!t) return false;
|
|
538
|
+
if (t.endsWith(":")) return true;
|
|
539
|
+
if (/[.!?]$/.test(t) && /\s/.test(t) && /[a-z]/.test(t) && !looksLikeCode(t) && t.split(/\s+/).length >= 3) {
|
|
540
|
+
return true;
|
|
541
|
+
}
|
|
542
|
+
return false;
|
|
543
|
+
}
|
|
399
544
|
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;
|
|
400
|
-
function isRedundantNarration(body, statementBelow, standalone) {
|
|
545
|
+
function isRedundantNarration(body, statementBelow, standalone, isolatedEnumeration, nested) {
|
|
401
546
|
const t = body.trim();
|
|
402
547
|
if (!t || looksLikeCode(t) || hasPseudocode(t)) return false;
|
|
403
548
|
if (standalone) {
|
|
404
549
|
if (STEP_NARRATION_RE.test(t)) return true;
|
|
405
550
|
if (META_COMMENTARY_RE.test(t) && !JUSTIFICATION_RE.test(t)) return true;
|
|
551
|
+
if (HELPER_OPENER_RE.test(t) || LETS_RE.test(t)) return true;
|
|
552
|
+
if (!nested && isSectionLabel(t)) return true;
|
|
553
|
+
if (isolatedEnumeration && ENUMERATION_RE.test(t)) return true;
|
|
554
|
+
}
|
|
555
|
+
return restatesStatementHead(t, statementBelow);
|
|
556
|
+
}
|
|
557
|
+
var STATEMENT_CONTAINERS = /* @__PURE__ */ new Set([
|
|
558
|
+
AST_NODE_TYPES4.Program,
|
|
559
|
+
AST_NODE_TYPES4.BlockStatement,
|
|
560
|
+
AST_NODE_TYPES4.ClassBody,
|
|
561
|
+
AST_NODE_TYPES4.StaticBlock,
|
|
562
|
+
AST_NODE_TYPES4.SwitchCase,
|
|
563
|
+
AST_NODE_TYPES4.TSModuleBlock,
|
|
564
|
+
AST_NODE_TYPES4.TSInterfaceBody
|
|
565
|
+
]);
|
|
566
|
+
function runCitesAReference(comments, index) {
|
|
567
|
+
for (let i = index; i >= 0; i--) {
|
|
568
|
+
if (i < index && !areAdjacentLineComments(comments[i], comments[i + 1])) break;
|
|
569
|
+
if (hasExternalReference(stripCommentMarker(comments[i]?.value ?? ""))) return true;
|
|
406
570
|
}
|
|
407
|
-
|
|
571
|
+
for (let i = index + 1; i < comments.length; i++) {
|
|
572
|
+
if (!areAdjacentLineComments(comments[i - 1], comments[i])) break;
|
|
573
|
+
if (hasExternalReference(stripCommentMarker(comments[i]?.value ?? ""))) return true;
|
|
574
|
+
}
|
|
575
|
+
return false;
|
|
408
576
|
}
|
|
409
577
|
function areAdjacentLineComments(a, b) {
|
|
410
578
|
return a !== void 0 && b !== void 0 && a.type === "Line" && b.type === "Line" && b.loc.start.line === a.loc.end.line + 1;
|
|
@@ -493,6 +661,9 @@ var no_comment_cruft_default = ESLintUtils3.RuleCreator(
|
|
|
493
661
|
Program() {
|
|
494
662
|
const comments = sourceCode.getAllComments();
|
|
495
663
|
const firstCodeLine = sourceCode.ast.tokens[0]?.loc.start.line ?? Number.MAX_SAFE_INTEGER;
|
|
664
|
+
const enumerated = comments.filter(
|
|
665
|
+
(c) => c.type === "Line" && ENUMERATION_RE.test(stripCommentMarker(c.value))
|
|
666
|
+
);
|
|
496
667
|
for (let i = 0; i < comments.length; i++) {
|
|
497
668
|
const comment = comments[i];
|
|
498
669
|
if (comment === void 0) continue;
|
|
@@ -513,7 +684,9 @@ var no_comment_cruft_default = ESLintUtils3.RuleCreator(
|
|
|
513
684
|
const body = texts[0];
|
|
514
685
|
const statement = restatableStatementBelow(comment, sourceCode);
|
|
515
686
|
const standalone = !isInsideCommentRun(comments, i);
|
|
516
|
-
|
|
687
|
+
const container = sourceCode.getNodeByRangeIndex(comment.range[0]);
|
|
688
|
+
const nested = container !== null && !STATEMENT_CONTAINERS.has(container.type);
|
|
689
|
+
if (body !== void 0 && !runCitesAReference(comments, i) && isRedundantNarration(body, statement, standalone, enumerated.length === 1, nested)) {
|
|
517
690
|
context.report({ node: comment, messageId: "redundantNarration" });
|
|
518
691
|
}
|
|
519
692
|
}
|
|
@@ -1212,13 +1385,13 @@ var no_raw_env_default = ESLintUtils8.RuleCreator(
|
|
|
1212
1385
|
// src/rules/no-sentinel-return-on-catch.ts
|
|
1213
1386
|
import {
|
|
1214
1387
|
ESLintUtils as ESLintUtils9,
|
|
1215
|
-
AST_NODE_TYPES as
|
|
1388
|
+
AST_NODE_TYPES as AST_NODE_TYPES5
|
|
1216
1389
|
} from "@typescript-eslint/utils";
|
|
1217
1390
|
function sentinelKind(arg) {
|
|
1218
1391
|
if (arg === null) {
|
|
1219
1392
|
return null;
|
|
1220
1393
|
}
|
|
1221
|
-
if (arg.type ===
|
|
1394
|
+
if (arg.type === AST_NODE_TYPES5.Literal) {
|
|
1222
1395
|
if (arg.value === null) {
|
|
1223
1396
|
return "nullish";
|
|
1224
1397
|
}
|
|
@@ -1230,13 +1403,13 @@ function sentinelKind(arg) {
|
|
|
1230
1403
|
}
|
|
1231
1404
|
return null;
|
|
1232
1405
|
}
|
|
1233
|
-
if (arg.type ===
|
|
1406
|
+
if (arg.type === AST_NODE_TYPES5.Identifier && arg.name === "undefined") {
|
|
1234
1407
|
return "nullish";
|
|
1235
1408
|
}
|
|
1236
|
-
if (arg.type ===
|
|
1409
|
+
if (arg.type === AST_NODE_TYPES5.ArrayExpression) {
|
|
1237
1410
|
return "array";
|
|
1238
1411
|
}
|
|
1239
|
-
if (arg.type ===
|
|
1412
|
+
if (arg.type === AST_NODE_TYPES5.ObjectExpression) {
|
|
1240
1413
|
return "object";
|
|
1241
1414
|
}
|
|
1242
1415
|
return null;
|
|
@@ -1245,25 +1418,25 @@ function isSentinelArgument(arg) {
|
|
|
1245
1418
|
if (arg === null) {
|
|
1246
1419
|
return false;
|
|
1247
1420
|
}
|
|
1248
|
-
if (arg.type ===
|
|
1421
|
+
if (arg.type === AST_NODE_TYPES5.Literal && arg.value === null) {
|
|
1249
1422
|
return true;
|
|
1250
1423
|
}
|
|
1251
|
-
if (arg.type ===
|
|
1424
|
+
if (arg.type === AST_NODE_TYPES5.Literal && arg.value === false) {
|
|
1252
1425
|
return true;
|
|
1253
1426
|
}
|
|
1254
|
-
if (arg.type ===
|
|
1427
|
+
if (arg.type === AST_NODE_TYPES5.Identifier && arg.name === "undefined") {
|
|
1255
1428
|
return true;
|
|
1256
1429
|
}
|
|
1257
|
-
if (arg.type ===
|
|
1430
|
+
if (arg.type === AST_NODE_TYPES5.ArrayExpression && arg.elements.length === 0) {
|
|
1258
1431
|
return true;
|
|
1259
1432
|
}
|
|
1260
|
-
if (arg.type ===
|
|
1433
|
+
if (arg.type === AST_NODE_TYPES5.ObjectExpression && arg.properties.length === 0) {
|
|
1261
1434
|
return true;
|
|
1262
1435
|
}
|
|
1263
1436
|
return false;
|
|
1264
1437
|
}
|
|
1265
1438
|
function isFunctionNode(node) {
|
|
1266
|
-
return node.type ===
|
|
1439
|
+
return node.type === AST_NODE_TYPES5.FunctionDeclaration || node.type === AST_NODE_TYPES5.FunctionExpression || node.type === AST_NODE_TYPES5.ArrowFunctionExpression;
|
|
1267
1440
|
}
|
|
1268
1441
|
function isNode(value) {
|
|
1269
1442
|
return typeof value === "object" && value !== null && typeof value.type === "string";
|
|
@@ -1303,24 +1476,24 @@ function walkWithinScope(node, visit) {
|
|
|
1303
1476
|
function containsThrow(node) {
|
|
1304
1477
|
return walkWithinScope(
|
|
1305
1478
|
node,
|
|
1306
|
-
(current) => current.type ===
|
|
1479
|
+
(current) => current.type === AST_NODE_TYPES5.ThrowStatement
|
|
1307
1480
|
);
|
|
1308
1481
|
}
|
|
1309
1482
|
function bindsName(param, name) {
|
|
1310
1483
|
switch (param.type) {
|
|
1311
|
-
case
|
|
1484
|
+
case AST_NODE_TYPES5.Identifier:
|
|
1312
1485
|
return param.name === name;
|
|
1313
|
-
case
|
|
1486
|
+
case AST_NODE_TYPES5.AssignmentPattern:
|
|
1314
1487
|
return bindsName(param.left, name);
|
|
1315
|
-
case
|
|
1488
|
+
case AST_NODE_TYPES5.RestElement:
|
|
1316
1489
|
return bindsName(param.argument, name);
|
|
1317
|
-
case
|
|
1490
|
+
case AST_NODE_TYPES5.ArrayPattern:
|
|
1318
1491
|
return param.elements.some(
|
|
1319
1492
|
(element) => element !== null && bindsName(element, name)
|
|
1320
1493
|
);
|
|
1321
|
-
case
|
|
1494
|
+
case AST_NODE_TYPES5.ObjectPattern:
|
|
1322
1495
|
return param.properties.some(
|
|
1323
|
-
(property) => property.type ===
|
|
1496
|
+
(property) => property.type === AST_NODE_TYPES5.RestElement ? bindsName(property.argument, name) : bindsName(property.value, name)
|
|
1324
1497
|
);
|
|
1325
1498
|
default:
|
|
1326
1499
|
return false;
|
|
@@ -1335,7 +1508,7 @@ function subtreeReadsName(node, name) {
|
|
|
1335
1508
|
if (found) {
|
|
1336
1509
|
return;
|
|
1337
1510
|
}
|
|
1338
|
-
if (current.type ===
|
|
1511
|
+
if (current.type === AST_NODE_TYPES5.Identifier && current.name === name) {
|
|
1339
1512
|
found = true;
|
|
1340
1513
|
return;
|
|
1341
1514
|
}
|
|
@@ -1346,10 +1519,10 @@ function subtreeReadsName(node, name) {
|
|
|
1346
1519
|
if (key === "parent") {
|
|
1347
1520
|
continue;
|
|
1348
1521
|
}
|
|
1349
|
-
if (key === "key" && current.type ===
|
|
1522
|
+
if (key === "key" && current.type === AST_NODE_TYPES5.Property && !current.computed) {
|
|
1350
1523
|
continue;
|
|
1351
1524
|
}
|
|
1352
|
-
if (key === "property" && current.type ===
|
|
1525
|
+
if (key === "property" && current.type === AST_NODE_TYPES5.MemberExpression && !current.computed) {
|
|
1353
1526
|
continue;
|
|
1354
1527
|
}
|
|
1355
1528
|
const value = current[key];
|
|
@@ -1382,10 +1555,10 @@ var SAFE_PARSE_CONSTRUCTORS = /* @__PURE__ */ new Set([
|
|
|
1382
1555
|
"URLPattern"
|
|
1383
1556
|
]);
|
|
1384
1557
|
function isParseShapedNode(node) {
|
|
1385
|
-
if (node.type ===
|
|
1558
|
+
if (node.type === AST_NODE_TYPES5.CallExpression && node.callee.type === AST_NODE_TYPES5.MemberExpression && !node.callee.computed && node.callee.property.type === AST_NODE_TYPES5.Identifier) {
|
|
1386
1559
|
return node.callee.property.name === "parse";
|
|
1387
1560
|
}
|
|
1388
|
-
if (node.type ===
|
|
1561
|
+
if (node.type === AST_NODE_TYPES5.NewExpression && node.callee.type === AST_NODE_TYPES5.Identifier) {
|
|
1389
1562
|
return SAFE_PARSE_CONSTRUCTORS.has(node.callee.name);
|
|
1390
1563
|
}
|
|
1391
1564
|
return false;
|
|
@@ -1396,10 +1569,10 @@ var BODY_DECODE_METHODS = /* @__PURE__ */ new Set([
|
|
|
1396
1569
|
"arrayBuffer"
|
|
1397
1570
|
]);
|
|
1398
1571
|
function isBodyDecodeNode(node) {
|
|
1399
|
-
return node.type ===
|
|
1572
|
+
return node.type === AST_NODE_TYPES5.CallExpression && node.callee.type === AST_NODE_TYPES5.MemberExpression && !node.callee.computed && node.callee.property.type === AST_NODE_TYPES5.Identifier && BODY_DECODE_METHODS.has(node.callee.property.name);
|
|
1400
1573
|
}
|
|
1401
1574
|
function returnsMatching(stmt, predicate) {
|
|
1402
|
-
return stmt.type ===
|
|
1575
|
+
return stmt.type === AST_NODE_TYPES5.ReturnStatement && stmt.argument !== null && walkWithinScope(stmt.argument, predicate);
|
|
1403
1576
|
}
|
|
1404
1577
|
function enclosingReturnTypeNode(node) {
|
|
1405
1578
|
let current = node.parent;
|
|
@@ -1417,11 +1590,11 @@ function enclosingFunctionName(node) {
|
|
|
1417
1590
|
let current = node.parent;
|
|
1418
1591
|
while (current !== void 0 && current !== null) {
|
|
1419
1592
|
if (isFunctionNode(current)) {
|
|
1420
|
-
if ("id" in current && isNode(current.id) && current.id.type ===
|
|
1593
|
+
if ("id" in current && isNode(current.id) && current.id.type === AST_NODE_TYPES5.Identifier) {
|
|
1421
1594
|
return current.id.name;
|
|
1422
1595
|
}
|
|
1423
1596
|
const parent = current.parent;
|
|
1424
|
-
if (parent?.type ===
|
|
1597
|
+
if (parent?.type === AST_NODE_TYPES5.VariableDeclarator && parent.id.type === AST_NODE_TYPES5.Identifier) {
|
|
1425
1598
|
return parent.id.name;
|
|
1426
1599
|
}
|
|
1427
1600
|
return null;
|
|
@@ -1442,10 +1615,10 @@ function isDeclaredBooleanPredicate(catchNode, kind) {
|
|
|
1442
1615
|
return false;
|
|
1443
1616
|
}
|
|
1444
1617
|
let declared = enclosingReturnTypeNode(catchNode);
|
|
1445
|
-
if (declared?.type ===
|
|
1618
|
+
if (declared?.type === AST_NODE_TYPES5.TSTypeReference && declared.typeName.type === AST_NODE_TYPES5.Identifier && declared.typeName.name === "Promise") {
|
|
1446
1619
|
declared = declared.typeArguments?.params[0] ?? null;
|
|
1447
1620
|
}
|
|
1448
|
-
return declared?.type ===
|
|
1621
|
+
return declared?.type === AST_NODE_TYPES5.TSBooleanKeyword;
|
|
1449
1622
|
}
|
|
1450
1623
|
function tryReturnsSafeParse(catchNode) {
|
|
1451
1624
|
const tryBlock = tryBlockOf(catchNode);
|
|
@@ -1461,7 +1634,7 @@ function tryReturnsSafeParse(catchNode) {
|
|
|
1461
1634
|
function enclosingFunctionBody(node) {
|
|
1462
1635
|
let current = node.parent;
|
|
1463
1636
|
while (current !== void 0 && current !== null) {
|
|
1464
|
-
if (isFunctionNode(current) && "body" in current && isNode(current.body) && current.body.type ===
|
|
1637
|
+
if (isFunctionNode(current) && "body" in current && isNode(current.body) && current.body.type === AST_NODE_TYPES5.BlockStatement) {
|
|
1465
1638
|
return current.body;
|
|
1466
1639
|
}
|
|
1467
1640
|
current = current.parent;
|
|
@@ -1474,7 +1647,7 @@ function functionReturnsSameSentinelKindElsewhere(catchNode, kind) {
|
|
|
1474
1647
|
return false;
|
|
1475
1648
|
}
|
|
1476
1649
|
return walkWithinScope(functionBody, (current) => {
|
|
1477
|
-
if (current.type !==
|
|
1650
|
+
if (current.type !== AST_NODE_TYPES5.ReturnStatement) {
|
|
1478
1651
|
return false;
|
|
1479
1652
|
}
|
|
1480
1653
|
if (isWithin(current, catchNode.body)) {
|
|
@@ -1493,13 +1666,13 @@ function returnedSentinelKinds(arg) {
|
|
|
1493
1666
|
kinds.add(direct);
|
|
1494
1667
|
return kinds;
|
|
1495
1668
|
}
|
|
1496
|
-
if (arg.type ===
|
|
1669
|
+
if (arg.type === AST_NODE_TYPES5.ConditionalExpression) {
|
|
1497
1670
|
for (const branch of [arg.consequent, arg.alternate]) {
|
|
1498
1671
|
for (const nested of returnedSentinelKinds(branch)) {
|
|
1499
1672
|
kinds.add(nested);
|
|
1500
1673
|
}
|
|
1501
1674
|
}
|
|
1502
|
-
} else if (arg.type ===
|
|
1675
|
+
} else if (arg.type === AST_NODE_TYPES5.LogicalExpression && (arg.operator === "??" || arg.operator === "||")) {
|
|
1503
1676
|
for (const nested of returnedSentinelKinds(arg.right)) {
|
|
1504
1677
|
kinds.add(nested);
|
|
1505
1678
|
}
|
|
@@ -1544,7 +1717,7 @@ var no_sentinel_return_on_catch_default = ESLintUtils9.RuleCreator(
|
|
|
1544
1717
|
const matcher = createLogMatcher(loggingOptions);
|
|
1545
1718
|
function logsOrReportsError(catchBody, caughtName) {
|
|
1546
1719
|
return walkWithinScope(catchBody, (current) => {
|
|
1547
|
-
if (current.type !==
|
|
1720
|
+
if (current.type !== AST_NODE_TYPES5.CallExpression) {
|
|
1548
1721
|
return false;
|
|
1549
1722
|
}
|
|
1550
1723
|
if (matcher.isLoggingCall(current)) {
|
|
@@ -1561,7 +1734,7 @@ var no_sentinel_return_on_catch_default = ESLintUtils9.RuleCreator(
|
|
|
1561
1734
|
return;
|
|
1562
1735
|
}
|
|
1563
1736
|
const last = body[body.length - 1];
|
|
1564
|
-
if (last === void 0 || last.type !==
|
|
1737
|
+
if (last === void 0 || last.type !== AST_NODE_TYPES5.ReturnStatement) {
|
|
1565
1738
|
return;
|
|
1566
1739
|
}
|
|
1567
1740
|
if (!isSentinelArgument(last.argument)) {
|
|
@@ -1570,7 +1743,7 @@ var no_sentinel_return_on_catch_default = ESLintUtils9.RuleCreator(
|
|
|
1570
1743
|
if (containsThrow(node.body)) {
|
|
1571
1744
|
return;
|
|
1572
1745
|
}
|
|
1573
|
-
const caughtName = node.param?.type ===
|
|
1746
|
+
const caughtName = node.param?.type === AST_NODE_TYPES5.Identifier ? node.param.name : null;
|
|
1574
1747
|
if (logsOrReportsError(node.body, caughtName)) {
|
|
1575
1748
|
return;
|
|
1576
1749
|
}
|
|
@@ -1995,7 +2168,7 @@ var no_string_concat_in_loop_default = ESLintUtils11.RuleCreator(
|
|
|
1995
2168
|
|
|
1996
2169
|
// src/rules/no-unnecessary-use-client.ts
|
|
1997
2170
|
import {
|
|
1998
|
-
AST_NODE_TYPES as
|
|
2171
|
+
AST_NODE_TYPES as AST_NODE_TYPES6,
|
|
1999
2172
|
ESLintUtils as ESLintUtils12
|
|
2000
2173
|
} from "@typescript-eslint/utils";
|
|
2001
2174
|
var HOOK_REGEX = /^use([A-Z]|$)/;
|
|
@@ -2023,13 +2196,13 @@ var CLIENT_ONLY_PACKAGES_REGEX = /^(?:@radix-ui\/|framer-motion|react-dom|react-
|
|
|
2023
2196
|
var isBareSpecifier = (source) => !source.startsWith(".") && !source.startsWith("/") && !source.startsWith("@/") && !source.startsWith("~");
|
|
2024
2197
|
var jsxRootName = (name) => {
|
|
2025
2198
|
let current = name;
|
|
2026
|
-
while (current.type ===
|
|
2199
|
+
while (current.type === AST_NODE_TYPES6.JSXMemberExpression) {
|
|
2027
2200
|
current = current.object;
|
|
2028
2201
|
}
|
|
2029
|
-
return current.type ===
|
|
2202
|
+
return current.type === AST_NODE_TYPES6.JSXIdentifier ? current.name : "";
|
|
2030
2203
|
};
|
|
2031
2204
|
var subtreeReadsImportedBinding = (node, imported) => {
|
|
2032
|
-
if (node.type ===
|
|
2205
|
+
if (node.type === AST_NODE_TYPES6.Identifier) {
|
|
2033
2206
|
return imported.has(node.name);
|
|
2034
2207
|
}
|
|
2035
2208
|
for (const key of Object.keys(node)) {
|
|
@@ -2044,16 +2217,16 @@ var subtreeReadsImportedBinding = (node, imported) => {
|
|
|
2044
2217
|
return false;
|
|
2045
2218
|
};
|
|
2046
2219
|
var isUseClientDirective = (node) => {
|
|
2047
|
-
return node.type ===
|
|
2220
|
+
return node.type === AST_NODE_TYPES6.ExpressionStatement && node.expression.type === AST_NODE_TYPES6.Literal && node.expression.value === "use client";
|
|
2048
2221
|
};
|
|
2049
2222
|
var isGlobalReference = (node, context) => {
|
|
2050
2223
|
if (!BROWSER_GLOBALS.has(node.name)) return false;
|
|
2051
2224
|
const parent = node.parent;
|
|
2052
2225
|
if (parent !== void 0) {
|
|
2053
|
-
if (parent.type ===
|
|
2226
|
+
if (parent.type === AST_NODE_TYPES6.MemberExpression && parent.property === node && !parent.computed) {
|
|
2054
2227
|
return false;
|
|
2055
2228
|
}
|
|
2056
|
-
if (parent.type ===
|
|
2229
|
+
if (parent.type === AST_NODE_TYPES6.Property && parent.key === node && !parent.computed) {
|
|
2057
2230
|
return false;
|
|
2058
2231
|
}
|
|
2059
2232
|
if (parent.type.startsWith("TS")) {
|
|
@@ -2095,13 +2268,13 @@ var no_unnecessary_use_client_default = ESLintUtils12.RuleCreator(
|
|
|
2095
2268
|
const importedLocals = /* @__PURE__ */ new Set();
|
|
2096
2269
|
const externalLocals = /* @__PURE__ */ new Set();
|
|
2097
2270
|
const markIfHookOrContext = (callee) => {
|
|
2098
|
-
if (callee.type ===
|
|
2271
|
+
if (callee.type === AST_NODE_TYPES6.Identifier) {
|
|
2099
2272
|
if (HOOK_REGEX.test(callee.name) || callee.name === "createContext") {
|
|
2100
2273
|
hasClientIndicator = true;
|
|
2101
2274
|
}
|
|
2102
2275
|
return;
|
|
2103
2276
|
}
|
|
2104
|
-
if (callee.type ===
|
|
2277
|
+
if (callee.type === AST_NODE_TYPES6.MemberExpression && callee.property.type === AST_NODE_TYPES6.Identifier) {
|
|
2105
2278
|
const name = callee.property.name;
|
|
2106
2279
|
if (HOOK_REGEX.test(name) || name === "createContext") {
|
|
2107
2280
|
hasClientIndicator = true;
|
|
@@ -2111,7 +2284,7 @@ var no_unnecessary_use_client_default = ESLintUtils12.RuleCreator(
|
|
|
2111
2284
|
return {
|
|
2112
2285
|
Program(node) {
|
|
2113
2286
|
for (const stmt of node.body) {
|
|
2114
|
-
if (stmt.type !==
|
|
2287
|
+
if (stmt.type !== AST_NODE_TYPES6.ExpressionStatement) break;
|
|
2115
2288
|
if (isUseClientDirective(stmt)) {
|
|
2116
2289
|
directiveNode = stmt;
|
|
2117
2290
|
break;
|
|
@@ -2124,7 +2297,7 @@ var no_unnecessary_use_client_default = ESLintUtils12.RuleCreator(
|
|
|
2124
2297
|
},
|
|
2125
2298
|
JSXAttribute(node) {
|
|
2126
2299
|
if (directiveNode === null) return;
|
|
2127
|
-
if (node.name.type ===
|
|
2300
|
+
if (node.name.type === AST_NODE_TYPES6.JSXIdentifier && EVENT_PROP_REGEX.test(node.name.name)) {
|
|
2128
2301
|
hasClientIndicator = true;
|
|
2129
2302
|
}
|
|
2130
2303
|
},
|
|
@@ -2192,7 +2365,7 @@ var no_unnecessary_use_client_default = ESLintUtils12.RuleCreator(
|
|
|
2192
2365
|
|
|
2193
2366
|
// src/rules/prefer-discriminated-union.ts
|
|
2194
2367
|
import { ESLintUtils as ESLintUtils13 } from "@typescript-eslint/utils";
|
|
2195
|
-
import { AST_NODE_TYPES as
|
|
2368
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES7 } from "@typescript-eslint/utils";
|
|
2196
2369
|
var STATUS_MEMBER_NAMES = /* @__PURE__ */ new Set([
|
|
2197
2370
|
"success",
|
|
2198
2371
|
"ok",
|
|
@@ -2202,27 +2375,27 @@ var STATUS_MEMBER_NAMES = /* @__PURE__ */ new Set([
|
|
|
2202
2375
|
]);
|
|
2203
2376
|
var MIN_OPTIONAL_MEMBERS = 2;
|
|
2204
2377
|
function getMemberName(member) {
|
|
2205
|
-
if (member.type !==
|
|
2378
|
+
if (member.type !== AST_NODE_TYPES7.TSPropertySignature) {
|
|
2206
2379
|
return null;
|
|
2207
2380
|
}
|
|
2208
2381
|
const { key } = member;
|
|
2209
|
-
if (key.type ===
|
|
2382
|
+
if (key.type === AST_NODE_TYPES7.Identifier) {
|
|
2210
2383
|
return key.name;
|
|
2211
2384
|
}
|
|
2212
|
-
if (key.type ===
|
|
2385
|
+
if (key.type === AST_NODE_TYPES7.Literal && typeof key.value === "string") {
|
|
2213
2386
|
return key.value;
|
|
2214
2387
|
}
|
|
2215
2388
|
return null;
|
|
2216
2389
|
}
|
|
2217
2390
|
function isBooleanTyped(member) {
|
|
2218
|
-
return member.typeAnnotation?.typeAnnotation.type ===
|
|
2391
|
+
return member.typeAnnotation?.typeAnnotation.type === AST_NODE_TYPES7.TSBooleanKeyword;
|
|
2219
2392
|
}
|
|
2220
2393
|
function looksLikeMutuallyExclusiveState(typeLiteral) {
|
|
2221
2394
|
let hasStatusBoolean = false;
|
|
2222
2395
|
let optionalCount = 0;
|
|
2223
2396
|
let optionalPayloadCount = 0;
|
|
2224
2397
|
for (const member of typeLiteral.members) {
|
|
2225
|
-
if (member.type !==
|
|
2398
|
+
if (member.type !== AST_NODE_TYPES7.TSPropertySignature) {
|
|
2226
2399
|
continue;
|
|
2227
2400
|
}
|
|
2228
2401
|
if (member.optional) {
|
|
@@ -2266,7 +2439,7 @@ var prefer_discriminated_union_default = ESLintUtils13.RuleCreator(
|
|
|
2266
2439
|
TSInterfaceDeclaration(node) {
|
|
2267
2440
|
const synthetic = {
|
|
2268
2441
|
...node.body,
|
|
2269
|
-
type:
|
|
2442
|
+
type: AST_NODE_TYPES7.TSTypeLiteral,
|
|
2270
2443
|
members: node.body.body
|
|
2271
2444
|
};
|
|
2272
2445
|
checkTypeLiteral(synthetic, node);
|
|
@@ -2280,15 +2453,15 @@ var prefer_discriminated_union_default = ESLintUtils13.RuleCreator(
|
|
|
2280
2453
|
|
|
2281
2454
|
// src/rules/prefer-schema-for-api-payload.ts
|
|
2282
2455
|
import {
|
|
2283
|
-
AST_NODE_TYPES as
|
|
2456
|
+
AST_NODE_TYPES as AST_NODE_TYPES8,
|
|
2284
2457
|
ESLintUtils as ESLintUtils14
|
|
2285
2458
|
} from "@typescript-eslint/utils";
|
|
2286
2459
|
var unwrap = (node) => {
|
|
2287
2460
|
let current = node;
|
|
2288
2461
|
while (current !== null && current !== void 0) {
|
|
2289
|
-
if (current.type ===
|
|
2462
|
+
if (current.type === AST_NODE_TYPES8.TSAsExpression || current.type === AST_NODE_TYPES8.TSTypeAssertion || current.type === AST_NODE_TYPES8.TSNonNullExpression || current.type === AST_NODE_TYPES8.TSSatisfiesExpression) {
|
|
2290
2463
|
current = current.expression;
|
|
2291
|
-
} else if (current.type ===
|
|
2464
|
+
} else if (current.type === AST_NODE_TYPES8.ChainExpression) {
|
|
2292
2465
|
current = current.expression;
|
|
2293
2466
|
} else {
|
|
2294
2467
|
break;
|
|
@@ -2299,25 +2472,25 @@ var unwrap = (node) => {
|
|
|
2299
2472
|
var isRawPayloadSource = (node) => {
|
|
2300
2473
|
let current = unwrap(node);
|
|
2301
2474
|
if (current === null) return false;
|
|
2302
|
-
if (current.type ===
|
|
2475
|
+
if (current.type === AST_NODE_TYPES8.AwaitExpression) {
|
|
2303
2476
|
current = unwrap(current.argument);
|
|
2304
2477
|
}
|
|
2305
|
-
if (current === null || current.type !==
|
|
2478
|
+
if (current === null || current.type !== AST_NODE_TYPES8.CallExpression) {
|
|
2306
2479
|
return false;
|
|
2307
2480
|
}
|
|
2308
2481
|
const callee = unwrap(current.callee);
|
|
2309
|
-
if (callee === null || callee.type !==
|
|
2482
|
+
if (callee === null || callee.type !== AST_NODE_TYPES8.MemberExpression) {
|
|
2310
2483
|
return false;
|
|
2311
2484
|
}
|
|
2312
2485
|
const property = unwrap(callee.property);
|
|
2313
|
-
if (property === null || property.type !==
|
|
2486
|
+
if (property === null || property.type !== AST_NODE_TYPES8.Identifier) {
|
|
2314
2487
|
return false;
|
|
2315
2488
|
}
|
|
2316
2489
|
if (property.name === "json") {
|
|
2317
2490
|
return true;
|
|
2318
2491
|
}
|
|
2319
2492
|
const object = unwrap(callee.object);
|
|
2320
|
-
return property.name === "parse" && object !== null && object.type ===
|
|
2493
|
+
return property.name === "parse" && object !== null && object.type === AST_NODE_TYPES8.Identifier && object.name === "JSON" && // ...but not `JSON.parse(readFileSync(p, "utf8"))` — see isLocalFileRead.
|
|
2321
2494
|
!isLocalFileRead(current.arguments[0]);
|
|
2322
2495
|
};
|
|
2323
2496
|
var FILE_READ_RE = /^(readFile|readFileSync|readJson|readJsonSync|readJSON)$/;
|
|
@@ -2325,9 +2498,9 @@ var isLocalFileRead = (node) => {
|
|
|
2325
2498
|
let found = false;
|
|
2326
2499
|
const visit = (current) => {
|
|
2327
2500
|
if (found || current === null || current === void 0) return;
|
|
2328
|
-
if (current.type ===
|
|
2501
|
+
if (current.type === AST_NODE_TYPES8.CallExpression) {
|
|
2329
2502
|
const callee = unwrap(current.callee);
|
|
2330
|
-
const name = callee?.type ===
|
|
2503
|
+
const name = callee?.type === AST_NODE_TYPES8.Identifier ? callee.name : callee?.type === AST_NODE_TYPES8.MemberExpression && !callee.computed && callee.property.type === AST_NODE_TYPES8.Identifier ? callee.property.name : null;
|
|
2331
2504
|
if (name !== null && FILE_READ_RE.test(name)) {
|
|
2332
2505
|
found = true;
|
|
2333
2506
|
return;
|
|
@@ -2349,15 +2522,15 @@ var isLocalFileRead = (node) => {
|
|
|
2349
2522
|
var ASSERTION_CALLEE_RE2 = /^(expect|assert|should|invariant)$/;
|
|
2350
2523
|
var isInsideAssertion = (node) => {
|
|
2351
2524
|
for (let current = node.parent; current !== void 0 && current !== null; current = current.parent) {
|
|
2352
|
-
if (current.type !==
|
|
2525
|
+
if (current.type !== AST_NODE_TYPES8.CallExpression) continue;
|
|
2353
2526
|
let callee = current.callee;
|
|
2354
|
-
while (callee.type ===
|
|
2527
|
+
while (callee.type === AST_NODE_TYPES8.MemberExpression) {
|
|
2355
2528
|
callee = callee.object;
|
|
2356
2529
|
}
|
|
2357
|
-
if (callee.type ===
|
|
2530
|
+
if (callee.type === AST_NODE_TYPES8.CallExpression) {
|
|
2358
2531
|
callee = callee.callee;
|
|
2359
2532
|
}
|
|
2360
|
-
if (callee.type ===
|
|
2533
|
+
if (callee.type === AST_NODE_TYPES8.Identifier && ASSERTION_CALLEE_RE2.test(callee.name)) {
|
|
2361
2534
|
return true;
|
|
2362
2535
|
}
|
|
2363
2536
|
}
|
|
@@ -2378,17 +2551,17 @@ var isGuardTestPosition = (node) => {
|
|
|
2378
2551
|
let parent = current.parent;
|
|
2379
2552
|
while (parent !== void 0 && parent !== null) {
|
|
2380
2553
|
switch (parent.type) {
|
|
2381
|
-
case
|
|
2382
|
-
case
|
|
2383
|
-
case
|
|
2554
|
+
case AST_NODE_TYPES8.UnaryExpression:
|
|
2555
|
+
case AST_NODE_TYPES8.LogicalExpression:
|
|
2556
|
+
case AST_NODE_TYPES8.ChainExpression:
|
|
2384
2557
|
current = parent;
|
|
2385
2558
|
parent = parent.parent;
|
|
2386
2559
|
continue;
|
|
2387
|
-
case
|
|
2388
|
-
case
|
|
2389
|
-
case
|
|
2390
|
-
case
|
|
2391
|
-
case
|
|
2560
|
+
case AST_NODE_TYPES8.IfStatement:
|
|
2561
|
+
case AST_NODE_TYPES8.ConditionalExpression:
|
|
2562
|
+
case AST_NODE_TYPES8.WhileStatement:
|
|
2563
|
+
case AST_NODE_TYPES8.DoWhileStatement:
|
|
2564
|
+
case AST_NODE_TYPES8.ForStatement:
|
|
2392
2565
|
return parent.test === current;
|
|
2393
2566
|
default:
|
|
2394
2567
|
return false;
|
|
@@ -2398,7 +2571,7 @@ var isGuardTestPosition = (node) => {
|
|
|
2398
2571
|
};
|
|
2399
2572
|
var isUnvalidatedVariableRef = (node, scope, tracked) => {
|
|
2400
2573
|
const unwrapped = unwrap(node);
|
|
2401
|
-
if (unwrapped === null || unwrapped.type !==
|
|
2574
|
+
if (unwrapped === null || unwrapped.type !== AST_NODE_TYPES8.Identifier) {
|
|
2402
2575
|
return false;
|
|
2403
2576
|
}
|
|
2404
2577
|
const variable = findVariable2(scope, unwrapped.name);
|
|
@@ -2435,11 +2608,11 @@ var prefer_schema_for_api_payload_default = ESLintUtils14.RuleCreator(
|
|
|
2435
2608
|
return {
|
|
2436
2609
|
VariableDeclarator(node) {
|
|
2437
2610
|
const scope = context.sourceCode.getScope(node);
|
|
2438
|
-
if (node.id.type ===
|
|
2611
|
+
if (node.id.type === AST_NODE_TYPES8.Identifier) {
|
|
2439
2612
|
trackInitializer(node);
|
|
2440
2613
|
return;
|
|
2441
2614
|
}
|
|
2442
|
-
if (node.id.type ===
|
|
2615
|
+
if (node.id.type === AST_NODE_TYPES8.ObjectPattern || node.id.type === AST_NODE_TYPES8.ArrayPattern) {
|
|
2443
2616
|
if (isRawPayloadSource(node.init)) {
|
|
2444
2617
|
context.report({ node: node.id, messageId: "unparsedJsonAccess" });
|
|
2445
2618
|
return;
|
|
@@ -2451,7 +2624,7 @@ var prefer_schema_for_api_payload_default = ESLintUtils14.RuleCreator(
|
|
|
2451
2624
|
},
|
|
2452
2625
|
AssignmentExpression(node) {
|
|
2453
2626
|
const scope = context.sourceCode.getScope(node);
|
|
2454
|
-
if (node.left.type ===
|
|
2627
|
+
if (node.left.type === AST_NODE_TYPES8.Identifier) {
|
|
2455
2628
|
const variable = findVariable2(scope, node.left.name);
|
|
2456
2629
|
if (variable === null) return;
|
|
2457
2630
|
if (isRawPayloadSource(node.right)) {
|
|
@@ -2461,7 +2634,7 @@ var prefer_schema_for_api_payload_default = ESLintUtils14.RuleCreator(
|
|
|
2461
2634
|
}
|
|
2462
2635
|
return;
|
|
2463
2636
|
}
|
|
2464
|
-
if (node.left.type ===
|
|
2637
|
+
if (node.left.type === AST_NODE_TYPES8.ObjectPattern || node.left.type === AST_NODE_TYPES8.ArrayPattern) {
|
|
2465
2638
|
if (isRawPayloadSource(node.right)) {
|
|
2466
2639
|
context.report({
|
|
2467
2640
|
node: node.left,
|
|
@@ -2478,15 +2651,15 @@ var prefer_schema_for_api_payload_default = ESLintUtils14.RuleCreator(
|
|
|
2478
2651
|
}
|
|
2479
2652
|
},
|
|
2480
2653
|
CallExpression(node) {
|
|
2481
|
-
if (node.callee.type !==
|
|
2654
|
+
if (node.callee.type !== AST_NODE_TYPES8.Identifier) return;
|
|
2482
2655
|
if (!GUARD_NAME_RE.test(node.callee.name) && !isGuardTestPosition(node)) {
|
|
2483
2656
|
return;
|
|
2484
2657
|
}
|
|
2485
2658
|
const scope = context.sourceCode.getScope(node);
|
|
2486
2659
|
for (const arg of node.arguments) {
|
|
2487
|
-
if (arg.type ===
|
|
2660
|
+
if (arg.type === AST_NODE_TYPES8.SpreadElement) continue;
|
|
2488
2661
|
const unwrapped = unwrap(arg);
|
|
2489
|
-
if (unwrapped === null || unwrapped.type !==
|
|
2662
|
+
if (unwrapped === null || unwrapped.type !== AST_NODE_TYPES8.Identifier) {
|
|
2490
2663
|
continue;
|
|
2491
2664
|
}
|
|
2492
2665
|
const variable = findVariable2(scope, unwrapped.name);
|
|
@@ -2499,13 +2672,13 @@ var prefer_schema_for_api_payload_default = ESLintUtils14.RuleCreator(
|
|
|
2499
2672
|
const obj = unwrap(node.object);
|
|
2500
2673
|
if (isRawPayloadSource(obj)) {
|
|
2501
2674
|
const parent = node.parent;
|
|
2502
|
-
if (parent.type ===
|
|
2675
|
+
if (parent.type === AST_NODE_TYPES8.CallExpression && parent.callee === node && node.property.type === AST_NODE_TYPES8.Identifier && (node.property.name === "parse" || node.property.name === "safeParse")) {
|
|
2503
2676
|
return;
|
|
2504
2677
|
}
|
|
2505
2678
|
context.report({ node, messageId: "unparsedJsonAccess" });
|
|
2506
2679
|
return;
|
|
2507
2680
|
}
|
|
2508
|
-
if (obj !== null && obj.type ===
|
|
2681
|
+
if (obj !== null && obj.type === AST_NODE_TYPES8.Identifier && isUnvalidatedVariableRef(obj, scope, unvalidatedVariables)) {
|
|
2509
2682
|
context.report({ node, messageId: "unparsedJsonAccess" });
|
|
2510
2683
|
const variable = findVariable2(scope, obj.name);
|
|
2511
2684
|
if (variable !== null) {
|
|
@@ -2518,7 +2691,7 @@ var prefer_schema_for_api_payload_default = ESLintUtils14.RuleCreator(
|
|
|
2518
2691
|
});
|
|
2519
2692
|
|
|
2520
2693
|
// src/rules/prefer-semantic-colors.ts
|
|
2521
|
-
import { AST_NODE_TYPES as
|
|
2694
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES9, ESLintUtils as ESLintUtils15 } from "@typescript-eslint/utils";
|
|
2522
2695
|
import { existsSync, readFileSync } from "fs";
|
|
2523
2696
|
import { dirname, join, parse } from "path";
|
|
2524
2697
|
|
|
@@ -2592,8 +2765,8 @@ var SVG_EXEMPT_COLOR_VALUES = /* @__PURE__ */ new Set([
|
|
|
2592
2765
|
]);
|
|
2593
2766
|
function jsxElementName(node) {
|
|
2594
2767
|
const name = node.openingElement.name;
|
|
2595
|
-
if (name.type ===
|
|
2596
|
-
if (name.type ===
|
|
2768
|
+
if (name.type === AST_NODE_TYPES9.JSXIdentifier) return name.name;
|
|
2769
|
+
if (name.type === AST_NODE_TYPES9.JSXMemberExpression && name.property.type === AST_NODE_TYPES9.JSXIdentifier) {
|
|
2597
2770
|
return name.property.name;
|
|
2598
2771
|
}
|
|
2599
2772
|
return null;
|
|
@@ -2604,7 +2777,7 @@ function isSvgLikeElementName(name) {
|
|
|
2604
2777
|
var isInsideSvg = (node) => {
|
|
2605
2778
|
let current = node.parent;
|
|
2606
2779
|
while (current !== void 0 && current !== null) {
|
|
2607
|
-
if (current.type ===
|
|
2780
|
+
if (current.type === AST_NODE_TYPES9.JSXElement) {
|
|
2608
2781
|
const name = jsxElementName(current);
|
|
2609
2782
|
if (name !== null && isSvgLikeElementName(name)) return true;
|
|
2610
2783
|
}
|
|
@@ -2615,7 +2788,7 @@ var isInsideSvg = (node) => {
|
|
|
2615
2788
|
var isInsideIconFactoryPath = (node) => {
|
|
2616
2789
|
let current = node.parent;
|
|
2617
2790
|
while (current !== void 0 && current !== null) {
|
|
2618
|
-
if (current.type ===
|
|
2791
|
+
if (current.type === AST_NODE_TYPES9.Property && propName(current.key) === "path" && current.parent.type === AST_NODE_TYPES9.ObjectExpression && current.parent.parent.type === AST_NODE_TYPES9.CallExpression && current.parent.parent.callee.type === AST_NODE_TYPES9.Identifier && current.parent.parent.callee.name === "createIcon") {
|
|
2619
2792
|
return true;
|
|
2620
2793
|
}
|
|
2621
2794
|
current = current.parent;
|
|
@@ -2651,8 +2824,8 @@ var hasSemanticTokenSystem = (filename) => {
|
|
|
2651
2824
|
return false;
|
|
2652
2825
|
};
|
|
2653
2826
|
var propName = (key) => {
|
|
2654
|
-
if (key.type ===
|
|
2655
|
-
if (key.type ===
|
|
2827
|
+
if (key.type === AST_NODE_TYPES9.Identifier) return key.name;
|
|
2828
|
+
if (key.type === AST_NODE_TYPES9.Literal && typeof key.value === "string") return key.value;
|
|
2656
2829
|
return null;
|
|
2657
2830
|
};
|
|
2658
2831
|
var prefer_semantic_colors_default = ESLintUtils15.RuleCreator(
|
|
@@ -2698,27 +2871,27 @@ var prefer_semantic_colors_default = ESLintUtils15.RuleCreator(
|
|
|
2698
2871
|
const checkClassNode = (node) => {
|
|
2699
2872
|
if (node === null) return;
|
|
2700
2873
|
switch (node.type) {
|
|
2701
|
-
case
|
|
2874
|
+
case AST_NODE_TYPES9.Literal:
|
|
2702
2875
|
if (typeof node.value === "string") reportClasses(node.value, node);
|
|
2703
2876
|
break;
|
|
2704
|
-
case
|
|
2877
|
+
case AST_NODE_TYPES9.TemplateLiteral:
|
|
2705
2878
|
for (const quasi of node.quasis) reportClasses(quasi.value.cooked ?? "", quasi);
|
|
2706
2879
|
break;
|
|
2707
|
-
case
|
|
2880
|
+
case AST_NODE_TYPES9.ArrayExpression:
|
|
2708
2881
|
for (const element of node.elements) {
|
|
2709
|
-
if (element !== null && element.type !==
|
|
2882
|
+
if (element !== null && element.type !== AST_NODE_TYPES9.SpreadElement) checkClassNode(element);
|
|
2710
2883
|
}
|
|
2711
2884
|
break;
|
|
2712
|
-
case
|
|
2885
|
+
case AST_NODE_TYPES9.ObjectExpression:
|
|
2713
2886
|
for (const property of node.properties) {
|
|
2714
|
-
if (property.type ===
|
|
2887
|
+
if (property.type === AST_NODE_TYPES9.Property) checkClassNode(property.value);
|
|
2715
2888
|
}
|
|
2716
2889
|
break;
|
|
2717
|
-
case
|
|
2890
|
+
case AST_NODE_TYPES9.ConditionalExpression:
|
|
2718
2891
|
checkClassNode(node.consequent);
|
|
2719
2892
|
checkClassNode(node.alternate);
|
|
2720
2893
|
break;
|
|
2721
|
-
case
|
|
2894
|
+
case AST_NODE_TYPES9.LogicalExpression:
|
|
2722
2895
|
checkClassNode(node.right);
|
|
2723
2896
|
break;
|
|
2724
2897
|
default:
|
|
@@ -2726,29 +2899,29 @@ var prefer_semantic_colors_default = ESLintUtils15.RuleCreator(
|
|
|
2726
2899
|
}
|
|
2727
2900
|
};
|
|
2728
2901
|
const checkColorValueNode = (node) => {
|
|
2729
|
-
if (node.type ===
|
|
2902
|
+
if (node.type === AST_NODE_TYPES9.Literal && typeof node.value === "string" && RAW_COLOR_VALUE_RE.test(node.value)) {
|
|
2730
2903
|
context.report({ node, messageId: "inlineColor", data: { value: node.value } });
|
|
2731
2904
|
}
|
|
2732
2905
|
};
|
|
2733
2906
|
return {
|
|
2734
2907
|
"JSXAttribute[name.name='className']"(node) {
|
|
2735
2908
|
if (node.value === null) return;
|
|
2736
|
-
if (node.value.type ===
|
|
2737
|
-
else if (node.value.type ===
|
|
2738
|
-
if (node.value.expression.type !==
|
|
2909
|
+
if (node.value.type === AST_NODE_TYPES9.Literal) checkClassNode(node.value);
|
|
2910
|
+
else if (node.value.type === AST_NODE_TYPES9.JSXExpressionContainer) {
|
|
2911
|
+
if (node.value.expression.type !== AST_NODE_TYPES9.JSXEmptyExpression) {
|
|
2739
2912
|
checkClassNode(node.value.expression);
|
|
2740
2913
|
}
|
|
2741
2914
|
}
|
|
2742
2915
|
},
|
|
2743
2916
|
CallExpression(node) {
|
|
2744
|
-
if (node.callee.type ===
|
|
2917
|
+
if (node.callee.type === AST_NODE_TYPES9.Identifier && CLASS_FNS.has(node.callee.name)) {
|
|
2745
2918
|
for (const arg of node.arguments) {
|
|
2746
|
-
if (arg.type !==
|
|
2919
|
+
if (arg.type !== AST_NODE_TYPES9.SpreadElement) checkClassNode(arg);
|
|
2747
2920
|
}
|
|
2748
2921
|
}
|
|
2749
2922
|
},
|
|
2750
2923
|
VariableDeclarator(node) {
|
|
2751
|
-
if (node.id.type ===
|
|
2924
|
+
if (node.id.type === AST_NODE_TYPES9.Identifier && CLASS_NAME_RE.test(node.id.name)) {
|
|
2752
2925
|
checkClassNode(node.init);
|
|
2753
2926
|
}
|
|
2754
2927
|
},
|
|
@@ -2760,7 +2933,7 @@ var prefer_semantic_colors_default = ESLintUtils15.RuleCreator(
|
|
|
2760
2933
|
// Neutral drawing literals and anything inside an SVG defs container are
|
|
2761
2934
|
// structural, not UI tokens, so they never fire.
|
|
2762
2935
|
"JSXAttribute[name.name=/^(fill|stroke|color)$/]"(node) {
|
|
2763
|
-
if (node.value?.type !==
|
|
2936
|
+
if (node.value?.type !== AST_NODE_TYPES9.Literal) return;
|
|
2764
2937
|
if (typeof node.value.value === "string" && SVG_EXEMPT_COLOR_VALUES.has(node.value.value.toLowerCase())) {
|
|
2765
2938
|
return;
|
|
2766
2939
|
}
|
|
@@ -2933,7 +3106,7 @@ var prefer_server_actions_default = ESLintUtils16.RuleCreator(
|
|
|
2933
3106
|
|
|
2934
3107
|
// src/rules/prefer-shadcn.ts
|
|
2935
3108
|
import {
|
|
2936
|
-
AST_NODE_TYPES as
|
|
3109
|
+
AST_NODE_TYPES as AST_NODE_TYPES10,
|
|
2937
3110
|
ESLintUtils as ESLintUtils17
|
|
2938
3111
|
} from "@typescript-eslint/utils";
|
|
2939
3112
|
var REPLACEMENTS = {
|
|
@@ -2950,10 +3123,10 @@ var SKIPPED_INPUT_TYPES = /* @__PURE__ */ new Set(["file", "hidden"]);
|
|
|
2950
3123
|
var kebabCase = (component) => component.replace(/([a-z0-9])([A-Z])/g, "$1-$2").toLowerCase();
|
|
2951
3124
|
var literalTypeAttr = (node) => {
|
|
2952
3125
|
for (const attribute of node.attributes) {
|
|
2953
|
-
if (attribute.type !==
|
|
3126
|
+
if (attribute.type !== AST_NODE_TYPES10.JSXAttribute || attribute.name.type !== AST_NODE_TYPES10.JSXIdentifier || attribute.name.name !== "type") {
|
|
2954
3127
|
continue;
|
|
2955
3128
|
}
|
|
2956
|
-
if (attribute.value?.type ===
|
|
3129
|
+
if (attribute.value?.type === AST_NODE_TYPES10.Literal && typeof attribute.value.value === "string") {
|
|
2957
3130
|
return { kind: "literal", value: attribute.value.value.toLowerCase() };
|
|
2958
3131
|
}
|
|
2959
3132
|
return { kind: "dynamic" };
|
|
@@ -2961,7 +3134,7 @@ var literalTypeAttr = (node) => {
|
|
|
2961
3134
|
return null;
|
|
2962
3135
|
};
|
|
2963
3136
|
var hasFileAcceptAttr = (node) => node.attributes.some(
|
|
2964
|
-
(attribute) => attribute.type ===
|
|
3137
|
+
(attribute) => attribute.type === AST_NODE_TYPES10.JSXAttribute && attribute.name.type === AST_NODE_TYPES10.JSXIdentifier && attribute.name.name === "accept"
|
|
2965
3138
|
);
|
|
2966
3139
|
var resolveInputReplacement = (node) => {
|
|
2967
3140
|
const typeAttr = literalTypeAttr(node);
|
|
@@ -3016,37 +3189,37 @@ var prefer_shadcn_default = ESLintUtils17.RuleCreator(
|
|
|
3016
3189
|
// src/rules/require-assert-never.ts
|
|
3017
3190
|
import {
|
|
3018
3191
|
ESLintUtils as ESLintUtils18,
|
|
3019
|
-
AST_NODE_TYPES as
|
|
3192
|
+
AST_NODE_TYPES as AST_NODE_TYPES11
|
|
3020
3193
|
} from "@typescript-eslint/utils";
|
|
3021
3194
|
var isAssertNeverCall = (expression) => {
|
|
3022
|
-
if (expression.type !==
|
|
3195
|
+
if (expression.type !== AST_NODE_TYPES11.CallExpression) return false;
|
|
3023
3196
|
const callee = expression.callee;
|
|
3024
|
-
if (callee.type ===
|
|
3197
|
+
if (callee.type === AST_NODE_TYPES11.Identifier) {
|
|
3025
3198
|
return callee.name === "assertNever";
|
|
3026
3199
|
}
|
|
3027
|
-
if (callee.type ===
|
|
3200
|
+
if (callee.type === AST_NODE_TYPES11.MemberExpression && !callee.computed && callee.property.type === AST_NODE_TYPES11.Identifier) {
|
|
3028
3201
|
return callee.property.name === "assertNever";
|
|
3029
3202
|
}
|
|
3030
3203
|
return false;
|
|
3031
3204
|
};
|
|
3032
3205
|
var statementContainsAssertNever = (statement) => {
|
|
3033
|
-
if (statement.type ===
|
|
3206
|
+
if (statement.type === AST_NODE_TYPES11.ExpressionStatement) {
|
|
3034
3207
|
return isAssertNeverCall(statement.expression);
|
|
3035
3208
|
}
|
|
3036
|
-
if (statement.type ===
|
|
3209
|
+
if (statement.type === AST_NODE_TYPES11.ThrowStatement) {
|
|
3037
3210
|
return isAssertNeverCall(statement.argument);
|
|
3038
3211
|
}
|
|
3039
|
-
if (statement.type ===
|
|
3212
|
+
if (statement.type === AST_NODE_TYPES11.ReturnStatement) {
|
|
3040
3213
|
return statement.argument !== null && isAssertNeverCall(statement.argument);
|
|
3041
3214
|
}
|
|
3042
|
-
if (statement.type ===
|
|
3215
|
+
if (statement.type === AST_NODE_TYPES11.BlockStatement) {
|
|
3043
3216
|
return statement.body.some(statementContainsAssertNever);
|
|
3044
3217
|
}
|
|
3045
3218
|
return false;
|
|
3046
3219
|
};
|
|
3047
3220
|
var isRuntimeHandlingStatement = (statement) => {
|
|
3048
|
-
if (statement.type ===
|
|
3049
|
-
if (statement.type ===
|
|
3221
|
+
if (statement.type === AST_NODE_TYPES11.EmptyStatement) return false;
|
|
3222
|
+
if (statement.type === AST_NODE_TYPES11.BlockStatement) {
|
|
3050
3223
|
return statement.body.some(isRuntimeHandlingStatement);
|
|
3051
3224
|
}
|
|
3052
3225
|
return true;
|
|
@@ -3062,7 +3235,7 @@ var isCommentOnlyNoopDefault = (defaultCase, sourceCode) => {
|
|
|
3062
3235
|
return colonToken !== null && sourceCode.getCommentsAfter(colonToken).length > 0;
|
|
3063
3236
|
}
|
|
3064
3237
|
const only = defaultCase.consequent[0];
|
|
3065
|
-
if (only !== void 0 && defaultCase.consequent.length === 1 && only.type ===
|
|
3238
|
+
if (only !== void 0 && defaultCase.consequent.length === 1 && only.type === AST_NODE_TYPES11.BlockStatement && only.body.length === 0) {
|
|
3066
3239
|
return sourceCode.getCommentsInside(only).length > 0;
|
|
3067
3240
|
}
|
|
3068
3241
|
return false;
|
|
@@ -3105,7 +3278,7 @@ var require_assert_never_default = ESLintUtils18.RuleCreator(
|
|
|
3105
3278
|
});
|
|
3106
3279
|
|
|
3107
3280
|
// src/rules/require-zod-form-validation.ts
|
|
3108
|
-
import { ESLintUtils as ESLintUtils19, AST_NODE_TYPES as
|
|
3281
|
+
import { ESLintUtils as ESLintUtils19, AST_NODE_TYPES as AST_NODE_TYPES12 } from "@typescript-eslint/utils";
|
|
3109
3282
|
|
|
3110
3283
|
// src/rules/_zod.ts
|
|
3111
3284
|
var ZOD_PREFIX_RE = /^Z[A-Z]/;
|
|
@@ -3116,14 +3289,14 @@ var ZOD_SCHEMA_NAME_RE = /Schema$|^Z[A-Z]/;
|
|
|
3116
3289
|
var looksLikeZodSchema = (node) => {
|
|
3117
3290
|
let current = node;
|
|
3118
3291
|
while (true) {
|
|
3119
|
-
if (current.type ===
|
|
3292
|
+
if (current.type === AST_NODE_TYPES12.Identifier) {
|
|
3120
3293
|
return current.name === "z" || ZOD_SCHEMA_NAME_RE.test(current.name);
|
|
3121
3294
|
}
|
|
3122
|
-
if (current.type ===
|
|
3295
|
+
if (current.type === AST_NODE_TYPES12.CallExpression) {
|
|
3123
3296
|
current = current.callee;
|
|
3124
3297
|
continue;
|
|
3125
3298
|
}
|
|
3126
|
-
if (current.type ===
|
|
3299
|
+
if (current.type === AST_NODE_TYPES12.MemberExpression) {
|
|
3127
3300
|
current = current.object;
|
|
3128
3301
|
continue;
|
|
3129
3302
|
}
|
|
@@ -3131,23 +3304,23 @@ var looksLikeZodSchema = (node) => {
|
|
|
3131
3304
|
}
|
|
3132
3305
|
};
|
|
3133
3306
|
var isZodParseCall = (node) => {
|
|
3134
|
-
if (node.type !==
|
|
3307
|
+
if (node.type !== AST_NODE_TYPES12.CallExpression) return false;
|
|
3135
3308
|
const callee = node.callee;
|
|
3136
|
-
if (callee.type !==
|
|
3309
|
+
if (callee.type !== AST_NODE_TYPES12.MemberExpression) return false;
|
|
3137
3310
|
if (callee.computed) return false;
|
|
3138
|
-
if (callee.property.type !==
|
|
3311
|
+
if (callee.property.type !== AST_NODE_TYPES12.Identifier) return false;
|
|
3139
3312
|
const method = callee.property.name;
|
|
3140
3313
|
if (method !== "parse" && method !== "safeParse") return false;
|
|
3141
3314
|
return looksLikeZodSchema(callee.object);
|
|
3142
3315
|
};
|
|
3143
3316
|
var isFormDataMethodCall = (node) => {
|
|
3144
3317
|
let current = node;
|
|
3145
|
-
if (current.type ===
|
|
3318
|
+
if (current.type === AST_NODE_TYPES12.AwaitExpression) {
|
|
3146
3319
|
current = current.argument;
|
|
3147
3320
|
}
|
|
3148
|
-
if (current.type !==
|
|
3321
|
+
if (current.type !== AST_NODE_TYPES12.CallExpression) return false;
|
|
3149
3322
|
const callee = current.callee;
|
|
3150
|
-
return callee.type ===
|
|
3323
|
+
return callee.type === AST_NODE_TYPES12.MemberExpression && !callee.computed && callee.property.type === AST_NODE_TYPES12.Identifier && callee.property.name === "formData";
|
|
3151
3324
|
};
|
|
3152
3325
|
var require_zod_form_validation_default = ESLintUtils19.RuleCreator(
|
|
3153
3326
|
(name) => `https://github.com/sarj-ai/linting/blob/main/packages/typescript/src/rules/${name}.ts`
|
|
@@ -3169,14 +3342,14 @@ var require_zod_form_validation_default = ESLintUtils19.RuleCreator(
|
|
|
3169
3342
|
return {};
|
|
3170
3343
|
}
|
|
3171
3344
|
const isFormSourceIdentifier = (node) => {
|
|
3172
|
-
if (node.type !==
|
|
3345
|
+
if (node.type !== AST_NODE_TYPES12.Identifier) return false;
|
|
3173
3346
|
if (/formdata/i.test(node.name)) return true;
|
|
3174
3347
|
let scope = context.sourceCode.getScope(node);
|
|
3175
3348
|
while (scope !== null) {
|
|
3176
3349
|
const variable = scope.set.get(node.name);
|
|
3177
3350
|
if (variable !== void 0 && variable.defs.length === 1) {
|
|
3178
3351
|
const def = variable.defs[0];
|
|
3179
|
-
if (def !== void 0 && def.type === "Variable" && def.node.type ===
|
|
3352
|
+
if (def !== void 0 && def.type === "Variable" && def.node.type === AST_NODE_TYPES12.VariableDeclarator && def.node.init !== null) {
|
|
3180
3353
|
return isFormDataMethodCall(def.node.init);
|
|
3181
3354
|
}
|
|
3182
3355
|
return false;
|
|
@@ -3187,8 +3360,8 @@ var require_zod_form_validation_default = ESLintUtils19.RuleCreator(
|
|
|
3187
3360
|
};
|
|
3188
3361
|
const isFormDataGetCall = (node) => {
|
|
3189
3362
|
const callee = node.callee;
|
|
3190
|
-
if (callee.type !==
|
|
3191
|
-
if (callee.property.type !==
|
|
3363
|
+
if (callee.type !== AST_NODE_TYPES12.MemberExpression) return false;
|
|
3364
|
+
if (callee.property.type !== AST_NODE_TYPES12.Identifier || callee.property.name !== "get") {
|
|
3192
3365
|
return false;
|
|
3193
3366
|
}
|
|
3194
3367
|
return isFormSourceIdentifier(callee.object);
|
|
@@ -3203,11 +3376,11 @@ var require_zod_form_validation_default = ESLintUtils19.RuleCreator(
|
|
|
3203
3376
|
};
|
|
3204
3377
|
const isInstanceofNarrowing = (node) => {
|
|
3205
3378
|
const parent = node.parent;
|
|
3206
|
-
return parent !== null && parent !== void 0 && parent.type ===
|
|
3379
|
+
return parent !== null && parent !== void 0 && parent.type === AST_NODE_TYPES12.BinaryExpression && parent.operator === "instanceof" && parent.left === node;
|
|
3207
3380
|
};
|
|
3208
3381
|
const boundDeclarator = (node) => {
|
|
3209
3382
|
const parent = node.parent;
|
|
3210
|
-
if (parent.type ===
|
|
3383
|
+
if (parent.type === AST_NODE_TYPES12.VariableDeclarator && parent.init === node && parent.id.type === AST_NODE_TYPES12.Identifier) {
|
|
3211
3384
|
return parent;
|
|
3212
3385
|
}
|
|
3213
3386
|
return null;
|
|
@@ -3235,7 +3408,7 @@ var require_zod_form_validation_default = ESLintUtils19.RuleCreator(
|
|
|
3235
3408
|
});
|
|
3236
3409
|
|
|
3237
3410
|
// src/rules/zod-naming-convention.ts
|
|
3238
|
-
import { ESLintUtils as ESLintUtils20, AST_NODE_TYPES as
|
|
3411
|
+
import { ESLintUtils as ESLintUtils20, AST_NODE_TYPES as AST_NODE_TYPES13 } from "@typescript-eslint/utils";
|
|
3239
3412
|
var CONVENTIONS = {
|
|
3240
3413
|
prefix: { test: ZOD_PREFIX_RE, messageId: "zPrefix" },
|
|
3241
3414
|
suffix: { test: ZOD_SUFFIX_RE, messageId: "schemaSuffix" },
|
|
@@ -3259,15 +3432,15 @@ var NON_SCHEMA_TERMINALS = /* @__PURE__ */ new Set([
|
|
|
3259
3432
|
"registry",
|
|
3260
3433
|
"implement"
|
|
3261
3434
|
]);
|
|
3262
|
-
var terminalMethodName = (callee) => !callee.computed && callee.property.type ===
|
|
3435
|
+
var terminalMethodName = (callee) => !callee.computed && callee.property.type === AST_NODE_TYPES13.Identifier ? callee.property.name : null;
|
|
3263
3436
|
var calleeChainStartsWithZ = (node) => {
|
|
3264
3437
|
let current = node;
|
|
3265
|
-
while (current.type ===
|
|
3438
|
+
while (current.type === AST_NODE_TYPES13.MemberExpression) {
|
|
3266
3439
|
const receiver = current.object;
|
|
3267
|
-
if (receiver.type ===
|
|
3440
|
+
if (receiver.type === AST_NODE_TYPES13.Identifier && receiver.name === "z") {
|
|
3268
3441
|
return true;
|
|
3269
3442
|
}
|
|
3270
|
-
if (receiver.type ===
|
|
3443
|
+
if (receiver.type === AST_NODE_TYPES13.CallExpression) {
|
|
3271
3444
|
current = receiver.callee;
|
|
3272
3445
|
continue;
|
|
3273
3446
|
}
|
|
@@ -3314,13 +3487,13 @@ var zod_naming_convention_default = ESLintUtils20.RuleCreator(
|
|
|
3314
3487
|
VariableDeclarator(node) {
|
|
3315
3488
|
const init = node.init;
|
|
3316
3489
|
if (init === null || init === void 0) return;
|
|
3317
|
-
if (init.type !==
|
|
3490
|
+
if (init.type !== AST_NODE_TYPES13.CallExpression) return;
|
|
3318
3491
|
const callee = init.callee;
|
|
3319
|
-
if (callee.type !==
|
|
3492
|
+
if (callee.type !== AST_NODE_TYPES13.MemberExpression) return;
|
|
3320
3493
|
if (!calleeChainStartsWithZ(callee)) return;
|
|
3321
3494
|
const terminal = terminalMethodName(callee);
|
|
3322
3495
|
if (terminal !== null && NON_SCHEMA_TERMINALS.has(terminal)) return;
|
|
3323
|
-
if (node.id.type !==
|
|
3496
|
+
if (node.id.type !== AST_NODE_TYPES13.Identifier) return;
|
|
3324
3497
|
if (test.test(node.id.name)) return;
|
|
3325
3498
|
if (acceptsSchemaWord && CONTAINS_SCHEMA_RE.test(node.id.name)) return;
|
|
3326
3499
|
context.report({
|
|
@@ -3543,9 +3716,9 @@ var no_cors_wildcard_with_credentials_default = ESLintUtils21.RuleCreator(
|
|
|
3543
3716
|
});
|
|
3544
3717
|
|
|
3545
3718
|
// src/rules/no-silent-promise-catch.ts
|
|
3546
|
-
import { AST_NODE_TYPES as
|
|
3719
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES14, ESLintUtils as ESLintUtils22 } from "@typescript-eslint/utils";
|
|
3547
3720
|
function isBodyParseCall(node) {
|
|
3548
|
-
return node.type ===
|
|
3721
|
+
return node.type === AST_NODE_TYPES14.CallExpression && node.arguments.length === 0 && node.callee.type === AST_NODE_TYPES14.MemberExpression && !node.callee.computed && node.callee.property.type === AST_NODE_TYPES14.Identifier && (node.callee.property.name === "json" || node.callee.property.name === "text");
|
|
3549
3722
|
}
|
|
3550
3723
|
var TEARDOWN_METHODS = /* @__PURE__ */ new Set([
|
|
3551
3724
|
"cancel",
|
|
@@ -3560,21 +3733,21 @@ var TEARDOWN_METHODS = /* @__PURE__ */ new Set([
|
|
|
3560
3733
|
var DIRECTIVE_COMMENT_RE = /^\s*(eslint-|@ts-|prettier-ignore|biome-ignore|c8 |v8 |istanbul )/;
|
|
3561
3734
|
var isExplanatory = (comment) => !DIRECTIVE_COMMENT_RE.test(comment.value);
|
|
3562
3735
|
function isTeardownCall(node) {
|
|
3563
|
-
return node.type ===
|
|
3736
|
+
return node.type === AST_NODE_TYPES14.CallExpression && node.callee.type === AST_NODE_TYPES14.MemberExpression && !node.callee.computed && node.callee.property.type === AST_NODE_TYPES14.Identifier && TEARDOWN_METHODS.has(node.callee.property.name);
|
|
3564
3737
|
}
|
|
3565
3738
|
function isSilentExpression(node) {
|
|
3566
3739
|
switch (node.type) {
|
|
3567
|
-
case
|
|
3740
|
+
case AST_NODE_TYPES14.Literal:
|
|
3568
3741
|
return !("regex" in node);
|
|
3569
|
-
case
|
|
3742
|
+
case AST_NODE_TYPES14.Identifier:
|
|
3570
3743
|
return node.name === "undefined";
|
|
3571
|
-
case
|
|
3572
|
-
return node.operator === "void" && node.argument.type ===
|
|
3573
|
-
case
|
|
3744
|
+
case AST_NODE_TYPES14.UnaryExpression:
|
|
3745
|
+
return node.operator === "void" && node.argument.type === AST_NODE_TYPES14.Literal;
|
|
3746
|
+
case AST_NODE_TYPES14.ObjectExpression:
|
|
3574
3747
|
return node.properties.length === 0;
|
|
3575
|
-
case
|
|
3748
|
+
case AST_NODE_TYPES14.ArrayExpression:
|
|
3576
3749
|
return node.elements.length === 0;
|
|
3577
|
-
case
|
|
3750
|
+
case AST_NODE_TYPES14.TSAsExpression:
|
|
3578
3751
|
return isSilentExpression(node.expression);
|
|
3579
3752
|
default:
|
|
3580
3753
|
return false;
|
|
@@ -3582,7 +3755,7 @@ function isSilentExpression(node) {
|
|
|
3582
3755
|
}
|
|
3583
3756
|
function isSilentHandler(handler) {
|
|
3584
3757
|
const body = handler.body;
|
|
3585
|
-
if (body.type !==
|
|
3758
|
+
if (body.type !== AST_NODE_TYPES14.BlockStatement) {
|
|
3586
3759
|
return isSilentExpression(body);
|
|
3587
3760
|
}
|
|
3588
3761
|
if (body.body.length === 0) {
|
|
@@ -3590,7 +3763,7 @@ function isSilentHandler(handler) {
|
|
|
3590
3763
|
}
|
|
3591
3764
|
if (body.body.length === 1) {
|
|
3592
3765
|
const only = body.body[0];
|
|
3593
|
-
if (only !== void 0 && only.type ===
|
|
3766
|
+
if (only !== void 0 && only.type === AST_NODE_TYPES14.ReturnStatement) {
|
|
3594
3767
|
return only.argument === null || isSilentExpression(only.argument);
|
|
3595
3768
|
}
|
|
3596
3769
|
}
|
|
@@ -3621,7 +3794,7 @@ var no_silent_promise_catch_default = ESLintUtils22.RuleCreator(
|
|
|
3621
3794
|
return true;
|
|
3622
3795
|
}
|
|
3623
3796
|
let statement = call;
|
|
3624
|
-
while (statement.parent !== void 0 && statement.parent !== null && !statement.type.endsWith("Statement") && statement.type !==
|
|
3797
|
+
while (statement.parent !== void 0 && statement.parent !== null && !statement.type.endsWith("Statement") && statement.type !== AST_NODE_TYPES14.VariableDeclaration) {
|
|
3625
3798
|
statement = statement.parent;
|
|
3626
3799
|
}
|
|
3627
3800
|
if (sourceCode.getCommentsBefore(statement).some(isExplanatory)) {
|
|
@@ -3633,7 +3806,7 @@ var no_silent_promise_catch_default = ESLintUtils22.RuleCreator(
|
|
|
3633
3806
|
};
|
|
3634
3807
|
return {
|
|
3635
3808
|
CallExpression(node) {
|
|
3636
|
-
if (node.callee.type !==
|
|
3809
|
+
if (node.callee.type !== AST_NODE_TYPES14.MemberExpression || node.callee.computed || node.callee.property.type !== AST_NODE_TYPES14.Identifier || node.callee.property.name !== "catch") {
|
|
3637
3810
|
return;
|
|
3638
3811
|
}
|
|
3639
3812
|
if (isBodyParseCall(node.callee.object)) {
|
|
@@ -3642,14 +3815,14 @@ var no_silent_promise_catch_default = ESLintUtils22.RuleCreator(
|
|
|
3642
3815
|
if (isTeardownCall(node.callee.object)) {
|
|
3643
3816
|
return;
|
|
3644
3817
|
}
|
|
3645
|
-
if (node.parent.type ===
|
|
3818
|
+
if (node.parent.type === AST_NODE_TYPES14.MemberExpression && node.parent.object === node) {
|
|
3646
3819
|
return;
|
|
3647
3820
|
}
|
|
3648
3821
|
if (node.arguments.length !== 1) {
|
|
3649
3822
|
return;
|
|
3650
3823
|
}
|
|
3651
3824
|
const handler = node.arguments[0];
|
|
3652
|
-
if (handler === void 0 || handler.type !==
|
|
3825
|
+
if (handler === void 0 || handler.type !== AST_NODE_TYPES14.ArrowFunctionExpression && handler.type !== AST_NODE_TYPES14.FunctionExpression) {
|
|
3653
3826
|
return;
|
|
3654
3827
|
}
|
|
3655
3828
|
if (hasExplanatoryComment(node, handler)) {
|
|
@@ -3665,7 +3838,7 @@ var no_silent_promise_catch_default = ESLintUtils22.RuleCreator(
|
|
|
3665
3838
|
|
|
3666
3839
|
// src/rules/require-fetch-timeout.ts
|
|
3667
3840
|
import {
|
|
3668
|
-
AST_NODE_TYPES as
|
|
3841
|
+
AST_NODE_TYPES as AST_NODE_TYPES15,
|
|
3669
3842
|
ASTUtils,
|
|
3670
3843
|
ESLintUtils as ESLintUtils23
|
|
3671
3844
|
} from "@typescript-eslint/utils";
|
|
@@ -3685,14 +3858,14 @@ function matchesAnyPattern2(filename, patterns) {
|
|
|
3685
3858
|
return false;
|
|
3686
3859
|
}
|
|
3687
3860
|
function initProvablyLacksSignal(init) {
|
|
3688
|
-
if (init.type !==
|
|
3861
|
+
if (init.type !== AST_NODE_TYPES15.ObjectExpression) {
|
|
3689
3862
|
return false;
|
|
3690
3863
|
}
|
|
3691
3864
|
for (const prop of init.properties) {
|
|
3692
|
-
if (prop.type ===
|
|
3865
|
+
if (prop.type === AST_NODE_TYPES15.SpreadElement) {
|
|
3693
3866
|
return false;
|
|
3694
3867
|
}
|
|
3695
|
-
if (prop.key.type ===
|
|
3868
|
+
if (prop.key.type === AST_NODE_TYPES15.Identifier && prop.key.name === "signal" || prop.key.type === AST_NODE_TYPES15.Literal && prop.key.value === "signal") {
|
|
3696
3869
|
return false;
|
|
3697
3870
|
}
|
|
3698
3871
|
if (prop.computed) {
|
|
@@ -3702,7 +3875,7 @@ function initProvablyLacksSignal(init) {
|
|
|
3702
3875
|
return true;
|
|
3703
3876
|
}
|
|
3704
3877
|
function isStringish(node) {
|
|
3705
|
-
return node.type ===
|
|
3878
|
+
return node.type === AST_NODE_TYPES15.Literal && typeof node.value === "string" || node.type === AST_NODE_TYPES15.TemplateLiteral;
|
|
3706
3879
|
}
|
|
3707
3880
|
var require_fetch_timeout_default = ESLintUtils23.RuleCreator(
|
|
3708
3881
|
(name) => `https://github.com/sarj-ai/linting/blob/main/packages/typescript/src/rules/${name}.ts`
|
|
@@ -3745,10 +3918,10 @@ var require_fetch_timeout_default = ESLintUtils23.RuleCreator(
|
|
|
3745
3918
|
return variable === null || variable.defs.length === 0;
|
|
3746
3919
|
}
|
|
3747
3920
|
function isGlobalFetchCall2(callee) {
|
|
3748
|
-
if (callee.type ===
|
|
3921
|
+
if (callee.type === AST_NODE_TYPES15.Identifier) {
|
|
3749
3922
|
return callee.name === "fetch" && resolvesToGlobal(callee);
|
|
3750
3923
|
}
|
|
3751
|
-
return callee.type ===
|
|
3924
|
+
return callee.type === AST_NODE_TYPES15.MemberExpression && !callee.computed && callee.property.type === AST_NODE_TYPES15.Identifier && callee.property.name === "fetch" && callee.object.type === AST_NODE_TYPES15.Identifier && GLOBAL_OBJECTS.has(callee.object.name) && resolvesToGlobal(callee.object);
|
|
3752
3925
|
}
|
|
3753
3926
|
return {
|
|
3754
3927
|
CallExpression(node) {
|
|
@@ -3768,23 +3941,23 @@ var require_fetch_timeout_default = ESLintUtils23.RuleCreator(
|
|
|
3768
3941
|
});
|
|
3769
3942
|
|
|
3770
3943
|
// src/rules/require-schema-validate-search.ts
|
|
3771
|
-
import { AST_NODE_TYPES as
|
|
3944
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES16, ESLintUtils as ESLintUtils24 } from "@typescript-eslint/utils";
|
|
3772
3945
|
var VALIDATOR_METHODS = /* @__PURE__ */ new Set([
|
|
3773
3946
|
"parse",
|
|
3774
3947
|
"safeParse",
|
|
3775
3948
|
"decode"
|
|
3776
3949
|
]);
|
|
3777
3950
|
function isConstTypeAnnotation(typeAnnotation) {
|
|
3778
|
-
return typeAnnotation.type ===
|
|
3951
|
+
return typeAnnotation.type === AST_NODE_TYPES16.TSTypeReference && typeAnnotation.typeName.type === AST_NODE_TYPES16.Identifier && typeAnnotation.typeName.name === "const";
|
|
3779
3952
|
}
|
|
3780
3953
|
function isValidatorCall(node) {
|
|
3781
|
-
return node.callee.type ===
|
|
3954
|
+
return node.callee.type === AST_NODE_TYPES16.MemberExpression && !node.callee.computed && node.callee.property.type === AST_NODE_TYPES16.Identifier && VALIDATOR_METHODS.has(node.callee.property.name);
|
|
3782
3955
|
}
|
|
3783
3956
|
function findCastExpression(node, insideValidatorArg) {
|
|
3784
|
-
if ((node.type ===
|
|
3957
|
+
if ((node.type === AST_NODE_TYPES16.TSAsExpression || node.type === AST_NODE_TYPES16.TSTypeAssertion) && !isConstTypeAnnotation(node.typeAnnotation) && !insideValidatorArg) {
|
|
3785
3958
|
return node;
|
|
3786
3959
|
}
|
|
3787
|
-
if (node.type ===
|
|
3960
|
+
if (node.type === AST_NODE_TYPES16.CallExpression && isValidatorCall(node)) {
|
|
3788
3961
|
const inCallee = findCastExpression(node.callee, insideValidatorArg);
|
|
3789
3962
|
if (inCallee !== null) {
|
|
3790
3963
|
return inCallee;
|
|
@@ -3838,11 +4011,11 @@ var require_schema_validate_search_default = ESLintUtils24.RuleCreator(
|
|
|
3838
4011
|
}
|
|
3839
4012
|
return {
|
|
3840
4013
|
Property(node) {
|
|
3841
|
-
const isValidateSearchKey = !node.computed && node.key.type ===
|
|
4014
|
+
const isValidateSearchKey = !node.computed && node.key.type === AST_NODE_TYPES16.Identifier && node.key.name === "validateSearch" || node.key.type === AST_NODE_TYPES16.Literal && node.key.value === "validateSearch";
|
|
3842
4015
|
if (!isValidateSearchKey) {
|
|
3843
4016
|
return;
|
|
3844
4017
|
}
|
|
3845
|
-
if (node.value.type !==
|
|
4018
|
+
if (node.value.type !== AST_NODE_TYPES16.ArrowFunctionExpression && node.value.type !== AST_NODE_TYPES16.FunctionExpression) {
|
|
3846
4019
|
return;
|
|
3847
4020
|
}
|
|
3848
4021
|
const cast = findCastExpression(node.value.body, false);
|
|
@@ -3857,13 +4030,13 @@ var require_schema_validate_search_default = ESLintUtils24.RuleCreator(
|
|
|
3857
4030
|
// src/rules/no-fat-try-blocks.ts
|
|
3858
4031
|
import {
|
|
3859
4032
|
ESLintUtils as ESLintUtils25,
|
|
3860
|
-
AST_NODE_TYPES as
|
|
4033
|
+
AST_NODE_TYPES as AST_NODE_TYPES17
|
|
3861
4034
|
} from "@typescript-eslint/utils";
|
|
3862
4035
|
var MAX_TRY_BODY_STATEMENTS = 3;
|
|
3863
4036
|
var NESTED_FUNCTION_TYPES = /* @__PURE__ */ new Set([
|
|
3864
|
-
|
|
3865
|
-
|
|
3866
|
-
|
|
4037
|
+
AST_NODE_TYPES17.FunctionDeclaration,
|
|
4038
|
+
AST_NODE_TYPES17.FunctionExpression,
|
|
4039
|
+
AST_NODE_TYPES17.ArrowFunctionExpression
|
|
3867
4040
|
]);
|
|
3868
4041
|
var PURE_METHODS = /* @__PURE__ */ new Set([
|
|
3869
4042
|
"map",
|
|
@@ -3961,20 +4134,20 @@ function isNode4(value) {
|
|
|
3961
4134
|
}
|
|
3962
4135
|
function isPureCall(node) {
|
|
3963
4136
|
const callee = node.callee;
|
|
3964
|
-
if (callee.type !==
|
|
4137
|
+
if (callee.type !== AST_NODE_TYPES17.MemberExpression) {
|
|
3965
4138
|
return false;
|
|
3966
4139
|
}
|
|
3967
4140
|
const property = callee.property;
|
|
3968
|
-
if (property.type !==
|
|
4141
|
+
if (property.type !== AST_NODE_TYPES17.Identifier) {
|
|
3969
4142
|
return false;
|
|
3970
4143
|
}
|
|
3971
|
-
if (callee.object.type ===
|
|
4144
|
+
if (callee.object.type === AST_NODE_TYPES17.Identifier && PURE_NAMESPACES.has(callee.object.name)) {
|
|
3972
4145
|
return true;
|
|
3973
4146
|
}
|
|
3974
4147
|
return PURE_METHODS.has(property.name);
|
|
3975
4148
|
}
|
|
3976
4149
|
function isPureNew(node) {
|
|
3977
|
-
return node.callee.type ===
|
|
4150
|
+
return node.callee.type === AST_NODE_TYPES17.Identifier && PURE_CONSTRUCTORS.has(node.callee.name);
|
|
3978
4151
|
}
|
|
3979
4152
|
function subtreeMatches(stmt, predicate) {
|
|
3980
4153
|
let found = false;
|
|
@@ -4011,20 +4184,20 @@ function subtreeMatches(stmt, predicate) {
|
|
|
4011
4184
|
visit(stmt);
|
|
4012
4185
|
return found;
|
|
4013
4186
|
}
|
|
4014
|
-
var hasAwait = (node) => subtreeMatches(node, (n) => n.type ===
|
|
4187
|
+
var hasAwait = (node) => subtreeMatches(node, (n) => n.type === AST_NODE_TYPES17.AwaitExpression);
|
|
4015
4188
|
var hasThrowingCallOrNew = (node) => subtreeMatches(
|
|
4016
4189
|
node,
|
|
4017
|
-
(n) => n.type ===
|
|
4190
|
+
(n) => n.type === AST_NODE_TYPES17.CallExpression && !isPureCall(n) || n.type === AST_NODE_TYPES17.NewExpression && !isPureNew(n)
|
|
4018
4191
|
);
|
|
4019
4192
|
function unwrap2(expr) {
|
|
4020
4193
|
let current = expr;
|
|
4021
|
-
while (current.type ===
|
|
4194
|
+
while (current.type === AST_NODE_TYPES17.ChainExpression || current.type === AST_NODE_TYPES17.TSNonNullExpression) {
|
|
4022
4195
|
current = current.expression;
|
|
4023
4196
|
}
|
|
4024
4197
|
return current;
|
|
4025
4198
|
}
|
|
4026
4199
|
function isBareCallStatement(stmt) {
|
|
4027
|
-
return stmt.type ===
|
|
4200
|
+
return stmt.type === AST_NODE_TYPES17.ExpressionStatement && unwrap2(stmt.expression).type === AST_NODE_TYPES17.CallExpression;
|
|
4028
4201
|
}
|
|
4029
4202
|
function canThrow(stmt) {
|
|
4030
4203
|
if (hasAwait(stmt)) {
|
|
@@ -4033,10 +4206,10 @@ function canThrow(stmt) {
|
|
|
4033
4206
|
if (isBareCallStatement(stmt)) {
|
|
4034
4207
|
return false;
|
|
4035
4208
|
}
|
|
4036
|
-
if (stmt.type ===
|
|
4209
|
+
if (stmt.type === AST_NODE_TYPES17.BlockStatement) {
|
|
4037
4210
|
return stmt.body.some(canThrow);
|
|
4038
4211
|
}
|
|
4039
|
-
if (stmt.type ===
|
|
4212
|
+
if (stmt.type === AST_NODE_TYPES17.IfStatement) {
|
|
4040
4213
|
return hasThrowingCallOrNew(stmt.test) || canThrow(stmt.consequent) || stmt.alternate !== null && canThrow(stmt.alternate);
|
|
4041
4214
|
}
|
|
4042
4215
|
return hasThrowingCallOrNew(stmt);
|
|
@@ -4047,7 +4220,7 @@ function handlerRethrows(handler) {
|
|
|
4047
4220
|
}
|
|
4048
4221
|
const body = handler.body.body;
|
|
4049
4222
|
const last = body[body.length - 1];
|
|
4050
|
-
return last !== void 0 && last.type ===
|
|
4223
|
+
return last !== void 0 && last.type === AST_NODE_TYPES17.ThrowStatement;
|
|
4051
4224
|
}
|
|
4052
4225
|
var no_fat_try_blocks_default = ESLintUtils25.RuleCreator(
|
|
4053
4226
|
(name) => `https://github.com/sarj-ai/standards/blob/main/packages/typescript/src/rules/${name}.ts`
|
|
@@ -4433,12 +4606,12 @@ var no_secret_in_log_default = ESLintUtils26.RuleCreator(
|
|
|
4433
4606
|
|
|
4434
4607
|
// src/rules/no-unsafe-cast.ts
|
|
4435
4608
|
import { ESLintUtils as ESLintUtils27 } from "@typescript-eslint/utils";
|
|
4436
|
-
import { AST_NODE_TYPES as
|
|
4609
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES18 } from "@typescript-eslint/utils";
|
|
4437
4610
|
function isAnyAnnotation(node) {
|
|
4438
|
-
return node.type ===
|
|
4611
|
+
return node.type === AST_NODE_TYPES18.TSAnyKeyword;
|
|
4439
4612
|
}
|
|
4440
4613
|
function isConstAssertion(typeAnnotation) {
|
|
4441
|
-
return typeAnnotation.type ===
|
|
4614
|
+
return typeAnnotation.type === AST_NODE_TYPES18.TSTypeReference && typeAnnotation.typeName.type === AST_NODE_TYPES18.Identifier && typeAnnotation.typeName.name === "const";
|
|
4442
4615
|
}
|
|
4443
4616
|
var no_unsafe_cast_default = ESLintUtils27.RuleCreator(
|
|
4444
4617
|
(name) => `https://github.com/sarj-ai/linting/blob/main/packages/typescript/src/rules/${name}.ts`
|
|
@@ -4469,7 +4642,7 @@ var no_unsafe_cast_default = ESLintUtils27.RuleCreator(
|
|
|
4469
4642
|
return;
|
|
4470
4643
|
}
|
|
4471
4644
|
const inner = node.expression;
|
|
4472
|
-
if (inner.type ===
|
|
4645
|
+
if (inner.type === AST_NODE_TYPES18.TSAsExpression || inner.type === AST_NODE_TYPES18.TSTypeAssertion) {
|
|
4473
4646
|
context.report({ node, messageId: "doubleCast" });
|
|
4474
4647
|
}
|
|
4475
4648
|
}
|
|
@@ -4483,7 +4656,7 @@ var no_unsafe_cast_default = ESLintUtils27.RuleCreator(
|
|
|
4483
4656
|
// src/rules/prefer-string-literal-union.ts
|
|
4484
4657
|
import {
|
|
4485
4658
|
ESLintUtils as ESLintUtils28,
|
|
4486
|
-
AST_NODE_TYPES as
|
|
4659
|
+
AST_NODE_TYPES as AST_NODE_TYPES19
|
|
4487
4660
|
} from "@typescript-eslint/utils";
|
|
4488
4661
|
import * as ts from "typescript";
|
|
4489
4662
|
var CHOICE_TOKENS = /* @__PURE__ */ new Set([
|
|
@@ -4527,19 +4700,19 @@ function isChoiceLikeName(name) {
|
|
|
4527
4700
|
return CHOICE_TOKENS.has(lastWord(name));
|
|
4528
4701
|
}
|
|
4529
4702
|
function keyName(key) {
|
|
4530
|
-
if (key.type ===
|
|
4703
|
+
if (key.type === AST_NODE_TYPES19.Identifier) {
|
|
4531
4704
|
return key.name;
|
|
4532
4705
|
}
|
|
4533
|
-
if (key.type ===
|
|
4706
|
+
if (key.type === AST_NODE_TYPES19.Literal && typeof key.value === "string") {
|
|
4534
4707
|
return key.value;
|
|
4535
4708
|
}
|
|
4536
4709
|
return null;
|
|
4537
4710
|
}
|
|
4538
4711
|
function isStringLiteralMember(t) {
|
|
4539
|
-
return t.type ===
|
|
4712
|
+
return t.type === AST_NODE_TYPES19.TSLiteralType && t.literal.type === AST_NODE_TYPES19.Literal && typeof t.literal.value === "string";
|
|
4540
4713
|
}
|
|
4541
4714
|
function isStringLiteralUnion(node) {
|
|
4542
|
-
if (node?.type !==
|
|
4715
|
+
if (node?.type !== AST_NODE_TYPES19.TSUnionType) {
|
|
4543
4716
|
return false;
|
|
4544
4717
|
}
|
|
4545
4718
|
return node.types.filter(isStringLiteralMember).length >= MIN_CLUSTER_SIZE;
|
|
@@ -4568,12 +4741,12 @@ function bindingSourceExpression(decl) {
|
|
|
4568
4741
|
return ts.isForOfStatement(node) ? node.expression : node.initializer;
|
|
4569
4742
|
}
|
|
4570
4743
|
function refKey(node) {
|
|
4571
|
-
if (node.type ===
|
|
4744
|
+
if (node.type === AST_NODE_TYPES19.Identifier) {
|
|
4572
4745
|
return node.name;
|
|
4573
4746
|
}
|
|
4574
|
-
if (node.type ===
|
|
4747
|
+
if (node.type === AST_NODE_TYPES19.MemberExpression && !node.computed) {
|
|
4575
4748
|
const inner = refKey(node.object);
|
|
4576
|
-
if (inner === null || node.property.type !==
|
|
4749
|
+
if (inner === null || node.property.type !== AST_NODE_TYPES19.Identifier) {
|
|
4577
4750
|
return null;
|
|
4578
4751
|
}
|
|
4579
4752
|
return `${inner}.${node.property.name}`;
|
|
@@ -4581,7 +4754,7 @@ function refKey(node) {
|
|
|
4581
4754
|
return null;
|
|
4582
4755
|
}
|
|
4583
4756
|
function strLiteral(node) {
|
|
4584
|
-
if (node.type ===
|
|
4757
|
+
if (node.type === AST_NODE_TYPES19.Literal && typeof node.value === "string") {
|
|
4585
4758
|
return node.value;
|
|
4586
4759
|
}
|
|
4587
4760
|
return null;
|
|
@@ -4736,7 +4909,7 @@ var prefer_string_literal_union_default = ESLintUtils28.RuleCreator(
|
|
|
4736
4909
|
containersWithUnion.add(container);
|
|
4737
4910
|
return;
|
|
4738
4911
|
}
|
|
4739
|
-
if (typeNode?.type !==
|
|
4912
|
+
if (typeNode?.type !== AST_NODE_TYPES19.TSStringKeyword) {
|
|
4740
4913
|
return;
|
|
4741
4914
|
}
|
|
4742
4915
|
const name = keyName(key);
|
|
@@ -4824,10 +4997,10 @@ var prefer_string_literal_union_default = ESLintUtils28.RuleCreator(
|
|
|
4824
4997
|
}
|
|
4825
4998
|
};
|
|
4826
4999
|
function refKeyText(node) {
|
|
4827
|
-
if (node.type ===
|
|
5000
|
+
if (node.type === AST_NODE_TYPES19.BinaryExpression) {
|
|
4828
5001
|
return refKey(node.left) ?? refKey(node.right) ?? "value";
|
|
4829
5002
|
}
|
|
4830
|
-
if (node.type ===
|
|
5003
|
+
if (node.type === AST_NODE_TYPES19.SwitchStatement) {
|
|
4831
5004
|
return refKey(node.discriminant) ?? "value";
|
|
4832
5005
|
}
|
|
4833
5006
|
return "value";
|
|
@@ -4836,7 +5009,7 @@ var prefer_string_literal_union_default = ESLintUtils28.RuleCreator(
|
|
|
4836
5009
|
});
|
|
4837
5010
|
|
|
4838
5011
|
// src/rules/single-public-export.ts
|
|
4839
|
-
import { ESLintUtils as ESLintUtils29, AST_NODE_TYPES as
|
|
5012
|
+
import { ESLintUtils as ESLintUtils29, AST_NODE_TYPES as AST_NODE_TYPES20 } from "@typescript-eslint/utils";
|
|
4840
5013
|
var JUNK_DRAWER_STEMS = /* @__PURE__ */ new Set([
|
|
4841
5014
|
"util",
|
|
4842
5015
|
"utils",
|
|
@@ -4870,12 +5043,12 @@ var kebabCase2 = (name) => {
|
|
|
4870
5043
|
}
|
|
4871
5044
|
return normalized.replace(CAMEL_BOUNDARY_RE, "-").toLowerCase();
|
|
4872
5045
|
};
|
|
4873
|
-
var isFunctionExpression = (node) => node !== null && (node.type ===
|
|
5046
|
+
var isFunctionExpression = (node) => node !== null && (node.type === AST_NODE_TYPES20.ArrowFunctionExpression || node.type === AST_NODE_TYPES20.FunctionExpression);
|
|
4874
5047
|
var functionConstName = (decl) => {
|
|
4875
5048
|
if (decl.declarations.length !== 1) return null;
|
|
4876
5049
|
const [declarator] = decl.declarations;
|
|
4877
5050
|
if (declarator === void 0) return null;
|
|
4878
|
-
if (declarator.id.type !==
|
|
5051
|
+
if (declarator.id.type !== AST_NODE_TYPES20.Identifier) return null;
|
|
4879
5052
|
if (!isFunctionExpression(declarator.init)) return null;
|
|
4880
5053
|
return declarator.id.name;
|
|
4881
5054
|
};
|
|
@@ -4889,20 +5062,20 @@ var summarizeExports = (body) => {
|
|
|
4889
5062
|
};
|
|
4890
5063
|
for (const statement of body) {
|
|
4891
5064
|
switch (statement.type) {
|
|
4892
|
-
case
|
|
5065
|
+
case AST_NODE_TYPES20.ExportAllDeclaration:
|
|
4893
5066
|
hasReExport = true;
|
|
4894
5067
|
break;
|
|
4895
|
-
case
|
|
5068
|
+
case AST_NODE_TYPES20.ExportDefaultDeclaration: {
|
|
4896
5069
|
names += 1;
|
|
4897
5070
|
const decl = statement.declaration;
|
|
4898
|
-
if (decl.type ===
|
|
5071
|
+
if (decl.type === AST_NODE_TYPES20.FunctionDeclaration && decl.id !== null) {
|
|
4899
5072
|
candidate = { name: decl.id.name, node: statement };
|
|
4900
|
-
} else if (decl.type ===
|
|
5073
|
+
} else if (decl.type === AST_NODE_TYPES20.ClassDeclaration && decl.id !== null) {
|
|
4901
5074
|
candidate = { name: decl.id.name, node: statement };
|
|
4902
5075
|
}
|
|
4903
5076
|
break;
|
|
4904
5077
|
}
|
|
4905
|
-
case
|
|
5078
|
+
case AST_NODE_TYPES20.ExportNamedDeclaration: {
|
|
4906
5079
|
if (statement.source !== null) {
|
|
4907
5080
|
hasReExport = true;
|
|
4908
5081
|
break;
|
|
@@ -4913,15 +5086,15 @@ var summarizeExports = (body) => {
|
|
|
4913
5086
|
break;
|
|
4914
5087
|
}
|
|
4915
5088
|
switch (decl.type) {
|
|
4916
|
-
case
|
|
5089
|
+
case AST_NODE_TYPES20.FunctionDeclaration:
|
|
4917
5090
|
if (decl.id !== null) addCandidate(decl.id.name, statement);
|
|
4918
5091
|
else names += 1;
|
|
4919
5092
|
break;
|
|
4920
|
-
case
|
|
5093
|
+
case AST_NODE_TYPES20.ClassDeclaration:
|
|
4921
5094
|
if (decl.id !== null) addCandidate(decl.id.name, statement);
|
|
4922
5095
|
else names += 1;
|
|
4923
5096
|
break;
|
|
4924
|
-
case
|
|
5097
|
+
case AST_NODE_TYPES20.VariableDeclaration: {
|
|
4925
5098
|
const fnName = functionConstName(decl);
|
|
4926
5099
|
if (fnName !== null && decl.declarations.length === 1) {
|
|
4927
5100
|
addCandidate(fnName, statement);
|
|
@@ -4961,8 +5134,8 @@ var single_public_export_default = ESLintUtils29.RuleCreator(
|
|
|
4961
5134
|
if (base.endsWith(".d.ts")) return {};
|
|
4962
5135
|
if (TEST_FILE_RE.test(base)) return {};
|
|
4963
5136
|
if (isTestFile(context.filename)) return {};
|
|
4964
|
-
const
|
|
4965
|
-
if (!JUNK_DRAWER_STEMS.has(
|
|
5137
|
+
const stem2 = stemOf(base);
|
|
5138
|
+
if (!JUNK_DRAWER_STEMS.has(stem2.toLowerCase())) return {};
|
|
4966
5139
|
return {
|
|
4967
5140
|
Program(node) {
|
|
4968
5141
|
const { names, hasReExport, candidate } = summarizeExports(node.body);
|
|
@@ -4970,11 +5143,11 @@ var single_public_export_default = ESLintUtils29.RuleCreator(
|
|
|
4970
5143
|
if (names !== 1 || candidate === null) return;
|
|
4971
5144
|
if (CONVENTIONAL_BUCKET_EXPORTS.has(candidate.name)) return;
|
|
4972
5145
|
const expected = kebabCase2(candidate.name);
|
|
4973
|
-
if (
|
|
5146
|
+
if (stem2 === expected) return;
|
|
4974
5147
|
context.report({
|
|
4975
5148
|
node: candidate.node,
|
|
4976
5149
|
messageId: "renameJunkDrawer",
|
|
4977
|
-
data: { stem, name: candidate.name, expected }
|
|
5150
|
+
data: { stem: stem2, name: candidate.name, expected }
|
|
4978
5151
|
});
|
|
4979
5152
|
}
|
|
4980
5153
|
};
|
|
@@ -4985,7 +5158,7 @@ var single_public_export_default = ESLintUtils29.RuleCreator(
|
|
|
4985
5158
|
import { ESLintUtils as ESLintUtils30 } from "@typescript-eslint/utils";
|
|
4986
5159
|
|
|
4987
5160
|
// src/rules/_sql.ts
|
|
4988
|
-
import { AST_NODE_TYPES as
|
|
5161
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES21 } from "@typescript-eslint/utils";
|
|
4989
5162
|
function stripSqlNoise(text) {
|
|
4990
5163
|
const out = [...text];
|
|
4991
5164
|
const n = text.length;
|
|
@@ -5046,13 +5219,13 @@ function stripSqlNoise(text) {
|
|
|
5046
5219
|
var SUBSTITUTION_MARKER = "?";
|
|
5047
5220
|
function sqlTextOf(node) {
|
|
5048
5221
|
switch (node.type) {
|
|
5049
|
-
case
|
|
5222
|
+
case AST_NODE_TYPES21.Literal:
|
|
5050
5223
|
return typeof node.value === "string" ? node.value : null;
|
|
5051
|
-
case
|
|
5224
|
+
case AST_NODE_TYPES21.TemplateLiteral:
|
|
5052
5225
|
return node.quasis.map((q) => q.value.cooked ?? q.value.raw).join(SUBSTITUTION_MARKER);
|
|
5053
|
-
case
|
|
5226
|
+
case AST_NODE_TYPES21.TaggedTemplateExpression:
|
|
5054
5227
|
return sqlTextOf(node.quasi);
|
|
5055
|
-
case
|
|
5228
|
+
case AST_NODE_TYPES21.BinaryExpression: {
|
|
5056
5229
|
if (node.operator !== "+") {
|
|
5057
5230
|
return null;
|
|
5058
5231
|
}
|
|
@@ -5060,7 +5233,7 @@ function sqlTextOf(node) {
|
|
|
5060
5233
|
const right = sqlTextOf(node.right);
|
|
5061
5234
|
return left !== null && right !== null ? left + right : null;
|
|
5062
5235
|
}
|
|
5063
|
-
case
|
|
5236
|
+
case AST_NODE_TYPES21.ArrayExpression: {
|
|
5064
5237
|
const parts = [];
|
|
5065
5238
|
for (const element of node.elements) {
|
|
5066
5239
|
if (element === null) {
|
|
@@ -5080,7 +5253,7 @@ function sqlTextOf(node) {
|
|
|
5080
5253
|
}
|
|
5081
5254
|
function isJoinedFragmentArray(node) {
|
|
5082
5255
|
const parent = node.parent;
|
|
5083
|
-
return parent?.type ===
|
|
5256
|
+
return parent?.type === AST_NODE_TYPES21.MemberExpression && parent.object === node && !parent.computed && parent.property.type === AST_NODE_TYPES21.Identifier && parent.property.name === "join" && parent.parent?.type === AST_NODE_TYPES21.CallExpression;
|
|
5084
5257
|
}
|
|
5085
5258
|
function markConsumed(node, consumed) {
|
|
5086
5259
|
consumed.add(node);
|
|
@@ -5159,15 +5332,15 @@ var no_offset_pagination_default = ESLintUtils30.RuleCreator(
|
|
|
5159
5332
|
});
|
|
5160
5333
|
|
|
5161
5334
|
// src/rules/no-positional-tuple-return.ts
|
|
5162
|
-
import { AST_NODE_TYPES as
|
|
5335
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES22, ESLintUtils as ESLintUtils31 } from "@typescript-eslint/utils";
|
|
5163
5336
|
var MIN_ELEMENTS = 2;
|
|
5164
5337
|
var ACCESSOR_PAIR_LENGTH = 2;
|
|
5165
5338
|
var AWAITABLE_TYPES = /* @__PURE__ */ new Set(["Promise", "PromiseLike", "Awaited"]);
|
|
5166
5339
|
function tupleReturnType(node) {
|
|
5167
|
-
if (node.type ===
|
|
5340
|
+
if (node.type === AST_NODE_TYPES22.TSTupleType) {
|
|
5168
5341
|
return node;
|
|
5169
5342
|
}
|
|
5170
|
-
if (node.type ===
|
|
5343
|
+
if (node.type === AST_NODE_TYPES22.TSTypeReference && node.typeName.type === AST_NODE_TYPES22.Identifier && AWAITABLE_TYPES.has(node.typeName.name)) {
|
|
5171
5344
|
const argument = node.typeArguments?.params[0];
|
|
5172
5345
|
return argument === void 0 ? null : tupleReturnType(argument);
|
|
5173
5346
|
}
|
|
@@ -5181,30 +5354,30 @@ function isPermittedTuple(tuple, sourceCode) {
|
|
|
5181
5354
|
if (elements.length < MIN_ELEMENTS) {
|
|
5182
5355
|
return true;
|
|
5183
5356
|
}
|
|
5184
|
-
if (elements.some((element) => element.type ===
|
|
5357
|
+
if (elements.some((element) => element.type === AST_NODE_TYPES22.TSRestType)) {
|
|
5185
5358
|
return true;
|
|
5186
5359
|
}
|
|
5187
|
-
if (elements.some((element) => element.type ===
|
|
5360
|
+
if (elements.some((element) => element.type === AST_NODE_TYPES22.TSNamedTupleMember)) {
|
|
5188
5361
|
return true;
|
|
5189
5362
|
}
|
|
5190
|
-
if (elements[0]?.type ===
|
|
5363
|
+
if (elements[0]?.type === AST_NODE_TYPES22.TSLiteralType) {
|
|
5191
5364
|
return true;
|
|
5192
5365
|
}
|
|
5193
|
-
if (elements.length === ACCESSOR_PAIR_LENGTH && elements.some((element) => element.type ===
|
|
5366
|
+
if (elements.length === ACCESSOR_PAIR_LENGTH && elements.some((element) => element.type === AST_NODE_TYPES22.TSFunctionType)) {
|
|
5194
5367
|
return true;
|
|
5195
5368
|
}
|
|
5196
5369
|
const texts = new Set(elements.map((element) => normalizedText(sourceCode, element)));
|
|
5197
5370
|
return texts.size === 1;
|
|
5198
5371
|
}
|
|
5199
5372
|
function functionName(node) {
|
|
5200
|
-
if (node.type ===
|
|
5373
|
+
if (node.type === AST_NODE_TYPES22.FunctionDeclaration) {
|
|
5201
5374
|
return node.id?.name ?? null;
|
|
5202
5375
|
}
|
|
5203
5376
|
const parent = node.parent;
|
|
5204
|
-
if (parent?.type ===
|
|
5377
|
+
if (parent?.type === AST_NODE_TYPES22.VariableDeclarator && parent.id.type === AST_NODE_TYPES22.Identifier) {
|
|
5205
5378
|
return parent.id.name;
|
|
5206
5379
|
}
|
|
5207
|
-
if ((parent?.type ===
|
|
5380
|
+
if ((parent?.type === AST_NODE_TYPES22.MethodDefinition || parent?.type === AST_NODE_TYPES22.PropertyDefinition || parent?.type === AST_NODE_TYPES22.Property) && parent.key.type === AST_NODE_TYPES22.Identifier) {
|
|
5208
5381
|
return parent.key.name;
|
|
5209
5382
|
}
|
|
5210
5383
|
return null;
|
|
@@ -5212,7 +5385,7 @@ function functionName(node) {
|
|
|
5212
5385
|
function isInlineExported(node) {
|
|
5213
5386
|
for (let current = node; current != null; current = current.parent) {
|
|
5214
5387
|
const parent = current.parent;
|
|
5215
|
-
if (parent?.type ===
|
|
5388
|
+
if (parent?.type === AST_NODE_TYPES22.ExportNamedDeclaration || parent?.type === AST_NODE_TYPES22.ExportDefaultDeclaration) {
|
|
5216
5389
|
return true;
|
|
5217
5390
|
}
|
|
5218
5391
|
}
|
|
@@ -5221,18 +5394,18 @@ function isInlineExported(node) {
|
|
|
5221
5394
|
function moduleScopeBindingName(node) {
|
|
5222
5395
|
let current = node;
|
|
5223
5396
|
let child = node;
|
|
5224
|
-
while (current.parent != null && current.parent.type !==
|
|
5397
|
+
while (current.parent != null && current.parent.type !== AST_NODE_TYPES22.Program) {
|
|
5225
5398
|
child = current;
|
|
5226
5399
|
current = current.parent;
|
|
5227
5400
|
}
|
|
5228
|
-
if (current.parent?.type !==
|
|
5401
|
+
if (current.parent?.type !== AST_NODE_TYPES22.Program) {
|
|
5229
5402
|
return null;
|
|
5230
5403
|
}
|
|
5231
|
-
if (current.type ===
|
|
5404
|
+
if (current.type === AST_NODE_TYPES22.FunctionDeclaration || current.type === AST_NODE_TYPES22.ClassDeclaration) {
|
|
5232
5405
|
return current.id?.name ?? null;
|
|
5233
5406
|
}
|
|
5234
|
-
if (current.type ===
|
|
5235
|
-
if (child.type !==
|
|
5407
|
+
if (current.type === AST_NODE_TYPES22.VariableDeclaration) {
|
|
5408
|
+
if (child.type !== AST_NODE_TYPES22.VariableDeclarator || child.id.type !== AST_NODE_TYPES22.Identifier) {
|
|
5236
5409
|
return null;
|
|
5237
5410
|
}
|
|
5238
5411
|
return child.id.name;
|
|
@@ -5242,19 +5415,19 @@ function moduleScopeBindingName(node) {
|
|
|
5242
5415
|
function specifierExportedNames(program) {
|
|
5243
5416
|
const names = /* @__PURE__ */ new Set();
|
|
5244
5417
|
for (const statement of program.body) {
|
|
5245
|
-
if (statement.type ===
|
|
5418
|
+
if (statement.type === AST_NODE_TYPES22.ExportNamedDeclaration && statement.declaration == null && statement.source == null && statement.exportKind !== "type") {
|
|
5246
5419
|
for (const specifier of statement.specifiers) {
|
|
5247
|
-
if (specifier.exportKind !== "type" && specifier.local.type ===
|
|
5420
|
+
if (specifier.exportKind !== "type" && specifier.local.type === AST_NODE_TYPES22.Identifier) {
|
|
5248
5421
|
names.add(specifier.local.name);
|
|
5249
5422
|
}
|
|
5250
5423
|
}
|
|
5251
5424
|
continue;
|
|
5252
5425
|
}
|
|
5253
|
-
if (statement.type ===
|
|
5426
|
+
if (statement.type === AST_NODE_TYPES22.ExportDefaultDeclaration && statement.declaration.type === AST_NODE_TYPES22.Identifier) {
|
|
5254
5427
|
names.add(statement.declaration.name);
|
|
5255
5428
|
continue;
|
|
5256
5429
|
}
|
|
5257
|
-
if (statement.type ===
|
|
5430
|
+
if (statement.type === AST_NODE_TYPES22.TSExportAssignment && statement.expression.type === AST_NODE_TYPES22.Identifier) {
|
|
5258
5431
|
names.add(statement.expression.name);
|
|
5259
5432
|
}
|
|
5260
5433
|
}
|
|
@@ -5318,7 +5491,7 @@ var no_positional_tuple_return_default = ESLintUtils31.RuleCreator(
|
|
|
5318
5491
|
});
|
|
5319
5492
|
|
|
5320
5493
|
// src/rules/no-repeated-string-literal.ts
|
|
5321
|
-
import { AST_NODE_TYPES as
|
|
5494
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES23, ESLintUtils as ESLintUtils32 } from "@typescript-eslint/utils";
|
|
5322
5495
|
var MIN_LENGTH = 40;
|
|
5323
5496
|
var MIN_OCCURRENCES = 3;
|
|
5324
5497
|
var MIN_DISTINCT_SCOPES = 2;
|
|
@@ -5326,9 +5499,9 @@ var PREVIEW_LENGTH = 40;
|
|
|
5326
5499
|
var SQL_KEYWORD_RE = /\b(SELECT|INSERT|UPDATE|DELETE|FROM|WHERE|JOIN|VALUES|ON CONFLICT|RETURNING|GROUP BY|ORDER BY)\b/;
|
|
5327
5500
|
var IDENTIFIER_RE = /^[a-z_][a-z0-9_.]*$/;
|
|
5328
5501
|
var FUNCTION_TYPES = /* @__PURE__ */ new Set([
|
|
5329
|
-
|
|
5330
|
-
|
|
5331
|
-
|
|
5502
|
+
AST_NODE_TYPES23.FunctionDeclaration,
|
|
5503
|
+
AST_NODE_TYPES23.FunctionExpression,
|
|
5504
|
+
AST_NODE_TYPES23.ArrowFunctionExpression
|
|
5332
5505
|
]);
|
|
5333
5506
|
function isStructured(value) {
|
|
5334
5507
|
return value.includes("\n") || SQL_KEYWORD_RE.test(value) || IDENTIFIER_RE.test(value);
|
|
@@ -5350,7 +5523,7 @@ function isScaffolding(node) {
|
|
|
5350
5523
|
if (parent === void 0) {
|
|
5351
5524
|
return true;
|
|
5352
5525
|
}
|
|
5353
|
-
return parent.type ===
|
|
5526
|
+
return parent.type === AST_NODE_TYPES23.ImportDeclaration || parent.type === AST_NODE_TYPES23.ExportNamedDeclaration || parent.type === AST_NODE_TYPES23.ExportAllDeclaration || parent.type === AST_NODE_TYPES23.TSImportType || parent.type === AST_NODE_TYPES23.JSXAttribute || parent.type === AST_NODE_TYPES23.TSLiteralType;
|
|
5354
5527
|
}
|
|
5355
5528
|
var no_repeated_string_literal_default = ESLintUtils32.RuleCreator(
|
|
5356
5529
|
(name) => `https://github.com/sarj-ai/standards/blob/main/packages/typescript/src/rules/${name}.ts`
|
|
@@ -5392,7 +5565,7 @@ var no_repeated_string_literal_default = ESLintUtils32.RuleCreator(
|
|
|
5392
5565
|
}
|
|
5393
5566
|
},
|
|
5394
5567
|
TemplateLiteral(node) {
|
|
5395
|
-
if (node.parent.type ===
|
|
5568
|
+
if (node.parent.type === AST_NODE_TYPES23.TaggedTemplateExpression) {
|
|
5396
5569
|
return;
|
|
5397
5570
|
}
|
|
5398
5571
|
const [only] = node.quasis;
|
|
@@ -5498,7 +5671,7 @@ var no_select_star_default = ESLintUtils33.RuleCreator(
|
|
|
5498
5671
|
});
|
|
5499
5672
|
|
|
5500
5673
|
// src/rules/no-sleep-in-test-body.ts
|
|
5501
|
-
import { AST_NODE_TYPES as
|
|
5674
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES24, ESLintUtils as ESLintUtils34 } from "@typescript-eslint/utils";
|
|
5502
5675
|
var SLEEP_HELPERS = /* @__PURE__ */ new Set(["sleep", "delay", "wait", "pause"]);
|
|
5503
5676
|
var TEST_CALLERS = /* @__PURE__ */ new Set([
|
|
5504
5677
|
"it",
|
|
@@ -5507,34 +5680,34 @@ var TEST_CALLERS = /* @__PURE__ */ new Set([
|
|
|
5507
5680
|
"afterEach"
|
|
5508
5681
|
]);
|
|
5509
5682
|
var FUNCTION_TYPES2 = /* @__PURE__ */ new Set([
|
|
5510
|
-
|
|
5511
|
-
|
|
5512
|
-
|
|
5683
|
+
AST_NODE_TYPES24.FunctionDeclaration,
|
|
5684
|
+
AST_NODE_TYPES24.FunctionExpression,
|
|
5685
|
+
AST_NODE_TYPES24.ArrowFunctionExpression
|
|
5513
5686
|
]);
|
|
5514
5687
|
function isNonzeroNumericLiteral(node) {
|
|
5515
|
-
return node?.type ===
|
|
5688
|
+
return node?.type === AST_NODE_TYPES24.Literal && typeof node.value === "number" && node.value !== 0;
|
|
5516
5689
|
}
|
|
5517
5690
|
function isTimedSetTimeout(node) {
|
|
5518
|
-
return node.type ===
|
|
5691
|
+
return node.type === AST_NODE_TYPES24.CallExpression && node.callee.type === AST_NODE_TYPES24.Identifier && node.callee.name === "setTimeout" && node.arguments.length >= 2 && isNonzeroNumericLiteral(node.arguments[1]);
|
|
5519
5692
|
}
|
|
5520
5693
|
function isPromiseSleep(node) {
|
|
5521
|
-
if (node.callee.type !==
|
|
5694
|
+
if (node.callee.type !== AST_NODE_TYPES24.Identifier || node.callee.name !== "Promise") {
|
|
5522
5695
|
return false;
|
|
5523
5696
|
}
|
|
5524
5697
|
const executor = node.arguments[0];
|
|
5525
|
-
if (executor?.type !==
|
|
5698
|
+
if (executor?.type !== AST_NODE_TYPES24.ArrowFunctionExpression && executor?.type !== AST_NODE_TYPES24.FunctionExpression) {
|
|
5526
5699
|
return false;
|
|
5527
5700
|
}
|
|
5528
5701
|
const body = executor.body;
|
|
5529
|
-
if (body.type !==
|
|
5702
|
+
if (body.type !== AST_NODE_TYPES24.BlockStatement) {
|
|
5530
5703
|
return isTimedSetTimeout(body);
|
|
5531
5704
|
}
|
|
5532
5705
|
return body.body.some(
|
|
5533
|
-
(stmt) => stmt.type ===
|
|
5706
|
+
(stmt) => stmt.type === AST_NODE_TYPES24.ExpressionStatement && isTimedSetTimeout(stmt.expression)
|
|
5534
5707
|
);
|
|
5535
5708
|
}
|
|
5536
5709
|
function isHelperSleep(node) {
|
|
5537
|
-
return node.callee.type ===
|
|
5710
|
+
return node.callee.type === AST_NODE_TYPES24.Identifier && SLEEP_HELPERS.has(node.callee.name) && node.arguments.length >= 1 && isNonzeroNumericLiteral(node.arguments[0]);
|
|
5538
5711
|
}
|
|
5539
5712
|
function nearestEnclosingFunction(node) {
|
|
5540
5713
|
for (let current = node.parent; current != null; current = current.parent) {
|
|
@@ -5542,7 +5715,7 @@ function nearestEnclosingFunction(node) {
|
|
|
5542
5715
|
continue;
|
|
5543
5716
|
}
|
|
5544
5717
|
const grandparent = current.parent;
|
|
5545
|
-
const isPromiseExecutor = grandparent?.type ===
|
|
5718
|
+
const isPromiseExecutor = grandparent?.type === AST_NODE_TYPES24.NewExpression && isPromiseSleep(grandparent);
|
|
5546
5719
|
if (!isPromiseExecutor) {
|
|
5547
5720
|
return current;
|
|
5548
5721
|
}
|
|
@@ -5550,23 +5723,23 @@ function nearestEnclosingFunction(node) {
|
|
|
5550
5723
|
return null;
|
|
5551
5724
|
}
|
|
5552
5725
|
function testCallerName(callee) {
|
|
5553
|
-
if (callee.type ===
|
|
5726
|
+
if (callee.type === AST_NODE_TYPES24.Identifier) {
|
|
5554
5727
|
return callee.name;
|
|
5555
5728
|
}
|
|
5556
|
-
if (callee.type ===
|
|
5729
|
+
if (callee.type === AST_NODE_TYPES24.MemberExpression) {
|
|
5557
5730
|
return testCallerName(callee.object);
|
|
5558
5731
|
}
|
|
5559
|
-
if (callee.type ===
|
|
5732
|
+
if (callee.type === AST_NODE_TYPES24.CallExpression) {
|
|
5560
5733
|
return testCallerName(callee.callee);
|
|
5561
5734
|
}
|
|
5562
|
-
if (callee.type ===
|
|
5735
|
+
if (callee.type === AST_NODE_TYPES24.TaggedTemplateExpression) {
|
|
5563
5736
|
return testCallerName(callee.tag);
|
|
5564
5737
|
}
|
|
5565
5738
|
return null;
|
|
5566
5739
|
}
|
|
5567
5740
|
function isTestBody(fn) {
|
|
5568
5741
|
const call = fn.parent;
|
|
5569
|
-
if (call?.type !==
|
|
5742
|
+
if (call?.type !== AST_NODE_TYPES24.CallExpression || !call.arguments.some((argument) => argument === fn)) {
|
|
5570
5743
|
return false;
|
|
5571
5744
|
}
|
|
5572
5745
|
const name = testCallerName(call.callee);
|
|
@@ -5614,7 +5787,7 @@ var no_sleep_in_test_body_default = ESLintUtils34.RuleCreator(
|
|
|
5614
5787
|
});
|
|
5615
5788
|
|
|
5616
5789
|
// src/rules/prefer-constant-time-secret-compare.ts
|
|
5617
|
-
import { AST_NODE_TYPES as
|
|
5790
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES25, ESLintUtils as ESLintUtils35 } from "@typescript-eslint/utils";
|
|
5618
5791
|
var EQUALITY_OPERATORS = /* @__PURE__ */ new Set(["===", "!==", "==", "!="]);
|
|
5619
5792
|
var SENTINEL_IDENTIFIERS = /* @__PURE__ */ new Set(["undefined", "NaN"]);
|
|
5620
5793
|
var SENTINEL_WORDS = /(^|_)(SENTINEL|EMPTY|NONE|NULL|UNSET|MISSING|PLACEHOLDER|DUMMY|FAKE|EXAMPLE)(_|$)/;
|
|
@@ -5627,36 +5800,36 @@ function isConstantReference(identifier) {
|
|
|
5627
5800
|
}
|
|
5628
5801
|
function isExcludedOperand(node) {
|
|
5629
5802
|
switch (node.type) {
|
|
5630
|
-
case
|
|
5803
|
+
case AST_NODE_TYPES25.Literal:
|
|
5631
5804
|
return true;
|
|
5632
|
-
case
|
|
5805
|
+
case AST_NODE_TYPES25.TemplateLiteral:
|
|
5633
5806
|
return node.expressions.length === 0;
|
|
5634
|
-
case
|
|
5807
|
+
case AST_NODE_TYPES25.Identifier:
|
|
5635
5808
|
return SENTINEL_IDENTIFIERS.has(node.name) || SENTINEL_PREFIX_RE.test(node.name) || isConstantReference(node.name);
|
|
5636
|
-
case
|
|
5637
|
-
return !node.computed && node.property.type ===
|
|
5809
|
+
case AST_NODE_TYPES25.MemberExpression:
|
|
5810
|
+
return !node.computed && node.property.type === AST_NODE_TYPES25.Identifier && (SENTINEL_PREFIX_RE.test(node.property.name) || isConstantReference(node.property.name));
|
|
5638
5811
|
default:
|
|
5639
5812
|
return false;
|
|
5640
5813
|
}
|
|
5641
5814
|
}
|
|
5642
5815
|
function operandName(node) {
|
|
5643
|
-
if (node.type ===
|
|
5816
|
+
if (node.type === AST_NODE_TYPES25.Identifier) {
|
|
5644
5817
|
return node.name;
|
|
5645
5818
|
}
|
|
5646
|
-
if (node.type ===
|
|
5819
|
+
if (node.type === AST_NODE_TYPES25.MemberExpression && !node.computed && node.property.type === AST_NODE_TYPES25.Identifier) {
|
|
5647
5820
|
return node.property.name;
|
|
5648
5821
|
}
|
|
5649
5822
|
return null;
|
|
5650
5823
|
}
|
|
5651
5824
|
function isSecretOperand(node) {
|
|
5652
|
-
if (node.type ===
|
|
5825
|
+
if (node.type === AST_NODE_TYPES25.TemplateLiteral) {
|
|
5653
5826
|
return node.expressions.some((expression) => isSecretOperand(expression));
|
|
5654
5827
|
}
|
|
5655
5828
|
const name = operandName(node);
|
|
5656
5829
|
return name !== null && isAuthSecretName(name);
|
|
5657
5830
|
}
|
|
5658
5831
|
function secretNameOf(node) {
|
|
5659
|
-
if (node.type ===
|
|
5832
|
+
if (node.type === AST_NODE_TYPES25.TemplateLiteral) {
|
|
5660
5833
|
for (const expression of node.expressions) {
|
|
5661
5834
|
const nested = secretNameOf(expression);
|
|
5662
5835
|
if (nested !== null) {
|
|
@@ -5743,17 +5916,17 @@ var store_insert_requires_on_conflict_default = ESLintUtils36.RuleCreator(
|
|
|
5743
5916
|
});
|
|
5744
5917
|
|
|
5745
5918
|
// src/rules/no-dynamic-sql.ts
|
|
5746
|
-
import { AST_NODE_TYPES as
|
|
5919
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES26, ESLintUtils as ESLintUtils37 } from "@typescript-eslint/utils";
|
|
5747
5920
|
var DEFAULT_METHODS = ["prepare", "exec", "query"];
|
|
5748
5921
|
var CONSTANT_CASE_RE = /^[A-Z][A-Z0-9_]*$/;
|
|
5749
5922
|
function isStaticFragment(expression) {
|
|
5750
|
-
if (expression.type ===
|
|
5923
|
+
if (expression.type === AST_NODE_TYPES26.Identifier) {
|
|
5751
5924
|
return CONSTANT_CASE_RE.test(expression.name);
|
|
5752
5925
|
}
|
|
5753
|
-
if (expression.type ===
|
|
5926
|
+
if (expression.type === AST_NODE_TYPES26.MemberExpression && !expression.computed && expression.property.type === AST_NODE_TYPES26.Identifier) {
|
|
5754
5927
|
return CONSTANT_CASE_RE.test(expression.property.name);
|
|
5755
5928
|
}
|
|
5756
|
-
if (expression.type ===
|
|
5929
|
+
if (expression.type === AST_NODE_TYPES26.Literal) {
|
|
5757
5930
|
return typeof expression.value === "string";
|
|
5758
5931
|
}
|
|
5759
5932
|
return false;
|
|
@@ -5764,36 +5937,36 @@ function runtimeInterpolations(template) {
|
|
|
5764
5937
|
);
|
|
5765
5938
|
}
|
|
5766
5939
|
function concatOperands(node) {
|
|
5767
|
-
if (node.type ===
|
|
5940
|
+
if (node.type === AST_NODE_TYPES26.BinaryExpression && node.operator === "+") {
|
|
5768
5941
|
return [...concatOperands(node.left), ...concatOperands(node.right)];
|
|
5769
5942
|
}
|
|
5770
5943
|
return [node];
|
|
5771
5944
|
}
|
|
5772
5945
|
function runtimeConcatOperands(node) {
|
|
5773
|
-
if (node.type !==
|
|
5946
|
+
if (node.type !== AST_NODE_TYPES26.BinaryExpression || node.operator !== "+") {
|
|
5774
5947
|
return [];
|
|
5775
5948
|
}
|
|
5776
5949
|
const operands = concatOperands(node);
|
|
5777
5950
|
const hasStringLiteral = operands.some(
|
|
5778
|
-
(operand) => operand.type ===
|
|
5951
|
+
(operand) => operand.type === AST_NODE_TYPES26.Literal && typeof operand.value === "string"
|
|
5779
5952
|
);
|
|
5780
5953
|
if (!hasStringLiteral) {
|
|
5781
5954
|
return [];
|
|
5782
5955
|
}
|
|
5783
5956
|
return operands.filter(
|
|
5784
|
-
(operand) => operand.type !==
|
|
5957
|
+
(operand) => operand.type !== AST_NODE_TYPES26.Literal && !isStaticFragment(operand)
|
|
5785
5958
|
);
|
|
5786
5959
|
}
|
|
5787
5960
|
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;
|
|
5788
5961
|
var RUNTIME_MARKER = " ? ";
|
|
5789
5962
|
function staticStatementText(node) {
|
|
5790
|
-
if (node.type ===
|
|
5963
|
+
if (node.type === AST_NODE_TYPES26.TemplateLiteral) {
|
|
5791
5964
|
return node.quasis.map((quasi) => quasi.value.cooked ?? quasi.value.raw).join(RUNTIME_MARKER);
|
|
5792
5965
|
}
|
|
5793
|
-
if (node.type ===
|
|
5966
|
+
if (node.type === AST_NODE_TYPES26.Literal) {
|
|
5794
5967
|
return typeof node.value === "string" ? node.value : RUNTIME_MARKER;
|
|
5795
5968
|
}
|
|
5796
|
-
if (node.type ===
|
|
5969
|
+
if (node.type === AST_NODE_TYPES26.BinaryExpression && node.operator === "+") {
|
|
5797
5970
|
return staticStatementText(node.left) + staticStatementText(node.right);
|
|
5798
5971
|
}
|
|
5799
5972
|
return RUNTIME_MARKER;
|
|
@@ -5803,7 +5976,7 @@ function looksLikeSql(node) {
|
|
|
5803
5976
|
}
|
|
5804
5977
|
function statementMethodName(node, methods) {
|
|
5805
5978
|
const callee = node.callee;
|
|
5806
|
-
if (callee.type !==
|
|
5979
|
+
if (callee.type !== AST_NODE_TYPES26.MemberExpression || callee.computed || callee.property.type !== AST_NODE_TYPES26.Identifier) {
|
|
5807
5980
|
return null;
|
|
5808
5981
|
}
|
|
5809
5982
|
const name = callee.property.name;
|
|
@@ -5848,7 +6021,7 @@ var no_dynamic_sql_default = ESLintUtils37.RuleCreator(
|
|
|
5848
6021
|
if (statement === void 0 || !looksLikeSql(statement)) {
|
|
5849
6022
|
return;
|
|
5850
6023
|
}
|
|
5851
|
-
const offenders = statement.type ===
|
|
6024
|
+
const offenders = statement.type === AST_NODE_TYPES26.TemplateLiteral ? runtimeInterpolations(statement) : runtimeConcatOperands(statement);
|
|
5852
6025
|
for (const offender of offenders) {
|
|
5853
6026
|
context.report({
|
|
5854
6027
|
node: offender,
|
|
@@ -5974,7 +6147,7 @@ var no_raw_fetch_outside_clients_default = ESLintUtils38.RuleCreator(
|
|
|
5974
6147
|
});
|
|
5975
6148
|
|
|
5976
6149
|
// src/rules/no-storage-in-stateless-modules.ts
|
|
5977
|
-
import { AST_NODE_TYPES as
|
|
6150
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES27, ESLintUtils as ESLintUtils39 } from "@typescript-eslint/utils";
|
|
5978
6151
|
var DEFAULT_METHODS2 = [
|
|
5979
6152
|
"prepare",
|
|
5980
6153
|
"put",
|
|
@@ -5993,7 +6166,7 @@ function compile2(patterns) {
|
|
|
5993
6166
|
}
|
|
5994
6167
|
function storageMethodName(node, methods) {
|
|
5995
6168
|
const callee = node.callee;
|
|
5996
|
-
if (callee.type !==
|
|
6169
|
+
if (callee.type !== AST_NODE_TYPES27.MemberExpression || callee.computed || callee.property.type !== AST_NODE_TYPES27.Identifier) {
|
|
5997
6170
|
return null;
|
|
5998
6171
|
}
|
|
5999
6172
|
const name = callee.property.name;
|
|
@@ -6065,7 +6238,7 @@ var no_storage_in_stateless_modules_default = ESLintUtils39.RuleCreator(
|
|
|
6065
6238
|
// src/rules/no-zod-native-enum.ts
|
|
6066
6239
|
import {
|
|
6067
6240
|
ESLintUtils as ESLintUtils40,
|
|
6068
|
-
AST_NODE_TYPES as
|
|
6241
|
+
AST_NODE_TYPES as AST_NODE_TYPES28
|
|
6069
6242
|
} from "@typescript-eslint/utils";
|
|
6070
6243
|
import * as ts2 from "typescript";
|
|
6071
6244
|
var IGNORE_PATTERNS2 = [
|
|
@@ -6084,7 +6257,7 @@ function isZodModule(source) {
|
|
|
6084
6257
|
return /(^|[/@-])zod([/-]|$)/.test(source);
|
|
6085
6258
|
}
|
|
6086
6259
|
function unwrap3(node) {
|
|
6087
|
-
if (node.type ===
|
|
6260
|
+
if (node.type === AST_NODE_TYPES28.TSAsExpression || node.type === AST_NODE_TYPES28.TSSatisfiesExpression) {
|
|
6088
6261
|
return unwrap3(node.expression);
|
|
6089
6262
|
}
|
|
6090
6263
|
return node;
|
|
@@ -6092,14 +6265,14 @@ function unwrap3(node) {
|
|
|
6092
6265
|
function stringValueTexts(node, sourceCode) {
|
|
6093
6266
|
const texts = [];
|
|
6094
6267
|
for (const prop of node.properties) {
|
|
6095
|
-
if (prop.type !==
|
|
6268
|
+
if (prop.type !== AST_NODE_TYPES28.Property) {
|
|
6096
6269
|
return null;
|
|
6097
6270
|
}
|
|
6098
6271
|
if (prop.computed || prop.shorthand || prop.method || prop.kind !== "init") {
|
|
6099
6272
|
return null;
|
|
6100
6273
|
}
|
|
6101
6274
|
const value = prop.value;
|
|
6102
|
-
if (value.type !==
|
|
6275
|
+
if (value.type !== AST_NODE_TYPES28.Literal || typeof value.value !== "string") {
|
|
6103
6276
|
return null;
|
|
6104
6277
|
}
|
|
6105
6278
|
const text = sourceCode.getText(value);
|
|
@@ -6115,7 +6288,7 @@ function resolvesToLocalEnum(node, scope) {
|
|
|
6115
6288
|
const variable = current.variables.find((v) => v.name === node.name);
|
|
6116
6289
|
if (variable !== void 0) {
|
|
6117
6290
|
return variable.defs.some(
|
|
6118
|
-
(def) => def.node.type ===
|
|
6291
|
+
(def) => def.node.type === AST_NODE_TYPES28.TSEnumDeclaration
|
|
6119
6292
|
);
|
|
6120
6293
|
}
|
|
6121
6294
|
current = current.upper;
|
|
@@ -6169,25 +6342,25 @@ var no_zod_native_enum_default = ESLintUtils40.RuleCreator(
|
|
|
6169
6342
|
const zodImportedNames = /* @__PURE__ */ new Map();
|
|
6170
6343
|
function isZodMemberCall(node, api) {
|
|
6171
6344
|
const callee = node.callee;
|
|
6172
|
-
if (callee.type ===
|
|
6345
|
+
if (callee.type === AST_NODE_TYPES28.MemberExpression && !callee.computed && callee.property.type === AST_NODE_TYPES28.Identifier) {
|
|
6173
6346
|
return callee.property.name === api;
|
|
6174
6347
|
}
|
|
6175
|
-
if (callee.type ===
|
|
6348
|
+
if (callee.type === AST_NODE_TYPES28.Identifier) {
|
|
6176
6349
|
return zodImportedNames.get(callee.name) === api;
|
|
6177
6350
|
}
|
|
6178
6351
|
return false;
|
|
6179
6352
|
}
|
|
6180
6353
|
function buildFix(node) {
|
|
6181
6354
|
const callee = node.callee;
|
|
6182
|
-
if (callee.type !==
|
|
6355
|
+
if (callee.type !== AST_NODE_TYPES28.MemberExpression || callee.property.type !== AST_NODE_TYPES28.Identifier) {
|
|
6183
6356
|
return null;
|
|
6184
6357
|
}
|
|
6185
6358
|
const arg = node.arguments[0];
|
|
6186
|
-
if (arg === void 0 || node.arguments.length !== 1 || arg.type ===
|
|
6359
|
+
if (arg === void 0 || node.arguments.length !== 1 || arg.type === AST_NODE_TYPES28.SpreadElement) {
|
|
6187
6360
|
return null;
|
|
6188
6361
|
}
|
|
6189
6362
|
const inner = unwrap3(arg);
|
|
6190
|
-
if (inner.type !==
|
|
6363
|
+
if (inner.type !== AST_NODE_TYPES28.ObjectExpression) {
|
|
6191
6364
|
return null;
|
|
6192
6365
|
}
|
|
6193
6366
|
const values = stringValueTexts(inner, sourceCode);
|
|
@@ -6207,7 +6380,7 @@ var no_zod_native_enum_default = ESLintUtils40.RuleCreator(
|
|
|
6207
6380
|
return;
|
|
6208
6381
|
}
|
|
6209
6382
|
for (const spec of node.specifiers) {
|
|
6210
|
-
if (spec.type ===
|
|
6383
|
+
if (spec.type === AST_NODE_TYPES28.ImportSpecifier && spec.imported.type === AST_NODE_TYPES28.Identifier) {
|
|
6211
6384
|
zodImportedNames.set(spec.local.name, spec.imported.name);
|
|
6212
6385
|
}
|
|
6213
6386
|
}
|
|
@@ -6226,7 +6399,7 @@ var no_zod_native_enum_default = ESLintUtils40.RuleCreator(
|
|
|
6226
6399
|
return;
|
|
6227
6400
|
}
|
|
6228
6401
|
const arg = node.arguments[0];
|
|
6229
|
-
if (arg === void 0 || arg.type !==
|
|
6402
|
+
if (arg === void 0 || arg.type !== AST_NODE_TYPES28.Identifier) {
|
|
6230
6403
|
return;
|
|
6231
6404
|
}
|
|
6232
6405
|
const isEnum = resolvesToLocalEnum(arg, sourceCode.getScope(arg)) || services !== null && resolvesToImportedEnum(arg, services);
|
|
@@ -6245,7 +6418,7 @@ var no_zod_native_enum_default = ESLintUtils40.RuleCreator(
|
|
|
6245
6418
|
// src/rules/prefer-module-level-constant.ts
|
|
6246
6419
|
import {
|
|
6247
6420
|
ESLintUtils as ESLintUtils41,
|
|
6248
|
-
AST_NODE_TYPES as
|
|
6421
|
+
AST_NODE_TYPES as AST_NODE_TYPES29
|
|
6249
6422
|
} from "@typescript-eslint/utils";
|
|
6250
6423
|
var DEFAULT_MIN_ELEMENTS = 3;
|
|
6251
6424
|
var MAX_LITERAL_DEPTH = 4;
|
|
@@ -6282,9 +6455,9 @@ var MUTATING_METHODS = /* @__PURE__ */ new Set([
|
|
|
6282
6455
|
"assign"
|
|
6283
6456
|
]);
|
|
6284
6457
|
var FUNCTION_TYPES3 = /* @__PURE__ */ new Set([
|
|
6285
|
-
|
|
6286
|
-
|
|
6287
|
-
|
|
6458
|
+
AST_NODE_TYPES29.FunctionDeclaration,
|
|
6459
|
+
AST_NODE_TYPES29.FunctionExpression,
|
|
6460
|
+
AST_NODE_TYPES29.ArrowFunctionExpression
|
|
6288
6461
|
]);
|
|
6289
6462
|
var COLLECTION_CONSTRUCTORS = /* @__PURE__ */ new Set(["Set", "Map"]);
|
|
6290
6463
|
function isIgnoredFile3(filename, sourceText) {
|
|
@@ -6297,13 +6470,13 @@ function isTestFile2(filename) {
|
|
|
6297
6470
|
return TEST_FILE_PATTERNS.some((re) => re.test(filename));
|
|
6298
6471
|
}
|
|
6299
6472
|
function unwrap4(node) {
|
|
6300
|
-
if (node.type ===
|
|
6473
|
+
if (node.type === AST_NODE_TYPES29.TSAsExpression || node.type === AST_NODE_TYPES29.TSSatisfiesExpression || node.type === AST_NODE_TYPES29.TSNonNullExpression) {
|
|
6301
6474
|
return unwrap4(node.expression);
|
|
6302
6475
|
}
|
|
6303
6476
|
return node;
|
|
6304
6477
|
}
|
|
6305
6478
|
function isRegexLiteral(node) {
|
|
6306
|
-
return node.type ===
|
|
6479
|
+
return node.type === AST_NODE_TYPES29.Literal && "regex" in node && node.regex !== void 0;
|
|
6307
6480
|
}
|
|
6308
6481
|
function isLiteralOnly(node, depth) {
|
|
6309
6482
|
if (depth > MAX_LITERAL_DEPTH) {
|
|
@@ -6311,29 +6484,29 @@ function isLiteralOnly(node, depth) {
|
|
|
6311
6484
|
}
|
|
6312
6485
|
const inner = unwrap4(node);
|
|
6313
6486
|
switch (inner.type) {
|
|
6314
|
-
case
|
|
6487
|
+
case AST_NODE_TYPES29.Literal: {
|
|
6315
6488
|
return true;
|
|
6316
6489
|
}
|
|
6317
|
-
case
|
|
6490
|
+
case AST_NODE_TYPES29.TemplateLiteral: {
|
|
6318
6491
|
return inner.expressions.length === 0;
|
|
6319
6492
|
}
|
|
6320
|
-
case
|
|
6321
|
-
return (inner.operator === "-" || inner.operator === "+") && inner.argument.type ===
|
|
6493
|
+
case AST_NODE_TYPES29.UnaryExpression: {
|
|
6494
|
+
return (inner.operator === "-" || inner.operator === "+") && inner.argument.type === AST_NODE_TYPES29.Literal && typeof inner.argument.value === "number";
|
|
6322
6495
|
}
|
|
6323
|
-
case
|
|
6496
|
+
case AST_NODE_TYPES29.ArrayExpression: {
|
|
6324
6497
|
return inner.elements.every(
|
|
6325
|
-
(el) => el !== null && el.type !==
|
|
6498
|
+
(el) => el !== null && el.type !== AST_NODE_TYPES29.SpreadElement && isLiteralOnly(el, depth + 1)
|
|
6326
6499
|
);
|
|
6327
6500
|
}
|
|
6328
|
-
case
|
|
6501
|
+
case AST_NODE_TYPES29.ObjectExpression: {
|
|
6329
6502
|
return inner.properties.every((prop) => {
|
|
6330
|
-
if (prop.type !==
|
|
6503
|
+
if (prop.type !== AST_NODE_TYPES29.Property) {
|
|
6331
6504
|
return false;
|
|
6332
6505
|
}
|
|
6333
6506
|
if (prop.shorthand || prop.method || prop.kind !== "init") {
|
|
6334
6507
|
return false;
|
|
6335
6508
|
}
|
|
6336
|
-
if (prop.computed && prop.key.type !==
|
|
6509
|
+
if (prop.computed && prop.key.type !== AST_NODE_TYPES29.Literal) {
|
|
6337
6510
|
return false;
|
|
6338
6511
|
}
|
|
6339
6512
|
return isLiteralOnly(prop.value, depth + 1);
|
|
@@ -6346,7 +6519,7 @@ function isLiteralOnly(node, depth) {
|
|
|
6346
6519
|
}
|
|
6347
6520
|
function unwrapObjectFreeze(node) {
|
|
6348
6521
|
const inner = unwrap4(node);
|
|
6349
|
-
if (inner.type ===
|
|
6522
|
+
if (inner.type === AST_NODE_TYPES29.CallExpression && inner.callee.type === AST_NODE_TYPES29.MemberExpression && !inner.callee.computed && inner.callee.object.type === AST_NODE_TYPES29.Identifier && inner.callee.object.name === "Object" && inner.callee.property.type === AST_NODE_TYPES29.Identifier && inner.callee.property.name === "freeze" && inner.arguments.length === 1 && inner.arguments[0] !== void 0 && inner.arguments[0].type !== AST_NODE_TYPES29.SpreadElement) {
|
|
6350
6523
|
return unwrap4(inner.arguments[0]);
|
|
6351
6524
|
}
|
|
6352
6525
|
return inner;
|
|
@@ -6362,19 +6535,19 @@ function classify(init, checkRegex) {
|
|
|
6362
6535
|
}
|
|
6363
6536
|
return { kind: "regex", size: 1 };
|
|
6364
6537
|
}
|
|
6365
|
-
if (node.type ===
|
|
6538
|
+
if (node.type === AST_NODE_TYPES29.ArrayExpression) {
|
|
6366
6539
|
return isLiteralOnly(node, 0) ? { kind: "array", size: node.elements.length } : null;
|
|
6367
6540
|
}
|
|
6368
|
-
if (node.type ===
|
|
6541
|
+
if (node.type === AST_NODE_TYPES29.ObjectExpression) {
|
|
6369
6542
|
return isLiteralOnly(node, 0) ? { kind: "object", size: node.properties.length } : null;
|
|
6370
6543
|
}
|
|
6371
|
-
if (node.type ===
|
|
6544
|
+
if (node.type === AST_NODE_TYPES29.NewExpression && node.callee.type === AST_NODE_TYPES29.Identifier && COLLECTION_CONSTRUCTORS.has(node.callee.name)) {
|
|
6372
6545
|
const arg = node.arguments[0];
|
|
6373
|
-
if (node.arguments.length !== 1 || arg === void 0 || arg.type ===
|
|
6546
|
+
if (node.arguments.length !== 1 || arg === void 0 || arg.type === AST_NODE_TYPES29.SpreadElement) {
|
|
6374
6547
|
return null;
|
|
6375
6548
|
}
|
|
6376
6549
|
const entries = unwrap4(arg);
|
|
6377
|
-
if (entries.type !==
|
|
6550
|
+
if (entries.type !== AST_NODE_TYPES29.ArrayExpression) {
|
|
6378
6551
|
return null;
|
|
6379
6552
|
}
|
|
6380
6553
|
return isLiteralOnly(entries, 0) ? { kind: node.callee.name === "Set" ? "Set" : "Map", size: entries.elements.length } : null;
|
|
@@ -6403,10 +6576,10 @@ var NON_RETAINING_BUILTINS = /* @__PURE__ */ new Map(
|
|
|
6403
6576
|
);
|
|
6404
6577
|
function isNonRetainingBuiltinCall(node, argument) {
|
|
6405
6578
|
const callee = node.callee;
|
|
6406
|
-
if (callee.type ===
|
|
6579
|
+
if (callee.type === AST_NODE_TYPES29.Identifier && callee.name === "structuredClone") {
|
|
6407
6580
|
return true;
|
|
6408
6581
|
}
|
|
6409
|
-
if (callee.type !==
|
|
6582
|
+
if (callee.type !== AST_NODE_TYPES29.MemberExpression || callee.computed || callee.object.type !== AST_NODE_TYPES29.Identifier || callee.property.type !== AST_NODE_TYPES29.Identifier) {
|
|
6410
6583
|
return false;
|
|
6411
6584
|
}
|
|
6412
6585
|
const members = NON_RETAINING_BUILTINS.get(callee.object.name);
|
|
@@ -6420,38 +6593,38 @@ function isNonRetainingBuiltinCall(node, argument) {
|
|
|
6420
6593
|
}
|
|
6421
6594
|
function isSafeRead(identifier) {
|
|
6422
6595
|
const parent = identifier.parent;
|
|
6423
|
-
if (parent.type ===
|
|
6596
|
+
if (parent.type === AST_NODE_TYPES29.MemberExpression) {
|
|
6424
6597
|
if (parent.object !== identifier) {
|
|
6425
6598
|
return true;
|
|
6426
6599
|
}
|
|
6427
6600
|
const grandparent = parent.parent;
|
|
6428
|
-
if (grandparent.type ===
|
|
6601
|
+
if (grandparent.type === AST_NODE_TYPES29.AssignmentExpression && grandparent.left === parent) {
|
|
6429
6602
|
return false;
|
|
6430
6603
|
}
|
|
6431
|
-
if (grandparent.type ===
|
|
6604
|
+
if (grandparent.type === AST_NODE_TYPES29.UpdateExpression) {
|
|
6432
6605
|
return false;
|
|
6433
6606
|
}
|
|
6434
|
-
if (grandparent.type ===
|
|
6607
|
+
if (grandparent.type === AST_NODE_TYPES29.UnaryExpression && grandparent.operator === "delete") {
|
|
6435
6608
|
return false;
|
|
6436
6609
|
}
|
|
6437
|
-
if (!parent.computed && parent.property.type ===
|
|
6610
|
+
if (!parent.computed && parent.property.type === AST_NODE_TYPES29.Identifier && MUTATING_METHODS.has(parent.property.name) && grandparent.type === AST_NODE_TYPES29.CallExpression && grandparent.callee === parent) {
|
|
6438
6611
|
return false;
|
|
6439
6612
|
}
|
|
6440
6613
|
return true;
|
|
6441
6614
|
}
|
|
6442
|
-
if (parent.type ===
|
|
6615
|
+
if (parent.type === AST_NODE_TYPES29.ForOfStatement && parent.right === identifier) {
|
|
6443
6616
|
return true;
|
|
6444
6617
|
}
|
|
6445
|
-
if (parent.type ===
|
|
6618
|
+
if (parent.type === AST_NODE_TYPES29.SpreadElement) {
|
|
6446
6619
|
return true;
|
|
6447
6620
|
}
|
|
6448
|
-
if (parent.type ===
|
|
6621
|
+
if (parent.type === AST_NODE_TYPES29.BinaryExpression) {
|
|
6449
6622
|
return true;
|
|
6450
6623
|
}
|
|
6451
|
-
if (parent.type ===
|
|
6624
|
+
if (parent.type === AST_NODE_TYPES29.CallExpression && parent.arguments.includes(identifier) && isNonRetainingBuiltinCall(parent, identifier)) {
|
|
6452
6625
|
return true;
|
|
6453
6626
|
}
|
|
6454
|
-
if (parent.type ===
|
|
6627
|
+
if (parent.type === AST_NODE_TYPES29.UnaryExpression && parent.operator !== "delete") {
|
|
6455
6628
|
return true;
|
|
6456
6629
|
}
|
|
6457
6630
|
return false;
|
|
@@ -6508,7 +6681,7 @@ var prefer_module_level_constant_default = ESLintUtils41.RuleCreator(
|
|
|
6508
6681
|
if (reference.isWrite()) {
|
|
6509
6682
|
return false;
|
|
6510
6683
|
}
|
|
6511
|
-
if (reference.identifier.type !==
|
|
6684
|
+
if (reference.identifier.type !== AST_NODE_TYPES29.Identifier) {
|
|
6512
6685
|
return false;
|
|
6513
6686
|
}
|
|
6514
6687
|
if (!isSafeRead(reference.identifier)) {
|
|
@@ -6520,10 +6693,10 @@ var prefer_module_level_constant_default = ESLintUtils41.RuleCreator(
|
|
|
6520
6693
|
return {
|
|
6521
6694
|
VariableDeclarator(node) {
|
|
6522
6695
|
const declaration = node.parent;
|
|
6523
|
-
if (declaration.type !==
|
|
6696
|
+
if (declaration.type !== AST_NODE_TYPES29.VariableDeclaration || declaration.kind !== "const" || declaration.declare === true) {
|
|
6524
6697
|
return;
|
|
6525
6698
|
}
|
|
6526
|
-
if (node.id.type !==
|
|
6699
|
+
if (node.id.type !== AST_NODE_TYPES29.Identifier || node.init === null) {
|
|
6527
6700
|
return;
|
|
6528
6701
|
}
|
|
6529
6702
|
if (enclosingFunction2(node) === null) {
|
|
@@ -6549,6 +6722,542 @@ var prefer_module_level_constant_default = ESLintUtils41.RuleCreator(
|
|
|
6549
6722
|
}
|
|
6550
6723
|
});
|
|
6551
6724
|
|
|
6725
|
+
// src/rules/jsdoc-restates-signature.ts
|
|
6726
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES30, ESLintUtils as ESLintUtils42 } from "@typescript-eslint/utils";
|
|
6727
|
+
var VALUE_TAGS = /* @__PURE__ */ new Set([
|
|
6728
|
+
"alpha",
|
|
6729
|
+
"author",
|
|
6730
|
+
"beta",
|
|
6731
|
+
"category",
|
|
6732
|
+
"copyright",
|
|
6733
|
+
"default",
|
|
6734
|
+
"defaultvalue",
|
|
6735
|
+
"deprecated",
|
|
6736
|
+
"example",
|
|
6737
|
+
"experimental",
|
|
6738
|
+
"fileoverview",
|
|
6739
|
+
"fixme",
|
|
6740
|
+
"group",
|
|
6741
|
+
"inheritdoc",
|
|
6742
|
+
"internal",
|
|
6743
|
+
"license",
|
|
6744
|
+
"link",
|
|
6745
|
+
"module",
|
|
6746
|
+
"override",
|
|
6747
|
+
"packagedocumentation",
|
|
6748
|
+
"remarks",
|
|
6749
|
+
"see",
|
|
6750
|
+
"since",
|
|
6751
|
+
"template",
|
|
6752
|
+
"throws",
|
|
6753
|
+
"todo",
|
|
6754
|
+
"typeparam"
|
|
6755
|
+
]);
|
|
6756
|
+
var MODELLED_TAGS = /* @__PURE__ */ new Set([
|
|
6757
|
+
"arg",
|
|
6758
|
+
"argument",
|
|
6759
|
+
"async",
|
|
6760
|
+
"description",
|
|
6761
|
+
"param",
|
|
6762
|
+
"return",
|
|
6763
|
+
"returns"
|
|
6764
|
+
]);
|
|
6765
|
+
var PARAM_TAGS = /* @__PURE__ */ new Set(["arg", "argument", "param"]);
|
|
6766
|
+
var RETURN_TAGS = /* @__PURE__ */ new Set(["return", "returns"]);
|
|
6767
|
+
var DIRECTIVE_RE2 = /^\s*(?:eslint\b|eslint-|@ts-|prettier|biome-|c8\b|v8\b|istanbul\b|@vite|webpack|@jsx|@jest-environment|@vitest-environment|#__)/i;
|
|
6768
|
+
var STOPWORDS2 = new Set(
|
|
6769
|
+
`the a an of to for in on with and or as at by is are was be been being
|
|
6770
|
+
this that it its if whether when where which what will would can could should
|
|
6771
|
+
must may into from over about not no does do done has have had used use uses
|
|
6772
|
+
using given provided specified current new existing all any each per via based
|
|
6773
|
+
function method component hook class instance object value values data item
|
|
6774
|
+
items element callback handler prop props param parameter argument arg return
|
|
6775
|
+
returns returning result optional required default true false null undefined
|
|
6776
|
+
string number boolean array list promise`.split(/\s+/)
|
|
6777
|
+
);
|
|
6778
|
+
var WORD_RE2 = /[A-Za-z]+/g;
|
|
6779
|
+
function parseJsDoc(value) {
|
|
6780
|
+
const lines = value.replace(/^\*/, "").split("\n").map((line) => line.replace(/^\s*\*?\s?/, ""));
|
|
6781
|
+
const description = [];
|
|
6782
|
+
const tags = [];
|
|
6783
|
+
let current = null;
|
|
6784
|
+
for (const line of lines) {
|
|
6785
|
+
const match = /^\s*@(\w[\w-]*)\s*(.*)$/.exec(line);
|
|
6786
|
+
if (match) {
|
|
6787
|
+
current = { name: (match[1] ?? "").toLowerCase(), text: match[2] ?? "" };
|
|
6788
|
+
tags.push(current);
|
|
6789
|
+
} else if (current !== null) {
|
|
6790
|
+
current.text += ` ${line.trim()}`;
|
|
6791
|
+
} else {
|
|
6792
|
+
description.push(line);
|
|
6793
|
+
}
|
|
6794
|
+
}
|
|
6795
|
+
return { description: description.join("\n").trim(), tags };
|
|
6796
|
+
}
|
|
6797
|
+
function proseTokens(text) {
|
|
6798
|
+
return (text.match(WORD_RE2) ?? []).map((word) => word.toLowerCase()).filter((word) => word.length > 1 && !STOPWORDS2.has(word));
|
|
6799
|
+
}
|
|
6800
|
+
function covered(text, known) {
|
|
6801
|
+
const stems = /* @__PURE__ */ new Set();
|
|
6802
|
+
for (const token of known) stems.add(stem(token));
|
|
6803
|
+
return proseTokens(text).every((word) => known.has(word) || stems.has(stem(word)));
|
|
6804
|
+
}
|
|
6805
|
+
function declarationNames(node) {
|
|
6806
|
+
switch (node.type) {
|
|
6807
|
+
// `export function f()` — the JSDoc sits above the `export`, so the token
|
|
6808
|
+
// after it resolves to the wrapper, not to the thing being documented.
|
|
6809
|
+
case AST_NODE_TYPES30.ExportNamedDeclaration:
|
|
6810
|
+
case AST_NODE_TYPES30.ExportDefaultDeclaration:
|
|
6811
|
+
return node.declaration == null ? null : declarationNames(node.declaration);
|
|
6812
|
+
case AST_NODE_TYPES30.FunctionDeclaration:
|
|
6813
|
+
case AST_NODE_TYPES30.TSDeclareFunction:
|
|
6814
|
+
return node.id === null ? null : { name: node.id.name, params: paramNames(node.params) };
|
|
6815
|
+
case AST_NODE_TYPES30.ClassDeclaration:
|
|
6816
|
+
case AST_NODE_TYPES30.TSInterfaceDeclaration:
|
|
6817
|
+
case AST_NODE_TYPES30.TSTypeAliasDeclaration:
|
|
6818
|
+
case AST_NODE_TYPES30.TSEnumDeclaration:
|
|
6819
|
+
return node.id === null ? null : { name: node.id.name, params: [] };
|
|
6820
|
+
case AST_NODE_TYPES30.VariableDeclaration: {
|
|
6821
|
+
const declarator = node.declarations[0];
|
|
6822
|
+
if (declarator === void 0 || declarator.id.type !== AST_NODE_TYPES30.Identifier) return null;
|
|
6823
|
+
const init = declarator.init;
|
|
6824
|
+
const params = init != null && (init.type === AST_NODE_TYPES30.ArrowFunctionExpression || init.type === AST_NODE_TYPES30.FunctionExpression) ? paramNames(init.params) : [];
|
|
6825
|
+
return { name: declarator.id.name, params };
|
|
6826
|
+
}
|
|
6827
|
+
case AST_NODE_TYPES30.MethodDefinition:
|
|
6828
|
+
case AST_NODE_TYPES30.PropertyDefinition:
|
|
6829
|
+
case AST_NODE_TYPES30.TSMethodSignature:
|
|
6830
|
+
case AST_NODE_TYPES30.TSPropertySignature: {
|
|
6831
|
+
if (node.key.type !== AST_NODE_TYPES30.Identifier) return null;
|
|
6832
|
+
const params = node.type === AST_NODE_TYPES30.MethodDefinition ? paramNames(node.value.params) : node.type === AST_NODE_TYPES30.TSMethodSignature ? paramNames(node.params) : [];
|
|
6833
|
+
return { name: node.key.name, params };
|
|
6834
|
+
}
|
|
6835
|
+
default:
|
|
6836
|
+
return null;
|
|
6837
|
+
}
|
|
6838
|
+
}
|
|
6839
|
+
function paramNames(params) {
|
|
6840
|
+
const names = [];
|
|
6841
|
+
for (const param of params) {
|
|
6842
|
+
const target = param.type === AST_NODE_TYPES30.AssignmentPattern ? param.left : param;
|
|
6843
|
+
if (target.type === AST_NODE_TYPES30.Identifier) names.push(target.name);
|
|
6844
|
+
else if (target.type === AST_NODE_TYPES30.TSParameterProperty) continue;
|
|
6845
|
+
}
|
|
6846
|
+
return names;
|
|
6847
|
+
}
|
|
6848
|
+
function tokensOf(names) {
|
|
6849
|
+
const tokens = /* @__PURE__ */ new Set();
|
|
6850
|
+
for (const name of names) for (const part of splitIdentifier(name)) tokens.add(part);
|
|
6851
|
+
return tokens;
|
|
6852
|
+
}
|
|
6853
|
+
var jsdoc_restates_signature_default = ESLintUtils42.RuleCreator(
|
|
6854
|
+
(name) => `https://github.com/sarj-ai/standards/blob/main/packages/typescript/src/rules/${name}.ts`
|
|
6855
|
+
)({
|
|
6856
|
+
name: "jsdoc-restates-signature",
|
|
6857
|
+
meta: {
|
|
6858
|
+
type: "suggestion",
|
|
6859
|
+
hasSuggestions: true,
|
|
6860
|
+
docs: {
|
|
6861
|
+
description: "Flag a JSDoc block whose description and tags only re-spell the signature they document."
|
|
6862
|
+
},
|
|
6863
|
+
schema: [],
|
|
6864
|
+
messages: {
|
|
6865
|
+
restatesSignature: "JSDoc only re-spells the signature \u2014 delete it, or say what the caller cannot read off the name (what it throws, what it assumes, why it exists).",
|
|
6866
|
+
deleteBlock: "Delete the JSDoc block."
|
|
6867
|
+
}
|
|
6868
|
+
},
|
|
6869
|
+
defaultOptions: [],
|
|
6870
|
+
create(context) {
|
|
6871
|
+
if (isGeneratedFile(context.filename, context.sourceCode.text)) {
|
|
6872
|
+
return {};
|
|
6873
|
+
}
|
|
6874
|
+
const sourceCode = context.sourceCode;
|
|
6875
|
+
return {
|
|
6876
|
+
Program() {
|
|
6877
|
+
for (const comment of sourceCode.getAllComments()) {
|
|
6878
|
+
if (comment.type !== "Block" || !comment.value.startsWith("*")) continue;
|
|
6879
|
+
const { description, tags } = parseJsDoc(comment.value);
|
|
6880
|
+
if (DIRECTIVE_RE2.test(description)) continue;
|
|
6881
|
+
const tagNames = new Set(tags.map((tag) => tag.name));
|
|
6882
|
+
if ([...tagNames].some((name) => VALUE_TAGS.has(name))) continue;
|
|
6883
|
+
if ([...tagNames].some((name) => !MODELLED_TAGS.has(name))) continue;
|
|
6884
|
+
if (isProtected(description)) continue;
|
|
6885
|
+
const token = sourceCode.getTokenAfter(comment, { includeComments: false });
|
|
6886
|
+
if (token === null || token.loc.start.line !== comment.loc.end.line + 1) continue;
|
|
6887
|
+
let node = sourceCode.getNodeByRangeIndex(token.range[0]);
|
|
6888
|
+
let declaration = null;
|
|
6889
|
+
while (node != null && node.type !== AST_NODE_TYPES30.Program) {
|
|
6890
|
+
declaration = declarationNames(node);
|
|
6891
|
+
if (declaration !== null) break;
|
|
6892
|
+
node = node.parent ?? null;
|
|
6893
|
+
}
|
|
6894
|
+
if (declaration === null) continue;
|
|
6895
|
+
const paramTags = tags.filter((tag) => PARAM_TAGS.has(tag.name));
|
|
6896
|
+
const returnTags = tags.filter((tag) => RETURN_TAGS.has(tag.name));
|
|
6897
|
+
if (description.length === 0 && paramTags.length === 0 && returnTags.length === 0) {
|
|
6898
|
+
continue;
|
|
6899
|
+
}
|
|
6900
|
+
const nameTokens = tokensOf([declaration.name]);
|
|
6901
|
+
const paramTokens = tokensOf(declaration.params);
|
|
6902
|
+
const known = /* @__PURE__ */ new Set([...nameTokens, ...paramTokens]);
|
|
6903
|
+
let addsNothing = covered(description, known);
|
|
6904
|
+
for (const tag of paramTags) {
|
|
6905
|
+
const text = tag.text.replace(/^\{[^}]*\}\s*/, "");
|
|
6906
|
+
const match = /^\[?([A-Za-z_$][\w.$]*)\]?\s*-?\s*([\s\S]*)$/.exec(text);
|
|
6907
|
+
if (match === null) {
|
|
6908
|
+
addsNothing = false;
|
|
6909
|
+
break;
|
|
6910
|
+
}
|
|
6911
|
+
const own = /* @__PURE__ */ new Set([...splitIdentifier(match[1]?.split(".").pop() ?? ""), ...nameTokens]);
|
|
6912
|
+
if (!covered(match[2] ?? "", own)) {
|
|
6913
|
+
addsNothing = false;
|
|
6914
|
+
break;
|
|
6915
|
+
}
|
|
6916
|
+
for (const part of splitIdentifier(match[1]?.split(".").pop() ?? "")) known.add(part);
|
|
6917
|
+
}
|
|
6918
|
+
if (addsNothing) {
|
|
6919
|
+
for (const tag of returnTags) {
|
|
6920
|
+
if (!covered(tag.text.replace(/^\{[^}]*\}\s*/, ""), known)) {
|
|
6921
|
+
addsNothing = false;
|
|
6922
|
+
break;
|
|
6923
|
+
}
|
|
6924
|
+
}
|
|
6925
|
+
}
|
|
6926
|
+
if (!addsNothing) continue;
|
|
6927
|
+
context.report({
|
|
6928
|
+
node: comment,
|
|
6929
|
+
messageId: "restatesSignature",
|
|
6930
|
+
suggest: [
|
|
6931
|
+
{
|
|
6932
|
+
messageId: "deleteBlock",
|
|
6933
|
+
fix: (fixer) => fixer.removeRange([comment.range[0], token.range[0]])
|
|
6934
|
+
}
|
|
6935
|
+
]
|
|
6936
|
+
});
|
|
6937
|
+
}
|
|
6938
|
+
}
|
|
6939
|
+
};
|
|
6940
|
+
}
|
|
6941
|
+
});
|
|
6942
|
+
|
|
6943
|
+
// src/rules/no-restated-comment.ts
|
|
6944
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES31, ESLintUtils as ESLintUtils43 } from "@typescript-eslint/utils";
|
|
6945
|
+
var MAX_WORDS = 8;
|
|
6946
|
+
var MIN_CONTENT_TOKENS = 2;
|
|
6947
|
+
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;
|
|
6948
|
+
var CODEY_RE = /^[\w.$[\]'"]+\s*[:=]\s*\S|^[\w.$]+\s*\(|^(?:return|throw|await|import|export|const|let|var)\b.*[=()[\]{}]/;
|
|
6949
|
+
var BANNERISH_RE = /[=\-─-╿*#~_.]{3,}|^[A-Z0-9 _:-]+$/;
|
|
6950
|
+
var MODALITY_RE = /\b(?:can|could|should|shall|may|might|must|will|would|cannot)\b/i;
|
|
6951
|
+
var LEAD_IN_RE = /:$/;
|
|
6952
|
+
var EMPHASIS_RE = /\*\w[^*]*\*|`[^`]+`/;
|
|
6953
|
+
var NEGATION_WORD_RE = /\b(?:no|not|never|neither|nor|without|none|non)\b/i;
|
|
6954
|
+
var ACTION_STMT_RE = /[\w.$\])]\s*\(|^\s*(?:return|throw|await|yield)\b/;
|
|
6955
|
+
var NON_ASCII_LETTER_RE = /[^\p{ASCII}\p{N}\p{P}\p{Z}]/u;
|
|
6956
|
+
function areAdjacentLineComments2(a, b) {
|
|
6957
|
+
return a !== void 0 && b !== void 0 && a.type === "Line" && b.type === "Line" && b.loc.start.line === a.loc.end.line + 1;
|
|
6958
|
+
}
|
|
6959
|
+
function headsSiblingRun(node) {
|
|
6960
|
+
const parent = node.parent;
|
|
6961
|
+
if (parent === void 0) return false;
|
|
6962
|
+
const body = "body" in parent && Array.isArray(parent.body) ? parent.body : void 0;
|
|
6963
|
+
if (body === void 0) return false;
|
|
6964
|
+
const index = body.indexOf(node);
|
|
6965
|
+
const next = index >= 0 ? body[index + 1] : void 0;
|
|
6966
|
+
return next !== void 0 && next.type === node.type;
|
|
6967
|
+
}
|
|
6968
|
+
var no_restated_comment_default = ESLintUtils43.RuleCreator(
|
|
6969
|
+
(name) => `https://github.com/sarj-ai/standards/blob/main/packages/typescript/src/rules/${name}.ts`
|
|
6970
|
+
)({
|
|
6971
|
+
name: "no-restated-comment",
|
|
6972
|
+
meta: {
|
|
6973
|
+
type: "suggestion",
|
|
6974
|
+
docs: {
|
|
6975
|
+
description: "Flag a single-line comment whose every word already appears on the statement below it."
|
|
6976
|
+
},
|
|
6977
|
+
schema: [],
|
|
6978
|
+
messages: {
|
|
6979
|
+
restatesLineBelow: "Comment restates the statement below it \u2014 delete it, or replace it with the *why*; the code already carries the *what*."
|
|
6980
|
+
}
|
|
6981
|
+
},
|
|
6982
|
+
defaultOptions: [],
|
|
6983
|
+
create(context) {
|
|
6984
|
+
if (isGeneratedFile(context.filename, context.sourceCode.text)) {
|
|
6985
|
+
return {};
|
|
6986
|
+
}
|
|
6987
|
+
const sourceCode = context.sourceCode;
|
|
6988
|
+
const lines = sourceCode.lines;
|
|
6989
|
+
function isStandalone(comment) {
|
|
6990
|
+
const before = sourceCode.getTokenBefore(comment, { includeComments: false });
|
|
6991
|
+
return !before || before.loc.end.line < comment.loc.start.line;
|
|
6992
|
+
}
|
|
6993
|
+
function labelsASiblingRun(comment) {
|
|
6994
|
+
const token = sourceCode.getTokenAfter(comment, { includeComments: false });
|
|
6995
|
+
if (token === null) return false;
|
|
6996
|
+
for (let node = sourceCode.getNodeByRangeIndex(token.range[0]); node != null && node.type !== AST_NODE_TYPES31.Program; node = node.parent) {
|
|
6997
|
+
if (headsSiblingRun(node)) return true;
|
|
6998
|
+
}
|
|
6999
|
+
return false;
|
|
7000
|
+
}
|
|
7001
|
+
return {
|
|
7002
|
+
Program() {
|
|
7003
|
+
const comments = sourceCode.getAllComments();
|
|
7004
|
+
for (let i = 0; i < comments.length; i++) {
|
|
7005
|
+
const comment = comments[i];
|
|
7006
|
+
if (comment === void 0 || comment.type !== "Line") continue;
|
|
7007
|
+
if (!isStandalone(comment)) continue;
|
|
7008
|
+
if (areAdjacentLineComments2(comments[i - 1], comment) || areAdjacentLineComments2(comment, comments[i + 1])) {
|
|
7009
|
+
continue;
|
|
7010
|
+
}
|
|
7011
|
+
const body = comment.value.replace(/^\/*/, "").trim();
|
|
7012
|
+
if (body.length === 0 || body.endsWith("?")) continue;
|
|
7013
|
+
if (DIRECTIVE_RE3.test(body) || CODEY_RE.test(body) || BANNERISH_RE.test(body)) continue;
|
|
7014
|
+
if (NON_ASCII_LETTER_RE.test(body) || isProtected(body)) continue;
|
|
7015
|
+
if (MODALITY_RE.test(body) || LEAD_IN_RE.test(body) || EMPHASIS_RE.test(body)) continue;
|
|
7016
|
+
if (NEGATION_WORD_RE.test(body)) continue;
|
|
7017
|
+
if (body.split(/\s+/).length > MAX_WORDS) continue;
|
|
7018
|
+
const tokens = contentTokens(body);
|
|
7019
|
+
if (tokens.length < MIN_CONTENT_TOKENS) continue;
|
|
7020
|
+
const statement = restatableStatementBelow(comment, sourceCode);
|
|
7021
|
+
if (statement === null) continue;
|
|
7022
|
+
if (restatesStatementHead(body, statement)) continue;
|
|
7023
|
+
const line = lines[comment.loc.start.line] ?? "";
|
|
7024
|
+
if (!ACTION_STMT_RE.test(line)) continue;
|
|
7025
|
+
if (labelsASiblingRun(comment)) continue;
|
|
7026
|
+
if (restates(tokens, codeTokens(line))) {
|
|
7027
|
+
context.report({ node: comment, messageId: "restatesLineBelow" });
|
|
7028
|
+
}
|
|
7029
|
+
}
|
|
7030
|
+
}
|
|
7031
|
+
};
|
|
7032
|
+
}
|
|
7033
|
+
});
|
|
7034
|
+
|
|
7035
|
+
// src/rules/trailing-value-narration.ts
|
|
7036
|
+
import { ESLintUtils as ESLintUtils44 } from "@typescript-eslint/utils";
|
|
7037
|
+
var NUMBER_RE = /(?<![\w.])(\d+(?:\.\d+)?)(?![\w.])/g;
|
|
7038
|
+
var WORD_RE3 = /[A-Za-z]+(?:'[a-z]+)?|\d+(?:\.\d+)?/g;
|
|
7039
|
+
var UNIT_WORDS = /* @__PURE__ */ new Set([
|
|
7040
|
+
"bytes",
|
|
7041
|
+
"characters",
|
|
7042
|
+
"chars",
|
|
7043
|
+
"day",
|
|
7044
|
+
"days",
|
|
7045
|
+
"gb",
|
|
7046
|
+
"hour",
|
|
7047
|
+
"hours",
|
|
7048
|
+
"hr",
|
|
7049
|
+
"hrs",
|
|
7050
|
+
"hz",
|
|
7051
|
+
"items",
|
|
7052
|
+
"k",
|
|
7053
|
+
"kb",
|
|
7054
|
+
"khz",
|
|
7055
|
+
"m",
|
|
7056
|
+
"mb",
|
|
7057
|
+
"milliseconds",
|
|
7058
|
+
"min",
|
|
7059
|
+
"mins",
|
|
7060
|
+
"minute",
|
|
7061
|
+
"minutes",
|
|
7062
|
+
"ms",
|
|
7063
|
+
"pct",
|
|
7064
|
+
"percent",
|
|
7065
|
+
"px",
|
|
7066
|
+
"retries",
|
|
7067
|
+
"rows",
|
|
7068
|
+
"s",
|
|
7069
|
+
"sec",
|
|
7070
|
+
"second",
|
|
7071
|
+
"seconds",
|
|
7072
|
+
"secs",
|
|
7073
|
+
"times",
|
|
7074
|
+
"tokens"
|
|
7075
|
+
]);
|
|
7076
|
+
var STOPWORDS3 = /* @__PURE__ */ new Set([
|
|
7077
|
+
"a",
|
|
7078
|
+
"an",
|
|
7079
|
+
"and",
|
|
7080
|
+
"are",
|
|
7081
|
+
"as",
|
|
7082
|
+
"at",
|
|
7083
|
+
"be",
|
|
7084
|
+
"by",
|
|
7085
|
+
"for",
|
|
7086
|
+
"in",
|
|
7087
|
+
"is",
|
|
7088
|
+
"it",
|
|
7089
|
+
"of",
|
|
7090
|
+
"on",
|
|
7091
|
+
"or",
|
|
7092
|
+
"that",
|
|
7093
|
+
"the",
|
|
7094
|
+
"this",
|
|
7095
|
+
"we",
|
|
7096
|
+
"with"
|
|
7097
|
+
]);
|
|
7098
|
+
var DIRECTIVE_RE4 = /^\s*(?:eslint\b|eslint-|sarj-noqa\b|@ts-|prettier|biome-|c8\b|v8\b|istanbul\b|todo\b|fixme\b|hack\b|xxx\b)/i;
|
|
7099
|
+
function numbersIn(text) {
|
|
7100
|
+
return new Set(text.match(NUMBER_RE) ?? []);
|
|
7101
|
+
}
|
|
7102
|
+
function narratesValue(body, code) {
|
|
7103
|
+
if (body.length === 0 || DIRECTIVE_RE4.test(body) || hasExternalReference(body)) return false;
|
|
7104
|
+
const codeNumbers = numbersIn(code);
|
|
7105
|
+
if (codeNumbers.size === 0) return false;
|
|
7106
|
+
const words = (body.match(WORD_RE3) ?? []).map((word) => word.toLowerCase());
|
|
7107
|
+
if (words.length === 0) return false;
|
|
7108
|
+
const commentNumbers = numbersIn(body);
|
|
7109
|
+
if (commentNumbers.size === 0) return false;
|
|
7110
|
+
for (const number of commentNumbers) {
|
|
7111
|
+
if (!codeNumbers.has(number)) return false;
|
|
7112
|
+
}
|
|
7113
|
+
const identifiers = codeTokens(code);
|
|
7114
|
+
const stems = /* @__PURE__ */ new Set();
|
|
7115
|
+
for (const token of identifiers) stems.add(stem(token));
|
|
7116
|
+
return words.every(
|
|
7117
|
+
(word) => STOPWORDS3.has(word) || UNIT_WORDS.has(word) || commentNumbers.has(word) || identifiers.has(word) || stems.has(stem(word))
|
|
7118
|
+
);
|
|
7119
|
+
}
|
|
7120
|
+
var trailing_value_narration_default = ESLintUtils44.RuleCreator(
|
|
7121
|
+
(name) => `https://github.com/sarj-ai/standards/blob/main/packages/typescript/src/rules/${name}.ts`
|
|
7122
|
+
)({
|
|
7123
|
+
name: "trailing-value-narration",
|
|
7124
|
+
meta: {
|
|
7125
|
+
type: "suggestion",
|
|
7126
|
+
docs: {
|
|
7127
|
+
description: "Flag a trailing comment whose every word and number is already on the line it annotates."
|
|
7128
|
+
},
|
|
7129
|
+
schema: [],
|
|
7130
|
+
messages: {
|
|
7131
|
+
narratesValue: "Trailing comment restates the literal on this line \u2014 put the unit in the name (STALE_TIME_MS) so it cannot drift."
|
|
7132
|
+
}
|
|
7133
|
+
},
|
|
7134
|
+
defaultOptions: [],
|
|
7135
|
+
create(context) {
|
|
7136
|
+
if (isGeneratedFile(context.filename, context.sourceCode.text)) {
|
|
7137
|
+
return {};
|
|
7138
|
+
}
|
|
7139
|
+
const sourceCode = context.sourceCode;
|
|
7140
|
+
function isTrailing(comment) {
|
|
7141
|
+
const before = sourceCode.getTokenBefore(comment, { includeComments: false });
|
|
7142
|
+
return before !== null && before.loc.end.line === comment.loc.start.line;
|
|
7143
|
+
}
|
|
7144
|
+
return {
|
|
7145
|
+
Program() {
|
|
7146
|
+
for (const comment of sourceCode.getAllComments()) {
|
|
7147
|
+
if (!isTrailing(comment)) continue;
|
|
7148
|
+
const line = sourceCode.lines[comment.loc.start.line - 1] ?? "";
|
|
7149
|
+
const code = line.slice(0, comment.loc.start.column);
|
|
7150
|
+
const body = comment.value.replace(/^\*+/, "").replace(/\*+$/, "").trim();
|
|
7151
|
+
if (narratesValue(body, code)) {
|
|
7152
|
+
context.report({ node: comment, messageId: "narratesValue" });
|
|
7153
|
+
}
|
|
7154
|
+
}
|
|
7155
|
+
}
|
|
7156
|
+
};
|
|
7157
|
+
}
|
|
7158
|
+
});
|
|
7159
|
+
|
|
7160
|
+
// src/rules/no-tautological-expect.ts
|
|
7161
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES32, ESLintUtils as ESLintUtils45 } from "@typescript-eslint/utils";
|
|
7162
|
+
var EQUALITY_MATCHERS = /* @__PURE__ */ new Set(["toBe", "toEqual", "toStrictEqual"]);
|
|
7163
|
+
var ZERO_ARG_MATCHERS = /* @__PURE__ */ new Set([
|
|
7164
|
+
"toBeDefined",
|
|
7165
|
+
"toBeUndefined",
|
|
7166
|
+
"toBeNull",
|
|
7167
|
+
"toBeTruthy",
|
|
7168
|
+
"toBeFalsy",
|
|
7169
|
+
"toBeNaN"
|
|
7170
|
+
]);
|
|
7171
|
+
var OPERAND_PREVIEW_CHARS = 40;
|
|
7172
|
+
var NUMERIC_SIGNS = /* @__PURE__ */ new Set(["-", "+"]);
|
|
7173
|
+
function isLiteral(node) {
|
|
7174
|
+
switch (node.type) {
|
|
7175
|
+
case AST_NODE_TYPES32.Literal:
|
|
7176
|
+
return true;
|
|
7177
|
+
case AST_NODE_TYPES32.TemplateLiteral:
|
|
7178
|
+
return node.expressions.length === 0;
|
|
7179
|
+
case AST_NODE_TYPES32.UnaryExpression:
|
|
7180
|
+
return NUMERIC_SIGNS.has(node.operator) && isLiteral(node.argument);
|
|
7181
|
+
case AST_NODE_TYPES32.ArrayExpression:
|
|
7182
|
+
return node.elements.every((element) => element !== null && isLiteral(element));
|
|
7183
|
+
case AST_NODE_TYPES32.ObjectExpression:
|
|
7184
|
+
return node.properties.every(
|
|
7185
|
+
(property) => property.type === AST_NODE_TYPES32.Property && !property.computed && isLiteral(property.value)
|
|
7186
|
+
);
|
|
7187
|
+
default:
|
|
7188
|
+
return false;
|
|
7189
|
+
}
|
|
7190
|
+
}
|
|
7191
|
+
function expectOperand(callee) {
|
|
7192
|
+
const receiver = callee.object;
|
|
7193
|
+
if (receiver.type !== AST_NODE_TYPES32.CallExpression || receiver.callee.type !== AST_NODE_TYPES32.Identifier || receiver.callee.name !== "expect" || receiver.arguments.length !== 1) {
|
|
7194
|
+
return null;
|
|
7195
|
+
}
|
|
7196
|
+
return receiver.arguments[0] ?? null;
|
|
7197
|
+
}
|
|
7198
|
+
var no_tautological_expect_default = ESLintUtils45.RuleCreator(
|
|
7199
|
+
(name) => `https://github.com/sarj-ai/standards/blob/main/packages/typescript/src/rules/${name}.ts`
|
|
7200
|
+
)({
|
|
7201
|
+
name: "no-tautological-expect",
|
|
7202
|
+
meta: {
|
|
7203
|
+
type: "problem",
|
|
7204
|
+
docs: {
|
|
7205
|
+
description: "Disallow an assertion whose operands are all literals; its outcome is fixed before the code runs, so it can never fail."
|
|
7206
|
+
},
|
|
7207
|
+
schema: [],
|
|
7208
|
+
messages: {
|
|
7209
|
+
tautologicalComparison: "`expect({{operand}}).{{matcher}}({{operand}})` compares a literal with an identical literal \u2014 it passes even if the code under test is deleted. Assert on a value the code produced, or delete the test.",
|
|
7210
|
+
tautologicalMatcher: "`expect({{operand}}).{{matcher}}()` asserts on a literal, so its outcome is fixed before the code runs. Assert on a value the code produced, or delete the test."
|
|
7211
|
+
}
|
|
7212
|
+
},
|
|
7213
|
+
defaultOptions: [],
|
|
7214
|
+
create(context) {
|
|
7215
|
+
if (!isTestFile(context.filename)) {
|
|
7216
|
+
return {};
|
|
7217
|
+
}
|
|
7218
|
+
const preview2 = (node) => {
|
|
7219
|
+
const text = context.sourceCode.getText(node).replaceAll(/\s+/gu, " ");
|
|
7220
|
+
return text.length > OPERAND_PREVIEW_CHARS ? `${text.slice(0, OPERAND_PREVIEW_CHARS)}\u2026` : text;
|
|
7221
|
+
};
|
|
7222
|
+
return {
|
|
7223
|
+
CallExpression(node) {
|
|
7224
|
+
const callee = node.callee;
|
|
7225
|
+
if (callee.type !== AST_NODE_TYPES32.MemberExpression || callee.computed) {
|
|
7226
|
+
return;
|
|
7227
|
+
}
|
|
7228
|
+
if (callee.property.type !== AST_NODE_TYPES32.Identifier) {
|
|
7229
|
+
return;
|
|
7230
|
+
}
|
|
7231
|
+
const matcher = callee.property.name;
|
|
7232
|
+
const operand = expectOperand(callee);
|
|
7233
|
+
if (operand === null || !isLiteral(operand)) {
|
|
7234
|
+
return;
|
|
7235
|
+
}
|
|
7236
|
+
if (ZERO_ARG_MATCHERS.has(matcher) && node.arguments.length === 0) {
|
|
7237
|
+
context.report({
|
|
7238
|
+
node,
|
|
7239
|
+
messageId: "tautologicalMatcher",
|
|
7240
|
+
data: { operand: preview2(operand), matcher }
|
|
7241
|
+
});
|
|
7242
|
+
return;
|
|
7243
|
+
}
|
|
7244
|
+
const expected = node.arguments[0];
|
|
7245
|
+
if (!EQUALITY_MATCHERS.has(matcher) || node.arguments.length !== 1 || expected === void 0 || !isLiteral(expected)) {
|
|
7246
|
+
return;
|
|
7247
|
+
}
|
|
7248
|
+
if (context.sourceCode.getText(operand) !== context.sourceCode.getText(expected)) {
|
|
7249
|
+
return;
|
|
7250
|
+
}
|
|
7251
|
+
context.report({
|
|
7252
|
+
node,
|
|
7253
|
+
messageId: "tautologicalComparison",
|
|
7254
|
+
data: { operand: preview2(operand), matcher }
|
|
7255
|
+
});
|
|
7256
|
+
}
|
|
7257
|
+
};
|
|
7258
|
+
}
|
|
7259
|
+
});
|
|
7260
|
+
|
|
6552
7261
|
// src/index.ts
|
|
6553
7262
|
var rules = {
|
|
6554
7263
|
"enforce-file-structure": enforce_file_structure_default,
|
|
@@ -6591,12 +7300,16 @@ var rules = {
|
|
|
6591
7300
|
"no-raw-fetch-outside-clients": no_raw_fetch_outside_clients_default,
|
|
6592
7301
|
"no-storage-in-stateless-modules": no_storage_in_stateless_modules_default,
|
|
6593
7302
|
"no-zod-native-enum": no_zod_native_enum_default,
|
|
6594
|
-
"prefer-module-level-constant": prefer_module_level_constant_default
|
|
7303
|
+
"prefer-module-level-constant": prefer_module_level_constant_default,
|
|
7304
|
+
"jsdoc-restates-signature": jsdoc_restates_signature_default,
|
|
7305
|
+
"no-restated-comment": no_restated_comment_default,
|
|
7306
|
+
"trailing-value-narration": trailing_value_narration_default,
|
|
7307
|
+
"no-tautological-expect": no_tautological_expect_default
|
|
6595
7308
|
};
|
|
6596
7309
|
var plugin = {
|
|
6597
7310
|
meta: {
|
|
6598
7311
|
name: "@sarj/eslint-plugin",
|
|
6599
|
-
version: "2.
|
|
7312
|
+
version: "2.14.0"
|
|
6600
7313
|
},
|
|
6601
7314
|
rules,
|
|
6602
7315
|
configs: {
|
|
@@ -6652,7 +7365,26 @@ var plugin = {
|
|
|
6652
7365
|
// Mined from two years of PR review — the single most frequent uncovered
|
|
6653
7366
|
// theme (~37 PRs). Measured 17 hits / 1085 real TS files, all true
|
|
6654
7367
|
// positives, so it is safe to run everywhere.
|
|
6655
|
-
"@sarj/prefer-module-level-constant": "warn"
|
|
7368
|
+
"@sarj/prefer-module-level-constant": "warn",
|
|
7369
|
+
// Anti-comment-verbosity family (2026-07), from a 37,918-comment,
|
|
7370
|
+
// nine-repo measurement study. Each is a deletion-class finding, so each
|
|
7371
|
+
// was validated against pydantic / trio / attrs as well as the maintained
|
|
7372
|
+
// repos: `no-restated-comment` 0 hits in bulbul and 4 in the three famous
|
|
7373
|
+
// corpora combined; `trailing-value-narration` 18 hits, 18 true
|
|
7374
|
+
// positives; `jsdoc-restates-signature` 36 hits, 0 measured false
|
|
7375
|
+
// positives, and it offers a suggestion rather than a `--fix` because a
|
|
7376
|
+
// wrong deletion is silent information loss.
|
|
7377
|
+
"@sarj/no-restated-comment": "warn",
|
|
7378
|
+
"@sarj/jsdoc-restates-signature": "warn",
|
|
7379
|
+
"@sarj/trailing-value-narration": "warn",
|
|
7380
|
+
// The TS half of SARJ057 (2026-07). Python has caught the
|
|
7381
|
+
// assertion-FREE test since 0.15.0 (SARJ043) and had no TS
|
|
7382
|
+
// counterpart, which is how `expect(true).toBe(true); // placeholder`
|
|
7383
|
+
// survived in internal-automations: the file HAS an assertion.
|
|
7384
|
+
// Measured across 5,819 .ts/.tsx files (1,003 of them test files) in
|
|
7385
|
+
// six internal repos plus got / hono / swr / trpc: 3 hits, 3 true
|
|
7386
|
+
// positives, 0 false positives.
|
|
7387
|
+
"@sarj/no-tautological-expect": "warn"
|
|
6656
7388
|
}
|
|
6657
7389
|
},
|
|
6658
7390
|
strict: {
|
|
@@ -6715,7 +7447,14 @@ var plugin = {
|
|
|
6715
7447
|
"@sarj/no-storage-in-stateless-modules": "error",
|
|
6716
7448
|
// Mined from two years of PR review (SARJ-928).
|
|
6717
7449
|
"@sarj/no-zod-native-enum": "error",
|
|
6718
|
-
"@sarj/prefer-module-level-constant": "error"
|
|
7450
|
+
"@sarj/prefer-module-level-constant": "error",
|
|
7451
|
+
// Anti-comment-verbosity family (2026-07) — see the `recommended` block
|
|
7452
|
+
// for the measured hit counts and false-positive rates.
|
|
7453
|
+
"@sarj/no-restated-comment": "error",
|
|
7454
|
+
"@sarj/jsdoc-restates-signature": "error",
|
|
7455
|
+
"@sarj/trailing-value-narration": "error",
|
|
7456
|
+
// TS half of SARJ057 — see the `recommended` block for the measurement.
|
|
7457
|
+
"@sarj/no-tautological-expect": "error"
|
|
6719
7458
|
}
|
|
6720
7459
|
}
|
|
6721
7460
|
}
|