adamantite 0.45.0 → 0.47.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.
Files changed (81) hide show
  1. package/README.md +447 -127
  2. package/dist/index.js +628 -57
  3. package/dist/oxlint.js +1 -0
  4. package/dist/presets/analyze.js +1 -0
  5. package/dist/presets/lint/{react-doctor.d.ts → architecture.d.ts} +1 -1
  6. package/dist/presets/lint/architecture.js +8 -0
  7. package/dist/presets/lint/core.js +1 -2
  8. package/dist/presets/lint/effect.js +26 -1
  9. package/dist/presets/lint/plugin/glob.d.ts +7 -0
  10. package/dist/presets/lint/plugin/glob.js +48 -0
  11. package/dist/presets/lint/plugin/imports.d.ts +4 -0
  12. package/dist/presets/lint/plugin/imports.js +4 -1
  13. package/dist/presets/lint/plugin/index.d.ts +3 -0
  14. package/dist/presets/lint/plugin/index.js +14 -8
  15. package/dist/presets/lint/plugin/options.d.ts +5 -5
  16. package/dist/presets/lint/plugin/options.js +19 -7
  17. package/dist/presets/lint/plugin/resolver.d.ts +8 -0
  18. package/dist/presets/lint/plugin/resolver.js +79 -0
  19. package/dist/presets/lint/plugin/rules/import-owners.d.ts +67 -0
  20. package/dist/presets/lint/plugin/rules/import-owners.js +310 -0
  21. package/dist/presets/lint/plugin/rules/layers.d.ts +136 -0
  22. package/dist/presets/lint/plugin/rules/layers.js +479 -0
  23. package/dist/presets/lint/plugin/rules/no-query-data-in-state.js +1 -1
  24. package/dist/presets/lint/plugin/rules/no-react-state-hooks.d.ts +0 -5
  25. package/dist/presets/lint/plugin/rules/no-react-state-hooks.js +3 -47
  26. package/dist/presets/lint/plugin/rules/query-from-loader.js +2 -2
  27. package/dist/presets/lint/plugin/rules/require-suppression-reason.d.ts +5 -0
  28. package/dist/presets/lint/plugin/rules/require-suppression-reason.js +32 -0
  29. package/dist/presets/lint/react-strict.js +22 -2
  30. package/dist/presets/lint/strict.js +35 -2
  31. package/dist/presets/lint/{antislop.d.ts → tailwind.d.ts} +1 -1
  32. package/dist/presets/lint/{shadcn.js → tailwind.js} +1 -1
  33. package/dist/presets/lint/vendor/antislop/license.md +26 -1
  34. package/dist/presets/lint/vendor/antislop/plugin.d.mts +3 -0
  35. package/dist/presets/lint/vendor/antislop/plugin.mjs +959 -33
  36. package/dist/presets/lint/vendor/antislop-effect/license.md +27 -0
  37. package/dist/presets/lint/vendor/antislop-effect/plugin.d.mts +17 -0
  38. package/dist/presets/lint/vendor/antislop-effect/plugin.mjs +579 -0
  39. package/dist/presets/{lint → rules}/custom.d.ts +3 -20
  40. package/dist/presets/{lint → rules}/custom.js +50 -46
  41. package/dist/presets/rules/folder.d.ts +34 -0
  42. package/dist/presets/rules/folder.js +52 -0
  43. package/dist/presets/rules/index.d.ts +2 -9
  44. package/dist/presets/rules/index.js +1 -29
  45. package/dist/presets/rules/load.d.ts +8 -0
  46. package/dist/presets/rules/load.js +29 -0
  47. package/dist/presets/rules/plugin.d.ts +3 -0
  48. package/dist/presets/rules/plugin.js +1 -0
  49. package/dist/presets/rules/testing.d.ts +2 -0
  50. package/dist/presets/rules/testing.js +14 -0
  51. package/dist/presets/tsconfig.json +3 -0
  52. package/dist/presets/typescript/resets/array-includes.d.ts +15 -0
  53. package/dist/presets/typescript/resets/array-index-of.d.ts +23 -0
  54. package/dist/presets/typescript/resets/eval.d.ts +1 -0
  55. package/dist/presets/typescript/resets/fetch.d.ts +3 -0
  56. package/dist/presets/typescript/resets/filter-boolean.d.ts +24 -0
  57. package/dist/presets/typescript/resets/helpers.d.ts +15 -0
  58. package/dist/presets/typescript/resets/index.d.ts +20 -0
  59. package/dist/presets/typescript/resets/is-array.d.ts +3 -0
  60. package/dist/presets/typescript/resets/json-parse.d.ts +14 -0
  61. package/dist/presets/typescript/resets/license.md +12 -0
  62. package/dist/presets/typescript/resets/map-constructor.d.ts +3 -0
  63. package/dist/presets/typescript/resets/map-groupby.d.ts +3 -0
  64. package/dist/presets/typescript/resets/map-has.d.ts +9 -0
  65. package/dist/presets/typescript/resets/object-assign.d.ts +8 -0
  66. package/dist/presets/typescript/resets/object-get-prototype-of.d.ts +3 -0
  67. package/dist/presets/typescript/resets/object-groupby.d.ts +6 -0
  68. package/dist/presets/typescript/resets/object-values.d.ts +8 -0
  69. package/dist/presets/typescript/resets/reflect.d.ts +12 -0
  70. package/dist/presets/typescript/resets/set-has.d.ts +9 -0
  71. package/dist/presets/typescript/resets/storage.d.ts +3 -0
  72. package/dist/presets/typescript.json +13 -0
  73. package/dist/runtime-CVZPDpfE.js +11 -0
  74. package/package.json +81 -19
  75. package/skills/adamantite/SKILL.md +110 -207
  76. package/skills/adamantite/references/custom-rules.md +120 -0
  77. package/skills/adamantite/references/lint-rules.md +152 -0
  78. package/skills/adamantite/references/setup.md +70 -0
  79. package/dist/presets/lint/antislop.js +0 -28
  80. package/dist/presets/lint/react-doctor.js +0 -20
  81. package/dist/presets/lint/shadcn.d.ts +0 -5
@@ -1,7 +1,8 @@
1
1
  // Vendored build of the anti-slop oxlint plugin.
2
- // Source: https://github.com/dmmulroy/anti-slop (MIT) at commit e8c4880471b23ab7f216fba7b27d173a6ef07d4c.
2
+ // Source: https://github.com/dmmulroy/anti-slop (MIT) at commit 13909c9e07590f5a85d93c62712259fe14a883f7.
3
3
  // Its dependencies (MIT) are inlined so this file is self-contained.
4
4
  // See license.md for the full license text.
5
+ // Patched with scripts/vendor-patches/anti-slop/no-unknown-parameters-rejection-callback.patch.
5
6
  //
6
7
  // Generated by scripts/vendor-plugins.ts — do not edit by hand.
7
8
  //#region node_modules/.pnpm/@oxlint+plugins@1.78.0/node_modules/@oxlint/plugins/index.js
@@ -347,6 +348,187 @@ function createContextAndVisitor(rule, afterHooksState) {
347
348
  };
348
349
  }
349
350
  //#endregion
