paperlint 18.3.2 → 18.4.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.
- package/dist/adapters/memory/index.d.ts +6 -0
- package/dist/adapters/memory/index.d.ts.map +1 -1
- package/dist/adapters/memory/index.js +11 -0
- package/dist/adapters/memory/index.js.map +1 -1
- package/dist/adapters/node/index.d.ts +1 -0
- package/dist/adapters/node/index.d.ts.map +1 -1
- package/dist/adapters/node/index.js +1 -0
- package/dist/adapters/node/index.js.map +1 -1
- package/dist/adapters/node/list-tree.io.d.ts +3 -0
- package/dist/adapters/node/list-tree.io.d.ts.map +1 -0
- package/dist/adapters/node/list-tree.io.js +23 -0
- package/dist/adapters/node/list-tree.io.js.map +1 -0
- package/dist/adapters/study-registry/index.d.ts +2 -2
- package/dist/artifact-rules.d.ts +26 -0
- package/dist/artifact-rules.d.ts.map +1 -0
- package/dist/artifact-rules.js +117 -0
- package/dist/artifact-rules.js.map +1 -0
- package/dist/cli.d.ts +2 -1
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +49 -20
- package/dist/cli.js.map +1 -1
- package/dist/domain/artifact.d.ts +36 -0
- package/dist/domain/artifact.d.ts.map +1 -0
- package/dist/domain/artifact.js +116 -0
- package/dist/domain/artifact.js.map +1 -0
- package/dist/domain/paper-dirs.d.ts +16 -0
- package/dist/domain/paper-dirs.d.ts.map +1 -0
- package/dist/domain/paper-dirs.js +42 -0
- package/dist/domain/paper-dirs.js.map +1 -0
- package/dist/lib/paper-config.d.ts.map +1 -1
- package/dist/lib/paper-config.js +2 -0
- package/dist/lib/paper-config.js.map +1 -1
- package/dist/paper-files.d.ts +25 -42
- package/dist/paper-files.d.ts.map +1 -1
- package/dist/paper-files.js +101 -9
- package/dist/paper-files.js.map +1 -1
- package/dist/paper-settings.d.ts +3 -0
- package/dist/paper-settings.d.ts.map +1 -1
- package/dist/paper-settings.js +19 -16
- package/dist/paper-settings.js.map +1 -1
- package/dist/ports/list-tree.d.ts +11 -0
- package/dist/ports/list-tree.d.ts.map +1 -0
- package/dist/ports/list-tree.js +2 -0
- package/dist/ports/list-tree.js.map +1 -0
- package/docs/configuration.md +2 -1
- package/docs/rules/artifact/promised.md +64 -0
- package/docs/rules/artifact/required-files.md +65 -0
- package/docs/rules.md +2 -0
- package/lib/paper-config.ts +3 -0
- package/package.json +1 -1
- package/src/adapters/memory/index.test.ts +9 -0
- package/src/adapters/memory/index.ts +15 -0
- package/src/adapters/node/index.ts +1 -0
- package/src/adapters/node/list-tree.io.ts +27 -0
- package/src/adapters/node/list-tree.test.ts +38 -0
- package/src/artifact-rules.test.ts +50 -0
- package/src/artifact-rules.ts +188 -0
- package/src/cli.test.ts +122 -0
- package/src/cli.ts +59 -18
- package/src/domain/artifact.test.ts +154 -0
- package/src/domain/artifact.ts +171 -0
- package/src/domain/paper-dirs.test.ts +91 -0
- package/src/domain/paper-dirs.ts +62 -0
- package/src/new-paper.test.ts +9 -3
- package/src/paper-files.test.ts +88 -0
- package/src/paper-files.ts +98 -9
- package/src/paper-settings-commands.test.ts +18 -0
- package/src/paper-settings.test.ts +19 -0
- package/src/paper-settings.ts +21 -16
- package/src/ports/list-tree.ts +11 -0
- package/src/rule-cases.test.ts +134 -1
package/src/new-paper.test.ts
CHANGED
|
@@ -73,7 +73,6 @@ describe("paperlint new — paperlint.json", () => {
|
|
|
73
73
|
from: "package",
|
|
74
74
|
});
|
|
75
75
|
const s = settingsOf(join(papers, "demo"));
|
|
76
|
-
expect(s["extends"]).toBeNull();
|
|
77
76
|
expect(String(s["$comment"])).toMatch(/paperlint:agenticdev-2026/);
|
|
78
77
|
expect(parsePaperSettings(s)).toEqual({
|
|
79
78
|
ok: true,
|
|
@@ -88,6 +87,7 @@ describe("paperlint new — paperlint.json", () => {
|
|
|
88
87
|
authors: null,
|
|
89
88
|
fields: null,
|
|
90
89
|
cycles: null,
|
|
90
|
+
artifact: null,
|
|
91
91
|
},
|
|
92
92
|
});
|
|
93
93
|
});
|
|
@@ -842,7 +842,8 @@ describe("paperlint lint — a scaffolded paper has no layout finding", () => {
|
|
|
842
842
|
|
|
843
843
|
describe("paperlint lint — extra/ is never read", () => {
|
|
844
844
|
// An archived snapshot of an older paper carries every marker a paper does. Under extra/ it is
|
|
845
|
-
// spillover the layout promises never to judge; anywhere else
|
|
845
|
+
// spillover the layout promises never to judge; anywhere else inside the paper it is a copy, and
|
|
846
|
+
// lint claims only the paper's own files (#582).
|
|
846
847
|
const SNAPSHOT = (dir: string) => ({
|
|
847
848
|
[`${dir}/PIPELINE-STATUS.md`]: "# Pipeline status\n",
|
|
848
849
|
[`${dir}/notes.txt`]: "x\n",
|
|
@@ -853,8 +854,13 @@ describe("paperlint lint — extra/ is never read", () => {
|
|
|
853
854
|
expect(ids).toEqual(["pdf/measured", "paper/sources-fresh"]);
|
|
854
855
|
});
|
|
855
856
|
|
|
856
|
-
it("the same snapshot
|
|
857
|
+
it("the same snapshot elsewhere in the paper is a copy, not a paper: no rule reads it either (#582)", async () => {
|
|
857
858
|
const { ids } = await lintScaffold(SNAPSHOT("research/old-2025"));
|
|
859
|
+
expect(ids).toEqual(["pdf/measured", "paper/sources-fresh"]);
|
|
860
|
+
});
|
|
861
|
+
|
|
862
|
+
it("a stray file at the paper's own top level is reported, so the two tests above can fail", async () => {
|
|
863
|
+
const { ids } = await lintScaffold({ "notes.txt": "x\n" });
|
|
858
864
|
expect(ids).toContain("paper/allowed-files-only");
|
|
859
865
|
});
|
|
860
866
|
});
|
package/src/paper-files.test.ts
CHANGED
|
@@ -25,15 +25,103 @@ import {
|
|
|
25
25
|
narrowToOwners,
|
|
26
26
|
ownedPatterns,
|
|
27
27
|
ownedScopes,
|
|
28
|
+
paperFiles,
|
|
29
|
+
papersScope,
|
|
30
|
+
rebaseGlob,
|
|
28
31
|
ruleOwners,
|
|
29
32
|
scopeToOwned,
|
|
30
33
|
} from "./paper-files.ts";
|
|
34
|
+
import { FRAGMENT_FILES } from "./paper-includes.ts";
|
|
35
|
+
|
|
31
36
|
import { lintReport } from "../test/lint-report.ts";
|
|
32
37
|
import { z } from "zod";
|
|
33
38
|
|
|
34
39
|
/** What `calculateConfigForFile` answers for a file inside the config's scope, read for its rules. */
|
|
35
40
|
const Computed = z.object({ rules: z.record(z.string(), z.unknown()) });
|
|
36
41
|
|
|
42
|
+
describe("the papers the config claims (#582)", () => {
|
|
43
|
+
it("🔴 GUARD: with papers named, every file a block of paperlint's own claims is one of theirs", () => {
|
|
44
|
+
// A block written the old way, `**/paper.tex`, would claim a copy of a paper kept inside it (a
|
|
45
|
+
// review snapshot, a build copy) as a paper of its own. The fragment block is scoped per paper
|
|
46
|
+
// by name instead (includeBlocks), so its glob is not a paper's.
|
|
47
|
+
const claimed = ownedPatterns(
|
|
48
|
+
buildConfig(
|
|
49
|
+
{},
|
|
50
|
+
texLanguage,
|
|
51
|
+
papersScope(["/w/papers/p", "/w/papers/q"], "/w"),
|
|
52
|
+
),
|
|
53
|
+
).filter((g) => !FRAGMENT_FILES.includes(g));
|
|
54
|
+
expect(
|
|
55
|
+
claimed.filter(
|
|
56
|
+
(g) => !g.startsWith("papers/p/") && !g.startsWith("papers/q/"),
|
|
57
|
+
),
|
|
58
|
+
).toEqual([]);
|
|
59
|
+
expect(claimed).toContain("papers/q/paper.tex");
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it("names each paper relative to ESLint's cwd, glob characters escaped, and puts its files under it", () => {
|
|
63
|
+
const scope = papersScope(
|
|
64
|
+
["/w/papers/p", "/w/papers/[draft] x*", "/w"],
|
|
65
|
+
"/w",
|
|
66
|
+
);
|
|
67
|
+
expect(paperFiles(scope, "reviews/*.md")).toEqual([
|
|
68
|
+
"papers/p/reviews/*.md",
|
|
69
|
+
"papers/\\[draft\\] x\\*/reviews/*.md",
|
|
70
|
+
"reviews/*.md",
|
|
71
|
+
]);
|
|
72
|
+
expect(paperFiles({ kind: "any" }, "paper.tex")).toEqual(["**/paper.tex"]);
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
describe("a paper's own settings read from its folder (#582)", () => {
|
|
77
|
+
it.each([
|
|
78
|
+
["the same folder", "papers/a/paper.tex", "/w", ["papers/a/paper.tex"]],
|
|
79
|
+
[
|
|
80
|
+
"a paper's own folder",
|
|
81
|
+
"papers/a/paper.tex",
|
|
82
|
+
"/w/papers/a",
|
|
83
|
+
["paper.tex"],
|
|
84
|
+
],
|
|
85
|
+
["another paper's folder", "papers/a/paper.tex", "/w/papers/b", []],
|
|
86
|
+
["a folder above cwd", "papers/a/paper.tex", "/", ["w/papers/a/paper.tex"]],
|
|
87
|
+
[
|
|
88
|
+
"any folder",
|
|
89
|
+
"**/siblings/README.md",
|
|
90
|
+
"/w/papers/a",
|
|
91
|
+
["**/siblings/README.md"],
|
|
92
|
+
],
|
|
93
|
+
])(
|
|
94
|
+
"rebases a cwd-relative glob onto a block's basePath: %s",
|
|
95
|
+
(_, glob, base, want) => {
|
|
96
|
+
expect(rebaseGlob(glob, "/w", base)).toEqual(want);
|
|
97
|
+
},
|
|
98
|
+
);
|
|
99
|
+
|
|
100
|
+
it("a paper's own block gets its paper's files, relative to its folder, and none of another paper's", () => {
|
|
101
|
+
const own = buildConfig(
|
|
102
|
+
{},
|
|
103
|
+
texLanguage,
|
|
104
|
+
papersScope(["/w/papers/a"], "/w"),
|
|
105
|
+
);
|
|
106
|
+
const scope = papersScope(["/w/papers/a"], "/w");
|
|
107
|
+
const block = (basePath: string) =>
|
|
108
|
+
narrowToOwners(
|
|
109
|
+
{ basePath, rules: { "paper/stages": "warn" } },
|
|
110
|
+
ruleOwners(own),
|
|
111
|
+
scope,
|
|
112
|
+
);
|
|
113
|
+
expect(block("/w/papers/a")).toEqual([
|
|
114
|
+
{
|
|
115
|
+
basePath: "/w/papers/a",
|
|
116
|
+
files: ["PIPELINE-STATUS.md"],
|
|
117
|
+
rules: { "paper/stages": "warn" },
|
|
118
|
+
},
|
|
119
|
+
]);
|
|
120
|
+
// ESLint refuses an empty `files`, so a block that can reach no claimed file is not emitted.
|
|
121
|
+
expect(block("/w/papers/b")).toEqual([]);
|
|
122
|
+
});
|
|
123
|
+
});
|
|
124
|
+
|
|
37
125
|
const dirs: string[] = [];
|
|
38
126
|
afterEach(() => {
|
|
39
127
|
for (const d of dirs.splice(0)) rmSync(d, { recursive: true, force: true });
|
package/src/paper-files.ts
CHANGED
|
@@ -40,8 +40,71 @@
|
|
|
40
40
|
* - later global-ignore patterns win, across blocks, in config order;
|
|
41
41
|
* - `files: [["a", "b"]]` matches a file only when BOTH patterns match.
|
|
42
42
|
*/
|
|
43
|
+
import { relative, sep } from "node:path";
|
|
43
44
|
import type { ConfigBlock, RuleBlock, RuleEntry } from "./rules-config.ts";
|
|
44
45
|
|
|
46
|
+
/**
|
|
47
|
+
* Which papers' own files paperlint's blocks claim. `any` is the config's SHAPE, for the rule list and
|
|
48
|
+
* the docs: a file in any folder. `papers` is what `paperlint lint` runs on: the real papers, as glob
|
|
49
|
+
* prefixes relative to ESLint's `cwd` ("" for `cwd` itself), so a copy of a paper kept inside one (a
|
|
50
|
+
* review snapshot, a build copy) is claimed by no block (#582).
|
|
51
|
+
*/
|
|
52
|
+
export type PaperScope =
|
|
53
|
+
| { readonly kind: "any" }
|
|
54
|
+
| {
|
|
55
|
+
readonly kind: "papers";
|
|
56
|
+
readonly cwd: string;
|
|
57
|
+
readonly prefixes: readonly string[];
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
export const ANY_PAPER: PaperScope = { kind: "any" };
|
|
61
|
+
|
|
62
|
+
/** The characters a glob reads as syntax, escaped so a folder's name matches only itself. Pure. */
|
|
63
|
+
const literalGlob = (path: string): string =>
|
|
64
|
+
path.replace(/[\\*?[\]{}()!+@]/gu, "\\$&");
|
|
65
|
+
|
|
66
|
+
/** `to` relative to `from`, `/`-separated. Pure. */
|
|
67
|
+
const posixRelative = (from: string, to: string): string =>
|
|
68
|
+
relative(from, to).split(sep).join("/");
|
|
69
|
+
|
|
70
|
+
/** The papers `dirs` under ESLint's `cwd`: the scope `paperlint lint` lints. Pure. */
|
|
71
|
+
export const papersScope = (
|
|
72
|
+
dirs: readonly string[],
|
|
73
|
+
cwd: string,
|
|
74
|
+
): PaperScope => ({
|
|
75
|
+
kind: "papers",
|
|
76
|
+
cwd,
|
|
77
|
+
prefixes: dirs.map((d) => literalGlob(posixRelative(cwd, d))),
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
/** A glob of a paper's own file (`paper.tex`, `reviews/*.md`) in each paper of `scope`. Pure. */
|
|
81
|
+
export const paperFiles = (
|
|
82
|
+
scope: PaperScope,
|
|
83
|
+
glob: string,
|
|
84
|
+
): readonly string[] =>
|
|
85
|
+
scope.kind === "any"
|
|
86
|
+
? [`**/${glob}`]
|
|
87
|
+
: scope.prefixes.map((p) => (p === "" ? glob : `${p}/${glob}`));
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* A glob relative to `cwd`, as the block whose `basePath` is `base` must write it — ESLint reads a
|
|
91
|
+
* block's patterns from its `basePath`, and a paper's own settings carry the paper's folder. None
|
|
92
|
+
* when the glob names files outside `base`: that block can never reach them. A glob that starts with
|
|
93
|
+
* `**` matches at any depth and is kept as it is. Pure.
|
|
94
|
+
*/
|
|
95
|
+
export const rebaseGlob = (
|
|
96
|
+
glob: string,
|
|
97
|
+
cwd: string,
|
|
98
|
+
base: string,
|
|
99
|
+
): readonly string[] => {
|
|
100
|
+
if (glob.startsWith("**")) return [glob];
|
|
101
|
+
const up = posixRelative(base, cwd);
|
|
102
|
+
if (!up.startsWith(".."))
|
|
103
|
+
return [up === "" ? glob : `${literalGlob(up)}/${glob}`];
|
|
104
|
+
const down = `${literalGlob(posixRelative(cwd, base))}/`;
|
|
105
|
+
return glob.startsWith(down) ? [glob.slice(down.length)] : [];
|
|
106
|
+
};
|
|
107
|
+
|
|
45
108
|
/**
|
|
46
109
|
* A set of files paperlint lints: an own block's globs and the exceptions that block makes. A file is
|
|
47
110
|
* in it when it matches one of `files` and none of `ignores`.
|
|
@@ -158,6 +221,7 @@ export function ruleOwners(
|
|
|
158
221
|
export function narrowToOwners(
|
|
159
222
|
block: RuleBlock,
|
|
160
223
|
owners: ReadonlyMap<string, readonly OwnedScope[]>,
|
|
224
|
+
papers: PaperScope = ANY_PAPER,
|
|
161
225
|
): ScopedBlock[] {
|
|
162
226
|
// Keyed by the owner's JSON, so rules with equal owners share one group of blocks.
|
|
163
227
|
const groups = new Map<string, Record<string, RuleEntry>>();
|
|
@@ -170,24 +234,49 @@ export function narrowToOwners(
|
|
|
170
234
|
ownerOf.set(key, owner);
|
|
171
235
|
}
|
|
172
236
|
return [...ownerOf].flatMap(([key, owner]) =>
|
|
173
|
-
owner.
|
|
237
|
+
owner.flatMap((scope) =>
|
|
238
|
+
within(block, rebased(scope, papers, block.basePath), {
|
|
239
|
+
...groups.get(key),
|
|
240
|
+
}),
|
|
241
|
+
),
|
|
174
242
|
);
|
|
175
243
|
}
|
|
176
244
|
|
|
177
|
-
/**
|
|
245
|
+
/**
|
|
246
|
+
* `scope` as the block with `basePath` `base` must write it. The scope's globs are relative to ESLint's
|
|
247
|
+
* `cwd`; a paper's own settings are read from the paper's folder (#582).
|
|
248
|
+
*/
|
|
249
|
+
function rebased(
|
|
250
|
+
scope: OwnedScope,
|
|
251
|
+
papers: PaperScope,
|
|
252
|
+
base: string,
|
|
253
|
+
): OwnedScope {
|
|
254
|
+
if (papers.kind === "any") return scope;
|
|
255
|
+
const onto = (globs: readonly string[]): readonly string[] =>
|
|
256
|
+
globs.flatMap((g) => rebaseGlob(g, papers.cwd, base));
|
|
257
|
+
return { files: onto(scope.files), ignores: onto(scope.ignores) };
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
/**
|
|
261
|
+
* `block`'s rules over the files both it and `scope` claim, minus both sets of exceptions; none when
|
|
262
|
+
* the scope claims no file the block can reach (ESLint refuses an empty `files`).
|
|
263
|
+
*/
|
|
178
264
|
function within(
|
|
179
265
|
block: RuleBlock,
|
|
180
266
|
scope: OwnedScope,
|
|
181
267
|
rules: Readonly<Record<string, RuleEntry>>,
|
|
182
|
-
): ScopedBlock {
|
|
268
|
+
): readonly ScopedBlock[] {
|
|
269
|
+
if (scope.files.length === 0) return [];
|
|
183
270
|
const files: readonly FilesEntry[] = block.files
|
|
184
271
|
? block.files.flatMap((f) => scope.files.map((o) => [f, o]))
|
|
185
272
|
: scope.files;
|
|
186
273
|
const ignores = [...(block.ignores ?? []), ...scope.ignores];
|
|
187
|
-
return
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
274
|
+
return [
|
|
275
|
+
{
|
|
276
|
+
basePath: block.basePath,
|
|
277
|
+
files,
|
|
278
|
+
...(ignores.length ? { ignores } : {}),
|
|
279
|
+
rules,
|
|
280
|
+
},
|
|
281
|
+
];
|
|
193
282
|
}
|
|
@@ -98,6 +98,24 @@ describe("🔴 an optional rule that reaches no paper — judged against the PRO
|
|
|
98
98
|
});
|
|
99
99
|
});
|
|
100
100
|
|
|
101
|
+
describe("paperlint lint — `rules` in a paper's paperlint.json as a list of blocks (#582)", () => {
|
|
102
|
+
it("turns a rule on for that paper alone, globs relative to the paper", async () => {
|
|
103
|
+
const root = project({
|
|
104
|
+
"papers/a/paperlint.json": JSON.stringify({
|
|
105
|
+
rules: [
|
|
106
|
+
{
|
|
107
|
+
files: ["paper.tex"],
|
|
108
|
+
rules: { "pdf/last-page-balance": "error" },
|
|
109
|
+
},
|
|
110
|
+
],
|
|
111
|
+
}),
|
|
112
|
+
});
|
|
113
|
+
const r = await lint(root);
|
|
114
|
+
expect(rulesIn(r.out, "a")).toContain("pdf/last-page-balance");
|
|
115
|
+
expect(rulesIn(r.out, "b")).not.toContain("pdf/last-page-balance");
|
|
116
|
+
});
|
|
117
|
+
});
|
|
118
|
+
|
|
101
119
|
describe("paperlint lint — `rules` in a paper's paperlint.json", () => {
|
|
102
120
|
it("turns an optional rule on for that paper alone", async () => {
|
|
103
121
|
const root = project({
|
|
@@ -36,6 +36,7 @@ describe("parsePaperSettings", () => {
|
|
|
36
36
|
authors: null,
|
|
37
37
|
fields: null,
|
|
38
38
|
cycles: null,
|
|
39
|
+
artifact: null,
|
|
39
40
|
},
|
|
40
41
|
});
|
|
41
42
|
expect(parsePaperSettings({})).toEqual({
|
|
@@ -51,6 +52,7 @@ describe("parsePaperSettings", () => {
|
|
|
51
52
|
authors: null,
|
|
52
53
|
fields: null,
|
|
53
54
|
cycles: null,
|
|
55
|
+
artifact: null,
|
|
54
56
|
},
|
|
55
57
|
});
|
|
56
58
|
});
|
|
@@ -69,6 +71,7 @@ describe("parsePaperSettings", () => {
|
|
|
69
71
|
authors: null,
|
|
70
72
|
fields: null,
|
|
71
73
|
cycles: null,
|
|
74
|
+
artifact: null,
|
|
72
75
|
},
|
|
73
76
|
});
|
|
74
77
|
});
|
|
@@ -191,6 +194,7 @@ const UNSET = {
|
|
|
191
194
|
authors: null,
|
|
192
195
|
fields: null,
|
|
193
196
|
cycles: null,
|
|
197
|
+
artifact: null,
|
|
194
198
|
};
|
|
195
199
|
|
|
196
200
|
describe("readPaperSettings — the root paperlint.json's defaults, the paper's file over them", () => {
|
|
@@ -252,6 +256,7 @@ describe("readPaperSettings — the root paperlint.json's defaults, the paper's
|
|
|
252
256
|
authors: null,
|
|
253
257
|
fields: null,
|
|
254
258
|
cycles: null,
|
|
259
|
+
artifact: null,
|
|
255
260
|
});
|
|
256
261
|
});
|
|
257
262
|
});
|
|
@@ -304,6 +309,7 @@ describe("paperRules — `rules` in paperlint.json", () => {
|
|
|
304
309
|
authors: null,
|
|
305
310
|
fields: null,
|
|
306
311
|
cycles: null,
|
|
312
|
+
artifact: null,
|
|
307
313
|
});
|
|
308
314
|
|
|
309
315
|
it("no rules: none", () => {
|
|
@@ -393,6 +399,19 @@ describe("talk in a paper's paperlint.json", () => {
|
|
|
393
399
|
});
|
|
394
400
|
});
|
|
395
401
|
|
|
402
|
+
it("🔴 artifact: parsed into the paper's settings, or refused naming the key", () => {
|
|
403
|
+
const r = parsePaperSettings({ artifact: { files: "a.txt" } });
|
|
404
|
+
expect(r.ok && r.value.artifact).toEqual({
|
|
405
|
+
source: { kind: "files", path: "a.txt" },
|
|
406
|
+
required: [],
|
|
407
|
+
promises: {},
|
|
408
|
+
});
|
|
409
|
+
expect(parsePaperSettings({ artifact: { dir: "/abs" } })).toEqual({
|
|
410
|
+
ok: false,
|
|
411
|
+
error: `"artifact.dir" must be a path relative to the paper, got "/abs"`,
|
|
412
|
+
});
|
|
413
|
+
});
|
|
414
|
+
|
|
396
415
|
describe("parsePaperSettings — `cycles`: the current attempt supplies extends, kind and submission", () => {
|
|
397
416
|
const closed = {
|
|
398
417
|
id: "alpha-2026",
|
package/src/paper-settings.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* One file name at two levels, one schema (lib/paper-config.mjs → SETTINGS_KEYS):
|
|
5
5
|
*
|
|
6
6
|
* paperlint.json the project (optional): papersDir, rules, defaults
|
|
7
|
-
* <paper>/paperlint.json this paper: { extends, kind, pdf, rules, identity, talk, submission, authors, fields } —
|
|
7
|
+
* <paper>/paperlint.json this paper: { extends, kind, pdf, rules, identity, talk, submission, authors, fields, artifact } —
|
|
8
8
|
* or `cycles`, from whose current attempt extends, kind and submission
|
|
9
9
|
* are DERIVED (src/domain/cycle.ts); the two forms do not mix
|
|
10
10
|
* a venue preset `paperlint:<name>` (shipped) or `./x.jsonc` (src/presets.ts)
|
|
@@ -47,6 +47,7 @@ import {
|
|
|
47
47
|
venueCycleOf,
|
|
48
48
|
type Cycles,
|
|
49
49
|
} from "./domain/cycle.ts";
|
|
50
|
+
import { parsePaperArtifact, type PaperArtifact } from "./domain/artifact.ts";
|
|
50
51
|
|
|
51
52
|
/** What one paper declares. Every absent field is null. */
|
|
52
53
|
export interface PaperSettings {
|
|
@@ -84,6 +85,8 @@ export interface PaperSettings {
|
|
|
84
85
|
* attempt's — derived, never written beside it. Never the root's.
|
|
85
86
|
*/
|
|
86
87
|
readonly cycles: Cycles | null;
|
|
88
|
+
/** Where the paper's reproduction artifact is and what the paper promises it holds (`artifact/contents`); null when absent. Never the root's. */
|
|
89
|
+
readonly artifact: PaperArtifact | null;
|
|
87
90
|
}
|
|
88
91
|
|
|
89
92
|
/** Why a paper's settings cannot be read. */
|
|
@@ -240,11 +243,14 @@ export function parsePaperSettings(
|
|
|
240
243
|
if (!rest.ok) return rest;
|
|
241
244
|
const cycles = cyclesField(json);
|
|
242
245
|
if (!cycles.ok) return cycles;
|
|
246
|
+
const artifact = parsePaperArtifact(json["artifact"]);
|
|
247
|
+
if (!artifact.ok) return artifact;
|
|
243
248
|
const flat = {
|
|
244
249
|
...fields.value,
|
|
245
250
|
...rest.value,
|
|
246
251
|
identity: identity.value,
|
|
247
252
|
cycles: cycles.value,
|
|
253
|
+
artifact: artifact.value,
|
|
248
254
|
};
|
|
249
255
|
return ok(
|
|
250
256
|
cycles.value === null ? flat : { ...flat, ...derived(cycles.value) },
|
|
@@ -321,6 +327,18 @@ const NO_DEFAULTS: Defaults = {
|
|
|
321
327
|
identity: null,
|
|
322
328
|
};
|
|
323
329
|
|
|
330
|
+
/** A paper that declares nothing. */
|
|
331
|
+
const NO_SETTINGS: PaperSettings = {
|
|
332
|
+
...NO_DEFAULTS,
|
|
333
|
+
rules: null,
|
|
334
|
+
talk: null,
|
|
335
|
+
submission: null,
|
|
336
|
+
authors: null,
|
|
337
|
+
fields: null,
|
|
338
|
+
cycles: null,
|
|
339
|
+
artifact: null,
|
|
340
|
+
};
|
|
341
|
+
|
|
324
342
|
/** Both lists, joined without repeats; null when neither side has one. */
|
|
325
343
|
const joined = (
|
|
326
344
|
a: readonly string[] | null,
|
|
@@ -334,26 +352,13 @@ function merge(
|
|
|
334
352
|
paper: PaperSettings | null,
|
|
335
353
|
): PaperSettings | null {
|
|
336
354
|
const r = root ?? NO_DEFAULTS;
|
|
337
|
-
const p = paper ??
|
|
338
|
-
...NO_DEFAULTS,
|
|
339
|
-
rules: null,
|
|
340
|
-
talk: null,
|
|
341
|
-
submission: null,
|
|
342
|
-
authors: null,
|
|
343
|
-
fields: null,
|
|
344
|
-
cycles: null,
|
|
345
|
-
};
|
|
355
|
+
const p = paper ?? NO_SETTINGS;
|
|
346
356
|
const merged: PaperSettings = {
|
|
357
|
+
...p,
|
|
347
358
|
extends: p.extends ?? r.extends,
|
|
348
359
|
kind: p.kind ?? r.kind,
|
|
349
360
|
pdf: p.pdf ?? r.pdf,
|
|
350
|
-
rules: p.rules,
|
|
351
361
|
identity: joined(r.identity, p.identity),
|
|
352
|
-
talk: p.talk,
|
|
353
|
-
submission: p.submission,
|
|
354
|
-
authors: p.authors,
|
|
355
|
-
fields: p.fields,
|
|
356
|
-
cycles: p.cycles,
|
|
357
362
|
};
|
|
358
363
|
return paper === null && Object.values(merged).every((v) => v === null)
|
|
359
364
|
? null
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Every file under a folder — what the artifact rules ask of a paper's artifact folder, to judge its
|
|
3
|
+
* top level and its promises' globs over the same list a committed `files` list gives.
|
|
4
|
+
*/
|
|
5
|
+
import type { AbsolutePath } from "../domain/paths.ts";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* The regular files under `dir`, at any depth, as paths relative to it (`/`-separated), sorted;
|
|
9
|
+
* null when `dir` is not a directory.
|
|
10
|
+
*/
|
|
11
|
+
export type ListTree = (dir: AbsolutePath) => readonly string[] | null;
|
package/src/rule-cases.test.ts
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
* `EXEMPT` with the reason; a case for a rule that is not registered fails too. A `_build/` file a
|
|
11
11
|
* rule reads is planted as the build would write it — no pdflatex, no network.
|
|
12
12
|
*/
|
|
13
|
-
import { readFileSync } from "node:fs";
|
|
13
|
+
import { mkdirSync, readFileSync } from "node:fs";
|
|
14
14
|
import { dirname, join } from "node:path";
|
|
15
15
|
import { fileURLToPath } from "node:url";
|
|
16
16
|
import { describe, expect, it } from "vitest";
|
|
@@ -813,7 +813,61 @@ const CHANGES_AT = `${P}/versions/beta-2027/changes.yaml`;
|
|
|
813
813
|
const DECLARED_CUT =
|
|
814
814
|
'- type: cut\n before: "We measured 63 repositories."\n why: too long\n reader_loses: the sample size\n drops: ["63"]\n';
|
|
815
815
|
|
|
816
|
+
/** A paper whose paperlint.json declares `artifact`, with the artifact's own files. */
|
|
817
|
+
const withArtifact = (
|
|
818
|
+
artifact: Readonly<Record<string, unknown>>,
|
|
819
|
+
files: Readonly<Record<string, string>> = {},
|
|
820
|
+
): Record<string, string> =>
|
|
821
|
+
paper(tex("x"), {
|
|
822
|
+
[`${P}/paperlint.json`]: JSON.stringify({ extends: null, artifact }),
|
|
823
|
+
...files,
|
|
824
|
+
});
|
|
825
|
+
/** The artifact in `extra/`, a folder the layout never judges. */
|
|
826
|
+
const ARTIFACT_DIR = "extra/artifact";
|
|
827
|
+
const LIST = "submission/artifact-files.txt";
|
|
828
|
+
const ARTIFACT_FILES: Readonly<Record<string, string>> = {
|
|
829
|
+
[`${P}/${ARTIFACT_DIR}/README.md`]: "# artifact\n",
|
|
830
|
+
[`${P}/${ARTIFACT_DIR}/LICENSE`]: "MIT\n",
|
|
831
|
+
[`${P}/${ARTIFACT_DIR}/data/prompts/a.md`]: "a\n",
|
|
832
|
+
};
|
|
833
|
+
const REQUIRED = ["README", "LICENSE"];
|
|
834
|
+
const PROMISES = { prompts: "**/prompts/*.md" };
|
|
835
|
+
|
|
816
836
|
const CASES: Readonly<Record<string, RuleCases>> = {
|
|
837
|
+
// A paper that requires README and LICENSE of an artifact holding only a README.
|
|
838
|
+
"artifact/required-files": {
|
|
839
|
+
reports: {
|
|
840
|
+
tree: withArtifact(
|
|
841
|
+
{ dir: ARTIFACT_DIR, required: REQUIRED },
|
|
842
|
+
{ [`${P}/${ARTIFACT_DIR}/README.md`]: "# artifact\n" },
|
|
843
|
+
),
|
|
844
|
+
file: `${P}/PIPELINE-STATUS.md`,
|
|
845
|
+
severity: 2,
|
|
846
|
+
line: 1,
|
|
847
|
+
},
|
|
848
|
+
// The same artifact with its LICENSE.
|
|
849
|
+
silent: withArtifact(
|
|
850
|
+
{ dir: ARTIFACT_DIR, required: REQUIRED },
|
|
851
|
+
ARTIFACT_FILES,
|
|
852
|
+
),
|
|
853
|
+
},
|
|
854
|
+
// A promise of prompts the artifact does not hold.
|
|
855
|
+
"artifact/promised": {
|
|
856
|
+
reports: {
|
|
857
|
+
tree: withArtifact(
|
|
858
|
+
{ dir: ARTIFACT_DIR, promises: PROMISES },
|
|
859
|
+
{ [`${P}/${ARTIFACT_DIR}/README.md`]: "# artifact\n" },
|
|
860
|
+
),
|
|
861
|
+
file: `${P}/PIPELINE-STATUS.md`,
|
|
862
|
+
severity: 2,
|
|
863
|
+
line: 1,
|
|
864
|
+
},
|
|
865
|
+
// The same promise in a committed list of a zip wrapped in one folder, the prompts there.
|
|
866
|
+
silent: withArtifact(
|
|
867
|
+
{ files: LIST, promises: PROMISES },
|
|
868
|
+
{ [`${P}/${LIST}`]: "artifact/\nartifact/data/prompts/a.md\n" },
|
|
869
|
+
),
|
|
870
|
+
},
|
|
817
871
|
"cycle/changes-since-approved": {
|
|
818
872
|
reports: {
|
|
819
873
|
tree: paper(tex("The rest is as before."), {
|
|
@@ -1629,11 +1683,13 @@ type Message = z.infer<typeof LintResults>[number]["messages"][number] & {
|
|
|
1629
1683
|
/** `paperlint lint --json` over the tree, in-process through the CLI: every message, by file. */
|
|
1630
1684
|
async function lintTree(
|
|
1631
1685
|
tree: Record<string, string | Uint8Array>,
|
|
1686
|
+
emptyDirs: readonly string[] = [],
|
|
1632
1687
|
): Promise<Message[]> {
|
|
1633
1688
|
const dir = writeTree(useTempDir("paperlint-rule-cases-"), {
|
|
1634
1689
|
"package.json": '{"name":"consumer","private":true}',
|
|
1635
1690
|
...tree,
|
|
1636
1691
|
});
|
|
1692
|
+
emptyDirs.forEach((d) => mkdirSync(join(dir, d), { recursive: true }));
|
|
1637
1693
|
const out: string[] = [];
|
|
1638
1694
|
await run(["lint", "--json"], {
|
|
1639
1695
|
cwd: dir,
|
|
@@ -1934,6 +1990,83 @@ describe("cycle/camera-ready-source, before the camera-ready is frozen", () => {
|
|
|
1934
1990
|
);
|
|
1935
1991
|
});
|
|
1936
1992
|
|
|
1993
|
+
const STATUS_AT = `${P}/PIPELINE-STATUS.md`;
|
|
1994
|
+
/** What the artifact rules say about `tree` (`emptyDirs` made too), as `file:line rule message`. */
|
|
1995
|
+
const said = async (
|
|
1996
|
+
tree: Record<string, string>,
|
|
1997
|
+
emptyDirs: readonly string[] = [],
|
|
1998
|
+
) =>
|
|
1999
|
+
(await lintTree(tree, emptyDirs))
|
|
2000
|
+
.filter((m) => (m.ruleId ?? "").startsWith("artifact/"))
|
|
2001
|
+
.map((m) => `${m.file}:${String(m.line)} ${m.ruleId ?? ""} ${m.message}`);
|
|
2002
|
+
|
|
2003
|
+
describe("the artifact rules through real ESLint: each message, both halves", () => {
|
|
2004
|
+
it(
|
|
2005
|
+
"🔴 a folder that does not exist: each rule says what it cannot check",
|
|
2006
|
+
{ timeout: CASE_TIMEOUT_MS },
|
|
2007
|
+
async () => {
|
|
2008
|
+
expect(
|
|
2009
|
+
await said(
|
|
2010
|
+
withArtifact({
|
|
2011
|
+
dir: ARTIFACT_DIR,
|
|
2012
|
+
required: ["README"],
|
|
2013
|
+
promises: PROMISES,
|
|
2014
|
+
}),
|
|
2015
|
+
),
|
|
2016
|
+
).toEqual([
|
|
2017
|
+
`${STATUS_AT}:1 artifact/required-files the artifact folder ${ARTIFACT_DIR} ("artifact.dir" in paperlint.json, relative to the paper) does not exist or is not a folder, so its required names cannot be checked`,
|
|
2018
|
+
`${STATUS_AT}:1 artifact/promised the artifact folder ${ARTIFACT_DIR} ("artifact.dir" in paperlint.json, relative to the paper) does not exist or is not a folder, so its promises cannot be checked`,
|
|
2019
|
+
]);
|
|
2020
|
+
},
|
|
2021
|
+
);
|
|
2022
|
+
|
|
2023
|
+
it(
|
|
2024
|
+
"🔴 a folder that exists and is empty: the name missing and the promise matching nothing, not the folder",
|
|
2025
|
+
{ timeout: CASE_TIMEOUT_MS },
|
|
2026
|
+
async () => {
|
|
2027
|
+
expect(
|
|
2028
|
+
await said(
|
|
2029
|
+
withArtifact({
|
|
2030
|
+
dir: ARTIFACT_DIR,
|
|
2031
|
+
required: ["README"],
|
|
2032
|
+
promises: PROMISES,
|
|
2033
|
+
}),
|
|
2034
|
+
[`${P}/${ARTIFACT_DIR}`],
|
|
2035
|
+
),
|
|
2036
|
+
).toEqual([
|
|
2037
|
+
`${STATUS_AT}:1 artifact/required-files the artifact (${ARTIFACT_DIR}) has no top-level README — any extension counts (README.md, README.txt, README); "artifact.required" in paperlint.json asks for one`,
|
|
2038
|
+
`${STATUS_AT}:1 artifact/promised the artifact promise "prompts" (**/prompts/*.md) matches no path of the artifact (${ARTIFACT_DIR}): the paper says the artifact holds it — add the files, or correct the glob in "artifact.promises"`,
|
|
2039
|
+
]);
|
|
2040
|
+
},
|
|
2041
|
+
);
|
|
2042
|
+
});
|
|
2043
|
+
|
|
2044
|
+
describe("the artifact rules through real ESLint: a committed list of paths", () => {
|
|
2045
|
+
it(
|
|
2046
|
+
"🔴 a list that does not exist, and one that names no file",
|
|
2047
|
+
{ timeout: CASE_TIMEOUT_MS },
|
|
2048
|
+
async () => {
|
|
2049
|
+
const declared = { files: LIST, required: ["README"] };
|
|
2050
|
+
expect(await said(withArtifact(declared))).toEqual([
|
|
2051
|
+
`${STATUS_AT}:1 artifact/required-files the artifact's list of paths ${LIST} ("artifact.files" in paperlint.json, relative to the paper) does not exist, so its required names cannot be checked`,
|
|
2052
|
+
]);
|
|
2053
|
+
expect(
|
|
2054
|
+
await said(withArtifact(declared, { [`${P}/${LIST}`]: "artifact/\n" })),
|
|
2055
|
+
).toEqual([
|
|
2056
|
+
`${STATUS_AT}:1 artifact/required-files the artifact's list of paths ${LIST} names no file, so its required names cannot be checked — write one path per line, relative to the artifact's root, as \`zipinfo -1\` or \`find . -type f\` print them`,
|
|
2057
|
+
]);
|
|
2058
|
+
},
|
|
2059
|
+
);
|
|
2060
|
+
|
|
2061
|
+
it(
|
|
2062
|
+
"a paper that declares no artifact: silent, the rules on by default all the same",
|
|
2063
|
+
{ timeout: CASE_TIMEOUT_MS },
|
|
2064
|
+
async () => {
|
|
2065
|
+
expect(await said(paper(tex("x")))).toEqual([]);
|
|
2066
|
+
},
|
|
2067
|
+
);
|
|
2068
|
+
});
|
|
2069
|
+
|
|
1937
2070
|
describe.each(Object.entries(CASES))("%s, through real ESLint", (id, c) => {
|
|
1938
2071
|
it(
|
|
1939
2072
|
`reports on ${c.reports.file}:${String(c.reports.line)} at severity ${String(c.reports.severity)}`,
|