@sarj/eslint-plugin 15.26.3 → 15.26.4

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
@@ -656,13 +656,17 @@ var import_typescript3 = __toESM(require("typescript"), 1);
656
656
  // src/rules/_for-each-ast-child.ts
657
657
  function forEachAstChild(node, visitorKeys, visit) {
658
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
- }
659
+ if (forEachAstChildKey(node, key, visit)) return true;
660
+ }
661
+ return false;
662
+ }
663
+ function forEachAstChildKey(node, key, visit) {
664
+ const value = node[key];
665
+ if (Array.isArray(value)) {
666
+ const children = value;
667
+ for (const child of children) if (isNode(child) && visit(child) === true) return true;
668
+ } else if (isNode(value)) {
669
+ if (visit(value) === true) return true;
666
670
  }
667
671
  return false;
668
672
  }
@@ -3987,6 +3991,17 @@ var import_utils27 = require("@typescript-eslint/utils");
3987
3991
 
3988
3992
  // src/rules/_sql.ts
3989
3993
  var import_utils26 = require("@typescript-eslint/utils");
3994
+
3995
+ // src/rules/_for-each-own-ast-child.ts
3996
+ function forEachOwnAstChild(node, visit, includeKey = () => true) {
3997
+ for (const key of Object.keys(node)) {
3998
+ if (key === "parent" || !includeKey(key)) continue;
3999
+ if (forEachAstChildKey(node, key, visit)) return true;
4000
+ }
4001
+ return false;
4002
+ }
4003
+
4004
+ // src/rules/_sql.ts
3990
4005
  function stripSqlNoise(text) {
3991
4006
  return scanSqlNoise(text);
3992
4007
  }
@@ -4118,17 +4133,7 @@ function isJoinedFragmentArray(node) {
4118
4133
  }
4119
4134
  function markConsumed(node, consumed) {
4120
4135
  consumed.add(node);
4121
- for (const key of Object.keys(node)) {
4122
- if (key === "parent") {
4123
- continue;
4124
- }
4125
- const value = node[key];
4126
- for (const child of Array.isArray(value) ? value : [value]) {
4127
- if (child !== null && typeof child === "object" && "type" in child) {
4128
- markConsumed(child, consumed);
4129
- }
4130
- }
4131
- }
4136
+ forEachOwnAstChild(node, (child) => markConsumed(child, consumed));
4132
4137
  }
