paperlint 20.5.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 +11 -8
- 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-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 +4 -2
- package/dist/corpus-record-rule.js.map +1 -1
- 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/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/optional-rules.md +11 -10
- package/docs/rules/corpus/licence.md +125 -0
- package/docs/rules/corpus/record.md +6 -3
- package/docs/rules.md +2 -1
- package/docs/venues.md +8 -8
- 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.ts +13 -11
- package/src/corpus-json-rules.ts +22 -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 +12 -0
- package/src/corpus-record-rule.ts +6 -2
- 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/rule-cases.test.ts +2 -44
- package/src/rule-id-shape.test.ts +42 -0
- package/dist/skill-chunks/{chunk-CXAGKT44.js → chunk-EDHTB7KT.js} +4 -4
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `corpus/licence` through `paperlint lint`, the way a consumer runs it: off unless the root
|
|
3
|
+
* `paperlint.json` turns it on, reported at the copy's `stored`, with the non-commercial setting as
|
|
4
|
+
* the rule's own option.
|
|
5
|
+
*/
|
|
6
|
+
import { describe, expect, it } from "vitest";
|
|
7
|
+
import { z } from "zod";
|
|
8
|
+
import { run } from "./cli.ts";
|
|
9
|
+
import { useTempDir, writeTree } from "../test/support.ts";
|
|
10
|
+
|
|
11
|
+
const STATUS = "---\nstages: []\n---\n# PIPELINE-STATUS\n";
|
|
12
|
+
const TEX = "\\documentclass{article}\n\\begin{document}\nx\n\\end{document}\n";
|
|
13
|
+
const PAPER = {
|
|
14
|
+
"papers/p/PIPELINE-STATUS.md": STATUS,
|
|
15
|
+
"papers/p/paper.tex": TEX,
|
|
16
|
+
};
|
|
17
|
+
const C = "papers/venues/agent";
|
|
18
|
+
const RECORD = `${C}/papers.json`;
|
|
19
|
+
|
|
20
|
+
/** A copy storing both kinds under `licence`. */
|
|
21
|
+
const copy = (licence: Readonly<Record<string, string>>) => ({
|
|
22
|
+
version: "published",
|
|
23
|
+
url: "https://doi.org/10.1/x",
|
|
24
|
+
licence,
|
|
25
|
+
stored: ["pdf", "text"],
|
|
26
|
+
fetched_from: "https://doi.org/10.1/x",
|
|
27
|
+
});
|
|
28
|
+
const READ = { read_from: "https://example.org", read_on: "2026-11-03" };
|
|
29
|
+
const record = (licences: readonly Record<string, string>[]): string =>
|
|
30
|
+
JSON.stringify(
|
|
31
|
+
{
|
|
32
|
+
venue: "agent",
|
|
33
|
+
editions: [
|
|
34
|
+
{
|
|
35
|
+
edition: 2026,
|
|
36
|
+
listed_from: "https://example.org/accepted",
|
|
37
|
+
read_on: "2026-11-03",
|
|
38
|
+
accepted: 1,
|
|
39
|
+
capped: null,
|
|
40
|
+
proxy: null,
|
|
41
|
+
},
|
|
42
|
+
],
|
|
43
|
+
papers: [
|
|
44
|
+
{
|
|
45
|
+
key: "a",
|
|
46
|
+
edition: 2026,
|
|
47
|
+
group: "accepted",
|
|
48
|
+
title: "A",
|
|
49
|
+
ids: { doi: "10.1/x" },
|
|
50
|
+
copies: licences.map(copy),
|
|
51
|
+
},
|
|
52
|
+
],
|
|
53
|
+
rebuild: [],
|
|
54
|
+
},
|
|
55
|
+
null,
|
|
56
|
+
2,
|
|
57
|
+
);
|
|
58
|
+
/** The corpus whose stored files the record claims. */
|
|
59
|
+
const corpus = (licences: readonly Record<string, string>[]) => ({
|
|
60
|
+
...PAPER,
|
|
61
|
+
[RECORD]: record(licences),
|
|
62
|
+
[`${C}/pdf/a.pdf`]: "%PDF",
|
|
63
|
+
[`${C}/text/a.txt`]: "a",
|
|
64
|
+
});
|
|
65
|
+
const ON = (options?: Readonly<Record<string, boolean>>) => ({
|
|
66
|
+
"paperlint.json": JSON.stringify({
|
|
67
|
+
rules: {
|
|
68
|
+
"corpus/licence": options === undefined ? "warn" : ["warn", options],
|
|
69
|
+
},
|
|
70
|
+
}),
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
const Results = z.array(
|
|
74
|
+
z.looseObject({
|
|
75
|
+
filePath: z.string(),
|
|
76
|
+
messages: z.array(
|
|
77
|
+
z.looseObject({
|
|
78
|
+
ruleId: z.string().nullable(),
|
|
79
|
+
messageId: z.string().optional(),
|
|
80
|
+
severity: z.number(),
|
|
81
|
+
line: z.number().optional(),
|
|
82
|
+
message: z.string(),
|
|
83
|
+
}),
|
|
84
|
+
),
|
|
85
|
+
}),
|
|
86
|
+
);
|
|
87
|
+
|
|
88
|
+
/** Every message of `corpus/licence`, with its file. */
|
|
89
|
+
async function licenceFindings(
|
|
90
|
+
tree: Readonly<Record<string, string>>,
|
|
91
|
+
paths: readonly string[] = [],
|
|
92
|
+
) {
|
|
93
|
+
const dir = writeTree(useTempDir("paperlint-licence-"), {
|
|
94
|
+
"package.json": '{"name":"consumer","private":true}',
|
|
95
|
+
...tree,
|
|
96
|
+
});
|
|
97
|
+
const out: string[] = [];
|
|
98
|
+
const errs: string[] = [];
|
|
99
|
+
const code = await run(["lint", "--json", ...paths], {
|
|
100
|
+
cwd: dir,
|
|
101
|
+
log: (...a: unknown[]) => out.push(a.join(" ")),
|
|
102
|
+
err: (...a: unknown[]) => errs.push(a.join(" ")),
|
|
103
|
+
});
|
|
104
|
+
if (code !== 0 && out.length === 0) throw new Error(errs.join("\n"));
|
|
105
|
+
return Results.parse(JSON.parse(out.join("\n"))).flatMap((r) =>
|
|
106
|
+
r.messages
|
|
107
|
+
.filter((m) => m.ruleId === "corpus/licence")
|
|
108
|
+
.map((m) => ({ ...m, file: r.filePath.slice(dir.length + 1) })),
|
|
109
|
+
);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
describe("corpus/licence is off unless it is turned on", () => {
|
|
113
|
+
it("🔴 says nothing about a corpus of forbidden and unread copies when no setting names it", async () => {
|
|
114
|
+
// Guards: opt-in means silent; the same files are legal in a private repository.
|
|
115
|
+
expect(
|
|
116
|
+
await licenceFindings(
|
|
117
|
+
corpus([
|
|
118
|
+
{ id: "LicenseRef-publisher", ...READ },
|
|
119
|
+
{ id: "NOASSERTION" },
|
|
120
|
+
]),
|
|
121
|
+
),
|
|
122
|
+
).toEqual([]);
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
it("reports a copy's refusal once with warn, at the copy's stored line", async () => {
|
|
126
|
+
// Guards: a copy whose two stored kinds are refused for one reason is one finding, not two.
|
|
127
|
+
const tree = corpus([{ id: "LicenseRef-publisher", ...READ }]);
|
|
128
|
+
const found = await licenceFindings({ ...tree, ...ON() });
|
|
129
|
+
const line =
|
|
130
|
+
tree[RECORD].split("\n").findIndex((l) => l.includes('"stored"')) + 1;
|
|
131
|
+
expect(found.map((m) => [m.file, m.severity, m.line, m.messageId])).toEqual(
|
|
132
|
+
[[RECORD, 1, line, "forbidden"]],
|
|
133
|
+
);
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
it("names each message by what was refused", async () => {
|
|
137
|
+
const found = await licenceFindings({
|
|
138
|
+
...corpus([
|
|
139
|
+
{ id: "NOASSERTION" },
|
|
140
|
+
{ id: "CC-BY-3.0", ...READ },
|
|
141
|
+
{ id: "CC-BY-NC-4.0", ...READ },
|
|
142
|
+
]),
|
|
143
|
+
...ON(),
|
|
144
|
+
});
|
|
145
|
+
expect(new Set(found.map((m) => m.messageId))).toEqual(
|
|
146
|
+
new Set(["not-read", "unlisted", "non-commercial-only"]),
|
|
147
|
+
);
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
it("is silent on a permitted licence even when turned on", async () => {
|
|
151
|
+
expect(
|
|
152
|
+
await licenceFindings({
|
|
153
|
+
...corpus([{ id: "CC-BY-4.0", ...READ }]),
|
|
154
|
+
...ON(),
|
|
155
|
+
}),
|
|
156
|
+
).toEqual([]);
|
|
157
|
+
});
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
describe("corpus/licence: turned on where there is no corpus", () => {
|
|
161
|
+
it("🔴 is refused as a rule that reached nothing, not read as a pass", async () => {
|
|
162
|
+
// Guards: an optional rule that is on and sees no file reports exactly like one that passed.
|
|
163
|
+
await expect(licenceFindings({ ...PAPER, ...ON() })).rejects.toThrow(
|
|
164
|
+
/corpus\/licence is turned on in "rules"/,
|
|
165
|
+
);
|
|
166
|
+
});
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
describe("corpus/licence: a lint of one paper in a project with a corpus", () => {
|
|
170
|
+
it("🔴 runs, and judges no corpus it was not given", async () => {
|
|
171
|
+
// Guards: the rule reaches the project's corpus, so a run over one paper is not refused.
|
|
172
|
+
expect(
|
|
173
|
+
await licenceFindings(
|
|
174
|
+
{ ...corpus([{ id: "LicenseRef-publisher", ...READ }]), ...ON() },
|
|
175
|
+
["papers/p"],
|
|
176
|
+
),
|
|
177
|
+
).toEqual([]);
|
|
178
|
+
});
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
describe("corpus/licence: a record that does not parse is corpus/record's", () => {
|
|
182
|
+
it("says nothing of its own about it", async () => {
|
|
183
|
+
// Guards: no licence can be read from a record the schema refuses.
|
|
184
|
+
expect(
|
|
185
|
+
await licenceFindings({
|
|
186
|
+
...PAPER,
|
|
187
|
+
...ON(),
|
|
188
|
+
[RECORD]: '{"venue":"agent"}',
|
|
189
|
+
}),
|
|
190
|
+
).toEqual([]);
|
|
191
|
+
});
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
describe("corpus/licence: the non-commercial setting is the rule's option", () => {
|
|
195
|
+
const nc = corpus([{ id: "CC-BY-NC-4.0", ...READ }]);
|
|
196
|
+
|
|
197
|
+
it("🔴 permits a non-commercial licence with nonCommercial: true", async () => {
|
|
198
|
+
expect(
|
|
199
|
+
await licenceFindings({ ...nc, ...ON({ nonCommercial: true }) }),
|
|
200
|
+
).toEqual([]);
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
it("refuses it with nonCommercial: false, as by default", async () => {
|
|
204
|
+
expect(
|
|
205
|
+
(await licenceFindings({ ...nc, ...ON({ nonCommercial: false }) })).map(
|
|
206
|
+
(m) => m.messageId,
|
|
207
|
+
),
|
|
208
|
+
).toEqual(["non-commercial-only"]);
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
it("refuses an option the rule does not have", async () => {
|
|
212
|
+
// Guards: a misspelt option is ESLint's schema error, not a silent default.
|
|
213
|
+
await expect(
|
|
214
|
+
licenceFindings({ ...nc, ...ON({ noncommercial: true }) }),
|
|
215
|
+
).rejects.toThrow(/corpus\/licence/);
|
|
216
|
+
});
|
|
217
|
+
});
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `corpus/licence` — the licence of each copy a venue corpus stores permits keeping it
|
|
3
|
+
* (docs/design/venue-corpus.md, decisions 3 and 4; docs/rules/corpus/licence.md). OFF by default and
|
|
4
|
+
* in no rule set: the same files are legal in a private repository and illegal in a public one, and
|
|
5
|
+
* the rule cannot tell which it is in. What is judged is `src/domain/corpus-licence.ts`, which asks
|
|
6
|
+
* the table in `src/domain/licence.ts`; this file reads the record through the codec, reads the
|
|
7
|
+
* rule's one option, and reports.
|
|
8
|
+
*
|
|
9
|
+
* ── WHERE IT REPORTS ─────────────────────────────────────────────────────────────
|
|
10
|
+
* On `<papers-root>/venues/<venue>/papers.json`, at the `stored` of the copy each finding is about
|
|
11
|
+
* (the same location technique as `corpus/record`, `spanAt`). A record that does not parse has
|
|
12
|
+
* findings of `corpus/record`'s and none of this rule's.
|
|
13
|
+
*
|
|
14
|
+
* ── THE OPTION ───────────────────────────────────────────────────────────────────
|
|
15
|
+
* `"corpus/licence": ["warn", { "nonCommercial": true }]` in the root `paperlint.json`: the project
|
|
16
|
+
* declares itself non-commercial, which makes a non-commercial licence permit storing. The
|
|
17
|
+
* default is false: paperlint does not assume it.
|
|
18
|
+
*/
|
|
19
|
+
import { spanAt, type JsonRuleModule } from "./corpus-record-rule.ts";
|
|
20
|
+
import {
|
|
21
|
+
judgeLicences,
|
|
22
|
+
licenceMessage,
|
|
23
|
+
type Refusal,
|
|
24
|
+
} from "./domain/corpus-licence.ts";
|
|
25
|
+
import type { VenueCorpusCodec } from "./ports/venue-corpus-codec.ts";
|
|
26
|
+
import { rulePageUrl } from "./venue-rules.ts";
|
|
27
|
+
|
|
28
|
+
/** What the rule reads with. */
|
|
29
|
+
export interface CorpusLicenceDeps {
|
|
30
|
+
readonly codec: VenueCorpusCodec;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** The option, as ESLint's schema validated it: `nonCommercial` is a boolean or absent. */
|
|
34
|
+
const nonCommercial = (options: readonly unknown[]): boolean => {
|
|
35
|
+
const [first] = options;
|
|
36
|
+
return (
|
|
37
|
+
typeof first === "object" &&
|
|
38
|
+
first !== null &&
|
|
39
|
+
"nonCommercial" in first &&
|
|
40
|
+
first.nonCommercial === true
|
|
41
|
+
);
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
const META: JsonRuleModule["meta"] = {
|
|
45
|
+
type: "suggestion",
|
|
46
|
+
docs: {
|
|
47
|
+
description:
|
|
48
|
+
"each copy a venue corpus stores has a licence that permits keeping that file (opt-in: the same files are legal in a private repository and illegal in a public one)",
|
|
49
|
+
url: rulePageUrl("corpus/licence"),
|
|
50
|
+
},
|
|
51
|
+
schema: [
|
|
52
|
+
{
|
|
53
|
+
type: "object",
|
|
54
|
+
properties: { nonCommercial: { type: "boolean" } },
|
|
55
|
+
additionalProperties: false,
|
|
56
|
+
},
|
|
57
|
+
],
|
|
58
|
+
// One id per kind of refusal, each with the whole text of `licenceMessage`.
|
|
59
|
+
messages: {
|
|
60
|
+
"not-read": "{{text}}",
|
|
61
|
+
unlisted: "{{text}}",
|
|
62
|
+
forbidden: "{{text}}",
|
|
63
|
+
"non-commercial-only": "{{text}}",
|
|
64
|
+
} satisfies Record<Refusal["kind"], string>,
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
/** The rule, reading each record through `deps.codec`. */
|
|
68
|
+
export function corpusLicenceRules(
|
|
69
|
+
deps: CorpusLicenceDeps,
|
|
70
|
+
): Readonly<Record<"licence", JsonRuleModule>> {
|
|
71
|
+
return {
|
|
72
|
+
licence: {
|
|
73
|
+
meta: META,
|
|
74
|
+
create(context) {
|
|
75
|
+
return {
|
|
76
|
+
Document() {
|
|
77
|
+
const { text, ast } = context.sourceCode;
|
|
78
|
+
const record = deps.codec.parse(text);
|
|
79
|
+
if (!record.ok) return;
|
|
80
|
+
judgeLicences(record.corpus, {
|
|
81
|
+
nonCommercial: nonCommercial(context.options),
|
|
82
|
+
}).forEach((f) => {
|
|
83
|
+
context.report({
|
|
84
|
+
loc: spanAt(ast, f.at),
|
|
85
|
+
messageId: f.refusal.kind,
|
|
86
|
+
data: { text: licenceMessage(f) },
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
},
|
|
90
|
+
};
|
|
91
|
+
},
|
|
92
|
+
},
|
|
93
|
+
};
|
|
94
|
+
}
|
|
@@ -184,6 +184,18 @@ describe("corpus/record: each finding, at its place in papers.json", () => {
|
|
|
184
184
|
]);
|
|
185
185
|
});
|
|
186
186
|
|
|
187
|
+
it("🔴 reports a venue that is not its folder's name at the venue field", async () => {
|
|
188
|
+
const text = record([]).replace('"venue": "agent"', '"venue": "agnet"');
|
|
189
|
+
const found = await onCorpus({ ...PAPER, [RECORD]: text });
|
|
190
|
+
// Guards: the folder is the preset's series, so the field must say the same; reported where it is written.
|
|
191
|
+
expect(found.map((m) => [m.ruleId, m.line, m.column, m.messageId])).toEqual(
|
|
192
|
+
[["corpus/record", lineOf(text, '"venue"'), 3, "venue"]],
|
|
193
|
+
);
|
|
194
|
+
expect(found.map((m) => m.message)).toEqual([
|
|
195
|
+
'the record says `"venue": "agnet"`, and its folder is `agent`. What to do: rename the folder to `agnet`, or correct the field to `agent`',
|
|
196
|
+
]);
|
|
197
|
+
});
|
|
198
|
+
|
|
187
199
|
it("is turned off in the root paperlint.json by one line", async () => {
|
|
188
200
|
expect(
|
|
189
201
|
await corpusFindings({
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
* folder without `papers.json` has no file to report on, and this rule says nothing about it:
|
|
13
13
|
* `corpus/allowed-files-only` reports it on the root `paperlint.json` (src/corpus-layout-rule.ts).
|
|
14
14
|
*/
|
|
15
|
-
import { dirname, join } from "node:path";
|
|
15
|
+
import { basename, dirname, join } from "node:path";
|
|
16
16
|
import { callerPath } from "./caller-path.ts";
|
|
17
17
|
import {
|
|
18
18
|
corpusMessage,
|
|
@@ -65,6 +65,8 @@ interface JsonDocument {
|
|
|
65
65
|
/** What the rule uses of ESLint's context on a JSON file. */
|
|
66
66
|
export interface JsonRuleContext {
|
|
67
67
|
readonly filename: string;
|
|
68
|
+
/** The options the rule was configured with: what follows its severity in `["warn", { … }]`. */
|
|
69
|
+
readonly options: readonly unknown[];
|
|
68
70
|
readonly sourceCode: { readonly text: string; readonly ast: JsonDocument };
|
|
69
71
|
report(d: {
|
|
70
72
|
readonly loc: Span;
|
|
@@ -117,6 +119,7 @@ const findingsFor = (
|
|
|
117
119
|
deps: CorpusRecordDeps,
|
|
118
120
|
): readonly CorpusFinding[] =>
|
|
119
121
|
judgeCorpus({
|
|
122
|
+
folder: basename(dirname(file)),
|
|
120
123
|
record: deps.codec.parse(text),
|
|
121
124
|
stored: {
|
|
122
125
|
pdf: visible(join(dirname(file), "pdf"), deps),
|
|
@@ -128,7 +131,7 @@ const META: FolderRuleModule["meta"] = {
|
|
|
128
131
|
type: "suggestion",
|
|
129
132
|
docs: {
|
|
130
133
|
description:
|
|
131
|
-
"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",
|
|
134
|
+
"a venue corpus's papers.json is a record that names its own folder as its venue, every copy stored in pdf/ and text/ is claimed by one copy in it, and every claimed file is there",
|
|
132
135
|
url: rulePageUrl("corpus/record"),
|
|
133
136
|
},
|
|
134
137
|
schema: [],
|
|
@@ -137,6 +140,7 @@ const META: FolderRuleModule["meta"] = {
|
|
|
137
140
|
(
|
|
138
141
|
[
|
|
139
142
|
"unparsed",
|
|
143
|
+
"venue",
|
|
140
144
|
"unclaimed",
|
|
141
145
|
"missing",
|
|
142
146
|
"twice",
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
/** The licence judge: each refusal of the table reaches a finding at its copy's `stored`, a permitted kind none. */
|
|
2
|
+
import { describe, expect, it } from "vitest";
|
|
3
|
+
import { judgeLicences, licenceMessage } from "./corpus-licence.ts";
|
|
4
|
+
import type { Copy, Paper, VenueCorpus } from "./venue-corpus.ts";
|
|
5
|
+
|
|
6
|
+
const copy = (id: string, stored: Copy["stored"]): Copy => ({
|
|
7
|
+
version: "published",
|
|
8
|
+
url: "https://doi.org/10.1/x",
|
|
9
|
+
licence: { id, read_from: "https://example.org", read_on: "2026-11-03" },
|
|
10
|
+
stored,
|
|
11
|
+
fetched_from: "https://doi.org/10.1/x",
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
const paper = (key: string, copies: readonly Copy[]): Paper => ({
|
|
15
|
+
key,
|
|
16
|
+
title: "A title",
|
|
17
|
+
group: "accepted",
|
|
18
|
+
edition: 2026,
|
|
19
|
+
ids: { doi: "10.1/x" },
|
|
20
|
+
copies,
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
const corpus = (papers: readonly Paper[]): VenueCorpus => ({
|
|
24
|
+
venue: "agent",
|
|
25
|
+
editions: [],
|
|
26
|
+
papers,
|
|
27
|
+
rebuild: [],
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
const OFF = { nonCommercial: false };
|
|
31
|
+
|
|
32
|
+
describe("judgeLicences", () => {
|
|
33
|
+
it("is silent on a permitted licence and on a copy that stores nothing", () => {
|
|
34
|
+
expect(
|
|
35
|
+
judgeLicences(
|
|
36
|
+
corpus([
|
|
37
|
+
paper("a", [
|
|
38
|
+
copy("CC-BY-4.0", ["pdf", "text"]),
|
|
39
|
+
{ ...copy("LicenseRef-publisher", []), fetched_from: undefined },
|
|
40
|
+
]),
|
|
41
|
+
]),
|
|
42
|
+
OFF,
|
|
43
|
+
),
|
|
44
|
+
).toEqual([]);
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it("reports each refused kind of each copy at that copy's stored, in the record's order", () => {
|
|
48
|
+
const found = judgeLicences(
|
|
49
|
+
corpus([
|
|
50
|
+
paper("a", [copy("CC-BY-4.0", ["pdf"])]),
|
|
51
|
+
paper("b", [
|
|
52
|
+
copy("CC-BY-4.0", ["text"]),
|
|
53
|
+
copy("CC-BY-ND-4.0", ["pdf", "text"]),
|
|
54
|
+
copy("CC-BY-3.0", ["pdf"]),
|
|
55
|
+
]),
|
|
56
|
+
]),
|
|
57
|
+
OFF,
|
|
58
|
+
);
|
|
59
|
+
expect(found.map((f) => [f.at, f.stored, f.refusal.kind])).toEqual([
|
|
60
|
+
[["papers", 1, "copies", 1, "stored"], ["text"], "forbidden"],
|
|
61
|
+
[["papers", 1, "copies", 2, "stored"], ["pdf"], "unlisted"],
|
|
62
|
+
]);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it("gives a copy one finding per reason, naming every kind it stands against", () => {
|
|
66
|
+
// Guards: two kinds refused for the same reason are one finding, not one per kind.
|
|
67
|
+
const found = judgeLicences(
|
|
68
|
+
corpus([
|
|
69
|
+
paper("a", [
|
|
70
|
+
copy("NOASSERTION", ["pdf", "text"]),
|
|
71
|
+
copy("CC-BY-NC-ND-4.0", ["pdf", "text"]),
|
|
72
|
+
]),
|
|
73
|
+
]),
|
|
74
|
+
OFF,
|
|
75
|
+
);
|
|
76
|
+
expect(found.map((f) => [f.at, f.stored, f.refusal.kind])).toEqual([
|
|
77
|
+
[["papers", 0, "copies", 0, "stored"], ["pdf", "text"], "not-read"],
|
|
78
|
+
[["papers", 0, "copies", 1, "stored"], ["pdf"], "non-commercial-only"],
|
|
79
|
+
[["papers", 0, "copies", 1, "stored"], ["text"], "forbidden"],
|
|
80
|
+
]);
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it("asks the table with the project's setting", () => {
|
|
84
|
+
const nc = corpus([paper("a", [copy("CC-BY-NC-4.0", ["pdf"])])]);
|
|
85
|
+
expect(judgeLicences(nc, OFF).map((f) => f.refusal.kind)).toEqual([
|
|
86
|
+
"non-commercial-only",
|
|
87
|
+
]);
|
|
88
|
+
expect(judgeLicences(nc, { nonCommercial: true })).toEqual([]);
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
describe("licenceMessage: each refusal names its cure", () => {
|
|
93
|
+
const messageOf = (id: string, stored: Copy["stored"]) => {
|
|
94
|
+
const [f] = judgeLicences(corpus([paper("k", [copy(id, stored)])]), OFF);
|
|
95
|
+
return f === undefined ? "" : licenceMessage(f);
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
it.each([
|
|
99
|
+
[
|
|
100
|
+
"NOASSERTION",
|
|
101
|
+
"a copy of `k` stores `pdf` (`pdf/<key>.pdf`), and no licence was read for that copy (`NOASSERTION`). What to do: record the licence and where it was read (`licence.id`, `read_from`, `read_on`), or remove the file and `\"pdf\"` from that copy's `stored`, and keep the paper's ids",
|
|
102
|
+
],
|
|
103
|
+
[
|
|
104
|
+
"CC-BY-3.0",
|
|
105
|
+
"a copy of `k` stores `pdf` (`pdf/<key>.pdf`) under `CC-BY-3.0`, and the licence table does not list that id, so it permits nothing. What to do: correct the id if it is misspelt; otherwise remove the file and `\"pdf\"` from that copy's `stored`, and keep the paper's ids",
|
|
106
|
+
],
|
|
107
|
+
[
|
|
108
|
+
"LicenseRef-publisher",
|
|
109
|
+
"a copy of `k` stores `pdf` (`pdf/<key>.pdf`) under `LicenseRef-publisher`, which does not permit it: the publisher grants no right to third parties. What to do: remove the file and `\"pdf\"` from that copy's `stored`, and keep the paper's ids",
|
|
110
|
+
],
|
|
111
|
+
[
|
|
112
|
+
"CC-BY-NC-4.0",
|
|
113
|
+
'a copy of `k` stores `pdf` (`pdf/<key>.pdf`) under `CC-BY-NC-4.0`, which permits it only in a non-commercial project, and this one has not declared itself one. What to do: if it is one, set `"corpus/licence": ["warn", { "nonCommercial": true }]` in the root `paperlint.json`; otherwise remove the file and `"pdf"` from that copy\'s `stored`, and keep the paper\'s ids',
|
|
114
|
+
],
|
|
115
|
+
])("%s", (id, text) => {
|
|
116
|
+
expect(messageOf(id, ["pdf"])).toBe(text);
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
it("names every kind and file of a finding", () => {
|
|
120
|
+
expect(messageOf("LicenseRef-publisher", ["pdf", "text"])).toBe(
|
|
121
|
+
'a copy of `k` stores `pdf` and `text` (`pdf/<key>.pdf`, `text/<key>.txt`) under `LicenseRef-publisher`, which does not permit them: the publisher grants no right to third parties. What to do: remove the files and `"pdf"` and `"text"` from that copy\'s `stored`, and keep the paper\'s ids',
|
|
122
|
+
);
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
it("names the text file for a stored text", () => {
|
|
126
|
+
expect(messageOf("NOASSERTION", ["text"])).toContain("(`text/<key>.txt`)");
|
|
127
|
+
});
|
|
128
|
+
});
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `corpus/licence`'s judgement of one venue corpus (docs/design/venue-corpus.md, decisions 3 and 4;
|
|
3
|
+
* docs/rules/corpus/licence.md): whether the licence of each copy permits keeping each kind it
|
|
4
|
+
* stores. Pure: the record, already parsed by the codec, and the one setting in; the findings out.
|
|
5
|
+
* What a licence permits is the table in `licence.ts`, asked here and never copied.
|
|
6
|
+
*/
|
|
7
|
+
import { groupBy } from "remeda";
|
|
8
|
+
import { storedAt } from "./corpus-record.ts";
|
|
9
|
+
import {
|
|
10
|
+
permits,
|
|
11
|
+
type LicenceSettings,
|
|
12
|
+
type Permission,
|
|
13
|
+
type StoredKind,
|
|
14
|
+
} from "./licence.ts";
|
|
15
|
+
import type { Copy, RecordPath, VenueCorpus } from "./venue-corpus.ts";
|
|
16
|
+
|
|
17
|
+
/** What stands against storing one kind of one copy: any permission but the one that allows it. */
|
|
18
|
+
export type Refusal = Exclude<Permission, { readonly kind: "permitted" }>;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* The kinds of one copy that one refusal stands against, with `at`, the copy's `stored` in `papers.json`.
|
|
22
|
+
* A copy whose kinds are refused for the same reason is one finding naming them all; ND, which
|
|
23
|
+
* refuses one kind and not the other, gives one finding for that kind.
|
|
24
|
+
*/
|
|
25
|
+
export interface LicenceFinding {
|
|
26
|
+
readonly at: RecordPath;
|
|
27
|
+
readonly key: string;
|
|
28
|
+
readonly licence: string;
|
|
29
|
+
readonly stored: readonly [StoredKind, ...StoredKind[]];
|
|
30
|
+
readonly refusal: Refusal;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** One stored kind of a copy and what refuses it. */
|
|
34
|
+
interface Refused {
|
|
35
|
+
readonly stored: StoredKind;
|
|
36
|
+
readonly refusal: Refusal;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** The stored kinds of `copy` its licence refuses, in its `stored` order. */
|
|
40
|
+
const refusedKinds = (
|
|
41
|
+
copy: Readonly<Copy>,
|
|
42
|
+
settings: Readonly<LicenceSettings>,
|
|
43
|
+
): readonly Refused[] =>
|
|
44
|
+
copy.stored.flatMap((stored) => {
|
|
45
|
+
const refusal = permits(copy.licence.id, stored, settings);
|
|
46
|
+
return refusal.kind === "permitted" ? [] : [{ stored, refusal }];
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
/** The refusals of one copy, one per reason (two refusals that print the same message are one), each with its kinds. */
|
|
50
|
+
const byReason = (
|
|
51
|
+
refused: readonly Refused[],
|
|
52
|
+
): readonly Pick<LicenceFinding, "stored" | "refusal">[] =>
|
|
53
|
+
Object.values(groupBy(refused, (r) => JSON.stringify(r.refusal))).map(
|
|
54
|
+
([first, ...rest]) => ({
|
|
55
|
+
stored: [first.stored, ...rest.map((r) => r.stored)],
|
|
56
|
+
refusal: first.refusal,
|
|
57
|
+
}),
|
|
58
|
+
);
|
|
59
|
+
|
|
60
|
+
/** Every refusal of every copy, with the stored kinds it stands against, in the record's order. */
|
|
61
|
+
export const judgeLicences = (
|
|
62
|
+
corpus: VenueCorpus,
|
|
63
|
+
settings: Readonly<LicenceSettings>,
|
|
64
|
+
): readonly LicenceFinding[] =>
|
|
65
|
+
corpus.papers.flatMap((p, paper) =>
|
|
66
|
+
p.copies.flatMap((c, copy) =>
|
|
67
|
+
byReason(refusedKinds(c, settings)).map((r) => ({
|
|
68
|
+
at: storedAt(paper, [copy]),
|
|
69
|
+
key: p.key,
|
|
70
|
+
licence: c.licence.id,
|
|
71
|
+
...r,
|
|
72
|
+
})),
|
|
73
|
+
),
|
|
74
|
+
);
|
|
75
|
+
|
|
76
|
+
const FILE: Readonly<Record<StoredKind, string>> = {
|
|
77
|
+
pdf: "pdf/<key>.pdf",
|
|
78
|
+
text: "text/<key>.txt",
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
/** The text of a finding: what is wrong, then what to do. */
|
|
82
|
+
export function licenceMessage(f: LicenceFinding): string {
|
|
83
|
+
const kinds = f.stored.map((k) => `\`${k}\``).join(" and ");
|
|
84
|
+
const files = f.stored.map((k) => `\`${FILE[k]}\``).join(", ");
|
|
85
|
+
const quoted = f.stored.map((k) => `\`"${k}"\``).join(" and ");
|
|
86
|
+
const it = f.stored.length === 1 ? "it" : "them";
|
|
87
|
+
const what = `a copy of \`${f.key}\` stores ${kinds} (${files})`;
|
|
88
|
+
const remove = `remove ${f.stored.length === 1 ? "the file" : "the files"} and ${quoted} from that copy's \`stored\`, and keep the paper's ids`;
|
|
89
|
+
switch (f.refusal.kind) {
|
|
90
|
+
case "not-read":
|
|
91
|
+
return `${what}, and no licence was read for that copy (\`NOASSERTION\`). What to do: record the licence and where it was read (\`licence.id\`, \`read_from\`, \`read_on\`), or ${remove}`;
|
|
92
|
+
case "unlisted":
|
|
93
|
+
return `${what} under \`${f.refusal.id}\`, and the licence table does not list that id, so it permits nothing. What to do: correct the id if it is misspelt; otherwise ${remove}`;
|
|
94
|
+
case "forbidden":
|
|
95
|
+
return `${what} under \`${f.licence}\`, which does not permit ${it}: ${f.refusal.why}. What to do: ${remove}`;
|
|
96
|
+
case "non-commercial-only":
|
|
97
|
+
return `${what} under \`${f.licence}\`, which permits ${it} only in a non-commercial project, and this one has not declared itself one. What to do: if it is one, set \`"corpus/licence": ["warn", { "nonCommercial": true }]\` in the root \`paperlint.json\`; otherwise ${remove}`;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
@@ -37,7 +37,7 @@ const folder = (
|
|
|
37
37
|
record: CorpusFolder["record"],
|
|
38
38
|
pdf: readonly string[] = [],
|
|
39
39
|
text: readonly string[] = [],
|
|
40
|
-
): CorpusFolder => ({ record, stored: { pdf, text } });
|
|
40
|
+
): CorpusFolder => ({ folder: "agent", record, stored: { pdf, text } });
|
|
41
41
|
|
|
42
42
|
const read = (papers: readonly Paper[]): CorpusFolder["record"] => ({
|
|
43
43
|
ok: true,
|
|
@@ -61,6 +61,12 @@ describe("storedKey: the paper a stored file's name belongs to", () => {
|
|
|
61
61
|
});
|
|
62
62
|
|
|
63
63
|
describe("judgeCorpus", () => {
|
|
64
|
+
it("names a record whose venue is not its folder's name, at the venue field", () => {
|
|
65
|
+
expect(judgeCorpus({ ...folder(read([])), folder: "other" })).toEqual([
|
|
66
|
+
{ kind: "venue", at: ["venue"], venue: "agent", folder: "other" },
|
|
67
|
+
]);
|
|
68
|
+
});
|
|
69
|
+
|
|
64
70
|
it("is silent when every stored file is claimed by exactly one copy and exists", () => {
|
|
65
71
|
expect(
|
|
66
72
|
judgeCorpus(
|