paperlint 20.1.2 → 20.3.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 (96) hide show
  1. package/.claude-plugin/plugin.json +1 -1
  2. package/CLAUDE.md +5 -1
  3. package/dist/adapters/venue-corpus/index.d.ts +361 -0
  4. package/dist/adapters/venue-corpus/index.d.ts.map +1 -0
  5. package/dist/adapters/venue-corpus/index.js +221 -0
  6. package/dist/adapters/venue-corpus/index.js.map +1 -0
  7. package/dist/cli.d.ts +4 -3
  8. package/dist/cli.d.ts.map +1 -1
  9. package/dist/cli.js +42 -13
  10. package/dist/cli.js.map +1 -1
  11. package/dist/corpus-record-rule.d.ts +65 -0
  12. package/dist/corpus-record-rule.d.ts.map +1 -0
  13. package/dist/corpus-record-rule.js +85 -0
  14. package/dist/corpus-record-rule.js.map +1 -0
  15. package/dist/domain/corpus-record.d.ts +51 -0
  16. package/dist/domain/corpus-record.d.ts.map +1 -0
  17. package/dist/domain/corpus-record.js +119 -0
  18. package/dist/domain/corpus-record.js.map +1 -0
  19. package/dist/domain/licence.d.ts +51 -0
  20. package/dist/domain/licence.d.ts.map +1 -0
  21. package/dist/domain/licence.js +61 -0
  22. package/dist/domain/licence.js.map +1 -0
  23. package/dist/domain/venue-corpus.d.ts +142 -0
  24. package/dist/domain/venue-corpus.d.ts.map +1 -0
  25. package/dist/domain/venue-corpus.js +17 -0
  26. package/dist/domain/venue-corpus.js.map +1 -0
  27. package/dist/eslint-rules/CLAUDE.md.spec.d.ts.map +1 -1
  28. package/dist/eslint-rules/CLAUDE.md.spec.js +1 -0
  29. package/dist/eslint-rules/CLAUDE.md.spec.js.map +1 -1
  30. package/dist/paper-files.d.ts +10 -3
  31. package/dist/paper-files.d.ts.map +1 -1
  32. package/dist/paper-files.js +17 -2
  33. package/dist/paper-files.js.map +1 -1
  34. package/dist/papers-roots.d.ts +6 -0
  35. package/dist/papers-roots.d.ts.map +1 -1
  36. package/dist/papers-roots.js +14 -0
  37. package/dist/papers-roots.js.map +1 -1
  38. package/dist/ports/venue-corpus-codec.d.ts +11 -0
  39. package/dist/ports/venue-corpus-codec.d.ts.map +1 -0
  40. package/dist/ports/venue-corpus-codec.js +2 -0
  41. package/dist/ports/venue-corpus-codec.js.map +1 -0
  42. package/dist/skill-chunks/chunk-5KCU4WTN.js +108 -0
  43. package/dist/skill-chunks/{chunk-X4VKG4KT.js → chunk-6YEM4VDI.js} +11 -9
  44. package/dist/skill-chunks/{chunk-L3NJUJUP.js → chunk-CXAGKT44.js} +5 -3
  45. package/dist/skill-chunks/{chunk-6NU6CXUS.js → chunk-J5XYPERO.js} +12 -72
  46. package/dist/skill-chunks/{chunk-IREAROCV.js → chunk-Z5YMDZYW.js} +4 -0
  47. package/dist/skills/study-accepted-papers/scripts/corpus-licences-core.d.ts +54 -0
  48. package/dist/skills/study-accepted-papers/scripts/corpus-licences.d.ts +2 -0
  49. package/docs/design/venue-corpus.md +271 -0
  50. package/docs/layout.md +2 -2
  51. package/docs/rules/corpus/record.md +119 -0
  52. package/docs/rules.md +1 -0
  53. package/docs/venues.md +158 -24
  54. package/eslint-rules/CLAUDE.md +5 -1
  55. package/eslint-rules/CLAUDE.md.spec.ts +3 -0
  56. package/eslint.config.mjs +1 -0
  57. package/package.json +3 -1
  58. package/scripts/bundle-skills.ts +1 -0
  59. package/scripts/eslint-file-length.mjs +3 -3
  60. package/scripts/venue-corpus-schema.test.ts +39 -0
  61. package/scripts/venue-corpus-schema.ts +17 -0
  62. package/skills/argument-arc/scripts/headings.js +6 -4
  63. package/skills/cold-read-diff/scripts/cold-read.js +6 -4
  64. package/skills/paper-pipeline/scripts/extract-ref-facts.js +6 -5
  65. package/skills/pc-panel-review/scripts/prior-reviews.js +7 -5
  66. package/skills/study-accepted-papers/SKILL.md +34 -2
  67. package/skills/study-accepted-papers/SKILL.md.spec.ts +33 -1
  68. package/skills/study-accepted-papers/papers.schema.json +474 -0
  69. package/skills/study-accepted-papers/scripts/corpus-licences-core.js +180 -0
  70. package/skills/study-accepted-papers/scripts/corpus-licences-core.ts +303 -0
  71. package/skills/study-accepted-papers/scripts/corpus-licences.js +393 -0
  72. package/skills/study-accepted-papers/scripts/corpus-licences.test.ts +488 -0
  73. package/skills/study-accepted-papers/scripts/corpus-licences.ts +27 -0
  74. package/skills/verify-citations/scripts/bib-authors.js +6 -5
  75. package/skills/verify-citations/scripts/verify-cites.js +6 -5
  76. package/src/adapters/venue-corpus/index.test.ts +337 -0
  77. package/src/adapters/venue-corpus/index.ts +306 -0
  78. package/src/cli-e2e.test.mjs +2 -2
  79. package/src/cli.test.ts +1 -1
  80. package/src/cli.ts +57 -13
  81. package/src/corpus-record-rule.test.ts +228 -0
  82. package/src/corpus-record-rule.ts +175 -0
  83. package/src/domain/corpus-record.test.ts +163 -0
  84. package/src/domain/corpus-record.ts +210 -0
  85. package/src/domain/licence.test.ts +122 -0
  86. package/src/domain/licence.ts +95 -0
  87. package/src/domain/venue-corpus.ts +159 -0
  88. package/src/paper-files.test.ts +13 -4
  89. package/src/paper-files.ts +23 -2
  90. package/src/paper-settings-commands.test.ts +2 -2
  91. package/src/papers-roots.test.ts +34 -1
  92. package/src/papers-roots.ts +15 -0
  93. package/src/ports/venue-corpus-codec.ts +11 -0
  94. package/src/rule-cases.test.ts +15 -0
  95. package/src/settled-paper.test.ts +1 -1
  96. package/src/unowned-file.test.ts +1 -1
