paperlint 20.6.2 → 20.8.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/revision-plan/index.d.ts +17 -0
- package/dist/adapters/revision-plan/index.d.ts.map +1 -0
- package/dist/adapters/revision-plan/index.js +168 -0
- package/dist/adapters/revision-plan/index.js.map +1 -0
- package/dist/domain/paper-layout.d.ts.map +1 -1
- package/dist/domain/paper-layout.js +4 -0
- package/dist/domain/paper-layout.js.map +1 -1
- package/dist/domain/preset-submission-fields.d.ts +15 -0
- package/dist/domain/preset-submission-fields.d.ts.map +1 -0
- package/dist/domain/preset-submission-fields.js +25 -0
- package/dist/domain/preset-submission-fields.js.map +1 -0
- package/dist/domain/revision-plan.d.ts +121 -0
- package/dist/domain/revision-plan.d.ts.map +1 -0
- package/dist/domain/revision-plan.js +15 -0
- package/dist/domain/revision-plan.js.map +1 -0
- package/dist/domain/venue-scope.d.ts +29 -0
- package/dist/domain/venue-scope.d.ts.map +1 -0
- package/dist/domain/venue-scope.js +18 -0
- package/dist/domain/venue-scope.js.map +1 -0
- package/dist/ports/revision-plan-codec.d.ts +7 -0
- package/dist/ports/revision-plan-codec.d.ts.map +1 -0
- package/dist/ports/revision-plan-codec.js +2 -0
- package/dist/ports/revision-plan-codec.js.map +1 -0
- package/dist/preset-merge.d.ts +34 -0
- package/dist/preset-merge.d.ts.map +1 -0
- package/dist/preset-merge.js +89 -0
- package/dist/preset-merge.js.map +1 -0
- package/dist/presets.d.ts +3 -2
- package/dist/presets.d.ts.map +1 -1
- package/dist/presets.js +3 -84
- package/dist/presets.js.map +1 -1
- package/dist/tex-requirements.d.ts +4 -1
- package/dist/tex-requirements.d.ts.map +1 -1
- package/dist/tex-requirements.js +3 -20
- package/dist/tex-requirements.js.map +1 -1
- package/docs/configuration.md +56 -0
- package/docs/layout.md +1 -0
- package/docs/rules/paper/allowed-files-only.md +1 -0
- package/docs/venues.md +6 -4
- package/package.json +2 -1
- package/presets/acl-latex.md +1 -1
- package/presets/langcode-2027.jsonc +106 -0
- package/presets/langcode-2027.md +79 -0
- package/presets/naacl-2027.jsonc +19 -0
- package/presets/naacl-2027.md +42 -0
- package/presets/venue-profile.schema.json +22 -1
- package/scripts/eslint-file-length.mjs +4 -4
- package/scripts/revision-plan-schema.test.ts +39 -0
- package/scripts/revision-plan-schema.ts +17 -0
- package/skills/paper-pipeline/revision-plan.schema.json +619 -0
- package/src/adapters/revision-plan/index.test.ts +207 -0
- package/src/adapters/revision-plan/index.ts +236 -0
- package/src/adapters/revision-plan/schema.test.ts +69 -0
- package/src/domain/paper-layout.test.ts +1 -0
- package/src/domain/paper-layout.ts +4 -0
- package/src/domain/preset-submission-fields.ts +49 -0
- package/src/domain/revision-plan.ts +127 -0
- package/src/domain/venue-scope.test.ts +33 -0
- package/src/domain/venue-scope.ts +39 -0
- package/src/paper-settings-commands.test.ts +1 -1
- package/src/ports/revision-plan-codec.ts +7 -0
- package/src/preset-card-rule.test.ts +2 -0
- package/src/preset-merge.ts +141 -0
- package/src/presets-scope.test.ts +177 -0
- package/src/presets.test.ts +17 -56
- package/src/presets.ts +5 -130
- package/src/tex-requirements.ts +14 -45
- package/src/tex-venue-rules.test.ts +3 -25
- package/src/venue-rules.test.ts +2 -2
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The parser of a paper's `revision-plan.json`: a valid plan becomes the value whole, and each planted
|
|
3
|
+
* defect is one problem at the path of its field.
|
|
4
|
+
*/
|
|
5
|
+
import { describe, expect, it } from "vitest";
|
|
6
|
+
import { PLAN, planText } from "../../../test/revision-plan-fixture.ts";
|
|
7
|
+
import { parseRevisionPlan, revisionPlanCodec } from "./index.ts";
|
|
8
|
+
|
|
9
|
+
/** The plan with `fields` set over its own; a field set to undefined is left out. */
|
|
10
|
+
const planWith = (fields: Readonly<Record<string, unknown>>): string =>
|
|
11
|
+
planText({ ...PLAN, ...fields });
|
|
12
|
+
|
|
13
|
+
/** The plan with row `i` replaced by `row`. */
|
|
14
|
+
const withRow = (i: number, row: Readonly<Record<string, unknown>>): string =>
|
|
15
|
+
planWith({ remaining: PLAN.remaining.map((r, k) => (k === i ? row : r)) });
|
|
16
|
+
|
|
17
|
+
const problems = (text: string) => {
|
|
18
|
+
const parsed = parseRevisionPlan(text);
|
|
19
|
+
return parsed.ok ? [] : parsed.problems;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
const [R1, R2, R3, R4] = PLAN.remaining;
|
|
23
|
+
const ENOUGH = { kind: "enough", since: "2026-12-01" };
|
|
24
|
+
|
|
25
|
+
/** Plans the shape accepts beside the fixture: each other bar, measurement, state and finding id. */
|
|
26
|
+
const VALID: readonly (readonly [string, string])[] = [
|
|
27
|
+
[
|
|
28
|
+
"a corpus bar",
|
|
29
|
+
planWith({
|
|
30
|
+
bar: { kind: "corpus", series: "usenix-sec", editions: [2024, 2025] },
|
|
31
|
+
}),
|
|
32
|
+
],
|
|
33
|
+
[
|
|
34
|
+
"a proxy bar",
|
|
35
|
+
planWith({
|
|
36
|
+
bar: { kind: "proxy", series: "agent", stands_in_for: "a first edition" },
|
|
37
|
+
}),
|
|
38
|
+
],
|
|
39
|
+
[
|
|
40
|
+
"enough measured",
|
|
41
|
+
planWith({
|
|
42
|
+
measurement: { ...ENOUGH, evidence: "research/2026-12-01-bar.md" },
|
|
43
|
+
}),
|
|
44
|
+
],
|
|
45
|
+
["a row being done", withRow(1, { ...R2, state: "doing" })],
|
|
46
|
+
[
|
|
47
|
+
"a finding named by its id",
|
|
48
|
+
withRow(1, {
|
|
49
|
+
...R2,
|
|
50
|
+
from: { kind: "finding", file: "reviews/a.md", finding: "M2" },
|
|
51
|
+
}),
|
|
52
|
+
],
|
|
53
|
+
];
|
|
54
|
+
|
|
55
|
+
/** One planted defect each, and the path it is reported at. */
|
|
56
|
+
const DEFECTS: readonly (readonly [string, string, readonly unknown[]])[] = [
|
|
57
|
+
[
|
|
58
|
+
"a misspelt key, at the key",
|
|
59
|
+
planWith({ writen: "2026-11-25" }),
|
|
60
|
+
["writen"],
|
|
61
|
+
],
|
|
62
|
+
[
|
|
63
|
+
"a corpus bar without its series",
|
|
64
|
+
planWith({ bar: { kind: "corpus", editions: [2025] } }),
|
|
65
|
+
["bar", "series"],
|
|
66
|
+
],
|
|
67
|
+
[
|
|
68
|
+
"a corpus bar with no edition",
|
|
69
|
+
planWith({ bar: { kind: "corpus", series: "agent", editions: [] } }),
|
|
70
|
+
// The first edition is the one missing: `editions` is a tuple with a rest element.
|
|
71
|
+
["bar", "editions", 0],
|
|
72
|
+
],
|
|
73
|
+
["no bar, without why", planWith({ bar: { kind: "none" } }), ["bar", "why"]],
|
|
74
|
+
[
|
|
75
|
+
"a bar of no kind the shape names",
|
|
76
|
+
planWith({ bar: { kind: "measured" } }),
|
|
77
|
+
["bar", "kind"],
|
|
78
|
+
],
|
|
79
|
+
[
|
|
80
|
+
"enough measured, without the file that decided it",
|
|
81
|
+
planWith({ measurement: ENOUGH }),
|
|
82
|
+
["measurement", "evidence"],
|
|
83
|
+
],
|
|
84
|
+
[
|
|
85
|
+
"evidence above the paper folder",
|
|
86
|
+
planWith({ measurement: { ...ENOUGH, evidence: "../other/notes.md" } }),
|
|
87
|
+
["measurement", "evidence"],
|
|
88
|
+
],
|
|
89
|
+
[
|
|
90
|
+
"an absolute evidence path",
|
|
91
|
+
planWith({ measurement: { ...ENOUGH, evidence: "/home/notes.md" } }),
|
|
92
|
+
["measurement", "evidence"],
|
|
93
|
+
],
|
|
94
|
+
[
|
|
95
|
+
"a drive-qualified evidence path",
|
|
96
|
+
planWith({ measurement: { ...ENOUGH, evidence: "C:/outside/notes.md" } }),
|
|
97
|
+
["measurement", "evidence"],
|
|
98
|
+
],
|
|
99
|
+
[
|
|
100
|
+
"a finding file with a drive letter",
|
|
101
|
+
withRow(1, {
|
|
102
|
+
...R2,
|
|
103
|
+
from: { kind: "finding", file: "C:/reviews/a.md", finding: 3 },
|
|
104
|
+
}),
|
|
105
|
+
["remaining", 1, "from", "file"],
|
|
106
|
+
],
|
|
107
|
+
[
|
|
108
|
+
"a finding file with a backslash",
|
|
109
|
+
withRow(1, {
|
|
110
|
+
...R2,
|
|
111
|
+
from: { kind: "finding", file: "reviews\\a.md", finding: 3 },
|
|
112
|
+
}),
|
|
113
|
+
["remaining", 1, "from", "file"],
|
|
114
|
+
],
|
|
115
|
+
[
|
|
116
|
+
"a done row without evidence",
|
|
117
|
+
withRow(2, { ...R3, evidence: undefined }),
|
|
118
|
+
["remaining", 2, "evidence"],
|
|
119
|
+
],
|
|
120
|
+
[
|
|
121
|
+
"a dropped row without its kind",
|
|
122
|
+
withRow(3, { ...R4, kind: undefined }),
|
|
123
|
+
["remaining", 3, "kind"],
|
|
124
|
+
],
|
|
125
|
+
[
|
|
126
|
+
"a row with no origin",
|
|
127
|
+
withRow(1, { ...R2, from: undefined }),
|
|
128
|
+
["remaining", 1, "from"],
|
|
129
|
+
],
|
|
130
|
+
[
|
|
131
|
+
"a row with no date it was added",
|
|
132
|
+
withRow(1, { ...R2, added: "soon" }),
|
|
133
|
+
["remaining", 1, "added"],
|
|
134
|
+
],
|
|
135
|
+
[
|
|
136
|
+
"a row of no state the shape names",
|
|
137
|
+
withRow(1, { ...R2, state: "blocked" }),
|
|
138
|
+
["remaining", 1, "state"],
|
|
139
|
+
],
|
|
140
|
+
[
|
|
141
|
+
"a by-rule row naming no rule id",
|
|
142
|
+
withRow(0, { ...R1, rule: "required-section" }),
|
|
143
|
+
["remaining", 0, "rule"],
|
|
144
|
+
],
|
|
145
|
+
[
|
|
146
|
+
"a row id that is not R and a number",
|
|
147
|
+
withRow(1, { ...R2, id: "row-2" }),
|
|
148
|
+
["remaining", 1, "id"],
|
|
149
|
+
],
|
|
150
|
+
[
|
|
151
|
+
"a cycle that is no cycle id",
|
|
152
|
+
planWith({ cycle: "LangCode 2027" }),
|
|
153
|
+
["cycle"],
|
|
154
|
+
],
|
|
155
|
+
[
|
|
156
|
+
"a whitespace-only reason",
|
|
157
|
+
withRow(3, { ...R4, reason: " " }),
|
|
158
|
+
["remaining", 3, "reason"],
|
|
159
|
+
],
|
|
160
|
+
];
|
|
161
|
+
|
|
162
|
+
describe("parseRevisionPlan: a valid plan", () => {
|
|
163
|
+
it("🔴 parses into the whole value, every field kept", () => {
|
|
164
|
+
expect(revisionPlanCodec.parse(planText())).toEqual({
|
|
165
|
+
ok: true,
|
|
166
|
+
plan: PLAN,
|
|
167
|
+
});
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
it.each(VALID)("%s parses", (_name, text) => {
|
|
171
|
+
expect(problems(text)).toEqual([]);
|
|
172
|
+
});
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
describe("parseRevisionPlan: each defect at its field", () => {
|
|
176
|
+
it.each(DEFECTS)("%s", (_name, text, path) => {
|
|
177
|
+
expect(problems(text).map((p) => p.path)).toEqual([path]);
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
it("🔴 two rows with one id: the second, naming the first", () => {
|
|
181
|
+
expect(problems(withRow(1, { ...R2, id: "R1" }))).toEqual([
|
|
182
|
+
{
|
|
183
|
+
path: ["remaining", 1, "id"],
|
|
184
|
+
message: '"R1" is the id of row 1 too: each row has its own',
|
|
185
|
+
},
|
|
186
|
+
]);
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
it("a tag of no kind names the kinds it takes", () => {
|
|
190
|
+
expect(problems(planWith({ bar: { kind: "measured" } }))).toEqual([
|
|
191
|
+
{
|
|
192
|
+
path: ["bar", "kind"],
|
|
193
|
+
message: '"kind" is one of "corpus", "proxy", "none"',
|
|
194
|
+
},
|
|
195
|
+
]);
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
it("a field left out is missing, at its own path", () => {
|
|
199
|
+
expect(problems(planWith({ bar: { kind: "none" } }))).toEqual([
|
|
200
|
+
{ path: ["bar", "why"], message: "missing: the shape requires it here" },
|
|
201
|
+
]);
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
it("text that is not JSON: one problem at the top", () => {
|
|
205
|
+
expect(problems("{ cycle: ")).toEqual([{ path: [], message: "not JSON" }]);
|
|
206
|
+
});
|
|
207
|
+
});
|
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The schema of a paper's `revision-plan.json` — the one place its shape is checked
|
|
3
|
+
* (src/domain/revision-plan.ts). The text is parsed once, here, into the domain's `RevisionPlan`;
|
|
4
|
+
* whatever reads a plan after it never re-validates. The venue corpus's pattern
|
|
5
|
+
* (`src/adapters/venue-corpus/`): every object strict, each problem at the path of its field, and the
|
|
6
|
+
* JSON Schema generated from this parser rather than written beside it.
|
|
7
|
+
*/
|
|
8
|
+
import { z } from "zod";
|
|
9
|
+
import { CYCLE_ID_PATTERN, cycleId } from "../../domain/cycle.ts";
|
|
10
|
+
import { SERIES_ID } from "../../domain/edition.ts";
|
|
11
|
+
import { isInside } from "../../domain/study-registry.ts";
|
|
12
|
+
import {
|
|
13
|
+
DROP_KINDS,
|
|
14
|
+
ROW_ID_PATTERN,
|
|
15
|
+
ROW_STATES,
|
|
16
|
+
RULE_ID_PATTERN,
|
|
17
|
+
type ParsedPlan,
|
|
18
|
+
type PlanProblem,
|
|
19
|
+
type RevisionPlan,
|
|
20
|
+
} from "../../domain/revision-plan.ts";
|
|
21
|
+
import type { RevisionPlanCodec } from "../../ports/revision-plan-codec.ts";
|
|
22
|
+
|
|
23
|
+
const words = z.string().trim().min(1, "a non-empty text");
|
|
24
|
+
const date = z.iso.date();
|
|
25
|
+
|
|
26
|
+
// The pattern first, so the JSON Schema carries it; then the id, minted by the cycle's own function.
|
|
27
|
+
const cycle = z
|
|
28
|
+
.string()
|
|
29
|
+
.regex(
|
|
30
|
+
new RegExp(`^${CYCLE_ID_PATTERN}$`, "u"),
|
|
31
|
+
"a cycle id: lowercase words and digits joined by hyphens, as in `langcode-2027`",
|
|
32
|
+
)
|
|
33
|
+
.transform(cycleId);
|
|
34
|
+
|
|
35
|
+
const series = z
|
|
36
|
+
.string()
|
|
37
|
+
.regex(
|
|
38
|
+
SERIES_ID,
|
|
39
|
+
"a venue corpus's series: its folder under venues/, as in `usenix-sec`",
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
/** A file of the paper, relative to its folder: never absolute (`/…`, `C:…`) and never above it. */
|
|
43
|
+
const paperFile = z
|
|
44
|
+
.string()
|
|
45
|
+
.min(1, "a path relative to the paper folder")
|
|
46
|
+
.refine(
|
|
47
|
+
isInside,
|
|
48
|
+
"a path inside the paper folder: relative, with `/` between its parts, never above it",
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
/** A discriminated union whose unknown or missing tag names the tags it takes. */
|
|
52
|
+
const oneOf = <
|
|
53
|
+
const K extends string,
|
|
54
|
+
const O extends readonly [
|
|
55
|
+
z.core.$ZodTypeDiscriminable,
|
|
56
|
+
...z.core.$ZodTypeDiscriminable[],
|
|
57
|
+
],
|
|
58
|
+
>(
|
|
59
|
+
key: K,
|
|
60
|
+
tags: readonly string[],
|
|
61
|
+
options: O,
|
|
62
|
+
) =>
|
|
63
|
+
z.discriminatedUnion(key, options, {
|
|
64
|
+
error: `"${key}" is one of ${tags.map((t) => `"${t}"`).join(", ")}`,
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
/** A year a venue corpus covers. */
|
|
68
|
+
const edition = z.int().min(1900).max(2999);
|
|
69
|
+
|
|
70
|
+
const bar = oneOf(
|
|
71
|
+
"kind",
|
|
72
|
+
["corpus", "proxy", "none"],
|
|
73
|
+
[
|
|
74
|
+
z.strictObject({
|
|
75
|
+
kind: z.literal("corpus"),
|
|
76
|
+
series,
|
|
77
|
+
// A tuple with a rest element, not `.array().nonempty()`: zod 4 infers the latter as
|
|
78
|
+
// `number[]`, which the domain's `[number, ...number[]]` refuses.
|
|
79
|
+
editions: z.tuple([edition], edition, {
|
|
80
|
+
error: "at least one edition the corpus covers",
|
|
81
|
+
}),
|
|
82
|
+
}),
|
|
83
|
+
z.strictObject({
|
|
84
|
+
kind: z.literal("proxy"),
|
|
85
|
+
series,
|
|
86
|
+
stands_in_for: words,
|
|
87
|
+
}),
|
|
88
|
+
z.strictObject({ kind: z.literal("none"), why: words }),
|
|
89
|
+
],
|
|
90
|
+
);
|
|
91
|
+
|
|
92
|
+
const measurement = oneOf(
|
|
93
|
+
"kind",
|
|
94
|
+
["open", "enough"],
|
|
95
|
+
[
|
|
96
|
+
z.strictObject({ kind: z.literal("open") }),
|
|
97
|
+
z.strictObject({
|
|
98
|
+
kind: z.literal("enough"),
|
|
99
|
+
since: date,
|
|
100
|
+
evidence: paperFile,
|
|
101
|
+
}),
|
|
102
|
+
],
|
|
103
|
+
);
|
|
104
|
+
|
|
105
|
+
const source = oneOf(
|
|
106
|
+
"kind",
|
|
107
|
+
["author", "venue", "finding", "prior-reviews"],
|
|
108
|
+
[
|
|
109
|
+
z.strictObject({ kind: z.literal("author") }),
|
|
110
|
+
z.strictObject({ kind: z.literal("venue") }),
|
|
111
|
+
z.strictObject({
|
|
112
|
+
kind: z.literal("finding"),
|
|
113
|
+
file: paperFile,
|
|
114
|
+
finding: z.union([words, z.int().min(1)]),
|
|
115
|
+
}),
|
|
116
|
+
z.strictObject({ kind: z.literal("prior-reviews"), cycle }),
|
|
117
|
+
],
|
|
118
|
+
);
|
|
119
|
+
|
|
120
|
+
const base = {
|
|
121
|
+
id: z.string().regex(ROW_ID_PATTERN, "a row id: R and a number, as in `R3`"),
|
|
122
|
+
what: words,
|
|
123
|
+
from: source,
|
|
124
|
+
added: date,
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
const row = oneOf("state", ROW_STATES, [
|
|
128
|
+
z.strictObject({ ...base, state: z.enum(["todo", "doing"]) }),
|
|
129
|
+
z.strictObject({ ...base, state: z.literal("done"), evidence: words }),
|
|
130
|
+
z.strictObject({
|
|
131
|
+
...base,
|
|
132
|
+
state: z.literal("dropped"),
|
|
133
|
+
reason: words,
|
|
134
|
+
kind: z.enum(DROP_KINDS),
|
|
135
|
+
}),
|
|
136
|
+
z.strictObject({
|
|
137
|
+
...base,
|
|
138
|
+
state: z.literal("by-rule"),
|
|
139
|
+
rule: z
|
|
140
|
+
.string()
|
|
141
|
+
.regex(
|
|
142
|
+
RULE_ID_PATTERN,
|
|
143
|
+
"a rule id as `paperlint lint` reports it, as in `tex/required-section`",
|
|
144
|
+
),
|
|
145
|
+
}),
|
|
146
|
+
]);
|
|
147
|
+
|
|
148
|
+
/** The index of each id that occurs earlier in `ids`, with the index of its first. */
|
|
149
|
+
const repeats = (
|
|
150
|
+
ids: readonly string[],
|
|
151
|
+
): readonly (readonly [number, number])[] =>
|
|
152
|
+
ids.flatMap((v, i) => {
|
|
153
|
+
const first = ids.indexOf(v);
|
|
154
|
+
return first === i ? [] : [[i, first] as const];
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
const plan = z
|
|
158
|
+
.strictObject({
|
|
159
|
+
cycle,
|
|
160
|
+
written: date,
|
|
161
|
+
bar,
|
|
162
|
+
measurement,
|
|
163
|
+
remaining: z.array(row),
|
|
164
|
+
})
|
|
165
|
+
.superRefine((p, ctx) => {
|
|
166
|
+
repeats(p.remaining.map((r) => r.id)).forEach(([i, first]) => {
|
|
167
|
+
ctx.addIssue({
|
|
168
|
+
code: "custom",
|
|
169
|
+
path: ["remaining", i, "id"],
|
|
170
|
+
message: `"${String(p.remaining[i]?.id)}" is the id of row ${String(first + 1)} too: each row has its own`,
|
|
171
|
+
});
|
|
172
|
+
});
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
/** The JSON `text` holds, or undefined when it is not JSON. */
|
|
176
|
+
function jsonOf(text: string): unknown {
|
|
177
|
+
try {
|
|
178
|
+
return JSON.parse(text);
|
|
179
|
+
} catch {
|
|
180
|
+
return undefined;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* One zod issue as a problem. A misspelt key's path ends at the key (the first, when there are
|
|
186
|
+
* several), so a reader of the file lands on it rather than on the object holding it.
|
|
187
|
+
*/
|
|
188
|
+
const problemOf = (i: z.core.$ZodIssue): PlanProblem => ({
|
|
189
|
+
path: [
|
|
190
|
+
...i.path.filter((s) => typeof s !== "symbol"),
|
|
191
|
+
...(i.code === "unrecognized_keys" ? i.keys.slice(0, 1) : []),
|
|
192
|
+
],
|
|
193
|
+
message: i.message,
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
/** A `revision-plan.json`'s text, parsed once at the boundary: the plan, or every reason it is not one. */
|
|
197
|
+
export function parseRevisionPlan(text: string): ParsedPlan {
|
|
198
|
+
const json = jsonOf(text);
|
|
199
|
+
if (json === undefined)
|
|
200
|
+
return { ok: false, problems: [{ path: [], message: "not JSON" }] };
|
|
201
|
+
// A field left out is "missing", not zod's "expected string, received undefined".
|
|
202
|
+
const parsed = plan.safeParse(json, {
|
|
203
|
+
error: (i) =>
|
|
204
|
+
i.code === "invalid_type" && i.input === undefined
|
|
205
|
+
? "missing: the shape requires it here"
|
|
206
|
+
: undefined,
|
|
207
|
+
});
|
|
208
|
+
if (!parsed.success)
|
|
209
|
+
return { ok: false, problems: parsed.error.issues.map(problemOf) };
|
|
210
|
+
const value: RevisionPlan = parsed.data;
|
|
211
|
+
return { ok: true, plan: value };
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
export const revisionPlanCodec: RevisionPlanCodec = {
|
|
215
|
+
parse: parseRevisionPlan,
|
|
216
|
+
};
|
|
217
|
+
|
|
218
|
+
/** Where the shipped JSON Schema of the plan sits, below the package root: in the skill that writes it. */
|
|
219
|
+
export const SCHEMA_FILE = "skills/paper-pipeline/revision-plan.schema.json";
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* The JSON Schema of a `revision-plan.json`, generated from the parser's own shape: what an editor
|
|
223
|
+
* completes and a skill reads instead of a hand-written table. Shipped as `SCHEMA_FILE`; a test holds
|
|
224
|
+
* the file to this. A schema cannot say that each row's id is unique or that a path stays inside the paper
|
|
225
|
+
* folder: `revision-plan/record` does.
|
|
226
|
+
*/
|
|
227
|
+
export const revisionPlanJsonSchema = (): unknown => ({
|
|
228
|
+
...z.toJSONSchema(plan, { io: "input", unrepresentable: "any" }),
|
|
229
|
+
title: "A paper's revision-plan.json",
|
|
230
|
+
description:
|
|
231
|
+
"The paper's revision plan for its current cycle: the accepted papers it is held against (bar), whether evidence is still being gathered (measurement), and the closed list of what remains (remaining). This schema lists the fields; it cannot express that each row's id is unique or that a path stays inside the paper folder, which the lint rule revision-plan/record checks with the rest.",
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
/** The shipped file's text: the schema, indented, with a closing newline. */
|
|
235
|
+
export const revisionPlanSchemaText = (): string =>
|
|
236
|
+
`${JSON.stringify(revisionPlanJsonSchema(), null, 2)}\n`;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The JSON Schema `paper-pipeline` ships for `revision-plan.json`: generated from the parser, so the
|
|
3
|
+
* fields an editor or a skill reads are the ones the plan is judged by.
|
|
4
|
+
*/
|
|
5
|
+
import Ajv from "ajv";
|
|
6
|
+
import { omit } from "remeda";
|
|
7
|
+
import { readFileSync } from "node:fs";
|
|
8
|
+
import { dirname, join } from "node:path";
|
|
9
|
+
import { fileURLToPath } from "node:url";
|
|
10
|
+
import { describe, expect, it } from "vitest";
|
|
11
|
+
import { z } from "zod";
|
|
12
|
+
import { PLAN } from "../../../test/revision-plan-fixture.ts";
|
|
13
|
+
import {
|
|
14
|
+
revisionPlanJsonSchema,
|
|
15
|
+
revisionPlanSchemaText,
|
|
16
|
+
SCHEMA_FILE,
|
|
17
|
+
} from "./index.ts";
|
|
18
|
+
|
|
19
|
+
describe("revisionPlanJsonSchema — the shipped schema file", () => {
|
|
20
|
+
const SHIPPED = join(
|
|
21
|
+
dirname(fileURLToPath(import.meta.url)),
|
|
22
|
+
"../../../",
|
|
23
|
+
SCHEMA_FILE,
|
|
24
|
+
);
|
|
25
|
+
|
|
26
|
+
it("🔴 is the generated schema, byte for byte", () => {
|
|
27
|
+
// Guards: the schema the skill points at never drifts from the parser that judges the plan.
|
|
28
|
+
expect(
|
|
29
|
+
readFileSync(SHIPPED, "utf8"),
|
|
30
|
+
`${SCHEMA_FILE} is stale: regenerate it with \`npm run schema:revision-plan\``,
|
|
31
|
+
).toBe(revisionPlanSchemaText());
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it("🔴 says the rule checks what a schema cannot, and names the plan's fields", () => {
|
|
35
|
+
const schema = z
|
|
36
|
+
.looseObject({
|
|
37
|
+
description: z.string(),
|
|
38
|
+
properties: z.looseObject({}),
|
|
39
|
+
})
|
|
40
|
+
.parse(revisionPlanJsonSchema());
|
|
41
|
+
expect(schema.description).toContain("revision-plan/record");
|
|
42
|
+
expect(Object.keys(schema.properties)).toEqual([
|
|
43
|
+
"cycle",
|
|
44
|
+
"written",
|
|
45
|
+
"bar",
|
|
46
|
+
"measurement",
|
|
47
|
+
"remaining",
|
|
48
|
+
]);
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* ajv 6 reads draft-07, so the 2020-12 `$schema` is left out, as an editor's draft-07 validator would
|
|
54
|
+
* read the file; every keyword the generated schema uses means the same in both.
|
|
55
|
+
*/
|
|
56
|
+
const schemaAccepts = (plan: unknown): boolean => {
|
|
57
|
+
const schema = omit(
|
|
58
|
+
z.looseObject({ $schema: z.string() }).parse(revisionPlanJsonSchema()),
|
|
59
|
+
["$schema"],
|
|
60
|
+
);
|
|
61
|
+
return new Ajv({ allErrors: true }).validate(schema, plan) === true;
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
describe("revisionPlanJsonSchema — validates the valid plan", () => {
|
|
65
|
+
it("accepts the fixture plan", () => {
|
|
66
|
+
// Guards: the schema an editor reads never refuses a plan the parser takes.
|
|
67
|
+
expect(schemaAccepts(PLAN)).toBe(true);
|
|
68
|
+
});
|
|
69
|
+
});
|
|
@@ -90,6 +90,10 @@ export const ROOT_FILE_NOTES: readonly Noted[] = [
|
|
|
90
90
|
name: "SUBMIT-CHECKLIST.md",
|
|
91
91
|
note: "the venue's format and submission mechanics",
|
|
92
92
|
},
|
|
93
|
+
{
|
|
94
|
+
name: "revision-plan.json",
|
|
95
|
+
note: "the current cycle's bar and the closed list of what remains",
|
|
96
|
+
},
|
|
93
97
|
{ name: ".gitignore", note: "keeps the build's byproducts out of git" },
|
|
94
98
|
{ name: "paper.pdf", note: "the built PDF" },
|
|
95
99
|
];
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A preset's `submission_fields` block, after the schema accepted it, as the typed preset holds it
|
|
3
|
+
* (`src/tex-requirements.ts` parses the rest of the file).
|
|
4
|
+
*/
|
|
5
|
+
import {
|
|
6
|
+
declareField,
|
|
7
|
+
RESERVED_FIELD_KEYS,
|
|
8
|
+
reservedKey,
|
|
9
|
+
type FieldDeclaration,
|
|
10
|
+
type FieldJson,
|
|
11
|
+
type VenueFields,
|
|
12
|
+
} from "./submission-fields.ts";
|
|
13
|
+
|
|
14
|
+
/** A preset's `submission_fields` after the schema accepted it. */
|
|
15
|
+
export interface SubmissionFieldsJson {
|
|
16
|
+
readonly source: VenueFields["source"];
|
|
17
|
+
readonly url: string;
|
|
18
|
+
readonly read: string;
|
|
19
|
+
readonly fields: Readonly<Record<string, FieldJson>>;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** A preset's `submission_fields`, or null when it records none; a reserved field name, or a field that contradicts its kind, is refused. */
|
|
23
|
+
export function submissionFieldsOf(
|
|
24
|
+
j: SubmissionFieldsJson | undefined,
|
|
25
|
+
file: string,
|
|
26
|
+
): VenueFields | null {
|
|
27
|
+
if (j === undefined) return null;
|
|
28
|
+
const reserved = reservedKey(Object.keys(j.fields));
|
|
29
|
+
if (reserved !== null)
|
|
30
|
+
throw new Error(
|
|
31
|
+
`${file}: "submission_fields" names "${reserved}", which paperlint sends itself (${RESERVED_FIELD_KEYS.join(", ")}) — a field of that name would overwrite it`,
|
|
32
|
+
);
|
|
33
|
+
const declared = Object.entries(j.fields).map(
|
|
34
|
+
([key, f]) => [key, declareField(f)] as const,
|
|
35
|
+
);
|
|
36
|
+
const fields: readonly (readonly [string, FieldDeclaration])[] =
|
|
37
|
+
declared.flatMap(([key, d]) => (d.ok ? [[key, d.value] as const] : []));
|
|
38
|
+
const errors = declared.flatMap(([key, d]) =>
|
|
39
|
+
d.ok ? [] : [`field "${key}": ${d.error}`],
|
|
40
|
+
);
|
|
41
|
+
if (errors.length > 0)
|
|
42
|
+
throw new Error(`${file}: "submission_fields" ${errors.join("; ")}`);
|
|
43
|
+
return {
|
|
44
|
+
source: j.source,
|
|
45
|
+
url: j.url,
|
|
46
|
+
read: j.read,
|
|
47
|
+
fields: Object.fromEntries(fields),
|
|
48
|
+
};
|
|
49
|
+
}
|