351
+ //#region src/shared/array-method.ts
352
+ /** Unwrap syntax-only wrappers when inspecting array methods and accumulator references. */
353
+ function unwrapArrayExpression(node) {
354
+ while (node.type === "ParenthesizedExpression" || node.type === "ChainExpression" || node.type === "TSAsExpression" || node.type === "TSTypeAssertion" || node.type === "TSNonNullExpression" || node.type === "TSSatisfiesExpression") node = node.expression;
355
+ return node;
356
+ }
357
+ /** Resolve a local binding by scope, not by identifier spelling. */
358
+ function resolveArrayBinding(sourceCode, node) {
359
+ node = unwrapArrayExpression(node);
360
+ if (node.type !== "Identifier") return null;
361
+ let scope = sourceCode.getScope(node);
362
+ while (scope !== null) {
363
+ const variable = scope.set.get(node.name);
364
+ if (variable !== void 0) return variable;
365
+ scope = scope.upper;
366
+ }
367
+ return null;
368
+ }
369
+ /** Read static method names, including computed string literals, without evaluating expressions. */
370
+ function arrayMethodTarget(node) {
371
+ node = unwrapArrayExpression(node);
372
+ if (node.type !== "MemberExpression") return null;
373
+ const property = node.property;
374
+ if (!node.computed && property.type === "Identifier") return {
375
+ name: property.name,
376
+ object: node.object
377
+ };
378
+ if (node.computed && property.type === "Literal" && typeof property.value === "string") return {
379
+ name: property.value,
380
+ object: node.object
381
+ };
382
+ return null;
383
+ }
384
+ function isArrayAnnotation(type) {
385
+ if (type.type === "TSArrayType" || type.type === "TSTupleType") return true;
386
+ if (type.type === "TSParenthesizedType") return isArrayAnnotation(type.typeAnnotation);
387
+ if (type.type === "TSTypeOperator" && type.operator === "readonly") return isArrayAnnotation(type.typeAnnotation);
388
+ return type.type === "TSTypeReference" && type.typeName.type === "Identifier" && (type.typeName.name === "Array" || type.typeName.name === "ReadonlyArray");
389
+ }
390
+ /** Recognize local array evidence; unknown receivers and iterator pipelines are deliberately excluded. */
391
+ function isKnownArrayExpression(sourceCode, node, visited = /* @__PURE__ */ new Set()) {
392
+ node = unwrapArrayExpression(node);
393
+ if (node.type === "ArrayExpression") return true;
394
+ if (node.type === "CallExpression") {
395
+ const method = arrayMethodTarget(node.callee);
396
+ return method !== null && [
397
+ "map",
398
+ "filter",
399
+ "flatMap",
400
+ "slice",
401
+ "concat",
402
+ "toSorted",
403
+ "toReversed",
404
+ "toSpliced"
405
+ ].includes(method.name) && isKnownArrayExpression(sourceCode, method.object, visited);
406
+ }
407
+ if (node.type !== "Identifier") return false;
408
+ const variable = resolveArrayBinding(sourceCode, node);
409
+ if (variable === null || visited.has(variable)) return false;
410
+ visited.add(variable);
411
+ if (variable.references.some((reference) => reference.isWrite() && !reference.init)) return false;
412
+ for (const identifier of variable.identifiers) {
413
+ const annotation = identifier.typeAnnotation?.typeAnnotation;
414
+ if (annotation !== void 0) return isArrayAnnotation(annotation);
415
+ }
416
+ for (const definition of variable.defs) if (definition.type === "Variable" && definition.node.type === "VariableDeclarator" && definition.node.id.type === "Identifier" && definition.node.init !== null && definition.node.parent.type === "VariableDeclaration" && definition.node.parent.kind === "const") return isKnownArrayExpression(sourceCode, definition.node.init, visited);
417
+ return false;
418
+ }
419
+ //#endregion
420
+ //#region src/rules/no-array-filter-map.ts
421
+ /** Reject eager array filter/map pipelines; lazy iterator helpers remain allowed. */
422
+ const noArrayFilterMapRule = defineRule({
423
+ meta: {
424
+ type: "suggestion",
425
+ docs: { description: "Disallow adjacent array filter/map passes in favor of lazy iterator helpers or a single transformation." },
426
+ messages: { arrayFilterMap: "Avoid consecutive array `{{first}}` and `{{second}}` passes. Prefer `.values().{{first}}(...).{{second}}(...).toArray()` where iterator helpers are supported, or a single `flatMap`/mutating reducer. Preserve callback ordering, indexes, and filtering semantics." }
427
+ },
428
+ createOnce(context) {
429
+ return { CallExpression(node) {
430
+ const outer = arrayMethodTarget(node.callee);
431
+ if (outer === null || outer.name !== "map" && outer.name !== "filter") return;
432
+ const innerCall = unwrapArrayExpression(outer.object);
433
+ if (innerCall.type !== "CallExpression") return;
434
+ const inner = arrayMethodTarget(innerCall.callee);
435
+ if (inner === null || inner.name !== (outer.name === "map" ? "filter" : "map")) return;
436
+ if (!isKnownArrayExpression(context.sourceCode, inner.object)) return;
437
+ context.report({
438
+ node,
439
+ messageId: "arrayFilterMap",
440
+ data: {
441
+ first: inner.name,
442
+ second: outer.name
443
+ }
444
+ });
445
+ } };
446
+ }
447
+ });
448
+ //#endregion
449
+ //#region src/rules/no-reduce-accumulator-copy.ts
450
+ function enclosingReducer(node) {
451
+ let parent = node.parent;
452
+ while (parent !== null) {
453
+ if (parent.type === "FunctionDeclaration") return null;
454
+ if (parent.type === "ArrowFunctionExpression" || parent.type === "FunctionExpression") {
455
+ const callback = parent;
456
+ let owner = callback.parent;
457
+ while (owner !== null && unwrapArrayExpression(owner) === callback) owner = owner.parent;
458
+ if (owner?.type !== "CallExpression") return null;
459
+ const method = arrayMethodTarget(owner.callee);
460
+ const firstArgument = owner.arguments[0];
461
+ if (method === null || method.name !== "reduce" && method.name !== "reduceRight" || owner.arguments.length > 2 || firstArgument === void 0 || unwrapArrayExpression(firstArgument) !== callback) return null;
462
+ const firstParameter = callback.params[0];
463
+ const accumulator = firstParameter?.type === "AssignmentPattern" ? firstParameter.left : firstParameter;
464
+ if (accumulator?.type !== "Identifier") return null;
465
+ return {
466
+ callback,
467
+ accumulator,
468
+ initialValue: owner.arguments[1]
469
+ };
470
+ }
471
+ parent = parent.parent;
472
+ }
473
+ return null;
474
+ }
475
+ function referencesAccumulator(sourceCode, node, accumulator, visited = /* @__PURE__ */ new Set()) {
476
+ const variable = resolveArrayBinding(sourceCode, node);
477
+ if (variable === null || visited.has(variable)) return false;
478
+ if (variable === accumulator) return true;
479
+ visited.add(variable);
480
+ if (variable.references.some((reference) => reference.isWrite() && !reference.init)) return false;
481
+ for (const definition of variable.defs) if (definition.type === "Variable" && definition.node.type === "VariableDeclarator" && definition.node.id.type === "Identifier" && definition.node.init !== null && definition.node.parent.type === "VariableDeclaration" && definition.node.parent.kind === "const") return referencesAccumulator(sourceCode, definition.node.init, accumulator, visited);
482
+ return false;
483
+ }
484
+ function isGlobalCopyOwner(sourceCode, node, name) {
485
+ node = unwrapArrayExpression(node);
486
+ if (node.type !== "Identifier" || node.name !== name) return false;
487
+ const variable = resolveArrayBinding(sourceCode, node);
488
+ return variable === null || variable.defs.length === 0;
489
+ }
490
+ /** Reject non-spread copies of reducer accumulators; pair with oxc/no-accumulating-spread. */
491
+ const noReduceAccumulatorCopyRule = defineRule({
492
+ meta: {
493
+ type: "problem",
494
+ docs: { description: "Disallow copying growing reducer accumulators with Object.assign, Array.from, or array copy methods." },
495
+ messages: { accumulatorCopy: "Do not copy the reducer accumulator on every iteration; growing copies can cause quadratic work. Mutate a fresh, locally owned accumulator and return it, or use an iterator pipeline/flatMap." }
496
+ },
497
+ createOnce(context) {
498
+ return { CallExpression(node) {
499
+ const method = arrayMethodTarget(node.callee);
500
+ if (method === null) return;
501
+ const reducer = enclosingReducer(node);
502
+ if (reducer === null) return;
503
+ const accumulator = context.sourceCode.getDeclaredVariables(reducer.callback).find((variable) => variable.identifiers.some((identifier) => identifier.start === reducer.accumulator.start));
504
+ if (accumulator === void 0) return;
505
+ const isAccumulator = (expression) => referencesAccumulator(context.sourceCode, expression, accumulator);
506
+ let copiesAccumulator = false;
507
+ if (method.name === "assign" && isGlobalCopyOwner(context.sourceCode, method.object, "Object")) {
508
+ const target = node.arguments[0];
509
+ copiesAccumulator = target !== void 0 && unwrapArrayExpression(target).type === "ObjectExpression" && node.arguments.slice(1).some(isAccumulator);
510
+ } else if (method.name === "from" && isGlobalCopyOwner(context.sourceCode, method.object, "Array")) {
511
+ const source = node.arguments[0];
512
+ copiesAccumulator = source !== void 0 && isAccumulator(source);
513
+ } else if ([
514
+ "concat",
515
+ "slice",
516
+ "toSpliced",
517
+ "toSorted",
518
+ "toReversed",
519
+ "with"
520
+ ].includes(method.name)) {
521
+ const initialValue = reducer.initialValue;
522
+ copiesAccumulator = initialValue !== void 0 && isKnownArrayExpression(context.sourceCode, initialValue) && isAccumulator(method.object);
523
+ }
524
+ if (copiesAccumulator) context.report({
525
+ node,
526
+ messageId: "accumulatorCopy"
527
+ });
528
+ } };
529
+ }
530
+ });
531
+ //#endregion
350
532
  //#region src/rules/no-chained-type-assertions.ts