package/src/cli.ts CHANGED
@@ -36,6 +36,7 @@ import { isOk } from "./domain/result.ts";
36
36
  import { stripVTControlCharacters } from "node:util";
37
37
  import { fileURLToPath } from "node:url";
38
38
  import { join, dirname, resolve, relative, basename, sep } from "node:path";
39
+ import json from "@eslint/json";
39
40
  import markdown from "@eslint/markdown";
40
41
  import { z } from "zod";
41
42
  // Types come from consumer.d.mts beside it.
@@ -135,6 +136,7 @@ import type { PortalSite } from "./ports/submission-portal.ts";
135
136
  import type { CheckReferences } from "./ports/check-references.ts";
136
137
  import {
137
138
  ANY_PAPER,
139
+ corpusFiles,
138
140
  narrowToOwners,
139
141
  ownedPatterns,
140
142
  paperFiles,
@@ -239,7 +241,13 @@ import {
239
241
  folderLayoutRules,
240
242
  } from "./folder-layout-rule.ts";
241
243
  import { folderLayoutHook } from "./folder-layout-hook.ts";
242
- import { papersDirOf, papersRoots, toPaths } from "./papers-roots.ts";
244
+ import { inCorpus, papersDirOf, papersRoots, toPaths } from "./papers-roots.ts";
245
+ import {
246
+ CORPUS_RECORD_RULE_LEVELS,
247
+ corpusRecordRules,
248
+ } from "./corpus-record-rule.ts";
249
+ import { CORPUS_RECORD } from "./domain/venue-corpus.ts";
250
+ import { venueCorpusCodec } from "./adapters/venue-corpus/index.ts";
243
251
  import { paperFolderOf, writtenPath } from "./domain/paper-folder.ts";
244
252
  import { papersReached, type PaperTree } from "./domain/paper-dirs.ts";
245
253
  import {
@@ -648,6 +656,26 @@ const TALK_RULE_DEPS = {
648
656
  listDir: nodeListDir,
649
657
  };
650
658
 
659
+ /**
660
+ * A venue corpus, `<papers-root>/venues/<venue>/`, reached through its `papers.json`, linted with
661
+ * ESLint's JSON language so `corpus/record` reports at the field (docs/design/venue-corpus.md,
662
+ * decision 4). The JSON language reaches no other file: this block alone names it.
663
+ */
664
+ const corpusBlock = (papers: PaperScope): ConfigBlock => ({
665
+ files: corpusFiles(papers, CORPUS_RECORD),
666
+ plugins: {
667
+ json,
668
+ corpus: {
669
+ rules: corpusRecordRules({
670
+ entries: nodeListEntries,
671
+ codec: venueCorpusCodec,
672
+ }),
673
+ },
674
+ },
675
+ language: "json/json",
676
+ rules: CORPUS_RECORD_RULE_LEVELS,
677
+ });
678
+
651
679
  /** The config the user would otherwise write by hand. The data comes from `opts`, the mechanism is here. */
652
680
  export function buildConfig(
653
681
  opts: PaperlintConfig = {},
@@ -733,6 +761,7 @@ export function buildConfig(
733
761
  ...STATUS_CYCLE_RULE_LEVELS,
734
762
  },
735
763
  },
764
+ corpusBlock(papers),
736
765
  {
737
766
  files: own("reviews/*.md"),
738
767
  plugins: { markdown, review: reviewFrontmatter },
@@ -864,11 +893,12 @@ export function eslintConfig(blocks: readonly ConfigBlock[]): Linter.Config[] {
864
893
 
865
894
  /**
866
895
  * The rule ids a consumer may name in `rules`: every rule paperlint's own config defines, read off that
867
- * config rather than listed again. `@eslint/markdown` is a dependency's plugin, not paperlint's.
896
+ * config rather than listed again. `@eslint/markdown` and `@eslint/json` are a dependency's plugins,
897
+ * not paperlint's.
868
898
  */
869
899
  export const SHIPPED_RULES: ReadonlySet<string> = shippedRuleIds(
870
900
  buildConfig({}, { sentinel: "tex language" }),
871
- [markdown],
901
+ [markdown, json],
872
902
  );
873
903
 
874
904
  /** A plugin as `rulePlugins` gives it: its rules, and for `tex` the LaTeX language when given. */
@@ -881,7 +911,7 @@ export interface RulePlugin {
881
911
  * Every plugin paperlint's config registers, ONE object per name, read off that config. In it one
882
912
  * name is bound to different objects in different blocks (`paper` beside `PIPELINE-STATUS.md` is
883
913
  * not `paper` beside `paper.tex`); here their rules are merged, so a config that lints any paper
884
- * file knows every rule id. `@eslint/markdown` is a dependency's plugin and is left out. The LaTeX
914
+ * file knows every rule id. `@eslint/markdown` and `@eslint/json` are a dependency's plugins and are left out. The LaTeX
885
915
  * language rides on `tex` when `texLanguage` is given, and that is how a consumer registers it: a
886
916
  * second `tex` plugin of its own is refused by ESLint ("Cannot redefine plugin "tex"", measured
887
917
  * with and without the language here). Without it, `tex` carries rules only.
@@ -890,7 +920,7 @@ export function rulePlugins(texLanguage?: unknown): Record<string, RulePlugin> {
890
920
  const out: Record<string, { rules: Record<string, unknown> }> = {};
891
921
  for (const block of buildConfig({}, texLanguage ?? { sentinel: "tex" }))
892
922
  for (const [name, plugin] of Object.entries(block.plugins ?? {}))
893
- if (plugin !== markdown)
923
+ if (plugin !== markdown && plugin !== json)
894
924
  out[name] = { rules: { ...out[name]?.rules, ...plugin.rules } };
895
925
  if (out["tex"] && texLanguage !== undefined)
896
926
  return {
@@ -1030,14 +1060,20 @@ const PAPER_TREE: PaperTree = {
1030
1060
  },
1031
1061
  };
1032
1062
 
1033
- /** The papers `paths` reach: a file counts as the folder it sits in (#582). */
1034
- const paperDirs = (paths: readonly string[]): readonly string[] =>
1063
+ /**
1064
+ * The papers `paths` reach: a file counts as the folder it sits in (#582). A folder in a venue corpus
1065
+ * of `roots` is none of them (#215): a `paper.tex` kept there is an accepted paper's source.
1066
+ */
1067
+ const paperDirs = (
1068
+ paths: readonly string[],
1069
+ roots: readonly string[],
1070
+ ): readonly string[] =>
1035
1071
  papersReached(
1036
1072
  paths.map((p) =>
1037
1073
  resolve(existsSync(p) && statSync(p).isFile() ? dirname(p) : p),
1038
1074
  ),
1039
1075
  PAPER_TREE,
1040
- );
1076
+ ).filter((d) => !inCorpus(d, roots));
1041
1077
 
1042
1078
  /**
1043
1079
  * Every linted paper's rules, as ESLint blocks scoped to that paper, in two groups: what its venue
@@ -1045,8 +1081,11 @@ const paperDirs = (paths: readonly string[]): readonly string[] =>
1045
1081
  * them. A file that does not parse, or names a rule paperlint does not ship, stops the run with one
1046
1082
  * line naming the file — the same strictness as the root's own `rules`.
1047
1083
  */
1048
- export function paperRuleBlocks(paths: readonly string[]): Parsed<PaperBlocks> {
1049
- const each = paperDirs(paths).map((dir): Parsed<PaperBlocks> => {
1084
+ export function paperRuleBlocks(
1085
+ paths: readonly string[],
1086
+ roots: readonly string[],
1087
+ ): Parsed<PaperBlocks> {
1088
+ const each = paperDirs(paths, roots).map((dir): Parsed<PaperBlocks> => {
1050
1089
  const p = paperPreset(dir, PRESET_DEPS);
1051
1090
  return p.kind === "settings-problem"
1052
1091
  ? { ok: false, error: settingsProblemLine(dir, p.problem) }
@@ -2737,7 +2776,8 @@ async function paperEslint(
2737
2776
  // paper's venue preset → the root paperlint.json → the paper's own paperlint.json → the paper's
2738
2777
  // stage (src/settled-paper.ts), last because a published text has nothing left to fix whoever
2739
2778
  // turned a writing rule on.
2740
- const papers = paperRuleBlocks(paths);
2779
+ const roots = papersRoots(cfg);
2780
+ const papers = paperRuleBlocks(paths, roots);
2741
2781
  if (!papers.ok) return papers;
2742
2782
  const opts = {
2743
2783
  ...cfg.opts,
@@ -2758,14 +2798,18 @@ async function paperEslint(
2758
2798
  // loaded, since only its rules read them. The project's papers too: `paperlint lint .` reaches
2759
2799
  // papers two levels down, which a directory's immediate papers do not.
2760
2800
  const bodies = texLanguage
2761
- ? paperBodies(paperDirs([...paths, ...papersRoots(cfg)]), RECORD_DEPS)
2801
+ ? paperBodies(paperDirs([...paths, ...roots], roots), RECORD_DEPS)
2762
2802
  : [];
2763
2803
 
2764
2804
  const cwd = lintRoot(cfg.root, paths);
2765
2805
  // The papers whose own files the config names: the ones `paths` reach and the project's. A copy of
2766
2806
  // a paper kept inside it (a review snapshot, a build copy) is in no such list, so no block claims
2767
2807
  // it (#582).
2768
- const claimed = papersScope(paperDirs([...paths, ...papersRoots(cfg)]), cwd);
2808
+ const claimed = papersScope(
2809
+ paperDirs([...paths, ...roots], roots),
2810
+ cwd,
2811
+ roots,
2812
+ );
2769
2813
  const eslint = new ESLint({
2770
2814
  cwd,
2771
2815
  overrideConfigFile: true,
@@ -0,0 +1,228 @@
1
+ /**
2
+ * `corpus/record` through `paperlint lint`, the way a consumer runs it: the block that lints a
3
+ * corpus's `papers.json` as JSON and reports at the field, no other JSON file reached, and a
4
+ * `paper.tex` kept in a corpus judged by no paper rule (#215).
5
+ */
6
+ import { describe, expect, it } from "vitest";
7
+ import { z } from "zod";
8
+ import { run } from "./cli.ts";
9
+ import { useTempDir, writeTree } from "../test/support.ts";
10
+
11
+ const STATUS = "---\nstages: []\n---\n# PIPELINE-STATUS\n";
12
+ const TEX = "\\documentclass{article}\n\\begin{document}\nx\n\\end{document}\n";
13
+ const PAPER = {
14
+ "papers/p/PIPELINE-STATUS.md": STATUS,
15
+ "papers/p/paper.tex": TEX,
16
+ };
17
+ const C = "papers/venues/agent";
18
+ const RECORD = `${C}/papers.json`;
19
+
20
+ const copy = (stored: readonly string[]) => ({
21
+ version: "published",
22
+ url: "https://doi.org/10.1/x",
23
+ licence: { id: "NOASSERTION" },
24
+ stored,
25
+ ...(stored.length > 0 ? { fetched_from: "https://doi.org/10.1/x" } : {}),
26
+ });
27
+ const record = (copies: readonly (readonly string[])[]): string =>
28
+ JSON.stringify(
29
+ {
30
+ venue: "agent",
31
+ editions: [
32
+ {
33
+ edition: 2026,
34
+ listed_from: "https://example.org/accepted",
35
+ read_on: "2026-11-03",
36
+ capped: null,
37
+ proxy: null,
38
+ },
39
+ ],
40
+ papers: [
41
+ {
42
+ key: "a",
43
+ edition: 2026,
44
+ group: "accepted",
45
+ title: "A",
46
+ ids: { doi: "10.1/x" },
47
+ copies: copies.map(copy),
48
+ },
49
+ ],
50
+ rebuild: [],
51
+ },
52
+ null,
53
+ 2,
54
+ );
55
+
56
+ const Results = z.array(
57
+ z.looseObject({
58
+ filePath: z.string(),
59
+ messages: z.array(
60
+ z.looseObject({
61
+ ruleId: z.string().nullable(),
62
+ messageId: z.string().optional(),
63
+ line: z.number().optional(),
64
+ column: z.number().optional(),
65
+ message: z.string(),
66
+ }),
67
+ ),
68
+ }),
69
+ );
70
+
71
+ /** `paperlint lint --json` over the tree: each linted file, and every message with its file. */
72
+ async function lint(tree: Readonly<Record<string, string>>) {
73
+ const dir = writeTree(useTempDir("paperlint-corpus-"), {
74
+ "package.json": '{"name":"consumer","private":true}',
75
+ ...tree,
76
+ });
77
+ const out: string[] = [];
78
+ await run(["lint", "--json"], {
79
+ cwd: dir,
80
+ log: (...a: unknown[]) => out.push(a.join(" ")),
81
+ err: () => undefined,
82
+ });
83
+ const results = Results.parse(JSON.parse(out.join("\n")));
84
+ const rel = (p: string) => p.slice(dir.length + 1);
85
+ return {
86
+ files: results.map((r) => rel(r.filePath)).sort(),
87
+ messages: results.flatMap((r) =>
88
+ r.messages.map((m) => ({ ...m, file: rel(r.filePath) })),
89
+ ),
90
+ };
91
+ }
92
+
93
+ /** Every message on a file of the corpus. */
94
+ const onCorpus = async (tree: Readonly<Record<string, string>>) =>
95
+ (await lint(tree)).messages.filter((m) => m.file.startsWith(C));
96
+
97
+ /** The corpus findings: where each is reported and which one it is. */
98
+ const corpusFindings = async (tree: Readonly<Record<string, string>>) =>
99
+ (await onCorpus(tree))
100
+ .filter((m) => m.ruleId === "corpus/record")
101
+ .map((m) => ({ file: m.file, line: m.line, messageId: m.messageId }));
102
+
103
+ /** The line of `text` holding the `nth` occurrence of `needle`, counted from 1. */
104
+ const lineOf = (text: string, needle: string, nth = 1): number =>
105
+ text
106
+ .split("\n")
107
+ .flatMap((l, i) => (l.includes(needle) ? [i + 1] : []))
108
+ .at(nth - 1) ?? 0;
109
+
110
+ describe("corpus/record: silent where nothing is wrong", () => {
111
+ it("🔴 is silent on a project with no venues/ at all", async () => {
112
+ // Guards: most consumers keep no corpus; the rule must cost them nothing.
113
+ expect(await corpusFindings(PAPER)).toEqual([]);
114
+ });
115
+
116
+ it("🔴 is silent on a corpus folder with stored files and no papers.json", async () => {
117
+ // Guards: a corpus not migrated yet is corpus/allowed-files-only's to report (PR 1b-ii), not this rule's.
118
+ const r = await lint({
119
+ ...PAPER,
120
+ [`${C}/MANIFEST.md`]: "# agent\n",
121
+ [`${C}/pdf/a.pdf`]: "%PDF",
122
+ [`${C}/text/a.txt`]: "a",
123
+ });
124
+ expect(r.files.filter((f) => f.startsWith("papers/venues/"))).toEqual([]);
125
+ expect(r.messages.filter((m) => m.file.startsWith(C))).toEqual([]);
126
+ });
127
+
128
+ it("is silent on a corpus whose stored files are each claimed by one copy", async () => {
129
+ const r = await lint({
130
+ ...PAPER,
131
+ [RECORD]: record([["pdf", "text"], []]),
132
+ [`${C}/pdf/a.pdf`]: "%PDF",
133
+ [`${C}/text/a.txt`]: "a",
134
+ [`${C}/text/a.pdfminer.txt`]: "a",
135
+ [`${C}/measurements.json`]: "[]",
136
+ });
137
+ // Guards: the block reaches the corpus (its papers.json is linted), and finds nothing.
138
+ expect(r.files).toContain(RECORD);
139
+ expect(r.messages.filter((m) => m.file.startsWith(C))).toEqual([]);
140
+ });
141
+ });
142
+
143
+ describe("corpus/record: each finding, at its place in papers.json", () => {
144
+ it("🔴 reports a field that breaks the schema at that field's line", async () => {
145
+ const text = record([["pdf"]]).replace('"fetched_from"', '"fetched"');
146
+ const found = await onCorpus({
147
+ ...PAPER,
148
+ [RECORD]: text,
149
+ [`${C}/pdf/a.pdf`]: "%PDF",
150
+ });
151
+ // Guards: the required key is reported on its copy (the line opening it), the misspelt one where it stands.
152
+ expect(found.map((m) => [m.line, m.column, m.messageId])).toEqual([
153
+ [lineOf(text, '"version"') - 1, 9, "unparsed"],
154
+ [lineOf(text, '"fetched"'), 11, "unparsed"],
155
+ ]);
156
+ expect(found.map((m) => m.message.split(":")[0])).toEqual([
157
+ "`papers.0.copies.0.fetched_from`",
158
+ "`papers.0.copies.0.fetched`",
159
+ ]);
160
+ });
161
+
162
+ it("reports a papers.json that is not JSON as ESLint's parse error", async () => {
163
+ const found = await onCorpus({ ...PAPER, [RECORD]: '{ "venue": ' });
164
+ expect(found.map((m) => [m.ruleId, m.line])).toEqual([[null, 1]]);
165
+ });
166
+
167
+ it("reports an unclaimed file, a missing file and two copies storing one kind", async () => {
168
+ const text = record([["pdf"], ["pdf", "text"]]);
169
+ // The second copy's `stored` holds both the second "pdf" and the "text" whose file is absent.
170
+ const second = lineOf(text, '"stored"', 2);
171
+ expect(
172
+ await corpusFindings({
173
+ ...PAPER,
174
+ [RECORD]: text,
175
+ [`${C}/pdf/a.pdf`]: "%PDF",
176
+ [`${C}/pdf/b.pdf`]: "%PDF",
177
+ }),
178
+ ).toEqual([
179
+ // A file of no listed paper is reported on the record's first line.
180
+ { file: RECORD, line: 1, messageId: "unclaimed" },
181
+ { file: RECORD, line: second, messageId: "twice" },
182
+ { file: RECORD, line: second, messageId: "missing" },
183
+ ]);
184
+ });
185
+
186
+ it("is turned off in the root paperlint.json by one line", async () => {
187
+ expect(
188
+ await corpusFindings({
189
+ ...PAPER,
190
+ "paperlint.json": JSON.stringify({
191
+ rules: { "corpus/record": "off" },
192
+ }),
193
+ [RECORD]: record([]),
194
+ [`${C}/pdf/a.pdf`]: "%PDF",
195
+ }),
196
+ ).toEqual([]);
197
+ });
198
+ });
199
+
200
+ describe("the JSON language reaches papers.json and nothing else", () => {
201
+ it("🔴 lints no other JSON file: the root and a paper's paperlint.json, measurements.json", async () => {
202
+ const r = await lint({
203
+ ...PAPER,
204
+ "paperlint.json": "{}",
205
+ "papers/p/paperlint.json": "{}",
206
+ "papers/p/data.json": "{ broken",
207
+ [RECORD]: record([]),
208
+ [`${C}/measurements.json`]: "{ broken",
209
+ "papers/venues/papers.json": "{ broken",
210
+ });
211
+ expect(r.files.filter((f) => f.endsWith(".json"))).toEqual([RECORD]);
212
+ });
213
+ });
214
+
215
+ describe("a paper.tex kept in a corpus (#215)", () => {
216
+ it("🔴 is judged by no paper rule, and the corpus still is", async () => {
217
+ const r = await lint({
218
+ ...PAPER,
219
+ [RECORD]: record([]),
220
+ [`${C}/paper.tex`]: TEX,
221
+ [`${C}/PIPELINE-STATUS.md`]: "no frontmatter\n",
222
+ [`${C}/sources/x/paper.tex`]: TEX,
223
+ });
224
+ expect(r.files.filter((f) => f.startsWith("papers/venues/"))).toEqual([
225
+ RECORD,
226
+ ]);
227
+ });
228
+ });
@@ -0,0 +1,175 @@
1
+ /**
2
+ * `corpus/record` — every copy a venue corpus stores in `pdf/` and `text/` is accounted for by its
3
+ * `papers.json` (docs/design/venue-corpus.md, decision 4; docs/rules/corpus/record.md). What is
4
+ * judged is `src/domain/corpus-record.ts`; this file reads the record through the codec, lists the
5
+ * corpus, and reports.
6
+ *
7
+ * ── WHERE IT REPORTS ─────────────────────────────────────────────────────────────
8
+ * On `<papers-root>/venues/<venue>/papers.json`, which `buildConfig` lints with ESLint's JSON
9
+ * language (`@eslint/json`): each finding at the field its path names, walked down the file's JSON
10
+ * tree; where the path stops being in the file (a required field left out), at the deepest part
11
+ * that is. A file that is not JSON never reaches the rule: ESLint reports its parse error. A corpus
12
+ * folder without `papers.json` has no file to report on, and this rule says nothing about it.
13
+ */
14
+ import { dirname, join } from "node:path";
15
+ import { callerPath } from "./caller-path.ts";
16
+ import {
17
+ corpusMessage,
18
+ judgeCorpus,
19
+ type CorpusFinding,
20
+ } from "./domain/corpus-record.ts";
21
+ import type { RecordPath } from "./domain/venue-corpus.ts";
22
+ import type { FolderRuleModule } from "./folder-venue-rule.ts";
23
+ import type { ListEntries } from "./ports/list-entries.ts";
24
+ import type { VenueCorpusCodec } from "./ports/venue-corpus-codec.ts";
25
+ import { rulePageUrl } from "./venue-rules.ts";
26
+
27
+ /** What the rule reads with. */
28
+ export interface CorpusRecordDeps {
29
+ readonly entries: ListEntries;
30
+ readonly codec: VenueCorpusCodec;
31
+ }
32
+
33
+ interface Position {
34
+ readonly line: number;
35
+ readonly column: number;
36
+ }
37
+
38
+ /** A span of the file, as ESLint's JSON language gives it. */
39
+ interface Span {
40
+ readonly start: Position;
41
+ readonly end: Position;
42
+ }
43
+
44
+ /** A node of ESLint's JSON tree, as far as walking a path needs: an object's members, an array's elements. */
45
+ interface JsonNode {
46
+ readonly loc: Span;
47
+ readonly members?: readonly {
48
+ readonly loc: Span;
49
+ readonly name: { readonly value: string };
50
+ readonly value: JsonNode;
51
+ }[];
52
+ readonly elements?: readonly {
53
+ readonly loc: Span;
54
+ readonly value: JsonNode;
55
+ }[];
56
+ }
57
+
58
+ /** The tree of the whole file. */
59
+ interface JsonDocument {
60
+ readonly loc: Span;
61
+ readonly body: JsonNode;
62
+ }
63
+
64
+ /** What the rule uses of ESLint's context on a JSON file. */
65
+ export interface JsonRuleContext {
66
+ readonly filename: string;
67
+ readonly sourceCode: { readonly text: string; readonly ast: JsonDocument };
68
+ report(d: {
69
+ readonly loc: Span;
70
+ readonly messageId: string;
71
+ readonly data: Readonly<Record<string, string>>;
72
+ }): void;
73
+ }
74
+
75
+ export interface JsonRuleModule {
76
+ readonly meta: FolderRuleModule["meta"];
77
+ create(context: JsonRuleContext): { Document?: () => void };
78
+ }
79
+
80
+ /** Where the walk is: the node reached and the span to report, or only the span once the path left the file. */
81
+ interface Walk {
82
+ readonly node: JsonNode | null;
83
+ readonly loc: Span;
84
+ }
85
+
86
+ /**
87
+ * One step of a path: a key to the member of that name (the last of them, as `JSON.parse` keeps it),
88
+ * whose whole `"key": value` is reported; an index to that element.
89
+ */
90
+ const step = (at: Walk, segment: string | number): Walk => {
91
+ const next =
92
+ typeof segment === "number"
93
+ ? at.node?.elements?.[segment]
94
+ : at.node?.members?.findLast((m) => m.name.value === segment);
95
+ return next === undefined
96
+ ? { node: null, loc: at.loc }
97
+ : { node: next.value, loc: next.loc };
98
+ };
99
+
100
+ /** The span of the field `path` names; the whole file for an empty path. */
101
+ export const spanAt = (doc: JsonDocument, path: RecordPath): Span =>
102
+ path.reduce<Walk>(step, { node: doc.body, loc: doc.loc }).loc;
103
+
104
+ /** The entries of `dir` a person put there: hidden ones (`.DS_Store`, `.gitkeep`) are not copies. */
105
+ const visible = (dir: string, deps: CorpusRecordDeps): readonly string[] =>
106
+ deps
107
+ .entries(callerPath(dir))
108
+ .filter((e) => !e.name.startsWith("."))
109
+ .map((e) => e.name)
110
+ .toSorted((a, b) => a.localeCompare(b));
111
+
112
+ /** The findings about the corpus whose `papers.json` is `file`, holding `text`. */
113
+ const findingsFor = (
114
+ file: string,
115
+ text: string,
116
+ deps: CorpusRecordDeps,
117
+ ): readonly CorpusFinding[] =>
118
+ judgeCorpus({
119
+ record: deps.codec.parse(text),
120
+ stored: {
121
+ pdf: visible(join(dirname(file), "pdf"), deps),
122
+ text: visible(join(dirname(file), "text"), deps),
123
+ },
124
+ });
125
+
126
+ const META: FolderRuleModule["meta"] = {
127
+ type: "suggestion",
128
+ docs: {
129
+ description:
130
+ "a venue corpus's papers.json is a record, every copy stored in pdf/ and text/ is claimed by one copy in it, and every claimed file is there",
131
+ url: rulePageUrl("corpus/record"),
132
+ },
133
+ schema: [],
134
+ // One id per finding, each with the whole text of `corpusMessage`.
135
+ messages: Object.fromEntries(
136
+ (
137
+ [
138
+ "unparsed",
139
+ "unclaimed",
140
+ "missing",
141
+ "twice",
142
+ ] satisfies readonly CorpusFinding["kind"][]
143
+ ).map((id) => [id, "{{text}}"]),
144
+ ),
145
+ };
146
+
147
+ /** The rule, reading the corpus through `deps`. */
148
+ export function corpusRecordRules(
149
+ deps: CorpusRecordDeps,
150
+ ): Readonly<Record<"record", JsonRuleModule>> {
151
+ return {
152
+ record: {
153
+ meta: META,
154
+ create(context) {
155
+ return {
156
+ Document() {
157
+ const { text, ast } = context.sourceCode;
158
+ findingsFor(context.filename, text, deps).forEach((f) => {
159
+ context.report({
160
+ loc: spanAt(ast, f.at),
161
+ messageId: f.kind,
162
+ data: { text: corpusMessage(f) },
163
+ });
164
+ });
165
+ },
166
+ };
167
+ },
168
+ },
169
+ };
170
+ }
171
+
172
+ /** On by default, on every corpus's `papers.json`. */
173
+ export const CORPUS_RECORD_RULE_LEVELS: Readonly<
174
+ Record<"corpus/record", "error">
175
+ > = { "corpus/record": "error" };