paperlint 18.9.1 → 19.0.1

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 (87) 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 +73 -110
  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/ports/submission-lint.d.ts +6 -0
  20. package/dist/ports/submission-lint.d.ts.map +1 -0
  21. package/dist/ports/submission-lint.js +2 -0
  22. package/dist/ports/submission-lint.js.map +1 -0
  23. package/dist/structure.d.ts +17 -1
  24. package/dist/structure.d.ts.map +1 -1
  25. package/dist/structure.js.map +1 -1
  26. package/dist/submission-confirm-hook.d.ts +8 -1
  27. package/dist/submission-confirm-hook.d.ts.map +1 -1
  28. package/dist/submission-confirm-hook.js +75 -20
  29. package/dist/submission-confirm-hook.js.map +1 -1
  30. package/dist/submission.d.ts +5 -0
  31. package/dist/submission.d.ts.map +1 -1
  32. package/dist/submission.js +46 -7
  33. package/dist/submission.js.map +1 -1
  34. package/dist/types.d.ts +2 -0
  35. package/dist/types.d.ts.map +1 -1
  36. package/docs/submission.md +19 -8
  37. package/eslint.config.mjs +2 -0
  38. package/lib/skill-corpus.mjs +2 -113
  39. package/lib/skill-corpus.test.mjs +10 -11
  40. package/package.json +1 -2
  41. package/scripts/eslint-file-length.mjs +117 -0
  42. package/scripts/harness-api.frozen.json +0 -18
  43. package/skills/build-label-page/build-label-page.test.ts +2 -7
  44. package/skills/harden-paper/check-numbers.test.ts +104 -0
  45. package/skills/harden-paper/check-release-claims.test.ts +126 -0
  46. package/skills/label-agent-runs/label-agent-runs.harness.ts +2 -6
  47. package/skills/render-paper/render-paper.harness.mjs +153 -0
  48. package/skills/rewrite-unclear/rewrite-unclear.harness.ts +0 -5
  49. package/skills/run-agent-grid/run-agent-grid.harness.ts +2 -6
  50. package/skills/submit-paper/check-deanon.test.ts +165 -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.ts +103 -134
  55. package/src/domain/submission-lint.test.ts +211 -0
  56. package/src/domain/submission-lint.ts +166 -0
  57. package/src/ports/submission-lint.ts +10 -0
  58. package/src/structure.ts +2 -4
  59. package/src/submission-confirm-hook-lint.test.ts +47 -0
  60. package/src/submission-confirm-hook.test.ts +73 -6
  61. package/src/submission-confirm-hook.ts +133 -28
  62. package/src/submission-fields-run.test.ts +1 -1
  63. package/src/submission-new.test.ts +4 -2
  64. package/src/submission-update.test.ts +16 -11
  65. package/src/submission.ts +62 -8
  66. package/src/types.ts +2 -0
  67. package/lib/skill-checks.d.mts +0 -10
  68. package/lib/skill-checks.mjs +0 -403
  69. package/lib/skill-checks.test.mjs +0 -288
  70. package/skills/analyze-sibling-paper/analyze-sibling-paper.harness.mjs +0 -23
  71. package/skills/argument-arc/argument-arc.harness.mjs +0 -23
  72. package/skills/build-benchmark/build-benchmark.harness.mjs +0 -23
  73. package/skills/camera-ready/camera-ready.harness.mjs +0 -23
  74. package/skills/cold-read-diff/cold-read-diff.harness.mjs +0 -21
  75. package/skills/draft-paper/draft-paper.harness.mjs +0 -23
  76. package/skills/extend-paper/extend-paper.harness.mjs +0 -23
  77. package/skills/find-venue/find-venue.harness.mjs +0 -23
  78. package/skills/harden-paper/harden-paper.harness.mjs +0 -23
  79. package/skills/map-prior-work/map-prior-work.harness.mjs +0 -23
  80. package/skills/paper-status/paper-status.harness.mjs +0 -25
  81. package/skills/pc-panel-review/pc-panel-review.harness.mjs +0 -24
  82. package/skills/plan-paper-timeline/plan-paper-timeline.harness.mjs +0 -23
  83. package/skills/research-ideate/research-ideate.harness.mjs +0 -23
  84. package/skills/study-accepted-papers/study-accepted-papers.harness.mjs +0 -23
  85. package/skills/submit-paper/submit-paper.harness.mjs +0 -23
  86. package/skills/tighten-paper/tighten-paper.harness.mjs +0 -23
  87. package/skills/verify-citations/verify-citations.harness.mjs +0 -23
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";
@@ -266,6 +275,7 @@ import {
266
275
  import {
267
276
  submissionConfirm,
268
277
  UNREADABLE_INPUT,
278
+ type Send,
269
279
  type Upload,
270
280
  } from "./submission-confirm-hook.ts";
271
281
  import { leafCommandsNormalized } from "vigiles/hook";
@@ -324,7 +334,7 @@ const USAGE = `paperlint — machine-checkable gates for a paper kept in git
324
334
  into ~/.cache/paperlint/texlive (PAPERLINT_TEXLIVE_DIR overrides); a second
325
335
  run does nothing. --check: report what is missing, change nothing
326
336
  npx paperlint doctor say what is actually wired — and what only LOOKS wired
327
- npx paperlint submission new [paper] [--abstract <file>] [--save]
337
+ npx paperlint submission new [paper] [--abstract <file>] [--save] [--allow-lint-errors <reason>]
328
338
  create the paper's submission on the venue's portal: the title
329
339
  and abstract from the build, the authors from paperlint.json,
330
340
  the PDF. A DRY RUN unless --save; a save records the new id in
@@ -335,6 +345,7 @@ const USAGE = `paperlint — machine-checkable gates for a paper kept in git
335
345
  whether it is the local paper.pdf (sha256); flags a title,
336
346
  abstract or authors that are not the paper's
337
347
  npx paperlint submission update [paper] [--pdf <file>] [--abstract <file>] [--submit] [--save]
348
+ [--allow-lint-errors <reason>]
338
349
  send the PDF (default: the paper's own), the paper's title
339
350
  and abstract each when the portal holds another (--abstract:
340
351
  that file's text instead), or "submitted". A DRY RUN unless --save: the portal checks the
@@ -425,6 +436,7 @@ submission:
425
436
  --pdf <file> the PDF to compare (show) or send (update) instead of the paper's own
426
437
  --abstract <file> new, update: a plain-text file whose text is sent as the abstract
427
438
  --submit update: mark the submission submitted
439
+ --allow-lint-errors <reason> permit reported lint errors on a submission --save
428
440
  --save new, update: really create or change the submission. Without it, nothing
429
441
  is saved
430
442
 
@@ -1329,6 +1341,7 @@ const STRING_FLAGS: ReadonlyMap<
1329
1341
  | "kind"
1330
1342
  | "pdf"
1331
1343
  | "abstract"
1344
+ | "allowLintErrors"
1332
1345
  | "url"
1333
1346
  | "host"
1334
1347
  | "to"
@@ -1340,6 +1353,7 @@ const STRING_FLAGS: ReadonlyMap<
1340
1353
  ["--kind", "kind"],
1341
1354
  ["--pdf", "pdf"],
1342
1355
  ["--abstract", "abstract"],
1356
+ ["--allow-lint-errors", "allowLintErrors"],
1343
1357
  ["--url", "url"],
1344
1358
  ["--host", "host"],
1345
1359
  ["--to", "to"],
@@ -1478,7 +1492,7 @@ const IN_PROCESS_HOOKS: Readonly<
1478
1492
  },
1479
1493
  // Never advisory-silent: an input it cannot read is refused, not let through.
1480
1494
  "submission-confirm": ({ stdin, out }) => {
1481
- const said = ((): ReturnType<typeof submissionConfirm> => {
1495
+ const said = (() => {
1482
1496
  try {
1483
1497
  return submissionConfirm(stdin(), {
1484
1498
  ...PRESET_DEPS,
@@ -1486,13 +1500,17 @@ const IN_PROCESS_HOOKS: Readonly<
1486
1500
  shellLeaves: leafCommandsNormalized,
1487
1501
  readSend: submissionSend,
1488
1502
  readUpload: uploadSend,
1503
+ lintPaper: lintSubmissionPaper,
1489
1504
  });
1490
1505
  } catch {
1491
1506
  return UNREADABLE_INPUT;
1492
1507
  }
1493
1508
  })();
1494
- if (said !== null) out(`${JSON.stringify(said)}\n`);
1495
- return 0;
1509
+ const write = (result: Awaited<typeof said>) => {
1510
+ if (result !== null) out(`${JSON.stringify(result)}\n`);
1511
+ return 0;
1512
+ };
1513
+ return said instanceof Promise ? said.then(write) : write(said);
1496
1514
  },
1497
1515
  };
1498
1516
 
@@ -1502,17 +1520,48 @@ const IN_PROCESS_HOOKS: Readonly<
1502
1520
  * (a flag missing its value, an unknown flag, a stray operand), so `submission-confirm` says it
1503
1521
  * cannot tell rather than guess.
1504
1522
  */
1505
- export function submissionSend(
1506
- words: readonly string[],
1507
- ): { readonly paper: string | null; readonly pdf: string | null } | null {
1523
+ export function submissionSend(words: readonly string[]): Send | null {
1508
1524
  const a = parseArgs(["submission", ...words]);
1509
1525
  const clean =
1510
1526
  a.missingValue === undefined &&
1511
1527
  a.unknownFlag === undefined &&
1512
1528
  a.paths.length <= 2;
1513
- return clean ? { paper: a.paths[1] ?? null, pdf: a.pdf } : null;
1529
+ return clean
1530
+ ? {
1531
+ paper: a.paths[1] ?? null,
1532
+ pdf: a.pdf,
1533
+ action:
1534
+ a.paths[0] === "new" ? "create" : a.submit ? "submit" : "update",
1535
+ allowLintErrors: a.allowLintErrors?.trim(),
1536
+ }
1537
+ : null;
1514
1538
  }
1515
1539
 
1540
+ const lintSubmissionPaper = submissionLinter(
1541
+ async (paperDir, cwd, accept) => {
1542
+ const stderr = collector();
1543
+ await run(["lint", paperDir], {
1544
+ cwd,
1545
+ log: () => {},
1546
+ err: (line: string) => {
1547
+ stderr.write(`${line}\n`);
1548
+ },
1549
+ onLintResults: (results, structure) => {
1550
+ accept([
1551
+ ...asEslintResults(structure).map((r) => ({
1552
+ ...r,
1553
+ filePath: resolve(cwd, r.filePath),
1554
+ })),
1555
+ ...results,
1556
+ ]);
1557
+ },
1558
+ });
1559
+ return firstLine(stderr.text());
1560
+ },
1561
+ (paperDir) =>
1562
+ submissionSections(paperDir, { ...RECORD_DEPS, latex: latexReader }),
1563
+ );
1564
+
1516
1565
  /**
1517
1566
  * The words after `artifact`, read by this CLI's own parser, for an upload: the file it uploads, the
1518
1567
  * paper (null for the current folder), and the host and project it goes to — or null when they would
@@ -2326,6 +2375,7 @@ const SIMPLE: Readonly<
2326
2375
  abstract: a.abstract,
2327
2376
  submit: a.submit,
2328
2377
  save: a.save,
2378
+ allowLintErrors: a.allowLintErrors ?? undefined,
2329
2379
  },
2330
2380
  {
2331
2381
  files: nodeFiles,
@@ -2336,6 +2386,7 @@ const SIMPLE: Readonly<
2336
2386
  latex: latexReader,
2337
2387
  codec: sourcesCodec,
2338
2388
  lintText,
2389
+ lintPaper: lintSubmissionPaper,
2339
2390
  yaml: parseYaml,
2340
2391
  now: isoNow,
2341
2392
  log,
@@ -2520,6 +2571,25 @@ const selfInstallDeps = (install: ProjectInstall): SelfInstallDeps => {
2520
2571
  const loadLatexLanguage = async (): Promise<unknown> =>
2521
2572
  (await import("#eslint-rules/latex-language")).texLanguage;
2522
2573
 
2574
+ type LintResults = (
2575
+ results: readonly ESLint.LintResult[],
2576
+ structure: Readonly<ReturnType<typeof checkStructure>>,
2577
+ ) => void;
2578
+
2579
+ /** A missing flag value must be reported before falling back to any default. */
2580
+ function argumentProblem(a: Args): string | null {
2581
+ if (a.missingValue)
2582
+ return (
2583
+ `${a.missingValue} needs a value — it was given none.\n` +
2584
+ `Without it the run would silently fall back to whatever config it discovers, which is not what the command line said.`
2585
+ );
2586
+ if (a.unknownFlag !== undefined)
2587
+ return `unknown flag \`${a.unknownFlag}\` — \`paperlint --help\` lists every flag`;
2588
+ return !a.help && a.cmd && a.cmd !== "submission" && a.allowLintErrors != null
2589
+ ? "--allow-lint-errors is only for submission new or update with --save"
2590
+ : null;
2591
+ }
2592
+
2523
2593
  export async function run(
2524
2594
  argv: readonly string[],
2525
2595
  {
@@ -2532,6 +2602,7 @@ export async function run(
2532
2602
  skillLinks = readSkillLinks,
2533
2603
  install = projectInstall,
2534
2604
  claude = claudeCode(),
2605
+ onLintResults,
2535
2606
  }: {
2536
2607
  log?: typeof console.log;
2537
2608
  err?: typeof console.error;
@@ -2554,26 +2625,12 @@ export async function run(
2554
2625
  checkReferences?: CheckReferences;
2555
2626
  /** The skills report `lint`'s stderr line reads; a test hands a fixed one. */
2556
2627
  skillLinks?: (root: string) => LinkReport;
2628
+ onLintResults?: LintResults;
2557
2629
  } = {},
2558
2630
  ): Promise<number> {
2559
2631
  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
- }
2632
+ const problem = argumentProblem(a);
2633
+ if (problem !== null) return (err(problem), 2);
2577
2634
  if (a.help || !a.cmd) {
2578
2635
  log(USAGE);
2579
2636
  return a.help ? 0 : 2;
@@ -2683,7 +2740,7 @@ export async function run(
2683
2740
  try {
2684
2741
  results = await eslint.lintFiles(paths);
2685
2742
  } catch (e) {
2686
- if (isEmptySet(e)) results = [];
2743
+ if (isEmptyLintSet(e)) results = [];
2687
2744
  else throw e;
2688
2745
  }
2689
2746
 
@@ -2713,6 +2770,7 @@ export async function run(
2713
2770
  .map((d) => join(d, MAIN))
2714
2771
  .filter((f) => existsSync(f)),
2715
2772
  bodies,
2773
+ onLintResults,
2716
2774
  });
2717
2775
  hooksLine(root, err, skillLinks, claude);
2718
2776
  // On stderr, so `--json` leaves stdout a clean array.
@@ -2833,25 +2891,11 @@ const editLinter =
2833
2891
  };
2834
2892
 
2835
2893
  /** 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
- });
2894
+ const counted = (r: LintResult): Readonly<ESLint.LintResult> =>
2895
+ lintResultFor(
2896
+ r.filePath,
2897
+ r.messages.map((m) => ({ ...m, severity: 2 })),
2898
+ );
2855
2899
 
2856
2900
  /**
2857
2901
  * The first path that is a FILE paperlint does not lint, or null. ESLint would answer such a file
@@ -2873,54 +2917,6 @@ async function firstUnownedFile(
2873
2917
  return null;
2874
2918
  }
2875
2919
 
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
2920
  /** Printed under a clean `lint`, the README's disclaimer in one line. */
2925
2921
  const CLEAN_RUN_REMINDER =
2926
2922
  "Check the venue's own call before you submit: a call can change between editions, and a check can miss a case.";
@@ -2932,7 +2928,7 @@ const CLEAN_RUN_REMINDER =
2932
2928
  async function reportLint(
2933
2929
  eslint: ESLint,
2934
2930
  results: ESLint.LintResult[],
2935
- structure: ReturnType<typeof checkStructure>,
2931
+ structure: Readonly<ReturnType<typeof checkStructure>>,
2936
2932
  {
2937
2933
  a,
2938
2934
  log,
@@ -2941,6 +2937,7 @@ async function reportLint(
2941
2937
  opts,
2942
2938
  projectPapers,
2943
2939
  bodies,
2940
+ onLintResults,
2944
2941
  }: {
2945
2942
  a: Args;
2946
2943
  log: typeof console.log;
@@ -2950,6 +2947,7 @@ async function reportLint(
2950
2947
  projectPapers: readonly string[];
2951
2948
  /** The body files handed to ESLint, as read before the run. */
2952
2949
  bodies: readonly PaperBody[];
2950
+ onLintResults: LintResults | undefined;
2953
2951
  },
2954
2952
  ): Promise<number> {
2955
2953
  const silent = await silentOptionalRules(
@@ -2966,46 +2964,17 @@ async function reportLint(
2966
2964
  return 1;
2967
2965
  }
2968
2966
 
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
- );
2967
+ if (onLintResults !== undefined) onLintResults(results, structure);
2980
2968
  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.
2969
+ const clean = await printLintResults(eslint, results, {
2970
+ json: a.json,
2971
+ structure: asEslintResults(structure),
2972
+ structureText: formatStructure(structure),
2973
+ log,
2974
+ });
2994
2975
  if (clean) log(` ${CLEAN_RUN_REMINDER}`);
2995
2976
  }
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;
2977
+ return lintExitCode(results, structure.length > 0, a.maxWarnings, err);
3009
2978
  }
3010
2979
 
3011
2980
  // 🔴 `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
+ });