@sarj/eslint-plugin 15.26.2 → 15.26.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -652,6 +652,25 @@ var no_broad_return_type_default = createRule({
652
652
  // src/rules/no-reduce-accumulator-copy.ts
653
653
  var import_utils5 = require("@typescript-eslint/utils");
654
654
  var import_typescript3 = __toESM(require("typescript"), 1);
655
+
656
+ // src/rules/_for-each-ast-child.ts
657
+ function forEachAstChild(node, visitorKeys, visit) {
658
+ for (const key of visitorKeys[node.type] ?? []) {
659
+ const value = node[key];
660
+ if (Array.isArray(value)) {
661
+ const children = value;
662
+ for (const child of children) if (isNode(child) && visit(child) === true) return true;
663
+ } else if (isNode(value)) {
664
+ if (visit(value) === true) return true;
665
+ }
666
+ }
667
+ return false;
668
+ }
669
+ function isNode(value) {
670
+ return typeof value === "object" && value !== null && "type" in value && typeof value.type === "string";
671
+ }
672
+
673
+ // src/rules/no-reduce-accumulator-copy.ts
655
674
  var NO_REDUCE_ACCUMULATOR_COPY_DOCUMENTATION = {
656
675
  summary: "Review copies of the accumulated collection inside a built-in reduce callback.",
657
676
  rationale: "Copying a growing accumulator at every step can make collection quadratic instead of linear in its output size.",
@@ -722,12 +741,7 @@ var no_reduce_accumulator_copy_default = createRule({
722
741
  context.report({ node: current, messageId: "copy" });
723
742
  }
724
743
  if (current.type === import_utils5.AST_NODE_TYPES.CallExpression) inspectCall(current);
725
- for (const key of context.sourceCode.visitorKeys[current.type] ?? []) {
726
- const child = current[key];
727
- if (Array.isArray(child)) {
728
- for (const item of child) if (item !== null && typeof item === "object" && "type" in item) inspect(item);
729
- } else if (child !== null && typeof child === "object" && "type" in child) inspect(child);
730
- }
744
+ forEachAstChild(current, context.sourceCode.visitorKeys, inspect);
731
745
  };
732
746
  inspect(callback.body);
733
747
  }
@@ -3546,17 +3560,17 @@ function subtreeContainsStarLiteral(node) {
3546
3560
  const value = node[key];
3547
3561
  if (Array.isArray(value)) {
3548
3562
  for (const child of value) {
3549
- if (isNode(child) && subtreeContainsStarLiteral(child)) {
3563
+ if (isNode2(child) && subtreeContainsStarLiteral(child)) {
3550
3564
  return true;
3551
3565
  }
3552
3566
  }
3553
- } else if (isNode(value) && subtreeContainsStarLiteral(value)) {
3567
+ } else if (isNode2(value) && subtreeContainsStarLiteral(value)) {
3554
3568
  return true;
3555
3569
  }
3556
3570
  }
3557
3571
  return false;
3558
3572
  }
3559
- function isNode(value) {
3573
+ function isNode2(value) {
3560
3574
  return typeof value === "object" && value !== null && typeof value.type === "string";
3561
3575
  }
3562
3576
  function calleeName(node) {
@@ -4570,15 +4584,7 @@ function functionComplexity(fn, visitorKeys) {
4570
4584
  visitChildren(node, nesting);
4571
4585
  }
4572
4586
  function visitChildren(node, nesting) {
4573
- for (const key of visitorKeys[node.type] ?? []) {
4574
- const value = node[key];
4575
- const candidates = Array.isArray(value) ? value : [value];
4576
- for (const candidate2 of candidates) {
4577
- if (typeof candidate2 === "object" && candidate2 !== null && "type" in candidate2) {
4578
- visit(candidate2, nesting);
4579
- }
4580
- }
4581
- }
4587
+ forEachAstChild(node, visitorKeys, (child) => visit(child, nesting));
4582
4588
  }
4583
4589
  visit(fn.body, 0);
4584
4590
  return points;
@@ -4747,7 +4753,7 @@ var PURE_CONSTRUCTORS = /* @__PURE__ */ new Set([
4747
4753
  "Response",
4748
4754
  "AbortController"
4749
4755
  ]);
4750
- function isNode2(value) {
4756
+ function isNode3(value) {
4751
4757
  return typeof value === "object" && value !== null && typeof value.type === "string";
4752
4758
  }
4753
4759
  function isPureCall(node) {
@@ -4797,11 +4803,11 @@ function subtreeMatches(stmt, predicate, descendIntoFunctions = false) {
4797
4803
  const value = current[key];
4798
4804
  if (Array.isArray(value)) {
4799
4805
  for (const child of value) {
4800
- if (isNode2(child)) {
4806
+ if (isNode3(child)) {
4801
4807
  visit(child);
4802
4808
  }
4803
4809
  }
4804
- } else if (isNode2(value)) {
4810
+ } else if (isNode3(value)) {
4805
4811
  visit(value);
4806
4812
  }
4807
4813
  if (found) {
@@ -9960,7 +9966,7 @@ function isSentinelArgument(arg) {
9960
9966
  function isFunctionNode(node) {
9961
9967
  return node.type === import_utils61.AST_NODE_TYPES.FunctionDeclaration || node.type === import_utils61.AST_NODE_TYPES.FunctionExpression || node.type === import_utils61.AST_NODE_TYPES.ArrowFunctionExpression;
9962
9968
  }
9963
- function isNode3(value) {
9969
+ function isNode4(value) {
9964
9970
  return typeof value === "object" && value !== null && typeof value.type === "string";
9965
9971
  }
9966
9972
  function walkWithinScope(node, visit) {
@@ -9983,11 +9989,11 @@ function walkWithinScope(node, visit) {
9983
9989
  const value = current[key];
9984
9990
  if (Array.isArray(value)) {
9985
9991
  for (const child of value) {
9986
- if (isNode3(child)) {
9992
+ if (isNode4(child)) {
9987
9993
  recurse(child);
9988
9994
  }
9989
9995
  }
9990
- } else if (isNode3(value)) {
9996
+ } else if (isNode4(value)) {
9991
9997
  recurse(value);
9992
9998
  }
9993
9999
  }
@@ -10045,11 +10051,11 @@ function subtreeReadsName(node, name) {
10045
10051
  const value = current[key];
10046
10052
  if (Array.isArray(value)) {
10047
10053
  for (const child of value) {
10048
- if (isNode3(child)) {
10054
+ if (isNode4(child)) {
10049
10055
  recurse(child);
10050
10056
  }
10051
10057
  }
10052
- } else if (isNode3(value)) {
10058
+ } else if (isNode4(value)) {
10053
10059
  recurse(value);
10054
10060
  }
10055
10061
  }
@@ -10110,7 +10116,7 @@ function enclosingFunctionName(node) {
10110
10116
  let current = node.parent;
10111
10117
  while (current !== void 0 && current !== null) {
10112
10118
  if (isFunctionNode(current)) {
10113
- if ("id" in current && isNode3(current.id) && current.id.type === import_utils61.AST_NODE_TYPES.Identifier) {
10119
+ if ("id" in current && isNode4(current.id) && current.id.type === import_utils61.AST_NODE_TYPES.Identifier) {
10114
10120
  return current.id.name;
10115
10121
  }
10116
10122
  const parent = current.parent;
@@ -10176,7 +10182,7 @@ function tryReturnsSafeParse(catchNode) {
10176
10182
  const value = current[key];
10177
10183
  const children = Array.isArray(value) ? value : [value];
10178
10184
  for (const child of children) {
10179
- if (isNode3(child)) recurse(child);
10185
+ if (isNode4(child)) recurse(child);
10180
10186
  }
10181
10187
  }
10182
10188
  }
@@ -10215,7 +10221,7 @@ function functionReturnsSameSentinelKindElsewhere(catchNode, kind) {
10215
10221
  function enclosingFunctionBody(node) {
10216
10222
  let current = node.parent;
10217
10223
  while (current !== void 0 && current !== null) {
10218
- if (isFunctionNode(current) && "body" in current && isNode3(current.body) && current.body.type === import_utils61.AST_NODE_TYPES.BlockStatement) {
10224
+ if (isFunctionNode(current) && "body" in current && isNode4(current.body) && current.body.type === import_utils61.AST_NODE_TYPES.BlockStatement) {
10219
10225
  return current.body;
10220
10226
  }
10221
10227
  current = current.parent;
@@ -16315,13 +16321,7 @@ function isEmptyGuard(node, access) {
16315
16321
  }
16316
16322
  function contains(node, visitorKeys, predicate) {
16317
16323
  if (predicate(node)) return true;
16318
- for (const key of visitorKeys[node.type] ?? []) {
16319
- const child = node[key];
16320
- for (const value of Array.isArray(child) ? child : [child]) {
16321
- if (value !== null && typeof value === "object" && "type" in value && contains(value, visitorKeys, predicate)) return true;
16322
- }
16323
- }
16324
- return false;
16324
+ return forEachAstChild(node, visitorKeys, (child) => contains(child, visitorKeys, predicate));
16325
16325
  }
16326
16326
  function belongsToFunction(node, fn) {
16327
16327
  let current = node;
@@ -22085,14 +22085,7 @@ function referencedPropertyName(node) {
22085
22085
  function walk(node, visitorKeys, visit, nestedFunction = false) {
22086
22086
  visit(node, nestedFunction);
22087
22087
  const nested = nestedFunction || isFunction(node);
22088
- for (const key of visitorKeys[node.type] ?? []) {
22089
- const child = node[key];
22090
- if (Array.isArray(child)) {
22091
- for (const item of child) if (typeof item === "object" && item !== null && "type" in item) walk(item, visitorKeys, visit, nested);
22092
- } else if (typeof child === "object" && child !== null && "type" in child) {
22093
- walk(child, visitorKeys, visit, nested);
22094
- }
22095
- }
22088
+ forEachAstChild(node, visitorKeys, (child) => walk(child, visitorKeys, visit, nested));
22096
22089
  }
22097
22090
  function classScope(context, node, computedReferenceNames) {
22098
22091
  const methods = node.body.body.filter(
@@ -23285,7 +23278,7 @@ var RULES = {
23285
23278
  };
23286
23279
  var meta = {
23287
23280
  name: "@sarj/eslint-plugin",
23288
- version: "15.26.2"
23281
+ version: "15.26.3"
23289
23282
  };
23290
23283
  var APPLICATION_ONLY_RULES = [];
23291
23284
  var LIBRARY_IMPORT_POLICY = ["error", {
package/dist/index.d.cts CHANGED
@@ -996,7 +996,7 @@ type FlatPreset = {
996
996
  declare const PLUGIN: {
997
997
  readonly meta: {
998
998
  readonly name: "@sarj/eslint-plugin";
999
- readonly version: "15.26.2";
999
+ readonly version: "15.26.3";
1000
1000
  };
1001
1001
  readonly rules: {
1002
1002
  readonly "no-conditional-empty-object-spread": DocumentedRule<[], "avoid">;
package/dist/index.d.ts CHANGED
@@ -996,7 +996,7 @@ type FlatPreset = {
996
996
  declare const PLUGIN: {
997
997
  readonly meta: {
998
998
  readonly name: "@sarj/eslint-plugin";
999
- readonly version: "15.26.2";
999
+ readonly version: "15.26.3";
1000
1000
  };
1001
1001
  readonly rules: {
1002
1002
  readonly "no-conditional-empty-object-spread": DocumentedRule<[], "avoid">;
package/dist/index.js CHANGED
@@ -608,6 +608,25 @@ var no_broad_return_type_default = createRule({
608
608
  // src/rules/no-reduce-accumulator-copy.ts
609
609
  import { AST_NODE_TYPES as AST_NODE_TYPES4, ASTUtils as ASTUtils2, ESLintUtils as ESLintUtils4 } from "@typescript-eslint/utils";
610
610
  import ts3 from "typescript";
611
+
612
+ // src/rules/_for-each-ast-child.ts
613
+ function forEachAstChild(node, visitorKeys, visit) {
614
+ for (const key of visitorKeys[node.type] ?? []) {
615
+ const value = node[key];
616
+ if (Array.isArray(value)) {
617
+ const children = value;
618
+ for (const child of children) if (isNode(child) && visit(child) === true) return true;
619
+ } else if (isNode(value)) {
620
+ if (visit(value) === true) return true;
621
+ }
622
+ }
623
+ return false;
624
+ }
625
+ function isNode(value) {
626
+ return typeof value === "object" && value !== null && "type" in value && typeof value.type === "string";
627
+ }
628
+
629
+ // src/rules/no-reduce-accumulator-copy.ts
611
630
  var NO_REDUCE_ACCUMULATOR_COPY_DOCUMENTATION = {
612
631
  summary: "Review copies of the accumulated collection inside a built-in reduce callback.",
613
632
  rationale: "Copying a growing accumulator at every step can make collection quadratic instead of linear in its output size.",
@@ -678,12 +697,7 @@ var no_reduce_accumulator_copy_default = createRule({
678
697
  context.report({ node: current, messageId: "copy" });
679
698
  }
680
699
  if (current.type === AST_NODE_TYPES4.CallExpression) inspectCall(current);
681
- for (const key of context.sourceCode.visitorKeys[current.type] ?? []) {
682
- const child = current[key];
683
- if (Array.isArray(child)) {
684
- for (const item of child) if (item !== null && typeof item === "object" && "type" in item) inspect(item);
685
- } else if (child !== null && typeof child === "object" && "type" in child) inspect(child);
686
- }
700
+ forEachAstChild(current, context.sourceCode.visitorKeys, inspect);
687
701
  };
688
702
  inspect(callback.body);
689
703
  }
@@ -3510,17 +3524,17 @@ function subtreeContainsStarLiteral(node) {
3510
3524
  const value = node[key];
3511
3525
  if (Array.isArray(value)) {
3512
3526
  for (const child of value) {
3513
- if (isNode(child) && subtreeContainsStarLiteral(child)) {
3527
+ if (isNode2(child) && subtreeContainsStarLiteral(child)) {
3514
3528
  return true;
3515
3529
  }
3516
3530
  }
3517
- } else if (isNode(value) && subtreeContainsStarLiteral(value)) {
3531
+ } else if (isNode2(value) && subtreeContainsStarLiteral(value)) {
3518
3532
  return true;
3519
3533
  }
3520
3534
  }
3521
3535
  return false;
3522
3536
  }
3523
- function isNode(value) {
3537
+ function isNode2(value) {
3524
3538
  return typeof value === "object" && value !== null && typeof value.type === "string";
3525
3539
  }
3526
3540
  function calleeName(node) {
@@ -4534,15 +4548,7 @@ function functionComplexity(fn, visitorKeys) {
4534
4548
  visitChildren(node, nesting);
4535
4549
  }
4536
4550
  function visitChildren(node, nesting) {
4537
- for (const key of visitorKeys[node.type] ?? []) {
4538
- const value = node[key];
4539
- const candidates = Array.isArray(value) ? value : [value];
4540
- for (const candidate2 of candidates) {
4541
- if (typeof candidate2 === "object" && candidate2 !== null && "type" in candidate2) {
4542
- visit(candidate2, nesting);
4543
- }
4544
- }
4545
- }
4551
+ forEachAstChild(node, visitorKeys, (child) => visit(child, nesting));
4546
4552
  }
4547
4553
  visit(fn.body, 0);
4548
4554
  return points;
@@ -4711,7 +4717,7 @@ var PURE_CONSTRUCTORS = /* @__PURE__ */ new Set([
4711
4717
  "Response",
4712
4718
  "AbortController"
4713
4719
  ]);
4714
- function isNode2(value) {
4720
+ function isNode3(value) {
4715
4721
  return typeof value === "object" && value !== null && typeof value.type === "string";
4716
4722
  }
4717
4723
  function isPureCall(node) {
@@ -4761,11 +4767,11 @@ function subtreeMatches(stmt, predicate, descendIntoFunctions = false) {
4761
4767
  const value = current[key];
4762
4768
  if (Array.isArray(value)) {
4763
4769
  for (const child of value) {
4764
- if (isNode2(child)) {
4770
+ if (isNode3(child)) {
4765
4771
  visit(child);
4766
4772
  }
4767
4773
  }
4768
- } else if (isNode2(value)) {
4774
+ } else if (isNode3(value)) {
4769
4775
  visit(value);
4770
4776
  }
4771
4777
  if (found) {
@@ -9942,7 +9948,7 @@ function isSentinelArgument(arg) {
9942
9948
  function isFunctionNode(node) {
9943
9949
  return node.type === AST_NODE_TYPES48.FunctionDeclaration || node.type === AST_NODE_TYPES48.FunctionExpression || node.type === AST_NODE_TYPES48.ArrowFunctionExpression;
9944
9950
  }
9945
- function isNode3(value) {
9951
+ function isNode4(value) {
9946
9952
  return typeof value === "object" && value !== null && typeof value.type === "string";
9947
9953
  }
9948
9954
  function walkWithinScope(node, visit) {
@@ -9965,11 +9971,11 @@ function walkWithinScope(node, visit) {
9965
9971
  const value = current[key];
9966
9972
  if (Array.isArray(value)) {
9967
9973
  for (const child of value) {
9968
- if (isNode3(child)) {
9974
+ if (isNode4(child)) {
9969
9975
  recurse(child);
9970
9976
  }
9971
9977
  }
9972
- } else if (isNode3(value)) {
9978
+ } else if (isNode4(value)) {
9973
9979
  recurse(value);
9974
9980
  }
9975
9981
  }
@@ -10027,11 +10033,11 @@ function subtreeReadsName(node, name) {
10027
10033
  const value = current[key];
10028
10034
  if (Array.isArray(value)) {
10029
10035
  for (const child of value) {
10030
- if (isNode3(child)) {
10036
+ if (isNode4(child)) {
10031
10037
  recurse(child);
10032
10038
  }
10033
10039
  }
10034
- } else if (isNode3(value)) {
10040
+ } else if (isNode4(value)) {
10035
10041
  recurse(value);
10036
10042
  }
10037
10043
  }
@@ -10092,7 +10098,7 @@ function enclosingFunctionName(node) {
10092
10098
  let current = node.parent;
10093
10099
  while (current !== void 0 && current !== null) {
10094
10100
  if (isFunctionNode(current)) {
10095
- if ("id" in current && isNode3(current.id) && current.id.type === AST_NODE_TYPES48.Identifier) {
10101
+ if ("id" in current && isNode4(current.id) && current.id.type === AST_NODE_TYPES48.Identifier) {
10096
10102
  return current.id.name;
10097
10103
  }
10098
10104
  const parent = current.parent;
@@ -10158,7 +10164,7 @@ function tryReturnsSafeParse(catchNode) {
10158
10164
  const value = current[key];
10159
10165
  const children = Array.isArray(value) ? value : [value];
10160
10166
  for (const child of children) {
10161
- if (isNode3(child)) recurse(child);
10167
+ if (isNode4(child)) recurse(child);
10162
10168
  }
10163
10169
  }
10164
10170
  }
@@ -10197,7 +10203,7 @@ function functionReturnsSameSentinelKindElsewhere(catchNode, kind) {
10197
10203
  function enclosingFunctionBody(node) {
10198
10204
  let current = node.parent;
10199
10205
  while (current !== void 0 && current !== null) {
10200
- if (isFunctionNode(current) && "body" in current && isNode3(current.body) && current.body.type === AST_NODE_TYPES48.BlockStatement) {
10206
+ if (isFunctionNode(current) && "body" in current && isNode4(current.body) && current.body.type === AST_NODE_TYPES48.BlockStatement) {
10201
10207
  return current.body;
10202
10208
  }
10203
10209
  current = current.parent;
@@ -16316,13 +16322,7 @@ function isEmptyGuard(node, access) {
16316
16322
  }
16317
16323
  function contains(node, visitorKeys, predicate) {
16318
16324
  if (predicate(node)) return true;
16319
- for (const key of visitorKeys[node.type] ?? []) {
16320
- const child = node[key];
16321
- for (const value of Array.isArray(child) ? child : [child]) {
16322
- if (value !== null && typeof value === "object" && "type" in value && contains(value, visitorKeys, predicate)) return true;
16323
- }
16324
- }
16325
- return false;
16325
+ return forEachAstChild(node, visitorKeys, (child) => contains(child, visitorKeys, predicate));
16326
16326
  }
16327
16327
  function belongsToFunction(node, fn) {
16328
16328
  let current = node;
@@ -22103,14 +22103,7 @@ function referencedPropertyName(node) {
22103
22103
  function walk(node, visitorKeys, visit, nestedFunction = false) {
22104
22104
  visit(node, nestedFunction);
22105
22105
  const nested = nestedFunction || isFunction(node);
22106
- for (const key of visitorKeys[node.type] ?? []) {
22107
- const child = node[key];
22108
- if (Array.isArray(child)) {
22109
- for (const item of child) if (typeof item === "object" && item !== null && "type" in item) walk(item, visitorKeys, visit, nested);
22110
- } else if (typeof child === "object" && child !== null && "type" in child) {
22111
- walk(child, visitorKeys, visit, nested);
22112
- }
22113
- }
22106
+ forEachAstChild(node, visitorKeys, (child) => walk(child, visitorKeys, visit, nested));
22114
22107
  }
22115
22108
  function classScope(context, node, computedReferenceNames) {
22116
22109
  const methods = node.body.body.filter(
@@ -23306,7 +23299,7 @@ var RULES = {
23306
23299
  };
23307
23300
  var meta = {
23308
23301
  name: "@sarj/eslint-plugin",
23309
- version: "15.26.2"
23302
+ version: "15.26.3"
23310
23303
  };
23311
23304
  var APPLICATION_ONLY_RULES = [];
23312
23305
  var LIBRARY_IMPORT_POLICY = ["error", {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sarj/eslint-plugin",
3
- "version": "15.26.2",
3
+ "version": "15.26.3",
4
4
  "packageManager": "npm@12.0.2",
5
5
  "description": "Custom ESLint rules for hypermodern TypeScript / React / Next.js projects",
6
6
  "type": "module",