@sarj/eslint-plugin 16.32.0 → 16.32.3
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/dist/{_docs-DU-K223M.d.cts → _docs-Bq5OCcWF.d.cts} +4 -4
- package/dist/{_docs-DU-K223M.d.ts → _docs-Bq5OCcWF.d.ts} +4 -4
- package/dist/index.cjs +975 -416
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +975 -416
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -51,10 +51,62 @@ module.exports = __toCommonJS(src_exports);
|
|
|
51
51
|
|
|
52
52
|
// src/rules/no-redundant-consumer-union.ts
|
|
53
53
|
var import_utils7 = require("@typescript-eslint/utils");
|
|
54
|
-
var
|
|
54
|
+
var import_typescript7 = __toESM(require("typescript"), 1);
|
|
55
55
|
|
|
56
|
-
// src/rules/
|
|
56
|
+
// src/rules/_checked-native-source.ts
|
|
57
57
|
var import_typescript = __toESM(require("typescript"), 1);
|
|
58
|
+
var CHECKED = /* @__PURE__ */ new WeakMap();
|
|
59
|
+
var SINGLE_LINE_DIRECTIVE = /^\/\/\/?\s*@(?:ts-expect-error|ts-ignore)/u;
|
|
60
|
+
var MULTI_LINE_DIRECTIVE = /^[/*]*\s*@(?:ts-expect-error|ts-ignore)/u;
|
|
61
|
+
var SINGLE_LINE_PRAGMA = /^\/\/\/?\s*@([^\s:]+)(?:(?:[^\S\r\n]|:).*)?$/mu;
|
|
62
|
+
function currentNativeSource(sourceCode, services) {
|
|
63
|
+
const source = services.esTreeNodeToTSNodeMap.get(sourceCode.ast);
|
|
64
|
+
return import_typescript.default.isSourceFile(source) && services.program.getSourceFile(source.fileName) === source && source.text === sourceCode.text ? source : null;
|
|
65
|
+
}
|
|
66
|
+
function checkedNativeSource(program, source) {
|
|
67
|
+
let files = CHECKED.get(program);
|
|
68
|
+
if (!files) {
|
|
69
|
+
files = /* @__PURE__ */ new WeakMap();
|
|
70
|
+
CHECKED.set(program, files);
|
|
71
|
+
}
|
|
72
|
+
const known2 = files.get(source);
|
|
73
|
+
if (known2 !== void 0) return known2;
|
|
74
|
+
const available = !program.getCompilerOptions().noCheck && !source.isDeclarationFile && (source.flags & (import_typescript.default.NodeFlags.JavaScriptFile | import_typescript.default.NodeFlags.JsonFile)) === 0 && !program.getProjectReferences()?.length && !program.getResolvedProjectReferences()?.length && program.getSourceFile(source.fileName) === source && !program.isSourceFileFromExternalLibrary(source) && !program.isSourceFileDefaultLibrary(source) && !program.getSyntacticDiagnostics(source).some((diagnostic) => diagnostic.category === import_typescript.default.DiagnosticCategory.Error && diagnostic.file === source) && !checkingSuppressed(source) && !program.getSemanticDiagnostics(source).some((diagnostic) => diagnostic.category === import_typescript.default.DiagnosticCategory.Error && diagnostic.file === source);
|
|
75
|
+
files.set(source, available);
|
|
76
|
+
return available;
|
|
77
|
+
}
|
|
78
|
+
function checkingSuppressed(source) {
|
|
79
|
+
if (!/@ts-/iu.test(source.text)) return false;
|
|
80
|
+
if (import_typescript.default.getLeadingCommentRanges(source.text, 0)?.some((comment) => comment.kind === import_typescript.default.SyntaxKind.SingleLineCommentTrivia && SINGLE_LINE_PRAGMA.exec(source.text.slice(comment.pos, comment.end))?.[1]?.toLowerCase() === "ts-nocheck")) return true;
|
|
81
|
+
const pending = [source];
|
|
82
|
+
while (pending.length) {
|
|
83
|
+
const node = pending.pop();
|
|
84
|
+
if (!node || import_typescript.default.isJsxText(node) || import_typescript.default.isJSDoc(node) || (node.flags & import_typescript.default.NodeFlags.JSDoc) !== 0) continue;
|
|
85
|
+
if (!import_typescript.default.isToken(node)) {
|
|
86
|
+
for (const child of node.getChildren(source)) pending.push(child);
|
|
87
|
+
continue;
|
|
88
|
+
}
|
|
89
|
+
if (tokenTriviaSuppressesChecking(node, source)) return true;
|
|
90
|
+
}
|
|
91
|
+
return false;
|
|
92
|
+
}
|
|
93
|
+
function tokenTriviaSuppressesChecking(node, source) {
|
|
94
|
+
const start = node.getStart(source);
|
|
95
|
+
for (const comment of [...import_typescript.default.getLeadingCommentRanges(source.text, node.pos) ?? [], ...import_typescript.default.getTrailingCommentRanges(source.text, node.pos) ?? []]) {
|
|
96
|
+
if (comment.pos < node.pos || comment.end > start) continue;
|
|
97
|
+
if (commentSuppressesChecking(source.text.slice(comment.pos, comment.end), comment.kind)) return true;
|
|
98
|
+
}
|
|
99
|
+
return false;
|
|
100
|
+
}
|
|
101
|
+
function commentSuppressesChecking(text, kind) {
|
|
102
|
+
if (kind === import_typescript.default.SyntaxKind.SingleLineCommentTrivia) return SINGLE_LINE_DIRECTIVE.test(text);
|
|
103
|
+
let lastLine = text.length;
|
|
104
|
+
while (lastLine > 0 && !import_typescript.default.isLineBreak(text.charCodeAt(lastLine - 1))) lastLine--;
|
|
105
|
+
return MULTI_LINE_DIRECTIVE.test(text.slice(lastLine).trimStart());
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// src/rules/_closed-object-contract.ts
|
|
109
|
+
var import_typescript2 = __toESM(require("typescript"), 1);
|
|
58
110
|
function closedObjectContract(type, checker) {
|
|
59
111
|
return visitContract(type, { checker, active: /* @__PURE__ */ new Set(), completed: /* @__PURE__ */ new WeakMap() });
|
|
60
112
|
}
|
|
@@ -70,32 +122,32 @@ function visitContract(type, proof) {
|
|
|
70
122
|
}
|
|
71
123
|
function completeObject(type, proof) {
|
|
72
124
|
if (!ordinaryObject(type, proof.checker)) return false;
|
|
73
|
-
const declarations = type.getSymbol()?.getDeclarations()?.filter((declaration) =>
|
|
125
|
+
const declarations = type.getSymbol()?.getDeclarations()?.filter((declaration) => import_typescript2.default.isInterfaceDeclaration(declaration) || import_typescript2.default.isTypeLiteralNode(declaration));
|
|
74
126
|
if (!declarations?.length) return false;
|
|
75
127
|
return declarations.every((declaration) => completeDeclaration(declaration, proof));
|
|
76
128
|
}
|
|
77
129
|
function ordinaryObject(type, checker) {
|
|
78
|
-
if ((type.flags &
|
|
130
|
+
if ((type.flags & import_typescript2.default.TypeFlags.Object) === 0 || type.isUnion() || checker.getIndexInfosOfType(type).length > 0) return false;
|
|
79
131
|
const object = type;
|
|
80
|
-
if ((object.objectFlags & (
|
|
81
|
-
if ((object.objectFlags &
|
|
82
|
-
return checker.getSignaturesOfType(type,
|
|
132
|
+
if ((object.objectFlags & (import_typescript2.default.ObjectFlags.Class | import_typescript2.default.ObjectFlags.Mapped)) !== 0) return false;
|
|
133
|
+
if ((object.objectFlags & import_typescript2.default.ObjectFlags.Reference) !== 0 && checker.getTypeArguments(type).some((argument) => (argument.flags & (import_typescript2.default.TypeFlags.Any | import_typescript2.default.TypeFlags.Unknown | import_typescript2.default.TypeFlags.TypeParameter)) !== 0)) return false;
|
|
134
|
+
return checker.getSignaturesOfType(type, import_typescript2.default.SignatureKind.Call).length === 0 && checker.getSignaturesOfType(type, import_typescript2.default.SignatureKind.Construct).length === 0;
|
|
83
135
|
}
|
|
84
136
|
function completeDeclaration(declaration, proof) {
|
|
85
137
|
if (!declaration.members.every((member3) => finiteMember(member3, proof.checker))) return false;
|
|
86
|
-
if (!
|
|
138
|
+
if (!import_typescript2.default.isInterfaceDeclaration(declaration)) return true;
|
|
87
139
|
if (declaration.typeParameters?.length) return false;
|
|
88
140
|
return (declaration.heritageClauses ?? []).every((heritage) => heritage.types.every((base) => visitContract(proof.checker.getTypeAtLocation(base), proof)));
|
|
89
141
|
}
|
|
90
142
|
function finiteMember(member3, checker) {
|
|
91
|
-
if (
|
|
92
|
-
if (!member3.name || !
|
|
93
|
-
return (checker.getTypeAtLocation(member3.name.expression).flags & (
|
|
143
|
+
if (import_typescript2.default.isIndexSignatureDeclaration(member3)) return false;
|
|
144
|
+
if (!member3.name || !import_typescript2.default.isComputedPropertyName(member3.name)) return true;
|
|
145
|
+
return (checker.getTypeAtLocation(member3.name.expression).flags & (import_typescript2.default.TypeFlags.StringLiteral | import_typescript2.default.TypeFlags.NumberLiteral | import_typescript2.default.TypeFlags.UniqueESSymbol)) !== 0;
|
|
94
146
|
}
|
|
95
147
|
|
|
96
148
|
// src/rules/_private-consumer-fix.ts
|
|
97
149
|
var import_utils2 = require("@typescript-eslint/utils");
|
|
98
|
-
var
|
|
150
|
+
var import_typescript3 = __toESM(require("typescript"), 1);
|
|
99
151
|
|
|
100
152
|
// src/rules/_type-binding.ts
|
|
101
153
|
var import_utils = require("@typescript-eslint/utils");
|
|
@@ -140,7 +192,7 @@ function insideTypeRange(node, range) {
|
|
|
140
192
|
}
|
|
141
193
|
|
|
142
194
|
// src/rules/_private-consumer-fix.ts
|
|
143
|
-
var UNSAFE =
|
|
195
|
+
var UNSAFE = import_typescript3.default.TypeFlags.Any | import_typescript3.default.TypeFlags.Unknown | import_typescript3.default.TypeFlags.Never | import_typescript3.default.TypeFlags.TypeParameter | import_typescript3.default.TypeFlags.Conditional | import_typescript3.default.TypeFlags.IndexedAccess | import_typescript3.default.TypeFlags.Substitution;
|
|
144
196
|
function validConsumerFixCalls(node, parameter, sourceCode, services) {
|
|
145
197
|
if (sourceCode.getAllComments().some((comment) => /@ts-(?:expect-error|ignore|nocheck)\b/u.test(comment.value))) return false;
|
|
146
198
|
const owner = node.type === import_utils2.AST_NODE_TYPES.FunctionDeclaration ? node : node.parent;
|
|
@@ -537,58 +589,75 @@ function commentLineEnd(sourceText, start) {
|
|
|
537
589
|
|
|
538
590
|
// src/rules/_private-scalar-consumer.ts
|
|
539
591
|
var import_utils6 = require("@typescript-eslint/utils");
|
|
592
|
+
var import_typescript6 = __toESM(require("typescript"), 1);
|
|
593
|
+
|
|
594
|
+
// src/rules/_scalar-parameter-view.ts
|
|
595
|
+
var import_typescript5 = __toESM(require("typescript"), 1);
|
|
596
|
+
|
|
597
|
+
// src/rules/_native-const-value.ts
|
|
540
598
|
var import_typescript4 = __toESM(require("typescript"), 1);
|
|
599
|
+
function constInitializer(declaration) {
|
|
600
|
+
if (!declaration || !import_typescript4.default.isVariableDeclaration(declaration) || !import_typescript4.default.isVariableDeclarationList(declaration.parent) || (declaration.parent.flags & import_typescript4.default.NodeFlags.BlockScoped) !== import_typescript4.default.NodeFlags.Const) return void 0;
|
|
601
|
+
let initializer = declaration.initializer;
|
|
602
|
+
while (initializer && import_typescript4.default.isParenthesizedExpression(initializer)) initializer = initializer.expression;
|
|
603
|
+
return initializer;
|
|
604
|
+
}
|
|
605
|
+
function unassertedValue(node) {
|
|
606
|
+
let value = node;
|
|
607
|
+
while (import_typescript4.default.isParenthesizedExpression(value) || import_typescript4.default.isAsExpression(value) || import_typescript4.default.isTypeAssertionExpression(value) || import_typescript4.default.isNonNullExpression(value) || import_typescript4.default.isSatisfiesExpression(value)) value = value.expression;
|
|
608
|
+
return value;
|
|
609
|
+
}
|
|
541
610
|
|
|
542
611
|
// src/rules/_scalar-parameter-view.ts
|
|
543
|
-
var import_typescript3 = __toESM(require("typescript"), 1);
|
|
544
612
|
var SCALAR_OPERATORS = /* @__PURE__ */ new Set([
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
613
|
+
import_typescript5.default.SyntaxKind.PlusToken,
|
|
614
|
+
import_typescript5.default.SyntaxKind.MinusToken,
|
|
615
|
+
import_typescript5.default.SyntaxKind.AsteriskToken,
|
|
616
|
+
import_typescript5.default.SyntaxKind.SlashToken,
|
|
617
|
+
import_typescript5.default.SyntaxKind.PercentToken,
|
|
618
|
+
import_typescript5.default.SyntaxKind.AsteriskAsteriskToken,
|
|
619
|
+
import_typescript5.default.SyntaxKind.LessThanToken,
|
|
620
|
+
import_typescript5.default.SyntaxKind.LessThanEqualsToken,
|
|
621
|
+
import_typescript5.default.SyntaxKind.GreaterThanToken,
|
|
622
|
+
import_typescript5.default.SyntaxKind.GreaterThanEqualsToken,
|
|
623
|
+
import_typescript5.default.SyntaxKind.EqualsEqualsEqualsToken,
|
|
624
|
+
import_typescript5.default.SyntaxKind.ExclamationEqualsEqualsToken,
|
|
625
|
+
import_typescript5.default.SyntaxKind.EqualsEqualsToken,
|
|
626
|
+
import_typescript5.default.SyntaxKind.ExclamationEqualsToken,
|
|
627
|
+
import_typescript5.default.SyntaxKind.AmpersandAmpersandToken,
|
|
628
|
+
import_typescript5.default.SyntaxKind.BarBarToken,
|
|
629
|
+
import_typescript5.default.SyntaxKind.QuestionQuestionToken
|
|
562
630
|
]);
|
|
563
|
-
var SCALAR_PREFIXES = /* @__PURE__ */ new Set([
|
|
631
|
+
var SCALAR_PREFIXES = /* @__PURE__ */ new Set([import_typescript5.default.SyntaxKind.PlusToken, import_typescript5.default.SyntaxKind.MinusToken, import_typescript5.default.SyntaxKind.ExclamationToken, import_typescript5.default.SyntaxKind.TildeToken]);
|
|
632
|
+
var RETURNED_OPERANDS = /* @__PURE__ */ new Set([import_typescript5.default.SyntaxKind.AmpersandAmpersandToken, import_typescript5.default.SyntaxKind.BarBarToken, import_typescript5.default.SyntaxKind.QuestionQuestionToken]);
|
|
564
633
|
function scalarParameterView(parameter, body3, checker) {
|
|
565
634
|
return parameterReads(parameter, body3, checker, true);
|
|
566
635
|
}
|
|
567
|
-
function scalarParameterReads(parameter, body3, checker) {
|
|
568
|
-
return parameterReads(parameter, body3, checker, false);
|
|
636
|
+
function scalarParameterReads(parameter, body3, checker, callProgram) {
|
|
637
|
+
return parameterReads(parameter, body3, checker, false, callProgram);
|
|
569
638
|
}
|
|
570
|
-
function parameterReads(parameter, body3, checker, jsx) {
|
|
571
|
-
if (parameter.dotDotDotToken || parameter.initializer ||
|
|
572
|
-
const root =
|
|
573
|
-
if (
|
|
639
|
+
function parameterReads(parameter, body3, checker, jsx, callProgram) {
|
|
640
|
+
if (parameter.dotDotDotToken || parameter.initializer || import_typescript5.default.isArrayBindingPattern(parameter.name)) return null;
|
|
641
|
+
const root = import_typescript5.default.isIdentifier(parameter.name) ? checker.getSymbolAtLocation(parameter.name) : void 0;
|
|
642
|
+
if (import_typescript5.default.isIdentifier(parameter.name) && !root) return null;
|
|
574
643
|
const reads = /* @__PURE__ */ new Set();
|
|
575
644
|
const aliases = parameterAliases(parameter.name, checker, reads);
|
|
576
645
|
if (!aliases) return null;
|
|
577
646
|
const expression = returnedExpression(body3);
|
|
578
|
-
const view = { checker, props: checker.getTypeAtLocation(parameter), root, aliases, reads,
|
|
579
|
-
return expression && scalarView(expression, view) ? reads : null;
|
|
647
|
+
const view = { checker, props: checker.getTypeAtLocation(parameter), root, aliases, reads, callProgram };
|
|
648
|
+
return expression && scalarView(expression, view, jsx) ? reads : null;
|
|
580
649
|
}
|
|
581
650
|
function scalarType(type, allowUndefined = true) {
|
|
582
651
|
if (type.isUnion()) return type.types.every((part) => scalarType(part, allowUndefined));
|
|
583
|
-
const flags =
|
|
584
|
-
return (type.flags & (allowUndefined ? flags |
|
|
652
|
+
const flags = import_typescript5.default.TypeFlags.StringLike | import_typescript5.default.TypeFlags.NumberLike | import_typescript5.default.TypeFlags.BooleanLike | import_typescript5.default.TypeFlags.BigIntLike | import_typescript5.default.TypeFlags.Null;
|
|
653
|
+
return (type.flags & (allowUndefined ? flags | import_typescript5.default.TypeFlags.Undefined : flags)) !== 0;
|
|
585
654
|
}
|
|
586
655
|
function parameterAliases(name, checker, reads) {
|
|
587
656
|
const aliases = /* @__PURE__ */ new Map();
|
|
588
|
-
if (
|
|
657
|
+
if (import_typescript5.default.isIdentifier(name)) return aliases;
|
|
589
658
|
for (const element of name.elements) {
|
|
590
659
|
const key = element.propertyName ?? element.name;
|
|
591
|
-
if (element.dotDotDotToken || element.initializer || !
|
|
660
|
+
if (element.dotDotDotToken || element.initializer || !import_typescript5.default.isIdentifier(element.name) || !import_typescript5.default.isIdentifier(key) && !import_typescript5.default.isStringLiteralLike(key) && !import_typescript5.default.isNumericLiteral(key)) return null;
|
|
592
661
|
const binding3 = checker.getSymbolAtLocation(element.name);
|
|
593
662
|
if (!binding3) return null;
|
|
594
663
|
reads.add(key.text);
|
|
@@ -597,31 +666,56 @@ function parameterAliases(name, checker, reads) {
|
|
|
597
666
|
return aliases;
|
|
598
667
|
}
|
|
599
668
|
function returnedExpression(body3) {
|
|
600
|
-
if (!
|
|
669
|
+
if (!import_typescript5.default.isBlock(body3)) return body3;
|
|
601
670
|
const statement = body3.statements.length === 1 ? body3.statements[0] : void 0;
|
|
602
|
-
return statement &&
|
|
671
|
+
return statement && import_typescript5.default.isReturnStatement(statement) ? statement.expression : void 0;
|
|
603
672
|
}
|
|
604
|
-
function scalarView(node, view) {
|
|
673
|
+
function scalarView(node, view, jsx = false) {
|
|
605
674
|
if (scalarLiteral(node)) return true;
|
|
606
|
-
if (
|
|
675
|
+
if (import_typescript5.default.isCallExpression(node)) return !jsx && scalarCall(node, view);
|
|
676
|
+
if (import_typescript5.default.isJsxExpression(node)) return !node.dotDotDotToken && (!node.expression || scalarView(node.expression, view, jsx));
|
|
677
|
+
if (import_typescript5.default.isIdentifier(node)) {
|
|
607
678
|
const binding3 = view.checker.getSymbolAtLocation(node);
|
|
608
679
|
const key = binding3 && view.aliases.get(binding3);
|
|
609
680
|
return key !== void 0 && readField(node, key, view);
|
|
610
681
|
}
|
|
611
|
-
if (
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
if (
|
|
616
|
-
if (
|
|
617
|
-
return view.jsx &&
|
|
682
|
+
if (import_typescript5.default.isPropertyAccessExpression(node) || import_typescript5.default.isElementAccessExpression(node)) return memberRead(node, view);
|
|
683
|
+
return scalarOperation(node, view, jsx);
|
|
684
|
+
}
|
|
685
|
+
function scalarOperation(node, view, jsx) {
|
|
686
|
+
if (import_typescript5.default.isParenthesizedExpression(node) || import_typescript5.default.isNonNullExpression(node)) return scalarView(node.expression, view, jsx);
|
|
687
|
+
if (import_typescript5.default.isTypeOfExpression(node)) return scalarView(node.expression, view);
|
|
688
|
+
if (import_typescript5.default.isConditionalExpression(node)) return scalarView(node.condition, view) && scalarView(node.whenTrue, view, jsx) && scalarView(node.whenFalse, view, jsx);
|
|
689
|
+
if (import_typescript5.default.isBinaryExpression(node)) return binaryView(node, view, jsx);
|
|
690
|
+
if (import_typescript5.default.isPrefixUnaryExpression(node)) return SCALAR_PREFIXES.has(node.operator) && scalarView(node.operand, view);
|
|
691
|
+
if (import_typescript5.default.isTemplateExpression(node)) return node.templateSpans.every((span) => scalarView(span.expression, view));
|
|
692
|
+
return jsx && jsxView(node, view);
|
|
693
|
+
}
|
|
694
|
+
function scalarCall(node, view) {
|
|
695
|
+
if (!view.callProgram || node.questionDotToken || node.typeArguments?.length || !import_typescript5.default.isIdentifier(node.expression) || !node.arguments.length || node.arguments.some(import_typescript5.default.isSpreadElement)) return false;
|
|
696
|
+
const declarations = view.checker.getSymbolAtLocation(node.expression)?.declarations;
|
|
697
|
+
const declaration = declarations?.length === 1 ? declarations[0] : void 0;
|
|
698
|
+
const helper = declaration && localHelper(declaration);
|
|
699
|
+
if (!helper || helper.getSourceFile() !== node.getSourceFile() || helper.typeParameters?.length || !helper.type || !node.arguments.every((argument) => scalarView(argument, view))) return false;
|
|
700
|
+
if (!checkedNativeSource(view.callProgram, node.getSourceFile())) return false;
|
|
701
|
+
const signature = view.checker.getResolvedSignature(node);
|
|
702
|
+
return signature?.declaration === helper && !view.checker.getTypePredicateOfSignature(signature) && scalarType(view.checker.getTypeAtLocation(node));
|
|
703
|
+
}
|
|
704
|
+
function localHelper(node) {
|
|
705
|
+
if (import_typescript5.default.isFunctionDeclaration(node)) return node.body && import_typescript5.default.isSourceFile(node.parent) ? node : void 0;
|
|
706
|
+
if (!import_typescript5.default.isVariableDeclaration(node) || node.type || !node.initializer || constInitializer(node) !== node.initializer || !import_typescript5.default.isArrowFunction(node.initializer) || !import_typescript5.default.isVariableStatement(node.parent.parent) || !import_typescript5.default.isSourceFile(node.parent.parent.parent)) return void 0;
|
|
707
|
+
return node.initializer;
|
|
708
|
+
}
|
|
709
|
+
function binaryView(node, view, jsx) {
|
|
710
|
+
const returned2 = jsx && RETURNED_OPERANDS.has(node.operatorToken.kind);
|
|
711
|
+
return SCALAR_OPERATORS.has(node.operatorToken.kind) && scalarView(node.left, view, returned2) && scalarView(node.right, view, returned2);
|
|
618
712
|
}
|
|
619
713
|
function scalarLiteral(node) {
|
|
620
|
-
return
|
|
714
|
+
return import_typescript5.default.isStringLiteralLike(node) || import_typescript5.default.isNumericLiteral(node) || import_typescript5.default.isBigIntLiteral(node) || import_typescript5.default.isJsxText(node) || node.kind === import_typescript5.default.SyntaxKind.TrueKeyword || node.kind === import_typescript5.default.SyntaxKind.FalseKeyword || node.kind === import_typescript5.default.SyntaxKind.NullKeyword;
|
|
621
715
|
}
|
|
622
716
|
function memberRead(node, view) {
|
|
623
|
-
if (!view.root || !
|
|
624
|
-
const key =
|
|
717
|
+
if (!view.root || !import_typescript5.default.isIdentifier(node.expression) || view.checker.getSymbolAtLocation(node.expression) !== view.root) return false;
|
|
718
|
+
const key = import_typescript5.default.isPropertyAccessExpression(node) ? node.name.text : node.argumentExpression && (import_typescript5.default.isStringLiteralLike(node.argumentExpression) || import_typescript5.default.isNumericLiteral(node.argumentExpression)) ? node.argumentExpression.text : void 0;
|
|
625
719
|
return key !== void 0 && readField(node, key, view);
|
|
626
720
|
}
|
|
627
721
|
function readField(node, key, view) {
|
|
@@ -630,15 +724,14 @@ function readField(node, key, view) {
|
|
|
630
724
|
return true;
|
|
631
725
|
}
|
|
632
726
|
function jsxView(node, view) {
|
|
633
|
-
if (
|
|
634
|
-
if (
|
|
635
|
-
if (
|
|
636
|
-
if (!
|
|
637
|
-
if (!import_typescript3.default.isIdentifier(node.tagName) || !/^[a-z][A-Za-z0-9]*$/u.test(node.tagName.text)) return false;
|
|
727
|
+
if (import_typescript5.default.isJsxFragment(node)) return node.children.every((child) => scalarView(child, view, true));
|
|
728
|
+
if (import_typescript5.default.isJsxElement(node)) return jsxView(node.openingElement, view) && node.children.every((child) => scalarView(child, view, true));
|
|
729
|
+
if (!import_typescript5.default.isJsxOpeningElement(node) && !import_typescript5.default.isJsxSelfClosingElement(node)) return false;
|
|
730
|
+
if (!import_typescript5.default.isIdentifier(node.tagName) || !/^[a-z][A-Za-z0-9]*$/u.test(node.tagName.text)) return false;
|
|
638
731
|
return node.attributes.properties.every((attribute) => intrinsicAttribute(attribute, view));
|
|
639
732
|
}
|
|
640
733
|
function intrinsicAttribute(attribute, view) {
|
|
641
|
-
return
|
|
734
|
+
return import_typescript5.default.isJsxAttribute(attribute) && import_typescript5.default.isIdentifier(attribute.name) && attribute.name.text !== "is" && (!attribute.initializer || scalarView(attribute.initializer, view));
|
|
642
735
|
}
|
|
643
736
|
|
|
644
737
|
// src/rules/_stable-value-binding.ts
|
|
@@ -691,7 +784,7 @@ function directEval(node) {
|
|
|
691
784
|
return callee.type === import_utils6.AST_NODE_TYPES.Identifier && callee.name === "eval";
|
|
692
785
|
}
|
|
693
786
|
function primitiveKeyword(node) {
|
|
694
|
-
return node !== void 0 && (node.kind ===
|
|
787
|
+
return node !== void 0 && (node.kind === import_typescript6.default.SyntaxKind.StringKeyword || node.kind === import_typescript6.default.SyntaxKind.NumberKeyword || node.kind === import_typescript6.default.SyntaxKind.BooleanKeyword || node.kind === import_typescript6.default.SyntaxKind.BigIntKeyword);
|
|
695
788
|
}
|
|
696
789
|
function consumerAnnotation(node) {
|
|
697
790
|
if (node.params.length !== 1) return void 0;
|
|
@@ -700,31 +793,31 @@ function consumerAnnotation(node) {
|
|
|
700
793
|
}
|
|
701
794
|
function exportedSymbols(source, checker) {
|
|
702
795
|
const symbol = checker.getSymbolAtLocation(source);
|
|
703
|
-
return new Set(symbol ? checker.getExportsOfModule(symbol).map((entry) => (entry.flags &
|
|
796
|
+
return new Set(symbol ? checker.getExportsOfModule(symbol).map((entry) => (entry.flags & import_typescript6.default.SymbolFlags.Alias) !== 0 ? checker.getAliasedSymbol(entry) : entry) : []);
|
|
704
797
|
}
|
|
705
|
-
function privateScalarConsumer(node, sourceCode, services, exports2) {
|
|
798
|
+
function privateScalarConsumer(node, sourceCode, services, exports2, scalarCalls = false) {
|
|
706
799
|
const native = services.esTreeNodeToTSNodeMap.get(node);
|
|
707
|
-
if (!
|
|
800
|
+
if (!import_typescript6.default.isFunctionDeclaration(native) && !import_typescript6.default.isArrowFunction(native) || !native.body || !independentSignature(native)) return null;
|
|
708
801
|
const checker = services.program.getTypeChecker();
|
|
709
|
-
if (!
|
|
802
|
+
if (!import_typescript6.default.isExternalModule(native.getSourceFile()) || !services.program.getCompilerOptions().strict) return null;
|
|
710
803
|
const parameter = native.parameters[0];
|
|
711
804
|
if (!parameter) return null;
|
|
712
805
|
const binding3 = callableBinding(node, sourceCode);
|
|
713
806
|
if (!binding3 || binding3.defs.length !== 1) return null;
|
|
714
|
-
const name =
|
|
807
|
+
const name = import_typescript6.default.isFunctionDeclaration(native) ? native.name : import_typescript6.default.isVariableDeclaration(native.parent) ? native.parent.name : void 0;
|
|
715
808
|
const symbol = name && checker.getSymbolAtLocation(name);
|
|
716
809
|
if (!symbol || symbol.declarations?.length !== 1 || exports2.has(symbol) || !directCalls(binding3)) return null;
|
|
717
810
|
const signature = checker.getSignatureFromDeclaration(native);
|
|
718
811
|
if (!signature || signature.typeParameters?.length || checker.getTypePredicateOfSignature(signature)) return null;
|
|
719
812
|
const expression = returnedExpression(native.body);
|
|
720
813
|
if (!expression || !checker.isTypeAssignableTo(checker.getTypeAtLocation(expression), checker.getReturnTypeOfSignature(signature))) return null;
|
|
721
|
-
const reads = scalarParameterReads(parameter, native.body, checker);
|
|
814
|
+
const reads = scalarParameterReads(parameter, native.body, checker, scalarCalls ? services.program : void 0);
|
|
722
815
|
return reads?.size ? { parameter, reads } : null;
|
|
723
816
|
}
|
|
724
817
|
function independentSignature(native) {
|
|
725
818
|
if (native.parameters.length !== 1 || native.typeParameters?.length || native.asteriskToken || native.modifiers?.length || !primitiveKeyword(native.type)) return false;
|
|
726
819
|
const parameter = native.parameters[0];
|
|
727
|
-
return parameter !== void 0 && parameter.type !== void 0 && !parameter.modifiers?.length && !parameter.questionToken && !parameter.initializer && !parameter.dotDotDotToken && (!
|
|
820
|
+
return parameter !== void 0 && parameter.type !== void 0 && !parameter.modifiers?.length && !parameter.questionToken && !parameter.initializer && !parameter.dotDotDotToken && (!import_typescript6.default.isIdentifier(parameter.name) || parameter.name.text !== "this");
|
|
728
821
|
}
|
|
729
822
|
function callableBinding(node, sourceCode) {
|
|
730
823
|
if (node.type === import_utils6.AST_NODE_TYPES.FunctionDeclaration) {
|
|
@@ -774,8 +867,8 @@ function scalarFields(type, checker) {
|
|
|
774
867
|
const fields = /* @__PURE__ */ new Map();
|
|
775
868
|
for (const property of type.getProperties()) {
|
|
776
869
|
const declarations = property.getDeclarations();
|
|
777
|
-
if (!declarations?.length || !declarations.every((member3) =>
|
|
778
|
-
fields.set(property.name, (property.flags &
|
|
870
|
+
if (!declarations?.length || !declarations.every((member3) => import_typescript7.default.isPropertySignature(member3) && member3.name && (import_typescript7.default.isIdentifier(member3.name) || import_typescript7.default.isStringLiteralLike(member3.name)) && member3.modifiers?.length === 1 && member3.modifiers[0]?.kind === import_typescript7.default.SyntaxKind.ReadonlyKeyword && primitiveKeyword(member3.type))) return null;
|
|
871
|
+
fields.set(property.name, (property.flags & import_typescript7.default.SymbolFlags.Optional) === 0);
|
|
779
872
|
}
|
|
780
873
|
return fields.size ? fields : null;
|
|
781
874
|
}
|
|
@@ -809,8 +902,10 @@ var no_redundant_consumer_union_default = createRule({
|
|
|
809
902
|
"Program:exit"() {
|
|
810
903
|
if (dynamic || !candidates.length) return;
|
|
811
904
|
const services = import_utils7.ESLintUtils.getParserServices(context);
|
|
905
|
+
const source = currentNativeSource(context.sourceCode, services);
|
|
906
|
+
if (!source) return;
|
|
812
907
|
const checker = services.program.getTypeChecker();
|
|
813
|
-
const exports2 = exportedSymbols(
|
|
908
|
+
const exports2 = exportedSymbols(source, checker);
|
|
814
909
|
const candidateAnnotations = candidates.flatMap((node) => {
|
|
815
910
|
const annotation = consumerAnnotation(node);
|
|
816
911
|
return annotation ? [annotation] : [];
|
|
@@ -823,7 +918,7 @@ var no_redundant_consumer_union_default = createRule({
|
|
|
823
918
|
for (const candidate2 of candidates) {
|
|
824
919
|
const consumer = privateScalarConsumer(candidate2, context.sourceCode, services, exports2);
|
|
825
920
|
const annotation = consumer?.parameter.type;
|
|
826
|
-
if (!consumer || !annotation || !
|
|
921
|
+
if (!consumer || !annotation || !import_typescript7.default.isUnionTypeNode(annotation) || annotation.types.length !== 2) continue;
|
|
827
922
|
const leftNode = annotation.types[0];
|
|
828
923
|
const rightNode = annotation.types[1];
|
|
829
924
|
if (!leftNode || !rightNode) continue;
|
|
@@ -855,9 +950,10 @@ var no_redundant_consumer_union_default = createRule({
|
|
|
855
950
|
|
|
856
951
|
// src/rules/prefer-minimal-parameter-contract.ts
|
|
857
952
|
var import_utils8 = require("@typescript-eslint/utils");
|
|
858
|
-
var
|
|
953
|
+
var import_typescript8 = __toESM(require("typescript"), 1);
|
|
859
954
|
var CONFIG2 = { path: "tsconfig.json", source: '{"compilerOptions":{"strict":true,"target":"ESNext","module":"ESNext","moduleResolution":"Bundler"}}' };
|
|
860
955
|
var EXAMPLE2 = 'export {}; const account = {name: "Ada", email: "a"}; function label(user: {readonly email: string; readonly name: string}): string {return user.name;} label(account);';
|
|
956
|
+
var HELPER_EXAMPLE = 'export {}; const account = {name: "Ada", email: "a"}; function formatName(name: string): string {return name.toUpperCase();} function label(user: {email: string; name: string}): string {return formatName(user.name);} label(account);';
|
|
861
957
|
var PREFER_MINIMAL_PARAMETER_CONTRACT_DOCUMENTATION = {
|
|
862
958
|
defaultLevel: "warning",
|
|
863
959
|
summary: "Prefer the proven read-only subset for a private consumer parameter.",
|
|
@@ -868,18 +964,20 @@ var PREFER_MINIMAL_PARAMETER_CONTRACT_DOCUMENTATION = {
|
|
|
868
964
|
limitations: [
|
|
869
965
|
"Automatic fixes additionally require every existing identifier caller to be natively assignable to the original contract, without Any, unknown, error or unresolved types on the relevant surface. Comments inside the annotation and TypeScript suppression directives keep the finding manual. Only unread required property signatures are removed; every read or optional member, modifier and terminator token is preserved. Edits that would merge distinct CR and LF terminators remain manual.",
|
|
870
966
|
"Requires parser-owned TypeScript information and a strict external module. Only top-level private function declarations and raw const arrows with exactly one explicit parameter and an independent broad primitive return annotation are supported. Every callable reference must be a direct call with one identifier argument; exports including type-only exports, typeof queries, callbacks, storage, constructors, contextual signatures, overloads, generics, decorators, async functions and direct eval prevent findings.",
|
|
871
|
-
"Only anonymous inline contracts made of
|
|
872
|
-
"The single return expression may use only fixed scalar field reads, flat destructuring, literals, operators and
|
|
967
|
+
"Only anonymous inline contracts made of broad string, number, boolean or bigint property types are supported. Fields may be plain or readonly; the consumer body must still prove read-only usage. Retained field modifiers and optional members are preserved. Named domain contracts, brands, literal discriminants, classes, methods, callbacks, indexes, mapped types and imported parameter contracts are excluded. At least one read required field and one unread required field must be established; all-optional reduced contracts can reject existing callers through weak-type checks.",
|
|
968
|
+
"The single return expression may use only fixed scalar field reads, flat destructuring, literals, operators, templates and scalar calls to same-file implemented top-level functions or raw const arrows with an explicit return annotation. These calls require one native resolved declaration, no generic or predicate signature, scalar arguments/result and complete active native checking of the local implementation file. Their helper bodies need not be pure because only scalar values cross the call and only an erased parameter annotation changes. Imported, aliased, ambient, overloaded, optional, spread and member calls remain unsupported. Bound destructured fields count as reads even when their local aliases are unused. Whole-object escape, identity, mutation, closures, reflection, serialization, dynamic keys, implicit Object capabilities and JSX are unsupported. Unknown semantic information causes abstention. Findings outside the fix proof remain manual; this is not a requirement to minimize every object or discard useful producer fields."
|
|
873
969
|
],
|
|
874
970
|
examples: [
|
|
875
971
|
{ id: "unused-required-field", title: "A private name consumer unnecessarily requires email", outcome: "match", files: [{ path: "src/case.ts", source: EXAMPLE2 }, CONFIG2], focusPath: "src/case.ts", expectedCount: 1, public: true, fixedFiles: [{ path: "src/case.ts", source: EXAMPLE2.replace("readonly email: string;", "") }] },
|
|
876
|
-
{ id: "used-fields", title: "Every required dependency is read", outcome: "no-match", files: [{ path: "src/case.ts", source: EXAMPLE2.replace("return user.name;", "return user.name + user.email;") }, CONFIG2], focusPath: "src/case.ts", expectedCount: 0, public: true }
|
|
972
|
+
{ id: "used-fields", title: "Every required dependency is read", outcome: "no-match", files: [{ path: "src/case.ts", source: EXAMPLE2.replace("return user.name;", "return user.name + user.email;") }, CONFIG2], focusPath: "src/case.ts", expectedCount: 0, public: true },
|
|
973
|
+
{ id: "scalar-helper", scenarioId: "local-scalar-helper", title: "Only the name crosses a local scalar helper call", outcome: "match", files: [{ path: "src/case.ts", source: HELPER_EXAMPLE }, CONFIG2], focusPath: "src/case.ts", expectedCount: 1, public: true, fixedFiles: [{ path: "src/case.ts", source: HELPER_EXAMPLE.replace("email: string;", "") }] },
|
|
974
|
+
{ id: "helper-and-other-field", scenarioId: "local-scalar-helper", title: "The consumer still requires a separately read field", outcome: "no-match", files: [{ path: "src/case.ts", source: HELPER_EXAMPLE.replace("return formatName(user.name);", "return formatName(user.name) + user.email;") }, CONFIG2], focusPath: "src/case.ts", expectedCount: 0, public: true }
|
|
877
975
|
]
|
|
878
976
|
};
|
|
879
977
|
function inlineFields(node) {
|
|
880
978
|
const fields = /* @__PURE__ */ new Map();
|
|
881
979
|
for (const member3 of node.members) {
|
|
882
|
-
if (!
|
|
980
|
+
if (!import_typescript8.default.isPropertySignature(member3) || !member3.name || !import_typescript8.default.isIdentifier(member3.name) && !import_typescript8.default.isStringLiteralLike(member3.name) || (member3.modifiers?.length ?? 0) > 1 || member3.modifiers?.some((modifier) => modifier.kind !== import_typescript8.default.SyntaxKind.ReadonlyKeyword) || !primitiveKeyword(member3.type)) return null;
|
|
883
981
|
const key = member3.name.text;
|
|
884
982
|
if (fields.has(key)) return null;
|
|
885
983
|
fields.set(key, !member3.questionToken);
|
|
@@ -890,7 +988,7 @@ var prefer_minimal_parameter_contract_default = createRule({
|
|
|
890
988
|
name: "prefer-minimal-parameter-contract",
|
|
891
989
|
documentation: PREFER_MINIMAL_PARAMETER_CONTRACT_DOCUMENTATION,
|
|
892
990
|
meta: { type: "suggestion", fixable: "code", docs: { description: PREFER_MINIMAL_PARAMETER_CONTRACT_DOCUMENTATION.summary }, schema: [], messages: {
|
|
893
|
-
minimal: "This private consumer reads only {{used}} but also requires {{unused}}. Review a smaller
|
|
991
|
+
minimal: "This private consumer reads only {{used}} but also requires {{unused}}. Review a smaller consumer contract; preserve the original runtime object and producer type."
|
|
894
992
|
} },
|
|
895
993
|
defaultOptions: [],
|
|
896
994
|
create(context) {
|
|
@@ -909,18 +1007,20 @@ var prefer_minimal_parameter_contract_default = createRule({
|
|
|
909
1007
|
"Program:exit"() {
|
|
910
1008
|
if (dynamic || !candidates.length) return;
|
|
911
1009
|
const services = import_utils8.ESLintUtils.getParserServices(context);
|
|
1010
|
+
const source = currentNativeSource(context.sourceCode, services);
|
|
1011
|
+
if (!source) return;
|
|
912
1012
|
const checker = services.program.getTypeChecker();
|
|
913
|
-
const exports2 = exportedSymbols(
|
|
1013
|
+
const exports2 = exportedSymbols(source, checker);
|
|
914
1014
|
for (const candidate2 of candidates) {
|
|
915
|
-
const consumer = privateScalarConsumer(candidate2, context.sourceCode, services, exports2);
|
|
1015
|
+
const consumer = privateScalarConsumer(candidate2, context.sourceCode, services, exports2, true);
|
|
916
1016
|
const annotation = consumer?.parameter.type;
|
|
917
|
-
if (!consumer || !annotation || !
|
|
1017
|
+
if (!consumer || !annotation || !import_typescript8.default.isTypeLiteralNode(annotation)) continue;
|
|
918
1018
|
const fields = inlineFields(annotation);
|
|
919
1019
|
if (!fields || [...consumer.reads].some((key) => !fields.has(key)) || ![...consumer.reads].some((key) => fields.get(key))) continue;
|
|
920
1020
|
const unused = [...fields].filter(([key, required]) => required && !consumer.reads.has(key)).map(([key]) => key).sort();
|
|
921
1021
|
if (!unused.length) continue;
|
|
922
1022
|
const reportNode = services.tsNodeToESTreeNodeMap.get(annotation);
|
|
923
|
-
const removed = annotation.members.filter((member3) =>
|
|
1023
|
+
const removed = annotation.members.filter((member3) => import_typescript8.default.isPropertySignature(member3) && member3.name && (import_typescript8.default.isIdentifier(member3.name) || import_typescript8.default.isStringLiteralLike(member3.name)) && unused.includes(member3.name.text)).map((member3) => ({ start: member3.getStart(), end: member3.getEnd() }));
|
|
924
1024
|
const fix = validConsumerFixCalls(candidate2, consumer.parameter, context.sourceCode, services) ? minimalConsumerFix(context.sourceCode, reportNode, removed) : null;
|
|
925
1025
|
context.report({ node: reportNode, messageId: "minimal", data: { used: [...consumer.reads].sort().join(", "), unused: unused.join(", ") }, fix });
|
|
926
1026
|
}
|
|
@@ -931,7 +1031,282 @@ var prefer_minimal_parameter_contract_default = createRule({
|
|
|
931
1031
|
|
|
932
1032
|
// src/rules/no-excess-jsx-props.ts
|
|
933
1033
|
var import_utils9 = require("@typescript-eslint/utils");
|
|
934
|
-
var
|
|
1034
|
+
var import_typescript10 = __toESM(require("typescript"), 1);
|
|
1035
|
+
|
|
1036
|
+
// src/rules/_ordinary-object-effects.ts
|
|
1037
|
+
var import_typescript9 = __toESM(require("typescript"), 1);
|
|
1038
|
+
var ANALYSES = /* @__PURE__ */ new WeakMap();
|
|
1039
|
+
var MAX_ALIAS_DEPTH = 64;
|
|
1040
|
+
var MAX_SOURCE_GRAPH = 128;
|
|
1041
|
+
var GLOBAL_IDENTITIES = [["Object", "object"], ["Reflect", "reflect"], ["globalThis", "globalThis"], ["eval", "dynamic"], ["Function", "dynamic"]];
|
|
1042
|
+
var OBJECT_REFLECTION = /* @__PURE__ */ new Set([
|
|
1043
|
+
"assign",
|
|
1044
|
+
"defineProperty",
|
|
1045
|
+
"defineProperties",
|
|
1046
|
+
"freeze",
|
|
1047
|
+
"seal",
|
|
1048
|
+
"preventExtensions",
|
|
1049
|
+
"setPrototypeOf",
|
|
1050
|
+
"getPrototypeOf",
|
|
1051
|
+
"getOwnPropertyDescriptor",
|
|
1052
|
+
"getOwnPropertyDescriptors"
|
|
1053
|
+
]);
|
|
1054
|
+
function ordinaryObjectEffects(program, source) {
|
|
1055
|
+
let analysis = ANALYSES.get(program);
|
|
1056
|
+
if (!analysis) {
|
|
1057
|
+
analysis = programFacts(program);
|
|
1058
|
+
ANALYSES.set(program, analysis);
|
|
1059
|
+
}
|
|
1060
|
+
const known2 = analysis.roots.get(source);
|
|
1061
|
+
if (known2 !== void 0) return known2;
|
|
1062
|
+
const visited = /* @__PURE__ */ new Set();
|
|
1063
|
+
const queue = [source];
|
|
1064
|
+
while (queue.length) {
|
|
1065
|
+
const current = queue.pop();
|
|
1066
|
+
if (!current || visited.has(current)) continue;
|
|
1067
|
+
if (analysis.roots.get(current) || visited.size >= MAX_SOURCE_GRAPH) {
|
|
1068
|
+
analysis.roots.set(source, true);
|
|
1069
|
+
return true;
|
|
1070
|
+
}
|
|
1071
|
+
visited.add(current);
|
|
1072
|
+
const facts = fileFacts(current, analysis);
|
|
1073
|
+
if (facts.unsafe || facts.jsx && !standardJSXRuntime(current, analysis) || analysis.aliasValues.has(current) && !checkedNativeSource(program, current)) {
|
|
1074
|
+
analysis.roots.set(source, true);
|
|
1075
|
+
return true;
|
|
1076
|
+
}
|
|
1077
|
+
queue.push(...facts.imports, ...analysis.importers.get(current) ?? []);
|
|
1078
|
+
}
|
|
1079
|
+
for (const file of visited) analysis.roots.set(file, false);
|
|
1080
|
+
return false;
|
|
1081
|
+
}
|
|
1082
|
+
function programFacts(program) {
|
|
1083
|
+
const checker = program.getTypeChecker();
|
|
1084
|
+
const globals = /* @__PURE__ */ new Map();
|
|
1085
|
+
for (const [name, identity2] of GLOBAL_IDENTITIES) {
|
|
1086
|
+
const symbol = checker.resolveName(name, void 0, import_typescript9.default.SymbolFlags.Value, false);
|
|
1087
|
+
if (symbol) globals.set(symbol, identity2);
|
|
1088
|
+
}
|
|
1089
|
+
const importers = /* @__PURE__ */ new Map();
|
|
1090
|
+
const analysis = { program, checker, globals, importers, aliasValues: /* @__PURE__ */ new WeakSet(), jsxRuntimes: /* @__PURE__ */ new WeakMap(), files: /* @__PURE__ */ new WeakMap(), roots: /* @__PURE__ */ new WeakMap() };
|
|
1091
|
+
for (const source of program.getSourceFiles()) {
|
|
1092
|
+
for (const dependency of fileFacts(source, analysis).imports) {
|
|
1093
|
+
let parents = importers.get(dependency);
|
|
1094
|
+
if (!parents) {
|
|
1095
|
+
parents = /* @__PURE__ */ new Set();
|
|
1096
|
+
importers.set(dependency, parents);
|
|
1097
|
+
}
|
|
1098
|
+
parents.add(source);
|
|
1099
|
+
}
|
|
1100
|
+
}
|
|
1101
|
+
return analysis;
|
|
1102
|
+
}
|
|
1103
|
+
function fileFacts(source, analysis) {
|
|
1104
|
+
let facts = analysis.files.get(source);
|
|
1105
|
+
if (!facts) {
|
|
1106
|
+
facts = sourceFacts(source, analysis);
|
|
1107
|
+
analysis.files.set(source, facts);
|
|
1108
|
+
}
|
|
1109
|
+
return facts;
|
|
1110
|
+
}
|
|
1111
|
+
function sourceFacts(source, analysis) {
|
|
1112
|
+
if (source.isDeclarationFile) return { unsafe: true, imports: [], jsx: false };
|
|
1113
|
+
const references = [];
|
|
1114
|
+
const imports = [];
|
|
1115
|
+
let unsafe = analysis.program.isSourceFileFromExternalLibrary(source);
|
|
1116
|
+
let jsx = false;
|
|
1117
|
+
const visit = (node) => {
|
|
1118
|
+
if (import_typescript9.default.isInterfaceDeclaration(node) || import_typescript9.default.isTypeAliasDeclaration(node) || import_typescript9.default.isTypeLiteralNode(node) || import_typescript9.default.isTypeQueryNode(node) || import_typescript9.default.isTypeReferenceNode(node) || import_typescript9.default.isImportTypeNode(node) || import_typescript9.default.isTypeParameterDeclaration(node) || import_typescript9.default.isHeritageClause(node) && node.token === import_typescript9.default.SyntaxKind.ImplementsKeyword) return;
|
|
1119
|
+
jsx ||= import_typescript9.default.isJsxElement(node) || import_typescript9.default.isJsxSelfClosingElement(node) || import_typescript9.default.isJsxFragment(node);
|
|
1120
|
+
const dependency = moduleEffect(node, imports, analysis);
|
|
1121
|
+
if (dependency !== void 0) unsafe ||= dependency;
|
|
1122
|
+
if (import_typescript9.default.isImportDeclaration(node) || import_typescript9.default.isExportDeclaration(node) && (node.isTypeOnly || node.moduleSpecifier) || import_typescript9.default.isExportSpecifier(node) && node.isTypeOnly) return;
|
|
1123
|
+
if (!unsafe) {
|
|
1124
|
+
if (import_typescript9.default.isIdentifier(node) || import_typescript9.default.isPropertyAccessExpression(node) || import_typescript9.default.isElementAccessExpression(node)) references.push(node);
|
|
1125
|
+
unsafe ||= runtimeEffect(node, analysis);
|
|
1126
|
+
}
|
|
1127
|
+
import_typescript9.default.forEachChild(node, visit);
|
|
1128
|
+
};
|
|
1129
|
+
visit(source);
|
|
1130
|
+
if (unsafe) return { unsafe, imports, jsx };
|
|
1131
|
+
for (const node of references) {
|
|
1132
|
+
if (reflectiveMember(node, analysis)) unsafe = true;
|
|
1133
|
+
const value = identity(node, analysis);
|
|
1134
|
+
if (value === "incomplete" || value === "dynamic" || protectedIdentity(value) && !containedUse(node)) unsafe = true;
|
|
1135
|
+
}
|
|
1136
|
+
return { unsafe, imports, jsx };
|
|
1137
|
+
}
|
|
1138
|
+
function moduleEffect(node, imports, analysis) {
|
|
1139
|
+
if (import_typescript9.default.isImportDeclaration(node) || import_typescript9.default.isExportDeclaration(node)) return !moduleDependency(node, imports, analysis);
|
|
1140
|
+
if (!import_typescript9.default.isCallExpression(node) || node.expression.kind !== import_typescript9.default.SyntaxKind.ImportKeyword) return void 0;
|
|
1141
|
+
const specifier = node.arguments[0];
|
|
1142
|
+
const resolved = specifier && import_typescript9.default.isStringLiteralLike(specifier) && resolvedDependency(specifier, imports, analysis);
|
|
1143
|
+
return node.arguments.length !== 1 || !resolved;
|
|
1144
|
+
}
|
|
1145
|
+
function runtimeEffect(node, analysis) {
|
|
1146
|
+
if (node.kind === import_typescript9.default.SyntaxKind.ThisKeyword || node.kind === import_typescript9.default.SyntaxKind.SuperKeyword || import_typescript9.default.isMetaProperty(node)) return true;
|
|
1147
|
+
if (import_typescript9.default.isVariableDeclaration(node)) return !node.initializer;
|
|
1148
|
+
if (import_typescript9.default.isFunctionDeclaration(node)) return !node.body;
|
|
1149
|
+
if (import_typescript9.default.isForOfStatement(node) || import_typescript9.default.isForInStatement(node) || import_typescript9.default.isNewExpression(node) || import_typescript9.default.isTaggedTemplateExpression(node)) return true;
|
|
1150
|
+
if (!import_typescript9.default.isCallExpression(node)) return mutationEffect(node, analysis);
|
|
1151
|
+
return node.expression.kind !== import_typescript9.default.SyntaxKind.ImportKeyword;
|
|
1152
|
+
}
|
|
1153
|
+
function mutationEffect(node, analysis) {
|
|
1154
|
+
if (import_typescript9.default.isBinaryExpression(node) && node.operatorToken.kind >= import_typescript9.default.SyntaxKind.FirstAssignment && node.operatorToken.kind <= import_typescript9.default.SyntaxKind.LastAssignment) return unsafeTarget(node.left, analysis);
|
|
1155
|
+
if (import_typescript9.default.isDeleteExpression(node)) return unsafeTarget(node.expression, analysis);
|
|
1156
|
+
return (import_typescript9.default.isPrefixUnaryExpression(node) || import_typescript9.default.isPostfixUnaryExpression(node)) && (node.operator === import_typescript9.default.SyntaxKind.PlusPlusToken || node.operator === import_typescript9.default.SyntaxKind.MinusMinusToken) && unsafeTarget(node.operand, analysis);
|
|
1157
|
+
}
|
|
1158
|
+
function identity(node, analysis, active = /* @__PURE__ */ new Set()) {
|
|
1159
|
+
const value = unassertedValue(node);
|
|
1160
|
+
if (active.has(value) || active.size >= MAX_ALIAS_DEPTH) return "incomplete";
|
|
1161
|
+
active.add(value);
|
|
1162
|
+
let result = "unknown";
|
|
1163
|
+
if (import_typescript9.default.isObjectLiteralExpression(value) || import_typescript9.default.isArrayLiteralExpression(value)) result = "fresh";
|
|
1164
|
+
else if (import_typescript9.default.isIdentifier(value)) result = identifierIdentity(value, analysis, active);
|
|
1165
|
+
else if (import_typescript9.default.isPropertyAccessExpression(value) || import_typescript9.default.isElementAccessExpression(value)) result = memberIdentity(value, analysis, active);
|
|
1166
|
+
active.delete(value);
|
|
1167
|
+
return result;
|
|
1168
|
+
}
|
|
1169
|
+
function identifierIdentity(value, analysis, active) {
|
|
1170
|
+
const parent = value.parent;
|
|
1171
|
+
if (nonValueName(value)) return "unknown";
|
|
1172
|
+
let symbol = import_typescript9.default.isShorthandPropertyAssignment(parent) && parent.name === value ? analysis.checker.getShorthandAssignmentValueSymbol(parent) : analysis.checker.getSymbolAtLocation(value);
|
|
1173
|
+
const alias = symbol !== void 0 && (symbol.flags & import_typescript9.default.SymbolFlags.Alias) !== 0;
|
|
1174
|
+
if (symbol && alias) symbol = analysis.checker.getAliasedSymbol(symbol);
|
|
1175
|
+
if (symbol && analysis.checker.isUnknownSymbol(symbol)) return "incomplete";
|
|
1176
|
+
if (!symbol || (symbol.flags & import_typescript9.default.SymbolFlags.Value) === 0) {
|
|
1177
|
+
const erasedBinding = import_typescript9.default.isModuleDeclaration(parent) && parent.name === value || import_typescript9.default.isExportSpecifier(parent) && symbol !== void 0 && (symbol.flags & (import_typescript9.default.SymbolFlags.Type | import_typescript9.default.SymbolFlags.Namespace)) !== 0;
|
|
1178
|
+
return erasedBinding ? "unknown" : "incomplete";
|
|
1179
|
+
}
|
|
1180
|
+
if (alias) analysis.aliasValues.add(value.getSourceFile());
|
|
1181
|
+
return runtimeBindingIdentity(value, symbol, alias, analysis, active);
|
|
1182
|
+
}
|
|
1183
|
+
function runtimeBindingIdentity(value, symbol, alias, analysis, active) {
|
|
1184
|
+
const parent = value.parent;
|
|
1185
|
+
if (symbol.declarations?.some(import_typescript9.default.isModuleDeclaration)) {
|
|
1186
|
+
return import_typescript9.default.isModuleDeclaration(parent) && parent.name === value && (import_typescript9.default.getCombinedModifierFlags(parent) & import_typescript9.default.ModifierFlags.Ambient) === 0 ? "unknown" : "incomplete";
|
|
1187
|
+
}
|
|
1188
|
+
if ((symbol.flags & import_typescript9.default.SymbolFlags.Property) !== 0) return "unknown";
|
|
1189
|
+
if ((symbol.flags & import_typescript9.default.SymbolFlags.ConstEnum) !== 0) return "incomplete";
|
|
1190
|
+
const global = analysis.globals.get(symbol);
|
|
1191
|
+
if (global !== void 0) return global;
|
|
1192
|
+
const declaration = symbol.valueDeclaration;
|
|
1193
|
+
if (declaration && !alias && declaration.getSourceFile() !== value.getSourceFile()) return "incomplete";
|
|
1194
|
+
if (declaration && (declaration.getSourceFile().isDeclarationFile || (import_typescript9.default.getCombinedModifierFlags(declaration) & import_typescript9.default.ModifierFlags.Ambient) !== 0)) return "incomplete";
|
|
1195
|
+
const initializer = constInitializer(declaration);
|
|
1196
|
+
return initializer ? identity(initializer, analysis, active) : "unknown";
|
|
1197
|
+
}
|
|
1198
|
+
function nonValueName(value) {
|
|
1199
|
+
const parent = value.parent;
|
|
1200
|
+
if ((import_typescript9.default.isPropertyAccessExpression(parent) || import_typescript9.default.isPropertyAssignment(parent) || import_typescript9.default.isJsxAttribute(parent) || import_typescript9.default.isEnumDeclaration(parent) || import_typescript9.default.isEnumMember(parent)) && parent.name === value) return true;
|
|
1201
|
+
if (import_typescript9.default.isBindingElement(parent) && parent.propertyName === value) return true;
|
|
1202
|
+
if ((import_typescript9.default.isLabeledStatement(parent) || import_typescript9.default.isBreakStatement(parent) || import_typescript9.default.isContinueStatement(parent)) && parent.label === value) return true;
|
|
1203
|
+
if (import_typescript9.default.isJsxNamespacedName(parent)) return true;
|
|
1204
|
+
return (import_typescript9.default.isJsxOpeningElement(parent) || import_typescript9.default.isJsxSelfClosingElement(parent) || import_typescript9.default.isJsxClosingElement(parent)) && parent.tagName === value && (/^[a-z]/u.test(value.text) || value.text.includes("-"));
|
|
1205
|
+
}
|
|
1206
|
+
function memberIdentity(value, analysis, active) {
|
|
1207
|
+
const base = identity(value.expression, analysis, active);
|
|
1208
|
+
if (base === "incomplete") return base;
|
|
1209
|
+
const key = memberKey(value);
|
|
1210
|
+
if (base === "object" && key === "prototype") return "prototype";
|
|
1211
|
+
if (base !== "globalThis" || key === void 0) return "unknown";
|
|
1212
|
+
const symbol = analysis.checker.resolveName(key, void 0, import_typescript9.default.SymbolFlags.Value, false);
|
|
1213
|
+
return symbol && analysis.globals.get(symbol) || "incomplete";
|
|
1214
|
+
}
|
|
1215
|
+
function memberKey(node) {
|
|
1216
|
+
if (import_typescript9.default.isPropertyAccessExpression(node)) return node.name.text;
|
|
1217
|
+
const key = node.argumentExpression && unassertedValue(node.argumentExpression);
|
|
1218
|
+
return key && (import_typescript9.default.isStringLiteralLike(key) || import_typescript9.default.isNumericLiteral(key)) ? key.text : void 0;
|
|
1219
|
+
}
|
|
1220
|
+
function protectedIdentity(value) {
|
|
1221
|
+
return value === "object" || value === "reflect" || value === "prototype" || value === "globalThis" || value === "dynamic";
|
|
1222
|
+
}
|
|
1223
|
+
function containedUse(node) {
|
|
1224
|
+
const value = expressionUse(node);
|
|
1225
|
+
const parent = value.parent;
|
|
1226
|
+
if (!parent) return false;
|
|
1227
|
+
if ((import_typescript9.default.isPropertyAccessExpression(parent) || import_typescript9.default.isElementAccessExpression(parent)) && parent.expression === value) return memberKey(parent) !== void 0;
|
|
1228
|
+
if (import_typescript9.default.isVariableDeclaration(parent) && parent.name === value) return true;
|
|
1229
|
+
if (import_typescript9.default.isVariableDeclaration(parent) && parent.initializer === value) {
|
|
1230
|
+
const statement = parent.parent.parent;
|
|
1231
|
+
return constInitializer(parent) !== void 0 && import_typescript9.default.isIdentifier(parent.name) && (!import_typescript9.default.isVariableStatement(statement) || !statement.modifiers?.some((modifier) => modifier.kind === import_typescript9.default.SyntaxKind.ExportKeyword));
|
|
1232
|
+
}
|
|
1233
|
+
return false;
|
|
1234
|
+
}
|
|
1235
|
+
function expressionUse(node) {
|
|
1236
|
+
let value = node;
|
|
1237
|
+
while (value.parent && unassertedValue(value.parent) === unassertedValue(value)) value = value.parent;
|
|
1238
|
+
return value;
|
|
1239
|
+
}
|
|
1240
|
+
function unsafeTarget(node, analysis) {
|
|
1241
|
+
const value = unassertedValue(node);
|
|
1242
|
+
if (import_typescript9.default.isIdentifier(value)) return protectedIdentity(identity(value, analysis));
|
|
1243
|
+
if (import_typescript9.default.isPropertyAccessExpression(value) || import_typescript9.default.isElementAccessExpression(value)) return identity(value.expression, analysis) !== "fresh";
|
|
1244
|
+
return true;
|
|
1245
|
+
}
|
|
1246
|
+
function reflectiveMember(node, analysis) {
|
|
1247
|
+
if (!import_typescript9.default.isPropertyAccessExpression(node) && !import_typescript9.default.isElementAccessExpression(node)) return false;
|
|
1248
|
+
const base = identity(node.expression, analysis);
|
|
1249
|
+
const key = memberKey(node);
|
|
1250
|
+
return base === "reflect" || base === "object" && (key === void 0 || OBJECT_REFLECTION.has(key));
|
|
1251
|
+
}
|
|
1252
|
+
function moduleDependency(node, imports, analysis) {
|
|
1253
|
+
if (import_typescript9.default.isImportDeclaration(node) && node.importClause?.isTypeOnly || import_typescript9.default.isExportDeclaration(node) && node.isTypeOnly) return true;
|
|
1254
|
+
const clause = import_typescript9.default.isImportDeclaration(node) ? node.importClause?.namedBindings : node.exportClause;
|
|
1255
|
+
const erasesNamedBindings = !analysis.program.getCompilerOptions().verbatimModuleSyntax;
|
|
1256
|
+
if (erasesNamedBindings && import_typescript9.default.isImportDeclaration(node) && clause && import_typescript9.default.isNamedImports(clause) && !node.importClause?.name && clause.elements.length && clause.elements.every((item) => item.isTypeOnly)) return true;
|
|
1257
|
+
if (erasesNamedBindings && clause && import_typescript9.default.isNamedExports(clause) && clause.elements.length && clause.elements.every((item) => item.isTypeOnly)) return true;
|
|
1258
|
+
if (!node.moduleSpecifier) return true;
|
|
1259
|
+
return resolvedDependency(node.moduleSpecifier, imports, analysis);
|
|
1260
|
+
}
|
|
1261
|
+
function resolvedDependency(specifier, imports, analysis) {
|
|
1262
|
+
const symbol = analysis.checker.getSymbolAtLocation(specifier);
|
|
1263
|
+
const declarations = symbol?.declarations;
|
|
1264
|
+
if (!declarations?.length) return false;
|
|
1265
|
+
let resolved = true;
|
|
1266
|
+
for (const declaration of declarations) {
|
|
1267
|
+
if (!import_typescript9.default.isSourceFile(declaration)) {
|
|
1268
|
+
resolved = false;
|
|
1269
|
+
continue;
|
|
1270
|
+
}
|
|
1271
|
+
imports.push(declaration);
|
|
1272
|
+
if (declaration.isDeclarationFile || analysis.program.isSourceFileFromExternalLibrary(declaration)) resolved = false;
|
|
1273
|
+
}
|
|
1274
|
+
return resolved;
|
|
1275
|
+
}
|
|
1276
|
+
function standardJSXRuntime(source, analysis) {
|
|
1277
|
+
const known2 = analysis.jsxRuntimes.get(source);
|
|
1278
|
+
if (known2 !== void 0) return known2;
|
|
1279
|
+
const standard = analysis.program.getSourceFile(source.fileName) === source && declaredJSXRuntime(source, analysis);
|
|
1280
|
+
analysis.jsxRuntimes.set(source, standard);
|
|
1281
|
+
return standard;
|
|
1282
|
+
}
|
|
1283
|
+
function declaredJSXRuntime(source, analysis) {
|
|
1284
|
+
const mode = analysis.program.getCompilerOptions().jsx;
|
|
1285
|
+
const name = mode === import_typescript9.default.JsxEmit.ReactJSX ? "react/jsx-runtime" : mode === import_typescript9.default.JsxEmit.ReactJSXDev ? "react/jsx-dev-runtime" : void 0;
|
|
1286
|
+
if (name === void 0) return false;
|
|
1287
|
+
const specifier = implicitJSXImport(source, name);
|
|
1288
|
+
const declarations = specifier && analysis.checker.getSymbolAtLocation(specifier)?.declarations;
|
|
1289
|
+
return declarations !== void 0 && declarations.length > 0 && declarations.every((declaration) => declaredReactRuntime(declaration, name, analysis.program));
|
|
1290
|
+
}
|
|
1291
|
+
function implicitJSXImport(source, name) {
|
|
1292
|
+
const imports = source.imports;
|
|
1293
|
+
if (!Array.isArray(imports)) return void 0;
|
|
1294
|
+
let selected;
|
|
1295
|
+
for (const node of imports) {
|
|
1296
|
+
if (!node || !import_typescript9.default.isStringLiteral(node) || node.text !== name || !node.parent || !import_typescript9.default.isImportDeclaration(node.parent) || node.parent.moduleSpecifier !== node || node.parent.parent !== source || source.statements.includes(node.parent) || node.getSourceFile() !== source) continue;
|
|
1297
|
+
if (selected) return void 0;
|
|
1298
|
+
selected = node;
|
|
1299
|
+
}
|
|
1300
|
+
return selected;
|
|
1301
|
+
}
|
|
1302
|
+
function declaredReactRuntime(declaration, name, program) {
|
|
1303
|
+
const source = declaration.getSourceFile();
|
|
1304
|
+
if (!source.isDeclarationFile || program.getSourceFile(source.fileName) !== source) return false;
|
|
1305
|
+
if (import_typescript9.default.isSourceFile(declaration)) return program.isSourceFileFromExternalLibrary(source);
|
|
1306
|
+
return import_typescript9.default.isModuleDeclaration(declaration) && declaration.parent === source && import_typescript9.default.isStringLiteral(declaration.name) && declaration.name.text === name;
|
|
1307
|
+
}
|
|
1308
|
+
|
|
1309
|
+
// src/rules/no-excess-jsx-props.ts
|
|
935
1310
|
var EXAMPLE_TSCONFIG = { path: "tsconfig.json", source: '{"compilerOptions":{"strict":true,"target":"ESNext","module":"ESNext","moduleResolution":"Bundler","jsx":"react-jsx"}}' };
|
|
936
1311
|
var EXAMPLE_JSX = { path: "jsx.d.ts", source: 'declare module "react/jsx-runtime" { export namespace JSX { interface Element {} interface IntrinsicElements {span: {children?: unknown}} } }' };
|
|
937
1312
|
var NO_EXCESS_JSX_PROPS_DOCUMENTATION = {
|
|
@@ -942,23 +1317,58 @@ var NO_EXCESS_JSX_PROPS_DOCUMENTATION = {
|
|
|
942
1317
|
defaultLevel: "warning",
|
|
943
1318
|
autofix: "none",
|
|
944
1319
|
limitations: [
|
|
1320
|
+
"The created JSX value must initialize a private actual const binding. Only unused values or same-function-scope fixed reads of already proven consumed scalar props are supported. Enclosing invocations must have no runtime argument or arguments-object dependency, async/generator suspension, or unproved captured values. Unused simple arguments and captured scalar data reuse the existing provenance proof; destructured/default/rest arguments remain unsupported. Exported, returned, aliased, captured, aggregated or forwarded elements, whole-props access, opaque calls, type observations and writes abstain. A caller can mutate production React props after creation even when development React freezes them; initial source provenance alone is insufficient. This restriction intentionally excludes ordinary exported and rendered elements until their consumers can be proved.",
|
|
1321
|
+
"The rule abstains when the receiving or calling project runtime dependency context contains a known ordinary Object-prototype effect or exposure, native eval/Function capabilities, any explicit call, constructor or tagged-template invocation, for-of or for-in iteration, an ambient or uninitialized value declaration or a declaration-file value read, an unresolved lexical value (including a shorthand or a type-only name used as a value), an erased const-enum value without a runtime binding proof, an opaque globalThis member, an implicit this/super/module-metadata capability, an extracted reflective method, or a member-write target not proven to be a fresh unrelated object/array literal. Callable and class metadata writes, including through erased const aliases, abstain: runtime metadata can observe omitted fields even when it is absent from the native JSX contract. Native shorthand value symbols preserve global capability identity instead of trusting a newly created property symbol. Property keys, control-flow labels, intrinsic JSX names and erased type positions do not evaluate lexical values; their missing symbols or Any types do not alone veto a finding. Native ESM imports/re-exports and literal dynamic imports are followed in both dependency and known-importer directions, including other dependencies of those importers and resolved bare path aliases; whole-clause import type/export type forms are skipped. Import-equals and other loader forms are unsupported. Per-specifier type imports/exports retain their runtime edges when native verbatimModuleSyntax emit keeps an empty import/export. Unresolved runtime imports and declaration-only or external-library runtime imports abstain. Literal dynamic imports retain their module-resolution proof. External code outside the analyzed project context and standard library implementations remain opaque; standard ordinary Object built-ins are assumed. Connected runtime dependency contexts beyond 128 files or const-alias proofs beyond 64 steps abstain. Safe reflective code may therefore be excluded. This finite known-effect exclusion does not prove universal prototype pristineness.",
|
|
945
1322
|
"Requires parser-owned TypeScript information, a strict module implementation, a complete Object base, a self-closing identifier tag with one plain object-literal spread and no other attributes, and one nongeneric implemented synchronous arrow receiver with a resolved finite props surface. Sibling attributes or children could override the proven source values. Unknown, opaque, union, overloaded, generic, intrinsic and class receivers are excluded.",
|
|
946
1323
|
"Mapped types, index signatures, namespace/value-derived contracts, unresolved inherited or computed receiver keys, nonliteral computed source keys, nested spreads, accessors and explicit __proto__ keys are excluded. Source type properties alone do not prove enumerable own runtime keys. key, ref, React's __self/__source development metadata and TypeScript's hyphenated JSX attribute names are preserved.",
|
|
947
1324
|
"Native member lookup includes inherited, optional, readonly and implicit Object capabilities. The rule reports runtime keys outside the contract; it does not infer unused component fields, demand smaller public APIs, or erase producer type information.",
|
|
948
|
-
"
|
|
1325
|
+
"Runtime alias references require active native checking of each reached local implementation, with no located syntax or semantic errors. Checking disabled by noCheck or native-shaped TypeScript suppression directives is unavailable evidence. JavaScript, declaration/default/external-library files, foreign SourceFile objects and project-reference programs are unsupported for this alias proof. Importer indexing does not request full semantic checks; reached files reuse the parser-owned Program's diagnostic caches. Unlocated/global diagnostics are not treated as a clean project or as proof of runtime binding presence. Namespace value reads, including merged and const-enum-only namespace carriers, abstain because a ValueModule symbol can survive erased runtime output without a native error. Pure type namespaces and nonambient namespace declaration names remain non-value positions; explicit ambient namespace declarations retain their existing exclusion. A non-import-alias value declared in another source also abstains: inclusion in the type Program does not establish that a script/global implementation executes or that an ambient binding is supplied as a data property. Native standard global identities retain their existing assumptions.",
|
|
1326
|
+
"Requires a single returned view made from intrinsic JSX, literals and scalar parameter reads/operators. JSX objects may be rendered as children or returned branches, but cannot be operands of scalar coercions or intrinsic attribute values. Free runtime values, helper calls, callbacks, object-valued consumed fields, custom tags, rest/spread, reflection and dynamic access prevent a finding; indirect element.props aliases cannot be inferred safe. Every inspected or destructured root field must be an own source-literal key; an omitted field could invoke an inherited getter. Bound/read source values require concrete scalar types without undefined, Any or unknown and runtime primitive provenance: literals, operators/templates with proven primitive operands, proven conditional tests and branches, or local immutable const initializers after removing assertions. Direct own fields of a same-file const object literal are supported only when every object reference is a fixed field value in a direct object initializer, inline JSX spread, JSX expression or local binding, with no direct eval. Mutation, accessors, method receivers, dynamic keys, reflection, whole-object aliases and exports abstain. Opaque calls, getters, parameters, mutable bindings and imported source values abstain even when annotated as scalars. Unproven source paths beyond 64 expressions abstain as an analysis resource limit. Only successful value proofs are memoized. An alias or assertion cannot turn an object into a primitive; undefined can activate runtime defaults. Opaque HOC and declaration-file signatures remain unsupported.",
|
|
949
1327
|
"The actual tag must resolve through immutable identifier aliases to a const arrow initializer. Constructible ordinary functions, mutable, member, proxy, call-produced and asserted receiver values are excluded even when their callable type resembles a known implementation; inherited runtime metadata can change ordinary function dispatch. Exactly one actual parameter and no explicit this parameter are supported.",
|
|
1328
|
+
"Reached files containing actual JSX additionally require their compiler-owned implicit runtime import and the native module symbol's declaration owners. Known non-declaration runtime implementations are unsupported even when their bodies have no ordinary Object effects: a custom factory can reinterpret forwarded fields. External declaration files and owned top-level ambient module declarations in declaration files retain the explicit standard-React library assumption; those declarations do not prove the actual runtime JavaScript identity. Missing or ambiguous internal import metadata, missing native symbols, foreign owners and local nonambient declaration-module sources abstain. Non-JSX dependencies do not acquire a runtime edge merely because the compiler records an unused synthetic JSX import. Runtime rebinding outside the compiler-visible module context remains opaque, not validated by this proof.",
|
|
950
1329
|
"Requires target ES2015 or newer, explicit native ES-module output and the standard React automatic JSX runtime (react-jsx or react-jsxdev). Downlevel arrows become constructible functions; CommonJS exports remain mutable. Preserve/classic JSX, custom factories, namespaces, import sources and per-file JSX directives are unsupported. Imported library implementations and cross-project source redirects are opaque; relative imports within this program remain supported."
|
|
951
1330
|
],
|
|
952
1331
|
references: ["https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-props-no-spreading.md"],
|
|
953
1332
|
examples: [
|
|
954
1333
|
{ id: "excess-runtime-field", title: "An unrelated field is forwarded at runtime", outcome: "match", files: [EXAMPLE_JSX, { path: "src/avatar.tsx", source: "export {}; const Avatar = ({ displayName }: { displayName: string }) => <span>{displayName}</span>;\nconst avatar = <Avatar {...{ displayName: 'Ada', email: 'ada@example.test' }} />;" }, EXAMPLE_TSCONFIG], focusPath: "src/avatar.tsx", expectedCount: 1, public: true },
|
|
955
|
-
{ id: "explicit-fields", title: "Forward only the declared field", outcome: "no-match", files: [EXAMPLE_JSX, { path: "src/avatar.tsx", source: "export {}; const Avatar = ({ displayName }: { displayName: string }) => <span>{displayName}</span>;\nconst avatar = <Avatar displayName='Ada' />;" }, EXAMPLE_TSCONFIG], focusPath: "src/avatar.tsx", expectedCount: 0, public: true }
|
|
1334
|
+
{ id: "explicit-fields", title: "Forward only the declared field", outcome: "no-match", files: [EXAMPLE_JSX, { path: "src/avatar.tsx", source: "export {}; const Avatar = ({ displayName }: { displayName: string }) => <span>{displayName}</span>;\nconst avatar = <Avatar displayName='Ada' />;" }, EXAMPLE_TSCONFIG], focusPath: "src/avatar.tsx", expectedCount: 0, public: true },
|
|
1335
|
+
{ id: "asserted-source-alias", scenarioId: "source-provenance", title: "An asserted alias can still observe forwarded data", outcome: "no-match", files: [EXAMPLE_JSX, { path: "src/avatar.tsx", source: "export {}; let element: any; const opaque = {toString() {return element.props.email;}}; const name = opaque as unknown as string; const Avatar = ({displayName}: {displayName: string}) => <span>{`${displayName}`}</span>; element = <Avatar {...{displayName: name, email: 'needed'}}/>;" }, EXAMPLE_TSCONFIG], focusPath: "src/avatar.tsx", expectedCount: 0, public: true },
|
|
1336
|
+
{ id: "literal-source-alias", scenarioId: "source-provenance", title: "A proven primitive alias preserves the finding", outcome: "match", files: [EXAMPLE_JSX, { path: "src/avatar.tsx", source: "export {}; const name = 'Ada'; const Avatar = ({displayName}: {displayName: string}) => <span>{`${displayName}`}</span>; const element = <Avatar {...{displayName: name, email: 'unused'}}/>;" }, EXAMPLE_TSCONFIG], focusPath: "src/avatar.tsx", expectedCount: 1, public: true },
|
|
1337
|
+
{ id: "inherited-runtime-hook", scenarioId: "prototype-effects", title: "An inherited runtime hook can observe forwarded data", outcome: "no-match", files: [EXAMPLE_JSX, { path: "src/avatar.tsx", source: "export {}; let element: any; const Avatar = ({displayName}: {displayName: string}) => <span>{displayName}</span>; element = <Avatar {...{displayName: 'Ada', email: 'needed'}}/>; Object.defineProperty(Object.prototype, 'ref', {configurable: true, get() {Object.defineProperty(this, 'children', {configurable: true, value: element.props.email}); return null;}});" }, EXAMPLE_TSCONFIG], focusPath: "src/avatar.tsx", expectedCount: 0, public: true },
|
|
1338
|
+
{ id: "unrelated-runtime-object", scenarioId: "prototype-effects", title: "An unrelated own-property write preserves the finding", outcome: "match", files: [EXAMPLE_JSX, { path: "src/avatar.tsx", source: "export {}; const target = {ref: null}; target.ref = null; const Avatar = ({displayName}: {displayName: string}) => <span>{displayName}</span>; const element = <Avatar {...{displayName: 'Ada', email: 'unused'}}/>;" }, EXAMPLE_TSCONFIG], focusPath: "src/avatar.tsx", expectedCount: 1, public: true },
|
|
1339
|
+
{ id: "erased-callable-metadata", scenarioId: "callable-metadata", title: "Runtime metadata can observe an omitted field", outcome: "no-match", files: [EXAMPLE_JSX, { path: "src/avatar.tsx", source: "export {}; const target = {ref: 0}; const Avatar = ({displayName}: {displayName: string}) => <span>{displayName}</span>; (Avatar as unknown as {defaultProps: {email: string}}).defaultProps = {get email() {target.ref = 1; return 'fallback';}}; const element = <Avatar {...{displayName: 'Ada', email: 'needed'}}/>; const observation = target.ref; export {observation};" }, EXAMPLE_TSCONFIG], focusPath: "src/avatar.tsx", expectedCount: 0, public: true },
|
|
1340
|
+
{ id: "unrelated-object-metadata", scenarioId: "callable-metadata", title: "An unrelated data object's metadata preserves the finding", outcome: "match", files: [EXAMPLE_JSX, { path: "src/avatar.tsx", source: "export {}; const settings = {defaultProps: {email: 'fallback'}}; settings.defaultProps = {email: 'updated'}; const Avatar = ({displayName}: {displayName: string}) => <span>{displayName}</span>; const element = <Avatar {...{displayName: 'Ada', email: 'unused'}}/>;" }, EXAMPLE_TSCONFIG], focusPath: "src/avatar.tsx", expectedCount: 1, public: true },
|
|
1341
|
+
{ id: "consumed-scalar-inspection", scenarioId: "created-value", title: "A private element exposes only its consumed scalar", outcome: "match", files: [EXAMPLE_JSX, { path: "src/avatar.tsx", source: "export {}; const Avatar = ({displayName}: {displayName: string}) => <span>{displayName}</span>; const element = <Avatar {...{displayName: 'Ada', email: 'unused'}}/>; const summary = {displayName: (element as {props: {displayName: string}}).props.displayName}; export {summary};" }, EXAMPLE_TSCONFIG], focusPath: "src/avatar.tsx", expectedCount: 1, public: true },
|
|
1342
|
+
{ id: "opaque-element-consumer", scenarioId: "created-value", title: "An opaque consumer can observe or mutate element props", outcome: "no-match", files: [EXAMPLE_JSX, { path: "src/avatar.tsx", source: "export {}; declare function inspect(value: unknown): void; const Avatar = ({displayName}: {displayName: string}) => <span>{displayName}</span>; const element = <Avatar {...{displayName: 'Ada', email: 'needed'}}/>; inspect(element);" }, EXAMPLE_TSCONFIG], focusPath: "src/avatar.tsx", expectedCount: 0, public: true }
|
|
956
1343
|
]
|
|
957
1344
|
};
|
|
958
1345
|
var RESERVED_PROPS = /* @__PURE__ */ new Set(["key", "ref", "__self", "__source"]);
|
|
959
|
-
var ESM_MODULES = /* @__PURE__ */ new Set([
|
|
1346
|
+
var ESM_MODULES = /* @__PURE__ */ new Set([import_typescript10.default.ModuleKind.ES2015, import_typescript10.default.ModuleKind.ES2020, import_typescript10.default.ModuleKind.ES2022, import_typescript10.default.ModuleKind.ESNext]);
|
|
960
1347
|
var JSX_DIRECTIVE = /@jsx(?:ImportSource|Runtime|Frag)?(?:\s|$)/iu;
|
|
961
|
-
|
|
1348
|
+
var MAX_VALUE_DEPTH = 64;
|
|
1349
|
+
var PRIMITIVE_OPERATORS = /* @__PURE__ */ new Set([
|
|
1350
|
+
import_typescript10.default.SyntaxKind.PlusToken,
|
|
1351
|
+
import_typescript10.default.SyntaxKind.MinusToken,
|
|
1352
|
+
import_typescript10.default.SyntaxKind.AsteriskToken,
|
|
1353
|
+
import_typescript10.default.SyntaxKind.SlashToken,
|
|
1354
|
+
import_typescript10.default.SyntaxKind.PercentToken,
|
|
1355
|
+
import_typescript10.default.SyntaxKind.AsteriskAsteriskToken,
|
|
1356
|
+
import_typescript10.default.SyntaxKind.LessThanToken,
|
|
1357
|
+
import_typescript10.default.SyntaxKind.LessThanEqualsToken,
|
|
1358
|
+
import_typescript10.default.SyntaxKind.GreaterThanToken,
|
|
1359
|
+
import_typescript10.default.SyntaxKind.GreaterThanEqualsToken,
|
|
1360
|
+
import_typescript10.default.SyntaxKind.EqualsEqualsEqualsToken,
|
|
1361
|
+
import_typescript10.default.SyntaxKind.ExclamationEqualsEqualsToken,
|
|
1362
|
+
import_typescript10.default.SyntaxKind.EqualsEqualsToken,
|
|
1363
|
+
import_typescript10.default.SyntaxKind.ExclamationEqualsToken,
|
|
1364
|
+
import_typescript10.default.SyntaxKind.AmpersandToken,
|
|
1365
|
+
import_typescript10.default.SyntaxKind.BarToken,
|
|
1366
|
+
import_typescript10.default.SyntaxKind.CaretToken,
|
|
1367
|
+
import_typescript10.default.SyntaxKind.LessThanLessThanToken,
|
|
1368
|
+
import_typescript10.default.SyntaxKind.GreaterThanGreaterThanToken,
|
|
1369
|
+
import_typescript10.default.SyntaxKind.GreaterThanGreaterThanGreaterThanToken
|
|
1370
|
+
]);
|
|
1371
|
+
function plainLiteralFields(node) {
|
|
962
1372
|
const fields = /* @__PURE__ */ new Map();
|
|
963
1373
|
for (const property of node.properties) {
|
|
964
1374
|
if (property.type !== import_utils9.AST_NODE_TYPES.Property || property.kind !== "init") return null;
|
|
@@ -968,20 +1378,27 @@ function literalFields(node) {
|
|
|
968
1378
|
else if (key.type === import_utils9.AST_NODE_TYPES.Literal && (typeof key.value === "string" || typeof key.value === "number")) name = String(key.value);
|
|
969
1379
|
else return null;
|
|
970
1380
|
if (name === "__proto__") return null;
|
|
971
|
-
|
|
1381
|
+
fields.set(name, property);
|
|
1382
|
+
}
|
|
1383
|
+
return fields;
|
|
1384
|
+
}
|
|
1385
|
+
function literalFields(node) {
|
|
1386
|
+
const fields = plainLiteralFields(node);
|
|
1387
|
+
if (fields) {
|
|
1388
|
+
for (const name of fields.keys()) if (RESERVED_PROPS.has(name) || name.includes("-")) fields.delete(name);
|
|
972
1389
|
}
|
|
973
1390
|
return fields;
|
|
974
1391
|
}
|
|
975
1392
|
function receiverReads(signature, checker) {
|
|
976
1393
|
const declaration = signature.getDeclaration();
|
|
977
|
-
if (!declaration || !
|
|
1394
|
+
if (!declaration || !import_typescript10.default.isArrowFunction(declaration) || declaration.modifiers?.some((modifier) => modifier.kind === import_typescript10.default.SyntaxKind.AsyncKeyword) || signature.thisParameter || declaration.parameters.length !== 1) return null;
|
|
978
1395
|
const parameter = declaration.parameters[0];
|
|
979
1396
|
return parameter ? scalarParameterView(parameter, declaration.body, checker) : null;
|
|
980
1397
|
}
|
|
981
1398
|
function stableReceiver(tag, signature, checker, program, overrides) {
|
|
982
|
-
if (!
|
|
1399
|
+
if (!import_typescript10.default.isIdentifier(tag)) return false;
|
|
983
1400
|
const initializer = immutableInitializer(tag, checker);
|
|
984
|
-
if (!initializer || initializer !== signature.getDeclaration() || !
|
|
1401
|
+
if (!initializer || initializer !== signature.getDeclaration() || !import_typescript10.default.isArrowFunction(initializer)) return false;
|
|
985
1402
|
return supportedImplementation(initializer.getSourceFile(), tag.getSourceFile(), program, overrides);
|
|
986
1403
|
}
|
|
987
1404
|
function immutableInitializer(tag, checker) {
|
|
@@ -989,37 +1406,31 @@ function immutableInitializer(tag, checker) {
|
|
|
989
1406
|
const seen = /* @__PURE__ */ new Set();
|
|
990
1407
|
while (symbol && !seen.has(symbol)) {
|
|
991
1408
|
seen.add(symbol);
|
|
992
|
-
if ((symbol.flags &
|
|
1409
|
+
if ((symbol.flags & import_typescript10.default.SymbolFlags.Alias) !== 0) {
|
|
993
1410
|
symbol = checker.getAliasedSymbol(symbol);
|
|
994
1411
|
continue;
|
|
995
1412
|
}
|
|
996
1413
|
const initializer = constInitializer(symbol.valueDeclaration);
|
|
997
|
-
if (!initializer || !
|
|
1414
|
+
if (!initializer || !import_typescript10.default.isIdentifier(initializer)) return initializer;
|
|
998
1415
|
symbol = checker.getSymbolAtLocation(initializer);
|
|
999
1416
|
}
|
|
1000
1417
|
return void 0;
|
|
1001
1418
|
}
|
|
1002
|
-
function constInitializer(declaration) {
|
|
1003
|
-
if (!declaration || !import_typescript7.default.isVariableDeclaration(declaration) || !import_typescript7.default.isVariableDeclarationList(declaration.parent) || (declaration.parent.flags & import_typescript7.default.NodeFlags.Const) === 0) return void 0;
|
|
1004
|
-
let initializer = declaration.initializer;
|
|
1005
|
-
while (initializer && import_typescript7.default.isParenthesizedExpression(initializer)) initializer = initializer.expression;
|
|
1006
|
-
return initializer;
|
|
1007
|
-
}
|
|
1008
1419
|
function supportedImplementation(source, caller, program, overrides) {
|
|
1009
|
-
if (!
|
|
1420
|
+
if (!import_typescript10.default.isExternalModule(source) || source.impliedNodeFormat === import_typescript10.default.ModuleKind.CommonJS || program.isSourceFileFromExternalLibrary(source)) return false;
|
|
1010
1421
|
if (source === caller) return true;
|
|
1011
1422
|
if (program.getProjectReferences()?.length) return false;
|
|
1012
|
-
if (!overrides.has(source)) overrides.set(source, (
|
|
1423
|
+
if (!overrides.has(source)) overrides.set(source, (import_typescript10.default.getLeadingCommentRanges(source.text, 0) ?? []).some((range) => JSX_DIRECTIVE.test(source.text.slice(range.pos, range.end))));
|
|
1013
1424
|
return !overrides.get(source);
|
|
1014
1425
|
}
|
|
1015
1426
|
function supportedJSX(options, comments) {
|
|
1016
|
-
return (options.target ??
|
|
1427
|
+
return (options.target ?? import_typescript10.default.ScriptTarget.ES5) >= import_typescript10.default.ScriptTarget.ES2015 && ESM_MODULES.has(options.module ?? import_typescript10.default.ModuleKind.None) && (options.jsx === import_typescript10.default.JsxEmit.ReactJSX || options.jsx === import_typescript10.default.JsxEmit.ReactJSXDev) && !options.jsxFactory && !options.reactNamespace && (!options.jsxImportSource || options.jsxImportSource === "react") && !comments.some((comment) => JSX_DIRECTIVE.test(comment.value));
|
|
1017
1428
|
}
|
|
1018
1429
|
function receivingContract(opening, services, checker, contracts) {
|
|
1019
1430
|
const native = services.esTreeNodeToTSNodeMap.get(opening);
|
|
1020
|
-
if (!
|
|
1431
|
+
if (!import_typescript10.default.isJsxOpeningElement(native) && !import_typescript10.default.isJsxSelfClosingElement(native)) return null;
|
|
1021
1432
|
const receiver = checker.getTypeAtLocation(native.tagName);
|
|
1022
|
-
const signatures = checker.getSignaturesOfType(receiver,
|
|
1433
|
+
const signatures = checker.getSignaturesOfType(receiver, import_typescript10.default.SignatureKind.Call);
|
|
1023
1434
|
const signature = signatures[0];
|
|
1024
1435
|
if (receiver.isUnion() || signatures.length !== 1 || !signature || signature.typeParameters?.length) return null;
|
|
1025
1436
|
const props = checker.getContextualType(native.attributes);
|
|
@@ -1027,19 +1438,132 @@ function receivingContract(opening, services, checker, contracts) {
|
|
|
1027
1438
|
if (!contracts.has(props)) contracts.set(props, closedObjectContract(props, checker));
|
|
1028
1439
|
return contracts.get(props) ? { tag: native.tagName, signature, props } : null;
|
|
1029
1440
|
}
|
|
1030
|
-
function ownScalarReads(fields, reads,
|
|
1441
|
+
function ownScalarReads(fields, reads, proof) {
|
|
1031
1442
|
for (const key of reads) {
|
|
1032
1443
|
const field = fields.get(key);
|
|
1033
1444
|
if (!field) return false;
|
|
1034
|
-
|
|
1035
|
-
if (!scalarType(checker.getTypeAtLocation(value), false)) return false;
|
|
1445
|
+
if (!primitiveValue(proof.services.esTreeNodeToTSNodeMap.get(field.value), proof, /* @__PURE__ */ new Set())) return false;
|
|
1036
1446
|
}
|
|
1037
1447
|
return true;
|
|
1038
1448
|
}
|
|
1039
|
-
function
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
return
|
|
1449
|
+
function primitiveValue(node, proof, active) {
|
|
1450
|
+
const value = unassertedValue(node);
|
|
1451
|
+
if (proof.values.has(value)) return true;
|
|
1452
|
+
if (active.has(value) || active.size >= MAX_VALUE_DEPTH) return false;
|
|
1453
|
+
active.add(value);
|
|
1454
|
+
const result = scalarType(proof.checker.getTypeAtLocation(value), false) && primitiveResult(value, proof, active);
|
|
1455
|
+
active.delete(value);
|
|
1456
|
+
if (result) proof.values.add(value);
|
|
1457
|
+
return result;
|
|
1458
|
+
}
|
|
1459
|
+
function primitiveResult(value, proof, active) {
|
|
1460
|
+
if (import_typescript10.default.isStringLiteralLike(value) || import_typescript10.default.isNumericLiteral(value) || import_typescript10.default.isBigIntLiteral(value) || value.kind === import_typescript10.default.SyntaxKind.TrueKeyword || value.kind === import_typescript10.default.SyntaxKind.FalseKeyword || value.kind === import_typescript10.default.SyntaxKind.NullKeyword) return true;
|
|
1461
|
+
if (import_typescript10.default.isTemplateExpression(value)) return value.templateSpans.every((span) => primitiveValue(span.expression, proof, active));
|
|
1462
|
+
if (import_typescript10.default.isTypeOfExpression(value)) return primitiveValue(value.expression, proof, active);
|
|
1463
|
+
if (import_typescript10.default.isPrefixUnaryExpression(value)) return (value.operator === import_typescript10.default.SyntaxKind.PlusToken || value.operator === import_typescript10.default.SyntaxKind.MinusToken || value.operator === import_typescript10.default.SyntaxKind.ExclamationToken || value.operator === import_typescript10.default.SyntaxKind.TildeToken) && primitiveValue(value.operand, proof, active);
|
|
1464
|
+
if (import_typescript10.default.isConditionalExpression(value)) return primitiveValue(value.condition, proof, active) && primitiveValue(value.whenTrue, proof, active) && primitiveValue(value.whenFalse, proof, active);
|
|
1465
|
+
if (import_typescript10.default.isBinaryExpression(value)) {
|
|
1466
|
+
return (PRIMITIVE_OPERATORS.has(value.operatorToken.kind) || RETURNED_OPERANDS.has(value.operatorToken.kind) || value.operatorToken.kind === import_typescript10.default.SyntaxKind.CommaToken) && primitiveValue(value.left, proof, active) && primitiveValue(value.right, proof, active);
|
|
1467
|
+
}
|
|
1468
|
+
if (import_typescript10.default.isPropertyAccessExpression(value) || import_typescript10.default.isElementAccessExpression(value)) return primitiveMember(value, proof, active);
|
|
1469
|
+
if (!import_typescript10.default.isIdentifier(value)) return false;
|
|
1470
|
+
const symbol = import_typescript10.default.isShorthandPropertyAssignment(value.parent) ? proof.checker.getShorthandAssignmentValueSymbol(value.parent) : proof.checker.getSymbolAtLocation(value);
|
|
1471
|
+
const initializer = symbol && (symbol.flags & import_typescript10.default.SymbolFlags.Alias) === 0 ? constInitializer(symbol.valueDeclaration) : void 0;
|
|
1472
|
+
return initializer !== void 0 && initializer.getSourceFile() === value.getSourceFile() && primitiveValue(initializer, proof, active);
|
|
1473
|
+
}
|
|
1474
|
+
function primitiveMember(node, proof, active) {
|
|
1475
|
+
if (!proof.staticScope || !import_typescript10.default.isIdentifier(node.expression)) return false;
|
|
1476
|
+
const key = import_typescript10.default.isPropertyAccessExpression(node) ? node.name.text : node.argumentExpression && (import_typescript10.default.isStringLiteralLike(node.argumentExpression) || import_typescript10.default.isNumericLiteral(node.argumentExpression)) ? node.argumentExpression.text : void 0;
|
|
1477
|
+
const symbol = proof.checker.getSymbolAtLocation(node.expression);
|
|
1478
|
+
if (!symbol || key === void 0 || (symbol.flags & import_typescript10.default.SymbolFlags.Alias) !== 0) return false;
|
|
1479
|
+
if (!proof.objects.has(symbol)) proof.objects.set(symbol, localObjectFields(symbol, node.getSourceFile(), proof));
|
|
1480
|
+
const field = proof.objects.get(symbol)?.get(key);
|
|
1481
|
+
return field !== void 0 && primitiveValue(proof.services.esTreeNodeToTSNodeMap.get(field.value), proof, active);
|
|
1482
|
+
}
|
|
1483
|
+
function localObjectFields(symbol, source, proof) {
|
|
1484
|
+
const native = symbol.valueDeclaration;
|
|
1485
|
+
const initial = constInitializer(native);
|
|
1486
|
+
const initializer = initial && unassertedValue(initial);
|
|
1487
|
+
if (!native || native.getSourceFile() !== source || !initializer || !import_typescript10.default.isObjectLiteralExpression(initializer)) return null;
|
|
1488
|
+
const declaration = proof.services.tsNodeToESTreeNodeMap.get(native);
|
|
1489
|
+
const literal2 = proof.services.tsNodeToESTreeNodeMap.get(initializer);
|
|
1490
|
+
if (declaration.type !== import_utils9.AST_NODE_TYPES.VariableDeclarator || declaration.parent.kind !== "const" || declaration.id.type !== import_utils9.AST_NODE_TYPES.Identifier || literal2.type !== import_utils9.AST_NODE_TYPES.ObjectExpression || declaration.parent.parent.type === import_utils9.AST_NODE_TYPES.ExportNamedDeclaration) return null;
|
|
1491
|
+
const fields = plainLiteralFields(literal2);
|
|
1492
|
+
const binding3 = proof.sourceCode.getDeclaredVariables(declaration).find((variable) => variable.defs.some((definition) => definition.type === "Variable" && definition.node === declaration));
|
|
1493
|
+
if (!fields || !binding3 || binding3.defs.length !== 1 || !stableValueBinding(binding3, (reference) => {
|
|
1494
|
+
if (!reference.isReadOnly() || reference.isTypeReference) return false;
|
|
1495
|
+
const member3 = reference.identifier.parent;
|
|
1496
|
+
return member3.type === import_utils9.AST_NODE_TYPES.MemberExpression && member3.object === reference.identifier && readonlyFieldValue(member3, fields);
|
|
1497
|
+
})) return null;
|
|
1498
|
+
return fields;
|
|
1499
|
+
}
|
|
1500
|
+
function staticMemberKey(member3) {
|
|
1501
|
+
const property = member3.property;
|
|
1502
|
+
return !member3.computed && property.type === import_utils9.AST_NODE_TYPES.Identifier ? property.name : property.type === import_utils9.AST_NODE_TYPES.Literal && (typeof property.value === "string" || typeof property.value === "number") ? String(property.value) : void 0;
|
|
1503
|
+
}
|
|
1504
|
+
function readonlyFieldValue(member3, fields) {
|
|
1505
|
+
const key = staticMemberKey(member3);
|
|
1506
|
+
if (key === void 0 || !fields.has(key)) return false;
|
|
1507
|
+
const parent = member3.parent;
|
|
1508
|
+
if (parent.type === import_utils9.AST_NODE_TYPES.Property && parent.value === member3 && parent.parent.type === import_utils9.AST_NODE_TYPES.ObjectExpression) {
|
|
1509
|
+
const object = parent.parent;
|
|
1510
|
+
const owner = object.parent;
|
|
1511
|
+
return owner.type === import_utils9.AST_NODE_TYPES.JSXSpreadAttribute && owner.argument === object || owner.type === import_utils9.AST_NODE_TYPES.VariableDeclarator && owner.init === object;
|
|
1512
|
+
}
|
|
1513
|
+
return parent.type === import_utils9.AST_NODE_TYPES.JSXExpressionContainer && parent.expression === member3 || parent.type === import_utils9.AST_NODE_TYPES.VariableDeclarator && parent.init === member3;
|
|
1514
|
+
}
|
|
1515
|
+
function privateElementDeclaration(opening) {
|
|
1516
|
+
const value = outerExpression(opening.parent);
|
|
1517
|
+
const declaration = value.parent;
|
|
1518
|
+
return declaration.type === import_utils9.AST_NODE_TYPES.VariableDeclarator && declaration.init === value && declaration.id.type === import_utils9.AST_NODE_TYPES.Identifier && declaration.parent.kind === "const" && declaration.parent.parent.type !== import_utils9.AST_NODE_TYPES.ExportNamedDeclaration ? declaration : null;
|
|
1519
|
+
}
|
|
1520
|
+
function closedElementValue(opening, declaration, fields, reads, proof) {
|
|
1521
|
+
if (!proof.staticScope || !closedInvocation(opening, proof) || !constInitializer(proof.services.esTreeNodeToTSNodeMap.get(declaration))) return false;
|
|
1522
|
+
const binding3 = proof.sourceCode.getDeclaredVariables(declaration).find((variable) => variable.defs.some((definition) => definition.type === "Variable" && definition.node === declaration));
|
|
1523
|
+
const symbol = proof.checker.getSymbolAtLocation(proof.services.esTreeNodeToTSNodeMap.get(declaration.id));
|
|
1524
|
+
if (!symbol || proof.exports.has(symbol)) return false;
|
|
1525
|
+
return binding3 !== void 0 && binding3.defs.length === 1 && stableValueBinding(binding3, (reference) => {
|
|
1526
|
+
if (!reference.isReadOnly() || reference.isTypeReference || reference.from.variableScope !== binding3.scope.variableScope) return false;
|
|
1527
|
+
return consumedElementRead(reference.identifier, fields, reads);
|
|
1528
|
+
});
|
|
1529
|
+
}
|
|
1530
|
+
function closedInvocation(node, proof) {
|
|
1531
|
+
for (let scope = proof.sourceCode.getScope(node); scope; scope = scope.upper) {
|
|
1532
|
+
if (scope.type !== "function") continue;
|
|
1533
|
+
let closed = proof.invocations.get(scope);
|
|
1534
|
+
if (closed === void 0) {
|
|
1535
|
+
closed = independentInvocation(scope, proof);
|
|
1536
|
+
proof.invocations.set(scope, closed);
|
|
1537
|
+
}
|
|
1538
|
+
if (!closed) return false;
|
|
1539
|
+
}
|
|
1540
|
+
return true;
|
|
1541
|
+
}
|
|
1542
|
+
function independentInvocation(scope, proof) {
|
|
1543
|
+
const block = scope.block;
|
|
1544
|
+
if (block.type !== import_utils9.AST_NODE_TYPES.ArrowFunctionExpression && block.type !== import_utils9.AST_NODE_TYPES.FunctionDeclaration && block.type !== import_utils9.AST_NODE_TYPES.FunctionExpression) return false;
|
|
1545
|
+
if (block.async || block.generator || scope.set.get("arguments")?.references.some((reference) => !typeOnlyReference(reference))) return false;
|
|
1546
|
+
for (const parameter of block.params) {
|
|
1547
|
+
if (parameter.type !== import_utils9.AST_NODE_TYPES.Identifier || parameter.name === "this") return false;
|
|
1548
|
+
const binding3 = scope.set.get(parameter.name);
|
|
1549
|
+
if (!binding3 || binding3.references.some((reference) => !typeOnlyReference(reference))) return false;
|
|
1550
|
+
}
|
|
1551
|
+
return scope.through.every((reference) => {
|
|
1552
|
+
if (typeOnlyReference(reference)) return true;
|
|
1553
|
+
const value = outerExpression(reference.identifier);
|
|
1554
|
+
const parent = value.parent;
|
|
1555
|
+
const read = parent?.type === import_utils9.AST_NODE_TYPES.MemberExpression && parent.object === value ? parent : value;
|
|
1556
|
+
return primitiveValue(proof.services.esTreeNodeToTSNodeMap.get(read), proof, /* @__PURE__ */ new Set());
|
|
1557
|
+
});
|
|
1558
|
+
}
|
|
1559
|
+
function consumedElementRead(node, fields, reads) {
|
|
1560
|
+
const identifier = outerExpression(node);
|
|
1561
|
+
const props = identifier.parent;
|
|
1562
|
+
if (!props || props.type !== import_utils9.AST_NODE_TYPES.MemberExpression || props.object !== identifier || props.optional || staticMemberKey(props) !== "props") return false;
|
|
1563
|
+
const member3 = props.parent;
|
|
1564
|
+
if (member3.type !== import_utils9.AST_NODE_TYPES.MemberExpression || member3.object !== props || member3.optional) return false;
|
|
1565
|
+
const key = staticMemberKey(member3);
|
|
1566
|
+
return key !== void 0 && reads.has(key) && readonlyFieldValue(member3, fields);
|
|
1043
1567
|
}
|
|
1044
1568
|
var no_excess_jsx_props_default = createRule({
|
|
1045
1569
|
name: "no-excess-jsx-props",
|
|
@@ -1058,33 +1582,63 @@ var no_excess_jsx_props_default = createRule({
|
|
|
1058
1582
|
const contracts = /* @__PURE__ */ new WeakMap();
|
|
1059
1583
|
const receivers = /* @__PURE__ */ new WeakMap();
|
|
1060
1584
|
const overrides = /* @__PURE__ */ new WeakMap();
|
|
1585
|
+
let proof;
|
|
1586
|
+
let dynamic = false;
|
|
1587
|
+
const candidates = [];
|
|
1061
1588
|
let standardJSX;
|
|
1589
|
+
const evaluate = (node, declaration, fields) => {
|
|
1590
|
+
const keys = [...fields.keys()];
|
|
1591
|
+
const opening = node.parent;
|
|
1592
|
+
services ??= import_utils9.ESLintUtils.getParserServices(context);
|
|
1593
|
+
standardJSX ??= supportedJSX(services.program.getCompilerOptions(), context.sourceCode.getAllComments());
|
|
1594
|
+
if (!standardJSX) return;
|
|
1595
|
+
const checker = services.program.getTypeChecker();
|
|
1596
|
+
if (objectContract2 === void 0) {
|
|
1597
|
+
const object = checker.resolveName("Object", void 0, import_typescript10.default.SymbolFlags.Type, false);
|
|
1598
|
+
objectContract2 = object !== void 0 && closedObjectContract(checker.getDeclaredTypeOfSymbol(object), checker);
|
|
1599
|
+
}
|
|
1600
|
+
if (!objectContract2) return;
|
|
1601
|
+
const contract = receivingContract(opening, services, checker, contracts);
|
|
1602
|
+
if (!contract) return;
|
|
1603
|
+
const excess = keys.filter((key) => checker.getPropertyOfType(contract.props, key) === void 0).sort();
|
|
1604
|
+
if (!excess.length || !stableReceiver(contract.tag, contract.signature, checker, services.program, overrides)) return;
|
|
1605
|
+
const signature = contract.signature;
|
|
1606
|
+
if (!receivers.has(signature)) receivers.set(signature, receiverReads(signature, checker));
|
|
1607
|
+
const reads = receivers.get(signature);
|
|
1608
|
+
proof ??= {
|
|
1609
|
+
checker,
|
|
1610
|
+
services,
|
|
1611
|
+
sourceCode: context.sourceCode,
|
|
1612
|
+
staticScope: !dynamic,
|
|
1613
|
+
exports: exportedSymbols(services.esTreeNodeToTSNodeMap.get(context.sourceCode.ast), checker),
|
|
1614
|
+
values: /* @__PURE__ */ new WeakSet(),
|
|
1615
|
+
objects: /* @__PURE__ */ new WeakMap(),
|
|
1616
|
+
invocations: /* @__PURE__ */ new WeakMap()
|
|
1617
|
+
};
|
|
1618
|
+
if (!reads || !ownScalarReads(fields, reads, proof) || !closedElementValue(opening, declaration, fields, reads, proof)) return;
|
|
1619
|
+
const implementation = signature.getDeclaration();
|
|
1620
|
+
if (!implementation || ordinaryObjectEffects(services.program, contract.tag.getSourceFile()) || ordinaryObjectEffects(services.program, implementation.getSourceFile())) return;
|
|
1621
|
+
context.report({ node, messageId: "excess", data: { fields: excess.join(", ") } });
|
|
1622
|
+
};
|
|
1062
1623
|
return {
|
|
1063
1624
|
JSXSpreadAttribute(node) {
|
|
1064
1625
|
if (node.argument.type !== import_utils9.AST_NODE_TYPES.ObjectExpression) return;
|
|
1065
|
-
const fields = literalFields(node.argument);
|
|
1066
|
-
if (!fields?.size) return;
|
|
1067
|
-
const keys = [...fields.keys()];
|
|
1068
1626
|
const opening = node.parent;
|
|
1069
1627
|
if (!opening.selfClosing || opening.attributes.length !== 1 || opening.name.type !== import_utils9.AST_NODE_TYPES.JSXIdentifier || /^[a-z]/u.test(opening.name.name)) return;
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
if (!
|
|
1081
|
-
|
|
1082
|
-
if (!
|
|
1083
|
-
const
|
|
1084
|
-
if (!receivers.has(signature)) receivers.set(signature, receiverReads(signature, checker));
|
|
1085
|
-
const reads = receivers.get(signature);
|
|
1086
|
-
if (!reads || !ownScalarReads(fields, reads, services, checker)) return;
|
|
1087
|
-
context.report({ node, messageId: "excess", data: { fields: excess.join(", ") } });
|
|
1628
|
+
const declaration = privateElementDeclaration(opening);
|
|
1629
|
+
if (!declaration) return;
|
|
1630
|
+
const fields = literalFields(node.argument);
|
|
1631
|
+
if (!fields?.size) return;
|
|
1632
|
+
candidates.push({ node, declaration, fields });
|
|
1633
|
+
},
|
|
1634
|
+
CallExpression(node) {
|
|
1635
|
+
if (directEval(node)) dynamic = true;
|
|
1636
|
+
},
|
|
1637
|
+
"Program:exit"() {
|
|
1638
|
+
if (!candidates.length) return;
|
|
1639
|
+
services = import_utils9.ESLintUtils.getParserServices(context);
|
|
1640
|
+
if (!currentNativeSource(context.sourceCode, services)) return;
|
|
1641
|
+
for (const { node, declaration, fields } of candidates) evaluate(node, declaration, fields);
|
|
1088
1642
|
}
|
|
1089
1643
|
};
|
|
1090
1644
|
}
|
|
@@ -1580,7 +2134,7 @@ function isSearchParamReceiver(call, services) {
|
|
|
1580
2134
|
// package.json
|
|
1581
2135
|
var package_default = {
|
|
1582
2136
|
name: "@sarj/eslint-plugin",
|
|
1583
|
-
version: "16.32.
|
|
2137
|
+
version: "16.32.3",
|
|
1584
2138
|
packageManager: "npm@12.2.1",
|
|
1585
2139
|
description: "Custom ESLint rules for hypermodern TypeScript / React / Next.js projects",
|
|
1586
2140
|
type: "module",
|
|
@@ -1703,26 +2257,26 @@ var package_default = {
|
|
|
1703
2257
|
|
|
1704
2258
|
// src/rules/require-explicit-contract-implementation.ts
|
|
1705
2259
|
var import_utils15 = require("@typescript-eslint/utils");
|
|
1706
|
-
var
|
|
2260
|
+
var ts12 = __toESM(require("typescript"), 1);
|
|
1707
2261
|
|
|
1708
2262
|
// src/rules/_closed-nominal-inheritance-fix.ts
|
|
1709
2263
|
var import_utils14 = require("@typescript-eslint/utils");
|
|
1710
|
-
var
|
|
2264
|
+
var import_typescript11 = __toESM(require("typescript"), 1);
|
|
1711
2265
|
function closedNominalInheritanceFix(sourceCode, call, consumer, implementation, contract) {
|
|
1712
2266
|
const source = call.getSourceFile();
|
|
1713
2267
|
if (source.text !== sourceCode.text || source.statements.length !== 5 || sourceCode.getAllComments().length > 0 || [consumer, implementation, contract].some(
|
|
1714
2268
|
(node) => node.getSourceFile() !== source
|
|
1715
2269
|
))
|
|
1716
2270
|
return null;
|
|
1717
|
-
const markers = source.statements.filter(
|
|
2271
|
+
const markers = source.statements.filter(import_typescript11.default.isExportDeclaration);
|
|
1718
2272
|
if (markers.length !== 1 || markers[0] === void 0 || !emptyModuleMarker(markers[0]))
|
|
1719
2273
|
return null;
|
|
1720
2274
|
const statements = source.statements.filter(
|
|
1721
|
-
(node) => !
|
|
2275
|
+
(node) => !import_typescript11.default.isExportDeclaration(node)
|
|
1722
2276
|
);
|
|
1723
|
-
if (statements[0] !== contract || statements[1] !== consumer || statements[2] !== implementation || statements[3] === void 0 || !
|
|
2277
|
+
if (statements[0] !== contract || statements[1] !== consumer || statements[2] !== implementation || statements[3] === void 0 || !import_typescript11.default.isExpressionStatement(statements[3]) || statements[3].expression !== call)
|
|
1724
2278
|
return null;
|
|
1725
|
-
if (!plainClass(contract,
|
|
2279
|
+
if (!plainClass(contract, import_typescript11.default.SyntaxKind.AbstractKeyword) || !plainClass(consumer, null) || !plainClass(implementation, null) || contract.name === void 0 || consumer.name === void 0 || implementation.name === void 0 || (/* @__PURE__ */ new Set([contract.name.text, consumer.name.text, implementation.name.text])).size !== 3)
|
|
1726
2280
|
return null;
|
|
1727
2281
|
const method = emptyContractMethod(contract);
|
|
1728
2282
|
if (method === null || !emptyImplementation(implementation, method) || !exactConsumer(sourceCode, consumer, contract.name.text) || !exactConstruction(call, consumer.name.text, implementation.name.text))
|
|
@@ -1735,47 +2289,47 @@ function closedNominalInheritanceFix(sourceCode, call, consumer, implementation,
|
|
|
1735
2289
|
);
|
|
1736
2290
|
}
|
|
1737
2291
|
function emptyModuleMarker(node) {
|
|
1738
|
-
return !node.isTypeOnly && node.moduleSpecifier === void 0 && node.attributes === void 0 && node.exportClause !== void 0 &&
|
|
2292
|
+
return !node.isTypeOnly && node.moduleSpecifier === void 0 && node.attributes === void 0 && node.exportClause !== void 0 && import_typescript11.default.isNamedExports(node.exportClause) && node.exportClause.elements.length === 0;
|
|
1739
2293
|
}
|
|
1740
2294
|
function plainClass(node, modifier) {
|
|
1741
|
-
const modifiers =
|
|
1742
|
-
return node.name !== void 0 && node.typeParameters === void 0 && node.heritageClauses === void 0 && (
|
|
2295
|
+
const modifiers = import_typescript11.default.getModifiers(node) ?? [];
|
|
2296
|
+
return node.name !== void 0 && node.typeParameters === void 0 && node.heritageClauses === void 0 && (import_typescript11.default.getDecorators(node)?.length ?? 0) === 0 && modifiers.length === (modifier === null ? 0 : 1) && (modifier === null || modifiers[0]?.kind === modifier);
|
|
1743
2297
|
}
|
|
1744
2298
|
function emptyContractMethod(node) {
|
|
1745
2299
|
const method = node.members[0];
|
|
1746
|
-
if (node.members.length !== 1 || method === void 0 || !
|
|
2300
|
+
if (node.members.length !== 1 || method === void 0 || !import_typescript11.default.isMethodDeclaration(method) || !import_typescript11.default.isIdentifier(method.name) || method.name.text === "constructor" || method.parameters.length !== 0 || method.typeParameters !== void 0 || method.questionToken !== void 0 || method.asteriskToken !== void 0 || method.body !== void 0 || method.type?.kind !== import_typescript11.default.SyntaxKind.VoidKeyword || method.modifiers?.length !== 1 || method.modifiers[0]?.kind !== import_typescript11.default.SyntaxKind.AbstractKeyword)
|
|
1747
2301
|
return null;
|
|
1748
2302
|
return method.name.text;
|
|
1749
2303
|
}
|
|
1750
2304
|
function emptyImplementation(node, key) {
|
|
1751
2305
|
const method = node.members[0];
|
|
1752
|
-
return node.members.length === 1 && method !== void 0 &&
|
|
2306
|
+
return node.members.length === 1 && method !== void 0 && import_typescript11.default.isMethodDeclaration(method) && import_typescript11.default.isIdentifier(method.name) && method.name.text === key && method.parameters.length === 0 && method.typeParameters === void 0 && method.questionToken === void 0 && method.asteriskToken === void 0 && method.modifiers === void 0 && (method.type === void 0 || method.type.kind === import_typescript11.default.SyntaxKind.VoidKeyword) && method.body?.statements.length === 0;
|
|
1753
2307
|
}
|
|
1754
2308
|
function exactConsumer(sourceCode, consumer, base) {
|
|
1755
2309
|
const constructor = consumer.members[0];
|
|
1756
|
-
if (consumer.members.length !== 1 || constructor === void 0 || !
|
|
2310
|
+
if (consumer.members.length !== 1 || constructor === void 0 || !import_typescript11.default.isConstructorDeclaration(constructor) || constructor.modifiers !== void 0 || constructor.parameters.length !== 1 || constructor.body?.statements.length !== 1)
|
|
1757
2311
|
return false;
|
|
1758
2312
|
const parameter = constructor.parameters[0];
|
|
1759
|
-
if (parameter === void 0 || !
|
|
2313
|
+
if (parameter === void 0 || !import_typescript11.default.isIdentifier(parameter.name) || parameter.name.text === base || parameter.initializer !== void 0 || parameter.questionToken !== void 0 || parameter.dotDotDotToken !== void 0 || parameter.modifiers?.length !== 1 || parameter.modifiers[0]?.kind !== import_typescript11.default.SyntaxKind.ReadonlyKeyword || parameter.type === void 0 || !import_typescript11.default.isTypeReferenceNode(parameter.type) || !import_typescript11.default.isIdentifier(parameter.type.typeName) || parameter.type.typeName.text !== base || parameter.type.typeArguments !== void 0)
|
|
1760
2314
|
return false;
|
|
1761
2315
|
const guard = constructor.body.statements[0];
|
|
1762
|
-
if (guard === void 0 || !
|
|
2316
|
+
if (guard === void 0 || !import_typescript11.default.isIfStatement(guard) || guard.elseStatement !== void 0)
|
|
1763
2317
|
return false;
|
|
1764
2318
|
const condition2 = unparenthesized(guard.expression);
|
|
1765
|
-
if (!
|
|
2319
|
+
if (!import_typescript11.default.isPrefixUnaryExpression(condition2) || condition2.operator !== import_typescript11.default.SyntaxKind.ExclamationToken)
|
|
1766
2320
|
return false;
|
|
1767
2321
|
const comparison2 = unparenthesized(condition2.operand);
|
|
1768
|
-
return
|
|
2322
|
+
return import_typescript11.default.isBinaryExpression(comparison2) && comparison2.operatorToken.kind === import_typescript11.default.SyntaxKind.InstanceOfKeyword && import_typescript11.default.isIdentifier(comparison2.left) && comparison2.left.text === parameter.name.text && import_typescript11.default.isIdentifier(comparison2.right) && comparison2.right.text === base && exactRejection(sourceCode, guard.thenStatement);
|
|
1769
2323
|
}
|
|
1770
2324
|
function unparenthesized(node) {
|
|
1771
2325
|
let expression = node;
|
|
1772
|
-
while (
|
|
2326
|
+
while (import_typescript11.default.isParenthesizedExpression(expression))
|
|
1773
2327
|
expression = expression.expression;
|
|
1774
2328
|
return expression;
|
|
1775
2329
|
}
|
|
1776
2330
|
function exactRejection(sourceCode, statement) {
|
|
1777
|
-
const rejected =
|
|
1778
|
-
if (rejected === void 0 || !
|
|
2331
|
+
const rejected = import_typescript11.default.isBlock(statement) && statement.statements.length === 1 ? statement.statements[0] : statement;
|
|
2332
|
+
if (rejected === void 0 || !import_typescript11.default.isThrowStatement(rejected) || rejected.expression === void 0 || !import_typescript11.default.isNewExpression(rejected.expression) || !import_typescript11.default.isIdentifier(rejected.expression.expression) || rejected.expression.expression.text !== "TypeError" || rejected.expression.typeArguments !== void 0 || rejected.expression.arguments?.length !== 1 || rejected.expression.arguments[0] === void 0 || !import_typescript11.default.isStringLiteral(rejected.expression.arguments[0]))
|
|
1779
2333
|
return false;
|
|
1780
2334
|
const identifier = sourceCode.getNodeByRangeIndex(
|
|
1781
2335
|
rejected.expression.expression.getStart()
|
|
@@ -1783,14 +2337,15 @@ function exactRejection(sourceCode, statement) {
|
|
|
1783
2337
|
return identifier?.type === import_utils14.AST_NODE_TYPES.Identifier && identifier.name === "TypeError" && (import_utils14.ASTUtils.findVariable(sourceCode.getScope(identifier), identifier.name)?.defs.length ?? 0) === 0;
|
|
1784
2338
|
}
|
|
1785
2339
|
function exactConstruction(node, consumer, implementation) {
|
|
1786
|
-
if (!
|
|
2340
|
+
if (!import_typescript11.default.isIdentifier(node.expression) || node.expression.text !== consumer || node.typeArguments !== void 0 || node.arguments?.length !== 1)
|
|
1787
2341
|
return false;
|
|
1788
2342
|
const argument = node.arguments[0];
|
|
1789
|
-
return argument !== void 0 &&
|
|
2343
|
+
return argument !== void 0 && import_typescript11.default.isNewExpression(argument) && import_typescript11.default.isIdentifier(argument.expression) && argument.expression.text === implementation && argument.typeArguments === void 0 && argument.arguments?.length === 0;
|
|
1790
2344
|
}
|
|
1791
2345
|
|
|
1792
2346
|
// src/rules/require-explicit-contract-implementation.ts
|
|
1793
2347
|
var ESCAPED_CLASSES = /* @__PURE__ */ new WeakMap();
|
|
2348
|
+
var PROTOTYPE_MUTATIONS = /* @__PURE__ */ new WeakMap();
|
|
1794
2349
|
var REQUIRE_EXPLICIT_CONTRACT_IMPLEMENTATION_DOCUMENTATION = {
|
|
1795
2350
|
defaultLevel: "error",
|
|
1796
2351
|
summary: "Require nominal inheritance when an injected abstract class is rejected by an instanceof guard.",
|
|
@@ -1855,19 +2410,23 @@ var REQUIRE_EXPLICIT_CONTRACT_IMPLEMENTATION_DOCUMENTATION = {
|
|
|
1855
2410
|
]
|
|
1856
2411
|
};
|
|
1857
2412
|
function hasPrototypeMutation(source) {
|
|
2413
|
+
const cached = PROTOTYPE_MUTATIONS.get(source);
|
|
2414
|
+
if (cached !== void 0) return cached;
|
|
1858
2415
|
function visit(node) {
|
|
1859
2416
|
const member3 = memberName(node);
|
|
1860
2417
|
if (member3 === "setPrototypeOf" || member3 === "__proto__" || member3 === "hasInstance")
|
|
1861
2418
|
return true;
|
|
1862
|
-
if (
|
|
2419
|
+
if (ts12.isBinaryExpression(node) && node.operatorToken.kind >= ts12.SyntaxKind.FirstAssignment && node.operatorToken.kind <= ts12.SyntaxKind.LastAssignment && memberName(node.left) === "prototype")
|
|
1863
2420
|
return true;
|
|
1864
|
-
return
|
|
2421
|
+
return ts12.forEachChild(node, visit);
|
|
1865
2422
|
}
|
|
1866
|
-
|
|
2423
|
+
const mutated = visit(source) === true;
|
|
2424
|
+
PROTOTYPE_MUTATIONS.set(source, mutated);
|
|
2425
|
+
return mutated;
|
|
1867
2426
|
}
|
|
1868
2427
|
function memberName(node) {
|
|
1869
|
-
if (
|
|
1870
|
-
if (
|
|
2428
|
+
if (ts12.isPropertyAccessExpression(node)) return node.name.text;
|
|
2429
|
+
if (ts12.isElementAccessExpression(node) && ts12.isStringLiteralLike(node.argumentExpression))
|
|
1871
2430
|
return node.argumentExpression.text;
|
|
1872
2431
|
return null;
|
|
1873
2432
|
}
|
|
@@ -1884,11 +2443,11 @@ function escapedClasses(program, checker, cwd) {
|
|
|
1884
2443
|
const escaped = /* @__PURE__ */ new Set();
|
|
1885
2444
|
const namespaceValues = /* @__PURE__ */ new Map();
|
|
1886
2445
|
function visit(node) {
|
|
1887
|
-
if (
|
|
1888
|
-
if (
|
|
2446
|
+
if (ts12.isTypeNode(node) || ts12.isImportDeclaration(node)) return;
|
|
2447
|
+
if (ts12.isIdentifier(node) || ts12.isPropertyAccessExpression(node) || ts12.isElementAccessExpression(node)) {
|
|
1889
2448
|
recordEscapedReference(checker, node, escaped, namespaceValues, cwd);
|
|
1890
2449
|
}
|
|
1891
|
-
|
|
2450
|
+
ts12.forEachChild(node, visit);
|
|
1892
2451
|
}
|
|
1893
2452
|
for (const source of program.getSourceFiles())
|
|
1894
2453
|
if (ownedSource(source, cwd)) visit(source);
|
|
@@ -1907,7 +2466,7 @@ function recordEscapedReference(checker, node, escaped, namespaceValues, cwd) {
|
|
|
1907
2466
|
if (!namespacePrefix(symbol, node) && !safeClassReference(node))
|
|
1908
2467
|
for (const value of values) escaped.add(value);
|
|
1909
2468
|
}
|
|
1910
|
-
if (
|
|
2469
|
+
if (ts12.isElementAccessExpression(node) && !safeClassReference(node)) {
|
|
1911
2470
|
const receiver = canonicalSymbol(checker, node.expression) ?? checker.getTypeAtLocation(node.expression).getSymbol();
|
|
1912
2471
|
if (receiver !== void 0)
|
|
1913
2472
|
for (const value of ownedClassValues(checker, receiver, cwd))
|
|
@@ -1915,16 +2474,16 @@ function recordEscapedReference(checker, node, escaped, namespaceValues, cwd) {
|
|
|
1915
2474
|
}
|
|
1916
2475
|
}
|
|
1917
2476
|
function ownedClassValues(checker, original, cwd, seen = /* @__PURE__ */ new Set()) {
|
|
1918
|
-
const symbol = original.flags &
|
|
2477
|
+
const symbol = original.flags & ts12.SymbolFlags.Alias ? checker.getAliasedSymbol(original) : original;
|
|
1919
2478
|
const values = /* @__PURE__ */ new Set();
|
|
1920
2479
|
if (seen.has(symbol)) return values;
|
|
1921
2480
|
seen.add(symbol);
|
|
1922
2481
|
if (symbol.declarations?.some(
|
|
1923
|
-
(declaration) =>
|
|
2482
|
+
(declaration) => ts12.isClassDeclaration(declaration) && ownedSource(declaration.getSourceFile(), cwd)
|
|
1924
2483
|
))
|
|
1925
2484
|
values.add(symbol);
|
|
1926
2485
|
if (symbol.declarations?.some(
|
|
1927
|
-
(declaration) => (
|
|
2486
|
+
(declaration) => (ts12.isSourceFile(declaration) || ts12.isModuleDeclaration(declaration)) && ownedSource(declaration.getSourceFile(), cwd)
|
|
1928
2487
|
)) {
|
|
1929
2488
|
for (const exported of checker.getExportsOfModule(symbol)) {
|
|
1930
2489
|
for (const value of ownedClassValues(checker, exported, cwd, seen))
|
|
@@ -1934,16 +2493,16 @@ function ownedClassValues(checker, original, cwd, seen = /* @__PURE__ */ new Set
|
|
|
1934
2493
|
return values;
|
|
1935
2494
|
}
|
|
1936
2495
|
function safeClassReference(node) {
|
|
1937
|
-
let reference =
|
|
1938
|
-
while (
|
|
2496
|
+
let reference = ts12.isPropertyAccessExpression(node.parent) && node.parent.name === node ? node.parent : node;
|
|
2497
|
+
while (ts12.isParenthesizedExpression(reference.parent))
|
|
1939
2498
|
reference = reference.parent;
|
|
1940
2499
|
const parent = reference.parent;
|
|
1941
|
-
return
|
|
2500
|
+
return ts12.isClassDeclaration(parent) && parent.name === reference || ts12.isNewExpression(parent) && parent.expression === reference || ts12.isExpressionWithTypeArguments(parent) && parent.expression === reference || ts12.isBinaryExpression(parent) && parent.operatorToken.kind === ts12.SyntaxKind.InstanceOfKeyword && parent.right === reference;
|
|
1942
2501
|
}
|
|
1943
2502
|
function namespacePrefix(symbol, node) {
|
|
1944
2503
|
const parent = node.parent;
|
|
1945
|
-
const memberCall = (
|
|
1946
|
-
return !symbol.declarations?.some(
|
|
2504
|
+
const memberCall = (ts12.isPropertyAccessExpression(parent) || ts12.isElementAccessExpression(parent)) && ts12.isCallExpression(parent.parent) && parent.parent.expression === parent;
|
|
2505
|
+
return !symbol.declarations?.some(ts12.isClassDeclaration) && (ts12.isPropertyAccessExpression(parent) || ts12.isElementAccessExpression(parent)) && parent.expression === node && !memberCall;
|
|
1947
2506
|
}
|
|
1948
2507
|
function closedNominalBoundary(program, checker, call, consumer, missing, cwd) {
|
|
1949
2508
|
const { implementation, contractSymbol } = missing;
|
|
@@ -1951,7 +2510,7 @@ function closedNominalBoundary(program, checker, call, consumer, missing, cwd) {
|
|
|
1951
2510
|
const consumerSymbol = consumer.name === void 0 ? void 0 : canonicalSymbol(checker, consumer.name);
|
|
1952
2511
|
if (implementationSymbol === void 0 || consumerSymbol === void 0)
|
|
1953
2512
|
return false;
|
|
1954
|
-
const contract = contractSymbol.declarations?.find(
|
|
2513
|
+
const contract = contractSymbol.declarations?.find(ts12.isClassDeclaration);
|
|
1955
2514
|
if (contract === void 0) return false;
|
|
1956
2515
|
const targets = /* @__PURE__ */ new Set([
|
|
1957
2516
|
consumerSymbol,
|
|
@@ -1973,12 +2532,12 @@ function classHierarchySymbols(checker, declaration, seen = /* @__PURE__ */ new
|
|
|
1973
2532
|
if (symbol === void 0 || seen.has(symbol)) return seen;
|
|
1974
2533
|
seen.add(symbol);
|
|
1975
2534
|
for (const clause of declaration.heritageClauses ?? []) {
|
|
1976
|
-
if (clause.token !==
|
|
2535
|
+
if (clause.token !== ts12.SyntaxKind.ExtendsKeyword) continue;
|
|
1977
2536
|
for (const parent of clause.types) {
|
|
1978
2537
|
const ancestor = canonicalSymbol(
|
|
1979
2538
|
checker,
|
|
1980
2539
|
parent.expression
|
|
1981
|
-
)?.declarations?.find(
|
|
2540
|
+
)?.declarations?.find(ts12.isClassDeclaration);
|
|
1982
2541
|
if (ancestor !== void 0)
|
|
1983
2542
|
classHierarchySymbols(checker, ancestor, seen);
|
|
1984
2543
|
}
|
|
@@ -2003,22 +2562,22 @@ function missingImplementation(checker, signature, parameter, call, argument) {
|
|
|
2003
2562
|
function behavioralContract(checker, type) {
|
|
2004
2563
|
if (type.isUnion()) {
|
|
2005
2564
|
const substantive = type.types.filter(
|
|
2006
|
-
(member3) => (member3.flags & (
|
|
2565
|
+
(member3) => (member3.flags & (ts12.TypeFlags.Null | ts12.TypeFlags.Undefined)) === 0
|
|
2007
2566
|
);
|
|
2008
2567
|
if (substantive.length !== 1) return null;
|
|
2009
2568
|
return behavioralContract(checker, substantive[0]);
|
|
2010
2569
|
}
|
|
2011
|
-
if ((type.flags & (
|
|
2570
|
+
if ((type.flags & (ts12.TypeFlags.Any | ts12.TypeFlags.Unknown)) !== 0)
|
|
2012
2571
|
return null;
|
|
2013
2572
|
const declaration = type.getSymbol()?.declarations?.find(
|
|
2014
|
-
(item) =>
|
|
2015
|
-
(modifier) => modifier.kind ===
|
|
2573
|
+
(item) => ts12.isClassDeclaration(item) && item.modifiers?.some(
|
|
2574
|
+
(modifier) => modifier.kind === ts12.SyntaxKind.AbstractKeyword
|
|
2016
2575
|
)
|
|
2017
2576
|
);
|
|
2018
2577
|
if (declaration === void 0) return null;
|
|
2019
2578
|
return checker.getPropertiesOfType(type).some((property) => {
|
|
2020
2579
|
if (!property.declarations?.some(
|
|
2021
|
-
(member3) =>
|
|
2580
|
+
(member3) => ts12.isMethodSignature(member3) || ts12.isMethodDeclaration(member3)
|
|
2022
2581
|
))
|
|
2023
2582
|
return false;
|
|
2024
2583
|
const propertyType = checker.getTypeOfSymbolAtLocation(
|
|
@@ -2029,15 +2588,15 @@ function behavioralContract(checker, type) {
|
|
|
2029
2588
|
}) ? type : null;
|
|
2030
2589
|
}
|
|
2031
2590
|
function ownedClass(checker, expression) {
|
|
2032
|
-
if (!
|
|
2591
|
+
if (!ts12.isNewExpression(expression)) return null;
|
|
2033
2592
|
const type = checker.getTypeAtLocation(expression);
|
|
2034
|
-
if ((type.flags & (
|
|
2593
|
+
if ((type.flags & (ts12.TypeFlags.Any | ts12.TypeFlags.Unknown)) !== 0)
|
|
2035
2594
|
return null;
|
|
2036
|
-
const declaration = type.getSymbol()?.declarations?.find(
|
|
2595
|
+
const declaration = type.getSymbol()?.declarations?.find(ts12.isClassDeclaration);
|
|
2037
2596
|
const constructed = canonicalSymbol(
|
|
2038
2597
|
checker,
|
|
2039
2598
|
expression.expression
|
|
2040
|
-
)?.declarations?.find(
|
|
2599
|
+
)?.declarations?.find(ts12.isClassDeclaration);
|
|
2041
2600
|
if (declaration === void 0 || declaration !== constructed || declaration.getSourceFile().isDeclarationFile || /(?:^|[/\\])(?:node_modules|vendor|generated)(?:[/\\])/u.test(
|
|
2042
2601
|
declaration.getSourceFile().fileName
|
|
2043
2602
|
))
|
|
@@ -2045,10 +2604,10 @@ function ownedClass(checker, expression) {
|
|
|
2045
2604
|
return declaration;
|
|
2046
2605
|
}
|
|
2047
2606
|
function nominallyInherits(checker, declaration, target, seen) {
|
|
2048
|
-
if (
|
|
2607
|
+
if (ts12.canHaveDecorators(declaration) && ts12.getDecorators(declaration)?.length)
|
|
2049
2608
|
return null;
|
|
2050
2609
|
if (hasPrototypeMutation(declaration.getSourceFile()) || declaration.members.some(
|
|
2051
|
-
(member3) =>
|
|
2610
|
+
(member3) => ts12.isConstructorDeclaration(member3) || ts12.isClassStaticBlockDeclaration(member3) || ts12.isPropertyDeclaration(member3) && member3.initializer !== void 0
|
|
2052
2611
|
))
|
|
2053
2612
|
return null;
|
|
2054
2613
|
const symbol = declaration.name === void 0 ? void 0 : canonicalSymbol(checker, declaration.name);
|
|
@@ -2057,60 +2616,60 @@ function nominallyInherits(checker, declaration, target, seen) {
|
|
|
2057
2616
|
seen.add(symbol);
|
|
2058
2617
|
}
|
|
2059
2618
|
const parents = declaration.heritageClauses?.find(
|
|
2060
|
-
(clause) => clause.token ===
|
|
2619
|
+
(clause) => clause.token === ts12.SyntaxKind.ExtendsKeyword
|
|
2061
2620
|
)?.types;
|
|
2062
2621
|
if (parents === void 0) return false;
|
|
2063
2622
|
if (parents.length !== 1) return null;
|
|
2064
2623
|
const parentSymbol = canonicalSymbol(checker, parents[0].expression);
|
|
2065
2624
|
if (parentSymbol === void 0) return null;
|
|
2066
2625
|
if (parentSymbol === target) return true;
|
|
2067
|
-
const inherited = parentSymbol.declarations?.find(
|
|
2626
|
+
const inherited = parentSymbol.declarations?.find(ts12.isClassDeclaration);
|
|
2068
2627
|
return inherited === void 0 ? null : nominallyInherits(checker, inherited, target, new Set(seen));
|
|
2069
2628
|
}
|
|
2070
2629
|
function hasNominalRejectionGuard(checker, signature, parameter, contract) {
|
|
2071
2630
|
const declaration = signature.getDeclaration();
|
|
2072
|
-
if (declaration === void 0 || !
|
|
2631
|
+
if (declaration === void 0 || !ts12.isConstructorDeclaration(declaration))
|
|
2073
2632
|
return false;
|
|
2074
|
-
if (
|
|
2633
|
+
if (ts12.canHaveDecorators(declaration.parent) && ts12.getDecorators(declaration.parent)?.length)
|
|
2075
2634
|
return false;
|
|
2076
2635
|
if (hasPrototypeMutation(declaration.getSourceFile())) return false;
|
|
2077
2636
|
const first = declaration.body?.statements[0];
|
|
2078
|
-
if (first === void 0 || !
|
|
2637
|
+
if (first === void 0 || !ts12.isIfStatement(first) || !alwaysThrows(first.thenStatement))
|
|
2079
2638
|
return false;
|
|
2080
2639
|
const condition2 = unparenthesized2(first.expression);
|
|
2081
|
-
if (!
|
|
2640
|
+
if (!ts12.isPrefixUnaryExpression(condition2) || condition2.operator !== ts12.SyntaxKind.ExclamationToken)
|
|
2082
2641
|
return false;
|
|
2083
2642
|
const comparison2 = unparenthesized2(condition2.operand);
|
|
2084
|
-
if (!
|
|
2643
|
+
if (!ts12.isBinaryExpression(comparison2) || comparison2.operatorToken.kind !== ts12.SyntaxKind.InstanceOfKeyword)
|
|
2085
2644
|
return false;
|
|
2086
2645
|
if (canonicalSymbol(checker, comparison2.left) !== parameter || canonicalSymbol(checker, comparison2.right) !== contract)
|
|
2087
2646
|
return false;
|
|
2088
|
-
const target = contract.declarations?.find(
|
|
2647
|
+
const target = contract.declarations?.find(ts12.isClassDeclaration);
|
|
2089
2648
|
return target !== void 0 && hasOrdinaryInstanceCheck(checker, target, /* @__PURE__ */ new Set());
|
|
2090
2649
|
}
|
|
2091
2650
|
function unparenthesized2(expression) {
|
|
2092
2651
|
let current = expression;
|
|
2093
|
-
while (
|
|
2652
|
+
while (ts12.isParenthesizedExpression(current)) current = current.expression;
|
|
2094
2653
|
return current;
|
|
2095
2654
|
}
|
|
2096
2655
|
function alwaysThrows(statement) {
|
|
2097
|
-
return
|
|
2656
|
+
return ts12.isThrowStatement(statement) || ts12.isBlock(statement) && statement.statements.length === 1 && ts12.isThrowStatement(statement.statements[0]);
|
|
2098
2657
|
}
|
|
2099
2658
|
function hasOrdinaryInstanceCheck(checker, declaration, seen) {
|
|
2100
|
-
if (seen.has(declaration) ||
|
|
2659
|
+
if (seen.has(declaration) || ts12.getDecorators(declaration)?.length || hasPrototypeMutation(declaration.getSourceFile()) || declaration.members.some(ts12.isClassStaticBlockDeclaration))
|
|
2101
2660
|
return false;
|
|
2102
2661
|
seen.add(declaration);
|
|
2103
2662
|
if (declaration.members.some(
|
|
2104
|
-
(member3) => member3.name !== void 0 &&
|
|
2663
|
+
(member3) => member3.name !== void 0 && ts12.isComputedPropertyName(member3.name) && ts12.canHaveModifiers(member3) && ts12.getModifiers(member3)?.some((modifier) => modifier.kind === ts12.SyntaxKind.StaticKeyword)
|
|
2105
2664
|
))
|
|
2106
2665
|
return false;
|
|
2107
2666
|
for (const clause of declaration.heritageClauses ?? []) {
|
|
2108
|
-
if (clause.token !==
|
|
2667
|
+
if (clause.token !== ts12.SyntaxKind.ExtendsKeyword) continue;
|
|
2109
2668
|
for (const parent of clause.types) {
|
|
2110
2669
|
const ancestor = canonicalSymbol(
|
|
2111
2670
|
checker,
|
|
2112
2671
|
parent.expression
|
|
2113
|
-
)?.declarations?.find(
|
|
2672
|
+
)?.declarations?.find(ts12.isClassDeclaration);
|
|
2114
2673
|
if (ancestor === void 0 || !hasOrdinaryInstanceCheck(checker, ancestor, seen))
|
|
2115
2674
|
return false;
|
|
2116
2675
|
}
|
|
@@ -2118,9 +2677,9 @@ function hasOrdinaryInstanceCheck(checker, declaration, seen) {
|
|
|
2118
2677
|
return true;
|
|
2119
2678
|
}
|
|
2120
2679
|
function canonicalSymbol(checker, node) {
|
|
2121
|
-
if (
|
|
2680
|
+
if (ts12.isParenthesizedExpression(node)) node = unparenthesized2(node);
|
|
2122
2681
|
const symbol = checker.getSymbolAtLocation(node);
|
|
2123
|
-
return symbol === void 0 ? void 0 : (symbol.flags &
|
|
2682
|
+
return symbol === void 0 ? void 0 : (symbol.flags & ts12.SymbolFlags.Alias) !== 0 ? checker.getAliasedSymbol(symbol) : symbol;
|
|
2124
2683
|
}
|
|
2125
2684
|
var require_explicit_contract_implementation_default = createRule({
|
|
2126
2685
|
name: "require-explicit-contract-implementation",
|
|
@@ -2145,11 +2704,11 @@ var require_explicit_contract_implementation_default = createRule({
|
|
|
2145
2704
|
const checker = services.program.getTypeChecker();
|
|
2146
2705
|
function inspect(node) {
|
|
2147
2706
|
const tsNode = services.esTreeNodeToTSNodeMap.get(node);
|
|
2148
|
-
if (!
|
|
2707
|
+
if (!ts12.isNewExpression(tsNode)) return;
|
|
2149
2708
|
const consumer = canonicalSymbol(
|
|
2150
2709
|
checker,
|
|
2151
2710
|
tsNode.expression
|
|
2152
|
-
)?.declarations?.find(
|
|
2711
|
+
)?.declarations?.find(ts12.isClassDeclaration);
|
|
2153
2712
|
if (consumer === void 0) return;
|
|
2154
2713
|
const signature = checker.getResolvedSignature(tsNode);
|
|
2155
2714
|
if (signature === void 0 || signature.getDeclaration()?.parent !== consumer)
|
|
@@ -2177,7 +2736,7 @@ var require_explicit_contract_implementation_default = createRule({
|
|
|
2177
2736
|
))
|
|
2178
2737
|
continue;
|
|
2179
2738
|
const contract = missing.contractSymbol.declarations?.find(
|
|
2180
|
-
|
|
2739
|
+
ts12.isClassDeclaration
|
|
2181
2740
|
);
|
|
2182
2741
|
context.report({
|
|
2183
2742
|
node: argument,
|
|
@@ -3468,7 +4027,7 @@ var no_conditional_empty_object_spread_default = createRule({
|
|
|
3468
4027
|
|
|
3469
4028
|
// src/rules/prefer-typed-reflection.ts
|
|
3470
4029
|
var import_utils20 = require("@typescript-eslint/utils");
|
|
3471
|
-
var
|
|
4030
|
+
var import_typescript12 = __toESM(require("typescript"), 1);
|
|
3472
4031
|
var PREFER_TYPED_REFLECTION_DOCUMENTATION = {
|
|
3473
4032
|
summary: "Prefer typed access when Reflect.get or Reflect.apply discards a known contract.",
|
|
3474
4033
|
rationale: "Reflect.get and Reflect.apply can accept property or argument mistakes that normal typed access catches.",
|
|
@@ -3521,7 +4080,7 @@ var PREFER_TYPED_REFLECTION_DOCUMENTATION = {
|
|
|
3521
4080
|
};
|
|
3522
4081
|
function knownType(type) {
|
|
3523
4082
|
if (type.isUnion()) return type.types.every(knownType);
|
|
3524
|
-
return (type.flags & (
|
|
4083
|
+
return (type.flags & (import_typescript12.default.TypeFlags.Any | import_typescript12.default.TypeFlags.Unknown | import_typescript12.default.TypeFlags.TypeParameter | import_typescript12.default.TypeFlags.Never)) === 0;
|
|
3525
4084
|
}
|
|
3526
4085
|
var prefer_typed_reflection_default = createRule({
|
|
3527
4086
|
name: "prefer-typed-reflection",
|
|
@@ -3573,7 +4132,7 @@ var prefer_typed_reflection_default = createRule({
|
|
|
3573
4132
|
const key = unwrapExpression(writtenKey);
|
|
3574
4133
|
const name = staticString(key) ?? (key.type === import_utils20.AST_NODE_TYPES.Literal && typeof key.value === "number" ? String(key.value) : null);
|
|
3575
4134
|
const members = type.isUnion() ? type.types : [type];
|
|
3576
|
-
if (name === null || !members.every((member3) => (member3.flags &
|
|
4135
|
+
if (name === null || !members.every((member3) => (member3.flags & import_typescript12.default.TypeFlags.Object) !== 0 && checker.getPropertyOfType(member3, name) !== void 0)) return null;
|
|
3577
4136
|
return `(${context.sourceCode.getText(target)})[${context.sourceCode.getText(writtenKey)}]`;
|
|
3578
4137
|
};
|
|
3579
4138
|
return {
|
|
@@ -3598,7 +4157,7 @@ var prefer_typed_reflection_default = createRule({
|
|
|
3598
4157
|
|
|
3599
4158
|
// src/rules/no-broad-return-type.ts
|
|
3600
4159
|
var import_utils22 = require("@typescript-eslint/utils");
|
|
3601
|
-
var
|
|
4160
|
+
var import_typescript13 = __toESM(require("typescript"), 1);
|
|
3602
4161
|
|
|
3603
4162
|
// src/rules/_unused-private-binding.ts
|
|
3604
4163
|
var import_utils21 = require("@typescript-eslint/utils");
|
|
@@ -3699,21 +4258,21 @@ var NO_BROAD_RETURN_TYPE_DOCUMENTATION = {
|
|
|
3699
4258
|
]
|
|
3700
4259
|
};
|
|
3701
4260
|
function isBroad(type, checker) {
|
|
3702
|
-
if ((type.flags & (
|
|
4261
|
+
if ((type.flags & (import_typescript13.default.TypeFlags.Unknown | import_typescript13.default.TypeFlags.NonPrimitive)) !== 0)
|
|
3703
4262
|
return true;
|
|
3704
4263
|
const indexes = checker.getIndexInfosOfType(type);
|
|
3705
|
-
return indexes.length > 0 && type.getProperties().length === 0 && indexes.every((index) => (index.type.flags &
|
|
4264
|
+
return indexes.length > 0 && type.getProperties().length === 0 && indexes.every((index) => (index.type.flags & import_typescript13.default.TypeFlags.Unknown) !== 0);
|
|
3706
4265
|
}
|
|
3707
4266
|
function hasKnownContract(type, checker) {
|
|
3708
4267
|
if (type.isUnion())
|
|
3709
4268
|
return type.types.every((part) => hasKnownContract(part, checker));
|
|
3710
|
-
const excluded =
|
|
4269
|
+
const excluded = import_typescript13.default.TypeFlags.Any | import_typescript13.default.TypeFlags.Unknown | import_typescript13.default.TypeFlags.Never | import_typescript13.default.TypeFlags.TypeParameter | import_typescript13.default.TypeFlags.Conditional | import_typescript13.default.TypeFlags.IndexedAccess | import_typescript13.default.TypeFlags.Substitution | import_typescript13.default.TypeFlags.Null | import_typescript13.default.TypeFlags.Undefined | import_typescript13.default.TypeFlags.Void;
|
|
3711
4270
|
if ((type.flags & excluded) !== 0 || isBroad(type, checker)) return false;
|
|
3712
|
-
return (type.flags &
|
|
4271
|
+
return (type.flags & import_typescript13.default.TypeFlags.Object) === 0 || type.getProperties().length > 0;
|
|
3713
4272
|
}
|
|
3714
4273
|
function isOpaque(type, checker) {
|
|
3715
4274
|
if (type.isUnion()) return type.types.some((part) => isOpaque(part, checker));
|
|
3716
|
-
return (type.flags & (
|
|
4275
|
+
return (type.flags & (import_typescript13.default.TypeFlags.Any | import_typescript13.default.TypeFlags.Unknown | import_typescript13.default.TypeFlags.TypeParameter | import_typescript13.default.TypeFlags.Conditional | import_typescript13.default.TypeFlags.IndexedAccess | import_typescript13.default.TypeFlags.Substitution)) !== 0 || isBroad(type, checker);
|
|
3717
4276
|
}
|
|
3718
4277
|
var no_broad_return_type_default = createRule({
|
|
3719
4278
|
name: "no-broad-return-type",
|
|
@@ -3740,7 +4299,7 @@ var no_broad_return_type_default = createRule({
|
|
|
3740
4299
|
const type = checker.getTypeAtLocation(
|
|
3741
4300
|
services.esTreeNodeToTSNodeMap.get(node)
|
|
3742
4301
|
);
|
|
3743
|
-
return (type.flags &
|
|
4302
|
+
return (type.flags & import_typescript13.default.TypeFlags.TypeParameter) !== 0 ? type : checker.getAwaitedType(type) ?? type;
|
|
3744
4303
|
};
|
|
3745
4304
|
const inspectReturn = (value) => {
|
|
3746
4305
|
const frame = frames.at(-1);
|
|
@@ -3785,7 +4344,7 @@ var no_broad_return_type_default = createRule({
|
|
|
3785
4344
|
|
|
3786
4345
|
// src/rules/no-reduce-accumulator-copy.ts
|
|
3787
4346
|
var import_utils24 = require("@typescript-eslint/utils");
|
|
3788
|
-
var
|
|
4347
|
+
var import_typescript14 = __toESM(require("typescript"), 1);
|
|
3789
4348
|
|
|
3790
4349
|
// src/rules/_literal-identity-reduce-fix.ts
|
|
3791
4350
|
var import_utils23 = require("@typescript-eslint/utils");
|
|
@@ -3945,7 +4504,7 @@ var no_reduce_accumulator_copy_default = createRule({
|
|
|
3945
4504
|
services.esTreeNodeToTSNodeMap.get(node)
|
|
3946
4505
|
);
|
|
3947
4506
|
const declaration = signature?.declaration;
|
|
3948
|
-
if (!declaration || !program.isSourceFileDefaultLibrary(declaration.getSourceFile()) || !
|
|
4507
|
+
if (!declaration || !program.isSourceFileDefaultLibrary(declaration.getSourceFile()) || !import_typescript14.default.isInterfaceDeclaration(declaration.parent) || !["Array", "ReadonlyArray"].includes(declaration.parent.name.text))
|
|
3949
4508
|
return;
|
|
3950
4509
|
const accumulator = context.sourceCode.getDeclaredVariables(callback).find((variable) => variable.identifiers.includes(parameter));
|
|
3951
4510
|
if (!accumulator || accumulator.references.some((reference) => reference.isWrite()))
|
|
@@ -4007,7 +4566,7 @@ var no_reduce_accumulator_copy_default = createRule({
|
|
|
4007
4566
|
|
|
4008
4567
|
// src/rules/no-known-value-widening.ts
|
|
4009
4568
|
var import_utils25 = require("@typescript-eslint/utils");
|
|
4010
|
-
var
|
|
4569
|
+
var import_typescript15 = __toESM(require("typescript"), 1);
|
|
4011
4570
|
var NO_KNOWN_VALUE_WIDENING_DOCUMENTATION = {
|
|
4012
4571
|
summary: "Preserve a known value's contract instead of widening a local binding to unknown, object, or an unknown-valued dictionary.",
|
|
4013
4572
|
rationale: "Erasing a typed value's fields forces downstream code to rediscover the same contract through casts, reflection, or representation checks.",
|
|
@@ -4034,13 +4593,13 @@ var NO_KNOWN_VALUE_WIDENING_DOCUMENTATION = {
|
|
|
4034
4593
|
]
|
|
4035
4594
|
};
|
|
4036
4595
|
function erasesContract(type, checker) {
|
|
4037
|
-
if ((type.flags & (
|
|
4596
|
+
if ((type.flags & (import_typescript15.default.TypeFlags.Unknown | import_typescript15.default.TypeFlags.NonPrimitive)) !== 0) return true;
|
|
4038
4597
|
const indexes = checker.getIndexInfosOfType(type);
|
|
4039
|
-
return indexes.length > 0 && checker.getPropertiesOfType(type).length === 0 && indexes.every((index) => (index.type.flags &
|
|
4598
|
+
return indexes.length > 0 && checker.getPropertiesOfType(type).length === 0 && indexes.every((index) => (index.type.flags & import_typescript15.default.TypeFlags.Unknown) !== 0);
|
|
4040
4599
|
}
|
|
4041
4600
|
function hasUnknownContract(type, checker) {
|
|
4042
4601
|
if (type.isUnionOrIntersection()) return type.types.some((part) => hasUnknownContract(part, checker));
|
|
4043
|
-
return (type.flags & (
|
|
4602
|
+
return (type.flags & (import_typescript15.default.TypeFlags.Any | import_typescript15.default.TypeFlags.Unknown | import_typescript15.default.TypeFlags.Never | import_typescript15.default.TypeFlags.TypeParameter | import_typescript15.default.TypeFlags.Conditional | import_typescript15.default.TypeFlags.IndexedAccess | import_typescript15.default.TypeFlags.Substitution)) !== 0 || erasesContract(type, checker);
|
|
4044
4603
|
}
|
|
4045
4604
|
var no_known_value_widening_default = createRule({
|
|
4046
4605
|
name: "no-known-value-widening",
|
|
@@ -4082,7 +4641,7 @@ var no_known_value_widening_default = createRule({
|
|
|
4082
4641
|
// src/rules/no-invalid-typed-mutation.ts
|
|
4083
4642
|
var import_utils26 = require("@typescript-eslint/utils");
|
|
4084
4643
|
var import_ts_api_utils = require("ts-api-utils");
|
|
4085
|
-
var
|
|
4644
|
+
var import_typescript16 = __toESM(require("typescript"), 1);
|
|
4086
4645
|
var NO_INVALID_TYPED_MUTATION_DOCUMENTATION = {
|
|
4087
4646
|
summary: "Keep native object mutation APIs from writing incompatible values into declared property types.",
|
|
4088
4647
|
rationale: "Object.assign, Reflect.set and property descriptors accept values that a normal typed property assignment rejects. They can invalidate a domain object's contract while subsequent reads retain its original type.",
|
|
@@ -4240,21 +4799,21 @@ function keepsMutableDescriptor(call, method) {
|
|
|
4240
4799
|
function declaredTargetType(node, checker) {
|
|
4241
4800
|
const symbol = checker.getSymbolAtLocation(node);
|
|
4242
4801
|
const declaration = symbol?.valueDeclaration;
|
|
4243
|
-
if (declaration === void 0 || !(
|
|
4802
|
+
if (declaration === void 0 || !(import_typescript16.default.isVariableDeclaration(declaration) || import_typescript16.default.isParameter(declaration)) || declaration.type === void 0) return void 0;
|
|
4244
4803
|
const type = checker.getTypeFromTypeNode(declaration.type);
|
|
4245
|
-
if (!definiteType(type, checker) || type.isUnionOrIntersection() || (type.flags &
|
|
4804
|
+
if (!definiteType(type, checker) || type.isUnionOrIntersection() || (type.flags & import_typescript16.default.TypeFlags.Object) === 0 || checker.getIndexInfosOfType(type).length > 0 || type.getCallSignatures().length > 0 || type.getConstructSignatures().length > 0) return void 0;
|
|
4246
4805
|
return type;
|
|
4247
4806
|
}
|
|
4248
4807
|
function typedDataProperty(property) {
|
|
4249
4808
|
const declarations = property.getDeclarations();
|
|
4250
|
-
return declarations !== void 0 && declarations.length === 1 && declarations.every((declaration) => (
|
|
4809
|
+
return declarations !== void 0 && declarations.length === 1 && declarations.every((declaration) => (import_typescript16.default.isPropertySignature(declaration) || import_typescript16.default.isPropertyDeclaration(declaration)) && declaration.type !== void 0);
|
|
4251
4810
|
}
|
|
4252
4811
|
function propertyWriteType(target, property, node, checker, exact) {
|
|
4253
4812
|
const exposed = checker.getTypeOfSymbolAtLocation(property, node);
|
|
4254
|
-
if (!exact || (property.flags &
|
|
4255
|
-
if ((target.aliasTypeArguments?.length ?? 0) > 0 || (0, import_ts_api_utils.isTypeReference)(target) && checker.getTypeArguments(target).length > 0 || (0, import_ts_api_utils.isObjectType)(target) && (target.objectFlags & (
|
|
4813
|
+
if (!exact || (property.flags & import_typescript16.default.SymbolFlags.Optional) === 0 || (property.flags & import_typescript16.default.SymbolFlags.Transient) !== 0) return exposed;
|
|
4814
|
+
if ((target.aliasTypeArguments?.length ?? 0) > 0 || (0, import_ts_api_utils.isTypeReference)(target) && checker.getTypeArguments(target).length > 0 || (0, import_ts_api_utils.isObjectType)(target) && (target.objectFlags & (import_typescript16.default.ObjectFlags.Mapped | import_typescript16.default.ObjectFlags.Instantiated)) !== 0) return exposed;
|
|
4256
4815
|
const declaration = property.getDeclarations()?.[0];
|
|
4257
|
-
if (declaration === void 0 || !(
|
|
4816
|
+
if (declaration === void 0 || !(import_typescript16.default.isPropertySignature(declaration) || import_typescript16.default.isPropertyDeclaration(declaration)) || declaration.questionToken === void 0 || declaration.type === void 0) return exposed;
|
|
4258
4817
|
const authored = checker.getTypeFromTypeNode(declaration.type);
|
|
4259
4818
|
return definiteType(authored, checker) && checker.isTypeAssignableTo(authored, exposed) ? authored : exposed;
|
|
4260
4819
|
}
|
|
@@ -4262,13 +4821,13 @@ function definiteType(type, checker, seen = /* @__PURE__ */ new Set()) {
|
|
|
4262
4821
|
if (seen.has(type)) return true;
|
|
4263
4822
|
if (seen.size >= 32) return false;
|
|
4264
4823
|
seen.add(type);
|
|
4265
|
-
const unsafe =
|
|
4824
|
+
const unsafe = import_typescript16.default.TypeFlags.Any | import_typescript16.default.TypeFlags.Unknown | import_typescript16.default.TypeFlags.Never | import_typescript16.default.TypeFlags.TypeParameter | import_typescript16.default.TypeFlags.Conditional | import_typescript16.default.TypeFlags.IndexedAccess | import_typescript16.default.TypeFlags.Substitution;
|
|
4266
4825
|
if ((type.flags & unsafe) !== 0) return false;
|
|
4267
4826
|
if (type.isUnionOrIntersection()) return type.types.every((part) => definiteType(part, checker, seen));
|
|
4268
4827
|
const arguments_ = (0, import_ts_api_utils.isTypeReference)(type) ? checker.getTypeArguments(type) : type.aliasTypeArguments ?? [];
|
|
4269
4828
|
if (!arguments_.every((argument) => definiteType(argument, checker, seen))) return false;
|
|
4270
4829
|
if (!definiteSignatures(type, checker, seen)) return false;
|
|
4271
|
-
if ((0, import_ts_api_utils.isTypeReference)(type) || (type.flags &
|
|
4830
|
+
if ((0, import_ts_api_utils.isTypeReference)(type) || (type.flags & import_typescript16.default.TypeFlags.Object) === 0) return true;
|
|
4272
4831
|
return type.getProperties().every((property) => {
|
|
4273
4832
|
const declaration = property.valueDeclaration ?? property.getDeclarations()?.[0];
|
|
4274
4833
|
return declaration !== void 0 && definiteType(checker.getTypeOfSymbolAtLocation(property, declaration), checker, seen);
|
|
@@ -4352,33 +4911,33 @@ function plainProperties(node) {
|
|
|
4352
4911
|
|
|
4353
4912
|
// src/rules/no-contradictory-type-predicate.ts
|
|
4354
4913
|
var import_utils28 = require("@typescript-eslint/utils");
|
|
4355
|
-
var
|
|
4914
|
+
var import_typescript19 = __toESM(require("typescript"), 1);
|
|
4356
4915
|
|
|
4357
4916
|
// src/rules/_has-separate-predicate-contract.ts
|
|
4358
|
-
var
|
|
4917
|
+
var import_typescript17 = __toESM(require("typescript"), 1);
|
|
4359
4918
|
function hasSeparatePredicateContract(node, checker) {
|
|
4360
|
-
if (
|
|
4361
|
-
if (!
|
|
4919
|
+
if (import_typescript17.default.isFunctionExpression(node) || import_typescript17.default.isArrowFunction(node)) return checker.getContextualType(node) !== void 0;
|
|
4920
|
+
if (!import_typescript17.default.isFunctionDeclaration(node) && !import_typescript17.default.isMethodDeclaration(node)) return true;
|
|
4362
4921
|
if (node.name !== void 0 && (checker.getSymbolAtLocation(node.name)?.getDeclarations()?.length ?? 0) > 1) return true;
|
|
4363
|
-
if (!
|
|
4922
|
+
if (!import_typescript17.default.isMethodDeclaration(node)) return false;
|
|
4364
4923
|
const owner = node.parent;
|
|
4365
|
-
if (
|
|
4366
|
-
return (
|
|
4924
|
+
if (import_typescript17.default.isObjectLiteralExpression(owner)) return checker.getContextualType(owner) !== void 0;
|
|
4925
|
+
return (import_typescript17.default.isClassDeclaration(owner) || import_typescript17.default.isClassExpression(owner)) && (owner.heritageClauses?.length ?? 0) > 0;
|
|
4367
4926
|
}
|
|
4368
4927
|
|
|
4369
4928
|
// src/rules/_contradictory-array-predicate.ts
|
|
4370
4929
|
var import_utils27 = require("@typescript-eslint/utils");
|
|
4371
|
-
var
|
|
4930
|
+
var import_typescript18 = __toESM(require("typescript"), 1);
|
|
4372
4931
|
var import_ts_api_utils2 = require("ts-api-utils");
|
|
4373
4932
|
var HOST_GLOBALS = ["globalThis", "window", "self", "global"];
|
|
4374
|
-
var PRIMITIVE_ELEMENTS =
|
|
4375
|
-
var
|
|
4933
|
+
var PRIMITIVE_ELEMENTS = import_typescript18.default.TypeFlags.String | import_typescript18.default.TypeFlags.Number | import_typescript18.default.TypeFlags.Boolean | import_typescript18.default.TypeFlags.BigInt | import_typescript18.default.TypeFlags.ESSymbol;
|
|
4934
|
+
var OBJECT_REFLECTION2 = /* @__PURE__ */ new Set(["getPrototypeOf", "getOwnPropertyDescriptor", "getOwnPropertyDescriptors", "prototype", "constructor", "__proto__"]);
|
|
4376
4935
|
function contradictoryArrayPredicate(sourceCode, services) {
|
|
4377
4936
|
const checker = services.program.getTypeChecker();
|
|
4378
4937
|
const stable2 = /* @__PURE__ */ new WeakMap();
|
|
4379
4938
|
let constructorCapability = false;
|
|
4380
4939
|
function matches(expression, parameter, input, target) {
|
|
4381
|
-
if ((input.flags &
|
|
4940
|
+
if ((input.flags & import_typescript18.default.TypeFlags.Unknown) === 0 || !plainPrimitiveArray(target, checker)) return false;
|
|
4382
4941
|
const call = unwrapExpression(expression);
|
|
4383
4942
|
if (call.type !== import_utils27.AST_NODE_TYPES.CallExpression || call.optional || call.arguments.length !== 1) return false;
|
|
4384
4943
|
const argument = call.arguments[0];
|
|
@@ -4406,7 +4965,7 @@ function contradictoryArrayPredicate(sourceCode, services) {
|
|
|
4406
4965
|
function plainPrimitiveArray(target, checker) {
|
|
4407
4966
|
if (!checker.isArrayType(target) || !(0, import_ts_api_utils2.isTypeReference)(target)) return false;
|
|
4408
4967
|
const [element] = checker.getTypeArguments(target);
|
|
4409
|
-
return element !== void 0 && (element.flags & PRIMITIVE_ELEMENTS) !== 0 && (element.flags & (
|
|
4968
|
+
return element !== void 0 && (element.flags & PRIMITIVE_ELEMENTS) !== 0 && (element.flags & (import_typescript18.default.TypeFlags.Enum | import_typescript18.default.TypeFlags.EnumLiteral | import_typescript18.default.TypeFlags.Intersection)) === 0;
|
|
4410
4969
|
}
|
|
4411
4970
|
function nativeBinding(identifier, sourceCode) {
|
|
4412
4971
|
const binding3 = import_utils27.ASTUtils.findVariable(sourceCode.getScope(identifier), identifier.name);
|
|
@@ -4438,7 +4997,7 @@ function ordinaryObjectUse(node) {
|
|
|
4438
4997
|
const member3 = node.parent;
|
|
4439
4998
|
if (member3?.type !== import_utils27.AST_NODE_TYPES.MemberExpression || member3.object !== node) return false;
|
|
4440
4999
|
const name = import_utils27.ASTUtils.getPropertyName(member3);
|
|
4441
|
-
return name !== null && !
|
|
5000
|
+
return name !== null && !OBJECT_REFLECTION2.has(name);
|
|
4442
5001
|
}
|
|
4443
5002
|
function ordinaryArrayReference(reference) {
|
|
4444
5003
|
if (reference.isWrite()) return false;
|
|
@@ -4471,11 +5030,11 @@ function ordinaryHostReference(reference) {
|
|
|
4471
5030
|
// src/rules/no-contradictory-type-predicate.ts
|
|
4472
5031
|
var RUNTIME_KINDS = /* @__PURE__ */ new Set(["string", "number", "bigint", "boolean", "symbol", "undefined", "object", "function"]);
|
|
4473
5032
|
var PRIMITIVE_KINDS = [
|
|
4474
|
-
[
|
|
4475
|
-
[
|
|
4476
|
-
[
|
|
4477
|
-
[
|
|
4478
|
-
[
|
|
5033
|
+
[import_typescript19.default.TypeFlags.String, "string"],
|
|
5034
|
+
[import_typescript19.default.TypeFlags.Number, "number"],
|
|
5035
|
+
[import_typescript19.default.TypeFlags.BigInt, "bigint"],
|
|
5036
|
+
[import_typescript19.default.TypeFlags.ESSymbol, "symbol"],
|
|
5037
|
+
[import_typescript19.default.TypeFlags.Undefined, "undefined"]
|
|
4479
5038
|
];
|
|
4480
5039
|
var NO_CONTRADICTORY_TYPE_PREDICATE_DOCUMENTATION = {
|
|
4481
5040
|
summary: "Keep explicit type predicates consistent with their primitive or native array membership check.",
|
|
@@ -4576,10 +5135,10 @@ var no_contradictory_type_predicate_default = createRule({
|
|
|
4576
5135
|
}
|
|
4577
5136
|
});
|
|
4578
5137
|
function contradiction(input, target, checked, checker, strictNulls) {
|
|
4579
|
-
if (strictNulls && checked === "object" && (target.flags &
|
|
5138
|
+
if (strictNulls && checked === "object" && (target.flags & import_typescript19.default.TypeFlags.NonPrimitive) !== 0 && admitsNull(input)) return "nullAccepted";
|
|
4580
5139
|
const possible = inputKinds(input, checker);
|
|
4581
5140
|
if (possible === void 0 || !possible.has(checked)) return void 0;
|
|
4582
|
-
if ((target.flags &
|
|
5141
|
+
if ((target.flags & import_typescript19.default.TypeFlags.Never) !== 0) return "contradictoryPredicate";
|
|
4583
5142
|
const promised = primitiveKinds(target, checker, false);
|
|
4584
5143
|
if (promised !== void 0) {
|
|
4585
5144
|
return !promised.has(checked) || [...promised].some((kind) => kind !== checked && possible.has(kind)) ? "contradictoryPredicate" : void 0;
|
|
@@ -4587,18 +5146,18 @@ function contradiction(input, target, checked, checker, strictNulls) {
|
|
|
4587
5146
|
return closedLiteralContradiction(input, target, checked, checker) ? "closedLiteralPredicate" : void 0;
|
|
4588
5147
|
}
|
|
4589
5148
|
function admitsNull(input) {
|
|
4590
|
-
return (input.flags &
|
|
5149
|
+
return (input.flags & import_typescript19.default.TypeFlags.Unknown) !== 0 || (input.isUnion() ? input.types : [input]).some((member3) => (member3.flags & import_typescript19.default.TypeFlags.Null) !== 0);
|
|
4591
5150
|
}
|
|
4592
5151
|
function closedLiteralContradiction(input, target, checked, checker) {
|
|
4593
5152
|
const members = target.isUnion() ? target.types : [target];
|
|
4594
|
-
const literalFlags =
|
|
5153
|
+
const literalFlags = import_typescript19.default.TypeFlags.StringLiteral | import_typescript19.default.TypeFlags.NumberLiteral | import_typescript19.default.TypeFlags.BigIntLiteral | import_typescript19.default.TypeFlags.BooleanLiteral | import_typescript19.default.TypeFlags.Null | import_typescript19.default.TypeFlags.Undefined;
|
|
4595
5154
|
if (!members.every((member3) => (member3.flags & literalFlags) !== 0)) return false;
|
|
4596
5155
|
if (members.some((member3) => literalKind(member3, checker) !== checked)) return true;
|
|
4597
|
-
if ((input.flags &
|
|
5156
|
+
if ((input.flags & import_typescript19.default.TypeFlags.Unknown) !== 0) return checked !== "undefined";
|
|
4598
5157
|
return (input.isUnion() ? input.types : [input]).some((member3) => literalKind(member3, checker) === checked && !checker.isTypeAssignableTo(member3, target));
|
|
4599
5158
|
}
|
|
4600
5159
|
function literalKind(type, checker) {
|
|
4601
|
-
if ((type.flags &
|
|
5160
|
+
if ((type.flags & import_typescript19.default.TypeFlags.BooleanLiteral) !== 0) return "boolean";
|
|
4602
5161
|
return primitiveKinds(type, checker, true)?.values().next().value;
|
|
4603
5162
|
}
|
|
4604
5163
|
function singleReturn(node) {
|
|
@@ -4626,7 +5185,7 @@ function sameParameter(declared, tested, sourceCode) {
|
|
|
4626
5185
|
return parameter !== null && parameter === import_utils28.ASTUtils.findVariable(sourceCode.getScope(tested), tested.name);
|
|
4627
5186
|
}
|
|
4628
5187
|
function inputKinds(type, checker) {
|
|
4629
|
-
if ((type.flags &
|
|
5188
|
+
if ((type.flags & import_typescript19.default.TypeFlags.Unknown) !== 0) return /* @__PURE__ */ new Set(["string", "number", "bigint", "boolean", "symbol", "undefined", "object", "function"]);
|
|
4630
5189
|
return primitiveKinds(type, checker, true);
|
|
4631
5190
|
}
|
|
4632
5191
|
function primitiveKinds(type, checker, allowLiterals) {
|
|
@@ -4638,7 +5197,7 @@ function primitiveKinds(type, checker, allowLiterals) {
|
|
|
4638
5197
|
kinds.add(kind);
|
|
4639
5198
|
continue;
|
|
4640
5199
|
}
|
|
4641
|
-
if ((member3.flags &
|
|
5200
|
+
if ((member3.flags & import_typescript19.default.TypeFlags.BooleanLiteral) === 0) return void 0;
|
|
4642
5201
|
booleans.add(checker.typeToString(member3));
|
|
4643
5202
|
}
|
|
4644
5203
|
if (booleans.size > 0) {
|
|
@@ -4652,21 +5211,21 @@ function primitiveKind(type, allowLiterals) {
|
|
|
4652
5211
|
if ((type.flags & flag) !== 0) return kind;
|
|
4653
5212
|
}
|
|
4654
5213
|
if (!allowLiterals) return void 0;
|
|
4655
|
-
if ((type.flags &
|
|
4656
|
-
if ((type.flags &
|
|
4657
|
-
if ((type.flags &
|
|
4658
|
-
if ((type.flags &
|
|
5214
|
+
if ((type.flags & import_typescript19.default.TypeFlags.StringLiteral) !== 0) return "string";
|
|
5215
|
+
if ((type.flags & import_typescript19.default.TypeFlags.NumberLiteral) !== 0) return "number";
|
|
5216
|
+
if ((type.flags & import_typescript19.default.TypeFlags.BigIntLiteral) !== 0) return "bigint";
|
|
5217
|
+
if ((type.flags & import_typescript19.default.TypeFlags.Null) !== 0) return "object";
|
|
4659
5218
|
return void 0;
|
|
4660
5219
|
}
|
|
4661
5220
|
|
|
4662
5221
|
// src/rules/no-partial-type-predicate.ts
|
|
4663
5222
|
var import_utils31 = require("@typescript-eslint/utils");
|
|
4664
5223
|
var import_ts_api_utils3 = require("ts-api-utils");
|
|
4665
|
-
var
|
|
5224
|
+
var import_typescript21 = __toESM(require("typescript"), 1);
|
|
4666
5225
|
|
|
4667
5226
|
// src/rules/_uuid-predicate-witness.ts
|
|
4668
5227
|
var import_utils30 = require("@typescript-eslint/utils");
|
|
4669
|
-
var
|
|
5228
|
+
var import_typescript20 = __toESM(require("typescript"), 1);
|
|
4670
5229
|
|
|
4671
5230
|
// src/rules/_native-runtime-unchanged.ts
|
|
4672
5231
|
var import_utils29 = require("@typescript-eslint/utils");
|
|
@@ -4773,7 +5332,7 @@ function noArguments(node) {
|
|
|
4773
5332
|
function installedZod(node, services) {
|
|
4774
5333
|
const checker = services.program.getTypeChecker();
|
|
4775
5334
|
const symbol = checker.getSymbolAtLocation(services.esTreeNodeToTSNodeMap.get(node));
|
|
4776
|
-
if (symbol === void 0 || (symbol.flags &
|
|
5335
|
+
if (symbol === void 0 || (symbol.flags & import_typescript20.default.SymbolFlags.Alias) === 0) return false;
|
|
4777
5336
|
const target = checker.getAliasedSymbol(symbol);
|
|
4778
5337
|
const declarations = target.getDeclarations();
|
|
4779
5338
|
return declarations !== void 0 && declarations.length > 0 && declarations.every((declaration) => {
|
|
@@ -4871,25 +5430,25 @@ function primitivePredicate(node, services) {
|
|
|
4871
5430
|
if (node.async || node.generator || node.typeParameters !== void 0 || node.params.length !== 1 || annotation?.type !== import_utils31.AST_NODE_TYPES.TSTypePredicate || annotation.asserts || annotation.parameterName.type !== import_utils31.AST_NODE_TYPES.Identifier || annotation.typeAnnotation === void 0 || parameter?.type !== import_utils31.AST_NODE_TYPES.Identifier || parameter.name !== annotation.parameterName.name || parameter.typeAnnotation === void 0) return void 0;
|
|
4872
5431
|
const checker = services.program.getTypeChecker();
|
|
4873
5432
|
const tsFunction = services.esTreeNodeToTSNodeMap.get(node);
|
|
4874
|
-
if (
|
|
5433
|
+
if (import_typescript21.default.isMethodDeclaration(tsFunction)) return void 0;
|
|
4875
5434
|
if (hasSeparatePredicateContract(tsFunction, checker)) return void 0;
|
|
4876
5435
|
const target = checker.getTypeAtLocation(services.esTreeNodeToTSNodeMap.get(annotation.typeAnnotation.typeAnnotation));
|
|
4877
5436
|
const kind = primitiveKind2(target);
|
|
4878
5437
|
const input = checker.getTypeAtLocation(services.esTreeNodeToTSNodeMap.get(parameter));
|
|
4879
|
-
const unsafe =
|
|
5438
|
+
const unsafe = import_typescript21.default.TypeFlags.Any | import_typescript21.default.TypeFlags.Never | import_typescript21.default.TypeFlags.TypeParameter | import_typescript21.default.TypeFlags.Conditional | import_typescript21.default.TypeFlags.IndexedAccess;
|
|
4880
5439
|
if (kind === void 0 || (input.flags & unsafe) !== 0 || !checker.isTypeAssignableTo(target, input)) return void 0;
|
|
4881
5440
|
const expression = returnedExpression2(node);
|
|
4882
5441
|
return expression === void 0 ? void 0 : { annotation, parameter, expression, kind, input, inputIsTarget: checker.isTypeAssignableTo(input, target) };
|
|
4883
5442
|
}
|
|
4884
5443
|
function primitiveKind2(type) {
|
|
4885
|
-
if ((type.flags &
|
|
4886
|
-
if ((type.flags &
|
|
4887
|
-
if ((type.flags &
|
|
4888
|
-
if ((type.flags &
|
|
5444
|
+
if ((type.flags & import_typescript21.default.TypeFlags.String) !== 0) return "string";
|
|
5445
|
+
if ((type.flags & import_typescript21.default.TypeFlags.Number) !== 0) return "number";
|
|
5446
|
+
if ((type.flags & import_typescript21.default.TypeFlags.BigInt) !== 0) return "bigint";
|
|
5447
|
+
if ((type.flags & import_typescript21.default.TypeFlags.Boolean) !== 0) return "boolean";
|
|
4889
5448
|
return void 0;
|
|
4890
5449
|
}
|
|
4891
5450
|
function numericWitnessInInput(value, input) {
|
|
4892
|
-
return (input.isUnion() ? input.types : [input]).some((member3) => (member3.flags & (
|
|
5451
|
+
return (input.isUnion() ? input.types : [input]).some((member3) => (member3.flags & (import_typescript21.default.TypeFlags.Unknown | import_typescript21.default.TypeFlags.Number)) !== 0 || Number.isFinite(value) && (0, import_ts_api_utils3.isNumberLiteralType)(member3) && member3.value === value);
|
|
4893
5452
|
}
|
|
4894
5453
|
function returnedExpression2(node) {
|
|
4895
5454
|
if (node.body === void 0) return void 0;
|
|
@@ -5002,7 +5561,7 @@ var import_utils34 = require("@typescript-eslint/utils");
|
|
|
5002
5561
|
|
|
5003
5562
|
// src/rules/_boolean-selector-contract.ts
|
|
5004
5563
|
var import_utils32 = require("@typescript-eslint/utils");
|
|
5005
|
-
var
|
|
5564
|
+
var import_typescript22 = __toESM(require("typescript"), 1);
|
|
5006
5565
|
var MEMBER_REFERENCES = /* @__PURE__ */ new WeakMap();
|
|
5007
5566
|
function isEligibleBooleanSelector(identifier, sourceCode, services) {
|
|
5008
5567
|
const owner = enclosingFunction(identifier);
|
|
@@ -5014,12 +5573,12 @@ function isEligibleBooleanSelector(identifier, sourceCode, services) {
|
|
|
5014
5573
|
const definition = binding3?.defs[0];
|
|
5015
5574
|
if (binding3?.defs.length !== 1 || definition?.type !== "Parameter" || definition.node !== owner || definition.name.type !== import_utils32.AST_NODE_TYPES.Identifier || binding3.references.some((reference) => reference.isWrite() && reference.init !== true)) return false;
|
|
5016
5575
|
const checker = services.program.getTypeChecker();
|
|
5017
|
-
if ((checker.getTypeAtLocation(services.esTreeNodeToTSNodeMap.get(definition.name)).flags &
|
|
5576
|
+
if ((checker.getTypeAtLocation(services.esTreeNodeToTSNodeMap.get(definition.name)).flags & import_typescript22.default.TypeFlags.Boolean) === 0) return false;
|
|
5018
5577
|
const parameter = definition.name.parent.type === import_utils32.AST_NODE_TYPES.AssignmentPattern ? definition.name.parent : definition.name;
|
|
5019
5578
|
const index = owner.params.indexOf(parameter);
|
|
5020
5579
|
if (index < 0 || isPureMapping(owner, sourceCode, services)) return false;
|
|
5021
5580
|
const implementation = services.esTreeNodeToTSNodeMap.get(owner);
|
|
5022
|
-
if (
|
|
5581
|
+
if (import_typescript22.default.isSetAccessorDeclaration(implementation)) return false;
|
|
5023
5582
|
const authority = { checker, index, implementation };
|
|
5024
5583
|
if (hasDeclaredContract(authority) || hasMemberCallbackReference(authority, sourceCode, services)) return false;
|
|
5025
5584
|
const callable = callableBinding2(owner, sourceCode);
|
|
@@ -5035,10 +5594,10 @@ function booleanContract(authority, type, independentlyAnnotated = false) {
|
|
|
5035
5594
|
return (type === void 0 ? [] : authority.checker.getNonNullableType(type).getCallSignatures()).some((signature) => {
|
|
5036
5595
|
const declaration = signature.declaration;
|
|
5037
5596
|
const parameter = declaration?.parameters[authority.index];
|
|
5038
|
-
if (declaration === void 0 || declaration === authority.implementation || parameter === void 0 || !
|
|
5039
|
-
if ((authority.checker.getTypeFromTypeNode(parameter.type).flags &
|
|
5597
|
+
if (declaration === void 0 || declaration === authority.implementation || parameter === void 0 || !import_typescript22.default.isParameter(parameter) || parameter.type === void 0) return false;
|
|
5598
|
+
if ((authority.checker.getTypeFromTypeNode(parameter.type).flags & import_typescript22.default.TypeFlags.BooleanLike) !== 0) return true;
|
|
5040
5599
|
const instantiated = signature.getParameters()[authority.index];
|
|
5041
|
-
return independentlyAnnotated && instantiated !== void 0 && (authority.checker.getTypeOfSymbolAtLocation(instantiated, declaration).flags &
|
|
5600
|
+
return independentlyAnnotated && instantiated !== void 0 && (authority.checker.getTypeOfSymbolAtLocation(instantiated, declaration).flags & import_typescript22.default.TypeFlags.BooleanLike) !== 0;
|
|
5042
5601
|
});
|
|
5043
5602
|
}
|
|
5044
5603
|
function callbackContract(authority, expression) {
|
|
@@ -5046,22 +5605,22 @@ function callbackContract(authority, expression) {
|
|
|
5046
5605
|
if (booleanContract(authority, checker.getContextualType(expression))) return true;
|
|
5047
5606
|
const value = outerTypedExpression(expression);
|
|
5048
5607
|
const parent = value.parent;
|
|
5049
|
-
if (
|
|
5608
|
+
if (import_typescript22.default.isCallExpression(parent)) {
|
|
5050
5609
|
const index = parent.arguments.indexOf(value);
|
|
5051
5610
|
const parameter = index < 0 ? void 0 : checker.getResolvedSignature(parent)?.declaration?.parameters[index];
|
|
5052
|
-
return parameter !== void 0 &&
|
|
5611
|
+
return parameter !== void 0 && import_typescript22.default.isParameter(parameter) && parameter.type !== void 0 && booleanContract(authority, checker.getTypeFromTypeNode(parameter.type), true);
|
|
5053
5612
|
}
|
|
5054
|
-
if (!
|
|
5613
|
+
if (!import_typescript22.default.isJsxExpression(parent) || !import_typescript22.default.isJsxAttribute(parent.parent)) return false;
|
|
5055
5614
|
const attribute = parent.parent;
|
|
5056
|
-
if (checker.getSymbolAtLocation(attribute.name)?.declarations?.some((declaration) => (
|
|
5057
|
-
if (!
|
|
5615
|
+
if (checker.getSymbolAtLocation(attribute.name)?.declarations?.some((declaration) => (import_typescript22.default.isPropertyDeclaration(declaration) || import_typescript22.default.isPropertySignature(declaration)) && declaration.type !== void 0 && booleanContract(authority, checker.getTypeFromTypeNode(declaration.type), true)) === true) return true;
|
|
5616
|
+
if (!import_typescript22.default.isIdentifier(attribute.name)) return false;
|
|
5058
5617
|
const opening = attribute.parent.parent;
|
|
5059
5618
|
const propContract = (type) => {
|
|
5060
5619
|
const property = checker.getPropertyOfType(type, attribute.name.getText());
|
|
5061
5620
|
return property !== void 0 && booleanContract(authority, checker.getTypeOfSymbolAtLocation(property, attribute), true);
|
|
5062
5621
|
};
|
|
5063
5622
|
const props = checker.getResolvedSignature(opening)?.declaration?.parameters[0];
|
|
5064
|
-
if (props !== void 0 &&
|
|
5623
|
+
if (props !== void 0 && import_typescript22.default.isParameter(props) && props.type !== void 0 && propContract(checker.getTypeFromTypeNode(props.type))) return true;
|
|
5065
5624
|
return checker.getTypeAtLocation(opening.tagName).getCallSignatures().some((signature) => {
|
|
5066
5625
|
const parameter = signature.getParameters()[0];
|
|
5067
5626
|
return parameter !== void 0 && propContract(checker.getTypeOfSymbolAtLocation(parameter, opening.tagName));
|
|
@@ -5069,41 +5628,41 @@ function callbackContract(authority, expression) {
|
|
|
5069
5628
|
}
|
|
5070
5629
|
function outerTypedExpression(node) {
|
|
5071
5630
|
let current = node;
|
|
5072
|
-
while ((
|
|
5631
|
+
while ((import_typescript22.default.isParenthesizedExpression(current.parent) || import_typescript22.default.isAsExpression(current.parent) || import_typescript22.default.isTypeAssertionExpression(current.parent) || import_typescript22.default.isNonNullExpression(current.parent) || import_typescript22.default.isSatisfiesExpression(current.parent)) && current.parent.expression === current) current = current.parent;
|
|
5073
5632
|
return current;
|
|
5074
5633
|
}
|
|
5075
5634
|
function hasDeclaredContract(authority) {
|
|
5076
5635
|
const node = authority.implementation;
|
|
5077
5636
|
const checker = authority.checker;
|
|
5078
|
-
if (
|
|
5637
|
+
if (import_typescript22.default.isArrowFunction(node) || import_typescript22.default.isFunctionExpression(node)) {
|
|
5079
5638
|
if (callbackContract(authority, node)) return true;
|
|
5080
5639
|
const binding3 = outerTypedExpression(node).parent;
|
|
5081
|
-
if ((
|
|
5082
|
-
return
|
|
5640
|
+
if ((import_typescript22.default.isVariableDeclaration(binding3) || import_typescript22.default.isPropertyDeclaration(binding3)) && binding3.type !== void 0 && booleanContract(authority, checker.getTypeFromTypeNode(binding3.type), true)) return true;
|
|
5641
|
+
return import_typescript22.default.isPropertyDeclaration(binding3) && memberContract(authority, binding3);
|
|
5083
5642
|
}
|
|
5084
|
-
if (
|
|
5085
|
-
if (!
|
|
5086
|
-
return checker.getSymbolAtLocation(node.name)?.declarations?.some((declaration) => declaration !== node &&
|
|
5643
|
+
if (import_typescript22.default.isMethodDeclaration(node)) return memberContract(authority, node);
|
|
5644
|
+
if (!import_typescript22.default.isFunctionDeclaration(node) || node.name === void 0) return false;
|
|
5645
|
+
return checker.getSymbolAtLocation(node.name)?.declarations?.some((declaration) => declaration !== node && import_typescript22.default.isFunctionDeclaration(declaration) && declaration.parameters[authority.index]?.type !== void 0) === true;
|
|
5087
5646
|
}
|
|
5088
5647
|
function memberContract(authority, member3) {
|
|
5089
5648
|
const owner = member3.parent;
|
|
5090
5649
|
const checker = authority.checker;
|
|
5091
5650
|
const symbol = checker.getSymbolAtLocation(member3.name);
|
|
5092
|
-
if (symbol === void 0 ||
|
|
5651
|
+
if (symbol === void 0 || import_typescript22.default.isPrivateIdentifier(member3.name)) return false;
|
|
5093
5652
|
const matches = (type, independentlyAnnotated = false) => {
|
|
5094
5653
|
const property = type.getProperties().find((candidate2) => candidate2.escapedName === symbol.escapedName);
|
|
5095
5654
|
return property !== void 0 && booleanContract(authority, checker.getTypeOfSymbolAtLocation(property, member3), independentlyAnnotated);
|
|
5096
5655
|
};
|
|
5097
|
-
if (
|
|
5656
|
+
if (import_typescript22.default.isObjectLiteralExpression(owner)) {
|
|
5098
5657
|
const contextual = checker.getContextualType(owner);
|
|
5099
5658
|
const binding3 = outerTypedExpression(owner).parent;
|
|
5100
|
-
if (
|
|
5659
|
+
if (import_typescript22.default.isVariableDeclaration(binding3) && binding3.type !== void 0 && matches(checker.getTypeFromTypeNode(binding3.type), true)) return true;
|
|
5101
5660
|
return contextual !== void 0 && matches(contextual);
|
|
5102
5661
|
}
|
|
5103
|
-
if (!
|
|
5104
|
-
const modifiers =
|
|
5105
|
-
if ((modifiers &
|
|
5106
|
-
return owner.heritageClauses?.some((clause) => clause.types.some((heritage) => matches(checker.getTypeAtLocation((modifiers &
|
|
5662
|
+
if (!import_typescript22.default.isClassDeclaration(owner) && !import_typescript22.default.isClassExpression(owner)) return false;
|
|
5663
|
+
const modifiers = import_typescript22.default.getCombinedModifierFlags(member3);
|
|
5664
|
+
if ((modifiers & import_typescript22.default.ModifierFlags.Private) !== 0) return false;
|
|
5665
|
+
return owner.heritageClauses?.some((clause) => clause.types.some((heritage) => matches(checker.getTypeAtLocation((modifiers & import_typescript22.default.ModifierFlags.Static) !== 0 ? heritage.expression : heritage), true))) === true;
|
|
5107
5666
|
}
|
|
5108
5667
|
function callableBinding2(owner, sourceCode) {
|
|
5109
5668
|
if (owner.type === import_utils32.AST_NODE_TYPES.FunctionDeclaration && owner.id !== null) return import_utils32.ASTUtils.findVariable(sourceCode.getScope(owner), owner.id.name);
|
|
@@ -5123,7 +5682,7 @@ function hasCallbackReference(binding3, authority, sourceCode, services, seen) {
|
|
|
5123
5682
|
const jsxAttribute = parent?.type === import_utils32.AST_NODE_TYPES.JSXExpressionContainer && parent.parent.type === import_utils32.AST_NODE_TYPES.JSXAttribute;
|
|
5124
5683
|
if (callArgument || jsxAttribute) {
|
|
5125
5684
|
const expression = services.esTreeNodeToTSNodeMap.get(value);
|
|
5126
|
-
if (
|
|
5685
|
+
if (import_typescript22.default.isExpression(expression) && callbackContract(authority, expression)) return true;
|
|
5127
5686
|
}
|
|
5128
5687
|
if (parent?.type === import_utils32.AST_NODE_TYPES.CallExpression && parent.callee === value && forwardedCallbackParameter(parent, authority, sourceCode, services)) return true;
|
|
5129
5688
|
let selected = value;
|
|
@@ -5148,20 +5707,20 @@ function forwardedCallbackParameter(call, authority, sourceCode, services) {
|
|
|
5148
5707
|
const binding3 = import_utils32.ASTUtils.findVariable(sourceCode.getScope(argument), argument.name);
|
|
5149
5708
|
const definition = binding3?.defs[0];
|
|
5150
5709
|
if (binding3?.defs.length !== 1 || definition?.type !== "Parameter" || definition.node !== wrapper || definition.name.type !== import_utils32.AST_NODE_TYPES.Identifier || binding3.references.some((reference) => reference.isWrite() && reference.init !== true)) return false;
|
|
5151
|
-
if ((authority.checker.getTypeAtLocation(services.esTreeNodeToTSNodeMap.get(definition.name)).flags &
|
|
5710
|
+
if ((authority.checker.getTypeAtLocation(services.esTreeNodeToTSNodeMap.get(definition.name)).flags & import_typescript22.default.TypeFlags.Boolean) === 0) return false;
|
|
5152
5711
|
const parameter = definition.name.parent.type === import_utils32.AST_NODE_TYPES.AssignmentPattern ? definition.name.parent : definition.name;
|
|
5153
5712
|
const index = wrapper.params.indexOf(parameter);
|
|
5154
5713
|
const implementation = services.esTreeNodeToTSNodeMap.get(wrapper);
|
|
5155
|
-
return index >= 0 && (
|
|
5714
|
+
return index >= 0 && (import_typescript22.default.isArrowFunction(implementation) || import_typescript22.default.isFunctionExpression(implementation)) && callbackContract({ checker: authority.checker, index, implementation }, implementation);
|
|
5156
5715
|
}
|
|
5157
5716
|
function hasMemberCallbackReference(authority, sourceCode, services) {
|
|
5158
5717
|
const node = authority.implementation;
|
|
5159
|
-
const member3 =
|
|
5160
|
-
if (member3 === void 0 || !
|
|
5718
|
+
const member3 = import_typescript22.default.isMethodDeclaration(node) ? node : import_typescript22.default.isArrowFunction(node) || import_typescript22.default.isFunctionExpression(node) ? outerTypedExpression(node).parent : void 0;
|
|
5719
|
+
if (member3 === void 0 || !import_typescript22.default.isMethodDeclaration(member3) && !import_typescript22.default.isPropertyDeclaration(member3) && !import_typescript22.default.isPropertyAssignment(member3)) return false;
|
|
5161
5720
|
let references = MEMBER_REFERENCES.get(sourceCode);
|
|
5162
5721
|
if (references === void 0) {
|
|
5163
5722
|
let visit2 = function(current) {
|
|
5164
|
-
if (
|
|
5723
|
+
if (import_typescript22.default.isPropertyAccessExpression(current)) {
|
|
5165
5724
|
const target = authority.checker.getSymbolAtLocation(current.name);
|
|
5166
5725
|
for (const declaration of target?.declarations ?? []) {
|
|
5167
5726
|
const values = collected.get(declaration) ?? [];
|
|
@@ -5169,7 +5728,7 @@ function hasMemberCallbackReference(authority, sourceCode, services) {
|
|
|
5169
5728
|
collected.set(declaration, values);
|
|
5170
5729
|
}
|
|
5171
5730
|
}
|
|
5172
|
-
|
|
5731
|
+
import_typescript22.default.forEachChild(current, visit2);
|
|
5173
5732
|
};
|
|
5174
5733
|
var visit = visit2;
|
|
5175
5734
|
const collected = /* @__PURE__ */ new Map();
|
|
@@ -5180,14 +5739,14 @@ function hasMemberCallbackReference(authority, sourceCode, services) {
|
|
|
5180
5739
|
return references.get(member3)?.some((reference) => {
|
|
5181
5740
|
let value = outerTypedExpression(reference);
|
|
5182
5741
|
const bind = value.parent;
|
|
5183
|
-
if (
|
|
5742
|
+
if (import_typescript22.default.isPropertyAccessExpression(bind) && bind.expression === value && bind.name.text === "bind" && import_typescript22.default.isCallExpression(bind.parent) && bind.parent.expression === bind && bind.parent.arguments.length === 1) {
|
|
5184
5743
|
const declaration = authority.checker.getResolvedSignature(bind.parent)?.declaration;
|
|
5185
5744
|
if (declaration === void 0 || !services.program.isSourceFileDefaultLibrary(declaration.getSourceFile())) return false;
|
|
5186
5745
|
value = outerTypedExpression(bind.parent);
|
|
5187
5746
|
}
|
|
5188
5747
|
const parent = value.parent;
|
|
5189
|
-
const callback =
|
|
5190
|
-
const jsx =
|
|
5748
|
+
const callback = import_typescript22.default.isCallExpression(parent) && parent.arguments.some((argument) => argument === value);
|
|
5749
|
+
const jsx = import_typescript22.default.isJsxExpression(parent) && import_typescript22.default.isJsxAttribute(parent.parent);
|
|
5191
5750
|
return (callback || jsx) && callbackContract(authority, value);
|
|
5192
5751
|
}) === true;
|
|
5193
5752
|
}
|
|
@@ -5231,21 +5790,21 @@ function sameTarget(left, right, sourceCode, services, operation2) {
|
|
|
5231
5790
|
if (!operation2) return true;
|
|
5232
5791
|
const checker = services.program.getTypeChecker();
|
|
5233
5792
|
const property = checker.getSymbolAtLocation(services.esTreeNodeToTSNodeMap.get(left.property));
|
|
5234
|
-
return property !== void 0 && property === checker.getSymbolAtLocation(services.esTreeNodeToTSNodeMap.get(right.property)) && property.declarations?.every((declaration) =>
|
|
5793
|
+
return property !== void 0 && property === checker.getSymbolAtLocation(services.esTreeNodeToTSNodeMap.get(right.property)) && property.declarations?.every((declaration) => import_typescript22.default.isMethodDeclaration(declaration)) === true;
|
|
5235
5794
|
}
|
|
5236
5795
|
function pureValue(node, sourceCode, services) {
|
|
5237
5796
|
const value = unwrapExpression(node);
|
|
5238
5797
|
if (value.type === import_utils32.AST_NODE_TYPES.MemberExpression && !value.computed) return value.object.type === import_utils32.AST_NODE_TYPES.Super || pureValue(value.object, sourceCode, services);
|
|
5239
5798
|
if (value.type === import_utils32.AST_NODE_TYPES.ChainExpression) return pureValue(value.expression, sourceCode, services);
|
|
5240
5799
|
if (value.type === import_utils32.AST_NODE_TYPES.UnaryExpression && (value.operator === "!" || value.operator === "typeof" || value.operator === "void")) return pureValue(value.argument, sourceCode, services);
|
|
5241
|
-
if (value.type === import_utils32.AST_NODE_TYPES.UnaryExpression && (value.operator === "+" || value.operator === "-" || value.operator === "~")) return
|
|
5800
|
+
if (value.type === import_utils32.AST_NODE_TYPES.UnaryExpression && (value.operator === "+" || value.operator === "-" || value.operator === "~")) return primitiveValue2(value.argument, services) && pureValue(value.argument, sourceCode, services);
|
|
5242
5801
|
if (!import_utils32.ASTUtils.hasSideEffect(value, sourceCode, { considerGetters: true, considerImplicitTypeConversion: true })) return true;
|
|
5243
5802
|
if (value.type !== import_utils32.AST_NODE_TYPES.BinaryExpression || value.left.type === import_utils32.AST_NODE_TYPES.PrivateIdentifier) return false;
|
|
5244
|
-
return
|
|
5803
|
+
return primitiveValue2(value.left, services) && primitiveValue2(value.right, services) && pureValue(value.left, sourceCode, services) && pureValue(value.right, sourceCode, services);
|
|
5245
5804
|
}
|
|
5246
|
-
function
|
|
5805
|
+
function primitiveValue2(operand, services) {
|
|
5247
5806
|
const type = services.program.getTypeChecker().getTypeAtLocation(services.esTreeNodeToTSNodeMap.get(operand));
|
|
5248
|
-
return (type.isUnion() ? type.types : [type]).every((member3) => (member3.flags & (
|
|
5807
|
+
return (type.isUnion() ? type.types : [type]).every((member3) => (member3.flags & (import_typescript22.default.TypeFlags.StringLike | import_typescript22.default.TypeFlags.NumberLike | import_typescript22.default.TypeFlags.BooleanLike | import_typescript22.default.TypeFlags.BigIntLike | import_typescript22.default.TypeFlags.Null | import_typescript22.default.TypeFlags.Undefined)) !== 0);
|
|
5249
5808
|
}
|
|
5250
5809
|
|
|
5251
5810
|
// src/rules/_literal-selector-fix.ts
|
|
@@ -5476,7 +6035,7 @@ function isDirectTest(identifier) {
|
|
|
5476
6035
|
// src/rules/no-invalid-zod-custom-parse.ts
|
|
5477
6036
|
var import_utils36 = require("@typescript-eslint/utils");
|
|
5478
6037
|
var import_ts_api_utils4 = require("ts-api-utils");
|
|
5479
|
-
var
|
|
6038
|
+
var import_typescript23 = __toESM(require("typescript"), 1);
|
|
5480
6039
|
|
|
5481
6040
|
// src/rules/_import-specifier-name.ts
|
|
5482
6041
|
var import_utils35 = require("@typescript-eslint/utils");
|
|
@@ -5572,17 +6131,17 @@ function nativeZodDeclaration(signature) {
|
|
|
5572
6131
|
}
|
|
5573
6132
|
function primitiveDomain(type) {
|
|
5574
6133
|
if (type.isUnion()) return type.types.every(primitiveDomain);
|
|
5575
|
-
if ((type.flags & (
|
|
5576
|
-
const flags =
|
|
6134
|
+
if ((type.flags & (import_typescript23.default.TypeFlags.Enum | import_typescript23.default.TypeFlags.EnumLiteral)) !== 0) return false;
|
|
6135
|
+
const flags = import_typescript23.default.TypeFlags.String | import_typescript23.default.TypeFlags.Number | import_typescript23.default.TypeFlags.BigInt | import_typescript23.default.TypeFlags.BooleanLiteral | import_typescript23.default.TypeFlags.StringLiteral | import_typescript23.default.TypeFlags.NumberLiteral | import_typescript23.default.TypeFlags.BigIntLiteral | import_typescript23.default.TypeFlags.Null | import_typescript23.default.TypeFlags.Undefined | import_typescript23.default.TypeFlags.Never;
|
|
5577
6136
|
return (type.flags & flags) !== 0;
|
|
5578
6137
|
}
|
|
5579
6138
|
function acceptsPrimitive(type, value) {
|
|
5580
6139
|
if (type.isUnion()) return type.types.some((member3) => acceptsPrimitive(member3, value));
|
|
5581
|
-
if (value === null) return (type.flags &
|
|
5582
|
-
if (typeof value === "string") return (type.flags &
|
|
5583
|
-
if (typeof value === "number") return (type.flags &
|
|
6140
|
+
if (value === null) return (type.flags & import_typescript23.default.TypeFlags.Null) !== 0;
|
|
6141
|
+
if (typeof value === "string") return (type.flags & import_typescript23.default.TypeFlags.String) !== 0 || (0, import_ts_api_utils4.isStringLiteralType)(type) && type.value === value;
|
|
6142
|
+
if (typeof value === "number") return (type.flags & import_typescript23.default.TypeFlags.Number) !== 0 || (0, import_ts_api_utils4.isNumberLiteralType)(type) && type.value === value;
|
|
5584
6143
|
if (typeof value === "boolean") return (0, import_ts_api_utils4.isBooleanLiteralType)(type) && type.intrinsicName === String(value);
|
|
5585
|
-
return (type.flags &
|
|
6144
|
+
return (type.flags & import_typescript23.default.TypeFlags.BigInt) !== 0 || (0, import_ts_api_utils4.isBigIntLiteralType)(type) && bigintValue(type) === value;
|
|
5586
6145
|
}
|
|
5587
6146
|
function bigintValue(type) {
|
|
5588
6147
|
return BigInt(`${type.value.negative ? "-" : ""}${type.value.base10Value}`);
|
|
@@ -5599,7 +6158,7 @@ function primitiveLiteral(node) {
|
|
|
5599
6158
|
|
|
5600
6159
|
// src/rules/no-contradictory-overload-return.ts
|
|
5601
6160
|
var import_utils37 = require("@typescript-eslint/utils");
|
|
5602
|
-
var
|
|
6161
|
+
var import_typescript24 = __toESM(require("typescript"), 1);
|
|
5603
6162
|
var LIMIT = 32;
|
|
5604
6163
|
var NO_CONTRADICTORY_OVERLOAD_RETURN_DOCUMENTATION = {
|
|
5605
6164
|
summary: "Preserve the input/result relationship promised by literal overloads.",
|
|
@@ -5697,16 +6256,16 @@ function privateOverloadFix(sourceCode, filename, node, implementation, proof, s
|
|
|
5697
6256
|
return edits.length === 0 ? null : (fixer) => edits.map((edit) => fixer.replaceText(edit.node, edit.text));
|
|
5698
6257
|
}
|
|
5699
6258
|
function directResultSyntax(node) {
|
|
5700
|
-
if (
|
|
5701
|
-
if (
|
|
5702
|
-
if (!
|
|
5703
|
-
return node.members.every((member3) =>
|
|
6259
|
+
if (import_typescript24.default.isParenthesizedTypeNode(node)) return directResultSyntax(node.type);
|
|
6260
|
+
if (import_typescript24.default.isUnionTypeNode(node)) return node.types.length <= LIMIT && node.types.every(directResultSyntax);
|
|
6261
|
+
if (!import_typescript24.default.isTypeLiteralNode(node)) return primitiveResultSyntax(node);
|
|
6262
|
+
return node.members.every((member3) => import_typescript24.default.isPropertySignature(member3) && propertyKey(member3.name) !== void 0 && member3.type !== void 0 && primitiveResultSyntax(member3.type));
|
|
5704
6263
|
}
|
|
5705
6264
|
function primitiveResultSyntax(node) {
|
|
5706
|
-
if (
|
|
5707
|
-
if (
|
|
5708
|
-
if (
|
|
5709
|
-
return node.kind ===
|
|
6265
|
+
if (import_typescript24.default.isParenthesizedTypeNode(node)) return primitiveResultSyntax(node.type);
|
|
6266
|
+
if (import_typescript24.default.isUnionTypeNode(node)) return node.types.length <= LIMIT && node.types.every(primitiveResultSyntax);
|
|
6267
|
+
if (import_typescript24.default.isLiteralTypeNode(node)) return primitiveLiteral2(node.literal) !== void 0;
|
|
6268
|
+
return node.kind === import_typescript24.default.SyntaxKind.StringKeyword || node.kind === import_typescript24.default.SyntaxKind.NumberKeyword || node.kind === import_typescript24.default.SyntaxKind.BooleanKeyword || node.kind === import_typescript24.default.SyntaxKind.UndefinedKeyword || node.kind === import_typescript24.default.SyntaxKind.NeverKeyword;
|
|
5710
6269
|
}
|
|
5711
6270
|
function branchResultType(branch, sourceCode, services) {
|
|
5712
6271
|
const valueType = (literal2) => typeof literal2.value === "string" ? sourceCode.getText(services.tsNodeToESTreeNodeMap.get(literal2.node)) : String(literal2.value);
|
|
@@ -5715,11 +6274,11 @@ function branchResultType(branch, sourceCode, services) {
|
|
|
5715
6274
|
}
|
|
5716
6275
|
function implementationProof(node, checker) {
|
|
5717
6276
|
const parameter = directParameter(node);
|
|
5718
|
-
if (!
|
|
6277
|
+
if (!import_typescript24.default.isSourceFile(node.parent) || node.name === void 0 || node.body?.statements.length !== 1 || node.typeParameters !== void 0 || node.asteriskToken !== void 0 || node.modifiers?.some((modifier) => modifier.kind === import_typescript24.default.SyntaxKind.AsyncKeyword) || parameter === void 0) return void 0;
|
|
5719
6278
|
const returned2 = node.body.statements[0];
|
|
5720
|
-
if (returned2 === void 0 || !
|
|
6279
|
+
if (returned2 === void 0 || !import_typescript24.default.isReturnStatement(returned2) || returned2.expression === void 0) return void 0;
|
|
5721
6280
|
const expression = unparen(returned2.expression);
|
|
5722
|
-
if (!
|
|
6281
|
+
if (!import_typescript24.default.isConditionalExpression(expression)) return void 0;
|
|
5723
6282
|
const condition2 = equality(expression.condition, checker.getSymbolAtLocation(parameter.name), checker);
|
|
5724
6283
|
const yes = branchValue(expression.whenTrue);
|
|
5725
6284
|
const no = branchValue(expression.whenFalse);
|
|
@@ -5733,21 +6292,21 @@ function implementationProof(node, checker) {
|
|
|
5733
6292
|
}
|
|
5734
6293
|
function directParameter(node) {
|
|
5735
6294
|
const parameter = node.parameters[0];
|
|
5736
|
-
if (node.parameters.length !== 1 || parameter === void 0 || !
|
|
6295
|
+
if (node.parameters.length !== 1 || parameter === void 0 || !import_typescript24.default.isIdentifier(parameter.name) || parameter.name.text === "this" || parameter.type === void 0 || parameter.questionToken !== void 0 || parameter.dotDotDotToken !== void 0 || parameter.initializer !== void 0) return void 0;
|
|
5737
6296
|
return { name: parameter.name, type: parameter.type };
|
|
5738
6297
|
}
|
|
5739
6298
|
function overloadCases(node, implementationOutput, checker) {
|
|
5740
6299
|
const declarations = node.name === void 0 ? void 0 : checker.getSymbolAtLocation(node.name)?.declarations;
|
|
5741
|
-
if (declarations === void 0 || declarations.length < 3 || declarations.length > LIMIT + 1 || declarations.some((declaration) => !
|
|
6300
|
+
if (declarations === void 0 || declarations.length < 3 || declarations.length > LIMIT + 1 || declarations.some((declaration) => !import_typescript24.default.isFunctionDeclaration(declaration))) return void 0;
|
|
5742
6301
|
const cases = [];
|
|
5743
6302
|
const seen = /* @__PURE__ */ new Set();
|
|
5744
6303
|
const implementationParameter = directParameter(node);
|
|
5745
6304
|
if (implementationParameter === void 0) return void 0;
|
|
5746
6305
|
const implementationInput = checker.getTypeAtLocation(implementationParameter.type);
|
|
5747
6306
|
for (const declaration of declarations) {
|
|
5748
|
-
if (!
|
|
6307
|
+
if (!import_typescript24.default.isFunctionDeclaration(declaration) || declaration === node) continue;
|
|
5749
6308
|
const parameter = directParameter(declaration);
|
|
5750
|
-
if (declaration.body !== void 0 || declaration.typeParameters !== void 0 || parameter === void 0 || !
|
|
6309
|
+
if (declaration.body !== void 0 || declaration.typeParameters !== void 0 || parameter === void 0 || !import_typescript24.default.isLiteralTypeNode(parameter.type)) return void 0;
|
|
5751
6310
|
const input = primitiveLiteral2(parameter.type.literal);
|
|
5752
6311
|
const signature = checker.getSignatureFromDeclaration(declaration);
|
|
5753
6312
|
if (input === void 0 || seen.has(input.value) || signature === void 0 || !checker.isTypeAssignableTo(checker.getTypeAtLocation(parameter.type), implementationInput)) return void 0;
|
|
@@ -5760,11 +6319,11 @@ function overloadCases(node, implementationOutput, checker) {
|
|
|
5760
6319
|
}
|
|
5761
6320
|
function equality(expression, parameter, checker) {
|
|
5762
6321
|
const value = unparen(expression);
|
|
5763
|
-
if (parameter === void 0 || !
|
|
6322
|
+
if (parameter === void 0 || !import_typescript24.default.isBinaryExpression(value) || value.operatorToken.kind !== import_typescript24.default.SyntaxKind.EqualsEqualsEqualsToken && value.operatorToken.kind !== import_typescript24.default.SyntaxKind.ExclamationEqualsEqualsToken) return void 0;
|
|
5764
6323
|
for (const [tested, expected] of [[value.left, value.right], [value.right, value.left]]) {
|
|
5765
6324
|
const named3 = unparen(tested);
|
|
5766
6325
|
const condition2 = primitiveLiteral2(expected);
|
|
5767
|
-
if (
|
|
6326
|
+
if (import_typescript24.default.isIdentifier(named3) && checker.getSymbolAtLocation(named3) === parameter && condition2 !== void 0) return { condition: condition2, equal: value.operatorToken.kind === import_typescript24.default.SyntaxKind.EqualsEqualsEqualsToken };
|
|
5768
6327
|
}
|
|
5769
6328
|
return void 0;
|
|
5770
6329
|
}
|
|
@@ -5772,10 +6331,10 @@ function branchValue(expression) {
|
|
|
5772
6331
|
const node = unparen(expression);
|
|
5773
6332
|
const literal2 = primitiveLiteral2(node);
|
|
5774
6333
|
if (literal2 !== void 0) return { kind: "literal", node, value: literal2 };
|
|
5775
|
-
if (!
|
|
6334
|
+
if (!import_typescript24.default.isObjectLiteralExpression(node) || node.properties.length > LIMIT) return void 0;
|
|
5776
6335
|
const values = /* @__PURE__ */ new Map();
|
|
5777
6336
|
for (const property of node.properties) {
|
|
5778
|
-
if (!
|
|
6337
|
+
if (!import_typescript24.default.isPropertyAssignment(property)) return void 0;
|
|
5779
6338
|
const name = propertyKey(property.name);
|
|
5780
6339
|
const value = primitiveLiteral2(property.initializer);
|
|
5781
6340
|
if (name === void 0 || name === "__proto__" || values.has(name) || value === void 0) return void 0;
|
|
@@ -5799,30 +6358,30 @@ function mismatches(branch, expected, checker) {
|
|
|
5799
6358
|
}
|
|
5800
6359
|
function plainPrimitive(type) {
|
|
5801
6360
|
const members = type.isUnion() ? type.types : [type];
|
|
5802
|
-
const allowed =
|
|
5803
|
-
return members.length <= LIMIT && members.every((member3) => (member3.flags & allowed) !== 0 && (member3.flags & (
|
|
6361
|
+
const allowed = import_typescript24.default.TypeFlags.String | import_typescript24.default.TypeFlags.StringLiteral | import_typescript24.default.TypeFlags.Number | import_typescript24.default.TypeFlags.NumberLiteral | import_typescript24.default.TypeFlags.BooleanLiteral | import_typescript24.default.TypeFlags.Null | import_typescript24.default.TypeFlags.Undefined | import_typescript24.default.TypeFlags.Never;
|
|
6362
|
+
return members.length <= LIMIT && members.every((member3) => (member3.flags & allowed) !== 0 && (member3.flags & (import_typescript24.default.TypeFlags.Enum | import_typescript24.default.TypeFlags.EnumLiteral)) === 0);
|
|
5804
6363
|
}
|
|
5805
6364
|
function primitiveLiteral2(expression) {
|
|
5806
6365
|
const node = unparen(expression);
|
|
5807
|
-
if (
|
|
5808
|
-
if (node.kind ===
|
|
5809
|
-
if (node.kind ===
|
|
5810
|
-
if (node.kind ===
|
|
5811
|
-
if (
|
|
5812
|
-
if (
|
|
5813
|
-
const value = Number(node.operand.text) * (node.operator ===
|
|
6366
|
+
if (import_typescript24.default.isStringLiteral(node)) return { node, value: node.text };
|
|
6367
|
+
if (node.kind === import_typescript24.default.SyntaxKind.TrueKeyword) return { node, value: true };
|
|
6368
|
+
if (node.kind === import_typescript24.default.SyntaxKind.FalseKeyword) return { node, value: false };
|
|
6369
|
+
if (node.kind === import_typescript24.default.SyntaxKind.NullKeyword) return { node, value: null };
|
|
6370
|
+
if (import_typescript24.default.isNumericLiteral(node) && Number.isFinite(Number(node.text))) return { node, value: Number(node.text) };
|
|
6371
|
+
if (import_typescript24.default.isPrefixUnaryExpression(node) && (node.operator === import_typescript24.default.SyntaxKind.MinusToken || node.operator === import_typescript24.default.SyntaxKind.PlusToken) && import_typescript24.default.isNumericLiteral(node.operand)) {
|
|
6372
|
+
const value = Number(node.operand.text) * (node.operator === import_typescript24.default.SyntaxKind.MinusToken ? -1 : 1);
|
|
5814
6373
|
if (Number.isFinite(value)) return { node, value };
|
|
5815
6374
|
}
|
|
5816
6375
|
return void 0;
|
|
5817
6376
|
}
|
|
5818
6377
|
function propertyKey(name) {
|
|
5819
|
-
if (
|
|
5820
|
-
if (
|
|
6378
|
+
if (import_typescript24.default.isIdentifier(name) || import_typescript24.default.isStringLiteral(name)) return name.text;
|
|
6379
|
+
if (import_typescript24.default.isNumericLiteral(name) && Number.isFinite(Number(name.text))) return String(Number(name.text));
|
|
5821
6380
|
return void 0;
|
|
5822
6381
|
}
|
|
5823
6382
|
function unparen(expression) {
|
|
5824
6383
|
let node = expression;
|
|
5825
|
-
while (
|
|
6384
|
+
while (import_typescript24.default.isParenthesizedExpression(node)) node = node.expression;
|
|
5826
6385
|
return node;
|
|
5827
6386
|
}
|
|
5828
6387
|
|
|
@@ -12412,7 +12971,7 @@ function branchTerminates(branch) {
|
|
|
12412
12971
|
|
|
12413
12972
|
// src/rules/no-json-stringify-object-equality.ts
|
|
12414
12973
|
var import_utils76 = require("@typescript-eslint/utils");
|
|
12415
|
-
var
|
|
12974
|
+
var import_typescript25 = __toESM(require("typescript"), 1);
|
|
12416
12975
|
|
|
12417
12976
|
// src/rules/_existing-domain-comparison-fix.ts
|
|
12418
12977
|
var import_utils75 = require("@typescript-eslint/utils");
|
|
@@ -12607,7 +13166,7 @@ var EQUALITY_OPERATORS = /* @__PURE__ */ new Set([
|
|
|
12607
13166
|
"==",
|
|
12608
13167
|
"==="
|
|
12609
13168
|
]);
|
|
12610
|
-
var PRIMITIVE_FLAGS =
|
|
13169
|
+
var PRIMITIVE_FLAGS = import_typescript25.default.TypeFlags.BigIntLike | import_typescript25.default.TypeFlags.BooleanLike | import_typescript25.default.TypeFlags.ESSymbolLike | import_typescript25.default.TypeFlags.Never | import_typescript25.default.TypeFlags.Null | import_typescript25.default.TypeFlags.NumberLike | import_typescript25.default.TypeFlags.StringLike | import_typescript25.default.TypeFlags.Undefined | import_typescript25.default.TypeFlags.Void;
|
|
12611
13170
|
function unwrapComparisonExpression(node) {
|
|
12612
13171
|
let current = unwrapExpression(node);
|
|
12613
13172
|
while (current.type === import_utils76.AST_NODE_TYPES.ChainExpression) {
|
|
@@ -12662,7 +13221,7 @@ function typeMayContainObject(type, checker) {
|
|
|
12662
13221
|
return type.types.some((member3) => typeMayContainObject(member3, checker));
|
|
12663
13222
|
}
|
|
12664
13223
|
if ((type.flags & PRIMITIVE_FLAGS) !== 0) return false;
|
|
12665
|
-
if ((type.flags & (
|
|
13224
|
+
if ((type.flags & (import_typescript25.default.TypeFlags.Any | import_typescript25.default.TypeFlags.Unknown | import_typescript25.default.TypeFlags.TypeParameter)) !== 0) {
|
|
12666
13225
|
return true;
|
|
12667
13226
|
}
|
|
12668
13227
|
if (checker.isArrayType(type) || checker.isTupleType(type)) {
|
|
@@ -12670,7 +13229,7 @@ function typeMayContainObject(type, checker) {
|
|
|
12670
13229
|
return elements.some((element) => typeMayContainObject(element, checker));
|
|
12671
13230
|
}
|
|
12672
13231
|
const symbolName = type.getSymbol()?.getName();
|
|
12673
|
-
if ((symbolName === "Array" || symbolName === "ReadonlyArray") && (type.flags &
|
|
13232
|
+
if ((symbolName === "Array" || symbolName === "ReadonlyArray") && (type.flags & import_typescript25.default.TypeFlags.Object) !== 0) {
|
|
12674
13233
|
const elements = checker.getTypeArguments(type);
|
|
12675
13234
|
return elements.length === 0 || elements.some((element) => typeMayContainObject(element, checker));
|
|
12676
13235
|
}
|
|
@@ -13116,7 +13675,7 @@ function zeroBoundSemantic(method) {
|
|
|
13116
13675
|
|
|
13117
13676
|
// src/rules/no-in-operator-on-built-in-collections.ts
|
|
13118
13677
|
var import_utils79 = require("@typescript-eslint/utils");
|
|
13119
|
-
var
|
|
13678
|
+
var ts27 = __toESM(require("typescript"), 1);
|
|
13120
13679
|
|
|
13121
13680
|
// src/rules/_collection-property-fix.ts
|
|
13122
13681
|
var import_utils78 = require("@typescript-eslint/utils");
|
|
@@ -13216,7 +13775,7 @@ function isDefaultLibraryCollection(node, services) {
|
|
|
13216
13775
|
const checker = services.program.getTypeChecker();
|
|
13217
13776
|
const tsNode = services.esTreeNodeToTSNodeMap.get(node);
|
|
13218
13777
|
const type = checker.getTypeAtLocation(tsNode);
|
|
13219
|
-
if ((type.flags & (
|
|
13778
|
+
if ((type.flags & (ts27.TypeFlags.Any | ts27.TypeFlags.Unknown | ts27.TypeFlags.Never | ts27.TypeFlags.TypeParameter | ts27.TypeFlags.Union | ts27.TypeFlags.Intersection)) !== 0) {
|
|
13220
13779
|
return false;
|
|
13221
13780
|
}
|
|
13222
13781
|
return isDefaultLibraryCollectionSymbol(type.getSymbol(), services);
|
|
@@ -13227,7 +13786,7 @@ function isDefaultLibraryCollectionSymbol(symbol, services) {
|
|
|
13227
13786
|
return declarations.length > 0 && declarations.every(
|
|
13228
13787
|
(declaration) => services.program.isSourceFileDefaultLibrary(declaration.getSourceFile())
|
|
13229
13788
|
) && declarations.some(
|
|
13230
|
-
(declaration) =>
|
|
13789
|
+
(declaration) => ts27.isInterfaceDeclaration(declaration) && declaration.name.text === symbol.name
|
|
13231
13790
|
);
|
|
13232
13791
|
}
|
|
13233
13792
|
var no_in_operator_on_built_in_collections_default = createRule({
|
|
@@ -13538,7 +14097,7 @@ var no_redundant_optional_array_default_default = createRule({
|
|
|
13538
14097
|
|
|
13539
14098
|
// src/rules/interface-contract-members-private.ts
|
|
13540
14099
|
var import_utils83 = require("@typescript-eslint/utils");
|
|
13541
|
-
var
|
|
14100
|
+
var ts28 = __toESM(require("typescript"), 1);
|
|
13542
14101
|
|
|
13543
14102
|
// src/rules/_class-private.ts
|
|
13544
14103
|
var import_utils82 = require("@typescript-eslint/utils");
|
|
@@ -13708,15 +14267,15 @@ function candidate(member3) {
|
|
|
13708
14267
|
}
|
|
13709
14268
|
function interfaceNames(services, owner) {
|
|
13710
14269
|
const tsOwner = services.esTreeNodeToTSNodeMap.get(owner);
|
|
13711
|
-
if (!
|
|
13712
|
-
const implemented = tsOwner.heritageClauses?.filter((clause) => clause.token ===
|
|
14270
|
+
if (!ts28.isClassDeclaration(tsOwner) && !ts28.isClassExpression(tsOwner)) return null;
|
|
14271
|
+
const implemented = tsOwner.heritageClauses?.filter((clause) => clause.token === ts28.SyntaxKind.ImplementsKeyword) ?? [];
|
|
13713
14272
|
if (implemented.length === 0) return null;
|
|
13714
14273
|
const checker = services.program.getTypeChecker();
|
|
13715
14274
|
const names = /* @__PURE__ */ new Set();
|
|
13716
14275
|
for (const clause of implemented) {
|
|
13717
14276
|
for (const contract of clause.types) {
|
|
13718
14277
|
const type = checker.getTypeAtLocation(contract);
|
|
13719
|
-
if ((type.flags & (
|
|
14278
|
+
if ((type.flags & (ts28.TypeFlags.Any | ts28.TypeFlags.Unknown)) !== 0) return null;
|
|
13720
14279
|
for (const property of checker.getPropertiesOfType(type)) names.add(property.getName());
|
|
13721
14280
|
}
|
|
13722
14281
|
}
|
|
@@ -14877,7 +15436,7 @@ function tupleFields(helper) {
|
|
|
14877
15436
|
const values = [];
|
|
14878
15437
|
for (const [index, field] of tuple.elementTypes.entries()) {
|
|
14879
15438
|
const value = returned2.argument.elements[index];
|
|
14880
|
-
if (field.type !== import_utils91.AST_NODE_TYPES.TSNamedTupleMember || field.optional || value?.type !== import_utils91.AST_NODE_TYPES.Literal || !
|
|
15439
|
+
if (field.type !== import_utils91.AST_NODE_TYPES.TSNamedTupleMember || field.optional || value?.type !== import_utils91.AST_NODE_TYPES.Literal || !primitiveValue3(field.elementType, value) || UNSAFE_NAMES.has(field.label.name) || labels.some((label) => label.name === field.label.name))
|
|
14881
15440
|
return null;
|
|
14882
15441
|
labels.push(field.label);
|
|
14883
15442
|
types.push(field.elementType);
|
|
@@ -14885,7 +15444,7 @@ function tupleFields(helper) {
|
|
|
14885
15444
|
}
|
|
14886
15445
|
return { labels, types, values, returned: returned2.argument };
|
|
14887
15446
|
}
|
|
14888
|
-
function
|
|
15447
|
+
function primitiveValue3(type, value) {
|
|
14889
15448
|
switch (type.type) {
|
|
14890
15449
|
case import_utils91.AST_NODE_TYPES.TSStringKeyword:
|
|
14891
15450
|
return typeof value.value === "string";
|
|
@@ -20962,7 +21521,7 @@ function mayBeVirtual(options) {
|
|
|
20962
21521
|
|
|
20963
21522
|
// src/rules/no-zod-native-enum.ts
|
|
20964
21523
|
var import_utils122 = require("@typescript-eslint/utils");
|
|
20965
|
-
var
|
|
21524
|
+
var ts29 = __toESM(require("typescript"), 1);
|
|
20966
21525
|
var NO_ZOD_NATIVE_ENUM_DOCUMENTATION = {
|
|
20967
21526
|
summary: 'Disallow `z.nativeEnum()` (and `z.enum()` over a TypeScript enum); use `z.enum(["a", "b"])` with a string-literal union instead.',
|
|
20968
21527
|
rationale: "The project prefers literal-first schema definitions. nativeEnum also accepts plain enum-like objects, so this is an explicit declaration policy, not proof that every call duplicates a TypeScript enum's runtime object.",
|
|
@@ -21071,7 +21630,7 @@ function resolvesToLocalEnum(node, scope) {
|
|
|
21071
21630
|
}
|
|
21072
21631
|
return false;
|
|
21073
21632
|
}
|
|
21074
|
-
var ENUM_SYMBOL_FLAGS =
|
|
21633
|
+
var ENUM_SYMBOL_FLAGS = ts29.SymbolFlags.RegularEnum | ts29.SymbolFlags.ConstEnum | ts29.SymbolFlags.Enum;
|
|
21075
21634
|
function resolvesToImportedEnum(node, services) {
|
|
21076
21635
|
const checker = services.program.getTypeChecker();
|
|
21077
21636
|
const tsNode = services.esTreeNodeToTSNodeMap.get(node);
|
|
@@ -21079,7 +21638,7 @@ function resolvesToImportedEnum(node, services) {
|
|
|
21079
21638
|
if (symbol === void 0) {
|
|
21080
21639
|
return false;
|
|
21081
21640
|
}
|
|
21082
|
-
if ((symbol.flags &
|
|
21641
|
+
if ((symbol.flags & ts29.SymbolFlags.Alias) !== 0) {
|
|
21083
21642
|
symbol = checker.getAliasedSymbol(symbol);
|
|
21084
21643
|
}
|
|
21085
21644
|
return (symbol.flags & ENUM_SYMBOL_FLAGS) !== 0;
|
|
@@ -24701,7 +25260,7 @@ var OPERATIONAL_ROLES = /* @__PURE__ */ new Set([
|
|
|
24701
25260
|
"timeout",
|
|
24702
25261
|
"interval"
|
|
24703
25262
|
]);
|
|
24704
|
-
var
|
|
25263
|
+
var MAX_ALIAS_DEPTH2 = 16;
|
|
24705
25264
|
var PREFER_NOMINAL_ID_TYPES_DOCUMENTATION = {
|
|
24706
25265
|
defaultLevel: "error",
|
|
24707
25266
|
summary: "Distinguish identifier roles sharing primitive types at callable boundaries.",
|
|
@@ -24799,7 +25358,7 @@ function typeDefinitions(node, context) {
|
|
|
24799
25358
|
return [];
|
|
24800
25359
|
}
|
|
24801
25360
|
function rawCarrier(node, context, depth = 0) {
|
|
24802
|
-
if (node === void 0 || depth >=
|
|
25361
|
+
if (node === void 0 || depth >= MAX_ALIAS_DEPTH2) return void 0;
|
|
24803
25362
|
switch (node.type) {
|
|
24804
25363
|
case import_utils140.AST_NODE_TYPES.TSStringKeyword:
|
|
24805
25364
|
return "string";
|
|
@@ -26276,7 +26835,7 @@ var prefer_non_nullable_collection_default = createRule({
|
|
|
26276
26835
|
|
|
26277
26836
|
// src/rules/prefer-nullish-filter-predicate.ts
|
|
26278
26837
|
var import_utils148 = require("@typescript-eslint/utils");
|
|
26279
|
-
var
|
|
26838
|
+
var import_typescript26 = __toESM(require("typescript"), 1);
|
|
26280
26839
|
var PREFER_NULLISH_FILTER_PREDICATE_DOCUMENTATION = {
|
|
26281
26840
|
summary: "Prefer an explicit nullish predicate when `filter(Boolean)` removes only nullish values but does not narrow the result type.",
|
|
26282
26841
|
rationale: "An explicit nullish predicate preserves the same runtime elements while letting TypeScript remove `null` and `undefined` from the result.",
|
|
@@ -26339,23 +26898,23 @@ function isBuiltinArrayFilter(node, services) {
|
|
|
26339
26898
|
const symbol = checker.getSymbolAtLocation(property) ?? checker.getTypeAtLocation(services.esTreeNodeToTSNodeMap.get(node.object)).getProperty("filter");
|
|
26340
26899
|
return symbol?.declarations?.some((declaration) => {
|
|
26341
26900
|
const owner = declaration.parent;
|
|
26342
|
-
return
|
|
26901
|
+
return import_typescript26.default.isInterfaceDeclaration(owner) && (owner.name.text === "Array" || owner.name.text === "ReadonlyArray") && services.program.isSourceFileDefaultLibrary(owner.getSourceFile());
|
|
26343
26902
|
}) ?? false;
|
|
26344
26903
|
}
|
|
26345
26904
|
function arrayElementType(node, services) {
|
|
26346
26905
|
const checker = services.program.getTypeChecker();
|
|
26347
26906
|
const receiver = services.esTreeNodeToTSNodeMap.get(node);
|
|
26348
|
-
return checker.getIndexTypeOfType(checker.getTypeAtLocation(receiver),
|
|
26907
|
+
return checker.getIndexTypeOfType(checker.getTypeAtLocation(receiver), import_typescript26.default.IndexKind.Number) ?? null;
|
|
26349
26908
|
}
|
|
26350
|
-
var NULLISH_FLAGS =
|
|
26351
|
-
var UNKNOWN_FLAGS =
|
|
26909
|
+
var NULLISH_FLAGS = import_typescript26.default.TypeFlags.Null | import_typescript26.default.TypeFlags.Undefined;
|
|
26910
|
+
var UNKNOWN_FLAGS = import_typescript26.default.TypeFlags.Any | import_typescript26.default.TypeFlags.Unknown | import_typescript26.default.TypeFlags.TypeParameter | import_typescript26.default.TypeFlags.Intersection | import_typescript26.default.TypeFlags.Enum | import_typescript26.default.TypeFlags.EnumLiteral;
|
|
26352
26911
|
function isNullishPlusTruthy(type, checker, falsyBrowserObject) {
|
|
26353
26912
|
const members = type.isUnion() ? type.types : [type];
|
|
26354
26913
|
let sawNullish = false;
|
|
26355
26914
|
for (const member3 of members) {
|
|
26356
26915
|
if ((member3.flags & NULLISH_FLAGS) !== 0) {
|
|
26357
26916
|
sawNullish = true;
|
|
26358
|
-
} else if ((member3.flags &
|
|
26917
|
+
} else if ((member3.flags & import_typescript26.default.TypeFlags.Never) === 0 && !isProvablyTruthy(member3, checker, falsyBrowserObject)) {
|
|
26359
26918
|
return false;
|
|
26360
26919
|
}
|
|
26361
26920
|
}
|
|
@@ -26363,7 +26922,7 @@ function isNullishPlusTruthy(type, checker, falsyBrowserObject) {
|
|
|
26363
26922
|
}
|
|
26364
26923
|
function isProvablyTruthy(type, checker, falsyBrowserObject) {
|
|
26365
26924
|
if ((type.flags & UNKNOWN_FLAGS) !== 0) return false;
|
|
26366
|
-
if ((type.flags &
|
|
26925
|
+
if ((type.flags & import_typescript26.default.TypeFlags.Object) !== 0) {
|
|
26367
26926
|
if (falsyBrowserObject !== null && checker.isTypeAssignableTo(falsyBrowserObject, type)) return false;
|
|
26368
26927
|
return ![
|
|
26369
26928
|
checker.getStringType(),
|
|
@@ -26372,18 +26931,18 @@ function isProvablyTruthy(type, checker, falsyBrowserObject) {
|
|
|
26372
26931
|
checker.getBooleanType()
|
|
26373
26932
|
].some((primitive) => checker.isTypeAssignableTo(primitive, type));
|
|
26374
26933
|
}
|
|
26375
|
-
if ((type.flags & (
|
|
26376
|
-
if ((type.flags &
|
|
26934
|
+
if ((type.flags & (import_typescript26.default.TypeFlags.ESSymbol | import_typescript26.default.TypeFlags.UniqueESSymbol)) !== 0) return true;
|
|
26935
|
+
if ((type.flags & import_typescript26.default.TypeFlags.BooleanLiteral) !== 0) {
|
|
26377
26936
|
return type.intrinsicName === "true";
|
|
26378
26937
|
}
|
|
26379
|
-
if ((type.flags &
|
|
26938
|
+
if ((type.flags & import_typescript26.default.TypeFlags.StringLiteral) !== 0) {
|
|
26380
26939
|
return type.value.length > 0;
|
|
26381
26940
|
}
|
|
26382
|
-
if ((type.flags &
|
|
26941
|
+
if ((type.flags & import_typescript26.default.TypeFlags.NumberLiteral) !== 0) {
|
|
26383
26942
|
const value = type.value;
|
|
26384
26943
|
return value !== 0 && !Number.isNaN(value);
|
|
26385
26944
|
}
|
|
26386
|
-
if ((type.flags &
|
|
26945
|
+
if ((type.flags & import_typescript26.default.TypeFlags.BigIntLiteral) !== 0) {
|
|
26387
26946
|
return type.value.base10Value !== "0";
|
|
26388
26947
|
}
|
|
26389
26948
|
return false;
|
|
@@ -26439,7 +26998,7 @@ var prefer_nullish_filter_predicate_default = createRule({
|
|
|
26439
26998
|
if (services === null) return {};
|
|
26440
26999
|
const program = services.program;
|
|
26441
27000
|
const checker = program.getTypeChecker();
|
|
26442
|
-
const browserCollection = checker.resolveName("HTMLAllCollection", void 0,
|
|
27001
|
+
const browserCollection = checker.resolveName("HTMLAllCollection", void 0, import_typescript26.default.SymbolFlags.Type, false);
|
|
26443
27002
|
const falsyBrowserObject = browserCollection?.declarations?.some((declaration) => program.isSourceFileDefaultLibrary(declaration.getSourceFile())) === true ? checker.getDeclaredTypeOfSymbol(browserCollection) : null;
|
|
26444
27003
|
return {
|
|
26445
27004
|
CallExpression(node) {
|
|
@@ -26473,7 +27032,7 @@ var prefer_nullish_filter_predicate_default = createRule({
|
|
|
26473
27032
|
|
|
26474
27033
|
// src/rules/prefer-await-in-async-return.ts
|
|
26475
27034
|
var import_utils149 = require("@typescript-eslint/utils");
|
|
26476
|
-
var
|
|
27035
|
+
var ts31 = __toESM(require("typescript"), 1);
|
|
26477
27036
|
var PREFER_AWAIT_IN_ASYNC_RETURN_DOCUMENTATION = {
|
|
26478
27037
|
summary: "Prefer explicit `await` for proven Promise `.then` calls; the default scope checks direct async returns.",
|
|
26479
27038
|
rationale: "Promise callback chains mix explicit async control flow with nested callbacks, making sequencing and failure handling harder to read.",
|
|
@@ -26557,7 +27116,7 @@ function isProvenPromiseLike(node, services) {
|
|
|
26557
27116
|
return members.every((member3) => isBuiltInPromiseType(member3, services));
|
|
26558
27117
|
}
|
|
26559
27118
|
function isBuiltInPromiseType(type, services) {
|
|
26560
|
-
if ((type.flags & (
|
|
27119
|
+
if ((type.flags & (ts31.TypeFlags.Any | ts31.TypeFlags.Unknown | ts31.TypeFlags.Never)) !== 0) {
|
|
26561
27120
|
return false;
|
|
26562
27121
|
}
|
|
26563
27122
|
const thenSymbol = services.program.getTypeChecker().getPropertyOfType(type, "then");
|
|
@@ -26566,7 +27125,7 @@ function isBuiltInPromiseType(type, services) {
|
|
|
26566
27125
|
return declarations.every(
|
|
26567
27126
|
(declaration) => {
|
|
26568
27127
|
let owner = declaration.parent;
|
|
26569
|
-
while (owner !== void 0 && !
|
|
27128
|
+
while (owner !== void 0 && !ts31.isInterfaceDeclaration(owner)) {
|
|
26570
27129
|
owner = owner.parent;
|
|
26571
27130
|
}
|
|
26572
27131
|
return owner !== void 0 && (owner.name.text === "Promise" || owner.name.text === "PromiseLike") && services.program.isSourceFileDefaultLibrary(owner.getSourceFile());
|
|
@@ -27350,7 +27909,7 @@ var prefer_shared_zod_enum_default = createRule({
|
|
|
27350
27909
|
|
|
27351
27910
|
// src/rules/prefer-switch-for-repeated-equality.ts
|
|
27352
27911
|
var import_utils153 = require("@typescript-eslint/utils");
|
|
27353
|
-
var
|
|
27912
|
+
var import_typescript27 = __toESM(require("typescript"), 1);
|
|
27354
27913
|
var PREFER_SWITCH_FOR_REPEATED_EQUALITY_DOCUMENTATION = {
|
|
27355
27914
|
defaultLevel: "error",
|
|
27356
27915
|
summary: "Prefer switch over long if/else-if chains that compare one value for strict equality.",
|
|
@@ -27430,7 +27989,7 @@ function hasUnsafeSwitchControl(node) {
|
|
|
27430
27989
|
function hasOpenDiscriminant(node, services) {
|
|
27431
27990
|
if (services === null) return false;
|
|
27432
27991
|
const type = services.program.getTypeChecker().getTypeAtLocation(services.esTreeNodeToTSNodeMap.get(node));
|
|
27433
|
-
const openFlags =
|
|
27992
|
+
const openFlags = import_typescript27.default.TypeFlags.Any | import_typescript27.default.TypeFlags.Unknown | import_typescript27.default.TypeFlags.String | import_typescript27.default.TypeFlags.Number | import_typescript27.default.TypeFlags.BigInt | import_typescript27.default.TypeFlags.ESSymbol;
|
|
27434
27993
|
return (type.isUnion() ? type.types : [type]).some((part) => (part.flags & openFlags) !== 0);
|
|
27435
27994
|
}
|
|
27436
27995
|
var prefer_switch_for_repeated_equality_default = createRule({
|
|
@@ -29624,14 +30183,14 @@ var named_child_schema_type_default = createRule({
|
|
|
29624
30183
|
|
|
29625
30184
|
// src/rules/prefer-zod-parse-output-type.ts
|
|
29626
30185
|
var import_utils160 = require("@typescript-eslint/utils");
|
|
29627
|
-
var
|
|
30186
|
+
var import_typescript30 = __toESM(require("typescript"), 1);
|
|
29628
30187
|
|
|
29629
30188
|
// src/rules/_equivalent-zod-output-contracts.ts
|
|
29630
30189
|
var import_ts_api_utils5 = require("ts-api-utils");
|
|
29631
|
-
var
|
|
30190
|
+
var import_typescript28 = __toESM(require("typescript"), 1);
|
|
29632
30191
|
var MAX_CONTRACT_PAIRS = 128;
|
|
29633
30192
|
var MAX_UNION_MEMBERS = 16;
|
|
29634
|
-
var UNSAFE_TYPES =
|
|
30193
|
+
var UNSAFE_TYPES = import_typescript28.default.TypeFlags.Any | import_typescript28.default.TypeFlags.Unknown | import_typescript28.default.TypeFlags.Never;
|
|
29635
30194
|
function equivalentZodOutputContracts(checker, parsed, contract) {
|
|
29636
30195
|
const comparison2 = { checker, pending: [[parsed, contract]], seen: /* @__PURE__ */ new Map(), pairs: 0 };
|
|
29637
30196
|
while (comparison2.pending.length > 0) {
|
|
@@ -29691,8 +30250,8 @@ function equivalentContainers(comparison2, left, right) {
|
|
|
29691
30250
|
const rightTuple = (0, import_ts_api_utils5.isTupleTypeReference)(right);
|
|
29692
30251
|
if (leftTuple !== rightTuple) return false;
|
|
29693
30252
|
if (leftTuple && rightTuple && (left.target.readonly !== right.target.readonly || left.target.elementFlags.length !== right.target.elementFlags.length || left.target.elementFlags.some((flag, index) => flag !== right.target.elementFlags[index]))) return false;
|
|
29694
|
-
const leftIndex = comparison2.checker.getIndexInfoOfType(left,
|
|
29695
|
-
const rightIndex = comparison2.checker.getIndexInfoOfType(right,
|
|
30253
|
+
const leftIndex = comparison2.checker.getIndexInfoOfType(left, import_typescript28.default.IndexKind.Number);
|
|
30254
|
+
const rightIndex = comparison2.checker.getIndexInfoOfType(right, import_typescript28.default.IndexKind.Number);
|
|
29696
30255
|
if (leftIndex?.isReadonly !== rightIndex?.isReadonly) return false;
|
|
29697
30256
|
const leftArguments = comparison2.checker.getTypeArguments(left);
|
|
29698
30257
|
const rightArguments = comparison2.checker.getTypeArguments(right);
|
|
@@ -29702,10 +30261,10 @@ function equivalentContainers(comparison2, left, right) {
|
|
|
29702
30261
|
});
|
|
29703
30262
|
}
|
|
29704
30263
|
function hasClassDeclaration(type) {
|
|
29705
|
-
return type.getSymbol()?.getDeclarations()?.some(
|
|
30264
|
+
return type.getSymbol()?.getDeclarations()?.some(import_typescript28.default.isClassDeclaration) === true || type.isIntersection() && type.types.some(hasClassDeclaration);
|
|
29706
30265
|
}
|
|
29707
30266
|
function objectLike(type) {
|
|
29708
|
-
return (type.flags &
|
|
30267
|
+
return (type.flags & import_typescript28.default.TypeFlags.Object) !== 0 || type.isIntersection();
|
|
29709
30268
|
}
|
|
29710
30269
|
function equivalentProperties(comparison2, left, right) {
|
|
29711
30270
|
const { checker } = comparison2;
|
|
@@ -29720,12 +30279,12 @@ function equivalentProperties(comparison2, left, right) {
|
|
|
29720
30279
|
return true;
|
|
29721
30280
|
}
|
|
29722
30281
|
function opaqueObject(checker, type) {
|
|
29723
|
-
return checker.getIndexInfosOfType(type).length > 0 || checker.getSignaturesOfType(type,
|
|
30282
|
+
return checker.getIndexInfosOfType(type).length > 0 || checker.getSignaturesOfType(type, import_typescript28.default.SignatureKind.Call).length > 0 || checker.getSignaturesOfType(type, import_typescript28.default.SignatureKind.Construct).length > 0;
|
|
29724
30283
|
}
|
|
29725
30284
|
function equivalentProperty(comparison2, left, right, property, other) {
|
|
29726
30285
|
const { checker } = comparison2;
|
|
29727
30286
|
if (opaqueProperty(property) || opaqueProperty(other)) return false;
|
|
29728
|
-
if ((property.flags &
|
|
30287
|
+
if ((property.flags & import_typescript28.default.SymbolFlags.Optional) !== (other.flags & import_typescript28.default.SymbolFlags.Optional)) return false;
|
|
29729
30288
|
if ((0, import_ts_api_utils5.isPropertyReadonlyInType)(left, property.getEscapedName(), checker) !== (0, import_ts_api_utils5.isPropertyReadonlyInType)(right, other.getEscapedName(), checker)) return false;
|
|
29730
30289
|
const declaration = property.valueDeclaration ?? property.getDeclarations()?.[0];
|
|
29731
30290
|
const otherDeclaration = other.valueDeclaration ?? other.getDeclarations()?.[0];
|
|
@@ -29736,39 +30295,39 @@ function equivalentProperty(comparison2, left, right, property, other) {
|
|
|
29736
30295
|
);
|
|
29737
30296
|
}
|
|
29738
30297
|
function opaqueProperty(property) {
|
|
29739
|
-
return property.getDeclarations()?.some((declaration) =>
|
|
30298
|
+
return property.getDeclarations()?.some((declaration) => import_typescript28.default.isGetAccessorDeclaration(declaration) || import_typescript28.default.isSetAccessorDeclaration(declaration) || import_typescript28.default.isMethodDeclaration(declaration) || import_typescript28.default.isMethodSignature(declaration)) === true;
|
|
29740
30299
|
}
|
|
29741
30300
|
|
|
29742
30301
|
// src/rules/_has-authoritative-output-contract.ts
|
|
29743
|
-
var
|
|
30302
|
+
var import_typescript29 = __toESM(require("typescript"), 1);
|
|
29744
30303
|
function hasAuthoritativeOutputContract(checker, output, contract) {
|
|
29745
30304
|
const callable = enclosingCallable(output);
|
|
29746
30305
|
if (callable === void 0) return false;
|
|
29747
30306
|
const authority = { checker, contract };
|
|
29748
|
-
if (
|
|
30307
|
+
if (import_typescript29.default.isMethodDeclaration(callable) || import_typescript29.default.isGetAccessorDeclaration(callable)) return memberContract2(authority, callable);
|
|
29749
30308
|
const binding3 = callable.parent;
|
|
29750
|
-
if ((
|
|
29751
|
-
if (
|
|
30309
|
+
if ((import_typescript29.default.isVariableDeclaration(binding3) || import_typescript29.default.isPropertyDeclaration(binding3)) && binding3.initializer === callable && binding3.type !== void 0 && callableContract(authority, checker.getTypeFromTypeNode(binding3.type))) return true;
|
|
30310
|
+
if (import_typescript29.default.isPropertyDeclaration(binding3) && binding3.initializer === callable && memberContract2(authority, binding3)) return true;
|
|
29752
30311
|
const contextual = checker.getContextualType(callable);
|
|
29753
30312
|
return contextual !== void 0 && callableContract(authority, contextual, callable);
|
|
29754
30313
|
}
|
|
29755
30314
|
function enclosingCallable(output) {
|
|
29756
30315
|
for (let current = output; current !== void 0; current = current.parent) {
|
|
29757
|
-
if (
|
|
29758
|
-
if (
|
|
30316
|
+
if (import_typescript29.default.isMethodDeclaration(current) || import_typescript29.default.isGetAccessorDeclaration(current) || import_typescript29.default.isArrowFunction(current) || import_typescript29.default.isFunctionExpression(current)) return current;
|
|
30317
|
+
if (import_typescript29.default.isFunctionDeclaration(current) || import_typescript29.default.isConstructorDeclaration(current) || import_typescript29.default.isSetAccessorDeclaration(current)) return void 0;
|
|
29759
30318
|
}
|
|
29760
30319
|
return void 0;
|
|
29761
30320
|
}
|
|
29762
30321
|
function memberContract2(authority, member3) {
|
|
29763
|
-
if ((
|
|
30322
|
+
if ((import_typescript29.default.getCombinedModifierFlags(member3) & (import_typescript29.default.ModifierFlags.Private | import_typescript29.default.ModifierFlags.Static)) !== 0 || import_typescript29.default.isPrivateIdentifier(member3.name)) return false;
|
|
29764
30323
|
const owner = member3.parent;
|
|
29765
30324
|
const name = authority.checker.getSymbolAtLocation(member3.name)?.getName();
|
|
29766
30325
|
if (name === void 0) return false;
|
|
29767
|
-
if (
|
|
30326
|
+
if (import_typescript29.default.isObjectLiteralExpression(owner)) {
|
|
29768
30327
|
const contextual = authority.checker.getContextualType(owner);
|
|
29769
30328
|
return contextual !== void 0 && propertyContract(authority, contextual, name, member3, member3);
|
|
29770
30329
|
}
|
|
29771
|
-
if (!
|
|
30330
|
+
if (!import_typescript29.default.isClassDeclaration(owner) && !import_typescript29.default.isClassExpression(owner)) return false;
|
|
29772
30331
|
for (const clause of owner.heritageClauses ?? []) {
|
|
29773
30332
|
for (const heritage of clause.types) {
|
|
29774
30333
|
if (propertyContract(authority, authority.checker.getTypeAtLocation(heritage), name, member3)) return true;
|
|
@@ -29780,9 +30339,9 @@ function propertyContract(authority, type, name, member3, contextual) {
|
|
|
29780
30339
|
const property = authority.checker.getPropertyOfType(type, name);
|
|
29781
30340
|
if (property === void 0) return false;
|
|
29782
30341
|
const declared = authority.checker.getTypeOfSymbolAtLocation(property, member3);
|
|
29783
|
-
if (!
|
|
30342
|
+
if (!import_typescript29.default.isGetAccessorDeclaration(member3)) return callableContract(authority, declared, contextual);
|
|
29784
30343
|
return property.getDeclarations()?.some((declaration) => {
|
|
29785
|
-
if (!(
|
|
30344
|
+
if (!(import_typescript29.default.isPropertySignature(declaration) || import_typescript29.default.isPropertyDeclaration(declaration) || import_typescript29.default.isGetAccessorDeclaration(declaration)) || declaration.type === void 0 || declaration === member3) return false;
|
|
29786
30345
|
return returnsContract(authority, contextual === void 0 ? declared : authority.checker.getTypeAtLocation(declaration.type));
|
|
29787
30346
|
}) === true;
|
|
29788
30347
|
}
|
|
@@ -30121,12 +30680,12 @@ function handWrittenObjectDeclaration(symbol) {
|
|
|
30121
30680
|
const [declaration] = declarations;
|
|
30122
30681
|
if (declarations.length !== 1 || declaration === void 0) return null;
|
|
30123
30682
|
const plainMembers = (members) => members.length > 0 && members.every(
|
|
30124
|
-
(member3) =>
|
|
30683
|
+
(member3) => import_typescript30.default.isPropertySignature(member3) && member3.type !== void 0 && member3.modifiers?.some((modifier) => modifier.kind === import_typescript30.default.SyntaxKind.ReadonlyKeyword) !== true
|
|
30125
30684
|
);
|
|
30126
|
-
if (
|
|
30685
|
+
if (import_typescript30.default.isInterfaceDeclaration(declaration) && declaration.typeParameters === void 0 && declaration.heritageClauses === void 0 && plainMembers(declaration.members)) {
|
|
30127
30686
|
return declaration;
|
|
30128
30687
|
}
|
|
30129
|
-
if (
|
|
30688
|
+
if (import_typescript30.default.isTypeAliasDeclaration(declaration) && declaration.typeParameters === void 0 && import_typescript30.default.isTypeLiteralNode(declaration.type) && plainMembers(declaration.type.members)) {
|
|
30130
30689
|
return declaration;
|
|
30131
30690
|
}
|
|
30132
30691
|
return null;
|
|
@@ -30206,7 +30765,7 @@ var prefer_zod_parse_output_type_default = createRule({
|
|
|
30206
30765
|
|
|
30207
30766
|
// src/rules/require-assert-never.ts
|
|
30208
30767
|
var import_utils162 = require("@typescript-eslint/utils");
|
|
30209
|
-
var
|
|
30768
|
+
var import_typescript31 = __toESM(require("typescript"), 1);
|
|
30210
30769
|
|
|
30211
30770
|
// src/rules/_empty-assertion-fix.ts
|
|
30212
30771
|
var import_utils161 = require("@typescript-eslint/utils");
|
|
@@ -30383,7 +30942,7 @@ function isExhaustiveFiniteSwitch(node, services) {
|
|
|
30383
30942
|
const constituents = discriminantType.isUnion() ? discriminantType.types : [discriminantType];
|
|
30384
30943
|
if (!discriminantType.isUnion() || constituents.length < 2) return false;
|
|
30385
30944
|
if (constituents.every(
|
|
30386
|
-
(constituent) => (constituent.flags &
|
|
30945
|
+
(constituent) => (constituent.flags & import_typescript31.default.TypeFlags.BooleanLiteral) !== 0
|
|
30387
30946
|
)) {
|
|
30388
30947
|
return false;
|
|
30389
30948
|
}
|
|
@@ -30405,7 +30964,7 @@ function isExhaustiveFiniteSwitch(node, services) {
|
|
|
30405
30964
|
return [...expected].every((key) => handled.has(key));
|
|
30406
30965
|
}
|
|
30407
30966
|
function finiteTypeKey(type, checker) {
|
|
30408
|
-
const finiteFlags =
|
|
30967
|
+
const finiteFlags = import_typescript31.default.TypeFlags.StringLiteral | import_typescript31.default.TypeFlags.NumberLiteral | import_typescript31.default.TypeFlags.BooleanLiteral | import_typescript31.default.TypeFlags.EnumLiteral | import_typescript31.default.TypeFlags.UniqueESSymbol | import_typescript31.default.TypeFlags.Null | import_typescript31.default.TypeFlags.Undefined;
|
|
30409
30968
|
return (type.flags & finiteFlags) !== 0 ? checker.typeToString(type) : null;
|
|
30410
30969
|
}
|
|
30411
30970
|
var require_assert_never_default = createRule({
|