paperlint 18.4.0 → 18.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.md +5 -1
- package/dist/adapters/latex/abstract.d.ts +11 -0
- package/dist/adapters/latex/abstract.d.ts.map +1 -1
- package/dist/adapters/latex/abstract.js +1 -1
- package/dist/adapters/latex/abstract.js.map +1 -1
- package/dist/adapters/latex/index.d.ts.map +1 -1
- package/dist/adapters/latex/index.js +3 -0
- package/dist/adapters/latex/index.js.map +1 -1
- package/dist/adapters/latex/macros.d.ts +6 -0
- package/dist/adapters/latex/macros.d.ts.map +1 -0
- package/dist/adapters/latex/macros.js +27 -0
- package/dist/adapters/latex/macros.js.map +1 -0
- package/dist/adapters/osf/host.io.d.ts +12 -0
- package/dist/adapters/osf/host.io.d.ts.map +1 -0
- package/dist/adapters/osf/host.io.js +119 -0
- package/dist/adapters/osf/host.io.js.map +1 -0
- package/dist/adapters/osf/index.d.ts +10 -0
- package/dist/adapters/osf/index.d.ts.map +1 -0
- package/dist/adapters/osf/index.js +10 -0
- package/dist/adapters/osf/index.js.map +1 -0
- package/dist/adapters/osf/response.d.ts +11 -0
- package/dist/adapters/osf/response.d.ts.map +1 -0
- package/dist/adapters/osf/response.js +87 -0
- package/dist/adapters/osf/response.js.map +1 -0
- package/dist/artifact-upload-rule.d.ts +66 -0
- package/dist/artifact-upload-rule.d.ts.map +1 -0
- package/dist/artifact-upload-rule.js +151 -0
- package/dist/artifact-upload-rule.js.map +1 -0
- package/dist/artifact.d.ts +35 -0
- package/dist/artifact.d.ts.map +1 -0
- package/dist/artifact.js +251 -0
- package/dist/artifact.js.map +1 -0
- package/dist/cli.d.ts +9 -1
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +136 -23
- package/dist/cli.js.map +1 -1
- package/dist/domain/artifact-upload.d.ts +44 -0
- package/dist/domain/artifact-upload.d.ts.map +1 -0
- package/dist/domain/artifact-upload.js +80 -0
- package/dist/domain/artifact-upload.js.map +1 -0
- package/dist/domain/paper-dirs.d.ts +16 -0
- package/dist/domain/paper-dirs.d.ts.map +1 -0
- package/dist/domain/paper-dirs.js +42 -0
- package/dist/domain/paper-dirs.js.map +1 -0
- package/dist/eslint-rules/CLAUDE.md.spec.d.ts.map +1 -1
- package/dist/eslint-rules/CLAUDE.md.spec.js +1 -0
- package/dist/eslint-rules/CLAUDE.md.spec.js.map +1 -1
- package/dist/paper-files.d.ts +25 -42
- package/dist/paper-files.d.ts.map +1 -1
- package/dist/paper-files.js +101 -9
- package/dist/paper-files.js.map +1 -1
- package/dist/ports/artifact-host.d.ts +54 -0
- package/dist/ports/artifact-host.d.ts.map +1 -0
- package/dist/ports/artifact-host.js +2 -0
- package/dist/ports/artifact-host.js.map +1 -0
- package/dist/ports/latex.d.ts +9 -0
- package/dist/ports/latex.d.ts.map +1 -1
- package/dist/submission-confirm-hook.d.ts +11 -1
- package/dist/submission-confirm-hook.d.ts.map +1 -1
- package/dist/submission-confirm-hook.js +83 -21
- package/dist/submission-confirm-hook.js.map +1 -1
- package/dist/types.d.ts +6 -0
- package/dist/types.d.ts.map +1 -1
- package/docs/artifact-upload.md +124 -0
- package/docs/optional-rules.md +1 -0
- package/docs/osf-artifact.md +4 -1
- package/docs/rules/artifact/upload-current.md +85 -0
- package/docs/rules.md +1 -0
- package/eslint-rules/CLAUDE.md +5 -1
- package/eslint-rules/CLAUDE.md.spec.ts +3 -0
- package/package.json +1 -1
- package/src/adapters/latex/abstract.ts +3 -1
- package/src/adapters/latex/index.ts +3 -0
- package/src/adapters/latex/macros.test.ts +31 -0
- package/src/adapters/latex/macros.ts +43 -0
- package/src/adapters/osf/cassette/README.md +20 -0
- package/src/adapters/osf/cassette/get-file.json +108 -0
- package/src/adapters/osf/cassette/get-listing.json +111 -0
- package/src/adapters/osf/cassette/get-missing.json +1 -0
- package/src/adapters/osf/cassette/put-new.json +31 -0
- package/src/adapters/osf/host.io.ts +156 -0
- package/src/adapters/osf/host.test.ts +274 -0
- package/src/adapters/osf/index.ts +14 -0
- package/src/adapters/osf/response.ts +105 -0
- package/src/artifact-upload-rule.test.ts +213 -0
- package/src/artifact-upload-rule.ts +213 -0
- package/src/artifact.test.ts +504 -0
- package/src/artifact.ts +402 -0
- package/src/cli.test.ts +271 -1
- package/src/cli.ts +168 -23
- package/src/domain/artifact-upload.test.ts +80 -0
- package/src/domain/artifact-upload.ts +111 -0
- package/src/domain/paper-dirs.test.ts +91 -0
- package/src/domain/paper-dirs.ts +62 -0
- package/src/new-paper.test.ts +8 -2
- package/src/paper-files.test.ts +88 -0
- package/src/paper-files.ts +98 -9
- package/src/paper-settings-commands.test.ts +18 -0
- package/src/ports/artifact-host.ts +65 -0
- package/src/ports/latex.ts +10 -0
- package/src/rule-cases.test.ts +44 -0
- package/src/submission-confirm-hook.test.ts +113 -1
- package/src/submission-confirm-hook.ts +120 -27
- package/src/types.ts +6 -0
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `artifact/upload-current` — the paper prints numbers the uploaded artifact was not built for.
|
|
3
|
+
*
|
|
4
|
+
* OPT-IN, configured the ESLint way: off unless turned on with its options,
|
|
5
|
+
* `"artifact/upload-current": ["warn", { "numbers": "numbersdef.tex" }]` (`record` names another
|
|
6
|
+
* record file). It reads two local files and never the network: the upload record
|
|
7
|
+
* (`src/domain/artifact-upload.ts`), written by `paperlint artifact record|upload` or by anyone, and
|
|
8
|
+
* the paper's numbers file of `\newcommand{\key}{value}` lines. It compares the values recorded at
|
|
9
|
+
* upload with the values now, counting only the macros the paper's source uses (`paper.tex` and the
|
|
10
|
+
* body files the last build's record lists), so a macro defined and never printed never fires.
|
|
11
|
+
*
|
|
12
|
+
* Reported once per paper, on the first line of `PIPELINE-STATUS.md`, like the other folder rules.
|
|
13
|
+
* Turned on and missing what it needs (its `numbers` option, the numbers file, the record), it says
|
|
14
|
+
* so once, naming what answers it, and judges nothing else.
|
|
15
|
+
*/
|
|
16
|
+
import { basename, dirname, join, resolve } from "node:path";
|
|
17
|
+
import { callerPath } from "./caller-path.ts";
|
|
18
|
+
import {
|
|
19
|
+
DEFAULT_RECORD,
|
|
20
|
+
drift,
|
|
21
|
+
parseUploadRecord,
|
|
22
|
+
printedThrough,
|
|
23
|
+
type UploadRecord,
|
|
24
|
+
} from "./domain/artifact-upload.ts";
|
|
25
|
+
import { fieldOf } from "./domain/record.ts";
|
|
26
|
+
import { err, ok, type Result } from "./domain/result.ts";
|
|
27
|
+
import type { FolderRuleContext } from "./folder-venue-rule.ts";
|
|
28
|
+
import type { LatexReader } from "./ports/latex.ts";
|
|
29
|
+
import {
|
|
30
|
+
paperRecord,
|
|
31
|
+
recordedFiles,
|
|
32
|
+
type RecordReadDeps,
|
|
33
|
+
} from "./paper-record.ts";
|
|
34
|
+
import { decoded } from "./tex-paper.ts";
|
|
35
|
+
import { rulePageUrl, type Finding } from "./venue-rules.ts";
|
|
36
|
+
|
|
37
|
+
/** The file the rule reports on: one per paper folder. */
|
|
38
|
+
const STATUS_FILE = "PIPELINE-STATUS.md";
|
|
39
|
+
|
|
40
|
+
export interface UploadRuleDeps extends RecordReadDeps {
|
|
41
|
+
readonly latex: LatexReader;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** The rule's options: the numbers file, and the record, each relative to the paper. */
|
|
45
|
+
export interface UploadOptions {
|
|
46
|
+
readonly numbers: string | null;
|
|
47
|
+
readonly record: string;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** The options as ESLint hands them: a string `numbers` or none, `record` or the default. */
|
|
51
|
+
export const uploadOptions = (raw: unknown): UploadOptions => {
|
|
52
|
+
const numbers = fieldOf(raw, "numbers");
|
|
53
|
+
const record = fieldOf(raw, "record");
|
|
54
|
+
return {
|
|
55
|
+
numbers: typeof numbers === "string" ? numbers : null,
|
|
56
|
+
record: typeof record === "string" ? record : DEFAULT_RECORD,
|
|
57
|
+
};
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
/** What the paper prints now: the numbers file's values, and the macros its source uses. */
|
|
61
|
+
export interface Printed {
|
|
62
|
+
readonly values: ReadonlyMap<string, string>;
|
|
63
|
+
readonly used: ReadonlySet<string>;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** Why there are no numbers to compare: the file is not there, or it defines no macro. */
|
|
67
|
+
export type NumbersProblem = "noNumbersFile" | "emptyNumbers";
|
|
68
|
+
|
|
69
|
+
/** The text of the file at `rel` in the paper folder, or null. */
|
|
70
|
+
const textAt = (
|
|
71
|
+
dir: string,
|
|
72
|
+
rel: string,
|
|
73
|
+
deps: UploadRuleDeps,
|
|
74
|
+
): string | null =>
|
|
75
|
+
decoded(deps.files.readBytes(callerPath(resolve(dir, rel))));
|
|
76
|
+
|
|
77
|
+
/** The files whose uses count: `paper.tex`, and the body files of a fresh build record. */
|
|
78
|
+
function sourcesOf(dir: string, deps: UploadRuleDeps): readonly string[] {
|
|
79
|
+
const r = paperRecord(dir, deps);
|
|
80
|
+
const body = r.kind === "fresh" ? recordedFiles(dir, r.record, "body") : [];
|
|
81
|
+
return [join(dir, "paper.tex"), ...body];
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** The paper's numbers now, from the numbers file `numbers` (relative to the paper folder `dir`). */
|
|
85
|
+
export function printedNumbers(
|
|
86
|
+
dir: string,
|
|
87
|
+
numbers: string,
|
|
88
|
+
deps: UploadRuleDeps,
|
|
89
|
+
): Result<Printed, NumbersProblem> {
|
|
90
|
+
const text = textAt(dir, numbers, deps);
|
|
91
|
+
if (text === null) return err("noNumbersFile");
|
|
92
|
+
const defined = deps.latex.macroValues(text);
|
|
93
|
+
if (defined.length === 0) return err("emptyNumbers");
|
|
94
|
+
const used = sourcesOf(dir, deps).flatMap((f) => {
|
|
95
|
+
const src = textAt(dir, f, deps);
|
|
96
|
+
return src === null ? [] : deps.latex.macrosUsed(src);
|
|
97
|
+
});
|
|
98
|
+
const values = new Map(defined.map((d) => [d.name, d.value]));
|
|
99
|
+
return ok({
|
|
100
|
+
values,
|
|
101
|
+
used: printedThrough(values, new Set(used), deps.latex.macrosUsed),
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/** How many keys a message names before it says how many more there are. */
|
|
106
|
+
const SHOWN = 3;
|
|
107
|
+
const someOf = (keys: readonly string[]): string =>
|
|
108
|
+
[
|
|
109
|
+
...keys.slice(0, SHOWN),
|
|
110
|
+
...(keys.length > SHOWN ? [`${String(keys.length - SHOWN)} more`] : []),
|
|
111
|
+
].join(", ");
|
|
112
|
+
|
|
113
|
+
/** The finding of a record against the paper's numbers now; none when they agree. */
|
|
114
|
+
function staleFindings(r: UploadRecord, p: Printed): readonly Finding[] {
|
|
115
|
+
const d = drift(r.numbers, p.values, p.used);
|
|
116
|
+
const detail = [
|
|
117
|
+
...(d.added.length > 0
|
|
118
|
+
? [`${String(d.added.length)} new (${someOf(d.added)})`]
|
|
119
|
+
: []),
|
|
120
|
+
...(d.changed.length > 0
|
|
121
|
+
? [`${String(d.changed.length)} changed (${someOf(d.changed)})`]
|
|
122
|
+
: []),
|
|
123
|
+
];
|
|
124
|
+
if (detail.length === 0) return [];
|
|
125
|
+
const count = d.added.length + d.changed.length;
|
|
126
|
+
return [
|
|
127
|
+
{
|
|
128
|
+
messageId: "stale",
|
|
129
|
+
data: {
|
|
130
|
+
count,
|
|
131
|
+
date: r.uploadedAt.slice(0, 10),
|
|
132
|
+
url: r.url,
|
|
133
|
+
detail: detail.join(", "),
|
|
134
|
+
},
|
|
135
|
+
},
|
|
136
|
+
];
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/** The rule's findings for the paper folder `dir`: at most one. Reads through `deps`; never throws. */
|
|
140
|
+
export function uploadFindings(
|
|
141
|
+
dir: string,
|
|
142
|
+
o: UploadOptions,
|
|
143
|
+
deps: UploadRuleDeps,
|
|
144
|
+
): readonly Finding[] {
|
|
145
|
+
if (o.numbers === null) return [{ messageId: "noOption", data: {} }];
|
|
146
|
+
const printed = printedNumbers(dir, o.numbers, deps);
|
|
147
|
+
if (!printed.ok)
|
|
148
|
+
return [{ messageId: printed.error, data: { path: o.numbers } }];
|
|
149
|
+
const text = textAt(dir, o.record, deps);
|
|
150
|
+
if (text === null)
|
|
151
|
+
return [{ messageId: "noRecord", data: { path: o.record } }];
|
|
152
|
+
const record = parseUploadRecord(text);
|
|
153
|
+
return record.ok
|
|
154
|
+
? staleFindings(record.value, printed.value)
|
|
155
|
+
: [{ messageId: "badRecord", data: { path: o.record, why: record.error } }];
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
const META = {
|
|
159
|
+
type: "problem",
|
|
160
|
+
docs: {
|
|
161
|
+
description:
|
|
162
|
+
"opt-in: the paper prints numbers the uploaded artifact, as its upload record says, was not built for",
|
|
163
|
+
url: rulePageUrl("artifact/upload-current"),
|
|
164
|
+
},
|
|
165
|
+
schema: [
|
|
166
|
+
{
|
|
167
|
+
type: "object",
|
|
168
|
+
properties: { numbers: { type: "string" }, record: { type: "string" } },
|
|
169
|
+
additionalProperties: false,
|
|
170
|
+
},
|
|
171
|
+
],
|
|
172
|
+
messages: {
|
|
173
|
+
stale:
|
|
174
|
+
"the paper prints {{count}} numbers the upload of {{date}} ({{url}}) was not built for: {{detail}} — rebuild and upload the artifact, then record it again (`paperlint artifact record <zip> --url <url>`)",
|
|
175
|
+
noOption:
|
|
176
|
+
'artifact/upload-current is on without its numbers file: give it as an option, ["warn", { "numbers": "numbersdef.tex" }], relative to the paper',
|
|
177
|
+
noNumbersFile:
|
|
178
|
+
'the numbers file {{path}} (the rule\'s "numbers" option, relative to the paper) does not exist, so the upload cannot be compared with what the paper prints',
|
|
179
|
+
emptyNumbers:
|
|
180
|
+
"the numbers file {{path}} defines no macro without arguments (\\newcommand{\\key}{value}), so the upload cannot be compared with what the paper prints",
|
|
181
|
+
noRecord:
|
|
182
|
+
"no upload record {{path}}: after uploading the artifact, write one with `paperlint artifact record <zip> --url <url>` (or by hand, docs/artifact-upload.md)",
|
|
183
|
+
badRecord: "the upload record {{path}} cannot be read: {{why}}",
|
|
184
|
+
},
|
|
185
|
+
} as const;
|
|
186
|
+
|
|
187
|
+
/** The rule, as a rule of the `artifact` plugin. On for no paper until its options turn it on. */
|
|
188
|
+
export function artifactUploadRules(deps: UploadRuleDeps): {
|
|
189
|
+
readonly "upload-current": {
|
|
190
|
+
readonly meta: typeof META;
|
|
191
|
+
create(c: FolderRuleContext & { readonly options: readonly unknown[] }): {
|
|
192
|
+
root?: () => void;
|
|
193
|
+
};
|
|
194
|
+
};
|
|
195
|
+
} {
|
|
196
|
+
return {
|
|
197
|
+
"upload-current": {
|
|
198
|
+
meta: META,
|
|
199
|
+
create(context) {
|
|
200
|
+
if (basename(context.filename) !== STATUS_FILE) return {};
|
|
201
|
+
return {
|
|
202
|
+
root() {
|
|
203
|
+
const at = context.sourceCode.getLocFromIndex(0);
|
|
204
|
+
const o = uploadOptions(context.options[0]);
|
|
205
|
+
uploadFindings(dirname(context.filename), o, deps).forEach((f) => {
|
|
206
|
+
context.report({ loc: { start: at, end: at }, ...f });
|
|
207
|
+
});
|
|
208
|
+
},
|
|
209
|
+
};
|
|
210
|
+
},
|
|
211
|
+
},
|
|
212
|
+
};
|
|
213
|
+
}
|