paperlint 17.1.0 → 17.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CLAUDE.md +2 -2
- package/README.md +6 -4
- package/dist/cli.d.ts +1 -1
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +28 -29
- package/dist/cli.js.map +1 -1
- package/dist/presets.d.ts.map +1 -1
- package/dist/presets.js +6 -1
- package/dist/presets.js.map +1 -1
- package/dist/register-bands.d.ts +1 -7
- package/dist/register-bands.d.ts.map +1 -1
- package/dist/register-bands.js +12 -19
- package/dist/register-bands.js.map +1 -1
- package/dist/rule-sets.d.ts +43 -0
- package/dist/rule-sets.d.ts.map +1 -0
- package/dist/rule-sets.js +59 -0
- package/dist/rule-sets.js.map +1 -0
- package/dist/rules-config.d.ts +2 -1
- package/dist/rules-config.d.ts.map +1 -1
- package/dist/rules-config.js +17 -3
- package/dist/rules-config.js.map +1 -1
- package/docs/configuration.md +9 -2
- package/docs/optional-rules.md +48 -6
- package/docs/rules/tex/claim-emphasis.md +1 -1
- package/docs/rules/tex/claim-provenance.md +3 -3
- package/docs/rules/tex/contrast-frames.md +1 -1
- package/docs/rules/tex/max-caption-words.md +1 -1
- package/docs/rules/tex/max-paragraph-numbers.md +1 -1
- package/docs/rules/tex/max-paragraph-words.md +1 -1
- package/docs/rules/tex/max-sentence-words.md +1 -1
- package/docs/rules/tex/negated-sentences.md +1 -1
- package/docs/rules/tex/register.md +1 -1
- package/docs/rules/tex/relation-markers.md +1 -1
- package/docs/rules.md +18 -16
- package/fixtures/real-papers.test.ts +3 -0
- package/package.json +1 -1
- package/presets/aidc.jsonc +2 -1
- package/presets/aidc.md +4 -3
- package/src/cli.harness.mjs +25 -5
- package/src/cli.ts +43 -30
- package/src/lint-fix.test.ts +15 -2
- package/src/paper-includes.test.ts +62 -1
- package/src/presets.ts +8 -1
- package/src/register-bands.ts +13 -23
- package/src/rule-cases.test.ts +155 -16
- package/src/rule-sets.test.ts +150 -0
- package/src/rule-sets.ts +63 -0
- package/src/rules-config.ts +31 -3
package/src/register-bands.ts
CHANGED
|
@@ -2,15 +2,18 @@
|
|
|
2
2
|
* THE REGISTER RULES THAT MEASURE A BODY AGAINST ITS VENUE'S ACCEPTED PAPERS — each a rate per
|
|
3
3
|
* 10,000 words, judged against the band the venue preset's anchors set (`src/domain/register.ts`):
|
|
4
4
|
*
|
|
5
|
-
* tex/contrast-frames
|
|
6
|
-
*
|
|
7
|
-
* tex/claim-emphasis
|
|
8
|
-
*
|
|
9
|
-
* tex/relation-markers
|
|
10
|
-
*
|
|
11
|
-
* tex/negated-sentences
|
|
12
|
-
*
|
|
13
|
-
*
|
|
5
|
+
* tex/contrast-frames «X, not Y», «rather than», «instead of» … outside the band; above it, each
|
|
6
|
+
* frame is reported where it stands
|
|
7
|
+
* tex/claim-emphasis claims set in bold inside a sentence outside the band; above it, each is
|
|
8
|
+
* reported where it stands
|
|
9
|
+
* tex/relation-markers words naming how a sentence relates to the one before (because, therefore,
|
|
10
|
+
* however, for example …) outside the band
|
|
11
|
+
* tex/negated-sentences the share of the body's sentences that hold a negator (not, no, never,
|
|
12
|
+
* without …) outside the band — a percent of sentences, not a rate per words
|
|
13
|
+
*
|
|
14
|
+
* All four are off by default, on any preset, the anchored AIDC included: they measure the writing,
|
|
15
|
+
* and the anchors are other papers' writing, not a number the venue states. They are in the opt-in
|
|
16
|
+
* set `paperlint:writing` (src/rule-sets.ts), which turns them on at `warn` (the author, 2026-11-19).
|
|
14
17
|
*
|
|
15
18
|
* ── WHY ──────────────────────────────────────────────────────────────────────────
|
|
16
19
|
* Reviewers called a paper "too informal" and "a blogpost". Its text differed from the accepted
|
|
@@ -59,7 +62,7 @@ import type { VenueRuleDeps } from "./venue-rules.ts";
|
|
|
59
62
|
/** What the three rules read: the preset store, the LaTeX reader, and the paper's files as the build recorded them. */
|
|
60
63
|
export interface RegisterBandDeps extends VenueRuleDeps, ProseDeps {}
|
|
61
64
|
|
|
62
|
-
/** The band rules
|
|
65
|
+
/** The band rules that judge a rate per 10,000 words. */
|
|
63
66
|
export type WordBandRuleName =
|
|
64
67
|
"contrast-frames" | "claim-emphasis" | "relation-markers";
|
|
65
68
|
|
|
@@ -339,16 +342,3 @@ export function registerBandRules(
|
|
|
339
342
|
"negated-sentences": rule("negated-sentences", deps),
|
|
340
343
|
};
|
|
341
344
|
}
|
|
342
|
-
|
|
343
|
-
/**
|
|
344
|
-
* The level each rule is on at in paperlint's own config, for every `paper.tex`. `tex/negated-sentences`
|
|
345
|
-
* is not here: a writing measure added after the default set was fixed to what the venue decides,
|
|
346
|
-
* it ships off.
|
|
347
|
-
*/
|
|
348
|
-
export const REGISTER_BAND_RULE_LEVELS: Readonly<
|
|
349
|
-
Record<`tex/${WordBandRuleName}`, "warn">
|
|
350
|
-
> = {
|
|
351
|
-
"tex/contrast-frames": "warn",
|
|
352
|
-
"tex/claim-emphasis": "warn",
|
|
353
|
-
"tex/relation-markers": "warn",
|
|
354
|
-
};
|
package/src/rule-cases.test.ts
CHANGED
|
@@ -184,6 +184,17 @@ const DECLARE_SAMPLE_ON: Readonly<Record<string, string>> = {
|
|
|
184
184
|
}),
|
|
185
185
|
};
|
|
186
186
|
|
|
187
|
+
/**
|
|
188
|
+
* The writing set (src/rule-sets.ts) is off by default; a paper turns it on with one line in its
|
|
189
|
+
* `paperlint.json`. The cases of its rules that were on by default before it run with it on.
|
|
190
|
+
*/
|
|
191
|
+
const WRITING_ON: Readonly<Record<string, string>> = {
|
|
192
|
+
[`${P}/paperlint.json`]: JSON.stringify({
|
|
193
|
+
extends: null,
|
|
194
|
+
rules: { "paperlint:writing": "warn" },
|
|
195
|
+
}),
|
|
196
|
+
};
|
|
197
|
+
|
|
187
198
|
/** `tex/max-paragraph-words` is off by default; a paper turns it on in its `paperlint.json`. */
|
|
188
199
|
const MAX_PARAGRAPH_WORDS_ON: Readonly<Record<string, string>> = {
|
|
189
200
|
[`${P}/paperlint.json`]: JSON.stringify({
|
|
@@ -480,6 +491,15 @@ const blind = (body: string, cls = IEEE) =>
|
|
|
480
491
|
tex(`\\section{Introduction}\n${body}\n${STATEMENT}`, cls),
|
|
481
492
|
BLIND_PAPER,
|
|
482
493
|
);
|
|
494
|
+
/** A BlindConf paper that turns the writing set on: the register bands are in it, off by default. */
|
|
495
|
+
const blindWriting = (body: string) =>
|
|
496
|
+
paper(tex(`\\section{Introduction}\n${body}\n${STATEMENT}`, IEEE), {
|
|
497
|
+
...BLIND_PAPER,
|
|
498
|
+
[`${P}/paperlint.json`]: JSON.stringify({
|
|
499
|
+
extends: "./blindconf.jsonc",
|
|
500
|
+
rules: { "paperlint:writing": "warn" },
|
|
501
|
+
}),
|
|
502
|
+
});
|
|
483
503
|
/** A BlindConf paper that turns `tex/negated-sentences` on, which is off by default. */
|
|
484
504
|
const blindNegation = (body: string) =>
|
|
485
505
|
paper(tex(`\\section{Introduction}\n${body}\n${STATEMENT}`, IEEE), {
|
|
@@ -977,7 +997,7 @@ const CASES: Readonly<Record<string, RuleCases>> = {
|
|
|
977
997
|
},
|
|
978
998
|
"paper/section-word": {
|
|
979
999
|
reports: {
|
|
980
|
-
tree: paper(tex("As in §2.")),
|
|
1000
|
+
tree: paper(tex("As in §2."), WRITING_ON),
|
|
981
1001
|
file: TEX_FILE,
|
|
982
1002
|
severity: 1,
|
|
983
1003
|
line: 3,
|
|
@@ -988,25 +1008,26 @@ const CASES: Readonly<Record<string, RuleCases>> = {
|
|
|
988
1008
|
"As in Section~2.",
|
|
989
1009
|
"\\documentclass{article}\n\\usepackage{cleveref}\n\\crefname{section}{§}{§§}",
|
|
990
1010
|
),
|
|
1011
|
+
WRITING_ON,
|
|
991
1012
|
),
|
|
992
1013
|
},
|
|
993
1014
|
"paper/leading-zero": {
|
|
994
1015
|
reports: {
|
|
995
|
-
tree: paper(tex("We found $p < .05$.")),
|
|
1016
|
+
tree: paper(tex("We found $p < .05$."), WRITING_ON),
|
|
996
1017
|
file: TEX_FILE,
|
|
997
1018
|
severity: 1,
|
|
998
1019
|
line: 3,
|
|
999
1020
|
},
|
|
1000
|
-
silent: paper(tex("We found $p < 0.05$.")),
|
|
1021
|
+
silent: paper(tex("We found $p < 0.05$."), WRITING_ON),
|
|
1001
1022
|
},
|
|
1002
1023
|
"paper/figure-ref-style": {
|
|
1003
1024
|
reports: {
|
|
1004
|
-
tree: paper(tex("Fig.~\\ref{f1} and Figure~\\ref{f2}.")),
|
|
1025
|
+
tree: paper(tex("Fig.~\\ref{f1} and Figure~\\ref{f2}."), WRITING_ON),
|
|
1005
1026
|
file: TEX_FILE,
|
|
1006
1027
|
severity: 1,
|
|
1007
1028
|
line: 3,
|
|
1008
1029
|
},
|
|
1009
|
-
silent: paper(tex("Figure~\\ref{f1} and Figure~\\ref{f2}.")),
|
|
1030
|
+
silent: paper(tex("Figure~\\ref{f1} and Figure~\\ref{f2}."), WRITING_ON),
|
|
1010
1031
|
},
|
|
1011
1032
|
"paper/author-list": {
|
|
1012
1033
|
reports: {
|
|
@@ -1302,7 +1323,7 @@ const CASES: Readonly<Record<string, RuleCases>> = {
|
|
|
1302
1323
|
},
|
|
1303
1324
|
"tex/claim-provenance": {
|
|
1304
1325
|
reports: {
|
|
1305
|
-
tree: paper(tex("Text.\nAgents ignore 42\\% of the rules.")),
|
|
1326
|
+
tree: paper(tex("Text.\nAgents ignore 42\\% of the rules."), WRITING_ON),
|
|
1306
1327
|
file: TEX_FILE,
|
|
1307
1328
|
severity: 1,
|
|
1308
1329
|
line: 4,
|
|
@@ -1311,16 +1332,20 @@ const CASES: Readonly<Record<string, RuleCases>> = {
|
|
|
1311
1332
|
tex(
|
|
1312
1333
|
"Text.\nWe measured that agents ignore 42\\% of the rules.\nThey run on Claude 3 and Python 3.12.",
|
|
1313
1334
|
),
|
|
1335
|
+
WRITING_ON,
|
|
1314
1336
|
),
|
|
1315
1337
|
},
|
|
1316
1338
|
"tex/register": {
|
|
1317
1339
|
reports: {
|
|
1318
|
-
tree: paper(
|
|
1340
|
+
tree: paper(
|
|
1341
|
+
tex(`${FORMAL} But it holds. So it goes. And it ends.`),
|
|
1342
|
+
WRITING_ON,
|
|
1343
|
+
),
|
|
1319
1344
|
file: TEX_FILE,
|
|
1320
1345
|
severity: 1,
|
|
1321
1346
|
line: 3,
|
|
1322
1347
|
},
|
|
1323
|
-
silent: paper(tex(FORMAL)),
|
|
1348
|
+
silent: paper(tex(FORMAL), WRITING_ON),
|
|
1324
1349
|
},
|
|
1325
1350
|
// The paragraph ceiling is off by default (see "tex/max-paragraph-words is off by default"
|
|
1326
1351
|
// below): its cases turn it on in the paper's paperlint.json, as study/declare-sample's do.
|
|
@@ -1383,31 +1408,39 @@ const CASES: Readonly<Record<string, RuleCases>> = {
|
|
|
1383
1408
|
},
|
|
1384
1409
|
silent: paper(tex(GATE_DEFINED), TERMS_ON),
|
|
1385
1410
|
},
|
|
1386
|
-
// The three register bands judge a body against the anchor of BlindConf's preset
|
|
1387
|
-
// on line 3, right after the \\section,
|
|
1411
|
+
// The three register bands judge a body against the anchor of BlindConf's preset, with the
|
|
1412
|
+
// writing set on (they are off by default); the body opens on line 3, right after the \\section,
|
|
1413
|
+
// where the finding about the whole body stands.
|
|
1388
1414
|
"tex/contrast-frames": {
|
|
1389
1415
|
reports: {
|
|
1390
|
-
tree:
|
|
1416
|
+
tree: blindWriting(
|
|
1417
|
+
formalWith(5, "It reads the word, not the operation."),
|
|
1418
|
+
),
|
|
1391
1419
|
file: TEX_FILE,
|
|
1392
1420
|
severity: 1,
|
|
1393
1421
|
line: 3,
|
|
1394
1422
|
},
|
|
1395
|
-
silent:
|
|
1423
|
+
silent: blindWriting(LINKED),
|
|
1396
1424
|
},
|
|
1397
1425
|
"tex/claim-emphasis": {
|
|
1398
1426
|
reports: {
|
|
1399
|
-
tree:
|
|
1427
|
+
tree: blindWriting(
|
|
1400
1428
|
formalWith(6, "We find that \\textbf{the rule counts 46 sentences}."),
|
|
1401
1429
|
),
|
|
1402
1430
|
file: TEX_FILE,
|
|
1403
1431
|
severity: 1,
|
|
1404
1432
|
line: 3,
|
|
1405
1433
|
},
|
|
1406
|
-
silent:
|
|
1434
|
+
silent: blindWriting(LINKED),
|
|
1407
1435
|
},
|
|
1408
1436
|
"tex/relation-markers": {
|
|
1409
|
-
reports: {
|
|
1410
|
-
|
|
1437
|
+
reports: {
|
|
1438
|
+
tree: blindWriting(FORMAL),
|
|
1439
|
+
file: TEX_FILE,
|
|
1440
|
+
severity: 1,
|
|
1441
|
+
line: 3,
|
|
1442
|
+
},
|
|
1443
|
+
silent: blindWriting(LINKED),
|
|
1411
1444
|
},
|
|
1412
1445
|
// Off by default; on in this paper's paperlint.json. FORMAL holds no negator (0%, below 7.2%);
|
|
1413
1446
|
// 25 negated sentences of 225 are 11.1%, inside the band.
|
|
@@ -1615,6 +1648,112 @@ describe("every registered rule has cases, and every case names a registered rul
|
|
|
1615
1648
|
});
|
|
1616
1649
|
});
|
|
1617
1650
|
|
|
1651
|
+
describe("the writing set: off by default, one line turns it on", () => {
|
|
1652
|
+
/** One body with a defect for each rule of the set that was on by default before it. */
|
|
1653
|
+
const DEFECTS = tex(
|
|
1654
|
+
`${FORMAL} But it holds. So it goes. And it ends.\nAs in §2, $p < .05$; Fig.~\\ref{f1} and Figure~\\ref{f2}.\nAgents ignore 42\\% of the rules.`,
|
|
1655
|
+
);
|
|
1656
|
+
const FIVE = [
|
|
1657
|
+
"paper/section-word",
|
|
1658
|
+
"paper/leading-zero",
|
|
1659
|
+
"paper/figure-ref-style",
|
|
1660
|
+
"tex/claim-provenance",
|
|
1661
|
+
"tex/register",
|
|
1662
|
+
];
|
|
1663
|
+
const fromSet = async (tree: Record<string, string>) =>
|
|
1664
|
+
(await lintTree(tree))
|
|
1665
|
+
.map((m) => m.ruleId ?? "")
|
|
1666
|
+
.filter((id) => FIVE.includes(id));
|
|
1667
|
+
|
|
1668
|
+
it("🔴 a paper with all five defects and no set gets no finding from them", async () => {
|
|
1669
|
+
expect(await fromSet(paper(DEFECTS))).toEqual([]);
|
|
1670
|
+
});
|
|
1671
|
+
|
|
1672
|
+
it("the same paper with the set on in its paperlint.json gets each of them", async () => {
|
|
1673
|
+
expect(new Set(await fromSet(paper(DEFECTS, WRITING_ON)))).toEqual(
|
|
1674
|
+
new Set(FIVE),
|
|
1675
|
+
);
|
|
1676
|
+
});
|
|
1677
|
+
|
|
1678
|
+
it("the set in the root paperlint.json reaches every paper", async () => {
|
|
1679
|
+
expect(
|
|
1680
|
+
new Set(
|
|
1681
|
+
await fromSet({
|
|
1682
|
+
...paper(DEFECTS),
|
|
1683
|
+
"paperlint.json": JSON.stringify({
|
|
1684
|
+
rules: { "paperlint:writing": "warn" },
|
|
1685
|
+
}),
|
|
1686
|
+
}),
|
|
1687
|
+
),
|
|
1688
|
+
).toEqual(new Set(FIVE));
|
|
1689
|
+
});
|
|
1690
|
+
|
|
1691
|
+
it("a paper turns the root's set off for itself", async () => {
|
|
1692
|
+
expect(
|
|
1693
|
+
await fromSet({
|
|
1694
|
+
...paper(DEFECTS, {
|
|
1695
|
+
[`${P}/paperlint.json`]: JSON.stringify({
|
|
1696
|
+
extends: null,
|
|
1697
|
+
rules: { "paperlint:writing": "off" },
|
|
1698
|
+
}),
|
|
1699
|
+
}),
|
|
1700
|
+
"paperlint.json": JSON.stringify({
|
|
1701
|
+
rules: { "paperlint:writing": "warn" },
|
|
1702
|
+
}),
|
|
1703
|
+
}),
|
|
1704
|
+
).toEqual([]);
|
|
1705
|
+
});
|
|
1706
|
+
});
|
|
1707
|
+
|
|
1708
|
+
describe("the register bands are in the writing set, on AIDC too", () => {
|
|
1709
|
+
/**
|
|
1710
|
+
* A body against AIDC's real anchors (presets/aidc.jsonc, per 10,000 words): five contrast
|
|
1711
|
+
* frames and six bold claims over about 2,900 words are above their bands (0–10.4, 0–17.8), and
|
|
1712
|
+
* no relation marker is below 25.4.
|
|
1713
|
+
*/
|
|
1714
|
+
const BODY = formalWith(
|
|
1715
|
+
1,
|
|
1716
|
+
`${Array.from({ length: 5 }, () => "It reads the word, not the operation.").join(" ")} ${Array.from({ length: 6 }, () => "We find that \\textbf{the rule counts 46 sentences}.").join(" ")}`,
|
|
1717
|
+
);
|
|
1718
|
+
const BANDS = [
|
|
1719
|
+
"tex/contrast-frames",
|
|
1720
|
+
"tex/claim-emphasis",
|
|
1721
|
+
"tex/relation-markers",
|
|
1722
|
+
];
|
|
1723
|
+
const onAidc = (
|
|
1724
|
+
rules: Record<string, string> | null,
|
|
1725
|
+
preset = "paperlint:aidc",
|
|
1726
|
+
) =>
|
|
1727
|
+
paper(tex(`\\section{Introduction}\n${BODY}\n${STATEMENT}`, IEEE), {
|
|
1728
|
+
[`${P}/paperlint.json`]: JSON.stringify({
|
|
1729
|
+
extends: preset,
|
|
1730
|
+
...(rules ? { rules } : {}),
|
|
1731
|
+
}),
|
|
1732
|
+
});
|
|
1733
|
+
const bands = async (tree: Record<string, string>) =>
|
|
1734
|
+
(await lintTree(tree))
|
|
1735
|
+
.map((m) => m.ruleId ?? "")
|
|
1736
|
+
.filter((id) => BANDS.includes(id));
|
|
1737
|
+
|
|
1738
|
+
it("🔴 an AIDC paper whose preset carries the anchors gets no band finding without the set", async () => {
|
|
1739
|
+
expect(await bands(onAidc(null))).toEqual([]);
|
|
1740
|
+
});
|
|
1741
|
+
|
|
1742
|
+
it("the same paper with the set on gets all three", async () => {
|
|
1743
|
+
expect(
|
|
1744
|
+
new Set(await bands(onAidc({ "paperlint:writing": "warn" }))),
|
|
1745
|
+
).toEqual(new Set(BANDS));
|
|
1746
|
+
});
|
|
1747
|
+
|
|
1748
|
+
it("with the set on, a preset that records no anchors (ieee-conference) gives them nothing to judge", async () => {
|
|
1749
|
+
expect(
|
|
1750
|
+
await bands(
|
|
1751
|
+
onAidc({ "paperlint:writing": "warn" }, "paperlint:ieee-conference"),
|
|
1752
|
+
),
|
|
1753
|
+
).toEqual([]);
|
|
1754
|
+
});
|
|
1755
|
+
});
|
|
1756
|
+
|
|
1618
1757
|
describe("tex/max-paragraph-words is off by default", () => {
|
|
1619
1758
|
it("a 300-word paragraph produces nothing under the default config, and fires once the paper turns the rule on", async () => {
|
|
1620
1759
|
const ids = async (tree: Record<string, string>) =>
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Named rule sets (src/rule-sets.ts): what `paperlint:writing` holds, that it holds only rules off by
|
|
3
|
+
* default, and how the parser of the `rules` key expands it — in place, so a later entry wins. What
|
|
4
|
+
* the set does to a paper through `paperlint lint` is in `rule-cases.test.ts` («the writing set») and
|
|
5
|
+
* `lint-fix.test.ts`.
|
|
6
|
+
*/
|
|
7
|
+
import { describe, expect, it } from "vitest";
|
|
8
|
+
import { OPTIONAL_RULES, SHIPPED_RULES } from "./cli.ts";
|
|
9
|
+
import { presetProblemText } from "./presets.ts";
|
|
10
|
+
import { parseRuleBlocks, parseRuleEntries } from "./rules-config.ts";
|
|
11
|
+
import { RULE_SETS, setMembers, WRITING_SET } from "./rule-sets.ts";
|
|
12
|
+
|
|
13
|
+
const parse = (v: unknown) => parseRuleEntries(v, "S", SHIPPED_RULES);
|
|
14
|
+
const atWarn = Object.fromEntries(WRITING_SET.map((id) => [id, "warn"]));
|
|
15
|
+
|
|
16
|
+
describe("paperlint:writing", () => {
|
|
17
|
+
it("holds the writing-preference rules, and only those", () => {
|
|
18
|
+
expect(setMembers("paperlint:writing")).toEqual([
|
|
19
|
+
"paper/section-word",
|
|
20
|
+
"paper/leading-zero",
|
|
21
|
+
"paper/figure-ref-style",
|
|
22
|
+
"tex/claim-provenance",
|
|
23
|
+
"tex/register",
|
|
24
|
+
"tex/contrast-frames",
|
|
25
|
+
"tex/claim-emphasis",
|
|
26
|
+
"tex/relation-markers",
|
|
27
|
+
"tex/negated-sentences",
|
|
28
|
+
"tex/max-paragraph-words",
|
|
29
|
+
"tex/max-paragraph-numbers",
|
|
30
|
+
"tex/max-sentence-words",
|
|
31
|
+
"tex/max-caption-words",
|
|
32
|
+
]);
|
|
33
|
+
expect([...RULE_SETS.keys()]).toEqual(["paperlint:writing"]);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it.each(WRITING_SET)(
|
|
37
|
+
"%s is a shipped rule that is off by default — turning the set off gives back the default set",
|
|
38
|
+
(id) => {
|
|
39
|
+
expect(SHIPPED_RULES.has(id)).toBe(true);
|
|
40
|
+
expect(OPTIONAL_RULES.has(id)).toBe(true);
|
|
41
|
+
},
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
it("a name that is no set has no members", () => {
|
|
45
|
+
expect(setMembers("paperlint:strict")).toBeNull();
|
|
46
|
+
expect(setMembers("constructor")).toBeNull();
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
describe("a set in the `rules` key expands where it is written", () => {
|
|
51
|
+
it("one line turns every member on at the set's severity", () => {
|
|
52
|
+
expect(parse({ "paperlint:writing": "warn" })).toEqual({
|
|
53
|
+
ok: true,
|
|
54
|
+
value: atWarn,
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it("an entry after the set wins: one member off, another with its options", () => {
|
|
59
|
+
expect(
|
|
60
|
+
parse({
|
|
61
|
+
"paperlint:writing": "warn",
|
|
62
|
+
"tex/register": "off",
|
|
63
|
+
"tex/max-sentence-words": ["error", { max: 40 }],
|
|
64
|
+
}),
|
|
65
|
+
).toEqual({
|
|
66
|
+
ok: true,
|
|
67
|
+
value: {
|
|
68
|
+
...atWarn,
|
|
69
|
+
"tex/register": "off",
|
|
70
|
+
"tex/max-sentence-words": ["error", { max: 40 }],
|
|
71
|
+
},
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it("the set after an entry wins over it, as a later ESLint entry does", () => {
|
|
76
|
+
expect(
|
|
77
|
+
parse({ "tex/register": "off", "paperlint:writing": "error" }),
|
|
78
|
+
).toEqual({
|
|
79
|
+
ok: true,
|
|
80
|
+
value: Object.fromEntries(WRITING_SET.map((id) => [id, "error"])),
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it('"off" turns every member off — how a paper undoes the root\'s set', () => {
|
|
85
|
+
expect(parse({ "paperlint:writing": "off" })).toEqual({
|
|
86
|
+
ok: true,
|
|
87
|
+
value: Object.fromEntries(WRITING_SET.map((id) => [id, "off"])),
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
describe("what a set refuses, and where else it is written", () => {
|
|
93
|
+
it("a set takes a severity alone: options would be one member's, so they are refused", () => {
|
|
94
|
+
expect(parse({ "paperlint:writing": ["warn", { max: 40 }] })).toEqual({
|
|
95
|
+
ok: false,
|
|
96
|
+
error:
|
|
97
|
+
'S["paperlint:writing"]: ["warn",{"max":40}] — a rule set takes a severity alone ("off", "warn" or "error"); give one member its options in its own entry after the set',
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
it("a name that is neither a rule nor a set is refused, and the message names the sets", () => {
|
|
102
|
+
const r = parse({ "paperlint:strict": "warn" });
|
|
103
|
+
expect(r.ok).toBe(false);
|
|
104
|
+
expect(r.ok ? "" : r.error).toMatch(
|
|
105
|
+
/^S: "paperlint:strict" is not a rule paperlint ships — known: .*; rule sets: paperlint:writing$/,
|
|
106
|
+
);
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
it("in a block of the list form too", () => {
|
|
110
|
+
expect(
|
|
111
|
+
parseRuleBlocks(
|
|
112
|
+
[{ files: ["papers/a/**"], rules: { "paperlint:writing": "warn" } }],
|
|
113
|
+
"S",
|
|
114
|
+
SHIPPED_RULES,
|
|
115
|
+
"/consumer",
|
|
116
|
+
),
|
|
117
|
+
).toEqual({
|
|
118
|
+
ok: true,
|
|
119
|
+
value: [{ basePath: "/consumer", files: ["papers/a/**"], rules: atWarn }],
|
|
120
|
+
});
|
|
121
|
+
});
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
describe('"extends" naming a set', () => {
|
|
125
|
+
it("says the set goes in `rules`", () => {
|
|
126
|
+
expect(
|
|
127
|
+
presetProblemText({
|
|
128
|
+
kind: "not-found",
|
|
129
|
+
spec: "paperlint:writing",
|
|
130
|
+
file: "/pkg/presets/writing.jsonc",
|
|
131
|
+
shipped: ["aisec"],
|
|
132
|
+
}),
|
|
133
|
+
).toBe(
|
|
134
|
+
'"extends": "paperlint:writing" names no preset (/pkg/presets/writing.jsonc); shipped presets (paperlint:<name>): aisec. paperlint:writing is a rule set, not a venue: turn it on in "rules": { "paperlint:writing": "warn" }',
|
|
135
|
+
);
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
it("any other unknown name gets the list alone", () => {
|
|
139
|
+
expect(
|
|
140
|
+
presetProblemText({
|
|
141
|
+
kind: "not-found",
|
|
142
|
+
spec: "paperlint:nope",
|
|
143
|
+
file: "/pkg/presets/nope.jsonc",
|
|
144
|
+
shipped: ["aisec"],
|
|
145
|
+
}),
|
|
146
|
+
).toBe(
|
|
147
|
+
'"extends": "paperlint:nope" names no preset (/pkg/presets/nope.jsonc); shipped presets (paperlint:<name>): aisec',
|
|
148
|
+
);
|
|
149
|
+
});
|
|
150
|
+
});
|
package/src/rule-sets.ts
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* NAMED RULE SETS — opt-in rules grouped so an author turns them on in one line (#524).
|
|
3
|
+
*
|
|
4
|
+
* "rules": { "paperlint:writing": "warn" }
|
|
5
|
+
*
|
|
6
|
+
* A set is written where a rule id is written, in the `rules` key of the root or a paper's
|
|
7
|
+
* `paperlint.json` (or in a block of it), and is expanded there, at the boundary
|
|
8
|
+
* (`parseRuleEntries`, src/rules-config.ts), into one entry per member at the set's severity. Nothing
|
|
9
|
+
* after the parser knows a set existed. The members keep the set's place among the entries, so a
|
|
10
|
+
* later entry wins, as in ESLint: `{ "paperlint:writing": "warn", "tex/register": "off" }` is the set
|
|
11
|
+
* without `tex/register`, and `["warn", { … }]` after the set gives one member its options.
|
|
12
|
+
*
|
|
13
|
+
* ── WHY A `rules` ENTRY AND NOT `extends` ─────────────────────────────────────────
|
|
14
|
+
* `extends` names the paper's venue preset: one string (an array is refused: «"extends" must be a
|
|
15
|
+
* non-empty string»), read as the venue by the build, the facts file, the folder-name rule and the
|
|
16
|
+
* cycles, and derived from the current cycle when a paper keeps `cycles`, where writing `extends` is
|
|
17
|
+
* refused. A set beside the venue there would need a second meaning for that key. textlint turns
|
|
18
|
+
* a preset on the same way, as an entry of `rules` (`"preset-example": true`); typescript-eslint
|
|
19
|
+
* keeps its style rules in `stylistic`, apart from `recommended` — as this set is apart from the
|
|
20
|
+
* default set.
|
|
21
|
+
*
|
|
22
|
+
* ── WHAT A SET HOLDS ──────────────────────────────────────────────────────────────
|
|
23
|
+
* Only rules that are off by default (`rule-sets.test.ts` holds it): turning a set off gives back
|
|
24
|
+
* the default set, never less. A rule a venue requires is not here: its preset turns it on with the
|
|
25
|
+
* venue's options and level (`tex/heading-case` on AgenticDev), and a set entry after the preset
|
|
26
|
+
* would lower it to the set's severity. Nor is a rule that holds only for papers of one markup
|
|
27
|
+
* convention: `tex/term-before-definition` and `tex/term-defined-twice` read `\emph` as a definition,
|
|
28
|
+
* and on a paper that uses it for stress, or not at all, they report that they check nothing
|
|
29
|
+
* (measured: one such warning on every paper of `paper-includes.test.ts` with them in the set).
|
|
30
|
+
*/
|
|
31
|
+
|
|
32
|
+
/** The prefix a set's name shares with a shipped preset's spec: both are paperlint's own. */
|
|
33
|
+
export const SET_PREFIX = "paperlint:";
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* `paperlint:writing` — every rule that flags the WRITING rather than what the venue decides: the
|
|
37
|
+
* typography preferences `--fix` rewrites, register and provenance proxies, length and density
|
|
38
|
+
* caps. Each runs with its own default options.
|
|
39
|
+
*/
|
|
40
|
+
export const WRITING_SET: readonly string[] = [
|
|
41
|
+
"paper/section-word",
|
|
42
|
+
"paper/leading-zero",
|
|
43
|
+
"paper/figure-ref-style",
|
|
44
|
+
"tex/claim-provenance",
|
|
45
|
+
"tex/register",
|
|
46
|
+
"tex/contrast-frames",
|
|
47
|
+
"tex/claim-emphasis",
|
|
48
|
+
"tex/relation-markers",
|
|
49
|
+
"tex/negated-sentences",
|
|
50
|
+
"tex/max-paragraph-words",
|
|
51
|
+
"tex/max-paragraph-numbers",
|
|
52
|
+
"tex/max-sentence-words",
|
|
53
|
+
"tex/max-caption-words",
|
|
54
|
+
];
|
|
55
|
+
|
|
56
|
+
/** Every set, by the name written in `rules`. */
|
|
57
|
+
export const RULE_SETS: ReadonlyMap<string, readonly string[]> = new Map([
|
|
58
|
+
[`${SET_PREFIX}writing`, WRITING_SET],
|
|
59
|
+
]);
|
|
60
|
+
|
|
61
|
+
/** The members of the set `name`, or null when `name` names no set. */
|
|
62
|
+
export const setMembers = (name: string): readonly string[] | null =>
|
|
63
|
+
RULE_SETS.get(name) ?? null;
|
package/src/rules-config.ts
CHANGED
|
@@ -26,6 +26,7 @@
|
|
|
26
26
|
* config (`buildConfig`), not listed a second time.
|
|
27
27
|
*/
|
|
28
28
|
import { SETTINGS_KEYS } from "#lib/paper-config";
|
|
29
|
+
import { RULE_SETS, setMembers } from "./rule-sets.ts";
|
|
29
30
|
|
|
30
31
|
/** ESLint's severities, in both of its spellings. */
|
|
31
32
|
export type Severity = "off" | "warn" | "error" | 0 | 1 | 2;
|
|
@@ -97,9 +98,31 @@ function parseEntry(v: unknown): RuleEntry | null {
|
|
|
97
98
|
return Array.isArray(v) ? [sev, ...options] : sev;
|
|
98
99
|
}
|
|
99
100
|
|
|
101
|
+
/** A written entry once sets are expanded: a rule's, or a set given more than a severity. */
|
|
102
|
+
type Expanded =
|
|
103
|
+
| { readonly kind: "rule"; readonly id: string; readonly raw: unknown }
|
|
104
|
+
| {
|
|
105
|
+
readonly kind: "set-options";
|
|
106
|
+
readonly set: string;
|
|
107
|
+
readonly raw: unknown;
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
/** One written entry → the entries it stands for: a set's members at its severity, or itself. */
|
|
111
|
+
const expandEntry = ([id, raw]: readonly [
|
|
112
|
+
string,
|
|
113
|
+
unknown,
|
|
114
|
+
]): readonly Expanded[] => {
|
|
115
|
+
const members = setMembers(id);
|
|
116
|
+
if (members === null) return [{ kind: "rule", id, raw }];
|
|
117
|
+
return isSeverity(raw)
|
|
118
|
+
? members.map((m): Expanded => ({ kind: "rule", id: m, raw }))
|
|
119
|
+
: [{ kind: "set-options", set: id, raw }];
|
|
120
|
+
};
|
|
121
|
+
|
|
100
122
|
/**
|
|
101
123
|
* A `rules` object — rule id → severity or `[severity, ...options]` — with only the rules paperlint
|
|
102
|
-
* ships. Read from every `paperlint.json`, the root's and each paper's.
|
|
124
|
+
* ships. Read from every `paperlint.json`, the root's and each paper's. A rule set's name
|
|
125
|
+
* (src/rule-sets.ts) stands for its members at its severity, in its place: a later entry wins.
|
|
103
126
|
*
|
|
104
127
|
* @param where the key path to name in messages, e.g. `package.json → "paperlint".rules[0].rules`
|
|
105
128
|
*/
|
|
@@ -111,10 +134,15 @@ export function parseRuleEntries(
|
|
|
111
134
|
if (typeof v !== "object" || v === null || Array.isArray(v))
|
|
112
135
|
return bad(`${where} must be an object of rule id → severity`);
|
|
113
136
|
const out: Record<string, RuleEntry> = {};
|
|
114
|
-
for (const
|
|
137
|
+
for (const e of Object.entries(v).flatMap(expandEntry)) {
|
|
138
|
+
if (e.kind === "set-options")
|
|
139
|
+
return bad(
|
|
140
|
+
`${where}["${e.set}"]: ${JSON.stringify(e.raw)} — a rule set takes a severity alone ("off", "warn" or "error"); give one member its options in its own entry after the set`,
|
|
141
|
+
);
|
|
142
|
+
const { id, raw } = e;
|
|
115
143
|
if (!shipped.has(id))
|
|
116
144
|
return bad(
|
|
117
|
-
`${where}: "${id}" is not a rule paperlint ships — known: ${[...shipped].sort().join(", ")}`,
|
|
145
|
+
`${where}: "${id}" is not a rule paperlint ships — known: ${[...shipped].sort().join(", ")}; rule sets: ${[...RULE_SETS.keys()].join(", ")}`,
|
|
118
146
|
);
|
|
119
147
|
const entry = parseEntry(raw);
|
|
120
148
|
if (entry === null)
|