@sarj/eslint-plugin 18.0.4 → 18.0.5
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 +923 -898
- package/dist/index.js +841 -816
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -859,11 +859,11 @@ function sameShape(checker, input, output, location) {
|
|
|
859
859
|
}
|
|
860
860
|
|
|
861
861
|
// src/rules/prefer-server-data-preparation.ts
|
|
862
|
-
var
|
|
863
|
-
var
|
|
862
|
+
var import_utils10 = require("@typescript-eslint/utils");
|
|
863
|
+
var import_typescript7 = __toESM(require("typescript"), 1);
|
|
864
864
|
|
|
865
865
|
// src/rules/_react-prop-bindings.ts
|
|
866
|
-
var
|
|
866
|
+
var import_utils9 = require("@typescript-eslint/utils");
|
|
867
867
|
|
|
868
868
|
// src/rules/_import-specifier-name.ts
|
|
869
869
|
var import_utils6 = require("@typescript-eslint/utils");
|
|
@@ -871,6 +871,206 @@ function importSpecifierName(node) {
|
|
|
871
871
|
return node.imported.type === import_utils6.AST_NODE_TYPES.Identifier ? node.imported.name : node.imported.value;
|
|
872
872
|
}
|
|
873
873
|
|
|
874
|
+
// src/rules/_private-scalar-consumer.ts
|
|
875
|
+
var import_utils8 = require("@typescript-eslint/utils");
|
|
876
|
+
var import_typescript6 = __toESM(require("typescript"), 1);
|
|
877
|
+
|
|
878
|
+
// src/rules/_scalar-parameter-view.ts
|
|
879
|
+
var import_typescript5 = __toESM(require("typescript"), 1);
|
|
880
|
+
|
|
881
|
+
// src/rules/_checked-native-source.ts
|
|
882
|
+
var import_typescript3 = __toESM(require("typescript"), 1);
|
|
883
|
+
var CHECKED = /* @__PURE__ */ new WeakMap();
|
|
884
|
+
var SINGLE_LINE_DIRECTIVE = /^\/\/\/?\s*@(?:ts-expect-error|ts-ignore)/u;
|
|
885
|
+
var MULTI_LINE_DIRECTIVE = /^[/*]*\s*@(?:ts-expect-error|ts-ignore)/u;
|
|
886
|
+
var SINGLE_LINE_PRAGMA = /^\/\/\/?\s*@([^\s:]+)(?:(?:[^\S\r\n]|:).*)?$/mu;
|
|
887
|
+
function currentNativeSource(sourceCode, services) {
|
|
888
|
+
const source = services.esTreeNodeToTSNodeMap.get(sourceCode.ast);
|
|
889
|
+
return import_typescript3.default.isSourceFile(source) && services.program.getSourceFile(source.fileName) === source && source.text === sourceCode.text ? source : null;
|
|
890
|
+
}
|
|
891
|
+
function checkedNativeSource(program, source) {
|
|
892
|
+
let files = CHECKED.get(program);
|
|
893
|
+
if (!files) {
|
|
894
|
+
files = /* @__PURE__ */ new WeakMap();
|
|
895
|
+
CHECKED.set(program, files);
|
|
896
|
+
}
|
|
897
|
+
const known2 = files.get(source);
|
|
898
|
+
if (known2 !== void 0) return known2;
|
|
899
|
+
const available = !program.getCompilerOptions().noCheck && !source.isDeclarationFile && (source.flags & (import_typescript3.default.NodeFlags.JavaScriptFile | import_typescript3.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_typescript3.default.DiagnosticCategory.Error && diagnostic.file === source) && !checkingSuppressed(source) && !program.getSemanticDiagnostics(source).some((diagnostic) => diagnostic.category === import_typescript3.default.DiagnosticCategory.Error && diagnostic.file === source);
|
|
900
|
+
files.set(source, available);
|
|
901
|
+
return available;
|
|
902
|
+
}
|
|
903
|
+
function checkingSuppressed(source) {
|
|
904
|
+
if (!/@ts-/iu.test(source.text)) return false;
|
|
905
|
+
if (import_typescript3.default.getLeadingCommentRanges(source.text, 0)?.some((comment) => comment.kind === import_typescript3.default.SyntaxKind.SingleLineCommentTrivia && SINGLE_LINE_PRAGMA.exec(source.text.slice(comment.pos, comment.end))?.[1]?.toLowerCase() === "ts-nocheck")) return true;
|
|
906
|
+
const pending = [source];
|
|
907
|
+
while (pending.length) {
|
|
908
|
+
const node = pending.pop();
|
|
909
|
+
if (!node || import_typescript3.default.isJsxText(node) || import_typescript3.default.isJSDoc(node) || (node.flags & import_typescript3.default.NodeFlags.JSDoc) !== 0) continue;
|
|
910
|
+
if (!import_typescript3.default.isToken(node)) {
|
|
911
|
+
for (const child of node.getChildren(source)) pending.push(child);
|
|
912
|
+
continue;
|
|
913
|
+
}
|
|
914
|
+
if (tokenTriviaSuppressesChecking(node, source)) return true;
|
|
915
|
+
}
|
|
916
|
+
return false;
|
|
917
|
+
}
|
|
918
|
+
function tokenTriviaSuppressesChecking(node, source) {
|
|
919
|
+
const start = node.getStart(source);
|
|
920
|
+
for (const comment of [...import_typescript3.default.getLeadingCommentRanges(source.text, node.pos) ?? [], ...import_typescript3.default.getTrailingCommentRanges(source.text, node.pos) ?? []]) {
|
|
921
|
+
if (comment.pos < node.pos || comment.end > start) continue;
|
|
922
|
+
if (commentSuppressesChecking(source.text.slice(comment.pos, comment.end), comment.kind)) return true;
|
|
923
|
+
}
|
|
924
|
+
return false;
|
|
925
|
+
}
|
|
926
|
+
function commentSuppressesChecking(text, kind) {
|
|
927
|
+
if (kind === import_typescript3.default.SyntaxKind.SingleLineCommentTrivia) return SINGLE_LINE_DIRECTIVE.test(text);
|
|
928
|
+
let lastLine = text.length;
|
|
929
|
+
while (lastLine > 0 && !import_typescript3.default.isLineBreak(text.charCodeAt(lastLine - 1))) lastLine--;
|
|
930
|
+
return MULTI_LINE_DIRECTIVE.test(text.slice(lastLine).trimStart());
|
|
931
|
+
}
|
|
932
|
+
|
|
933
|
+
// src/rules/_native-const-value.ts
|
|
934
|
+
var import_typescript4 = __toESM(require("typescript"), 1);
|
|
935
|
+
function constInitializer(declaration) {
|
|
936
|
+
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;
|
|
937
|
+
let initializer = declaration.initializer;
|
|
938
|
+
while (initializer && import_typescript4.default.isParenthesizedExpression(initializer)) initializer = initializer.expression;
|
|
939
|
+
return initializer;
|
|
940
|
+
}
|
|
941
|
+
function unassertedValue(node) {
|
|
942
|
+
let value = node;
|
|
943
|
+
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;
|
|
944
|
+
return value;
|
|
945
|
+
}
|
|
946
|
+
|
|
947
|
+
// src/rules/_scalar-parameter-view.ts
|
|
948
|
+
var SCALAR_OPERATORS = /* @__PURE__ */ new Set([
|
|
949
|
+
import_typescript5.default.SyntaxKind.PlusToken,
|
|
950
|
+
import_typescript5.default.SyntaxKind.MinusToken,
|
|
951
|
+
import_typescript5.default.SyntaxKind.AsteriskToken,
|
|
952
|
+
import_typescript5.default.SyntaxKind.SlashToken,
|
|
953
|
+
import_typescript5.default.SyntaxKind.PercentToken,
|
|
954
|
+
import_typescript5.default.SyntaxKind.AsteriskAsteriskToken,
|
|
955
|
+
import_typescript5.default.SyntaxKind.LessThanToken,
|
|
956
|
+
import_typescript5.default.SyntaxKind.LessThanEqualsToken,
|
|
957
|
+
import_typescript5.default.SyntaxKind.GreaterThanToken,
|
|
958
|
+
import_typescript5.default.SyntaxKind.GreaterThanEqualsToken,
|
|
959
|
+
import_typescript5.default.SyntaxKind.EqualsEqualsEqualsToken,
|
|
960
|
+
import_typescript5.default.SyntaxKind.ExclamationEqualsEqualsToken,
|
|
961
|
+
import_typescript5.default.SyntaxKind.EqualsEqualsToken,
|
|
962
|
+
import_typescript5.default.SyntaxKind.ExclamationEqualsToken,
|
|
963
|
+
import_typescript5.default.SyntaxKind.AmpersandAmpersandToken,
|
|
964
|
+
import_typescript5.default.SyntaxKind.BarBarToken,
|
|
965
|
+
import_typescript5.default.SyntaxKind.QuestionQuestionToken
|
|
966
|
+
]);
|
|
967
|
+
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]);
|
|
968
|
+
var RETURNED_OPERANDS = /* @__PURE__ */ new Set([import_typescript5.default.SyntaxKind.AmpersandAmpersandToken, import_typescript5.default.SyntaxKind.BarBarToken, import_typescript5.default.SyntaxKind.QuestionQuestionToken]);
|
|
969
|
+
function scalarParameterView(parameter, body3, checker) {
|
|
970
|
+
return parameterReads(parameter, body3, checker, true);
|
|
971
|
+
}
|
|
972
|
+
function scalarParameterReads(parameter, body3, checker, callProgram, auxiliaries) {
|
|
973
|
+
return parameterReads(parameter, body3, checker, false, callProgram, auxiliaries);
|
|
974
|
+
}
|
|
975
|
+
function parameterReads(parameter, body3, checker, jsx, callProgram, auxiliaries) {
|
|
976
|
+
if (parameter.dotDotDotToken || parameter.initializer || import_typescript5.default.isArrayBindingPattern(parameter.name)) return null;
|
|
977
|
+
const root = import_typescript5.default.isIdentifier(parameter.name) ? checker.getSymbolAtLocation(parameter.name) : void 0;
|
|
978
|
+
if (import_typescript5.default.isIdentifier(parameter.name) && !root) return null;
|
|
979
|
+
const reads = /* @__PURE__ */ new Set();
|
|
980
|
+
const aliases = parameterAliases(parameter.name, checker, reads);
|
|
981
|
+
if (!aliases) return null;
|
|
982
|
+
const expression = returnedExpression(body3);
|
|
983
|
+
const view = { checker, props: checker.getTypeAtLocation(parameter), root, aliases, reads, callProgram, auxiliaries };
|
|
984
|
+
return expression && scalarView(expression, view, jsx) ? reads : null;
|
|
985
|
+
}
|
|
986
|
+
function scalarType(type, allowUndefined = true) {
|
|
987
|
+
if (type.isUnion()) return type.types.every((part) => scalarType(part, allowUndefined));
|
|
988
|
+
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;
|
|
989
|
+
return (type.flags & (allowUndefined ? flags | import_typescript5.default.TypeFlags.Undefined : flags)) !== 0;
|
|
990
|
+
}
|
|
991
|
+
function parameterAliases(name, checker, reads) {
|
|
992
|
+
const aliases = /* @__PURE__ */ new Map();
|
|
993
|
+
if (import_typescript5.default.isIdentifier(name)) return aliases;
|
|
994
|
+
for (const element of name.elements) {
|
|
995
|
+
const key = element.propertyName ?? element.name;
|
|
996
|
+
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;
|
|
997
|
+
const binding3 = checker.getSymbolAtLocation(element.name);
|
|
998
|
+
if (!binding3) return null;
|
|
999
|
+
reads.add(key.text);
|
|
1000
|
+
aliases.set(binding3, key.text);
|
|
1001
|
+
}
|
|
1002
|
+
return aliases;
|
|
1003
|
+
}
|
|
1004
|
+
function returnedExpression(body3) {
|
|
1005
|
+
if (!import_typescript5.default.isBlock(body3)) return body3;
|
|
1006
|
+
const statement = body3.statements.length === 1 ? body3.statements[0] : void 0;
|
|
1007
|
+
return statement && import_typescript5.default.isReturnStatement(statement) ? statement.expression : void 0;
|
|
1008
|
+
}
|
|
1009
|
+
function scalarView(node, view, jsx = false) {
|
|
1010
|
+
if (scalarLiteral(node)) return true;
|
|
1011
|
+
if (import_typescript5.default.isCallExpression(node)) return !jsx && scalarCall(node, view);
|
|
1012
|
+
if (import_typescript5.default.isJsxExpression(node)) return !node.dotDotDotToken && (!node.expression || scalarView(node.expression, view, jsx));
|
|
1013
|
+
if (import_typescript5.default.isIdentifier(node)) {
|
|
1014
|
+
const binding3 = view.checker.getSymbolAtLocation(node);
|
|
1015
|
+
if (binding3 && view.auxiliaries?.has(binding3)) return scalarType(view.checker.getTypeAtLocation(node));
|
|
1016
|
+
const key = binding3 && view.aliases.get(binding3);
|
|
1017
|
+
return key !== void 0 && readField(node, key, view);
|
|
1018
|
+
}
|
|
1019
|
+
if (import_typescript5.default.isPropertyAccessExpression(node) || import_typescript5.default.isElementAccessExpression(node)) return memberRead(node, view);
|
|
1020
|
+
return scalarOperation(node, view, jsx);
|
|
1021
|
+
}
|
|
1022
|
+
function scalarOperation(node, view, jsx) {
|
|
1023
|
+
if (import_typescript5.default.isParenthesizedExpression(node) || import_typescript5.default.isNonNullExpression(node)) return scalarView(node.expression, view, jsx);
|
|
1024
|
+
if (import_typescript5.default.isTypeOfExpression(node)) return scalarView(node.expression, view);
|
|
1025
|
+
if (import_typescript5.default.isConditionalExpression(node)) return scalarView(node.condition, view) && scalarView(node.whenTrue, view, jsx) && scalarView(node.whenFalse, view, jsx);
|
|
1026
|
+
if (import_typescript5.default.isBinaryExpression(node)) return binaryView(node, view, jsx);
|
|
1027
|
+
if (import_typescript5.default.isPrefixUnaryExpression(node)) return SCALAR_PREFIXES.has(node.operator) && scalarView(node.operand, view);
|
|
1028
|
+
if (import_typescript5.default.isTemplateExpression(node)) return node.templateSpans.every((span) => scalarView(span.expression, view));
|
|
1029
|
+
return jsx && jsxView(node, view);
|
|
1030
|
+
}
|
|
1031
|
+
function scalarCall(node, view) {
|
|
1032
|
+
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;
|
|
1033
|
+
const declarations = view.checker.getSymbolAtLocation(node.expression)?.declarations;
|
|
1034
|
+
const declaration = declarations?.length === 1 ? declarations[0] : void 0;
|
|
1035
|
+
const helper = declaration && localHelper(declaration);
|
|
1036
|
+
if (!helper || helper.getSourceFile() !== node.getSourceFile() || helper.typeParameters?.length || !helper.type || !node.arguments.every((argument) => scalarView(argument, view))) return false;
|
|
1037
|
+
if (!checkedNativeSource(view.callProgram, node.getSourceFile())) return false;
|
|
1038
|
+
const signature = view.checker.getResolvedSignature(node);
|
|
1039
|
+
return signature?.declaration === helper && !view.checker.getTypePredicateOfSignature(signature) && scalarType(view.checker.getTypeAtLocation(node));
|
|
1040
|
+
}
|
|
1041
|
+
function localHelper(node) {
|
|
1042
|
+
if (import_typescript5.default.isFunctionDeclaration(node)) return node.body && import_typescript5.default.isSourceFile(node.parent) ? node : void 0;
|
|
1043
|
+
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;
|
|
1044
|
+
return node.initializer;
|
|
1045
|
+
}
|
|
1046
|
+
function binaryView(node, view, jsx) {
|
|
1047
|
+
const returned2 = jsx && RETURNED_OPERANDS.has(node.operatorToken.kind);
|
|
1048
|
+
return SCALAR_OPERATORS.has(node.operatorToken.kind) && scalarView(node.left, view, returned2) && scalarView(node.right, view, returned2);
|
|
1049
|
+
}
|
|
1050
|
+
function scalarLiteral(node) {
|
|
1051
|
+
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;
|
|
1052
|
+
}
|
|
1053
|
+
function memberRead(node, view) {
|
|
1054
|
+
if (!view.root || !import_typescript5.default.isIdentifier(node.expression) || view.checker.getSymbolAtLocation(node.expression) !== view.root) return false;
|
|
1055
|
+
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;
|
|
1056
|
+
return key !== void 0 && readField(node, key, view);
|
|
1057
|
+
}
|
|
1058
|
+
function readField(node, key, view) {
|
|
1059
|
+
if (!view.checker.getPropertyOfType(view.props, key) || !scalarType(view.checker.getTypeAtLocation(node))) return false;
|
|
1060
|
+
view.reads.add(key);
|
|
1061
|
+
return true;
|
|
1062
|
+
}
|
|
1063
|
+
function jsxView(node, view) {
|
|
1064
|
+
if (import_typescript5.default.isJsxFragment(node)) return node.children.every((child) => scalarView(child, view, true));
|
|
1065
|
+
if (import_typescript5.default.isJsxElement(node)) return jsxView(node.openingElement, view) && node.children.every((child) => scalarView(child, view, true));
|
|
1066
|
+
if (!import_typescript5.default.isJsxOpeningElement(node) && !import_typescript5.default.isJsxSelfClosingElement(node)) return false;
|
|
1067
|
+
if (!import_typescript5.default.isIdentifier(node.tagName) || !/^[a-z][A-Za-z0-9]*$/u.test(node.tagName.text)) return false;
|
|
1068
|
+
return node.attributes.properties.every((attribute) => intrinsicAttribute(attribute, view));
|
|
1069
|
+
}
|
|
1070
|
+
function intrinsicAttribute(attribute, view) {
|
|
1071
|
+
return import_typescript5.default.isJsxAttribute(attribute) && import_typescript5.default.isIdentifier(attribute.name) && attribute.name.text !== "is" && (!attribute.initializer || scalarView(attribute.initializer, view));
|
|
1072
|
+
}
|
|
1073
|
+
|
|
874
1074
|
// src/rules/_stable-value-binding.ts
|
|
875
1075
|
var import_utils7 = require("@typescript-eslint/utils");
|
|
876
1076
|
function typeOnlyReference(reference) {
|
|
@@ -891,8 +1091,106 @@ function stableValueBinding(variable, acceptRead) {
|
|
|
891
1091
|
});
|
|
892
1092
|
}
|
|
893
1093
|
|
|
1094
|
+
// src/rules/_private-scalar-consumer.ts
|
|
1095
|
+
function directEval(node) {
|
|
1096
|
+
let callee = unwrapExpression(node.callee);
|
|
1097
|
+
while (callee.type === import_utils8.AST_NODE_TYPES.TSInstantiationExpression) callee = unwrapExpression(callee.expression);
|
|
1098
|
+
return callee.type === import_utils8.AST_NODE_TYPES.Identifier && callee.name === "eval";
|
|
1099
|
+
}
|
|
1100
|
+
function primitiveKeyword(node) {
|
|
1101
|
+
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);
|
|
1102
|
+
}
|
|
1103
|
+
function nullishPrimitiveUnion(node) {
|
|
1104
|
+
return node !== void 0 && import_typescript6.default.isUnionTypeNode(node) && node.types.length === 2 && node.types.some(primitiveKeyword) && node.types.some((part) => part.kind === import_typescript6.default.SyntaxKind.UndefinedKeyword || import_typescript6.default.isLiteralTypeNode(part) && part.literal.kind === import_typescript6.default.SyntaxKind.NullKeyword);
|
|
1105
|
+
}
|
|
1106
|
+
function consumerAnnotation(node, auxiliaryScalars = false) {
|
|
1107
|
+
if (node.params.length !== 1) {
|
|
1108
|
+
if (!auxiliaryScalars) return void 0;
|
|
1109
|
+
let annotation;
|
|
1110
|
+
for (const parameter2 of node.params) {
|
|
1111
|
+
if (parameter2.type !== import_utils8.AST_NODE_TYPES.Identifier && parameter2.type !== import_utils8.AST_NODE_TYPES.ObjectPattern) continue;
|
|
1112
|
+
const current = parameter2.typeAnnotation?.typeAnnotation;
|
|
1113
|
+
if (current?.type !== import_utils8.AST_NODE_TYPES.TSTypeLiteral) continue;
|
|
1114
|
+
if (annotation) return void 0;
|
|
1115
|
+
annotation = current;
|
|
1116
|
+
}
|
|
1117
|
+
return annotation;
|
|
1118
|
+
}
|
|
1119
|
+
const parameter = node.params[0];
|
|
1120
|
+
return parameter?.type === import_utils8.AST_NODE_TYPES.Identifier || parameter?.type === import_utils8.AST_NODE_TYPES.ObjectPattern ? parameter.typeAnnotation?.typeAnnotation : void 0;
|
|
1121
|
+
}
|
|
1122
|
+
function exportedSymbols(source, checker) {
|
|
1123
|
+
const symbol = checker.getSymbolAtLocation(source);
|
|
1124
|
+
return new Set(symbol ? checker.getExportsOfModule(symbol).map((entry) => (entry.flags & import_typescript6.default.SymbolFlags.Alias) !== 0 ? checker.getAliasedSymbol(entry) : entry) : []);
|
|
1125
|
+
}
|
|
1126
|
+
function privateScalarConsumer(node, sourceCode, services, exports2, options = {}) {
|
|
1127
|
+
const native = services.esTreeNodeToTSNodeMap.get(node);
|
|
1128
|
+
if (!import_typescript6.default.isFunctionDeclaration(native) && !import_typescript6.default.isArrowFunction(native) || !native.body) return null;
|
|
1129
|
+
let parameter = native.parameters[0];
|
|
1130
|
+
if (native.parameters.length !== 1) {
|
|
1131
|
+
const annotation = consumerAnnotation(node, options.auxiliaryScalars);
|
|
1132
|
+
const selected = annotation && services.esTreeNodeToTSNodeMap.get(annotation);
|
|
1133
|
+
parameter = native.parameters.find((entry) => entry.type === selected);
|
|
1134
|
+
}
|
|
1135
|
+
if (!parameter || !independentSignature(native, parameter, options.auxiliaryScalars === true)) return null;
|
|
1136
|
+
const checker = services.program.getTypeChecker();
|
|
1137
|
+
if (!import_typescript6.default.isExternalModule(native.getSourceFile()) || !services.program.getCompilerOptions().strict) return null;
|
|
1138
|
+
if (!privateDirectCallable(node, native, sourceCode, checker, exports2)) return null;
|
|
1139
|
+
const signature = checker.getSignatureFromDeclaration(native);
|
|
1140
|
+
if (!signature || signature.typeParameters?.length || checker.getTypePredicateOfSignature(signature)) return null;
|
|
1141
|
+
const expression = returnedExpression(native.body);
|
|
1142
|
+
if (!expression || !checker.isTypeAssignableTo(checker.getTypeAtLocation(expression), checker.getReturnTypeOfSignature(signature))) return null;
|
|
1143
|
+
const auxiliaries = native.parameters.length > 1 ? auxiliaryBindings(native, parameter, checker) : void 0;
|
|
1144
|
+
if (auxiliaries === null) return null;
|
|
1145
|
+
const reads = scalarParameterReads(parameter, native.body, checker, options.scalarCalls ? services.program : void 0, auxiliaries);
|
|
1146
|
+
return reads?.size ? { parameter, reads } : null;
|
|
1147
|
+
}
|
|
1148
|
+
function privateDirectCallable(node, native, sourceCode, checker, exports2) {
|
|
1149
|
+
const binding3 = callableBinding(node, sourceCode);
|
|
1150
|
+
if (!binding3 || binding3.defs.length !== 1) return false;
|
|
1151
|
+
const name = import_typescript6.default.isFunctionDeclaration(native) ? native.name : import_typescript6.default.isVariableDeclaration(native.parent) ? native.parent.name : void 0;
|
|
1152
|
+
const symbol = name && checker.getSymbolAtLocation(name);
|
|
1153
|
+
return symbol !== void 0 && symbol.declarations?.length === 1 && !exports2.has(symbol) && directCalls(binding3, native.parameters.length);
|
|
1154
|
+
}
|
|
1155
|
+
function independentSignature(native, selected, auxiliaryScalars) {
|
|
1156
|
+
if (!auxiliaryScalars && native.parameters.length !== 1 || native.typeParameters?.length || native.asteriskToken || native.modifiers?.length || !primitiveKeyword(native.type)) return false;
|
|
1157
|
+
return native.parameters.every((parameter) => parameter.type !== void 0 && !parameter.modifiers?.length && !parameter.questionToken && !parameter.initializer && !parameter.dotDotDotToken && (!import_typescript6.default.isIdentifier(parameter.name) || parameter.name.text !== "this") && (parameter === selected || import_typescript6.default.isIdentifier(parameter.name) && primitiveKeyword(parameter.type)));
|
|
1158
|
+
}
|
|
1159
|
+
function auxiliaryBindings(native, selected, checker) {
|
|
1160
|
+
const bindings = /* @__PURE__ */ new Set();
|
|
1161
|
+
for (const parameter of native.parameters) {
|
|
1162
|
+
if (parameter === selected) continue;
|
|
1163
|
+
const symbol = import_typescript6.default.isIdentifier(parameter.name) ? checker.getSymbolAtLocation(parameter.name) : void 0;
|
|
1164
|
+
if (!symbol || symbol.declarations?.length !== 1 || symbol.declarations[0] !== parameter || bindings.has(symbol)) return null;
|
|
1165
|
+
bindings.add(symbol);
|
|
1166
|
+
}
|
|
1167
|
+
return bindings;
|
|
1168
|
+
}
|
|
1169
|
+
function callableBinding(node, sourceCode) {
|
|
1170
|
+
if (node.type === import_utils8.AST_NODE_TYPES.FunctionDeclaration) {
|
|
1171
|
+
if (node.parent.type !== import_utils8.AST_NODE_TYPES.Program) return void 0;
|
|
1172
|
+
return sourceCode.getDeclaredVariables(node).find((variable) => variable.defs.some((definition) => definition.type === "FunctionName" && definition.node === node));
|
|
1173
|
+
}
|
|
1174
|
+
const declaration = node.parent;
|
|
1175
|
+
if (declaration.type !== import_utils8.AST_NODE_TYPES.VariableDeclarator || declaration.init !== node || declaration.id.type !== import_utils8.AST_NODE_TYPES.Identifier || declaration.id.typeAnnotation || declaration.parent.kind !== "const" || declaration.parent.parent.type !== import_utils8.AST_NODE_TYPES.Program) return void 0;
|
|
1176
|
+
return sourceCode.getDeclaredVariables(declaration).find((variable) => variable.defs.some((definition) => definition.type === "Variable" && definition.node === declaration));
|
|
1177
|
+
}
|
|
1178
|
+
function directCalls(binding3, arity) {
|
|
1179
|
+
let calls = 0;
|
|
1180
|
+
const stable2 = stableValueBinding(binding3, (reference) => {
|
|
1181
|
+
const identifier = reference.identifier;
|
|
1182
|
+
const call = identifier.parent;
|
|
1183
|
+
if (reference.isTypeReference || !reference.isReadOnly() || call.type !== import_utils8.AST_NODE_TYPES.CallExpression || call.callee !== identifier || call.optional || call.typeArguments || call.arguments.length !== arity || !call.arguments.every((argument) => argument.type === import_utils8.AST_NODE_TYPES.Identifier)) return false;
|
|
1184
|
+
calls += 1;
|
|
1185
|
+
return true;
|
|
1186
|
+
});
|
|
1187
|
+
return stable2 && calls > 0;
|
|
1188
|
+
}
|
|
1189
|
+
|
|
894
1190
|
// src/rules/_react-prop-bindings.ts
|
|
895
1191
|
var VIEWS = /* @__PURE__ */ new WeakMap();
|
|
1192
|
+
var DIRECT_EVAL = /* @__PURE__ */ new WeakMap();
|
|
1193
|
+
var REACT_IMPORTS = /* @__PURE__ */ new WeakMap();
|
|
896
1194
|
var PARAMETER_BINDINGS = /* @__PURE__ */ new WeakMap();
|
|
897
1195
|
function renderFunction(node) {
|
|
898
1196
|
let parent = node.parent;
|
|
@@ -923,13 +1221,14 @@ function firstParameterBindings(source, node) {
|
|
|
923
1221
|
return bindings;
|
|
924
1222
|
}
|
|
925
1223
|
function collectParameterBindings(source, node) {
|
|
1224
|
+
if (hasDirectEval(source)) return /* @__PURE__ */ new Set();
|
|
926
1225
|
const parameter = node.params[0];
|
|
927
1226
|
const identifiers = [];
|
|
928
|
-
if (parameter?.type ===
|
|
1227
|
+
if (parameter?.type === import_utils9.AST_NODE_TYPES.Identifier)
|
|
929
1228
|
identifiers.push(parameter);
|
|
930
|
-
if (parameter?.type ===
|
|
1229
|
+
if (parameter?.type === import_utils9.AST_NODE_TYPES.ObjectPattern) {
|
|
931
1230
|
for (const property of parameter.properties) {
|
|
932
|
-
if (property.type ===
|
|
1231
|
+
if (property.type === import_utils9.AST_NODE_TYPES.Property && !property.computed && property.value.type === import_utils9.AST_NODE_TYPES.Identifier)
|
|
933
1232
|
identifiers.push(property.value);
|
|
934
1233
|
}
|
|
935
1234
|
}
|
|
@@ -941,17 +1240,34 @@ function collectParameterBindings(source, node) {
|
|
|
941
1240
|
)
|
|
942
1241
|
);
|
|
943
1242
|
}
|
|
1243
|
+
function hasDirectEval(source) {
|
|
1244
|
+
let found = DIRECT_EVAL.get(source);
|
|
1245
|
+
if (found !== void 0) return found;
|
|
1246
|
+
found = source.scopeManager?.scopes.some(
|
|
1247
|
+
(scope) => scope.references.some(({ identifier }) => {
|
|
1248
|
+
if (identifier.type !== import_utils9.AST_NODE_TYPES.Identifier || identifier.name !== "eval")
|
|
1249
|
+
return false;
|
|
1250
|
+
let callee = outerExpression(identifier);
|
|
1251
|
+
while (callee.parent?.type === import_utils9.AST_NODE_TYPES.TSInstantiationExpression && callee.parent.expression === callee)
|
|
1252
|
+
callee = outerExpression(callee.parent);
|
|
1253
|
+
const call = callee.parent;
|
|
1254
|
+
return call?.type === import_utils9.AST_NODE_TYPES.CallExpression && call.callee === callee && !call.optional && directEval(call);
|
|
1255
|
+
})
|
|
1256
|
+
) ?? true;
|
|
1257
|
+
DIRECT_EVAL.set(source, found);
|
|
1258
|
+
return found;
|
|
1259
|
+
}
|
|
944
1260
|
function parameterPath(source, node, bindings) {
|
|
945
1261
|
let current = unwrapExpression(node);
|
|
946
1262
|
for (let depth = 0; depth < 64; depth += 1) {
|
|
947
|
-
if (current.type ===
|
|
948
|
-
const variable =
|
|
1263
|
+
if (current.type === import_utils9.AST_NODE_TYPES.Identifier) {
|
|
1264
|
+
const variable = import_utils9.ASTUtils.findVariable(
|
|
949
1265
|
source.getScope(current),
|
|
950
1266
|
current.name
|
|
951
1267
|
);
|
|
952
1268
|
return variable !== null && bindings.has(variable);
|
|
953
1269
|
}
|
|
954
|
-
if (current.type !==
|
|
1270
|
+
if (current.type !== import_utils9.AST_NODE_TYPES.MemberExpression || current.optional || current.computed && (current.property.type !== import_utils9.AST_NODE_TYPES.Literal || typeof current.property.value !== "string"))
|
|
955
1271
|
return false;
|
|
956
1272
|
current = unwrapExpression(current.object);
|
|
957
1273
|
}
|
|
@@ -961,25 +1277,30 @@ function reactHook(source, callee, hook) {
|
|
|
961
1277
|
callee = unwrapExpression(callee);
|
|
962
1278
|
let identifier;
|
|
963
1279
|
let namespace = false;
|
|
964
|
-
if (callee.type ===
|
|
965
|
-
else if (callee.type ===
|
|
1280
|
+
if (callee.type === import_utils9.AST_NODE_TYPES.Identifier) identifier = callee;
|
|
1281
|
+
else if (callee.type === import_utils9.AST_NODE_TYPES.MemberExpression && !callee.optional && import_utils9.ASTUtils.getPropertyName(callee) === hook && callee.object.type === import_utils9.AST_NODE_TYPES.Identifier) {
|
|
966
1282
|
identifier = callee.object;
|
|
967
1283
|
namespace = true;
|
|
968
1284
|
} else return false;
|
|
969
|
-
const variable =
|
|
1285
|
+
const variable = import_utils9.ASTUtils.findVariable(
|
|
970
1286
|
source.getScope(identifier),
|
|
971
1287
|
identifier.name
|
|
972
1288
|
);
|
|
973
|
-
if (variable === null
|
|
974
|
-
|
|
1289
|
+
if (variable === null) return false;
|
|
1290
|
+
const specifier = reactImportSpecifier(variable);
|
|
1291
|
+
if (specifier === null) return false;
|
|
1292
|
+
return namespace ? specifier.type === import_utils9.AST_NODE_TYPES.ImportDefaultSpecifier || specifier.type === import_utils9.AST_NODE_TYPES.ImportNamespaceSpecifier : specifier.type === import_utils9.AST_NODE_TYPES.ImportSpecifier && specifier.importKind !== "type" && importSpecifierName(specifier) === hook;
|
|
1293
|
+
}
|
|
1294
|
+
function reactImportSpecifier(variable) {
|
|
1295
|
+
let specifier = REACT_IMPORTS.get(variable);
|
|
1296
|
+
if (specifier !== void 0) return specifier;
|
|
975
1297
|
const definition = variable.defs[0];
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
return namespace ? specifier.type === import_utils8.AST_NODE_TYPES.ImportDefaultSpecifier || specifier.type === import_utils8.AST_NODE_TYPES.ImportNamespaceSpecifier : specifier.type === import_utils8.AST_NODE_TYPES.ImportSpecifier && specifier.importKind !== "type" && importSpecifierName(specifier) === hook;
|
|
1298
|
+
specifier = variable.defs.length === 1 && definition?.type === "ImportBinding" && definition.parent.type === import_utils9.AST_NODE_TYPES.ImportDeclaration && definition.parent.source.value === "react" && definition.parent.importKind !== "type" && stableValueBinding(variable) ? definition.node : null;
|
|
1299
|
+
REACT_IMPORTS.set(variable, specifier);
|
|
1300
|
+
return specifier;
|
|
980
1301
|
}
|
|
981
1302
|
function containsView(node) {
|
|
982
|
-
if (node.type ===
|
|
1303
|
+
if (node.type === import_utils9.AST_NODE_TYPES.JSXElement || node.type === import_utils9.AST_NODE_TYPES.JSXFragment)
|
|
983
1304
|
return true;
|
|
984
1305
|
if (isFunction(node)) return false;
|
|
985
1306
|
return forEachOwnAstChild(
|
|
@@ -989,7 +1310,7 @@ function containsView(node) {
|
|
|
989
1310
|
);
|
|
990
1311
|
}
|
|
991
1312
|
function isFunction(node) {
|
|
992
|
-
return node.type ===
|
|
1313
|
+
return node.type === import_utils9.AST_NODE_TYPES.ArrowFunctionExpression || node.type === import_utils9.AST_NODE_TYPES.FunctionDeclaration || node.type === import_utils9.AST_NODE_TYPES.FunctionExpression;
|
|
993
1314
|
}
|
|
994
1315
|
|
|
995
1316
|
// src/rules/prefer-server-data-preparation.ts
|
|
@@ -1030,7 +1351,7 @@ var PREFER_SERVER_DATA_PREPARATION_DOCUMENTATION = {
|
|
|
1030
1351
|
limitations: [
|
|
1031
1352
|
"Advisory only. Local syntax cannot establish whether a caller is a Server Component, whether props change interactively or whether server preparation reduces the total cost. This rule is a review lead, never proof that code can be moved to the server. No automatic fix is provided.",
|
|
1032
1353
|
"Requires an explicit use client directive and parser-owned TypeScript services resolving map/filter/flatMap to the standard Array or ReadonlyArray library signature. The receiver beneath erased wrappers must itself have an Array, ReadonlyArray or tuple type after nullish narrowing; casts from opaque or custom collections do not establish this. Subclass and structural collection types outside those native array types are excluded. The containing view must have an independent React useState/useReducer call or a native callable type on an intrinsic DOM onClick/onChange/onInput/onSubmit handler. Nullish, noncallable and opaque handler types do not establish interaction. Noninteractive boundaries remain owned by no-unnecessary-use-client; custom hooks and indirect client requirements are unsupported.",
|
|
1033
|
-
"Every runtime reference to the source parameter binding must be a supported native data projection or a field-only JSX display loop. Inputs also needed for editing, whole-record forwarding, lookup, mutation, other fields or opaque helpers are excluded. Only direct first-parameter paths and synchronous single-expression callbacks are supported. Whole-row identity maps and constant maps are excluded; supported projections must read a fixed input field.",
|
|
1354
|
+
"Every runtime reference to the source parameter binding must be a supported native data projection or a field-only JSX display loop. Inputs also needed for editing, whole-record forwarding, lookup, mutation, other fields or opaque helpers are excluded. Files containing direct eval are excluded because it can observe or change lexical bindings; indirect eval and properties named eval do not establish lexical access. Only direct first-parameter paths and synchronous single-expression callbacks are supported. Whole-row identity maps and constant maps are excluded; supported projections must read a fixed input field.",
|
|
1034
1355
|
"JSX-rendering callbacks are never reported as preparation findings. Callback calls, captured values, destructuring defaults/rest/nesting, async callbacks, event handlers, effects, memo callbacks, opaque helpers, dynamic/optional paths, custom collection signatures, missing type services, generated source and tests are excluded. First-parameter provenance is syntactic; annotations cannot prove absence of runtime getters or patched array methods. Analysis does not claim callback purity or preserve semantics of a hypothetical move.",
|
|
1035
1356
|
"Reports the direct source projection once; chained operations with a call receiver are not independently reported. A static subprojection may still be prepared by its producer while a union with pending local edits remains in the client."
|
|
1036
1357
|
],
|
|
@@ -1087,7 +1408,7 @@ var prefer_server_data_preparation_default = createRule({
|
|
|
1087
1408
|
};
|
|
1088
1409
|
const nativeArray = (node) => {
|
|
1089
1410
|
const callee = unwrapExpression(node.callee);
|
|
1090
|
-
if (callee.type !==
|
|
1411
|
+
if (callee.type !== import_utils10.AST_NODE_TYPES.MemberExpression) return false;
|
|
1091
1412
|
const receiver = checker.getNonNullableType(
|
|
1092
1413
|
checker.getTypeAtLocation(
|
|
1093
1414
|
services.esTreeNodeToTSNodeMap.get(unwrapExpression(callee.object))
|
|
@@ -1103,15 +1424,15 @@ var prefer_server_data_preparation_default = createRule({
|
|
|
1103
1424
|
)?.declaration;
|
|
1104
1425
|
return declaration !== void 0 && services.program.isSourceFileDefaultLibrary(
|
|
1105
1426
|
declaration.getSourceFile()
|
|
1106
|
-
) &&
|
|
1427
|
+
) && import_typescript7.default.isInterfaceDeclaration(declaration.parent) && ["Array", "ReadonlyArray"].includes(declaration.parent.name.text);
|
|
1107
1428
|
};
|
|
1108
1429
|
return {
|
|
1109
1430
|
CallExpression(node) {
|
|
1110
1431
|
const callee = unwrapExpression(node.callee);
|
|
1111
|
-
if (node.optional || callee.type !==
|
|
1432
|
+
if (node.optional || callee.type !== import_utils10.AST_NODE_TYPES.MemberExpression || callee.optional || node.arguments.length !== 1 || !METHODS.has(import_utils10.ASTUtils.getPropertyName(callee) ?? ""))
|
|
1112
1433
|
return;
|
|
1113
1434
|
const callback = node.arguments[0];
|
|
1114
|
-
if (callback?.type !==
|
|
1435
|
+
if (callback?.type !== import_utils10.AST_NODE_TYPES.ArrowFunctionExpression && callback?.type !== import_utils10.AST_NODE_TYPES.FunctionExpression)
|
|
1115
1436
|
return;
|
|
1116
1437
|
const component = renderFunction(node);
|
|
1117
1438
|
if (component === null || !parameterPath(
|
|
@@ -1143,7 +1464,7 @@ var prefer_server_data_preparation_default = createRule({
|
|
|
1143
1464
|
});
|
|
1144
1465
|
function clientDirective(program) {
|
|
1145
1466
|
for (const statement of program.body) {
|
|
1146
|
-
if (statement.type !==
|
|
1467
|
+
if (statement.type !== import_utils10.AST_NODE_TYPES.ExpressionStatement || statement.directive === void 0)
|
|
1147
1468
|
return false;
|
|
1148
1469
|
if (statement.directive === "use client") return true;
|
|
1149
1470
|
}
|
|
@@ -1153,16 +1474,16 @@ function projection(source, callback, mode = "data") {
|
|
|
1153
1474
|
if (callback.async || callback.generator || callback.params.length !== 1)
|
|
1154
1475
|
return false;
|
|
1155
1476
|
const parameter = callback.params[0];
|
|
1156
|
-
if (parameter?.type ===
|
|
1157
|
-
(property) => property.type !==
|
|
1477
|
+
if (parameter?.type === import_utils10.AST_NODE_TYPES.ObjectPattern && parameter.properties.some(
|
|
1478
|
+
(property) => property.type !== import_utils10.AST_NODE_TYPES.Property || property.computed || property.value.type !== import_utils10.AST_NODE_TYPES.Identifier
|
|
1158
1479
|
))
|
|
1159
1480
|
return false;
|
|
1160
1481
|
const parameters = firstParameterBindings(source, callback);
|
|
1161
1482
|
if (parameters.size === 0) return false;
|
|
1162
1483
|
let body3 = callback.body;
|
|
1163
|
-
if (body3.type ===
|
|
1484
|
+
if (body3.type === import_utils10.AST_NODE_TYPES.BlockStatement) {
|
|
1164
1485
|
const [statement] = body3.body;
|
|
1165
|
-
if (body3.body.length !== 1 || statement?.type !==
|
|
1486
|
+
if (body3.body.length !== 1 || statement?.type !== import_utils10.AST_NODE_TYPES.ReturnStatement || statement.argument === null)
|
|
1166
1487
|
return false;
|
|
1167
1488
|
body3 = statement.argument;
|
|
1168
1489
|
}
|
|
@@ -1171,245 +1492,95 @@ function projection(source, callback, mode = "data") {
|
|
|
1171
1492
|
if (depth > 64) return false;
|
|
1172
1493
|
node = unwrapExpression(node);
|
|
1173
1494
|
if (parameterPath(source, node, parameters)) {
|
|
1174
|
-
if (node.type !==
|
|
1495
|
+
if (node.type !== import_utils10.AST_NODE_TYPES.MemberExpression && callback.params[0]?.type !== import_utils10.AST_NODE_TYPES.ObjectPattern)
|
|
1175
1496
|
return false;
|
|
1176
1497
|
fieldRead = true;
|
|
1177
1498
|
return true;
|
|
1178
1499
|
}
|
|
1179
|
-
if (node.type ===
|
|
1180
|
-
if (node.type ===
|
|
1500
|
+
if (node.type === import_utils10.AST_NODE_TYPES.Literal) return !("regex" in node);
|
|
1501
|
+
if (node.type === import_utils10.AST_NODE_TYPES.UnaryExpression)
|
|
1181
1502
|
return ["!", "+", "-", "~", "typeof"].includes(node.operator) && inspect(node.argument, depth + 1);
|
|
1182
|
-
if (node.type ===
|
|
1503
|
+
if (node.type === import_utils10.AST_NODE_TYPES.BinaryExpression)
|
|
1183
1504
|
return BINARY.has(node.operator) && inspect(node.left, depth + 1) && inspect(node.right, depth + 1);
|
|
1184
|
-
if (node.type ===
|
|
1505
|
+
if (node.type === import_utils10.AST_NODE_TYPES.LogicalExpression)
|
|
1185
1506
|
return inspect(node.left, depth + 1) && inspect(node.right, depth + 1);
|
|
1186
|
-
if (node.type ===
|
|
1507
|
+
if (node.type === import_utils10.AST_NODE_TYPES.ConditionalExpression)
|
|
1187
1508
|
return inspect(node.test, depth + 1) && inspect(node.consequent, depth + 1) && inspect(node.alternate, depth + 1);
|
|
1188
|
-
if (node.type ===
|
|
1189
|
-
return node.properties.every(
|
|
1190
|
-
(property) => property.type ===
|
|
1191
|
-
);
|
|
1192
|
-
return mode === "view" && displayProjection(node, (child) => inspect(child, depth + 1));
|
|
1193
|
-
};
|
|
1194
|
-
return inspect(body3, 0) && fieldRead;
|
|
1195
|
-
}
|
|
1196
|
-
function displayProjection(node, inspectChild) {
|
|
1197
|
-
if (node.type === import_utils9.AST_NODE_TYPES.JSXElement)
|
|
1198
|
-
return node.openingElement.attributes.every(
|
|
1199
|
-
(attribute) => attribute.type === import_utils9.AST_NODE_TYPES.JSXAttribute && (attribute.value === null || inspectChild(attribute.value))
|
|
1200
|
-
) && node.children.every(inspectChild);
|
|
1201
|
-
if (node.type === import_utils9.AST_NODE_TYPES.JSXFragment)
|
|
1202
|
-
return node.children.every(inspectChild);
|
|
1203
|
-
if (node.type === import_utils9.AST_NODE_TYPES.JSXText) return true;
|
|
1204
|
-
if (node.type === import_utils9.AST_NODE_TYPES.JSXExpressionContainer)
|
|
1205
|
-
return node.expression.type === import_utils9.AST_NODE_TYPES.JSXEmptyExpression || inspectChild(node.expression);
|
|
1206
|
-
return false;
|
|
1207
|
-
}
|
|
1208
|
-
function onlyProjectedInput(source, receiver, nativeArray, cache) {
|
|
1209
|
-
let root = unwrapExpression(receiver);
|
|
1210
|
-
while (root.type === import_utils9.AST_NODE_TYPES.MemberExpression)
|
|
1211
|
-
root = unwrapExpression(root.object);
|
|
1212
|
-
if (root.type !== import_utils9.AST_NODE_TYPES.Identifier) return false;
|
|
1213
|
-
const variable = import_utils9.ASTUtils.findVariable(source.getScope(root), root.name);
|
|
1214
|
-
if (variable === null) return false;
|
|
1215
|
-
const cached = cache.get(variable);
|
|
1216
|
-
if (cached !== void 0) return cached;
|
|
1217
|
-
const projected = variable.references.every((reference) => {
|
|
1218
|
-
if (typeOnlyReference(reference)) return true;
|
|
1219
|
-
if (!reference.isRead()) return false;
|
|
1220
|
-
let access = outerExpression(reference.identifier);
|
|
1221
|
-
let parent = access.parent;
|
|
1222
|
-
while (parent?.type === import_utils9.AST_NODE_TYPES.MemberExpression && parent.object === access) {
|
|
1223
|
-
access = outerExpression(parent);
|
|
1224
|
-
parent = access.parent;
|
|
1225
|
-
}
|
|
1226
|
-
const member3 = unwrapExpression(access);
|
|
1227
|
-
const call = parent;
|
|
1228
|
-
if (call?.type !== import_utils9.AST_NODE_TYPES.CallExpression) return false;
|
|
1229
|
-
if (member3.type !== import_utils9.AST_NODE_TYPES.MemberExpression || member3.optional || !METHODS.has(import_utils9.ASTUtils.getPropertyName(member3) ?? "") || call.optional || call.arguments.length !== 1 || !nativeArray(call))
|
|
1230
|
-
return false;
|
|
1231
|
-
const callback = call.arguments[0];
|
|
1232
|
-
return (callback?.type === import_utils9.AST_NODE_TYPES.ArrowFunctionExpression || callback?.type === import_utils9.AST_NODE_TYPES.FunctionExpression) && (projection(source, callback) || projection(source, callback, "view")) && call.callee === access;
|
|
1233
|
-
});
|
|
1234
|
-
cache.set(variable, projected);
|
|
1235
|
-
return projected;
|
|
1236
|
-
}
|
|
1237
|
-
function clientInteraction(source, node, callable) {
|
|
1238
|
-
if (node.type === import_utils9.AST_NODE_TYPES.ArrowFunctionExpression || node.type === import_utils9.AST_NODE_TYPES.FunctionExpression || node.type === import_utils9.AST_NODE_TYPES.FunctionDeclaration)
|
|
1239
|
-
return false;
|
|
1240
|
-
if (node.type === import_utils9.AST_NODE_TYPES.CallExpression && (reactHook(source, node.callee, "useState") || reactHook(source, node.callee, "useReducer")))
|
|
1241
|
-
return true;
|
|
1242
|
-
if (node.type === import_utils9.AST_NODE_TYPES.JSXOpeningElement && node.name.type === import_utils9.AST_NODE_TYPES.JSXIdentifier && /^[a-z]/u.test(node.name.name) && node.attributes.some(
|
|
1243
|
-
(attribute) => attribute.type === import_utils9.AST_NODE_TYPES.JSXAttribute && attribute.name.type === import_utils9.AST_NODE_TYPES.JSXIdentifier && DOM_EVENTS.has(attribute.name.name) && attribute.value?.type === import_utils9.AST_NODE_TYPES.JSXExpressionContainer && attribute.value.expression.type !== import_utils9.AST_NODE_TYPES.JSXEmptyExpression && callable(attribute.value.expression)
|
|
1244
|
-
))
|
|
1245
|
-
return true;
|
|
1246
|
-
return forEachOwnAstChild(
|
|
1247
|
-
node,
|
|
1248
|
-
(child) => clientInteraction(source, child, callable),
|
|
1249
|
-
(key) => key !== "tokens" && key !== "comments"
|
|
1250
|
-
);
|
|
1251
|
-
}
|
|
1252
|
-
|
|
1253
|
-
// src/rules/no-readonly-prop-state.ts
|
|
1254
|
-
var import_utils12 = require("@typescript-eslint/utils");
|
|
1255
|
-
var import_typescript4 = __toESM(require("typescript"), 1);
|
|
1256
|
-
|
|
1257
|
-
// src/rules/_unused-private-binding.ts
|
|
1258
|
-
var import_utils11 = require("@typescript-eslint/utils");
|
|
1259
|
-
|
|
1260
|
-
// src/rules/_type-binding.ts
|
|
1261
|
-
var import_utils10 = require("@typescript-eslint/utils");
|
|
1262
|
-
function typeBinding(source, identifier) {
|
|
1263
|
-
let scope = source.getScope(identifier);
|
|
1264
|
-
while (scope !== null) {
|
|
1265
|
-
const variable = scope.set.get(identifier.name);
|
|
1266
|
-
if (variable !== void 0 && (variable.isTypeVariable || variable.defs.some((definition) => definition.isTypeDefinition))) {
|
|
1267
|
-
return variable;
|
|
1268
|
-
}
|
|
1269
|
-
scope = scope.upper;
|
|
1270
|
-
}
|
|
1271
|
-
return null;
|
|
1272
|
-
}
|
|
1273
|
-
var REFERENCE_INDEXES = /* @__PURE__ */ new WeakMap();
|
|
1274
|
-
function retainsNamedTypeUses(source, removed) {
|
|
1275
|
-
const manager = source.scopeManager;
|
|
1276
|
-
if (manager === null) return false;
|
|
1277
|
-
const index = referenceIndex(source, manager);
|
|
1278
|
-
for (const reference of referencesWithin(index.references, removed)) {
|
|
1279
|
-
if (!reference.isRead()) continue;
|
|
1280
|
-
const binding3 = reference.resolved;
|
|
1281
|
-
if (!binding3 || !reference.isTypeReference && !reference.isValueReference) return false;
|
|
1282
|
-
if (binding3.defs.length === 0) continue;
|
|
1283
|
-
const reads = publicReadExtents(index, binding3);
|
|
1284
|
-
const extent = reference.isTypeReference ? reference.isValueReference ? reads.both : reads.type : reads.value;
|
|
1285
|
-
if (extent === null || extent.minStart >= removed.range[0] && extent.maxEnd <= removed.range[1]) return false;
|
|
1286
|
-
}
|
|
1287
|
-
return true;
|
|
1288
|
-
}
|
|
1289
|
-
function referenceIndex(source, manager) {
|
|
1290
|
-
const cached = REFERENCE_INDEXES.get(source);
|
|
1291
|
-
if (cached?.manager === manager) return cached;
|
|
1292
|
-
const references = manager.scopes.flatMap((scope) => scope.references);
|
|
1293
|
-
references.sort((left, right) => left.identifier.range[0] - right.identifier.range[0]);
|
|
1294
|
-
const index = { manager, references, publicReads: /* @__PURE__ */ new Map() };
|
|
1295
|
-
REFERENCE_INDEXES.set(source, index);
|
|
1296
|
-
return index;
|
|
1297
|
-
}
|
|
1298
|
-
function* referencesWithin(references, removed) {
|
|
1299
|
-
let low = 0;
|
|
1300
|
-
let high = references.length;
|
|
1301
|
-
while (low < high) {
|
|
1302
|
-
const middle = low + Math.floor((high - low) / 2);
|
|
1303
|
-
const reference = references[middle];
|
|
1304
|
-
if (reference === void 0 || reference.identifier.range[0] >= removed.range[0]) high = middle;
|
|
1305
|
-
else low = middle + 1;
|
|
1306
|
-
}
|
|
1307
|
-
for (let index = low; index < references.length; index++) {
|
|
1308
|
-
const reference = references[index];
|
|
1309
|
-
if (reference === void 0) continue;
|
|
1310
|
-
if (reference.identifier.range[0] > removed.range[1]) break;
|
|
1311
|
-
if (insideTypeRange(reference.identifier, removed)) yield reference;
|
|
1312
|
-
}
|
|
1313
|
-
}
|
|
1314
|
-
function publicReadExtents(index, binding3) {
|
|
1315
|
-
const cached = index.publicReads.get(binding3);
|
|
1316
|
-
if (cached !== void 0) return cached;
|
|
1317
|
-
let type = null;
|
|
1318
|
-
let value = null;
|
|
1319
|
-
let both = null;
|
|
1320
|
-
for (const retained of binding3.references) {
|
|
1321
|
-
if (!retained.isRead() || !retained.isTypeReference && !retained.isValueReference || binding3.defs.some((definition) => insideTypeRange(retained.identifier, definition.node)) || !publicTypeUse(retained.identifier)) continue;
|
|
1322
|
-
if (retained.isTypeReference) type = extendExtent(type, retained.identifier);
|
|
1323
|
-
if (retained.isValueReference) value = extendExtent(value, retained.identifier);
|
|
1324
|
-
if (retained.isTypeReference && retained.isValueReference) both = extendExtent(both, retained.identifier);
|
|
1325
|
-
}
|
|
1326
|
-
const result = { type, value, both };
|
|
1327
|
-
index.publicReads.set(binding3, result);
|
|
1328
|
-
return result;
|
|
1329
|
-
}
|
|
1330
|
-
function extendExtent(extent, identifier) {
|
|
1331
|
-
return {
|
|
1332
|
-
minStart: Math.min(extent?.minStart ?? identifier.range[0], identifier.range[0]),
|
|
1333
|
-
maxEnd: Math.max(extent?.maxEnd ?? identifier.range[1], identifier.range[1])
|
|
1334
|
-
};
|
|
1335
|
-
}
|
|
1336
|
-
function publicTypeUse(identifier) {
|
|
1337
|
-
let node = identifier;
|
|
1338
|
-
while (node.parent) {
|
|
1339
|
-
if (node.type === import_utils10.AST_NODE_TYPES.TSTypeAnnotation || node.type === import_utils10.AST_NODE_TYPES.TSTypePredicate || node.type === import_utils10.AST_NODE_TYPES.TSAsExpression || node.type === import_utils10.AST_NODE_TYPES.TSTypeAssertion) return false;
|
|
1340
|
-
if (node.type === import_utils10.AST_NODE_TYPES.TSTypeAliasDeclaration) {
|
|
1341
|
-
return node.parent.type === import_utils10.AST_NODE_TYPES.ExportNamedDeclaration && node.parent.declaration === node && node.parent.parent.type === import_utils10.AST_NODE_TYPES.Program;
|
|
1342
|
-
}
|
|
1343
|
-
if (node.type === import_utils10.AST_NODE_TYPES.ExportSpecifier) {
|
|
1344
|
-
return node.parent.type === import_utils10.AST_NODE_TYPES.ExportNamedDeclaration && node.parent.source === null && node.parent.parent.type === import_utils10.AST_NODE_TYPES.Program;
|
|
1345
|
-
}
|
|
1346
|
-
node = node.parent;
|
|
1347
|
-
}
|
|
1348
|
-
return false;
|
|
1349
|
-
}
|
|
1350
|
-
function insideTypeRange(node, range) {
|
|
1351
|
-
return node.range[0] >= range.range[0] && node.range[1] <= range.range[1];
|
|
1352
|
-
}
|
|
1353
|
-
|
|
1354
|
-
// src/rules/_unused-private-binding.ts
|
|
1355
|
-
function isUnusedPrivateBinding(sourceCode, declaration, identifier, filename, allowedDeclarations = [declaration]) {
|
|
1356
|
-
if (/\.d\.[cm]?ts$/u.test(filename)) return false;
|
|
1357
|
-
const bindings = sourceCode.getDeclaredVariables(declaration).filter((binding3) => binding3.name === identifier.name);
|
|
1358
|
-
if (bindings.length === 0 || bindings.some((binding3) => binding3.defs.length !== allowedDeclarations.length || binding3.defs.some((definition) => !allowedDeclarations.includes(definition.node)) || binding3.eslintUsed || binding3.references.some((reference) => reference.isRead() || reference.init !== true))) return false;
|
|
1359
|
-
if (hasIdentifierNamed(sourceCode.ast, "eval")) return false;
|
|
1360
|
-
const statement = declaration.type === import_utils11.AST_NODE_TYPES.VariableDeclarator ? declaration.parent : declaration;
|
|
1361
|
-
if (statement.parent.type === import_utils11.AST_NODE_TYPES.ExportNamedDeclaration || statement.parent.type === import_utils11.AST_NODE_TYPES.ExportDefaultDeclaration) return false;
|
|
1362
|
-
if (statement.parent.type !== import_utils11.AST_NODE_TYPES.Program) return statement.parent.type === import_utils11.AST_NODE_TYPES.BlockStatement;
|
|
1363
|
-
return sourceCode.ast.body.some((node) => node.type === import_utils11.AST_NODE_TYPES.ImportDeclaration || node.type === import_utils11.AST_NODE_TYPES.ExportNamedDeclaration || node.type === import_utils11.AST_NODE_TYPES.ExportDefaultDeclaration || node.type === import_utils11.AST_NODE_TYPES.ExportAllDeclaration);
|
|
1509
|
+
if (node.type === import_utils10.AST_NODE_TYPES.ObjectExpression)
|
|
1510
|
+
return node.properties.every(
|
|
1511
|
+
(property) => property.type === import_utils10.AST_NODE_TYPES.Property && property.kind === "init" && !property.method && !property.computed && inspect(property.value, depth + 1)
|
|
1512
|
+
);
|
|
1513
|
+
return mode === "view" && displayProjection(node, (child) => inspect(child, depth + 1));
|
|
1514
|
+
};
|
|
1515
|
+
return inspect(body3, 0) && fieldRead;
|
|
1364
1516
|
}
|
|
1365
|
-
function
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
return
|
|
1372
|
-
|
|
1517
|
+
function displayProjection(node, inspectChild) {
|
|
1518
|
+
if (node.type === import_utils10.AST_NODE_TYPES.JSXElement)
|
|
1519
|
+
return node.openingElement.attributes.every(
|
|
1520
|
+
(attribute) => attribute.type === import_utils10.AST_NODE_TYPES.JSXAttribute && (attribute.value === null || inspectChild(attribute.value))
|
|
1521
|
+
) && node.children.every(inspectChild);
|
|
1522
|
+
if (node.type === import_utils10.AST_NODE_TYPES.JSXFragment)
|
|
1523
|
+
return node.children.every(inspectChild);
|
|
1524
|
+
if (node.type === import_utils10.AST_NODE_TYPES.JSXText) return true;
|
|
1525
|
+
if (node.type === import_utils10.AST_NODE_TYPES.JSXExpressionContainer)
|
|
1526
|
+
return node.expression.type === import_utils10.AST_NODE_TYPES.JSXEmptyExpression || inspectChild(node.expression);
|
|
1527
|
+
return false;
|
|
1373
1528
|
}
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1529
|
+
function onlyProjectedInput(source, receiver, nativeArray, cache) {
|
|
1530
|
+
let root = unwrapExpression(receiver);
|
|
1531
|
+
while (root.type === import_utils10.AST_NODE_TYPES.MemberExpression)
|
|
1532
|
+
root = unwrapExpression(root.object);
|
|
1533
|
+
if (root.type !== import_utils10.AST_NODE_TYPES.Identifier) return false;
|
|
1534
|
+
const variable = import_utils10.ASTUtils.findVariable(source.getScope(root), root.name);
|
|
1535
|
+
if (variable === null) return false;
|
|
1536
|
+
const cached = cache.get(variable);
|
|
1537
|
+
if (cached !== void 0) return cached;
|
|
1538
|
+
const projected = variable.references.every((reference) => {
|
|
1539
|
+
if (typeOnlyReference(reference)) return true;
|
|
1540
|
+
if (!reference.isRead()) return false;
|
|
1541
|
+
let access = outerExpression(reference.identifier);
|
|
1542
|
+
let parent = access.parent;
|
|
1543
|
+
while (parent?.type === import_utils10.AST_NODE_TYPES.MemberExpression && parent.object === access) {
|
|
1544
|
+
access = outerExpression(parent);
|
|
1545
|
+
parent = access.parent;
|
|
1389
1546
|
}
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1547
|
+
const member3 = unwrapExpression(access);
|
|
1548
|
+
const call = parent;
|
|
1549
|
+
if (call?.type !== import_utils10.AST_NODE_TYPES.CallExpression) return false;
|
|
1550
|
+
if (member3.type !== import_utils10.AST_NODE_TYPES.MemberExpression || member3.optional || !METHODS.has(import_utils10.ASTUtils.getPropertyName(member3) ?? "") || call.optional || call.arguments.length !== 1 || !nativeArray(call))
|
|
1551
|
+
return false;
|
|
1552
|
+
const callback = call.arguments[0];
|
|
1553
|
+
return (callback?.type === import_utils10.AST_NODE_TYPES.ArrowFunctionExpression || callback?.type === import_utils10.AST_NODE_TYPES.FunctionExpression) && (projection(source, callback) || projection(source, callback, "view")) && call.callee === access;
|
|
1554
|
+
});
|
|
1555
|
+
cache.set(variable, projected);
|
|
1556
|
+
return projected;
|
|
1394
1557
|
}
|
|
1395
|
-
function
|
|
1396
|
-
if (
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1558
|
+
function clientInteraction(source, node, callable) {
|
|
1559
|
+
if (node.type === import_utils10.AST_NODE_TYPES.ArrowFunctionExpression || node.type === import_utils10.AST_NODE_TYPES.FunctionExpression || node.type === import_utils10.AST_NODE_TYPES.FunctionDeclaration)
|
|
1560
|
+
return false;
|
|
1561
|
+
if (node.type === import_utils10.AST_NODE_TYPES.CallExpression && (reactHook(source, node.callee, "useState") || reactHook(source, node.callee, "useReducer")))
|
|
1562
|
+
return true;
|
|
1563
|
+
if (node.type === import_utils10.AST_NODE_TYPES.JSXOpeningElement && node.name.type === import_utils10.AST_NODE_TYPES.JSXIdentifier && /^[a-z]/u.test(node.name.name) && node.attributes.some(
|
|
1564
|
+
(attribute) => attribute.type === import_utils10.AST_NODE_TYPES.JSXAttribute && attribute.name.type === import_utils10.AST_NODE_TYPES.JSXIdentifier && DOM_EVENTS.has(attribute.name.name) && attribute.value?.type === import_utils10.AST_NODE_TYPES.JSXExpressionContainer && attribute.value.expression.type !== import_utils10.AST_NODE_TYPES.JSXEmptyExpression && callable(attribute.value.expression)
|
|
1565
|
+
))
|
|
1566
|
+
return true;
|
|
1567
|
+
return forEachOwnAstChild(
|
|
1568
|
+
node,
|
|
1569
|
+
(child) => clientInteraction(source, child, callable),
|
|
1570
|
+
(key) => key !== "tokens" && key !== "comments"
|
|
1571
|
+
);
|
|
1403
1572
|
}
|
|
1404
1573
|
|
|
1405
1574
|
// src/rules/no-readonly-prop-state.ts
|
|
1575
|
+
var import_utils11 = require("@typescript-eslint/utils");
|
|
1576
|
+
var import_typescript8 = __toESM(require("typescript"), 1);
|
|
1406
1577
|
var BEFORE2 = "import { useState } from 'react'; export function Status({ status }: { status: string }) { const [savedStatus] = useState(status); return <p>{savedStatus}</p>; }";
|
|
1407
1578
|
var AFTER2 = "export function Status({ status }: { status: string }) { return <p>{status}</p>; }";
|
|
1408
1579
|
var CONFIG2 = {
|
|
1409
1580
|
path: "tsconfig.json",
|
|
1410
1581
|
source: '{"compilerOptions":{"strict":true,"target":"ESNext","module":"ESNext","moduleResolution":"Bundler","jsx":"preserve"},"include":["src/**/*"]}'
|
|
1411
1582
|
};
|
|
1412
|
-
var PRIMITIVE_TYPES =
|
|
1583
|
+
var PRIMITIVE_TYPES = import_typescript8.default.TypeFlags.StringLike | import_typescript8.default.TypeFlags.NumberLike | import_typescript8.default.TypeFlags.BigIntLike | import_typescript8.default.TypeFlags.BooleanLike | import_typescript8.default.TypeFlags.ESSymbolLike | import_typescript8.default.TypeFlags.Null | import_typescript8.default.TypeFlags.Undefined;
|
|
1413
1584
|
var MAX_TYPE_DEPTH = 16;
|
|
1414
1585
|
var NO_READONLY_PROP_STATE_DOCUMENTATION = {
|
|
1415
1586
|
defaultLevel: "warning",
|
|
@@ -1421,7 +1592,7 @@ var NO_READONLY_PROP_STATE_DOCUMENTATION = {
|
|
|
1421
1592
|
"Advisory only: initial snapshots can be intentional. There is no automatic fix because replacing state with current props changes how later updates behave.",
|
|
1422
1593
|
"Recognizes direct React useState imports and default/namespace member calls, including renamed imports, through lexical binding identity. Checks a direct array destructure in a function containing its own JSX and a direct first-parameter property path, or a zero-argument synchronous lazy initializer returning that path.",
|
|
1423
1594
|
"Eager initializers require parser-owned TypeScript services and primitive types, including unions composed entirely of primitives. Object and void types can hide callable values through structural assignment or ignored return values, so eager nonprimitive values, Any, unknown and unresolved generics are excluded. React executes function arguments as lazy initializers. Explicit zero-argument lazy callbacks returning a prop directly remain supported for all value types without type services. Opaque casts cannot prove runtime identity; lifecycle changes stay manual.",
|
|
1424
|
-
"An updater read, escape, reassignment or nontrivial destructuring excludes the finding. Unused state values remain owned by unused-variable checks. Opaque initialization, property aliases, optional/dynamic paths, rest/default bindings,
|
|
1595
|
+
"An updater read, escape, reassignment or nontrivial destructuring excludes the finding. Unused state values remain owned by unused-variable checks. Files containing direct eval are excluded because it can observe or change lexical bindings. Indirect eval and properties named eval do not establish lexical access. Opaque initialization, property aliases, optional/dynamic paths, rest/default bindings, non-JSX hooks, generated source and tests are outside scope. This does not ban interactive useState or replace the upstream set-state-in-effect rule."
|
|
1425
1596
|
],
|
|
1426
1597
|
references: [
|
|
1427
1598
|
"https://react.dev/learn/choosing-the-state-structure",
|
|
@@ -1463,19 +1634,19 @@ var no_readonly_prop_state_default = createRule({
|
|
|
1463
1634
|
defaultOptions: [],
|
|
1464
1635
|
create(context) {
|
|
1465
1636
|
if (isGeneratedFile(context, context.sourceCode.text) || isTestFile(context) || !context.sourceCode.ast.body.some(
|
|
1466
|
-
(statement) => statement.type ===
|
|
1467
|
-
)
|
|
1637
|
+
(statement) => statement.type === import_utils11.AST_NODE_TYPES.ImportDeclaration && statement.source.value === "react" && statement.importKind !== "type"
|
|
1638
|
+
))
|
|
1468
1639
|
return {};
|
|
1469
1640
|
return {
|
|
1470
1641
|
CallExpression(node) {
|
|
1471
1642
|
if (node.optional || node.arguments.length !== 1 || !reactHook(context.sourceCode, node.callee, "useState"))
|
|
1472
1643
|
return;
|
|
1473
1644
|
const declaration = outerExpression(node).parent;
|
|
1474
|
-
if (declaration.type !==
|
|
1645
|
+
if (declaration.type !== import_utils11.AST_NODE_TYPES.VariableDeclarator || declaration.parent.kind !== "const" || !hasReadonlyStateBinding(context.sourceCode, declaration))
|
|
1475
1646
|
return;
|
|
1476
1647
|
const component = renderFunction(node);
|
|
1477
1648
|
const argument = node.arguments[0];
|
|
1478
|
-
if (component === null || argument === void 0 || argument.type ===
|
|
1649
|
+
if (component === null || argument === void 0 || argument.type === import_utils11.AST_NODE_TYPES.SpreadElement)
|
|
1479
1650
|
return;
|
|
1480
1651
|
const initial = initializerValue(argument);
|
|
1481
1652
|
if (initial === null || !parameterPath(
|
|
@@ -1485,7 +1656,7 @@ var no_readonly_prop_state_default = createRule({
|
|
|
1485
1656
|
))
|
|
1486
1657
|
return;
|
|
1487
1658
|
const lazy = unwrapExpression(argument);
|
|
1488
|
-
if (lazy.type !==
|
|
1659
|
+
if (lazy.type !== import_utils11.AST_NODE_TYPES.ArrowFunctionExpression && lazy.type !== import_utils11.AST_NODE_TYPES.FunctionExpression) {
|
|
1489
1660
|
if (!context.sourceCode.parserServices?.program || !context.sourceCode.parserServices.esTreeNodeToTSNodeMap)
|
|
1490
1661
|
return;
|
|
1491
1662
|
const services = getTypeServices(context);
|
|
@@ -1498,9 +1669,9 @@ var no_readonly_prop_state_default = createRule({
|
|
|
1498
1669
|
}
|
|
1499
1670
|
});
|
|
1500
1671
|
function hasReadonlyStateBinding(source, declaration) {
|
|
1501
|
-
if (declaration.id.type !==
|
|
1672
|
+
if (declaration.id.type !== import_utils11.AST_NODE_TYPES.ArrayPattern) return false;
|
|
1502
1673
|
const [value, setter] = declaration.id.elements;
|
|
1503
|
-
if (value?.type !==
|
|
1674
|
+
if (value?.type !== import_utils11.AST_NODE_TYPES.Identifier || declaration.id.elements.length > 2 || setter !== void 0 && setter !== null && setter.type !== import_utils11.AST_NODE_TYPES.Identifier)
|
|
1504
1675
|
return false;
|
|
1505
1676
|
const variables = source.getDeclaredVariables(declaration);
|
|
1506
1677
|
const state = variables.find(
|
|
@@ -1510,7 +1681,7 @@ function hasReadonlyStateBinding(source, declaration) {
|
|
|
1510
1681
|
(reference) => reference.isRead() && !typeOnlyReference(reference)
|
|
1511
1682
|
))
|
|
1512
1683
|
return false;
|
|
1513
|
-
if (setter?.type ===
|
|
1684
|
+
if (setter?.type === import_utils11.AST_NODE_TYPES.Identifier) {
|
|
1514
1685
|
const updater = variables.find(
|
|
1515
1686
|
(variable) => variable.identifiers.includes(setter)
|
|
1516
1687
|
);
|
|
@@ -1523,12 +1694,12 @@ function hasReadonlyStateBinding(source, declaration) {
|
|
|
1523
1694
|
}
|
|
1524
1695
|
function initializerValue(node) {
|
|
1525
1696
|
node = unwrapExpression(node);
|
|
1526
|
-
if (node.type !==
|
|
1697
|
+
if (node.type !== import_utils11.AST_NODE_TYPES.ArrowFunctionExpression && node.type !== import_utils11.AST_NODE_TYPES.FunctionExpression)
|
|
1527
1698
|
return node;
|
|
1528
1699
|
if (node.async || node.generator || node.params.length !== 0) return null;
|
|
1529
|
-
if (node.body.type !==
|
|
1700
|
+
if (node.body.type !== import_utils11.AST_NODE_TYPES.BlockStatement) return node.body;
|
|
1530
1701
|
const [statement] = node.body.body;
|
|
1531
|
-
return node.body.body.length === 1 && statement?.type ===
|
|
1702
|
+
return node.body.body.length === 1 && statement?.type === import_utils11.AST_NODE_TYPES.ReturnStatement ? statement.argument : null;
|
|
1532
1703
|
}
|
|
1533
1704
|
function isPrimitiveType(type, depth = 0) {
|
|
1534
1705
|
if (depth >= MAX_TYPE_DEPTH) return false;
|
|
@@ -1538,7 +1709,7 @@ function isPrimitiveType(type, depth = 0) {
|
|
|
1538
1709
|
}
|
|
1539
1710
|
|
|
1540
1711
|
// src/rules/no-runtime-typeof.ts
|
|
1541
|
-
var
|
|
1712
|
+
var import_utils12 = require("@typescript-eslint/utils");
|
|
1542
1713
|
var NO_RUNTIME_TYPEOF_DOCUMENTATION = {
|
|
1543
1714
|
defaultLevel: "error",
|
|
1544
1715
|
summary: "Prefer Zod boundary schemas or discriminated unions over runtime typeof checks.",
|
|
@@ -1656,9 +1827,9 @@ var no_runtime_typeof_default = createRule({
|
|
|
1656
1827
|
UnaryExpression(node) {
|
|
1657
1828
|
if (node.operator !== "typeof") return;
|
|
1658
1829
|
const parent = node.parent;
|
|
1659
|
-
if (node.argument.type ===
|
|
1830
|
+
if (node.argument.type === import_utils12.AST_NODE_TYPES.Identifier && parent.type === import_utils12.AST_NODE_TYPES.BinaryExpression && ["===", "!==", "==", "!="].includes(parent.operator)) {
|
|
1660
1831
|
const other = parent.left === node ? parent.right : parent.left;
|
|
1661
|
-
if (other.type ===
|
|
1832
|
+
if (other.type === import_utils12.AST_NODE_TYPES.Literal && other.value === "undefined" && !import_utils12.ASTUtils.findVariable(context.sourceCode.getScope(node.argument), node.argument.name)?.defs.length) return;
|
|
1662
1833
|
}
|
|
1663
1834
|
context.report({ node, messageId: "runtimeTypeof" });
|
|
1664
1835
|
}
|
|
@@ -1669,7 +1840,7 @@ var no_runtime_typeof_default = createRule({
|
|
|
1669
1840
|
// src/rules/_is-frontend-source.ts
|
|
1670
1841
|
var import_node_fs = require("fs");
|
|
1671
1842
|
var import_node_path2 = require("path");
|
|
1672
|
-
var
|
|
1843
|
+
var import_utils13 = require("@typescript-eslint/utils");
|
|
1673
1844
|
var FRONTEND_PACKAGES = /* @__PURE__ */ new Set(["react", "react-dom", "next", "preact", "vue", "svelte", "@angular/core", "solid-js", "@sveltejs/kit", "astro"]);
|
|
1674
1845
|
var FRONTEND_IMPORT = /^(?:react(?:-dom)?|next|preact|vue|svelte|@angular\/core|solid-js|@sveltejs\/kit)(?:\/|$)/u;
|
|
1675
1846
|
function isFrontendSource(context) {
|
|
@@ -1697,15 +1868,15 @@ function declaresFrontend(value) {
|
|
|
1697
1868
|
}
|
|
1698
1869
|
function frontendModule(program) {
|
|
1699
1870
|
return program.body.some(
|
|
1700
|
-
(statement) => statement.type ===
|
|
1871
|
+
(statement) => statement.type === import_utils13.AST_NODE_TYPES.ExpressionStatement && (statement.directive === "use client" || statement.directive === "use server") || statement.type === import_utils13.AST_NODE_TYPES.ImportDeclaration && FRONTEND_IMPORT.test(statement.source.value)
|
|
1701
1872
|
);
|
|
1702
1873
|
}
|
|
1703
1874
|
|
|
1704
1875
|
// src/rules/no-test-comments.ts
|
|
1705
|
-
var
|
|
1876
|
+
var import_utils16 = require("@typescript-eslint/utils");
|
|
1706
1877
|
|
|
1707
1878
|
// src/rules/_comments.ts
|
|
1708
|
-
var
|
|
1879
|
+
var import_utils14 = require("@typescript-eslint/utils");
|
|
1709
1880
|
var REF_RE = /https?:\/\/|\bRFC[- ]?\d+|\bPEP[- ]?\d+|\bCVE-\d{4}|\b(?!UTF-|SHA-|ISO-|AES-|CRC-|MD-|PCM-|EOF-|API-|BASE-)[A-Z][A-Z0-9]{1,9}-\d[A-Z0-9]{0,5}\b|(?<![&\w])#\d{2,6}\b|@[a-z][\w.-]*\.(?:us|com|ai|io|net|org|dev)\b/;
|
|
1710
1881
|
var VERSION_RE = /(?:>=|<=|==|<|>)\s*v?\d+\.\d+|\bv\d+\.\d+|\b(?:since|until|as of)\s+(?:v?\d+\.\d+|Python\s*\d)/i;
|
|
1711
1882
|
var UNITS_RE = /[~<>]?\d+(?:\.\d+)?\s?(?:ms|s\b|sec\b|seconds?\b|min\b|minutes?\b|hours?\b|days?\b|KB|MB|MiB|GiB|kHz|Hz|bytes?\b|bit\b|-bit\b|%|px\b|rps\b|qps\b)|\b[1-5]xx\b|\b(?:301|302|304|307|308|400|401|403|404|405|409|410|412|422|425|429|500|501|502|503|504)\b/;
|
|
@@ -1791,10 +1962,10 @@ var NARRATION_MAX_WORDS = 6;
|
|
|
1791
1962
|
var NARRATION_MIN_CONTENT = 1;
|
|
1792
1963
|
var TOKEN_PLURAL_MIN = 4;
|
|
1793
1964
|
var RESTATABLE_STATEMENTS = /* @__PURE__ */ new Set([
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
|
|
1965
|
+
import_utils14.AST_NODE_TYPES.ExpressionStatement,
|
|
1966
|
+
import_utils14.AST_NODE_TYPES.ReturnStatement,
|
|
1967
|
+
import_utils14.AST_NODE_TYPES.ThrowStatement,
|
|
1968
|
+
import_utils14.AST_NODE_TYPES.VariableDeclaration
|
|
1798
1969
|
]);
|
|
1799
1970
|
var NARRATION_VERB_RE = /^(?:add|append|assign|build|calculate|call|check|clear|close|compute|convert|copy|count|create|declare|decrement|define|delete|extract|fetch|filter|find|format|generate|get|handle|increment|init|initialise|initialize|insert|iterate|join|load|log|loop|make|map|merge|open|parse|print|process|push|read|remove|render|reset|return|save|send|set|setup|sort|split|start|stop|store|update|validate|wrap|write)(?:s|es|d|ed|ing)?$/i;
|
|
1800
1971
|
var NARRATION_STOPWORDS = /* @__PURE__ */ new Set([
|
|
@@ -1853,12 +2024,12 @@ function restatableStatementBelow(comment, sourceCode) {
|
|
|
1853
2024
|
function restatableStatementNodeBelow(comment, sourceCode) {
|
|
1854
2025
|
const token = sourceCode.getTokenAfter(comment, { includeComments: false });
|
|
1855
2026
|
if (token === null || token.loc.start.line !== comment.loc.end.line + 1) return null;
|
|
1856
|
-
for (let node = sourceCode.getNodeByRangeIndex(token.range[0]); node != null && node.type !==
|
|
2027
|
+
for (let node = sourceCode.getNodeByRangeIndex(token.range[0]); node != null && node.type !== import_utils14.AST_NODE_TYPES.Program; node = node.parent) {
|
|
1857
2028
|
if (!RESTATABLE_STATEMENTS.has(node.type)) continue;
|
|
1858
2029
|
if (node.loc.start.line !== token.loc.start.line || node.loc.end.line !== node.loc.start.line) {
|
|
1859
2030
|
return null;
|
|
1860
2031
|
}
|
|
1861
|
-
if (node.type ===
|
|
2032
|
+
if (node.type === import_utils14.AST_NODE_TYPES.VariableDeclaration && isTrivialInitializer(node)) {
|
|
1862
2033
|
return null;
|
|
1863
2034
|
}
|
|
1864
2035
|
return node;
|
|
@@ -1868,8 +2039,8 @@ function restatableStatementNodeBelow(comment, sourceCode) {
|
|
|
1868
2039
|
function isTrivialInitializer(node) {
|
|
1869
2040
|
return node.declarations.every((declarator) => {
|
|
1870
2041
|
const init = declarator.init;
|
|
1871
|
-
if (init == null || init.type ===
|
|
1872
|
-
return init.type ===
|
|
2042
|
+
if (init == null || init.type === import_utils14.AST_NODE_TYPES.Literal) return true;
|
|
2043
|
+
return init.type === import_utils14.AST_NODE_TYPES.ArrayExpression && init.elements.length === 0 || init.type === import_utils14.AST_NODE_TYPES.ObjectExpression && init.properties.length === 0;
|
|
1873
2044
|
});
|
|
1874
2045
|
}
|
|
1875
2046
|
function restatesStatementHead(body3, statement) {
|
|
@@ -1896,7 +2067,7 @@ function headTokens(source) {
|
|
|
1896
2067
|
}
|
|
1897
2068
|
|
|
1898
2069
|
// src/rules/_comment-edits.ts
|
|
1899
|
-
var
|
|
2070
|
+
var import_utils15 = require("@typescript-eslint/utils");
|
|
1900
2071
|
function physicalLineEnd(text, offset) {
|
|
1901
2072
|
const newline = text.indexOf("\n", offset);
|
|
1902
2073
|
return newline < 0 ? text.length : newline;
|
|
@@ -2019,7 +2190,7 @@ function ownsTestComments(context) {
|
|
|
2019
2190
|
if (!isTestFile(context)) return false;
|
|
2020
2191
|
const filename = scopedFilename(context);
|
|
2021
2192
|
const unambiguous = /(?:^|\/)(?:tests?|__tests__|fixtures|__fixtures__|__mocks__)\//u.test(filename) || /\.(?:test|spec|e2e|integration)\.[cm]?[jt]sx?$/u.test(filename);
|
|
2022
|
-
const framework = context.sourceCode.ast.body.some((statement) => statement.type ===
|
|
2193
|
+
const framework = context.sourceCode.ast.body.some((statement) => statement.type === import_utils16.AST_NODE_TYPES.ImportDeclaration && statement.importKind !== "type" && (statement.specifiers.length === 0 || statement.specifiers.some((specifier) => specifier.type !== import_utils16.AST_NODE_TYPES.ImportSpecifier || specifier.importKind !== "type")) && ["vitest", "@jest/globals", "@playwright/test", "bun:test", "node:test"].includes(statement.source.value));
|
|
2023
2194
|
return unambiguous || framework;
|
|
2024
2195
|
}
|
|
2025
2196
|
var no_test_comments_default = createRule({
|
|
@@ -2202,7 +2373,7 @@ function emptyCommentRange(text, comment) {
|
|
|
2202
2373
|
}
|
|
2203
2374
|
|
|
2204
2375
|
// src/rules/prefer-dependency-interface.ts
|
|
2205
|
-
var
|
|
2376
|
+
var import_utils17 = require("@typescript-eslint/utils");
|
|
2206
2377
|
var PREFER_DEPENDENCY_INTERFACE_DOCUMENTATION = {
|
|
2207
2378
|
defaultLevel: "warning",
|
|
2208
2379
|
summary: "Annotate retained collaborators with their existing interface when the consumer uses only that contract.",
|
|
@@ -2227,31 +2398,31 @@ var prefer_dependency_interface_default = createRule({
|
|
|
2227
2398
|
if (isGeneratedFile(context, context.sourceCode.text)) return {};
|
|
2228
2399
|
function contract(node) {
|
|
2229
2400
|
const concrete = definition(node);
|
|
2230
|
-
if (concrete?.type !==
|
|
2401
|
+
if (concrete?.type !== import_utils17.AST_NODE_TYPES.ClassDeclaration || concrete.abstract || concrete.superClass !== null || concrete.decorators.length !== 0 || concrete.typeParameters !== void 0 || concrete.implements.length !== 1) return null;
|
|
2231
2402
|
const heritage = concrete.implements[0];
|
|
2232
|
-
if (heritage?.expression.type !==
|
|
2403
|
+
if (heritage?.expression.type !== import_utils17.AST_NODE_TYPES.Identifier) return null;
|
|
2233
2404
|
const port = definition(heritage.expression);
|
|
2234
|
-
return port?.type ===
|
|
2405
|
+
return port?.type === import_utils17.AST_NODE_TYPES.TSInterfaceDeclaration && port.extends.length === 0 && port.typeParameters === void 0 ? port : null;
|
|
2235
2406
|
}
|
|
2236
2407
|
function definition(node) {
|
|
2237
|
-
const variable =
|
|
2408
|
+
const variable = import_utils17.ASTUtils.findVariable(context.sourceCode.getScope(node), node.name);
|
|
2238
2409
|
return variable?.defs.length === 1 ? variable.defs[0]?.node ?? null : null;
|
|
2239
2410
|
}
|
|
2240
2411
|
function usesOnlyInterface(owner, name, port) {
|
|
2241
2412
|
const members = /* @__PURE__ */ new Set();
|
|
2242
2413
|
for (const member3 of port.body.body) {
|
|
2243
|
-
if (member3.type !==
|
|
2414
|
+
if (member3.type !== import_utils17.AST_NODE_TYPES.TSMethodSignature && member3.type !== import_utils17.AST_NODE_TYPES.TSPropertySignature || member3.computed || member3.key.type !== import_utils17.AST_NODE_TYPES.Identifier) return false;
|
|
2244
2415
|
members.add(member3.key.name);
|
|
2245
2416
|
}
|
|
2246
2417
|
let uses = 0;
|
|
2247
2418
|
let compatible = true;
|
|
2248
2419
|
function visit(node) {
|
|
2249
|
-
if (node.type ===
|
|
2420
|
+
if (node.type === import_utils17.AST_NODE_TYPES.MemberExpression && node.object.type === import_utils17.AST_NODE_TYPES.ThisExpression && import_utils17.ASTUtils.getPropertyName(node) === name) {
|
|
2250
2421
|
uses += 1;
|
|
2251
2422
|
const parent = node.parent;
|
|
2252
|
-
if (parent.type !==
|
|
2423
|
+
if (parent.type !== import_utils17.AST_NODE_TYPES.MemberExpression || parent.object !== node || !members.has(import_utils17.ASTUtils.getPropertyName(parent) ?? "") || parent.parent.type === import_utils17.AST_NODE_TYPES.AssignmentExpression && parent.parent.left === parent || parent.parent.type === import_utils17.AST_NODE_TYPES.UpdateExpression) compatible = false;
|
|
2253
2424
|
}
|
|
2254
|
-
if (node !== owner && (node.type ===
|
|
2425
|
+
if (node !== owner && (node.type === import_utils17.AST_NODE_TYPES.ClassDeclaration || node.type === import_utils17.AST_NODE_TYPES.ClassExpression)) return;
|
|
2255
2426
|
forEachOwnAstChild(node, visit);
|
|
2256
2427
|
}
|
|
2257
2428
|
visit(owner);
|
|
@@ -2261,9 +2432,9 @@ var prefer_dependency_interface_default = createRule({
|
|
|
2261
2432
|
TSParameterProperty(node) {
|
|
2262
2433
|
const parameter = node.parameter;
|
|
2263
2434
|
const constructor = node.parent.parent;
|
|
2264
|
-
if (!node.readonly || node.accessibility !== "private" || node.decorators.length !== 0 || parameter.type !==
|
|
2435
|
+
if (!node.readonly || node.accessibility !== "private" || node.decorators.length !== 0 || parameter.type !== import_utils17.AST_NODE_TYPES.Identifier || parameter.typeAnnotation?.typeAnnotation.type !== import_utils17.AST_NODE_TYPES.TSTypeReference || parameter.typeAnnotation.typeAnnotation.typeName.type !== import_utils17.AST_NODE_TYPES.Identifier || constructor.type !== import_utils17.AST_NODE_TYPES.MethodDefinition || constructor.kind !== "constructor" || constructor.value.body?.body.length !== 0 || constructor.parent.type !== import_utils17.AST_NODE_TYPES.ClassBody) return;
|
|
2265
2436
|
const owner = constructor.parent.parent;
|
|
2266
|
-
if (owner.type !==
|
|
2437
|
+
if (owner.type !== import_utils17.AST_NODE_TYPES.ClassDeclaration && owner.type !== import_utils17.AST_NODE_TYPES.ClassExpression) return;
|
|
2267
2438
|
if (owner.decorators.length !== 0 || owner.typeParameters !== void 0) return;
|
|
2268
2439
|
const port = contract(parameter.typeAnnotation.typeAnnotation.typeName);
|
|
2269
2440
|
if (port !== null && usesOnlyInterface(owner, parameter.name, port)) context.report({ node: parameter.typeAnnotation, messageId: "interface", data: { contract: port.id.name } });
|
|
@@ -2273,7 +2444,7 @@ var prefer_dependency_interface_default = createRule({
|
|
|
2273
2444
|
});
|
|
2274
2445
|
|
|
2275
2446
|
// src/rules/no-mutating-input-with-result.ts
|
|
2276
|
-
var
|
|
2447
|
+
var import_utils18 = require("@typescript-eslint/utils");
|
|
2277
2448
|
var NO_MUTATING_INPUT_WITH_RESULT_DOCUMENTATION = {
|
|
2278
2449
|
defaultLevel: "warning",
|
|
2279
2450
|
summary: "Return replacement object values instead of writing input fields in result-returning functions.",
|
|
@@ -2291,8 +2462,8 @@ var NO_MUTATING_INPUT_WITH_RESULT_DOCUMENTATION = {
|
|
|
2291
2462
|
]
|
|
2292
2463
|
};
|
|
2293
2464
|
function command(annotation) {
|
|
2294
|
-
if (annotation.type ===
|
|
2295
|
-
if (annotation.type ===
|
|
2465
|
+
if (annotation.type === import_utils18.AST_NODE_TYPES.TSVoidKeyword || annotation.type === import_utils18.AST_NODE_TYPES.TSUndefinedKeyword || annotation.type === import_utils18.AST_NODE_TYPES.TSNeverKeyword) return true;
|
|
2466
|
+
if (annotation.type === import_utils18.AST_NODE_TYPES.TSTypeReference && annotation.typeName.type === import_utils18.AST_NODE_TYPES.Identifier && annotation.typeName.name === "Promise" && annotation.typeArguments?.params.length === 1) {
|
|
2296
2467
|
const result = annotation.typeArguments.params[0];
|
|
2297
2468
|
return result !== void 0 && command(result);
|
|
2298
2469
|
}
|
|
@@ -2307,35 +2478,35 @@ function fields(annotation, sourceCode) {
|
|
|
2307
2478
|
return names;
|
|
2308
2479
|
}
|
|
2309
2480
|
function membersOf(annotation, sourceCode) {
|
|
2310
|
-
if (annotation.type ===
|
|
2311
|
-
if (annotation.type !==
|
|
2312
|
-
const variable =
|
|
2481
|
+
if (annotation.type === import_utils18.AST_NODE_TYPES.TSTypeLiteral) return annotation.members;
|
|
2482
|
+
if (annotation.type !== import_utils18.AST_NODE_TYPES.TSTypeReference || annotation.typeName.type !== import_utils18.AST_NODE_TYPES.Identifier || annotation.typeArguments !== void 0) return [];
|
|
2483
|
+
const variable = import_utils18.ASTUtils.findVariable(sourceCode.getScope(annotation.typeName), annotation.typeName.name);
|
|
2313
2484
|
if (variable?.defs.length !== 1) return [];
|
|
2314
2485
|
const definition = variable.defs[0]?.node;
|
|
2315
2486
|
switch (definition?.type) {
|
|
2316
|
-
case
|
|
2487
|
+
case import_utils18.AST_NODE_TYPES.TSInterfaceDeclaration:
|
|
2317
2488
|
return definition.extends.length === 0 && definition.typeParameters === void 0 ? definition.body.body : [];
|
|
2318
|
-
case
|
|
2319
|
-
return definition.typeParameters === void 0 && definition.typeAnnotation.type ===
|
|
2320
|
-
case
|
|
2489
|
+
case import_utils18.AST_NODE_TYPES.TSTypeAliasDeclaration:
|
|
2490
|
+
return definition.typeParameters === void 0 && definition.typeAnnotation.type === import_utils18.AST_NODE_TYPES.TSTypeLiteral ? definition.typeAnnotation.members : [];
|
|
2491
|
+
case import_utils18.AST_NODE_TYPES.ClassDeclaration:
|
|
2321
2492
|
return definition.superClass === null && definition.typeParameters === void 0 && definition.decorators.length === 0 ? definition.body.body : [];
|
|
2322
2493
|
default:
|
|
2323
2494
|
return [];
|
|
2324
2495
|
}
|
|
2325
2496
|
}
|
|
2326
2497
|
function mutableField(member3) {
|
|
2327
|
-
if (member3.type !==
|
|
2328
|
-
if (member3.type ===
|
|
2329
|
-
if (member3.key.type ===
|
|
2330
|
-
return member3.key.type ===
|
|
2498
|
+
if (member3.type !== import_utils18.AST_NODE_TYPES.TSPropertySignature && member3.type !== import_utils18.AST_NODE_TYPES.PropertyDefinition || member3.readonly || member3.computed) return null;
|
|
2499
|
+
if (member3.type === import_utils18.AST_NODE_TYPES.PropertyDefinition && (member3.static || member3.accessibility === "private" || member3.accessibility === "protected")) return null;
|
|
2500
|
+
if (member3.key.type === import_utils18.AST_NODE_TYPES.Identifier) return member3.key.name;
|
|
2501
|
+
return member3.key.type === import_utils18.AST_NODE_TYPES.Literal && (typeof member3.key.value === "string" || typeof member3.key.value === "number") ? String(member3.key.value) : null;
|
|
2331
2502
|
}
|
|
2332
2503
|
function walkBody(node, visit) {
|
|
2333
|
-
if (node.type ===
|
|
2504
|
+
if (node.type === import_utils18.AST_NODE_TYPES.FunctionDeclaration || node.type === import_utils18.AST_NODE_TYPES.FunctionExpression || node.type === import_utils18.AST_NODE_TYPES.ArrowFunctionExpression || node.type === import_utils18.AST_NODE_TYPES.ClassDeclaration || node.type === import_utils18.AST_NODE_TYPES.ClassExpression) return;
|
|
2334
2505
|
visit(node);
|
|
2335
|
-
if (node.type ===
|
|
2506
|
+
if (node.type === import_utils18.AST_NODE_TYPES.BlockStatement) {
|
|
2336
2507
|
for (const statement of node.body) {
|
|
2337
2508
|
walkBody(statement, visit);
|
|
2338
|
-
if (statement.type ===
|
|
2509
|
+
if (statement.type === import_utils18.AST_NODE_TYPES.ReturnStatement || statement.type === import_utils18.AST_NODE_TYPES.ThrowStatement) break;
|
|
2339
2510
|
}
|
|
2340
2511
|
return;
|
|
2341
2512
|
}
|
|
@@ -2347,15 +2518,15 @@ function walkBody(node, visit) {
|
|
|
2347
2518
|
forEachOwnAstChild(node, (child) => walkBody(child, visit), (key) => key !== "typeAnnotation" && key !== "returnType");
|
|
2348
2519
|
}
|
|
2349
2520
|
function selectedChildren(node) {
|
|
2350
|
-
if (node.type ===
|
|
2521
|
+
if (node.type === import_utils18.AST_NODE_TYPES.IfStatement && node.test.type === import_utils18.AST_NODE_TYPES.Literal) {
|
|
2351
2522
|
const branch = node.test.value ? node.consequent : node.alternate;
|
|
2352
2523
|
return branch === null ? [node.test] : [node.test, branch];
|
|
2353
2524
|
}
|
|
2354
|
-
if (node.type ===
|
|
2525
|
+
if (node.type === import_utils18.AST_NODE_TYPES.LogicalExpression && node.left.type === import_utils18.AST_NODE_TYPES.Literal) {
|
|
2355
2526
|
const skips = node.operator === "&&" && !node.left.value || node.operator === "||" && !!node.left.value || node.operator === "??" && node.left.value !== null;
|
|
2356
2527
|
return skips ? [node.left] : [node.left, node.right];
|
|
2357
2528
|
}
|
|
2358
|
-
if (node.type ===
|
|
2529
|
+
if (node.type === import_utils18.AST_NODE_TYPES.ConditionalExpression && node.test.type === import_utils18.AST_NODE_TYPES.Literal) return [node.test, node.test.value ? node.consequent : node.alternate];
|
|
2359
2530
|
return null;
|
|
2360
2531
|
}
|
|
2361
2532
|
var no_mutating_input_with_result_default = createRule({
|
|
@@ -2376,23 +2547,23 @@ var no_mutating_input_with_result_default = createRule({
|
|
|
2376
2547
|
if (annotation === void 0 || command(annotation) || node.body === void 0) return;
|
|
2377
2548
|
const inputs = /* @__PURE__ */ new Map();
|
|
2378
2549
|
for (const parameter of node.params) {
|
|
2379
|
-
if (parameter.type !==
|
|
2380
|
-
const variable =
|
|
2550
|
+
if (parameter.type !== import_utils18.AST_NODE_TYPES.Identifier || parameter.typeAnnotation === void 0) continue;
|
|
2551
|
+
const variable = import_utils18.ASTUtils.findVariable(sourceCode.getScope(parameter), parameter.name);
|
|
2381
2552
|
if (variable === null || variable.references.some((reference) => reference.isWrite())) continue;
|
|
2382
2553
|
const names = fields(parameter.typeAnnotation.typeAnnotation, sourceCode);
|
|
2383
2554
|
if (names.size > 0) inputs.set(variable, names);
|
|
2384
2555
|
}
|
|
2385
2556
|
if (inputs.size === 0) return;
|
|
2386
|
-
let returned2 = node.body.type !==
|
|
2557
|
+
let returned2 = node.body.type !== import_utils18.AST_NODE_TYPES.BlockStatement;
|
|
2387
2558
|
const writes = [];
|
|
2388
2559
|
walkBody(node.body, (current) => {
|
|
2389
|
-
if (current.type ===
|
|
2390
|
-
const candidate2 = current.type ===
|
|
2560
|
+
if (current.type === import_utils18.AST_NODE_TYPES.ReturnStatement && current.argument !== null) returned2 = true;
|
|
2561
|
+
const candidate2 = current.type === import_utils18.AST_NODE_TYPES.AssignmentExpression ? current.left : current.type === import_utils18.AST_NODE_TYPES.UpdateExpression || current.type === import_utils18.AST_NODE_TYPES.UnaryExpression && current.operator === "delete" ? current.argument : null;
|
|
2391
2562
|
if (candidate2 === null) return;
|
|
2392
2563
|
const target = unwrapExpression(candidate2);
|
|
2393
|
-
if (target.type !==
|
|
2394
|
-
const variable =
|
|
2395
|
-
const property =
|
|
2564
|
+
if (target.type !== import_utils18.AST_NODE_TYPES.MemberExpression || target.object.type !== import_utils18.AST_NODE_TYPES.Identifier) return;
|
|
2565
|
+
const variable = import_utils18.ASTUtils.findVariable(sourceCode.getScope(target.object), target.object.name);
|
|
2566
|
+
const property = import_utils18.ASTUtils.getPropertyName(target);
|
|
2396
2567
|
if (variable !== null && property !== null && inputs.get(variable)?.has(property)) writes.push({ node: target, name: target.object.name });
|
|
2397
2568
|
});
|
|
2398
2569
|
const first = writes[0];
|
|
@@ -2403,26 +2574,26 @@ var no_mutating_input_with_result_default = createRule({
|
|
|
2403
2574
|
});
|
|
2404
2575
|
|
|
2405
2576
|
// src/rules/no-negative-only-http-status-assertion.ts
|
|
2406
|
-
var
|
|
2577
|
+
var import_utils23 = require("@typescript-eslint/utils");
|
|
2407
2578
|
|
|
2408
2579
|
// src/rules/_native-fetch-reference.ts
|
|
2409
|
-
var
|
|
2580
|
+
var import_utils21 = require("@typescript-eslint/utils");
|
|
2410
2581
|
|
|
2411
2582
|
// src/rules/_native-runtime-unchanged.ts
|
|
2412
|
-
var
|
|
2583
|
+
var import_utils20 = require("@typescript-eslint/utils");
|
|
2413
2584
|
|
|
2414
2585
|
// src/rules/_static-string.ts
|
|
2415
|
-
var
|
|
2586
|
+
var import_utils19 = require("@typescript-eslint/utils");
|
|
2416
2587
|
function staticString(node) {
|
|
2417
2588
|
if (node === void 0) return null;
|
|
2418
2589
|
const value = unwrapExpression(node);
|
|
2419
|
-
if (value.type ===
|
|
2420
|
-
return value.type ===
|
|
2590
|
+
if (value.type === import_utils19.AST_NODE_TYPES.Literal && typeof value.value === "string") return value.value;
|
|
2591
|
+
return value.type === import_utils19.AST_NODE_TYPES.TemplateLiteral && value.expressions.length === 0 ? value.quasis[0]?.value.cooked ?? null : null;
|
|
2421
2592
|
}
|
|
2422
2593
|
var SCOPED_STRING_VALUES = /* @__PURE__ */ new WeakMap();
|
|
2423
2594
|
function scopedStaticString(node, sourceCode) {
|
|
2424
2595
|
let value = unwrapExpression(node);
|
|
2425
|
-
if (value.type !==
|
|
2596
|
+
if (value.type !== import_utils19.AST_NODE_TYPES.Identifier) return staticString(value);
|
|
2426
2597
|
let values = SCOPED_STRING_VALUES.get(sourceCode);
|
|
2427
2598
|
if (values === void 0) {
|
|
2428
2599
|
values = /* @__PURE__ */ new WeakMap();
|
|
@@ -2431,8 +2602,8 @@ function scopedStaticString(node, sourceCode) {
|
|
|
2431
2602
|
const seen = /* @__PURE__ */ new Set();
|
|
2432
2603
|
const pending = [];
|
|
2433
2604
|
let result = null;
|
|
2434
|
-
while (value.type ===
|
|
2435
|
-
const binding3 =
|
|
2605
|
+
while (value.type === import_utils19.AST_NODE_TYPES.Identifier) {
|
|
2606
|
+
const binding3 = import_utils19.ASTUtils.findVariable(sourceCode.getScope(value), value.name);
|
|
2436
2607
|
if (binding3 === null || seen.has(binding3)) break;
|
|
2437
2608
|
if (values.has(binding3)) {
|
|
2438
2609
|
result = values.get(binding3) ?? null;
|
|
@@ -2441,17 +2612,17 @@ function scopedStaticString(node, sourceCode) {
|
|
|
2441
2612
|
seen.add(binding3);
|
|
2442
2613
|
pending.push(binding3);
|
|
2443
2614
|
const definition = binding3.defs.length === 1 ? binding3.defs[0] : void 0;
|
|
2444
|
-
if (definition?.type !== "Variable" || definition.node.id.type !==
|
|
2615
|
+
if (definition?.type !== "Variable" || definition.node.id.type !== import_utils19.AST_NODE_TYPES.Identifier || definition.node.init === null || binding3.references.some((reference) => reference.isWrite() && reference.init !== true)) break;
|
|
2445
2616
|
value = unwrapExpression(definition.node.init);
|
|
2446
|
-
if (value.type !==
|
|
2617
|
+
if (value.type !== import_utils19.AST_NODE_TYPES.Identifier) result = staticString(value);
|
|
2447
2618
|
}
|
|
2448
2619
|
for (const binding3 of pending) values.set(binding3, result);
|
|
2449
2620
|
return result;
|
|
2450
2621
|
}
|
|
2451
2622
|
function staticPropertyName(node, sourceCode) {
|
|
2452
|
-
const direct =
|
|
2623
|
+
const direct = import_utils19.ASTUtils.getPropertyName(node);
|
|
2453
2624
|
if (direct !== null || !node.computed) return direct;
|
|
2454
|
-
const key = node.type ===
|
|
2625
|
+
const key = node.type === import_utils19.AST_NODE_TYPES.MemberExpression ? node.property : node.key;
|
|
2455
2626
|
return scopedStaticString(key, sourceCode);
|
|
2456
2627
|
}
|
|
2457
2628
|
|
|
@@ -2462,7 +2633,7 @@ function nativeRuntimeUnchanged(sourceCode, name) {
|
|
|
2462
2633
|
const index = runtimeIndex(sourceCode);
|
|
2463
2634
|
const cached = index.results.get(name);
|
|
2464
2635
|
if (cached !== void 0) return cached;
|
|
2465
|
-
const changed = index.nodes.some((node) => node.type ===
|
|
2636
|
+
const changed = index.nodes.some((node) => node.type === import_utils20.AST_NODE_TYPES.MemberExpression && staticPropertyName(node, sourceCode) === "constructor" || name === "fetch" && node.type === import_utils20.AST_NODE_TYPES.Property && node.parent.type === import_utils20.AST_NODE_TYPES.ObjectPattern && staticPropertyName(node, sourceCode) === "constructor" || name === "RegExp" && node.type === import_utils20.AST_NODE_TYPES.Literal && "regex" in node) || index.references.some((reference) => (name !== "fetch" || !typeOnlyReference(reference)) && unsafeReference(reference.identifier, sourceCode, name, index));
|
|
2466
2637
|
index.results.set(name, !changed);
|
|
2467
2638
|
return !changed;
|
|
2468
2639
|
}
|
|
@@ -2491,8 +2662,8 @@ function unsafeReference(node, sourceCode, name, index) {
|
|
|
2491
2662
|
if (!GLOBAL_OBJECTS.has(node.name)) return false;
|
|
2492
2663
|
const value = outerExpression(node);
|
|
2493
2664
|
const property = value.parent;
|
|
2494
|
-
if (name === "fetch" && property?.type ===
|
|
2495
|
-
if (property?.type !==
|
|
2665
|
+
if (name === "fetch" && property?.type === import_utils20.AST_NODE_TYPES.UnaryExpression && property.operator === "typeof") return false;
|
|
2666
|
+
if (property?.type !== import_utils20.AST_NODE_TYPES.MemberExpression || property.object !== value) {
|
|
2496
2667
|
return name !== "fetch" || !fetchProjection(value, sourceCode, index);
|
|
2497
2668
|
}
|
|
2498
2669
|
const key = staticPropertyName(property, sourceCode);
|
|
@@ -2501,21 +2672,21 @@ function unsafeReference(node, sourceCode, name, index) {
|
|
|
2501
2672
|
return key === name && !(name === "fetch" ? fetchRead(property, sourceCode, index) : nativeRead(property, name));
|
|
2502
2673
|
}
|
|
2503
2674
|
function ambient(node, sourceCode) {
|
|
2504
|
-
const variable =
|
|
2675
|
+
const variable = import_utils20.ASTUtils.findVariable(sourceCode.getScope(node), node.name);
|
|
2505
2676
|
return variable === null || variable.defs.length === 0;
|
|
2506
2677
|
}
|
|
2507
2678
|
function fetchUse(node, sourceCode) {
|
|
2508
2679
|
const value = outerExpression(node);
|
|
2509
2680
|
const parent = value.parent;
|
|
2510
|
-
if (parent?.type ===
|
|
2511
|
-
if (parent?.type !==
|
|
2681
|
+
if (parent?.type === import_utils20.AST_NODE_TYPES.CallExpression && parent.callee === value || parent?.type === import_utils20.AST_NODE_TYPES.UnaryExpression && parent.operator === "typeof") return true;
|
|
2682
|
+
if (parent?.type !== import_utils20.AST_NODE_TYPES.VariableDeclarator || parent.init !== value || parent.id.type !== import_utils20.AST_NODE_TYPES.Identifier) return false;
|
|
2512
2683
|
return stableConstBinding(parent.id, sourceCode) ?? false;
|
|
2513
2684
|
}
|
|
2514
2685
|
function stableConstBinding(node, sourceCode) {
|
|
2515
|
-
const binding3 =
|
|
2686
|
+
const binding3 = import_utils20.ASTUtils.findVariable(sourceCode.getScope(node), node.name);
|
|
2516
2687
|
if (binding3 === null || binding3.defs.length !== 1) return null;
|
|
2517
2688
|
const [definition] = binding3.defs;
|
|
2518
|
-
return definition?.type === "Variable" && definition.parent.kind === "const" && definition.node.init !== null && definition.parent.parent.type !==
|
|
2689
|
+
return definition?.type === "Variable" && definition.parent.kind === "const" && definition.node.init !== null && definition.parent.parent.type !== import_utils20.AST_NODE_TYPES.ExportNamedDeclaration && !binding3.references.some((reference) => reference.isWrite() && reference.init !== true) ? binding3 : null;
|
|
2519
2690
|
}
|
|
2520
2691
|
function fetchRead(node, sourceCode, index) {
|
|
2521
2692
|
const use = fetchUse(node, sourceCode);
|
|
@@ -2558,18 +2729,18 @@ function fetchAliasCaptures(binding3, sourceCode) {
|
|
|
2558
2729
|
}
|
|
2559
2730
|
function fetchProjection(node, sourceCode, index) {
|
|
2560
2731
|
const declaration = node.parent;
|
|
2561
|
-
if (declaration?.type !==
|
|
2732
|
+
if (declaration?.type !== import_utils20.AST_NODE_TYPES.VariableDeclarator || declaration.init !== node || declaration.id.type !== import_utils20.AST_NODE_TYPES.ObjectPattern || declaration.id.properties.length !== 1) return false;
|
|
2562
2733
|
const [property] = declaration.id.properties;
|
|
2563
|
-
if (property?.type !==
|
|
2734
|
+
if (property?.type !== import_utils20.AST_NODE_TYPES.Property || staticPropertyName(property, sourceCode) !== "fetch" || property.value.type !== import_utils20.AST_NODE_TYPES.Identifier) return false;
|
|
2564
2735
|
const binding3 = stableConstBinding(property.value, sourceCode);
|
|
2565
2736
|
return binding3 !== null && fetchAliasRead(binding3, sourceCode, index);
|
|
2566
2737
|
}
|
|
2567
2738
|
function nativeRead(node, name) {
|
|
2568
2739
|
const value = outerExpression(node);
|
|
2569
2740
|
const parent = value.parent;
|
|
2570
|
-
if (parent?.type ===
|
|
2741
|
+
if (parent?.type === import_utils20.AST_NODE_TYPES.UnaryExpression && parent.operator === "typeof") return true;
|
|
2571
2742
|
if (name !== "Error") return false;
|
|
2572
|
-
return parent?.type ===
|
|
2743
|
+
return parent?.type === import_utils20.AST_NODE_TYPES.NewExpression && parent.callee === value || parent?.type === import_utils20.AST_NODE_TYPES.BinaryExpression && parent.operator === "instanceof" && parent.right === value;
|
|
2573
2744
|
}
|
|
2574
2745
|
|
|
2575
2746
|
// src/rules/_native-fetch-reference.ts
|
|
@@ -2579,34 +2750,34 @@ function nativeFetchReference(node, sourceCode) {
|
|
|
2579
2750
|
}
|
|
2580
2751
|
function lexicalFetchReference(node, sourceCode, seen = /* @__PURE__ */ new Set()) {
|
|
2581
2752
|
const expression = unwrapExpression(node);
|
|
2582
|
-
if (expression.type ===
|
|
2753
|
+
if (expression.type === import_utils21.AST_NODE_TYPES.MemberExpression) {
|
|
2583
2754
|
return staticPropertyName(expression, sourceCode) === "fetch" && globalReceiver(expression.object, sourceCode);
|
|
2584
2755
|
}
|
|
2585
|
-
if (expression.type !==
|
|
2586
|
-
const binding3 =
|
|
2756
|
+
if (expression.type !== import_utils21.AST_NODE_TYPES.Identifier) return false;
|
|
2757
|
+
const binding3 = import_utils21.ASTUtils.findVariable(sourceCode.getScope(expression), expression.name);
|
|
2587
2758
|
if (binding3 === null || binding3.defs.length === 0) return expression.name === "fetch";
|
|
2588
2759
|
if (seen.has(binding3) || seen.size >= 8 || binding3.defs.length !== 1 || binding3.references.some((reference) => reference.isWrite() && reference.init !== true)) return false;
|
|
2589
2760
|
seen.add(binding3);
|
|
2590
2761
|
const [definition] = binding3.defs;
|
|
2591
2762
|
if (definition?.type !== "Variable" || definition.parent.kind !== "const" || definition.node.init === null) return false;
|
|
2592
|
-
if (definition.node.id.type ===
|
|
2763
|
+
if (definition.node.id.type === import_utils21.AST_NODE_TYPES.Identifier) {
|
|
2593
2764
|
return lexicalFetchReference(definition.node.init, sourceCode, seen);
|
|
2594
2765
|
}
|
|
2595
|
-
return definition.node.id.type ===
|
|
2766
|
+
return definition.node.id.type === import_utils21.AST_NODE_TYPES.ObjectPattern && globalReceiver(definition.node.init, sourceCode) && definition.node.id.properties.some((property) => property.type === import_utils21.AST_NODE_TYPES.Property && staticPropertyName(property, sourceCode) === "fetch" && property.value.type === import_utils21.AST_NODE_TYPES.Identifier && import_utils21.ASTUtils.findVariable(sourceCode.getScope(property.value), property.value.name) === binding3);
|
|
2596
2767
|
}
|
|
2597
2768
|
function globalReceiver(node, sourceCode) {
|
|
2598
2769
|
const receiver = unwrapExpression(node);
|
|
2599
|
-
return receiver.type ===
|
|
2770
|
+
return receiver.type === import_utils21.AST_NODE_TYPES.Identifier && GLOBAL_RECEIVERS2.has(receiver.name) && !import_utils21.ASTUtils.findVariable(sourceCode.getScope(receiver), receiver.name)?.defs.length;
|
|
2600
2771
|
}
|
|
2601
2772
|
|
|
2602
2773
|
// src/rules/_test-mock-provenance.ts
|
|
2603
|
-
var
|
|
2774
|
+
var import_utils22 = require("@typescript-eslint/utils");
|
|
2604
2775
|
function importedTestMockNamespace(source, identifier) {
|
|
2605
|
-
const binding3 =
|
|
2776
|
+
const binding3 = import_utils22.ASTUtils.findVariable(source.getScope(identifier), identifier.name);
|
|
2606
2777
|
const importedBinding = runtimeImportBinding(binding3);
|
|
2607
|
-
if (importedBinding === null || importedBinding.specifier.type !==
|
|
2778
|
+
if (importedBinding === null || importedBinding.specifier.type !== import_utils22.AST_NODE_TYPES.ImportSpecifier) return null;
|
|
2608
2779
|
const specifier = importedBinding.specifier;
|
|
2609
|
-
const imported = specifier.imported.type ===
|
|
2780
|
+
const imported = specifier.imported.type === import_utils22.AST_NODE_TYPES.Identifier ? specifier.imported.name : specifier.imported.value;
|
|
2610
2781
|
const module2 = importedBinding.module;
|
|
2611
2782
|
if (module2 === "vitest" && (imported === "vi" || imported === "vitest")) return "vitest";
|
|
2612
2783
|
if (module2 === "@jest/globals" && imported === "jest") return "jest";
|
|
@@ -2614,12 +2785,12 @@ function importedTestMockNamespace(source, identifier) {
|
|
|
2614
2785
|
}
|
|
2615
2786
|
function isUnshadowedTestMockGlobal(source, identifier) {
|
|
2616
2787
|
if (identifier.name !== "vi" && identifier.name !== "jest") return false;
|
|
2617
|
-
const binding3 =
|
|
2788
|
+
const binding3 = import_utils22.ASTUtils.findVariable(source.getScope(identifier), identifier.name);
|
|
2618
2789
|
return binding3 === null || binding3.defs.length === 0 && !binding3.references.some((reference) => reference.isWrite());
|
|
2619
2790
|
}
|
|
2620
2791
|
var TEST_FRAMEWORK_MODULES = /* @__PURE__ */ new Set(["@jest/globals", "@playwright/test", "bun:test", "node:test", "vitest"]);
|
|
2621
2792
|
function runtimeTestFrameworkName(source, identifier, kind) {
|
|
2622
|
-
const binding3 =
|
|
2793
|
+
const binding3 = import_utils22.ASTUtils.findVariable(source.getScope(identifier), identifier.name);
|
|
2623
2794
|
if (binding3 === null || binding3.defs.length === 0) {
|
|
2624
2795
|
return binding3?.references.some((reference) => reference.isWrite()) ? null : identifier.name;
|
|
2625
2796
|
}
|
|
@@ -2627,22 +2798,22 @@ function runtimeTestFrameworkName(source, identifier, kind) {
|
|
|
2627
2798
|
if (importedBinding === null) return null;
|
|
2628
2799
|
const { specifier, module: module2 } = importedBinding;
|
|
2629
2800
|
const isNodeAssertion = kind === "assertion" && (module2 === "node:assert" || module2 === "node:assert/strict");
|
|
2630
|
-
if (specifier.type ===
|
|
2801
|
+
if (specifier.type === import_utils22.AST_NODE_TYPES.ImportSpecifier) {
|
|
2631
2802
|
if (isNodeAssertion) return "assert";
|
|
2632
2803
|
if (!TEST_FRAMEWORK_MODULES.has(module2)) return null;
|
|
2633
|
-
const imported = specifier.imported.type ===
|
|
2804
|
+
const imported = specifier.imported.type === import_utils22.AST_NODE_TYPES.Identifier ? specifier.imported.name : specifier.imported.value;
|
|
2634
2805
|
return imported;
|
|
2635
2806
|
}
|
|
2636
2807
|
if (isNodeAssertion) return "assert";
|
|
2637
|
-
return kind === "test" && module2 === "node:test" && specifier.type ===
|
|
2808
|
+
return kind === "test" && module2 === "node:test" && specifier.type === import_utils22.AST_NODE_TYPES.ImportDefaultSpecifier ? "test" : null;
|
|
2638
2809
|
}
|
|
2639
2810
|
function runtimeImportBinding(binding3) {
|
|
2640
2811
|
if (binding3?.defs.length !== 1) return null;
|
|
2641
2812
|
const definition = binding3.defs[0];
|
|
2642
|
-
if (definition?.type !== "ImportBinding" || definition.parent.type !==
|
|
2813
|
+
if (definition?.type !== "ImportBinding" || definition.parent.type !== import_utils22.AST_NODE_TYPES.ImportDeclaration || definition.parent.importKind === "type") return null;
|
|
2643
2814
|
const specifier = definition.node;
|
|
2644
|
-
if (specifier.type !==
|
|
2645
|
-
if (specifier.type ===
|
|
2815
|
+
if (specifier.type !== import_utils22.AST_NODE_TYPES.ImportSpecifier && specifier.type !== import_utils22.AST_NODE_TYPES.ImportDefaultSpecifier && specifier.type !== import_utils22.AST_NODE_TYPES.ImportNamespaceSpecifier) return null;
|
|
2816
|
+
if (specifier.type === import_utils22.AST_NODE_TYPES.ImportSpecifier && specifier.importKind === "type") return null;
|
|
2646
2817
|
return { module: definition.parent.source.value, specifier };
|
|
2647
2818
|
}
|
|
2648
2819
|
function vitestFixtureTestName(source, identifier) {
|
|
@@ -2650,24 +2821,24 @@ function vitestFixtureTestName(source, identifier) {
|
|
|
2650
2821
|
}
|
|
2651
2822
|
function fixtureTestName(node, source, seen) {
|
|
2652
2823
|
node = unwrapExpression(node);
|
|
2653
|
-
if (node.type ===
|
|
2824
|
+
if (node.type === import_utils22.AST_NODE_TYPES.CallExpression) {
|
|
2654
2825
|
const callee = unwrapExpression(node.callee);
|
|
2655
|
-
return !node.optional && callee.type ===
|
|
2826
|
+
return !node.optional && callee.type === import_utils22.AST_NODE_TYPES.MemberExpression && !callee.optional && import_utils22.ASTUtils.getPropertyName(callee) === "extend" && node.arguments.length > 0 && !node.arguments.some((argument) => argument.type === import_utils22.AST_NODE_TYPES.SpreadElement) ? fixtureTestName(callee.object, source, seen) : null;
|
|
2656
2827
|
}
|
|
2657
|
-
if (node.type !==
|
|
2658
|
-
const binding3 =
|
|
2828
|
+
if (node.type !== import_utils22.AST_NODE_TYPES.Identifier) return null;
|
|
2829
|
+
const binding3 = import_utils22.ASTUtils.findVariable(source.getScope(node), node.name);
|
|
2659
2830
|
if (binding3 === null || seen.has(binding3) || !unchangedFixtureApi(binding3)) return null;
|
|
2660
2831
|
seen.add(binding3);
|
|
2661
2832
|
const imported = runtimeImportBinding(binding3);
|
|
2662
|
-
if (imported?.module === "vitest" && imported.specifier.type ===
|
|
2833
|
+
if (imported?.module === "vitest" && imported.specifier.type === import_utils22.AST_NODE_TYPES.ImportSpecifier) {
|
|
2663
2834
|
const name = imported.specifier.imported;
|
|
2664
|
-
const value = name.type ===
|
|
2835
|
+
const value = name.type === import_utils22.AST_NODE_TYPES.Identifier ? name.name : name.value;
|
|
2665
2836
|
return value === "test" || value === "it" ? value : null;
|
|
2666
2837
|
}
|
|
2667
2838
|
const definition = binding3.defs[0];
|
|
2668
|
-
if (binding3.defs.length !== 1 || definition?.node.type !==
|
|
2839
|
+
if (binding3.defs.length !== 1 || definition?.node.type !== import_utils22.AST_NODE_TYPES.VariableDeclarator || definition.node.id.type !== import_utils22.AST_NODE_TYPES.Identifier || definition.node.parent.kind !== "const" || definition.node.init === null || definition.node.init.range[1] > node.range[0]) return null;
|
|
2669
2840
|
const initializer = unwrapExpression(definition.node.init);
|
|
2670
|
-
return initializer.type ===
|
|
2841
|
+
return initializer.type === import_utils22.AST_NODE_TYPES.CallExpression ? fixtureTestName(initializer, source, seen) : null;
|
|
2671
2842
|
}
|
|
2672
2843
|
var FIXTURE_API_STABILITY = /* @__PURE__ */ new WeakMap();
|
|
2673
2844
|
function unchangedFixtureApi(binding3) {
|
|
@@ -2677,9 +2848,9 @@ function unchangedFixtureApi(binding3) {
|
|
|
2677
2848
|
if (reference.isWrite()) return reference.init === true;
|
|
2678
2849
|
if (reference.isTypeReference && !reference.isValueReference) return true;
|
|
2679
2850
|
let use = outerExpression(reference.identifier);
|
|
2680
|
-
while (use.parent?.type ===
|
|
2851
|
+
while (use.parent?.type === import_utils22.AST_NODE_TYPES.MemberExpression && use.parent.object === use) use = outerExpression(use.parent);
|
|
2681
2852
|
const parent = use.parent;
|
|
2682
|
-
return parent?.type ===
|
|
2853
|
+
return parent?.type === import_utils22.AST_NODE_TYPES.CallExpression && parent.callee === use || parent?.type === import_utils22.AST_NODE_TYPES.ExportSpecifier || parent?.type === import_utils22.AST_NODE_TYPES.ExportDefaultDeclaration || parent?.type === import_utils22.AST_NODE_TYPES.TSTypeQuery || parent?.type === import_utils22.AST_NODE_TYPES.UnaryExpression && parent.operator === "typeof";
|
|
2683
2854
|
});
|
|
2684
2855
|
FIXTURE_API_STABILITY.set(binding3, unchanged);
|
|
2685
2856
|
return unchanged;
|
|
@@ -2709,72 +2880,72 @@ var NO_NEGATIVE_ONLY_HTTP_STATUS_ASSERTION_DOCUMENTATION = {
|
|
|
2709
2880
|
]
|
|
2710
2881
|
};
|
|
2711
2882
|
function statusAssertion(source, call) {
|
|
2712
|
-
if (call.arguments.length !== 1 || call.arguments[0]?.type !==
|
|
2713
|
-
const matcher =
|
|
2883
|
+
if (call.arguments.length !== 1 || call.arguments[0]?.type !== import_utils23.AST_NODE_TYPES.Literal || typeof call.arguments[0].value !== "number" || call.callee.type !== import_utils23.AST_NODE_TYPES.MemberExpression) return null;
|
|
2884
|
+
const matcher = import_utils23.ASTUtils.getPropertyName(call.callee);
|
|
2714
2885
|
if (matcher === null) return null;
|
|
2715
2886
|
let object = unwrapExpression(call.callee.object);
|
|
2716
|
-
const negative = object.type ===
|
|
2717
|
-
if (negative && object.type ===
|
|
2718
|
-
if (object.type !==
|
|
2887
|
+
const negative = object.type === import_utils23.AST_NODE_TYPES.MemberExpression && import_utils23.ASTUtils.getPropertyName(object) === "not";
|
|
2888
|
+
if (negative && object.type === import_utils23.AST_NODE_TYPES.MemberExpression) object = unwrapExpression(object.object);
|
|
2889
|
+
if (object.type !== import_utils23.AST_NODE_TYPES.CallExpression || object.arguments.length !== 1 || object.callee.type !== import_utils23.AST_NODE_TYPES.Identifier || runtimeTestFrameworkName(source, object.callee, "assertion") !== "expect") return null;
|
|
2719
2890
|
const argument = object.arguments[0];
|
|
2720
|
-
const response = argument === void 0 || argument.type ===
|
|
2891
|
+
const response = argument === void 0 || argument.type === import_utils23.AST_NODE_TYPES.SpreadElement ? null : fetchResponse(source, argument);
|
|
2721
2892
|
return response === null ? null : { response, expected: call.arguments[0].value, matcher, negative };
|
|
2722
2893
|
}
|
|
2723
2894
|
function fetchResponse(source, value) {
|
|
2724
2895
|
const node = unwrapExpression(value);
|
|
2725
|
-
if (node.type !==
|
|
2896
|
+
if (node.type !== import_utils23.AST_NODE_TYPES.MemberExpression || import_utils23.ASTUtils.getPropertyName(node) !== "status" || node.object.type !== import_utils23.AST_NODE_TYPES.Identifier) return null;
|
|
2726
2897
|
return responseBinding(source, node.object);
|
|
2727
2898
|
}
|
|
2728
2899
|
function responseBinding(source, node, seen = /* @__PURE__ */ new Set()) {
|
|
2729
|
-
const variable =
|
|
2900
|
+
const variable = import_utils23.ASTUtils.findVariable(source.getScope(node), node.name);
|
|
2730
2901
|
const definition = variable?.defs[0]?.node;
|
|
2731
2902
|
if (variable?.defs.length !== 1 || seen.has(variable) || variable.references.some((reference) => reference.isWrite() && !reference.init)) return null;
|
|
2732
2903
|
seen.add(variable);
|
|
2733
2904
|
const parameter = variable.defs[0];
|
|
2734
|
-
if (parameter?.type === "Parameter" && parameter.name.type ===
|
|
2905
|
+
if (parameter?.type === "Parameter" && parameter.name.type === import_utils23.AST_NODE_TYPES.Identifier) {
|
|
2735
2906
|
const annotation = parameter.name.typeAnnotation?.typeAnnotation;
|
|
2736
|
-
return annotation?.type ===
|
|
2907
|
+
return annotation?.type === import_utils23.AST_NODE_TYPES.TSTypeReference && annotation.typeName.type === import_utils23.AST_NODE_TYPES.Identifier && annotation.typeName.name === "Response" && (import_utils23.ASTUtils.findVariable(source.getScope(annotation.typeName), "Response")?.defs.length ?? 0) === 0 ? variable : null;
|
|
2737
2908
|
}
|
|
2738
|
-
if (definition?.type !==
|
|
2909
|
+
if (definition?.type !== import_utils23.AST_NODE_TYPES.VariableDeclarator || definition.parent.kind !== "const" || definition.init === null) return null;
|
|
2739
2910
|
let initial = unwrapExpression(definition.init);
|
|
2740
|
-
if (initial.type ===
|
|
2741
|
-
if (initial.type ===
|
|
2911
|
+
if (initial.type === import_utils23.AST_NODE_TYPES.AwaitExpression) initial = unwrapExpression(initial.argument);
|
|
2912
|
+
if (initial.type === import_utils23.AST_NODE_TYPES.Identifier) return responseBinding(source, initial, seen);
|
|
2742
2913
|
return nativeResponse(initial, source) ? variable : null;
|
|
2743
2914
|
}
|
|
2744
2915
|
function nativeResponse(initial, source) {
|
|
2745
|
-
if (initial.type ===
|
|
2746
|
-
if (initial.type ===
|
|
2747
|
-
if (initial.type !==
|
|
2916
|
+
if (initial.type === import_utils23.AST_NODE_TYPES.NewExpression && initial.callee.type === import_utils23.AST_NODE_TYPES.Identifier && initial.callee.name === "Response" && (import_utils23.ASTUtils.findVariable(source.getScope(initial.callee), "Response")?.defs.length ?? 0) === 0) return true;
|
|
2917
|
+
if (initial.type === import_utils23.AST_NODE_TYPES.CallExpression && nativeFetchReference(initial.callee, source)) return true;
|
|
2918
|
+
if (initial.type !== import_utils23.AST_NODE_TYPES.CallExpression || initial.callee.type !== import_utils23.AST_NODE_TYPES.Identifier) return false;
|
|
2748
2919
|
const callee = initial.callee;
|
|
2749
|
-
const binding3 =
|
|
2920
|
+
const binding3 = import_utils23.ASTUtils.findVariable(source.getScope(callee), callee.name);
|
|
2750
2921
|
if ((binding3?.defs.length ?? 0) === 0) return callee.name === "fetch";
|
|
2751
2922
|
const imported = binding3?.defs[0];
|
|
2752
|
-
if (binding3?.defs.length !== 1 || imported?.type !== "ImportBinding" || imported.parent.type !==
|
|
2923
|
+
if (binding3?.defs.length !== 1 || imported?.type !== "ImportBinding" || imported.parent.type !== import_utils23.AST_NODE_TYPES.ImportDeclaration || imported.parent.importKind === "type" || !FETCH_MODULES.has(imported.parent.source.value)) return false;
|
|
2753
2924
|
const specifier = imported.node;
|
|
2754
|
-
if (specifier.type ===
|
|
2755
|
-
if (specifier.type !==
|
|
2756
|
-
const importedName7 = specifier.imported.type ===
|
|
2925
|
+
if (specifier.type === import_utils23.AST_NODE_TYPES.ImportDefaultSpecifier) return imported.parent.source.value === "node-fetch";
|
|
2926
|
+
if (specifier.type !== import_utils23.AST_NODE_TYPES.ImportSpecifier || specifier.importKind === "type") return false;
|
|
2927
|
+
const importedName7 = specifier.imported.type === import_utils23.AST_NODE_TYPES.Identifier ? specifier.imported.name : specifier.imported.value;
|
|
2757
2928
|
return importedName7 === "fetch";
|
|
2758
2929
|
}
|
|
2759
2930
|
function enclosingTest(source, node) {
|
|
2760
2931
|
for (let current = node.parent; current != null; current = current.parent) {
|
|
2761
|
-
if (current.type ===
|
|
2762
|
-
if (current.type !==
|
|
2932
|
+
if (current.type === import_utils23.AST_NODE_TYPES.FunctionDeclaration) return null;
|
|
2933
|
+
if (current.type !== import_utils23.AST_NODE_TYPES.ArrowFunctionExpression && current.type !== import_utils23.AST_NODE_TYPES.FunctionExpression) continue;
|
|
2763
2934
|
const registration2 = directArgumentCall(current);
|
|
2764
2935
|
const callee = registration2?.callee;
|
|
2765
|
-
if (callee?.type !==
|
|
2936
|
+
if (callee?.type !== import_utils23.AST_NODE_TYPES.Identifier) return null;
|
|
2766
2937
|
const name = runtimeTestFrameworkName(source, callee, "test") ?? vitestFixtureTestName(source, callee);
|
|
2767
2938
|
return name === "test" || name === "it" ? current : null;
|
|
2768
2939
|
}
|
|
2769
2940
|
return null;
|
|
2770
2941
|
}
|
|
2771
2942
|
function hasExactStatus(source, test, response) {
|
|
2772
|
-
if (test.body.type !==
|
|
2943
|
+
if (test.body.type !== import_utils23.AST_NODE_TYPES.BlockStatement) return false;
|
|
2773
2944
|
return test.body.body.some((statement) => {
|
|
2774
|
-
if (statement.type !==
|
|
2945
|
+
if (statement.type !== import_utils23.AST_NODE_TYPES.ExpressionStatement) return false;
|
|
2775
2946
|
let expression = unwrapExpression(statement.expression);
|
|
2776
|
-
if (expression.type ===
|
|
2777
|
-
if (expression.type !==
|
|
2947
|
+
if (expression.type === import_utils23.AST_NODE_TYPES.AwaitExpression) expression = unwrapExpression(expression.argument);
|
|
2948
|
+
if (expression.type !== import_utils23.AST_NODE_TYPES.CallExpression) return false;
|
|
2778
2949
|
const assertion = statusAssertion(source, expression);
|
|
2779
2950
|
return assertion !== null && assertion.response === response && !assertion.negative && EXACT_MATCHERS.has(assertion.matcher) && Number.isInteger(assertion.expected) && assertion.expected >= HTTP_STATUS_MIN && assertion.expected <= SERVER_ERROR_MAX;
|
|
2780
2951
|
});
|
|
@@ -2805,7 +2976,7 @@ var no_negative_only_http_status_assertion_default = createRule({
|
|
|
2805
2976
|
});
|
|
2806
2977
|
|
|
2807
2978
|
// src/rules/prefer-test-fixture-reuse.ts
|
|
2808
|
-
var
|
|
2979
|
+
var import_utils24 = require("@typescript-eslint/utils");
|
|
2809
2980
|
var MAX_DEPTH = 8;
|
|
2810
2981
|
var FRAMEWORKS = /* @__PURE__ */ new Set(["vitest", "@playwright/test"]);
|
|
2811
2982
|
var TEST_MODIFIERS = /* @__PURE__ */ new Set(["only", "skip", "concurrent", "sequential"]);
|
|
@@ -2827,24 +2998,24 @@ var PREFER_TEST_FIXTURE_REUSE_DOCUMENTATION = {
|
|
|
2827
2998
|
]
|
|
2828
2999
|
};
|
|
2829
3000
|
function stableBinding(source, identifier) {
|
|
2830
|
-
const variable =
|
|
3001
|
+
const variable = import_utils24.ASTUtils.findVariable(source.getScope(identifier), identifier.name);
|
|
2831
3002
|
if (variable?.defs.length !== 1 || variable.references.some((reference) => reference.isWrite() && !reference.init)) return null;
|
|
2832
3003
|
return variable;
|
|
2833
3004
|
}
|
|
2834
3005
|
function constructorBinding(source, node, depth = 0) {
|
|
2835
3006
|
node = unwrapExpression(node);
|
|
2836
|
-
if (node.type !==
|
|
3007
|
+
if (node.type !== import_utils24.AST_NODE_TYPES.Identifier || depth >= MAX_DEPTH) return null;
|
|
2837
3008
|
const variable = stableBinding(source, node);
|
|
2838
3009
|
const definition = variable?.defs[0];
|
|
2839
3010
|
if (variable === null || definition === void 0) return null;
|
|
2840
3011
|
if (definition.type === "ClassName") return variable;
|
|
2841
|
-
if (definition.type === "ImportBinding" && definition.parent.type ===
|
|
2842
|
-
if (definition.node.type ===
|
|
3012
|
+
if (definition.type === "ImportBinding" && definition.parent.type === import_utils24.AST_NODE_TYPES.ImportDeclaration && definition.parent.importKind !== "type" && (definition.node.type !== import_utils24.AST_NODE_TYPES.ImportSpecifier || definition.node.importKind !== "type")) return variable;
|
|
3013
|
+
if (definition.node.type === import_utils24.AST_NODE_TYPES.VariableDeclarator && definition.node.parent.kind === "const" && definition.node.init !== null && definition.node.range[1] < node.range[0]) return constructorBinding(source, definition.node.init, depth + 1);
|
|
2843
3014
|
return null;
|
|
2844
3015
|
}
|
|
2845
3016
|
function fixtureApi(source, expression, depth = 0) {
|
|
2846
3017
|
const node = unwrapExpression(expression);
|
|
2847
|
-
if (node.type !==
|
|
3018
|
+
if (node.type !== import_utils24.AST_NODE_TYPES.Identifier || depth >= MAX_DEPTH) return null;
|
|
2848
3019
|
const variable = stableBinding(source, node);
|
|
2849
3020
|
const definition = variable?.defs[0];
|
|
2850
3021
|
if (variable === null || definition === void 0) return null;
|
|
@@ -2856,35 +3027,35 @@ function fixtureApi(source, expression, depth = 0) {
|
|
|
2856
3027
|
}
|
|
2857
3028
|
function importedFixtureApi(variable) {
|
|
2858
3029
|
const definition = variable.defs[0];
|
|
2859
|
-
if (definition?.type === "ImportBinding" && definition.parent.type ===
|
|
3030
|
+
if (definition?.type === "ImportBinding" && definition.parent.type === import_utils24.AST_NODE_TYPES.ImportDeclaration && FRAMEWORKS.has(definition.parent.source.value) && definition.parent.importKind !== "type" && definition.node.type === import_utils24.AST_NODE_TYPES.ImportSpecifier && definition.node.importKind !== "type") {
|
|
2860
3031
|
const imported = definition.node.imported;
|
|
2861
|
-
const name = imported.type ===
|
|
3032
|
+
const name = imported.type === import_utils24.AST_NODE_TYPES.Identifier ? imported.name : imported.value;
|
|
2862
3033
|
return name === "test" || name === "it";
|
|
2863
3034
|
}
|
|
2864
3035
|
return false;
|
|
2865
3036
|
}
|
|
2866
3037
|
function fixtureExtension(declaration, before) {
|
|
2867
|
-
if (declaration.type !==
|
|
3038
|
+
if (declaration.type !== import_utils24.AST_NODE_TYPES.VariableDeclarator || declaration.parent.kind !== "const" || declaration.init === null || declaration.range[1] >= before) return null;
|
|
2868
3039
|
const initial = unwrapExpression(declaration.init);
|
|
2869
|
-
if (initial.type !==
|
|
3040
|
+
if (initial.type !== import_utils24.AST_NODE_TYPES.CallExpression || initial.optional || initial.arguments.length !== 1 || initial.callee.type !== import_utils24.AST_NODE_TYPES.MemberExpression || initial.callee.optional || import_utils24.ASTUtils.getPropertyName(initial.callee) !== "extend") return null;
|
|
2870
3041
|
const declarations = initial.arguments[0];
|
|
2871
|
-
if (declarations?.type !==
|
|
3042
|
+
if (declarations?.type !== import_utils24.AST_NODE_TYPES.ObjectExpression || declarations.properties.some((property) => property.type !== import_utils24.AST_NODE_TYPES.Property || property.computed || property.kind !== "init")) return null;
|
|
2872
3043
|
return { receiver: initial.callee.object, declarations };
|
|
2873
3044
|
}
|
|
2874
3045
|
function fixtureApiStable(variable) {
|
|
2875
3046
|
return !variable.references.some((reference) => {
|
|
2876
3047
|
if (reference.isWrite() || reference.isTypeReference && !reference.isValueReference) return false;
|
|
2877
3048
|
let use = reference.identifier;
|
|
2878
|
-
while (use.parent?.type ===
|
|
2879
|
-
return use.parent?.type !==
|
|
3049
|
+
while (use.parent?.type === import_utils24.AST_NODE_TYPES.MemberExpression && use.parent.object === use) use = use.parent;
|
|
3050
|
+
return use.parent?.type !== import_utils24.AST_NODE_TYPES.CallExpression || use.parent.callee !== use;
|
|
2880
3051
|
});
|
|
2881
3052
|
}
|
|
2882
3053
|
function fixtureConstructors(source, declarations, inherited) {
|
|
2883
3054
|
const result = new Map(inherited);
|
|
2884
3055
|
for (const property of declarations.properties) {
|
|
2885
|
-
if (property.type !==
|
|
2886
|
-
const name =
|
|
2887
|
-
if (name === null || property.value.type ===
|
|
3056
|
+
if (property.type !== import_utils24.AST_NODE_TYPES.Property || property.computed || property.value.type === import_utils24.AST_NODE_TYPES.AssignmentPattern) continue;
|
|
3057
|
+
const name = import_utils24.ASTUtils.getPropertyName(property);
|
|
3058
|
+
if (name === null || property.value.type === import_utils24.AST_NODE_TYPES.TSEmptyBodyFunctionExpression) continue;
|
|
2888
3059
|
const constructor = fixtureConstructor(source, property.value);
|
|
2889
3060
|
if (constructor === null) result.delete(name);
|
|
2890
3061
|
else result.set(name, constructor);
|
|
@@ -2893,24 +3064,24 @@ function fixtureConstructors(source, declarations, inherited) {
|
|
|
2893
3064
|
}
|
|
2894
3065
|
function fixtureConstructor(source, value) {
|
|
2895
3066
|
value = unwrapExpression(value);
|
|
2896
|
-
if (value.type !==
|
|
3067
|
+
if (value.type !== import_utils24.AST_NODE_TYPES.ArrowFunctionExpression && value.type !== import_utils24.AST_NODE_TYPES.FunctionExpression) return newConstructor(source, value);
|
|
2897
3068
|
const use = value.params[1];
|
|
2898
|
-
if (use?.type !==
|
|
3069
|
+
if (use?.type !== import_utils24.AST_NODE_TYPES.Identifier) return null;
|
|
2899
3070
|
const binding3 = stableBinding(source, use);
|
|
2900
|
-
const calls = scopeNodes(value.body, source).filter((node) => node.type ===
|
|
3071
|
+
const calls = scopeNodes(value.body, source).filter((node) => node.type === import_utils24.AST_NODE_TYPES.CallExpression && !node.optional && node.arguments.length === 1 && node.callee.type === import_utils24.AST_NODE_TYPES.Identifier && stableBinding(source, node.callee) === binding3);
|
|
2901
3072
|
if (calls.length !== 1 || binding3 === null) return null;
|
|
2902
3073
|
const argument = calls[0]?.arguments[0];
|
|
2903
|
-
return argument === void 0 || argument.type ===
|
|
3074
|
+
return argument === void 0 || argument.type === import_utils24.AST_NODE_TYPES.SpreadElement ? null : newConstructor(source, argument);
|
|
2904
3075
|
}
|
|
2905
3076
|
function newConstructor(source, expression) {
|
|
2906
3077
|
const value = unwrapExpression(expression);
|
|
2907
|
-
if (value.type ===
|
|
2908
|
-
if (value.type !==
|
|
3078
|
+
if (value.type === import_utils24.AST_NODE_TYPES.NewExpression) return constructorBinding(source, value.callee);
|
|
3079
|
+
if (value.type !== import_utils24.AST_NODE_TYPES.Identifier) return null;
|
|
2909
3080
|
const variable = stableBinding(source, value);
|
|
2910
3081
|
const declaration = variable?.defs[0]?.node;
|
|
2911
|
-
if (declaration?.type !==
|
|
3082
|
+
if (declaration?.type !== import_utils24.AST_NODE_TYPES.VariableDeclarator || declaration.parent.kind !== "const" || declaration.init === null || declaration.range[1] >= value.range[0]) return null;
|
|
2912
3083
|
const initial = unwrapExpression(declaration.init);
|
|
2913
|
-
return initial.type ===
|
|
3084
|
+
return initial.type === import_utils24.AST_NODE_TYPES.NewExpression ? constructorBinding(source, initial.callee) : null;
|
|
2914
3085
|
}
|
|
2915
3086
|
function scopeNodes(root, source) {
|
|
2916
3087
|
const result = [];
|
|
@@ -2919,7 +3090,7 @@ function scopeNodes(root, source) {
|
|
|
2919
3090
|
const node = pending.pop();
|
|
2920
3091
|
if (node === void 0) continue;
|
|
2921
3092
|
result.push(node);
|
|
2922
|
-
if (node !== root && (node.type ===
|
|
3093
|
+
if (node !== root && (node.type === import_utils24.AST_NODE_TYPES.ArrowFunctionExpression || node.type === import_utils24.AST_NODE_TYPES.FunctionExpression || node.type === import_utils24.AST_NODE_TYPES.FunctionDeclaration || node.type === import_utils24.AST_NODE_TYPES.ClassDeclaration || node.type === import_utils24.AST_NODE_TYPES.ClassExpression)) continue;
|
|
2923
3094
|
for (const key of source.visitorKeys[node.type] ?? []) {
|
|
2924
3095
|
const value = Reflect.get(node, key);
|
|
2925
3096
|
if (Array.isArray(value)) pending.push(...value.filter(isNode2));
|
|
@@ -2933,13 +3104,13 @@ function isNode2(value) {
|
|
|
2933
3104
|
}
|
|
2934
3105
|
function testApiCallee(expression) {
|
|
2935
3106
|
let node = unwrapExpression(expression);
|
|
2936
|
-
while (node.type ===
|
|
3107
|
+
while (node.type === import_utils24.AST_NODE_TYPES.MemberExpression && !node.optional && TEST_MODIFIERS.has(import_utils24.ASTUtils.getPropertyName(node) ?? "")) node = unwrapExpression(node.object);
|
|
2937
3108
|
return node;
|
|
2938
3109
|
}
|
|
2939
3110
|
function requestingFunction(node) {
|
|
2940
3111
|
for (let current = node.parent; current != null; current = current.parent) {
|
|
2941
|
-
if (current.type ===
|
|
2942
|
-
if (current.type ===
|
|
3112
|
+
if (current.type === import_utils24.AST_NODE_TYPES.ArrowFunctionExpression || current.type === import_utils24.AST_NODE_TYPES.FunctionExpression) return current;
|
|
3113
|
+
if (current.type === import_utils24.AST_NODE_TYPES.FunctionDeclaration) return null;
|
|
2943
3114
|
}
|
|
2944
3115
|
return null;
|
|
2945
3116
|
}
|
|
@@ -2961,13 +3132,13 @@ var prefer_test_fixture_reuse_default = createRule({
|
|
|
2961
3132
|
const call = functionNode === null ? null : directArgumentCall(functionNode);
|
|
2962
3133
|
if (functionNode === null || call === null) return;
|
|
2963
3134
|
const parameter = functionNode.params[0];
|
|
2964
|
-
if (parameter?.type !==
|
|
3135
|
+
if (parameter?.type !== import_utils24.AST_NODE_TYPES.ObjectPattern) return;
|
|
2965
3136
|
const entries = fixtureApi(context.sourceCode, testApiCallee(call.callee));
|
|
2966
3137
|
const constructor = constructorBinding(context.sourceCode, node.callee);
|
|
2967
3138
|
if (entries === null || constructor === null) return;
|
|
2968
3139
|
for (const property of parameter.properties) {
|
|
2969
|
-
if (property.type !==
|
|
2970
|
-
const name =
|
|
3140
|
+
if (property.type !== import_utils24.AST_NODE_TYPES.Property || property.computed) continue;
|
|
3141
|
+
const name = import_utils24.ASTUtils.getPropertyName(property);
|
|
2971
3142
|
if (name !== null && entries.get(name) === constructor) {
|
|
2972
3143
|
context.report({ node, messageId: "reuseFixture", data: { fixture: name } });
|
|
2973
3144
|
return;
|
|
@@ -2979,7 +3150,7 @@ var prefer_test_fixture_reuse_default = createRule({
|
|
|
2979
3150
|
});
|
|
2980
3151
|
|
|
2981
3152
|
// src/rules/no-return-disposed-resource.ts
|
|
2982
|
-
var
|
|
3153
|
+
var import_utils25 = require("@typescript-eslint/utils");
|
|
2983
3154
|
var NO_RETURN_DISPOSED_RESOURCE_DOCUMENTATION = {
|
|
2984
3155
|
defaultLevel: "warning",
|
|
2985
3156
|
summary: "Do not return a resource whose using declaration disposes it before the caller receives it.",
|
|
@@ -2999,16 +3170,16 @@ var NO_RETURN_DISPOSED_RESOURCE_DOCUMENTATION = {
|
|
|
2999
3170
|
};
|
|
3000
3171
|
function owningFunction(node) {
|
|
3001
3172
|
for (let current = node.parent; current != null; current = current.parent) {
|
|
3002
|
-
if (current.type ===
|
|
3173
|
+
if (current.type === import_utils25.AST_NODE_TYPES.FunctionDeclaration || current.type === import_utils25.AST_NODE_TYPES.FunctionExpression || current.type === import_utils25.AST_NODE_TYPES.ArrowFunctionExpression) return current;
|
|
3003
3174
|
}
|
|
3004
3175
|
return null;
|
|
3005
3176
|
}
|
|
3006
3177
|
function resourceOwner(source, value, seen = /* @__PURE__ */ new Set()) {
|
|
3007
3178
|
const node = unwrapExpression(value);
|
|
3008
|
-
if (node.type !==
|
|
3009
|
-
const variable =
|
|
3179
|
+
if (node.type !== import_utils25.AST_NODE_TYPES.Identifier) return null;
|
|
3180
|
+
const variable = import_utils25.ASTUtils.findVariable(source.getScope(node), node.name);
|
|
3010
3181
|
const definition = variable?.defs[0];
|
|
3011
|
-
if (variable === null || variable?.defs.length !== 1 || definition === void 0 || seen.has(variable) || variable.references.some((reference) => reference.isWrite() && !reference.init) || definition.node.type !==
|
|
3182
|
+
if (variable === null || variable?.defs.length !== 1 || definition === void 0 || seen.has(variable) || variable.references.some((reference) => reference.isWrite() && !reference.init) || definition.node.type !== import_utils25.AST_NODE_TYPES.VariableDeclarator) return null;
|
|
3012
3183
|
const declaration = definition.node;
|
|
3013
3184
|
if (declaration.parent.kind === "using" || declaration.parent.kind === "await using") return declaration;
|
|
3014
3185
|
if (declaration.parent.kind !== "const" || declaration.init === null || declaration.range[1] >= node.range[0]) return null;
|
|
@@ -3037,7 +3208,7 @@ var no_return_disposed_resource_default = createRule({
|
|
|
3037
3208
|
});
|
|
3038
3209
|
|
|
3039
3210
|
// src/rules/require-jwt-lifetime.ts
|
|
3040
|
-
var
|
|
3211
|
+
var import_utils26 = require("@typescript-eslint/utils");
|
|
3041
3212
|
var REQUIRE_JWT_LIFETIME_DOCUMENTATION = {
|
|
3042
3213
|
defaultLevel: "warning",
|
|
3043
3214
|
summary: "Require an expiration claim or a maximum token age when returning a verified JWT.",
|
|
@@ -3065,36 +3236,36 @@ var require_jwt_lifetime_default = createRule({
|
|
|
3065
3236
|
function inspect(input) {
|
|
3066
3237
|
if (input === null) return;
|
|
3067
3238
|
let node = unwrapExpression(input);
|
|
3068
|
-
if (node.type ===
|
|
3069
|
-
if (node.type !==
|
|
3239
|
+
if (node.type === import_utils26.AST_NODE_TYPES.AwaitExpression) node = unwrapExpression(node.argument);
|
|
3240
|
+
if (node.type !== import_utils26.AST_NODE_TYPES.CallExpression || !isVerifier(node.callee)) return;
|
|
3070
3241
|
if (!missingLifetime(node.arguments[2])) return;
|
|
3071
3242
|
context.report({ node, messageId: "lifetime" });
|
|
3072
3243
|
}
|
|
3073
3244
|
function isVerifier(node) {
|
|
3074
3245
|
node = unwrapExpression(node);
|
|
3075
|
-
if (node.type ===
|
|
3076
|
-
const variable =
|
|
3246
|
+
if (node.type === import_utils26.AST_NODE_TYPES.Identifier) {
|
|
3247
|
+
const variable = import_utils26.ASTUtils.findVariable(sourceCode.getScope(node), node.name);
|
|
3077
3248
|
const declaration = variable?.defs[0]?.node;
|
|
3078
|
-
return variable?.defs.length === 1 && declaration?.type ===
|
|
3249
|
+
return variable?.defs.length === 1 && declaration?.type === import_utils26.AST_NODE_TYPES.ImportSpecifier && declaration.parent.type === import_utils26.AST_NODE_TYPES.ImportDeclaration && declaration.importKind !== "type" && declaration.parent.importKind !== "type" && declaration.parent.source.value === "jose" && declaration.imported.type === import_utils26.AST_NODE_TYPES.Identifier && declaration.imported.name === "jwtVerify";
|
|
3079
3250
|
}
|
|
3080
|
-
if (node.type !==
|
|
3081
|
-
const definition =
|
|
3082
|
-
return definition?.type ===
|
|
3251
|
+
if (node.type !== import_utils26.AST_NODE_TYPES.MemberExpression || import_utils26.ASTUtils.getPropertyName(node) !== "jwtVerify" || node.object.type !== import_utils26.AST_NODE_TYPES.Identifier) return false;
|
|
3252
|
+
const definition = import_utils26.ASTUtils.findVariable(sourceCode.getScope(node.object), node.object.name)?.defs[0]?.node;
|
|
3253
|
+
return definition?.type === import_utils26.AST_NODE_TYPES.ImportNamespaceSpecifier && definition.parent.importKind !== "type" && definition.parent.source.value === "jose";
|
|
3083
3254
|
}
|
|
3084
3255
|
function missingLifetime(options) {
|
|
3085
3256
|
if (options === void 0) return true;
|
|
3086
|
-
if (options.type !==
|
|
3087
|
-
return !options.properties.some((property) => property.type ===
|
|
3257
|
+
if (options.type !== import_utils26.AST_NODE_TYPES.ObjectExpression || options.properties.some((property) => property.type !== import_utils26.AST_NODE_TYPES.Property || property.computed)) return false;
|
|
3258
|
+
return !options.properties.some((property) => property.type === import_utils26.AST_NODE_TYPES.Property && lifetimeProperty(property));
|
|
3088
3259
|
}
|
|
3089
3260
|
function lifetimeProperty(property) {
|
|
3090
|
-
const name = property.key.type ===
|
|
3261
|
+
const name = property.key.type === import_utils26.AST_NODE_TYPES.Identifier ? property.key.name : property.key.type === import_utils26.AST_NODE_TYPES.Literal ? property.key.value : null;
|
|
3091
3262
|
if (name === "maxTokenAge") {
|
|
3092
|
-
if (property.value.type !==
|
|
3263
|
+
if (property.value.type !== import_utils26.AST_NODE_TYPES.Literal) return true;
|
|
3093
3264
|
return typeof property.value.value === "number" && Number.isFinite(property.value.value) || typeof property.value.value === "string" && property.value.value.trim() !== "";
|
|
3094
3265
|
}
|
|
3095
3266
|
if (name !== "requiredClaims") return false;
|
|
3096
|
-
if (property.value.type !==
|
|
3097
|
-
return property.value.elements.some((element) => element?.type ===
|
|
3267
|
+
if (property.value.type !== import_utils26.AST_NODE_TYPES.ArrayExpression || property.value.elements.some((element) => element?.type !== import_utils26.AST_NODE_TYPES.Literal)) return true;
|
|
3268
|
+
return property.value.elements.some((element) => element?.type === import_utils26.AST_NODE_TYPES.Literal && element.value === "exp");
|
|
3098
3269
|
}
|
|
3099
3270
|
return {
|
|
3100
3271
|
ReturnStatement(node) {
|
|
@@ -3108,7 +3279,7 @@ var require_jwt_lifetime_default = createRule({
|
|
|
3108
3279
|
});
|
|
3109
3280
|
|
|
3110
3281
|
// src/rules/no-discarded-validation-result.ts
|
|
3111
|
-
var
|
|
3282
|
+
var import_utils27 = require("@typescript-eslint/utils");
|
|
3112
3283
|
|
|
3113
3284
|
// src/rules/_zod.ts
|
|
3114
3285
|
var ZOD_SCHEMA_NAME_RE = /Schema$|^Z[A-Z]/;
|
|
@@ -3144,52 +3315,52 @@ var no_discarded_validation_result_default = createRule({
|
|
|
3144
3315
|
function schema(node, depth = 0) {
|
|
3145
3316
|
if (depth > 24) return null;
|
|
3146
3317
|
node = unwrapExpression(node);
|
|
3147
|
-
if (node.type ===
|
|
3148
|
-
const variable =
|
|
3318
|
+
if (node.type === import_utils27.AST_NODE_TYPES.Identifier) {
|
|
3319
|
+
const variable = import_utils27.ASTUtils.findVariable(sourceCode.getScope(node), node.name);
|
|
3149
3320
|
const definition = variable?.defs[0]?.node;
|
|
3150
3321
|
if (variable?.defs.length !== 1) return null;
|
|
3151
|
-
if (definition?.type ===
|
|
3152
|
-
if (definition?.type ===
|
|
3153
|
-
if (definition?.type ===
|
|
3322
|
+
if (definition?.type === import_utils27.AST_NODE_TYPES.ImportSpecifier && definition.parent.type === import_utils27.AST_NODE_TYPES.ImportDeclaration && definition.importKind !== "type" && definition.parent.importKind !== "type" && isZodModule(definition.parent.source.value)) return { changed: false };
|
|
3323
|
+
if (definition?.type === import_utils27.AST_NODE_TYPES.ImportNamespaceSpecifier && definition.parent.importKind !== "type" && isZodModule(definition.parent.source.value)) return { changed: false };
|
|
3324
|
+
if (definition?.type === import_utils27.AST_NODE_TYPES.VariableDeclarator && definition.parent.kind === "const" && definition.init !== null && definition.range[1] < node.range[0] && !variable.references.some((reference) => reference.isWrite() && !reference.init)) return schema(definition.init, depth + 1);
|
|
3154
3325
|
return null;
|
|
3155
3326
|
}
|
|
3156
|
-
if (node.type ===
|
|
3327
|
+
if (node.type === import_utils27.AST_NODE_TYPES.MemberExpression) {
|
|
3157
3328
|
const owner2 = schema(node.object, depth + 1);
|
|
3158
3329
|
return owner2;
|
|
3159
3330
|
}
|
|
3160
|
-
if (node.type !==
|
|
3331
|
+
if (node.type !== import_utils27.AST_NODE_TYPES.CallExpression) return null;
|
|
3161
3332
|
const owner = schema(node.callee, depth + 1);
|
|
3162
3333
|
if (owner === null) return null;
|
|
3163
|
-
const invokedChange = node.callee.type ===
|
|
3164
|
-
const coerced = node.callee.type ===
|
|
3334
|
+
const invokedChange = node.callee.type === import_utils27.AST_NODE_TYPES.MemberExpression && CHANGING.has(import_utils27.ASTUtils.getPropertyName(node.callee) ?? "");
|
|
3335
|
+
const coerced = node.callee.type === import_utils27.AST_NODE_TYPES.MemberExpression && coercionNamespace(node.callee.object);
|
|
3165
3336
|
const changedArgument = node.arguments.some((argument) => {
|
|
3166
|
-
if (argument.type ===
|
|
3167
|
-
if (argument.type ===
|
|
3337
|
+
if (argument.type === import_utils27.AST_NODE_TYPES.ArrayExpression) return argument.elements.some((element) => element !== null && schema(element, depth + 1)?.changed === true);
|
|
3338
|
+
if (argument.type === import_utils27.AST_NODE_TYPES.ObjectExpression) return argument.properties.some((property) => property.type === import_utils27.AST_NODE_TYPES.Property && schema(property.value, depth + 1)?.changed === true);
|
|
3168
3339
|
return schema(argument, depth + 1)?.changed === true;
|
|
3169
3340
|
});
|
|
3170
3341
|
return { changed: owner.changed || invokedChange || coerced || changedArgument };
|
|
3171
3342
|
}
|
|
3172
3343
|
function coercionNamespace(node) {
|
|
3173
3344
|
let namespace = false;
|
|
3174
|
-
if (node.type ===
|
|
3345
|
+
if (node.type === import_utils27.AST_NODE_TYPES.MemberExpression && import_utils27.ASTUtils.getPropertyName(node) === "coerce") {
|
|
3175
3346
|
namespace = true;
|
|
3176
3347
|
node = node.object;
|
|
3177
3348
|
}
|
|
3178
|
-
if (node.type !==
|
|
3179
|
-
const variable =
|
|
3349
|
+
if (node.type !== import_utils27.AST_NODE_TYPES.Identifier) return false;
|
|
3350
|
+
const variable = import_utils27.ASTUtils.findVariable(sourceCode.getScope(node), node.name);
|
|
3180
3351
|
const definition = variable?.defs[0]?.node;
|
|
3181
|
-
if (variable?.defs.length !== 1 || definition === void 0 || definition.parent.type !==
|
|
3182
|
-
if (definition.type ===
|
|
3183
|
-
if (definition.type !==
|
|
3184
|
-
const name = definition.imported.type ===
|
|
3352
|
+
if (variable?.defs.length !== 1 || definition === void 0 || definition.parent.type !== import_utils27.AST_NODE_TYPES.ImportDeclaration || definition.parent.importKind === "type" || !isZodModule(definition.parent.source.value)) return false;
|
|
3353
|
+
if (definition.type === import_utils27.AST_NODE_TYPES.ImportNamespaceSpecifier) return namespace;
|
|
3354
|
+
if (definition.type !== import_utils27.AST_NODE_TYPES.ImportSpecifier || definition.importKind === "type") return false;
|
|
3355
|
+
const name = definition.imported.type === import_utils27.AST_NODE_TYPES.Identifier ? definition.imported.name : definition.imported.value;
|
|
3185
3356
|
return namespace ? name === "z" : name === "coerce";
|
|
3186
3357
|
}
|
|
3187
3358
|
return {
|
|
3188
3359
|
ExpressionStatement(statement) {
|
|
3189
3360
|
let expression = unwrapExpression(statement.expression);
|
|
3190
|
-
if (expression.type ===
|
|
3191
|
-
if (expression.type !==
|
|
3192
|
-
const method =
|
|
3361
|
+
if (expression.type === import_utils27.AST_NODE_TYPES.AwaitExpression) expression = unwrapExpression(expression.argument);
|
|
3362
|
+
if (expression.type !== import_utils27.AST_NODE_TYPES.CallExpression || expression.callee.type !== import_utils27.AST_NODE_TYPES.MemberExpression) return;
|
|
3363
|
+
const method = import_utils27.ASTUtils.getPropertyName(expression.callee);
|
|
3193
3364
|
if (!(/* @__PURE__ */ new Set(["parse", "parseAsync", "safeParse", "safeParseAsync"])).has(method ?? "")) return;
|
|
3194
3365
|
const owner = schema(expression.callee.object);
|
|
3195
3366
|
if (owner !== null && (owner.changed || method?.startsWith("safe") === true)) context.report({ node: expression, messageId: "discarded" });
|
|
@@ -3199,7 +3370,7 @@ var no_discarded_validation_result_default = createRule({
|
|
|
3199
3370
|
});
|
|
3200
3371
|
|
|
3201
3372
|
// src/rules/production-derived-test-cases.ts
|
|
3202
|
-
var
|
|
3373
|
+
var import_utils28 = require("@typescript-eslint/utils");
|
|
3203
3374
|
var MEMBERSHIP = /(?:^|_)(?:ALLOWED|ELIGIBLE|REQUIRED|SUPPORTED)(?:_|$)/u;
|
|
3204
3375
|
var SUPPORT_PATH = /(?:^|[/_.-])(?:tests?|fixtures?|fakes?|mocks?|stubs?|__tests__)(?:[/_.-]|$)/u;
|
|
3205
3376
|
var PRODUCTION_DERIVED_TEST_CASES_DOCUMENTATION = {
|
|
@@ -3234,52 +3405,52 @@ var production_derived_test_cases_default = createRule({
|
|
|
3234
3405
|
const tables = [];
|
|
3235
3406
|
const asserted = /* @__PURE__ */ new Set();
|
|
3236
3407
|
function binding3(node) {
|
|
3237
|
-
return
|
|
3408
|
+
return import_utils28.ASTUtils.findVariable(sourceCode.getScope(node), node.name);
|
|
3238
3409
|
}
|
|
3239
3410
|
function importedName7(node, module2) {
|
|
3240
3411
|
const variable = binding3(node);
|
|
3241
3412
|
const specifier = variable?.defs[0]?.node;
|
|
3242
|
-
if (variable?.defs.length !== 1 || specifier?.type !==
|
|
3243
|
-
return specifier.imported.type ===
|
|
3413
|
+
if (variable?.defs.length !== 1 || specifier?.type !== import_utils28.AST_NODE_TYPES.ImportSpecifier || specifier.importKind === "type" || specifier.parent.type !== import_utils28.AST_NODE_TYPES.ImportDeclaration || specifier.parent.importKind === "type" || specifier.parent.source.value !== module2 || variable.references.some((reference) => reference.isWrite())) return null;
|
|
3414
|
+
return specifier.imported.type === import_utils28.AST_NODE_TYPES.Identifier ? specifier.imported.name : specifier.imported.value;
|
|
3244
3415
|
}
|
|
3245
3416
|
function production(node) {
|
|
3246
3417
|
node = unwrapExpression(node);
|
|
3247
|
-
if (node.type !==
|
|
3418
|
+
if (node.type !== import_utils28.AST_NODE_TYPES.Identifier) return null;
|
|
3248
3419
|
const variable = binding3(node);
|
|
3249
3420
|
const specifier = variable?.defs[0]?.node;
|
|
3250
|
-
if (variable?.defs.length !== 1 || specifier?.type !==
|
|
3251
|
-
const name = specifier.imported.type ===
|
|
3421
|
+
if (variable?.defs.length !== 1 || specifier?.type !== import_utils28.AST_NODE_TYPES.ImportSpecifier || specifier.importKind === "type" || specifier.parent.type !== import_utils28.AST_NODE_TYPES.ImportDeclaration || specifier.parent.importKind === "type" || !specifier.parent.source.value.startsWith(".") || SUPPORT_PATH.test(specifier.parent.source.value) || variable.references.some((reference) => reference.isWrite())) return null;
|
|
3422
|
+
const name = specifier.imported.type === import_utils28.AST_NODE_TYPES.Identifier ? specifier.imported.name : specifier.imported.value;
|
|
3252
3423
|
return MEMBERSHIP.test(name) && !name.endsWith("REGISTRY") ? variable : null;
|
|
3253
3424
|
}
|
|
3254
3425
|
function runner(node) {
|
|
3255
3426
|
node = unwrapExpression(node);
|
|
3256
|
-
while (node.type ===
|
|
3257
|
-
if (node.type !==
|
|
3427
|
+
while (node.type === import_utils28.AST_NODE_TYPES.MemberExpression && ["only", "skip", "concurrent", "sequential"].includes(import_utils28.ASTUtils.getPropertyName(node) ?? "")) node = unwrapExpression(node.object);
|
|
3428
|
+
if (node.type !== import_utils28.AST_NODE_TYPES.Identifier) return false;
|
|
3258
3429
|
const name = importedName7(node, "vitest");
|
|
3259
3430
|
return name === "test" || name === "it" || vitestFixtureTestName(sourceCode, node) !== null;
|
|
3260
3431
|
}
|
|
3261
3432
|
function caseTable(node) {
|
|
3262
|
-
return node.type ===
|
|
3433
|
+
return node.type === import_utils28.AST_NODE_TYPES.CallExpression && node.callee.type === import_utils28.AST_NODE_TYPES.MemberExpression && ["each", "for"].includes(import_utils28.ASTUtils.getPropertyName(node.callee) ?? "") && runner(node.callee.object);
|
|
3263
3434
|
}
|
|
3264
3435
|
function literalTable(node, seen = /* @__PURE__ */ new Set()) {
|
|
3265
3436
|
node = unwrapExpression(node);
|
|
3266
3437
|
if (seen.has(node)) return false;
|
|
3267
3438
|
seen.add(node);
|
|
3268
|
-
if (node.type ===
|
|
3439
|
+
if (node.type === import_utils28.AST_NODE_TYPES.Identifier) {
|
|
3269
3440
|
const variable = binding3(node);
|
|
3270
3441
|
const definition = variable?.defs[0]?.node;
|
|
3271
|
-
return variable?.defs.length === 1 && definition?.type ===
|
|
3442
|
+
return variable?.defs.length === 1 && definition?.type === import_utils28.AST_NODE_TYPES.VariableDeclarator && definition.parent.kind === "const" && definition.init !== null && definition.range[1] < node.range[0] && variable.references.every((reference) => reference.init || !reference.isWrite() && reference.identifier.parent.type === import_utils28.AST_NODE_TYPES.CallExpression && (caseTable(reference.identifier.parent) || reference.identifier.parent.callee.type === import_utils28.AST_NODE_TYPES.Identifier && importedName7(reference.identifier.parent.callee, "vitest") === "expect" || reference.identifier.parent.callee.type === import_utils28.AST_NODE_TYPES.MemberExpression && ["toEqual", "toStrictEqual"].includes(import_utils28.ASTUtils.getPropertyName(reference.identifier.parent.callee) ?? ""))) && literalTable(definition.init, seen);
|
|
3272
3443
|
}
|
|
3273
|
-
return node.type ===
|
|
3444
|
+
return node.type === import_utils28.AST_NODE_TYPES.ArrayExpression && node.elements.every((element) => element?.type === import_utils28.AST_NODE_TYPES.Literal && !("regex" in element));
|
|
3274
3445
|
}
|
|
3275
3446
|
function unconditional(node) {
|
|
3276
3447
|
const statement = node.parent;
|
|
3277
|
-
if (statement.type !==
|
|
3278
|
-
if (statement.parent.type ===
|
|
3448
|
+
if (statement.type !== import_utils28.AST_NODE_TYPES.ExpressionStatement) return false;
|
|
3449
|
+
if (statement.parent.type === import_utils28.AST_NODE_TYPES.Program) return true;
|
|
3279
3450
|
const block = statement.parent;
|
|
3280
|
-
if (block.type !==
|
|
3451
|
+
if (block.type !== import_utils28.AST_NODE_TYPES.BlockStatement || block.parent.type !== import_utils28.AST_NODE_TYPES.ArrowFunctionExpression && block.parent.type !== import_utils28.AST_NODE_TYPES.FunctionExpression) return false;
|
|
3281
3452
|
const call = block.parent.parent;
|
|
3282
|
-
return call.type ===
|
|
3453
|
+
return call.type === import_utils28.AST_NODE_TYPES.CallExpression && runner(call.callee);
|
|
3283
3454
|
}
|
|
3284
3455
|
return {
|
|
3285
3456
|
CallExpression(node) {
|
|
@@ -3287,9 +3458,9 @@ var production_derived_test_cases_default = createRule({
|
|
|
3287
3458
|
const variable2 = production(node.arguments[0]);
|
|
3288
3459
|
if (variable2 !== null) tables.push({ node, variable: variable2 });
|
|
3289
3460
|
}
|
|
3290
|
-
if (node.callee.type !==
|
|
3461
|
+
if (node.callee.type !== import_utils28.AST_NODE_TYPES.MemberExpression || !["toEqual", "toStrictEqual"].includes(import_utils28.ASTUtils.getPropertyName(node.callee) ?? "") || node.arguments.length !== 1 || node.arguments[0] === void 0 || !literalTable(node.arguments[0]) || !unconditional(node)) return;
|
|
3291
3462
|
const expect = node.callee.object;
|
|
3292
|
-
if (expect.type !==
|
|
3463
|
+
if (expect.type !== import_utils28.AST_NODE_TYPES.CallExpression || expect.callee.type !== import_utils28.AST_NODE_TYPES.Identifier || importedName7(expect.callee, "vitest") !== "expect" || expect.arguments.length !== 1 || expect.arguments[0] === void 0) return;
|
|
3293
3464
|
const variable = production(expect.arguments[0]);
|
|
3294
3465
|
if (variable !== null) asserted.add(variable);
|
|
3295
3466
|
},
|
|
@@ -3301,14 +3472,14 @@ var production_derived_test_cases_default = createRule({
|
|
|
3301
3472
|
});
|
|
3302
3473
|
|
|
3303
3474
|
// src/rules/require-constrained-schema-integer.ts
|
|
3304
|
-
var
|
|
3475
|
+
var import_utils29 = require("@typescript-eslint/utils");
|
|
3305
3476
|
var FIELD_MINIMUMS = /* @__PURE__ */ new Map([["limit", 1], ["version", 0]]);
|
|
3306
3477
|
var NUMBER_FACTORIES = /* @__PURE__ */ new Set(["number", "int", "int32", "uint32"]);
|
|
3307
3478
|
var PRESERVING = /* @__PURE__ */ new Set(["optional", "nullable", "nullish", "default", "catch", "readonly", "brand", "describe", "meta", "max", "lte", "lt", "finite", "safe", "multipleOf"]);
|
|
3308
3479
|
function numericLiteral(node) {
|
|
3309
3480
|
node = unwrapExpression(node);
|
|
3310
|
-
if (node.type ===
|
|
3311
|
-
if (node.type ===
|
|
3481
|
+
if (node.type === import_utils29.AST_NODE_TYPES.Literal && typeof node.value === "number") return node.value;
|
|
3482
|
+
if (node.type === import_utils29.AST_NODE_TYPES.UnaryExpression && (node.operator === "-" || node.operator === "+")) {
|
|
3312
3483
|
const value = numericLiteral(node.argument);
|
|
3313
3484
|
return value === null ? null : node.operator === "-" ? -value : value;
|
|
3314
3485
|
}
|
|
@@ -3345,35 +3516,35 @@ var require_constrained_schema_integer_default = createRule({
|
|
|
3345
3516
|
const sourceCode = context.sourceCode;
|
|
3346
3517
|
function factory(node) {
|
|
3347
3518
|
node = unwrapExpression(node);
|
|
3348
|
-
if (node.type ===
|
|
3519
|
+
if (node.type === import_utils29.AST_NODE_TYPES.Identifier) {
|
|
3349
3520
|
const definition2 = imported(node);
|
|
3350
|
-
return definition2?.type ===
|
|
3521
|
+
return definition2?.type === import_utils29.AST_NODE_TYPES.ImportSpecifier ? definition2.imported.type === import_utils29.AST_NODE_TYPES.Identifier ? definition2.imported.name : definition2.imported.value : null;
|
|
3351
3522
|
}
|
|
3352
|
-
if (node.type !==
|
|
3523
|
+
if (node.type !== import_utils29.AST_NODE_TYPES.MemberExpression) return null;
|
|
3353
3524
|
let receiver = unwrapExpression(node.object);
|
|
3354
|
-
if (receiver.type ===
|
|
3355
|
-
if (receiver.type !==
|
|
3525
|
+
if (receiver.type === import_utils29.AST_NODE_TYPES.MemberExpression && import_utils29.ASTUtils.getPropertyName(receiver) === "coerce") receiver = unwrapExpression(receiver.object);
|
|
3526
|
+
if (receiver.type !== import_utils29.AST_NODE_TYPES.Identifier) return null;
|
|
3356
3527
|
const definition = imported(receiver);
|
|
3357
|
-
if (definition === null || definition.type ===
|
|
3358
|
-
return
|
|
3528
|
+
if (definition === null || definition.type === import_utils29.AST_NODE_TYPES.ImportSpecifier && (definition.imported.type === import_utils29.AST_NODE_TYPES.Identifier ? definition.imported.name : definition.imported.value) !== "z") return null;
|
|
3529
|
+
return import_utils29.ASTUtils.getPropertyName(node);
|
|
3359
3530
|
}
|
|
3360
3531
|
function imported(identifier) {
|
|
3361
|
-
const variable =
|
|
3532
|
+
const variable = import_utils29.ASTUtils.findVariable(sourceCode.getScope(identifier), identifier.name);
|
|
3362
3533
|
const definition = variable?.defs[0]?.node;
|
|
3363
|
-
if (variable?.defs.length !== 1 || definition?.type !==
|
|
3364
|
-
return definition.type ===
|
|
3534
|
+
if (variable?.defs.length !== 1 || definition?.type !== import_utils29.AST_NODE_TYPES.ImportSpecifier && definition?.type !== import_utils29.AST_NODE_TYPES.ImportNamespaceSpecifier || definition.parent.type !== import_utils29.AST_NODE_TYPES.ImportDeclaration || definition.parent.importKind === "type" || !isZodModule(definition.parent.source.value)) return null;
|
|
3535
|
+
return definition.type === import_utils29.AST_NODE_TYPES.ImportSpecifier && definition.importKind === "type" ? null : definition;
|
|
3365
3536
|
}
|
|
3366
3537
|
function constrained(value, minimum) {
|
|
3367
3538
|
const calls = [];
|
|
3368
3539
|
value = unwrapExpression(value);
|
|
3369
|
-
while (value.type ===
|
|
3540
|
+
while (value.type === import_utils29.AST_NODE_TYPES.CallExpression) {
|
|
3370
3541
|
const name = factory(value.callee);
|
|
3371
3542
|
if (name !== null) {
|
|
3372
3543
|
return chainContract(name, calls, minimum);
|
|
3373
3544
|
}
|
|
3374
3545
|
const callee = unwrapExpression(value.callee);
|
|
3375
|
-
if (callee.type !==
|
|
3376
|
-
const method =
|
|
3546
|
+
if (callee.type !== import_utils29.AST_NODE_TYPES.MemberExpression) return null;
|
|
3547
|
+
const method = import_utils29.ASTUtils.getPropertyName(callee);
|
|
3377
3548
|
if (method === null) return null;
|
|
3378
3549
|
calls.push({ method, call: value });
|
|
3379
3550
|
value = unwrapExpression(callee.object);
|
|
@@ -3398,7 +3569,7 @@ var require_constrained_schema_integer_default = createRule({
|
|
|
3398
3569
|
}
|
|
3399
3570
|
function lowerBound(call, minimum, exclusive) {
|
|
3400
3571
|
const argument = call.arguments[0];
|
|
3401
|
-
if (argument === void 0 || argument.type ===
|
|
3572
|
+
if (argument === void 0 || argument.type === import_utils29.AST_NODE_TYPES.SpreadElement) return null;
|
|
3402
3573
|
const bound = numericLiteral(argument);
|
|
3403
3574
|
return bound === null || bound >= minimum - (exclusive ? 1 : 0);
|
|
3404
3575
|
}
|
|
@@ -3407,10 +3578,10 @@ var require_constrained_schema_integer_default = createRule({
|
|
|
3407
3578
|
const name = factory(node.callee);
|
|
3408
3579
|
if (name === null || !["object", "strictObject", "looseObject"].includes(name) || node.arguments.length !== 1) return;
|
|
3409
3580
|
const shape = node.arguments[0];
|
|
3410
|
-
if (shape?.type !==
|
|
3581
|
+
if (shape?.type !== import_utils29.AST_NODE_TYPES.ObjectExpression) return;
|
|
3411
3582
|
for (const property of shape.properties) {
|
|
3412
|
-
if (property.type !==
|
|
3413
|
-
const field =
|
|
3583
|
+
if (property.type !== import_utils29.AST_NODE_TYPES.Property || property.computed || property.kind !== "init" || property.method) continue;
|
|
3584
|
+
const field = import_utils29.ASTUtils.getPropertyName(property);
|
|
3414
3585
|
const minimum = field === null ? void 0 : FIELD_MINIMUMS.get(field);
|
|
3415
3586
|
if (minimum === void 0 || field === null || constrained(property.value, minimum) !== false) continue;
|
|
3416
3587
|
context.report({ node: property, messageId: "constrainInteger", data: { field, minimum } });
|
|
@@ -3421,7 +3592,7 @@ var require_constrained_schema_integer_default = createRule({
|
|
|
3421
3592
|
});
|
|
3422
3593
|
|
|
3423
3594
|
// src/rules/no-generic-json-parser.ts
|
|
3424
|
-
var
|
|
3595
|
+
var import_utils30 = require("@typescript-eslint/utils");
|
|
3425
3596
|
var OPEN_FACTORIES = /* @__PURE__ */ new Set(["any", "unknown", "json", "record", "partialRecord"]);
|
|
3426
3597
|
var WRAPPERS = /* @__PURE__ */ new Set(["optional", "nullable", "nullish", "default", "catch", "readonly", "brand", "describe", "meta"]);
|
|
3427
3598
|
var NO_GENERIC_JSON_PARSER_DOCUMENTATION = {
|
|
@@ -3454,60 +3625,60 @@ var no_generic_json_parser_default = createRule({
|
|
|
3454
3625
|
if (isGeneratedFile(context, context.sourceCode.text)) return {};
|
|
3455
3626
|
const sourceCode = context.sourceCode;
|
|
3456
3627
|
function binding3(node) {
|
|
3457
|
-
return
|
|
3628
|
+
return import_utils30.ASTUtils.findVariable(sourceCode.getScope(node), node.name);
|
|
3458
3629
|
}
|
|
3459
3630
|
function initializer(node) {
|
|
3460
3631
|
const variable = binding3(node);
|
|
3461
3632
|
const definition = variable?.defs[0];
|
|
3462
|
-
if (variable?.defs.length !== 1 || definition?.node.type !==
|
|
3633
|
+
if (variable?.defs.length !== 1 || definition?.node.type !== import_utils30.AST_NODE_TYPES.VariableDeclarator || definition.node.parent.kind !== "const" || definition.node.init === null || definition.node.range[1] >= node.range[0] || variable.references.some((reference) => reference.isWrite() && !reference.init)) return null;
|
|
3463
3634
|
return definition.node.init;
|
|
3464
3635
|
}
|
|
3465
3636
|
function parser(node, seen = /* @__PURE__ */ new Set(), awaited = false) {
|
|
3466
3637
|
node = unwrapExpression(node);
|
|
3467
3638
|
if (seen.has(node)) return null;
|
|
3468
3639
|
seen.add(node);
|
|
3469
|
-
if (node.type ===
|
|
3470
|
-
if (node.type ===
|
|
3640
|
+
if (node.type === import_utils30.AST_NODE_TYPES.AwaitExpression) return parser(node.argument, seen, true);
|
|
3641
|
+
if (node.type === import_utils30.AST_NODE_TYPES.Identifier) {
|
|
3471
3642
|
const value = initializer(node);
|
|
3472
3643
|
return value === null ? null : parser(value, seen, awaited);
|
|
3473
3644
|
}
|
|
3474
|
-
if (node.type !==
|
|
3475
|
-
if (
|
|
3645
|
+
if (node.type !== import_utils30.AST_NODE_TYPES.CallExpression || node.callee.type !== import_utils30.AST_NODE_TYPES.MemberExpression || !["parse", "parseAsync"].includes(import_utils30.ASTUtils.getPropertyName(node.callee) ?? "")) return null;
|
|
3646
|
+
if (import_utils30.ASTUtils.getPropertyName(node.callee) === "parseAsync" && !awaited) return null;
|
|
3476
3647
|
return openSchema(node.callee.object) ? node : null;
|
|
3477
3648
|
}
|
|
3478
3649
|
function openSchema(node, seen = /* @__PURE__ */ new Set()) {
|
|
3479
3650
|
node = unwrapExpression(node);
|
|
3480
3651
|
if (seen.has(node)) return false;
|
|
3481
3652
|
seen.add(node);
|
|
3482
|
-
if (node.type ===
|
|
3653
|
+
if (node.type === import_utils30.AST_NODE_TYPES.Identifier) {
|
|
3483
3654
|
const value = initializer(node);
|
|
3484
3655
|
return value !== null && openSchema(value, seen);
|
|
3485
3656
|
}
|
|
3486
|
-
if (node.type !==
|
|
3657
|
+
if (node.type !== import_utils30.AST_NODE_TYPES.CallExpression) return false;
|
|
3487
3658
|
const name = factory(node.callee);
|
|
3488
3659
|
if (name !== null) return OPEN_FACTORIES.has(name);
|
|
3489
3660
|
const callee = unwrapExpression(node.callee);
|
|
3490
|
-
return callee.type ===
|
|
3661
|
+
return callee.type === import_utils30.AST_NODE_TYPES.MemberExpression && WRAPPERS.has(import_utils30.ASTUtils.getPropertyName(callee) ?? "") && openSchema(callee.object, seen);
|
|
3491
3662
|
}
|
|
3492
3663
|
function factory(node) {
|
|
3493
3664
|
node = unwrapExpression(node);
|
|
3494
|
-
if (node.type ===
|
|
3665
|
+
if (node.type === import_utils30.AST_NODE_TYPES.Identifier) {
|
|
3495
3666
|
const definition2 = binding3(node)?.defs[0]?.node;
|
|
3496
|
-
if (definition2?.type !==
|
|
3497
|
-
return definition2.imported.type ===
|
|
3667
|
+
if (definition2?.type !== import_utils30.AST_NODE_TYPES.ImportSpecifier || definition2.parent.type !== import_utils30.AST_NODE_TYPES.ImportDeclaration || definition2.importKind === "type" || definition2.parent.importKind === "type" || !isZodModule(definition2.parent.source.value)) return null;
|
|
3668
|
+
return definition2.imported.type === import_utils30.AST_NODE_TYPES.Identifier ? definition2.imported.name : definition2.imported.value;
|
|
3498
3669
|
}
|
|
3499
|
-
if (node.type !==
|
|
3670
|
+
if (node.type !== import_utils30.AST_NODE_TYPES.MemberExpression) return null;
|
|
3500
3671
|
const receiver = unwrapExpression(node.object);
|
|
3501
|
-
if (receiver.type !==
|
|
3672
|
+
if (receiver.type !== import_utils30.AST_NODE_TYPES.Identifier) return null;
|
|
3502
3673
|
const definition = binding3(receiver)?.defs[0]?.node;
|
|
3503
|
-
if (definition === void 0 || definition.type !==
|
|
3504
|
-
if (definition.type ===
|
|
3505
|
-
return
|
|
3674
|
+
if (definition === void 0 || definition.type !== import_utils30.AST_NODE_TYPES.ImportSpecifier && definition.type !== import_utils30.AST_NODE_TYPES.ImportNamespaceSpecifier || definition.parent.type !== import_utils30.AST_NODE_TYPES.ImportDeclaration || definition.parent.importKind === "type" || !isZodModule(definition.parent.source.value)) return null;
|
|
3675
|
+
if (definition.type === import_utils30.AST_NODE_TYPES.ImportSpecifier && (definition.importKind === "type" || (definition.imported.type === import_utils30.AST_NODE_TYPES.Identifier ? definition.imported.name : definition.imported.value) !== "z")) return null;
|
|
3676
|
+
return import_utils30.ASTUtils.getPropertyName(node);
|
|
3506
3677
|
}
|
|
3507
3678
|
const reported = /* @__PURE__ */ new Set();
|
|
3508
3679
|
return {
|
|
3509
3680
|
MemberExpression(node) {
|
|
3510
|
-
const field =
|
|
3681
|
+
const field = import_utils30.ASTUtils.getPropertyName(node);
|
|
3511
3682
|
if (field === null) return;
|
|
3512
3683
|
const call = parser(node.object);
|
|
3513
3684
|
if (call === null || reported.has(call)) return;
|
|
@@ -3516,10 +3687,160 @@ var no_generic_json_parser_default = createRule({
|
|
|
3516
3687
|
}
|
|
3517
3688
|
};
|
|
3518
3689
|
}
|
|
3519
|
-
});
|
|
3690
|
+
});
|
|
3691
|
+
|
|
3692
|
+
// src/rules/no-redundant-local-alias.ts
|
|
3693
|
+
var import_utils33 = require("@typescript-eslint/utils");
|
|
3694
|
+
|
|
3695
|
+
// src/rules/_unused-private-binding.ts
|
|
3696
|
+
var import_utils32 = require("@typescript-eslint/utils");
|
|
3697
|
+
|
|
3698
|
+
// src/rules/_type-binding.ts
|
|
3699
|
+
var import_utils31 = require("@typescript-eslint/utils");
|
|
3700
|
+
function typeBinding(source, identifier) {
|
|
3701
|
+
let scope = source.getScope(identifier);
|
|
3702
|
+
while (scope !== null) {
|
|
3703
|
+
const variable = scope.set.get(identifier.name);
|
|
3704
|
+
if (variable !== void 0 && (variable.isTypeVariable || variable.defs.some((definition) => definition.isTypeDefinition))) {
|
|
3705
|
+
return variable;
|
|
3706
|
+
}
|
|
3707
|
+
scope = scope.upper;
|
|
3708
|
+
}
|
|
3709
|
+
return null;
|
|
3710
|
+
}
|
|
3711
|
+
var REFERENCE_INDEXES = /* @__PURE__ */ new WeakMap();
|
|
3712
|
+
function retainsNamedTypeUses(source, removed) {
|
|
3713
|
+
const manager = source.scopeManager;
|
|
3714
|
+
if (manager === null) return false;
|
|
3715
|
+
const index = referenceIndex(source, manager);
|
|
3716
|
+
for (const reference of referencesWithin(index.references, removed)) {
|
|
3717
|
+
if (!reference.isRead()) continue;
|
|
3718
|
+
const binding3 = reference.resolved;
|
|
3719
|
+
if (!binding3 || !reference.isTypeReference && !reference.isValueReference) return false;
|
|
3720
|
+
if (binding3.defs.length === 0) continue;
|
|
3721
|
+
const reads = publicReadExtents(index, binding3);
|
|
3722
|
+
const extent = reference.isTypeReference ? reference.isValueReference ? reads.both : reads.type : reads.value;
|
|
3723
|
+
if (extent === null || extent.minStart >= removed.range[0] && extent.maxEnd <= removed.range[1]) return false;
|
|
3724
|
+
}
|
|
3725
|
+
return true;
|
|
3726
|
+
}
|
|
3727
|
+
function referenceIndex(source, manager) {
|
|
3728
|
+
const cached = REFERENCE_INDEXES.get(source);
|
|
3729
|
+
if (cached?.manager === manager) return cached;
|
|
3730
|
+
const references = manager.scopes.flatMap((scope) => scope.references);
|
|
3731
|
+
references.sort((left, right) => left.identifier.range[0] - right.identifier.range[0]);
|
|
3732
|
+
const index = { manager, references, publicReads: /* @__PURE__ */ new Map() };
|
|
3733
|
+
REFERENCE_INDEXES.set(source, index);
|
|
3734
|
+
return index;
|
|
3735
|
+
}
|
|
3736
|
+
function* referencesWithin(references, removed) {
|
|
3737
|
+
let low = 0;
|
|
3738
|
+
let high = references.length;
|
|
3739
|
+
while (low < high) {
|
|
3740
|
+
const middle = low + Math.floor((high - low) / 2);
|
|
3741
|
+
const reference = references[middle];
|
|
3742
|
+
if (reference === void 0 || reference.identifier.range[0] >= removed.range[0]) high = middle;
|
|
3743
|
+
else low = middle + 1;
|
|
3744
|
+
}
|
|
3745
|
+
for (let index = low; index < references.length; index++) {
|
|
3746
|
+
const reference = references[index];
|
|
3747
|
+
if (reference === void 0) continue;
|
|
3748
|
+
if (reference.identifier.range[0] > removed.range[1]) break;
|
|
3749
|
+
if (insideTypeRange(reference.identifier, removed)) yield reference;
|
|
3750
|
+
}
|
|
3751
|
+
}
|
|
3752
|
+
function publicReadExtents(index, binding3) {
|
|
3753
|
+
const cached = index.publicReads.get(binding3);
|
|
3754
|
+
if (cached !== void 0) return cached;
|
|
3755
|
+
let type = null;
|
|
3756
|
+
let value = null;
|
|
3757
|
+
let both = null;
|
|
3758
|
+
for (const retained of binding3.references) {
|
|
3759
|
+
if (!retained.isRead() || !retained.isTypeReference && !retained.isValueReference || binding3.defs.some((definition) => insideTypeRange(retained.identifier, definition.node)) || !publicTypeUse(retained.identifier)) continue;
|
|
3760
|
+
if (retained.isTypeReference) type = extendExtent(type, retained.identifier);
|
|
3761
|
+
if (retained.isValueReference) value = extendExtent(value, retained.identifier);
|
|
3762
|
+
if (retained.isTypeReference && retained.isValueReference) both = extendExtent(both, retained.identifier);
|
|
3763
|
+
}
|
|
3764
|
+
const result = { type, value, both };
|
|
3765
|
+
index.publicReads.set(binding3, result);
|
|
3766
|
+
return result;
|
|
3767
|
+
}
|
|
3768
|
+
function extendExtent(extent, identifier) {
|
|
3769
|
+
return {
|
|
3770
|
+
minStart: Math.min(extent?.minStart ?? identifier.range[0], identifier.range[0]),
|
|
3771
|
+
maxEnd: Math.max(extent?.maxEnd ?? identifier.range[1], identifier.range[1])
|
|
3772
|
+
};
|
|
3773
|
+
}
|
|
3774
|
+
function publicTypeUse(identifier) {
|
|
3775
|
+
let node = identifier;
|
|
3776
|
+
while (node.parent) {
|
|
3777
|
+
if (node.type === import_utils31.AST_NODE_TYPES.TSTypeAnnotation || node.type === import_utils31.AST_NODE_TYPES.TSTypePredicate || node.type === import_utils31.AST_NODE_TYPES.TSAsExpression || node.type === import_utils31.AST_NODE_TYPES.TSTypeAssertion) return false;
|
|
3778
|
+
if (node.type === import_utils31.AST_NODE_TYPES.TSTypeAliasDeclaration) {
|
|
3779
|
+
return node.parent.type === import_utils31.AST_NODE_TYPES.ExportNamedDeclaration && node.parent.declaration === node && node.parent.parent.type === import_utils31.AST_NODE_TYPES.Program;
|
|
3780
|
+
}
|
|
3781
|
+
if (node.type === import_utils31.AST_NODE_TYPES.ExportSpecifier) {
|
|
3782
|
+
return node.parent.type === import_utils31.AST_NODE_TYPES.ExportNamedDeclaration && node.parent.source === null && node.parent.parent.type === import_utils31.AST_NODE_TYPES.Program;
|
|
3783
|
+
}
|
|
3784
|
+
node = node.parent;
|
|
3785
|
+
}
|
|
3786
|
+
return false;
|
|
3787
|
+
}
|
|
3788
|
+
function insideTypeRange(node, range) {
|
|
3789
|
+
return node.range[0] >= range.range[0] && node.range[1] <= range.range[1];
|
|
3790
|
+
}
|
|
3791
|
+
|
|
3792
|
+
// src/rules/_unused-private-binding.ts
|
|
3793
|
+
function isUnusedPrivateBinding(sourceCode, declaration, identifier, filename, allowedDeclarations = [declaration]) {
|
|
3794
|
+
if (/\.d\.[cm]?ts$/u.test(filename)) return false;
|
|
3795
|
+
const bindings = sourceCode.getDeclaredVariables(declaration).filter((binding3) => binding3.name === identifier.name);
|
|
3796
|
+
if (bindings.length === 0 || bindings.some((binding3) => binding3.defs.length !== allowedDeclarations.length || binding3.defs.some((definition) => !allowedDeclarations.includes(definition.node)) || binding3.eslintUsed || binding3.references.some((reference) => reference.isRead() || reference.init !== true))) return false;
|
|
3797
|
+
if (hasIdentifierNamed(sourceCode.ast, "eval")) return false;
|
|
3798
|
+
const statement = declaration.type === import_utils32.AST_NODE_TYPES.VariableDeclarator ? declaration.parent : declaration;
|
|
3799
|
+
if (statement.parent.type === import_utils32.AST_NODE_TYPES.ExportNamedDeclaration || statement.parent.type === import_utils32.AST_NODE_TYPES.ExportDefaultDeclaration) return false;
|
|
3800
|
+
if (statement.parent.type !== import_utils32.AST_NODE_TYPES.Program) return statement.parent.type === import_utils32.AST_NODE_TYPES.BlockStatement;
|
|
3801
|
+
return sourceCode.ast.body.some((node) => node.type === import_utils32.AST_NODE_TYPES.ImportDeclaration || node.type === import_utils32.AST_NODE_TYPES.ExportNamedDeclaration || node.type === import_utils32.AST_NODE_TYPES.ExportDefaultDeclaration || node.type === import_utils32.AST_NODE_TYPES.ExportAllDeclaration);
|
|
3802
|
+
}
|
|
3803
|
+
function hasOnlyDirectFactoryUses(variable) {
|
|
3804
|
+
return variable.references.every((reference) => {
|
|
3805
|
+
if (reference.isTypeReference && !reference.isValueReference) return true;
|
|
3806
|
+
const identifier = reference.identifier;
|
|
3807
|
+
const parent = identifier.parent;
|
|
3808
|
+
if (parent.type === import_utils32.AST_NODE_TYPES.CallExpression && parent.callee === identifier) return true;
|
|
3809
|
+
return parent.type === import_utils32.AST_NODE_TYPES.MemberExpression && parent.object === identifier && !parent.computed && parent.parent.type === import_utils32.AST_NODE_TYPES.CallExpression && parent.parent.callee === parent;
|
|
3810
|
+
});
|
|
3811
|
+
}
|
|
3812
|
+
var IDENTIFIER_NAMES = /* @__PURE__ */ new WeakMap();
|
|
3813
|
+
function hasIdentifierNamed(node, name) {
|
|
3814
|
+
let names = IDENTIFIER_NAMES.get(node);
|
|
3815
|
+
if (names === void 0) {
|
|
3816
|
+
const collected = /* @__PURE__ */ new Set();
|
|
3817
|
+
const pending = [node];
|
|
3818
|
+
const seen = /* @__PURE__ */ new WeakSet();
|
|
3819
|
+
while (pending.length > 0) {
|
|
3820
|
+
const current = pending.pop();
|
|
3821
|
+
if (current === void 0 || seen.has(current)) continue;
|
|
3822
|
+
seen.add(current);
|
|
3823
|
+
if (current.type === import_utils32.AST_NODE_TYPES.Identifier || current.type === import_utils32.AST_NODE_TYPES.JSXIdentifier) collected.add(current.name);
|
|
3824
|
+
forEachOwnAstChild(current, (child) => {
|
|
3825
|
+
pending.push(child);
|
|
3826
|
+
}, (key) => key !== "tokens" && key !== "comments");
|
|
3827
|
+
}
|
|
3828
|
+
names = collected;
|
|
3829
|
+
IDENTIFIER_NAMES.set(node, names);
|
|
3830
|
+
}
|
|
3831
|
+
return names.has(name);
|
|
3832
|
+
}
|
|
3833
|
+
function privatePredicateBooleanFix(sourceCode, node, annotation, filename) {
|
|
3834
|
+
if (!annotation.typeAnnotation || !retainsNamedTypeUses(sourceCode, annotation.typeAnnotation) || node.type !== import_utils32.AST_NODE_TYPES.FunctionDeclaration || node.id === null || !isUnusedPrivateBinding(sourceCode, node, node.id, filename) || sourceCode.getCommentsInside(annotation).length > 0) return null;
|
|
3835
|
+
const text = `boolean${sourceCode.getText(annotation).replace(/[^\r\n\u2028\u2029]/gu, "")}`;
|
|
3836
|
+
const neighbor = Math.max(0, annotation.range[0] - 1);
|
|
3837
|
+
const before = sourceCode.text.slice(neighbor, annotation.range[1] + 1).match(/\r\n|[\r\n\u2028\u2029]/gu) ?? [];
|
|
3838
|
+
const after = (sourceCode.text.slice(neighbor, annotation.range[0]) + text + sourceCode.text.slice(annotation.range[1], annotation.range[1] + 1)).match(/\r\n|[\r\n\u2028\u2029]/gu) ?? [];
|
|
3839
|
+
if (before.length !== after.length || before.some((ending, index) => ending !== after[index])) return null;
|
|
3840
|
+
return (fixer) => fixer.replaceText(annotation, text);
|
|
3841
|
+
}
|
|
3520
3842
|
|
|
3521
3843
|
// src/rules/no-redundant-local-alias.ts
|
|
3522
|
-
var import_utils32 = require("@typescript-eslint/utils");
|
|
3523
3844
|
var NO_REDUNDANT_LOCAL_ALIAS_DOCUMENTATION = {
|
|
3524
3845
|
defaultLevel: "warning",
|
|
3525
3846
|
summary: "Pass the original local into an object field instead of creating a single-use rename.",
|
|
@@ -3541,24 +3862,24 @@ var NO_REDUNDANT_LOCAL_ALIAS_DOCUMENTATION = {
|
|
|
3541
3862
|
function stableSource(variable, alias) {
|
|
3542
3863
|
const definition = variable.defs[0];
|
|
3543
3864
|
if (variable.defs.length !== 1 || definition === void 0 || variable.references.some((reference) => reference.isWrite() && !reference.init)) return false;
|
|
3544
|
-
return definition.type === "Parameter" || definition.node.type ===
|
|
3865
|
+
return definition.type === "Parameter" || definition.node.type === import_utils33.AST_NODE_TYPES.VariableDeclarator && definition.node.parent.kind === "const" && definition.node.init !== null && definition.node.range[1] < alias.range[0];
|
|
3545
3866
|
}
|
|
3546
3867
|
var PRIMITIVE_PARAMETERS = /* @__PURE__ */ new Set([
|
|
3547
|
-
|
|
3548
|
-
|
|
3549
|
-
|
|
3550
|
-
|
|
3551
|
-
|
|
3868
|
+
import_utils33.AST_NODE_TYPES.TSStringKeyword,
|
|
3869
|
+
import_utils33.AST_NODE_TYPES.TSNumberKeyword,
|
|
3870
|
+
import_utils33.AST_NODE_TYPES.TSBooleanKeyword,
|
|
3871
|
+
import_utils33.AST_NODE_TYPES.TSBigIntKeyword,
|
|
3872
|
+
import_utils33.AST_NODE_TYPES.TSSymbolKeyword
|
|
3552
3873
|
]);
|
|
3553
3874
|
function closedPrimitiveReturnFix(sourceCode, node, property, source, target) {
|
|
3554
3875
|
const statement = node.parent;
|
|
3555
3876
|
const body3 = statement.parent;
|
|
3556
|
-
if (body3.type !==
|
|
3877
|
+
if (body3.type !== import_utils33.AST_NODE_TYPES.BlockStatement) return null;
|
|
3557
3878
|
const owner = body3.parent;
|
|
3558
|
-
if (owner.type !==
|
|
3879
|
+
if (owner.type !== import_utils33.AST_NODE_TYPES.FunctionDeclaration || owner.parent.type !== import_utils33.AST_NODE_TYPES.Program || owner.id === null || owner.async || owner.generator || owner.typeParameters !== void 0 || owner.returnType !== void 0 || owner.params.length !== 1 || body3.body.length !== 2 || body3.body[0] !== statement || node.id.type !== import_utils33.AST_NODE_TYPES.Identifier || node.id.name === "__proto__" || node.init?.type !== import_utils33.AST_NODE_TYPES.Identifier || sourceCode.getCommentsInside(owner).length !== 0 || hasIdentifierNamed(sourceCode.ast, "eval")) return null;
|
|
3559
3880
|
const parameter = owner.params[0];
|
|
3560
3881
|
const returned2 = body3.body[1];
|
|
3561
|
-
if (parameter?.type !==
|
|
3882
|
+
if (parameter?.type !== import_utils33.AST_NODE_TYPES.Identifier || parameter.optional === true || parameter.typeAnnotation === void 0 || !PRIMITIVE_PARAMETERS.has(parameter.typeAnnotation.typeAnnotation.type) || returned2?.type !== import_utils33.AST_NODE_TYPES.ReturnStatement || returned2.argument !== property.parent || property.parent.type !== import_utils33.AST_NODE_TYPES.ObjectExpression || property.parent.properties.length !== 1 || import_utils33.ASTUtils.findVariable(sourceCode.getScope(parameter), parameter.name) !== source || import_utils33.ASTUtils.findVariable(sourceCode.getScope(property), node.init.name) !== source || source.references.some((reference) => reference.isTypeReference) || target.references.some((reference) => reference.isTypeReference)) return null;
|
|
3562
3883
|
const name = owner.id.name;
|
|
3563
3884
|
const bindings = sourceCode.getDeclaredVariables(owner).filter((binding3) => binding3.name === name);
|
|
3564
3885
|
if (bindings.length !== 1 || bindings[0]?.defs.length !== 1 || bindings[0].defs[0]?.node !== owner || bindings[0].references.some((reference) => reference.isTypeReference)) return null;
|
|
@@ -3585,21 +3906,21 @@ var no_redundant_local_alias_default = createRule({
|
|
|
3585
3906
|
defaultOptions: [],
|
|
3586
3907
|
create(context) {
|
|
3587
3908
|
if (isGeneratedFile(context, context.sourceCode.text)) return {};
|
|
3588
|
-
const hasModuleSyntax = context.sourceCode.ast.body.some((candidate2) => candidate2.type ===
|
|
3909
|
+
const hasModuleSyntax = context.sourceCode.ast.body.some((candidate2) => candidate2.type === import_utils33.AST_NODE_TYPES.ImportDeclaration || candidate2.type === import_utils33.AST_NODE_TYPES.ExportNamedDeclaration || candidate2.type === import_utils33.AST_NODE_TYPES.ExportDefaultDeclaration || candidate2.type === import_utils33.AST_NODE_TYPES.ExportAllDeclaration);
|
|
3589
3910
|
return {
|
|
3590
3911
|
VariableDeclarator(node) {
|
|
3591
|
-
if (node.parent.kind !== "const" || node.parent.declarations.length !== 1 || node.id.type !==
|
|
3912
|
+
if (node.parent.kind !== "const" || node.parent.declarations.length !== 1 || node.id.type !== import_utils33.AST_NODE_TYPES.Identifier || node.id.typeAnnotation !== void 0 || node.init?.type !== import_utils33.AST_NODE_TYPES.Identifier) return;
|
|
3592
3913
|
const scope = context.sourceCode.getScope(node);
|
|
3593
3914
|
if (scope.variableScope.type !== "function") return;
|
|
3594
|
-
const target =
|
|
3595
|
-
const source =
|
|
3915
|
+
const target = import_utils33.ASTUtils.findVariable(scope, node.id.name);
|
|
3916
|
+
const source = import_utils33.ASTUtils.findVariable(scope, node.init.name);
|
|
3596
3917
|
if (target === null || source === null || !stableSource(source, node)) return;
|
|
3597
3918
|
const reads = target.references.filter((reference) => reference.isRead());
|
|
3598
3919
|
if (reads.length !== 1 || target.references.some((reference) => reference.isWrite() && !reference.init)) return;
|
|
3599
3920
|
const read = reads[0];
|
|
3600
3921
|
if (read === void 0 || read.from.variableScope !== scope.variableScope) return;
|
|
3601
3922
|
const property = read.identifier.parent;
|
|
3602
|
-
if (property.type !==
|
|
3923
|
+
if (property.type !== import_utils33.AST_NODE_TYPES.Property || !property.shorthand || property.value !== read.identifier || property.parent.type !== import_utils33.AST_NODE_TYPES.ObjectExpression || property.computed || property.method || property.kind !== "init") return;
|
|
3603
3924
|
context.report({ node, messageId: "redundantAlias", fix: hasModuleSyntax ? closedPrimitiveReturnFix(context.sourceCode, node, property, source, target) : null, data: { source: node.init.name, target: node.id.name } });
|
|
3604
3925
|
}
|
|
3605
3926
|
};
|
|
@@ -3607,14 +3928,14 @@ var no_redundant_local_alias_default = createRule({
|
|
|
3607
3928
|
});
|
|
3608
3929
|
|
|
3609
3930
|
// src/rules/no-mutating-container-transform.ts
|
|
3610
|
-
var
|
|
3931
|
+
var import_utils34 = require("@typescript-eslint/utils");
|
|
3611
3932
|
var MUTATORS = /* @__PURE__ */ new Set(["copyWithin", "fill", "pop", "push", "reverse", "shift", "sort", "splice", "unshift"]);
|
|
3612
3933
|
var PRIMITIVES = /* @__PURE__ */ new Set([
|
|
3613
|
-
|
|
3614
|
-
|
|
3615
|
-
|
|
3616
|
-
|
|
3617
|
-
|
|
3934
|
+
import_utils34.AST_NODE_TYPES.TSStringKeyword,
|
|
3935
|
+
import_utils34.AST_NODE_TYPES.TSNumberKeyword,
|
|
3936
|
+
import_utils34.AST_NODE_TYPES.TSBooleanKeyword,
|
|
3937
|
+
import_utils34.AST_NODE_TYPES.TSBigIntKeyword,
|
|
3938
|
+
import_utils34.AST_NODE_TYPES.TSSymbolKeyword
|
|
3618
3939
|
]);
|
|
3619
3940
|
var NO_MUTATING_CONTAINER_TRANSFORM_DOCUMENTATION = {
|
|
3620
3941
|
defaultLevel: "warning",
|
|
@@ -3633,27 +3954,27 @@ var NO_MUTATING_CONTAINER_TRANSFORM_DOCUMENTATION = {
|
|
|
3633
3954
|
]
|
|
3634
3955
|
};
|
|
3635
3956
|
function arrayElement(node, sourceCode) {
|
|
3636
|
-
if (node.type ===
|
|
3637
|
-
if (node.type ===
|
|
3957
|
+
if (node.type === import_utils34.AST_NODE_TYPES.TSArrayType) return node.elementType;
|
|
3958
|
+
if (node.type === import_utils34.AST_NODE_TYPES.TSTypeReference && node.typeName.type === import_utils34.AST_NODE_TYPES.Identifier && (node.typeName.name === "Array" || node.typeName.name === "ReadonlyArray") && (import_utils34.ASTUtils.findVariable(sourceCode.getScope(node.typeName), node.typeName.name)?.defs.length ?? 0) === 0 && node.typeArguments?.params.length === 1) return node.typeArguments.params[0] ?? null;
|
|
3638
3959
|
return null;
|
|
3639
3960
|
}
|
|
3640
3961
|
function returnsArray(node, sourceCode) {
|
|
3641
3962
|
let annotation = node.returnType?.typeAnnotation;
|
|
3642
|
-
if (annotation?.type ===
|
|
3963
|
+
if (annotation?.type === import_utils34.AST_NODE_TYPES.TSTypeReference && annotation.typeName.type === import_utils34.AST_NODE_TYPES.Identifier && annotation.typeName.name === "Promise" && (import_utils34.ASTUtils.findVariable(sourceCode.getScope(annotation.typeName), "Promise")?.defs.length ?? 0) === 0 && annotation.typeArguments?.params.length === 1) annotation = annotation.typeArguments.params[0];
|
|
3643
3964
|
return annotation !== void 0 && arrayElement(annotation, sourceCode) !== null;
|
|
3644
3965
|
}
|
|
3645
3966
|
function supported(statements) {
|
|
3646
3967
|
return statements.every((statement) => {
|
|
3647
3968
|
switch (statement.type) {
|
|
3648
|
-
case
|
|
3649
|
-
case
|
|
3650
|
-
case
|
|
3651
|
-
case
|
|
3652
|
-
case
|
|
3969
|
+
case import_utils34.AST_NODE_TYPES.ExpressionStatement:
|
|
3970
|
+
case import_utils34.AST_NODE_TYPES.VariableDeclaration:
|
|
3971
|
+
case import_utils34.AST_NODE_TYPES.ReturnStatement:
|
|
3972
|
+
case import_utils34.AST_NODE_TYPES.ThrowStatement:
|
|
3973
|
+
case import_utils34.AST_NODE_TYPES.EmptyStatement:
|
|
3653
3974
|
return true;
|
|
3654
|
-
case
|
|
3975
|
+
case import_utils34.AST_NODE_TYPES.BlockStatement:
|
|
3655
3976
|
return supported(statement.body);
|
|
3656
|
-
case
|
|
3977
|
+
case import_utils34.AST_NODE_TYPES.IfStatement:
|
|
3657
3978
|
return supported([statement.consequent]) && (statement.alternate === null || supported([statement.alternate]));
|
|
3658
3979
|
default:
|
|
3659
3980
|
return false;
|
|
@@ -3674,13 +3995,13 @@ var no_mutating_container_transform_default = createRule({
|
|
|
3674
3995
|
if (isGeneratedFile(context, context.sourceCode.text)) return {};
|
|
3675
3996
|
const sourceCode = context.sourceCode;
|
|
3676
3997
|
function binding3(node) {
|
|
3677
|
-
return node.type ===
|
|
3998
|
+
return node.type === import_utils34.AST_NODE_TYPES.Identifier ? import_utils34.ASTUtils.findVariable(sourceCode.getScope(node), node.name) : null;
|
|
3678
3999
|
}
|
|
3679
4000
|
function inspect(node) {
|
|
3680
|
-
if (node.body?.type !==
|
|
4001
|
+
if (node.body?.type !== import_utils34.AST_NODE_TYPES.BlockStatement || !returnsArray(node, sourceCode) || !supported(node.body.body)) return;
|
|
3681
4002
|
const initial = /* @__PURE__ */ new Map();
|
|
3682
4003
|
for (const parameter of node.params) {
|
|
3683
|
-
if (parameter.type !==
|
|
4004
|
+
if (parameter.type !== import_utils34.AST_NODE_TYPES.Identifier || parameter.typeAnnotation === void 0) continue;
|
|
3684
4005
|
const element = arrayElement(parameter.typeAnnotation.typeAnnotation, sourceCode);
|
|
3685
4006
|
const variable = binding3(parameter);
|
|
3686
4007
|
if (element !== null && PRIMITIVES.has(element.type) && variable !== null) initial.set(variable, parameter.name);
|
|
@@ -3693,26 +4014,26 @@ var no_mutating_container_transform_default = createRule({
|
|
|
3693
4014
|
}
|
|
3694
4015
|
function expression(current, state) {
|
|
3695
4016
|
switch (current.type) {
|
|
3696
|
-
case
|
|
3697
|
-
case
|
|
3698
|
-
case
|
|
4017
|
+
case import_utils34.AST_NODE_TYPES.FunctionExpression:
|
|
4018
|
+
case import_utils34.AST_NODE_TYPES.ArrowFunctionExpression:
|
|
4019
|
+
case import_utils34.AST_NODE_TYPES.ClassExpression:
|
|
3699
4020
|
return;
|
|
3700
|
-
case
|
|
4021
|
+
case import_utils34.AST_NODE_TYPES.AssignmentExpression:
|
|
3701
4022
|
assignment(current, state);
|
|
3702
4023
|
return;
|
|
3703
|
-
case
|
|
4024
|
+
case import_utils34.AST_NODE_TYPES.LogicalExpression:
|
|
3704
4025
|
logical(current, state);
|
|
3705
4026
|
return;
|
|
3706
|
-
case
|
|
4027
|
+
case import_utils34.AST_NODE_TYPES.ConditionalExpression:
|
|
3707
4028
|
conditional(current, state);
|
|
3708
4029
|
return;
|
|
3709
|
-
case
|
|
4030
|
+
case import_utils34.AST_NODE_TYPES.UpdateExpression:
|
|
3710
4031
|
write(current.argument, state);
|
|
3711
4032
|
break;
|
|
3712
|
-
case
|
|
4033
|
+
case import_utils34.AST_NODE_TYPES.UnaryExpression:
|
|
3713
4034
|
if (current.operator === "delete") write(current.argument, state);
|
|
3714
4035
|
break;
|
|
3715
|
-
case
|
|
4036
|
+
case import_utils34.AST_NODE_TYPES.CallExpression:
|
|
3716
4037
|
mutationCall(current, state);
|
|
3717
4038
|
break;
|
|
3718
4039
|
default:
|
|
@@ -3732,13 +4053,13 @@ var no_mutating_container_transform_default = createRule({
|
|
|
3732
4053
|
function logical(current, state) {
|
|
3733
4054
|
expression(current.left, state);
|
|
3734
4055
|
const left = unwrapExpression(current.left);
|
|
3735
|
-
if (left.type ===
|
|
4056
|
+
if (left.type === import_utils34.AST_NODE_TYPES.Literal && (current.operator === "&&" && !left.value || current.operator === "||" && !!left.value || current.operator === "??" && left.value !== null)) return;
|
|
3736
4057
|
expression(current.right, state);
|
|
3737
4058
|
}
|
|
3738
4059
|
function conditional(current, state) {
|
|
3739
4060
|
expression(current.test, state);
|
|
3740
4061
|
const test = unwrapExpression(current.test);
|
|
3741
|
-
if (test.type ===
|
|
4062
|
+
if (test.type === import_utils34.AST_NODE_TYPES.Literal) {
|
|
3742
4063
|
expression(test.value ? current.consequent : current.alternate, state);
|
|
3743
4064
|
return;
|
|
3744
4065
|
}
|
|
@@ -3746,13 +4067,13 @@ var no_mutating_container_transform_default = createRule({
|
|
|
3746
4067
|
expression(current.alternate, state);
|
|
3747
4068
|
}
|
|
3748
4069
|
function mutationCall(current, state) {
|
|
3749
|
-
if (current.callee.type !==
|
|
4070
|
+
if (current.callee.type !== import_utils34.AST_NODE_TYPES.MemberExpression || !MUTATORS.has(import_utils34.ASTUtils.getPropertyName(current.callee) ?? "")) return;
|
|
3750
4071
|
const parameter = origin(current.callee.object, state);
|
|
3751
4072
|
if (parameter !== void 0 && first === null) first = { node: current, parameter };
|
|
3752
4073
|
}
|
|
3753
4074
|
function write(target, state) {
|
|
3754
4075
|
target = unwrapExpression(target);
|
|
3755
|
-
if (target.type !==
|
|
4076
|
+
if (target.type !== import_utils34.AST_NODE_TYPES.MemberExpression || !target.computed && import_utils34.ASTUtils.getPropertyName(target) !== "length") return;
|
|
3756
4077
|
const parameter = origin(target.object, state);
|
|
3757
4078
|
if (parameter !== void 0 && first === null) first = { node: target, parameter };
|
|
3758
4079
|
}
|
|
@@ -3762,18 +4083,18 @@ var no_mutating_container_transform_default = createRule({
|
|
|
3762
4083
|
}
|
|
3763
4084
|
function statement(current, state) {
|
|
3764
4085
|
switch (current.type) {
|
|
3765
|
-
case
|
|
4086
|
+
case import_utils34.AST_NODE_TYPES.BlockStatement:
|
|
3766
4087
|
return statements(current.body, state);
|
|
3767
|
-
case
|
|
4088
|
+
case import_utils34.AST_NODE_TYPES.IfStatement:
|
|
3768
4089
|
return branch(current, state);
|
|
3769
|
-
case
|
|
4090
|
+
case import_utils34.AST_NODE_TYPES.VariableDeclaration:
|
|
3770
4091
|
declarations(current, state);
|
|
3771
4092
|
return false;
|
|
3772
|
-
case
|
|
3773
|
-
case
|
|
4093
|
+
case import_utils34.AST_NODE_TYPES.ReturnStatement:
|
|
4094
|
+
case import_utils34.AST_NODE_TYPES.ThrowStatement:
|
|
3774
4095
|
if (current.argument !== null) expression(current.argument, state);
|
|
3775
4096
|
return true;
|
|
3776
|
-
case
|
|
4097
|
+
case import_utils34.AST_NODE_TYPES.ExpressionStatement:
|
|
3777
4098
|
expression(current.expression, state);
|
|
3778
4099
|
return false;
|
|
3779
4100
|
default:
|
|
@@ -3782,7 +4103,7 @@ var no_mutating_container_transform_default = createRule({
|
|
|
3782
4103
|
}
|
|
3783
4104
|
function branch(current, state) {
|
|
3784
4105
|
expression(current.test, state);
|
|
3785
|
-
if (current.test.type ===
|
|
4106
|
+
if (current.test.type === import_utils34.AST_NODE_TYPES.Literal) return current.test.value ? statements([current.consequent], state) : current.alternate !== null && statements([current.alternate], state);
|
|
3786
4107
|
const left = new Map(state);
|
|
3787
4108
|
const right = new Map(state);
|
|
3788
4109
|
const leftEnds = statements([current.consequent], left);
|
|
@@ -3817,60 +4138,8 @@ var no_mutating_container_transform_default = createRule({
|
|
|
3817
4138
|
var import_utils36 = require("@typescript-eslint/utils");
|
|
3818
4139
|
var import_typescript11 = __toESM(require("typescript"), 1);
|
|
3819
4140
|
|
|
3820
|
-
// src/rules/_checked-native-source.ts
|
|
3821
|
-
var import_typescript5 = __toESM(require("typescript"), 1);
|
|
3822
|
-
var CHECKED = /* @__PURE__ */ new WeakMap();
|
|
3823
|
-
var SINGLE_LINE_DIRECTIVE = /^\/\/\/?\s*@(?:ts-expect-error|ts-ignore)/u;
|
|
3824
|
-
var MULTI_LINE_DIRECTIVE = /^[/*]*\s*@(?:ts-expect-error|ts-ignore)/u;
|
|
3825
|
-
var SINGLE_LINE_PRAGMA = /^\/\/\/?\s*@([^\s:]+)(?:(?:[^\S\r\n]|:).*)?$/mu;
|
|
3826
|
-
function currentNativeSource(sourceCode, services) {
|
|
3827
|
-
const source = services.esTreeNodeToTSNodeMap.get(sourceCode.ast);
|
|
3828
|
-
return import_typescript5.default.isSourceFile(source) && services.program.getSourceFile(source.fileName) === source && source.text === sourceCode.text ? source : null;
|
|
3829
|
-
}
|
|
3830
|
-
function checkedNativeSource(program, source) {
|
|
3831
|
-
let files = CHECKED.get(program);
|
|
3832
|
-
if (!files) {
|
|
3833
|
-
files = /* @__PURE__ */ new WeakMap();
|
|
3834
|
-
CHECKED.set(program, files);
|
|
3835
|
-
}
|
|
3836
|
-
const known2 = files.get(source);
|
|
3837
|
-
if (known2 !== void 0) return known2;
|
|
3838
|
-
const available = !program.getCompilerOptions().noCheck && !source.isDeclarationFile && (source.flags & (import_typescript5.default.NodeFlags.JavaScriptFile | import_typescript5.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_typescript5.default.DiagnosticCategory.Error && diagnostic.file === source) && !checkingSuppressed(source) && !program.getSemanticDiagnostics(source).some((diagnostic) => diagnostic.category === import_typescript5.default.DiagnosticCategory.Error && diagnostic.file === source);
|
|
3839
|
-
files.set(source, available);
|
|
3840
|
-
return available;
|
|
3841
|
-
}
|
|
3842
|
-
function checkingSuppressed(source) {
|
|
3843
|
-
if (!/@ts-/iu.test(source.text)) return false;
|
|
3844
|
-
if (import_typescript5.default.getLeadingCommentRanges(source.text, 0)?.some((comment) => comment.kind === import_typescript5.default.SyntaxKind.SingleLineCommentTrivia && SINGLE_LINE_PRAGMA.exec(source.text.slice(comment.pos, comment.end))?.[1]?.toLowerCase() === "ts-nocheck")) return true;
|
|
3845
|
-
const pending = [source];
|
|
3846
|
-
while (pending.length) {
|
|
3847
|
-
const node = pending.pop();
|
|
3848
|
-
if (!node || import_typescript5.default.isJsxText(node) || import_typescript5.default.isJSDoc(node) || (node.flags & import_typescript5.default.NodeFlags.JSDoc) !== 0) continue;
|
|
3849
|
-
if (!import_typescript5.default.isToken(node)) {
|
|
3850
|
-
for (const child of node.getChildren(source)) pending.push(child);
|
|
3851
|
-
continue;
|
|
3852
|
-
}
|
|
3853
|
-
if (tokenTriviaSuppressesChecking(node, source)) return true;
|
|
3854
|
-
}
|
|
3855
|
-
return false;
|
|
3856
|
-
}
|
|
3857
|
-
function tokenTriviaSuppressesChecking(node, source) {
|
|
3858
|
-
const start = node.getStart(source);
|
|
3859
|
-
for (const comment of [...import_typescript5.default.getLeadingCommentRanges(source.text, node.pos) ?? [], ...import_typescript5.default.getTrailingCommentRanges(source.text, node.pos) ?? []]) {
|
|
3860
|
-
if (comment.pos < node.pos || comment.end > start) continue;
|
|
3861
|
-
if (commentSuppressesChecking(source.text.slice(comment.pos, comment.end), comment.kind)) return true;
|
|
3862
|
-
}
|
|
3863
|
-
return false;
|
|
3864
|
-
}
|
|
3865
|
-
function commentSuppressesChecking(text, kind) {
|
|
3866
|
-
if (kind === import_typescript5.default.SyntaxKind.SingleLineCommentTrivia) return SINGLE_LINE_DIRECTIVE.test(text);
|
|
3867
|
-
let lastLine = text.length;
|
|
3868
|
-
while (lastLine > 0 && !import_typescript5.default.isLineBreak(text.charCodeAt(lastLine - 1))) lastLine--;
|
|
3869
|
-
return MULTI_LINE_DIRECTIVE.test(text.slice(lastLine).trimStart());
|
|
3870
|
-
}
|
|
3871
|
-
|
|
3872
4141
|
// src/rules/_closed-object-contract.ts
|
|
3873
|
-
var
|
|
4142
|
+
var import_typescript9 = __toESM(require("typescript"), 1);
|
|
3874
4143
|
function closedObjectContract(type, checker, singlePropertyOrigins = false) {
|
|
3875
4144
|
return visitContract(type, {
|
|
3876
4145
|
checker,
|
|
@@ -3892,7 +4161,7 @@ function visitContract(type, proof) {
|
|
|
3892
4161
|
function completeObject(type, proof) {
|
|
3893
4162
|
if (!ordinaryObject(type, proof.checker)) return false;
|
|
3894
4163
|
if (proof.origins && !singleOrigins(type, proof.origins)) return false;
|
|
3895
|
-
const declarations = type.getSymbol()?.getDeclarations()?.filter((declaration) =>
|
|
4164
|
+
const declarations = type.getSymbol()?.getDeclarations()?.filter((declaration) => import_typescript9.default.isInterfaceDeclaration(declaration) || import_typescript9.default.isTypeLiteralNode(declaration));
|
|
3896
4165
|
if (!declarations?.length) return false;
|
|
3897
4166
|
return declarations.every((declaration) => completeDeclaration(declaration, proof));
|
|
3898
4167
|
}
|
|
@@ -3906,36 +4175,36 @@ function singleOrigins(type, origins) {
|
|
|
3906
4175
|
return true;
|
|
3907
4176
|
}
|
|
3908
4177
|
function ordinaryObject(type, checker) {
|
|
3909
|
-
if ((type.flags &
|
|
4178
|
+
if ((type.flags & import_typescript9.default.TypeFlags.Object) === 0 || type.isUnion() || checker.getIndexInfosOfType(type).length > 0) return false;
|
|
3910
4179
|
const object = type;
|
|
3911
|
-
if ((object.objectFlags & (
|
|
3912
|
-
if ((object.objectFlags &
|
|
3913
|
-
return checker.getSignaturesOfType(type,
|
|
4180
|
+
if ((object.objectFlags & (import_typescript9.default.ObjectFlags.Class | import_typescript9.default.ObjectFlags.Mapped)) !== 0) return false;
|
|
4181
|
+
if ((object.objectFlags & import_typescript9.default.ObjectFlags.Reference) !== 0 && checker.getTypeArguments(type).some((argument) => (argument.flags & (import_typescript9.default.TypeFlags.Any | import_typescript9.default.TypeFlags.Unknown | import_typescript9.default.TypeFlags.TypeParameter)) !== 0)) return false;
|
|
4182
|
+
return checker.getSignaturesOfType(type, import_typescript9.default.SignatureKind.Call).length === 0 && checker.getSignaturesOfType(type, import_typescript9.default.SignatureKind.Construct).length === 0;
|
|
3914
4183
|
}
|
|
3915
4184
|
function completeDeclaration(declaration, proof) {
|
|
3916
4185
|
if (!declaration.members.every((member3) => finiteMember(member3, proof.checker))) return false;
|
|
3917
|
-
if (!
|
|
4186
|
+
if (!import_typescript9.default.isInterfaceDeclaration(declaration)) return true;
|
|
3918
4187
|
if (declaration.typeParameters?.length) return false;
|
|
3919
4188
|
return (declaration.heritageClauses ?? []).every((heritage) => heritage.types.every((base) => visitContract(proof.checker.getTypeAtLocation(base), proof)));
|
|
3920
4189
|
}
|
|
3921
4190
|
function finiteMember(member3, checker) {
|
|
3922
|
-
if (
|
|
3923
|
-
if (!member3.name || !
|
|
3924
|
-
return (checker.getTypeAtLocation(member3.name.expression).flags & (
|
|
4191
|
+
if (import_typescript9.default.isIndexSignatureDeclaration(member3)) return false;
|
|
4192
|
+
if (!member3.name || !import_typescript9.default.isComputedPropertyName(member3.name)) return true;
|
|
4193
|
+
return (checker.getTypeAtLocation(member3.name.expression).flags & (import_typescript9.default.TypeFlags.StringLiteral | import_typescript9.default.TypeFlags.NumberLiteral | import_typescript9.default.TypeFlags.UniqueESSymbol)) !== 0;
|
|
3925
4194
|
}
|
|
3926
4195
|
|
|
3927
4196
|
// src/rules/_private-consumer-fix.ts
|
|
3928
|
-
var
|
|
3929
|
-
var
|
|
3930
|
-
var UNSAFE =
|
|
4197
|
+
var import_utils35 = require("@typescript-eslint/utils");
|
|
4198
|
+
var import_typescript10 = __toESM(require("typescript"), 1);
|
|
4199
|
+
var UNSAFE = import_typescript10.default.TypeFlags.Any | import_typescript10.default.TypeFlags.Unknown | import_typescript10.default.TypeFlags.Never | import_typescript10.default.TypeFlags.TypeParameter | import_typescript10.default.TypeFlags.Conditional | import_typescript10.default.TypeFlags.IndexedAccess | import_typescript10.default.TypeFlags.Substitution;
|
|
3931
4200
|
function validConsumerFixCalls(node, parameter, sourceCode, services) {
|
|
3932
4201
|
if (sourceCode.getAllComments().some((comment) => /@ts-(?:expect-error|ignore|nocheck)\b/u.test(comment.value))) return false;
|
|
3933
|
-
const owner = node.type ===
|
|
3934
|
-
if (owner.type !==
|
|
4202
|
+
const owner = node.type === import_utils35.AST_NODE_TYPES.FunctionDeclaration ? node : node.parent;
|
|
4203
|
+
if (owner.type !== import_utils35.AST_NODE_TYPES.FunctionDeclaration && owner.type !== import_utils35.AST_NODE_TYPES.VariableDeclarator) return false;
|
|
3935
4204
|
const binding3 = sourceCode.getDeclaredVariables(owner).find((variable) => variable.defs.some((definition) => definition.node === owner && (definition.type === "FunctionName" || definition.type === "Variable")));
|
|
3936
4205
|
if (!binding3) return false;
|
|
3937
4206
|
const declaration = services.esTreeNodeToTSNodeMap.get(node);
|
|
3938
|
-
if (!
|
|
4207
|
+
if (!import_typescript10.default.isFunctionDeclaration(declaration) && !import_typescript10.default.isArrowFunction(declaration) || parameter.parent !== declaration || declaration.parameters.some((entry) => import_typescript10.default.isIdentifier(entry.name) && entry.name.text === "this")) return false;
|
|
3939
4208
|
const selected = declaration.parameters.indexOf(parameter);
|
|
3940
4209
|
if (selected < 0) return false;
|
|
3941
4210
|
const checker = services.program.getTypeChecker();
|
|
@@ -3951,7 +4220,7 @@ function validConsumerFixCalls(node, parameter, sourceCode, services) {
|
|
|
3951
4220
|
const validArguments = (call) => {
|
|
3952
4221
|
if (declaration.parameters.length > 1) {
|
|
3953
4222
|
const nativeCall = services.esTreeNodeToTSNodeMap.get(call);
|
|
3954
|
-
if (!
|
|
4223
|
+
if (!import_typescript10.default.isCallExpression(nativeCall) || checker.getResolvedSignature(nativeCall)?.declaration !== declaration) return false;
|
|
3955
4224
|
}
|
|
3956
4225
|
return call.arguments.every((argument, index) => {
|
|
3957
4226
|
const target = originals[index];
|
|
@@ -3967,7 +4236,7 @@ function validConsumerFixCalls(node, parameter, sourceCode, services) {
|
|
|
3967
4236
|
continue;
|
|
3968
4237
|
}
|
|
3969
4238
|
const call = reference.identifier.parent;
|
|
3970
|
-
if (reference.isTypeReference || !reference.isReadOnly() || call.type !==
|
|
4239
|
+
if (reference.isTypeReference || !reference.isReadOnly() || call.type !== import_utils35.AST_NODE_TYPES.CallExpression || call.callee !== reference.identifier || call.optional || call.typeArguments || call.arguments.length !== declaration.parameters.length || !call.arguments.every((argument) => argument.type === import_utils35.AST_NODE_TYPES.Identifier) || !validArguments(call)) return false;
|
|
3971
4240
|
calls += 1;
|
|
3972
4241
|
}
|
|
3973
4242
|
return calls > 0;
|
|
@@ -4018,250 +4287,6 @@ function minimalConsumerFix(sourceCode, annotation, removed) {
|
|
|
4018
4287
|
return sameLineTerminators(sourceCode, annotation, text) ? (fixer) => fixer.replaceText(annotation, text) : null;
|
|
4019
4288
|
}
|
|
4020
4289
|
|
|
4021
|
-
// src/rules/_private-scalar-consumer.ts
|
|
4022
|
-
var import_utils35 = require("@typescript-eslint/utils");
|
|
4023
|
-
var import_typescript10 = __toESM(require("typescript"), 1);
|
|
4024
|
-
|
|
4025
|
-
// src/rules/_scalar-parameter-view.ts
|
|
4026
|
-
var import_typescript9 = __toESM(require("typescript"), 1);
|
|
4027
|
-
|
|
4028
|
-
// src/rules/_native-const-value.ts
|
|
4029
|
-
var import_typescript8 = __toESM(require("typescript"), 1);
|
|
4030
|
-
function constInitializer(declaration) {
|
|
4031
|
-
if (!declaration || !import_typescript8.default.isVariableDeclaration(declaration) || !import_typescript8.default.isVariableDeclarationList(declaration.parent) || (declaration.parent.flags & import_typescript8.default.NodeFlags.BlockScoped) !== import_typescript8.default.NodeFlags.Const) return void 0;
|
|
4032
|
-
let initializer = declaration.initializer;
|
|
4033
|
-
while (initializer && import_typescript8.default.isParenthesizedExpression(initializer)) initializer = initializer.expression;
|
|
4034
|
-
return initializer;
|
|
4035
|
-
}
|
|
4036
|
-
function unassertedValue(node) {
|
|
4037
|
-
let value = node;
|
|
4038
|
-
while (import_typescript8.default.isParenthesizedExpression(value) || import_typescript8.default.isAsExpression(value) || import_typescript8.default.isTypeAssertionExpression(value) || import_typescript8.default.isNonNullExpression(value) || import_typescript8.default.isSatisfiesExpression(value)) value = value.expression;
|
|
4039
|
-
return value;
|
|
4040
|
-
}
|
|
4041
|
-
|
|
4042
|
-
// src/rules/_scalar-parameter-view.ts
|
|
4043
|
-
var SCALAR_OPERATORS = /* @__PURE__ */ new Set([
|
|
4044
|
-
import_typescript9.default.SyntaxKind.PlusToken,
|
|
4045
|
-
import_typescript9.default.SyntaxKind.MinusToken,
|
|
4046
|
-
import_typescript9.default.SyntaxKind.AsteriskToken,
|
|
4047
|
-
import_typescript9.default.SyntaxKind.SlashToken,
|
|
4048
|
-
import_typescript9.default.SyntaxKind.PercentToken,
|
|
4049
|
-
import_typescript9.default.SyntaxKind.AsteriskAsteriskToken,
|
|
4050
|
-
import_typescript9.default.SyntaxKind.LessThanToken,
|
|
4051
|
-
import_typescript9.default.SyntaxKind.LessThanEqualsToken,
|
|
4052
|
-
import_typescript9.default.SyntaxKind.GreaterThanToken,
|
|
4053
|
-
import_typescript9.default.SyntaxKind.GreaterThanEqualsToken,
|
|
4054
|
-
import_typescript9.default.SyntaxKind.EqualsEqualsEqualsToken,
|
|
4055
|
-
import_typescript9.default.SyntaxKind.ExclamationEqualsEqualsToken,
|
|
4056
|
-
import_typescript9.default.SyntaxKind.EqualsEqualsToken,
|
|
4057
|
-
import_typescript9.default.SyntaxKind.ExclamationEqualsToken,
|
|
4058
|
-
import_typescript9.default.SyntaxKind.AmpersandAmpersandToken,
|
|
4059
|
-
import_typescript9.default.SyntaxKind.BarBarToken,
|
|
4060
|
-
import_typescript9.default.SyntaxKind.QuestionQuestionToken
|
|
4061
|
-
]);
|
|
4062
|
-
var SCALAR_PREFIXES = /* @__PURE__ */ new Set([import_typescript9.default.SyntaxKind.PlusToken, import_typescript9.default.SyntaxKind.MinusToken, import_typescript9.default.SyntaxKind.ExclamationToken, import_typescript9.default.SyntaxKind.TildeToken]);
|
|
4063
|
-
var RETURNED_OPERANDS = /* @__PURE__ */ new Set([import_typescript9.default.SyntaxKind.AmpersandAmpersandToken, import_typescript9.default.SyntaxKind.BarBarToken, import_typescript9.default.SyntaxKind.QuestionQuestionToken]);
|
|
4064
|
-
function scalarParameterView(parameter, body3, checker) {
|
|
4065
|
-
return parameterReads(parameter, body3, checker, true);
|
|
4066
|
-
}
|
|
4067
|
-
function scalarParameterReads(parameter, body3, checker, callProgram, auxiliaries) {
|
|
4068
|
-
return parameterReads(parameter, body3, checker, false, callProgram, auxiliaries);
|
|
4069
|
-
}
|
|
4070
|
-
function parameterReads(parameter, body3, checker, jsx, callProgram, auxiliaries) {
|
|
4071
|
-
if (parameter.dotDotDotToken || parameter.initializer || import_typescript9.default.isArrayBindingPattern(parameter.name)) return null;
|
|
4072
|
-
const root = import_typescript9.default.isIdentifier(parameter.name) ? checker.getSymbolAtLocation(parameter.name) : void 0;
|
|
4073
|
-
if (import_typescript9.default.isIdentifier(parameter.name) && !root) return null;
|
|
4074
|
-
const reads = /* @__PURE__ */ new Set();
|
|
4075
|
-
const aliases = parameterAliases(parameter.name, checker, reads);
|
|
4076
|
-
if (!aliases) return null;
|
|
4077
|
-
const expression = returnedExpression(body3);
|
|
4078
|
-
const view = { checker, props: checker.getTypeAtLocation(parameter), root, aliases, reads, callProgram, auxiliaries };
|
|
4079
|
-
return expression && scalarView(expression, view, jsx) ? reads : null;
|
|
4080
|
-
}
|
|
4081
|
-
function scalarType(type, allowUndefined = true) {
|
|
4082
|
-
if (type.isUnion()) return type.types.every((part) => scalarType(part, allowUndefined));
|
|
4083
|
-
const flags = import_typescript9.default.TypeFlags.StringLike | import_typescript9.default.TypeFlags.NumberLike | import_typescript9.default.TypeFlags.BooleanLike | import_typescript9.default.TypeFlags.BigIntLike | import_typescript9.default.TypeFlags.Null;
|
|
4084
|
-
return (type.flags & (allowUndefined ? flags | import_typescript9.default.TypeFlags.Undefined : flags)) !== 0;
|
|
4085
|
-
}
|
|
4086
|
-
function parameterAliases(name, checker, reads) {
|
|
4087
|
-
const aliases = /* @__PURE__ */ new Map();
|
|
4088
|
-
if (import_typescript9.default.isIdentifier(name)) return aliases;
|
|
4089
|
-
for (const element of name.elements) {
|
|
4090
|
-
const key = element.propertyName ?? element.name;
|
|
4091
|
-
if (element.dotDotDotToken || element.initializer || !import_typescript9.default.isIdentifier(element.name) || !import_typescript9.default.isIdentifier(key) && !import_typescript9.default.isStringLiteralLike(key) && !import_typescript9.default.isNumericLiteral(key)) return null;
|
|
4092
|
-
const binding3 = checker.getSymbolAtLocation(element.name);
|
|
4093
|
-
if (!binding3) return null;
|
|
4094
|
-
reads.add(key.text);
|
|
4095
|
-
aliases.set(binding3, key.text);
|
|
4096
|
-
}
|
|
4097
|
-
return aliases;
|
|
4098
|
-
}
|
|
4099
|
-
function returnedExpression(body3) {
|
|
4100
|
-
if (!import_typescript9.default.isBlock(body3)) return body3;
|
|
4101
|
-
const statement = body3.statements.length === 1 ? body3.statements[0] : void 0;
|
|
4102
|
-
return statement && import_typescript9.default.isReturnStatement(statement) ? statement.expression : void 0;
|
|
4103
|
-
}
|
|
4104
|
-
function scalarView(node, view, jsx = false) {
|
|
4105
|
-
if (scalarLiteral(node)) return true;
|
|
4106
|
-
if (import_typescript9.default.isCallExpression(node)) return !jsx && scalarCall(node, view);
|
|
4107
|
-
if (import_typescript9.default.isJsxExpression(node)) return !node.dotDotDotToken && (!node.expression || scalarView(node.expression, view, jsx));
|
|
4108
|
-
if (import_typescript9.default.isIdentifier(node)) {
|
|
4109
|
-
const binding3 = view.checker.getSymbolAtLocation(node);
|
|
4110
|
-
if (binding3 && view.auxiliaries?.has(binding3)) return scalarType(view.checker.getTypeAtLocation(node));
|
|
4111
|
-
const key = binding3 && view.aliases.get(binding3);
|
|
4112
|
-
return key !== void 0 && readField(node, key, view);
|
|
4113
|
-
}
|
|
4114
|
-
if (import_typescript9.default.isPropertyAccessExpression(node) || import_typescript9.default.isElementAccessExpression(node)) return memberRead(node, view);
|
|
4115
|
-
return scalarOperation(node, view, jsx);
|
|
4116
|
-
}
|
|
4117
|
-
function scalarOperation(node, view, jsx) {
|
|
4118
|
-
if (import_typescript9.default.isParenthesizedExpression(node) || import_typescript9.default.isNonNullExpression(node)) return scalarView(node.expression, view, jsx);
|
|
4119
|
-
if (import_typescript9.default.isTypeOfExpression(node)) return scalarView(node.expression, view);
|
|
4120
|
-
if (import_typescript9.default.isConditionalExpression(node)) return scalarView(node.condition, view) && scalarView(node.whenTrue, view, jsx) && scalarView(node.whenFalse, view, jsx);
|
|
4121
|
-
if (import_typescript9.default.isBinaryExpression(node)) return binaryView(node, view, jsx);
|
|
4122
|
-
if (import_typescript9.default.isPrefixUnaryExpression(node)) return SCALAR_PREFIXES.has(node.operator) && scalarView(node.operand, view);
|
|
4123
|
-
if (import_typescript9.default.isTemplateExpression(node)) return node.templateSpans.every((span) => scalarView(span.expression, view));
|
|
4124
|
-
return jsx && jsxView(node, view);
|
|
4125
|
-
}
|
|
4126
|
-
function scalarCall(node, view) {
|
|
4127
|
-
if (!view.callProgram || node.questionDotToken || node.typeArguments?.length || !import_typescript9.default.isIdentifier(node.expression) || !node.arguments.length || node.arguments.some(import_typescript9.default.isSpreadElement)) return false;
|
|
4128
|
-
const declarations = view.checker.getSymbolAtLocation(node.expression)?.declarations;
|
|
4129
|
-
const declaration = declarations?.length === 1 ? declarations[0] : void 0;
|
|
4130
|
-
const helper = declaration && localHelper(declaration);
|
|
4131
|
-
if (!helper || helper.getSourceFile() !== node.getSourceFile() || helper.typeParameters?.length || !helper.type || !node.arguments.every((argument) => scalarView(argument, view))) return false;
|
|
4132
|
-
if (!checkedNativeSource(view.callProgram, node.getSourceFile())) return false;
|
|
4133
|
-
const signature = view.checker.getResolvedSignature(node);
|
|
4134
|
-
return signature?.declaration === helper && !view.checker.getTypePredicateOfSignature(signature) && scalarType(view.checker.getTypeAtLocation(node));
|
|
4135
|
-
}
|
|
4136
|
-
function localHelper(node) {
|
|
4137
|
-
if (import_typescript9.default.isFunctionDeclaration(node)) return node.body && import_typescript9.default.isSourceFile(node.parent) ? node : void 0;
|
|
4138
|
-
if (!import_typescript9.default.isVariableDeclaration(node) || node.type || !node.initializer || constInitializer(node) !== node.initializer || !import_typescript9.default.isArrowFunction(node.initializer) || !import_typescript9.default.isVariableStatement(node.parent.parent) || !import_typescript9.default.isSourceFile(node.parent.parent.parent)) return void 0;
|
|
4139
|
-
return node.initializer;
|
|
4140
|
-
}
|
|
4141
|
-
function binaryView(node, view, jsx) {
|
|
4142
|
-
const returned2 = jsx && RETURNED_OPERANDS.has(node.operatorToken.kind);
|
|
4143
|
-
return SCALAR_OPERATORS.has(node.operatorToken.kind) && scalarView(node.left, view, returned2) && scalarView(node.right, view, returned2);
|
|
4144
|
-
}
|
|
4145
|
-
function scalarLiteral(node) {
|
|
4146
|
-
return import_typescript9.default.isStringLiteralLike(node) || import_typescript9.default.isNumericLiteral(node) || import_typescript9.default.isBigIntLiteral(node) || import_typescript9.default.isJsxText(node) || node.kind === import_typescript9.default.SyntaxKind.TrueKeyword || node.kind === import_typescript9.default.SyntaxKind.FalseKeyword || node.kind === import_typescript9.default.SyntaxKind.NullKeyword;
|
|
4147
|
-
}
|
|
4148
|
-
function memberRead(node, view) {
|
|
4149
|
-
if (!view.root || !import_typescript9.default.isIdentifier(node.expression) || view.checker.getSymbolAtLocation(node.expression) !== view.root) return false;
|
|
4150
|
-
const key = import_typescript9.default.isPropertyAccessExpression(node) ? node.name.text : node.argumentExpression && (import_typescript9.default.isStringLiteralLike(node.argumentExpression) || import_typescript9.default.isNumericLiteral(node.argumentExpression)) ? node.argumentExpression.text : void 0;
|
|
4151
|
-
return key !== void 0 && readField(node, key, view);
|
|
4152
|
-
}
|
|
4153
|
-
function readField(node, key, view) {
|
|
4154
|
-
if (!view.checker.getPropertyOfType(view.props, key) || !scalarType(view.checker.getTypeAtLocation(node))) return false;
|
|
4155
|
-
view.reads.add(key);
|
|
4156
|
-
return true;
|
|
4157
|
-
}
|
|
4158
|
-
function jsxView(node, view) {
|
|
4159
|
-
if (import_typescript9.default.isJsxFragment(node)) return node.children.every((child) => scalarView(child, view, true));
|
|
4160
|
-
if (import_typescript9.default.isJsxElement(node)) return jsxView(node.openingElement, view) && node.children.every((child) => scalarView(child, view, true));
|
|
4161
|
-
if (!import_typescript9.default.isJsxOpeningElement(node) && !import_typescript9.default.isJsxSelfClosingElement(node)) return false;
|
|
4162
|
-
if (!import_typescript9.default.isIdentifier(node.tagName) || !/^[a-z][A-Za-z0-9]*$/u.test(node.tagName.text)) return false;
|
|
4163
|
-
return node.attributes.properties.every((attribute) => intrinsicAttribute(attribute, view));
|
|
4164
|
-
}
|
|
4165
|
-
function intrinsicAttribute(attribute, view) {
|
|
4166
|
-
return import_typescript9.default.isJsxAttribute(attribute) && import_typescript9.default.isIdentifier(attribute.name) && attribute.name.text !== "is" && (!attribute.initializer || scalarView(attribute.initializer, view));
|
|
4167
|
-
}
|
|
4168
|
-
|
|
4169
|
-
// src/rules/_private-scalar-consumer.ts
|
|
4170
|
-
function directEval(node) {
|
|
4171
|
-
let callee = unwrapExpression(node.callee);
|
|
4172
|
-
while (callee.type === import_utils35.AST_NODE_TYPES.TSInstantiationExpression) callee = unwrapExpression(callee.expression);
|
|
4173
|
-
return callee.type === import_utils35.AST_NODE_TYPES.Identifier && callee.name === "eval";
|
|
4174
|
-
}
|
|
4175
|
-
function primitiveKeyword(node) {
|
|
4176
|
-
return node !== void 0 && (node.kind === import_typescript10.default.SyntaxKind.StringKeyword || node.kind === import_typescript10.default.SyntaxKind.NumberKeyword || node.kind === import_typescript10.default.SyntaxKind.BooleanKeyword || node.kind === import_typescript10.default.SyntaxKind.BigIntKeyword);
|
|
4177
|
-
}
|
|
4178
|
-
function nullishPrimitiveUnion(node) {
|
|
4179
|
-
return node !== void 0 && import_typescript10.default.isUnionTypeNode(node) && node.types.length === 2 && node.types.some(primitiveKeyword) && node.types.some((part) => part.kind === import_typescript10.default.SyntaxKind.UndefinedKeyword || import_typescript10.default.isLiteralTypeNode(part) && part.literal.kind === import_typescript10.default.SyntaxKind.NullKeyword);
|
|
4180
|
-
}
|
|
4181
|
-
function consumerAnnotation(node, auxiliaryScalars = false) {
|
|
4182
|
-
if (node.params.length !== 1) {
|
|
4183
|
-
if (!auxiliaryScalars) return void 0;
|
|
4184
|
-
let annotation;
|
|
4185
|
-
for (const parameter2 of node.params) {
|
|
4186
|
-
if (parameter2.type !== import_utils35.AST_NODE_TYPES.Identifier && parameter2.type !== import_utils35.AST_NODE_TYPES.ObjectPattern) continue;
|
|
4187
|
-
const current = parameter2.typeAnnotation?.typeAnnotation;
|
|
4188
|
-
if (current?.type !== import_utils35.AST_NODE_TYPES.TSTypeLiteral) continue;
|
|
4189
|
-
if (annotation) return void 0;
|
|
4190
|
-
annotation = current;
|
|
4191
|
-
}
|
|
4192
|
-
return annotation;
|
|
4193
|
-
}
|
|
4194
|
-
const parameter = node.params[0];
|
|
4195
|
-
return parameter?.type === import_utils35.AST_NODE_TYPES.Identifier || parameter?.type === import_utils35.AST_NODE_TYPES.ObjectPattern ? parameter.typeAnnotation?.typeAnnotation : void 0;
|
|
4196
|
-
}
|
|
4197
|
-
function exportedSymbols(source, checker) {
|
|
4198
|
-
const symbol = checker.getSymbolAtLocation(source);
|
|
4199
|
-
return new Set(symbol ? checker.getExportsOfModule(symbol).map((entry) => (entry.flags & import_typescript10.default.SymbolFlags.Alias) !== 0 ? checker.getAliasedSymbol(entry) : entry) : []);
|
|
4200
|
-
}
|
|
4201
|
-
function privateScalarConsumer(node, sourceCode, services, exports2, options = {}) {
|
|
4202
|
-
const native = services.esTreeNodeToTSNodeMap.get(node);
|
|
4203
|
-
if (!import_typescript10.default.isFunctionDeclaration(native) && !import_typescript10.default.isArrowFunction(native) || !native.body) return null;
|
|
4204
|
-
let parameter = native.parameters[0];
|
|
4205
|
-
if (native.parameters.length !== 1) {
|
|
4206
|
-
const annotation = consumerAnnotation(node, options.auxiliaryScalars);
|
|
4207
|
-
const selected = annotation && services.esTreeNodeToTSNodeMap.get(annotation);
|
|
4208
|
-
parameter = native.parameters.find((entry) => entry.type === selected);
|
|
4209
|
-
}
|
|
4210
|
-
if (!parameter || !independentSignature(native, parameter, options.auxiliaryScalars === true)) return null;
|
|
4211
|
-
const checker = services.program.getTypeChecker();
|
|
4212
|
-
if (!import_typescript10.default.isExternalModule(native.getSourceFile()) || !services.program.getCompilerOptions().strict) return null;
|
|
4213
|
-
if (!privateDirectCallable(node, native, sourceCode, checker, exports2)) return null;
|
|
4214
|
-
const signature = checker.getSignatureFromDeclaration(native);
|
|
4215
|
-
if (!signature || signature.typeParameters?.length || checker.getTypePredicateOfSignature(signature)) return null;
|
|
4216
|
-
const expression = returnedExpression(native.body);
|
|
4217
|
-
if (!expression || !checker.isTypeAssignableTo(checker.getTypeAtLocation(expression), checker.getReturnTypeOfSignature(signature))) return null;
|
|
4218
|
-
const auxiliaries = native.parameters.length > 1 ? auxiliaryBindings(native, parameter, checker) : void 0;
|
|
4219
|
-
if (auxiliaries === null) return null;
|
|
4220
|
-
const reads = scalarParameterReads(parameter, native.body, checker, options.scalarCalls ? services.program : void 0, auxiliaries);
|
|
4221
|
-
return reads?.size ? { parameter, reads } : null;
|
|
4222
|
-
}
|
|
4223
|
-
function privateDirectCallable(node, native, sourceCode, checker, exports2) {
|
|
4224
|
-
const binding3 = callableBinding(node, sourceCode);
|
|
4225
|
-
if (!binding3 || binding3.defs.length !== 1) return false;
|
|
4226
|
-
const name = import_typescript10.default.isFunctionDeclaration(native) ? native.name : import_typescript10.default.isVariableDeclaration(native.parent) ? native.parent.name : void 0;
|
|
4227
|
-
const symbol = name && checker.getSymbolAtLocation(name);
|
|
4228
|
-
return symbol !== void 0 && symbol.declarations?.length === 1 && !exports2.has(symbol) && directCalls(binding3, native.parameters.length);
|
|
4229
|
-
}
|
|
4230
|
-
function independentSignature(native, selected, auxiliaryScalars) {
|
|
4231
|
-
if (!auxiliaryScalars && native.parameters.length !== 1 || native.typeParameters?.length || native.asteriskToken || native.modifiers?.length || !primitiveKeyword(native.type)) return false;
|
|
4232
|
-
return native.parameters.every((parameter) => parameter.type !== void 0 && !parameter.modifiers?.length && !parameter.questionToken && !parameter.initializer && !parameter.dotDotDotToken && (!import_typescript10.default.isIdentifier(parameter.name) || parameter.name.text !== "this") && (parameter === selected || import_typescript10.default.isIdentifier(parameter.name) && primitiveKeyword(parameter.type)));
|
|
4233
|
-
}
|
|
4234
|
-
function auxiliaryBindings(native, selected, checker) {
|
|
4235
|
-
const bindings = /* @__PURE__ */ new Set();
|
|
4236
|
-
for (const parameter of native.parameters) {
|
|
4237
|
-
if (parameter === selected) continue;
|
|
4238
|
-
const symbol = import_typescript10.default.isIdentifier(parameter.name) ? checker.getSymbolAtLocation(parameter.name) : void 0;
|
|
4239
|
-
if (!symbol || symbol.declarations?.length !== 1 || symbol.declarations[0] !== parameter || bindings.has(symbol)) return null;
|
|
4240
|
-
bindings.add(symbol);
|
|
4241
|
-
}
|
|
4242
|
-
return bindings;
|
|
4243
|
-
}
|
|
4244
|
-
function callableBinding(node, sourceCode) {
|
|
4245
|
-
if (node.type === import_utils35.AST_NODE_TYPES.FunctionDeclaration) {
|
|
4246
|
-
if (node.parent.type !== import_utils35.AST_NODE_TYPES.Program) return void 0;
|
|
4247
|
-
return sourceCode.getDeclaredVariables(node).find((variable) => variable.defs.some((definition) => definition.type === "FunctionName" && definition.node === node));
|
|
4248
|
-
}
|
|
4249
|
-
const declaration = node.parent;
|
|
4250
|
-
if (declaration.type !== import_utils35.AST_NODE_TYPES.VariableDeclarator || declaration.init !== node || declaration.id.type !== import_utils35.AST_NODE_TYPES.Identifier || declaration.id.typeAnnotation || declaration.parent.kind !== "const" || declaration.parent.parent.type !== import_utils35.AST_NODE_TYPES.Program) return void 0;
|
|
4251
|
-
return sourceCode.getDeclaredVariables(declaration).find((variable) => variable.defs.some((definition) => definition.type === "Variable" && definition.node === declaration));
|
|
4252
|
-
}
|
|
4253
|
-
function directCalls(binding3, arity) {
|
|
4254
|
-
let calls = 0;
|
|
4255
|
-
const stable2 = stableValueBinding(binding3, (reference) => {
|
|
4256
|
-
const identifier = reference.identifier;
|
|
4257
|
-
const call = identifier.parent;
|
|
4258
|
-
if (reference.isTypeReference || !reference.isReadOnly() || call.type !== import_utils35.AST_NODE_TYPES.CallExpression || call.callee !== identifier || call.optional || call.typeArguments || call.arguments.length !== arity || !call.arguments.every((argument) => argument.type === import_utils35.AST_NODE_TYPES.Identifier)) return false;
|
|
4259
|
-
calls += 1;
|
|
4260
|
-
return true;
|
|
4261
|
-
});
|
|
4262
|
-
return stable2 && calls > 0;
|
|
4263
|
-
}
|
|
4264
|
-
|
|
4265
4290
|
// src/rules/no-redundant-consumer-union.ts
|
|
4266
4291
|
var CONFIG3 = { path: "tsconfig.json", source: '{"compilerOptions":{"strict":true,"target":"ESNext","module":"ESNext","moduleResolution":"Bundler"}}' };
|
|
4267
4292
|
var EXAMPLE = 'export {}; interface Animal {readonly name: string} interface Dog extends Animal {readonly breed: string} export type KeptDog = Dog; const dog: Dog = {name: "Ada", breed: "Collie"}; function label(value: Dog | Animal): string {return value.name;} label(dog);';
|
|
@@ -5589,7 +5614,7 @@ function isSearchParamReceiver(call, services) {
|
|
|
5589
5614
|
// package.json
|
|
5590
5615
|
var package_default = {
|
|
5591
5616
|
name: "@sarj/eslint-plugin",
|
|
5592
|
-
version: "18.0.
|
|
5617
|
+
version: "18.0.5",
|
|
5593
5618
|
packageManager: "npm@12.2.1",
|
|
5594
5619
|
description: "Custom ESLint rules for hypermodern TypeScript / React / Next.js projects",
|
|
5595
5620
|
type: "module",
|