paperlint 20.4.0 → 20.6.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/adapters/venue-corpus/index.d.ts.map +1 -1
- package/dist/adapters/venue-corpus/index.js +9 -2
- package/dist/adapters/venue-corpus/index.js.map +1 -1
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +61 -26
- package/dist/cli.js.map +1 -1
- package/dist/corpus-json-rules.d.ts +6 -0
- package/dist/corpus-json-rules.d.ts.map +1 -0
- package/dist/corpus-json-rules.js +15 -0
- package/dist/corpus-json-rules.js.map +1 -0
- 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-licence-rule.d.ts +27 -0
- package/dist/corpus-licence-rule.d.ts.map +1 -0
- package/dist/corpus-licence-rule.js +78 -0
- package/dist/corpus-licence-rule.js.map +1 -0
- package/dist/corpus-record-rule.d.ts +2 -0
- package/dist/corpus-record-rule.d.ts.map +1 -1
- package/dist/corpus-record-rule.js +6 -3
- 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/corpus-licence.d.ts +23 -0
- package/dist/domain/corpus-licence.d.ts.map +1 -0
- package/dist/domain/corpus-licence.js +50 -0
- package/dist/domain/corpus-licence.js.map +1 -0
- package/dist/domain/corpus-record.d.ts +8 -0
- package/dist/domain/corpus-record.d.ts.map +1 -1
- package/dist/domain/corpus-record.js +11 -9
- package/dist/domain/corpus-record.js.map +1 -1
- package/dist/domain/edition.d.ts +3 -1
- package/dist/domain/edition.d.ts.map +1 -1
- package/dist/domain/edition.js +6 -2
- package/dist/domain/edition.js.map +1 -1
- package/dist/domain/licence.d.ts +1 -1
- package/dist/domain/licence.d.ts.map +1 -1
- package/dist/domain/licence.js +2 -2
- package/dist/domain/licence.js.map +1 -1
- 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/dist/skill-chunks/chunk-QPWFSYJG.js +17 -0
- package/dist/skill-chunks/{chunk-6YEM4VDI.js → chunk-WYQTXKNM.js} +1 -1
- package/docs/design/venue-corpus.md +16 -16
- package/docs/layout.md +2 -2
- package/docs/optional-rules.md +11 -10
- package/docs/rules/corpus/allowed-files-only.md +99 -0
- package/docs/rules/corpus/licence.md +125 -0
- package/docs/rules/corpus/record.md +10 -6
- package/docs/rules.md +3 -1
- package/docs/venues.md +14 -11
- package/package.json +1 -1
- package/skills/argument-arc/scripts/headings.js +2 -2
- package/skills/cold-read-diff/scripts/cold-read.js +5 -5
- package/skills/paper-pipeline/scripts/extract-ref-facts.js +3 -3
- package/skills/pc-panel-review/scripts/prior-reviews.js +2 -1
- package/skills/study-accepted-papers/SKILL.md +4 -3
- package/skills/study-accepted-papers/SKILL.md.spec.ts +3 -2
- package/skills/study-accepted-papers/papers.schema.json +2 -2
- package/skills/study-accepted-papers/scripts/corpus-licences.js +15 -3
- package/skills/study-accepted-papers/scripts/corpus-licences.test.ts +1 -1
- package/skills/verify-citations/scripts/bib-authors.js +3 -3
- package/skills/verify-citations/scripts/verify-cites.js +3 -3
- package/src/adapters/venue-corpus/index.test.ts +25 -0
- package/src/adapters/venue-corpus/index.ts +16 -2
- package/src/cli-e2e.test.mjs +2 -2
- package/src/cli.ts +75 -26
- package/src/corpus-json-rules.ts +22 -0
- package/src/corpus-layout-rule.test.ts +177 -0
- package/src/corpus-layout-rule.ts +145 -0
- package/src/corpus-licence-rule.test.ts +217 -0
- package/src/corpus-licence-rule.ts +94 -0
- package/src/corpus-record-rule.test.ts +27 -4
- package/src/corpus-record-rule.ts +8 -3
- package/src/domain/corpus-layout.test.ts +118 -0
- package/src/domain/corpus-layout.ts +159 -0
- package/src/domain/corpus-licence.test.ts +128 -0
- package/src/domain/corpus-licence.ts +99 -0
- package/src/domain/corpus-record.test.ts +7 -1
- package/src/domain/corpus-record.ts +26 -9
- package/src/domain/edition.ts +8 -2
- package/src/domain/licence.test.ts +1 -1
- package/src/domain/licence.ts +2 -2
- 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 +6 -70
- package/src/rule-id-shape.test.ts +42 -0
- package/src/unowned-file.test.ts +1 -1
- package/dist/skill-chunks/{chunk-CXAGKT44.js → chunk-EDHTB7KT.js} +4 -4
|
@@ -264,6 +264,31 @@ const REFUSED: readonly (readonly [string, string, string])[] = [
|
|
|
264
264
|
}),
|
|
265
265
|
"editions.0.accepted: Invalid input: expected number, received undefined; editions.0.capped: Invalid input: expected string, received undefined; editions.0.proxy.papers: Too small: expected number to be >=0",
|
|
266
266
|
],
|
|
267
|
+
[
|
|
268
|
+
"🔴 a venue that is one edition, not its series",
|
|
269
|
+
text({ ...RECORD, venue: "agent-2026" }),
|
|
270
|
+
"venue: a venue is a series, not one edition: drop the year (`agent`, not `agent-2026`)",
|
|
271
|
+
],
|
|
272
|
+
[
|
|
273
|
+
"🔴 a venue that is a display name, and a sister's too",
|
|
274
|
+
text({
|
|
275
|
+
...RECORD,
|
|
276
|
+
venue: "ICSE",
|
|
277
|
+
papers: [
|
|
278
|
+
PAPER,
|
|
279
|
+
{
|
|
280
|
+
...PAPER,
|
|
281
|
+
key: "s",
|
|
282
|
+
edition: undefined,
|
|
283
|
+
group: "sister",
|
|
284
|
+
venue: "NLBSE",
|
|
285
|
+
year: 2025,
|
|
286
|
+
listed_from: "https://nlbse.github.io/2025/",
|
|
287
|
+
},
|
|
288
|
+
],
|
|
289
|
+
}),
|
|
290
|
+
"venue: a venue is a series id: lowercase words and digits joined by hyphens, as in `usenix-sec`; papers.1.venue: a venue is a series id: lowercase words and digits joined by hyphens, as in `usenix-sec`",
|
|
291
|
+
],
|
|
267
292
|
[
|
|
268
293
|
"🔴 a record without its rebuild commands",
|
|
269
294
|
text({ ...RECORD, rebuild: undefined }),
|
|
@@ -30,9 +30,23 @@ import {
|
|
|
30
30
|
type StrongAcceptProxy,
|
|
31
31
|
type VenueCorpus,
|
|
32
32
|
} from "../../domain/venue-corpus.ts";
|
|
33
|
+
import { endsInYear, SERIES_ID } from "../../domain/edition.ts";
|
|
33
34
|
import type { VenueCorpusCodec } from "../../ports/venue-corpus-codec.ts";
|
|
34
35
|
|
|
35
36
|
const words = z.string().min(1);
|
|
37
|
+
|
|
38
|
+
// A venue is a series (`agent`, `usenix-sec`), the part of a preset's id before its year, so a
|
|
39
|
+
// corpus is found from any edition of it; an edition's id or a display name here would match none.
|
|
40
|
+
const series = z
|
|
41
|
+
.string()
|
|
42
|
+
.regex(
|
|
43
|
+
SERIES_ID,
|
|
44
|
+
"a venue is a series id: lowercase words and digits joined by hyphens, as in `usenix-sec`",
|
|
45
|
+
)
|
|
46
|
+
.refine(
|
|
47
|
+
(v) => !endsInYear(v),
|
|
48
|
+
"a venue is a series, not one edition: drop the year (`agent`, not `agent-2026`)",
|
|
49
|
+
);
|
|
36
50
|
const date = z.iso.date();
|
|
37
51
|
/** Where a page or a file was read: a web address, never a local path or another scheme. */
|
|
38
52
|
const webUrl = z.url({
|
|
@@ -158,7 +172,7 @@ const paper = z.discriminatedUnion("group", [
|
|
|
158
172
|
z.looseObject({
|
|
159
173
|
...paperFields,
|
|
160
174
|
group: z.literal("sister"),
|
|
161
|
-
venue:
|
|
175
|
+
venue: series,
|
|
162
176
|
year,
|
|
163
177
|
listed_from: webUrl,
|
|
164
178
|
}),
|
|
@@ -211,7 +225,7 @@ const consistent = (
|
|
|
211
225
|
|
|
212
226
|
const record = z
|
|
213
227
|
.strictObject({
|
|
214
|
-
venue:
|
|
228
|
+
venue: series,
|
|
215
229
|
editions: z.array(edition),
|
|
216
230
|
papers: z.array(paper),
|
|
217
231
|
rebuild: z.array(words),
|
package/src/cli-e2e.test.mjs
CHANGED
|
@@ -180,11 +180,11 @@ it("config is assembled, and consumer data gets through", async () => {
|
|
|
180
180
|
const ruleBlocks = (c) => c.filter((b) => Array.isArray(b.files));
|
|
181
181
|
check(
|
|
182
182
|
"without a LaTeX language the config still gets built — a corpus with no .tex is not a reason to refuse",
|
|
183
|
-
Array.isArray(cfg) && ruleBlocks(cfg).length ===
|
|
183
|
+
Array.isArray(cfg) && ruleBlocks(cfg).length === 5,
|
|
184
184
|
);
|
|
185
185
|
check(
|
|
186
186
|
"with a LaTeX language two blocks are added: paper.tex, and the files it includes",
|
|
187
|
-
ruleBlocks(buildConfig({}, {})).length ===
|
|
187
|
+
ruleBlocks(buildConfig({}, {})).length === 7,
|
|
188
188
|
);
|
|
189
189
|
check(
|
|
190
190
|
"🔴 the project's paper TEMPLATE directory is ignored — flat config does not skip dot-directories",
|
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";
|
|
@@ -242,10 +243,13 @@ import {
|
|
|
242
243
|
} from "./folder-layout-rule.ts";
|
|
243
244
|
import { folderLayoutHook } from "./folder-layout-hook.ts";
|
|
244
245
|
import { inCorpus, papersDirOf, papersRoots, toPaths } from "./papers-roots.ts";
|
|
246
|
+
import { CORPUS_RECORD_RULE_LEVELS } from "./corpus-record-rule.ts";
|
|
247
|
+
import { corpusJsonRules, corpusRecords } from "./corpus-json-rules.ts";
|
|
245
248
|
import {
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
} from "./corpus-
|
|
249
|
+
CORPUS_LAYOUT_RULE_LEVELS,
|
|
250
|
+
corpusLayoutRules,
|
|
251
|
+
} from "./corpus-layout-rule.ts";
|
|
252
|
+
import { CORPORA_DIR } from "./domain/corpus-record.ts";
|
|
249
253
|
import { CORPUS_RECORD } from "./domain/venue-corpus.ts";
|
|
250
254
|
import { venueCorpusCodec } from "./adapters/venue-corpus/index.ts";
|
|
251
255
|
import { paperFolderOf, writtenPath } from "./domain/paper-folder.ts";
|
|
@@ -659,22 +663,36 @@ const TALK_RULE_DEPS = {
|
|
|
659
663
|
/**
|
|
660
664
|
* A venue corpus, `<papers-root>/venues/<venue>/`, reached through its `papers.json`, linted with
|
|
661
665
|
* ESLint's JSON language so `corpus/record` reports at the field (docs/design/venue-corpus.md,
|
|
662
|
-
* decision 4)
|
|
666
|
+
* decision 4); and the root `paperlint.json`, where `corpus/allowed-files-only` reports a corpus that
|
|
667
|
+
* has no `papers.json`. The JSON language reaches no other file: these blocks alone name it. Each
|
|
668
|
+
* registers only the rules it turns on, so a consumer's `corpus/record` never reaches the root file.
|
|
663
669
|
*/
|
|
664
|
-
const
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
670
|
+
const corpusBlocks = (papers: PaperScope): readonly ConfigBlock[] => {
|
|
671
|
+
const layout = corpusLayoutRules({
|
|
672
|
+
files: nodeFiles,
|
|
673
|
+
listDir: nodeListDir,
|
|
674
|
+
roots: papers.kind === "papers" ? papers.roots : [],
|
|
675
|
+
});
|
|
676
|
+
// `corpus/licence` is registered with them and on for no corpus: `"warn"` in the root paperlint.json turns it on.
|
|
677
|
+
const record = corpusJsonRules({
|
|
678
|
+
entries: nodeListEntries,
|
|
679
|
+
codec: venueCorpusCodec,
|
|
680
|
+
});
|
|
681
|
+
return [
|
|
682
|
+
{
|
|
683
|
+
files: corpusFiles(papers, CORPUS_RECORD),
|
|
684
|
+
plugins: { json, corpus: { rules: { ...record, ...layout } } },
|
|
685
|
+
language: "json/json",
|
|
686
|
+
rules: { ...CORPUS_RECORD_RULE_LEVELS, ...CORPUS_LAYOUT_RULE_LEVELS },
|
|
673
687
|
},
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
688
|
+
{
|
|
689
|
+
files: rootSettingsFile(papers),
|
|
690
|
+
plugins: { json, corpus: { rules: layout } },
|
|
691
|
+
language: "json/json",
|
|
692
|
+
rules: CORPUS_LAYOUT_RULE_LEVELS,
|
|
693
|
+
},
|
|
694
|
+
];
|
|
695
|
+
};
|
|
678
696
|
|
|
679
697
|
/** The config the user would otherwise write by hand. The data comes from `opts`, the mechanism is here. */
|
|
680
698
|
export function buildConfig(
|
|
@@ -761,7 +779,7 @@ export function buildConfig(
|
|
|
761
779
|
...STATUS_CYCLE_RULE_LEVELS,
|
|
762
780
|
},
|
|
763
781
|
},
|
|
764
|
-
|
|
782
|
+
...corpusBlocks(papers),
|
|
765
783
|
{
|
|
766
784
|
files: own("reviews/*.md"),
|
|
767
785
|
plugins: { markdown, review: reviewFrontmatter },
|
|
@@ -1026,7 +1044,8 @@ export async function silentOptionalRules(
|
|
|
1026
1044
|
const probes = [
|
|
1027
1045
|
...new Set(files.filter((p) => basename(p) === MAIN)),
|
|
1028
1046
|
].flatMap((f) => [f, join(dirname(f), STATUS_FILE), ...bodyFiles(f)]);
|
|
1029
|
-
|
|
1047
|
+
// A corpus rule is reached through the record it judges, not through a paper.
|
|
1048
|
+
for (const probe of [...probes, ...corpusRecords(files)]) {
|
|
1030
1049
|
// Undefined for a file outside ESLint's cwd or scope: it reaches nothing.
|
|
1031
1050
|
const cfg = ComputedConfig.parse(
|
|
1032
1051
|
await eslint.calculateConfigForFile(probe),
|
|
@@ -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;
|
|
@@ -2726,11 +2746,13 @@ export async function run(
|
|
|
2726
2746
|
err,
|
|
2727
2747
|
where: relative(cwd, root) || ".",
|
|
2728
2748
|
opts: withPapers,
|
|
2729
|
-
// Every paper of the project, not only the ones on the command line (#103).
|
|
2730
|
-
projectPapers: papersRoots(cfg)
|
|
2731
|
-
.
|
|
2732
|
-
.map((d) =>
|
|
2733
|
-
|
|
2749
|
+
// Every paper and corpus record of the project, not only the ones on the command line (#103).
|
|
2750
|
+
projectPapers: papersRoots(cfg).flatMap((r) => [
|
|
2751
|
+
...papersIn(r, [MAIN]).map((d) => join(d, MAIN)),
|
|
2752
|
+
...papersIn(join(r, CORPORA_DIR), [CORPUS_RECORD]).map((d) =>
|
|
2753
|
+
join(d, CORPUS_RECORD),
|
|
2754
|
+
),
|
|
2755
|
+
]),
|
|
2734
2756
|
bodies,
|
|
2735
2757
|
onLintResults,
|
|
2736
2758
|
});
|
|
@@ -2746,6 +2768,32 @@ export async function run(
|
|
|
2746
2768
|
return code;
|
|
2747
2769
|
}
|
|
2748
2770
|
|
|
2771
|
+
/**
|
|
2772
|
+
* The project root whose `paperlint.json` is linted, or null: only where a papers root holds
|
|
2773
|
+
* `venues/`, since that file is where `corpus/allowed-files-only` reports a corpus without
|
|
2774
|
+
* `papers.json`. A project with no corpus lints exactly the files it linted before.
|
|
2775
|
+
*/
|
|
2776
|
+
const corpusHome = (cfg: {
|
|
2777
|
+
readonly opts: PaperlintConfig;
|
|
2778
|
+
readonly root: string;
|
|
2779
|
+
}): string | null =>
|
|
2780
|
+
papersRoots(cfg).some((r) => existsSync(join(r, CORPORA_DIR)))
|
|
2781
|
+
? cfg.root
|
|
2782
|
+
: null;
|
|
2783
|
+
|
|
2784
|
+
/** What `paperlint lint` hands ESLint: `paths`, and the root `paperlint.json` on a run of the whole project. */
|
|
2785
|
+
const withRootSettings = (
|
|
2786
|
+
cfg: { readonly opts: PaperlintConfig; readonly root: string },
|
|
2787
|
+
wholeProject: boolean,
|
|
2788
|
+
paths: readonly string[],
|
|
2789
|
+
): readonly string[] => {
|
|
2790
|
+
const home = corpusHome(cfg);
|
|
2791
|
+
const file = home === null ? null : join(home, CONFIG_FILE);
|
|
2792
|
+
return wholeProject && file !== null && existsSync(file)
|
|
2793
|
+
? [...paths, file]
|
|
2794
|
+
: paths;
|
|
2795
|
+
};
|
|
2796
|
+
|
|
2749
2797
|
/**
|
|
2750
2798
|
* The ESLint `paperlint lint` runs over `paths`, with the config it lints them by — ONE setup for
|
|
2751
2799
|
* `paperlint lint` and the `lint-edited` hook, so what the hook reports while a paper is written is
|
|
@@ -2809,6 +2857,7 @@ async function paperEslint(
|
|
|
2809
2857
|
paperDirs([...paths, ...roots], roots),
|
|
2810
2858
|
cwd,
|
|
2811
2859
|
roots,
|
|
2860
|
+
corpusHome(cfg),
|
|
2812
2861
|
);
|
|
2813
2862
|
const eslint = new ESLint({
|
|
2814
2863
|
cwd,
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/** The rules that judge a venue corpus's `papers.json` (`corpus/record`, `corpus/licence`), as one plugin's rules. */
|
|
2
|
+
import { corpusLicenceRules } from "./corpus-licence-rule.ts";
|
|
3
|
+
import { basename } from "node:path";
|
|
4
|
+
import { CORPUS_RECORD } from "./domain/venue-corpus.ts";
|
|
5
|
+
import {
|
|
6
|
+
corpusRecordRules,
|
|
7
|
+
type CorpusRecordDeps,
|
|
8
|
+
type JsonRuleModule,
|
|
9
|
+
} from "./corpus-record-rule.ts";
|
|
10
|
+
|
|
11
|
+
/** Both rules, reading the corpus through `deps`; which of them is on is the config's, not theirs. */
|
|
12
|
+
export const corpusJsonRules = (
|
|
13
|
+
deps: CorpusRecordDeps,
|
|
14
|
+
): Readonly<Record<"record" | "licence", JsonRuleModule>> => ({
|
|
15
|
+
...corpusRecordRules(deps),
|
|
16
|
+
...corpusLicenceRules(deps),
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
/** The venue corpora's `papers.json` among `files`, each once: the files a corpus rule is reached through. */
|
|
20
|
+
export const corpusRecords = (files: readonly string[]): readonly string[] => [
|
|
21
|
+
...new Set(files.filter((f) => basename(f) === CORPUS_RECORD)),
|
|
22
|
+
];
|
|
@@ -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" };
|