@sarj/eslint-plugin 16.0.0 → 16.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +479 -386
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +479 -386
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -489,8 +489,8 @@ var prefer_typed_reflection_default = createRule({
|
|
|
489
489
|
const services = import_utils3.ESLintUtils.getParserServices(context);
|
|
490
490
|
if (!services.program) return {};
|
|
491
491
|
const checker = services.program.getTypeChecker();
|
|
492
|
-
const globalName = (node, name) => node.type === import_utils3.AST_NODE_TYPES.Identifier && node.name === name && !import_utils3.ASTUtils.findVariable(context.sourceCode.getScope(node), name)?.defs.length;
|
|
493
492
|
const isReflect = (node) => globalName(node, "Reflect") || node.type === import_utils3.AST_NODE_TYPES.MemberExpression && propertyName(node) === "Reflect" && globalName(node.object, "globalThis");
|
|
493
|
+
const globalName = (node, name) => node.type === import_utils3.AST_NODE_TYPES.Identifier && node.name === name && !import_utils3.ASTUtils.findVariable(context.sourceCode.getScope(node), name)?.defs.length;
|
|
494
494
|
const closedObject = (type) => {
|
|
495
495
|
if (type.isUnion()) return type.types.every(closedObject);
|
|
496
496
|
return knownType(type) && type.getProperties().length > 0 && checker.getIndexInfosOfType(type).length === 0;
|
|
@@ -727,6 +727,14 @@ var no_reduce_accumulator_copy_default = createRule({
|
|
|
727
727
|
const accumulator = context.sourceCode.getDeclaredVariables(callback).find((variable) => variable.identifiers.includes(parameter));
|
|
728
728
|
if (!accumulator || accumulator.references.some((reference) => reference.isWrite())) return;
|
|
729
729
|
const referencesAccumulator = (value) => value.type === import_utils5.AST_NODE_TYPES.Identifier && import_utils5.ASTUtils.findVariable(context.sourceCode.getScope(value), value.name) === accumulator;
|
|
730
|
+
const inspect = (current) => {
|
|
731
|
+
if (current !== callback.body && [import_utils5.AST_NODE_TYPES.ArrowFunctionExpression, import_utils5.AST_NODE_TYPES.FunctionExpression, import_utils5.AST_NODE_TYPES.FunctionDeclaration].some((kind) => kind === current.type)) return;
|
|
732
|
+
if (current.type === import_utils5.AST_NODE_TYPES.SpreadElement && (arraySeed && current.parent.type === import_utils5.AST_NODE_TYPES.ArrayExpression || objectSeed && current.parent.type === import_utils5.AST_NODE_TYPES.ObjectExpression) && referencesAccumulator(current.argument)) {
|
|
733
|
+
context.report({ node: current, messageId: "copy" });
|
|
734
|
+
}
|
|
735
|
+
if (current.type === import_utils5.AST_NODE_TYPES.CallExpression) inspectCall(current);
|
|
736
|
+
forEachAstChild(current, context.sourceCode.visitorKeys, inspect);
|
|
737
|
+
};
|
|
730
738
|
const inspectCall = (current) => {
|
|
731
739
|
if (current.callee.type !== import_utils5.AST_NODE_TYPES.MemberExpression) return;
|
|
732
740
|
const member = current.callee;
|
|
@@ -739,14 +747,6 @@ var no_reduce_accumulator_copy_default = createRule({
|
|
|
739
747
|
const assignCopy = objectSeed && name === "assign" && globalObject && target?.type === import_utils5.AST_NODE_TYPES.ObjectExpression && current.arguments.slice(1).some(referencesAccumulator);
|
|
740
748
|
if (directCopy || fromCopy || assignCopy) context.report({ node: current, messageId: "copy" });
|
|
741
749
|
};
|
|
742
|
-
const inspect = (current) => {
|
|
743
|
-
if (current !== callback.body && [import_utils5.AST_NODE_TYPES.ArrowFunctionExpression, import_utils5.AST_NODE_TYPES.FunctionExpression, import_utils5.AST_NODE_TYPES.FunctionDeclaration].some((kind) => kind === current.type)) return;
|
|
744
|
-
if (current.type === import_utils5.AST_NODE_TYPES.SpreadElement && (arraySeed && current.parent.type === import_utils5.AST_NODE_TYPES.ArrayExpression || objectSeed && current.parent.type === import_utils5.AST_NODE_TYPES.ObjectExpression) && referencesAccumulator(current.argument)) {
|
|
745
|
-
context.report({ node: current, messageId: "copy" });
|
|
746
|
-
}
|
|
747
|
-
if (current.type === import_utils5.AST_NODE_TYPES.CallExpression) inspectCall(current);
|
|
748
|
-
forEachAstChild(current, context.sourceCode.visitorKeys, inspect);
|
|
749
|
-
};
|
|
750
750
|
inspect(callback.body);
|
|
751
751
|
}
|
|
752
752
|
};
|
|
@@ -3650,28 +3650,6 @@ var no_cors_wildcard_with_credentials_default = createRule({
|
|
|
3650
3650
|
const scopeHeaderSets = /* @__PURE__ */ new Map();
|
|
3651
3651
|
const variableIds = /* @__PURE__ */ new WeakMap();
|
|
3652
3652
|
let nextVariableId = 0;
|
|
3653
|
-
function variableId(variable) {
|
|
3654
|
-
const existing = variableIds.get(variable);
|
|
3655
|
-
if (existing !== void 0) return existing;
|
|
3656
|
-
const value = nextVariableId++;
|
|
3657
|
-
variableIds.set(variable, value);
|
|
3658
|
-
return value;
|
|
3659
|
-
}
|
|
3660
|
-
function receiverIdentity(node) {
|
|
3661
|
-
if (node.type === import_utils23.AST_NODE_TYPES.Identifier) {
|
|
3662
|
-
const variable = import_utils23.ASTUtils.findVariable(
|
|
3663
|
-
context.sourceCode.getScope(node),
|
|
3664
|
-
node.name
|
|
3665
|
-
);
|
|
3666
|
-
return variable === null ? `global:${node.name}` : `variable:${variableId(variable)}`;
|
|
3667
|
-
}
|
|
3668
|
-
if (node.type === import_utils23.AST_NODE_TYPES.ThisExpression) return "this";
|
|
3669
|
-
if (node.type === import_utils23.AST_NODE_TYPES.MemberExpression && !node.computed && node.property.type === import_utils23.AST_NODE_TYPES.Identifier) {
|
|
3670
|
-
const owner = receiverIdentity(node.object);
|
|
3671
|
-
return owner === null ? null : `${owner}.${node.property.name}`;
|
|
3672
|
-
}
|
|
3673
|
-
return null;
|
|
3674
|
-
}
|
|
3675
3653
|
function recordHeaderSet(node, kind) {
|
|
3676
3654
|
if (node.callee.type !== import_utils23.AST_NODE_TYPES.MemberExpression) return;
|
|
3677
3655
|
const receiver = receiverIdentity(node.callee.object);
|
|
@@ -3693,6 +3671,28 @@ var no_cors_wildcard_with_credentials_default = createRule({
|
|
|
3693
3671
|
entry.credentialsNodes.push(node);
|
|
3694
3672
|
}
|
|
3695
3673
|
}
|
|
3674
|
+
function receiverIdentity(node) {
|
|
3675
|
+
if (node.type === import_utils23.AST_NODE_TYPES.Identifier) {
|
|
3676
|
+
const variable = import_utils23.ASTUtils.findVariable(
|
|
3677
|
+
context.sourceCode.getScope(node),
|
|
3678
|
+
node.name
|
|
3679
|
+
);
|
|
3680
|
+
return variable === null ? `global:${node.name}` : `variable:${variableId(variable)}`;
|
|
3681
|
+
}
|
|
3682
|
+
if (node.type === import_utils23.AST_NODE_TYPES.ThisExpression) return "this";
|
|
3683
|
+
if (node.type === import_utils23.AST_NODE_TYPES.MemberExpression && !node.computed && node.property.type === import_utils23.AST_NODE_TYPES.Identifier) {
|
|
3684
|
+
const owner = receiverIdentity(node.object);
|
|
3685
|
+
return owner === null ? null : `${owner}.${node.property.name}`;
|
|
3686
|
+
}
|
|
3687
|
+
return null;
|
|
3688
|
+
}
|
|
3689
|
+
function variableId(variable) {
|
|
3690
|
+
const existing = variableIds.get(variable);
|
|
3691
|
+
if (existing !== void 0) return existing;
|
|
3692
|
+
const value = nextVariableId++;
|
|
3693
|
+
variableIds.set(variable, value);
|
|
3694
|
+
return value;
|
|
3695
|
+
}
|
|
3696
3696
|
return {
|
|
3697
3697
|
NewExpression(node) {
|
|
3698
3698
|
if (isCorsWildcardCredentialsCall(node)) {
|
|
@@ -4482,20 +4482,6 @@ function functionComplexity(fn, visitorKeys) {
|
|
|
4482
4482
|
function add(node, nesting, construct) {
|
|
4483
4483
|
points.push({ line: node.loc.start.line, amount: nesting + 1, construct });
|
|
4484
4484
|
}
|
|
4485
|
-
function logical(node, nesting) {
|
|
4486
|
-
let previous;
|
|
4487
|
-
function flatten(expression) {
|
|
4488
|
-
if (expression.type !== import_utils29.AST_NODE_TYPES.LogicalExpression || expression.operator === "??") {
|
|
4489
|
-
visit(expression, nesting);
|
|
4490
|
-
return;
|
|
4491
|
-
}
|
|
4492
|
-
flatten(expression.left);
|
|
4493
|
-
if (previous !== expression.operator) add(expression, 0, expression.operator);
|
|
4494
|
-
previous = expression.operator;
|
|
4495
|
-
flatten(expression.right);
|
|
4496
|
-
}
|
|
4497
|
-
flatten(node);
|
|
4498
|
-
}
|
|
4499
4485
|
function conditional(node, nesting) {
|
|
4500
4486
|
add(node, nesting, "if");
|
|
4501
4487
|
let branch = node;
|
|
@@ -4574,6 +4560,20 @@ function functionComplexity(fn, visitorKeys) {
|
|
|
4574
4560
|
}
|
|
4575
4561
|
visitChildren(node, nesting);
|
|
4576
4562
|
}
|
|
4563
|
+
function logical(node, nesting) {
|
|
4564
|
+
let previous;
|
|
4565
|
+
function flatten(expression) {
|
|
4566
|
+
if (expression.type !== import_utils29.AST_NODE_TYPES.LogicalExpression || expression.operator === "??") {
|
|
4567
|
+
visit(expression, nesting);
|
|
4568
|
+
return;
|
|
4569
|
+
}
|
|
4570
|
+
flatten(expression.left);
|
|
4571
|
+
if (previous !== expression.operator) add(expression, 0, expression.operator);
|
|
4572
|
+
previous = expression.operator;
|
|
4573
|
+
flatten(expression.right);
|
|
4574
|
+
}
|
|
4575
|
+
flatten(node);
|
|
4576
|
+
}
|
|
4577
4577
|
function visitChildren(node, nesting) {
|
|
4578
4578
|
forEachAstChild(node, visitorKeys, (child) => visit(child, nesting));
|
|
4579
4579
|
}
|
|
@@ -5196,6 +5196,14 @@ var no_hand_rolled_sleep_default = createRule({
|
|
|
5196
5196
|
const callee = callback.type === import_utils31.AST_NODE_TYPES.Identifier ? callback : callback.type === import_utils31.AST_NODE_TYPES.ArrowFunctionExpression || callback.type === import_utils31.AST_NODE_TYPES.FunctionExpression ? soleCall(callback)?.callee : null;
|
|
5197
5197
|
return callee?.type === import_utils31.AST_NODE_TYPES.Identifier && bindingOf(callee) === bindingOf(parameter);
|
|
5198
5198
|
};
|
|
5199
|
+
let clientModule = null;
|
|
5200
|
+
const reportsSleepHere = () => {
|
|
5201
|
+
if (checkClientModules) {
|
|
5202
|
+
return true;
|
|
5203
|
+
}
|
|
5204
|
+
clientModule ??= isClientModule2();
|
|
5205
|
+
return !clientModule;
|
|
5206
|
+
};
|
|
5199
5207
|
function isClientModule2() {
|
|
5200
5208
|
if (/\.[cm]?[jt]sx$/.test(filename)) {
|
|
5201
5209
|
return true;
|
|
@@ -5211,14 +5219,6 @@ var no_hand_rolled_sleep_default = createRule({
|
|
|
5211
5219
|
}
|
|
5212
5220
|
return false;
|
|
5213
5221
|
}
|
|
5214
|
-
let clientModule = null;
|
|
5215
|
-
const reportsSleepHere = () => {
|
|
5216
|
-
if (checkClientModules) {
|
|
5217
|
-
return true;
|
|
5218
|
-
}
|
|
5219
|
-
clientModule ??= isClientModule2();
|
|
5220
|
-
return !clientModule;
|
|
5221
|
-
};
|
|
5222
5222
|
return {
|
|
5223
5223
|
NewExpression(node) {
|
|
5224
5224
|
if (node.callee.type !== import_utils31.AST_NODE_TYPES.Identifier || node.callee.name !== "Promise" || !isGlobal(node.callee)) {
|
|
@@ -5648,13 +5648,6 @@ var no_detached_global_fetch_default = createRule({
|
|
|
5648
5648
|
const variable = bindingOf(identifier);
|
|
5649
5649
|
if (variable !== null && isStableAlias(variable)) aliases.add(variable);
|
|
5650
5650
|
}
|
|
5651
|
-
function isGlobalFetchMember(node) {
|
|
5652
|
-
if (!isGlobalReceiver(node.object)) return false;
|
|
5653
|
-
if (!node.computed) {
|
|
5654
|
-
return node.property.type === import_utils34.AST_NODE_TYPES.Identifier && node.property.name === "fetch";
|
|
5655
|
-
}
|
|
5656
|
-
return node.property.type === import_utils34.AST_NODE_TYPES.Literal && node.property.value === "fetch";
|
|
5657
|
-
}
|
|
5658
5651
|
function staticMemberName9(node) {
|
|
5659
5652
|
if (!node.computed) {
|
|
5660
5653
|
return node.property.type === import_utils34.AST_NODE_TYPES.Identifier ? node.property.name : null;
|
|
@@ -5683,6 +5676,13 @@ var no_detached_global_fetch_default = createRule({
|
|
|
5683
5676
|
}
|
|
5684
5677
|
return false;
|
|
5685
5678
|
}
|
|
5679
|
+
function isGlobalFetchMember(node) {
|
|
5680
|
+
if (!isGlobalReceiver(node.object)) return false;
|
|
5681
|
+
if (!node.computed) {
|
|
5682
|
+
return node.property.type === import_utils34.AST_NODE_TYPES.Identifier && node.property.name === "fetch";
|
|
5683
|
+
}
|
|
5684
|
+
return node.property.type === import_utils34.AST_NODE_TYPES.Literal && node.property.value === "fetch";
|
|
5685
|
+
}
|
|
5686
5686
|
function recordAliasFromValue(identifier, value) {
|
|
5687
5687
|
if (mayBeRawFetch(value)) recordAlias(identifier);
|
|
5688
5688
|
}
|
|
@@ -6241,17 +6241,6 @@ var no_impossible_zod_literal_bounds_default = createRule({
|
|
|
6241
6241
|
}
|
|
6242
6242
|
return false;
|
|
6243
6243
|
}
|
|
6244
|
-
function baseKind(node) {
|
|
6245
|
-
const callee = node.callee;
|
|
6246
|
-
if (callee.type === import_utils37.AST_NODE_TYPES.Identifier) {
|
|
6247
|
-
return resolvesToTrackedImport(callee) ? constructors.get(callee.name) ?? null : null;
|
|
6248
|
-
}
|
|
6249
|
-
if (callee.type !== import_utils37.AST_NODE_TYPES.MemberExpression || callee.object.type !== import_utils37.AST_NODE_TYPES.Identifier || !namespaces.has(callee.object.name) || !resolvesToTrackedImport(callee.object)) {
|
|
6250
|
-
return null;
|
|
6251
|
-
}
|
|
6252
|
-
const name = memberName(callee);
|
|
6253
|
-
return name !== null && KINDS.has(name) ? name : null;
|
|
6254
|
-
}
|
|
6255
6244
|
function readChain(node) {
|
|
6256
6245
|
const calls = [];
|
|
6257
6246
|
let current = node;
|
|
@@ -6268,6 +6257,17 @@ var no_impossible_zod_literal_bounds_default = createRule({
|
|
|
6268
6257
|
current = callee.object;
|
|
6269
6258
|
}
|
|
6270
6259
|
}
|
|
6260
|
+
function baseKind(node) {
|
|
6261
|
+
const callee = node.callee;
|
|
6262
|
+
if (callee.type === import_utils37.AST_NODE_TYPES.Identifier) {
|
|
6263
|
+
return resolvesToTrackedImport(callee) ? constructors.get(callee.name) ?? null : null;
|
|
6264
|
+
}
|
|
6265
|
+
if (callee.type !== import_utils37.AST_NODE_TYPES.MemberExpression || callee.object.type !== import_utils37.AST_NODE_TYPES.Identifier || !namespaces.has(callee.object.name) || !resolvesToTrackedImport(callee.object)) {
|
|
6266
|
+
return null;
|
|
6267
|
+
}
|
|
6268
|
+
const name = memberName(callee);
|
|
6269
|
+
return name !== null && KINDS.has(name) ? name : null;
|
|
6270
|
+
}
|
|
6271
6271
|
function isInsideReshapingCall(node) {
|
|
6272
6272
|
let child = node;
|
|
6273
6273
|
let parent = child.parent;
|
|
@@ -6581,30 +6581,30 @@ var no_redundant_optional_array_default_default = createRule({
|
|
|
6581
6581
|
}
|
|
6582
6582
|
return false;
|
|
6583
6583
|
}
|
|
6584
|
-
function
|
|
6584
|
+
function isArraySchemaExpression(node) {
|
|
6585
6585
|
if (node.type !== import_utils39.AST_NODE_TYPES.CallExpression) return false;
|
|
6586
6586
|
const { callee } = node;
|
|
6587
6587
|
if (callee.type === import_utils39.AST_NODE_TYPES.Identifier) {
|
|
6588
|
-
return resolvesToTrackedImport(callee);
|
|
6588
|
+
return arrayConstructors.has(callee.name) && resolvesToTrackedImport(callee);
|
|
6589
6589
|
}
|
|
6590
6590
|
if (callee.type !== import_utils39.AST_NODE_TYPES.MemberExpression) return false;
|
|
6591
|
-
|
|
6591
|
+
const method = memberName2(callee);
|
|
6592
|
+
if (method === "array" && (callee.object.type === import_utils39.AST_NODE_TYPES.Identifier ? namespaces.has(callee.object.name) && resolvesToTrackedImport(callee.object) : isZodSchemaExpression(callee.object))) {
|
|
6592
6593
|
return true;
|
|
6593
6594
|
}
|
|
6594
|
-
return
|
|
6595
|
+
return isArraySchemaExpression(callee.object);
|
|
6595
6596
|
}
|
|
6596
|
-
function
|
|
6597
|
+
function isZodSchemaExpression(node) {
|
|
6597
6598
|
if (node.type !== import_utils39.AST_NODE_TYPES.CallExpression) return false;
|
|
6598
6599
|
const { callee } = node;
|
|
6599
6600
|
if (callee.type === import_utils39.AST_NODE_TYPES.Identifier) {
|
|
6600
|
-
return
|
|
6601
|
+
return resolvesToTrackedImport(callee);
|
|
6601
6602
|
}
|
|
6602
6603
|
if (callee.type !== import_utils39.AST_NODE_TYPES.MemberExpression) return false;
|
|
6603
|
-
|
|
6604
|
-
if (method === "array" && (callee.object.type === import_utils39.AST_NODE_TYPES.Identifier ? namespaces.has(callee.object.name) && resolvesToTrackedImport(callee.object) : isZodSchemaExpression(callee.object))) {
|
|
6604
|
+
if (callee.object.type === import_utils39.AST_NODE_TYPES.Identifier && namespaces.has(callee.object.name) && resolvesToTrackedImport(callee.object)) {
|
|
6605
6605
|
return true;
|
|
6606
6606
|
}
|
|
6607
|
-
return
|
|
6607
|
+
return isZodSchemaExpression(callee.object);
|
|
6608
6608
|
}
|
|
6609
6609
|
return {
|
|
6610
6610
|
ImportDeclaration(node) {
|
|
@@ -7036,10 +7036,6 @@ var no_log_only_catch_default = createRule({
|
|
|
7036
7036
|
}
|
|
7037
7037
|
return matcher.isLoggingCall(statement.expression);
|
|
7038
7038
|
}
|
|
7039
|
-
function hasCommentDirectlyAbove(node) {
|
|
7040
|
-
const above = sourceCode.getCommentsBefore(node).at(-1);
|
|
7041
|
-
return above !== void 0 && above.loc.end.line === node.loc.start.line - 1;
|
|
7042
|
-
}
|
|
7043
7039
|
function hasAdjacentRationale(node) {
|
|
7044
7040
|
const tryStatement = node.parent;
|
|
7045
7041
|
if (hasCommentDirectlyAbove(tryStatement) || hasCommentDirectlyAbove(node)) return true;
|
|
@@ -7049,6 +7045,10 @@ var no_log_only_catch_default = createRule({
|
|
|
7049
7045
|
}
|
|
7050
7046
|
return hasCommentDirectlyAbove(block.parent);
|
|
7051
7047
|
}
|
|
7048
|
+
function hasCommentDirectlyAbove(node) {
|
|
7049
|
+
const above = sourceCode.getCommentsBefore(node).at(-1);
|
|
7050
|
+
return above !== void 0 && above.loc.end.line === node.loc.start.line - 1;
|
|
7051
|
+
}
|
|
7052
7052
|
if (isTestFile(filename) || BENCHMARK_DIR_RE.test(filename.replaceAll("\\", "/"))) {
|
|
7053
7053
|
return {};
|
|
7054
7054
|
}
|
|
@@ -8049,6 +8049,10 @@ var no_positional_tuple_return_default = createRule({
|
|
|
8049
8049
|
data: { name, count: String(tuple.elements.length) }
|
|
8050
8050
|
});
|
|
8051
8051
|
};
|
|
8052
|
+
const enterFunction = (node) => {
|
|
8053
|
+
functionStack.push(node);
|
|
8054
|
+
check(node);
|
|
8055
|
+
};
|
|
8052
8056
|
const check = (node) => {
|
|
8053
8057
|
if (isQueryKeyFactory(node)) return;
|
|
8054
8058
|
const annotation = node.returnType?.typeAnnotation;
|
|
@@ -8064,10 +8068,6 @@ var no_positional_tuple_return_default = createRule({
|
|
|
8064
8068
|
}
|
|
8065
8069
|
report2(annotation, name);
|
|
8066
8070
|
};
|
|
8067
|
-
const enterFunction = (node) => {
|
|
8068
|
-
functionStack.push(node);
|
|
8069
|
-
check(node);
|
|
8070
|
-
};
|
|
8071
8071
|
const exitFunction = () => {
|
|
8072
8072
|
functionStack.pop();
|
|
8073
8073
|
};
|
|
@@ -8514,32 +8514,16 @@ var no_raw_fetch_outside_clients_default = createRule({
|
|
|
8514
8514
|
const definition = variable.defs[0];
|
|
8515
8515
|
return definition?.type === "Variable" && definition.parent.kind === "const" && definition.node.init !== null && !variable.references.some((reference) => reference.isWrite() && reference.init !== true) && !(definition.node.init.type === import_utils51.AST_NODE_TYPES.ObjectExpression && variable.references.some((reference) => reference.identifier !== node && reference.init !== true)) ? definition.node.init : node;
|
|
8516
8516
|
}
|
|
8517
|
-
function
|
|
8518
|
-
if (node
|
|
8519
|
-
|
|
8520
|
-
for (const property of [...node.properties].reverse()) {
|
|
8521
|
-
if (property.type !== import_utils51.AST_NODE_TYPES.Property || property.computed) continue;
|
|
8522
|
-
const key = property.key;
|
|
8523
|
-
const keyName = key.type === import_utils51.AST_NODE_TYPES.Identifier ? key.name : key.type === import_utils51.AST_NODE_TYPES.Literal && typeof key.value === "string" ? key.value : null;
|
|
8524
|
-
if (keyName !== name) continue;
|
|
8525
|
-
return property.value.type === import_utils51.AST_NODE_TYPES.AssignmentPattern || property.value.type === import_utils51.AST_NODE_TYPES.ArrayPattern || property.value.type === import_utils51.AST_NODE_TYPES.ObjectPattern ? null : property.value;
|
|
8526
|
-
}
|
|
8527
|
-
return null;
|
|
8528
|
-
}
|
|
8529
|
-
function isInternalApiUrl(node) {
|
|
8530
|
-
const resolved = resolveNode2(node ?? void 0);
|
|
8531
|
-
if (resolved?.type === import_utils51.AST_NODE_TYPES.Literal) {
|
|
8532
|
-
return typeof resolved.value === "string" && internalApiPrefixes.some(
|
|
8533
|
-
(prefix) => resolved.value === prefix || resolved.value.startsWith(`${prefix}/`)
|
|
8534
|
-
);
|
|
8517
|
+
function serverActionOwns(node) {
|
|
8518
|
+
if (node.callee.type !== import_utils51.AST_NODE_TYPES.Identifier || !hasUseClientDirective || hasUseServerDirective || importsServerOnly || SERVER_ACTION_SKIP_FILE_RE.test(filename) || nonReactFramework) {
|
|
8519
|
+
return false;
|
|
8535
8520
|
}
|
|
8536
|
-
|
|
8537
|
-
|
|
8538
|
-
|
|
8539
|
-
|
|
8540
|
-
);
|
|
8521
|
+
const url = node.arguments[0];
|
|
8522
|
+
const init = node.arguments[1];
|
|
8523
|
+
if (url === void 0 || url.type === import_utils51.AST_NODE_TYPES.SpreadElement || init === void 0 || init.type === import_utils51.AST_NODE_TYPES.SpreadElement || !isInternalApiUrl(url)) {
|
|
8524
|
+
return false;
|
|
8541
8525
|
}
|
|
8542
|
-
return
|
|
8526
|
+
return isMutationMethod2(propertyValue(resolveNode2(init), "method"));
|
|
8543
8527
|
}
|
|
8544
8528
|
function isMutationMethod2(node) {
|
|
8545
8529
|
const resolved = resolveNode2(node ?? void 0);
|
|
@@ -8556,16 +8540,32 @@ var no_raw_fetch_outside_clients_default = createRule({
|
|
|
8556
8540
|
}
|
|
8557
8541
|
return resolved?.type === import_utils51.AST_NODE_TYPES.LogicalExpression && resolved.operator === "||" && (isMutationMethod2(resolved.left) || isMutationMethod2(resolved.right));
|
|
8558
8542
|
}
|
|
8559
|
-
function
|
|
8560
|
-
|
|
8561
|
-
|
|
8543
|
+
function isInternalApiUrl(node) {
|
|
8544
|
+
const resolved = resolveNode2(node ?? void 0);
|
|
8545
|
+
if (resolved?.type === import_utils51.AST_NODE_TYPES.Literal) {
|
|
8546
|
+
return typeof resolved.value === "string" && internalApiPrefixes.some(
|
|
8547
|
+
(prefix) => resolved.value === prefix || resolved.value.startsWith(`${prefix}/`)
|
|
8548
|
+
);
|
|
8562
8549
|
}
|
|
8563
|
-
|
|
8564
|
-
|
|
8565
|
-
|
|
8566
|
-
|
|
8550
|
+
if (resolved?.type === import_utils51.AST_NODE_TYPES.TemplateLiteral) {
|
|
8551
|
+
const prefix = resolved.quasis[0]?.value.cooked;
|
|
8552
|
+
return typeof prefix === "string" && internalApiPrefixes.some(
|
|
8553
|
+
(apiPrefix) => prefix === apiPrefix || prefix.startsWith(`${apiPrefix}/`)
|
|
8554
|
+
);
|
|
8567
8555
|
}
|
|
8568
|
-
return
|
|
8556
|
+
return resolved?.type === import_utils51.AST_NODE_TYPES.BinaryExpression && resolved.operator === "+" && isInternalApiUrl(resolved.left);
|
|
8557
|
+
}
|
|
8558
|
+
function propertyValue(node, name) {
|
|
8559
|
+
if (node?.type !== import_utils51.AST_NODE_TYPES.ObjectExpression) return null;
|
|
8560
|
+
if (node.properties.some((property) => property.type !== import_utils51.AST_NODE_TYPES.Property || property.computed)) return null;
|
|
8561
|
+
for (const property of [...node.properties].reverse()) {
|
|
8562
|
+
if (property.type !== import_utils51.AST_NODE_TYPES.Property || property.computed) continue;
|
|
8563
|
+
const key = property.key;
|
|
8564
|
+
const keyName = key.type === import_utils51.AST_NODE_TYPES.Identifier ? key.name : key.type === import_utils51.AST_NODE_TYPES.Literal && typeof key.value === "string" ? key.value : null;
|
|
8565
|
+
if (keyName !== name) continue;
|
|
8566
|
+
return property.value.type === import_utils51.AST_NODE_TYPES.AssignmentPattern || property.value.type === import_utils51.AST_NODE_TYPES.ArrayPattern || property.value.type === import_utils51.AST_NODE_TYPES.ObjectPattern ? null : property.value;
|
|
8567
|
+
}
|
|
8568
|
+
return null;
|
|
8569
8569
|
}
|
|
8570
8570
|
if (allowed.some((re) => re.test(filename))) {
|
|
8571
8571
|
return {};
|
|
@@ -9664,35 +9664,30 @@ var no_secret_in_log_default = createRule({
|
|
|
9664
9664
|
create(context, [loggingOptions]) {
|
|
9665
9665
|
const matcher = createLogMatcher(loggingOptions);
|
|
9666
9666
|
const blobArmApplies = !isTestFile(context.filename);
|
|
9667
|
-
function
|
|
9668
|
-
|
|
9669
|
-
|
|
9670
|
-
|
|
9667
|
+
function inspectLoggedValue(value) {
|
|
9668
|
+
if (value.type === "ObjectExpression") {
|
|
9669
|
+
for (const property of literalProperties(value)) {
|
|
9670
|
+
if (reportSecretProperty(property) || reportRawBlob(property, property.value)) continue;
|
|
9671
|
+
inspectLoggedValue(property.value);
|
|
9672
|
+
}
|
|
9673
|
+
return;
|
|
9671
9674
|
}
|
|
9672
|
-
|
|
9673
|
-
|
|
9674
|
-
|
|
9675
|
-
|
|
9676
|
-
|
|
9677
|
-
const value = valueName(prop.value);
|
|
9678
|
-
if (value !== null && hasRedactionMarker(value)) return false;
|
|
9679
|
-
const name = value !== null && isSecretKeyword(value) ? value : keyName;
|
|
9680
|
-
if (name === null || !isSecretKeyword(name) || !isRawSecretValue(prop)) {
|
|
9681
|
-
return false;
|
|
9675
|
+
if (value.type === "ArrayExpression") {
|
|
9676
|
+
for (const element of value.elements) {
|
|
9677
|
+
if (element !== null && element.type !== "SpreadElement") inspectLoggedValue(element);
|
|
9678
|
+
}
|
|
9679
|
+
return;
|
|
9682
9680
|
}
|
|
9683
|
-
|
|
9684
|
-
|
|
9685
|
-
|
|
9686
|
-
function reportRawBlob(node, value) {
|
|
9687
|
-
if (!blobArmApplies) {
|
|
9688
|
-
return false;
|
|
9681
|
+
if (value.type === "TemplateLiteral") {
|
|
9682
|
+
for (const expression of value.expressions) inspectLoggedValue(expression);
|
|
9683
|
+
return;
|
|
9689
9684
|
}
|
|
9690
|
-
|
|
9691
|
-
|
|
9692
|
-
|
|
9693
|
-
return
|
|
9685
|
+
if (value.type === "BinaryExpression" && value.operator === "+") {
|
|
9686
|
+
inspectLoggedValue(value.left);
|
|
9687
|
+
inspectLoggedValue(value.right);
|
|
9688
|
+
return;
|
|
9694
9689
|
}
|
|
9695
|
-
|
|
9690
|
+
if (!reportSecretArgument(value)) reportRawBlob(value, value);
|
|
9696
9691
|
}
|
|
9697
9692
|
function literalProperties(value) {
|
|
9698
9693
|
const effective = /* @__PURE__ */ new Map();
|
|
@@ -9717,30 +9712,35 @@ var no_secret_in_log_default = createRule({
|
|
|
9717
9712
|
}
|
|
9718
9713
|
return [...effective.values()];
|
|
9719
9714
|
}
|
|
9720
|
-
function
|
|
9721
|
-
if (
|
|
9722
|
-
|
|
9723
|
-
if (reportSecretProperty(property) || reportRawBlob(property, property.value)) continue;
|
|
9724
|
-
inspectLoggedValue(property.value);
|
|
9725
|
-
}
|
|
9726
|
-
return;
|
|
9715
|
+
function reportRawBlob(node, value) {
|
|
9716
|
+
if (!blobArmApplies) {
|
|
9717
|
+
return false;
|
|
9727
9718
|
}
|
|
9728
|
-
|
|
9729
|
-
|
|
9730
|
-
|
|
9731
|
-
|
|
9732
|
-
return;
|
|
9719
|
+
const name = rawBlobValueName(value);
|
|
9720
|
+
if (name !== null) {
|
|
9721
|
+
context.report({ node, messageId: "noRawBodyInLog", data: { name } });
|
|
9722
|
+
return true;
|
|
9733
9723
|
}
|
|
9734
|
-
|
|
9735
|
-
|
|
9736
|
-
|
|
9724
|
+
return false;
|
|
9725
|
+
}
|
|
9726
|
+
function reportSecretProperty(prop) {
|
|
9727
|
+
const keyName = propertyKeyName2(prop);
|
|
9728
|
+
const value = valueName(prop.value);
|
|
9729
|
+
if (value !== null && hasRedactionMarker(value)) return false;
|
|
9730
|
+
const name = value !== null && isSecretKeyword(value) ? value : keyName;
|
|
9731
|
+
if (name === null || !isSecretKeyword(name) || !isRawSecretValue(prop)) {
|
|
9732
|
+
return false;
|
|
9737
9733
|
}
|
|
9738
|
-
|
|
9739
|
-
|
|
9740
|
-
|
|
9741
|
-
|
|
9734
|
+
context.report({ node: prop, messageId: "noSecretInLog", data: { name } });
|
|
9735
|
+
return true;
|
|
9736
|
+
}
|
|
9737
|
+
function reportSecretArgument(arg) {
|
|
9738
|
+
const name = valueName(arg);
|
|
9739
|
+
if (name === null || !isSecretKeyword(name)) {
|
|
9740
|
+
return false;
|
|
9742
9741
|
}
|
|
9743
|
-
|
|
9742
|
+
context.report({ node: arg, messageId: "noSecretInLog", data: { name } });
|
|
9743
|
+
return true;
|
|
9744
9744
|
}
|
|
9745
9745
|
return {
|
|
9746
9746
|
CallExpression(node) {
|
|
@@ -10038,9 +10038,6 @@ function bindsName(param, name) {
|
|
|
10038
10038
|
}
|
|
10039
10039
|
function subtreeReadsName(node, name) {
|
|
10040
10040
|
let found = false;
|
|
10041
|
-
const shadowsName = (fn) => isFunctionNode(fn) && fn.params.some(
|
|
10042
|
-
(param) => bindsName(param, name)
|
|
10043
|
-
);
|
|
10044
10041
|
const recurse = (current) => {
|
|
10045
10042
|
if (found) {
|
|
10046
10043
|
return;
|
|
@@ -10057,6 +10054,9 @@ function subtreeReadsName(node, name) {
|
|
|
10057
10054
|
return found;
|
|
10058
10055
|
}, (key) => !isNonReadingProperty(current, key));
|
|
10059
10056
|
};
|
|
10057
|
+
const shadowsName = (fn) => isFunctionNode(fn) && fn.params.some(
|
|
10058
|
+
(param) => bindsName(param, name)
|
|
10059
|
+
);
|
|
10060
10060
|
recurse(node);
|
|
10061
10061
|
return found;
|
|
10062
10062
|
}
|
|
@@ -11918,14 +11918,6 @@ var no_declaration_comment_wall_default = createRule({
|
|
|
11918
11918
|
const trail = startingOn.get(member.loc.end.line);
|
|
11919
11919
|
return trail !== void 0 && trail.range[0] > member.range[0] ? trail : void 0;
|
|
11920
11920
|
}
|
|
11921
|
-
function isGroupLabel(comment, member, headsRun) {
|
|
11922
|
-
if (comment.loc.end.line >= member.node.loc.start.line) return false;
|
|
11923
|
-
const body2 = commentBody(comment);
|
|
11924
|
-
if (!BARE_LABEL_RE.test(body2)) return false;
|
|
11925
|
-
if (labelStems(body2) === labelStems(sourceCode.getText(member.key))) return false;
|
|
11926
|
-
const lineAbove = sourceCode.lines[comment.loc.start.line - 2];
|
|
11927
|
-
return headsRun || lineAbove !== void 0 && lineAbove.trim().length === 0;
|
|
11928
|
-
}
|
|
11929
11921
|
function check(node, members) {
|
|
11930
11922
|
const judged = members.map(named).filter((member) => member !== void 0);
|
|
11931
11923
|
if (judged.length === 0) return;
|
|
@@ -11964,6 +11956,14 @@ var no_declaration_comment_wall_default = createRule({
|
|
|
11964
11956
|
data: { restated: String(restated), commented: String(commented) }
|
|
11965
11957
|
});
|
|
11966
11958
|
}
|
|
11959
|
+
function isGroupLabel(comment, member, headsRun) {
|
|
11960
|
+
if (comment.loc.end.line >= member.node.loc.start.line) return false;
|
|
11961
|
+
const body2 = commentBody(comment);
|
|
11962
|
+
if (!BARE_LABEL_RE.test(body2)) return false;
|
|
11963
|
+
if (labelStems(body2) === labelStems(sourceCode.getText(member.key))) return false;
|
|
11964
|
+
const lineAbove = sourceCode.lines[comment.loc.start.line - 2];
|
|
11965
|
+
return headsRun || lineAbove !== void 0 && lineAbove.trim().length === 0;
|
|
11966
|
+
}
|
|
11967
11967
|
return {
|
|
11968
11968
|
ClassBody: (node) => {
|
|
11969
11969
|
check(node, node.body);
|
|
@@ -12199,14 +12199,6 @@ var no_type_member_comment_wall_default = createRule({
|
|
|
12199
12199
|
const trail = startingOn.get(member.loc.end.line);
|
|
12200
12200
|
return trail !== void 0 && trail.range[0] > member.range[0] ? trail : void 0;
|
|
12201
12201
|
}
|
|
12202
|
-
function isGroupLabel(comment, member, headsRun) {
|
|
12203
|
-
if (comment.loc.end.line >= member.loc.start.line) return false;
|
|
12204
|
-
const body2 = commentBody(comment);
|
|
12205
|
-
if (!BARE_LABEL_RE.test(body2)) return false;
|
|
12206
|
-
if (labelStems(body2) === labelStems(sourceCode.getText(member.key))) return false;
|
|
12207
|
-
const lineAbove = sourceCode.lines[comment.loc.start.line - 2];
|
|
12208
|
-
return headsRun || lineAbove !== void 0 && lineAbove.trim().length === 0;
|
|
12209
|
-
}
|
|
12210
12202
|
function check(node) {
|
|
12211
12203
|
const members = node.type === import_utils71.AST_NODE_TYPES.TSInterfaceBody ? node.body : node.members;
|
|
12212
12204
|
const named2 = members.filter(isNamedMember);
|
|
@@ -12242,6 +12234,14 @@ var no_type_member_comment_wall_default = createRule({
|
|
|
12242
12234
|
data: { restated: String(restated), commented: String(commented) }
|
|
12243
12235
|
});
|
|
12244
12236
|
}
|
|
12237
|
+
function isGroupLabel(comment, member, headsRun) {
|
|
12238
|
+
if (comment.loc.end.line >= member.loc.start.line) return false;
|
|
12239
|
+
const body2 = commentBody(comment);
|
|
12240
|
+
if (!BARE_LABEL_RE.test(body2)) return false;
|
|
12241
|
+
if (labelStems(body2) === labelStems(sourceCode.getText(member.key))) return false;
|
|
12242
|
+
const lineAbove = sourceCode.lines[comment.loc.start.line - 2];
|
|
12243
|
+
return headsRun || lineAbove !== void 0 && lineAbove.trim().length === 0;
|
|
12244
|
+
}
|
|
12245
12245
|
return {
|
|
12246
12246
|
TSInterfaceBody: check,
|
|
12247
12247
|
TSTypeLiteral: check
|
|
@@ -12557,6 +12557,11 @@ var no_unsafe_mock_casting_default = createRule({
|
|
|
12557
12557
|
const binding = resolve2(identifier);
|
|
12558
12558
|
if (binding !== null) destination.add(binding);
|
|
12559
12559
|
}
|
|
12560
|
+
function checkAssertion(node) {
|
|
12561
|
+
if (isMockTypeReference(node.typeAnnotation)) {
|
|
12562
|
+
context.report({ node, messageId: "unsafeMockCast" });
|
|
12563
|
+
}
|
|
12564
|
+
}
|
|
12560
12565
|
function isMockTypeReference(node) {
|
|
12561
12566
|
if (node.type !== import_utils73.AST_NODE_TYPES.TSTypeReference) return false;
|
|
12562
12567
|
const typeName = node.typeName;
|
|
@@ -12570,11 +12575,6 @@ var no_unsafe_mock_casting_default = createRule({
|
|
|
12570
12575
|
}
|
|
12571
12576
|
return false;
|
|
12572
12577
|
}
|
|
12573
|
-
function checkAssertion(node) {
|
|
12574
|
-
if (isMockTypeReference(node.typeAnnotation)) {
|
|
12575
|
-
context.report({ node, messageId: "unsafeMockCast" });
|
|
12576
|
-
}
|
|
12577
|
-
}
|
|
12578
12578
|
return {
|
|
12579
12579
|
ImportDeclaration(node) {
|
|
12580
12580
|
if (!MOCK_MODULES.has(node.source.value)) return;
|
|
@@ -17885,7 +17885,7 @@ var staticallyImportsExternalRenderer = (program) => program.body.some((statemen
|
|
|
17885
17885
|
var semanticForegroundRoles = (filename) => {
|
|
17886
17886
|
const packageRoot = nearestPackageRoot((0, import_path.dirname)(filename));
|
|
17887
17887
|
if (packageRoot === null) return /* @__PURE__ */ new Set();
|
|
17888
|
-
const candidates = CSS_DETECTION_FILES.map((
|
|
17888
|
+
const candidates = CSS_DETECTION_FILES.map((relative3) => (0, import_path.join)(packageRoot, relative3));
|
|
17889
17889
|
const fingerprint = candidates.map(fileFingerprint2).join("|");
|
|
17890
17890
|
const cached = SEMANTIC_DECLARATIONS_CACHE.get(packageRoot);
|
|
17891
17891
|
if (cached?.fingerprint === fingerprint) return cached.value;
|
|
@@ -17968,6 +17968,34 @@ var prefer_semantic_colors_default = createRule({
|
|
|
17968
17968
|
const key = `${node.range[0]}:${node.range[1]}:${messageId}:${JSON.stringify(data)}`;
|
|
17969
17969
|
pendingReports.set(key, { node, messageId, data });
|
|
17970
17970
|
};
|
|
17971
|
+
const checkClassNode = (node, objectKeys = false) => {
|
|
17972
|
+
if (node === null) return;
|
|
17973
|
+
switch (node.type) {
|
|
17974
|
+
case import_utils103.AST_NODE_TYPES.Literal:
|
|
17975
|
+
if (typeof node.value === "string") reportClasses(node.value, node);
|
|
17976
|
+
break;
|
|
17977
|
+
case import_utils103.AST_NODE_TYPES.TemplateLiteral:
|
|
17978
|
+
for (const quasi of node.quasis) reportClasses(quasi.value.cooked ?? "", quasi);
|
|
17979
|
+
break;
|
|
17980
|
+
case import_utils103.AST_NODE_TYPES.ArrayExpression:
|
|
17981
|
+
for (const element of node.elements) {
|
|
17982
|
+
if (element !== null && element.type !== import_utils103.AST_NODE_TYPES.SpreadElement) checkClassNode(element, objectKeys);
|
|
17983
|
+
}
|
|
17984
|
+
break;
|
|
17985
|
+
case import_utils103.AST_NODE_TYPES.ObjectExpression:
|
|
17986
|
+
checkClassProperties(node, objectKeys);
|
|
17987
|
+
break;
|
|
17988
|
+
case import_utils103.AST_NODE_TYPES.ConditionalExpression:
|
|
17989
|
+
checkClassNode(node.consequent, objectKeys);
|
|
17990
|
+
checkClassNode(node.alternate, objectKeys);
|
|
17991
|
+
break;
|
|
17992
|
+
case import_utils103.AST_NODE_TYPES.LogicalExpression:
|
|
17993
|
+
checkClassNode(node.right, objectKeys);
|
|
17994
|
+
break;
|
|
17995
|
+
default:
|
|
17996
|
+
break;
|
|
17997
|
+
}
|
|
17998
|
+
};
|
|
17971
17999
|
const reportClasses = (value, node) => {
|
|
17972
18000
|
const tokens = classTokens(value);
|
|
17973
18001
|
for (const token of tokens) {
|
|
@@ -17999,34 +18027,6 @@ var prefer_semantic_colors_default = createRule({
|
|
|
17999
18027
|
});
|
|
18000
18028
|
}
|
|
18001
18029
|
};
|
|
18002
|
-
const checkClassNode = (node, objectKeys = false) => {
|
|
18003
|
-
if (node === null) return;
|
|
18004
|
-
switch (node.type) {
|
|
18005
|
-
case import_utils103.AST_NODE_TYPES.Literal:
|
|
18006
|
-
if (typeof node.value === "string") reportClasses(node.value, node);
|
|
18007
|
-
break;
|
|
18008
|
-
case import_utils103.AST_NODE_TYPES.TemplateLiteral:
|
|
18009
|
-
for (const quasi of node.quasis) reportClasses(quasi.value.cooked ?? "", quasi);
|
|
18010
|
-
break;
|
|
18011
|
-
case import_utils103.AST_NODE_TYPES.ArrayExpression:
|
|
18012
|
-
for (const element of node.elements) {
|
|
18013
|
-
if (element !== null && element.type !== import_utils103.AST_NODE_TYPES.SpreadElement) checkClassNode(element, objectKeys);
|
|
18014
|
-
}
|
|
18015
|
-
break;
|
|
18016
|
-
case import_utils103.AST_NODE_TYPES.ObjectExpression:
|
|
18017
|
-
checkClassProperties(node, objectKeys);
|
|
18018
|
-
break;
|
|
18019
|
-
case import_utils103.AST_NODE_TYPES.ConditionalExpression:
|
|
18020
|
-
checkClassNode(node.consequent, objectKeys);
|
|
18021
|
-
checkClassNode(node.alternate, objectKeys);
|
|
18022
|
-
break;
|
|
18023
|
-
case import_utils103.AST_NODE_TYPES.LogicalExpression:
|
|
18024
|
-
checkClassNode(node.right, objectKeys);
|
|
18025
|
-
break;
|
|
18026
|
-
default:
|
|
18027
|
-
break;
|
|
18028
|
-
}
|
|
18029
|
-
};
|
|
18030
18030
|
function checkClassProperties(node, objectKeys) {
|
|
18031
18031
|
for (const property of node.properties) {
|
|
18032
18032
|
if (property.type !== import_utils103.AST_NODE_TYPES.Property) continue;
|
|
@@ -18460,80 +18460,6 @@ var prefer_whole_object_assertion_default = createRule({
|
|
|
18460
18460
|
return {};
|
|
18461
18461
|
}
|
|
18462
18462
|
const { sourceCode } = context;
|
|
18463
|
-
function parseAssertion(statement) {
|
|
18464
|
-
if (statement.type !== import_utils105.AST_NODE_TYPES.ExpressionStatement) {
|
|
18465
|
-
return null;
|
|
18466
|
-
}
|
|
18467
|
-
const call = statement.expression;
|
|
18468
|
-
if (call.type !== import_utils105.AST_NODE_TYPES.CallExpression) {
|
|
18469
|
-
return null;
|
|
18470
|
-
}
|
|
18471
|
-
const callee = call.callee;
|
|
18472
|
-
if (callee.type !== import_utils105.AST_NODE_TYPES.MemberExpression || callee.computed || callee.property.type !== import_utils105.AST_NODE_TYPES.Identifier) {
|
|
18473
|
-
return null;
|
|
18474
|
-
}
|
|
18475
|
-
const matcher = callee.property.name;
|
|
18476
|
-
const expectCall = callee.object;
|
|
18477
|
-
if (expectCall.type !== import_utils105.AST_NODE_TYPES.CallExpression || expectCall.callee.type !== import_utils105.AST_NODE_TYPES.Identifier || expectCall.callee.name !== "expect" || expectCall.arguments.length !== 1) {
|
|
18478
|
-
return null;
|
|
18479
|
-
}
|
|
18480
|
-
const actual = expectCall.arguments[0];
|
|
18481
|
-
if (!isTestExpect(expectCall.callee)) return null;
|
|
18482
|
-
if (actual === void 0 || actual.type !== import_utils105.AST_NODE_TYPES.MemberExpression || actual.optional) {
|
|
18483
|
-
return null;
|
|
18484
|
-
}
|
|
18485
|
-
if (!isPureReceiver(actual.object)) {
|
|
18486
|
-
return null;
|
|
18487
|
-
}
|
|
18488
|
-
let key;
|
|
18489
|
-
let receiver;
|
|
18490
|
-
if (actual.computed) {
|
|
18491
|
-
const index = literalIndex(actual.property);
|
|
18492
|
-
if (index === null) {
|
|
18493
|
-
return null;
|
|
18494
|
-
}
|
|
18495
|
-
key = { kind: "index", index };
|
|
18496
|
-
receiver = actual.object;
|
|
18497
|
-
} else {
|
|
18498
|
-
const access = propertyAccess(actual);
|
|
18499
|
-
if (access === null) return null;
|
|
18500
|
-
key = { kind: "property", path: access.path };
|
|
18501
|
-
receiver = access.receiver;
|
|
18502
|
-
}
|
|
18503
|
-
return assertionExpectation(statement, call, receiver, key, matcher);
|
|
18504
|
-
}
|
|
18505
|
-
function assertionExpectation(statement, call, receiver, key, matcher) {
|
|
18506
|
-
const synthetic = SYNTHETIC_LITERAL_MATCHERS.get(matcher);
|
|
18507
|
-
if (synthetic !== void 0 && call.arguments.length === 0) {
|
|
18508
|
-
return { statement, receiver, key, matcher, expectedText: synthetic, expectedIsLiteral: true };
|
|
18509
|
-
}
|
|
18510
|
-
if (!MERGEABLE_MATCHERS.has(matcher)) {
|
|
18511
|
-
return null;
|
|
18512
|
-
}
|
|
18513
|
-
const expected = call.arguments[0];
|
|
18514
|
-
if (call.arguments.length !== 1 || expected === void 0 || expected.type === import_utils105.AST_NODE_TYPES.SpreadElement) {
|
|
18515
|
-
return null;
|
|
18516
|
-
}
|
|
18517
|
-
const literal = literalText(expected, (node) => sourceCode.getText(node));
|
|
18518
|
-
return {
|
|
18519
|
-
statement,
|
|
18520
|
-
receiver,
|
|
18521
|
-
key,
|
|
18522
|
-
matcher,
|
|
18523
|
-
expectedText: literal ?? sourceCode.getText(expected),
|
|
18524
|
-
expectedIsLiteral: literal !== null
|
|
18525
|
-
};
|
|
18526
|
-
}
|
|
18527
|
-
function isTestExpect(callee) {
|
|
18528
|
-
const variable = import_utils105.ASTUtils.findVariable(sourceCode.getScope(callee), callee.name);
|
|
18529
|
-
if (variable !== null && variable.defs.some((definition) => {
|
|
18530
|
-
if (definition.node.type !== import_utils105.AST_NODE_TYPES.ImportSpecifier) return true;
|
|
18531
|
-
const declaration = definition.node.parent;
|
|
18532
|
-
const imported = definition.node.imported;
|
|
18533
|
-
return declaration.type !== import_utils105.AST_NODE_TYPES.ImportDeclaration || !["vitest", "@jest/globals", "@playwright/test", "bun:test"].includes(String(declaration.source.value)) || (imported.type === import_utils105.AST_NODE_TYPES.Identifier ? imported.name : imported.value) !== "expect";
|
|
18534
|
-
})) return false;
|
|
18535
|
-
return true;
|
|
18536
|
-
}
|
|
18537
18463
|
function reportPropertyRun(run) {
|
|
18538
18464
|
const tree = /* @__PURE__ */ new Map();
|
|
18539
18465
|
const paths = [];
|
|
@@ -18643,6 +18569,80 @@ var prefer_whole_object_assertion_default = createRule({
|
|
|
18643
18569
|
}
|
|
18644
18570
|
flush();
|
|
18645
18571
|
}
|
|
18572
|
+
function parseAssertion(statement) {
|
|
18573
|
+
if (statement.type !== import_utils105.AST_NODE_TYPES.ExpressionStatement) {
|
|
18574
|
+
return null;
|
|
18575
|
+
}
|
|
18576
|
+
const call = statement.expression;
|
|
18577
|
+
if (call.type !== import_utils105.AST_NODE_TYPES.CallExpression) {
|
|
18578
|
+
return null;
|
|
18579
|
+
}
|
|
18580
|
+
const callee = call.callee;
|
|
18581
|
+
if (callee.type !== import_utils105.AST_NODE_TYPES.MemberExpression || callee.computed || callee.property.type !== import_utils105.AST_NODE_TYPES.Identifier) {
|
|
18582
|
+
return null;
|
|
18583
|
+
}
|
|
18584
|
+
const matcher = callee.property.name;
|
|
18585
|
+
const expectCall = callee.object;
|
|
18586
|
+
if (expectCall.type !== import_utils105.AST_NODE_TYPES.CallExpression || expectCall.callee.type !== import_utils105.AST_NODE_TYPES.Identifier || expectCall.callee.name !== "expect" || expectCall.arguments.length !== 1) {
|
|
18587
|
+
return null;
|
|
18588
|
+
}
|
|
18589
|
+
const actual = expectCall.arguments[0];
|
|
18590
|
+
if (!isTestExpect(expectCall.callee)) return null;
|
|
18591
|
+
if (actual === void 0 || actual.type !== import_utils105.AST_NODE_TYPES.MemberExpression || actual.optional) {
|
|
18592
|
+
return null;
|
|
18593
|
+
}
|
|
18594
|
+
if (!isPureReceiver(actual.object)) {
|
|
18595
|
+
return null;
|
|
18596
|
+
}
|
|
18597
|
+
let key;
|
|
18598
|
+
let receiver;
|
|
18599
|
+
if (actual.computed) {
|
|
18600
|
+
const index = literalIndex(actual.property);
|
|
18601
|
+
if (index === null) {
|
|
18602
|
+
return null;
|
|
18603
|
+
}
|
|
18604
|
+
key = { kind: "index", index };
|
|
18605
|
+
receiver = actual.object;
|
|
18606
|
+
} else {
|
|
18607
|
+
const access = propertyAccess(actual);
|
|
18608
|
+
if (access === null) return null;
|
|
18609
|
+
key = { kind: "property", path: access.path };
|
|
18610
|
+
receiver = access.receiver;
|
|
18611
|
+
}
|
|
18612
|
+
return assertionExpectation(statement, call, receiver, key, matcher);
|
|
18613
|
+
}
|
|
18614
|
+
function isTestExpect(callee) {
|
|
18615
|
+
const variable = import_utils105.ASTUtils.findVariable(sourceCode.getScope(callee), callee.name);
|
|
18616
|
+
if (variable !== null && variable.defs.some((definition) => {
|
|
18617
|
+
if (definition.node.type !== import_utils105.AST_NODE_TYPES.ImportSpecifier) return true;
|
|
18618
|
+
const declaration = definition.node.parent;
|
|
18619
|
+
const imported = definition.node.imported;
|
|
18620
|
+
return declaration.type !== import_utils105.AST_NODE_TYPES.ImportDeclaration || !["vitest", "@jest/globals", "@playwright/test", "bun:test"].includes(String(declaration.source.value)) || (imported.type === import_utils105.AST_NODE_TYPES.Identifier ? imported.name : imported.value) !== "expect";
|
|
18621
|
+
})) return false;
|
|
18622
|
+
return true;
|
|
18623
|
+
}
|
|
18624
|
+
function assertionExpectation(statement, call, receiver, key, matcher) {
|
|
18625
|
+
const synthetic = SYNTHETIC_LITERAL_MATCHERS.get(matcher);
|
|
18626
|
+
if (synthetic !== void 0 && call.arguments.length === 0) {
|
|
18627
|
+
return { statement, receiver, key, matcher, expectedText: synthetic, expectedIsLiteral: true };
|
|
18628
|
+
}
|
|
18629
|
+
if (!MERGEABLE_MATCHERS.has(matcher)) {
|
|
18630
|
+
return null;
|
|
18631
|
+
}
|
|
18632
|
+
const expected = call.arguments[0];
|
|
18633
|
+
if (call.arguments.length !== 1 || expected === void 0 || expected.type === import_utils105.AST_NODE_TYPES.SpreadElement) {
|
|
18634
|
+
return null;
|
|
18635
|
+
}
|
|
18636
|
+
const literal = literalText(expected, (node) => sourceCode.getText(node));
|
|
18637
|
+
return {
|
|
18638
|
+
statement,
|
|
18639
|
+
receiver,
|
|
18640
|
+
key,
|
|
18641
|
+
matcher,
|
|
18642
|
+
expectedText: literal ?? sourceCode.getText(expected),
|
|
18643
|
+
expectedIsLiteral: literal !== null
|
|
18644
|
+
};
|
|
18645
|
+
}
|
|
18646
18646
|
return {
|
|
18647
18647
|
BlockStatement: (node) => {
|
|
18648
18648
|
checkBody(node.body);
|
|
@@ -21382,6 +21382,11 @@ var require_use_form_default_values_default = createRule({
|
|
|
21382
21382
|
const value = unwrapExpression6(node);
|
|
21383
21383
|
return value.type === import_utils115.AST_NODE_TYPES.UnaryExpression && value.operator === "void" || value.type === import_utils115.AST_NODE_TYPES.Identifier && value.name === "undefined" && (bindingOf(value)?.defs.length ?? 0) === 0;
|
|
21384
21384
|
};
|
|
21385
|
+
const uninitializedUseFormCall = (node) => {
|
|
21386
|
+
if (node.type !== import_utils115.AST_NODE_TYPES.CallExpression || node.callee.type !== import_utils115.AST_NODE_TYPES.Identifier || importedKind(node.callee) !== "useForm") return false;
|
|
21387
|
+
const options = node.arguments[0];
|
|
21388
|
+
return options?.type !== import_utils115.AST_NODE_TYPES.SpreadElement && initializationState(options) === "uninitialized";
|
|
21389
|
+
};
|
|
21385
21390
|
const initializationState = (node) => {
|
|
21386
21391
|
if (node === void 0) return "uninitialized";
|
|
21387
21392
|
if (node.type !== import_utils115.AST_NODE_TYPES.ObjectExpression) return "unknown";
|
|
@@ -21394,11 +21399,6 @@ var require_use_form_default_values_default = createRule({
|
|
|
21394
21399
|
}
|
|
21395
21400
|
return [...initialization.values()].some(Boolean) ? "initialized" : "uninitialized";
|
|
21396
21401
|
};
|
|
21397
|
-
const uninitializedUseFormCall = (node) => {
|
|
21398
|
-
if (node.type !== import_utils115.AST_NODE_TYPES.CallExpression || node.callee.type !== import_utils115.AST_NODE_TYPES.Identifier || importedKind(node.callee) !== "useForm") return false;
|
|
21399
|
-
const options = node.arguments[0];
|
|
21400
|
-
return options?.type !== import_utils115.AST_NODE_TYPES.SpreadElement && initializationState(options) === "uninitialized";
|
|
21401
|
-
};
|
|
21402
21402
|
const isUninitializedForm = (node) => {
|
|
21403
21403
|
if (node.type !== import_utils115.AST_NODE_TYPES.Identifier) return false;
|
|
21404
21404
|
const variable = bindingOf(node);
|
|
@@ -21627,28 +21627,13 @@ var require_zod_form_validation_default = createRule({
|
|
|
21627
21627
|
context.sourceCode.getScope(identifier),
|
|
21628
21628
|
identifier.name
|
|
21629
21629
|
);
|
|
21630
|
-
const
|
|
21631
|
-
const binding = resolvedBinding(identifier);
|
|
21632
|
-
if (binding === null || zodBindings.has(binding) || binding.defs.length !== 1) {
|
|
21633
|
-
return false;
|
|
21634
|
-
}
|
|
21635
|
-
const definition = binding.defs[0];
|
|
21636
|
-
if (definition?.type !== "Variable" || definition.node.type !== import_utils117.AST_NODE_TYPES.VariableDeclarator) {
|
|
21637
|
-
return false;
|
|
21638
|
-
}
|
|
21639
|
-
const init = definition.node.init;
|
|
21640
|
-
return init?.type === import_utils117.AST_NODE_TYPES.ObjectExpression || init?.type === import_utils117.AST_NODE_TYPES.ArrayExpression || init?.type === import_utils117.AST_NODE_TYPES.Literal || init?.type === import_utils117.AST_NODE_TYPES.ArrowFunctionExpression || init?.type === import_utils117.AST_NODE_TYPES.FunctionExpression;
|
|
21641
|
-
};
|
|
21642
|
-
const isZodParseCall = (node) => {
|
|
21643
|
-
if (node.type !== import_utils117.AST_NODE_TYPES.CallExpression) return false;
|
|
21630
|
+
const isFormDataGetCall = (node) => {
|
|
21644
21631
|
const callee = node.callee;
|
|
21645
|
-
if (callee.type !== import_utils117.AST_NODE_TYPES.MemberExpression
|
|
21632
|
+
if (callee.type !== import_utils117.AST_NODE_TYPES.MemberExpression) return false;
|
|
21633
|
+
if (callee.property.type !== import_utils117.AST_NODE_TYPES.Identifier || !FORM_VALUE_METHODS.has(callee.property.name)) {
|
|
21646
21634
|
return false;
|
|
21647
21635
|
}
|
|
21648
|
-
|
|
21649
|
-
if (root === null) return false;
|
|
21650
|
-
const binding = resolvedBinding(root);
|
|
21651
|
-
return binding !== null && zodBindings.has(binding) || (root.name === "z" || ZOD_SCHEMA_NAME_RE.test(root.name)) && !isProvablyNonZodLocal(root);
|
|
21636
|
+
return isFormSourceIdentifier(callee.object);
|
|
21652
21637
|
};
|
|
21653
21638
|
const isFormSourceIdentifier = (node) => {
|
|
21654
21639
|
if (node.type !== import_utils117.AST_NODE_TYPES.Identifier) return false;
|
|
@@ -21667,14 +21652,6 @@ var require_zod_form_validation_default = createRule({
|
|
|
21667
21652
|
}
|
|
21668
21653
|
return conventionalName;
|
|
21669
21654
|
};
|
|
21670
|
-
const isFormDataGetCall = (node) => {
|
|
21671
|
-
const callee = node.callee;
|
|
21672
|
-
if (callee.type !== import_utils117.AST_NODE_TYPES.MemberExpression) return false;
|
|
21673
|
-
if (callee.property.type !== import_utils117.AST_NODE_TYPES.Identifier || !FORM_VALUE_METHODS.has(callee.property.name)) {
|
|
21674
|
-
return false;
|
|
21675
|
-
}
|
|
21676
|
-
return isFormSourceIdentifier(callee.object);
|
|
21677
|
-
};
|
|
21678
21655
|
const zodParseAncestor = (node) => {
|
|
21679
21656
|
let parent = node.parent;
|
|
21680
21657
|
while (parent !== null && parent !== void 0) {
|
|
@@ -21692,6 +21669,29 @@ var require_zod_form_validation_default = createRule({
|
|
|
21692
21669
|
}
|
|
21693
21670
|
return null;
|
|
21694
21671
|
};
|
|
21672
|
+
const isZodParseCall = (node) => {
|
|
21673
|
+
if (node.type !== import_utils117.AST_NODE_TYPES.CallExpression) return false;
|
|
21674
|
+
const callee = node.callee;
|
|
21675
|
+
if (callee.type !== import_utils117.AST_NODE_TYPES.MemberExpression || callee.computed || callee.property.type !== import_utils117.AST_NODE_TYPES.Identifier || !ZOD_PARSE_METHODS.has(callee.property.name)) {
|
|
21676
|
+
return false;
|
|
21677
|
+
}
|
|
21678
|
+
const root = zodReceiverRoot(callee.object);
|
|
21679
|
+
if (root === null) return false;
|
|
21680
|
+
const binding = resolvedBinding(root);
|
|
21681
|
+
return binding !== null && zodBindings.has(binding) || (root.name === "z" || ZOD_SCHEMA_NAME_RE.test(root.name)) && !isProvablyNonZodLocal(root);
|
|
21682
|
+
};
|
|
21683
|
+
const isProvablyNonZodLocal = (identifier) => {
|
|
21684
|
+
const binding = resolvedBinding(identifier);
|
|
21685
|
+
if (binding === null || zodBindings.has(binding) || binding.defs.length !== 1) {
|
|
21686
|
+
return false;
|
|
21687
|
+
}
|
|
21688
|
+
const definition = binding.defs[0];
|
|
21689
|
+
if (definition?.type !== "Variable" || definition.node.type !== import_utils117.AST_NODE_TYPES.VariableDeclarator) {
|
|
21690
|
+
return false;
|
|
21691
|
+
}
|
|
21692
|
+
const init = definition.node.init;
|
|
21693
|
+
return init?.type === import_utils117.AST_NODE_TYPES.ObjectExpression || init?.type === import_utils117.AST_NODE_TYPES.ArrayExpression || init?.type === import_utils117.AST_NODE_TYPES.Literal || init?.type === import_utils117.AST_NODE_TYPES.ArrowFunctionExpression || init?.type === import_utils117.AST_NODE_TYPES.FunctionExpression;
|
|
21694
|
+
};
|
|
21695
21695
|
const hasZodParseAncestor = (node) => zodParseAncestor(node) !== null;
|
|
21696
21696
|
const isInstanceofNarrowing = (node) => {
|
|
21697
21697
|
const parent = node.parent;
|
|
@@ -21720,28 +21720,6 @@ var require_zod_form_validation_default = createRule({
|
|
|
21720
21720
|
}
|
|
21721
21721
|
return null;
|
|
21722
21722
|
};
|
|
21723
|
-
const zodParseMethod = (call) => {
|
|
21724
|
-
const callee = call.callee;
|
|
21725
|
-
return callee.type === import_utils117.AST_NODE_TYPES.MemberExpression && !callee.computed && callee.property.type === import_utils117.AST_NODE_TYPES.Identifier ? callee.property.name : null;
|
|
21726
|
-
};
|
|
21727
|
-
const hasConditionalAncestorBeforeStatement = (node, statement) => {
|
|
21728
|
-
let current = node.parent;
|
|
21729
|
-
while (current !== void 0 && current !== statement) {
|
|
21730
|
-
if (current.type === import_utils117.AST_NODE_TYPES.LogicalExpression || current.type === import_utils117.AST_NODE_TYPES.ConditionalExpression) {
|
|
21731
|
-
return true;
|
|
21732
|
-
}
|
|
21733
|
-
current = current.parent;
|
|
21734
|
-
}
|
|
21735
|
-
return false;
|
|
21736
|
-
};
|
|
21737
|
-
const isAwaitedBeforeStatement = (node, statement) => {
|
|
21738
|
-
let current = node.parent;
|
|
21739
|
-
while (current !== void 0 && current !== statement) {
|
|
21740
|
-
if (current.type === import_utils117.AST_NODE_TYPES.AwaitExpression) return true;
|
|
21741
|
-
current = current.parent;
|
|
21742
|
-
}
|
|
21743
|
-
return false;
|
|
21744
|
-
};
|
|
21745
21723
|
const guaranteedValidationStatement = (declarator, reference) => {
|
|
21746
21724
|
const parse2 = zodParseAncestor(reference);
|
|
21747
21725
|
if (parse2 === null) return null;
|
|
@@ -21760,6 +21738,28 @@ var require_zod_form_validation_default = createRule({
|
|
|
21760
21738
|
}
|
|
21761
21739
|
return null;
|
|
21762
21740
|
};
|
|
21741
|
+
const isAwaitedBeforeStatement = (node, statement) => {
|
|
21742
|
+
let current = node.parent;
|
|
21743
|
+
while (current !== void 0 && current !== statement) {
|
|
21744
|
+
if (current.type === import_utils117.AST_NODE_TYPES.AwaitExpression) return true;
|
|
21745
|
+
current = current.parent;
|
|
21746
|
+
}
|
|
21747
|
+
return false;
|
|
21748
|
+
};
|
|
21749
|
+
const hasConditionalAncestorBeforeStatement = (node, statement) => {
|
|
21750
|
+
let current = node.parent;
|
|
21751
|
+
while (current !== void 0 && current !== statement) {
|
|
21752
|
+
if (current.type === import_utils117.AST_NODE_TYPES.LogicalExpression || current.type === import_utils117.AST_NODE_TYPES.ConditionalExpression) {
|
|
21753
|
+
return true;
|
|
21754
|
+
}
|
|
21755
|
+
current = current.parent;
|
|
21756
|
+
}
|
|
21757
|
+
return false;
|
|
21758
|
+
};
|
|
21759
|
+
const zodParseMethod = (call) => {
|
|
21760
|
+
const callee = call.callee;
|
|
21761
|
+
return callee.type === import_utils117.AST_NODE_TYPES.MemberExpression && !callee.computed && callee.property.type === import_utils117.AST_NODE_TYPES.Identifier ? callee.property.name : null;
|
|
21762
|
+
};
|
|
21763
21763
|
const isSafePrevalidationInspection = (identifier) => {
|
|
21764
21764
|
const parent = identifier.parent;
|
|
21765
21765
|
if (parent.type === import_utils117.AST_NODE_TYPES.UnaryExpression && parent.operator === "typeof") {
|
|
@@ -21940,7 +21940,7 @@ var STEPDOWN_DOCUMENTATION = {
|
|
|
21940
21940
|
remediation: "Consider moving the private helper below its sole caller after reviewing initialization and reflection dependencies.",
|
|
21941
21941
|
category: "maintainability",
|
|
21942
21942
|
limitations: [
|
|
21943
|
-
"Generated and test files, cycles, dynamic or escaped references, overload targets, and helpers with multiple callers are excluded; immutable local callable aliases are followed only when every use stays in the caller.",
|
|
21943
|
+
"Generated and test files, cycles, dynamic or escaped references, overload targets, and helpers with multiple callers are excluded; immutable local callable aliases are followed only when every use stays in the caller. Function bodies include nested sibling helpers.",
|
|
21944
21944
|
"Class helpers must be private; their sole caller may be public, protected, or private.",
|
|
21945
21945
|
"Runtime class-field, static-block, computed-member, and decorator barriers are never crossed; non-hoisted module helpers also cannot cross eager execution or unrelated initialization.",
|
|
21946
21946
|
"This rule is report-only: reordering methods can change reflective property order, and moving module declarations can change initialization behavior or introduce temporal-dead-zone failures. Review module cycles and eager callers manually."
|
|
@@ -22083,8 +22083,9 @@ function localCallCount(context, node, owner) {
|
|
|
22083
22083
|
}
|
|
22084
22084
|
return count;
|
|
22085
22085
|
}
|
|
22086
|
-
function
|
|
22086
|
+
function declarationScope(context, program) {
|
|
22087
22087
|
const declarations = moduleDefinitions(program);
|
|
22088
|
+
if (declarations.length < 2) return;
|
|
22088
22089
|
const counts = /* @__PURE__ */ new Map();
|
|
22089
22090
|
for (const node of declarations) counts.set(node.name, (counts.get(node.name) ?? 0) + 1);
|
|
22090
22091
|
const overloadNames = new Set(
|
|
@@ -22093,7 +22094,7 @@ function moduleScope(context, program) {
|
|
|
22093
22094
|
return node?.type === import_utils119.AST_NODE_TYPES.TSDeclareFunction && node.id !== null ? [node.id.name] : [];
|
|
22094
22095
|
})
|
|
22095
22096
|
);
|
|
22096
|
-
const exported = exportedNames(program);
|
|
22097
|
+
const exported = program.type === import_utils119.AST_NODE_TYPES.Program ? exportedNames(program) : /* @__PURE__ */ new Set();
|
|
22097
22098
|
const scopeDefinitions = declarations.filter((node) => counts.get(node.name) === 1);
|
|
22098
22099
|
const definitions = scopeDefinitions.filter(
|
|
22099
22100
|
(definition) => !exported.has(definition.name) && !overloadNames.has(definition.name)
|
|
@@ -22104,17 +22105,17 @@ function moduleScope(context, program) {
|
|
|
22104
22105
|
for (const statement of program.body) {
|
|
22105
22106
|
runtimeBarrierPrefix.push((runtimeBarrierPrefix.at(-1) ?? 0) + (isDeferredModuleStatement(statement) ? 0 : 1));
|
|
22106
22107
|
}
|
|
22107
|
-
const statementIndex = (definition) => {
|
|
22108
|
-
let current = definition.node;
|
|
22109
|
-
while (current.parent !== void 0 && current.parent.type !== import_utils119.AST_NODE_TYPES.Program) current = current.parent;
|
|
22110
|
-
return statementIndexes.get(current);
|
|
22111
|
-
};
|
|
22112
22108
|
const canMove = (helper, caller) => {
|
|
22113
22109
|
if (helper.node.type === import_utils119.AST_NODE_TYPES.FunctionDeclaration) return true;
|
|
22114
22110
|
const helperIndex = statementIndex(helper);
|
|
22115
22111
|
const callerIndex = statementIndex(caller);
|
|
22116
22112
|
return helperIndex !== void 0 && callerIndex !== void 0 && runtimeBarrierPrefix[callerIndex + 1] === runtimeBarrierPrefix[helperIndex + 1];
|
|
22117
22113
|
};
|
|
22114
|
+
const statementIndex = (definition) => {
|
|
22115
|
+
let current = definition.node;
|
|
22116
|
+
while (current.parent !== void 0 && current.parent !== program) current = current.parent;
|
|
22117
|
+
return statementIndexes.get(current);
|
|
22118
|
+
};
|
|
22118
22119
|
reportMisordered(context, definitions, scopeDefinitions, calls, pinned, canMove);
|
|
22119
22120
|
}
|
|
22120
22121
|
function moduleCallGraph(context, scopeDefinitions) {
|
|
@@ -22215,9 +22216,38 @@ function methodKey(name, isStatic2) {
|
|
|
22215
22216
|
function receiverDomain(context, object, receivers, thisIsStatic) {
|
|
22216
22217
|
const unwrapped = unwrapExpression7(object);
|
|
22217
22218
|
if (unwrapped.type === import_utils119.AST_NODE_TYPES.ThisExpression) return thisIsStatic;
|
|
22218
|
-
|
|
22219
|
-
|
|
22220
|
-
|
|
22219
|
+
return externalReceiverDomain(context, unwrapped, receivers);
|
|
22220
|
+
}
|
|
22221
|
+
function externalReceiverDomain(context, object, receivers) {
|
|
22222
|
+
const origin = receiverOrigin(context, object, receivers);
|
|
22223
|
+
if (origin === null || typeof origin === "boolean") return origin;
|
|
22224
|
+
if (origin.type === import_utils119.AST_NODE_TYPES.NewExpression) {
|
|
22225
|
+
return receiverOrigin(context, origin.callee, receivers) === true ? false : null;
|
|
22226
|
+
}
|
|
22227
|
+
if (origin.type === import_utils119.AST_NODE_TYPES.ObjectExpression || origin.type === import_utils119.AST_NODE_TYPES.ArrayExpression || origin.type === import_utils119.AST_NODE_TYPES.Literal || origin.type === import_utils119.AST_NODE_TYPES.ArrowFunctionExpression || origin.type === import_utils119.AST_NODE_TYPES.FunctionExpression) return "unrelated";
|
|
22228
|
+
return null;
|
|
22229
|
+
}
|
|
22230
|
+
function receiverOrigin(context, object, receivers) {
|
|
22231
|
+
let current = object;
|
|
22232
|
+
const seen = /* @__PURE__ */ new Set();
|
|
22233
|
+
while (true) {
|
|
22234
|
+
const unwrapped = unwrapExpression7(current);
|
|
22235
|
+
if (unwrapped.type !== import_utils119.AST_NODE_TYPES.Identifier) return unwrapped;
|
|
22236
|
+
const variable = import_utils119.ASTUtils.findVariable(context.sourceCode.getScope(unwrapped), unwrapped.name);
|
|
22237
|
+
if (variable === null) return null;
|
|
22238
|
+
const known = receivers.get(variable);
|
|
22239
|
+
if (known !== void 0) return known;
|
|
22240
|
+
const initializer = immutableInitializer(variable, seen);
|
|
22241
|
+
if (initializer === null) return null;
|
|
22242
|
+
current = initializer;
|
|
22243
|
+
}
|
|
22244
|
+
}
|
|
22245
|
+
function immutableInitializer(variable, seen) {
|
|
22246
|
+
if (seen.has(variable) || !stableVariable(variable) || variable.defs.length !== 1) return null;
|
|
22247
|
+
seen.add(variable);
|
|
22248
|
+
const definition = variable.defs[0];
|
|
22249
|
+
if (definition?.node.type !== import_utils119.AST_NODE_TYPES.VariableDeclarator || definition.node.parent.type !== import_utils119.AST_NODE_TYPES.VariableDeclaration || definition.node.parent.kind !== "const") return null;
|
|
22250
|
+
return definition.node.init;
|
|
22221
22251
|
}
|
|
22222
22252
|
function stableVariable(variable) {
|
|
22223
22253
|
return !variable.references.some((reference) => reference.isWrite() && reference.init !== true);
|
|
@@ -22232,7 +22262,7 @@ function walk(node, visitorKeys, visit, nestedFunction = false) {
|
|
|
22232
22262
|
const nested = nestedFunction || isFunction(node) || node.type === import_utils119.AST_NODE_TYPES.ClassDeclaration || node.type === import_utils119.AST_NODE_TYPES.ClassExpression;
|
|
22233
22263
|
forEachAstChild(node, visitorKeys, (child) => walk(child, visitorKeys, visit, nested));
|
|
22234
22264
|
}
|
|
22235
|
-
function classScope(context, node,
|
|
22265
|
+
function classScope(context, node, computedReferences) {
|
|
22236
22266
|
const methods = node.body.body.filter(
|
|
22237
22267
|
(member) => member.type === import_utils119.AST_NODE_TYPES.MethodDefinition
|
|
22238
22268
|
);
|
|
@@ -22289,7 +22319,7 @@ function classScope(context, node, computedReferenceNames) {
|
|
|
22289
22319
|
const collectAlias = (current, nestedFunction) => {
|
|
22290
22320
|
if (nestedFunction || current.type !== import_utils119.AST_NODE_TYPES.VariableDeclarator || current.init === null) return;
|
|
22291
22321
|
const domain = receiverDomain(context, current.init, receivers, method.static);
|
|
22292
|
-
if (domain === null) return;
|
|
22322
|
+
if (domain === null || domain === "unrelated") return;
|
|
22293
22323
|
if (current.id.type === import_utils119.AST_NODE_TYPES.ObjectPattern) {
|
|
22294
22324
|
pinDestructuredMembers(current.id, domain);
|
|
22295
22325
|
return;
|
|
@@ -22314,11 +22344,12 @@ function classScope(context, node, computedReferenceNames) {
|
|
|
22314
22344
|
const destructuring = receiverDestructuring(current);
|
|
22315
22345
|
if (destructuring !== null) {
|
|
22316
22346
|
const domain2 = receiverDomain(context, destructuring.value, receivers, method.static);
|
|
22317
|
-
pinDestructuredMembers(destructuring.binding, domain2);
|
|
22347
|
+
if (domain2 !== "unrelated") pinDestructuredMembers(destructuring.binding, domain2);
|
|
22318
22348
|
}
|
|
22319
22349
|
if (current.type !== import_utils119.AST_NODE_TYPES.MemberExpression) return;
|
|
22320
22350
|
const domain = receiverDomain(context, current.object, receivers, method.static);
|
|
22321
22351
|
const targetName = referencedPropertyName(current);
|
|
22352
|
+
if (domain === "unrelated") return;
|
|
22322
22353
|
if (domain === null) {
|
|
22323
22354
|
pinNames(targetName);
|
|
22324
22355
|
return;
|
|
@@ -22352,11 +22383,20 @@ function classScope(context, node, computedReferenceNames) {
|
|
|
22352
22383
|
if (member.type === import_utils119.AST_NODE_TYPES.MethodDefinition || member.type === import_utils119.AST_NODE_TYPES.TSAbstractMethodDefinition) continue;
|
|
22353
22384
|
walk(member, context.sourceCode.visitorKeys, (current) => {
|
|
22354
22385
|
if (current.type !== import_utils119.AST_NODE_TYPES.MemberExpression) return;
|
|
22386
|
+
if (externalReceiverDomain(context, current.object, classReceivers) === "unrelated") return;
|
|
22355
22387
|
pinNames(referencedPropertyName(current));
|
|
22356
22388
|
});
|
|
22357
22389
|
}
|
|
22358
|
-
|
|
22359
|
-
|
|
22390
|
+
const externalReceivers = new Map(classReceivers);
|
|
22391
|
+
for (const variable of context.sourceCode.getDeclaredVariables(node)) {
|
|
22392
|
+
if (stableVariable(variable)) externalReceivers.set(variable, true);
|
|
22393
|
+
}
|
|
22394
|
+
for (const reference of computedReferences) {
|
|
22395
|
+
if (context.sourceCode.getAncestors(reference).includes(node)) continue;
|
|
22396
|
+
const domain = externalReceiverDomain(context, reference.object, externalReceivers);
|
|
22397
|
+
if (domain === "unrelated") continue;
|
|
22398
|
+
const name = referencedPropertyName(reference);
|
|
22399
|
+
if (name !== null || domain !== null) pinNames(name, domain);
|
|
22360
22400
|
}
|
|
22361
22401
|
const memberIndexes = new Map(node.body.body.map((member, index) => [member, index]));
|
|
22362
22402
|
const runtimeBarrierPrefix = [0];
|
|
@@ -22420,6 +22460,7 @@ var stepdown_default = createRule({
|
|
|
22420
22460
|
create(context) {
|
|
22421
22461
|
if (isTestFile(context.filename) || isGeneratedFile(context.filename, context.sourceCode.text)) return {};
|
|
22422
22462
|
const classes = [];
|
|
22463
|
+
const functionBodies = [];
|
|
22423
22464
|
return {
|
|
22424
22465
|
ClassDeclaration: (node) => {
|
|
22425
22466
|
classes.push(node);
|
|
@@ -22427,13 +22468,17 @@ var stepdown_default = createRule({
|
|
|
22427
22468
|
ClassExpression: (node) => {
|
|
22428
22469
|
classes.push(node);
|
|
22429
22470
|
},
|
|
22471
|
+
"FunctionDeclaration, FunctionExpression, ArrowFunctionExpression": (node) => {
|
|
22472
|
+
if (isFunction(node) && node.body?.type === import_utils119.AST_NODE_TYPES.BlockStatement) functionBodies.push(node.body);
|
|
22473
|
+
},
|
|
22430
22474
|
"Program:exit": (program) => {
|
|
22431
|
-
|
|
22432
|
-
const
|
|
22475
|
+
declarationScope(context, program);
|
|
22476
|
+
for (const body2 of functionBodies) declarationScope(context, body2);
|
|
22477
|
+
const computedReferences = [];
|
|
22433
22478
|
walk(program, context.sourceCode.visitorKeys, (node) => {
|
|
22434
|
-
if (node.type === import_utils119.AST_NODE_TYPES.MemberExpression && node.computed
|
|
22479
|
+
if (node.type === import_utils119.AST_NODE_TYPES.MemberExpression && node.computed) computedReferences.push(node);
|
|
22435
22480
|
});
|
|
22436
|
-
for (const node of classes) classScope(context, node,
|
|
22481
|
+
for (const node of classes) classScope(context, node, computedReferences);
|
|
22437
22482
|
}
|
|
22438
22483
|
};
|
|
22439
22484
|
}
|
|
@@ -22785,6 +22830,59 @@ function importedAssertionKind(specifier) {
|
|
|
22785
22830
|
|
|
22786
22831
|
// src/rules/sole-export-matches-filename.ts
|
|
22787
22832
|
var import_utils121 = require("@typescript-eslint/utils");
|
|
22833
|
+
|
|
22834
|
+
// src/rules/_is-framework-entrypoint.ts
|
|
22835
|
+
var import_node_fs2 = require("fs");
|
|
22836
|
+
var import_node_path2 = require("path");
|
|
22837
|
+
var HTTP_METHODS = /* @__PURE__ */ new Set(["GET", "HEAD", "POST", "PUT", "DELETE", "PATCH", "OPTIONS"]);
|
|
22838
|
+
var NEXT_COMPONENT = /^(?:src\/)?app\/(?:.*\/)?(?:page|layout|loading|not-found|template|error|global-error|default|forbidden|unauthorized)\.[jt]sx?$/u;
|
|
22839
|
+
var NEXT_ROUTE = /^(?:src\/)?app\/(?:.*\/)?route\.[jt]s$/u;
|
|
22840
|
+
function isFrameworkEntrypoint(filename, exportKey) {
|
|
22841
|
+
const normalized = filename.replaceAll("\\", "/");
|
|
22842
|
+
if (!/(?:^|\/)(?:app|pages)\/|(?:^|\/)(?:middleware|proxy)\.[jt]s$/u.test(normalized)) return false;
|
|
22843
|
+
const owner = packageOwner(normalized);
|
|
22844
|
+
if (owner === null) return false;
|
|
22845
|
+
const path = (0, import_node_path2.relative)(owner.root, normalized).replaceAll("\\", "/");
|
|
22846
|
+
if (declaresFramework(owner.metadata, "next") && isNextEntrypoint(path, exportKey)) return true;
|
|
22847
|
+
return declaresFramework(owner.metadata, "astro") && isAstroEntrypoint(path, exportKey);
|
|
22848
|
+
}
|
|
22849
|
+
function isNextEntrypoint(path, exportKey) {
|
|
22850
|
+
const privateAppFolder = /^(?:src\/)?app\/(?:.*\/)?_[^/]+\//u.test(path);
|
|
22851
|
+
if (!privateAppFolder && NEXT_COMPONENT.test(path) && exportKey === "default") return true;
|
|
22852
|
+
if (!privateAppFolder && NEXT_ROUTE.test(path) && HTTP_METHODS.has(exportKey)) return true;
|
|
22853
|
+
if (/^(?:src\/)?pages\/.*\.[jt]sx?$/u.test(path) && exportKey === "default") return true;
|
|
22854
|
+
const middleware = /^(?:src\/)?(middleware|proxy)\.[jt]s$/u.exec(path);
|
|
22855
|
+
return middleware !== null && (exportKey === "default" || exportKey === middleware[1]);
|
|
22856
|
+
}
|
|
22857
|
+
function isAstroEntrypoint(path, exportKey) {
|
|
22858
|
+
return (
|
|
22859
|
+
// Astro pages implicitly export their rendered component, including when only a routing hook is explicit.
|
|
22860
|
+
/^src\/pages\/.*\.astro$/u.test(path) || /^src\/pages\/.*\.[jt]s$/u.test(path) && (HTTP_METHODS.has(exportKey) || exportKey === "ALL") || /^src\/middleware\.[jt]s$/u.test(path) && exportKey === "onRequest"
|
|
22861
|
+
);
|
|
22862
|
+
}
|
|
22863
|
+
function packageOwner(filename) {
|
|
22864
|
+
let root = (0, import_node_path2.dirname)(filename);
|
|
22865
|
+
while (true) {
|
|
22866
|
+
try {
|
|
22867
|
+
return { root, metadata: JSON.parse((0, import_node_fs2.readFileSync)((0, import_node_path2.join)(root, "package.json"), "utf8")) };
|
|
22868
|
+
} catch (error) {
|
|
22869
|
+
if (typeof error !== "object" || error === null || !("code" in error) || error.code !== "ENOENT") return null;
|
|
22870
|
+
}
|
|
22871
|
+
const parent = (0, import_node_path2.dirname)(root);
|
|
22872
|
+
if (parent === root) return null;
|
|
22873
|
+
root = parent;
|
|
22874
|
+
}
|
|
22875
|
+
}
|
|
22876
|
+
function declaresFramework(metadata, name) {
|
|
22877
|
+
if (typeof metadata !== "object" || metadata === null) return false;
|
|
22878
|
+
for (const section of ["dependencies", "devDependencies", "peerDependencies", "optionalDependencies"]) {
|
|
22879
|
+
const dependencies = Reflect.get(metadata, section);
|
|
22880
|
+
if (typeof dependencies === "object" && dependencies !== null && typeof Reflect.get(dependencies, name) === "string") return true;
|
|
22881
|
+
}
|
|
22882
|
+
return false;
|
|
22883
|
+
}
|
|
22884
|
+
|
|
22885
|
+
// src/rules/sole-export-matches-filename.ts
|
|
22788
22886
|
var SOLE_EXPORT_MATCHES_FILENAME_DOCUMENTATION = {
|
|
22789
22887
|
defaultLevel: "error",
|
|
22790
22888
|
summary: "Make a module filename reflect its sole named public runtime export.",
|
|
@@ -22794,7 +22892,8 @@ var SOLE_EXPORT_MATCHES_FILENAME_DOCUMENTATION = {
|
|
|
22794
22892
|
limitations: [
|
|
22795
22893
|
"Framework entrypoints, generic stems covered by no-generic-single-export-module, tests, generated files, anonymous defaults, CommonJS, unresolved re-exports, and emission-dependent exports are excluded.",
|
|
22796
22894
|
"The rule compares the primary filename stem and preserves a single private underscore prefix and conventional suffixes such as .server or .worker. Supporting types do not exempt a sole runtime export; public runtime aliases count as distinct exports.",
|
|
22797
|
-
"Exported destructuring patterns are excluded rather than undercounted as public exports."
|
|
22895
|
+
"Exported destructuring patterns are excluded rather than undercounted as public exports.",
|
|
22896
|
+
"Next.js and Astro routing exemptions require the nearest package.json to declare the framework, a conventional entrypoint path, and its expected runtime export. Custom routing roots and pageExtensions are not inferred."
|
|
22798
22897
|
],
|
|
22799
22898
|
examples: [
|
|
22800
22899
|
{ id: "matching-class", title: "Match a class and module", outcome: "no-match", files: [{ path: "src/artifact-store.ts", source: "export class ArtifactStore {}" }], focusPath: "src/artifact-store.ts", expectedCount: 0, public: true },
|
|
@@ -22804,13 +22903,6 @@ var SOLE_EXPORT_MATCHES_FILENAME_DOCUMENTATION = {
|
|
|
22804
22903
|
var EXCLUDED_STEMS = /* @__PURE__ */ new Set([
|
|
22805
22904
|
"global",
|
|
22806
22905
|
"index",
|
|
22807
|
-
"layout",
|
|
22808
|
-
"loading",
|
|
22809
|
-
"middleware",
|
|
22810
|
-
"not-found",
|
|
22811
|
-
"page",
|
|
22812
|
-
"route",
|
|
22813
|
-
"template",
|
|
22814
22906
|
"types"
|
|
22815
22907
|
]);
|
|
22816
22908
|
function stem3(filename) {
|
|
@@ -22835,7 +22927,7 @@ var sole_export_matches_filename_default = createRule({
|
|
|
22835
22927
|
create(context) {
|
|
22836
22928
|
const fileStem = stem3(context.filename);
|
|
22837
22929
|
const normalizedFilename = context.filename.replaceAll("\\", "/");
|
|
22838
|
-
if (EXCLUDED_STEMS.has(fileStem) || GENERIC_MODULE_STEMS.has(fileStem) ||
|
|
22930
|
+
if (EXCLUDED_STEMS.has(fileStem) || GENERIC_MODULE_STEMS.has(fileStem) || context.filename.endsWith(".d.ts") || isTestFile(context.filename) || isGeneratedFile(context.filename, context.sourceCode.text)) return {};
|
|
22839
22931
|
let hasCommonJsExport = false;
|
|
22840
22932
|
return {
|
|
22841
22933
|
"CallExpression, MemberExpression"(node) {
|
|
@@ -22847,6 +22939,7 @@ var sole_export_matches_filename_default = createRule({
|
|
|
22847
22939
|
if (exports2.ambiguous || exports2.exports.length !== 1) return;
|
|
22848
22940
|
const only = exports2.exports[0];
|
|
22849
22941
|
if (only === void 0) return;
|
|
22942
|
+
if (isFrameworkEntrypoint(normalizedFilename, only.key)) return;
|
|
22850
22943
|
if (only.name === "onRouterTransitionStart" && /(?:^|\/)instrumentation-client\.[jt]s$/u.test(normalizedFilename)) return;
|
|
22851
22944
|
if (only.name === "collections" && /(?:^|\/)src\/content\.config\.(?:ts|js|mjs)$/u.test(normalizedFilename) && program.body.some((statement) => statement.type === import_utils121.AST_NODE_TYPES.ImportDeclaration && statement.source.value === "astro:content")) return;
|
|
22852
22945
|
const exportedStem = kebabCase(only.name);
|
|
@@ -23107,16 +23200,6 @@ var require_pascal_case_zod_schema_name_default = createRule({
|
|
|
23107
23200
|
const binding = resolvedBinding(identifier);
|
|
23108
23201
|
if (binding !== null) zodBindings.add(binding);
|
|
23109
23202
|
}
|
|
23110
|
-
function isZodChain(node) {
|
|
23111
|
-
const root = calleeChainRoot2(node);
|
|
23112
|
-
if (root === null) return false;
|
|
23113
|
-
const binding = resolvedBinding(root);
|
|
23114
|
-
return binding !== null && zodBindings.has(binding);
|
|
23115
|
-
}
|
|
23116
|
-
function isSchemaBinding(identifier) {
|
|
23117
|
-
const binding = resolvedBinding(identifier);
|
|
23118
|
-
return binding !== null && schemaBindings.has(binding);
|
|
23119
|
-
}
|
|
23120
23203
|
function isConfirmedSchema(expression) {
|
|
23121
23204
|
const init = unwrapExpression8(expression);
|
|
23122
23205
|
if (init.type === import_utils122.AST_NODE_TYPES.Identifier) return isSchemaBinding(init);
|
|
@@ -23133,6 +23216,16 @@ var require_pascal_case_zod_schema_name_default = createRule({
|
|
|
23133
23216
|
const root = calleeChainRoot2(init.callee);
|
|
23134
23217
|
return root !== null && isSchemaBinding(root) && SCHEMA_RETURNING_METHODS.has(terminal);
|
|
23135
23218
|
}
|
|
23219
|
+
function isSchemaBinding(identifier) {
|
|
23220
|
+
const binding = resolvedBinding(identifier);
|
|
23221
|
+
return binding !== null && schemaBindings.has(binding);
|
|
23222
|
+
}
|
|
23223
|
+
function isZodChain(node) {
|
|
23224
|
+
const root = calleeChainRoot2(node);
|
|
23225
|
+
if (root === null) return false;
|
|
23226
|
+
const binding = resolvedBinding(root);
|
|
23227
|
+
return binding !== null && zodBindings.has(binding);
|
|
23228
|
+
}
|
|
23136
23229
|
if (isTestFile(context.filename) || BENCHMARK_PATH_RE2.test(context.filename.replaceAll("\\", "/")) || isGeneratedFile(context.filename, context.sourceCode.text)) {
|
|
23137
23230
|
return {};
|
|
23138
23231
|
}
|
|
@@ -23364,7 +23457,7 @@ var RULES = {
|
|
|
23364
23457
|
};
|
|
23365
23458
|
var meta = {
|
|
23366
23459
|
name: "@sarj/eslint-plugin",
|
|
23367
|
-
version: "16.
|
|
23460
|
+
version: "16.1.0"
|
|
23368
23461
|
};
|
|
23369
23462
|
var APPLICATION_ONLY_RULES = [];
|
|
23370
23463
|
var LIBRARY_IMPORT_POLICY = ["error", {
|