@sarj/eslint-plugin 16.32.1 → 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/index.cjs +969 -415
- package/dist/index.js +969 -415
- 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,10 +2337,10 @@ 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
|
|
@@ -1862,17 +2416,17 @@ function hasPrototypeMutation(source) {
|
|
|
1862
2416
|
const member3 = memberName(node);
|
|
1863
2417
|
if (member3 === "setPrototypeOf" || member3 === "__proto__" || member3 === "hasInstance")
|
|
1864
2418
|
return true;
|
|
1865
|
-
if (
|
|
2419
|
+
if (ts12.isBinaryExpression(node) && node.operatorToken.kind >= ts12.SyntaxKind.FirstAssignment && node.operatorToken.kind <= ts12.SyntaxKind.LastAssignment && memberName(node.left) === "prototype")
|
|
1866
2420
|
return true;
|
|
1867
|
-
return
|
|
2421
|
+
return ts12.forEachChild(node, visit);
|
|
1868
2422
|
}
|
|
1869
2423
|
const mutated = visit(source) === true;
|
|
1870
2424
|
PROTOTYPE_MUTATIONS.set(source, mutated);
|
|
1871
2425
|
return mutated;
|
|
1872
2426
|
}
|
|
1873
2427
|
function memberName(node) {
|
|
1874
|
-
if (
|
|
1875
|
-
if (
|
|
2428
|
+
if (ts12.isPropertyAccessExpression(node)) return node.name.text;
|
|
2429
|
+
if (ts12.isElementAccessExpression(node) && ts12.isStringLiteralLike(node.argumentExpression))
|
|
1876
2430
|
return node.argumentExpression.text;
|
|
1877
2431
|
return null;
|
|
1878
2432
|
}
|
|
@@ -1889,11 +2443,11 @@ function escapedClasses(program, checker, cwd) {
|
|
|
1889
2443
|
const escaped = /* @__PURE__ */ new Set();
|
|
1890
2444
|
const namespaceValues = /* @__PURE__ */ new Map();
|
|
1891
2445
|
function visit(node) {
|
|
1892
|
-
if (
|
|
1893
|
-
if (
|
|
2446
|
+
if (ts12.isTypeNode(node) || ts12.isImportDeclaration(node)) return;
|
|
2447
|
+
if (ts12.isIdentifier(node) || ts12.isPropertyAccessExpression(node) || ts12.isElementAccessExpression(node)) {
|
|
1894
2448
|
recordEscapedReference(checker, node, escaped, namespaceValues, cwd);
|
|
1895
2449
|
}
|
|
1896
|
-
|
|
2450
|
+
ts12.forEachChild(node, visit);
|
|
1897
2451
|
}
|
|
1898
2452
|
for (const source of program.getSourceFiles())
|
|
1899
2453
|
if (ownedSource(source, cwd)) visit(source);
|
|
@@ -1912,7 +2466,7 @@ function recordEscapedReference(checker, node, escaped, namespaceValues, cwd) {
|
|
|
1912
2466
|
if (!namespacePrefix(symbol, node) && !safeClassReference(node))
|
|
1913
2467
|
for (const value of values) escaped.add(value);
|
|
1914
2468
|
}
|
|
1915
|
-
if (
|
|
2469
|
+
if (ts12.isElementAccessExpression(node) && !safeClassReference(node)) {
|
|
1916
2470
|
const receiver = canonicalSymbol(checker, node.expression) ?? checker.getTypeAtLocation(node.expression).getSymbol();
|
|
1917
2471
|
if (receiver !== void 0)
|
|
1918
2472
|
for (const value of ownedClassValues(checker, receiver, cwd))
|
|
@@ -1920,16 +2474,16 @@ function recordEscapedReference(checker, node, escaped, namespaceValues, cwd) {
|
|
|
1920
2474
|
}
|
|
1921
2475
|
}
|
|
1922
2476
|
function ownedClassValues(checker, original, cwd, seen = /* @__PURE__ */ new Set()) {
|
|
1923
|
-
const symbol = original.flags &
|
|
2477
|
+
const symbol = original.flags & ts12.SymbolFlags.Alias ? checker.getAliasedSymbol(original) : original;
|
|
1924
2478
|
const values = /* @__PURE__ */ new Set();
|
|
1925
2479
|
if (seen.has(symbol)) return values;
|
|
1926
2480
|
seen.add(symbol);
|
|
1927
2481
|
if (symbol.declarations?.some(
|
|
1928
|
-
(declaration) =>
|
|
2482
|
+
(declaration) => ts12.isClassDeclaration(declaration) && ownedSource(declaration.getSourceFile(), cwd)
|
|
1929
2483
|
))
|
|
1930
2484
|
values.add(symbol);
|
|
1931
2485
|
if (symbol.declarations?.some(
|
|
1932
|
-
(declaration) => (
|
|
2486
|
+
(declaration) => (ts12.isSourceFile(declaration) || ts12.isModuleDeclaration(declaration)) && ownedSource(declaration.getSourceFile(), cwd)
|
|
1933
2487
|
)) {
|
|
1934
2488
|
for (const exported of checker.getExportsOfModule(symbol)) {
|
|
1935
2489
|
for (const value of ownedClassValues(checker, exported, cwd, seen))
|
|
@@ -1939,16 +2493,16 @@ function ownedClassValues(checker, original, cwd, seen = /* @__PURE__ */ new Set
|
|
|
1939
2493
|
return values;
|
|
1940
2494
|
}
|
|
1941
2495
|
function safeClassReference(node) {
|
|
1942
|
-
let reference =
|
|
1943
|
-
while (
|
|
2496
|
+
let reference = ts12.isPropertyAccessExpression(node.parent) && node.parent.name === node ? node.parent : node;
|
|
2497
|
+
while (ts12.isParenthesizedExpression(reference.parent))
|
|
1944
2498
|
reference = reference.parent;
|
|
1945
2499
|
const parent = reference.parent;
|
|
1946
|
-
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;
|
|
1947
2501
|
}
|
|
1948
2502
|
function namespacePrefix(symbol, node) {
|
|
1949
2503
|
const parent = node.parent;
|
|
1950
|
-
const memberCall = (
|
|
1951
|
-
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;
|
|
1952
2506
|
}
|
|
1953
2507
|
function closedNominalBoundary(program, checker, call, consumer, missing, cwd) {
|
|
1954
2508
|
const { implementation, contractSymbol } = missing;
|
|
@@ -1956,7 +2510,7 @@ function closedNominalBoundary(program, checker, call, consumer, missing, cwd) {
|
|
|
1956
2510
|
const consumerSymbol = consumer.name === void 0 ? void 0 : canonicalSymbol(checker, consumer.name);
|
|
1957
2511
|
if (implementationSymbol === void 0 || consumerSymbol === void 0)
|
|
1958
2512
|
return false;
|
|
1959
|
-
const contract = contractSymbol.declarations?.find(
|
|
2513
|
+
const contract = contractSymbol.declarations?.find(ts12.isClassDeclaration);
|
|
1960
2514
|
if (contract === void 0) return false;
|
|
1961
2515
|
const targets = /* @__PURE__ */ new Set([
|
|
1962
2516
|
consumerSymbol,
|
|
@@ -1978,12 +2532,12 @@ function classHierarchySymbols(checker, declaration, seen = /* @__PURE__ */ new
|
|
|
1978
2532
|
if (symbol === void 0 || seen.has(symbol)) return seen;
|
|
1979
2533
|
seen.add(symbol);
|
|
1980
2534
|
for (const clause of declaration.heritageClauses ?? []) {
|
|
1981
|
-
if (clause.token !==
|
|
2535
|
+
if (clause.token !== ts12.SyntaxKind.ExtendsKeyword) continue;
|
|
1982
2536
|
for (const parent of clause.types) {
|
|
1983
2537
|
const ancestor = canonicalSymbol(
|
|
1984
2538
|
checker,
|
|
1985
2539
|
parent.expression
|
|
1986
|
-
)?.declarations?.find(
|
|
2540
|
+
)?.declarations?.find(ts12.isClassDeclaration);
|
|
1987
2541
|
if (ancestor !== void 0)
|
|
1988
2542
|
classHierarchySymbols(checker, ancestor, seen);
|
|
1989
2543
|
}
|
|
@@ -2008,22 +2562,22 @@ function missingImplementation(checker, signature, parameter, call, argument) {
|
|
|
2008
2562
|
function behavioralContract(checker, type) {
|
|
2009
2563
|
if (type.isUnion()) {
|
|
2010
2564
|
const substantive = type.types.filter(
|
|
2011
|
-
(member3) => (member3.flags & (
|
|
2565
|
+
(member3) => (member3.flags & (ts12.TypeFlags.Null | ts12.TypeFlags.Undefined)) === 0
|
|
2012
2566
|
);
|
|
2013
2567
|
if (substantive.length !== 1) return null;
|
|
2014
2568
|
return behavioralContract(checker, substantive[0]);
|
|
2015
2569
|
}
|
|
2016
|
-
if ((type.flags & (
|
|
2570
|
+
if ((type.flags & (ts12.TypeFlags.Any | ts12.TypeFlags.Unknown)) !== 0)
|
|
2017
2571
|
return null;
|
|
2018
2572
|
const declaration = type.getSymbol()?.declarations?.find(
|
|
2019
|
-
(item) =>
|
|
2020
|
-
(modifier) => modifier.kind ===
|
|
2573
|
+
(item) => ts12.isClassDeclaration(item) && item.modifiers?.some(
|
|
2574
|
+
(modifier) => modifier.kind === ts12.SyntaxKind.AbstractKeyword
|
|
2021
2575
|
)
|
|
2022
2576
|
);
|
|
2023
2577
|
if (declaration === void 0) return null;
|
|
2024
2578
|
return checker.getPropertiesOfType(type).some((property) => {
|
|
2025
2579
|
if (!property.declarations?.some(
|
|
2026
|
-
(member3) =>
|
|
2580
|
+
(member3) => ts12.isMethodSignature(member3) || ts12.isMethodDeclaration(member3)
|
|
2027
2581
|
))
|
|
2028
2582
|
return false;
|
|
2029
2583
|
const propertyType = checker.getTypeOfSymbolAtLocation(
|
|
@@ -2034,15 +2588,15 @@ function behavioralContract(checker, type) {
|
|
|
2034
2588
|
}) ? type : null;
|
|
2035
2589
|
}
|
|
2036
2590
|
function ownedClass(checker, expression) {
|
|
2037
|
-
if (!
|
|
2591
|
+
if (!ts12.isNewExpression(expression)) return null;
|
|
2038
2592
|
const type = checker.getTypeAtLocation(expression);
|
|
2039
|
-
if ((type.flags & (
|
|
2593
|
+
if ((type.flags & (ts12.TypeFlags.Any | ts12.TypeFlags.Unknown)) !== 0)
|
|
2040
2594
|
return null;
|
|
2041
|
-
const declaration = type.getSymbol()?.declarations?.find(
|
|
2595
|
+
const declaration = type.getSymbol()?.declarations?.find(ts12.isClassDeclaration);
|
|
2042
2596
|
const constructed = canonicalSymbol(
|
|
2043
2597
|
checker,
|
|
2044
2598
|
expression.expression
|
|
2045
|
-
)?.declarations?.find(
|
|
2599
|
+
)?.declarations?.find(ts12.isClassDeclaration);
|
|
2046
2600
|
if (declaration === void 0 || declaration !== constructed || declaration.getSourceFile().isDeclarationFile || /(?:^|[/\\])(?:node_modules|vendor|generated)(?:[/\\])/u.test(
|
|
2047
2601
|
declaration.getSourceFile().fileName
|
|
2048
2602
|
))
|
|
@@ -2050,10 +2604,10 @@ function ownedClass(checker, expression) {
|
|
|
2050
2604
|
return declaration;
|
|
2051
2605
|
}
|
|
2052
2606
|
function nominallyInherits(checker, declaration, target, seen) {
|
|
2053
|
-
if (
|
|
2607
|
+
if (ts12.canHaveDecorators(declaration) && ts12.getDecorators(declaration)?.length)
|
|
2054
2608
|
return null;
|
|
2055
2609
|
if (hasPrototypeMutation(declaration.getSourceFile()) || declaration.members.some(
|
|
2056
|
-
(member3) =>
|
|
2610
|
+
(member3) => ts12.isConstructorDeclaration(member3) || ts12.isClassStaticBlockDeclaration(member3) || ts12.isPropertyDeclaration(member3) && member3.initializer !== void 0
|
|
2057
2611
|
))
|
|
2058
2612
|
return null;
|
|
2059
2613
|
const symbol = declaration.name === void 0 ? void 0 : canonicalSymbol(checker, declaration.name);
|
|
@@ -2062,60 +2616,60 @@ function nominallyInherits(checker, declaration, target, seen) {
|
|
|
2062
2616
|
seen.add(symbol);
|
|
2063
2617
|
}
|
|
2064
2618
|
const parents = declaration.heritageClauses?.find(
|
|
2065
|
-
(clause) => clause.token ===
|
|
2619
|
+
(clause) => clause.token === ts12.SyntaxKind.ExtendsKeyword
|
|
2066
2620
|
)?.types;
|
|
2067
2621
|
if (parents === void 0) return false;
|
|
2068
2622
|
if (parents.length !== 1) return null;
|
|
2069
2623
|
const parentSymbol = canonicalSymbol(checker, parents[0].expression);
|
|
2070
2624
|
if (parentSymbol === void 0) return null;
|
|
2071
2625
|
if (parentSymbol === target) return true;
|
|
2072
|
-
const inherited = parentSymbol.declarations?.find(
|
|
2626
|
+
const inherited = parentSymbol.declarations?.find(ts12.isClassDeclaration);
|
|
2073
2627
|
return inherited === void 0 ? null : nominallyInherits(checker, inherited, target, new Set(seen));
|
|
2074
2628
|
}
|
|
2075
2629
|
function hasNominalRejectionGuard(checker, signature, parameter, contract) {
|
|
2076
2630
|
const declaration = signature.getDeclaration();
|
|
2077
|
-
if (declaration === void 0 || !
|
|
2631
|
+
if (declaration === void 0 || !ts12.isConstructorDeclaration(declaration))
|
|
2078
2632
|
return false;
|
|
2079
|
-
if (
|
|
2633
|
+
if (ts12.canHaveDecorators(declaration.parent) && ts12.getDecorators(declaration.parent)?.length)
|
|
2080
2634
|
return false;
|
|
2081
2635
|
if (hasPrototypeMutation(declaration.getSourceFile())) return false;
|
|
2082
2636
|
const first = declaration.body?.statements[0];
|
|
2083
|
-
if (first === void 0 || !
|
|
2637
|
+
if (first === void 0 || !ts12.isIfStatement(first) || !alwaysThrows(first.thenStatement))
|
|
2084
2638
|
return false;
|
|
2085
2639
|
const condition2 = unparenthesized2(first.expression);
|
|
2086
|
-
if (!
|
|
2640
|
+
if (!ts12.isPrefixUnaryExpression(condition2) || condition2.operator !== ts12.SyntaxKind.ExclamationToken)
|
|
2087
2641
|
return false;
|
|
2088
2642
|
const comparison2 = unparenthesized2(condition2.operand);
|
|
2089
|
-
if (!
|
|
2643
|
+
if (!ts12.isBinaryExpression(comparison2) || comparison2.operatorToken.kind !== ts12.SyntaxKind.InstanceOfKeyword)
|
|
2090
2644
|
return false;
|
|
2091
2645
|
if (canonicalSymbol(checker, comparison2.left) !== parameter || canonicalSymbol(checker, comparison2.right) !== contract)
|
|
2092
2646
|
return false;
|
|
2093
|
-
const target = contract.declarations?.find(
|
|
2647
|
+
const target = contract.declarations?.find(ts12.isClassDeclaration);
|
|
2094
2648
|
return target !== void 0 && hasOrdinaryInstanceCheck(checker, target, /* @__PURE__ */ new Set());
|
|
2095
2649
|
}
|
|
2096
2650
|
function unparenthesized2(expression) {
|
|
2097
2651
|
let current = expression;
|
|
2098
|
-
while (
|
|
2652
|
+
while (ts12.isParenthesizedExpression(current)) current = current.expression;
|
|
2099
2653
|
return current;
|
|
2100
2654
|
}
|
|
2101
2655
|
function alwaysThrows(statement) {
|
|
2102
|
-
return
|
|
2656
|
+
return ts12.isThrowStatement(statement) || ts12.isBlock(statement) && statement.statements.length === 1 && ts12.isThrowStatement(statement.statements[0]);
|
|
2103
2657
|
}
|
|
2104
2658
|
function hasOrdinaryInstanceCheck(checker, declaration, seen) {
|
|
2105
|
-
if (seen.has(declaration) ||
|
|
2659
|
+
if (seen.has(declaration) || ts12.getDecorators(declaration)?.length || hasPrototypeMutation(declaration.getSourceFile()) || declaration.members.some(ts12.isClassStaticBlockDeclaration))
|
|
2106
2660
|
return false;
|
|
2107
2661
|
seen.add(declaration);
|
|
2108
2662
|
if (declaration.members.some(
|
|
2109
|
-
(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)
|
|
2110
2664
|
))
|
|
2111
2665
|
return false;
|
|
2112
2666
|
for (const clause of declaration.heritageClauses ?? []) {
|
|
2113
|
-
if (clause.token !==
|
|
2667
|
+
if (clause.token !== ts12.SyntaxKind.ExtendsKeyword) continue;
|
|
2114
2668
|
for (const parent of clause.types) {
|
|
2115
2669
|
const ancestor = canonicalSymbol(
|
|
2116
2670
|
checker,
|
|
2117
2671
|
parent.expression
|
|
2118
|
-
)?.declarations?.find(
|
|
2672
|
+
)?.declarations?.find(ts12.isClassDeclaration);
|
|
2119
2673
|
if (ancestor === void 0 || !hasOrdinaryInstanceCheck(checker, ancestor, seen))
|
|
2120
2674
|
return false;
|
|
2121
2675
|
}
|
|
@@ -2123,9 +2677,9 @@ function hasOrdinaryInstanceCheck(checker, declaration, seen) {
|
|
|
2123
2677
|
return true;
|
|
2124
2678
|
}
|
|
2125
2679
|
function canonicalSymbol(checker, node) {
|
|
2126
|
-
if (
|
|
2680
|
+
if (ts12.isParenthesizedExpression(node)) node = unparenthesized2(node);
|
|
2127
2681
|
const symbol = checker.getSymbolAtLocation(node);
|
|
2128
|
-
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;
|
|
2129
2683
|
}
|
|
2130
2684
|
var require_explicit_contract_implementation_default = createRule({
|
|
2131
2685
|
name: "require-explicit-contract-implementation",
|
|
@@ -2150,11 +2704,11 @@ var require_explicit_contract_implementation_default = createRule({
|
|
|
2150
2704
|
const checker = services.program.getTypeChecker();
|
|
2151
2705
|
function inspect(node) {
|
|
2152
2706
|
const tsNode = services.esTreeNodeToTSNodeMap.get(node);
|
|
2153
|
-
if (!
|
|
2707
|
+
if (!ts12.isNewExpression(tsNode)) return;
|
|
2154
2708
|
const consumer = canonicalSymbol(
|
|
2155
2709
|
checker,
|
|
2156
2710
|
tsNode.expression
|
|
2157
|
-
)?.declarations?.find(
|
|
2711
|
+
)?.declarations?.find(ts12.isClassDeclaration);
|
|
2158
2712
|
if (consumer === void 0) return;
|
|
2159
2713
|
const signature = checker.getResolvedSignature(tsNode);
|
|
2160
2714
|
if (signature === void 0 || signature.getDeclaration()?.parent !== consumer)
|
|
@@ -2182,7 +2736,7 @@ var require_explicit_contract_implementation_default = createRule({
|
|
|
2182
2736
|
))
|
|
2183
2737
|
continue;
|
|
2184
2738
|
const contract = missing.contractSymbol.declarations?.find(
|
|
2185
|
-
|
|
2739
|
+
ts12.isClassDeclaration
|
|
2186
2740
|
);
|
|
2187
2741
|
context.report({
|
|
2188
2742
|
node: argument,
|
|
@@ -3473,7 +4027,7 @@ var no_conditional_empty_object_spread_default = createRule({
|
|
|
3473
4027
|
|
|
3474
4028
|
// src/rules/prefer-typed-reflection.ts
|
|
3475
4029
|
var import_utils20 = require("@typescript-eslint/utils");
|
|
3476
|
-
var
|
|
4030
|
+
var import_typescript12 = __toESM(require("typescript"), 1);
|
|
3477
4031
|
var PREFER_TYPED_REFLECTION_DOCUMENTATION = {
|
|
3478
4032
|
summary: "Prefer typed access when Reflect.get or Reflect.apply discards a known contract.",
|
|
3479
4033
|
rationale: "Reflect.get and Reflect.apply can accept property or argument mistakes that normal typed access catches.",
|
|
@@ -3526,7 +4080,7 @@ var PREFER_TYPED_REFLECTION_DOCUMENTATION = {
|
|
|
3526
4080
|
};
|
|
3527
4081
|
function knownType(type) {
|
|
3528
4082
|
if (type.isUnion()) return type.types.every(knownType);
|
|
3529
|
-
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;
|
|
3530
4084
|
}
|
|
3531
4085
|
var prefer_typed_reflection_default = createRule({
|
|
3532
4086
|
name: "prefer-typed-reflection",
|
|
@@ -3578,7 +4132,7 @@ var prefer_typed_reflection_default = createRule({
|
|
|
3578
4132
|
const key = unwrapExpression(writtenKey);
|
|
3579
4133
|
const name = staticString(key) ?? (key.type === import_utils20.AST_NODE_TYPES.Literal && typeof key.value === "number" ? String(key.value) : null);
|
|
3580
4134
|
const members = type.isUnion() ? type.types : [type];
|
|
3581
|
-
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;
|
|
3582
4136
|
return `(${context.sourceCode.getText(target)})[${context.sourceCode.getText(writtenKey)}]`;
|
|
3583
4137
|
};
|
|
3584
4138
|
return {
|
|
@@ -3603,7 +4157,7 @@ var prefer_typed_reflection_default = createRule({
|
|
|
3603
4157
|
|
|
3604
4158
|
// src/rules/no-broad-return-type.ts
|
|
3605
4159
|
var import_utils22 = require("@typescript-eslint/utils");
|
|
3606
|
-
var
|
|
4160
|
+
var import_typescript13 = __toESM(require("typescript"), 1);
|
|
3607
4161
|
|
|
3608
4162
|
// src/rules/_unused-private-binding.ts
|
|
3609
4163
|
var import_utils21 = require("@typescript-eslint/utils");
|
|
@@ -3704,21 +4258,21 @@ var NO_BROAD_RETURN_TYPE_DOCUMENTATION = {
|
|
|
3704
4258
|
]
|
|
3705
4259
|
};
|
|
3706
4260
|
function isBroad(type, checker) {
|
|
3707
|
-
if ((type.flags & (
|
|
4261
|
+
if ((type.flags & (import_typescript13.default.TypeFlags.Unknown | import_typescript13.default.TypeFlags.NonPrimitive)) !== 0)
|
|
3708
4262
|
return true;
|
|
3709
4263
|
const indexes = checker.getIndexInfosOfType(type);
|
|
3710
|
-
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);
|
|
3711
4265
|
}
|
|
3712
4266
|
function hasKnownContract(type, checker) {
|
|
3713
4267
|
if (type.isUnion())
|
|
3714
4268
|
return type.types.every((part) => hasKnownContract(part, checker));
|
|
3715
|
-
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;
|
|
3716
4270
|
if ((type.flags & excluded) !== 0 || isBroad(type, checker)) return false;
|
|
3717
|
-
return (type.flags &
|
|
4271
|
+
return (type.flags & import_typescript13.default.TypeFlags.Object) === 0 || type.getProperties().length > 0;
|
|
3718
4272
|
}
|
|
3719
4273
|
function isOpaque(type, checker) {
|
|
3720
4274
|
if (type.isUnion()) return type.types.some((part) => isOpaque(part, checker));
|
|
3721
|
-
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);
|
|
3722
4276
|
}
|
|
3723
4277
|
var no_broad_return_type_default = createRule({
|
|
3724
4278
|
name: "no-broad-return-type",
|
|
@@ -3745,7 +4299,7 @@ var no_broad_return_type_default = createRule({
|
|
|
3745
4299
|
const type = checker.getTypeAtLocation(
|
|
3746
4300
|
services.esTreeNodeToTSNodeMap.get(node)
|
|
3747
4301
|
);
|
|
3748
|
-
return (type.flags &
|
|
4302
|
+
return (type.flags & import_typescript13.default.TypeFlags.TypeParameter) !== 0 ? type : checker.getAwaitedType(type) ?? type;
|
|
3749
4303
|
};
|
|
3750
4304
|
const inspectReturn = (value) => {
|
|
3751
4305
|
const frame = frames.at(-1);
|
|
@@ -3790,7 +4344,7 @@ var no_broad_return_type_default = createRule({
|
|
|
3790
4344
|
|
|
3791
4345
|
// src/rules/no-reduce-accumulator-copy.ts
|
|
3792
4346
|
var import_utils24 = require("@typescript-eslint/utils");
|
|
3793
|
-
var
|
|
4347
|
+
var import_typescript14 = __toESM(require("typescript"), 1);
|
|
3794
4348
|
|
|
3795
4349
|
// src/rules/_literal-identity-reduce-fix.ts
|
|
3796
4350
|
var import_utils23 = require("@typescript-eslint/utils");
|
|
@@ -3950,7 +4504,7 @@ var no_reduce_accumulator_copy_default = createRule({
|
|
|
3950
4504
|
services.esTreeNodeToTSNodeMap.get(node)
|
|
3951
4505
|
);
|
|
3952
4506
|
const declaration = signature?.declaration;
|
|
3953
|
-
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))
|
|
3954
4508
|
return;
|
|
3955
4509
|
const accumulator = context.sourceCode.getDeclaredVariables(callback).find((variable) => variable.identifiers.includes(parameter));
|
|
3956
4510
|
if (!accumulator || accumulator.references.some((reference) => reference.isWrite()))
|
|
@@ -4012,7 +4566,7 @@ var no_reduce_accumulator_copy_default = createRule({
|
|
|
4012
4566
|
|
|
4013
4567
|
// src/rules/no-known-value-widening.ts
|
|
4014
4568
|
var import_utils25 = require("@typescript-eslint/utils");
|
|
4015
|
-
var
|
|
4569
|
+
var import_typescript15 = __toESM(require("typescript"), 1);
|
|
4016
4570
|
var NO_KNOWN_VALUE_WIDENING_DOCUMENTATION = {
|
|
4017
4571
|
summary: "Preserve a known value's contract instead of widening a local binding to unknown, object, or an unknown-valued dictionary.",
|
|
4018
4572
|
rationale: "Erasing a typed value's fields forces downstream code to rediscover the same contract through casts, reflection, or representation checks.",
|
|
@@ -4039,13 +4593,13 @@ var NO_KNOWN_VALUE_WIDENING_DOCUMENTATION = {
|
|
|
4039
4593
|
]
|
|
4040
4594
|
};
|
|
4041
4595
|
function erasesContract(type, checker) {
|
|
4042
|
-
if ((type.flags & (
|
|
4596
|
+
if ((type.flags & (import_typescript15.default.TypeFlags.Unknown | import_typescript15.default.TypeFlags.NonPrimitive)) !== 0) return true;
|
|
4043
4597
|
const indexes = checker.getIndexInfosOfType(type);
|
|
4044
|
-
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);
|
|
4045
4599
|
}
|
|
4046
4600
|
function hasUnknownContract(type, checker) {
|
|
4047
4601
|
if (type.isUnionOrIntersection()) return type.types.some((part) => hasUnknownContract(part, checker));
|
|
4048
|
-
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);
|
|
4049
4603
|
}
|
|
4050
4604
|
var no_known_value_widening_default = createRule({
|
|
4051
4605
|
name: "no-known-value-widening",
|
|
@@ -4087,7 +4641,7 @@ var no_known_value_widening_default = createRule({
|
|
|
4087
4641
|
// src/rules/no-invalid-typed-mutation.ts
|
|
4088
4642
|
var import_utils26 = require("@typescript-eslint/utils");
|
|
4089
4643
|
var import_ts_api_utils = require("ts-api-utils");
|
|
4090
|
-
var
|
|
4644
|
+
var import_typescript16 = __toESM(require("typescript"), 1);
|
|
4091
4645
|
var NO_INVALID_TYPED_MUTATION_DOCUMENTATION = {
|
|
4092
4646
|
summary: "Keep native object mutation APIs from writing incompatible values into declared property types.",
|
|
4093
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.",
|
|
@@ -4245,21 +4799,21 @@ function keepsMutableDescriptor(call, method) {
|
|
|
4245
4799
|
function declaredTargetType(node, checker) {
|
|
4246
4800
|
const symbol = checker.getSymbolAtLocation(node);
|
|
4247
4801
|
const declaration = symbol?.valueDeclaration;
|
|
4248
|
-
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;
|
|
4249
4803
|
const type = checker.getTypeFromTypeNode(declaration.type);
|
|
4250
|
-
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;
|
|
4251
4805
|
return type;
|
|
4252
4806
|
}
|
|
4253
4807
|
function typedDataProperty(property) {
|
|
4254
4808
|
const declarations = property.getDeclarations();
|
|
4255
|
-
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);
|
|
4256
4810
|
}
|
|
4257
4811
|
function propertyWriteType(target, property, node, checker, exact) {
|
|
4258
4812
|
const exposed = checker.getTypeOfSymbolAtLocation(property, node);
|
|
4259
|
-
if (!exact || (property.flags &
|
|
4260
|
-
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;
|
|
4261
4815
|
const declaration = property.getDeclarations()?.[0];
|
|
4262
|
-
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;
|
|
4263
4817
|
const authored = checker.getTypeFromTypeNode(declaration.type);
|
|
4264
4818
|
return definiteType(authored, checker) && checker.isTypeAssignableTo(authored, exposed) ? authored : exposed;
|
|
4265
4819
|
}
|
|
@@ -4267,13 +4821,13 @@ function definiteType(type, checker, seen = /* @__PURE__ */ new Set()) {
|
|
|
4267
4821
|
if (seen.has(type)) return true;
|
|
4268
4822
|
if (seen.size >= 32) return false;
|
|
4269
4823
|
seen.add(type);
|
|
4270
|
-
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;
|
|
4271
4825
|
if ((type.flags & unsafe) !== 0) return false;
|
|
4272
4826
|
if (type.isUnionOrIntersection()) return type.types.every((part) => definiteType(part, checker, seen));
|
|
4273
4827
|
const arguments_ = (0, import_ts_api_utils.isTypeReference)(type) ? checker.getTypeArguments(type) : type.aliasTypeArguments ?? [];
|
|
4274
4828
|
if (!arguments_.every((argument) => definiteType(argument, checker, seen))) return false;
|
|
4275
4829
|
if (!definiteSignatures(type, checker, seen)) return false;
|
|
4276
|
-
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;
|
|
4277
4831
|
return type.getProperties().every((property) => {
|
|
4278
4832
|
const declaration = property.valueDeclaration ?? property.getDeclarations()?.[0];
|
|
4279
4833
|
return declaration !== void 0 && definiteType(checker.getTypeOfSymbolAtLocation(property, declaration), checker, seen);
|
|
@@ -4357,33 +4911,33 @@ function plainProperties(node) {
|
|
|
4357
4911
|
|
|
4358
4912
|
// src/rules/no-contradictory-type-predicate.ts
|
|
4359
4913
|
var import_utils28 = require("@typescript-eslint/utils");
|
|
4360
|
-
var
|
|
4914
|
+
var import_typescript19 = __toESM(require("typescript"), 1);
|
|
4361
4915
|
|
|
4362
4916
|
// src/rules/_has-separate-predicate-contract.ts
|
|
4363
|
-
var
|
|
4917
|
+
var import_typescript17 = __toESM(require("typescript"), 1);
|
|
4364
4918
|
function hasSeparatePredicateContract(node, checker) {
|
|
4365
|
-
if (
|
|
4366
|
-
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;
|
|
4367
4921
|
if (node.name !== void 0 && (checker.getSymbolAtLocation(node.name)?.getDeclarations()?.length ?? 0) > 1) return true;
|
|
4368
|
-
if (!
|
|
4922
|
+
if (!import_typescript17.default.isMethodDeclaration(node)) return false;
|
|
4369
4923
|
const owner = node.parent;
|
|
4370
|
-
if (
|
|
4371
|
-
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;
|
|
4372
4926
|
}
|
|
4373
4927
|
|
|
4374
4928
|
// src/rules/_contradictory-array-predicate.ts
|
|
4375
4929
|
var import_utils27 = require("@typescript-eslint/utils");
|
|
4376
|
-
var
|
|
4930
|
+
var import_typescript18 = __toESM(require("typescript"), 1);
|
|
4377
4931
|
var import_ts_api_utils2 = require("ts-api-utils");
|
|
4378
4932
|
var HOST_GLOBALS = ["globalThis", "window", "self", "global"];
|
|
4379
|
-
var PRIMITIVE_ELEMENTS =
|
|
4380
|
-
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__"]);
|
|
4381
4935
|
function contradictoryArrayPredicate(sourceCode, services) {
|
|
4382
4936
|
const checker = services.program.getTypeChecker();
|
|
4383
4937
|
const stable2 = /* @__PURE__ */ new WeakMap();
|
|
4384
4938
|
let constructorCapability = false;
|
|
4385
4939
|
function matches(expression, parameter, input, target) {
|
|
4386
|
-
if ((input.flags &
|
|
4940
|
+
if ((input.flags & import_typescript18.default.TypeFlags.Unknown) === 0 || !plainPrimitiveArray(target, checker)) return false;
|
|
4387
4941
|
const call = unwrapExpression(expression);
|
|
4388
4942
|
if (call.type !== import_utils27.AST_NODE_TYPES.CallExpression || call.optional || call.arguments.length !== 1) return false;
|
|
4389
4943
|
const argument = call.arguments[0];
|
|
@@ -4411,7 +4965,7 @@ function contradictoryArrayPredicate(sourceCode, services) {
|
|
|
4411
4965
|
function plainPrimitiveArray(target, checker) {
|
|
4412
4966
|
if (!checker.isArrayType(target) || !(0, import_ts_api_utils2.isTypeReference)(target)) return false;
|
|
4413
4967
|
const [element] = checker.getTypeArguments(target);
|
|
4414
|
-
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;
|
|
4415
4969
|
}
|
|
4416
4970
|
function nativeBinding(identifier, sourceCode) {
|
|
4417
4971
|
const binding3 = import_utils27.ASTUtils.findVariable(sourceCode.getScope(identifier), identifier.name);
|
|
@@ -4443,7 +4997,7 @@ function ordinaryObjectUse(node) {
|
|
|
4443
4997
|
const member3 = node.parent;
|
|
4444
4998
|
if (member3?.type !== import_utils27.AST_NODE_TYPES.MemberExpression || member3.object !== node) return false;
|
|
4445
4999
|
const name = import_utils27.ASTUtils.getPropertyName(member3);
|
|
4446
|
-
return name !== null && !
|
|
5000
|
+
return name !== null && !OBJECT_REFLECTION2.has(name);
|
|
4447
5001
|
}
|
|
4448
5002
|
function ordinaryArrayReference(reference) {
|
|
4449
5003
|
if (reference.isWrite()) return false;
|
|
@@ -4476,11 +5030,11 @@ function ordinaryHostReference(reference) {
|
|
|
4476
5030
|
// src/rules/no-contradictory-type-predicate.ts
|
|
4477
5031
|
var RUNTIME_KINDS = /* @__PURE__ */ new Set(["string", "number", "bigint", "boolean", "symbol", "undefined", "object", "function"]);
|
|
4478
5032
|
var PRIMITIVE_KINDS = [
|
|
4479
|
-
[
|
|
4480
|
-
[
|
|
4481
|
-
[
|
|
4482
|
-
[
|
|
4483
|
-
[
|
|
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"]
|
|
4484
5038
|
];
|
|
4485
5039
|
var NO_CONTRADICTORY_TYPE_PREDICATE_DOCUMENTATION = {
|
|
4486
5040
|
summary: "Keep explicit type predicates consistent with their primitive or native array membership check.",
|
|
@@ -4581,10 +5135,10 @@ var no_contradictory_type_predicate_default = createRule({
|
|
|
4581
5135
|
}
|
|
4582
5136
|
});
|
|
4583
5137
|
function contradiction(input, target, checked, checker, strictNulls) {
|
|
4584
|
-
if (strictNulls && checked === "object" && (target.flags &
|
|
5138
|
+
if (strictNulls && checked === "object" && (target.flags & import_typescript19.default.TypeFlags.NonPrimitive) !== 0 && admitsNull(input)) return "nullAccepted";
|
|
4585
5139
|
const possible = inputKinds(input, checker);
|
|
4586
5140
|
if (possible === void 0 || !possible.has(checked)) return void 0;
|
|
4587
|
-
if ((target.flags &
|
|
5141
|
+
if ((target.flags & import_typescript19.default.TypeFlags.Never) !== 0) return "contradictoryPredicate";
|
|
4588
5142
|
const promised = primitiveKinds(target, checker, false);
|
|
4589
5143
|
if (promised !== void 0) {
|
|
4590
5144
|
return !promised.has(checked) || [...promised].some((kind) => kind !== checked && possible.has(kind)) ? "contradictoryPredicate" : void 0;
|
|
@@ -4592,18 +5146,18 @@ function contradiction(input, target, checked, checker, strictNulls) {
|
|
|
4592
5146
|
return closedLiteralContradiction(input, target, checked, checker) ? "closedLiteralPredicate" : void 0;
|
|
4593
5147
|
}
|
|
4594
5148
|
function admitsNull(input) {
|
|
4595
|
-
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);
|
|
4596
5150
|
}
|
|
4597
5151
|
function closedLiteralContradiction(input, target, checked, checker) {
|
|
4598
5152
|
const members = target.isUnion() ? target.types : [target];
|
|
4599
|
-
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;
|
|
4600
5154
|
if (!members.every((member3) => (member3.flags & literalFlags) !== 0)) return false;
|
|
4601
5155
|
if (members.some((member3) => literalKind(member3, checker) !== checked)) return true;
|
|
4602
|
-
if ((input.flags &
|
|
5156
|
+
if ((input.flags & import_typescript19.default.TypeFlags.Unknown) !== 0) return checked !== "undefined";
|
|
4603
5157
|
return (input.isUnion() ? input.types : [input]).some((member3) => literalKind(member3, checker) === checked && !checker.isTypeAssignableTo(member3, target));
|
|
4604
5158
|
}
|
|
4605
5159
|
function literalKind(type, checker) {
|
|
4606
|
-
if ((type.flags &
|
|
5160
|
+
if ((type.flags & import_typescript19.default.TypeFlags.BooleanLiteral) !== 0) return "boolean";
|
|
4607
5161
|
return primitiveKinds(type, checker, true)?.values().next().value;
|
|
4608
5162
|
}
|
|
4609
5163
|
function singleReturn(node) {
|
|
@@ -4631,7 +5185,7 @@ function sameParameter(declared, tested, sourceCode) {
|
|
|
4631
5185
|
return parameter !== null && parameter === import_utils28.ASTUtils.findVariable(sourceCode.getScope(tested), tested.name);
|
|
4632
5186
|
}
|
|
4633
5187
|
function inputKinds(type, checker) {
|
|
4634
|
-
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"]);
|
|
4635
5189
|
return primitiveKinds(type, checker, true);
|
|
4636
5190
|
}
|
|
4637
5191
|
function primitiveKinds(type, checker, allowLiterals) {
|
|
@@ -4643,7 +5197,7 @@ function primitiveKinds(type, checker, allowLiterals) {
|
|
|
4643
5197
|
kinds.add(kind);
|
|
4644
5198
|
continue;
|
|
4645
5199
|
}
|
|
4646
|
-
if ((member3.flags &
|
|
5200
|
+
if ((member3.flags & import_typescript19.default.TypeFlags.BooleanLiteral) === 0) return void 0;
|
|
4647
5201
|
booleans.add(checker.typeToString(member3));
|
|
4648
5202
|
}
|
|
4649
5203
|
if (booleans.size > 0) {
|
|
@@ -4657,21 +5211,21 @@ function primitiveKind(type, allowLiterals) {
|
|
|
4657
5211
|
if ((type.flags & flag) !== 0) return kind;
|
|
4658
5212
|
}
|
|
4659
5213
|
if (!allowLiterals) return void 0;
|
|
4660
|
-
if ((type.flags &
|
|
4661
|
-
if ((type.flags &
|
|
4662
|
-
if ((type.flags &
|
|
4663
|
-
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";
|
|
4664
5218
|
return void 0;
|
|
4665
5219
|
}
|
|
4666
5220
|
|
|
4667
5221
|
// src/rules/no-partial-type-predicate.ts
|
|
4668
5222
|
var import_utils31 = require("@typescript-eslint/utils");
|
|
4669
5223
|
var import_ts_api_utils3 = require("ts-api-utils");
|
|
4670
|
-
var
|
|
5224
|
+
var import_typescript21 = __toESM(require("typescript"), 1);
|
|
4671
5225
|
|
|
4672
5226
|
// src/rules/_uuid-predicate-witness.ts
|
|
4673
5227
|
var import_utils30 = require("@typescript-eslint/utils");
|
|
4674
|
-
var
|
|
5228
|
+
var import_typescript20 = __toESM(require("typescript"), 1);
|
|
4675
5229
|
|
|
4676
5230
|
// src/rules/_native-runtime-unchanged.ts
|
|
4677
5231
|
var import_utils29 = require("@typescript-eslint/utils");
|
|
@@ -4778,7 +5332,7 @@ function noArguments(node) {
|
|
|
4778
5332
|
function installedZod(node, services) {
|
|
4779
5333
|
const checker = services.program.getTypeChecker();
|
|
4780
5334
|
const symbol = checker.getSymbolAtLocation(services.esTreeNodeToTSNodeMap.get(node));
|
|
4781
|
-
if (symbol === void 0 || (symbol.flags &
|
|
5335
|
+
if (symbol === void 0 || (symbol.flags & import_typescript20.default.SymbolFlags.Alias) === 0) return false;
|
|
4782
5336
|
const target = checker.getAliasedSymbol(symbol);
|
|
4783
5337
|
const declarations = target.getDeclarations();
|
|
4784
5338
|
return declarations !== void 0 && declarations.length > 0 && declarations.every((declaration) => {
|
|
@@ -4876,25 +5430,25 @@ function primitivePredicate(node, services) {
|
|
|
4876
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;
|
|
4877
5431
|
const checker = services.program.getTypeChecker();
|
|
4878
5432
|
const tsFunction = services.esTreeNodeToTSNodeMap.get(node);
|
|
4879
|
-
if (
|
|
5433
|
+
if (import_typescript21.default.isMethodDeclaration(tsFunction)) return void 0;
|
|
4880
5434
|
if (hasSeparatePredicateContract(tsFunction, checker)) return void 0;
|
|
4881
5435
|
const target = checker.getTypeAtLocation(services.esTreeNodeToTSNodeMap.get(annotation.typeAnnotation.typeAnnotation));
|
|
4882
5436
|
const kind = primitiveKind2(target);
|
|
4883
5437
|
const input = checker.getTypeAtLocation(services.esTreeNodeToTSNodeMap.get(parameter));
|
|
4884
|
-
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;
|
|
4885
5439
|
if (kind === void 0 || (input.flags & unsafe) !== 0 || !checker.isTypeAssignableTo(target, input)) return void 0;
|
|
4886
5440
|
const expression = returnedExpression2(node);
|
|
4887
5441
|
return expression === void 0 ? void 0 : { annotation, parameter, expression, kind, input, inputIsTarget: checker.isTypeAssignableTo(input, target) };
|
|
4888
5442
|
}
|
|
4889
5443
|
function primitiveKind2(type) {
|
|
4890
|
-
if ((type.flags &
|
|
4891
|
-
if ((type.flags &
|
|
4892
|
-
if ((type.flags &
|
|
4893
|
-
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";
|
|
4894
5448
|
return void 0;
|
|
4895
5449
|
}
|
|
4896
5450
|
function numericWitnessInInput(value, input) {
|
|
4897
|
-
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);
|
|
4898
5452
|
}
|
|
4899
5453
|
function returnedExpression2(node) {
|
|
4900
5454
|
if (node.body === void 0) return void 0;
|
|
@@ -5007,7 +5561,7 @@ var import_utils34 = require("@typescript-eslint/utils");
|
|
|
5007
5561
|
|
|
5008
5562
|
// src/rules/_boolean-selector-contract.ts
|
|
5009
5563
|
var import_utils32 = require("@typescript-eslint/utils");
|
|
5010
|
-
var
|
|
5564
|
+
var import_typescript22 = __toESM(require("typescript"), 1);
|
|
5011
5565
|
var MEMBER_REFERENCES = /* @__PURE__ */ new WeakMap();
|
|
5012
5566
|
function isEligibleBooleanSelector(identifier, sourceCode, services) {
|
|
5013
5567
|
const owner = enclosingFunction(identifier);
|
|
@@ -5019,12 +5573,12 @@ function isEligibleBooleanSelector(identifier, sourceCode, services) {
|
|
|
5019
5573
|
const definition = binding3?.defs[0];
|
|
5020
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;
|
|
5021
5575
|
const checker = services.program.getTypeChecker();
|
|
5022
|
-
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;
|
|
5023
5577
|
const parameter = definition.name.parent.type === import_utils32.AST_NODE_TYPES.AssignmentPattern ? definition.name.parent : definition.name;
|
|
5024
5578
|
const index = owner.params.indexOf(parameter);
|
|
5025
5579
|
if (index < 0 || isPureMapping(owner, sourceCode, services)) return false;
|
|
5026
5580
|
const implementation = services.esTreeNodeToTSNodeMap.get(owner);
|
|
5027
|
-
if (
|
|
5581
|
+
if (import_typescript22.default.isSetAccessorDeclaration(implementation)) return false;
|
|
5028
5582
|
const authority = { checker, index, implementation };
|
|
5029
5583
|
if (hasDeclaredContract(authority) || hasMemberCallbackReference(authority, sourceCode, services)) return false;
|
|
5030
5584
|
const callable = callableBinding2(owner, sourceCode);
|
|
@@ -5040,10 +5594,10 @@ function booleanContract(authority, type, independentlyAnnotated = false) {
|
|
|
5040
5594
|
return (type === void 0 ? [] : authority.checker.getNonNullableType(type).getCallSignatures()).some((signature) => {
|
|
5041
5595
|
const declaration = signature.declaration;
|
|
5042
5596
|
const parameter = declaration?.parameters[authority.index];
|
|
5043
|
-
if (declaration === void 0 || declaration === authority.implementation || parameter === void 0 || !
|
|
5044
|
-
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;
|
|
5045
5599
|
const instantiated = signature.getParameters()[authority.index];
|
|
5046
|
-
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;
|
|
5047
5601
|
});
|
|
5048
5602
|
}
|
|
5049
5603
|
function callbackContract(authority, expression) {
|
|
@@ -5051,22 +5605,22 @@ function callbackContract(authority, expression) {
|
|
|
5051
5605
|
if (booleanContract(authority, checker.getContextualType(expression))) return true;
|
|
5052
5606
|
const value = outerTypedExpression(expression);
|
|
5053
5607
|
const parent = value.parent;
|
|
5054
|
-
if (
|
|
5608
|
+
if (import_typescript22.default.isCallExpression(parent)) {
|
|
5055
5609
|
const index = parent.arguments.indexOf(value);
|
|
5056
5610
|
const parameter = index < 0 ? void 0 : checker.getResolvedSignature(parent)?.declaration?.parameters[index];
|
|
5057
|
-
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);
|
|
5058
5612
|
}
|
|
5059
|
-
if (!
|
|
5613
|
+
if (!import_typescript22.default.isJsxExpression(parent) || !import_typescript22.default.isJsxAttribute(parent.parent)) return false;
|
|
5060
5614
|
const attribute = parent.parent;
|
|
5061
|
-
if (checker.getSymbolAtLocation(attribute.name)?.declarations?.some((declaration) => (
|
|
5062
|
-
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;
|
|
5063
5617
|
const opening = attribute.parent.parent;
|
|
5064
5618
|
const propContract = (type) => {
|
|
5065
5619
|
const property = checker.getPropertyOfType(type, attribute.name.getText());
|
|
5066
5620
|
return property !== void 0 && booleanContract(authority, checker.getTypeOfSymbolAtLocation(property, attribute), true);
|
|
5067
5621
|
};
|
|
5068
5622
|
const props = checker.getResolvedSignature(opening)?.declaration?.parameters[0];
|
|
5069
|
-
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;
|
|
5070
5624
|
return checker.getTypeAtLocation(opening.tagName).getCallSignatures().some((signature) => {
|
|
5071
5625
|
const parameter = signature.getParameters()[0];
|
|
5072
5626
|
return parameter !== void 0 && propContract(checker.getTypeOfSymbolAtLocation(parameter, opening.tagName));
|
|
@@ -5074,41 +5628,41 @@ function callbackContract(authority, expression) {
|
|
|
5074
5628
|
}
|
|
5075
5629
|
function outerTypedExpression(node) {
|
|
5076
5630
|
let current = node;
|
|
5077
|
-
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;
|
|
5078
5632
|
return current;
|
|
5079
5633
|
}
|
|
5080
5634
|
function hasDeclaredContract(authority) {
|
|
5081
5635
|
const node = authority.implementation;
|
|
5082
5636
|
const checker = authority.checker;
|
|
5083
|
-
if (
|
|
5637
|
+
if (import_typescript22.default.isArrowFunction(node) || import_typescript22.default.isFunctionExpression(node)) {
|
|
5084
5638
|
if (callbackContract(authority, node)) return true;
|
|
5085
5639
|
const binding3 = outerTypedExpression(node).parent;
|
|
5086
|
-
if ((
|
|
5087
|
-
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);
|
|
5088
5642
|
}
|
|
5089
|
-
if (
|
|
5090
|
-
if (!
|
|
5091
|
-
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;
|
|
5092
5646
|
}
|
|
5093
5647
|
function memberContract(authority, member3) {
|
|
5094
5648
|
const owner = member3.parent;
|
|
5095
5649
|
const checker = authority.checker;
|
|
5096
5650
|
const symbol = checker.getSymbolAtLocation(member3.name);
|
|
5097
|
-
if (symbol === void 0 ||
|
|
5651
|
+
if (symbol === void 0 || import_typescript22.default.isPrivateIdentifier(member3.name)) return false;
|
|
5098
5652
|
const matches = (type, independentlyAnnotated = false) => {
|
|
5099
5653
|
const property = type.getProperties().find((candidate2) => candidate2.escapedName === symbol.escapedName);
|
|
5100
5654
|
return property !== void 0 && booleanContract(authority, checker.getTypeOfSymbolAtLocation(property, member3), independentlyAnnotated);
|
|
5101
5655
|
};
|
|
5102
|
-
if (
|
|
5656
|
+
if (import_typescript22.default.isObjectLiteralExpression(owner)) {
|
|
5103
5657
|
const contextual = checker.getContextualType(owner);
|
|
5104
5658
|
const binding3 = outerTypedExpression(owner).parent;
|
|
5105
|
-
if (
|
|
5659
|
+
if (import_typescript22.default.isVariableDeclaration(binding3) && binding3.type !== void 0 && matches(checker.getTypeFromTypeNode(binding3.type), true)) return true;
|
|
5106
5660
|
return contextual !== void 0 && matches(contextual);
|
|
5107
5661
|
}
|
|
5108
|
-
if (!
|
|
5109
|
-
const modifiers =
|
|
5110
|
-
if ((modifiers &
|
|
5111
|
-
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;
|
|
5112
5666
|
}
|
|
5113
5667
|
function callableBinding2(owner, sourceCode) {
|
|
5114
5668
|
if (owner.type === import_utils32.AST_NODE_TYPES.FunctionDeclaration && owner.id !== null) return import_utils32.ASTUtils.findVariable(sourceCode.getScope(owner), owner.id.name);
|
|
@@ -5128,7 +5682,7 @@ function hasCallbackReference(binding3, authority, sourceCode, services, seen) {
|
|
|
5128
5682
|
const jsxAttribute = parent?.type === import_utils32.AST_NODE_TYPES.JSXExpressionContainer && parent.parent.type === import_utils32.AST_NODE_TYPES.JSXAttribute;
|
|
5129
5683
|
if (callArgument || jsxAttribute) {
|
|
5130
5684
|
const expression = services.esTreeNodeToTSNodeMap.get(value);
|
|
5131
|
-
if (
|
|
5685
|
+
if (import_typescript22.default.isExpression(expression) && callbackContract(authority, expression)) return true;
|
|
5132
5686
|
}
|
|
5133
5687
|
if (parent?.type === import_utils32.AST_NODE_TYPES.CallExpression && parent.callee === value && forwardedCallbackParameter(parent, authority, sourceCode, services)) return true;
|
|
5134
5688
|
let selected = value;
|
|
@@ -5153,20 +5707,20 @@ function forwardedCallbackParameter(call, authority, sourceCode, services) {
|
|
|
5153
5707
|
const binding3 = import_utils32.ASTUtils.findVariable(sourceCode.getScope(argument), argument.name);
|
|
5154
5708
|
const definition = binding3?.defs[0];
|
|
5155
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;
|
|
5156
|
-
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;
|
|
5157
5711
|
const parameter = definition.name.parent.type === import_utils32.AST_NODE_TYPES.AssignmentPattern ? definition.name.parent : definition.name;
|
|
5158
5712
|
const index = wrapper.params.indexOf(parameter);
|
|
5159
5713
|
const implementation = services.esTreeNodeToTSNodeMap.get(wrapper);
|
|
5160
|
-
return index >= 0 && (
|
|
5714
|
+
return index >= 0 && (import_typescript22.default.isArrowFunction(implementation) || import_typescript22.default.isFunctionExpression(implementation)) && callbackContract({ checker: authority.checker, index, implementation }, implementation);
|
|
5161
5715
|
}
|
|
5162
5716
|
function hasMemberCallbackReference(authority, sourceCode, services) {
|
|
5163
5717
|
const node = authority.implementation;
|
|
5164
|
-
const member3 =
|
|
5165
|
-
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;
|
|
5166
5720
|
let references = MEMBER_REFERENCES.get(sourceCode);
|
|
5167
5721
|
if (references === void 0) {
|
|
5168
5722
|
let visit2 = function(current) {
|
|
5169
|
-
if (
|
|
5723
|
+
if (import_typescript22.default.isPropertyAccessExpression(current)) {
|
|
5170
5724
|
const target = authority.checker.getSymbolAtLocation(current.name);
|
|
5171
5725
|
for (const declaration of target?.declarations ?? []) {
|
|
5172
5726
|
const values = collected.get(declaration) ?? [];
|
|
@@ -5174,7 +5728,7 @@ function hasMemberCallbackReference(authority, sourceCode, services) {
|
|
|
5174
5728
|
collected.set(declaration, values);
|
|
5175
5729
|
}
|
|
5176
5730
|
}
|
|
5177
|
-
|
|
5731
|
+
import_typescript22.default.forEachChild(current, visit2);
|
|
5178
5732
|
};
|
|
5179
5733
|
var visit = visit2;
|
|
5180
5734
|
const collected = /* @__PURE__ */ new Map();
|
|
@@ -5185,14 +5739,14 @@ function hasMemberCallbackReference(authority, sourceCode, services) {
|
|
|
5185
5739
|
return references.get(member3)?.some((reference) => {
|
|
5186
5740
|
let value = outerTypedExpression(reference);
|
|
5187
5741
|
const bind = value.parent;
|
|
5188
|
-
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) {
|
|
5189
5743
|
const declaration = authority.checker.getResolvedSignature(bind.parent)?.declaration;
|
|
5190
5744
|
if (declaration === void 0 || !services.program.isSourceFileDefaultLibrary(declaration.getSourceFile())) return false;
|
|
5191
5745
|
value = outerTypedExpression(bind.parent);
|
|
5192
5746
|
}
|
|
5193
5747
|
const parent = value.parent;
|
|
5194
|
-
const callback =
|
|
5195
|
-
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);
|
|
5196
5750
|
return (callback || jsx) && callbackContract(authority, value);
|
|
5197
5751
|
}) === true;
|
|
5198
5752
|
}
|
|
@@ -5236,21 +5790,21 @@ function sameTarget(left, right, sourceCode, services, operation2) {
|
|
|
5236
5790
|
if (!operation2) return true;
|
|
5237
5791
|
const checker = services.program.getTypeChecker();
|
|
5238
5792
|
const property = checker.getSymbolAtLocation(services.esTreeNodeToTSNodeMap.get(left.property));
|
|
5239
|
-
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;
|
|
5240
5794
|
}
|
|
5241
5795
|
function pureValue(node, sourceCode, services) {
|
|
5242
5796
|
const value = unwrapExpression(node);
|
|
5243
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);
|
|
5244
5798
|
if (value.type === import_utils32.AST_NODE_TYPES.ChainExpression) return pureValue(value.expression, sourceCode, services);
|
|
5245
5799
|
if (value.type === import_utils32.AST_NODE_TYPES.UnaryExpression && (value.operator === "!" || value.operator === "typeof" || value.operator === "void")) return pureValue(value.argument, sourceCode, services);
|
|
5246
|
-
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);
|
|
5247
5801
|
if (!import_utils32.ASTUtils.hasSideEffect(value, sourceCode, { considerGetters: true, considerImplicitTypeConversion: true })) return true;
|
|
5248
5802
|
if (value.type !== import_utils32.AST_NODE_TYPES.BinaryExpression || value.left.type === import_utils32.AST_NODE_TYPES.PrivateIdentifier) return false;
|
|
5249
|
-
return
|
|
5803
|
+
return primitiveValue2(value.left, services) && primitiveValue2(value.right, services) && pureValue(value.left, sourceCode, services) && pureValue(value.right, sourceCode, services);
|
|
5250
5804
|
}
|
|
5251
|
-
function
|
|
5805
|
+
function primitiveValue2(operand, services) {
|
|
5252
5806
|
const type = services.program.getTypeChecker().getTypeAtLocation(services.esTreeNodeToTSNodeMap.get(operand));
|
|
5253
|
-
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);
|
|
5254
5808
|
}
|
|
5255
5809
|
|
|
5256
5810
|
// src/rules/_literal-selector-fix.ts
|
|
@@ -5481,7 +6035,7 @@ function isDirectTest(identifier) {
|
|
|
5481
6035
|
// src/rules/no-invalid-zod-custom-parse.ts
|
|
5482
6036
|
var import_utils36 = require("@typescript-eslint/utils");
|
|
5483
6037
|
var import_ts_api_utils4 = require("ts-api-utils");
|
|
5484
|
-
var
|
|
6038
|
+
var import_typescript23 = __toESM(require("typescript"), 1);
|
|
5485
6039
|
|
|
5486
6040
|
// src/rules/_import-specifier-name.ts
|
|
5487
6041
|
var import_utils35 = require("@typescript-eslint/utils");
|
|
@@ -5577,17 +6131,17 @@ function nativeZodDeclaration(signature) {
|
|
|
5577
6131
|
}
|
|
5578
6132
|
function primitiveDomain(type) {
|
|
5579
6133
|
if (type.isUnion()) return type.types.every(primitiveDomain);
|
|
5580
|
-
if ((type.flags & (
|
|
5581
|
-
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;
|
|
5582
6136
|
return (type.flags & flags) !== 0;
|
|
5583
6137
|
}
|
|
5584
6138
|
function acceptsPrimitive(type, value) {
|
|
5585
6139
|
if (type.isUnion()) return type.types.some((member3) => acceptsPrimitive(member3, value));
|
|
5586
|
-
if (value === null) return (type.flags &
|
|
5587
|
-
if (typeof value === "string") return (type.flags &
|
|
5588
|
-
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;
|
|
5589
6143
|
if (typeof value === "boolean") return (0, import_ts_api_utils4.isBooleanLiteralType)(type) && type.intrinsicName === String(value);
|
|
5590
|
-
return (type.flags &
|
|
6144
|
+
return (type.flags & import_typescript23.default.TypeFlags.BigInt) !== 0 || (0, import_ts_api_utils4.isBigIntLiteralType)(type) && bigintValue(type) === value;
|
|
5591
6145
|
}
|
|
5592
6146
|
function bigintValue(type) {
|
|
5593
6147
|
return BigInt(`${type.value.negative ? "-" : ""}${type.value.base10Value}`);
|
|
@@ -5604,7 +6158,7 @@ function primitiveLiteral(node) {
|
|
|
5604
6158
|
|
|
5605
6159
|
// src/rules/no-contradictory-overload-return.ts
|
|
5606
6160
|
var import_utils37 = require("@typescript-eslint/utils");
|
|
5607
|
-
var
|
|
6161
|
+
var import_typescript24 = __toESM(require("typescript"), 1);
|
|
5608
6162
|
var LIMIT = 32;
|
|
5609
6163
|
var NO_CONTRADICTORY_OVERLOAD_RETURN_DOCUMENTATION = {
|
|
5610
6164
|
summary: "Preserve the input/result relationship promised by literal overloads.",
|
|
@@ -5702,16 +6256,16 @@ function privateOverloadFix(sourceCode, filename, node, implementation, proof, s
|
|
|
5702
6256
|
return edits.length === 0 ? null : (fixer) => edits.map((edit) => fixer.replaceText(edit.node, edit.text));
|
|
5703
6257
|
}
|
|
5704
6258
|
function directResultSyntax(node) {
|
|
5705
|
-
if (
|
|
5706
|
-
if (
|
|
5707
|
-
if (!
|
|
5708
|
-
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));
|
|
5709
6263
|
}
|
|
5710
6264
|
function primitiveResultSyntax(node) {
|
|
5711
|
-
if (
|
|
5712
|
-
if (
|
|
5713
|
-
if (
|
|
5714
|
-
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;
|
|
5715
6269
|
}
|
|
5716
6270
|
function branchResultType(branch, sourceCode, services) {
|
|
5717
6271
|
const valueType = (literal2) => typeof literal2.value === "string" ? sourceCode.getText(services.tsNodeToESTreeNodeMap.get(literal2.node)) : String(literal2.value);
|
|
@@ -5720,11 +6274,11 @@ function branchResultType(branch, sourceCode, services) {
|
|
|
5720
6274
|
}
|
|
5721
6275
|
function implementationProof(node, checker) {
|
|
5722
6276
|
const parameter = directParameter(node);
|
|
5723
|
-
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;
|
|
5724
6278
|
const returned2 = node.body.statements[0];
|
|
5725
|
-
if (returned2 === void 0 || !
|
|
6279
|
+
if (returned2 === void 0 || !import_typescript24.default.isReturnStatement(returned2) || returned2.expression === void 0) return void 0;
|
|
5726
6280
|
const expression = unparen(returned2.expression);
|
|
5727
|
-
if (!
|
|
6281
|
+
if (!import_typescript24.default.isConditionalExpression(expression)) return void 0;
|
|
5728
6282
|
const condition2 = equality(expression.condition, checker.getSymbolAtLocation(parameter.name), checker);
|
|
5729
6283
|
const yes = branchValue(expression.whenTrue);
|
|
5730
6284
|
const no = branchValue(expression.whenFalse);
|
|
@@ -5738,21 +6292,21 @@ function implementationProof(node, checker) {
|
|
|
5738
6292
|
}
|
|
5739
6293
|
function directParameter(node) {
|
|
5740
6294
|
const parameter = node.parameters[0];
|
|
5741
|
-
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;
|
|
5742
6296
|
return { name: parameter.name, type: parameter.type };
|
|
5743
6297
|
}
|
|
5744
6298
|
function overloadCases(node, implementationOutput, checker) {
|
|
5745
6299
|
const declarations = node.name === void 0 ? void 0 : checker.getSymbolAtLocation(node.name)?.declarations;
|
|
5746
|
-
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;
|
|
5747
6301
|
const cases = [];
|
|
5748
6302
|
const seen = /* @__PURE__ */ new Set();
|
|
5749
6303
|
const implementationParameter = directParameter(node);
|
|
5750
6304
|
if (implementationParameter === void 0) return void 0;
|
|
5751
6305
|
const implementationInput = checker.getTypeAtLocation(implementationParameter.type);
|
|
5752
6306
|
for (const declaration of declarations) {
|
|
5753
|
-
if (!
|
|
6307
|
+
if (!import_typescript24.default.isFunctionDeclaration(declaration) || declaration === node) continue;
|
|
5754
6308
|
const parameter = directParameter(declaration);
|
|
5755
|
-
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;
|
|
5756
6310
|
const input = primitiveLiteral2(parameter.type.literal);
|
|
5757
6311
|
const signature = checker.getSignatureFromDeclaration(declaration);
|
|
5758
6312
|
if (input === void 0 || seen.has(input.value) || signature === void 0 || !checker.isTypeAssignableTo(checker.getTypeAtLocation(parameter.type), implementationInput)) return void 0;
|
|
@@ -5765,11 +6319,11 @@ function overloadCases(node, implementationOutput, checker) {
|
|
|
5765
6319
|
}
|
|
5766
6320
|
function equality(expression, parameter, checker) {
|
|
5767
6321
|
const value = unparen(expression);
|
|
5768
|
-
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;
|
|
5769
6323
|
for (const [tested, expected] of [[value.left, value.right], [value.right, value.left]]) {
|
|
5770
6324
|
const named3 = unparen(tested);
|
|
5771
6325
|
const condition2 = primitiveLiteral2(expected);
|
|
5772
|
-
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 };
|
|
5773
6327
|
}
|
|
5774
6328
|
return void 0;
|
|
5775
6329
|
}
|
|
@@ -5777,10 +6331,10 @@ function branchValue(expression) {
|
|
|
5777
6331
|
const node = unparen(expression);
|
|
5778
6332
|
const literal2 = primitiveLiteral2(node);
|
|
5779
6333
|
if (literal2 !== void 0) return { kind: "literal", node, value: literal2 };
|
|
5780
|
-
if (!
|
|
6334
|
+
if (!import_typescript24.default.isObjectLiteralExpression(node) || node.properties.length > LIMIT) return void 0;
|
|
5781
6335
|
const values = /* @__PURE__ */ new Map();
|
|
5782
6336
|
for (const property of node.properties) {
|
|
5783
|
-
if (!
|
|
6337
|
+
if (!import_typescript24.default.isPropertyAssignment(property)) return void 0;
|
|
5784
6338
|
const name = propertyKey(property.name);
|
|
5785
6339
|
const value = primitiveLiteral2(property.initializer);
|
|
5786
6340
|
if (name === void 0 || name === "__proto__" || values.has(name) || value === void 0) return void 0;
|
|
@@ -5804,30 +6358,30 @@ function mismatches(branch, expected, checker) {
|
|
|
5804
6358
|
}
|
|
5805
6359
|
function plainPrimitive(type) {
|
|
5806
6360
|
const members = type.isUnion() ? type.types : [type];
|
|
5807
|
-
const allowed =
|
|
5808
|
-
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);
|
|
5809
6363
|
}
|
|
5810
6364
|
function primitiveLiteral2(expression) {
|
|
5811
6365
|
const node = unparen(expression);
|
|
5812
|
-
if (
|
|
5813
|
-
if (node.kind ===
|
|
5814
|
-
if (node.kind ===
|
|
5815
|
-
if (node.kind ===
|
|
5816
|
-
if (
|
|
5817
|
-
if (
|
|
5818
|
-
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);
|
|
5819
6373
|
if (Number.isFinite(value)) return { node, value };
|
|
5820
6374
|
}
|
|
5821
6375
|
return void 0;
|
|
5822
6376
|
}
|
|
5823
6377
|
function propertyKey(name) {
|
|
5824
|
-
if (
|
|
5825
|
-
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));
|
|
5826
6380
|
return void 0;
|
|
5827
6381
|
}
|
|
5828
6382
|
function unparen(expression) {
|
|
5829
6383
|
let node = expression;
|
|
5830
|
-
while (
|
|
6384
|
+
while (import_typescript24.default.isParenthesizedExpression(node)) node = node.expression;
|
|
5831
6385
|
return node;
|
|
5832
6386
|
}
|
|
5833
6387
|
|
|
@@ -12417,7 +12971,7 @@ function branchTerminates(branch) {
|
|
|
12417
12971
|
|
|
12418
12972
|
// src/rules/no-json-stringify-object-equality.ts
|
|
12419
12973
|
var import_utils76 = require("@typescript-eslint/utils");
|
|
12420
|
-
var
|
|
12974
|
+
var import_typescript25 = __toESM(require("typescript"), 1);
|
|
12421
12975
|
|
|
12422
12976
|
// src/rules/_existing-domain-comparison-fix.ts
|
|
12423
12977
|
var import_utils75 = require("@typescript-eslint/utils");
|
|
@@ -12612,7 +13166,7 @@ var EQUALITY_OPERATORS = /* @__PURE__ */ new Set([
|
|
|
12612
13166
|
"==",
|
|
12613
13167
|
"==="
|
|
12614
13168
|
]);
|
|
12615
|
-
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;
|
|
12616
13170
|
function unwrapComparisonExpression(node) {
|
|
12617
13171
|
let current = unwrapExpression(node);
|
|
12618
13172
|
while (current.type === import_utils76.AST_NODE_TYPES.ChainExpression) {
|
|
@@ -12667,7 +13221,7 @@ function typeMayContainObject(type, checker) {
|
|
|
12667
13221
|
return type.types.some((member3) => typeMayContainObject(member3, checker));
|
|
12668
13222
|
}
|
|
12669
13223
|
if ((type.flags & PRIMITIVE_FLAGS) !== 0) return false;
|
|
12670
|
-
if ((type.flags & (
|
|
13224
|
+
if ((type.flags & (import_typescript25.default.TypeFlags.Any | import_typescript25.default.TypeFlags.Unknown | import_typescript25.default.TypeFlags.TypeParameter)) !== 0) {
|
|
12671
13225
|
return true;
|
|
12672
13226
|
}
|
|
12673
13227
|
if (checker.isArrayType(type) || checker.isTupleType(type)) {
|
|
@@ -12675,7 +13229,7 @@ function typeMayContainObject(type, checker) {
|
|
|
12675
13229
|
return elements.some((element) => typeMayContainObject(element, checker));
|
|
12676
13230
|
}
|
|
12677
13231
|
const symbolName = type.getSymbol()?.getName();
|
|
12678
|
-
if ((symbolName === "Array" || symbolName === "ReadonlyArray") && (type.flags &
|
|
13232
|
+
if ((symbolName === "Array" || symbolName === "ReadonlyArray") && (type.flags & import_typescript25.default.TypeFlags.Object) !== 0) {
|
|
12679
13233
|
const elements = checker.getTypeArguments(type);
|
|
12680
13234
|
return elements.length === 0 || elements.some((element) => typeMayContainObject(element, checker));
|
|
12681
13235
|
}
|
|
@@ -13121,7 +13675,7 @@ function zeroBoundSemantic(method) {
|
|
|
13121
13675
|
|
|
13122
13676
|
// src/rules/no-in-operator-on-built-in-collections.ts
|
|
13123
13677
|
var import_utils79 = require("@typescript-eslint/utils");
|
|
13124
|
-
var
|
|
13678
|
+
var ts27 = __toESM(require("typescript"), 1);
|
|
13125
13679
|
|
|
13126
13680
|
// src/rules/_collection-property-fix.ts
|
|
13127
13681
|
var import_utils78 = require("@typescript-eslint/utils");
|
|
@@ -13221,7 +13775,7 @@ function isDefaultLibraryCollection(node, services) {
|
|
|
13221
13775
|
const checker = services.program.getTypeChecker();
|
|
13222
13776
|
const tsNode = services.esTreeNodeToTSNodeMap.get(node);
|
|
13223
13777
|
const type = checker.getTypeAtLocation(tsNode);
|
|
13224
|
-
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) {
|
|
13225
13779
|
return false;
|
|
13226
13780
|
}
|
|
13227
13781
|
return isDefaultLibraryCollectionSymbol(type.getSymbol(), services);
|
|
@@ -13232,7 +13786,7 @@ function isDefaultLibraryCollectionSymbol(symbol, services) {
|
|
|
13232
13786
|
return declarations.length > 0 && declarations.every(
|
|
13233
13787
|
(declaration) => services.program.isSourceFileDefaultLibrary(declaration.getSourceFile())
|
|
13234
13788
|
) && declarations.some(
|
|
13235
|
-
(declaration) =>
|
|
13789
|
+
(declaration) => ts27.isInterfaceDeclaration(declaration) && declaration.name.text === symbol.name
|
|
13236
13790
|
);
|
|
13237
13791
|
}
|
|
13238
13792
|
var no_in_operator_on_built_in_collections_default = createRule({
|
|
@@ -13543,7 +14097,7 @@ var no_redundant_optional_array_default_default = createRule({
|
|
|
13543
14097
|
|
|
13544
14098
|
// src/rules/interface-contract-members-private.ts
|
|
13545
14099
|
var import_utils83 = require("@typescript-eslint/utils");
|
|
13546
|
-
var
|
|
14100
|
+
var ts28 = __toESM(require("typescript"), 1);
|
|
13547
14101
|
|
|
13548
14102
|
// src/rules/_class-private.ts
|
|
13549
14103
|
var import_utils82 = require("@typescript-eslint/utils");
|
|
@@ -13713,15 +14267,15 @@ function candidate(member3) {
|
|
|
13713
14267
|
}
|
|
13714
14268
|
function interfaceNames(services, owner) {
|
|
13715
14269
|
const tsOwner = services.esTreeNodeToTSNodeMap.get(owner);
|
|
13716
|
-
if (!
|
|
13717
|
-
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) ?? [];
|
|
13718
14272
|
if (implemented.length === 0) return null;
|
|
13719
14273
|
const checker = services.program.getTypeChecker();
|
|
13720
14274
|
const names = /* @__PURE__ */ new Set();
|
|
13721
14275
|
for (const clause of implemented) {
|
|
13722
14276
|
for (const contract of clause.types) {
|
|
13723
14277
|
const type = checker.getTypeAtLocation(contract);
|
|
13724
|
-
if ((type.flags & (
|
|
14278
|
+
if ((type.flags & (ts28.TypeFlags.Any | ts28.TypeFlags.Unknown)) !== 0) return null;
|
|
13725
14279
|
for (const property of checker.getPropertiesOfType(type)) names.add(property.getName());
|
|
13726
14280
|
}
|
|
13727
14281
|
}
|
|
@@ -14882,7 +15436,7 @@ function tupleFields(helper) {
|
|
|
14882
15436
|
const values = [];
|
|
14883
15437
|
for (const [index, field] of tuple.elementTypes.entries()) {
|
|
14884
15438
|
const value = returned2.argument.elements[index];
|
|
14885
|
-
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))
|
|
14886
15440
|
return null;
|
|
14887
15441
|
labels.push(field.label);
|
|
14888
15442
|
types.push(field.elementType);
|
|
@@ -14890,7 +15444,7 @@ function tupleFields(helper) {
|
|
|
14890
15444
|
}
|
|
14891
15445
|
return { labels, types, values, returned: returned2.argument };
|
|
14892
15446
|
}
|
|
14893
|
-
function
|
|
15447
|
+
function primitiveValue3(type, value) {
|
|
14894
15448
|
switch (type.type) {
|
|
14895
15449
|
case import_utils91.AST_NODE_TYPES.TSStringKeyword:
|
|
14896
15450
|
return typeof value.value === "string";
|
|
@@ -20967,7 +21521,7 @@ function mayBeVirtual(options) {
|
|
|
20967
21521
|
|
|
20968
21522
|
// src/rules/no-zod-native-enum.ts
|
|
20969
21523
|
var import_utils122 = require("@typescript-eslint/utils");
|
|
20970
|
-
var
|
|
21524
|
+
var ts29 = __toESM(require("typescript"), 1);
|
|
20971
21525
|
var NO_ZOD_NATIVE_ENUM_DOCUMENTATION = {
|
|
20972
21526
|
summary: 'Disallow `z.nativeEnum()` (and `z.enum()` over a TypeScript enum); use `z.enum(["a", "b"])` with a string-literal union instead.',
|
|
20973
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.",
|
|
@@ -21076,7 +21630,7 @@ function resolvesToLocalEnum(node, scope) {
|
|
|
21076
21630
|
}
|
|
21077
21631
|
return false;
|
|
21078
21632
|
}
|
|
21079
|
-
var ENUM_SYMBOL_FLAGS =
|
|
21633
|
+
var ENUM_SYMBOL_FLAGS = ts29.SymbolFlags.RegularEnum | ts29.SymbolFlags.ConstEnum | ts29.SymbolFlags.Enum;
|
|
21080
21634
|
function resolvesToImportedEnum(node, services) {
|
|
21081
21635
|
const checker = services.program.getTypeChecker();
|
|
21082
21636
|
const tsNode = services.esTreeNodeToTSNodeMap.get(node);
|
|
@@ -21084,7 +21638,7 @@ function resolvesToImportedEnum(node, services) {
|
|
|
21084
21638
|
if (symbol === void 0) {
|
|
21085
21639
|
return false;
|
|
21086
21640
|
}
|
|
21087
|
-
if ((symbol.flags &
|
|
21641
|
+
if ((symbol.flags & ts29.SymbolFlags.Alias) !== 0) {
|
|
21088
21642
|
symbol = checker.getAliasedSymbol(symbol);
|
|
21089
21643
|
}
|
|
21090
21644
|
return (symbol.flags & ENUM_SYMBOL_FLAGS) !== 0;
|
|
@@ -24706,7 +25260,7 @@ var OPERATIONAL_ROLES = /* @__PURE__ */ new Set([
|
|
|
24706
25260
|
"timeout",
|
|
24707
25261
|
"interval"
|
|
24708
25262
|
]);
|
|
24709
|
-
var
|
|
25263
|
+
var MAX_ALIAS_DEPTH2 = 16;
|
|
24710
25264
|
var PREFER_NOMINAL_ID_TYPES_DOCUMENTATION = {
|
|
24711
25265
|
defaultLevel: "error",
|
|
24712
25266
|
summary: "Distinguish identifier roles sharing primitive types at callable boundaries.",
|
|
@@ -24804,7 +25358,7 @@ function typeDefinitions(node, context) {
|
|
|
24804
25358
|
return [];
|
|
24805
25359
|
}
|
|
24806
25360
|
function rawCarrier(node, context, depth = 0) {
|
|
24807
|
-
if (node === void 0 || depth >=
|
|
25361
|
+
if (node === void 0 || depth >= MAX_ALIAS_DEPTH2) return void 0;
|
|
24808
25362
|
switch (node.type) {
|
|
24809
25363
|
case import_utils140.AST_NODE_TYPES.TSStringKeyword:
|
|
24810
25364
|
return "string";
|
|
@@ -26281,7 +26835,7 @@ var prefer_non_nullable_collection_default = createRule({
|
|
|
26281
26835
|
|
|
26282
26836
|
// src/rules/prefer-nullish-filter-predicate.ts
|
|
26283
26837
|
var import_utils148 = require("@typescript-eslint/utils");
|
|
26284
|
-
var
|
|
26838
|
+
var import_typescript26 = __toESM(require("typescript"), 1);
|
|
26285
26839
|
var PREFER_NULLISH_FILTER_PREDICATE_DOCUMENTATION = {
|
|
26286
26840
|
summary: "Prefer an explicit nullish predicate when `filter(Boolean)` removes only nullish values but does not narrow the result type.",
|
|
26287
26841
|
rationale: "An explicit nullish predicate preserves the same runtime elements while letting TypeScript remove `null` and `undefined` from the result.",
|
|
@@ -26344,23 +26898,23 @@ function isBuiltinArrayFilter(node, services) {
|
|
|
26344
26898
|
const symbol = checker.getSymbolAtLocation(property) ?? checker.getTypeAtLocation(services.esTreeNodeToTSNodeMap.get(node.object)).getProperty("filter");
|
|
26345
26899
|
return symbol?.declarations?.some((declaration) => {
|
|
26346
26900
|
const owner = declaration.parent;
|
|
26347
|
-
return
|
|
26901
|
+
return import_typescript26.default.isInterfaceDeclaration(owner) && (owner.name.text === "Array" || owner.name.text === "ReadonlyArray") && services.program.isSourceFileDefaultLibrary(owner.getSourceFile());
|
|
26348
26902
|
}) ?? false;
|
|
26349
26903
|
}
|
|
26350
26904
|
function arrayElementType(node, services) {
|
|
26351
26905
|
const checker = services.program.getTypeChecker();
|
|
26352
26906
|
const receiver = services.esTreeNodeToTSNodeMap.get(node);
|
|
26353
|
-
return checker.getIndexTypeOfType(checker.getTypeAtLocation(receiver),
|
|
26907
|
+
return checker.getIndexTypeOfType(checker.getTypeAtLocation(receiver), import_typescript26.default.IndexKind.Number) ?? null;
|
|
26354
26908
|
}
|
|
26355
|
-
var NULLISH_FLAGS =
|
|
26356
|
-
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;
|
|
26357
26911
|
function isNullishPlusTruthy(type, checker, falsyBrowserObject) {
|
|
26358
26912
|
const members = type.isUnion() ? type.types : [type];
|
|
26359
26913
|
let sawNullish = false;
|
|
26360
26914
|
for (const member3 of members) {
|
|
26361
26915
|
if ((member3.flags & NULLISH_FLAGS) !== 0) {
|
|
26362
26916
|
sawNullish = true;
|
|
26363
|
-
} else if ((member3.flags &
|
|
26917
|
+
} else if ((member3.flags & import_typescript26.default.TypeFlags.Never) === 0 && !isProvablyTruthy(member3, checker, falsyBrowserObject)) {
|
|
26364
26918
|
return false;
|
|
26365
26919
|
}
|
|
26366
26920
|
}
|
|
@@ -26368,7 +26922,7 @@ function isNullishPlusTruthy(type, checker, falsyBrowserObject) {
|
|
|
26368
26922
|
}
|
|
26369
26923
|
function isProvablyTruthy(type, checker, falsyBrowserObject) {
|
|
26370
26924
|
if ((type.flags & UNKNOWN_FLAGS) !== 0) return false;
|
|
26371
|
-
if ((type.flags &
|
|
26925
|
+
if ((type.flags & import_typescript26.default.TypeFlags.Object) !== 0) {
|
|
26372
26926
|
if (falsyBrowserObject !== null && checker.isTypeAssignableTo(falsyBrowserObject, type)) return false;
|
|
26373
26927
|
return ![
|
|
26374
26928
|
checker.getStringType(),
|
|
@@ -26377,18 +26931,18 @@ function isProvablyTruthy(type, checker, falsyBrowserObject) {
|
|
|
26377
26931
|
checker.getBooleanType()
|
|
26378
26932
|
].some((primitive) => checker.isTypeAssignableTo(primitive, type));
|
|
26379
26933
|
}
|
|
26380
|
-
if ((type.flags & (
|
|
26381
|
-
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) {
|
|
26382
26936
|
return type.intrinsicName === "true";
|
|
26383
26937
|
}
|
|
26384
|
-
if ((type.flags &
|
|
26938
|
+
if ((type.flags & import_typescript26.default.TypeFlags.StringLiteral) !== 0) {
|
|
26385
26939
|
return type.value.length > 0;
|
|
26386
26940
|
}
|
|
26387
|
-
if ((type.flags &
|
|
26941
|
+
if ((type.flags & import_typescript26.default.TypeFlags.NumberLiteral) !== 0) {
|
|
26388
26942
|
const value = type.value;
|
|
26389
26943
|
return value !== 0 && !Number.isNaN(value);
|
|
26390
26944
|
}
|
|
26391
|
-
if ((type.flags &
|
|
26945
|
+
if ((type.flags & import_typescript26.default.TypeFlags.BigIntLiteral) !== 0) {
|
|
26392
26946
|
return type.value.base10Value !== "0";
|
|
26393
26947
|
}
|
|
26394
26948
|
return false;
|
|
@@ -26444,7 +26998,7 @@ var prefer_nullish_filter_predicate_default = createRule({
|
|
|
26444
26998
|
if (services === null) return {};
|
|
26445
26999
|
const program = services.program;
|
|
26446
27000
|
const checker = program.getTypeChecker();
|
|
26447
|
-
const browserCollection = checker.resolveName("HTMLAllCollection", void 0,
|
|
27001
|
+
const browserCollection = checker.resolveName("HTMLAllCollection", void 0, import_typescript26.default.SymbolFlags.Type, false);
|
|
26448
27002
|
const falsyBrowserObject = browserCollection?.declarations?.some((declaration) => program.isSourceFileDefaultLibrary(declaration.getSourceFile())) === true ? checker.getDeclaredTypeOfSymbol(browserCollection) : null;
|
|
26449
27003
|
return {
|
|
26450
27004
|
CallExpression(node) {
|
|
@@ -26478,7 +27032,7 @@ var prefer_nullish_filter_predicate_default = createRule({
|
|
|
26478
27032
|
|
|
26479
27033
|
// src/rules/prefer-await-in-async-return.ts
|
|
26480
27034
|
var import_utils149 = require("@typescript-eslint/utils");
|
|
26481
|
-
var
|
|
27035
|
+
var ts31 = __toESM(require("typescript"), 1);
|
|
26482
27036
|
var PREFER_AWAIT_IN_ASYNC_RETURN_DOCUMENTATION = {
|
|
26483
27037
|
summary: "Prefer explicit `await` for proven Promise `.then` calls; the default scope checks direct async returns.",
|
|
26484
27038
|
rationale: "Promise callback chains mix explicit async control flow with nested callbacks, making sequencing and failure handling harder to read.",
|
|
@@ -26562,7 +27116,7 @@ function isProvenPromiseLike(node, services) {
|
|
|
26562
27116
|
return members.every((member3) => isBuiltInPromiseType(member3, services));
|
|
26563
27117
|
}
|
|
26564
27118
|
function isBuiltInPromiseType(type, services) {
|
|
26565
|
-
if ((type.flags & (
|
|
27119
|
+
if ((type.flags & (ts31.TypeFlags.Any | ts31.TypeFlags.Unknown | ts31.TypeFlags.Never)) !== 0) {
|
|
26566
27120
|
return false;
|
|
26567
27121
|
}
|
|
26568
27122
|
const thenSymbol = services.program.getTypeChecker().getPropertyOfType(type, "then");
|
|
@@ -26571,7 +27125,7 @@ function isBuiltInPromiseType(type, services) {
|
|
|
26571
27125
|
return declarations.every(
|
|
26572
27126
|
(declaration) => {
|
|
26573
27127
|
let owner = declaration.parent;
|
|
26574
|
-
while (owner !== void 0 && !
|
|
27128
|
+
while (owner !== void 0 && !ts31.isInterfaceDeclaration(owner)) {
|
|
26575
27129
|
owner = owner.parent;
|
|
26576
27130
|
}
|
|
26577
27131
|
return owner !== void 0 && (owner.name.text === "Promise" || owner.name.text === "PromiseLike") && services.program.isSourceFileDefaultLibrary(owner.getSourceFile());
|
|
@@ -27355,7 +27909,7 @@ var prefer_shared_zod_enum_default = createRule({
|
|
|
27355
27909
|
|
|
27356
27910
|
// src/rules/prefer-switch-for-repeated-equality.ts
|
|
27357
27911
|
var import_utils153 = require("@typescript-eslint/utils");
|
|
27358
|
-
var
|
|
27912
|
+
var import_typescript27 = __toESM(require("typescript"), 1);
|
|
27359
27913
|
var PREFER_SWITCH_FOR_REPEATED_EQUALITY_DOCUMENTATION = {
|
|
27360
27914
|
defaultLevel: "error",
|
|
27361
27915
|
summary: "Prefer switch over long if/else-if chains that compare one value for strict equality.",
|
|
@@ -27435,7 +27989,7 @@ function hasUnsafeSwitchControl(node) {
|
|
|
27435
27989
|
function hasOpenDiscriminant(node, services) {
|
|
27436
27990
|
if (services === null) return false;
|
|
27437
27991
|
const type = services.program.getTypeChecker().getTypeAtLocation(services.esTreeNodeToTSNodeMap.get(node));
|
|
27438
|
-
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;
|
|
27439
27993
|
return (type.isUnion() ? type.types : [type]).some((part) => (part.flags & openFlags) !== 0);
|
|
27440
27994
|
}
|
|
27441
27995
|
var prefer_switch_for_repeated_equality_default = createRule({
|
|
@@ -29629,14 +30183,14 @@ var named_child_schema_type_default = createRule({
|
|
|
29629
30183
|
|
|
29630
30184
|
// src/rules/prefer-zod-parse-output-type.ts
|
|
29631
30185
|
var import_utils160 = require("@typescript-eslint/utils");
|
|
29632
|
-
var
|
|
30186
|
+
var import_typescript30 = __toESM(require("typescript"), 1);
|
|
29633
30187
|
|
|
29634
30188
|
// src/rules/_equivalent-zod-output-contracts.ts
|
|
29635
30189
|
var import_ts_api_utils5 = require("ts-api-utils");
|
|
29636
|
-
var
|
|
30190
|
+
var import_typescript28 = __toESM(require("typescript"), 1);
|
|
29637
30191
|
var MAX_CONTRACT_PAIRS = 128;
|
|
29638
30192
|
var MAX_UNION_MEMBERS = 16;
|
|
29639
|
-
var UNSAFE_TYPES =
|
|
30193
|
+
var UNSAFE_TYPES = import_typescript28.default.TypeFlags.Any | import_typescript28.default.TypeFlags.Unknown | import_typescript28.default.TypeFlags.Never;
|
|
29640
30194
|
function equivalentZodOutputContracts(checker, parsed, contract) {
|
|
29641
30195
|
const comparison2 = { checker, pending: [[parsed, contract]], seen: /* @__PURE__ */ new Map(), pairs: 0 };
|
|
29642
30196
|
while (comparison2.pending.length > 0) {
|
|
@@ -29696,8 +30250,8 @@ function equivalentContainers(comparison2, left, right) {
|
|
|
29696
30250
|
const rightTuple = (0, import_ts_api_utils5.isTupleTypeReference)(right);
|
|
29697
30251
|
if (leftTuple !== rightTuple) return false;
|
|
29698
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;
|
|
29699
|
-
const leftIndex = comparison2.checker.getIndexInfoOfType(left,
|
|
29700
|
-
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);
|
|
29701
30255
|
if (leftIndex?.isReadonly !== rightIndex?.isReadonly) return false;
|
|
29702
30256
|
const leftArguments = comparison2.checker.getTypeArguments(left);
|
|
29703
30257
|
const rightArguments = comparison2.checker.getTypeArguments(right);
|
|
@@ -29707,10 +30261,10 @@ function equivalentContainers(comparison2, left, right) {
|
|
|
29707
30261
|
});
|
|
29708
30262
|
}
|
|
29709
30263
|
function hasClassDeclaration(type) {
|
|
29710
|
-
return type.getSymbol()?.getDeclarations()?.some(
|
|
30264
|
+
return type.getSymbol()?.getDeclarations()?.some(import_typescript28.default.isClassDeclaration) === true || type.isIntersection() && type.types.some(hasClassDeclaration);
|
|
29711
30265
|
}
|
|
29712
30266
|
function objectLike(type) {
|
|
29713
|
-
return (type.flags &
|
|
30267
|
+
return (type.flags & import_typescript28.default.TypeFlags.Object) !== 0 || type.isIntersection();
|
|
29714
30268
|
}
|
|
29715
30269
|
function equivalentProperties(comparison2, left, right) {
|
|
29716
30270
|
const { checker } = comparison2;
|
|
@@ -29725,12 +30279,12 @@ function equivalentProperties(comparison2, left, right) {
|
|
|
29725
30279
|
return true;
|
|
29726
30280
|
}
|
|
29727
30281
|
function opaqueObject(checker, type) {
|
|
29728
|
-
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;
|
|
29729
30283
|
}
|
|
29730
30284
|
function equivalentProperty(comparison2, left, right, property, other) {
|
|
29731
30285
|
const { checker } = comparison2;
|
|
29732
30286
|
if (opaqueProperty(property) || opaqueProperty(other)) return false;
|
|
29733
|
-
if ((property.flags &
|
|
30287
|
+
if ((property.flags & import_typescript28.default.SymbolFlags.Optional) !== (other.flags & import_typescript28.default.SymbolFlags.Optional)) return false;
|
|
29734
30288
|
if ((0, import_ts_api_utils5.isPropertyReadonlyInType)(left, property.getEscapedName(), checker) !== (0, import_ts_api_utils5.isPropertyReadonlyInType)(right, other.getEscapedName(), checker)) return false;
|
|
29735
30289
|
const declaration = property.valueDeclaration ?? property.getDeclarations()?.[0];
|
|
29736
30290
|
const otherDeclaration = other.valueDeclaration ?? other.getDeclarations()?.[0];
|
|
@@ -29741,39 +30295,39 @@ function equivalentProperty(comparison2, left, right, property, other) {
|
|
|
29741
30295
|
);
|
|
29742
30296
|
}
|
|
29743
30297
|
function opaqueProperty(property) {
|
|
29744
|
-
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;
|
|
29745
30299
|
}
|
|
29746
30300
|
|
|
29747
30301
|
// src/rules/_has-authoritative-output-contract.ts
|
|
29748
|
-
var
|
|
30302
|
+
var import_typescript29 = __toESM(require("typescript"), 1);
|
|
29749
30303
|
function hasAuthoritativeOutputContract(checker, output, contract) {
|
|
29750
30304
|
const callable = enclosingCallable(output);
|
|
29751
30305
|
if (callable === void 0) return false;
|
|
29752
30306
|
const authority = { checker, contract };
|
|
29753
|
-
if (
|
|
30307
|
+
if (import_typescript29.default.isMethodDeclaration(callable) || import_typescript29.default.isGetAccessorDeclaration(callable)) return memberContract2(authority, callable);
|
|
29754
30308
|
const binding3 = callable.parent;
|
|
29755
|
-
if ((
|
|
29756
|
-
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;
|
|
29757
30311
|
const contextual = checker.getContextualType(callable);
|
|
29758
30312
|
return contextual !== void 0 && callableContract(authority, contextual, callable);
|
|
29759
30313
|
}
|
|
29760
30314
|
function enclosingCallable(output) {
|
|
29761
30315
|
for (let current = output; current !== void 0; current = current.parent) {
|
|
29762
|
-
if (
|
|
29763
|
-
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;
|
|
29764
30318
|
}
|
|
29765
30319
|
return void 0;
|
|
29766
30320
|
}
|
|
29767
30321
|
function memberContract2(authority, member3) {
|
|
29768
|
-
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;
|
|
29769
30323
|
const owner = member3.parent;
|
|
29770
30324
|
const name = authority.checker.getSymbolAtLocation(member3.name)?.getName();
|
|
29771
30325
|
if (name === void 0) return false;
|
|
29772
|
-
if (
|
|
30326
|
+
if (import_typescript29.default.isObjectLiteralExpression(owner)) {
|
|
29773
30327
|
const contextual = authority.checker.getContextualType(owner);
|
|
29774
30328
|
return contextual !== void 0 && propertyContract(authority, contextual, name, member3, member3);
|
|
29775
30329
|
}
|
|
29776
|
-
if (!
|
|
30330
|
+
if (!import_typescript29.default.isClassDeclaration(owner) && !import_typescript29.default.isClassExpression(owner)) return false;
|
|
29777
30331
|
for (const clause of owner.heritageClauses ?? []) {
|
|
29778
30332
|
for (const heritage of clause.types) {
|
|
29779
30333
|
if (propertyContract(authority, authority.checker.getTypeAtLocation(heritage), name, member3)) return true;
|
|
@@ -29785,9 +30339,9 @@ function propertyContract(authority, type, name, member3, contextual) {
|
|
|
29785
30339
|
const property = authority.checker.getPropertyOfType(type, name);
|
|
29786
30340
|
if (property === void 0) return false;
|
|
29787
30341
|
const declared = authority.checker.getTypeOfSymbolAtLocation(property, member3);
|
|
29788
|
-
if (!
|
|
30342
|
+
if (!import_typescript29.default.isGetAccessorDeclaration(member3)) return callableContract(authority, declared, contextual);
|
|
29789
30343
|
return property.getDeclarations()?.some((declaration) => {
|
|
29790
|
-
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;
|
|
29791
30345
|
return returnsContract(authority, contextual === void 0 ? declared : authority.checker.getTypeAtLocation(declaration.type));
|
|
29792
30346
|
}) === true;
|
|
29793
30347
|
}
|
|
@@ -30126,12 +30680,12 @@ function handWrittenObjectDeclaration(symbol) {
|
|
|
30126
30680
|
const [declaration] = declarations;
|
|
30127
30681
|
if (declarations.length !== 1 || declaration === void 0) return null;
|
|
30128
30682
|
const plainMembers = (members) => members.length > 0 && members.every(
|
|
30129
|
-
(member3) =>
|
|
30683
|
+
(member3) => import_typescript30.default.isPropertySignature(member3) && member3.type !== void 0 && member3.modifiers?.some((modifier) => modifier.kind === import_typescript30.default.SyntaxKind.ReadonlyKeyword) !== true
|
|
30130
30684
|
);
|
|
30131
|
-
if (
|
|
30685
|
+
if (import_typescript30.default.isInterfaceDeclaration(declaration) && declaration.typeParameters === void 0 && declaration.heritageClauses === void 0 && plainMembers(declaration.members)) {
|
|
30132
30686
|
return declaration;
|
|
30133
30687
|
}
|
|
30134
|
-
if (
|
|
30688
|
+
if (import_typescript30.default.isTypeAliasDeclaration(declaration) && declaration.typeParameters === void 0 && import_typescript30.default.isTypeLiteralNode(declaration.type) && plainMembers(declaration.type.members)) {
|
|
30135
30689
|
return declaration;
|
|
30136
30690
|
}
|
|
30137
30691
|
return null;
|
|
@@ -30211,7 +30765,7 @@ var prefer_zod_parse_output_type_default = createRule({
|
|
|
30211
30765
|
|
|
30212
30766
|
// src/rules/require-assert-never.ts
|
|
30213
30767
|
var import_utils162 = require("@typescript-eslint/utils");
|
|
30214
|
-
var
|
|
30768
|
+
var import_typescript31 = __toESM(require("typescript"), 1);
|
|
30215
30769
|
|
|
30216
30770
|
// src/rules/_empty-assertion-fix.ts
|
|
30217
30771
|
var import_utils161 = require("@typescript-eslint/utils");
|
|
@@ -30388,7 +30942,7 @@ function isExhaustiveFiniteSwitch(node, services) {
|
|
|
30388
30942
|
const constituents = discriminantType.isUnion() ? discriminantType.types : [discriminantType];
|
|
30389
30943
|
if (!discriminantType.isUnion() || constituents.length < 2) return false;
|
|
30390
30944
|
if (constituents.every(
|
|
30391
|
-
(constituent) => (constituent.flags &
|
|
30945
|
+
(constituent) => (constituent.flags & import_typescript31.default.TypeFlags.BooleanLiteral) !== 0
|
|
30392
30946
|
)) {
|
|
30393
30947
|
return false;
|
|
30394
30948
|
}
|
|
@@ -30410,7 +30964,7 @@ function isExhaustiveFiniteSwitch(node, services) {
|
|
|
30410
30964
|
return [...expected].every((key) => handled.has(key));
|
|
30411
30965
|
}
|
|
30412
30966
|
function finiteTypeKey(type, checker) {
|
|
30413
|
-
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;
|
|
30414
30968
|
return (type.flags & finiteFlags) !== 0 ? checker.typeToString(type) : null;
|
|
30415
30969
|
}
|
|
30416
30970
|
var require_assert_never_default = createRule({
|