@sarj/eslint-plugin 16.26.1 → 16.26.2
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 +25 -7
- package/dist/index.js +25 -7
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -883,7 +883,7 @@ function isSearchParamReceiver(call, services) {
|
|
|
883
883
|
// package.json
|
|
884
884
|
var package_default = {
|
|
885
885
|
name: "@sarj/eslint-plugin",
|
|
886
|
-
version: "16.26.
|
|
886
|
+
version: "16.26.2",
|
|
887
887
|
packageManager: "npm@12.2.0",
|
|
888
888
|
description: "Custom ESLint rules for hypermodern TypeScript / React / Next.js projects",
|
|
889
889
|
type: "module",
|
|
@@ -11084,6 +11084,7 @@ var no_bare_return_from_test_catch_default = createRule({
|
|
|
11084
11084
|
const returnBlock = node.parent;
|
|
11085
11085
|
if (parameter?.type === import_utils64.AST_NODE_TYPES.Identifier && returnBlock?.type === import_utils64.AST_NODE_TYPES.BlockStatement) {
|
|
11086
11086
|
const errorBinding = import_utils64.ASTUtils.findVariable(context.sourceCode.getScope(parameter), parameter.name);
|
|
11087
|
+
const errorReferences = errorBinding !== null && errorBinding.references.length > 32 ? new Set(errorBinding.references.map((reference) => reference.identifier)) : void 0;
|
|
11087
11088
|
const assertedError = returnBlock.body.some((statement) => {
|
|
11088
11089
|
if (statement.range[1] > node.range[0] || statement.type !== import_utils64.AST_NODE_TYPES.ExpressionStatement) return false;
|
|
11089
11090
|
const expression = statement.expression;
|
|
@@ -11094,7 +11095,7 @@ var no_bare_return_from_test_catch_default = createRule({
|
|
|
11094
11095
|
let operand = expression.callee.type === import_utils64.AST_NODE_TYPES.MemberExpression ? expression.callee.object : null;
|
|
11095
11096
|
if (operand?.type === import_utils64.AST_NODE_TYPES.MemberExpression && staticMemberName3(operand) === "not") operand = operand.object;
|
|
11096
11097
|
if (assertionName !== "assert" && (assertionName !== "expect" || operand?.type !== import_utils64.AST_NODE_TYPES.CallExpression || operand.callee !== root)) return false;
|
|
11097
|
-
return walkOwnScope(expression, (current) => current.type === import_utils64.AST_NODE_TYPES.Identifier && errorBinding?.references.some((reference) => reference.identifier === current) === true);
|
|
11098
|
+
return walkOwnScope(expression, (current) => current.type === import_utils64.AST_NODE_TYPES.Identifier && (errorReferences?.has(current) ?? errorBinding?.references.some((reference) => reference.identifier === current)) === true);
|
|
11098
11099
|
});
|
|
11099
11100
|
if (assertedError) return;
|
|
11100
11101
|
}
|
|
@@ -17325,6 +17326,15 @@ var test_loops_over_literal_cases_default = createRule({
|
|
|
17325
17326
|
if (!isTestFile(context)) {
|
|
17326
17327
|
return {};
|
|
17327
17328
|
}
|
|
17329
|
+
const referenceIdentifiers = /* @__PURE__ */ new WeakMap();
|
|
17330
|
+
const isReference = (variable, identifier) => {
|
|
17331
|
+
let identifiers = referenceIdentifiers.get(variable);
|
|
17332
|
+
if (identifiers === void 0) {
|
|
17333
|
+
identifiers = new Set(variable.references.map((reference) => reference.identifier));
|
|
17334
|
+
referenceIdentifiers.set(variable, identifiers);
|
|
17335
|
+
}
|
|
17336
|
+
return identifiers.has(identifier);
|
|
17337
|
+
};
|
|
17328
17338
|
const isFrameworkTest = (identifier) => TEST_CALLERS3.has(runtimeTestFrameworkName(context.sourceCode, identifier, "test") ?? "");
|
|
17329
17339
|
const isFrameworkAssertion = (identifier) => ASSERTION_ROOTS.has(runtimeTestFrameworkName(context.sourceCode, identifier, "assertion") ?? "");
|
|
17330
17340
|
return {
|
|
@@ -17348,7 +17358,7 @@ var test_loops_over_literal_cases_default = createRule({
|
|
|
17348
17358
|
const capturesSetup = walkOwnScope2(node.body, (current) => {
|
|
17349
17359
|
if (current.type !== import_utils99.AST_NODE_TYPES.Identifier) return false;
|
|
17350
17360
|
const variable = import_utils99.ASTUtils.findVariable(context.sourceCode.getScope(current), current.name);
|
|
17351
|
-
if (variable === null || !variable
|
|
17361
|
+
if (variable === null || !isReference(variable, current)) return false;
|
|
17352
17362
|
return variable.defs.some((definition) => {
|
|
17353
17363
|
const declaration = definition.name;
|
|
17354
17364
|
return declaration.range[0] >= enclosing.range[0] && declaration.range[1] <= enclosing.range[1] && (declaration.range[0] < node.range[0] || declaration.range[1] > node.range[1]);
|
|
@@ -27532,6 +27542,14 @@ function createSourceCoupledRule(name, documentation, sourceSuffixRe) {
|
|
|
27532
27542
|
defaultOptions: [],
|
|
27533
27543
|
create(context) {
|
|
27534
27544
|
if (!isTestFile(context) || isGeneratedFile(context, context.sourceCode.text)) return {};
|
|
27545
|
+
const referenceStability = /* @__PURE__ */ new WeakMap();
|
|
27546
|
+
const referenceStable = (variable) => {
|
|
27547
|
+
const cached = referenceStability.get(variable);
|
|
27548
|
+
if (cached !== void 0) return cached;
|
|
27549
|
+
const stable = !variable.references.some((reference) => reference.isWrite() && reference.init !== true);
|
|
27550
|
+
referenceStability.set(variable, stable);
|
|
27551
|
+
return stable;
|
|
27552
|
+
};
|
|
27535
27553
|
const scopes = [newScope()];
|
|
27536
27554
|
const reportedOrigins = /* @__PURE__ */ new Set();
|
|
27537
27555
|
const currentScope = () => scopes.at(-1) ?? scopes[0];
|
|
@@ -27549,7 +27567,7 @@ function createSourceCoupledRule(name, documentation, sourceSuffixRe) {
|
|
|
27549
27567
|
};
|
|
27550
27568
|
const visible = (kind, node) => {
|
|
27551
27569
|
const name2 = bindingOf(node);
|
|
27552
|
-
if (name2 === null || name2
|
|
27570
|
+
if (name2 === null || !referenceStable(name2)) return false;
|
|
27553
27571
|
for (let index = scopes.length - 1; index >= 0; index--) {
|
|
27554
27572
|
const scope = scopes[index];
|
|
27555
27573
|
if (scope.declared.has(name2)) return scope[kind].has(name2);
|
|
@@ -27558,7 +27576,7 @@ function createSourceCoupledRule(name, documentation, sourceSuffixRe) {
|
|
|
27558
27576
|
};
|
|
27559
27577
|
const visibleRawOrigins = (node) => {
|
|
27560
27578
|
const name2 = bindingOf(node);
|
|
27561
|
-
if (name2 === null || name2
|
|
27579
|
+
if (name2 === null || !referenceStable(name2)) return /* @__PURE__ */ new Set();
|
|
27562
27580
|
for (let index = scopes.length - 1; index >= 0; index--) {
|
|
27563
27581
|
const scope = scopes[index];
|
|
27564
27582
|
if (scope.declared.has(name2)) return scope.rawOrigins.get(name2) ?? /* @__PURE__ */ new Set();
|
|
@@ -27590,7 +27608,7 @@ function createSourceCoupledRule(name, documentation, sourceSuffixRe) {
|
|
|
27590
27608
|
};
|
|
27591
27609
|
const nativeImportedName = (node, modules) => {
|
|
27592
27610
|
const binding = bindingOf(node);
|
|
27593
|
-
if (binding === null || binding
|
|
27611
|
+
if (binding === null || !referenceStable(binding)) return null;
|
|
27594
27612
|
for (const definition of binding.defs) {
|
|
27595
27613
|
const imported = definition.node;
|
|
27596
27614
|
if (imported.type === import_utils144.AST_NODE_TYPES.ImportSpecifier && imported.imported.type === import_utils144.AST_NODE_TYPES.Identifier && imported.parent.type === import_utils144.AST_NODE_TYPES.ImportDeclaration && modules.has(String(imported.parent.source.value))) {
|
|
@@ -27601,7 +27619,7 @@ function createSourceCoupledRule(name, documentation, sourceSuffixRe) {
|
|
|
27601
27619
|
};
|
|
27602
27620
|
const stableInitializer = (node) => {
|
|
27603
27621
|
const binding = bindingOf(node);
|
|
27604
|
-
if (binding === null || binding
|
|
27622
|
+
if (binding === null || !referenceStable(binding) || binding.defs.length !== 1) return null;
|
|
27605
27623
|
const definition = binding.defs[0]?.node;
|
|
27606
27624
|
return definition?.type === import_utils144.AST_NODE_TYPES.VariableDeclarator ? definition.init : null;
|
|
27607
27625
|
};
|
package/dist/index.js
CHANGED
|
@@ -836,7 +836,7 @@ function isSearchParamReceiver(call, services) {
|
|
|
836
836
|
// package.json
|
|
837
837
|
var package_default = {
|
|
838
838
|
name: "@sarj/eslint-plugin",
|
|
839
|
-
version: "16.26.
|
|
839
|
+
version: "16.26.2",
|
|
840
840
|
packageManager: "npm@12.2.0",
|
|
841
841
|
description: "Custom ESLint rules for hypermodern TypeScript / React / Next.js projects",
|
|
842
842
|
type: "module",
|
|
@@ -11069,6 +11069,7 @@ var no_bare_return_from_test_catch_default = createRule({
|
|
|
11069
11069
|
const returnBlock = node.parent;
|
|
11070
11070
|
if (parameter?.type === AST_NODE_TYPES55.Identifier && returnBlock?.type === AST_NODE_TYPES55.BlockStatement) {
|
|
11071
11071
|
const errorBinding = ASTUtils32.findVariable(context.sourceCode.getScope(parameter), parameter.name);
|
|
11072
|
+
const errorReferences = errorBinding !== null && errorBinding.references.length > 32 ? new Set(errorBinding.references.map((reference) => reference.identifier)) : void 0;
|
|
11072
11073
|
const assertedError = returnBlock.body.some((statement) => {
|
|
11073
11074
|
if (statement.range[1] > node.range[0] || statement.type !== AST_NODE_TYPES55.ExpressionStatement) return false;
|
|
11074
11075
|
const expression = statement.expression;
|
|
@@ -11079,7 +11080,7 @@ var no_bare_return_from_test_catch_default = createRule({
|
|
|
11079
11080
|
let operand = expression.callee.type === AST_NODE_TYPES55.MemberExpression ? expression.callee.object : null;
|
|
11080
11081
|
if (operand?.type === AST_NODE_TYPES55.MemberExpression && staticMemberName3(operand) === "not") operand = operand.object;
|
|
11081
11082
|
if (assertionName !== "assert" && (assertionName !== "expect" || operand?.type !== AST_NODE_TYPES55.CallExpression || operand.callee !== root)) return false;
|
|
11082
|
-
return walkOwnScope(expression, (current) => current.type === AST_NODE_TYPES55.Identifier && errorBinding?.references.some((reference) => reference.identifier === current) === true);
|
|
11083
|
+
return walkOwnScope(expression, (current) => current.type === AST_NODE_TYPES55.Identifier && (errorReferences?.has(current) ?? errorBinding?.references.some((reference) => reference.identifier === current)) === true);
|
|
11083
11084
|
});
|
|
11084
11085
|
if (assertedError) return;
|
|
11085
11086
|
}
|
|
@@ -17316,6 +17317,15 @@ var test_loops_over_literal_cases_default = createRule({
|
|
|
17316
17317
|
if (!isTestFile(context)) {
|
|
17317
17318
|
return {};
|
|
17318
17319
|
}
|
|
17320
|
+
const referenceIdentifiers = /* @__PURE__ */ new WeakMap();
|
|
17321
|
+
const isReference = (variable, identifier) => {
|
|
17322
|
+
let identifiers = referenceIdentifiers.get(variable);
|
|
17323
|
+
if (identifiers === void 0) {
|
|
17324
|
+
identifiers = new Set(variable.references.map((reference) => reference.identifier));
|
|
17325
|
+
referenceIdentifiers.set(variable, identifiers);
|
|
17326
|
+
}
|
|
17327
|
+
return identifiers.has(identifier);
|
|
17328
|
+
};
|
|
17319
17329
|
const isFrameworkTest = (identifier) => TEST_CALLERS3.has(runtimeTestFrameworkName(context.sourceCode, identifier, "test") ?? "");
|
|
17320
17330
|
const isFrameworkAssertion = (identifier) => ASSERTION_ROOTS.has(runtimeTestFrameworkName(context.sourceCode, identifier, "assertion") ?? "");
|
|
17321
17331
|
return {
|
|
@@ -17339,7 +17349,7 @@ var test_loops_over_literal_cases_default = createRule({
|
|
|
17339
17349
|
const capturesSetup = walkOwnScope2(node.body, (current) => {
|
|
17340
17350
|
if (current.type !== AST_NODE_TYPES82.Identifier) return false;
|
|
17341
17351
|
const variable = ASTUtils50.findVariable(context.sourceCode.getScope(current), current.name);
|
|
17342
|
-
if (variable === null || !variable
|
|
17352
|
+
if (variable === null || !isReference(variable, current)) return false;
|
|
17343
17353
|
return variable.defs.some((definition) => {
|
|
17344
17354
|
const declaration = definition.name;
|
|
17345
17355
|
return declaration.range[0] >= enclosing.range[0] && declaration.range[1] <= enclosing.range[1] && (declaration.range[0] < node.range[0] || declaration.range[1] > node.range[1]);
|
|
@@ -27556,6 +27566,14 @@ function createSourceCoupledRule(name, documentation, sourceSuffixRe) {
|
|
|
27556
27566
|
defaultOptions: [],
|
|
27557
27567
|
create(context) {
|
|
27558
27568
|
if (!isTestFile(context) || isGeneratedFile(context, context.sourceCode.text)) return {};
|
|
27569
|
+
const referenceStability = /* @__PURE__ */ new WeakMap();
|
|
27570
|
+
const referenceStable = (variable) => {
|
|
27571
|
+
const cached = referenceStability.get(variable);
|
|
27572
|
+
if (cached !== void 0) return cached;
|
|
27573
|
+
const stable = !variable.references.some((reference) => reference.isWrite() && reference.init !== true);
|
|
27574
|
+
referenceStability.set(variable, stable);
|
|
27575
|
+
return stable;
|
|
27576
|
+
};
|
|
27559
27577
|
const scopes = [newScope()];
|
|
27560
27578
|
const reportedOrigins = /* @__PURE__ */ new Set();
|
|
27561
27579
|
const currentScope = () => scopes.at(-1) ?? scopes[0];
|
|
@@ -27573,7 +27591,7 @@ function createSourceCoupledRule(name, documentation, sourceSuffixRe) {
|
|
|
27573
27591
|
};
|
|
27574
27592
|
const visible = (kind, node) => {
|
|
27575
27593
|
const name2 = bindingOf(node);
|
|
27576
|
-
if (name2 === null || name2
|
|
27594
|
+
if (name2 === null || !referenceStable(name2)) return false;
|
|
27577
27595
|
for (let index = scopes.length - 1; index >= 0; index--) {
|
|
27578
27596
|
const scope = scopes[index];
|
|
27579
27597
|
if (scope.declared.has(name2)) return scope[kind].has(name2);
|
|
@@ -27582,7 +27600,7 @@ function createSourceCoupledRule(name, documentation, sourceSuffixRe) {
|
|
|
27582
27600
|
};
|
|
27583
27601
|
const visibleRawOrigins = (node) => {
|
|
27584
27602
|
const name2 = bindingOf(node);
|
|
27585
|
-
if (name2 === null || name2
|
|
27603
|
+
if (name2 === null || !referenceStable(name2)) return /* @__PURE__ */ new Set();
|
|
27586
27604
|
for (let index = scopes.length - 1; index >= 0; index--) {
|
|
27587
27605
|
const scope = scopes[index];
|
|
27588
27606
|
if (scope.declared.has(name2)) return scope.rawOrigins.get(name2) ?? /* @__PURE__ */ new Set();
|
|
@@ -27614,7 +27632,7 @@ function createSourceCoupledRule(name, documentation, sourceSuffixRe) {
|
|
|
27614
27632
|
};
|
|
27615
27633
|
const nativeImportedName = (node, modules) => {
|
|
27616
27634
|
const binding = bindingOf(node);
|
|
27617
|
-
if (binding === null || binding
|
|
27635
|
+
if (binding === null || !referenceStable(binding)) return null;
|
|
27618
27636
|
for (const definition of binding.defs) {
|
|
27619
27637
|
const imported = definition.node;
|
|
27620
27638
|
if (imported.type === AST_NODE_TYPES123.ImportSpecifier && imported.imported.type === AST_NODE_TYPES123.Identifier && imported.parent.type === AST_NODE_TYPES123.ImportDeclaration && modules.has(String(imported.parent.source.value))) {
|
|
@@ -27625,7 +27643,7 @@ function createSourceCoupledRule(name, documentation, sourceSuffixRe) {
|
|
|
27625
27643
|
};
|
|
27626
27644
|
const stableInitializer = (node) => {
|
|
27627
27645
|
const binding = bindingOf(node);
|
|
27628
|
-
if (binding === null || binding
|
|
27646
|
+
if (binding === null || !referenceStable(binding) || binding.defs.length !== 1) return null;
|
|
27629
27647
|
const definition = binding.defs[0]?.node;
|
|
27630
27648
|
return definition?.type === AST_NODE_TYPES123.VariableDeclarator ? definition.init : null;
|
|
27631
27649
|
};
|