4133
4138
  function createSqlListener(handler) {
4134
4139
  const consumed = /* @__PURE__ */ new WeakSet();
@@ -4753,9 +4758,6 @@ var PURE_CONSTRUCTORS = /* @__PURE__ */ new Set([
4753
4758
  "Response",
4754
4759
  "AbortController"
4755
4760
  ]);
4756
- function isNode3(value) {
4757
- return typeof value === "object" && value !== null && typeof value.type === "string";
4758
- }
4759
4761
  function isPureCall(node) {
4760
4762
  const callee = node.callee;
4761
4763
  if (callee.type !== import_utils30.AST_NODE_TYPES.MemberExpression) {
@@ -4793,27 +4795,7 @@ function subtreeMatches(stmt, predicate, descendIntoFunctions = false) {
4793
4795
  found = true;
4794
4796
  return;
4795
4797
  }
4796
- for (const key of Object.keys(current)) {
4797
- if (key === "parent") {
4798
- continue;
4799
- }
4800
- if (!descendIntoFunctions && NESTED_FUNCTION_TYPES.has(current.type) && key === "body") {
4801
- continue;
4802
- }
4803
- const value = current[key];
4804
- if (Array.isArray(value)) {
4805
- for (const child of value) {
4806
- if (isNode3(child)) {
4807
- visit(child);
4808
- }
4809
- }
4810
- } else if (isNode3(value)) {
4811
- visit(value);
4812
- }
4813
- if (found) {
4814
- return;
4815
- }
4816
- }
4798
+ forEachOwnAstChild(current, visit, (key) => descendIntoFunctions || !NESTED_FUNCTION_TYPES.has(current.type) || key !== "body");
4817
4799
  };
4818
4800
  visit(stmt);
4819
4801
  return found;
@@ -7169,17 +7151,7 @@ function nearestFunction(node) {
7169
7151
  }
7170
7152
  function walkOwnScope(node, predicate) {
7171
7153
  if (predicate(node)) return true;
7172
- for (const key of Object.keys(node)) {
7173
- if (key === "parent") continue;
7174
- const value = node[key];
7175
- for (const child of Array.isArray(value) ? value : [value]) {
7176
- if (typeof child === "object" && child !== null && typeof child.type === "string") {
7177
- const childNode = child;
7178
- if (!FUNCTION_TYPES3.has(childNode.type) && walkOwnScope(childNode, predicate)) return true;
7179
- }
7180
- }
7181
- }
7182
- return false;
7154
+ return forEachOwnAstChild(node, (child) => !FUNCTION_TYPES3.has(child.type) && walkOwnScope(child, predicate));
7183
7155
  }
7184
7156
  function isAssertion(node, context) {
7185
7157
  if (node.type !== import_utils44.AST_NODE_TYPES.CallExpression) return false;
@@ -9966,7 +9938,7 @@ function isSentinelArgument(arg) {
9966
9938
  function isFunctionNode(node) {
9967
9939
  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;
9968
9940
  }
9969
- function isNode4(value) {
9941
+ function isNode3(value) {
9970
9942
  return typeof value === "object" && value !== null && typeof value.type === "string";
9971
9943
  }
9972
9944
  function walkWithinScope(node, visit) {
@@ -9982,21 +9954,10 @@ function walkWithinScope(node, visit) {
9982
9954
  if (isFunctionNode(current)) {
9983
9955
  return;
9984
9956
  }
9985
- for (const key of Object.keys(current)) {
9986
- if (key === "parent") {
9987
- continue;
9988
- }
9989
- const value = current[key];
9990
- if (Array.isArray(value)) {
9991
- for (const child of value) {
9992
- if (isNode4(child)) {
9993
- recurse(child);
9994
- }
9995
- }
9996
- } else if (isNode4(value)) {
9997
- recurse(value);
9998
- }
9999
- }
9957
+ forEachOwnAstChild(current, (child) => {
9958
+ recurse(child);
9959
+ return found;
9960
+ });
10000
9961
  };
10001
9962
  recurse(node);
10002
9963
  return found;
@@ -10043,22 +10004,10 @@ function subtreeReadsName(node, name) {
10043
10004
  if (shadowsName(current)) {
10044
10005
  return;
10045
10006
  }
10046
- for (const key of Object.keys(current)) {
10047
- if (key === "parent") {
10048
- continue;
10049
- }
10050
- if (isNonReadingProperty(current, key)) continue;
10051
- const value = current[key];
10052
- if (Array.isArray(value)) {
10053
- for (const child of value) {
10054
- if (isNode4(child)) {
10055
- recurse(child);
10056
- }
10057
- }
10058
- } else if (isNode4(value)) {
10059
- recurse(value);
10060
- }
10061
- }
10007
+ forEachOwnAstChild(current, (child) => {
10008
+ recurse(child);
10009
+ return found;
10010
+ }, (key) => !isNonReadingProperty(current, key));
10062
10011
  };
10063
10012
  recurse(node);
10064
10013
  return found;
@@ -10116,7 +10065,7 @@ function enclosingFunctionName(node) {
10116
10065
  let current = node.parent;
10117
10066
  while (current !== void 0 && current !== null) {
10118
10067
  if (isFunctionNode(current)) {
10119
- if ("id" in current && isNode4(current.id) && current.id.type === import_utils61.AST_NODE_TYPES.Identifier) {
10068
+ if ("id" in current && isNode3(current.id) && current.id.type === import_utils61.AST_NODE_TYPES.Identifier) {
10120
10069
  return current.id.name;
10121
10070
  }
10122
10071
  const parent = current.parent;
@@ -10177,14 +10126,10 @@ function tryReturnsSafeParse(catchNode) {
10177
10126
  visitChildren(current);
10178
10127
  };
10179
10128
  function visitChildren(current) {
10180
- for (const key of Object.keys(current)) {
10181
- if (key === "parent") continue;
10182
- const value = current[key];
10183
- const children = Array.isArray(value) ? value : [value];
10184
- for (const child of children) {
10185
- if (isNode4(child)) recurse(child);
10186
- }
10187
- }
10129
+ forEachOwnAstChild(current, (child) => {
10130
+ recurse(child);
10131
+ return sawUnsafeOperation;
10132
+ });
10188
10133
  }
10189
10134
  recurse(tryBlock);
10190
10135
  return sawSafeParse && !sawUnsafeOperation;
@@ -10221,7 +10166,7 @@ function functionReturnsSameSentinelKindElsewhere(catchNode, kind) {
10221
10166
  function enclosingFunctionBody(node) {
10222
10167
  let current = node.parent;
10223
10168
  while (current !== void 0 && current !== null) {
10224
- if (isFunctionNode(current) && "body" in current && isNode4(current.body) && current.body.type === import_utils61.AST_NODE_TYPES.BlockStatement) {
10169
+ if (isFunctionNode(current) && "body" in current && isNode3(current.body) && current.body.type === import_utils61.AST_NODE_TYPES.BlockStatement) {
10225
10170
  return current.body;
10226
10171
  }
10227
10172
  current = current.parent;
@@ -23278,7 +23223,7 @@ var RULES = {
23278
23223
  };
23279
23224
  var meta = {
23280
23225
  name: "@sarj/eslint-plugin",
23281
- version: "15.26.3"
23226
+ version: "15.26.4"
23282
23227
  };
23283
23228
  var APPLICATION_ONLY_RULES = [];
23284
23229
  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.3";
999
+ readonly version: "15.26.4";
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.3";
999
+ readonly version: "15.26.4";
1000
1000
  };
1001
1001
  readonly rules: {
1002
1002
  readonly "no-conditional-empty-object-spread": DocumentedRule<[], "avoid">;
package/dist/index.js CHANGED
@@ -612,13 +612,17 @@ import ts3 from "typescript";
612
612
  // src/rules/_for-each-ast-child.ts
613
613
  function forEachAstChild(node, visitorKeys, visit) {
614
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
- }
615
+ if (forEachAstChildKey(node, key, visit)) return true;
616
+ }
617
+ return false;
618
+ }
619
+ function forEachAstChildKey(node, key, visit) {
620
+ const value = node[key];
621
+ if (Array.isArray(value)) {
622
+ const children = value;
623
+ for (const child of children) if (isNode(child) && visit(child) === true) return true;
624
+ } else if (isNode(value)) {
625
+ if (visit(value) === true) return true;
622
626
  }
623
627
  return false;
624
628
  }
@@ -3951,6 +3955,17 @@ import { AST_NODE_TYPES as AST_NODE_TYPES25 } from "@typescript-eslint/utils";
3951
3955
 
3952
3956
  // src/rules/_sql.ts
3953
3957
  import { AST_NODE_TYPES as AST_NODE_TYPES24 } from "@typescript-eslint/utils";
3958
+
3959
+ // src/rules/_for-each-own-ast-child.ts
3960
+ function forEachOwnAstChild(node, visit, includeKey = () => true) {
3961
+ for (const key of Object.keys(node)) {
3962
+ if (key === "parent" || !includeKey(key)) continue;
3963
+ if (forEachAstChildKey(node, key, visit)) return true;
3964
+ }
3965
+ return false;
3966
+ }
3967
+
3968
+ // src/rules/_sql.ts
3954
3969
  function stripSqlNoise(text) {
3955
3970
  return scanSqlNoise(text);
3956
3971
  }
@@ -4082,17 +4097,7 @@ function isJoinedFragmentArray(node) {
4082
4097
  }
4083
4098
  function markConsumed(node, consumed) {
4084
4099
  consumed.add(node);
4085
- for (const key of Object.keys(node)) {
4086
- if (key === "parent") {
4087
- continue;
4088
- }
4089
- const value = node[key];
4090
- for (const child of Array.isArray(value) ? value : [value]) {
4091
- if (child !== null && typeof child === "object" && "type" in child) {
4092
- markConsumed(child, consumed);
4093
- }
4094
- }
4095
- }
4100
+ forEachOwnAstChild(node, (child) => markConsumed(child, consumed));
4096
4101
  }
4097
4102
  function createSqlListener(handler) {
4098
4103
  const consumed = /* @__PURE__ */ new WeakSet();
@@ -4717,9 +4722,6 @@ var PURE_CONSTRUCTORS = /* @__PURE__ */ new Set([
4717
4722
  "Response",
4718
4723
  "AbortController"
4719
4724
  ]);
4720
- function isNode3(value) {
4721
- return typeof value === "object" && value !== null && typeof value.type === "string";
4722
- }
4723
4725
  function isPureCall(node) {
4724
4726
  const callee = node.callee;
4725
4727
  if (callee.type !== AST_NODE_TYPES27.MemberExpression) {
@@ -4757,27 +4759,7 @@ function subtreeMatches(stmt, predicate, descendIntoFunctions = false) {
4757
4759
  found = true;
4758
4760
  return;
4759
4761
  }
4760
- for (const key of Object.keys(current)) {
4761
- if (key === "parent") {
4762
- continue;
4763
- }
4764
- if (!descendIntoFunctions && NESTED_FUNCTION_TYPES.has(current.type) && key === "body") {
4765
- continue;
4766
- }
4767
- const value = current[key];
4768
- if (Array.isArray(value)) {
4769
- for (const child of value) {
4770
- if (isNode3(child)) {
4771
- visit(child);
4772
- }
4773
- }
4774
- } else if (isNode3(value)) {
4775
- visit(value);
4776
- }
4777
- if (found) {
4778
- return;
4779
- }
4780
- }
4762
+ forEachOwnAstChild(current, visit, (key) => descendIntoFunctions || !NESTED_FUNCTION_TYPES.has(current.type) || key !== "body");
4781
4763
  };
4782
4764
  visit(stmt);
4783
4765
  return found;
@@ -7151,17 +7133,7 @@ function nearestFunction(node) {
7151
7133
  }
7152
7134
  function walkOwnScope(node, predicate) {
7153
7135
  if (predicate(node)) return true;
7154
- for (const key of Object.keys(node)) {
7155
- if (key === "parent") continue;
7156
- const value = node[key];
7157
- for (const child of Array.isArray(value) ? value : [value]) {
7158
- if (typeof child === "object" && child !== null && typeof child.type === "string") {
7159
- const childNode = child;
7160
- if (!FUNCTION_TYPES3.has(childNode.type) && walkOwnScope(childNode, predicate)) return true;
7161
- }
7162
- }
7163
- }
7164
- return false;
7136
+ return forEachOwnAstChild(node, (child) => !FUNCTION_TYPES3.has(child.type) && walkOwnScope(child, predicate));
7165
7137
  }
7166
7138
  function isAssertion(node, context) {
7167
7139
  if (node.type !== AST_NODE_TYPES37.CallExpression) return false;
@@ -9948,7 +9920,7 @@ function isSentinelArgument(arg) {
9948
9920
  function isFunctionNode(node) {
9949
9921
  return node.type === AST_NODE_TYPES48.FunctionDeclaration || node.type === AST_NODE_TYPES48.FunctionExpression || node.type === AST_NODE_TYPES48.ArrowFunctionExpression;
9950
9922
  }
9951
- function isNode4(value) {
9923
+ function isNode3(value) {
9952
9924
  return typeof value === "object" && value !== null && typeof value.type === "string";
9953
9925
  }
9954
9926
  function walkWithinScope(node, visit) {
@@ -9964,21 +9936,10 @@ function walkWithinScope(node, visit) {
9964
9936
  if (isFunctionNode(current)) {
9965
9937
  return;
9966
9938
  }
9967
- for (const key of Object.keys(current)) {
9968
- if (key === "parent") {
9969
- continue;
9970
- }
9971
- const value = current[key];
9972
- if (Array.isArray(value)) {
9973
- for (const child of value) {
9974
- if (isNode4(child)) {
9975
- recurse(child);
9976
- }
9977
- }
9978
- } else if (isNode4(value)) {
9979
- recurse(value);
9980
- }
9981
- }
9939
+ forEachOwnAstChild(current, (child) => {
9940
+ recurse(child);
9941
+ return found;
9942
+ });
9982
9943
  };
9983
9944
  recurse(node);
9984
9945
  return found;
@@ -10025,22 +9986,10 @@ function subtreeReadsName(node, name) {
10025
9986
  if (shadowsName(current)) {
10026
9987
  return;
10027
9988
  }
10028
- for (const key of Object.keys(current)) {
10029
- if (key === "parent") {
10030
- continue;
10031
- }
10032
- if (isNonReadingProperty(current, key)) continue;
10033
- const value = current[key];
10034
- if (Array.isArray(value)) {
10035
- for (const child of value) {
10036
- if (isNode4(child)) {
10037
- recurse(child);
10038
- }
10039
- }
10040
- } else if (isNode4(value)) {
10041
- recurse(value);
10042
- }
10043
- }
9989
+ forEachOwnAstChild(current, (child) => {
9990
+ recurse(child);
9991
+ return found;
9992
+ }, (key) => !isNonReadingProperty(current, key));
10044
9993
  };
10045
9994
  recurse(node);
10046
9995
  return found;
@@ -10098,7 +10047,7 @@ function enclosingFunctionName(node) {
10098
10047
  let current = node.parent;
10099
10048
  while (current !== void 0 && current !== null) {
10100
10049
  if (isFunctionNode(current)) {
10101
- if ("id" in current && isNode4(current.id) && current.id.type === AST_NODE_TYPES48.Identifier) {
10050
+ if ("id" in current && isNode3(current.id) && current.id.type === AST_NODE_TYPES48.Identifier) {
10102
10051
  return current.id.name;
10103
10052
  }
10104
10053
  const parent = current.parent;
@@ -10159,14 +10108,10 @@ function tryReturnsSafeParse(catchNode) {
10159
10108
  visitChildren(current);
10160
10109
  };
10161
10110
  function visitChildren(current) {
10162
- for (const key of Object.keys(current)) {
10163
- if (key === "parent") continue;
10164
- const value = current[key];
10165
- const children = Array.isArray(value) ? value : [value];
10166
- for (const child of children) {
10167
- if (isNode4(child)) recurse(child);
10168
- }
10169
- }
10111
+ forEachOwnAstChild(current, (child) => {
10112
+ recurse(child);
10113
+ return sawUnsafeOperation;
10114
+ });
10170
10115
  }
10171
10116
  recurse(tryBlock);
10172
10117
  return sawSafeParse && !sawUnsafeOperation;
@@ -10203,7 +10148,7 @@ function functionReturnsSameSentinelKindElsewhere(catchNode, kind) {
10203
10148
  function enclosingFunctionBody(node) {
10204
10149
  let current = node.parent;
10205
10150
  while (current !== void 0 && current !== null) {
10206
- if (isFunctionNode(current) && "body" in current && isNode4(current.body) && current.body.type === AST_NODE_TYPES48.BlockStatement) {
10151
+ if (isFunctionNode(current) && "body" in current && isNode3(current.body) && current.body.type === AST_NODE_TYPES48.BlockStatement) {
10207
10152
  return current.body;
10208
10153
  }
10209
10154
  current = current.parent;
@@ -23299,7 +23244,7 @@ var RULES = {
23299
23244
  };
23300
23245
  var meta = {
23301
23246
  name: "@sarj/eslint-plugin",
23302
- version: "15.26.3"
23247
+ version: "15.26.4"
23303
23248
  };
23304
23249
  var APPLICATION_ONLY_RULES = [];
23305
23250
  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.3",
3
+ "version": "15.26.4",
4
4
  "packageManager": "npm@12.0.2",
5
5
  "description": "Custom ESLint rules for hypermodern TypeScript / React / Next.js projects",
6
6
  "type": "module",