paperlint 20.6.0 → 20.6.2
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/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/default-levels.d.ts +5 -0
- package/dist/default-levels.d.ts.map +1 -0
- package/dist/default-levels.js +36 -0
- package/dist/default-levels.js.map +1 -0
- package/dist/folder-venue-rule.d.ts +1 -1
- package/dist/folder-venue-rule.d.ts.map +1 -1
- package/dist/folder-venue-rule.js.map +1 -1
- package/dist/tex-venue-rules.d.ts +4 -24
- package/dist/tex-venue-rules.d.ts.map +1 -1
- package/dist/tex-venue-rules.js +6 -84
- package/dist/tex-venue-rules.js.map +1 -1
- package/dist/venue-leftover.d.ts +50 -0
- package/dist/venue-leftover.d.ts.map +1 -0
- package/dist/venue-leftover.js +129 -0
- package/dist/venue-leftover.js.map +1 -0
- package/docs/rules/corpus/allowed-files-only.md +9 -8
- package/docs/rules/tex/venue-leftover.md +34 -3
- package/docs/rules.md +2 -2
- package/package.json +2 -1
- package/scripts/eslint-file-length.mjs +2 -2
- package/scripts/release-config.test.ts +114 -0
- package/scripts/release-type.test.ts +86 -0
- package/scripts/release-type.ts +76 -0
- package/scripts/semantic-release-plugins.d.ts +20 -1
- package/src/corpus-layout-rule.test.ts +3 -1
- package/src/corpus-layout-rule.ts +7 -3
- package/src/default-levels.test.ts +43 -0
- package/src/default-levels.ts +53 -0
- package/src/folder-venue-rule.ts +2 -1
- package/src/rule-cases.test.ts +10 -3
- package/src/tex-venue-rules.test.ts +63 -129
- package/src/tex-venue-rules.ts +25 -146
- package/src/venue-leftover.test.ts +112 -0
- package/src/venue-leftover.ts +207 -0
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `tex/venue-leftover`'s judge: where the rendered text names another shipped venue than the
|
|
3
|
+
* paper's edition. Pure; the rule module (`tex-venue-rules.ts`) reads the paper and the presets and
|
|
4
|
+
* hands them here.
|
|
5
|
+
*
|
|
6
|
+
* Where it reads (#552): the commands that state the paper's venue (`\acmConference` …) wherever
|
|
7
|
+
* they stand, and of the other prose what the rule's `body` option says. A leftover from an earlier
|
|
8
|
+
* submission sits in the front matter — the author block, the title-page footnotes, the abstract —
|
|
9
|
+
* so that is read always; the body, where related work names venues and recent years on every page,
|
|
10
|
+
* only when `body` is set. The front matter ends where the first `\section` begins; a paper with no
|
|
11
|
+
* section is all front matter.
|
|
12
|
+
*/
|
|
13
|
+
import { z } from "zod";
|
|
14
|
+
import { runText, spanIn, } from "./domain/tex-document.js";
|
|
15
|
+
import { editionLabel } from "./domain/edition.js";
|
|
16
|
+
/** Where the front matter ends: at the first section heading, or null when the paper has none. */
|
|
17
|
+
export function frontMatterEnd(outline) {
|
|
18
|
+
const first = outline.sections[0]?.place;
|
|
19
|
+
return first?.kind === "at" ? first.span.start : null;
|
|
20
|
+
}
|
|
21
|
+
/** The rule's options as its `meta.schema` declares them to ESLint. */
|
|
22
|
+
export const LEFTOVER_SCHEMA = [
|
|
23
|
+
{
|
|
24
|
+
type: "object",
|
|
25
|
+
properties: { body: { type: "boolean" } },
|
|
26
|
+
additionalProperties: false,
|
|
27
|
+
},
|
|
28
|
+
];
|
|
29
|
+
/** The same options, parsed: none, or `{ body }`. */
|
|
30
|
+
const LeftoverOptions = z.union([
|
|
31
|
+
z.tuple([]),
|
|
32
|
+
z.tuple([z.object({ body: z.boolean().optional() }).strict()]),
|
|
33
|
+
]);
|
|
34
|
+
/**
|
|
35
|
+
* The places of one paper: `lines` are its venue-stating commands; prose is read in the front
|
|
36
|
+
* matter, or anywhere when `body` is set. A name with no place is read only when everything is.
|
|
37
|
+
*/
|
|
38
|
+
export function leftoverPlaces(lines, outline, options) {
|
|
39
|
+
const body = LeftoverOptions.parse(options)[0]?.body ?? false;
|
|
40
|
+
const end = frontMatterEnd(outline);
|
|
41
|
+
return {
|
|
42
|
+
inLine: (at) => at !== null &&
|
|
43
|
+
lines.some((l) => l.kind === "at" && l.span.start <= at.start && at.start < l.span.end),
|
|
44
|
+
read: (at) => body || end === null || (at !== null && at.start < end),
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* A year beside a name, right after it: `2027`, `'27` or `’27`, after spaces or none (`~` renders
|
|
49
|
+
* as a no-break space). Anchored: it is tried on the text after the name.
|
|
50
|
+
*/
|
|
51
|
+
const YEAR_AFTER = /^[\s\u00a0]*(?:(\d{4})|['’](\d{2}))(?![\p{L}\p{N}])/u;
|
|
52
|
+
/** The year written right after offset `end` of `text`, or null. `'27` is 2027. Pure. */
|
|
53
|
+
function yearAfter(text, end) {
|
|
54
|
+
const m = YEAR_AFTER.exec(text.slice(end));
|
|
55
|
+
if (m === null)
|
|
56
|
+
return null;
|
|
57
|
+
return m[1] !== undefined
|
|
58
|
+
? Number.parseInt(m[1], 10)
|
|
59
|
+
: 2000 + Number.parseInt(String(m[2]), 10);
|
|
60
|
+
}
|
|
61
|
+
/** `s` as a pattern that matches it literally. */
|
|
62
|
+
const literal = (s) => s.replace(/[.*+?^${}()|[\]\\]/gu, "\\$&");
|
|
63
|
+
/**
|
|
64
|
+
* Every name to look for, once each: every other shipped venue's, shown as that venue's `name`, and
|
|
65
|
+
* the paper's own and its parent's, which count only in another edition. Pure.
|
|
66
|
+
*/
|
|
67
|
+
function namesToJudge(preset, others) {
|
|
68
|
+
const own = new Set([...preset.aliases, ...preset.parentNames]);
|
|
69
|
+
const shownBy = (name) => others.find((o) => o.aliases.includes(name))?.label ??
|
|
70
|
+
(preset.aliases.includes(name) ? preset.label : name);
|
|
71
|
+
const all = [...new Set([...others.flatMap((o) => o.aliases), ...own])];
|
|
72
|
+
return all.map((name) => ({
|
|
73
|
+
name,
|
|
74
|
+
own: own.has(name),
|
|
75
|
+
shows: shownBy(name),
|
|
76
|
+
}));
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Whether a name at a place, with `year` beside it (null: none), names another venue than the
|
|
80
|
+
* paper's edition (of year `paperYear`). Inside a venue-identity command (`inLine`) any other
|
|
81
|
+
* venue's name counts; in prose only beside a year no older than the paper's year minus one, so
|
|
82
|
+
* related work («ICSE 2019») and a bare acronym are not leftovers. The paper's own names, and its
|
|
83
|
+
* parent's, count only beside another year: another edition of its own series. Pure.
|
|
84
|
+
*/
|
|
85
|
+
export function namesAnotherEdition(n, year, paperYear) {
|
|
86
|
+
const recent = paperYear === null || (year !== null && year >= paperYear - 1);
|
|
87
|
+
if (n.own)
|
|
88
|
+
return (year !== null &&
|
|
89
|
+
paperYear !== null &&
|
|
90
|
+
year !== paperYear &&
|
|
91
|
+
(n.inLine || recent));
|
|
92
|
+
return n.inLine || (year !== null && recent);
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* The findings of one name in one run: each whole-word match judged with the year beside it and
|
|
96
|
+
* whether it stands in a venue-stating command (`inLine`). Pure.
|
|
97
|
+
*/
|
|
98
|
+
function matchesIn(run, n, paper) {
|
|
99
|
+
const { inLine, read, venue } = paper;
|
|
100
|
+
const text = runText(run);
|
|
101
|
+
return [...text.matchAll(n.re)].flatMap((m) => {
|
|
102
|
+
const at = spanIn(run, m.index, m.index + m[0].length);
|
|
103
|
+
const year = yearAfter(text, m.index + m[0].length);
|
|
104
|
+
const judged = { own: n.own, inLine: inLine(at) };
|
|
105
|
+
if (!judged.inLine && !read(at))
|
|
106
|
+
return [];
|
|
107
|
+
if (!namesAnotherEdition(judged, year, paper.year))
|
|
108
|
+
return [];
|
|
109
|
+
const other = editionLabel(n.shows, year);
|
|
110
|
+
return [{ messageId: "leftover", data: { name: m[0], other, venue }, at }];
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Each place the rendered text names another venue than the paper's edition — a name as a whole
|
|
115
|
+
* word, case and all, judged with the year beside it (`namesAnotherEdition`), in the `places` the
|
|
116
|
+
* rule reads (`leftoverPlaces`). A family preset names no venue, so nothing is another venue:
|
|
117
|
+
* silent.
|
|
118
|
+
*/
|
|
119
|
+
export function judgeLeftover(runs, preset, others, places) {
|
|
120
|
+
if (preset.identity.type !== "venue")
|
|
121
|
+
return [];
|
|
122
|
+
const venue = editionLabel(preset.label, preset.year);
|
|
123
|
+
const names = namesToJudge(preset, others).map((n) => ({
|
|
124
|
+
...n,
|
|
125
|
+
re: new RegExp(`(?<![\\p{L}\\p{N}])${literal(n.name)}(?![\\p{L}\\p{N}])`, "gu"),
|
|
126
|
+
}));
|
|
127
|
+
return runs.flatMap((run) => names.flatMap((n) => matchesIn(run, n, { ...places, year: preset.year, venue })));
|
|
128
|
+
}
|
|
129
|
+
//# sourceMappingURL=venue-leftover.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"venue-leftover.js","sourceRoot":"","sources":["../src/venue-leftover.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EACL,OAAO,EACP,MAAM,GAKP,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAKnD,kGAAkG;AAClG,MAAM,UAAU,cAAc,CAAC,OAAgB;IAC7C,MAAM,KAAK,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC;IACzC,OAAO,KAAK,EAAE,IAAI,KAAK,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC;AACxD,CAAC;AAED,uEAAuE;AACvE,MAAM,CAAC,MAAM,eAAe,GAAG;IAC7B;QACE,IAAI,EAAE,QAAQ;QACd,UAAU,EAAE,EAAE,IAAI,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,EAAE;QACzC,oBAAo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I,EAAE,MAAM,CAAC,IAAI,EAAE,KAAK,EAAE,CAAC,CAC3D,CACF,CAAC;AACJ,CAAC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# corpus/allowed-files-only
|
|
2
2
|
|
|
3
|
-
**Level:**
|
|
3
|
+
**Level:** warn, on by default · **Reads:** the listing of each venue corpus's top · **Reported
|
|
4
4
|
on:** the corpus's `papers.json`, first line, once per stray entry; the project's root
|
|
5
5
|
`paperlint.json`, first line, once per corpus that stores copies without `papers.json`
|
|
6
6
|
|
|
@@ -51,7 +51,8 @@ name, a page saved beside it, or notes on one paper at the top are files nobody
|
|
|
51
51
|
of. A corpus that stores copies with no record is one where nobody can say what each file is a copy
|
|
52
52
|
of, or whether its licence lets the project keep it, and [`corpus/record`](record.md) has no file to
|
|
53
53
|
read. It is on by default because this holds for every corpus whatever the venue; it is silent in a
|
|
54
|
-
project with no `venues/`.
|
|
54
|
+
project with no `venues/`. It warns rather than fails: a corpus folder made before `papers.json`
|
|
55
|
+
existed is a migration to do, not a broken build.
|
|
55
56
|
|
|
56
57
|
## Examples
|
|
57
58
|
|
|
@@ -59,14 +60,14 @@ Failing: a note at the top of a corpus, and PDFs kept with no record.
|
|
|
59
60
|
|
|
60
61
|
```text
|
|
61
62
|
papers/venues/agent/papers.json
|
|
62
|
-
1:1
|
|
63
|
-
|
|
64
|
-
|
|
63
|
+
1:1 warning `venues/agent/notes.md` is not one of the names a venue corpus holds. Where it goes:
|
|
64
|
+
MANIFEST.md when it is a caveat about the whole corpus; deep-reads/<key>.md when it is
|
|
65
|
+
about one paper. corpus/allowed-files-only
|
|
65
66
|
|
|
66
67
|
paperlint.json
|
|
67
|
-
1:1
|
|
68
|
-
|
|
69
|
-
|
|
68
|
+
1:1 warning `papers/venues/other/` stores copies in pdf/ or text/ and has no papers.json, so nothing
|
|
69
|
+
records which paper each file is a copy of, or under which licence it is kept.
|
|
70
|
+
corpus/allowed-files-only
|
|
70
71
|
```
|
|
71
72
|
|
|
72
73
|
Passing: the seven names, the optional ones left out or not.
|
|
@@ -12,6 +12,25 @@ It only knows the venues paperlint ships a preset for, by each preset's `name` a
|
|
|
12
12
|
year of each edition, which is the preset's id (`icse-2028` is ICSE 2028). A venue with no preset is
|
|
13
13
|
not recognized.
|
|
14
14
|
|
|
15
|
+
It runs only when the paper extends a venue preset. A template family (`paperlint:acm-sigconf`,
|
|
16
|
+
`paperlint:ieee-conference`) names no venue, so no venue is "another" one, and the rule is silent.
|
|
17
|
+
|
|
18
|
+
## Where it looks
|
|
19
|
+
|
|
20
|
+
| part of the paper | read |
|
|
21
|
+
| ---------------------------------------------------------------- | ---------------------------- |
|
|
22
|
+
| a venue-stating command (`\acmConference` …), wherever it stands | always |
|
|
23
|
+
| the front matter: everything before the first `\section` | always |
|
|
24
|
+
| the body: from the first `\section` on | only with `{ "body": true }` |
|
|
25
|
+
| a paper with no `\section` | all of it, as front matter |
|
|
26
|
+
|
|
27
|
+
The body is off by default because related work names venues with recent years on every page:
|
|
28
|
+
«Lam et al. (CodeCrash, NeurIPS 2025)», «A separate ASE 2026 study examines …». On the 206 papers of
|
|
29
|
+
the real-paper corpus, every one of the 18 findings the rule gave in the body or under a family preset
|
|
30
|
+
was such a citation or the paper's own venue line; with this scope it gives none. A leftover from an
|
|
31
|
+
earlier submission sits in the author block, the venue line, a footnote on the title page or the
|
|
32
|
+
abstract, which the default still reads.
|
|
33
|
+
|
|
15
34
|
## When a name counts
|
|
16
35
|
|
|
17
36
|
A venue preset is one edition, and its year has one source: the id. A name never carries a year
|
|
@@ -31,7 +50,7 @@ year: any year beside another venue's name counts, and its own names never do.
|
|
|
31
50
|
ACL's template has no venue-stating command; IEEEtran states the venue, when at all, in the
|
|
32
51
|
`\IEEEpubid` copyright line.
|
|
33
52
|
|
|
34
|
-
It reads
|
|
53
|
+
It reads `paper.tex` with the files it `\input`s, `\include`s or `\subfile`s
|
|
35
54
|
spliced in; a name found in an included file is reported at that include, with the file and line at
|
|
36
55
|
the front of the message. It looks at what a reader sees — prose, the author block, captions,
|
|
37
56
|
footnotes, a citation's note in square brackets, and the venue-stating commands — and ignores
|
|
@@ -59,7 +78,11 @@ the definition, whether or not the macro is used: the rule does not expand macro
|
|
|
59
78
|
and the exit code stays 0
|
|
60
79
|
```
|
|
61
80
|
|
|
62
|
-
What the machine cannot see: a venue without a shipped preset; a
|
|
81
|
+
What the machine cannot see: a venue without a shipped preset; a leftover in the body, unless
|
|
82
|
+
`body` is on; an abstract set as `\section*{Abstract}` (the front matter ends at the first section,
|
|
83
|
+
starred or not, so such an abstract is body); a `\section` token that is no heading
|
|
84
|
+
(`\titlespacing*{\section}`, `\let\oldsection\section`) standing before the abstract, which ends the
|
|
85
|
+
front matter early; a year written apart from the name
|
|
63
86
|
(«MSR, in 2027»); a name split by markup (`\textbf{AI}Sec`); a venue named in a sentence on purpose,
|
|
64
87
|
which only a disable directive tells apart.
|
|
65
88
|
|
|
@@ -95,7 +118,13 @@ edition.
|
|
|
95
118
|
|
|
96
119
|
## Preset fields
|
|
97
120
|
|
|
98
|
-
|
|
121
|
+
One rule option, `body` (default `false`): also read the body, from the first `\section` on.
|
|
122
|
+
|
|
123
|
+
```jsonc
|
|
124
|
+
"rules": { "tex/venue-leftover": ["warn", { "body": true }] }
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
It reads every shipped preset's `name` and `aliases`, collected along `extends`,
|
|
99
128
|
and the year of its id:
|
|
100
129
|
|
|
101
130
|
```jsonc
|
|
@@ -121,6 +150,8 @@ venue preset, a parent of another year, or parents that name each other, are ref
|
|
|
121
150
|
## What it does not check
|
|
122
151
|
|
|
123
152
|
- A venue no shipped preset describes.
|
|
153
|
+
- A paper that extends a template family rather than a venue.
|
|
154
|
+
- The body, from the first `\section` on, unless `body` is on.
|
|
124
155
|
- A name split by markup (`\textbf{AI}Sec`).
|
|
125
156
|
- A name in prose with no year beside it («submitted to MSR»): the rule cannot tell it from an
|
|
126
157
|
acronym or a mention of the series.
|
package/docs/rules.md
CHANGED
|
@@ -9,7 +9,7 @@ reads and when it fails. Errors fail `paperlint lint`; warnings print and do not
|
|
|
9
9
|
| `paper/source` | error | `PIPELINE-STATUS.md` | a declared stage has no frozen `.tex` beside its PDF (a commit hash does not count — squash and gc destroy it). Silent in a paper that keeps `cycles`: there [`versions/layout`](rules/versions/layout.md) holds each PDF to its source |
|
|
10
10
|
| [`study/declare-sample`](rules/study/declare-sample.md) | experimental; off unless a paper turns it on (`"error"`) | each study's `repro/<study>/prereg.json` | a study's pre-registration does not declare its `population` (what the claim is about, source, size), the `strata` and what each of its `screens` removed per stratum value, its `coverage` (share 0–1 or null with a reason, and the strata it cannot reach), or the `author_check` of the drawn units (a doubtful verdict needs a recorded `decision`); reported on `PIPELINE-STATUS.md`, once per problem — [page](rules/study/declare-sample.md) |
|
|
11
11
|
| [`cycle/record`](rules/cycle/record.md) | error | `paperlint.json` (`cycles`) | the paper's attempts at venues (`cycles`, one entry per attempt) hold one source's deadlines out of order (registration ≤ submission ≤ resubmission < notification < camera-ready), or copy a portal reading the venue's preset carries; reported on `PIPELINE-STATUS.md`. A record that does not parse — a bare date, two open cycles, an unknown key — is refused by `paperlint lint` itself before any rule runs, exit 2 — [page](rules/cycle/record.md) |
|
|
12
|
-
| [`corpus/allowed-files-only`](rules/corpus/allowed-files-only.md) |
|
|
12
|
+
| [`corpus/allowed-files-only`](rules/corpus/allowed-files-only.md) | warn | the listing of each venue corpus's top | a name at the top of a corpus outside `papers.json`, `MANIFEST.md`, `measurements.json`, `pdf/`, `text/`, `deep-reads/`, `sources/`, reported on its `papers.json`; a corpus with `pdf/` or `text/` and no `papers.json`, and a file loose in `venues/`, reported on the root `paperlint.json`. Off with `"corpus/allowed-files-only": "off"` in the root `paperlint.json` — [page](rules/corpus/allowed-files-only.md) |
|
|
13
13
|
| [`corpus/record`](rules/corpus/record.md) | error | a venue corpus's `papers.json` → its `pdf/` and `text/` listing | a field of `papers.json` breaks the record's schema, its `venue` is not its folder's name, a stored file is claimed by no copy, a claimed file is missing, or two copies of a paper store one kind; reported in `papers.json` at the field. Off with `"corpus/record": "off"` in the root `paperlint.json` — [page](rules/corpus/record.md) |
|
|
14
14
|
| [`corpus/licence`](rules/corpus/licence.md) | off, in no set; `"warn"` turns it on | a venue corpus's `papers.json` → the licence table | a stored copy whose licence was not read, is not in the table, forbids that kind, or is non-commercial in a project not declared so (`["warn", { "nonCommercial": true }]`); reported at the copy's `stored`. Opt-in: the same files are legal in a private repository and illegal in a public one — [page](rules/corpus/licence.md) |
|
|
15
15
|
| [`cycle/evidence`](rules/cycle/evidence.md) | error | `paperlint.json` (`cycles`) → the paper folder | a closed cycle (`accepted`, `rejected`, `withdrawn`) or a deadline's `override` names an `evidence` file — the decision mail, the reviews, the withdrawal note, the chairs' mail — that is not in the paper folder; reported on `PIPELINE-STATUS.md` — [page](rules/cycle/evidence.md) |
|
|
@@ -48,7 +48,7 @@ reads and when it fails. Errors fail `paperlint lint`; warnings print and do not
|
|
|
48
48
|
| [`tex/heading-case`](rules/tex/heading-case.md) | optional; the AgenticDev preset sets `error` | `paper.tex` and the files it includes | a word in the paper's `\title` or in a `\section`, `\subsection`, `\subsubsection`, `\paragraph` or `\subparagraph` title is not in the style its scope asks: `{ "title", "headings", "levels"? }`, each `chicago-headline` (Conference Publishing's quote of the Chicago Manual of Style), `sentence` (first word only) or `any`. Words that are a preposition in one title and a particle in another (`up`, `on`, `in`) are not read mid-title. **Fixable:** `--fix` — [page](rules/tex/heading-case.md) |
|
|
49
49
|
| [`format/layout-override`](rules/format/layout-override.md) | error | `paper.tex` → `paperlint.json` | the source changes the page layout the venue's template sets for the whole document — `geometry`, a layout `\setlength`, `\linespread`, `\baselinestretch` — [page](rules/format/layout-override.md) |
|
|
50
50
|
| [`anonymity/identity`](rules/anonymity/identity.md) | error | `paper.tex` → `_build/paper.facts.json` | a double-blind venue (`"blind": true`) and no `identity` declared, or a declared name, handle, email or project in the PDF's text, metadata or link targets — [page](rules/anonymity/identity.md) |
|
|
51
|
-
| [`tex/venue-leftover`](rules/tex/venue-leftover.md) | warn | `paper.tex` → `paperlint.json` | the text names another shipped venue than the edition the paper extends («Submission to VenueA 2026» in a paper now set for VenueB 2027): in prose beside a year no older than the paper's own minus one, in a venue-stating command (`\acmConference` …) always — [page](rules/tex/venue-leftover.md)
|
|
51
|
+
| [`tex/venue-leftover`](rules/tex/venue-leftover.md) | warn | `paper.tex` → `paperlint.json` | the text names another shipped venue than the edition the paper extends («Submission to VenueA 2026» in a paper now set for VenueB 2027): in prose beside a year no older than the paper's own minus one, in a venue-stating command (`\acmConference` …) always; reads the front matter (the body with `body: true`), silent under a template family — [page](rules/tex/venue-leftover.md) |
|
|
52
52
|
| [`tex/claim-provenance`](rules/tex/claim-provenance.md) | opt-in: `paperlint:writing` | `paper.tex` | a sentence of the body states a number and does not say whose it is — no citation or link, no _we_/_our_, no `\ref` or "Table 2", no sample ("n = 134", "48 runs") — [page](rules/tex/claim-provenance.md) |
|
|
53
53
|
| [`tex/register`](rules/tex/register.md) | opt-in: `paperlint:writing` | `paper.tex` and the files it includes | the body runs to a post's register: more than 0.8 sentences per 1000 words open with _And_, _So_, _But_, _Nor_, _Or_ or _Yet_ — the limit is an option — [page](rules/tex/register.md) |
|
|
54
54
|
| [`tex/contrast-frames`](rules/tex/contrast-frames.md) | opt-in: `paperlint:writing` | `paper.tex` and the files it includes → `paperlint.json` | contrast frames (_X, not Y_, _not X but Y_, _rather than_, _instead of_, _as opposed to_) per 10,000 words fall outside the band the venue preset's anchors set (AIDC: 0–10.4, from five accepted ACSAC papers); above it, each frame is reported too — [page](rules/tex/contrast-frames.md) |
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "paperlint",
|
|
3
|
-
"version": "20.6.
|
|
3
|
+
"version": "20.6.2",
|
|
4
4
|
"description": "A linter for scientific papers written in LaTeX: catches mistakes before you submit to a conference or journal.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -54,6 +54,7 @@
|
|
|
54
54
|
},
|
|
55
55
|
"devDependencies": {
|
|
56
56
|
"@semantic-release/commit-analyzer": "13.0.1",
|
|
57
|
+
"@semantic-release/exec": "7.1.0",
|
|
57
58
|
"@semantic-release/release-notes-generator": "14.1.1",
|
|
58
59
|
"@types/js-yaml": "^4.0.9",
|
|
59
60
|
"@types/markdown-it": "^14.2.0",
|
|
@@ -90,8 +90,8 @@ const legacyCeilings = {
|
|
|
90
90
|
"src/talk-rules.test.ts": 427,
|
|
91
91
|
"src/talk-rules.ts": 562,
|
|
92
92
|
"src/tex-requirements.ts": 482,
|
|
93
|
-
"src/tex-venue-rules.test.ts":
|
|
94
|
-
"src/tex-venue-rules.ts":
|
|
93
|
+
"src/tex-venue-rules.test.ts": 2090,
|
|
94
|
+
"src/tex-venue-rules.ts": 615,
|
|
95
95
|
"src/toolchain-mirror.test.mjs": 631,
|
|
96
96
|
"src/toolchain.ts": 605,
|
|
97
97
|
"src/venue-rules.test.ts": 1684,
|
|
@@ -13,7 +13,14 @@
|
|
|
13
13
|
*/
|
|
14
14
|
import { describe, expect, test } from "vitest";
|
|
15
15
|
import { readFileSync } from "node:fs";
|
|
16
|
+
import { execFileSync } from "node:child_process";
|
|
17
|
+
import { mkdtempSync, realpathSync } from "node:fs";
|
|
18
|
+
import { tmpdir } from "node:os";
|
|
19
|
+
import { join, resolve } from "node:path";
|
|
20
|
+
import { PassThrough } from "node:stream";
|
|
16
21
|
import { analyzeCommits } from "@semantic-release/commit-analyzer";
|
|
22
|
+
import { analyzeCommits as runAnalyzeCmd } from "@semantic-release/exec";
|
|
23
|
+
import steps from "semantic-release/lib/definitions/plugins.js";
|
|
17
24
|
import { generateNotes } from "@semantic-release/release-notes-generator";
|
|
18
25
|
import { z } from "zod";
|
|
19
26
|
|
|
@@ -96,3 +103,110 @@ describe("release config (.releaserc.json) with the installed toolchain", () =>
|
|
|
96
103
|
expect(notes).toContain("resolve the paper from the config root");
|
|
97
104
|
});
|
|
98
105
|
});
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* A commit whose tree holds only `default-rules.json` with `snapshot` in it, written to a throwaway
|
|
109
|
+
* object directory that reads this repository's objects but never writes to them. The returned `env`
|
|
110
|
+
* makes git see the commit.
|
|
111
|
+
*/
|
|
112
|
+
function releaseWithSnapshot(snapshot: string): {
|
|
113
|
+
readonly sha: string;
|
|
114
|
+
readonly env: NodeJS.ProcessEnv;
|
|
115
|
+
} {
|
|
116
|
+
const repo = resolve(import.meta.dirname, "..");
|
|
117
|
+
const shared = resolve(
|
|
118
|
+
repo,
|
|
119
|
+
execFileSync("git", ["rev-parse", "--git-common-dir"], {
|
|
120
|
+
cwd: repo,
|
|
121
|
+
encoding: "utf8",
|
|
122
|
+
}).trim(),
|
|
123
|
+
"objects",
|
|
124
|
+
);
|
|
125
|
+
const env = {
|
|
126
|
+
...process.env,
|
|
127
|
+
GIT_OBJECT_DIRECTORY: realpathSync(
|
|
128
|
+
mkdtempSync(join(tmpdir(), "release-objects-")),
|
|
129
|
+
),
|
|
130
|
+
GIT_ALTERNATE_OBJECT_DIRECTORIES: shared,
|
|
131
|
+
};
|
|
132
|
+
const git = (args: readonly string[], input?: string): string =>
|
|
133
|
+
execFileSync("git", args, {
|
|
134
|
+
cwd: repo,
|
|
135
|
+
env,
|
|
136
|
+
input,
|
|
137
|
+
encoding: "utf8",
|
|
138
|
+
}).trim();
|
|
139
|
+
const blob = git(["hash-object", "-w", "--stdin"], snapshot);
|
|
140
|
+
const tree = git(["mktree"], `100644 blob ${blob}\tdefault-rules.json\n`);
|
|
141
|
+
const sha = git([
|
|
142
|
+
"-c",
|
|
143
|
+
"user.name=t",
|
|
144
|
+
"-c",
|
|
145
|
+
"user.email=t@example.com",
|
|
146
|
+
"commit-tree",
|
|
147
|
+
tree,
|
|
148
|
+
"-m",
|
|
149
|
+
"v1",
|
|
150
|
+
]);
|
|
151
|
+
return { sha, env };
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
describe("the default rule set's analyzer (@semantic-release/exec)", () => {
|
|
155
|
+
const run = (gitTag: string, env: NodeJS.ProcessEnv) =>
|
|
156
|
+
runAnalyzeCmd(optionsFor("@semantic-release/exec"), {
|
|
157
|
+
...context,
|
|
158
|
+
cwd: resolve(import.meta.dirname, ".."),
|
|
159
|
+
env,
|
|
160
|
+
stdout: new PassThrough(),
|
|
161
|
+
stderr: new PassThrough(),
|
|
162
|
+
lastRelease: { gitTag, version: "1.0.0" },
|
|
163
|
+
commits: [feature],
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
test("runs beside the commit analyzer, so semantic-release keeps the higher of the two", () => {
|
|
167
|
+
// Guards: an analyzer placed in no step, or removed, would let a breaking default set out as a minor.
|
|
168
|
+
const names = releaserc.plugins.map((p) => (Array.isArray(p) ? p[0] : p));
|
|
169
|
+
expect(names.slice(0, 2)).toEqual([
|
|
170
|
+
"@semantic-release/commit-analyzer",
|
|
171
|
+
"@semantic-release/exec",
|
|
172
|
+
]);
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
test("semantic-release keeps the highest type the analyzers return", () => {
|
|
176
|
+
// Guards: the whole mechanism rests on this merge; a semantic-release that took the first answer
|
|
177
|
+
// instead would release a breaking default set as whatever the PR title says.
|
|
178
|
+
const merge = steps.analyzeCommits.postprocess;
|
|
179
|
+
expect(merge(["minor", "major"])).toBe("major");
|
|
180
|
+
expect(merge([null, "major"])).toBe("major");
|
|
181
|
+
expect(merge(["minor", undefined])).toBe("minor");
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
test("says major when a rule the last release had at warn is at error now", async () => {
|
|
185
|
+
// Guards: the command semantic-release renders from .releaserc.json reaches the script and its
|
|
186
|
+
// answer comes back, end to end through the installed plugin.
|
|
187
|
+
const now = z
|
|
188
|
+
.record(z.string(), z.string())
|
|
189
|
+
.parse(
|
|
190
|
+
JSON.parse(
|
|
191
|
+
readFileSync(
|
|
192
|
+
new URL("../default-rules.json", import.meta.url),
|
|
193
|
+
"utf8",
|
|
194
|
+
),
|
|
195
|
+
),
|
|
196
|
+
);
|
|
197
|
+
const anError = Object.keys(now).find((id) => now[id] === "error");
|
|
198
|
+
expect(anError).toBeDefined();
|
|
199
|
+
const release = releaseWithSnapshot(
|
|
200
|
+
JSON.stringify({ ...now, [String(anError)]: "warn" }),
|
|
201
|
+
);
|
|
202
|
+
expect(await run(release.sha, release.env)).toBe("major");
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
test("says nothing when the last release had the same set, and on a first release", async () => {
|
|
206
|
+
const same = releaseWithSnapshot(
|
|
207
|
+
readFileSync(new URL("../default-rules.json", import.meta.url), "utf8"),
|
|
208
|
+
);
|
|
209
|
+
expect(await run(same.sha, same.env)).toBeUndefined();
|
|
210
|
+
expect(await run("", process.env)).toBeUndefined();
|
|
211
|
+
});
|
|
212
|
+
});
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The release type the default rule set asks for (`scripts/release-type.ts`), which `.releaserc.json`
|
|
3
|
+
* runs through `@semantic-release/exec` beside the commit analyzer: semantic-release takes the
|
|
4
|
+
* higher of the two, so a pull request titled `feat:` or `chore:` that makes a default rule fail a
|
|
5
|
+
* build still releases a major version.
|
|
6
|
+
*/
|
|
7
|
+
import { execFileSync } from "node:child_process";
|
|
8
|
+
import { mkdtempSync, realpathSync, writeFileSync } from "node:fs";
|
|
9
|
+
import { tmpdir } from "node:os";
|
|
10
|
+
import { join } from "node:path";
|
|
11
|
+
import { describe, expect, it } from "vitest";
|
|
12
|
+
import { breakingRules, breakingSince } from "./release-type.ts";
|
|
13
|
+
|
|
14
|
+
describe("breakingRules", () => {
|
|
15
|
+
it("names a rule that joins the set at error, and one raised from warn to error", () => {
|
|
16
|
+
// Guards: both ways a default rule starts failing a build that passed.
|
|
17
|
+
expect(
|
|
18
|
+
breakingRules(
|
|
19
|
+
{ "a/kept": "error", "a/raised": "warn" },
|
|
20
|
+
{ "a/kept": "error", "a/raised": "error", "a/new": "error" },
|
|
21
|
+
),
|
|
22
|
+
).toEqual(["a/new", "a/raised"]);
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it("names nothing for a rule that joins at warn, is lowered, or leaves the set", () => {
|
|
26
|
+
// Guards: a warning never fails a build (`--max-warnings` defaults to -1), so none of these
|
|
27
|
+
// breaks a consumer.
|
|
28
|
+
expect(
|
|
29
|
+
breakingRules(
|
|
30
|
+
{ "a/lowered": "error", "a/gone": "error" },
|
|
31
|
+
{ "a/lowered": "warn", "a/new": "warn" },
|
|
32
|
+
),
|
|
33
|
+
).toEqual([]);
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
/** A git repository whose tag `v1.0.0` holds `before` as the snapshot, or no snapshot at all. */
|
|
38
|
+
function repoWith(before: string | undefined): string {
|
|
39
|
+
const dir = realpathSync(mkdtempSync(join(tmpdir(), "release-type-")));
|
|
40
|
+
const git = (...args: string[]) =>
|
|
41
|
+
execFileSync("git", args, { cwd: dir, stdio: "pipe" });
|
|
42
|
+
git("init", "-q");
|
|
43
|
+
writeFileSync(
|
|
44
|
+
join(dir, before === undefined ? "README.md" : "default-rules.json"),
|
|
45
|
+
before ?? "no snapshot yet\n",
|
|
46
|
+
);
|
|
47
|
+
git("add", ".");
|
|
48
|
+
git(
|
|
49
|
+
"-c",
|
|
50
|
+
"user.name=t",
|
|
51
|
+
"-c",
|
|
52
|
+
"user.email=t@example.com",
|
|
53
|
+
"commit",
|
|
54
|
+
"-qm",
|
|
55
|
+
"init",
|
|
56
|
+
);
|
|
57
|
+
git("tag", "v1.0.0");
|
|
58
|
+
return dir;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
describe("breakingSince", () => {
|
|
62
|
+
const now = { "a/x": "error" } as const;
|
|
63
|
+
|
|
64
|
+
it("names the rule the tagged snapshot had at warn", () => {
|
|
65
|
+
const repo = repoWith(JSON.stringify({ "a/x": "warn" }));
|
|
66
|
+
expect(breakingSince(repo, "v1.0.0", now)).toEqual(["a/x"]);
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
it("names nothing when the set did not break", () => {
|
|
70
|
+
const repo = repoWith(JSON.stringify({ "a/x": "error" }));
|
|
71
|
+
expect(breakingSince(repo, "v1.0.0", now)).toEqual([]);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it("names nothing for a first release, or a tag from before the snapshot existed", () => {
|
|
75
|
+
// Guards: `${lastRelease.gitTag}` renders empty on a first release, and every tag before this
|
|
76
|
+
// file has no snapshot; neither may stop the release.
|
|
77
|
+
expect(breakingSince(repoWith(undefined), "", now)).toEqual([]);
|
|
78
|
+
expect(breakingSince(repoWith(undefined), "v1.0.0", now)).toEqual([]);
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it("refuses a tagged snapshot that is not a rule set", () => {
|
|
82
|
+
// Guards: a corrupt snapshot fails the release loudly instead of reading as "nothing broke".
|
|
83
|
+
const repo = repoWith(JSON.stringify({ "a/x": "loud" }));
|
|
84
|
+
expect(() => breakingSince(repo, "v1.0.0", now)).toThrow();
|
|
85
|
+
});
|
|
86
|
+
});
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Prints `major` when the default rule set breaks a build that passed at the last release, and
|
|
3
|
+
* nothing otherwise. `.releaserc.json` runs it through `@semantic-release/exec` (`analyzeCommitsCmd`),
|
|
4
|
+
* whose contract is exactly that: a release type on stdout, or no output for "no release from me".
|
|
5
|
+
* semantic-release keeps the highest type any analyzer returns, so the commit analyzer still decides
|
|
6
|
+
* every other release.
|
|
7
|
+
*
|
|
8
|
+
* Breaking means a rule that a project with no configuration now gets at `error` and did not before:
|
|
9
|
+
* one that joins the set at `error`, or one raised from `warn`. A warning never fails a build
|
|
10
|
+
* (`--max-warnings` defaults to -1), so a rule that joins at `warn`, is lowered or leaves is not.
|
|
11
|
+
*
|
|
12
|
+
* The set at each point is `default-rules.json`, which `src/default-levels.test.ts` keeps equal to
|
|
13
|
+
* the real config on every CI run. Usage: `node scripts/release-type.ts <last release tag>`.
|
|
14
|
+
*/
|
|
15
|
+
import { execFileSync } from "node:child_process";
|
|
16
|
+
import { readFileSync } from "node:fs";
|
|
17
|
+
import { dirname, join } from "node:path";
|
|
18
|
+
import { fileURLToPath } from "node:url";
|
|
19
|
+
import { z } from "zod";
|
|
20
|
+
|
|
21
|
+
const SNAPSHOT = "default-rules.json";
|
|
22
|
+
|
|
23
|
+
const RuleSet = z.record(z.string(), z.enum(["warn", "error"]));
|
|
24
|
+
type RuleSet = z.infer<typeof RuleSet>;
|
|
25
|
+
|
|
26
|
+
/** The rules at `error` in `after` that were not at `error` in `before`, sorted. */
|
|
27
|
+
export const breakingRules = (
|
|
28
|
+
before: Readonly<RuleSet>,
|
|
29
|
+
after: Readonly<RuleSet>,
|
|
30
|
+
): readonly string[] =>
|
|
31
|
+
Object.keys(after)
|
|
32
|
+
.filter((id) => after[id] === "error" && before[id] !== "error")
|
|
33
|
+
.sort();
|
|
34
|
+
|
|
35
|
+
/** The snapshot as it was at `tag` in `repo`, or none when the tag predates it. */
|
|
36
|
+
function snapshotAt(repo: string, tag: string): RuleSet | undefined {
|
|
37
|
+
const ls = execFileSync("git", ["ls-tree", "--name-only", tag, SNAPSHOT], {
|
|
38
|
+
cwd: repo,
|
|
39
|
+
encoding: "utf8",
|
|
40
|
+
});
|
|
41
|
+
if (ls.trim() === "") return undefined;
|
|
42
|
+
return RuleSet.parse(
|
|
43
|
+
JSON.parse(
|
|
44
|
+
execFileSync("git", ["show", `${tag}:${SNAPSHOT}`], {
|
|
45
|
+
cwd: repo,
|
|
46
|
+
encoding: "utf8",
|
|
47
|
+
}),
|
|
48
|
+
),
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** The rules that break since `tag` in `repo`; none for no tag, or a tag from before the snapshot. */
|
|
53
|
+
export function breakingSince(
|
|
54
|
+
repo: string,
|
|
55
|
+
tag: string,
|
|
56
|
+
now: Readonly<RuleSet>,
|
|
57
|
+
): readonly string[] {
|
|
58
|
+
const before = tag === "" ? undefined : snapshotAt(repo, tag);
|
|
59
|
+
return before === undefined ? [] : breakingRules(before, now);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
if (process.argv[1] === fileURLToPath(import.meta.url)) {
|
|
63
|
+
const repo = dirname(dirname(fileURLToPath(import.meta.url)));
|
|
64
|
+
const now = RuleSet.parse(
|
|
65
|
+
JSON.parse(readFileSync(join(repo, SNAPSHOT), "utf8")),
|
|
66
|
+
);
|
|
67
|
+
const tag = process.argv[2] ?? "";
|
|
68
|
+
const broken = breakingSince(repo, tag, now);
|
|
69
|
+
if (broken.length > 0) {
|
|
70
|
+
// stderr reaches the release log; stdout carries the release type alone.
|
|
71
|
+
process.stderr.write(
|
|
72
|
+
`now at error by default since ${tag}: ${broken.join(", ")}\n`,
|
|
73
|
+
);
|
|
74
|
+
process.stdout.write("major");
|
|
75
|
+
}
|
|
76
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// The
|
|
1
|
+
// The three semantic-release plugins ship no types. Only what scripts/release-config.test.ts calls
|
|
2
2
|
// is declared: the plugin step functions, taking the plugin's options and semantic-release's
|
|
3
3
|
// context, as their READMEs document them.
|
|
4
4
|
declare module "@semantic-release/commit-analyzer" {
|
|
@@ -14,3 +14,22 @@ declare module "@semantic-release/release-notes-generator" {
|
|
|
14
14
|
context: Record<string, unknown>,
|
|
15
15
|
): Promise<string>;
|
|
16
16
|
}
|
|
17
|
+
|
|
18
|
+
declare module "@semantic-release/exec" {
|
|
19
|
+
export function analyzeCommits(
|
|
20
|
+
pluginConfig: Record<string, unknown>,
|
|
21
|
+
context: Record<string, unknown>,
|
|
22
|
+
): Promise<string | undefined>;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// semantic-release's own step definitions: how it merges what several analyzers return.
|
|
26
|
+
declare module "semantic-release/lib/definitions/plugins.js" {
|
|
27
|
+
const definitions: {
|
|
28
|
+
readonly analyzeCommits: {
|
|
29
|
+
readonly postprocess: (
|
|
30
|
+
results: readonly (string | undefined | null)[],
|
|
31
|
+
) => string | undefined;
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
export default definitions;
|
|
35
|
+
}
|