paperlint 19.0.0 → 19.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (75) hide show
  1. package/.claude-plugin/plugin.json +1 -1
  2. package/CLAUDE.md +2 -2
  3. package/dist/adapters/eslint/index.d.ts +13 -0
  4. package/dist/adapters/eslint/index.d.ts.map +1 -0
  5. package/dist/adapters/eslint/index.js +44 -0
  6. package/dist/adapters/eslint/index.js.map +1 -0
  7. package/dist/adapters/eslint/report.io.d.ts +15 -0
  8. package/dist/adapters/eslint/report.io.d.ts.map +1 -0
  9. package/dist/adapters/eslint/report.io.js +48 -0
  10. package/dist/adapters/eslint/report.io.js.map +1 -0
  11. package/dist/cli.d.ts +7 -12
  12. package/dist/cli.d.ts.map +1 -1
  13. package/dist/cli.js +80 -121
  14. package/dist/cli.js.map +1 -1
  15. package/dist/domain/submission-lint.d.ts +29 -0
  16. package/dist/domain/submission-lint.d.ts.map +1 -0
  17. package/dist/domain/submission-lint.js +84 -0
  18. package/dist/domain/submission-lint.js.map +1 -0
  19. package/dist/folder-layout-hook.js +1 -1
  20. package/dist/hooks-notice.d.ts +2 -0
  21. package/dist/hooks-notice.d.ts.map +1 -1
  22. package/dist/hooks-notice.js +4 -1
  23. package/dist/hooks-notice.js.map +1 -1
  24. package/dist/ports/submission-lint.d.ts +6 -0
  25. package/dist/ports/submission-lint.d.ts.map +1 -0
  26. package/dist/ports/submission-lint.js +2 -0
  27. package/dist/ports/submission-lint.js.map +1 -0
  28. package/dist/structure.d.ts +17 -1
  29. package/dist/structure.d.ts.map +1 -1
  30. package/dist/structure.js.map +1 -1
  31. package/dist/submission-confirm-hook.d.ts +8 -1
  32. package/dist/submission-confirm-hook.d.ts.map +1 -1
  33. package/dist/submission-confirm-hook.js +75 -20
  34. package/dist/submission-confirm-hook.js.map +1 -1
  35. package/dist/submission.d.ts +5 -0
  36. package/dist/submission.d.ts.map +1 -1
  37. package/dist/submission.js +46 -7
  38. package/dist/submission.js.map +1 -1
  39. package/dist/types.d.ts +2 -0
  40. package/dist/types.d.ts.map +1 -1
  41. package/docs/install.md +4 -4
  42. package/docs/layout.md +0 -1
  43. package/docs/submission.md +19 -8
  44. package/eslint.config.mjs +2 -0
  45. package/hooks/hooks.harness.ts +2 -140
  46. package/hooks/paper-skills-nudge.hook.mjs +0 -6
  47. package/lib/paper-config.harness.mjs +1 -2
  48. package/package.json +1 -1
  49. package/plugin/hooks/hooks.json +0 -9
  50. package/scripts/eslint-file-length.mjs +117 -0
  51. package/src/adapters/eslint/index.test.ts +152 -0
  52. package/src/adapters/eslint/index.ts +89 -0
  53. package/src/adapters/eslint/report.io.ts +82 -0
  54. package/src/cli.harness.mjs +9 -8
  55. package/src/cli.test.ts +4 -4
  56. package/src/cli.ts +110 -144
  57. package/src/domain/submission-lint.test.ts +211 -0
  58. package/src/domain/submission-lint.ts +166 -0
  59. package/src/folder-layout-hook.ts +1 -1
  60. package/src/hooks-notice.test.ts +2 -2
  61. package/src/hooks-notice.ts +10 -1
  62. package/src/hooks-settings.harness.ts +8 -8
  63. package/src/ports/submission-lint.ts +10 -0
  64. package/src/structure.ts +2 -4
  65. package/src/submission-confirm-hook-lint.test.ts +47 -0
  66. package/src/submission-confirm-hook.test.ts +73 -6
  67. package/src/submission-confirm-hook.ts +133 -28
  68. package/src/submission-fields-run.test.ts +1 -1
  69. package/src/submission-new.test.ts +4 -2
  70. package/src/submission-update.test.ts +16 -11
  71. package/src/submission.ts +62 -8
  72. package/src/types.ts +2 -0
  73. package/hooks/paper-status-gates.hook.mjs +0 -158
  74. package/hooks/paper-status-gates.sh +0 -93
  75. package/hooks/paper-status-gates.test.ts +0 -101
