paperlint 20.4.0 → 20.5.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.
- package/.claude-plugin/plugin.json +1 -1
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +51 -19
- package/dist/cli.js.map +1 -1
- package/dist/corpus-layout-rule.d.ts +11 -0
- package/dist/corpus-layout-rule.d.ts.map +1 -0
- package/dist/corpus-layout-rule.js +92 -0
- package/dist/corpus-layout-rule.js.map +1 -0
- package/dist/corpus-record-rule.d.ts.map +1 -1
- package/dist/corpus-record-rule.js +2 -1
- package/dist/corpus-record-rule.js.map +1 -1
- package/dist/domain/corpus-layout.d.ts +30 -0
- package/dist/domain/corpus-layout.d.ts.map +1 -0
- package/dist/domain/corpus-layout.js +101 -0
- package/dist/domain/corpus-layout.js.map +1 -0
- package/dist/domain/paper-layout.d.ts +3 -2
- package/dist/domain/paper-layout.d.ts.map +1 -1
- package/dist/domain/paper-layout.js +3 -2
- package/dist/domain/paper-layout.js.map +1 -1
- package/dist/paper-files.d.ts +11 -4
- package/dist/paper-files.d.ts.map +1 -1
- package/dist/paper-files.js +16 -2
- package/dist/paper-files.js.map +1 -1
- package/docs/layout.md +2 -2
- package/docs/rules/corpus/allowed-files-only.md +99 -0
- package/docs/rules/corpus/record.md +4 -3
- package/docs/rules.md +1 -0
- package/docs/venues.md +10 -7
- package/package.json +1 -1
- package/src/cli-e2e.test.mjs +2 -2
- package/src/cli.ts +64 -17
- package/src/corpus-layout-rule.test.ts +177 -0
- package/src/corpus-layout-rule.ts +145 -0
- package/src/corpus-record-rule.test.ts +15 -4
- package/src/corpus-record-rule.ts +2 -1
- package/src/domain/corpus-layout.test.ts +118 -0
- package/src/domain/corpus-layout.ts +159 -0
- package/src/domain/paper-layout.ts +3 -2
- package/src/layout-docs.test.ts +3 -1
- package/src/paper-files.ts +19 -3
- package/src/rule-cases.test.ts +20 -42
- package/src/unowned-file.test.ts +1 -1
package/src/cli.ts
CHANGED
|
@@ -141,6 +141,7 @@ import {
|
|
|
141
141
|
ownedPatterns,
|
|
142
142
|
paperFiles,
|
|
143
143
|
papersScope,
|
|
144
|
+
rootSettingsFile,
|
|
144
145
|
ruleOwners,
|
|
145
146
|
scopeToOwned,
|
|
146
147
|
} from "./paper-files.ts";
|
|
@@ -246,6 +247,11 @@ import {
|
|
|
246
247
|
CORPUS_RECORD_RULE_LEVELS,
|
|
247
248
|
corpusRecordRules,
|
|
248
249
|
} from "./corpus-record-rule.ts";
|
|
250
|
+
import {
|
|
251
|
+
CORPUS_LAYOUT_RULE_LEVELS,
|
|
252
|
+
corpusLayoutRules,
|
|
253
|
+
} from "./corpus-layout-rule.ts";
|
|
254
|
+
import { CORPORA_DIR } from "./domain/corpus-record.ts";
|
|
249
255
|
import { CORPUS_RECORD } from "./domain/venue-corpus.ts";
|
|
250
256
|
import { venueCorpusCodec } from "./adapters/venue-corpus/index.ts";
|
|
251
257
|
import { paperFolderOf, writtenPath } from "./domain/paper-folder.ts";
|
|
@@ -659,22 +665,35 @@ const TALK_RULE_DEPS = {
|
|
|
659
665
|
/**
|
|
660
666
|
* A venue corpus, `<papers-root>/venues/<venue>/`, reached through its `papers.json`, linted with
|
|
661
667
|
* ESLint's JSON language so `corpus/record` reports at the field (docs/design/venue-corpus.md,
|
|
662
|
-
* decision 4)
|
|
668
|
+
* decision 4); and the root `paperlint.json`, where `corpus/allowed-files-only` reports a corpus that
|
|
669
|
+
* has no `papers.json`. The JSON language reaches no other file: these blocks alone name it. Each
|
|
670
|
+
* registers only the rules it turns on, so a consumer's `corpus/record` never reaches the root file.
|
|
663
671
|
*/
|
|
664
|
-
const
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
672
|
+
const corpusBlocks = (papers: PaperScope): readonly ConfigBlock[] => {
|
|
673
|
+
const layout = corpusLayoutRules({
|
|
674
|
+
files: nodeFiles,
|
|
675
|
+
listDir: nodeListDir,
|
|
676
|
+
roots: papers.kind === "papers" ? papers.roots : [],
|
|
677
|
+
});
|
|
678
|
+
const record = corpusRecordRules({
|
|
679
|
+
entries: nodeListEntries,
|
|
680
|
+
codec: venueCorpusCodec,
|
|
681
|
+
});
|
|
682
|
+
return [
|
|
683
|
+
{
|
|
684
|
+
files: corpusFiles(papers, CORPUS_RECORD),
|
|
685
|
+
plugins: { json, corpus: { rules: { ...record, ...layout } } },
|
|
686
|
+
language: "json/json",
|
|
687
|
+
rules: { ...CORPUS_RECORD_RULE_LEVELS, ...CORPUS_LAYOUT_RULE_LEVELS },
|
|
673
688
|
},
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
689
|
+
{
|
|
690
|
+
files: rootSettingsFile(papers),
|
|
691
|
+
plugins: { json, corpus: { rules: layout } },
|
|
692
|
+
language: "json/json",
|
|
693
|
+
rules: CORPUS_LAYOUT_RULE_LEVELS,
|
|
694
|
+
},
|
|
695
|
+
];
|
|
696
|
+
};
|
|
678
697
|
|
|
679
698
|
/** The config the user would otherwise write by hand. The data comes from `opts`, the mechanism is here. */
|
|
680
699
|
export function buildConfig(
|
|
@@ -761,7 +780,7 @@ export function buildConfig(
|
|
|
761
780
|
...STATUS_CYCLE_RULE_LEVELS,
|
|
762
781
|
},
|
|
763
782
|
},
|
|
764
|
-
|
|
783
|
+
...corpusBlocks(papers),
|
|
765
784
|
{
|
|
766
785
|
files: own("reviews/*.md"),
|
|
767
786
|
plugins: { markdown, review: reviewFrontmatter },
|
|
@@ -2676,7 +2695,8 @@ export async function run(
|
|
|
2676
2695
|
if (!engine.ok) return (err(engine.error), 2);
|
|
2677
2696
|
const { eslint, opts: withPapers, bodies } = engine.value;
|
|
2678
2697
|
|
|
2679
|
-
const
|
|
2698
|
+
const linted = withRootSettings(cfg, a.paths.length === 0, paths);
|
|
2699
|
+
const unowned = await firstUnownedFile(eslint, linted);
|
|
2680
2700
|
if (unowned !== null) {
|
|
2681
2701
|
err(
|
|
2682
2702
|
refusalOf(
|
|
@@ -2700,7 +2720,7 @@ export async function run(
|
|
|
2700
2720
|
// an explicable one.
|
|
2701
2721
|
let results: ESLint.LintResult[];
|
|
2702
2722
|
try {
|
|
2703
|
-
results = await eslint.lintFiles([...
|
|
2723
|
+
results = await eslint.lintFiles([...linted]);
|
|
2704
2724
|
} catch (e) {
|
|
2705
2725
|
if (isEmptyLintSet(e)) results = [];
|
|
2706
2726
|
else throw e;
|
|
@@ -2746,6 +2766,32 @@ export async function run(
|
|
|
2746
2766
|
return code;
|
|
2747
2767
|
}
|
|
2748
2768
|
|
|
2769
|
+
/**
|
|
2770
|
+
* The project root whose `paperlint.json` is linted, or null: only where a papers root holds
|
|
2771
|
+
* `venues/`, since that file is where `corpus/allowed-files-only` reports a corpus without
|
|
2772
|
+
* `papers.json`. A project with no corpus lints exactly the files it linted before.
|
|
2773
|
+
*/
|
|
2774
|
+
const corpusHome = (cfg: {
|
|
2775
|
+
readonly opts: PaperlintConfig;
|
|
2776
|
+
readonly root: string;
|
|
2777
|
+
}): string | null =>
|
|
2778
|
+
papersRoots(cfg).some((r) => existsSync(join(r, CORPORA_DIR)))
|
|
2779
|
+
? cfg.root
|
|
2780
|
+
: null;
|
|
2781
|
+
|
|
2782
|
+
/** What `paperlint lint` hands ESLint: `paths`, and the root `paperlint.json` on a run of the whole project. */
|
|
2783
|
+
const withRootSettings = (
|
|
2784
|
+
cfg: { readonly opts: PaperlintConfig; readonly root: string },
|
|
2785
|
+
wholeProject: boolean,
|
|
2786
|
+
paths: readonly string[],
|
|
2787
|
+
): readonly string[] => {
|
|
2788
|
+
const home = corpusHome(cfg);
|
|
2789
|
+
const file = home === null ? null : join(home, CONFIG_FILE);
|
|
2790
|
+
return wholeProject && file !== null && existsSync(file)
|
|
2791
|
+
? [...paths, file]
|
|
2792
|
+
: paths;
|
|
2793
|
+
};
|
|
2794
|
+
|
|
2749
2795
|
/**
|
|
2750
2796
|
* The ESLint `paperlint lint` runs over `paths`, with the config it lints them by — ONE setup for
|
|
2751
2797
|
* `paperlint lint` and the `lint-edited` hook, so what the hook reports while a paper is written is
|
|
@@ -2809,6 +2855,7 @@ async function paperEslint(
|
|
|
2809
2855
|
paperDirs([...paths, ...roots], roots),
|
|
2810
2856
|
cwd,
|
|
2811
2857
|
roots,
|
|
2858
|
+
corpusHome(cfg),
|
|
2812
2859
|
);
|
|
2813
2860
|
const eslint = new ESLint({
|
|
2814
2861
|
cwd,
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `corpus/allowed-files-only` through `paperlint lint`, the way a consumer runs it: a stray name at
|
|
3
|
+
* the top of a corpus reported on its `papers.json`, and a corpus that stores copies with no
|
|
4
|
+
* `papers.json` reported on the project's root `paperlint.json`. The texts are pinned beside the
|
|
5
|
+
* domain (src/domain/corpus-layout.test.ts); here, where each finding lands and what it names.
|
|
6
|
+
*/
|
|
7
|
+
import { join } from "node:path";
|
|
8
|
+
import { describe, expect, it } from "vitest";
|
|
9
|
+
import { run } from "./cli.ts";
|
|
10
|
+
import { lintReport } from "../test/lint-report.ts";
|
|
11
|
+
import { useTempDir, writeTree } from "../test/support.ts";
|
|
12
|
+
|
|
13
|
+
const STATUS = "---\nstages: []\n---\n# PIPELINE-STATUS\n";
|
|
14
|
+
const TEX = "\\documentclass{article}\n\\begin{document}\nx\n\\end{document}\n";
|
|
15
|
+
const PAPER = {
|
|
16
|
+
"papers/p/PIPELINE-STATUS.md": STATUS,
|
|
17
|
+
"papers/p/paper.tex": TEX,
|
|
18
|
+
};
|
|
19
|
+
const C = "papers/venues/agent";
|
|
20
|
+
const RECORD = `${C}/papers.json`;
|
|
21
|
+
const EMPTY = '{"venue":"agent","editions":[],"papers":[],"rebuild":[]}';
|
|
22
|
+
const ID = "corpus/allowed-files-only";
|
|
23
|
+
|
|
24
|
+
/** `paperlint lint --json` run in `from`: the exit code, the linted files, and each finding as [file, line, the path it names]. */
|
|
25
|
+
async function lint(tree: Readonly<Record<string, string>>, from = ".") {
|
|
26
|
+
const dir = writeTree(useTempDir("paperlint-corpus-layout-"), {
|
|
27
|
+
"package.json": '{"name":"consumer","private":true}',
|
|
28
|
+
...tree,
|
|
29
|
+
});
|
|
30
|
+
const out: string[] = [];
|
|
31
|
+
const code = await run(["lint", "--json"], {
|
|
32
|
+
cwd: join(dir, from),
|
|
33
|
+
log: (...a: unknown[]) => out.push(a.join(" ")),
|
|
34
|
+
err: () => undefined,
|
|
35
|
+
});
|
|
36
|
+
const results = lintReport(out.join("\n"));
|
|
37
|
+
const rel = (p: string) => p.slice(dir.length + 1);
|
|
38
|
+
return {
|
|
39
|
+
code,
|
|
40
|
+
files: results.map((r) => rel(r.filePath)).sort(),
|
|
41
|
+
found: results.flatMap((r) =>
|
|
42
|
+
r.messages
|
|
43
|
+
.filter((m) => m.ruleId === ID)
|
|
44
|
+
.map((m) => [rel(r.filePath), m.line, m.message.split("`")[1]]),
|
|
45
|
+
),
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
describe("corpus/allowed-files-only: a name at the top of a corpus", () => {
|
|
50
|
+
it("🔴 reports a note, a folder and a script, each once, on papers.json", async () => {
|
|
51
|
+
const r = await lint({
|
|
52
|
+
...PAPER,
|
|
53
|
+
[RECORD]: EMPTY,
|
|
54
|
+
[`${C}/notes.md`]: "# notes\n",
|
|
55
|
+
[`${C}/scripts/fetch.sh`]: "echo\n",
|
|
56
|
+
[`${C}/x.py`]: "print(1)\n",
|
|
57
|
+
[`${C}/pdf/a.md`]: "inside pdf/: corpus/record's, not this rule's\n",
|
|
58
|
+
});
|
|
59
|
+
expect(r.found).toEqual(
|
|
60
|
+
["notes.md", "scripts/", "x.py"].map((n) => [
|
|
61
|
+
RECORD,
|
|
62
|
+
1,
|
|
63
|
+
`venues/agent/${n}`,
|
|
64
|
+
]),
|
|
65
|
+
);
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it("🔴 is silent on a corpus holding all seven names", async () => {
|
|
69
|
+
const r = await lint({
|
|
70
|
+
...PAPER,
|
|
71
|
+
[RECORD]: EMPTY,
|
|
72
|
+
[`${C}/MANIFEST.md`]: "# caveats\n",
|
|
73
|
+
[`${C}/measurements.json`]: "[]",
|
|
74
|
+
[`${C}/pdf/.gitkeep`]: "",
|
|
75
|
+
[`${C}/text/.gitkeep`]: "",
|
|
76
|
+
[`${C}/deep-reads/a.md`]: "# a\n",
|
|
77
|
+
[`${C}/sources/cfp.html`]: "<p>cfp</p>\n",
|
|
78
|
+
[`${C}/.DS_Store`]: "",
|
|
79
|
+
"papers/venues/README.md": "loose in venues/: not a corpus, not judged\n",
|
|
80
|
+
});
|
|
81
|
+
expect(r.found).toEqual([]);
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it("🔴 is silent on a project with no venues/, and lints no new file there", async () => {
|
|
85
|
+
// Guards: most consumers keep no corpus; the rule must cost them nothing, not even a file.
|
|
86
|
+
const r = await lint({ ...PAPER, "paperlint.json": "{}" });
|
|
87
|
+
expect({ found: r.found, files: r.files }).toEqual({
|
|
88
|
+
found: [],
|
|
89
|
+
files: ["papers/p/PIPELINE-STATUS.md", "papers/p/paper.tex"],
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
it("is turned off, both findings, in the root paperlint.json by one line", async () => {
|
|
94
|
+
const r = await lint({
|
|
95
|
+
...PAPER,
|
|
96
|
+
"paperlint.json": JSON.stringify({ rules: { [ID]: "off" } }),
|
|
97
|
+
[RECORD]: EMPTY,
|
|
98
|
+
[`${C}/notes.md`]: "# notes\n",
|
|
99
|
+
"papers/venues/other/pdf/a.pdf": "%PDF",
|
|
100
|
+
});
|
|
101
|
+
expect(r.found).toEqual([]);
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
describe("corpus/allowed-files-only: a corpus that stores copies with no papers.json", () => {
|
|
106
|
+
it("🔴 is reported on the root paperlint.json, once per corpus", async () => {
|
|
107
|
+
const r = await lint({
|
|
108
|
+
...PAPER,
|
|
109
|
+
"paperlint.json": "{}",
|
|
110
|
+
"papers/venues/agent/pdf/a.pdf": "%PDF",
|
|
111
|
+
"papers/venues/other/text/a.txt": "a",
|
|
112
|
+
"papers/venues/ids-only/MANIFEST.md": "# ids only\n",
|
|
113
|
+
"papers/venues/kept/papers.json": EMPTY.replace("agent", "kept"),
|
|
114
|
+
"papers/venues/kept/pdf/.gitkeep": "",
|
|
115
|
+
});
|
|
116
|
+
expect({ code: r.code, found: r.found }).toEqual({
|
|
117
|
+
code: 1,
|
|
118
|
+
found: [
|
|
119
|
+
["paperlint.json", 1, "papers/venues/agent/"],
|
|
120
|
+
["paperlint.json", 1, "papers/venues/other/"],
|
|
121
|
+
],
|
|
122
|
+
});
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
it("follows papersDir, and a paper's own paperlint.json is never linted", async () => {
|
|
126
|
+
const r = await lint({
|
|
127
|
+
"paperlint.json": '{"papersDir":"writing"}',
|
|
128
|
+
"writing/p/PIPELINE-STATUS.md": STATUS,
|
|
129
|
+
"writing/p/paper.tex": TEX,
|
|
130
|
+
"writing/p/paperlint.json": "{}",
|
|
131
|
+
"writing/venues/agent/pdf/a.pdf": "%PDF",
|
|
132
|
+
});
|
|
133
|
+
expect({ files: r.files, found: r.found }).toEqual({
|
|
134
|
+
files: [
|
|
135
|
+
"paperlint.json",
|
|
136
|
+
"writing/p/PIPELINE-STATUS.md",
|
|
137
|
+
"writing/p/paper.tex",
|
|
138
|
+
],
|
|
139
|
+
found: [["paperlint.json", 1, "writing/venues/agent/"]],
|
|
140
|
+
});
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
it("finds the root paperlint.json when the papers sit outside the project", async () => {
|
|
144
|
+
// ESLint then runs from the folder above both, and names the file through the project's folder.
|
|
145
|
+
const tree = {
|
|
146
|
+
"proj/package.json": '{"name":"consumer","private":true}',
|
|
147
|
+
"proj/paperlint.json": '{"papersDir":"../writing"}',
|
|
148
|
+
"writing/p/PIPELINE-STATUS.md": STATUS,
|
|
149
|
+
"writing/p/paper.tex": TEX,
|
|
150
|
+
"writing/venues/agent/text/a.txt": "a",
|
|
151
|
+
};
|
|
152
|
+
expect((await lint(tree, "proj")).found).toEqual([
|
|
153
|
+
["proj/paperlint.json", 1, "../writing/venues/agent/"],
|
|
154
|
+
]);
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
it("is silent with no root paperlint.json: there is no file to report on", async () => {
|
|
158
|
+
const r = await lint({ ...PAPER, [`${C}/pdf/a.pdf`]: "%PDF" });
|
|
159
|
+
expect({ code: r.code, found: r.found }).toEqual({ code: 0, found: [] });
|
|
160
|
+
});
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
describe("corpus/allowed-files-only: a file loose in venues/", () => {
|
|
164
|
+
it("🔴 a file loose in venues/ is reported there too; its index and corpus folders are not", async () => {
|
|
165
|
+
const r = await lint({
|
|
166
|
+
...PAPER,
|
|
167
|
+
"paperlint.json": "{}",
|
|
168
|
+
[RECORD]: EMPTY,
|
|
169
|
+
"papers/venues/README.md": "# the corpora\n",
|
|
170
|
+
"papers/venues/codebook.md": "# codes\n",
|
|
171
|
+
"papers/venues/scripts/check.py": "print(1)\n",
|
|
172
|
+
});
|
|
173
|
+
expect(r.found).toEqual([
|
|
174
|
+
["paperlint.json", 1, "papers/venues/codebook.md"],
|
|
175
|
+
]);
|
|
176
|
+
});
|
|
177
|
+
});
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `corpus/allowed-files-only` — the top of a venue corpus holds its seven fixed names, and a corpus
|
|
3
|
+
* that stores copies has the record that names them (docs/design/venue-corpus.md, decisions 4 and 5;
|
|
4
|
+
* docs/rules/corpus/allowed-files-only.md). What may stand there is `src/domain/corpus-layout.ts`;
|
|
5
|
+
* this file lists the folders and reports.
|
|
6
|
+
*
|
|
7
|
+
* ── WHERE IT REPORTS ─────────────────────────────────────────────────────────────
|
|
8
|
+
* A stray name: on the corpus's `papers.json`, first line, the file `corpus/record` is linted on. A
|
|
9
|
+
* corpus that keeps `pdf/` or `text/` and has no `papers.json` has no file of its own: it is reported
|
|
10
|
+
* on the project's root `paperlint.json`, which `paperlint lint` lints only when a papers root holds
|
|
11
|
+
* `venues/` (src/cli.ts). Both are linted with ESLint's JSON language; no other file reaches the rule.
|
|
12
|
+
*/
|
|
13
|
+
import { basename, dirname, join, relative, sep } from "node:path";
|
|
14
|
+
import { callerPath } from "./caller-path.ts";
|
|
15
|
+
import type { JsonRuleContext, JsonRuleModule } from "./corpus-record-rule.ts";
|
|
16
|
+
import {
|
|
17
|
+
corpusStrayMessage,
|
|
18
|
+
judgeCorpusLayout,
|
|
19
|
+
judgeVenues,
|
|
20
|
+
looseMessage,
|
|
21
|
+
storesWithoutRecord,
|
|
22
|
+
unrecordedMessage,
|
|
23
|
+
} from "./domain/corpus-layout.ts";
|
|
24
|
+
import { CORPORA_DIR } from "./domain/corpus-record.ts";
|
|
25
|
+
import type { LayoutEntry } from "./domain/paper-layout.ts";
|
|
26
|
+
import { CORPUS_RECORD } from "./domain/venue-corpus.ts";
|
|
27
|
+
import type { FolderLayoutDeps } from "./folder-layout-rule.ts";
|
|
28
|
+
import { rulePageUrl } from "./venue-rules.ts";
|
|
29
|
+
|
|
30
|
+
/** What the rule reads with: the disk, and the papers roots whose `venues/` hold the corpora. */
|
|
31
|
+
export interface CorpusLayoutDeps extends FolderLayoutDeps {
|
|
32
|
+
readonly roots: readonly string[];
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** The entries of `dir`, sorted, each a file or a folder; none when it does not exist. */
|
|
36
|
+
const entriesOf = (
|
|
37
|
+
dir: string,
|
|
38
|
+
deps: FolderLayoutDeps,
|
|
39
|
+
): readonly LayoutEntry[] =>
|
|
40
|
+
[...deps.listDir(callerPath(dir))].sort().map((name) => ({
|
|
41
|
+
name,
|
|
42
|
+
kind: deps.files.isFile(callerPath(join(dir, name))) ? "file" : "dir",
|
|
43
|
+
}));
|
|
44
|
+
|
|
45
|
+
/** The text of each stray at the top of the corpus whose `papers.json` is `file`. */
|
|
46
|
+
const strayTexts = (
|
|
47
|
+
file: string,
|
|
48
|
+
deps: FolderLayoutDeps,
|
|
49
|
+
): readonly string[] => {
|
|
50
|
+
const dir = dirname(file);
|
|
51
|
+
const shown = `${CORPORA_DIR}/${basename(dir)}`;
|
|
52
|
+
return judgeCorpusLayout(entriesOf(dir, deps)).map((s) =>
|
|
53
|
+
corpusStrayMessage(shown, s),
|
|
54
|
+
);
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
/** The text of each corpus under `deps.roots` that stores copies with no record, shown from `home`. */
|
|
58
|
+
const unrecordedTexts = (
|
|
59
|
+
home: string,
|
|
60
|
+
deps: CorpusLayoutDeps,
|
|
61
|
+
): readonly string[] =>
|
|
62
|
+
deps.roots
|
|
63
|
+
.map((r) => join(r, CORPORA_DIR))
|
|
64
|
+
.flatMap((venues) =>
|
|
65
|
+
entriesOf(venues, deps)
|
|
66
|
+
.filter((e) => e.kind === "dir")
|
|
67
|
+
.map((e) => join(venues, e.name)),
|
|
68
|
+
)
|
|
69
|
+
.filter((corpus) => storesWithoutRecord(entriesOf(corpus, deps)))
|
|
70
|
+
.map((corpus) =>
|
|
71
|
+
unrecordedMessage(relative(home, corpus).split(sep).join("/")),
|
|
72
|
+
);
|
|
73
|
+
|
|
74
|
+
/** The text of each file loose in a `venues/` under `deps.roots`, shown from `home`. */
|
|
75
|
+
const looseTexts = (home: string, deps: CorpusLayoutDeps): readonly string[] =>
|
|
76
|
+
deps.roots
|
|
77
|
+
.map((r) => join(r, CORPORA_DIR))
|
|
78
|
+
.flatMap((venues) =>
|
|
79
|
+
judgeVenues(entriesOf(venues, deps)).map((name) =>
|
|
80
|
+
looseMessage(relative(home, venues).split(sep).join("/"), name),
|
|
81
|
+
),
|
|
82
|
+
);
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Each finding about the file being linted, by its message id. The config hands the rule two files
|
|
86
|
+
* only (src/cli.ts): a corpus's `papers.json`, and the root settings file.
|
|
87
|
+
*/
|
|
88
|
+
const findingsFor = (
|
|
89
|
+
file: string,
|
|
90
|
+
deps: CorpusLayoutDeps,
|
|
91
|
+
): readonly { readonly id: string; readonly text: string }[] =>
|
|
92
|
+
basename(file) === CORPUS_RECORD
|
|
93
|
+
? strayTexts(file, deps).map((text) => ({ id: "stray", text }))
|
|
94
|
+
: [
|
|
95
|
+
...unrecordedTexts(dirname(file), deps).map((text) => ({
|
|
96
|
+
id: "unrecorded",
|
|
97
|
+
text,
|
|
98
|
+
})),
|
|
99
|
+
...looseTexts(dirname(file), deps).map((text) => ({
|
|
100
|
+
id: "loose",
|
|
101
|
+
text,
|
|
102
|
+
})),
|
|
103
|
+
];
|
|
104
|
+
|
|
105
|
+
const META: JsonRuleModule["meta"] = {
|
|
106
|
+
type: "suggestion",
|
|
107
|
+
docs: {
|
|
108
|
+
description:
|
|
109
|
+
"the top of a venue corpus holds papers.json, MANIFEST.md, measurements.json, pdf/, text/, deep-reads/ and sources/, a corpus that stores copies has its papers.json, and venues/ holds only corpus folders and its index",
|
|
110
|
+
url: rulePageUrl("corpus/allowed-files-only"),
|
|
111
|
+
},
|
|
112
|
+
schema: [],
|
|
113
|
+
// The whole text is the domain's message (src/domain/corpus-layout.ts).
|
|
114
|
+
messages: { stray: "{{text}}", unrecorded: "{{text}}", loose: "{{text}}" },
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
/** The rule, reading the corpora through `deps`. */
|
|
118
|
+
export function corpusLayoutRules(
|
|
119
|
+
deps: CorpusLayoutDeps,
|
|
120
|
+
): Readonly<Record<"allowed-files-only", JsonRuleModule>> {
|
|
121
|
+
return {
|
|
122
|
+
"allowed-files-only": {
|
|
123
|
+
meta: META,
|
|
124
|
+
create(context: JsonRuleContext) {
|
|
125
|
+
return {
|
|
126
|
+
Document() {
|
|
127
|
+
const at = context.sourceCode.ast.loc.start;
|
|
128
|
+
findingsFor(context.filename, deps).forEach(({ id, text }) => {
|
|
129
|
+
context.report({
|
|
130
|
+
loc: { start: at, end: at },
|
|
131
|
+
messageId: id,
|
|
132
|
+
data: { text },
|
|
133
|
+
});
|
|
134
|
+
});
|
|
135
|
+
},
|
|
136
|
+
};
|
|
137
|
+
},
|
|
138
|
+
},
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/** On by default, on every corpus's `papers.json` and the root `paperlint.json`. */
|
|
143
|
+
export const CORPUS_LAYOUT_RULE_LEVELS: Readonly<
|
|
144
|
+
Record<"corpus/allowed-files-only", "error">
|
|
145
|
+
> = { "corpus/allowed-files-only": "error" };
|
|
@@ -115,7 +115,7 @@ describe("corpus/record: silent where nothing is wrong", () => {
|
|
|
115
115
|
});
|
|
116
116
|
|
|
117
117
|
it("🔴 is silent on a corpus folder with stored files and no papers.json", async () => {
|
|
118
|
-
// Guards: a corpus not migrated yet is corpus/allowed-files-only's to report
|
|
118
|
+
// Guards: a corpus not migrated yet is corpus/allowed-files-only's to report, not this rule's.
|
|
119
119
|
const r = await lint({
|
|
120
120
|
...PAPER,
|
|
121
121
|
[`${C}/MANIFEST.md`]: "# agent\n",
|
|
@@ -198,8 +198,8 @@ describe("corpus/record: each finding, at its place in papers.json", () => {
|
|
|
198
198
|
});
|
|
199
199
|
});
|
|
200
200
|
|
|
201
|
-
describe("the JSON language reaches papers.json and nothing else", () => {
|
|
202
|
-
it("🔴 lints no other JSON file:
|
|
201
|
+
describe("the JSON language reaches papers.json and the root paperlint.json, nothing else", () => {
|
|
202
|
+
it("🔴 lints no other JSON file: a paper's paperlint.json, measurements.json", async () => {
|
|
203
203
|
const r = await lint({
|
|
204
204
|
...PAPER,
|
|
205
205
|
"paperlint.json": "{}",
|
|
@@ -209,7 +209,18 @@ describe("the JSON language reaches papers.json and nothing else", () => {
|
|
|
209
209
|
[`${C}/measurements.json`]: "{ broken",
|
|
210
210
|
"papers/venues/papers.json": "{ broken",
|
|
211
211
|
});
|
|
212
|
-
|
|
212
|
+
// The root file is corpus/allowed-files-only's, for a corpus without papers.json; corpus/record
|
|
213
|
+
// is not registered on it.
|
|
214
|
+
expect(r.files.filter((f) => f.endsWith(".json"))).toEqual([
|
|
215
|
+
"paperlint.json",
|
|
216
|
+
RECORD,
|
|
217
|
+
]);
|
|
218
|
+
// Guards: no broken JSON is parsed; the one message is the stray papers.json loose in venues/.
|
|
219
|
+
expect(
|
|
220
|
+
r.messages
|
|
221
|
+
.filter((m) => m.file.endsWith(".json"))
|
|
222
|
+
.map((m) => [m.file, m.ruleId, m.messageId]),
|
|
223
|
+
).toEqual([["paperlint.json", "corpus/allowed-files-only", "loose"]]);
|
|
213
224
|
});
|
|
214
225
|
});
|
|
215
226
|
|
|
@@ -9,7 +9,8 @@
|
|
|
9
9
|
* language (`@eslint/json`): each finding at the field its path names, walked down the file's JSON
|
|
10
10
|
* tree; where the path stops being in the file (a required field left out), at the deepest part
|
|
11
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
|
|
12
|
+
* folder without `papers.json` has no file to report on, and this rule says nothing about it:
|
|
13
|
+
* `corpus/allowed-files-only` reports it on the root `paperlint.json` (src/corpus-layout-rule.ts).
|
|
13
14
|
*/
|
|
14
15
|
import { dirname, join } from "node:path";
|
|
15
16
|
import { callerPath } from "./caller-path.ts";
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The layout of a venue corpus (`src/domain/corpus-layout.ts`). Both halves: the seven names and
|
|
3
|
+
* the byproducts are clean; every other entry is reported once, with where it goes by kind.
|
|
4
|
+
*/
|
|
5
|
+
import { describe, expect, it } from "vitest";
|
|
6
|
+
import {
|
|
7
|
+
CORPUS_LAYOUT_TREE,
|
|
8
|
+
DIR_CURE,
|
|
9
|
+
FILE_CURE,
|
|
10
|
+
FILE_CURES,
|
|
11
|
+
corpusStrayMessage,
|
|
12
|
+
judgeCorpusLayout,
|
|
13
|
+
judgeVenues,
|
|
14
|
+
looseMessage,
|
|
15
|
+
storesWithoutRecord,
|
|
16
|
+
unrecordedMessage,
|
|
17
|
+
} from "./corpus-layout.ts";
|
|
18
|
+
import type { LayoutEntry } from "./paper-layout.ts";
|
|
19
|
+
|
|
20
|
+
const file = (name: string): LayoutEntry => ({ name, kind: "file" });
|
|
21
|
+
const dir = (name: string): LayoutEntry => ({ name, kind: "dir" });
|
|
22
|
+
const cure = (i: number): string => FILE_CURES[i]?.cure ?? "";
|
|
23
|
+
|
|
24
|
+
const SEVEN: readonly LayoutEntry[] = [
|
|
25
|
+
...["papers.json", "MANIFEST.md", "measurements.json"].map(file),
|
|
26
|
+
...["pdf", "text", "deep-reads", "sources"].map(dir),
|
|
27
|
+
];
|
|
28
|
+
|
|
29
|
+
describe("judgeCorpusLayout", () => {
|
|
30
|
+
it("🔴 reports nothing for the seven names and the byproducts", () => {
|
|
31
|
+
expect(
|
|
32
|
+
judgeCorpusLayout([...SEVEN, file(".DS_Store"), dir("__pycache__")]),
|
|
33
|
+
).toEqual([]);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it("🔴 a .gitignore that keeps the stored copies out of git is no stray", () => {
|
|
37
|
+
// Guards: a public repository keeps a corpus's pdf/ out of git with it (no false red).
|
|
38
|
+
expect(judgeCorpusLayout([...SEVEN, file(".gitignore")])).toEqual([]);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it("🔴 reports each stray once, by kind, in the order given", () => {
|
|
42
|
+
// One file per entry of FILE_CURES, in its order.
|
|
43
|
+
const names = [
|
|
44
|
+
"a.pdf",
|
|
45
|
+
"a.txt",
|
|
46
|
+
"notes.md",
|
|
47
|
+
"x.py",
|
|
48
|
+
"list.csv",
|
|
49
|
+
"cfp.html",
|
|
50
|
+
];
|
|
51
|
+
expect(
|
|
52
|
+
judgeCorpusLayout([...SEVEN, ...names.map(file), file("odd.bin")]),
|
|
53
|
+
).toEqual([
|
|
54
|
+
...names.map((name, i) => ({ name, cure: cure(i) })),
|
|
55
|
+
{ name: "odd.bin", cure: FILE_CURE },
|
|
56
|
+
]);
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
it("judges a name by its kind too: a folder named papers.json, a file named pdf", () => {
|
|
60
|
+
expect(judgeCorpusLayout([dir("papers.json"), file("pdf")])).toEqual([
|
|
61
|
+
{ name: "papers.json/", cure: DIR_CURE },
|
|
62
|
+
{ name: "pdf", cure: FILE_CURE },
|
|
63
|
+
]);
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
describe("storesWithoutRecord", () => {
|
|
68
|
+
it.each([
|
|
69
|
+
["pdf/ and no papers.json", [dir("pdf")], true],
|
|
70
|
+
["text/ and no papers.json", [dir("text"), file("MANIFEST.md")], true],
|
|
71
|
+
["pdf/ with papers.json", [dir("pdf"), file("papers.json")], false],
|
|
72
|
+
["no stored copies", [dir("sources")], false],
|
|
73
|
+
["a file named pdf", [file("pdf")], false],
|
|
74
|
+
] as const)("%s", (_, entries, want) => {
|
|
75
|
+
expect(storesWithoutRecord(entries)).toBe(want);
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
describe("the messages", () => {
|
|
80
|
+
it("a stray names itself, its cure, the layout and the rule's page", () => {
|
|
81
|
+
expect(
|
|
82
|
+
corpusStrayMessage("venues/agent", { name: "x/", cure: DIR_CURE }),
|
|
83
|
+
).toBe(
|
|
84
|
+
[
|
|
85
|
+
`\`venues/agent/x/\` is not one of the names a venue corpus holds. Where it goes: ${DIR_CURE}.`,
|
|
86
|
+
"What a corpus holds (.DS_Store and what interpreters leave, like __pycache__/, are never reported):",
|
|
87
|
+
CORPUS_LAYOUT_TREE,
|
|
88
|
+
"Rule corpus/allowed-files-only: https://github.com/zernie/paperlint/blob/main/docs/rules/corpus/allowed-files-only.md",
|
|
89
|
+
].join("\n"),
|
|
90
|
+
);
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
it("an unrecorded corpus names the folder and both cures", () => {
|
|
94
|
+
expect(unrecordedMessage("papers/venues/agent")).toBe(
|
|
95
|
+
"`papers/venues/agent/` stores copies in pdf/ or text/ and has no papers.json, so nothing records which paper each file is a copy of, or under which licence it is kept. What to do: write papers/venues/agent/papers.json (study-accepted-papers writes it; its fields are in papers.schema.json), or remove pdf/ and text/ and keep the papers' ids. Rule corpus/allowed-files-only: https://github.com/zernie/paperlint/blob/main/docs/rules/corpus/allowed-files-only.md",
|
|
96
|
+
);
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
describe("judgeVenues", () => {
|
|
101
|
+
it("🔴 reports each file loose in venues/, and no corpus folder, index or byproduct", () => {
|
|
102
|
+
const entries = [
|
|
103
|
+
dir("agent"),
|
|
104
|
+
dir("scripts"),
|
|
105
|
+
...["README.md", "CLAUDE.md", "AGENTS.md", ".DS_Store"].map(file),
|
|
106
|
+
file("codebook.md"),
|
|
107
|
+
file("check.py"),
|
|
108
|
+
];
|
|
109
|
+
// Guards: a folder is a corpus (its own names are judged inside it); only loose files are strays.
|
|
110
|
+
expect(judgeVenues(entries)).toEqual(["codebook.md", "check.py"]);
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
it("says where a loose file goes, and what venues/ holds", () => {
|
|
114
|
+
expect(looseMessage("papers/venues", "check.py")).toBe(
|
|
115
|
+
"`papers/venues/check.py` is a file loose in venues/, which holds one folder per venue corpus, and README.md, CLAUDE.md or AGENTS.md. Where it goes: into the corpus it is about (caveats into its MANIFEST.md, saved pages into its sources/), or out of venues/ when it serves several (a script into a paper's repro/tools/, its command into each papers.json's `rebuild`). Rule corpus/allowed-files-only: https://github.com/zernie/paperlint/blob/main/docs/rules/corpus/allowed-files-only.md",
|
|
116
|
+
);
|
|
117
|
+
});
|
|
118
|
+
});
|