351
533
  function isTypeAssertionExpression(node) {
352
534
  return node.type === "TSAsExpression" || node.type === "TSTypeAssertion";
@@ -880,13 +1062,9 @@ function functionParameterBindingName(parameter, sourceCode) {
880
1062
  return annotationStart === void 0 ? sourceText : sourceText.slice(0, annotationStart - parameter.start).trimEnd();
881
1063
  }
882
1064
  //#endregion
883
- //#region src/rules/no-known-value-widening.ts
884
- function unwrapExpression(expression) {
885
- let current = expression;
886
- while (current.type === "ParenthesizedExpression" || current.type === "TSAsExpression" || current.type === "TSSatisfiesExpression" || current.type === "TSTypeAssertion" || current.type === "TSNonNullExpression") current = current.expression;
887
- return current;
888
- }
889
- function resolveVariable$2(sourceCode, identifier) {
1065
+ //#region src/shared/scope.ts
1066
+ /** Resolve an identifier to its binding by walking lexical scopes upward. */
1067
+ function resolveVariable(sourceCode, identifier) {
890
1068
  let scope = sourceCode.getScope(identifier);
891
1069
  while (scope !== null) {
892
1070
  const variable = scope.set.get(identifier.name);
@@ -895,6 +1073,13 @@ function resolveVariable$2(sourceCode, identifier) {
895
1073
  }
896
1074
  return null;
897
1075
  }
1076
+ //#endregion
1077
+ //#region src/rules/no-known-value-widening.ts
1078
+ function unwrapExpression(expression) {
1079
+ let current = expression;
1080
+ while (current.type === "ParenthesizedExpression" || current.type === "TSAsExpression" || current.type === "TSSatisfiesExpression" || current.type === "TSTypeAssertion" || current.type === "TSNonNullExpression") current = current.expression;
1081
+ return current;
1082
+ }
898
1083
  function variableDeclarator$1(variable) {
899
1084
  if (variable.defs.length !== 1) return null;
900
1085
  const [definition] = variable.defs;
@@ -907,7 +1092,7 @@ function hasKnownEvidence(sourceCode, expression, visitedVariables = /* @__PURE_
907
1092
  if (isKnownEvidenceExpression(expression)) return true;
908
1093
  const unwrapped = unwrapExpression(expression);
909
1094
  if (unwrapped.type !== "Identifier") return false;
910
- const variable = resolveVariable$2(sourceCode, unwrapped);
1095
+ const variable = resolveVariable(sourceCode, unwrapped);
911
1096
  if (variable === null || visitedVariables.has(variable)) return false;
912
1097
  const declarator = variableDeclarator$1(variable);
913
1098
  if (declarator === null || declarator.init === null || !isStableConstVariable(variable, declarator)) return false;
@@ -921,7 +1106,7 @@ function localFunctionForCall(sourceCode, callee) {
921
1106
  const unwrapped = unwrapExpression(callee);
922
1107
  if (isFunctionExpression(unwrapped)) return unwrapped;
923
1108
  if (unwrapped.type !== "Identifier") return null;
924
- const variable = resolveVariable$2(sourceCode, unwrapped);
1109
+ const variable = resolveVariable(sourceCode, unwrapped);
925
1110
  if (variable === null || variable.defs.length !== 1) return null;
926
1111
  const [definition] = variable.defs;
927
1112
  if (definition === void 0) return null;
@@ -953,7 +1138,7 @@ function hasKnownCallArgumentEvidence(sourceCode, expression, environment, visit
953
1138
  return returnType !== void 0 && hasInformativeType(returnType, environment);
954
1139
  }
955
1140
  if (expression.type !== "Identifier") return isKnownEvidenceExpression(expression);
956
- const variable = resolveVariable$2(sourceCode, expression);
1141
+ const variable = resolveVariable(sourceCode, expression);
957
1142
  if (variable === null || visitedVariables.has(variable)) return false;
958
1143
  const annotation = variableTypeAnnotation(sourceCode, variable);
959
1144
  if (annotation !== null) return hasInformativeType(annotation.typeAnnotation, environment);
@@ -1044,7 +1229,7 @@ const noKnownValueWideningRule = defineRule({
1044
1229
  },
1045
1230
  AssignmentExpression(node) {
1046
1231
  if (node.operator !== "=" || node.left.type !== "Identifier") return;
1047
- const variable = resolveVariable$2(context.sourceCode, node.left);
1232
+ const variable = resolveVariable(context.sourceCode, node.left);
1048
1233
  if (variable === null) return;
1049
1234
  const declarator = variableDeclarator$1(variable);
1050
1235
  if (declarator === null || declarator.id.type !== "Identifier") return;
@@ -1098,15 +1283,6 @@ const moduleMockMethods = /* @__PURE__ */ new Set([
1098
1283
  "mock",
1099
1284
  "unstable_mockModule"
1100
1285
  ]);
1101
- function resolveVariable$1(sourceCode, identifier) {
1102
- let scope = sourceCode.getScope(identifier);
1103
- while (scope !== null) {
1104
- const variable = scope.set.get(identifier.name);
1105
- if (variable !== void 0) return variable;
1106
- scope = scope.upper;
1107
- }
1108
- return null;
1109
- }
1110
1286
  function importedName(node) {
1111
1287
  if (node.type !== "ImportSpecifier") return null;
1112
1288
  return node.imported.type === "Identifier" ? node.imported.name : node.imported.value;
@@ -1114,7 +1290,7 @@ function importedName(node) {
1114
1290
  function isTestFrameworkObject(sourceCode, expression) {
1115
1291
  if (expression.type !== "Identifier") return false;
1116
1292
  if ((expression.name === "vi" || expression.name === "jest") && sourceCode.isGlobalReference(expression)) return true;
1117
- const variable = resolveVariable$1(sourceCode, expression);
1293
+ const variable = resolveVariable(sourceCode, expression);
1118
1294
  if (variable === null || variable.defs.length === 0) return expression.name === "vi" || expression.name === "jest";
1119
1295
  return variable.defs.some((definition) => {
1120
1296
  if (definition.type !== "ImportBinding" || definition.parent?.type !== "ImportDeclaration") return false;
@@ -1194,15 +1370,6 @@ const noObjectParametersRule = defineRule({
1194
1370
  });
1195
1371
  //#endregion
1196
1372
  //#region src/shared/reflect-method.ts
1197
- function resolveVariable(sourceCode, identifier) {
1198
- let scope = sourceCode.getScope(identifier);
1199
- while (scope !== null) {
1200
- const variable = scope.set.get(identifier.name);
1201
- if (variable !== void 0) return variable;
1202
- scope = scope.upper;
1203
- }
1204
- return null;
1205
- }
1206
1373
  function isGlobalReflect(sourceCode, expression) {
1207
1374
  if (expression.type !== "Identifier" || expression.name !== "Reflect") return false;
1208
1375
  if (sourceCode.isGlobalReference(expression)) return true;
@@ -1345,21 +1512,37 @@ function isTypePredicateSubject(owner, parameterName) {
1345
1512
  const predicate = owner.returnType?.typeAnnotation;
1346
1513
  return predicate?.type === "TSTypePredicate" && predicate.parameterName.type === "Identifier" && predicate.parameterName.name === parameterName;
1347
1514
  }
1515
+ /** The argument position of the rejection callback for each promise method that takes one. */
1516
+ const REJECTION_CALLBACK_INDEX = /* @__PURE__ */ new Map([["catch", 0], ["then", 1]]);
1517
+ /**
1518
+ * Return whether a function is the rejection callback of `.catch()` or `.then()`. The promise
1519
+ * fixes the type of the rejection reason, so the callback cannot accept a parsed domain type.
1520
+ */
1521
+ function isRejectionCallback(owner) {
1522
+ const call = owner.parent;
1523
+ if (call?.type !== "CallExpression") return false;
1524
+ const callee = call.callee;
1525
+ if (callee.type !== "MemberExpression" || callee.computed) return false;
1526
+ if (callee.property.type !== "Identifier") return false;
1527
+ const index = REJECTION_CALLBACK_INDEX.get(callee.property.name);
1528
+ return index !== void 0 && call.arguments[index] === owner;
1529
+ }
1348
1530
  /** Disallow unknown inputs except explicitly named error-cause enrichment. */
1349
1531
  const noUnknownParametersRule = defineRule({
1350
1532
  meta: {
1351
1533
  type: "problem",
1352
- docs: { description: "Disallow explicitly unknown function parameters except `cause` and type-predicate subjects; decode unknown input at its I/O boundary instead." },
1534
+ docs: { description: "Disallow explicitly unknown function parameters except `cause`, type-predicate subjects, and promise rejection reasons; decode unknown input at its I/O boundary instead." },
1353
1535
  messages: { unknownParameter: "Parameter `{{parameter}}` leaves input unparsed. Accept a named domain type; run the expected schema or parser at the I/O boundary before calling this function." }
1354
1536
  },
1355
1537
  createOnce(context) {
1356
1538
  const checkParameters = (node) => {
1357
- for (const parameter of node.params) {
1539
+ for (const [index, parameter] of node.params.entries()) {
1358
1540
  const annotation = functionParameterTypeAnnotation(parameter);
1359
1541
  if (annotation === null || annotation === void 0) continue;
1360
1542
  if (!containsUnknownType(annotation.typeAnnotation)) continue;
1361
1543
  const name = functionParameterBindingName(parameter, context.sourceCode);
1362
1544
  if (name === "cause" || isTypePredicateSubject(node, name)) continue;
1545
+ if (index === 0 && isRejectionCallback(node)) continue;
1363
1546
  context.report({
1364
1547
  node: annotation.typeAnnotation,
1365
1548
  messageId: "unknownParameter",
@@ -1765,6 +1948,746 @@ const noWidenThenAssertRule = defineRule({
1765
1948
  }
1766
1949
  });
1767
1950
  //#endregion
1951
+ //#region src/vendor/eslint-stylistic/padding-line-ast.ts
1952
+ /** Line terminators recognized by the upstream padding matcher. */
1953
+ const LINEBREAKS = /* @__PURE__ */ new Set([
1954
+ "\r\n",
1955
+ "\r",
1956
+ "\n",
1957
+ "\u2028",
1958
+ "\u2029"
1959
+ ]);
1960
+ /** Test a closing brace without treating comment text as punctuation. */
1961
+ const isClosingBraceToken = (token) => token.type === "Punctuator" && token.value === "}";
1962
+ /** Test a semicolon without treating comment text as punctuation. */
1963
+ const isSemicolonToken = (token) => token.type === "Punctuator" && token.value === ";";
1964
+ /** Filter the optional final semicolon when identifying block-like statements. */
1965
+ const isNotSemicolonToken = (token) => !isSemicolonToken(token);
1966
+ /** Compare token/node boundaries, including attached comments. */
1967
+ const isTokenOnSameLine = (left, right) => left.loc.end.line === right.loc.start.line;
1968
+ /** Recognize declarations and expressions used by the upstream IIFE matcher. */
1969
+ const isFunction = (node) => node.type === "FunctionDeclaration" || node.type === "FunctionExpression" || node.type === "ArrowFunctionExpression";
1970
+ /** Preserve the upstream multiline statement heuristic. */
1971
+ const isSingleLine = (node) => node.loc.start.line === node.loc.end.line;
1972
+ /** Unwrap optional chaining before checking IIFE syntax. */
1973
+ const skipChainExpression = (node) => node.type === "ChainExpression" ? node.expression : node;
1974
+ /** Only a program or function-body expression can begin a directive prologue. */
1975
+ const isTopLevelExpressionStatement = (node) => node.type === "ExpressionStatement" && (node.parent.type === "Program" || node.parent.type === "BlockStatement" && isFunction(node.parent.parent));
1976
+ /** A single wrapping pair suffices to exclude a string from directive syntax. */
1977
+ function isParenthesized(node, sourceCode) {
1978
+ const before = sourceCode.getTokenBefore(node);
1979
+ const after = sourceCode.getTokenAfter(node);
1980
+ return before?.value === "(" && after?.value === ")";
1981
+ }
1982
+ //#endregion
1983
+ //#region src/vendor/eslint-stylistic/padding-line-between-statements.ts
1984
+ const CJS_EXPORT = /^(?:module\s*\.\s*)?exports(?:\s*\.|\s*\[|$)/u;
1985
+ const CJS_IMPORT = /^require\(/u;
1986
+ const LT = `[${Array.from(LINEBREAKS).join("")}]`;
1987
+ const PADDING_LINE_SEQUENCE = new RegExp(String.raw`^(\s*?${LT})\s*${LT}(\s*;?)$`, "u");
1988
+ function isSelectorOption(option) {
1989
+ return typeof option === "object" && !Array.isArray(option);
1990
+ }
1991
+ /**
1992
+ * Creates tester which check if a node starts with specific keyword with the
1993
+ * appropriate AST_NODE_TYPES.
1994
+ * @param keyword The keyword to test.
1995
+ * @returns the created tester.
1996
+ * @private
1997
+ */
1998
+ function newKeywordTester(type, keyword) {
1999
+ return { test(node, sourceCode) {
2000
+ const isSameKeyword = sourceCode.getFirstToken(node)?.value === keyword;
2001
+ const isSameType = Array.isArray(type) ? type.includes(node.type) : type === node.type;
2002
+ return isSameKeyword && isSameType;
2003
+ } };
2004
+ }
2005
+ /**
2006
+ * Creates tester which check if a node is specific type.
2007
+ * @param type The node type to test.
2008
+ * @returns the created tester.
2009
+ * @private
2010
+ */
2011
+ function newNodeTypeTester(type) {
2012
+ return { test: (node) => node.type === type };
2013
+ }
2014
+ /**
2015
+ * Checks the given node is an expression statement of IIFE.
2016
+ * @param node The node to check.
2017
+ * @returns `true` if the node is an expression statement of IIFE.
2018
+ * @private
2019
+ */
2020
+ function isIIFEStatement(node) {
2021
+ if (node.type === "ExpressionStatement") {
2022
+ let expression = skipChainExpression(node.expression);
2023
+ if (expression.type === "UnaryExpression") expression = skipChainExpression(expression.argument);
2024
+ if (expression.type === "CallExpression") {
2025
+ let node = expression.callee;
2026
+ while (node.type === "SequenceExpression") {
2027
+ const lastExpression = node.expressions.at(-1);
2028
+ if (lastExpression === void 0) throw new Error("Padding rule invariant: sequence expression is empty");
2029
+ node = lastExpression;
2030
+ }
2031
+ return isFunction(node);
2032
+ }
2033
+ }
2034
+ return false;
2035
+ }
2036
+ /**
2037
+ * Checks the given node is a CommonJS require statement
2038
+ * @param node The node to check.
2039
+ * @returns `true` if the node is a CommonJS require statement.
2040
+ * @private
2041
+ */
2042
+ function isCJSRequire(node) {
2043
+ if (node.type === "VariableDeclaration") {
2044
+ const declaration = node.declarations[0];
2045
+ if (declaration?.init) {
2046
+ let call = declaration?.init;
2047
+ while (call.type === "MemberExpression") call = call.object;
2048
+ if (call.type === "CallExpression" && call.callee.type === "Identifier") return call.callee.name === "require";
2049
+ }
2050
+ }
2051
+ return false;
2052
+ }
2053
+ /**
2054
+ * Checks whether the given node is a block-like statement.
2055
+ * This checks the last token of the node is the closing brace of a block.
2056
+ * @param sourceCode The source code to get tokens.
2057
+ * @param node The node to check.
2058
+ * @returns `true` if the node is a block-like statement.
2059
+ * @private
2060
+ */
2061
+ function isBlockLikeStatement(node, sourceCode) {
2062
+ if (node.type === "DoWhileStatement" && node.body.type === "BlockStatement") return true;
2063
+ /**
2064
+ * IIFE is a block-like statement specially from
2065
+ * JSCS#disallowPaddingNewLinesAfterBlocks.
2066
+ */
2067
+ if (isIIFEStatement(node)) return true;
2068
+ const lastToken = sourceCode.getLastToken(node, isNotSemicolonToken);
2069
+ const belongingNode = lastToken && isClosingBraceToken(lastToken) ? sourceCode.getNodeByRangeIndex(lastToken.range[0]) : null;
2070
+ return !!belongingNode && (belongingNode.type === "BlockStatement" || belongingNode.type === "SwitchStatement");
2071
+ }
2072
+ /**
2073
+ * Check whether the given node is a directive or not.
2074
+ * @param node The node to check.
2075
+ * @param sourceCode The source code object to get tokens.
2076
+ * @returns `true` if the node is a directive.
2077
+ */
2078
+ function isDirective(node, sourceCode) {
2079
+ return isTopLevelExpressionStatement(node) && node.expression.type === "Literal" && typeof node.expression.value === "string" && !isParenthesized(node.expression, sourceCode);
2080
+ }
2081
+ /**
2082
+ * Check whether the given node is a part of directive prologue or not.
2083
+ * @param node The node to check.
2084
+ * @param sourceCode The source code object to get tokens.
2085
+ * @returns `true` if the node is a part of directive prologue.
2086
+ */
2087
+ function isDirectivePrologue(node, sourceCode) {
2088
+ if (isDirective(node, sourceCode) && node.parent && "body" in node.parent && Array.isArray(node.parent.body)) {
2089
+ for (const sibling of node.parent.body) {
2090
+ if (sibling === node) break;
2091
+ if (!isDirective(sibling, sourceCode)) return false;
2092
+ }
2093
+ return true;
2094
+ }
2095
+ return false;
2096
+ }
2097
+ /**
2098
+ * Checks the given node is a CommonJS export statement
2099
+ * @param node The node to check.
2100
+ * @returns `true` if the node is a CommonJS export statement.
2101
+ * @private
2102
+ */
2103
+ function isCJSExport(node) {
2104
+ if (node.type === "ExpressionStatement") {
2105
+ const expression = node.expression;
2106
+ if (expression.type === "AssignmentExpression") {
2107
+ let left = expression.left;
2108
+ if (left.type === "MemberExpression") {
2109
+ while (left.object.type === "MemberExpression") left = left.object;
2110
+ return left.object.type === "Identifier" && (left.object.name === "exports" || left.object.name === "module" && left.property.type === "Identifier" && left.property.name === "exports");
2111
+ }
2112
+ }
2113
+ }
2114
+ return false;
2115
+ }
2116
+ /**
2117
+ * Check whether the given node is an expression
2118
+ * @param node The node to check.
2119
+ * @param sourceCode The source code object to get tokens.
2120
+ * @returns `true` if the node is an expression
2121
+ */
2122
+ function isExpression(node, sourceCode) {
2123
+ return node.type === "ExpressionStatement" && !isDirectivePrologue(node, sourceCode);
2124
+ }
2125
+ /**
2126
+ * Gets the actual last token.
2127
+ *
2128
+ * If a semicolon is semicolon-less style's semicolon, this ignores it.
2129
+ * For example:
2130
+ *
2131
+ * foo()
2132
+ * ;[1, 2, 3].forEach(bar)
2133
+ * @param sourceCode The source code to get tokens.
2134
+ * @param node The node to get.
2135
+ * @returns The actual last token.
2136
+ * @private
2137
+ */
2138
+ function getActualLastToken(node, sourceCode) {
2139
+ const semiToken = sourceCode.getLastToken(node);
2140
+ const prevToken = sourceCode.getTokenBefore(semiToken);
2141
+ const nextToken = sourceCode.getTokenAfter(semiToken);
2142
+ return prevToken && nextToken && prevToken.range[0] >= node.range[0] && isSemicolonToken(semiToken) && !isTokenOnSameLine(prevToken, semiToken) && isTokenOnSameLine(semiToken, nextToken) ? prevToken : semiToken;
2143
+ }
2144
+ /**
2145
+ * This returns the concatenation of the first 2 captured strings.
2146
+ * @param _ Unused. Whole matched string.
2147
+ * @param trailingSpaces The trailing spaces of the first line.
2148
+ * @param indentSpaces The indentation spaces of the last line.
2149
+ * @returns The concatenation of trailingSpaces and indentSpaces.
2150
+ * @private
2151
+ */
2152
+ function replacerToRemovePaddingLines(_, trailingSpaces, indentSpaces) {
2153
+ return trailingSpaces + indentSpaces;
2154
+ }
2155
+ function getReportLoc(node, sourceCode) {
2156
+ if (isSingleLine(node)) return node.loc;
2157
+ const line = node.loc.start.line;
2158
+ const sourceLine = sourceCode.lines[line - 1];
2159
+ if (sourceLine === void 0) throw new Error("Padding rule invariant: statement source line is missing");
2160
+ return {
2161
+ start: node.loc.start,
2162
+ end: {
2163
+ line,
2164
+ column: sourceLine.length
2165
+ }
2166
+ };
2167
+ }
2168
+ /**
2169
+ * Check and report statements for `any` configuration.
2170
+ * It does nothing.
2171
+ *
2172
+ * @private
2173
+ */
2174
+ function verifyForAny() {}
2175
+ /**
2176
+ * Check and report statements for `never` configuration.
2177
+ * This autofix removes blank lines between the given 2 statements.
2178
+ * However, if comments exist between 2 blank lines, it does not remove those
2179
+ * blank lines automatically.
2180
+ * @param context The rule context to report.
2181
+ * @param _ Unused. The previous node to check.
2182
+ * @param nextNode The next node to check.
2183
+ * @param paddingLines The array of token pairs that blank
2184
+ * lines exist between the pair.
2185
+ *
2186
+ * @private
2187
+ */
2188
+ function verifyForNever(context, _, nextNode, paddingLines) {
2189
+ if (paddingLines.length === 0) return;
2190
+ context.report({
2191
+ node: nextNode,
2192
+ messageId: "unexpectedBlankLine",
2193
+ loc: getReportLoc(nextNode, context.sourceCode),
2194
+ fix(fixer) {
2195
+ if (paddingLines.length >= 2) return null;
2196
+ const paddingPair = paddingLines[0];
2197
+ if (paddingPair === void 0) throw new Error("Padding rule invariant: reported padding pair is missing");
2198
+ const [prevToken, nextToken] = paddingPair;
2199
+ const start = prevToken.range[1];
2200
+ const end = nextToken.range[0];
2201
+ const text = context.sourceCode.text.slice(start, end).replace(PADDING_LINE_SEQUENCE, replacerToRemovePaddingLines);
2202
+ return fixer.replaceTextRange([start, end], text);
2203
+ }
2204
+ });
2205
+ }
2206
+ /**
2207
+ * Check and report statements for `always` configuration.
2208
+ * This autofix inserts a blank line between the given 2 statements.
2209
+ * If the `prevNode` has trailing comments, it inserts a blank line after the
2210
+ * trailing comments.
2211
+ * @param context The rule context to report.
2212
+ * @param prevNode The previous node to check.
2213
+ * @param nextNode The next node to check.
2214
+ * @param paddingLines The array of token pairs that blank
2215
+ * lines exist between the pair.
2216
+ *
2217
+ * @private
2218
+ */
2219
+ function verifyForAlways(context, prevNode, nextNode, paddingLines) {
2220
+ if (paddingLines.length > 0) return;
2221
+ context.report({
2222
+ node: nextNode,
2223
+ messageId: "expectedBlankLine",
2224
+ loc: getReportLoc(nextNode, context.sourceCode),
2225
+ fix(fixer) {
2226
+ const sourceCode = context.sourceCode;
2227
+ let prevToken = getActualLastToken(prevNode, sourceCode);
2228
+ const nextToken = sourceCode.getFirstTokenBetween(prevToken, nextNode, {
2229
+ includeComments: true,
2230
+ /**
2231
+ * Skip the trailing comments of the previous node.
2232
+ * This inserts a blank line after the last trailing comment.
2233
+ *
2234
+ * For example:
2235
+ *
2236
+ * foo(); // trailing comment.
2237
+ * // comment.
2238
+ * bar();
2239
+ *
2240
+ * Get fixed to:
2241
+ *
2242
+ * foo(); // trailing comment.
2243
+ *
2244
+ * // comment.
2245
+ * bar();
2246
+ * @param token The token to check.
2247
+ * @returns `true` if the token is not a trailing comment.
2248
+ * @private
2249
+ */
2250
+ filter(token) {
2251
+ if (isTokenOnSameLine(prevToken, token)) {
2252
+ prevToken = token;
2253
+ return false;
2254
+ }
2255
+ return true;
2256
+ }
2257
+ }) || nextNode;
2258
+ const insertText = isTokenOnSameLine(prevToken, nextToken) ? "\n\n" : "\n";
2259
+ return fixer.insertTextAfter(prevToken, insertText);
2260
+ }
2261
+ });
2262
+ }
2263
+ /**
2264
+ * Types of blank lines.
2265
+ * `any`, `never`, and `always` are defined.
2266
+ * Those have `verify` method to check and report statements.
2267
+ * @private
2268
+ */
2269
+ const PaddingTypes = {
2270
+ any: { verify: verifyForAny },
2271
+ never: { verify: verifyForNever },
2272
+ always: { verify: verifyForAlways }
2273
+ };
2274
+ const MaybeMultilineStatementType = {
2275
+ "block-like": { test: isBlockLikeStatement },
2276
+ "expression": { test: isExpression },
2277
+ "return": newKeywordTester("ReturnStatement", "return"),
2278
+ "export": newKeywordTester([
2279
+ "ExportAllDeclaration",
2280
+ "ExportDefaultDeclaration",
2281
+ "ExportNamedDeclaration"
2282
+ ], "export"),
2283
+ "var": newKeywordTester("VariableDeclaration", "var"),
2284
+ "let": newKeywordTester("VariableDeclaration", "let"),
2285
+ "const": newKeywordTester("VariableDeclaration", "const"),
2286
+ "using": { test: (node) => node.type === "VariableDeclaration" && (node.kind === "using" || node.kind === "await using") },
2287
+ "type": newKeywordTester("TSTypeAliasDeclaration", "type")
2288
+ };
2289
+ /**
2290
+ * Types of statements.
2291
+ * Those have `test` method to check it matches to the given statement.
2292
+ * @private
2293
+ */
2294
+ const StatementTypes = {
2295
+ "*": { test: () => true },
2296
+ "exports": { test: isCJSExport },
2297
+ "require": { test: isCJSRequire },
2298
+ "directive": { test: isDirectivePrologue },
2299
+ "iife": { test: isIIFEStatement },
2300
+ "block": newNodeTypeTester("BlockStatement"),
2301
+ "empty": newNodeTypeTester("EmptyStatement"),
2302
+ "function": newNodeTypeTester("FunctionDeclaration"),
2303
+ "ts-method": newNodeTypeTester("TSMethodSignature"),
2304
+ "break": newKeywordTester("BreakStatement", "break"),
2305
+ "case": newKeywordTester("SwitchCase", "case"),
2306
+ "class": newKeywordTester("ClassDeclaration", "class"),
2307
+ "continue": newKeywordTester("ContinueStatement", "continue"),
2308
+ "debugger": newKeywordTester("DebuggerStatement", "debugger"),
2309
+ "default": newKeywordTester(["SwitchCase", "ExportDefaultDeclaration"], "default"),
2310
+ "do": newKeywordTester("DoWhileStatement", "do"),
2311
+ "for": newKeywordTester([
2312
+ "ForStatement",
2313
+ "ForInStatement",
2314
+ "ForOfStatement"
2315
+ ], "for"),
2316
+ "if": newKeywordTester("IfStatement", "if"),
2317
+ "import": newKeywordTester("ImportDeclaration", "import"),
2318
+ "switch": newKeywordTester("SwitchStatement", "switch"),
2319
+ "throw": newKeywordTester("ThrowStatement", "throw"),
2320
+ "try": newKeywordTester("TryStatement", "try"),
2321
+ "while": newKeywordTester(["WhileStatement", "DoWhileStatement"], "while"),
2322
+ "with": newKeywordTester("WithStatement", "with"),
2323
+ "cjs-export": { test: (node, sourceCode) => node.type === "ExpressionStatement" && node.expression.type === "AssignmentExpression" && CJS_EXPORT.test(sourceCode.getText(node.expression.left)) },
2324
+ "cjs-import": { test: (node, sourceCode) => node.type === "VariableDeclaration" && node.declarations.length > 0 && node.declarations[0]?.init != null && CJS_IMPORT.test(sourceCode.getText(node.declarations[0].init)) },
2325
+ "enum": newKeywordTester("TSEnumDeclaration", "enum"),
2326
+ "interface": newKeywordTester("TSInterfaceDeclaration", "interface"),
2327
+ "function-overload": newNodeTypeTester("TSDeclareFunction"),
2328
+ ...Object.fromEntries(Object.entries(MaybeMultilineStatementType).flatMap(([key, value]) => [
2329
+ [key, value],
2330
+ [`singleline-${key}`, {
2331
+ ...value,
2332
+ test: (node, sourceCode) => value.test(node, sourceCode) && isSingleLine(node)
2333
+ }],
2334
+ [`multiline-${key}`, {
2335
+ ...value,
2336
+ test: (node, sourceCode) => value.test(node, sourceCode) && !isSingleLine(node)
2337
+ }]
2338
+ ]))
2339
+ };
2340
+ /**
2341
+ * Build the vendored padding rule with caller-owned, typed policy options.
2342
+ * `statementTypes` registers caller-defined statement types, looked up before
2343
+ * the upstream table, for syntax the upstream matchers do not distinguish.
2344
+ */
2345
+ function createPaddingLineRule(options, statementTypes) {
2346
+ const customStatementTypes = statementTypes ?? {};
2347
+ return {
2348
+ meta: {
2349
+ type: "layout",
2350
+ docs: { description: "Require or disallow padding lines between statements" },
2351
+ fixable: "whitespace",
2352
+ hasSuggestions: false,
2353
+ schema: {
2354
+ $defs: {
2355
+ paddingType: {
2356
+ type: "string",
2357
+ enum: Object.keys(PaddingTypes)
2358
+ },
2359
+ statementType: {
2360
+ type: "string",
2361
+ enum: Object.keys(StatementTypes)
2362
+ },
2363
+ selectorOption: {
2364
+ type: "object",
2365
+ properties: {
2366
+ selector: { type: "string" },
2367
+ lineMode: {
2368
+ type: "string",
2369
+ enum: [
2370
+ "any",
2371
+ "singleline",
2372
+ "multiline"
2373
+ ]
2374
+ }
2375
+ },
2376
+ required: ["selector"],
2377
+ additionalProperties: false
2378
+ },
2379
+ statementMatcher: { anyOf: [{ $ref: "#/$defs/statementType" }, { $ref: "#/$defs/selectorOption" }] },
2380
+ statementOption: { anyOf: [{ $ref: "#/$defs/statementMatcher" }, {
2381
+ type: "array",
2382
+ items: { $ref: "#/$defs/statementMatcher" },
2383
+ minItems: 1,
2384
+ uniqueItems: true,
2385
+ additionalItems: false
2386
+ }] }
2387
+ },
2388
+ type: "array",
2389
+ additionalItems: false,
2390
+ items: {
2391
+ type: "object",
2392
+ properties: {
2393
+ blankLine: { $ref: "#/$defs/paddingType" },
2394
+ prev: { $ref: "#/$defs/statementOption" },
2395
+ next: { $ref: "#/$defs/statementOption" }
2396
+ },
2397
+ additionalProperties: false,
2398
+ required: [
2399
+ "blankLine",
2400
+ "prev",
2401
+ "next"
2402
+ ]
2403
+ }
2404
+ },
2405
+ messages: {
2406
+ unexpectedBlankLine: "Unexpected blank line before this statement.",
2407
+ expectedBlankLine: "Expected blank line before this statement."
2408
+ }
2409
+ },
2410
+ create(context) {
2411
+ const sourceCode = context.sourceCode;
2412
+ const selectorMatchedNodes = /* @__PURE__ */ new Map();
2413
+ const pendingPairs = [];
2414
+ function collectSelectorOption(option) {
2415
+ if (Array.isArray(option)) {
2416
+ for (const item of option) collectSelectorOption(item);
2417
+ return;
2418
+ }
2419
+ if (!isSelectorOption(option)) return;
2420
+ selectorMatchedNodes.set(option.selector, /* @__PURE__ */ new Set());
2421
+ }
2422
+ for (const configure of options) {
2423
+ collectSelectorOption(configure.prev);
2424
+ collectSelectorOption(configure.next);
2425
+ }
2426
+ let scopeInfo = null;
2427
+ /**
2428
+ * Processes to enter to new scope.
2429
+ * This manages the current previous statement.
2430
+ *
2431
+ * @private
2432
+ */
2433
+ function enterScope() {
2434
+ scopeInfo = {
2435
+ upper: scopeInfo,
2436
+ prevNode: null
2437
+ };
2438
+ }
2439
+ /**
2440
+ * Processes to exit from the current scope.
2441
+ *
2442
+ * @private
2443
+ */
2444
+ function exitScope() {
2445
+ if (scopeInfo) scopeInfo = scopeInfo.upper;
2446
+ }
2447
+ /**
2448
+ * Checks whether the given node matches the given type.
2449
+ * @param node The statement node to check.
2450
+ * @param type The statement type to check.
2451
+ * @returns `true` if the statement node matched the type.
2452
+ * @private
2453
+ */
2454
+ function match(node, type) {
2455
+ let innerStatementNode = node;
2456
+ while (innerStatementNode.type === "LabeledStatement") innerStatementNode = innerStatementNode.body;
2457
+ if (Array.isArray(type)) return type.some(match.bind(null, innerStatementNode));
2458
+ if (isSelectorOption(type)) {
2459
+ if (!selectorMatchedNodes.get(type.selector)?.has(innerStatementNode)) return false;
2460
+ const lineMode = type.lineMode;
2461
+ if (lineMode === "singleline") return isSingleLine(innerStatementNode);
2462
+ else if (lineMode === "multiline") return !isSingleLine(innerStatementNode);
2463
+ return true;
2464
+ } else {
2465
+ const statementType = customStatementTypes[type] ?? StatementTypes[type];
2466
+ if (statementType === void 0) throw new Error(`Padding rule invariant: unsupported statement type ${type}`);
2467
+ return statementType.test(innerStatementNode, sourceCode);
2468
+ }
2469
+ }
2470
+ /**
2471
+ * Finds the last matched configure from options.
2472
+ * @param prevNode The previous statement to match.
2473
+ * @param nextNode The current statement to match.
2474
+ * @returns The tester of the last matched configure.
2475
+ * @private
2476
+ */
2477
+ function getPaddingType(prevNode, nextNode) {
2478
+ for (let i = options.length - 1; i >= 0; --i) {
2479
+ const configure = options[i];
2480
+ if (configure === void 0) throw new Error("Padding rule invariant: configuration entry is missing");
2481
+ if (match(prevNode, configure.prev) && match(nextNode, configure.next)) return PaddingTypes[configure.blankLine];
2482
+ }
2483
+ return PaddingTypes.any;
2484
+ }
2485
+ /**
2486
+ * Gets padding line sequences between the given 2 statements.
2487
+ * Comments are separators of the padding line sequences.
2488
+ * @param prevNode The previous statement to count.
2489
+ * @param nextNode The current statement to count.
2490
+ * @returns The array of token pairs.
2491
+ * @private
2492
+ */
2493
+ function getPaddingLineSequences(prevNode, nextNode) {
2494
+ const pairs = [];
2495
+ let prevToken = getActualLastToken(prevNode, sourceCode);
2496
+ if (nextNode.loc.start.line - prevToken.loc.end.line >= 2) do {
2497
+ const token = sourceCode.getTokenAfter(prevToken, { includeComments: true });
2498
+ if (token.loc.start.line - prevToken.loc.end.line >= 2) pairs.push([prevToken, token]);
2499
+ prevToken = token;
2500
+ } while (prevToken.range[0] < nextNode.range[0]);
2501
+ return pairs;
2502
+ }
2503
+ /**
2504
+ * Verify padding lines between the given node and the previous node.
2505
+ * @param node The node to verify.
2506
+ *
2507
+ * @private
2508
+ */
2509
+ function verify(node) {
2510
+ if (!node.parent || ![
2511
+ "BlockStatement",
2512
+ "Program",
2513
+ "StaticBlock",
2514
+ "SwitchCase",
2515
+ "SwitchStatement",
2516
+ "TSInterfaceBody",
2517
+ "TSModuleBlock",
2518
+ "TSTypeLiteral"
2519
+ ].includes(node.parent.type)) return;
2520
+ const prevNode = scopeInfo.prevNode;
2521
+ if (prevNode) pendingPairs.push({
2522
+ prevNode,
2523
+ nextNode: node
2524
+ });
2525
+ scopeInfo.prevNode = node;
2526
+ }
2527
+ function verifyPendingPairs() {
2528
+ for (const { prevNode, nextNode } of pendingPairs) {
2529
+ const type = getPaddingType(prevNode, nextNode);
2530
+ const paddingLines = getPaddingLineSequences(prevNode, nextNode);
2531
+ type.verify(context, prevNode, nextNode, paddingLines);
2532
+ }
2533
+ }
2534
+ /**
2535
+ * Verify padding lines between the given node and the previous node.
2536
+ * Then process to enter to new scope.
2537
+ * @param node The node to verify.
2538
+ *
2539
+ * @private
2540
+ */
2541
+ function verifyThenEnterScope(node) {
2542
+ verify(node);
2543
+ enterScope();
2544
+ }
2545
+ return {
2546
+ "Program": enterScope,
2547
+ "Program:exit": () => {
2548
+ verifyPendingPairs();
2549
+ exitScope();
2550
+ },
2551
+ "BlockStatement": enterScope,
2552
+ "BlockStatement:exit": exitScope,
2553
+ "SwitchStatement": enterScope,
2554
+ "SwitchStatement:exit": exitScope,
2555
+ "SwitchCase": verifyThenEnterScope,
2556
+ "SwitchCase:exit": exitScope,
2557
+ "StaticBlock": enterScope,
2558
+ "StaticBlock:exit": exitScope,
2559
+ "TSInterfaceBody": enterScope,
2560
+ "TSInterfaceBody:exit": exitScope,
2561
+ "TSModuleBlock": enterScope,
2562
+ "TSModuleBlock:exit": exitScope,
2563
+ "TSTypeLiteral": enterScope,
2564
+ "TSTypeLiteral:exit": exitScope,
2565
+ "TSDeclareFunction": verifyThenEnterScope,
2566
+ "TSDeclareFunction:exit": exitScope,
2567
+ "TSMethodSignature": verifyThenEnterScope,
2568
+ "TSMethodSignature:exit": exitScope,
2569
+ ":statement": verify,
2570
+ ...Object.fromEntries(Array.from(selectorMatchedNodes.keys(), (selector) => [selector, (node) => {
2571
+ selectorMatchedNodes.get(selector)?.add(node);
2572
+ }]))
2573
+ };
2574
+ }
2575
+ };
2576
+ }
2577
+ //#endregion
2578
+ //#region src/rules/require-readable-spacing.ts
2579
+ /** A `const`/`let`/`var`/`using` declaration, optionally exported, written on one line. */
2580
+ function isSinglelineBinding(node) {
2581
+ return (node.type === "ExportNamedDeclaration" ? node.declaration : node)?.type === "VariableDeclaration" && node.loc.start.line === node.loc.end.line;
2582
+ }
2583
+ /** Comments above a statement belong to it; a comment trailing the previous line does not. */
2584
+ function hasLeadingComment(node, sourceCode) {
2585
+ const previousLine = sourceCode.getTokenBefore(node)?.loc.end.line;
2586
+ return sourceCode.getCommentsBefore(node).some((comment) => comment.loc.start.line !== previousLine);
2587
+ }
2588
+ const paddingRule = createPaddingLineRule([
2589
+ {
2590
+ blankLine: "always",
2591
+ prev: "import",
2592
+ next: "*"
2593
+ },
2594
+ {
2595
+ blankLine: "always",
2596
+ prev: "*",
2597
+ next: { selector: "Program > :not(ImportDeclaration)" }
2598
+ },
2599
+ {
2600
+ blankLine: "always",
2601
+ prev: { selector: "Program > :not(ImportDeclaration)" },
2602
+ next: "*"
2603
+ },
2604
+ {
2605
+ blankLine: "always",
2606
+ prev: "*",
2607
+ next: [
2608
+ "function",
2609
+ "class",
2610
+ "interface",
2611
+ "type"
2612
+ ]
2613
+ },
2614
+ {
2615
+ blankLine: "always",
2616
+ prev: [
2617
+ "function",
2618
+ "class",
2619
+ "interface",
2620
+ "type"
2621
+ ],
2622
+ next: "*"
2623
+ },
2624
+ {
2625
+ blankLine: "always",
2626
+ prev: "*",
2627
+ next: [
2628
+ "multiline-const",
2629
+ "multiline-let",
2630
+ "multiline-var",
2631
+ "multiline-using"
2632
+ ]
2633
+ },
2634
+ {
2635
+ blankLine: "always",
2636
+ prev: [
2637
+ "multiline-const",
2638
+ "multiline-let",
2639
+ "multiline-var",
2640
+ "multiline-using"
2641
+ ],
2642
+ next: "*"
2643
+ },
2644
+ {
2645
+ blankLine: "always",
2646
+ prev: "*",
2647
+ next: [
2648
+ "return",
2649
+ "if",
2650
+ "switch",
2651
+ "try",
2652
+ "for",
2653
+ "while",
2654
+ "do"
2655
+ ]
2656
+ },
2657
+ {
2658
+ blankLine: "always",
2659
+ prev: "block-like",
2660
+ next: "*"
2661
+ },
2662
+ {
2663
+ blankLine: "any",
2664
+ prev: "import",
2665
+ next: "import"
2666
+ },
2667
+ {
2668
+ blankLine: "any",
2669
+ prev: "singleline-binding",
2670
+ next: "undocumented-singleline-binding"
2671
+ },
2672
+ {
2673
+ blankLine: "any",
2674
+ prev: { selector: ":matches(TSDeclareFunction, ExportNamedDeclaration[declaration.type=\"TSDeclareFunction\"])" },
2675
+ next: { selector: ":matches(TSDeclareFunction, FunctionDeclaration, ExportNamedDeclaration[declaration.type=\"TSDeclareFunction\"], ExportNamedDeclaration[declaration.type=\"FunctionDeclaration\"])" }
2676
+ }
2677
+ ], {
2678
+ "singleline-binding": { test: (node) => isSinglelineBinding(node) },
2679
+ "undocumented-singleline-binding": { test: (node, sourceCode) => isSinglelineBinding(node) && !hasLeadingComment(node, sourceCode) }
2680
+ });
2681
+ /** Restore structural blank lines with whitespace-only fixes; keep single-line binding groups and overloads grouped. */
2682
+ const requireReadableSpacingRule = {
2683
+ ...paddingRule,
2684
+ meta: {
2685
+ ...paddingRule.meta,
2686
+ docs: { description: "Require readable spacing between declarations and logical statement groups." },
2687
+ schema: []
2688
+ }
2689
+ };
2690
+ //#endregion
1768
2691
  //#region src/rules/require-safety-comment-for-type-assertion.ts
1769
2692
  const DEFAULT_SAFETY_MARKERS = ["SAFETY"];
1770
2693
  const commentOwnerKinds = /* @__PURE__ */ new Set([
@@ -1809,6 +2732,8 @@ function hasSafetyComment(sourceCode, node, pattern) {
1809
2732
  const antiSlopPlugin = eslintCompatPlugin({
1810
2733
  meta: { name: "anti-slop" },
1811
2734
  rules: {
2735
+ "no-array-filter-map": noArrayFilterMapRule,
2736
+ "no-reduce-accumulator-copy": noReduceAccumulatorCopyRule,
1812
2737
  "no-chained-type-assertions": noChainedTypeAssertionsRule,
1813
2738
  "no-conditional-empty-object-spread": noConditionalEmptyObjectSpreadRule,
1814
2739
  "no-known-value-widening": noKnownValueWideningRule,
@@ -1823,6 +2748,7 @@ const antiSlopPlugin = eslintCompatPlugin({
1823
2748
  "no-unknown-returns": noUnknownReturnsRule,
1824
2749
  "no-unknown-type-aliases": noUnknownTypeAliasesRule,
1825
2750
  "no-widen-then-assert": noWidenThenAssertRule,
2751
+ "require-readable-spacing": requireReadableSpacingRule,
1826
2752
  "require-safety-comment-for-type-assertion": defineRule({
1827
2753
  meta: {
1828
2754
  type: "problem",