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,112 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `tex/venue-leftover`'s judge (`src/venue-leftover.ts`): where it reads — the venue lines wherever
|
|
3
|
+
* they stand, the front matter always, the body only with `body` — and a name the parser gave no
|
|
4
|
+
* place. The rule as ESLint runs it, on whole papers, is in `src/tex-venue-rules.test.ts`.
|
|
5
|
+
*/
|
|
6
|
+
import { describe, expect, it } from "vitest";
|
|
7
|
+
import { latexReader } from "./adapters/latex/index.ts";
|
|
8
|
+
import { memoryFiles } from "./adapters/memory/index.ts";
|
|
9
|
+
import type { Outline } from "./domain/tex-document.ts";
|
|
10
|
+
import { resolvePreset } from "./presets.ts";
|
|
11
|
+
import {
|
|
12
|
+
frontMatterEnd,
|
|
13
|
+
judgeLeftover,
|
|
14
|
+
leftoverPlaces,
|
|
15
|
+
} from "./venue-leftover.ts";
|
|
16
|
+
import { PAPER, shipped, VENUES } from "../test/venue-rules-lint.ts";
|
|
17
|
+
|
|
18
|
+
/** An outline whose first section starts at `at` (null: no section; "unplaced": one with no place). */
|
|
19
|
+
const outline = (at: number | null | "unplaced"): Outline => ({
|
|
20
|
+
sections:
|
|
21
|
+
at === null
|
|
22
|
+
? []
|
|
23
|
+
: [
|
|
24
|
+
{
|
|
25
|
+
title: "Introduction",
|
|
26
|
+
place:
|
|
27
|
+
at === "unplaced"
|
|
28
|
+
? { kind: "unplaced" }
|
|
29
|
+
: { kind: "at", span: { start: at, end: at + 21 } },
|
|
30
|
+
},
|
|
31
|
+
],
|
|
32
|
+
backMatter: null,
|
|
33
|
+
end: null,
|
|
34
|
+
});
|
|
35
|
+
const span = (start: number) => ({ start, end: start + 5 });
|
|
36
|
+
|
|
37
|
+
describe("frontMatterEnd", () => {
|
|
38
|
+
it("is where the first section starts, or null without a placed one", () => {
|
|
39
|
+
expect(
|
|
40
|
+
[outline(100), outline(null), outline("unplaced")].map(frontMatterEnd),
|
|
41
|
+
).toEqual([100, null, null]);
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
describe("leftoverPlaces — which prose is read", () => {
|
|
46
|
+
it("by default the front matter only: before the first section, not after it, not unplaced", () => {
|
|
47
|
+
const { read } = leftoverPlaces([], outline(100), []);
|
|
48
|
+
expect([read(span(10)), read(span(150)), read(null)]).toEqual([
|
|
49
|
+
true,
|
|
50
|
+
false,
|
|
51
|
+
false,
|
|
52
|
+
]);
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it("with `body: true`, everything, a name with no place included", () => {
|
|
56
|
+
const { read } = leftoverPlaces([], outline(100), [{ body: true }]);
|
|
57
|
+
expect([read(span(10)), read(span(150)), read(null)]).toEqual([
|
|
58
|
+
true,
|
|
59
|
+
true,
|
|
60
|
+
true,
|
|
61
|
+
]);
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it("a paper with no section is all front matter", () => {
|
|
65
|
+
const { read } = leftoverPlaces([], outline(null), [{ body: false }]);
|
|
66
|
+
expect([read(span(10)), read(null)]).toEqual([true, true]);
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
it("a venue line holds a name wherever it stands; an unplaced line holds none", () => {
|
|
70
|
+
const { inLine } = leftoverPlaces(
|
|
71
|
+
[{ kind: "at", span: { start: 200, end: 260 } }, { kind: "unplaced" }],
|
|
72
|
+
outline(100),
|
|
73
|
+
[],
|
|
74
|
+
);
|
|
75
|
+
expect([inLine(span(210)), inLine(span(10)), inLine(null)]).toEqual([
|
|
76
|
+
true,
|
|
77
|
+
false,
|
|
78
|
+
false,
|
|
79
|
+
]);
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it("an option the schema does not declare is refused, not ignored", () => {
|
|
83
|
+
expect(() =>
|
|
84
|
+
leftoverPlaces([], outline(null), [{ bodies: true }]),
|
|
85
|
+
).toThrow();
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
describe("judgeLeftover, on places the parser did not give", () => {
|
|
90
|
+
const files = memoryFiles(shipped);
|
|
91
|
+
const aidc = resolvePreset("paperlint:aidc-2026", `${PAPER}/paperlint.json`, {
|
|
92
|
+
files,
|
|
93
|
+
venuesDir: VENUES,
|
|
94
|
+
});
|
|
95
|
+
const preset = aidc.ok ? aidc.value : null;
|
|
96
|
+
|
|
97
|
+
it("a venue line with no place holds no name; a parent's name no shipped venue carries is shown as written", () => {
|
|
98
|
+
expect(preset).not.toBeNull();
|
|
99
|
+
if (preset === null) return;
|
|
100
|
+
const src = "Unlike AISec, and Gone 2025.";
|
|
101
|
+
// The line is unplaced, so «AISec» without a year stands in prose: silent.
|
|
102
|
+
const found = judgeLeftover(
|
|
103
|
+
latexReader.renderedRuns(src),
|
|
104
|
+
{ ...preset, parentNames: ["Gone"] },
|
|
105
|
+
[],
|
|
106
|
+
leftoverPlaces([{ kind: "unplaced" }], latexReader.outline(src), []),
|
|
107
|
+
);
|
|
108
|
+
expect(found.map((f) => f.data)).toEqual([
|
|
109
|
+
{ name: "Gone", other: "Gone 2025", venue: "AIDC 2026" },
|
|
110
|
+
]);
|
|
111
|
+
});
|
|
112
|
+
});
|
|
@@ -0,0 +1,207 @@
|
|
|
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 {
|
|
15
|
+
runText,
|
|
16
|
+
spanIn,
|
|
17
|
+
type Outline,
|
|
18
|
+
type Place,
|
|
19
|
+
type Span,
|
|
20
|
+
type TextRun,
|
|
21
|
+
} from "./domain/tex-document.ts";
|
|
22
|
+
import { editionLabel } from "./domain/edition.ts";
|
|
23
|
+
import type { NamedVenue } from "./domain/venue-name.ts";
|
|
24
|
+
import type { Preset } from "./presets.ts";
|
|
25
|
+
import type { Located } from "./tex-venue-rules.ts";
|
|
26
|
+
|
|
27
|
+
/** Where the front matter ends: at the first section heading, or null when the paper has none. */
|
|
28
|
+
export function frontMatterEnd(outline: Outline): number | null {
|
|
29
|
+
const first = outline.sections[0]?.place;
|
|
30
|
+
return first?.kind === "at" ? first.span.start : null;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** The rule's options as its `meta.schema` declares them to ESLint. */
|
|
34
|
+
export const LEFTOVER_SCHEMA = [
|
|
35
|
+
{
|
|
36
|
+
type: "object",
|
|
37
|
+
properties: { body: { type: "boolean" } },
|
|
38
|
+
additionalProperties: false,
|
|
39
|
+
},
|
|
40
|
+
] as const;
|
|
41
|
+
|
|
42
|
+
/** The same options, parsed: none, or `{ body }`. */
|
|
43
|
+
const LeftoverOptions = z.union([
|
|
44
|
+
z.tuple([]),
|
|
45
|
+
z.tuple([z.object({ body: z.boolean().optional() }).strict()]),
|
|
46
|
+
]);
|
|
47
|
+
|
|
48
|
+
/** Of a name found at `at` (null: the parser gave it no place): is it in a venue line, is it read. */
|
|
49
|
+
export interface LeftoverPlaces {
|
|
50
|
+
readonly inLine: (at: Span | null) => boolean;
|
|
51
|
+
readonly read: (at: Span | null) => boolean;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* The places of one paper: `lines` are its venue-stating commands; prose is read in the front
|
|
56
|
+
* matter, or anywhere when `body` is set. A name with no place is read only when everything is.
|
|
57
|
+
*/
|
|
58
|
+
export function leftoverPlaces(
|
|
59
|
+
lines: readonly Place[],
|
|
60
|
+
outline: Outline,
|
|
61
|
+
options: readonly unknown[],
|
|
62
|
+
): LeftoverPlaces {
|
|
63
|
+
const body = LeftoverOptions.parse(options)[0]?.body ?? false;
|
|
64
|
+
const end = frontMatterEnd(outline);
|
|
65
|
+
return {
|
|
66
|
+
inLine: (at) =>
|
|
67
|
+
at !== null &&
|
|
68
|
+
lines.some(
|
|
69
|
+
(l) =>
|
|
70
|
+
l.kind === "at" && l.span.start <= at.start && at.start < l.span.end,
|
|
71
|
+
),
|
|
72
|
+
read: (at) => body || end === null || (at !== null && at.start < end),
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Another shipped venue as the text names it: the word for it (its `name`), every name it goes by,
|
|
78
|
+
* and its edition's year (from its id).
|
|
79
|
+
*/
|
|
80
|
+
export type OtherVenue = NamedVenue & Pick<Preset, "year" | "declaredAliases">;
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* A year beside a name, right after it: `2027`, `'27` or `’27`, after spaces or none (`~` renders
|
|
84
|
+
* as a no-break space). Anchored: it is tried on the text after the name.
|
|
85
|
+
*/
|
|
86
|
+
const YEAR_AFTER = /^[\s\u00a0]*(?:(\d{4})|['’](\d{2}))(?![\p{L}\p{N}])/u;
|
|
87
|
+
|
|
88
|
+
/** The year written right after offset `end` of `text`, or null. `'27` is 2027. Pure. */
|
|
89
|
+
function yearAfter(text: string, end: number): number | null {
|
|
90
|
+
const m = YEAR_AFTER.exec(text.slice(end));
|
|
91
|
+
if (m === null) return null;
|
|
92
|
+
return m[1] !== undefined
|
|
93
|
+
? Number.parseInt(m[1], 10)
|
|
94
|
+
: 2000 + Number.parseInt(String(m[2]), 10);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/** `s` as a pattern that matches it literally. */
|
|
98
|
+
const literal = (s: string): string =>
|
|
99
|
+
s.replace(/[.*+?^${}()|[\]\\]/gu, "\\$&");
|
|
100
|
+
|
|
101
|
+
/** One name a match is judged by: whether it is the paper's own, and the venue it shows as. */
|
|
102
|
+
interface NameToJudge {
|
|
103
|
+
readonly name: string;
|
|
104
|
+
readonly own: boolean;
|
|
105
|
+
readonly shows: string;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Every name to look for, once each: every other shipped venue's, shown as that venue's `name`, and
|
|
110
|
+
* the paper's own and its parent's, which count only in another edition. Pure.
|
|
111
|
+
*/
|
|
112
|
+
function namesToJudge(
|
|
113
|
+
preset: Pick<Preset, "label" | "aliases" | "parentNames">,
|
|
114
|
+
others: readonly OtherVenue[],
|
|
115
|
+
): readonly NameToJudge[] {
|
|
116
|
+
const own = new Set([...preset.aliases, ...preset.parentNames]);
|
|
117
|
+
const shownBy = (name: string): string =>
|
|
118
|
+
others.find((o) => o.aliases.includes(name))?.label ??
|
|
119
|
+
(preset.aliases.includes(name) ? preset.label : name);
|
|
120
|
+
const all = [...new Set([...others.flatMap((o) => o.aliases), ...own])];
|
|
121
|
+
return all.map((name) => ({
|
|
122
|
+
name,
|
|
123
|
+
own: own.has(name),
|
|
124
|
+
shows: shownBy(name),
|
|
125
|
+
}));
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Whether a name at a place, with `year` beside it (null: none), names another venue than the
|
|
130
|
+
* paper's edition (of year `paperYear`). Inside a venue-identity command (`inLine`) any other
|
|
131
|
+
* venue's name counts; in prose only beside a year no older than the paper's year minus one, so
|
|
132
|
+
* related work («ICSE 2019») and a bare acronym are not leftovers. The paper's own names, and its
|
|
133
|
+
* parent's, count only beside another year: another edition of its own series. Pure.
|
|
134
|
+
*/
|
|
135
|
+
export function namesAnotherEdition(
|
|
136
|
+
n: { readonly own: boolean; readonly inLine: boolean },
|
|
137
|
+
year: number | null,
|
|
138
|
+
paperYear: number | null,
|
|
139
|
+
): boolean {
|
|
140
|
+
const recent = paperYear === null || (year !== null && year >= paperYear - 1);
|
|
141
|
+
if (n.own)
|
|
142
|
+
return (
|
|
143
|
+
year !== null &&
|
|
144
|
+
paperYear !== null &&
|
|
145
|
+
year !== paperYear &&
|
|
146
|
+
(n.inLine || recent)
|
|
147
|
+
);
|
|
148
|
+
return n.inLine || (year !== null && recent);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/** A name to look for, with the pattern that finds it as a whole word. */
|
|
152
|
+
type NameMatcher = NameToJudge & { readonly re: RegExp };
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* The findings of one name in one run: each whole-word match judged with the year beside it and
|
|
156
|
+
* whether it stands in a venue-stating command (`inLine`). Pure.
|
|
157
|
+
*/
|
|
158
|
+
function matchesIn(
|
|
159
|
+
run: TextRun,
|
|
160
|
+
n: NameMatcher,
|
|
161
|
+
paper: LeftoverPlaces & {
|
|
162
|
+
readonly year: number | null;
|
|
163
|
+
readonly venue: string;
|
|
164
|
+
},
|
|
165
|
+
): readonly Located[] {
|
|
166
|
+
const { inLine, read, venue } = paper;
|
|
167
|
+
const text = runText(run);
|
|
168
|
+
return [...text.matchAll(n.re)].flatMap((m) => {
|
|
169
|
+
const at = spanIn(run, m.index, m.index + m[0].length);
|
|
170
|
+
const year = yearAfter(text, m.index + m[0].length);
|
|
171
|
+
const judged = { own: n.own, inLine: inLine(at) };
|
|
172
|
+
if (!judged.inLine && !read(at)) return [];
|
|
173
|
+
if (!namesAnotherEdition(judged, year, paper.year)) return [];
|
|
174
|
+
const other = editionLabel(n.shows, year);
|
|
175
|
+
return [{ messageId: "leftover", data: { name: m[0], other, venue }, at }];
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* Each place the rendered text names another venue than the paper's edition — a name as a whole
|
|
181
|
+
* word, case and all, judged with the year beside it (`namesAnotherEdition`), in the `places` the
|
|
182
|
+
* rule reads (`leftoverPlaces`). A family preset names no venue, so nothing is another venue:
|
|
183
|
+
* silent.
|
|
184
|
+
*/
|
|
185
|
+
export function judgeLeftover(
|
|
186
|
+
runs: readonly TextRun[],
|
|
187
|
+
preset: Preset,
|
|
188
|
+
others: readonly OtherVenue[],
|
|
189
|
+
places: LeftoverPlaces,
|
|
190
|
+
): readonly Located[] {
|
|
191
|
+
if (preset.identity.type !== "venue") return [];
|
|
192
|
+
const venue = editionLabel(preset.label, preset.year);
|
|
193
|
+
const names: readonly NameMatcher[] = namesToJudge(preset, others).map(
|
|
194
|
+
(n) => ({
|
|
195
|
+
...n,
|
|
196
|
+
re: new RegExp(
|
|
197
|
+
`(?<![\\p{L}\\p{N}])${literal(n.name)}(?![\\p{L}\\p{N}])`,
|
|
198
|
+
"gu",
|
|
199
|
+
),
|
|
200
|
+
}),
|
|
201
|
+
);
|
|
202
|
+
return runs.flatMap((run) =>
|
|
203
|
+
names.flatMap((n) =>
|
|
204
|
+
matchesIn(run, n, { ...places, year: preset.year, venue }),
|
|
205
|
+
),
|
|
206
|
+
);
|
|
207
|
+
}
|