paperlint 20.2.0 → 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 (62) hide show
  1. package/.claude-plugin/plugin.json +1 -1
  2. package/dist/adapters/venue-corpus/index.d.ts +17 -1
  3. package/dist/adapters/venue-corpus/index.d.ts.map +1 -1
  4. package/dist/adapters/venue-corpus/index.js +23 -7
  5. package/dist/adapters/venue-corpus/index.js.map +1 -1
  6. package/dist/cli.d.ts +4 -3
  7. package/dist/cli.d.ts.map +1 -1
  8. package/dist/cli.js +42 -13
  9. package/dist/cli.js.map +1 -1
  10. package/dist/corpus-record-rule.d.ts +65 -0
  11. package/dist/corpus-record-rule.d.ts.map +1 -0
  12. package/dist/corpus-record-rule.js +85 -0
  13. package/dist/corpus-record-rule.js.map +1 -0
  14. package/dist/domain/corpus-record.d.ts +51 -0
  15. package/dist/domain/corpus-record.d.ts.map +1 -0
  16. package/dist/domain/corpus-record.js +119 -0
  17. package/dist/domain/corpus-record.js.map +1 -0
  18. package/dist/domain/venue-corpus.d.ts +25 -3
  19. package/dist/domain/venue-corpus.d.ts.map +1 -1
  20. package/dist/domain/venue-corpus.js +4 -0
  21. package/dist/domain/venue-corpus.js.map +1 -1
  22. package/dist/paper-files.d.ts +10 -3
  23. package/dist/paper-files.d.ts.map +1 -1
  24. package/dist/paper-files.js +17 -2
  25. package/dist/paper-files.js.map +1 -1
  26. package/dist/papers-roots.d.ts +6 -0
  27. package/dist/papers-roots.d.ts.map +1 -1
  28. package/dist/papers-roots.js +14 -0
  29. package/dist/papers-roots.js.map +1 -1
  30. package/docs/design/venue-corpus.md +48 -27
  31. package/docs/layout.md +2 -2
  32. package/docs/rules/corpus/record.md +119 -0
  33. package/docs/rules.md +1 -0
  34. package/docs/venues.md +31 -20
  35. package/eslint.config.mjs +1 -0
  36. package/package.json +2 -1
  37. package/scripts/eslint-file-length.mjs +3 -3
  38. package/skills/study-accepted-papers/SKILL.md +14 -8
  39. package/skills/study-accepted-papers/SKILL.md.spec.ts +13 -7
  40. package/skills/study-accepted-papers/papers.schema.json +49 -2
  41. package/skills/study-accepted-papers/scripts/corpus-licences-core.js +2 -2
  42. package/skills/study-accepted-papers/scripts/corpus-licences-core.ts +2 -1
  43. package/skills/study-accepted-papers/scripts/corpus-licences.js +19 -9
  44. package/skills/study-accepted-papers/scripts/corpus-licences.test.ts +4 -1
  45. package/src/adapters/venue-corpus/index.test.ts +68 -10
  46. package/src/adapters/venue-corpus/index.ts +28 -8
  47. package/src/cli-e2e.test.mjs +2 -2
  48. package/src/cli.test.ts +1 -1
  49. package/src/cli.ts +57 -13
  50. package/src/corpus-record-rule.test.ts +228 -0
  51. package/src/corpus-record-rule.ts +175 -0
  52. package/src/domain/corpus-record.test.ts +163 -0
  53. package/src/domain/corpus-record.ts +210 -0
  54. package/src/domain/venue-corpus.ts +32 -3
  55. package/src/paper-files.test.ts +13 -4
  56. package/src/paper-files.ts +23 -2
  57. package/src/paper-settings-commands.test.ts +2 -2
  58. package/src/papers-roots.test.ts +34 -1
  59. package/src/papers-roots.ts +15 -0
  60. package/src/rule-cases.test.ts +15 -0
  61. package/src/settled-paper.test.ts +1 -1
  62. package/src/unowned-file.test.ts +1 -1
@@ -41,6 +41,7 @@
41
41
  * - `files: [["a", "b"]]` matches a file only when BOTH patterns match.
42
42
  */
43
43
  import { relative, sep } from "node:path";
