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