@sarj/eslint-plugin 2.12.1 → 2.13.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 +14 -1
- package/dist/index.cjs +1126 -463
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +24 -0
- package/dist/index.d.ts +24 -0
- package/dist/index.js +1070 -407
- package/dist/index.js.map +1 -1
- package/package.json +4 -1
package/dist/index.js
CHANGED
|
@@ -4,7 +4,8 @@ import { ESLintUtils, AST_NODE_TYPES } from "@typescript-eslint/utils";
|
|
|
4
4
|
// src/rules/_paths.ts
|
|
5
5
|
var SCRIPT_FILE_RE = /([\\/]scripts[\\/])|(\.mjs$)/;
|
|
6
6
|
var STORY_FILE_RE = /\.stories\.[cm]?[jt]sx?$/i;
|
|
7
|
-
var GENERATED_FILE_RE = /([\\/]generated[\\/])|(\.gen\.[cm]?[jt]sx?$)|(\.generated\.[cm]?[jt]sx?$)|(\.d\.[cm]?ts$)/;
|
|
7
|
+
var GENERATED_FILE_RE = /([\\/](?:generated|openapi-gen|graphql[\\/]types)[\\/])|(\.gen\.[cm]?[jt]sx?$)|(\.generated\.[cm]?[jt]sx?$)|(\.d\.[cm]?ts$)|(\.types\.[cm]?ts$)/;
|
|
8
|
+
var GENERATED_MARKER_RE = /(?:@generated\b|generated (?:with|by)|generated (?:graphql )?types|do not edit(?: directly| manually)?)/i;
|
|
8
9
|
function isTestFile(filename) {
|
|
9
10
|
const normalized = filename.replaceAll("\\", "/");
|
|
10
11
|
const base = normalized.slice(normalized.lastIndexOf("/") + 1);
|
|
@@ -17,7 +18,7 @@ function isStoryFile(filename) {
|
|
|
17
18
|
return STORY_FILE_RE.test(filename);
|
|
18
19
|
}
|
|
19
20
|
function isGeneratedFile(filename, sourceText = "") {
|
|
20
|
-
return GENERATED_FILE_RE.test(filename.replaceAll("\\", "/")) ||
|
|
21
|
+
return GENERATED_FILE_RE.test(filename.replaceAll("\\", "/")) || GENERATED_MARKER_RE.test(sourceText.slice(0, 2048));
|
|
21
22
|
}
|
|
22
23
|
function isScriptFile(filename) {
|
|
23
24
|
return SCRIPT_FILE_RE.test(filename);
|
|
@@ -60,7 +61,7 @@ var enforce_file_structure_default = ESLintUtils.RuleCreator(
|
|
|
60
61
|
},
|
|
61
62
|
defaultOptions: [],
|
|
62
63
|
create(context) {
|
|
63
|
-
if (isTestFile(context.filename)) {
|
|
64
|
+
if (isTestFile(context.filename) || isGeneratedFile(context.filename, context.sourceCode.text)) {
|
|
64
65
|
return {};
|
|
65
66
|
}
|
|
66
67
|
return {
|
|
@@ -241,56 +242,90 @@ var no_client_side_data_fetching_default = ESLintUtils2.RuleCreator(
|
|
|
241
242
|
});
|
|
242
243
|
|
|
243
244
|
// src/rules/no-comment-cruft.ts
|
|
244
|
-
import { AST_NODE_TYPES as
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
var
|
|
249
|
-
var
|
|
250
|
-
var
|
|
251
|
-
var
|
|
252
|
-
var
|
|
253
|
-
var
|
|
254
|
-
var
|
|
255
|
-
var
|
|
256
|
-
var
|
|
257
|
-
var
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
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;
|
|
278
299
|
}
|
|
279
|
-
function
|
|
280
|
-
|
|
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;
|
|
281
310
|
}
|
|
282
|
-
function
|
|
283
|
-
const
|
|
284
|
-
|
|
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));
|
|
285
317
|
}
|
|
286
|
-
function
|
|
287
|
-
const
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
if (/[.!?]$/.test(t) && /\s/.test(t) && /[a-z]/.test(t) && !looksLikeCode(t) && t.split(/\s+/).length >= 3) {
|
|
291
|
-
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);
|
|
292
322
|
}
|
|
293
|
-
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)));
|
|
294
329
|
}
|
|
295
330
|
var NARRATION_MAX_WORDS = 6;
|
|
296
331
|
var NARRATION_MIN_CONTENT = 1;
|
|
@@ -351,7 +386,7 @@ function normalizeToken(word) {
|
|
|
351
386
|
const lower = word.toLowerCase();
|
|
352
387
|
return lower.length > TOKEN_PLURAL_MIN && lower.endsWith("s") && !lower.endsWith("ss") ? lower.slice(0, -1) : lower;
|
|
353
388
|
}
|
|
354
|
-
function
|
|
389
|
+
function headTokens(source) {
|
|
355
390
|
const tokens = /* @__PURE__ */ new Set();
|
|
356
391
|
for (const identifier of source.match(/[A-Za-z_$][\w$]*/g) ?? []) {
|
|
357
392
|
tokens.add(normalizeToken(identifier));
|
|
@@ -383,7 +418,7 @@ function restatableStatementBelow(comment, sourceCode) {
|
|
|
383
418
|
}
|
|
384
419
|
return null;
|
|
385
420
|
}
|
|
386
|
-
function
|
|
421
|
+
function restatesStatementHead(body, statement) {
|
|
387
422
|
if (statement === null) return false;
|
|
388
423
|
const words = body.match(/[A-Za-z][\w$]*/g) ?? [];
|
|
389
424
|
const opener = words[0];
|
|
@@ -392,18 +427,152 @@ function restatesNextLine(body, statement) {
|
|
|
392
427
|
const content = words.slice(1).map(normalizeToken).filter((word) => !NARRATION_STOPWORDS.has(word));
|
|
393
428
|
if (content.length < NARRATION_MIN_CONTENT) return false;
|
|
394
429
|
const head = statement.split("(")[0] ?? statement;
|
|
395
|
-
const code =
|
|
430
|
+
const code = headTokens(head);
|
|
396
431
|
return content.every((word) => code.has(word));
|
|
397
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
|
+
}
|
|
398
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;
|
|
399
|
-
function isRedundantNarration(body, statementBelow, standalone) {
|
|
545
|
+
function isRedundantNarration(body, statementBelow, standalone, isolatedEnumeration, nested) {
|
|
400
546
|
const t = body.trim();
|
|
401
547
|
if (!t || looksLikeCode(t) || hasPseudocode(t)) return false;
|
|
402
548
|
if (standalone) {
|
|
403
549
|
if (STEP_NARRATION_RE.test(t)) return true;
|
|
404
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;
|
|
570
|
+
}
|
|
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;
|
|
405
574
|
}
|
|
406
|
-
return
|
|
575
|
+
return false;
|
|
407
576
|
}
|
|
408
577
|
function areAdjacentLineComments(a, b) {
|
|
409
578
|
return a !== void 0 && b !== void 0 && a.type === "Line" && b.type === "Line" && b.loc.start.line === a.loc.end.line + 1;
|
|
@@ -452,6 +621,9 @@ var no_comment_cruft_default = ESLintUtils3.RuleCreator(
|
|
|
452
621
|
},
|
|
453
622
|
defaultOptions: [],
|
|
454
623
|
create(context) {
|
|
624
|
+
if (isGeneratedFile(context.filename, context.sourceCode.text)) {
|
|
625
|
+
return {};
|
|
626
|
+
}
|
|
455
627
|
const sourceCode = context.sourceCode;
|
|
456
628
|
function isStandalone(comment) {
|
|
457
629
|
const before = sourceCode.getTokenBefore(comment, {
|
|
@@ -489,6 +661,9 @@ var no_comment_cruft_default = ESLintUtils3.RuleCreator(
|
|
|
489
661
|
Program() {
|
|
490
662
|
const comments = sourceCode.getAllComments();
|
|
491
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
|
+
);
|
|
492
667
|
for (let i = 0; i < comments.length; i++) {
|
|
493
668
|
const comment = comments[i];
|
|
494
669
|
if (comment === void 0) continue;
|
|
@@ -509,7 +684,9 @@ var no_comment_cruft_default = ESLintUtils3.RuleCreator(
|
|
|
509
684
|
const body = texts[0];
|
|
510
685
|
const statement = restatableStatementBelow(comment, sourceCode);
|
|
511
686
|
const standalone = !isInsideCommentRun(comments, i);
|
|
512
|
-
|
|
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)) {
|
|
513
690
|
context.report({ node: comment, messageId: "redundantNarration" });
|
|
514
691
|
}
|
|
515
692
|
}
|
|
@@ -524,6 +701,7 @@ var no_comment_cruft_default = ESLintUtils3.RuleCreator(
|
|
|
524
701
|
import { ESLintUtils as ESLintUtils4 } from "@typescript-eslint/utils";
|
|
525
702
|
var DEFAULT_IGNORE_PATTERNS = [
|
|
526
703
|
/[\\/]generated[\\/]/,
|
|
704
|
+
/[\\/]openapi-gen[\\/]/,
|
|
527
705
|
/\.gen\.tsx?$/,
|
|
528
706
|
/\.generated\.tsx?$/
|
|
529
707
|
];
|
|
@@ -575,7 +753,7 @@ var no_enum_default = ESLintUtils4.RuleCreator(
|
|
|
575
753
|
(re) => re.test(filename)
|
|
576
754
|
);
|
|
577
755
|
const isIgnoredByOption = ignoreFiles.length > 0 && matchesAnyPattern(filename, ignoreFiles);
|
|
578
|
-
const isGenerated = hasGeneratedMarker(sourceText);
|
|
756
|
+
const isGenerated = hasGeneratedMarker(sourceText) || isGeneratedFile(filename, sourceText);
|
|
579
757
|
if (isIgnoredByDefault || isIgnoredByOption || isGenerated) {
|
|
580
758
|
return {};
|
|
581
759
|
}
|
|
@@ -1207,13 +1385,13 @@ var no_raw_env_default = ESLintUtils8.RuleCreator(
|
|
|
1207
1385
|
// src/rules/no-sentinel-return-on-catch.ts
|
|
1208
1386
|
import {
|
|
1209
1387
|
ESLintUtils as ESLintUtils9,
|
|
1210
|
-
AST_NODE_TYPES as
|
|
1388
|
+
AST_NODE_TYPES as AST_NODE_TYPES5
|
|
1211
1389
|
} from "@typescript-eslint/utils";
|
|
1212
1390
|
function sentinelKind(arg) {
|
|
1213
1391
|
if (arg === null) {
|
|
1214
1392
|
return null;
|
|
1215
1393
|
}
|
|
1216
|
-
if (arg.type ===
|
|
1394
|
+
if (arg.type === AST_NODE_TYPES5.Literal) {
|
|
1217
1395
|
if (arg.value === null) {
|
|
1218
1396
|
return "nullish";
|
|
1219
1397
|
}
|
|
@@ -1225,13 +1403,13 @@ function sentinelKind(arg) {
|
|
|
1225
1403
|
}
|
|
1226
1404
|
return null;
|
|
1227
1405
|
}
|
|
1228
|
-
if (arg.type ===
|
|
1406
|
+
if (arg.type === AST_NODE_TYPES5.Identifier && arg.name === "undefined") {
|
|
1229
1407
|
return "nullish";
|
|
1230
1408
|
}
|
|
1231
|
-
if (arg.type ===
|
|
1409
|
+
if (arg.type === AST_NODE_TYPES5.ArrayExpression) {
|
|
1232
1410
|
return "array";
|
|
1233
1411
|
}
|
|
1234
|
-
if (arg.type ===
|
|
1412
|
+
if (arg.type === AST_NODE_TYPES5.ObjectExpression) {
|
|
1235
1413
|
return "object";
|
|
1236
1414
|
}
|
|
1237
1415
|
return null;
|
|
@@ -1240,25 +1418,25 @@ function isSentinelArgument(arg) {
|
|
|
1240
1418
|
if (arg === null) {
|
|
1241
1419
|
return false;
|
|
1242
1420
|
}
|
|
1243
|
-
if (arg.type ===
|
|
1421
|
+
if (arg.type === AST_NODE_TYPES5.Literal && arg.value === null) {
|
|
1244
1422
|
return true;
|
|
1245
1423
|
}
|
|
1246
|
-
if (arg.type ===
|
|
1424
|
+
if (arg.type === AST_NODE_TYPES5.Literal && arg.value === false) {
|
|
1247
1425
|
return true;
|
|
1248
1426
|
}
|
|
1249
|
-
if (arg.type ===
|
|
1427
|
+
if (arg.type === AST_NODE_TYPES5.Identifier && arg.name === "undefined") {
|
|
1250
1428
|
return true;
|
|
1251
1429
|
}
|
|
1252
|
-
if (arg.type ===
|
|
1430
|
+
if (arg.type === AST_NODE_TYPES5.ArrayExpression && arg.elements.length === 0) {
|
|
1253
1431
|
return true;
|
|
1254
1432
|
}
|
|
1255
|
-
if (arg.type ===
|
|
1433
|
+
if (arg.type === AST_NODE_TYPES5.ObjectExpression && arg.properties.length === 0) {
|
|
1256
1434
|
return true;
|
|
1257
1435
|
}
|
|
1258
1436
|
return false;
|
|
1259
1437
|
}
|
|
1260
1438
|
function isFunctionNode(node) {
|
|
1261
|
-
return node.type ===
|
|
1439
|
+
return node.type === AST_NODE_TYPES5.FunctionDeclaration || node.type === AST_NODE_TYPES5.FunctionExpression || node.type === AST_NODE_TYPES5.ArrowFunctionExpression;
|
|
1262
1440
|
}
|
|
1263
1441
|
function isNode(value) {
|
|
1264
1442
|
return typeof value === "object" && value !== null && typeof value.type === "string";
|
|
@@ -1298,24 +1476,24 @@ function walkWithinScope(node, visit) {
|
|
|
1298
1476
|
function containsThrow(node) {
|
|
1299
1477
|
return walkWithinScope(
|
|
1300
1478
|
node,
|
|
1301
|
-
(current) => current.type ===
|
|
1479
|
+
(current) => current.type === AST_NODE_TYPES5.ThrowStatement
|
|
1302
1480
|
);
|
|
1303
1481
|
}
|
|
1304
1482
|
function bindsName(param, name) {
|
|
1305
1483
|
switch (param.type) {
|
|
1306
|
-
case
|
|
1484
|
+
case AST_NODE_TYPES5.Identifier:
|
|
1307
1485
|
return param.name === name;
|
|
1308
|
-
case
|
|
1486
|
+
case AST_NODE_TYPES5.AssignmentPattern:
|
|
1309
1487
|
return bindsName(param.left, name);
|
|
1310
|
-
case
|
|
1488
|
+
case AST_NODE_TYPES5.RestElement:
|
|
1311
1489
|
return bindsName(param.argument, name);
|
|
1312
|
-
case
|
|
1490
|
+
case AST_NODE_TYPES5.ArrayPattern:
|
|
1313
1491
|
return param.elements.some(
|
|
1314
1492
|
(element) => element !== null && bindsName(element, name)
|
|
1315
1493
|
);
|
|
1316
|
-
case
|
|
1494
|
+
case AST_NODE_TYPES5.ObjectPattern:
|
|
1317
1495
|
return param.properties.some(
|
|
1318
|
-
(property) => property.type ===
|
|
1496
|
+
(property) => property.type === AST_NODE_TYPES5.RestElement ? bindsName(property.argument, name) : bindsName(property.value, name)
|
|
1319
1497
|
);
|
|
1320
1498
|
default:
|
|
1321
1499
|
return false;
|
|
@@ -1330,7 +1508,7 @@ function subtreeReadsName(node, name) {
|
|
|
1330
1508
|
if (found) {
|
|
1331
1509
|
return;
|
|
1332
1510
|
}
|
|
1333
|
-
if (current.type ===
|
|
1511
|
+
if (current.type === AST_NODE_TYPES5.Identifier && current.name === name) {
|
|
1334
1512
|
found = true;
|
|
1335
1513
|
return;
|
|
1336
1514
|
}
|
|
@@ -1341,10 +1519,10 @@ function subtreeReadsName(node, name) {
|
|
|
1341
1519
|
if (key === "parent") {
|
|
1342
1520
|
continue;
|
|
1343
1521
|
}
|
|
1344
|
-
if (key === "key" && current.type ===
|
|
1522
|
+
if (key === "key" && current.type === AST_NODE_TYPES5.Property && !current.computed) {
|
|
1345
1523
|
continue;
|
|
1346
1524
|
}
|
|
1347
|
-
if (key === "property" && current.type ===
|
|
1525
|
+
if (key === "property" && current.type === AST_NODE_TYPES5.MemberExpression && !current.computed) {
|
|
1348
1526
|
continue;
|
|
1349
1527
|
}
|
|
1350
1528
|
const value = current[key];
|
|
@@ -1377,10 +1555,10 @@ var SAFE_PARSE_CONSTRUCTORS = /* @__PURE__ */ new Set([
|
|
|
1377
1555
|
"URLPattern"
|
|
1378
1556
|
]);
|
|
1379
1557
|
function isParseShapedNode(node) {
|
|
1380
|
-
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) {
|
|
1381
1559
|
return node.callee.property.name === "parse";
|
|
1382
1560
|
}
|
|
1383
|
-
if (node.type ===
|
|
1561
|
+
if (node.type === AST_NODE_TYPES5.NewExpression && node.callee.type === AST_NODE_TYPES5.Identifier) {
|
|
1384
1562
|
return SAFE_PARSE_CONSTRUCTORS.has(node.callee.name);
|
|
1385
1563
|
}
|
|
1386
1564
|
return false;
|
|
@@ -1391,10 +1569,10 @@ var BODY_DECODE_METHODS = /* @__PURE__ */ new Set([
|
|
|
1391
1569
|
"arrayBuffer"
|
|
1392
1570
|
]);
|
|
1393
1571
|
function isBodyDecodeNode(node) {
|
|
1394
|
-
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);
|
|
1395
1573
|
}
|
|
1396
1574
|
function returnsMatching(stmt, predicate) {
|
|
1397
|
-
return stmt.type ===
|
|
1575
|
+
return stmt.type === AST_NODE_TYPES5.ReturnStatement && stmt.argument !== null && walkWithinScope(stmt.argument, predicate);
|
|
1398
1576
|
}
|
|
1399
1577
|
function enclosingReturnTypeNode(node) {
|
|
1400
1578
|
let current = node.parent;
|
|
@@ -1412,11 +1590,11 @@ function enclosingFunctionName(node) {
|
|
|
1412
1590
|
let current = node.parent;
|
|
1413
1591
|
while (current !== void 0 && current !== null) {
|
|
1414
1592
|
if (isFunctionNode(current)) {
|
|
1415
|
-
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) {
|
|
1416
1594
|
return current.id.name;
|
|
1417
1595
|
}
|
|
1418
1596
|
const parent = current.parent;
|
|
1419
|
-
if (parent?.type ===
|
|
1597
|
+
if (parent?.type === AST_NODE_TYPES5.VariableDeclarator && parent.id.type === AST_NODE_TYPES5.Identifier) {
|
|
1420
1598
|
return parent.id.name;
|
|
1421
1599
|
}
|
|
1422
1600
|
return null;
|
|
@@ -1437,10 +1615,10 @@ function isDeclaredBooleanPredicate(catchNode, kind) {
|
|
|
1437
1615
|
return false;
|
|
1438
1616
|
}
|
|
1439
1617
|
let declared = enclosingReturnTypeNode(catchNode);
|
|
1440
|
-
if (declared?.type ===
|
|
1618
|
+
if (declared?.type === AST_NODE_TYPES5.TSTypeReference && declared.typeName.type === AST_NODE_TYPES5.Identifier && declared.typeName.name === "Promise") {
|
|
1441
1619
|
declared = declared.typeArguments?.params[0] ?? null;
|
|
1442
1620
|
}
|
|
1443
|
-
return declared?.type ===
|
|
1621
|
+
return declared?.type === AST_NODE_TYPES5.TSBooleanKeyword;
|
|
1444
1622
|
}
|
|
1445
1623
|
function tryReturnsSafeParse(catchNode) {
|
|
1446
1624
|
const tryBlock = tryBlockOf(catchNode);
|
|
@@ -1456,7 +1634,7 @@ function tryReturnsSafeParse(catchNode) {
|
|
|
1456
1634
|
function enclosingFunctionBody(node) {
|
|
1457
1635
|
let current = node.parent;
|
|
1458
1636
|
while (current !== void 0 && current !== null) {
|
|
1459
|
-
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) {
|
|
1460
1638
|
return current.body;
|
|
1461
1639
|
}
|
|
1462
1640
|
current = current.parent;
|
|
@@ -1469,7 +1647,7 @@ function functionReturnsSameSentinelKindElsewhere(catchNode, kind) {
|
|
|
1469
1647
|
return false;
|
|
1470
1648
|
}
|
|
1471
1649
|
return walkWithinScope(functionBody, (current) => {
|
|
1472
|
-
if (current.type !==
|
|
1650
|
+
if (current.type !== AST_NODE_TYPES5.ReturnStatement) {
|
|
1473
1651
|
return false;
|
|
1474
1652
|
}
|
|
1475
1653
|
if (isWithin(current, catchNode.body)) {
|
|
@@ -1488,13 +1666,13 @@ function returnedSentinelKinds(arg) {
|
|
|
1488
1666
|
kinds.add(direct);
|
|
1489
1667
|
return kinds;
|
|
1490
1668
|
}
|
|
1491
|
-
if (arg.type ===
|
|
1669
|
+
if (arg.type === AST_NODE_TYPES5.ConditionalExpression) {
|
|
1492
1670
|
for (const branch of [arg.consequent, arg.alternate]) {
|
|
1493
1671
|
for (const nested of returnedSentinelKinds(branch)) {
|
|
1494
1672
|
kinds.add(nested);
|
|
1495
1673
|
}
|
|
1496
1674
|
}
|
|
1497
|
-
} else if (arg.type ===
|
|
1675
|
+
} else if (arg.type === AST_NODE_TYPES5.LogicalExpression && (arg.operator === "??" || arg.operator === "||")) {
|
|
1498
1676
|
for (const nested of returnedSentinelKinds(arg.right)) {
|
|
1499
1677
|
kinds.add(nested);
|
|
1500
1678
|
}
|
|
@@ -1533,10 +1711,13 @@ var no_sentinel_return_on_catch_default = ESLintUtils9.RuleCreator(
|
|
|
1533
1711
|
},
|
|
1534
1712
|
defaultOptions: [{}],
|
|
1535
1713
|
create(context, [loggingOptions]) {
|
|
1714
|
+
if (isGeneratedFile(context.filename, context.sourceCode.text)) {
|
|
1715
|
+
return {};
|
|
1716
|
+
}
|
|
1536
1717
|
const matcher = createLogMatcher(loggingOptions);
|
|
1537
1718
|
function logsOrReportsError(catchBody, caughtName) {
|
|
1538
1719
|
return walkWithinScope(catchBody, (current) => {
|
|
1539
|
-
if (current.type !==
|
|
1720
|
+
if (current.type !== AST_NODE_TYPES5.CallExpression) {
|
|
1540
1721
|
return false;
|
|
1541
1722
|
}
|
|
1542
1723
|
if (matcher.isLoggingCall(current)) {
|
|
@@ -1553,7 +1734,7 @@ var no_sentinel_return_on_catch_default = ESLintUtils9.RuleCreator(
|
|
|
1553
1734
|
return;
|
|
1554
1735
|
}
|
|
1555
1736
|
const last = body[body.length - 1];
|
|
1556
|
-
if (last === void 0 || last.type !==
|
|
1737
|
+
if (last === void 0 || last.type !== AST_NODE_TYPES5.ReturnStatement) {
|
|
1557
1738
|
return;
|
|
1558
1739
|
}
|
|
1559
1740
|
if (!isSentinelArgument(last.argument)) {
|
|
@@ -1562,7 +1743,7 @@ var no_sentinel_return_on_catch_default = ESLintUtils9.RuleCreator(
|
|
|
1562
1743
|
if (containsThrow(node.body)) {
|
|
1563
1744
|
return;
|
|
1564
1745
|
}
|
|
1565
|
-
const caughtName = node.param?.type ===
|
|
1746
|
+
const caughtName = node.param?.type === AST_NODE_TYPES5.Identifier ? node.param.name : null;
|
|
1566
1747
|
if (logsOrReportsError(node.body, caughtName)) {
|
|
1567
1748
|
return;
|
|
1568
1749
|
}
|
|
@@ -1939,6 +2120,9 @@ var no_string_concat_in_loop_default = ESLintUtils11.RuleCreator(
|
|
|
1939
2120
|
},
|
|
1940
2121
|
defaultOptions: [],
|
|
1941
2122
|
create(context) {
|
|
2123
|
+
if (isGeneratedFile(context.filename, context.sourceCode.text)) {
|
|
2124
|
+
return {};
|
|
2125
|
+
}
|
|
1942
2126
|
const reported = /* @__PURE__ */ new WeakMap();
|
|
1943
2127
|
return {
|
|
1944
2128
|
AssignmentExpression(node) {
|
|
@@ -1984,7 +2168,7 @@ var no_string_concat_in_loop_default = ESLintUtils11.RuleCreator(
|
|
|
1984
2168
|
|
|
1985
2169
|
// src/rules/no-unnecessary-use-client.ts
|
|
1986
2170
|
import {
|
|
1987
|
-
AST_NODE_TYPES as
|
|
2171
|
+
AST_NODE_TYPES as AST_NODE_TYPES6,
|
|
1988
2172
|
ESLintUtils as ESLintUtils12
|
|
1989
2173
|
} from "@typescript-eslint/utils";
|
|
1990
2174
|
var HOOK_REGEX = /^use([A-Z]|$)/;
|
|
@@ -2012,13 +2196,13 @@ var CLIENT_ONLY_PACKAGES_REGEX = /^(?:@radix-ui\/|framer-motion|react-dom|react-
|
|
|
2012
2196
|
var isBareSpecifier = (source) => !source.startsWith(".") && !source.startsWith("/") && !source.startsWith("@/") && !source.startsWith("~");
|
|
2013
2197
|
var jsxRootName = (name) => {
|
|
2014
2198
|
let current = name;
|
|
2015
|
-
while (current.type ===
|
|
2199
|
+
while (current.type === AST_NODE_TYPES6.JSXMemberExpression) {
|
|
2016
2200
|
current = current.object;
|
|
2017
2201
|
}
|
|
2018
|
-
return current.type ===
|
|
2202
|
+
return current.type === AST_NODE_TYPES6.JSXIdentifier ? current.name : "";
|
|
2019
2203
|
};
|
|
2020
2204
|
var subtreeReadsImportedBinding = (node, imported) => {
|
|
2021
|
-
if (node.type ===
|
|
2205
|
+
if (node.type === AST_NODE_TYPES6.Identifier) {
|
|
2022
2206
|
return imported.has(node.name);
|
|
2023
2207
|
}
|
|
2024
2208
|
for (const key of Object.keys(node)) {
|
|
@@ -2033,16 +2217,16 @@ var subtreeReadsImportedBinding = (node, imported) => {
|
|
|
2033
2217
|
return false;
|
|
2034
2218
|
};
|
|
2035
2219
|
var isUseClientDirective = (node) => {
|
|
2036
|
-
return node.type ===
|
|
2220
|
+
return node.type === AST_NODE_TYPES6.ExpressionStatement && node.expression.type === AST_NODE_TYPES6.Literal && node.expression.value === "use client";
|
|
2037
2221
|
};
|
|
2038
2222
|
var isGlobalReference = (node, context) => {
|
|
2039
2223
|
if (!BROWSER_GLOBALS.has(node.name)) return false;
|
|
2040
2224
|
const parent = node.parent;
|
|
2041
2225
|
if (parent !== void 0) {
|
|
2042
|
-
if (parent.type ===
|
|
2226
|
+
if (parent.type === AST_NODE_TYPES6.MemberExpression && parent.property === node && !parent.computed) {
|
|
2043
2227
|
return false;
|
|
2044
2228
|
}
|
|
2045
|
-
if (parent.type ===
|
|
2229
|
+
if (parent.type === AST_NODE_TYPES6.Property && parent.key === node && !parent.computed) {
|
|
2046
2230
|
return false;
|
|
2047
2231
|
}
|
|
2048
2232
|
if (parent.type.startsWith("TS")) {
|
|
@@ -2084,13 +2268,13 @@ var no_unnecessary_use_client_default = ESLintUtils12.RuleCreator(
|
|
|
2084
2268
|
const importedLocals = /* @__PURE__ */ new Set();
|
|
2085
2269
|
const externalLocals = /* @__PURE__ */ new Set();
|
|
2086
2270
|
const markIfHookOrContext = (callee) => {
|
|
2087
|
-
if (callee.type ===
|
|
2271
|
+
if (callee.type === AST_NODE_TYPES6.Identifier) {
|
|
2088
2272
|
if (HOOK_REGEX.test(callee.name) || callee.name === "createContext") {
|
|
2089
2273
|
hasClientIndicator = true;
|
|
2090
2274
|
}
|
|
2091
2275
|
return;
|
|
2092
2276
|
}
|
|
2093
|
-
if (callee.type ===
|
|
2277
|
+
if (callee.type === AST_NODE_TYPES6.MemberExpression && callee.property.type === AST_NODE_TYPES6.Identifier) {
|
|
2094
2278
|
const name = callee.property.name;
|
|
2095
2279
|
if (HOOK_REGEX.test(name) || name === "createContext") {
|
|
2096
2280
|
hasClientIndicator = true;
|
|
@@ -2100,7 +2284,7 @@ var no_unnecessary_use_client_default = ESLintUtils12.RuleCreator(
|
|
|
2100
2284
|
return {
|
|
2101
2285
|
Program(node) {
|
|
2102
2286
|
for (const stmt of node.body) {
|
|
2103
|
-
if (stmt.type !==
|
|
2287
|
+
if (stmt.type !== AST_NODE_TYPES6.ExpressionStatement) break;
|
|
2104
2288
|
if (isUseClientDirective(stmt)) {
|
|
2105
2289
|
directiveNode = stmt;
|
|
2106
2290
|
break;
|
|
@@ -2113,7 +2297,7 @@ var no_unnecessary_use_client_default = ESLintUtils12.RuleCreator(
|
|
|
2113
2297
|
},
|
|
2114
2298
|
JSXAttribute(node) {
|
|
2115
2299
|
if (directiveNode === null) return;
|
|
2116
|
-
if (node.name.type ===
|
|
2300
|
+
if (node.name.type === AST_NODE_TYPES6.JSXIdentifier && EVENT_PROP_REGEX.test(node.name.name)) {
|
|
2117
2301
|
hasClientIndicator = true;
|
|
2118
2302
|
}
|
|
2119
2303
|
},
|
|
@@ -2181,7 +2365,7 @@ var no_unnecessary_use_client_default = ESLintUtils12.RuleCreator(
|
|
|
2181
2365
|
|
|
2182
2366
|
// src/rules/prefer-discriminated-union.ts
|
|
2183
2367
|
import { ESLintUtils as ESLintUtils13 } from "@typescript-eslint/utils";
|
|
2184
|
-
import { AST_NODE_TYPES as
|
|
2368
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES7 } from "@typescript-eslint/utils";
|
|
2185
2369
|
var STATUS_MEMBER_NAMES = /* @__PURE__ */ new Set([
|
|
2186
2370
|
"success",
|
|
2187
2371
|
"ok",
|
|
@@ -2191,27 +2375,27 @@ var STATUS_MEMBER_NAMES = /* @__PURE__ */ new Set([
|
|
|
2191
2375
|
]);
|
|
2192
2376
|
var MIN_OPTIONAL_MEMBERS = 2;
|
|
2193
2377
|
function getMemberName(member) {
|
|
2194
|
-
if (member.type !==
|
|
2378
|
+
if (member.type !== AST_NODE_TYPES7.TSPropertySignature) {
|
|
2195
2379
|
return null;
|
|
2196
2380
|
}
|
|
2197
2381
|
const { key } = member;
|
|
2198
|
-
if (key.type ===
|
|
2382
|
+
if (key.type === AST_NODE_TYPES7.Identifier) {
|
|
2199
2383
|
return key.name;
|
|
2200
2384
|
}
|
|
2201
|
-
if (key.type ===
|
|
2385
|
+
if (key.type === AST_NODE_TYPES7.Literal && typeof key.value === "string") {
|
|
2202
2386
|
return key.value;
|
|
2203
2387
|
}
|
|
2204
2388
|
return null;
|
|
2205
2389
|
}
|
|
2206
2390
|
function isBooleanTyped(member) {
|
|
2207
|
-
return member.typeAnnotation?.typeAnnotation.type ===
|
|
2391
|
+
return member.typeAnnotation?.typeAnnotation.type === AST_NODE_TYPES7.TSBooleanKeyword;
|
|
2208
2392
|
}
|
|
2209
2393
|
function looksLikeMutuallyExclusiveState(typeLiteral) {
|
|
2210
2394
|
let hasStatusBoolean = false;
|
|
2211
2395
|
let optionalCount = 0;
|
|
2212
2396
|
let optionalPayloadCount = 0;
|
|
2213
2397
|
for (const member of typeLiteral.members) {
|
|
2214
|
-
if (member.type !==
|
|
2398
|
+
if (member.type !== AST_NODE_TYPES7.TSPropertySignature) {
|
|
2215
2399
|
continue;
|
|
2216
2400
|
}
|
|
2217
2401
|
if (member.optional) {
|
|
@@ -2255,7 +2439,7 @@ var prefer_discriminated_union_default = ESLintUtils13.RuleCreator(
|
|
|
2255
2439
|
TSInterfaceDeclaration(node) {
|
|
2256
2440
|
const synthetic = {
|
|
2257
2441
|
...node.body,
|
|
2258
|
-
type:
|
|
2442
|
+
type: AST_NODE_TYPES7.TSTypeLiteral,
|
|
2259
2443
|
members: node.body.body
|
|
2260
2444
|
};
|
|
2261
2445
|
checkTypeLiteral(synthetic, node);
|
|
@@ -2269,15 +2453,15 @@ var prefer_discriminated_union_default = ESLintUtils13.RuleCreator(
|
|
|
2269
2453
|
|
|
2270
2454
|
// src/rules/prefer-schema-for-api-payload.ts
|
|
2271
2455
|
import {
|
|
2272
|
-
AST_NODE_TYPES as
|
|
2456
|
+
AST_NODE_TYPES as AST_NODE_TYPES8,
|
|
2273
2457
|
ESLintUtils as ESLintUtils14
|
|
2274
2458
|
} from "@typescript-eslint/utils";
|
|
2275
2459
|
var unwrap = (node) => {
|
|
2276
2460
|
let current = node;
|
|
2277
2461
|
while (current !== null && current !== void 0) {
|
|
2278
|
-
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) {
|
|
2279
2463
|
current = current.expression;
|
|
2280
|
-
} else if (current.type ===
|
|
2464
|
+
} else if (current.type === AST_NODE_TYPES8.ChainExpression) {
|
|
2281
2465
|
current = current.expression;
|
|
2282
2466
|
} else {
|
|
2283
2467
|
break;
|
|
@@ -2288,25 +2472,25 @@ var unwrap = (node) => {
|
|
|
2288
2472
|
var isRawPayloadSource = (node) => {
|
|
2289
2473
|
let current = unwrap(node);
|
|
2290
2474
|
if (current === null) return false;
|
|
2291
|
-
if (current.type ===
|
|
2475
|
+
if (current.type === AST_NODE_TYPES8.AwaitExpression) {
|
|
2292
2476
|
current = unwrap(current.argument);
|
|
2293
2477
|
}
|
|
2294
|
-
if (current === null || current.type !==
|
|
2478
|
+
if (current === null || current.type !== AST_NODE_TYPES8.CallExpression) {
|
|
2295
2479
|
return false;
|
|
2296
2480
|
}
|
|
2297
2481
|
const callee = unwrap(current.callee);
|
|
2298
|
-
if (callee === null || callee.type !==
|
|
2482
|
+
if (callee === null || callee.type !== AST_NODE_TYPES8.MemberExpression) {
|
|
2299
2483
|
return false;
|
|
2300
2484
|
}
|
|
2301
2485
|
const property = unwrap(callee.property);
|
|
2302
|
-
if (property === null || property.type !==
|
|
2486
|
+
if (property === null || property.type !== AST_NODE_TYPES8.Identifier) {
|
|
2303
2487
|
return false;
|
|
2304
2488
|
}
|
|
2305
2489
|
if (property.name === "json") {
|
|
2306
2490
|
return true;
|
|
2307
2491
|
}
|
|
2308
2492
|
const object = unwrap(callee.object);
|
|
2309
|
-
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.
|
|
2310
2494
|
!isLocalFileRead(current.arguments[0]);
|
|
2311
2495
|
};
|
|
2312
2496
|
var FILE_READ_RE = /^(readFile|readFileSync|readJson|readJsonSync|readJSON)$/;
|
|
@@ -2314,9 +2498,9 @@ var isLocalFileRead = (node) => {
|
|
|
2314
2498
|
let found = false;
|
|
2315
2499
|
const visit = (current) => {
|
|
2316
2500
|
if (found || current === null || current === void 0) return;
|
|
2317
|
-
if (current.type ===
|
|
2501
|
+
if (current.type === AST_NODE_TYPES8.CallExpression) {
|
|
2318
2502
|
const callee = unwrap(current.callee);
|
|
2319
|
-
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;
|
|
2320
2504
|
if (name !== null && FILE_READ_RE.test(name)) {
|
|
2321
2505
|
found = true;
|
|
2322
2506
|
return;
|
|
@@ -2338,15 +2522,15 @@ var isLocalFileRead = (node) => {
|
|
|
2338
2522
|
var ASSERTION_CALLEE_RE2 = /^(expect|assert|should|invariant)$/;
|
|
2339
2523
|
var isInsideAssertion = (node) => {
|
|
2340
2524
|
for (let current = node.parent; current !== void 0 && current !== null; current = current.parent) {
|
|
2341
|
-
if (current.type !==
|
|
2525
|
+
if (current.type !== AST_NODE_TYPES8.CallExpression) continue;
|
|
2342
2526
|
let callee = current.callee;
|
|
2343
|
-
while (callee.type ===
|
|
2527
|
+
while (callee.type === AST_NODE_TYPES8.MemberExpression) {
|
|
2344
2528
|
callee = callee.object;
|
|
2345
2529
|
}
|
|
2346
|
-
if (callee.type ===
|
|
2530
|
+
if (callee.type === AST_NODE_TYPES8.CallExpression) {
|
|
2347
2531
|
callee = callee.callee;
|
|
2348
2532
|
}
|
|
2349
|
-
if (callee.type ===
|
|
2533
|
+
if (callee.type === AST_NODE_TYPES8.Identifier && ASSERTION_CALLEE_RE2.test(callee.name)) {
|
|
2350
2534
|
return true;
|
|
2351
2535
|
}
|
|
2352
2536
|
}
|
|
@@ -2367,17 +2551,17 @@ var isGuardTestPosition = (node) => {
|
|
|
2367
2551
|
let parent = current.parent;
|
|
2368
2552
|
while (parent !== void 0 && parent !== null) {
|
|
2369
2553
|
switch (parent.type) {
|
|
2370
|
-
case
|
|
2371
|
-
case
|
|
2372
|
-
case
|
|
2554
|
+
case AST_NODE_TYPES8.UnaryExpression:
|
|
2555
|
+
case AST_NODE_TYPES8.LogicalExpression:
|
|
2556
|
+
case AST_NODE_TYPES8.ChainExpression:
|
|
2373
2557
|
current = parent;
|
|
2374
2558
|
parent = parent.parent;
|
|
2375
2559
|
continue;
|
|
2376
|
-
case
|
|
2377
|
-
case
|
|
2378
|
-
case
|
|
2379
|
-
case
|
|
2380
|
-
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:
|
|
2381
2565
|
return parent.test === current;
|
|
2382
2566
|
default:
|
|
2383
2567
|
return false;
|
|
@@ -2387,7 +2571,7 @@ var isGuardTestPosition = (node) => {
|
|
|
2387
2571
|
};
|
|
2388
2572
|
var isUnvalidatedVariableRef = (node, scope, tracked) => {
|
|
2389
2573
|
const unwrapped = unwrap(node);
|
|
2390
|
-
if (unwrapped === null || unwrapped.type !==
|
|
2574
|
+
if (unwrapped === null || unwrapped.type !== AST_NODE_TYPES8.Identifier) {
|
|
2391
2575
|
return false;
|
|
2392
2576
|
}
|
|
2393
2577
|
const variable = findVariable2(scope, unwrapped.name);
|
|
@@ -2409,7 +2593,7 @@ var prefer_schema_for_api_payload_default = ESLintUtils14.RuleCreator(
|
|
|
2409
2593
|
},
|
|
2410
2594
|
defaultOptions: [],
|
|
2411
2595
|
create(context) {
|
|
2412
|
-
if (isTestFile(context.filename)) {
|
|
2596
|
+
if (isTestFile(context.filename) || isGeneratedFile(context.filename, context.sourceCode.text)) {
|
|
2413
2597
|
return {};
|
|
2414
2598
|
}
|
|
2415
2599
|
const unvalidatedVariables = /* @__PURE__ */ new Set();
|
|
@@ -2424,11 +2608,11 @@ var prefer_schema_for_api_payload_default = ESLintUtils14.RuleCreator(
|
|
|
2424
2608
|
return {
|
|
2425
2609
|
VariableDeclarator(node) {
|
|
2426
2610
|
const scope = context.sourceCode.getScope(node);
|
|
2427
|
-
if (node.id.type ===
|
|
2611
|
+
if (node.id.type === AST_NODE_TYPES8.Identifier) {
|
|
2428
2612
|
trackInitializer(node);
|
|
2429
2613
|
return;
|
|
2430
2614
|
}
|
|
2431
|
-
if (node.id.type ===
|
|
2615
|
+
if (node.id.type === AST_NODE_TYPES8.ObjectPattern || node.id.type === AST_NODE_TYPES8.ArrayPattern) {
|
|
2432
2616
|
if (isRawPayloadSource(node.init)) {
|
|
2433
2617
|
context.report({ node: node.id, messageId: "unparsedJsonAccess" });
|
|
2434
2618
|
return;
|
|
@@ -2440,7 +2624,7 @@ var prefer_schema_for_api_payload_default = ESLintUtils14.RuleCreator(
|
|
|
2440
2624
|
},
|
|
2441
2625
|
AssignmentExpression(node) {
|
|
2442
2626
|
const scope = context.sourceCode.getScope(node);
|
|
2443
|
-
if (node.left.type ===
|
|
2627
|
+
if (node.left.type === AST_NODE_TYPES8.Identifier) {
|
|
2444
2628
|
const variable = findVariable2(scope, node.left.name);
|
|
2445
2629
|
if (variable === null) return;
|
|
2446
2630
|
if (isRawPayloadSource(node.right)) {
|
|
@@ -2450,7 +2634,7 @@ var prefer_schema_for_api_payload_default = ESLintUtils14.RuleCreator(
|
|
|
2450
2634
|
}
|
|
2451
2635
|
return;
|
|
2452
2636
|
}
|
|
2453
|
-
if (node.left.type ===
|
|
2637
|
+
if (node.left.type === AST_NODE_TYPES8.ObjectPattern || node.left.type === AST_NODE_TYPES8.ArrayPattern) {
|
|
2454
2638
|
if (isRawPayloadSource(node.right)) {
|
|
2455
2639
|
context.report({
|
|
2456
2640
|
node: node.left,
|
|
@@ -2467,15 +2651,15 @@ var prefer_schema_for_api_payload_default = ESLintUtils14.RuleCreator(
|
|
|
2467
2651
|
}
|
|
2468
2652
|
},
|
|
2469
2653
|
CallExpression(node) {
|
|
2470
|
-
if (node.callee.type !==
|
|
2654
|
+
if (node.callee.type !== AST_NODE_TYPES8.Identifier) return;
|
|
2471
2655
|
if (!GUARD_NAME_RE.test(node.callee.name) && !isGuardTestPosition(node)) {
|
|
2472
2656
|
return;
|
|
2473
2657
|
}
|
|
2474
2658
|
const scope = context.sourceCode.getScope(node);
|
|
2475
2659
|
for (const arg of node.arguments) {
|
|
2476
|
-
if (arg.type ===
|
|
2660
|
+
if (arg.type === AST_NODE_TYPES8.SpreadElement) continue;
|
|
2477
2661
|
const unwrapped = unwrap(arg);
|
|
2478
|
-
if (unwrapped === null || unwrapped.type !==
|
|
2662
|
+
if (unwrapped === null || unwrapped.type !== AST_NODE_TYPES8.Identifier) {
|
|
2479
2663
|
continue;
|
|
2480
2664
|
}
|
|
2481
2665
|
const variable = findVariable2(scope, unwrapped.name);
|
|
@@ -2488,13 +2672,13 @@ var prefer_schema_for_api_payload_default = ESLintUtils14.RuleCreator(
|
|
|
2488
2672
|
const obj = unwrap(node.object);
|
|
2489
2673
|
if (isRawPayloadSource(obj)) {
|
|
2490
2674
|
const parent = node.parent;
|
|
2491
|
-
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")) {
|
|
2492
2676
|
return;
|
|
2493
2677
|
}
|
|
2494
2678
|
context.report({ node, messageId: "unparsedJsonAccess" });
|
|
2495
2679
|
return;
|
|
2496
2680
|
}
|
|
2497
|
-
if (obj !== null && obj.type ===
|
|
2681
|
+
if (obj !== null && obj.type === AST_NODE_TYPES8.Identifier && isUnvalidatedVariableRef(obj, scope, unvalidatedVariables)) {
|
|
2498
2682
|
context.report({ node, messageId: "unparsedJsonAccess" });
|
|
2499
2683
|
const variable = findVariable2(scope, obj.name);
|
|
2500
2684
|
if (variable !== null) {
|
|
@@ -2507,7 +2691,7 @@ var prefer_schema_for_api_payload_default = ESLintUtils14.RuleCreator(
|
|
|
2507
2691
|
});
|
|
2508
2692
|
|
|
2509
2693
|
// src/rules/prefer-semantic-colors.ts
|
|
2510
|
-
import { AST_NODE_TYPES as
|
|
2694
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES9, ESLintUtils as ESLintUtils15 } from "@typescript-eslint/utils";
|
|
2511
2695
|
import { existsSync, readFileSync } from "fs";
|
|
2512
2696
|
import { dirname, join, parse } from "path";
|
|
2513
2697
|
|
|
@@ -2579,10 +2763,32 @@ var SVG_EXEMPT_COLOR_VALUES = /* @__PURE__ */ new Set([
|
|
|
2579
2763
|
"currentcolor",
|
|
2580
2764
|
"inherit"
|
|
2581
2765
|
]);
|
|
2766
|
+
function jsxElementName(node) {
|
|
2767
|
+
const name = node.openingElement.name;
|
|
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) {
|
|
2770
|
+
return name.property.name;
|
|
2771
|
+
}
|
|
2772
|
+
return null;
|
|
2773
|
+
}
|
|
2774
|
+
function isSvgLikeElementName(name) {
|
|
2775
|
+
return name === "svg" || SVG_DEFS_CONTAINERS.has(name) || /svg$/i.test(name);
|
|
2776
|
+
}
|
|
2582
2777
|
var isInsideSvg = (node) => {
|
|
2583
2778
|
let current = node.parent;
|
|
2584
2779
|
while (current !== void 0 && current !== null) {
|
|
2585
|
-
if (current.type ===
|
|
2780
|
+
if (current.type === AST_NODE_TYPES9.JSXElement) {
|
|
2781
|
+
const name = jsxElementName(current);
|
|
2782
|
+
if (name !== null && isSvgLikeElementName(name)) return true;
|
|
2783
|
+
}
|
|
2784
|
+
current = current.parent;
|
|
2785
|
+
}
|
|
2786
|
+
return false;
|
|
2787
|
+
};
|
|
2788
|
+
var isInsideIconFactoryPath = (node) => {
|
|
2789
|
+
let current = node.parent;
|
|
2790
|
+
while (current !== void 0 && current !== null) {
|
|
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") {
|
|
2586
2792
|
return true;
|
|
2587
2793
|
}
|
|
2588
2794
|
current = current.parent;
|
|
@@ -2618,8 +2824,8 @@ var hasSemanticTokenSystem = (filename) => {
|
|
|
2618
2824
|
return false;
|
|
2619
2825
|
};
|
|
2620
2826
|
var propName = (key) => {
|
|
2621
|
-
if (key.type ===
|
|
2622
|
-
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;
|
|
2623
2829
|
return null;
|
|
2624
2830
|
};
|
|
2625
2831
|
var prefer_semantic_colors_default = ESLintUtils15.RuleCreator(
|
|
@@ -2665,27 +2871,27 @@ var prefer_semantic_colors_default = ESLintUtils15.RuleCreator(
|
|
|
2665
2871
|
const checkClassNode = (node) => {
|
|
2666
2872
|
if (node === null) return;
|
|
2667
2873
|
switch (node.type) {
|
|
2668
|
-
case
|
|
2874
|
+
case AST_NODE_TYPES9.Literal:
|
|
2669
2875
|
if (typeof node.value === "string") reportClasses(node.value, node);
|
|
2670
2876
|
break;
|
|
2671
|
-
case
|
|
2877
|
+
case AST_NODE_TYPES9.TemplateLiteral:
|
|
2672
2878
|
for (const quasi of node.quasis) reportClasses(quasi.value.cooked ?? "", quasi);
|
|
2673
2879
|
break;
|
|
2674
|
-
case
|
|
2880
|
+
case AST_NODE_TYPES9.ArrayExpression:
|
|
2675
2881
|
for (const element of node.elements) {
|
|
2676
|
-
if (element !== null && element.type !==
|
|
2882
|
+
if (element !== null && element.type !== AST_NODE_TYPES9.SpreadElement) checkClassNode(element);
|
|
2677
2883
|
}
|
|
2678
2884
|
break;
|
|
2679
|
-
case
|
|
2885
|
+
case AST_NODE_TYPES9.ObjectExpression:
|
|
2680
2886
|
for (const property of node.properties) {
|
|
2681
|
-
if (property.type ===
|
|
2887
|
+
if (property.type === AST_NODE_TYPES9.Property) checkClassNode(property.value);
|
|
2682
2888
|
}
|
|
2683
2889
|
break;
|
|
2684
|
-
case
|
|
2890
|
+
case AST_NODE_TYPES9.ConditionalExpression:
|
|
2685
2891
|
checkClassNode(node.consequent);
|
|
2686
2892
|
checkClassNode(node.alternate);
|
|
2687
2893
|
break;
|
|
2688
|
-
case
|
|
2894
|
+
case AST_NODE_TYPES9.LogicalExpression:
|
|
2689
2895
|
checkClassNode(node.right);
|
|
2690
2896
|
break;
|
|
2691
2897
|
default:
|
|
@@ -2693,29 +2899,29 @@ var prefer_semantic_colors_default = ESLintUtils15.RuleCreator(
|
|
|
2693
2899
|
}
|
|
2694
2900
|
};
|
|
2695
2901
|
const checkColorValueNode = (node) => {
|
|
2696
|
-
if (node.type ===
|
|
2902
|
+
if (node.type === AST_NODE_TYPES9.Literal && typeof node.value === "string" && RAW_COLOR_VALUE_RE.test(node.value)) {
|
|
2697
2903
|
context.report({ node, messageId: "inlineColor", data: { value: node.value } });
|
|
2698
2904
|
}
|
|
2699
2905
|
};
|
|
2700
2906
|
return {
|
|
2701
2907
|
"JSXAttribute[name.name='className']"(node) {
|
|
2702
2908
|
if (node.value === null) return;
|
|
2703
|
-
if (node.value.type ===
|
|
2704
|
-
else if (node.value.type ===
|
|
2705
|
-
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) {
|
|
2706
2912
|
checkClassNode(node.value.expression);
|
|
2707
2913
|
}
|
|
2708
2914
|
}
|
|
2709
2915
|
},
|
|
2710
2916
|
CallExpression(node) {
|
|
2711
|
-
if (node.callee.type ===
|
|
2917
|
+
if (node.callee.type === AST_NODE_TYPES9.Identifier && CLASS_FNS.has(node.callee.name)) {
|
|
2712
2918
|
for (const arg of node.arguments) {
|
|
2713
|
-
if (arg.type !==
|
|
2919
|
+
if (arg.type !== AST_NODE_TYPES9.SpreadElement) checkClassNode(arg);
|
|
2714
2920
|
}
|
|
2715
2921
|
}
|
|
2716
2922
|
},
|
|
2717
2923
|
VariableDeclarator(node) {
|
|
2718
|
-
if (node.id.type ===
|
|
2924
|
+
if (node.id.type === AST_NODE_TYPES9.Identifier && CLASS_NAME_RE.test(node.id.name)) {
|
|
2719
2925
|
checkClassNode(node.init);
|
|
2720
2926
|
}
|
|
2721
2927
|
},
|
|
@@ -2727,11 +2933,11 @@ var prefer_semantic_colors_default = ESLintUtils15.RuleCreator(
|
|
|
2727
2933
|
// Neutral drawing literals and anything inside an SVG defs container are
|
|
2728
2934
|
// structural, not UI tokens, so they never fire.
|
|
2729
2935
|
"JSXAttribute[name.name=/^(fill|stroke|color)$/]"(node) {
|
|
2730
|
-
if (node.value?.type !==
|
|
2936
|
+
if (node.value?.type !== AST_NODE_TYPES9.Literal) return;
|
|
2731
2937
|
if (typeof node.value.value === "string" && SVG_EXEMPT_COLOR_VALUES.has(node.value.value.toLowerCase())) {
|
|
2732
2938
|
return;
|
|
2733
2939
|
}
|
|
2734
|
-
if (isInsideSvg(node)) return;
|
|
2940
|
+
if (isInsideSvg(node) || isInsideIconFactoryPath(node)) return;
|
|
2735
2941
|
checkColorValueNode(node.value);
|
|
2736
2942
|
},
|
|
2737
2943
|
// Inline style objects: style={{ color: "#111827", backgroundColor: "#fff" }}
|
|
@@ -2900,7 +3106,7 @@ var prefer_server_actions_default = ESLintUtils16.RuleCreator(
|
|
|
2900
3106
|
|
|
2901
3107
|
// src/rules/prefer-shadcn.ts
|
|
2902
3108
|
import {
|
|
2903
|
-
AST_NODE_TYPES as
|
|
3109
|
+
AST_NODE_TYPES as AST_NODE_TYPES10,
|
|
2904
3110
|
ESLintUtils as ESLintUtils17
|
|
2905
3111
|
} from "@typescript-eslint/utils";
|
|
2906
3112
|
var REPLACEMENTS = {
|
|
@@ -2917,10 +3123,10 @@ var SKIPPED_INPUT_TYPES = /* @__PURE__ */ new Set(["file", "hidden"]);
|
|
|
2917
3123
|
var kebabCase = (component) => component.replace(/([a-z0-9])([A-Z])/g, "$1-$2").toLowerCase();
|
|
2918
3124
|
var literalTypeAttr = (node) => {
|
|
2919
3125
|
for (const attribute of node.attributes) {
|
|
2920
|
-
if (attribute.type !==
|
|
3126
|
+
if (attribute.type !== AST_NODE_TYPES10.JSXAttribute || attribute.name.type !== AST_NODE_TYPES10.JSXIdentifier || attribute.name.name !== "type") {
|
|
2921
3127
|
continue;
|
|
2922
3128
|
}
|
|
2923
|
-
if (attribute.value?.type ===
|
|
3129
|
+
if (attribute.value?.type === AST_NODE_TYPES10.Literal && typeof attribute.value.value === "string") {
|
|
2924
3130
|
return { kind: "literal", value: attribute.value.value.toLowerCase() };
|
|
2925
3131
|
}
|
|
2926
3132
|
return { kind: "dynamic" };
|
|
@@ -2928,7 +3134,7 @@ var literalTypeAttr = (node) => {
|
|
|
2928
3134
|
return null;
|
|
2929
3135
|
};
|
|
2930
3136
|
var hasFileAcceptAttr = (node) => node.attributes.some(
|
|
2931
|
-
(attribute) => attribute.type ===
|
|
3137
|
+
(attribute) => attribute.type === AST_NODE_TYPES10.JSXAttribute && attribute.name.type === AST_NODE_TYPES10.JSXIdentifier && attribute.name.name === "accept"
|
|
2932
3138
|
);
|
|
2933
3139
|
var resolveInputReplacement = (node) => {
|
|
2934
3140
|
const typeAttr = literalTypeAttr(node);
|
|
@@ -2983,37 +3189,37 @@ var prefer_shadcn_default = ESLintUtils17.RuleCreator(
|
|
|
2983
3189
|
// src/rules/require-assert-never.ts
|
|
2984
3190
|
import {
|
|
2985
3191
|
ESLintUtils as ESLintUtils18,
|
|
2986
|
-
AST_NODE_TYPES as
|
|
3192
|
+
AST_NODE_TYPES as AST_NODE_TYPES11
|
|
2987
3193
|
} from "@typescript-eslint/utils";
|
|
2988
3194
|
var isAssertNeverCall = (expression) => {
|
|
2989
|
-
if (expression.type !==
|
|
3195
|
+
if (expression.type !== AST_NODE_TYPES11.CallExpression) return false;
|
|
2990
3196
|
const callee = expression.callee;
|
|
2991
|
-
if (callee.type ===
|
|
3197
|
+
if (callee.type === AST_NODE_TYPES11.Identifier) {
|
|
2992
3198
|
return callee.name === "assertNever";
|
|
2993
3199
|
}
|
|
2994
|
-
if (callee.type ===
|
|
3200
|
+
if (callee.type === AST_NODE_TYPES11.MemberExpression && !callee.computed && callee.property.type === AST_NODE_TYPES11.Identifier) {
|
|
2995
3201
|
return callee.property.name === "assertNever";
|
|
2996
3202
|
}
|
|
2997
3203
|
return false;
|
|
2998
3204
|
};
|
|
2999
3205
|
var statementContainsAssertNever = (statement) => {
|
|
3000
|
-
if (statement.type ===
|
|
3206
|
+
if (statement.type === AST_NODE_TYPES11.ExpressionStatement) {
|
|
3001
3207
|
return isAssertNeverCall(statement.expression);
|
|
3002
3208
|
}
|
|
3003
|
-
if (statement.type ===
|
|
3209
|
+
if (statement.type === AST_NODE_TYPES11.ThrowStatement) {
|
|
3004
3210
|
return isAssertNeverCall(statement.argument);
|
|
3005
3211
|
}
|
|
3006
|
-
if (statement.type ===
|
|
3212
|
+
if (statement.type === AST_NODE_TYPES11.ReturnStatement) {
|
|
3007
3213
|
return statement.argument !== null && isAssertNeverCall(statement.argument);
|
|
3008
3214
|
}
|
|
3009
|
-
if (statement.type ===
|
|
3215
|
+
if (statement.type === AST_NODE_TYPES11.BlockStatement) {
|
|
3010
3216
|
return statement.body.some(statementContainsAssertNever);
|
|
3011
3217
|
}
|
|
3012
3218
|
return false;
|
|
3013
3219
|
};
|
|
3014
3220
|
var isRuntimeHandlingStatement = (statement) => {
|
|
3015
|
-
if (statement.type ===
|
|
3016
|
-
if (statement.type ===
|
|
3221
|
+
if (statement.type === AST_NODE_TYPES11.EmptyStatement) return false;
|
|
3222
|
+
if (statement.type === AST_NODE_TYPES11.BlockStatement) {
|
|
3017
3223
|
return statement.body.some(isRuntimeHandlingStatement);
|
|
3018
3224
|
}
|
|
3019
3225
|
return true;
|
|
@@ -3029,7 +3235,7 @@ var isCommentOnlyNoopDefault = (defaultCase, sourceCode) => {
|
|
|
3029
3235
|
return colonToken !== null && sourceCode.getCommentsAfter(colonToken).length > 0;
|
|
3030
3236
|
}
|
|
3031
3237
|
const only = defaultCase.consequent[0];
|
|
3032
|
-
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) {
|
|
3033
3239
|
return sourceCode.getCommentsInside(only).length > 0;
|
|
3034
3240
|
}
|
|
3035
3241
|
return false;
|
|
@@ -3072,7 +3278,7 @@ var require_assert_never_default = ESLintUtils18.RuleCreator(
|
|
|
3072
3278
|
});
|
|
3073
3279
|
|
|
3074
3280
|
// src/rules/require-zod-form-validation.ts
|
|
3075
|
-
import { ESLintUtils as ESLintUtils19, AST_NODE_TYPES as
|
|
3281
|
+
import { ESLintUtils as ESLintUtils19, AST_NODE_TYPES as AST_NODE_TYPES12 } from "@typescript-eslint/utils";
|
|
3076
3282
|
|
|
3077
3283
|
// src/rules/_zod.ts
|
|
3078
3284
|
var ZOD_PREFIX_RE = /^Z[A-Z]/;
|
|
@@ -3083,14 +3289,14 @@ var ZOD_SCHEMA_NAME_RE = /Schema$|^Z[A-Z]/;
|
|
|
3083
3289
|
var looksLikeZodSchema = (node) => {
|
|
3084
3290
|
let current = node;
|
|
3085
3291
|
while (true) {
|
|
3086
|
-
if (current.type ===
|
|
3292
|
+
if (current.type === AST_NODE_TYPES12.Identifier) {
|
|
3087
3293
|
return current.name === "z" || ZOD_SCHEMA_NAME_RE.test(current.name);
|
|
3088
3294
|
}
|
|
3089
|
-
if (current.type ===
|
|
3295
|
+
if (current.type === AST_NODE_TYPES12.CallExpression) {
|
|
3090
3296
|
current = current.callee;
|
|
3091
3297
|
continue;
|
|
3092
3298
|
}
|
|
3093
|
-
if (current.type ===
|
|
3299
|
+
if (current.type === AST_NODE_TYPES12.MemberExpression) {
|
|
3094
3300
|
current = current.object;
|
|
3095
3301
|
continue;
|
|
3096
3302
|
}
|
|
@@ -3098,23 +3304,23 @@ var looksLikeZodSchema = (node) => {
|
|
|
3098
3304
|
}
|
|
3099
3305
|
};
|
|
3100
3306
|
var isZodParseCall = (node) => {
|
|
3101
|
-
if (node.type !==
|
|
3307
|
+
if (node.type !== AST_NODE_TYPES12.CallExpression) return false;
|
|
3102
3308
|
const callee = node.callee;
|
|
3103
|
-
if (callee.type !==
|
|
3309
|
+
if (callee.type !== AST_NODE_TYPES12.MemberExpression) return false;
|
|
3104
3310
|
if (callee.computed) return false;
|
|
3105
|
-
if (callee.property.type !==
|
|
3311
|
+
if (callee.property.type !== AST_NODE_TYPES12.Identifier) return false;
|
|
3106
3312
|
const method = callee.property.name;
|
|
3107
3313
|
if (method !== "parse" && method !== "safeParse") return false;
|
|
3108
3314
|
return looksLikeZodSchema(callee.object);
|
|
3109
3315
|
};
|
|
3110
3316
|
var isFormDataMethodCall = (node) => {
|
|
3111
3317
|
let current = node;
|
|
3112
|
-
if (current.type ===
|
|
3318
|
+
if (current.type === AST_NODE_TYPES12.AwaitExpression) {
|
|
3113
3319
|
current = current.argument;
|
|
3114
3320
|
}
|
|
3115
|
-
if (current.type !==
|
|
3321
|
+
if (current.type !== AST_NODE_TYPES12.CallExpression) return false;
|
|
3116
3322
|
const callee = current.callee;
|
|
3117
|
-
return callee.type ===
|
|
3323
|
+
return callee.type === AST_NODE_TYPES12.MemberExpression && !callee.computed && callee.property.type === AST_NODE_TYPES12.Identifier && callee.property.name === "formData";
|
|
3118
3324
|
};
|
|
3119
3325
|
var require_zod_form_validation_default = ESLintUtils19.RuleCreator(
|
|
3120
3326
|
(name) => `https://github.com/sarj-ai/linting/blob/main/packages/typescript/src/rules/${name}.ts`
|
|
@@ -3136,14 +3342,14 @@ var require_zod_form_validation_default = ESLintUtils19.RuleCreator(
|
|
|
3136
3342
|
return {};
|
|
3137
3343
|
}
|
|
3138
3344
|
const isFormSourceIdentifier = (node) => {
|
|
3139
|
-
if (node.type !==
|
|
3345
|
+
if (node.type !== AST_NODE_TYPES12.Identifier) return false;
|
|
3140
3346
|
if (/formdata/i.test(node.name)) return true;
|
|
3141
3347
|
let scope = context.sourceCode.getScope(node);
|
|
3142
3348
|
while (scope !== null) {
|
|
3143
3349
|
const variable = scope.set.get(node.name);
|
|
3144
3350
|
if (variable !== void 0 && variable.defs.length === 1) {
|
|
3145
3351
|
const def = variable.defs[0];
|
|
3146
|
-
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) {
|
|
3147
3353
|
return isFormDataMethodCall(def.node.init);
|
|
3148
3354
|
}
|
|
3149
3355
|
return false;
|
|
@@ -3154,8 +3360,8 @@ var require_zod_form_validation_default = ESLintUtils19.RuleCreator(
|
|
|
3154
3360
|
};
|
|
3155
3361
|
const isFormDataGetCall = (node) => {
|
|
3156
3362
|
const callee = node.callee;
|
|
3157
|
-
if (callee.type !==
|
|
3158
|
-
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") {
|
|
3159
3365
|
return false;
|
|
3160
3366
|
}
|
|
3161
3367
|
return isFormSourceIdentifier(callee.object);
|
|
@@ -3170,11 +3376,11 @@ var require_zod_form_validation_default = ESLintUtils19.RuleCreator(
|
|
|
3170
3376
|
};
|
|
3171
3377
|
const isInstanceofNarrowing = (node) => {
|
|
3172
3378
|
const parent = node.parent;
|
|
3173
|
-
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;
|
|
3174
3380
|
};
|
|
3175
3381
|
const boundDeclarator = (node) => {
|
|
3176
3382
|
const parent = node.parent;
|
|
3177
|
-
if (parent.type ===
|
|
3383
|
+
if (parent.type === AST_NODE_TYPES12.VariableDeclarator && parent.init === node && parent.id.type === AST_NODE_TYPES12.Identifier) {
|
|
3178
3384
|
return parent;
|
|
3179
3385
|
}
|
|
3180
3386
|
return null;
|
|
@@ -3202,7 +3408,7 @@ var require_zod_form_validation_default = ESLintUtils19.RuleCreator(
|
|
|
3202
3408
|
});
|
|
3203
3409
|
|
|
3204
3410
|
// src/rules/zod-naming-convention.ts
|
|
3205
|
-
import { ESLintUtils as ESLintUtils20, AST_NODE_TYPES as
|
|
3411
|
+
import { ESLintUtils as ESLintUtils20, AST_NODE_TYPES as AST_NODE_TYPES13 } from "@typescript-eslint/utils";
|
|
3206
3412
|
var CONVENTIONS = {
|
|
3207
3413
|
prefix: { test: ZOD_PREFIX_RE, messageId: "zPrefix" },
|
|
3208
3414
|
suffix: { test: ZOD_SUFFIX_RE, messageId: "schemaSuffix" },
|
|
@@ -3226,15 +3432,15 @@ var NON_SCHEMA_TERMINALS = /* @__PURE__ */ new Set([
|
|
|
3226
3432
|
"registry",
|
|
3227
3433
|
"implement"
|
|
3228
3434
|
]);
|
|
3229
|
-
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;
|
|
3230
3436
|
var calleeChainStartsWithZ = (node) => {
|
|
3231
3437
|
let current = node;
|
|
3232
|
-
while (current.type ===
|
|
3438
|
+
while (current.type === AST_NODE_TYPES13.MemberExpression) {
|
|
3233
3439
|
const receiver = current.object;
|
|
3234
|
-
if (receiver.type ===
|
|
3440
|
+
if (receiver.type === AST_NODE_TYPES13.Identifier && receiver.name === "z") {
|
|
3235
3441
|
return true;
|
|
3236
3442
|
}
|
|
3237
|
-
if (receiver.type ===
|
|
3443
|
+
if (receiver.type === AST_NODE_TYPES13.CallExpression) {
|
|
3238
3444
|
current = receiver.callee;
|
|
3239
3445
|
continue;
|
|
3240
3446
|
}
|
|
@@ -3281,13 +3487,13 @@ var zod_naming_convention_default = ESLintUtils20.RuleCreator(
|
|
|
3281
3487
|
VariableDeclarator(node) {
|
|
3282
3488
|
const init = node.init;
|
|
3283
3489
|
if (init === null || init === void 0) return;
|
|
3284
|
-
if (init.type !==
|
|
3490
|
+
if (init.type !== AST_NODE_TYPES13.CallExpression) return;
|
|
3285
3491
|
const callee = init.callee;
|
|
3286
|
-
if (callee.type !==
|
|
3492
|
+
if (callee.type !== AST_NODE_TYPES13.MemberExpression) return;
|
|
3287
3493
|
if (!calleeChainStartsWithZ(callee)) return;
|
|
3288
3494
|
const terminal = terminalMethodName(callee);
|
|
3289
3495
|
if (terminal !== null && NON_SCHEMA_TERMINALS.has(terminal)) return;
|
|
3290
|
-
if (node.id.type !==
|
|
3496
|
+
if (node.id.type !== AST_NODE_TYPES13.Identifier) return;
|
|
3291
3497
|
if (test.test(node.id.name)) return;
|
|
3292
3498
|
if (acceptsSchemaWord && CONTAINS_SCHEMA_RE.test(node.id.name)) return;
|
|
3293
3499
|
context.report({
|
|
@@ -3510,9 +3716,9 @@ var no_cors_wildcard_with_credentials_default = ESLintUtils21.RuleCreator(
|
|
|
3510
3716
|
});
|
|
3511
3717
|
|
|
3512
3718
|
// src/rules/no-silent-promise-catch.ts
|
|
3513
|
-
import { AST_NODE_TYPES as
|
|
3719
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES14, ESLintUtils as ESLintUtils22 } from "@typescript-eslint/utils";
|
|
3514
3720
|
function isBodyParseCall(node) {
|
|
3515
|
-
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");
|
|
3516
3722
|
}
|
|
3517
3723
|
var TEARDOWN_METHODS = /* @__PURE__ */ new Set([
|
|
3518
3724
|
"cancel",
|
|
@@ -3527,21 +3733,21 @@ var TEARDOWN_METHODS = /* @__PURE__ */ new Set([
|
|
|
3527
3733
|
var DIRECTIVE_COMMENT_RE = /^\s*(eslint-|@ts-|prettier-ignore|biome-ignore|c8 |v8 |istanbul )/;
|
|
3528
3734
|
var isExplanatory = (comment) => !DIRECTIVE_COMMENT_RE.test(comment.value);
|
|
3529
3735
|
function isTeardownCall(node) {
|
|
3530
|
-
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);
|
|
3531
3737
|
}
|
|
3532
3738
|
function isSilentExpression(node) {
|
|
3533
3739
|
switch (node.type) {
|
|
3534
|
-
case
|
|
3740
|
+
case AST_NODE_TYPES14.Literal:
|
|
3535
3741
|
return !("regex" in node);
|
|
3536
|
-
case
|
|
3742
|
+
case AST_NODE_TYPES14.Identifier:
|
|
3537
3743
|
return node.name === "undefined";
|
|
3538
|
-
case
|
|
3539
|
-
return node.operator === "void" && node.argument.type ===
|
|
3540
|
-
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:
|
|
3541
3747
|
return node.properties.length === 0;
|
|
3542
|
-
case
|
|
3748
|
+
case AST_NODE_TYPES14.ArrayExpression:
|
|
3543
3749
|
return node.elements.length === 0;
|
|
3544
|
-
case
|
|
3750
|
+
case AST_NODE_TYPES14.TSAsExpression:
|
|
3545
3751
|
return isSilentExpression(node.expression);
|
|
3546
3752
|
default:
|
|
3547
3753
|
return false;
|
|
@@ -3549,7 +3755,7 @@ function isSilentExpression(node) {
|
|
|
3549
3755
|
}
|
|
3550
3756
|
function isSilentHandler(handler) {
|
|
3551
3757
|
const body = handler.body;
|
|
3552
|
-
if (body.type !==
|
|
3758
|
+
if (body.type !== AST_NODE_TYPES14.BlockStatement) {
|
|
3553
3759
|
return isSilentExpression(body);
|
|
3554
3760
|
}
|
|
3555
3761
|
if (body.body.length === 0) {
|
|
@@ -3557,7 +3763,7 @@ function isSilentHandler(handler) {
|
|
|
3557
3763
|
}
|
|
3558
3764
|
if (body.body.length === 1) {
|
|
3559
3765
|
const only = body.body[0];
|
|
3560
|
-
if (only !== void 0 && only.type ===
|
|
3766
|
+
if (only !== void 0 && only.type === AST_NODE_TYPES14.ReturnStatement) {
|
|
3561
3767
|
return only.argument === null || isSilentExpression(only.argument);
|
|
3562
3768
|
}
|
|
3563
3769
|
}
|
|
@@ -3588,7 +3794,7 @@ var no_silent_promise_catch_default = ESLintUtils22.RuleCreator(
|
|
|
3588
3794
|
return true;
|
|
3589
3795
|
}
|
|
3590
3796
|
let statement = call;
|
|
3591
|
-
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) {
|
|
3592
3798
|
statement = statement.parent;
|
|
3593
3799
|
}
|
|
3594
3800
|
if (sourceCode.getCommentsBefore(statement).some(isExplanatory)) {
|
|
@@ -3600,7 +3806,7 @@ var no_silent_promise_catch_default = ESLintUtils22.RuleCreator(
|
|
|
3600
3806
|
};
|
|
3601
3807
|
return {
|
|
3602
3808
|
CallExpression(node) {
|
|
3603
|
-
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") {
|
|
3604
3810
|
return;
|
|
3605
3811
|
}
|
|
3606
3812
|
if (isBodyParseCall(node.callee.object)) {
|
|
@@ -3609,14 +3815,14 @@ var no_silent_promise_catch_default = ESLintUtils22.RuleCreator(
|
|
|
3609
3815
|
if (isTeardownCall(node.callee.object)) {
|
|
3610
3816
|
return;
|
|
3611
3817
|
}
|
|
3612
|
-
if (node.parent.type ===
|
|
3818
|
+
if (node.parent.type === AST_NODE_TYPES14.MemberExpression && node.parent.object === node) {
|
|
3613
3819
|
return;
|
|
3614
3820
|
}
|
|
3615
3821
|
if (node.arguments.length !== 1) {
|
|
3616
3822
|
return;
|
|
3617
3823
|
}
|
|
3618
3824
|
const handler = node.arguments[0];
|
|
3619
|
-
if (handler === void 0 || handler.type !==
|
|
3825
|
+
if (handler === void 0 || handler.type !== AST_NODE_TYPES14.ArrowFunctionExpression && handler.type !== AST_NODE_TYPES14.FunctionExpression) {
|
|
3620
3826
|
return;
|
|
3621
3827
|
}
|
|
3622
3828
|
if (hasExplanatoryComment(node, handler)) {
|
|
@@ -3632,7 +3838,7 @@ var no_silent_promise_catch_default = ESLintUtils22.RuleCreator(
|
|
|
3632
3838
|
|
|
3633
3839
|
// src/rules/require-fetch-timeout.ts
|
|
3634
3840
|
import {
|
|
3635
|
-
AST_NODE_TYPES as
|
|
3841
|
+
AST_NODE_TYPES as AST_NODE_TYPES15,
|
|
3636
3842
|
ASTUtils,
|
|
3637
3843
|
ESLintUtils as ESLintUtils23
|
|
3638
3844
|
} from "@typescript-eslint/utils";
|
|
@@ -3652,14 +3858,14 @@ function matchesAnyPattern2(filename, patterns) {
|
|
|
3652
3858
|
return false;
|
|
3653
3859
|
}
|
|
3654
3860
|
function initProvablyLacksSignal(init) {
|
|
3655
|
-
if (init.type !==
|
|
3861
|
+
if (init.type !== AST_NODE_TYPES15.ObjectExpression) {
|
|
3656
3862
|
return false;
|
|
3657
3863
|
}
|
|
3658
3864
|
for (const prop of init.properties) {
|
|
3659
|
-
if (prop.type ===
|
|
3865
|
+
if (prop.type === AST_NODE_TYPES15.SpreadElement) {
|
|
3660
3866
|
return false;
|
|
3661
3867
|
}
|
|
3662
|
-
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") {
|
|
3663
3869
|
return false;
|
|
3664
3870
|
}
|
|
3665
3871
|
if (prop.computed) {
|
|
@@ -3669,7 +3875,7 @@ function initProvablyLacksSignal(init) {
|
|
|
3669
3875
|
return true;
|
|
3670
3876
|
}
|
|
3671
3877
|
function isStringish(node) {
|
|
3672
|
-
return node.type ===
|
|
3878
|
+
return node.type === AST_NODE_TYPES15.Literal && typeof node.value === "string" || node.type === AST_NODE_TYPES15.TemplateLiteral;
|
|
3673
3879
|
}
|
|
3674
3880
|
var require_fetch_timeout_default = ESLintUtils23.RuleCreator(
|
|
3675
3881
|
(name) => `https://github.com/sarj-ai/linting/blob/main/packages/typescript/src/rules/${name}.ts`
|
|
@@ -3712,10 +3918,10 @@ var require_fetch_timeout_default = ESLintUtils23.RuleCreator(
|
|
|
3712
3918
|
return variable === null || variable.defs.length === 0;
|
|
3713
3919
|
}
|
|
3714
3920
|
function isGlobalFetchCall2(callee) {
|
|
3715
|
-
if (callee.type ===
|
|
3921
|
+
if (callee.type === AST_NODE_TYPES15.Identifier) {
|
|
3716
3922
|
return callee.name === "fetch" && resolvesToGlobal(callee);
|
|
3717
3923
|
}
|
|
3718
|
-
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);
|
|
3719
3925
|
}
|
|
3720
3926
|
return {
|
|
3721
3927
|
CallExpression(node) {
|
|
@@ -3735,23 +3941,23 @@ var require_fetch_timeout_default = ESLintUtils23.RuleCreator(
|
|
|
3735
3941
|
});
|
|
3736
3942
|
|
|
3737
3943
|
// src/rules/require-schema-validate-search.ts
|
|
3738
|
-
import { AST_NODE_TYPES as
|
|
3944
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES16, ESLintUtils as ESLintUtils24 } from "@typescript-eslint/utils";
|
|
3739
3945
|
var VALIDATOR_METHODS = /* @__PURE__ */ new Set([
|
|
3740
3946
|
"parse",
|
|
3741
3947
|
"safeParse",
|
|
3742
3948
|
"decode"
|
|
3743
3949
|
]);
|
|
3744
3950
|
function isConstTypeAnnotation(typeAnnotation) {
|
|
3745
|
-
return typeAnnotation.type ===
|
|
3951
|
+
return typeAnnotation.type === AST_NODE_TYPES16.TSTypeReference && typeAnnotation.typeName.type === AST_NODE_TYPES16.Identifier && typeAnnotation.typeName.name === "const";
|
|
3746
3952
|
}
|
|
3747
3953
|
function isValidatorCall(node) {
|
|
3748
|
-
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);
|
|
3749
3955
|
}
|
|
3750
3956
|
function findCastExpression(node, insideValidatorArg) {
|
|
3751
|
-
if ((node.type ===
|
|
3957
|
+
if ((node.type === AST_NODE_TYPES16.TSAsExpression || node.type === AST_NODE_TYPES16.TSTypeAssertion) && !isConstTypeAnnotation(node.typeAnnotation) && !insideValidatorArg) {
|
|
3752
3958
|
return node;
|
|
3753
3959
|
}
|
|
3754
|
-
if (node.type ===
|
|
3960
|
+
if (node.type === AST_NODE_TYPES16.CallExpression && isValidatorCall(node)) {
|
|
3755
3961
|
const inCallee = findCastExpression(node.callee, insideValidatorArg);
|
|
3756
3962
|
if (inCallee !== null) {
|
|
3757
3963
|
return inCallee;
|
|
@@ -3805,11 +4011,11 @@ var require_schema_validate_search_default = ESLintUtils24.RuleCreator(
|
|
|
3805
4011
|
}
|
|
3806
4012
|
return {
|
|
3807
4013
|
Property(node) {
|
|
3808
|
-
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";
|
|
3809
4015
|
if (!isValidateSearchKey) {
|
|
3810
4016
|
return;
|
|
3811
4017
|
}
|
|
3812
|
-
if (node.value.type !==
|
|
4018
|
+
if (node.value.type !== AST_NODE_TYPES16.ArrowFunctionExpression && node.value.type !== AST_NODE_TYPES16.FunctionExpression) {
|
|
3813
4019
|
return;
|
|
3814
4020
|
}
|
|
3815
4021
|
const cast = findCastExpression(node.value.body, false);
|
|
@@ -3824,13 +4030,13 @@ var require_schema_validate_search_default = ESLintUtils24.RuleCreator(
|
|
|
3824
4030
|
// src/rules/no-fat-try-blocks.ts
|
|
3825
4031
|
import {
|
|
3826
4032
|
ESLintUtils as ESLintUtils25,
|
|
3827
|
-
AST_NODE_TYPES as
|
|
4033
|
+
AST_NODE_TYPES as AST_NODE_TYPES17
|
|
3828
4034
|
} from "@typescript-eslint/utils";
|
|
3829
4035
|
var MAX_TRY_BODY_STATEMENTS = 3;
|
|
3830
4036
|
var NESTED_FUNCTION_TYPES = /* @__PURE__ */ new Set([
|
|
3831
|
-
|
|
3832
|
-
|
|
3833
|
-
|
|
4037
|
+
AST_NODE_TYPES17.FunctionDeclaration,
|
|
4038
|
+
AST_NODE_TYPES17.FunctionExpression,
|
|
4039
|
+
AST_NODE_TYPES17.ArrowFunctionExpression
|
|
3834
4040
|
]);
|
|
3835
4041
|
var PURE_METHODS = /* @__PURE__ */ new Set([
|
|
3836
4042
|
"map",
|
|
@@ -3928,20 +4134,20 @@ function isNode4(value) {
|
|
|
3928
4134
|
}
|
|
3929
4135
|
function isPureCall(node) {
|
|
3930
4136
|
const callee = node.callee;
|
|
3931
|
-
if (callee.type !==
|
|
4137
|
+
if (callee.type !== AST_NODE_TYPES17.MemberExpression) {
|
|
3932
4138
|
return false;
|
|
3933
4139
|
}
|
|
3934
4140
|
const property = callee.property;
|
|
3935
|
-
if (property.type !==
|
|
4141
|
+
if (property.type !== AST_NODE_TYPES17.Identifier) {
|
|
3936
4142
|
return false;
|
|
3937
4143
|
}
|
|
3938
|
-
if (callee.object.type ===
|
|
4144
|
+
if (callee.object.type === AST_NODE_TYPES17.Identifier && PURE_NAMESPACES.has(callee.object.name)) {
|
|
3939
4145
|
return true;
|
|
3940
4146
|
}
|
|
3941
4147
|
return PURE_METHODS.has(property.name);
|
|
3942
4148
|
}
|
|
3943
4149
|
function isPureNew(node) {
|
|
3944
|
-
return node.callee.type ===
|
|
4150
|
+
return node.callee.type === AST_NODE_TYPES17.Identifier && PURE_CONSTRUCTORS.has(node.callee.name);
|
|
3945
4151
|
}
|
|
3946
4152
|
function subtreeMatches(stmt, predicate) {
|
|
3947
4153
|
let found = false;
|
|
@@ -3978,20 +4184,20 @@ function subtreeMatches(stmt, predicate) {
|
|
|
3978
4184
|
visit(stmt);
|
|
3979
4185
|
return found;
|
|
3980
4186
|
}
|
|
3981
|
-
var hasAwait = (node) => subtreeMatches(node, (n) => n.type ===
|
|
4187
|
+
var hasAwait = (node) => subtreeMatches(node, (n) => n.type === AST_NODE_TYPES17.AwaitExpression);
|
|
3982
4188
|
var hasThrowingCallOrNew = (node) => subtreeMatches(
|
|
3983
4189
|
node,
|
|
3984
|
-
(n) => n.type ===
|
|
4190
|
+
(n) => n.type === AST_NODE_TYPES17.CallExpression && !isPureCall(n) || n.type === AST_NODE_TYPES17.NewExpression && !isPureNew(n)
|
|
3985
4191
|
);
|
|
3986
4192
|
function unwrap2(expr) {
|
|
3987
4193
|
let current = expr;
|
|
3988
|
-
while (current.type ===
|
|
4194
|
+
while (current.type === AST_NODE_TYPES17.ChainExpression || current.type === AST_NODE_TYPES17.TSNonNullExpression) {
|
|
3989
4195
|
current = current.expression;
|
|
3990
4196
|
}
|
|
3991
4197
|
return current;
|
|
3992
4198
|
}
|
|
3993
4199
|
function isBareCallStatement(stmt) {
|
|
3994
|
-
return stmt.type ===
|
|
4200
|
+
return stmt.type === AST_NODE_TYPES17.ExpressionStatement && unwrap2(stmt.expression).type === AST_NODE_TYPES17.CallExpression;
|
|
3995
4201
|
}
|
|
3996
4202
|
function canThrow(stmt) {
|
|
3997
4203
|
if (hasAwait(stmt)) {
|
|
@@ -4000,10 +4206,10 @@ function canThrow(stmt) {
|
|
|
4000
4206
|
if (isBareCallStatement(stmt)) {
|
|
4001
4207
|
return false;
|
|
4002
4208
|
}
|
|
4003
|
-
if (stmt.type ===
|
|
4209
|
+
if (stmt.type === AST_NODE_TYPES17.BlockStatement) {
|
|
4004
4210
|
return stmt.body.some(canThrow);
|
|
4005
4211
|
}
|
|
4006
|
-
if (stmt.type ===
|
|
4212
|
+
if (stmt.type === AST_NODE_TYPES17.IfStatement) {
|
|
4007
4213
|
return hasThrowingCallOrNew(stmt.test) || canThrow(stmt.consequent) || stmt.alternate !== null && canThrow(stmt.alternate);
|
|
4008
4214
|
}
|
|
4009
4215
|
return hasThrowingCallOrNew(stmt);
|
|
@@ -4014,7 +4220,7 @@ function handlerRethrows(handler) {
|
|
|
4014
4220
|
}
|
|
4015
4221
|
const body = handler.body.body;
|
|
4016
4222
|
const last = body[body.length - 1];
|
|
4017
|
-
return last !== void 0 && last.type ===
|
|
4223
|
+
return last !== void 0 && last.type === AST_NODE_TYPES17.ThrowStatement;
|
|
4018
4224
|
}
|
|
4019
4225
|
var no_fat_try_blocks_default = ESLintUtils25.RuleCreator(
|
|
4020
4226
|
(name) => `https://github.com/sarj-ai/standards/blob/main/packages/typescript/src/rules/${name}.ts`
|
|
@@ -4032,6 +4238,9 @@ var no_fat_try_blocks_default = ESLintUtils25.RuleCreator(
|
|
|
4032
4238
|
},
|
|
4033
4239
|
defaultOptions: [],
|
|
4034
4240
|
create(context) {
|
|
4241
|
+
if (isGeneratedFile(context.filename, context.sourceCode.text)) {
|
|
4242
|
+
return {};
|
|
4243
|
+
}
|
|
4035
4244
|
const sourceCode = context.sourceCode;
|
|
4036
4245
|
return {
|
|
4037
4246
|
TryStatement(node) {
|
|
@@ -4397,12 +4606,12 @@ var no_secret_in_log_default = ESLintUtils26.RuleCreator(
|
|
|
4397
4606
|
|
|
4398
4607
|
// src/rules/no-unsafe-cast.ts
|
|
4399
4608
|
import { ESLintUtils as ESLintUtils27 } from "@typescript-eslint/utils";
|
|
4400
|
-
import { AST_NODE_TYPES as
|
|
4609
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES18 } from "@typescript-eslint/utils";
|
|
4401
4610
|
function isAnyAnnotation(node) {
|
|
4402
|
-
return node.type ===
|
|
4611
|
+
return node.type === AST_NODE_TYPES18.TSAnyKeyword;
|
|
4403
4612
|
}
|
|
4404
4613
|
function isConstAssertion(typeAnnotation) {
|
|
4405
|
-
return typeAnnotation.type ===
|
|
4614
|
+
return typeAnnotation.type === AST_NODE_TYPES18.TSTypeReference && typeAnnotation.typeName.type === AST_NODE_TYPES18.Identifier && typeAnnotation.typeName.name === "const";
|
|
4406
4615
|
}
|
|
4407
4616
|
var no_unsafe_cast_default = ESLintUtils27.RuleCreator(
|
|
4408
4617
|
(name) => `https://github.com/sarj-ai/linting/blob/main/packages/typescript/src/rules/${name}.ts`
|
|
@@ -4421,7 +4630,7 @@ var no_unsafe_cast_default = ESLintUtils27.RuleCreator(
|
|
|
4421
4630
|
},
|
|
4422
4631
|
defaultOptions: [],
|
|
4423
4632
|
create(context) {
|
|
4424
|
-
if (isTestFile(context.filename)) {
|
|
4633
|
+
if (isTestFile(context.filename) || isGeneratedFile(context.filename, context.sourceCode.text)) {
|
|
4425
4634
|
return {};
|
|
4426
4635
|
}
|
|
4427
4636
|
function checkAssertion(node) {
|
|
@@ -4433,7 +4642,7 @@ var no_unsafe_cast_default = ESLintUtils27.RuleCreator(
|
|
|
4433
4642
|
return;
|
|
4434
4643
|
}
|
|
4435
4644
|
const inner = node.expression;
|
|
4436
|
-
if (inner.type ===
|
|
4645
|
+
if (inner.type === AST_NODE_TYPES18.TSAsExpression || inner.type === AST_NODE_TYPES18.TSTypeAssertion) {
|
|
4437
4646
|
context.report({ node, messageId: "doubleCast" });
|
|
4438
4647
|
}
|
|
4439
4648
|
}
|
|
@@ -4447,7 +4656,7 @@ var no_unsafe_cast_default = ESLintUtils27.RuleCreator(
|
|
|
4447
4656
|
// src/rules/prefer-string-literal-union.ts
|
|
4448
4657
|
import {
|
|
4449
4658
|
ESLintUtils as ESLintUtils28,
|
|
4450
|
-
AST_NODE_TYPES as
|
|
4659
|
+
AST_NODE_TYPES as AST_NODE_TYPES19
|
|
4451
4660
|
} from "@typescript-eslint/utils";
|
|
4452
4661
|
import * as ts from "typescript";
|
|
4453
4662
|
var CHOICE_TOKENS = /* @__PURE__ */ new Set([
|
|
@@ -4491,19 +4700,19 @@ function isChoiceLikeName(name) {
|
|
|
4491
4700
|
return CHOICE_TOKENS.has(lastWord(name));
|
|
4492
4701
|
}
|
|
4493
4702
|
function keyName(key) {
|
|
4494
|
-
if (key.type ===
|
|
4703
|
+
if (key.type === AST_NODE_TYPES19.Identifier) {
|
|
4495
4704
|
return key.name;
|
|
4496
4705
|
}
|
|
4497
|
-
if (key.type ===
|
|
4706
|
+
if (key.type === AST_NODE_TYPES19.Literal && typeof key.value === "string") {
|
|
4498
4707
|
return key.value;
|
|
4499
4708
|
}
|
|
4500
4709
|
return null;
|
|
4501
4710
|
}
|
|
4502
4711
|
function isStringLiteralMember(t) {
|
|
4503
|
-
return t.type ===
|
|
4712
|
+
return t.type === AST_NODE_TYPES19.TSLiteralType && t.literal.type === AST_NODE_TYPES19.Literal && typeof t.literal.value === "string";
|
|
4504
4713
|
}
|
|
4505
4714
|
function isStringLiteralUnion(node) {
|
|
4506
|
-
if (node?.type !==
|
|
4715
|
+
if (node?.type !== AST_NODE_TYPES19.TSUnionType) {
|
|
4507
4716
|
return false;
|
|
4508
4717
|
}
|
|
4509
4718
|
return node.types.filter(isStringLiteralMember).length >= MIN_CLUSTER_SIZE;
|
|
@@ -4532,12 +4741,12 @@ function bindingSourceExpression(decl) {
|
|
|
4532
4741
|
return ts.isForOfStatement(node) ? node.expression : node.initializer;
|
|
4533
4742
|
}
|
|
4534
4743
|
function refKey(node) {
|
|
4535
|
-
if (node.type ===
|
|
4744
|
+
if (node.type === AST_NODE_TYPES19.Identifier) {
|
|
4536
4745
|
return node.name;
|
|
4537
4746
|
}
|
|
4538
|
-
if (node.type ===
|
|
4747
|
+
if (node.type === AST_NODE_TYPES19.MemberExpression && !node.computed) {
|
|
4539
4748
|
const inner = refKey(node.object);
|
|
4540
|
-
if (inner === null || node.property.type !==
|
|
4749
|
+
if (inner === null || node.property.type !== AST_NODE_TYPES19.Identifier) {
|
|
4541
4750
|
return null;
|
|
4542
4751
|
}
|
|
4543
4752
|
return `${inner}.${node.property.name}`;
|
|
@@ -4545,7 +4754,7 @@ function refKey(node) {
|
|
|
4545
4754
|
return null;
|
|
4546
4755
|
}
|
|
4547
4756
|
function strLiteral(node) {
|
|
4548
|
-
if (node.type ===
|
|
4757
|
+
if (node.type === AST_NODE_TYPES19.Literal && typeof node.value === "string") {
|
|
4549
4758
|
return node.value;
|
|
4550
4759
|
}
|
|
4551
4760
|
return null;
|
|
@@ -4700,7 +4909,7 @@ var prefer_string_literal_union_default = ESLintUtils28.RuleCreator(
|
|
|
4700
4909
|
containersWithUnion.add(container);
|
|
4701
4910
|
return;
|
|
4702
4911
|
}
|
|
4703
|
-
if (typeNode?.type !==
|
|
4912
|
+
if (typeNode?.type !== AST_NODE_TYPES19.TSStringKeyword) {
|
|
4704
4913
|
return;
|
|
4705
4914
|
}
|
|
4706
4915
|
const name = keyName(key);
|
|
@@ -4788,10 +4997,10 @@ var prefer_string_literal_union_default = ESLintUtils28.RuleCreator(
|
|
|
4788
4997
|
}
|
|
4789
4998
|
};
|
|
4790
4999
|
function refKeyText(node) {
|
|
4791
|
-
if (node.type ===
|
|
5000
|
+
if (node.type === AST_NODE_TYPES19.BinaryExpression) {
|
|
4792
5001
|
return refKey(node.left) ?? refKey(node.right) ?? "value";
|
|
4793
5002
|
}
|
|
4794
|
-
if (node.type ===
|
|
5003
|
+
if (node.type === AST_NODE_TYPES19.SwitchStatement) {
|
|
4795
5004
|
return refKey(node.discriminant) ?? "value";
|
|
4796
5005
|
}
|
|
4797
5006
|
return "value";
|
|
@@ -4800,7 +5009,7 @@ var prefer_string_literal_union_default = ESLintUtils28.RuleCreator(
|
|
|
4800
5009
|
});
|
|
4801
5010
|
|
|
4802
5011
|
// src/rules/single-public-export.ts
|
|
4803
|
-
import { ESLintUtils as ESLintUtils29, AST_NODE_TYPES as
|
|
5012
|
+
import { ESLintUtils as ESLintUtils29, AST_NODE_TYPES as AST_NODE_TYPES20 } from "@typescript-eslint/utils";
|
|
4804
5013
|
var JUNK_DRAWER_STEMS = /* @__PURE__ */ new Set([
|
|
4805
5014
|
"util",
|
|
4806
5015
|
"utils",
|
|
@@ -4834,12 +5043,12 @@ var kebabCase2 = (name) => {
|
|
|
4834
5043
|
}
|
|
4835
5044
|
return normalized.replace(CAMEL_BOUNDARY_RE, "-").toLowerCase();
|
|
4836
5045
|
};
|
|
4837
|
-
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);
|
|
4838
5047
|
var functionConstName = (decl) => {
|
|
4839
5048
|
if (decl.declarations.length !== 1) return null;
|
|
4840
5049
|
const [declarator] = decl.declarations;
|
|
4841
5050
|
if (declarator === void 0) return null;
|
|
4842
|
-
if (declarator.id.type !==
|
|
5051
|
+
if (declarator.id.type !== AST_NODE_TYPES20.Identifier) return null;
|
|
4843
5052
|
if (!isFunctionExpression(declarator.init)) return null;
|
|
4844
5053
|
return declarator.id.name;
|
|
4845
5054
|
};
|
|
@@ -4853,20 +5062,20 @@ var summarizeExports = (body) => {
|
|
|
4853
5062
|
};
|
|
4854
5063
|
for (const statement of body) {
|
|
4855
5064
|
switch (statement.type) {
|
|
4856
|
-
case
|
|
5065
|
+
case AST_NODE_TYPES20.ExportAllDeclaration:
|
|
4857
5066
|
hasReExport = true;
|
|
4858
5067
|
break;
|
|
4859
|
-
case
|
|
5068
|
+
case AST_NODE_TYPES20.ExportDefaultDeclaration: {
|
|
4860
5069
|
names += 1;
|
|
4861
5070
|
const decl = statement.declaration;
|
|
4862
|
-
if (decl.type ===
|
|
5071
|
+
if (decl.type === AST_NODE_TYPES20.FunctionDeclaration && decl.id !== null) {
|
|
4863
5072
|
candidate = { name: decl.id.name, node: statement };
|
|
4864
|
-
} else if (decl.type ===
|
|
5073
|
+
} else if (decl.type === AST_NODE_TYPES20.ClassDeclaration && decl.id !== null) {
|
|
4865
5074
|
candidate = { name: decl.id.name, node: statement };
|
|
4866
5075
|
}
|
|
4867
5076
|
break;
|
|
4868
5077
|
}
|
|
4869
|
-
case
|
|
5078
|
+
case AST_NODE_TYPES20.ExportNamedDeclaration: {
|
|
4870
5079
|
if (statement.source !== null) {
|
|
4871
5080
|
hasReExport = true;
|
|
4872
5081
|
break;
|
|
@@ -4877,15 +5086,15 @@ var summarizeExports = (body) => {
|
|
|
4877
5086
|
break;
|
|
4878
5087
|
}
|
|
4879
5088
|
switch (decl.type) {
|
|
4880
|
-
case
|
|
5089
|
+
case AST_NODE_TYPES20.FunctionDeclaration:
|
|
4881
5090
|
if (decl.id !== null) addCandidate(decl.id.name, statement);
|
|
4882
5091
|
else names += 1;
|
|
4883
5092
|
break;
|
|
4884
|
-
case
|
|
5093
|
+
case AST_NODE_TYPES20.ClassDeclaration:
|
|
4885
5094
|
if (decl.id !== null) addCandidate(decl.id.name, statement);
|
|
4886
5095
|
else names += 1;
|
|
4887
5096
|
break;
|
|
4888
|
-
case
|
|
5097
|
+
case AST_NODE_TYPES20.VariableDeclaration: {
|
|
4889
5098
|
const fnName = functionConstName(decl);
|
|
4890
5099
|
if (fnName !== null && decl.declarations.length === 1) {
|
|
4891
5100
|
addCandidate(fnName, statement);
|
|
@@ -4925,8 +5134,8 @@ var single_public_export_default = ESLintUtils29.RuleCreator(
|
|
|
4925
5134
|
if (base.endsWith(".d.ts")) return {};
|
|
4926
5135
|
if (TEST_FILE_RE.test(base)) return {};
|
|
4927
5136
|
if (isTestFile(context.filename)) return {};
|
|
4928
|
-
const
|
|
4929
|
-
if (!JUNK_DRAWER_STEMS.has(
|
|
5137
|
+
const stem2 = stemOf(base);
|
|
5138
|
+
if (!JUNK_DRAWER_STEMS.has(stem2.toLowerCase())) return {};
|
|
4930
5139
|
return {
|
|
4931
5140
|
Program(node) {
|
|
4932
5141
|
const { names, hasReExport, candidate } = summarizeExports(node.body);
|
|
@@ -4934,11 +5143,11 @@ var single_public_export_default = ESLintUtils29.RuleCreator(
|
|
|
4934
5143
|
if (names !== 1 || candidate === null) return;
|
|
4935
5144
|
if (CONVENTIONAL_BUCKET_EXPORTS.has(candidate.name)) return;
|
|
4936
5145
|
const expected = kebabCase2(candidate.name);
|
|
4937
|
-
if (
|
|
5146
|
+
if (stem2 === expected) return;
|
|
4938
5147
|
context.report({
|
|
4939
5148
|
node: candidate.node,
|
|
4940
5149
|
messageId: "renameJunkDrawer",
|
|
4941
|
-
data: { stem, name: candidate.name, expected }
|
|
5150
|
+
data: { stem: stem2, name: candidate.name, expected }
|
|
4942
5151
|
});
|
|
4943
5152
|
}
|
|
4944
5153
|
};
|
|
@@ -4949,7 +5158,7 @@ var single_public_export_default = ESLintUtils29.RuleCreator(
|
|
|
4949
5158
|
import { ESLintUtils as ESLintUtils30 } from "@typescript-eslint/utils";
|
|
4950
5159
|
|
|
4951
5160
|
// src/rules/_sql.ts
|
|
4952
|
-
import { AST_NODE_TYPES as
|
|
5161
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES21 } from "@typescript-eslint/utils";
|
|
4953
5162
|
function stripSqlNoise(text) {
|
|
4954
5163
|
const out = [...text];
|
|
4955
5164
|
const n = text.length;
|
|
@@ -5010,13 +5219,13 @@ function stripSqlNoise(text) {
|
|
|
5010
5219
|
var SUBSTITUTION_MARKER = "?";
|
|
5011
5220
|
function sqlTextOf(node) {
|
|
5012
5221
|
switch (node.type) {
|
|
5013
|
-
case
|
|
5222
|
+
case AST_NODE_TYPES21.Literal:
|
|
5014
5223
|
return typeof node.value === "string" ? node.value : null;
|
|
5015
|
-
case
|
|
5224
|
+
case AST_NODE_TYPES21.TemplateLiteral:
|
|
5016
5225
|
return node.quasis.map((q) => q.value.cooked ?? q.value.raw).join(SUBSTITUTION_MARKER);
|
|
5017
|
-
case
|
|
5226
|
+
case AST_NODE_TYPES21.TaggedTemplateExpression:
|
|
5018
5227
|
return sqlTextOf(node.quasi);
|
|
5019
|
-
case
|
|
5228
|
+
case AST_NODE_TYPES21.BinaryExpression: {
|
|
5020
5229
|
if (node.operator !== "+") {
|
|
5021
5230
|
return null;
|
|
5022
5231
|
}
|
|
@@ -5024,7 +5233,7 @@ function sqlTextOf(node) {
|
|
|
5024
5233
|
const right = sqlTextOf(node.right);
|
|
5025
5234
|
return left !== null && right !== null ? left + right : null;
|
|
5026
5235
|
}
|
|
5027
|
-
case
|
|
5236
|
+
case AST_NODE_TYPES21.ArrayExpression: {
|
|
5028
5237
|
const parts = [];
|
|
5029
5238
|
for (const element of node.elements) {
|
|
5030
5239
|
if (element === null) {
|
|
@@ -5044,7 +5253,7 @@ function sqlTextOf(node) {
|
|
|
5044
5253
|
}
|
|
5045
5254
|
function isJoinedFragmentArray(node) {
|
|
5046
5255
|
const parent = node.parent;
|
|
5047
|
-
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;
|
|
5048
5257
|
}
|
|
5049
5258
|
function markConsumed(node, consumed) {
|
|
5050
5259
|
consumed.add(node);
|
|
@@ -5123,15 +5332,15 @@ var no_offset_pagination_default = ESLintUtils30.RuleCreator(
|
|
|
5123
5332
|
});
|
|
5124
5333
|
|
|
5125
5334
|
// src/rules/no-positional-tuple-return.ts
|
|
5126
|
-
import { AST_NODE_TYPES as
|
|
5335
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES22, ESLintUtils as ESLintUtils31 } from "@typescript-eslint/utils";
|
|
5127
5336
|
var MIN_ELEMENTS = 2;
|
|
5128
5337
|
var ACCESSOR_PAIR_LENGTH = 2;
|
|
5129
5338
|
var AWAITABLE_TYPES = /* @__PURE__ */ new Set(["Promise", "PromiseLike", "Awaited"]);
|
|
5130
5339
|
function tupleReturnType(node) {
|
|
5131
|
-
if (node.type ===
|
|
5340
|
+
if (node.type === AST_NODE_TYPES22.TSTupleType) {
|
|
5132
5341
|
return node;
|
|
5133
5342
|
}
|
|
5134
|
-
if (node.type ===
|
|
5343
|
+
if (node.type === AST_NODE_TYPES22.TSTypeReference && node.typeName.type === AST_NODE_TYPES22.Identifier && AWAITABLE_TYPES.has(node.typeName.name)) {
|
|
5135
5344
|
const argument = node.typeArguments?.params[0];
|
|
5136
5345
|
return argument === void 0 ? null : tupleReturnType(argument);
|
|
5137
5346
|
}
|
|
@@ -5145,30 +5354,30 @@ function isPermittedTuple(tuple, sourceCode) {
|
|
|
5145
5354
|
if (elements.length < MIN_ELEMENTS) {
|
|
5146
5355
|
return true;
|
|
5147
5356
|
}
|
|
5148
|
-
if (elements.some((element) => element.type ===
|
|
5357
|
+
if (elements.some((element) => element.type === AST_NODE_TYPES22.TSRestType)) {
|
|
5149
5358
|
return true;
|
|
5150
5359
|
}
|
|
5151
|
-
if (elements.some((element) => element.type ===
|
|
5360
|
+
if (elements.some((element) => element.type === AST_NODE_TYPES22.TSNamedTupleMember)) {
|
|
5152
5361
|
return true;
|
|
5153
5362
|
}
|
|
5154
|
-
if (elements[0]?.type ===
|
|
5363
|
+
if (elements[0]?.type === AST_NODE_TYPES22.TSLiteralType) {
|
|
5155
5364
|
return true;
|
|
5156
5365
|
}
|
|
5157
|
-
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)) {
|
|
5158
5367
|
return true;
|
|
5159
5368
|
}
|
|
5160
5369
|
const texts = new Set(elements.map((element) => normalizedText(sourceCode, element)));
|
|
5161
5370
|
return texts.size === 1;
|
|
5162
5371
|
}
|
|
5163
5372
|
function functionName(node) {
|
|
5164
|
-
if (node.type ===
|
|
5373
|
+
if (node.type === AST_NODE_TYPES22.FunctionDeclaration) {
|
|
5165
5374
|
return node.id?.name ?? null;
|
|
5166
5375
|
}
|
|
5167
5376
|
const parent = node.parent;
|
|
5168
|
-
if (parent?.type ===
|
|
5377
|
+
if (parent?.type === AST_NODE_TYPES22.VariableDeclarator && parent.id.type === AST_NODE_TYPES22.Identifier) {
|
|
5169
5378
|
return parent.id.name;
|
|
5170
5379
|
}
|
|
5171
|
-
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) {
|
|
5172
5381
|
return parent.key.name;
|
|
5173
5382
|
}
|
|
5174
5383
|
return null;
|
|
@@ -5176,7 +5385,7 @@ function functionName(node) {
|
|
|
5176
5385
|
function isInlineExported(node) {
|
|
5177
5386
|
for (let current = node; current != null; current = current.parent) {
|
|
5178
5387
|
const parent = current.parent;
|
|
5179
|
-
if (parent?.type ===
|
|
5388
|
+
if (parent?.type === AST_NODE_TYPES22.ExportNamedDeclaration || parent?.type === AST_NODE_TYPES22.ExportDefaultDeclaration) {
|
|
5180
5389
|
return true;
|
|
5181
5390
|
}
|
|
5182
5391
|
}
|
|
@@ -5185,18 +5394,18 @@ function isInlineExported(node) {
|
|
|
5185
5394
|
function moduleScopeBindingName(node) {
|
|
5186
5395
|
let current = node;
|
|
5187
5396
|
let child = node;
|
|
5188
|
-
while (current.parent != null && current.parent.type !==
|
|
5397
|
+
while (current.parent != null && current.parent.type !== AST_NODE_TYPES22.Program) {
|
|
5189
5398
|
child = current;
|
|
5190
5399
|
current = current.parent;
|
|
5191
5400
|
}
|
|
5192
|
-
if (current.parent?.type !==
|
|
5401
|
+
if (current.parent?.type !== AST_NODE_TYPES22.Program) {
|
|
5193
5402
|
return null;
|
|
5194
5403
|
}
|
|
5195
|
-
if (current.type ===
|
|
5404
|
+
if (current.type === AST_NODE_TYPES22.FunctionDeclaration || current.type === AST_NODE_TYPES22.ClassDeclaration) {
|
|
5196
5405
|
return current.id?.name ?? null;
|
|
5197
5406
|
}
|
|
5198
|
-
if (current.type ===
|
|
5199
|
-
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) {
|
|
5200
5409
|
return null;
|
|
5201
5410
|
}
|
|
5202
5411
|
return child.id.name;
|
|
@@ -5206,19 +5415,19 @@ function moduleScopeBindingName(node) {
|
|
|
5206
5415
|
function specifierExportedNames(program) {
|
|
5207
5416
|
const names = /* @__PURE__ */ new Set();
|
|
5208
5417
|
for (const statement of program.body) {
|
|
5209
|
-
if (statement.type ===
|
|
5418
|
+
if (statement.type === AST_NODE_TYPES22.ExportNamedDeclaration && statement.declaration == null && statement.source == null && statement.exportKind !== "type") {
|
|
5210
5419
|
for (const specifier of statement.specifiers) {
|
|
5211
|
-
if (specifier.exportKind !== "type" && specifier.local.type ===
|
|
5420
|
+
if (specifier.exportKind !== "type" && specifier.local.type === AST_NODE_TYPES22.Identifier) {
|
|
5212
5421
|
names.add(specifier.local.name);
|
|
5213
5422
|
}
|
|
5214
5423
|
}
|
|
5215
5424
|
continue;
|
|
5216
5425
|
}
|
|
5217
|
-
if (statement.type ===
|
|
5426
|
+
if (statement.type === AST_NODE_TYPES22.ExportDefaultDeclaration && statement.declaration.type === AST_NODE_TYPES22.Identifier) {
|
|
5218
5427
|
names.add(statement.declaration.name);
|
|
5219
5428
|
continue;
|
|
5220
5429
|
}
|
|
5221
|
-
if (statement.type ===
|
|
5430
|
+
if (statement.type === AST_NODE_TYPES22.TSExportAssignment && statement.expression.type === AST_NODE_TYPES22.Identifier) {
|
|
5222
5431
|
names.add(statement.expression.name);
|
|
5223
5432
|
}
|
|
5224
5433
|
}
|
|
@@ -5282,7 +5491,7 @@ var no_positional_tuple_return_default = ESLintUtils31.RuleCreator(
|
|
|
5282
5491
|
});
|
|
5283
5492
|
|
|
5284
5493
|
// src/rules/no-repeated-string-literal.ts
|
|
5285
|
-
import { AST_NODE_TYPES as
|
|
5494
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES23, ESLintUtils as ESLintUtils32 } from "@typescript-eslint/utils";
|
|
5286
5495
|
var MIN_LENGTH = 40;
|
|
5287
5496
|
var MIN_OCCURRENCES = 3;
|
|
5288
5497
|
var MIN_DISTINCT_SCOPES = 2;
|
|
@@ -5290,9 +5499,9 @@ var PREVIEW_LENGTH = 40;
|
|
|
5290
5499
|
var SQL_KEYWORD_RE = /\b(SELECT|INSERT|UPDATE|DELETE|FROM|WHERE|JOIN|VALUES|ON CONFLICT|RETURNING|GROUP BY|ORDER BY)\b/;
|
|
5291
5500
|
var IDENTIFIER_RE = /^[a-z_][a-z0-9_.]*$/;
|
|
5292
5501
|
var FUNCTION_TYPES = /* @__PURE__ */ new Set([
|
|
5293
|
-
|
|
5294
|
-
|
|
5295
|
-
|
|
5502
|
+
AST_NODE_TYPES23.FunctionDeclaration,
|
|
5503
|
+
AST_NODE_TYPES23.FunctionExpression,
|
|
5504
|
+
AST_NODE_TYPES23.ArrowFunctionExpression
|
|
5296
5505
|
]);
|
|
5297
5506
|
function isStructured(value) {
|
|
5298
5507
|
return value.includes("\n") || SQL_KEYWORD_RE.test(value) || IDENTIFIER_RE.test(value);
|
|
@@ -5314,7 +5523,7 @@ function isScaffolding(node) {
|
|
|
5314
5523
|
if (parent === void 0) {
|
|
5315
5524
|
return true;
|
|
5316
5525
|
}
|
|
5317
|
-
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;
|
|
5318
5527
|
}
|
|
5319
5528
|
var no_repeated_string_literal_default = ESLintUtils32.RuleCreator(
|
|
5320
5529
|
(name) => `https://github.com/sarj-ai/standards/blob/main/packages/typescript/src/rules/${name}.ts`
|
|
@@ -5356,7 +5565,7 @@ var no_repeated_string_literal_default = ESLintUtils32.RuleCreator(
|
|
|
5356
5565
|
}
|
|
5357
5566
|
},
|
|
5358
5567
|
TemplateLiteral(node) {
|
|
5359
|
-
if (node.parent.type ===
|
|
5568
|
+
if (node.parent.type === AST_NODE_TYPES23.TaggedTemplateExpression) {
|
|
5360
5569
|
return;
|
|
5361
5570
|
}
|
|
5362
5571
|
const [only] = node.quasis;
|
|
@@ -5462,7 +5671,7 @@ var no_select_star_default = ESLintUtils33.RuleCreator(
|
|
|
5462
5671
|
});
|
|
5463
5672
|
|
|
5464
5673
|
// src/rules/no-sleep-in-test-body.ts
|
|
5465
|
-
import { AST_NODE_TYPES as
|
|
5674
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES24, ESLintUtils as ESLintUtils34 } from "@typescript-eslint/utils";
|
|
5466
5675
|
var SLEEP_HELPERS = /* @__PURE__ */ new Set(["sleep", "delay", "wait", "pause"]);
|
|
5467
5676
|
var TEST_CALLERS = /* @__PURE__ */ new Set([
|
|
5468
5677
|
"it",
|
|
@@ -5471,34 +5680,34 @@ var TEST_CALLERS = /* @__PURE__ */ new Set([
|
|
|
5471
5680
|
"afterEach"
|
|
5472
5681
|
]);
|
|
5473
5682
|
var FUNCTION_TYPES2 = /* @__PURE__ */ new Set([
|
|
5474
|
-
|
|
5475
|
-
|
|
5476
|
-
|
|
5683
|
+
AST_NODE_TYPES24.FunctionDeclaration,
|
|
5684
|
+
AST_NODE_TYPES24.FunctionExpression,
|
|
5685
|
+
AST_NODE_TYPES24.ArrowFunctionExpression
|
|
5477
5686
|
]);
|
|
5478
5687
|
function isNonzeroNumericLiteral(node) {
|
|
5479
|
-
return node?.type ===
|
|
5688
|
+
return node?.type === AST_NODE_TYPES24.Literal && typeof node.value === "number" && node.value !== 0;
|
|
5480
5689
|
}
|
|
5481
5690
|
function isTimedSetTimeout(node) {
|
|
5482
|
-
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]);
|
|
5483
5692
|
}
|
|
5484
5693
|
function isPromiseSleep(node) {
|
|
5485
|
-
if (node.callee.type !==
|
|
5694
|
+
if (node.callee.type !== AST_NODE_TYPES24.Identifier || node.callee.name !== "Promise") {
|
|
5486
5695
|
return false;
|
|
5487
5696
|
}
|
|
5488
5697
|
const executor = node.arguments[0];
|
|
5489
|
-
if (executor?.type !==
|
|
5698
|
+
if (executor?.type !== AST_NODE_TYPES24.ArrowFunctionExpression && executor?.type !== AST_NODE_TYPES24.FunctionExpression) {
|
|
5490
5699
|
return false;
|
|
5491
5700
|
}
|
|
5492
5701
|
const body = executor.body;
|
|
5493
|
-
if (body.type !==
|
|
5702
|
+
if (body.type !== AST_NODE_TYPES24.BlockStatement) {
|
|
5494
5703
|
return isTimedSetTimeout(body);
|
|
5495
5704
|
}
|
|
5496
5705
|
return body.body.some(
|
|
5497
|
-
(stmt) => stmt.type ===
|
|
5706
|
+
(stmt) => stmt.type === AST_NODE_TYPES24.ExpressionStatement && isTimedSetTimeout(stmt.expression)
|
|
5498
5707
|
);
|
|
5499
5708
|
}
|
|
5500
5709
|
function isHelperSleep(node) {
|
|
5501
|
-
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]);
|
|
5502
5711
|
}
|
|
5503
5712
|
function nearestEnclosingFunction(node) {
|
|
5504
5713
|
for (let current = node.parent; current != null; current = current.parent) {
|
|
@@ -5506,7 +5715,7 @@ function nearestEnclosingFunction(node) {
|
|
|
5506
5715
|
continue;
|
|
5507
5716
|
}
|
|
5508
5717
|
const grandparent = current.parent;
|
|
5509
|
-
const isPromiseExecutor = grandparent?.type ===
|
|
5718
|
+
const isPromiseExecutor = grandparent?.type === AST_NODE_TYPES24.NewExpression && isPromiseSleep(grandparent);
|
|
5510
5719
|
if (!isPromiseExecutor) {
|
|
5511
5720
|
return current;
|
|
5512
5721
|
}
|
|
@@ -5514,23 +5723,23 @@ function nearestEnclosingFunction(node) {
|
|
|
5514
5723
|
return null;
|
|
5515
5724
|
}
|
|
5516
5725
|
function testCallerName(callee) {
|
|
5517
|
-
if (callee.type ===
|
|
5726
|
+
if (callee.type === AST_NODE_TYPES24.Identifier) {
|
|
5518
5727
|
return callee.name;
|
|
5519
5728
|
}
|
|
5520
|
-
if (callee.type ===
|
|
5729
|
+
if (callee.type === AST_NODE_TYPES24.MemberExpression) {
|
|
5521
5730
|
return testCallerName(callee.object);
|
|
5522
5731
|
}
|
|
5523
|
-
if (callee.type ===
|
|
5732
|
+
if (callee.type === AST_NODE_TYPES24.CallExpression) {
|
|
5524
5733
|
return testCallerName(callee.callee);
|
|
5525
5734
|
}
|
|
5526
|
-
if (callee.type ===
|
|
5735
|
+
if (callee.type === AST_NODE_TYPES24.TaggedTemplateExpression) {
|
|
5527
5736
|
return testCallerName(callee.tag);
|
|
5528
5737
|
}
|
|
5529
5738
|
return null;
|
|
5530
5739
|
}
|
|
5531
5740
|
function isTestBody(fn) {
|
|
5532
5741
|
const call = fn.parent;
|
|
5533
|
-
if (call?.type !==
|
|
5742
|
+
if (call?.type !== AST_NODE_TYPES24.CallExpression || !call.arguments.some((argument) => argument === fn)) {
|
|
5534
5743
|
return false;
|
|
5535
5744
|
}
|
|
5536
5745
|
const name = testCallerName(call.callee);
|
|
@@ -5578,7 +5787,7 @@ var no_sleep_in_test_body_default = ESLintUtils34.RuleCreator(
|
|
|
5578
5787
|
});
|
|
5579
5788
|
|
|
5580
5789
|
// src/rules/prefer-constant-time-secret-compare.ts
|
|
5581
|
-
import { AST_NODE_TYPES as
|
|
5790
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES25, ESLintUtils as ESLintUtils35 } from "@typescript-eslint/utils";
|
|
5582
5791
|
var EQUALITY_OPERATORS = /* @__PURE__ */ new Set(["===", "!==", "==", "!="]);
|
|
5583
5792
|
var SENTINEL_IDENTIFIERS = /* @__PURE__ */ new Set(["undefined", "NaN"]);
|
|
5584
5793
|
var SENTINEL_WORDS = /(^|_)(SENTINEL|EMPTY|NONE|NULL|UNSET|MISSING|PLACEHOLDER|DUMMY|FAKE|EXAMPLE)(_|$)/;
|
|
@@ -5591,36 +5800,36 @@ function isConstantReference(identifier) {
|
|
|
5591
5800
|
}
|
|
5592
5801
|
function isExcludedOperand(node) {
|
|
5593
5802
|
switch (node.type) {
|
|
5594
|
-
case
|
|
5803
|
+
case AST_NODE_TYPES25.Literal:
|
|
5595
5804
|
return true;
|
|
5596
|
-
case
|
|
5805
|
+
case AST_NODE_TYPES25.TemplateLiteral:
|
|
5597
5806
|
return node.expressions.length === 0;
|
|
5598
|
-
case
|
|
5807
|
+
case AST_NODE_TYPES25.Identifier:
|
|
5599
5808
|
return SENTINEL_IDENTIFIERS.has(node.name) || SENTINEL_PREFIX_RE.test(node.name) || isConstantReference(node.name);
|
|
5600
|
-
case
|
|
5601
|
-
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));
|
|
5602
5811
|
default:
|
|
5603
5812
|
return false;
|
|
5604
5813
|
}
|
|
5605
5814
|
}
|
|
5606
5815
|
function operandName(node) {
|
|
5607
|
-
if (node.type ===
|
|
5816
|
+
if (node.type === AST_NODE_TYPES25.Identifier) {
|
|
5608
5817
|
return node.name;
|
|
5609
5818
|
}
|
|
5610
|
-
if (node.type ===
|
|
5819
|
+
if (node.type === AST_NODE_TYPES25.MemberExpression && !node.computed && node.property.type === AST_NODE_TYPES25.Identifier) {
|
|
5611
5820
|
return node.property.name;
|
|
5612
5821
|
}
|
|
5613
5822
|
return null;
|
|
5614
5823
|
}
|
|
5615
5824
|
function isSecretOperand(node) {
|
|
5616
|
-
if (node.type ===
|
|
5825
|
+
if (node.type === AST_NODE_TYPES25.TemplateLiteral) {
|
|
5617
5826
|
return node.expressions.some((expression) => isSecretOperand(expression));
|
|
5618
5827
|
}
|
|
5619
5828
|
const name = operandName(node);
|
|
5620
5829
|
return name !== null && isAuthSecretName(name);
|
|
5621
5830
|
}
|
|
5622
5831
|
function secretNameOf(node) {
|
|
5623
|
-
if (node.type ===
|
|
5832
|
+
if (node.type === AST_NODE_TYPES25.TemplateLiteral) {
|
|
5624
5833
|
for (const expression of node.expressions) {
|
|
5625
5834
|
const nested = secretNameOf(expression);
|
|
5626
5835
|
if (nested !== null) {
|
|
@@ -5707,17 +5916,17 @@ var store_insert_requires_on_conflict_default = ESLintUtils36.RuleCreator(
|
|
|
5707
5916
|
});
|
|
5708
5917
|
|
|
5709
5918
|
// src/rules/no-dynamic-sql.ts
|
|
5710
|
-
import { AST_NODE_TYPES as
|
|
5919
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES26, ESLintUtils as ESLintUtils37 } from "@typescript-eslint/utils";
|
|
5711
5920
|
var DEFAULT_METHODS = ["prepare", "exec", "query"];
|
|
5712
5921
|
var CONSTANT_CASE_RE = /^[A-Z][A-Z0-9_]*$/;
|
|
5713
5922
|
function isStaticFragment(expression) {
|
|
5714
|
-
if (expression.type ===
|
|
5923
|
+
if (expression.type === AST_NODE_TYPES26.Identifier) {
|
|
5715
5924
|
return CONSTANT_CASE_RE.test(expression.name);
|
|
5716
5925
|
}
|
|
5717
|
-
if (expression.type ===
|
|
5926
|
+
if (expression.type === AST_NODE_TYPES26.MemberExpression && !expression.computed && expression.property.type === AST_NODE_TYPES26.Identifier) {
|
|
5718
5927
|
return CONSTANT_CASE_RE.test(expression.property.name);
|
|
5719
5928
|
}
|
|
5720
|
-
if (expression.type ===
|
|
5929
|
+
if (expression.type === AST_NODE_TYPES26.Literal) {
|
|
5721
5930
|
return typeof expression.value === "string";
|
|
5722
5931
|
}
|
|
5723
5932
|
return false;
|
|
@@ -5728,36 +5937,36 @@ function runtimeInterpolations(template) {
|
|
|
5728
5937
|
);
|
|
5729
5938
|
}
|
|
5730
5939
|
function concatOperands(node) {
|
|
5731
|
-
if (node.type ===
|
|
5940
|
+
if (node.type === AST_NODE_TYPES26.BinaryExpression && node.operator === "+") {
|
|
5732
5941
|
return [...concatOperands(node.left), ...concatOperands(node.right)];
|
|
5733
5942
|
}
|
|
5734
5943
|
return [node];
|
|
5735
5944
|
}
|
|
5736
5945
|
function runtimeConcatOperands(node) {
|
|
5737
|
-
if (node.type !==
|
|
5946
|
+
if (node.type !== AST_NODE_TYPES26.BinaryExpression || node.operator !== "+") {
|
|
5738
5947
|
return [];
|
|
5739
5948
|
}
|
|
5740
5949
|
const operands = concatOperands(node);
|
|
5741
5950
|
const hasStringLiteral = operands.some(
|
|
5742
|
-
(operand) => operand.type ===
|
|
5951
|
+
(operand) => operand.type === AST_NODE_TYPES26.Literal && typeof operand.value === "string"
|
|
5743
5952
|
);
|
|
5744
5953
|
if (!hasStringLiteral) {
|
|
5745
5954
|
return [];
|
|
5746
5955
|
}
|
|
5747
5956
|
return operands.filter(
|
|
5748
|
-
(operand) => operand.type !==
|
|
5957
|
+
(operand) => operand.type !== AST_NODE_TYPES26.Literal && !isStaticFragment(operand)
|
|
5749
5958
|
);
|
|
5750
5959
|
}
|
|
5751
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;
|
|
5752
5961
|
var RUNTIME_MARKER = " ? ";
|
|
5753
5962
|
function staticStatementText(node) {
|
|
5754
|
-
if (node.type ===
|
|
5963
|
+
if (node.type === AST_NODE_TYPES26.TemplateLiteral) {
|
|
5755
5964
|
return node.quasis.map((quasi) => quasi.value.cooked ?? quasi.value.raw).join(RUNTIME_MARKER);
|
|
5756
5965
|
}
|
|
5757
|
-
if (node.type ===
|
|
5966
|
+
if (node.type === AST_NODE_TYPES26.Literal) {
|
|
5758
5967
|
return typeof node.value === "string" ? node.value : RUNTIME_MARKER;
|
|
5759
5968
|
}
|
|
5760
|
-
if (node.type ===
|
|
5969
|
+
if (node.type === AST_NODE_TYPES26.BinaryExpression && node.operator === "+") {
|
|
5761
5970
|
return staticStatementText(node.left) + staticStatementText(node.right);
|
|
5762
5971
|
}
|
|
5763
5972
|
return RUNTIME_MARKER;
|
|
@@ -5767,7 +5976,7 @@ function looksLikeSql(node) {
|
|
|
5767
5976
|
}
|
|
5768
5977
|
function statementMethodName(node, methods) {
|
|
5769
5978
|
const callee = node.callee;
|
|
5770
|
-
if (callee.type !==
|
|
5979
|
+
if (callee.type !== AST_NODE_TYPES26.MemberExpression || callee.computed || callee.property.type !== AST_NODE_TYPES26.Identifier) {
|
|
5771
5980
|
return null;
|
|
5772
5981
|
}
|
|
5773
5982
|
const name = callee.property.name;
|
|
@@ -5812,7 +6021,7 @@ var no_dynamic_sql_default = ESLintUtils37.RuleCreator(
|
|
|
5812
6021
|
if (statement === void 0 || !looksLikeSql(statement)) {
|
|
5813
6022
|
return;
|
|
5814
6023
|
}
|
|
5815
|
-
const offenders = statement.type ===
|
|
6024
|
+
const offenders = statement.type === AST_NODE_TYPES26.TemplateLiteral ? runtimeInterpolations(statement) : runtimeConcatOperands(statement);
|
|
5816
6025
|
for (const offender of offenders) {
|
|
5817
6026
|
context.report({
|
|
5818
6027
|
node: offender,
|
|
@@ -5938,7 +6147,7 @@ var no_raw_fetch_outside_clients_default = ESLintUtils38.RuleCreator(
|
|
|
5938
6147
|
});
|
|
5939
6148
|
|
|
5940
6149
|
// src/rules/no-storage-in-stateless-modules.ts
|
|
5941
|
-
import { AST_NODE_TYPES as
|
|
6150
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES27, ESLintUtils as ESLintUtils39 } from "@typescript-eslint/utils";
|
|
5942
6151
|
var DEFAULT_METHODS2 = [
|
|
5943
6152
|
"prepare",
|
|
5944
6153
|
"put",
|
|
@@ -5957,7 +6166,7 @@ function compile2(patterns) {
|
|
|
5957
6166
|
}
|
|
5958
6167
|
function storageMethodName(node, methods) {
|
|
5959
6168
|
const callee = node.callee;
|
|
5960
|
-
if (callee.type !==
|
|
6169
|
+
if (callee.type !== AST_NODE_TYPES27.MemberExpression || callee.computed || callee.property.type !== AST_NODE_TYPES27.Identifier) {
|
|
5961
6170
|
return null;
|
|
5962
6171
|
}
|
|
5963
6172
|
const name = callee.property.name;
|
|
@@ -6029,7 +6238,7 @@ var no_storage_in_stateless_modules_default = ESLintUtils39.RuleCreator(
|
|
|
6029
6238
|
// src/rules/no-zod-native-enum.ts
|
|
6030
6239
|
import {
|
|
6031
6240
|
ESLintUtils as ESLintUtils40,
|
|
6032
|
-
AST_NODE_TYPES as
|
|
6241
|
+
AST_NODE_TYPES as AST_NODE_TYPES28
|
|
6033
6242
|
} from "@typescript-eslint/utils";
|
|
6034
6243
|
import * as ts2 from "typescript";
|
|
6035
6244
|
var IGNORE_PATTERNS2 = [
|
|
@@ -6048,7 +6257,7 @@ function isZodModule(source) {
|
|
|
6048
6257
|
return /(^|[/@-])zod([/-]|$)/.test(source);
|
|
6049
6258
|
}
|
|
6050
6259
|
function unwrap3(node) {
|
|
6051
|
-
if (node.type ===
|
|
6260
|
+
if (node.type === AST_NODE_TYPES28.TSAsExpression || node.type === AST_NODE_TYPES28.TSSatisfiesExpression) {
|
|
6052
6261
|
return unwrap3(node.expression);
|
|
6053
6262
|
}
|
|
6054
6263
|
return node;
|
|
@@ -6056,14 +6265,14 @@ function unwrap3(node) {
|
|
|
6056
6265
|
function stringValueTexts(node, sourceCode) {
|
|
6057
6266
|
const texts = [];
|
|
6058
6267
|
for (const prop of node.properties) {
|
|
6059
|
-
if (prop.type !==
|
|
6268
|
+
if (prop.type !== AST_NODE_TYPES28.Property) {
|
|
6060
6269
|
return null;
|
|
6061
6270
|
}
|
|
6062
6271
|
if (prop.computed || prop.shorthand || prop.method || prop.kind !== "init") {
|
|
6063
6272
|
return null;
|
|
6064
6273
|
}
|
|
6065
6274
|
const value = prop.value;
|
|
6066
|
-
if (value.type !==
|
|
6275
|
+
if (value.type !== AST_NODE_TYPES28.Literal || typeof value.value !== "string") {
|
|
6067
6276
|
return null;
|
|
6068
6277
|
}
|
|
6069
6278
|
const text = sourceCode.getText(value);
|
|
@@ -6079,7 +6288,7 @@ function resolvesToLocalEnum(node, scope) {
|
|
|
6079
6288
|
const variable = current.variables.find((v) => v.name === node.name);
|
|
6080
6289
|
if (variable !== void 0) {
|
|
6081
6290
|
return variable.defs.some(
|
|
6082
|
-
(def) => def.node.type ===
|
|
6291
|
+
(def) => def.node.type === AST_NODE_TYPES28.TSEnumDeclaration
|
|
6083
6292
|
);
|
|
6084
6293
|
}
|
|
6085
6294
|
current = current.upper;
|
|
@@ -6133,25 +6342,25 @@ var no_zod_native_enum_default = ESLintUtils40.RuleCreator(
|
|
|
6133
6342
|
const zodImportedNames = /* @__PURE__ */ new Map();
|
|
6134
6343
|
function isZodMemberCall(node, api) {
|
|
6135
6344
|
const callee = node.callee;
|
|
6136
|
-
if (callee.type ===
|
|
6345
|
+
if (callee.type === AST_NODE_TYPES28.MemberExpression && !callee.computed && callee.property.type === AST_NODE_TYPES28.Identifier) {
|
|
6137
6346
|
return callee.property.name === api;
|
|
6138
6347
|
}
|
|
6139
|
-
if (callee.type ===
|
|
6348
|
+
if (callee.type === AST_NODE_TYPES28.Identifier) {
|
|
6140
6349
|
return zodImportedNames.get(callee.name) === api;
|
|
6141
6350
|
}
|
|
6142
6351
|
return false;
|
|
6143
6352
|
}
|
|
6144
6353
|
function buildFix(node) {
|
|
6145
6354
|
const callee = node.callee;
|
|
6146
|
-
if (callee.type !==
|
|
6355
|
+
if (callee.type !== AST_NODE_TYPES28.MemberExpression || callee.property.type !== AST_NODE_TYPES28.Identifier) {
|
|
6147
6356
|
return null;
|
|
6148
6357
|
}
|
|
6149
6358
|
const arg = node.arguments[0];
|
|
6150
|
-
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) {
|
|
6151
6360
|
return null;
|
|
6152
6361
|
}
|
|
6153
6362
|
const inner = unwrap3(arg);
|
|
6154
|
-
if (inner.type !==
|
|
6363
|
+
if (inner.type !== AST_NODE_TYPES28.ObjectExpression) {
|
|
6155
6364
|
return null;
|
|
6156
6365
|
}
|
|
6157
6366
|
const values = stringValueTexts(inner, sourceCode);
|
|
@@ -6171,7 +6380,7 @@ var no_zod_native_enum_default = ESLintUtils40.RuleCreator(
|
|
|
6171
6380
|
return;
|
|
6172
6381
|
}
|
|
6173
6382
|
for (const spec of node.specifiers) {
|
|
6174
|
-
if (spec.type ===
|
|
6383
|
+
if (spec.type === AST_NODE_TYPES28.ImportSpecifier && spec.imported.type === AST_NODE_TYPES28.Identifier) {
|
|
6175
6384
|
zodImportedNames.set(spec.local.name, spec.imported.name);
|
|
6176
6385
|
}
|
|
6177
6386
|
}
|
|
@@ -6190,7 +6399,7 @@ var no_zod_native_enum_default = ESLintUtils40.RuleCreator(
|
|
|
6190
6399
|
return;
|
|
6191
6400
|
}
|
|
6192
6401
|
const arg = node.arguments[0];
|
|
6193
|
-
if (arg === void 0 || arg.type !==
|
|
6402
|
+
if (arg === void 0 || arg.type !== AST_NODE_TYPES28.Identifier) {
|
|
6194
6403
|
return;
|
|
6195
6404
|
}
|
|
6196
6405
|
const isEnum = resolvesToLocalEnum(arg, sourceCode.getScope(arg)) || services !== null && resolvesToImportedEnum(arg, services);
|
|
@@ -6209,7 +6418,7 @@ var no_zod_native_enum_default = ESLintUtils40.RuleCreator(
|
|
|
6209
6418
|
// src/rules/prefer-module-level-constant.ts
|
|
6210
6419
|
import {
|
|
6211
6420
|
ESLintUtils as ESLintUtils41,
|
|
6212
|
-
AST_NODE_TYPES as
|
|
6421
|
+
AST_NODE_TYPES as AST_NODE_TYPES29
|
|
6213
6422
|
} from "@typescript-eslint/utils";
|
|
6214
6423
|
var DEFAULT_MIN_ELEMENTS = 3;
|
|
6215
6424
|
var MAX_LITERAL_DEPTH = 4;
|
|
@@ -6246,9 +6455,9 @@ var MUTATING_METHODS = /* @__PURE__ */ new Set([
|
|
|
6246
6455
|
"assign"
|
|
6247
6456
|
]);
|
|
6248
6457
|
var FUNCTION_TYPES3 = /* @__PURE__ */ new Set([
|
|
6249
|
-
|
|
6250
|
-
|
|
6251
|
-
|
|
6458
|
+
AST_NODE_TYPES29.FunctionDeclaration,
|
|
6459
|
+
AST_NODE_TYPES29.FunctionExpression,
|
|
6460
|
+
AST_NODE_TYPES29.ArrowFunctionExpression
|
|
6252
6461
|
]);
|
|
6253
6462
|
var COLLECTION_CONSTRUCTORS = /* @__PURE__ */ new Set(["Set", "Map"]);
|
|
6254
6463
|
function isIgnoredFile3(filename, sourceText) {
|
|
@@ -6261,13 +6470,13 @@ function isTestFile2(filename) {
|
|
|
6261
6470
|
return TEST_FILE_PATTERNS.some((re) => re.test(filename));
|
|
6262
6471
|
}
|
|
6263
6472
|
function unwrap4(node) {
|
|
6264
|
-
if (node.type ===
|
|
6473
|
+
if (node.type === AST_NODE_TYPES29.TSAsExpression || node.type === AST_NODE_TYPES29.TSSatisfiesExpression || node.type === AST_NODE_TYPES29.TSNonNullExpression) {
|
|
6265
6474
|
return unwrap4(node.expression);
|
|
6266
6475
|
}
|
|
6267
6476
|
return node;
|
|
6268
6477
|
}
|
|
6269
6478
|
function isRegexLiteral(node) {
|
|
6270
|
-
return node.type ===
|
|
6479
|
+
return node.type === AST_NODE_TYPES29.Literal && "regex" in node && node.regex !== void 0;
|
|
6271
6480
|
}
|
|
6272
6481
|
function isLiteralOnly(node, depth) {
|
|
6273
6482
|
if (depth > MAX_LITERAL_DEPTH) {
|
|
@@ -6275,29 +6484,29 @@ function isLiteralOnly(node, depth) {
|
|
|
6275
6484
|
}
|
|
6276
6485
|
const inner = unwrap4(node);
|
|
6277
6486
|
switch (inner.type) {
|
|
6278
|
-
case
|
|
6487
|
+
case AST_NODE_TYPES29.Literal: {
|
|
6279
6488
|
return true;
|
|
6280
6489
|
}
|
|
6281
|
-
case
|
|
6490
|
+
case AST_NODE_TYPES29.TemplateLiteral: {
|
|
6282
6491
|
return inner.expressions.length === 0;
|
|
6283
6492
|
}
|
|
6284
|
-
case
|
|
6285
|
-
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";
|
|
6286
6495
|
}
|
|
6287
|
-
case
|
|
6496
|
+
case AST_NODE_TYPES29.ArrayExpression: {
|
|
6288
6497
|
return inner.elements.every(
|
|
6289
|
-
(el) => el !== null && el.type !==
|
|
6498
|
+
(el) => el !== null && el.type !== AST_NODE_TYPES29.SpreadElement && isLiteralOnly(el, depth + 1)
|
|
6290
6499
|
);
|
|
6291
6500
|
}
|
|
6292
|
-
case
|
|
6501
|
+
case AST_NODE_TYPES29.ObjectExpression: {
|
|
6293
6502
|
return inner.properties.every((prop) => {
|
|
6294
|
-
if (prop.type !==
|
|
6503
|
+
if (prop.type !== AST_NODE_TYPES29.Property) {
|
|
6295
6504
|
return false;
|
|
6296
6505
|
}
|
|
6297
6506
|
if (prop.shorthand || prop.method || prop.kind !== "init") {
|
|
6298
6507
|
return false;
|
|
6299
6508
|
}
|
|
6300
|
-
if (prop.computed && prop.key.type !==
|
|
6509
|
+
if (prop.computed && prop.key.type !== AST_NODE_TYPES29.Literal) {
|
|
6301
6510
|
return false;
|
|
6302
6511
|
}
|
|
6303
6512
|
return isLiteralOnly(prop.value, depth + 1);
|
|
@@ -6310,7 +6519,7 @@ function isLiteralOnly(node, depth) {
|
|
|
6310
6519
|
}
|
|
6311
6520
|
function unwrapObjectFreeze(node) {
|
|
6312
6521
|
const inner = unwrap4(node);
|
|
6313
|
-
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) {
|
|
6314
6523
|
return unwrap4(inner.arguments[0]);
|
|
6315
6524
|
}
|
|
6316
6525
|
return inner;
|
|
@@ -6326,19 +6535,19 @@ function classify(init, checkRegex) {
|
|
|
6326
6535
|
}
|
|
6327
6536
|
return { kind: "regex", size: 1 };
|
|
6328
6537
|
}
|
|
6329
|
-
if (node.type ===
|
|
6538
|
+
if (node.type === AST_NODE_TYPES29.ArrayExpression) {
|
|
6330
6539
|
return isLiteralOnly(node, 0) ? { kind: "array", size: node.elements.length } : null;
|
|
6331
6540
|
}
|
|
6332
|
-
if (node.type ===
|
|
6541
|
+
if (node.type === AST_NODE_TYPES29.ObjectExpression) {
|
|
6333
6542
|
return isLiteralOnly(node, 0) ? { kind: "object", size: node.properties.length } : null;
|
|
6334
6543
|
}
|
|
6335
|
-
if (node.type ===
|
|
6544
|
+
if (node.type === AST_NODE_TYPES29.NewExpression && node.callee.type === AST_NODE_TYPES29.Identifier && COLLECTION_CONSTRUCTORS.has(node.callee.name)) {
|
|
6336
6545
|
const arg = node.arguments[0];
|
|
6337
|
-
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) {
|
|
6338
6547
|
return null;
|
|
6339
6548
|
}
|
|
6340
6549
|
const entries = unwrap4(arg);
|
|
6341
|
-
if (entries.type !==
|
|
6550
|
+
if (entries.type !== AST_NODE_TYPES29.ArrayExpression) {
|
|
6342
6551
|
return null;
|
|
6343
6552
|
}
|
|
6344
6553
|
return isLiteralOnly(entries, 0) ? { kind: node.callee.name === "Set" ? "Set" : "Map", size: entries.elements.length } : null;
|
|
@@ -6367,10 +6576,10 @@ var NON_RETAINING_BUILTINS = /* @__PURE__ */ new Map(
|
|
|
6367
6576
|
);
|
|
6368
6577
|
function isNonRetainingBuiltinCall(node, argument) {
|
|
6369
6578
|
const callee = node.callee;
|
|
6370
|
-
if (callee.type ===
|
|
6579
|
+
if (callee.type === AST_NODE_TYPES29.Identifier && callee.name === "structuredClone") {
|
|
6371
6580
|
return true;
|
|
6372
6581
|
}
|
|
6373
|
-
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) {
|
|
6374
6583
|
return false;
|
|
6375
6584
|
}
|
|
6376
6585
|
const members = NON_RETAINING_BUILTINS.get(callee.object.name);
|
|
@@ -6384,38 +6593,38 @@ function isNonRetainingBuiltinCall(node, argument) {
|
|
|
6384
6593
|
}
|
|
6385
6594
|
function isSafeRead(identifier) {
|
|
6386
6595
|
const parent = identifier.parent;
|
|
6387
|
-
if (parent.type ===
|
|
6596
|
+
if (parent.type === AST_NODE_TYPES29.MemberExpression) {
|
|
6388
6597
|
if (parent.object !== identifier) {
|
|
6389
6598
|
return true;
|
|
6390
6599
|
}
|
|
6391
6600
|
const grandparent = parent.parent;
|
|
6392
|
-
if (grandparent.type ===
|
|
6601
|
+
if (grandparent.type === AST_NODE_TYPES29.AssignmentExpression && grandparent.left === parent) {
|
|
6393
6602
|
return false;
|
|
6394
6603
|
}
|
|
6395
|
-
if (grandparent.type ===
|
|
6604
|
+
if (grandparent.type === AST_NODE_TYPES29.UpdateExpression) {
|
|
6396
6605
|
return false;
|
|
6397
6606
|
}
|
|
6398
|
-
if (grandparent.type ===
|
|
6607
|
+
if (grandparent.type === AST_NODE_TYPES29.UnaryExpression && grandparent.operator === "delete") {
|
|
6399
6608
|
return false;
|
|
6400
6609
|
}
|
|
6401
|
-
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) {
|
|
6402
6611
|
return false;
|
|
6403
6612
|
}
|
|
6404
6613
|
return true;
|
|
6405
6614
|
}
|
|
6406
|
-
if (parent.type ===
|
|
6615
|
+
if (parent.type === AST_NODE_TYPES29.ForOfStatement && parent.right === identifier) {
|
|
6407
6616
|
return true;
|
|
6408
6617
|
}
|
|
6409
|
-
if (parent.type ===
|
|
6618
|
+
if (parent.type === AST_NODE_TYPES29.SpreadElement) {
|
|
6410
6619
|
return true;
|
|
6411
6620
|
}
|
|
6412
|
-
if (parent.type ===
|
|
6621
|
+
if (parent.type === AST_NODE_TYPES29.BinaryExpression) {
|
|
6413
6622
|
return true;
|
|
6414
6623
|
}
|
|
6415
|
-
if (parent.type ===
|
|
6624
|
+
if (parent.type === AST_NODE_TYPES29.CallExpression && parent.arguments.includes(identifier) && isNonRetainingBuiltinCall(parent, identifier)) {
|
|
6416
6625
|
return true;
|
|
6417
6626
|
}
|
|
6418
|
-
if (parent.type ===
|
|
6627
|
+
if (parent.type === AST_NODE_TYPES29.UnaryExpression && parent.operator !== "delete") {
|
|
6419
6628
|
return true;
|
|
6420
6629
|
}
|
|
6421
6630
|
return false;
|
|
@@ -6472,7 +6681,7 @@ var prefer_module_level_constant_default = ESLintUtils41.RuleCreator(
|
|
|
6472
6681
|
if (reference.isWrite()) {
|
|
6473
6682
|
return false;
|
|
6474
6683
|
}
|
|
6475
|
-
if (reference.identifier.type !==
|
|
6684
|
+
if (reference.identifier.type !== AST_NODE_TYPES29.Identifier) {
|
|
6476
6685
|
return false;
|
|
6477
6686
|
}
|
|
6478
6687
|
if (!isSafeRead(reference.identifier)) {
|
|
@@ -6484,10 +6693,10 @@ var prefer_module_level_constant_default = ESLintUtils41.RuleCreator(
|
|
|
6484
6693
|
return {
|
|
6485
6694
|
VariableDeclarator(node) {
|
|
6486
6695
|
const declaration = node.parent;
|
|
6487
|
-
if (declaration.type !==
|
|
6696
|
+
if (declaration.type !== AST_NODE_TYPES29.VariableDeclaration || declaration.kind !== "const" || declaration.declare === true) {
|
|
6488
6697
|
return;
|
|
6489
6698
|
}
|
|
6490
|
-
if (node.id.type !==
|
|
6699
|
+
if (node.id.type !== AST_NODE_TYPES29.Identifier || node.init === null) {
|
|
6491
6700
|
return;
|
|
6492
6701
|
}
|
|
6493
6702
|
if (enclosingFunction2(node) === null) {
|
|
@@ -6513,6 +6722,441 @@ var prefer_module_level_constant_default = ESLintUtils41.RuleCreator(
|
|
|
6513
6722
|
}
|
|
6514
6723
|
});
|
|
6515
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
|
+
|
|
6516
7160
|
// src/index.ts
|
|
6517
7161
|
var rules = {
|
|
6518
7162
|
"enforce-file-structure": enforce_file_structure_default,
|
|
@@ -6555,12 +7199,15 @@ var rules = {
|
|
|
6555
7199
|
"no-raw-fetch-outside-clients": no_raw_fetch_outside_clients_default,
|
|
6556
7200
|
"no-storage-in-stateless-modules": no_storage_in_stateless_modules_default,
|
|
6557
7201
|
"no-zod-native-enum": no_zod_native_enum_default,
|
|
6558
|
-
"prefer-module-level-constant": prefer_module_level_constant_default
|
|
7202
|
+
"prefer-module-level-constant": prefer_module_level_constant_default,
|
|
7203
|
+
"jsdoc-restates-signature": jsdoc_restates_signature_default,
|
|
7204
|
+
"no-restated-comment": no_restated_comment_default,
|
|
7205
|
+
"trailing-value-narration": trailing_value_narration_default
|
|
6559
7206
|
};
|
|
6560
7207
|
var plugin = {
|
|
6561
7208
|
meta: {
|
|
6562
7209
|
name: "@sarj/eslint-plugin",
|
|
6563
|
-
version: "2.
|
|
7210
|
+
version: "2.13.0"
|
|
6564
7211
|
},
|
|
6565
7212
|
rules,
|
|
6566
7213
|
configs: {
|
|
@@ -6616,7 +7263,18 @@ var plugin = {
|
|
|
6616
7263
|
// Mined from two years of PR review — the single most frequent uncovered
|
|
6617
7264
|
// theme (~37 PRs). Measured 17 hits / 1085 real TS files, all true
|
|
6618
7265
|
// positives, so it is safe to run everywhere.
|
|
6619
|
-
"@sarj/prefer-module-level-constant": "warn"
|
|
7266
|
+
"@sarj/prefer-module-level-constant": "warn",
|
|
7267
|
+
// Anti-comment-verbosity family (2026-07), from a 37,918-comment,
|
|
7268
|
+
// nine-repo measurement study. Each is a deletion-class finding, so each
|
|
7269
|
+
// was validated against pydantic / trio / attrs as well as the maintained
|
|
7270
|
+
// repos: `no-restated-comment` 0 hits in bulbul and 4 in the three famous
|
|
7271
|
+
// corpora combined; `trailing-value-narration` 18 hits, 18 true
|
|
7272
|
+
// positives; `jsdoc-restates-signature` 36 hits, 0 measured false
|
|
7273
|
+
// positives, and it offers a suggestion rather than a `--fix` because a
|
|
7274
|
+
// wrong deletion is silent information loss.
|
|
7275
|
+
"@sarj/no-restated-comment": "warn",
|
|
7276
|
+
"@sarj/jsdoc-restates-signature": "warn",
|
|
7277
|
+
"@sarj/trailing-value-narration": "warn"
|
|
6620
7278
|
}
|
|
6621
7279
|
},
|
|
6622
7280
|
strict: {
|
|
@@ -6679,7 +7337,12 @@ var plugin = {
|
|
|
6679
7337
|
"@sarj/no-storage-in-stateless-modules": "error",
|
|
6680
7338
|
// Mined from two years of PR review (SARJ-928).
|
|
6681
7339
|
"@sarj/no-zod-native-enum": "error",
|
|
6682
|
-
"@sarj/prefer-module-level-constant": "error"
|
|
7340
|
+
"@sarj/prefer-module-level-constant": "error",
|
|
7341
|
+
// Anti-comment-verbosity family (2026-07) — see the `recommended` block
|
|
7342
|
+
// for the measured hit counts and false-positive rates.
|
|
7343
|
+
"@sarj/no-restated-comment": "error",
|
|
7344
|
+
"@sarj/jsdoc-restates-signature": "error",
|
|
7345
|
+
"@sarj/trailing-value-narration": "error"
|
|
6683
7346
|
}
|
|
6684
7347
|
}
|
|
6685
7348
|
}
|