44
+ import { CORPORA_DIR } from "./domain/corpus-record.ts";
44
45
  import type {
45
46
  ConfigBlock,
46
47
  RuleBlock,
@@ -52,7 +53,8 @@ import type {
52
53
  * Which papers' own files paperlint's blocks claim. `any` is the config's SHAPE, for the rule list and
53
54
  * the docs: a file in any folder. `papers` is what `paperlint lint` runs on: the real papers, as glob
54
55
  * prefixes relative to ESLint's `cwd` ("" for `cwd` itself), so a copy of a paper kept inside one (a
55
- * review snapshot, a build copy) is claimed by no block (#582).
56
+ * review snapshot, a build copy) is claimed by no block (#582); and the papers roots (absolute),
57
+ * whose `venues/` hold the venue corpora.
56
58
  */
57
59
  export type PaperScope =
58
60
  | { readonly kind: "any" }
@@ -60,6 +62,7 @@ export type PaperScope =
60
62
  readonly kind: "papers";
61
63
  readonly cwd: string;
62
64
  readonly prefixes: readonly string[];
65
+ readonly roots: readonly string[];
63
66
  };
64
67
 
65
68
  export const ANY_PAPER: PaperScope = { kind: "any" };
@@ -72,14 +75,16 @@ const literalGlob = (path: string): string =>
72
75
  const posixRelative = (from: string, to: string): string =>
73
76
  relative(from, to).split(sep).join("/");
74
77
 
75
- /** The papers `dirs` under ESLint's `cwd`: the scope `paperlint lint` lints. Pure. */
78
+ /** The papers `dirs` and the papers `roots` under ESLint's `cwd`: the scope `paperlint lint` lints. Pure. */
76
79
  export const papersScope = (
77
80
  dirs: readonly string[],
78
81
  cwd: string,
82
+ roots: readonly string[],
79
83
  ): PaperScope => ({
80
84
  kind: "papers",
81
85
  cwd,
82
86
  prefixes: dirs.map((d) => literalGlob(posixRelative(cwd, d))),
87
+ roots,
83
88
  });
84
89
 
85
90
  /** A glob of a paper's own file (`paper.tex`, `reviews/*.md`) in each paper of `scope`. Pure. */
@@ -91,6 +96,22 @@ export const paperFiles = (
91
96
  ? [`**/${glob}`]
92
97
  : scope.prefixes.map((p) => (p === "" ? glob : `${p}/${glob}`));
93
98
 
99
+ /**
100
+ * A glob of a file in each venue corpus, `<papers-root>/venues/<venue>/<glob>`; none for a root
101
+ * outside ESLint's `cwd`, whose files ESLint never lints. Pure.
102
+ */
103
+ export const corpusFiles = (
104
+ scope: PaperScope,
105
+ glob: string,
106
+ ): readonly string[] => {
107
+ const inCorpus = `${CORPORA_DIR}/*/${glob}`;
108
+ if (scope.kind === "any") return [`**/${inCorpus}`];
109
+ return scope.roots
110
+ .map((r) => posixRelative(scope.cwd, r))
111
+ .filter((r) => r !== ".." && !r.startsWith("../"))
112
+ .map((r) => (r === "" ? inCorpus : `${literalGlob(r)}/${inCorpus}`));
113
+ };
114
+
94
115
  /**
95
116
  * A glob relative to `cwd`, as the block whose `basePath` is `base` must write it — ESLint reads a
96
117
  * block's patterns from its `basePath`, and a paper's own settings carry the paper's folder. None
@@ -230,7 +230,7 @@ describe("paperlint lint — the venue preset's rules", () => {
230
230
  }),
231
231
  });
232
232
  const cfgOf = await import("./cli.ts").then((m) =>
233
- m.paperRuleBlocks([join(root, "papers")]),
233
+ m.paperRuleBlocks([join(root, "papers")], [join(root, "papers")]),
234
234
  );
235
235
  expect(cfgOf.ok && cfgOf.value.preset).toEqual([
236
236
  {
@@ -276,7 +276,7 @@ describe("paperlint lint — the paper over its preset, and the project's own pr
276
276
  }),
277
277
  });
278
278
  const blocks = await import("./cli.ts").then((m) =>
279
- m.paperRuleBlocks([join(root, "papers")]),
279
+ m.paperRuleBlocks([join(root, "papers")], [join(root, "papers")]),
280
280
  );
281
281
  // The preset's block comes first and the paper's own after it: the later block wins.
282
282
  expect(blocks.ok && blocks.value.preset[0]?.rules).toEqual({
@@ -4,7 +4,12 @@
4
4
  */
5
5
  import assert from "node:assert/strict";
6
6
  import { test } from "vitest";
7
- import { papersRoots, segmentsUnder, toPaths } from "./papers-roots.ts";
7
+ import {
8
+ inCorpus,
9
+ papersRoots,
10
+ segmentsUnder,
11
+ toPaths,
12
+ } from "./papers-roots.ts";
8
13
 
9
14
  test("a papers directory given as a string or as a list normalises to a list; anything else to none", () => {
10
15
  assert.deepEqual(
@@ -54,3 +59,31 @@ test("a path is placed under the first directory that holds it, by its segments"
54
59
  [["x", "paper.tex"], ["y"], null, null, null, ["..draft", "paper.tex"]],
55
60
  );
56
61
  });
62
+
63
+ test("a folder is in a venue corpus when it is `<root>/venues/<venue>/` or below it", () => {
64
+ const roots = ["/p/papers"];
65
+ assert.deepEqual(
66
+ [
67
+ "/p/papers/venues/agent",
68
+ "/p/papers/venues/agent/sources/x",
69
+ "/p/papers/venues",
70
+ "/p/papers/agent",
71
+ "/p/elsewhere/venues/agent",
72
+ ].map((d) => inCorpus(d, roots)),
73
+ [true, true, false, false, false],
74
+ );
75
+ });
76
+
77
+ test("🔴 a corpus under any of overlapping roots is a corpus, whichever root is listed first", () => {
78
+ // Guards: `papersDir: [".", "papers"]` — the corpus under the second root must still be excluded
79
+ // from the paper rules, not read through the first root as `papers/venues/agent`.
80
+ const dir = "/project/papers/venues/agent";
81
+ assert.deepEqual(
82
+ [
83
+ inCorpus(dir, ["/project", "/project/papers"]),
84
+ inCorpus(dir, ["/project/papers", "/project"]),
85
+ inCorpus("/project/papers/agent", ["/project", "/project/papers"]),
86
+ ],
87
+ [true, true, false],
88
+ );
89
+ });
@@ -11,6 +11,7 @@
11
11
  */
12
12
  import { isAbsolute, relative, resolve, sep } from "node:path";
13
13
  import { DEFAULT_PAPERS_ROOT } from "#lib/paper-config";
14
+ import { CORPORA_DIR } from "./domain/corpus-record.ts";
14
15
 
15
16
  /** The papers directory field of the settings, read by its one declared name; the default when absent. */
16
17
  export function papersDirOf(opts: { readonly papersDir?: unknown }): unknown {
@@ -54,3 +55,17 @@ export function segmentsUnder(
54
55
  );
55
56
  return below === undefined ? null : below.split(sep);
56
57
  }
58
+
59
+ /**
60
+ * Whether the absolute folder `dir` is a venue corpus of one of `roots`, or inside one:
61
+ * `<root>/venues/<venue>/` and below. A paper found there is an accepted paper's source kept in the
62
+ * corpus, not one of the project's papers (#215), so no paper rule judges it.
63
+ */
64
+ export function inCorpus(dir: string, roots: readonly string[]): boolean {
65
+ // Each root on its own: roots may overlap (`.` and `papers`), and the first that holds `dir` need
66
+ // not be the one whose `venues/` it is in.
67
+ return roots.some((root) => {
68
+ const [first, venue] = segmentsUnder(dir, [root]) ?? [];
69
+ return first === CORPORA_DIR && venue !== undefined;
70
+ });
71
+ }
@@ -42,6 +42,8 @@ const fixture = (p: string): string =>
42
42
  readFileSync(join(ROOT, "fixtures", p), "utf8");
43
43
 
44
44
  const P = "papers/p";
45
+ const CORPUS_RECORD = "papers/venues/agent/papers.json";
46
+ const EMPTY_RECORD = '{"venue":"agent","editions":[],"papers":[],"rebuild":[]}';
45
47
  const STATUS = "---\nstages: []\n---\n# PIPELINE-STATUS\n";
46
48
  const tex = (body: string, cls = "\\documentclass{article}"): string =>
47
49
  `${cls}\n\\begin{document}\n${body}\n\\end{document}\n`;
@@ -1280,6 +1282,19 @@ const CASES: Readonly<Record<string, RuleCases>> = {
1280
1282
  [`${P}/extra/PLAN.md`]: "# plan\n",
1281
1283
  }),
1282
1284
  },
1285
+ // A venue corpus storing a PDF its papers.json lists no paper for; silent while it stores nothing.
1286
+ "corpus/record": {
1287
+ reports: {
1288
+ tree: paper(tex("x"), {
1289
+ [CORPUS_RECORD]: EMPTY_RECORD,
1290
+ "papers/venues/agent/pdf/a.pdf": "",
1291
+ }),
1292
+ file: CORPUS_RECORD,
1293
+ severity: 2,
1294
+ line: 1,
1295
+ },
1296
+ silent: paper(tex("x"), { [CORPUS_RECORD]: EMPTY_RECORD }),
1297
+ },
1283
1298
  // A loose script at the top of repro/: it belongs in repro/tools/.
1284
1299
  "repro/allowed-files-only": {
1285
1300
  reports: {
@@ -60,7 +60,7 @@ function paper(
60
60
 
61
61
  /** The blocks the paper's stage adds. */
62
62
  function stageBlocks(dir: string) {
63
- const r = paperRuleBlocks([dir]);
63
+ const r = paperRuleBlocks([dir], []);
64
64
  assert.ok(r.ok, r.ok ? "" : r.error);
65
65
  return r.value.stage;
66
66
  }
@@ -88,7 +88,7 @@ describe("any other unowned file keeps the general refusal, without the glob it
88
88
  const r = await lint(dir, "papers/a/repro/x.js");
89
89
  expect(r.code).toBe(2);
90
90
  expect(r.err).toBe(
91
- "papers/a/repro/x.js is not a file paperlint lints — it lints **/PIPELINE-STATUS.md, **/reviews/*.md, **/paper.tex, **/siblings/*.md, and the .tex files a built paper.tex includes",
91
+ "papers/a/repro/x.js is not a file paperlint lints — it lints **/PIPELINE-STATUS.md, **/venues/*/papers.json, **/reviews/*.md, **/paper.tex, **/siblings/*.md, and the .tex files a built paper.tex includes",
92
92
  );
93
93
  });
94
94