package/src/cli.ts CHANGED
@@ -56,7 +56,7 @@ import {
56
56
  paperBodies,
57
57
  type PaperBody,
58
58
  } from "./paper-includes.ts";
59
- import { hasAtLeast, omit } from "remeda";
59
+ import { hasAtLeast } from "remeda";
60
60
  import { refusalOf } from "./unowned-file.ts";
61
61
  import { ruleTimes, timingLines } from "./lint-timing.ts";
62
62
  import { prepareEngine } from "./build-engine.ts";
@@ -85,7 +85,6 @@ import {
85
85
  pageLimitRules,
86
86
  VENUE_RULE_LEVELS,
87
87
  venueRules,
88
- type VenueMessage,
89
88
  } from "./venue-rules.ts";
90
89
  import {
91
90
  FORMAT_RULE_LEVELS,
@@ -121,7 +120,17 @@ import { BIB_RULE_LEVELS, bibRules } from "./bib-rules.ts";
121
120
  import { bibliographyReader } from "./references.ts";
122
121
  import { onlineReferences } from "./adapters/references/index.ts";
123
122
  import { hotcrpSite } from "./adapters/hotcrp/index.ts";
124
- import { runSubmission } from "./submission.ts";
123
+ import { runSubmission, submissionSections } from "./submission.ts";
124
+ import {
125
+ LINT_FORMAT,
126
+ isEmptyLintSet,
127
+ lintExitCode,
128
+ lintResultFor,
129
+ lintText,
130
+ printLintResults,
131
+ submissionLinter,
132
+ } from "./adapters/eslint/index.ts";
133
+ export { lintText } from "./adapters/eslint/index.ts";
125
134
  import type { PortalKind, SupportedPortal } from "./domain/submission.ts";
126
135
  import type { PortalSite } from "./ports/submission-portal.ts";
127
136
  import type { CheckReferences } from "./ports/check-references.ts";
@@ -241,6 +250,7 @@ import {
241
250
  noticeText,
242
251
  notYetTold,
243
252
  recordTold,
253
+ hookNotRunningText,
244
254
  } from "./hooks-notice.ts";
245
255
  import { unwiredHooks } from "./hooks-settings.ts";
246
256
  import {
@@ -266,6 +276,7 @@ import {
266
276
  import {
267
277
  submissionConfirm,
268
278
  UNREADABLE_INPUT,
279
+ type Send,
269
280
  type Upload,
270
281
  } from "./submission-confirm-hook.ts";
271
282
  import { leafCommandsNormalized } from "vigiles/hook";
@@ -324,7 +335,7 @@ const USAGE = `paperlint — machine-checkable gates for a paper kept in git
324
335
  into ~/.cache/paperlint/texlive (PAPERLINT_TEXLIVE_DIR overrides); a second
325
336
  run does nothing. --check: report what is missing, change nothing
326
337
  npx paperlint doctor say what is actually wired — and what only LOOKS wired
327
- npx paperlint submission new [paper] [--abstract <file>] [--save]
338
+ npx paperlint submission new [paper] [--abstract <file>] [--save] [--allow-lint-errors <reason>]
328
339
  create the paper's submission on the venue's portal: the title
329
340
  and abstract from the build, the authors from paperlint.json,
330
341
  the PDF. A DRY RUN unless --save; a save records the new id in
@@ -335,6 +346,7 @@ const USAGE = `paperlint — machine-checkable gates for a paper kept in git
335
346
  whether it is the local paper.pdf (sha256); flags a title,
336
347
  abstract or authors that are not the paper's
337
348
  npx paperlint submission update [paper] [--pdf <file>] [--abstract <file>] [--submit] [--save]
349
+ [--allow-lint-errors <reason>]
338
350
  send the PDF (default: the paper's own), the paper's title
339
351
  and abstract each when the portal holds another (--abstract:
340
352
  that file's text instead), or "submitted". A DRY RUN unless --save: the portal checks the
@@ -425,6 +437,7 @@ submission:
425
437
  --pdf <file> the PDF to compare (show) or send (update) instead of the paper's own
426
438
  --abstract <file> new, update: a plain-text file whose text is sent as the abstract
427
439
  --submit update: mark the submission submitted
440
+ --allow-lint-errors <reason> permit reported lint errors on a submission --save
428
441
  --save new, update: really create or change the submission. Without it, nothing
429
442
  is saved
430
443
 
@@ -1329,6 +1342,7 @@ const STRING_FLAGS: ReadonlyMap<
1329
1342
  | "kind"
1330
1343
  | "pdf"
1331
1344
  | "abstract"
1345
+ | "allowLintErrors"
1332
1346
  | "url"
1333
1347
  | "host"
1334
1348
  | "to"
@@ -1340,6 +1354,7 @@ const STRING_FLAGS: ReadonlyMap<
1340
1354
  ["--kind", "kind"],
1341
1355
  ["--pdf", "pdf"],
1342
1356
  ["--abstract", "abstract"],
1357
+ ["--allow-lint-errors", "allowLintErrors"],
1343
1358
  ["--url", "url"],
1344
1359
  ["--host", "host"],
1345
1360
  ["--to", "to"],
@@ -1478,7 +1493,7 @@ const IN_PROCESS_HOOKS: Readonly<
1478
1493
  },
1479
1494
  // Never advisory-silent: an input it cannot read is refused, not let through.
1480
1495
  "submission-confirm": ({ stdin, out }) => {
1481
- const said = ((): ReturnType<typeof submissionConfirm> => {
1496
+ const said = (() => {
1482
1497
  try {
1483
1498
  return submissionConfirm(stdin(), {
1484
1499
  ...PRESET_DEPS,
@@ -1486,13 +1501,17 @@ const IN_PROCESS_HOOKS: Readonly<
1486
1501
  shellLeaves: leafCommandsNormalized,
1487
1502
  readSend: submissionSend,
1488
1503
  readUpload: uploadSend,
1504
+ lintPaper: lintSubmissionPaper,
1489
1505
  });
1490
1506
  } catch {
1491
1507
  return UNREADABLE_INPUT;
1492
1508
  }
1493
1509
  })();
1494
- if (said !== null) out(`${JSON.stringify(said)}\n`);
1495
- return 0;
1510
+ const write = (result: Awaited<typeof said>) => {
1511
+ if (result !== null) out(`${JSON.stringify(result)}\n`);
1512
+ return 0;
1513
+ };
1514
+ return said instanceof Promise ? said.then(write) : write(said);
1496
1515
  },
1497
1516
  };
1498
1517
 
@@ -1502,17 +1521,48 @@ const IN_PROCESS_HOOKS: Readonly<
1502
1521
  * (a flag missing its value, an unknown flag, a stray operand), so `submission-confirm` says it
1503
1522
  * cannot tell rather than guess.
1504
1523
  */
1505
- export function submissionSend(
1506
- words: readonly string[],
1507
- ): { readonly paper: string | null; readonly pdf: string | null } | null {
1524
+ export function submissionSend(words: readonly string[]): Send | null {
1508
1525
  const a = parseArgs(["submission", ...words]);
1509
1526
  const clean =
1510
1527
  a.missingValue === undefined &&
1511
1528
  a.unknownFlag === undefined &&
1512
1529
  a.paths.length <= 2;
1513
- return clean ? { paper: a.paths[1] ?? null, pdf: a.pdf } : null;
1530
+ return clean
1531
+ ? {
1532
+ paper: a.paths[1] ?? null,
1533
+ pdf: a.pdf,
1534
+ action:
1535
+ a.paths[0] === "new" ? "create" : a.submit ? "submit" : "update",
1536
+ allowLintErrors: a.allowLintErrors?.trim(),
1537
+ }
1538
+ : null;
1514
1539
  }
1515
1540
 
1541
+ const lintSubmissionPaper = submissionLinter(
1542
+ async (paperDir, cwd, accept) => {
1543
+ const stderr = collector();
1544
+ await run(["lint", paperDir], {
1545
+ cwd,
1546
+ log: () => {},
1547
+ err: (line: string) => {
1548
+ stderr.write(`${line}\n`);
1549
+ },
1550
+ onLintResults: (results, structure) => {
1551
+ accept([
1552
+ ...asEslintResults(structure).map((r) => ({
1553
+ ...r,
1554
+ filePath: resolve(cwd, r.filePath),
1555
+ })),
1556
+ ...results,
1557
+ ]);
1558
+ },
1559
+ });
1560
+ return firstLine(stderr.text());
1561
+ },
1562
+ (paperDir) =>
1563
+ submissionSections(paperDir, { ...RECORD_DEPS, latex: latexReader }),
1564
+ );
1565
+
1516
1566
  /**
1517
1567
  * The words after `artifact`, read by this CLI's own parser, for an upload: the file it uploads, the
1518
1568
  * paper (null for the current folder), and the host and project it goes to — or null when they would
@@ -1807,18 +1857,14 @@ function runHookPlain(
1807
1857
  readonly capture?: boolean;
1808
1858
  } = {},
1809
1859
  ): number | Promise<number> {
1810
- if (!name) {
1811
- err(`\`hook\` needs a name, e.g. \`paperlint hook paper-edit-guard\``);
1812
- return 2;
1813
- }
1814
- const inProcess = IN_PROCESS_HOOKS[name];
1860
+ const inProcess = IN_PROCESS_HOOKS[name ?? ""];
1815
1861
  if (inProcess !== undefined) return inProcess({ err, stdin, out });
1816
1862
  const program = fileURLToPath(
1817
- new URL(`../hooks/${name}.hook.mjs`, import.meta.url),
1863
+ new URL(`../hooks/${name ?? ""}.hook.mjs`, import.meta.url),
1818
1864
  );
1819
- if (!existsSync(program)) {
1820
- err(`unknown hook \`${name}\` — no such program at ${program}`);
1821
- return 2;
1865
+ if (!name || !existsSync(program)) {
1866
+ err(hookNotRunningText(name, program, packageVersion()));
1867
+ return 1; // not 2: that denies every Bash command, the fix included (#324); not 0: nobody sees it
1822
1868
  }
1823
1869
  let runtime;
1824
1870
  try {
@@ -1831,7 +1877,7 @@ function runHookPlain(
1831
1877
  `The \`${name}\` hook is NOT running. Everything else — \`paperlint lint\`, CI — is unaffected.\n` +
1832
1878
  `Reinstall this package so its dependencies are present.`,
1833
1879
  );
1834
- return 0;
1880
+ return 1; // not 2: that would deny every Bash command; not 0: nobody would see this
1835
1881
  }
1836
1882
  const args = [runtime, "hook-runtime", "run-program", program];
1837
1883
  const r =
@@ -2326,6 +2372,7 @@ const SIMPLE: Readonly<
2326
2372
  abstract: a.abstract,
2327
2373
  submit: a.submit,
2328
2374
  save: a.save,
2375
+ allowLintErrors: a.allowLintErrors ?? undefined,
2329
2376
  },
2330
2377
  {
2331
2378
  files: nodeFiles,
@@ -2336,6 +2383,7 @@ const SIMPLE: Readonly<
2336
2383
  latex: latexReader,
2337
2384
  codec: sourcesCodec,
2338
2385
  lintText,
2386
+ lintPaper: lintSubmissionPaper,
2339
2387
  yaml: parseYaml,
2340
2388
  now: isoNow,
2341
2389
  log,
@@ -2520,6 +2568,25 @@ const selfInstallDeps = (install: ProjectInstall): SelfInstallDeps => {
2520
2568
  const loadLatexLanguage = async (): Promise<unknown> =>
2521
2569
  (await import("#eslint-rules/latex-language")).texLanguage;
2522
2570
 
2571
+ type LintResults = (
2572
+ results: readonly ESLint.LintResult[],
2573
+ structure: Readonly<ReturnType<typeof checkStructure>>,
2574
+ ) => void;
2575
+
2576
+ /** A missing flag value must be reported before falling back to any default. */
2577
+ function argumentProblem(a: Args): string | null {
2578
+ if (a.missingValue)
2579
+ return (
2580
+ `${a.missingValue} needs a value — it was given none.\n` +
2581
+ `Without it the run would silently fall back to whatever config it discovers, which is not what the command line said.`
2582
+ );
2583
+ if (a.unknownFlag !== undefined)
2584
+ return `unknown flag \`${a.unknownFlag}\` — \`paperlint --help\` lists every flag`;
2585
+ return !a.help && a.cmd && a.cmd !== "submission" && a.allowLintErrors != null
2586
+ ? "--allow-lint-errors is only for submission new or update with --save"
2587
+ : null;
2588
+ }
2589
+
2523
2590
  export async function run(
2524
2591
  argv: readonly string[],
2525
2592
  {
@@ -2532,6 +2599,7 @@ export async function run(
2532
2599
  skillLinks = readSkillLinks,
2533
2600
  install = projectInstall,
2534
2601
  claude = claudeCode(),
2602
+ onLintResults,
2535
2603
  }: {
2536
2604
  log?: typeof console.log;
2537
2605
  err?: typeof console.error;
@@ -2554,26 +2622,12 @@ export async function run(
2554
2622
  checkReferences?: CheckReferences;
2555
2623
  /** The skills report `lint`'s stderr line reads; a test hands a fixed one. */
2556
2624
  skillLinks?: (root: string) => LinkReport;
2625
+ onLintResults?: LintResults;
2557
2626
  } = {},
2558
2627
  ): Promise<number> {
2559
2628
  const a = parseArgs(argv);
2560
- // The refusal must come FIRST: behind a flag without a value there is usually a typo, or a
2561
- // substitution in CI that collapsed into nothing, and any continuation works on something other
2562
- // than what was asked for.
2563
- if (a.missingValue) {
2564
- err(
2565
- `${a.missingValue} needs a value — it was given none.\n` +
2566
- `Without it the run would silently fall back to whatever config it discovers, which is ` +
2567
- `not what the command line said.`,
2568
- );
2569
- return 2;
2570
- }
2571
- if (a.unknownFlag !== undefined) {
2572
- err(
2573
- `unknown flag \`${a.unknownFlag}\` — \`paperlint --help\` lists every flag`,
2574
- );
2575
- return 2;
2576
- }
2629
+ const problem = argumentProblem(a);
2630
+ if (problem !== null) return (err(problem), 2);
2577
2631
  if (a.help || !a.cmd) {
2578
2632
  log(USAGE);
2579
2633
  return a.help ? 0 : 2;
@@ -2683,7 +2737,7 @@ export async function run(
2683
2737
  try {
2684
2738
  results = await eslint.lintFiles(paths);
2685
2739
  } catch (e) {
2686
- if (isEmptySet(e)) results = [];
2740
+ if (isEmptyLintSet(e)) results = [];
2687
2741
  else throw e;
2688
2742
  }
2689
2743
 
@@ -2713,6 +2767,7 @@ export async function run(
2713
2767
  .map((d) => join(d, MAIN))
2714
2768
  .filter((f) => existsSync(f)),
2715
2769
  bodies,
2770
+ onLintResults,
2716
2771
  });
2717
2772
  hooksLine(root, err, skillLinks, claude);
2718
2773
  // On stderr, so `--json` leaves stdout a clean array.
@@ -2833,25 +2888,11 @@ const editLinter =
2833
2888
  };
2834
2889
 
2835
2890
  /** A result of the hook's new errors, with the counts the formatter prints recomputed. */
2836
- const counted = (r: LintResult): Readonly<ESLint.LintResult> => ({
2837
- filePath: r.filePath,
2838
- // Only errors reach the formatter: the hook reports nothing else.
2839
- messages: r.messages.map((m) => ({
2840
- ruleId: m.ruleId,
2841
- message: m.message,
2842
- line: m.line,
2843
- column: m.column,
2844
- endLine: m.endLine,
2845
- severity: 2,
2846
- })),
2847
- suppressedMessages: [],
2848
- errorCount: r.messages.length,
2849
- fatalErrorCount: 0,
2850
- warningCount: 0,
2851
- fixableErrorCount: 0,
2852
- fixableWarningCount: 0,
2853
- usedDeprecatedRules: [],
2854
- });
2891
+ const counted = (r: LintResult): Readonly<ESLint.LintResult> =>
2892
+ lintResultFor(
2893
+ r.filePath,
2894
+ r.messages.map((m) => ({ ...m, severity: 2 })),
2895
+ );
2855
2896
 
2856
2897
  /**
2857
2898
  * The first path that is a FILE paperlint does not lint, or null. ESLint would answer such a file
@@ -2873,54 +2914,6 @@ async function firstUnownedFile(
2873
2914
  return null;
2874
2915
  }
2875
2916
 
2876
- /**
2877
- * ESLint's refusals of an empty set: nothing matched (`file-not-found`), or everything that matched
2878
- * is outside paperlint's scope (`all-matched-files-ignored` — a papers directory holding only
2879
- * vendored scripts). Both mean "nothing was linted", which the caller reports itself.
2880
- */
2881
- /** What a thrown ESLint error says about itself; anything else thrown says nothing. */
2882
- const EslintFailure = z
2883
- .object({
2884
- messageTemplate: z.string().optional(),
2885
- message: z.string().optional(),
2886
- })
2887
- .catch({});
2888
-
2889
- const isEmptySet = (e: unknown): boolean => {
2890
- const fail = EslintFailure.parse(e);
2891
- return (
2892
- fail.messageTemplate === "file-not-found" ||
2893
- fail.messageTemplate === "all-matched-files-ignored" ||
2894
- /No files matching/i.test(String(fail.message))
2895
- );
2896
- };
2897
-
2898
- /**
2899
- * Findings on one file, printed by the formatter `paperlint lint` prints with — what `paperlint
2900
- * submission` shows of the venue rules before a send, so the two read the same.
2901
- */
2902
- export async function lintText(
2903
- file: string,
2904
- messages: readonly VenueMessage[],
2905
- ): Promise<string> {
2906
- const errorCount = messages.filter((m) => m.severity === 2).length;
2907
- const result: Readonly<ESLint.LintResult> = {
2908
- filePath: file,
2909
- messages: [...messages],
2910
- suppressedMessages: [],
2911
- errorCount,
2912
- fatalErrorCount: 0,
2913
- warningCount: messages.length - errorCount,
2914
- fixableErrorCount: 0,
2915
- fixableWarningCount: 0,
2916
- usedDeprecatedRules: [],
2917
- };
2918
- return (await new ESLint().loadFormatter(LINT_FORMAT)).format([result]);
2919
- }
2920
-
2921
- /** The formatter `paperlint lint` prints with. */
2922
- const LINT_FORMAT = "stylish";
2923
-
2924
2917
  /** Printed under a clean `lint`, the README's disclaimer in one line. */
2925
2918
  const CLEAN_RUN_REMINDER =
2926
2919
  "Check the venue's own call before you submit: a call can change between editions, and a check can miss a case.";
@@ -2932,7 +2925,7 @@ const CLEAN_RUN_REMINDER =
2932
2925
  async function reportLint(
2933
2926
  eslint: ESLint,
2934
2927
  results: ESLint.LintResult[],
2935
- structure: ReturnType<typeof checkStructure>,
2928
+ structure: Readonly<ReturnType<typeof checkStructure>>,
2936
2929
  {
2937
2930
  a,
2938
2931
  log,
@@ -2941,6 +2934,7 @@ async function reportLint(
2941
2934
  opts,
2942
2935
  projectPapers,
2943
2936
  bodies,
2937
+ onLintResults,
2944
2938
  }: {
2945
2939
  a: Args;
2946
2940
  log: typeof console.log;
@@ -2950,6 +2944,7 @@ async function reportLint(
2950
2944
  projectPapers: readonly string[];
2951
2945
  /** The body files handed to ESLint, as read before the run. */
2952
2946
  bodies: readonly PaperBody[];
2947
+ onLintResults: LintResults | undefined;
2953
2948
  },
2954
2949
  ): Promise<number> {
2955
2950
  const silent = await silentOptionalRules(
@@ -2966,46 +2961,17 @@ async function reportLint(
2966
2961
  return 1;
2967
2962
  }
2968
2963
 
2969
- if (a.json)
2970
- log(
2971
- JSON.stringify(
2972
- [
2973
- ...asEslintResults(structure),
2974
- ...results.map((r) => omit(r, ["stats"])),
2975
- ],
2976
- null,
2977
- 1,
2978
- ),
2979
- );
2964
+ if (onLintResults !== undefined) onLintResults(results, structure);
2980
2965
  else {
2981
- // Missing things are printed FIRST: they explain why the report below may be suspiciously
2982
- // short. The reverse order would read as "all clean — oh, and also this".
2983
- if (structure.length > 0) log(formatStructure(structure));
2984
- const out = await (await eslint.loadFormatter(LINT_FORMAT)).format(results);
2985
- const clean = out.trim() === "" && structure.length === 0;
2986
- log(
2987
- out.trim() ||
2988
- (clean
2989
- ? `✓ ${String(results.length)} file(s) checked, no findings`
2990
- : ""),
2991
- );
2992
- // A clean run is the one result a reader could take as a guarantee, so it, and only it,
2993
- // carries the README's reminder. Findings speak for themselves; --json is for machines.
2966
+ const clean = await printLintResults(eslint, results, {
2967
+ json: a.json,
2968
+ structure: asEslintResults(structure),
2969
+ structureText: formatStructure(structure),
2970
+ log,
2971
+ });
2994
2972
  if (clean) log(` ${CLEAN_RUN_REMINDER}`);
2995
2973
  }
2996
- if (structure.length > 0 || results.some((r) => r.errorCount > 0)) return 1;
2997
- // Warnings fail the run only when the threshold is named EXPLICITLY. A negative threshold means
2998
- // "do not count them at all", and that is the default.
2999
- if (a.maxWarnings >= 0) {
3000
- const warnings = results.reduce((n, r) => n + r.warningCount, 0);
3001
- if (warnings > a.maxWarnings) {
3002
- err(
3003
- `${String(warnings)} warning(s) exceed the --max-warnings limit of ${String(a.maxWarnings)}`,
3004
- );
3005
- return 1;
3006
- }
3007
- }
3008
- return 0;
2974
+ return lintExitCode(results, structure.length > 0, a.maxWarnings, err);
3009
2975
  }
3010
2976
 
3011
2977
  // 🔴 `isMain`, NOT A STRING COMPARISON. The first version wrote
@@ -0,0 +1,211 @@
1
+ import { describe, expect, test } from "vitest";
2
+ import { latexReader } from "../adapters/latex/index.ts";
3
+ import { assemblePaper } from "./paper-source.ts";
4
+ import {
5
+ lintFindingLine,
6
+ lintReportLines,
7
+ submissionLint,
8
+ type LintFinding,
9
+ type PaperSections,
10
+ } from "./submission-lint.ts";
11
+ import type { Heading, Outline } from "./tex-document.ts";
12
+
13
+ test("warnings on the abstract include and introduction precede other findings", () => {
14
+ const tex = [
15
+ "\\documentclass{article}",
16
+ "\\begin{document}",
17
+ "\\input{summary}",
18
+ "\\section{Introduction and motivation}",
19
+ "Motivation.",
20
+ "\\section{Results}",
21
+ "The result.",
22
+ "\\end{document}",
23
+ ].join("\n");
24
+ const paper = assemblePaper("paper.tex", tex, {
25
+ includes: latexReader.includes,
26
+ documentBody: latexReader.documentBody,
27
+ read: (name) =>
28
+ name === "summary.tex"
29
+ ? "\\begin{abstract}\nSummary.\n\\end{abstract}\n"
30
+ : null,
31
+ });
32
+ const message = (
33
+ line: number,
34
+ severity: 1 | 2,
35
+ text: string,
36
+ ): LintFinding => ({
37
+ file: "paper.tex",
38
+ line,
39
+ column: 1,
40
+ severity,
41
+ ruleId: "tex/example",
42
+ message: text,
43
+ });
44
+ const findings = submissionLint(
45
+ [
46
+ message(7, 1, "Results warning"),
47
+ message(7, 2, "Results error"),
48
+ message(5, 1, "Introduction warning"),
49
+ message(3, 1, "Abstract warning"),
50
+ ],
51
+ {
52
+ paper,
53
+ abstract: latexReader.abstractSpan(paper.text),
54
+ outline: latexReader.outline(paper.text),
55
+ },
56
+ );
57
+ expect(lintReportLines(findings)).toStrictEqual([
58
+ "lint: 1 error, 3 warnings (abstract: 1, introduction: 1)",
59
+ "Abstract warnings",
60
+ " paper.tex:3:1 tex/example — Abstract warning",
61
+ "Introduction warnings",
62
+ " paper.tex:5:1 tex/example — Introduction warning",
63
+ "Lint errors",
64
+ " paper.tex:7:1 tex/example — Results error",
65
+ "Other lint warnings",
66
+ " paper.tex:7:1 tex/example — Results warning",
67
+ ]);
68
+ });
69
+
70
+ const sample = [
71
+ "\\section{Introduction}",
72
+ "intro text",
73
+ "\\section{Methods}",
74
+ "method text",
75
+ "\\bibliography{refs}",
76
+ "",
77
+ ].join("\n");
78
+ const offsetOfLine = (line: number): number =>
79
+ sample
80
+ .split("\n")
81
+ .slice(0, line - 1)
82
+ .reduce((n, text) => n + text.length + 1, 0);
83
+ const heading = (title: string, line: number): Heading => ({
84
+ title,
85
+ place: {
86
+ kind: "at",
87
+ span: { start: offsetOfLine(line), end: offsetOfLine(line + 1) },
88
+ },
89
+ });
90
+ const warnAt = (line: number, file = "paper.tex"): LintFinding => ({
91
+ file,
92
+ line,
93
+ column: 1,
94
+ severity: 1,
95
+ ruleId: "tex/example",
96
+ message: `line ${String(line)}`,
97
+ });
98
+ const sampleSections = (
99
+ outline: Outline,
100
+ abstract: PaperSections["abstract"] = null,
101
+ ): PaperSections => ({
102
+ paper: assemblePaper("paper.tex", sample, {
103
+ includes: () => [],
104
+ documentBody: () => null,
105
+ read: () => null,
106
+ }),
107
+ abstract,
108
+ outline,
109
+ });
110
+ const introductionLines = (outline: Outline): readonly (number | undefined)[] =>
111
+ submissionLint(
112
+ [2, 4].map((line) => warnAt(line)),
113
+ sampleSections(outline),
114
+ ).introductionWarnings.map((m) => m.line);
115
+
116
+ describe("the introduction ends where the next section, the back matter or the document ends", () => {
117
+ const intro = heading("Introduction", 1);
118
+ const methods = heading("Methods", 3);
119
+ const unplaced: Heading = { title: "Preface", place: { kind: "unplaced" } };
120
+
121
+ test("at the next placed section, skipping a heading the parser did not place", () => {
122
+ expect(
123
+ introductionLines({
124
+ sections: [unplaced, intro, methods],
125
+ backMatter: null,
126
+ end: null,
127
+ }),
128
+ ).toStrictEqual([2]);
129
+ });
130
+
131
+ test("at the back matter when the introduction is the last section", () => {
132
+ expect(
133
+ introductionLines({
134
+ sections: [heading("Intro and background", 1)],
135
+ backMatter: offsetOfLine(5),
136
+ end: sample.length,
137
+ }),
138
+ ).toStrictEqual([2, 4]);
139
+ });
140
+
141
+ test("at the end of the document when there is no back matter", () => {
142
+ expect(
143
+ introductionLines({
144
+ sections: [intro],
145
+ backMatter: null,
146
+ end: offsetOfLine(4),
147
+ }),
148
+ ).toStrictEqual([2]);
149
+ });
150
+
151
+ test("nowhere when neither the back matter nor the end is known", () => {
152
+ expect(
153
+ introductionLines({ sections: [intro], backMatter: null, end: null }),
154
+ ).toStrictEqual([2, 4]);
155
+ });
156
+
157
+ test("there is no introduction when no heading names one", () => {
158
+ expect(
159
+ introductionLines({
160
+ sections: [methods],
161
+ backMatter: null,
162
+ end: null,
163
+ }),
164
+ ).toStrictEqual([]);
165
+ });
166
+ });
167
+
168
+ test("a warning is placed in a section only when its file, line and column point into the paper", () => {
169
+ const abstract = { start: 0, end: sample.length };
170
+ const noColumn: LintFinding = { ...warnAt(2), column: undefined };
171
+ const noLine: LintFinding = { ...warnAt(2), line: undefined };
172
+ const beforeFirstLine: LintFinding = { ...warnAt(2), line: 0 };
173
+ const pastLastLine = warnAt(99);
174
+ const otherFile = warnAt(2, "other.tex");
175
+ const all = [noColumn, noLine, beforeFirstLine, pastLastLine, otherFile];
176
+ const lint = submissionLint(
177
+ all,
178
+ sampleSections({ sections: [], backMatter: null, end: null }, abstract),
179
+ );
180
+ expect(lint.abstractWarnings).toStrictEqual([noColumn]);
181
+ expect(lint.warnings).toStrictEqual(all);
182
+ expect(lint.errors).toStrictEqual([]);
183
+ });
184
+
185
+ test("without the paper's sections no warning belongs to the abstract or the introduction", () => {
186
+ const lint = submissionLint([warnAt(2)], null);
187
+ expect([lint.abstractWarnings, lint.introductionWarnings]).toStrictEqual([
188
+ [],
189
+ [],
190
+ ]);
191
+ });
192
+
193
+ test("a finding line names the place only when the finding has a line, and the rule only when it has one", () => {
194
+ const base: LintFinding = {
195
+ file: "paper.tex",
196
+ severity: 2,
197
+ ruleId: null,
198
+ message: " broken \n",
199
+ };
200
+ expect([
201
+ lintFindingLine(base),
202
+ lintFindingLine({ ...base, line: 0 }),
203
+ lintFindingLine({ ...base, line: 3 }),
204
+ lintFindingLine({ ...base, line: 3, column: 7, ruleId: "tex/example" }),
205
+ ]).toStrictEqual([
206
+ "paper.tex — broken",
207
+ "paper.tex — broken",
208
+ "paper.tex:3:1 — broken",
209
+ "paper.tex:3:7 tex/example — broken",
210
+ ]);
211
+ });