paperlint 20.2.0 → 20.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/plugin.json +1 -1
- package/dist/adapters/venue-corpus/index.d.ts +17 -1
- package/dist/adapters/venue-corpus/index.d.ts.map +1 -1
- package/dist/adapters/venue-corpus/index.js +23 -7
- package/dist/adapters/venue-corpus/index.js.map +1 -1
- package/dist/cli.d.ts +4 -3
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +42 -13
- package/dist/cli.js.map +1 -1
- package/dist/corpus-record-rule.d.ts +65 -0
- package/dist/corpus-record-rule.d.ts.map +1 -0
- package/dist/corpus-record-rule.js +85 -0
- package/dist/corpus-record-rule.js.map +1 -0
- package/dist/domain/corpus-record.d.ts +51 -0
- package/dist/domain/corpus-record.d.ts.map +1 -0
- package/dist/domain/corpus-record.js +119 -0
- package/dist/domain/corpus-record.js.map +1 -0
- package/dist/domain/venue-corpus.d.ts +25 -3
- package/dist/domain/venue-corpus.d.ts.map +1 -1
- package/dist/domain/venue-corpus.js +4 -0
- package/dist/domain/venue-corpus.js.map +1 -1
- package/dist/paper-files.d.ts +10 -3
- package/dist/paper-files.d.ts.map +1 -1
- package/dist/paper-files.js +17 -2
- package/dist/paper-files.js.map +1 -1
- package/dist/papers-roots.d.ts +6 -0
- package/dist/papers-roots.d.ts.map +1 -1
- package/dist/papers-roots.js +14 -0
- package/dist/papers-roots.js.map +1 -1
- package/docs/design/venue-corpus.md +48 -27
- package/docs/layout.md +2 -2
- package/docs/rules/corpus/record.md +119 -0
- package/docs/rules.md +1 -0
- package/docs/venues.md +31 -20
- package/eslint.config.mjs +1 -0
- package/package.json +2 -1
- package/scripts/eslint-file-length.mjs +3 -3
- package/skills/study-accepted-papers/SKILL.md +14 -8
- package/skills/study-accepted-papers/SKILL.md.spec.ts +13 -7
- package/skills/study-accepted-papers/papers.schema.json +49 -2
- package/skills/study-accepted-papers/scripts/corpus-licences-core.js +2 -2
- package/skills/study-accepted-papers/scripts/corpus-licences-core.ts +2 -1
- package/skills/study-accepted-papers/scripts/corpus-licences.js +19 -9
- package/skills/study-accepted-papers/scripts/corpus-licences.test.ts +4 -1
- package/src/adapters/venue-corpus/index.test.ts +68 -10
- package/src/adapters/venue-corpus/index.ts +28 -8
- package/src/cli-e2e.test.mjs +2 -2
- package/src/cli.test.ts +1 -1
- package/src/cli.ts +57 -13
- package/src/corpus-record-rule.test.ts +228 -0
- package/src/corpus-record-rule.ts +175 -0
- package/src/domain/corpus-record.test.ts +163 -0
- package/src/domain/corpus-record.ts +210 -0
- package/src/domain/venue-corpus.ts +32 -3
- package/src/paper-files.test.ts +13 -4
- package/src/paper-files.ts +23 -2
- package/src/paper-settings-commands.test.ts +2 -2
- package/src/papers-roots.test.ts +34 -1
- package/src/papers-roots.ts +15 -0
- package/src/rule-cases.test.ts +15 -0
- package/src/settled-paper.test.ts +1 -1
- package/src/unowned-file.test.ts +1 -1
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `corpus/record` — every copy a venue corpus stores in `pdf/` and `text/` is accounted for by its
|
|
3
|
+
* `papers.json` (docs/design/venue-corpus.md, decision 4; docs/rules/corpus/record.md). What is
|
|
4
|
+
* judged is `src/domain/corpus-record.ts`; this file reads the record through the codec, lists the
|
|
5
|
+
* corpus, and reports.
|
|
6
|
+
*
|
|
7
|
+
* ── WHERE IT REPORTS ─────────────────────────────────────────────────────────────
|
|
8
|
+
* On `<papers-root>/venues/<venue>/papers.json`, which `buildConfig` lints with ESLint's JSON
|
|
9
|
+
* language (`@eslint/json`): each finding at the field its path names, walked down the file's JSON
|
|
10
|
+
* tree; where the path stops being in the file (a required field left out), at the deepest part
|
|
11
|
+
* that is. A file that is not JSON never reaches the rule: ESLint reports its parse error. A corpus
|
|
12
|
+
* folder without `papers.json` has no file to report on, and this rule says nothing about it.
|
|
13
|
+
*/
|
|
14
|
+
import { dirname, join } from "node:path";
|
|
15
|
+
import { callerPath } from "./caller-path.ts";
|
|
16
|
+
import {
|
|
17
|
+
corpusMessage,
|
|
18
|
+
judgeCorpus,
|
|
19
|
+
type CorpusFinding,
|
|
20
|
+
} from "./domain/corpus-record.ts";
|
|
21
|
+
import type { RecordPath } from "./domain/venue-corpus.ts";
|
|
22
|
+
import type { FolderRuleModule } from "./folder-venue-rule.ts";
|
|
23
|
+
import type { ListEntries } from "./ports/list-entries.ts";
|
|
24
|
+
import type { VenueCorpusCodec } from "./ports/venue-corpus-codec.ts";
|
|
25
|
+
import { rulePageUrl } from "./venue-rules.ts";
|
|
26
|
+
|
|
27
|
+
/** What the rule reads with. */
|
|
28
|
+
export interface CorpusRecordDeps {
|
|
29
|
+
readonly entries: ListEntries;
|
|
30
|
+
readonly codec: VenueCorpusCodec;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
interface Position {
|
|
34
|
+
readonly line: number;
|
|
35
|
+
readonly column: number;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** A span of the file, as ESLint's JSON language gives it. */
|
|
39
|
+
interface Span {
|
|
40
|
+
readonly start: Position;
|
|
41
|
+
readonly end: Position;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** A node of ESLint's JSON tree, as far as walking a path needs: an object's members, an array's elements. */
|
|
45
|
+
interface JsonNode {
|
|
46
|
+
readonly loc: Span;
|
|
47
|
+
readonly members?: readonly {
|
|
48
|
+
readonly loc: Span;
|
|
49
|
+
readonly name: { readonly value: string };
|
|
50
|
+
readonly value: JsonNode;
|
|
51
|
+
}[];
|
|
52
|
+
readonly elements?: readonly {
|
|
53
|
+
readonly loc: Span;
|
|
54
|
+
readonly value: JsonNode;
|
|
55
|
+
}[];
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** The tree of the whole file. */
|
|
59
|
+
interface JsonDocument {
|
|
60
|
+
readonly loc: Span;
|
|
61
|
+
readonly body: JsonNode;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** What the rule uses of ESLint's context on a JSON file. */
|
|
65
|
+
export interface JsonRuleContext {
|
|
66
|
+
readonly filename: string;
|
|
67
|
+
readonly sourceCode: { readonly text: string; readonly ast: JsonDocument };
|
|
68
|
+
report(d: {
|
|
69
|
+
readonly loc: Span;
|
|
70
|
+
readonly messageId: string;
|
|
71
|
+
readonly data: Readonly<Record<string, string>>;
|
|
72
|
+
}): void;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export interface JsonRuleModule {
|
|
76
|
+
readonly meta: FolderRuleModule["meta"];
|
|
77
|
+
create(context: JsonRuleContext): { Document?: () => void };
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** Where the walk is: the node reached and the span to report, or only the span once the path left the file. */
|
|
81
|
+
interface Walk {
|
|
82
|
+
readonly node: JsonNode | null;
|
|
83
|
+
readonly loc: Span;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* One step of a path: a key to the member of that name (the last of them, as `JSON.parse` keeps it),
|
|
88
|
+
* whose whole `"key": value` is reported; an index to that element.
|
|
89
|
+
*/
|
|
90
|
+
const step = (at: Walk, segment: string | number): Walk => {
|
|
91
|
+
const next =
|
|
92
|
+
typeof segment === "number"
|
|
93
|
+
? at.node?.elements?.[segment]
|
|
94
|
+
: at.node?.members?.findLast((m) => m.name.value === segment);
|
|
95
|
+
return next === undefined
|
|
96
|
+
? { node: null, loc: at.loc }
|
|
97
|
+
: { node: next.value, loc: next.loc };
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
/** The span of the field `path` names; the whole file for an empty path. */
|
|
101
|
+
export const spanAt = (doc: JsonDocument, path: RecordPath): Span =>
|
|
102
|
+
path.reduce<Walk>(step, { node: doc.body, loc: doc.loc }).loc;
|
|
103
|
+
|
|
104
|
+
/** The entries of `dir` a person put there: hidden ones (`.DS_Store`, `.gitkeep`) are not copies. */
|
|
105
|
+
const visible = (dir: string, deps: CorpusRecordDeps): readonly string[] =>
|
|
106
|
+
deps
|
|
107
|
+
.entries(callerPath(dir))
|
|
108
|
+
.filter((e) => !e.name.startsWith("."))
|
|
109
|
+
.map((e) => e.name)
|
|
110
|
+
.toSorted((a, b) => a.localeCompare(b));
|
|
111
|
+
|
|
112
|
+
/** The findings about the corpus whose `papers.json` is `file`, holding `text`. */
|
|
113
|
+
const findingsFor = (
|
|
114
|
+
file: string,
|
|
115
|
+
text: string,
|
|
116
|
+
deps: CorpusRecordDeps,
|
|
117
|
+
): readonly CorpusFinding[] =>
|
|
118
|
+
judgeCorpus({
|
|
119
|
+
record: deps.codec.parse(text),
|
|
120
|
+
stored: {
|
|
121
|
+
pdf: visible(join(dirname(file), "pdf"), deps),
|
|
122
|
+
text: visible(join(dirname(file), "text"), deps),
|
|
123
|
+
},
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
const META: FolderRuleModule["meta"] = {
|
|
127
|
+
type: "suggestion",
|
|
128
|
+
docs: {
|
|
129
|
+
description:
|
|
130
|
+
"a venue corpus's papers.json is a record, every copy stored in pdf/ and text/ is claimed by one copy in it, and every claimed file is there",
|
|
131
|
+
url: rulePageUrl("corpus/record"),
|
|
132
|
+
},
|
|
133
|
+
schema: [],
|
|
134
|
+
// One id per finding, each with the whole text of `corpusMessage`.
|
|
135
|
+
messages: Object.fromEntries(
|
|
136
|
+
(
|
|
137
|
+
[
|
|
138
|
+
"unparsed",
|
|
139
|
+
"unclaimed",
|
|
140
|
+
"missing",
|
|
141
|
+
"twice",
|
|
142
|
+
] satisfies readonly CorpusFinding["kind"][]
|
|
143
|
+
).map((id) => [id, "{{text}}"]),
|
|
144
|
+
),
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
/** The rule, reading the corpus through `deps`. */
|
|
148
|
+
export function corpusRecordRules(
|
|
149
|
+
deps: CorpusRecordDeps,
|
|
150
|
+
): Readonly<Record<"record", JsonRuleModule>> {
|
|
151
|
+
return {
|
|
152
|
+
record: {
|
|
153
|
+
meta: META,
|
|
154
|
+
create(context) {
|
|
155
|
+
return {
|
|
156
|
+
Document() {
|
|
157
|
+
const { text, ast } = context.sourceCode;
|
|
158
|
+
findingsFor(context.filename, text, deps).forEach((f) => {
|
|
159
|
+
context.report({
|
|
160
|
+
loc: spanAt(ast, f.at),
|
|
161
|
+
messageId: f.kind,
|
|
162
|
+
data: { text: corpusMessage(f) },
|
|
163
|
+
});
|
|
164
|
+
});
|
|
165
|
+
},
|
|
166
|
+
};
|
|
167
|
+
},
|
|
168
|
+
},
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/** On by default, on every corpus's `papers.json`. */
|
|
173
|
+
export const CORPUS_RECORD_RULE_LEVELS: Readonly<
|
|
174
|
+
Record<"corpus/record", "error">
|
|
175
|
+
> = { "corpus/record": "error" };
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
/** The corpus record's judge: each finding of `corpus/record`, and silence on a corpus that keeps its record. */
|
|
2
|
+
import { describe, expect, it } from "vitest";
|
|
3
|
+
import {
|
|
4
|
+
corpusMessage,
|
|
5
|
+
judgeCorpus,
|
|
6
|
+
storedKey,
|
|
7
|
+
type CorpusFinding,
|
|
8
|
+
type CorpusFolder,
|
|
9
|
+
} from "./corpus-record.ts";
|
|
10
|
+
import type { Copy, Paper, VenueCorpus } from "./venue-corpus.ts";
|
|
11
|
+
|
|
12
|
+
const copy = (stored: Copy["stored"]): Copy => ({
|
|
13
|
+
version: "published",
|
|
14
|
+
url: "https://doi.org/10.1/x",
|
|
15
|
+
licence: { id: "NOASSERTION" },
|
|
16
|
+
stored,
|
|
17
|
+
...(stored.length > 0 ? { fetched_from: "https://doi.org/10.1/x" } : {}),
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
const paper = (key: string, copies: readonly Copy[]): Paper => ({
|
|
21
|
+
key,
|
|
22
|
+
title: "A title",
|
|
23
|
+
group: "accepted",
|
|
24
|
+
edition: 2026,
|
|
25
|
+
ids: { doi: "10.1/x" },
|
|
26
|
+
copies,
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
const corpus = (papers: readonly Paper[]): VenueCorpus => ({
|
|
30
|
+
venue: "agent",
|
|
31
|
+
editions: [],
|
|
32
|
+
papers,
|
|
33
|
+
rebuild: [],
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
const folder = (
|
|
37
|
+
record: CorpusFolder["record"],
|
|
38
|
+
pdf: readonly string[] = [],
|
|
39
|
+
text: readonly string[] = [],
|
|
40
|
+
): CorpusFolder => ({ record, stored: { pdf, text } });
|
|
41
|
+
|
|
42
|
+
const read = (papers: readonly Paper[]): CorpusFolder["record"] => ({
|
|
43
|
+
ok: true,
|
|
44
|
+
corpus: corpus(papers),
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
describe("storedKey: the paper a stored file's name belongs to", () => {
|
|
48
|
+
it.each([
|
|
49
|
+
["pdf", "2026-01.pdf", "2026-01"],
|
|
50
|
+
["text", "2026-01.txt", "2026-01"],
|
|
51
|
+
["text", "2026-01.pdfminer.txt", "2026-01"],
|
|
52
|
+
["pdf", "2026-01.txt", null],
|
|
53
|
+
["pdf", "a.b.pdf", null],
|
|
54
|
+
["text", "2026-01.pdf", null],
|
|
55
|
+
["text", "2026-01..txt", null],
|
|
56
|
+
["text", ".txt", null],
|
|
57
|
+
] as const)("%s/%s → %s", (kind, name, key) => {
|
|
58
|
+
// Guards: a name outside `<key>.pdf` / `<key>[.<variant>].txt` belongs to no paper.
|
|
59
|
+
expect(storedKey(kind, name)).toBe(key);
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
describe("judgeCorpus", () => {
|
|
64
|
+
it("is silent when every stored file is claimed by exactly one copy and exists", () => {
|
|
65
|
+
expect(
|
|
66
|
+
judgeCorpus(
|
|
67
|
+
folder(
|
|
68
|
+
read([paper("a", [copy(["pdf", "text"]), copy([])])]),
|
|
69
|
+
["a.pdf"],
|
|
70
|
+
["a.txt", "a.pdfminer.txt"],
|
|
71
|
+
),
|
|
72
|
+
),
|
|
73
|
+
).toEqual([]);
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it("reports a record that does not parse: each of the codec's problems at its path", () => {
|
|
77
|
+
expect(
|
|
78
|
+
judgeCorpus(
|
|
79
|
+
folder({
|
|
80
|
+
ok: false,
|
|
81
|
+
problems: [
|
|
82
|
+
{ path: ["papers", 0, "key"], message: "x" },
|
|
83
|
+
{ path: [], message: "not JSON" },
|
|
84
|
+
],
|
|
85
|
+
}),
|
|
86
|
+
),
|
|
87
|
+
).toEqual([
|
|
88
|
+
{ kind: "unparsed", at: ["papers", 0, "key"], message: "x" },
|
|
89
|
+
{ kind: "unparsed", at: [], message: "not JSON" },
|
|
90
|
+
]);
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
describe("judgeCorpus: a record that does not account for the folder", () => {
|
|
95
|
+
it("reports a claimed PDF that is not there at the stored of the copy that claims it", () => {
|
|
96
|
+
expect(
|
|
97
|
+
judgeCorpus(folder(read([paper("a", [copy([]), copy(["pdf"])])]))),
|
|
98
|
+
).toEqual([
|
|
99
|
+
{
|
|
100
|
+
kind: "missing",
|
|
101
|
+
at: ["papers", 0, "copies", 1, "stored"],
|
|
102
|
+
key: "a",
|
|
103
|
+
stored: "pdf",
|
|
104
|
+
file: "pdf/a.pdf",
|
|
105
|
+
},
|
|
106
|
+
]);
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
it("reports an unclaimed file, a missing file and two copies storing one kind", () => {
|
|
110
|
+
expect(
|
|
111
|
+
judgeCorpus(
|
|
112
|
+
folder(
|
|
113
|
+
read([
|
|
114
|
+
paper("a", [copy(["pdf"]), copy(["pdf"])]),
|
|
115
|
+
paper("b", [copy(["text"])]),
|
|
116
|
+
]),
|
|
117
|
+
["a.pdf", "b.pdf", "c.pdf", "notes.docx"],
|
|
118
|
+
[],
|
|
119
|
+
),
|
|
120
|
+
),
|
|
121
|
+
).toEqual([
|
|
122
|
+
{
|
|
123
|
+
kind: "twice",
|
|
124
|
+
at: ["papers", 0, "copies", 1, "stored"],
|
|
125
|
+
key: "a",
|
|
126
|
+
stored: "pdf",
|
|
127
|
+
copies: [0, 1],
|
|
128
|
+
},
|
|
129
|
+
// A file of a listed paper is reported at that paper's copies; any other, on the record.
|
|
130
|
+
{
|
|
131
|
+
kind: "unclaimed",
|
|
132
|
+
at: ["papers", 1, "copies"],
|
|
133
|
+
file: "pdf/b.pdf",
|
|
134
|
+
key: "b",
|
|
135
|
+
},
|
|
136
|
+
{ kind: "unclaimed", at: [], file: "pdf/c.pdf", key: "c" },
|
|
137
|
+
{ kind: "unclaimed", at: [], file: "pdf/notes.docx", key: null },
|
|
138
|
+
{
|
|
139
|
+
kind: "missing",
|
|
140
|
+
at: ["papers", 1, "copies", 0, "stored"],
|
|
141
|
+
key: "b",
|
|
142
|
+
stored: "text",
|
|
143
|
+
file: "text/b.txt",
|
|
144
|
+
},
|
|
145
|
+
]);
|
|
146
|
+
});
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
describe("corpusMessage: every finding names its cure", () => {
|
|
150
|
+
const at = ["papers", 0, "copies", 0, "stored"];
|
|
151
|
+
const findings: readonly CorpusFinding[] = [
|
|
152
|
+
{ kind: "unparsed", at: ["papers", 0, "key"], message: "x" },
|
|
153
|
+
{ kind: "unparsed", at: [], message: "not JSON" },
|
|
154
|
+
{ kind: "unclaimed", at: [], file: "pdf/b.pdf", key: "b" },
|
|
155
|
+
{ kind: "unclaimed", at: [], file: "pdf/x.docx", key: null },
|
|
156
|
+
{ kind: "missing", at, key: "b", stored: "text", file: "text/b.txt" },
|
|
157
|
+
{ kind: "twice", at, key: "a", stored: "pdf", copies: [0, 1] },
|
|
158
|
+
];
|
|
159
|
+
it.each(findings)("$kind", (f) => {
|
|
160
|
+
// Guards: each message says what to do, after the finding itself.
|
|
161
|
+
expect(corpusMessage(f)).toMatch(/What to do: \S/u);
|
|
162
|
+
});
|
|
163
|
+
});
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `corpus/record`'s judgement of one venue corpus (docs/design/venue-corpus.md, decisions 4–6;
|
|
3
|
+
* docs/rules/corpus/record.md): whether every copy stored in `pdf/` and `text/` is accounted for by
|
|
4
|
+
* `papers.json`. Pure: the folder's listing and the record, already parsed by the codec, in; the
|
|
5
|
+
* findings out. What the record's fields mean is `venue-corpus.ts`; this file never re-checks them.
|
|
6
|
+
*
|
|
7
|
+
* A stored file's path follows from its paper's `key` (decision 5): `pdf/<key>.pdf`,
|
|
8
|
+
* `text/<key>.txt` and `text/<key>.<variant>.txt`. The folder is named after the kind it holds.
|
|
9
|
+
*/
|
|
10
|
+
import { STORED_KINDS, type StoredKind } from "./licence.ts";
|
|
11
|
+
import {
|
|
12
|
+
CORPUS_RECORD,
|
|
13
|
+
KEY_PATTERN,
|
|
14
|
+
pathText,
|
|
15
|
+
type Paper,
|
|
16
|
+
type ParsedCorpus,
|
|
17
|
+
type RecordPath,
|
|
18
|
+
type VenueCorpus,
|
|
19
|
+
} from "./venue-corpus.ts";
|
|
20
|
+
|
|
21
|
+
/** The folder in a papers root that holds one corpus per venue. */
|
|
22
|
+
export const CORPORA_DIR = "venues";
|
|
23
|
+
|
|
24
|
+
/** What the rule reads of one corpus folder. */
|
|
25
|
+
export interface CorpusFolder {
|
|
26
|
+
/** `papers.json`, as the codec parsed it. */
|
|
27
|
+
readonly record: ParsedCorpus;
|
|
28
|
+
/** The names in `pdf/` and in `text/`, hidden ones left out; none when the folder is absent. */
|
|
29
|
+
readonly stored: Readonly<Record<StoredKind, readonly string[]>>;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* One finding, with `at`, the path in `papers.json` it is reported at (empty: the whole file);
|
|
34
|
+
* `file` is relative to the corpus folder.
|
|
35
|
+
*/
|
|
36
|
+
export type CorpusFinding = { readonly at: RecordPath } & (
|
|
37
|
+
| { readonly kind: "unparsed"; readonly message: string }
|
|
38
|
+
| {
|
|
39
|
+
readonly kind: "unclaimed";
|
|
40
|
+
readonly file: string;
|
|
41
|
+
readonly key: string | null;
|
|
42
|
+
}
|
|
43
|
+
| {
|
|
44
|
+
readonly kind: "missing";
|
|
45
|
+
readonly key: string;
|
|
46
|
+
readonly stored: StoredKind;
|
|
47
|
+
readonly file: string;
|
|
48
|
+
}
|
|
49
|
+
| {
|
|
50
|
+
readonly kind: "twice";
|
|
51
|
+
readonly key: string;
|
|
52
|
+
readonly stored: StoredKind;
|
|
53
|
+
readonly copies: readonly number[];
|
|
54
|
+
}
|
|
55
|
+
);
|
|
56
|
+
|
|
57
|
+
const keyOrNull = (key: string): string | null =>
|
|
58
|
+
KEY_PATTERN.test(key) ? key : null;
|
|
59
|
+
|
|
60
|
+
/** The key a stored file's name belongs to, or null when the name is not one a copy can store. */
|
|
61
|
+
export function storedKey(kind: StoredKind, name: string): string | null {
|
|
62
|
+
switch (kind) {
|
|
63
|
+
case "pdf":
|
|
64
|
+
return name.endsWith(".pdf") ? keyOrNull(name.slice(0, -4)) : null;
|
|
65
|
+
case "text": {
|
|
66
|
+
if (!name.endsWith(".txt")) return null;
|
|
67
|
+
const [key = "", ...variant] = name.slice(0, -4).split(".");
|
|
68
|
+
return variant.length > 0 && variant.join(".") === ""
|
|
69
|
+
? null
|
|
70
|
+
: keyOrNull(key);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** The extension of a stored kind's file. */
|
|
76
|
+
const EXTENSION: Readonly<Record<StoredKind, string>> = {
|
|
77
|
+
pdf: "pdf",
|
|
78
|
+
text: "txt",
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
/** The name the record expects a paper's stored kind under, for a message. */
|
|
82
|
+
const expectedFile = (kind: StoredKind, key: string): string =>
|
|
83
|
+
`${kind}/${key}.${EXTENSION[kind]}`;
|
|
84
|
+
|
|
85
|
+
/** The indexes of `p`'s copies that store `kind`. */
|
|
86
|
+
const storing = (p: Paper, kind: StoredKind): readonly number[] =>
|
|
87
|
+
p.copies.flatMap((c, i) => (c.stored.includes(kind) ? [i] : []));
|
|
88
|
+
|
|
89
|
+
/** Which copies of one paper (the `paper`-th of the record) store one kind. */
|
|
90
|
+
interface Claim {
|
|
91
|
+
readonly kind: StoredKind;
|
|
92
|
+
readonly key: string;
|
|
93
|
+
readonly paper: number;
|
|
94
|
+
readonly copies: readonly number[];
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/** The `stored` of a paper's copy (`copy` holds its index), as a path. */
|
|
98
|
+
const storedAt = (paper: number, copy: readonly number[]): RecordPath => [
|
|
99
|
+
"papers",
|
|
100
|
+
paper,
|
|
101
|
+
"copies",
|
|
102
|
+
...copy,
|
|
103
|
+
"stored",
|
|
104
|
+
];
|
|
105
|
+
|
|
106
|
+
/** A paper's kind stored by more than one of its copies, reported at the second one. */
|
|
107
|
+
const twice = (claims: readonly Claim[]): readonly CorpusFinding[] =>
|
|
108
|
+
claims
|
|
109
|
+
.filter((c) => c.copies.length > 1)
|
|
110
|
+
.map((c) => ({
|
|
111
|
+
kind: "twice",
|
|
112
|
+
at: storedAt(c.paper, c.copies.slice(1, 2)),
|
|
113
|
+
key: c.key,
|
|
114
|
+
stored: c.kind,
|
|
115
|
+
copies: c.copies,
|
|
116
|
+
}));
|
|
117
|
+
|
|
118
|
+
/** A stored file no copy claims: at its paper's copies when the record lists the paper, else on the file. */
|
|
119
|
+
const unclaimed = (
|
|
120
|
+
claims: readonly Claim[],
|
|
121
|
+
stored: CorpusFolder["stored"],
|
|
122
|
+
): readonly CorpusFinding[] =>
|
|
123
|
+
STORED_KINDS.flatMap((kind) =>
|
|
124
|
+
stored[kind]
|
|
125
|
+
.map((name) => ({ name, key: storedKey(kind, name) }))
|
|
126
|
+
.filter(
|
|
127
|
+
(f) =>
|
|
128
|
+
!claims.some(
|
|
129
|
+
(c) => c.kind === kind && c.key === f.key && c.copies.length > 0,
|
|
130
|
+
),
|
|
131
|
+
)
|
|
132
|
+
.map((f) => ({
|
|
133
|
+
kind: "unclaimed",
|
|
134
|
+
at: atPaper(claims, f.key),
|
|
135
|
+
file: `${kind}/${f.name}`,
|
|
136
|
+
key: f.key,
|
|
137
|
+
})),
|
|
138
|
+
);
|
|
139
|
+
|
|
140
|
+
/** The copies of the paper `key` names, as a path; the whole file when no paper has that key. */
|
|
141
|
+
const atPaper = (claims: readonly Claim[], key: string | null): RecordPath => {
|
|
142
|
+
const claim = claims.find((c) => c.key === key);
|
|
143
|
+
return claim === undefined ? [] : ["papers", claim.paper, "copies"];
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
/** A claimed kind with no file of its paper's key. */
|
|
147
|
+
const missing = (
|
|
148
|
+
claims: readonly Claim[],
|
|
149
|
+
stored: CorpusFolder["stored"],
|
|
150
|
+
): readonly CorpusFinding[] =>
|
|
151
|
+
claims
|
|
152
|
+
.filter(
|
|
153
|
+
(c) =>
|
|
154
|
+
c.copies.length > 0 &&
|
|
155
|
+
!stored[c.kind].some((name) => storedKey(c.kind, name) === c.key),
|
|
156
|
+
)
|
|
157
|
+
.map((c) => ({
|
|
158
|
+
kind: "missing",
|
|
159
|
+
at: storedAt(c.paper, c.copies.slice(0, 1)),
|
|
160
|
+
key: c.key,
|
|
161
|
+
stored: c.kind,
|
|
162
|
+
file: expectedFile(c.kind, c.key),
|
|
163
|
+
}));
|
|
164
|
+
|
|
165
|
+
/** What a read record says about the folder. */
|
|
166
|
+
function judgeRecord(
|
|
167
|
+
corpus: VenueCorpus,
|
|
168
|
+
stored: CorpusFolder["stored"],
|
|
169
|
+
): readonly CorpusFinding[] {
|
|
170
|
+
const claims = STORED_KINDS.flatMap((kind) =>
|
|
171
|
+
corpus.papers.map((p, paper) => ({
|
|
172
|
+
kind,
|
|
173
|
+
key: p.key,
|
|
174
|
+
paper,
|
|
175
|
+
copies: storing(p, kind),
|
|
176
|
+
})),
|
|
177
|
+
);
|
|
178
|
+
return [
|
|
179
|
+
...twice(claims),
|
|
180
|
+
...unclaimed(claims, stored),
|
|
181
|
+
...missing(claims, stored),
|
|
182
|
+
];
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/** Every finding about one corpus folder; none for a corpus whose record accounts for each copy. */
|
|
186
|
+
export const judgeCorpus = (folder: CorpusFolder): readonly CorpusFinding[] =>
|
|
187
|
+
folder.record.ok
|
|
188
|
+
? judgeRecord(folder.record.corpus, folder.stored)
|
|
189
|
+
: folder.record.problems.map((p) => ({
|
|
190
|
+
kind: "unparsed",
|
|
191
|
+
at: p.path,
|
|
192
|
+
message: p.message,
|
|
193
|
+
}));
|
|
194
|
+
|
|
195
|
+
const KEEP_IDS =
|
|
196
|
+
"or remove the file and keep the paper's ids in `papers.json`, which is all a corpus needs to measure against it";
|
|
197
|
+
|
|
198
|
+
/** The text of a finding: what is wrong, then what to do. */
|
|
199
|
+
export function corpusMessage(f: CorpusFinding): string {
|
|
200
|
+
switch (f.kind) {
|
|
201
|
+
case "unparsed":
|
|
202
|
+
return `\`${pathText(f.at)}\`: ${f.message}. What to do: correct the field; the fields are in the JSON Schema \`papers.schema.json\` that \`study-accepted-papers\` ships`;
|
|
203
|
+
case "unclaimed":
|
|
204
|
+
return `\`${f.file}\` is stored, and no copy in \`${CORPUS_RECORD}\` claims it${f.key === null ? `: its name is not \`pdf/<key>.pdf\`, \`text/<key>.txt\` or \`text/<key>.<variant>.txt\`` : ` (no copy of the paper \`${f.key}\` lists it in \`stored\`)`}. What to do: record it under the copy it was fetched from, with \`fetched_from\`, its licence and where the licence was read; ${KEEP_IDS}`;
|
|
205
|
+
case "missing":
|
|
206
|
+
return `a copy of \`${f.key}\` stores \`${f.stored}\` in \`${CORPUS_RECORD}\`, and \`${f.file}\` is not there. What to do: put the file back, or remove \`"${f.stored}"\` from that copy's \`stored\``;
|
|
207
|
+
case "twice":
|
|
208
|
+
return `copies ${f.copies.join(" and ")} of \`${f.key}\` both store \`${f.stored}\`, and one stored file is a copy of one version. What to do: keep \`"${f.stored}"\` in the \`stored\` of the copy the file was fetched from, and remove it from the other`;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* A VENUE CORPUS'S RECORD — `<papers-root>/venues/<venue>/papers.json` (docs/design/venue-corpus.md,
|
|
3
3
|
* decision 1; docs/venues.md): the papers a venue accepted and, for each, every copy we know of with
|
|
4
|
-
* its licence
|
|
5
|
-
*
|
|
4
|
+
* its licence, and the facts of how the corpus was collected. Codes and measurements stay in
|
|
5
|
+
* `measurements.json`, keyed by a paper's `key`; only caveats stay prose, in an optional `MANIFEST.md`.
|
|
6
6
|
*
|
|
7
7
|
* The text of the file is checked once, where it enters: `VenueCorpusCodec`
|
|
8
8
|
* (`src/ports/venue-corpus-codec.ts`), whose adapter holds the zod schema of this shape. The domain
|
|
@@ -43,6 +43,16 @@ export interface Edition {
|
|
|
43
43
|
readonly read_on: string;
|
|
44
44
|
/** How many it accepted, when the page says. */
|
|
45
45
|
readonly accepted?: number | undefined;
|
|
46
|
+
/** What was left out of the edition and why; null when nothing was (never left out). */
|
|
47
|
+
readonly capped: string | null;
|
|
48
|
+
/** The stand-in for "strong accept" in this edition; null when it has none. */
|
|
49
|
+
readonly proxy: StrongAcceptProxy | null;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** What stands in for "strong accept" (an award, an oral slot), and how many papers it marks. */
|
|
53
|
+
export interface StrongAcceptProxy {
|
|
54
|
+
readonly what: string;
|
|
55
|
+
readonly papers: number;
|
|
46
56
|
}
|
|
47
57
|
|
|
48
58
|
/** A licence read from a source, or `NOASSERTION`: none was read. */
|
|
@@ -122,9 +132,28 @@ export interface VenueCorpus {
|
|
|
122
132
|
readonly venue: string;
|
|
123
133
|
readonly editions: readonly Edition[];
|
|
124
134
|
readonly papers: readonly Paper[];
|
|
135
|
+
/** The commands that regenerate the corpus, in order; empty when none was kept. */
|
|
136
|
+
readonly rebuild: readonly string[];
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/** Where in a `papers.json` a problem is: keys and indexes from the top; empty for the whole file. */
|
|
140
|
+
export type RecordPath = readonly (string | number)[];
|
|
141
|
+
|
|
142
|
+
/** One reason a `papers.json` is not a record. */
|
|
143
|
+
export interface CorpusProblem {
|
|
144
|
+
readonly path: RecordPath;
|
|
145
|
+
readonly message: string;
|
|
125
146
|
}
|
|
126
147
|
|
|
127
148
|
/** A `papers.json`'s text, parsed: the record, or every reason it is not one. */
|
|
128
149
|
export type ParsedCorpus =
|
|
129
150
|
| { readonly ok: true; readonly corpus: VenueCorpus }
|
|
130
|
-
| { readonly ok: false; readonly
|
|
151
|
+
| { readonly ok: false; readonly problems: readonly CorpusProblem[] };
|
|
152
|
+
|
|
153
|
+
/** A path as a message names it: `papers.0.copies`, or `(top)` for the whole file. */
|
|
154
|
+
export const pathText = (path: RecordPath): string =>
|
|
155
|
+
path.length === 0 ? "(top)" : path.join(".");
|
|
156
|
+
|
|
157
|
+
/** Every problem on one line, each with its path. */
|
|
158
|
+
export const problemsText = (problems: readonly CorpusProblem[]): string =>
|
|
159
|
+
`${CORPUS_RECORD}: ${problems.map((p) => `${pathText(p.path)}: ${p.message}`).join("; ")}`;
|
package/src/paper-files.test.ts
CHANGED
|
@@ -27,6 +27,7 @@ import {
|
|
|
27
27
|
ownedScopes,
|
|
28
28
|
paperFiles,
|
|
29
29
|
papersScope,
|
|
30
|
+
corpusFiles,
|
|
30
31
|
rebaseGlob,
|
|
31
32
|
ruleOwners,
|
|
32
33
|
scopeToOwned,
|
|
@@ -48,14 +49,15 @@ describe("the papers the config claims (#582)", () => {
|
|
|
48
49
|
buildConfig(
|
|
49
50
|
{},
|
|
50
51
|
texLanguage,
|
|
51
|
-
papersScope(["/w/papers/p", "/w/papers/q"], "/w"),
|
|
52
|
+
papersScope(["/w/papers/p", "/w/papers/q"], "/w", ["/w/papers"]),
|
|
52
53
|
),
|
|
53
54
|
).filter((g) => !FRAGMENT_FILES.includes(g));
|
|
55
|
+
// Beside the papers' own files, only each venue corpus's papers.json (corpus/record).
|
|
54
56
|
expect(
|
|
55
57
|
claimed.filter(
|
|
56
58
|
(g) => !g.startsWith("papers/p/") && !g.startsWith("papers/q/"),
|
|
57
59
|
),
|
|
58
|
-
).toEqual([]);
|
|
60
|
+
).toEqual(["papers/venues/*/papers.json"]);
|
|
59
61
|
expect(claimed).toContain("papers/q/paper.tex");
|
|
60
62
|
});
|
|
61
63
|
|
|
@@ -63,6 +65,7 @@ describe("the papers the config claims (#582)", () => {
|
|
|
63
65
|
const scope = papersScope(
|
|
64
66
|
["/w/papers/p", "/w/papers/[draft] x*", "/w"],
|
|
65
67
|
"/w",
|
|
68
|
+
["/w", "/w/[a]", "/x/papers", "/"],
|
|
66
69
|
);
|
|
67
70
|
expect(paperFiles(scope, "reviews/*.md")).toEqual([
|
|
68
71
|
"papers/p/reviews/*.md",
|
|
@@ -70,6 +73,12 @@ describe("the papers the config claims (#582)", () => {
|
|
|
70
73
|
"reviews/*.md",
|
|
71
74
|
]);
|
|
72
75
|
expect(paperFiles({ kind: "any" }, "paper.tex")).toEqual(["**/paper.tex"]);
|
|
76
|
+
// A papers root's corpora likewise; a root outside cwd has none ESLint could lint.
|
|
77
|
+
expect(corpusFiles(scope, "M.md")).toEqual([
|
|
78
|
+
"venues/*/M.md",
|
|
79
|
+
"\\[a\\]/venues/*/M.md",
|
|
80
|
+
]);
|
|
81
|
+
expect(corpusFiles({ kind: "any" }, "M.md")).toEqual(["**/venues/*/M.md"]);
|
|
73
82
|
});
|
|
74
83
|
});
|
|
75
84
|
|
|
@@ -101,9 +110,9 @@ describe("a paper's own settings read from its folder (#582)", () => {
|
|
|
101
110
|
const own = buildConfig(
|
|
102
111
|
{},
|
|
103
112
|
texLanguage,
|
|
104
|
-
papersScope(["/w/papers/a"], "/w"),
|
|
113
|
+
papersScope(["/w/papers/a"], "/w", []),
|
|
105
114
|
);
|
|
106
|
-
const scope = papersScope(["/w/papers/a"], "/w");
|
|
115
|
+
const scope = papersScope(["/w/papers/a"], "/w", []);
|
|
107
116
|
const block = (basePath: string) =>
|
|
108
117
|
narrowToOwners(
|
|
109
118
|
{ basePath, rules: { "paper/stages": "warn" } },
|