paperlint 20.5.0 → 20.6.1
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-layout-rule.d.ts +6 -2
- package/dist/corpus-layout-rule.d.ts.map +1 -1
- package/dist/corpus-layout-rule.js +6 -2
- package/dist/corpus-layout-rule.js.map +1 -1
- 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/allowed-files-only.md +9 -8
- package/docs/rules/corpus/licence.md +125 -0
- package/docs/rules/corpus/record.md +6 -3
- package/docs/rules.md +3 -2
- 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-layout-rule.test.ts +3 -1
- package/src/corpus-layout-rule.ts +7 -3
- 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
|
@@ -30,9 +30,23 @@ import {
|
|
|
30
30
|
type StrongAcceptProxy,
|
|
31
31
|
type VenueCorpus,
|
|
32
32
|
} from "../../domain/venue-corpus.ts";
|
|
33
|
+
import { endsInYear, SERIES_ID } from "../../domain/edition.ts";
|
|
33
34
|
import type { VenueCorpusCodec } from "../../ports/venue-corpus-codec.ts";
|
|
34
35
|
|
|
35
36
|
const words = z.string().min(1);
|
|
37
|
+
|
|
38
|
+
// A venue is a series (`agent`, `usenix-sec`), the part of a preset's id before its year, so a
|
|
39
|
+
// corpus is found from any edition of it; an edition's id or a display name here would match none.
|
|
40
|
+
const series = z
|
|
41
|
+
.string()
|
|
42
|
+
.regex(
|
|
43
|
+
SERIES_ID,
|
|
44
|
+
"a venue is a series id: lowercase words and digits joined by hyphens, as in `usenix-sec`",
|
|
45
|
+
)
|
|
46
|
+
.refine(
|
|
47
|
+
(v) => !endsInYear(v),
|
|
48
|
+
"a venue is a series, not one edition: drop the year (`agent`, not `agent-2026`)",
|
|
49
|
+
);
|
|
36
50
|
const date = z.iso.date();
|
|
37
51
|
/** Where a page or a file was read: a web address, never a local path or another scheme. */
|
|
38
52
|
const webUrl = z.url({
|
|
@@ -158,7 +172,7 @@ const paper = z.discriminatedUnion("group", [
|
|
|
158
172
|
z.looseObject({
|
|
159
173
|
...paperFields,
|
|
160
174
|
group: z.literal("sister"),
|
|
161
|
-
venue:
|
|
175
|
+
venue: series,
|
|
162
176
|
year,
|
|
163
177
|
listed_from: webUrl,
|
|
164
178
|
}),
|
|
@@ -211,7 +225,7 @@ const consistent = (
|
|
|
211
225
|
|
|
212
226
|
const record = z
|
|
213
227
|
.strictObject({
|
|
214
|
-
venue:
|
|
228
|
+
venue: series,
|
|
215
229
|
editions: z.array(edition),
|
|
216
230
|
papers: z.array(paper),
|
|
217
231
|
rebuild: z.array(words),
|
package/src/cli.ts
CHANGED
|
@@ -243,10 +243,8 @@ import {
|
|
|
243
243
|
} from "./folder-layout-rule.ts";
|
|
244
244
|
import { folderLayoutHook } from "./folder-layout-hook.ts";
|
|
245
245
|
import { inCorpus, papersDirOf, papersRoots, toPaths } from "./papers-roots.ts";
|
|
246
|
-
import {
|
|
247
|
-
|
|
248
|
-
corpusRecordRules,
|
|
249
|
-
} from "./corpus-record-rule.ts";
|
|
246
|
+
import { CORPUS_RECORD_RULE_LEVELS } from "./corpus-record-rule.ts";
|
|
247
|
+
import { corpusJsonRules, corpusRecords } from "./corpus-json-rules.ts";
|
|
250
248
|
import {
|
|
251
249
|
CORPUS_LAYOUT_RULE_LEVELS,
|
|
252
250
|
corpusLayoutRules,
|
|
@@ -675,7 +673,8 @@ const corpusBlocks = (papers: PaperScope): readonly ConfigBlock[] => {
|
|
|
675
673
|
listDir: nodeListDir,
|
|
676
674
|
roots: papers.kind === "papers" ? papers.roots : [],
|
|
677
675
|
});
|
|
678
|
-
|
|
676
|
+
// `corpus/licence` is registered with them and on for no corpus: `"warn"` in the root paperlint.json turns it on.
|
|
677
|
+
const record = corpusJsonRules({
|
|
679
678
|
entries: nodeListEntries,
|
|
680
679
|
codec: venueCorpusCodec,
|
|
681
680
|
});
|
|
@@ -1045,7 +1044,8 @@ export async function silentOptionalRules(
|
|
|
1045
1044
|
const probes = [
|
|
1046
1045
|
...new Set(files.filter((p) => basename(p) === MAIN)),
|
|
1047
1046
|
].flatMap((f) => [f, join(dirname(f), STATUS_FILE), ...bodyFiles(f)]);
|
|
1048
|
-
|
|
1047
|
+
// A corpus rule is reached through the record it judges, not through a paper.
|
|
1048
|
+
for (const probe of [...probes, ...corpusRecords(files)]) {
|
|
1049
1049
|
// Undefined for a file outside ESLint's cwd or scope: it reaches nothing.
|
|
1050
1050
|
const cfg = ComputedConfig.parse(
|
|
1051
1051
|
await eslint.calculateConfigForFile(probe),
|
|
@@ -2746,11 +2746,13 @@ export async function run(
|
|
|
2746
2746
|
err,
|
|
2747
2747
|
where: relative(cwd, root) || ".",
|
|
2748
2748
|
opts: withPapers,
|
|
2749
|
-
// Every paper of the project, not only the ones on the command line (#103).
|
|
2750
|
-
projectPapers: papersRoots(cfg)
|
|
2751
|
-
.
|
|
2752
|
-
.map((d) =>
|
|
2753
|
-
|
|
2749
|
+
// Every paper and corpus record of the project, not only the ones on the command line (#103).
|
|
2750
|
+
projectPapers: papersRoots(cfg).flatMap((r) => [
|
|
2751
|
+
...papersIn(r, [MAIN]).map((d) => join(d, MAIN)),
|
|
2752
|
+
...papersIn(join(r, CORPORA_DIR), [CORPUS_RECORD]).map((d) =>
|
|
2753
|
+
join(d, CORPUS_RECORD),
|
|
2754
|
+
),
|
|
2755
|
+
]),
|
|
2754
2756
|
bodies,
|
|
2755
2757
|
onLintResults,
|
|
2756
2758
|
});
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/** The rules that judge a venue corpus's `papers.json` (`corpus/record`, `corpus/licence`), as one plugin's rules. */
|
|
2
|
+
import { corpusLicenceRules } from "./corpus-licence-rule.ts";
|
|
3
|
+
import { basename } from "node:path";
|
|
4
|
+
import { CORPUS_RECORD } from "./domain/venue-corpus.ts";
|
|
5
|
+
import {
|
|
6
|
+
corpusRecordRules,
|
|
7
|
+
type CorpusRecordDeps,
|
|
8
|
+
type JsonRuleModule,
|
|
9
|
+
} from "./corpus-record-rule.ts";
|
|
10
|
+
|
|
11
|
+
/** Both rules, reading the corpus through `deps`; which of them is on is the config's, not theirs. */
|
|
12
|
+
export const corpusJsonRules = (
|
|
13
|
+
deps: CorpusRecordDeps,
|
|
14
|
+
): Readonly<Record<"record" | "licence", JsonRuleModule>> => ({
|
|
15
|
+
...corpusRecordRules(deps),
|
|
16
|
+
...corpusLicenceRules(deps),
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
/** The venue corpora's `papers.json` among `files`, each once: the files a corpus rule is reached through. */
|
|
20
|
+
export const corpusRecords = (files: readonly string[]): readonly string[] => [
|
|
21
|
+
...new Set(files.filter((f) => basename(f) === CORPUS_RECORD)),
|
|
22
|
+
];
|
|
@@ -113,8 +113,10 @@ describe("corpus/allowed-files-only: a corpus that stores copies with no papers.
|
|
|
113
113
|
"papers/venues/kept/papers.json": EMPTY.replace("agent", "kept"),
|
|
114
114
|
"papers/venues/kept/pdf/.gitkeep": "",
|
|
115
115
|
});
|
|
116
|
+
// Guards: a corpus folder made before papers.json existed warns and never fails the build (v20.6.0
|
|
117
|
+
// shipped this rule at error in a minor release, which turned such a consumer red).
|
|
116
118
|
expect({ code: r.code, found: r.found }).toEqual({
|
|
117
|
-
code:
|
|
119
|
+
code: 0,
|
|
118
120
|
found: [
|
|
119
121
|
["paperlint.json", 1, "papers/venues/agent/"],
|
|
120
122
|
["paperlint.json", 1, "papers/venues/other/"],
|
|
@@ -139,7 +139,11 @@ export function corpusLayoutRules(
|
|
|
139
139
|
};
|
|
140
140
|
}
|
|
141
141
|
|
|
142
|
-
/**
|
|
142
|
+
/**
|
|
143
|
+
* On by default, on every corpus's `papers.json` and the root `paperlint.json`, at `warn`: a corpus
|
|
144
|
+
* folder made before `papers.json` existed is a migration to do, not a broken build. Raising it to
|
|
145
|
+
* `error` is a major release.
|
|
146
|
+
*/
|
|
143
147
|
export const CORPUS_LAYOUT_RULE_LEVELS: Readonly<
|
|
144
|
-
Record<"corpus/allowed-files-only", "
|
|
145
|
-
> = { "corpus/allowed-files-only": "
|
|
148
|
+
Record<"corpus/allowed-files-only", "warn">
|
|
149
|
+
> = { "corpus/allowed-files-only": "warn" };
|
|
@@ -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
|
+
});
|