paperlint 6.0.0 → 6.1.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/dist/adapters/latex/index.d.ts +1 -1
- package/dist/adapters/latex/index.d.ts.map +1 -1
- package/dist/adapters/latex/index.js +3 -2
- package/dist/adapters/latex/index.js.map +1 -1
- package/dist/adapters/latex/prose.d.ts +6 -1
- package/dist/adapters/latex/prose.d.ts.map +1 -1
- package/dist/adapters/latex/prose.js +142 -31
- package/dist/adapters/latex/prose.js.map +1 -1
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +15 -18
- package/dist/cli.js.map +1 -1
- package/dist/domain/register.d.ts +96 -0
- package/dist/domain/register.d.ts.map +1 -0
- package/dist/domain/register.js +136 -0
- package/dist/domain/register.js.map +1 -0
- package/dist/domain/tex-document.d.ts +19 -0
- package/dist/domain/tex-document.d.ts.map +1 -1
- package/dist/domain/tex-document.js +8 -3
- package/dist/domain/tex-document.js.map +1 -1
- package/dist/ports/latex.d.ts +6 -1
- package/dist/ports/latex.d.ts.map +1 -1
- package/dist/presets.d.ts +3 -0
- package/dist/presets.d.ts.map +1 -1
- package/dist/presets.js +4 -1
- package/dist/presets.js.map +1 -1
- package/dist/register-bands.d.ts +37 -0
- package/dist/register-bands.d.ts.map +1 -0
- package/dist/register-bands.js +196 -0
- package/dist/register-bands.js.map +1 -0
- package/dist/register.d.ts +4 -2
- package/dist/register.d.ts.map +1 -1
- package/dist/register.js +6 -45
- package/dist/register.js.map +1 -1
- package/dist/tex-requirements.d.ts +6 -0
- package/dist/tex-requirements.d.ts.map +1 -1
- package/dist/tex-requirements.js +26 -6
- package/dist/tex-requirements.js.map +1 -1
- package/dist/tex-venue-rules.d.ts +1 -1
- package/dist/tex-venue-rules.d.ts.map +1 -1
- package/dist/tex-venue-rules.js.map +1 -1
- package/docs/rules/tex/claim-emphasis.md +71 -0
- package/docs/rules/tex/contrast-frames.md +100 -0
- package/docs/rules/tex/relation-markers.md +72 -0
- package/docs/rules.md +46 -42
- package/package.json +1 -1
- package/presets/aidc.jsonc +50 -0
- package/presets/venue-profile.schema.json +48 -1
- package/skills/grade-paper-writing/SKILL.md +59 -27
- package/skills/grade-paper-writing/SKILL.md.spec.ts +58 -26
- package/src/adapters/latex/index.test.ts +91 -0
- package/src/adapters/latex/index.ts +3 -2
- package/src/adapters/latex/prose.ts +188 -58
- package/src/cli.ts +19 -18
- package/src/domain/register.test.ts +153 -0
- package/src/domain/register.ts +261 -0
- package/src/domain/tex-document.ts +37 -3
- package/src/ports/latex.ts +6 -0
- package/src/presets.ts +7 -1
- package/src/register-bands.test.ts +327 -0
- package/src/register-bands.ts +291 -0
- package/src/register.ts +7 -37
- package/src/rule-cases.test.ts +67 -17
- package/src/tex-requirements.ts +47 -8
- package/src/tex-venue-rules.ts +7 -1
|
@@ -14,10 +14,18 @@
|
|
|
14
14
|
* own passage; one that cites or links leaves a citation mark in the sentence it hangs from.
|
|
15
15
|
*/
|
|
16
16
|
import type * as Ast from "@unified-latex/unified-latex-types";
|
|
17
|
-
import { hasAtLeast, sortBy } from "remeda";
|
|
18
|
-
import type {
|
|
17
|
+
import { hasAtLeast, mapWithFeedback, only, sortBy, zip } from "remeda";
|
|
18
|
+
import type {
|
|
19
|
+
Emphasis,
|
|
20
|
+
EmphasisStyle,
|
|
21
|
+
Owner,
|
|
22
|
+
Passage,
|
|
23
|
+
Place,
|
|
24
|
+
ProsePiece,
|
|
25
|
+
} from "../../domain/tex-document.ts";
|
|
19
26
|
import {
|
|
20
27
|
argumentsOf,
|
|
28
|
+
collapse,
|
|
21
29
|
inPlace,
|
|
22
30
|
macroPlace,
|
|
23
31
|
mandatory,
|
|
@@ -28,12 +36,16 @@ import {
|
|
|
28
36
|
} from "./nodes.ts";
|
|
29
37
|
import { CITATION_MACROS, DEFINITION_MACROS, type ParsedTex } from "./parse.ts";
|
|
30
38
|
|
|
31
|
-
/**
|
|
39
|
+
/**
|
|
40
|
+
* What the walk yields: a piece, the end of a passage, the start of the back matter, a footnote, and
|
|
41
|
+
* an emphasised phrase — which stands beside the pieces it typesets, and makes no passage of its own.
|
|
42
|
+
*/
|
|
32
43
|
type Event =
|
|
33
44
|
| { readonly kind: "piece"; readonly piece: ProsePiece }
|
|
34
45
|
| { readonly kind: "break" }
|
|
35
46
|
| { readonly kind: "end" }
|
|
36
|
-
| { readonly kind: "aside"; readonly events: readonly Event[] }
|
|
47
|
+
| { readonly kind: "aside"; readonly events: readonly Event[] }
|
|
48
|
+
| { readonly kind: "emphasis"; readonly emphasis: Emphasis };
|
|
37
49
|
|
|
38
50
|
const BREAK: Event = { kind: "break" };
|
|
39
51
|
const END: Event = { kind: "end" };
|
|
@@ -251,6 +263,75 @@ const OWN_EVENTS: ReadonlyMap<
|
|
|
251
263
|
],
|
|
252
264
|
]);
|
|
253
265
|
|
|
266
|
+
/** Formatting macros that set their argument apart from the running text, and how. */
|
|
267
|
+
const EMPHASIS_MACROS: ReadonlyMap<string, EmphasisStyle> = new Map([
|
|
268
|
+
["textbf", "bold"],
|
|
269
|
+
["emph", "italic"],
|
|
270
|
+
["textit", "italic"],
|
|
271
|
+
["textsl", "italic"],
|
|
272
|
+
["underline", "underline"],
|
|
273
|
+
["uline", "underline"],
|
|
274
|
+
]);
|
|
275
|
+
|
|
276
|
+
/**
|
|
277
|
+
* Declarations that set the rest of their group apart — `{\bfseries …}`, `{\em …}` — and how. The
|
|
278
|
+
* group is the phrase.
|
|
279
|
+
*/
|
|
280
|
+
const EMPHASIS_DECLARATIONS: ReadonlyMap<string, EmphasisStyle> = new Map([
|
|
281
|
+
["bfseries", "bold"],
|
|
282
|
+
["bf", "bold"],
|
|
283
|
+
["em", "italic"],
|
|
284
|
+
["itshape", "italic"],
|
|
285
|
+
["it", "italic"],
|
|
286
|
+
["slshape", "italic"],
|
|
287
|
+
]);
|
|
288
|
+
|
|
289
|
+
/** An emphasised phrase over `place`, typesetting what `inner` typesets; nothing when it has no place or no text. */
|
|
290
|
+
const emphasisOf = (
|
|
291
|
+
style: EmphasisStyle,
|
|
292
|
+
place: Place,
|
|
293
|
+
inner: readonly Event[],
|
|
294
|
+
): readonly Event[] =>
|
|
295
|
+
inPlace(place, (span) => {
|
|
296
|
+
const text = collapse(typeset(inner));
|
|
297
|
+
return text === ""
|
|
298
|
+
? []
|
|
299
|
+
: [
|
|
300
|
+
{
|
|
301
|
+
kind: "emphasis",
|
|
302
|
+
emphasis: { style, place: "inline", text, span },
|
|
303
|
+
},
|
|
304
|
+
];
|
|
305
|
+
});
|
|
306
|
+
|
|
307
|
+
/** A formatting macro's events: what it typesets, and — for an emphasising one — the phrase. */
|
|
308
|
+
function formattingEvents(t: ParsedTex, m: Macro): readonly Event[] {
|
|
309
|
+
const inner = walkList(t, lastArgument(m));
|
|
310
|
+
const style = EMPHASIS_MACROS.get(m.content);
|
|
311
|
+
return style === undefined
|
|
312
|
+
? inner
|
|
313
|
+
: [...emphasisOf(style, macroPlace(m), inner), ...inner];
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
/** The style a group's opening declaration sets, when it opens with one (`{\bfseries …}`). */
|
|
317
|
+
function declaredStyle(list: readonly Node[]): EmphasisStyle | undefined {
|
|
318
|
+
const first = list.find(
|
|
319
|
+
(n) => n.type !== "whitespace" && n.type !== "comment",
|
|
320
|
+
);
|
|
321
|
+
return first?.type === "macro"
|
|
322
|
+
? EMPHASIS_DECLARATIONS.get(first.content)
|
|
323
|
+
: undefined;
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
/** A group's events: what it typesets, and — when it opens with an emphasis declaration — the phrase. */
|
|
327
|
+
function groupEvents(t: ParsedTex, g: NodeOf<"group">): readonly Event[] {
|
|
328
|
+
const inner = walkList(t, g.content);
|
|
329
|
+
const style = declaredStyle(g.content);
|
|
330
|
+
return style === undefined
|
|
331
|
+
? inner
|
|
332
|
+
: [...emphasisOf(style, placeOf(g), inner), ...inner];
|
|
333
|
+
}
|
|
334
|
+
|
|
254
335
|
function macroEvents(t: ParsedTex, m: Macro): readonly Event[] {
|
|
255
336
|
const name = m.content;
|
|
256
337
|
if (DEFINITION_MACROS.has(name)) return [];
|
|
@@ -260,7 +341,7 @@ function macroEvents(t: ParsedTex, m: Macro): readonly Event[] {
|
|
|
260
341
|
const own = OWN_EVENTS.get(name);
|
|
261
342
|
if (own !== undefined) return own(t, m);
|
|
262
343
|
if (BREAK_MACROS.has(name)) return [BREAK];
|
|
263
|
-
if (INLINE_MACROS.has(name)) return
|
|
344
|
+
if (INLINE_MACROS.has(name)) return formattingEvents(t, m);
|
|
264
345
|
const ch = CHARACTER_MACROS.get(name);
|
|
265
346
|
return ch === undefined ? [] : characterAt(m, ch);
|
|
266
347
|
}
|
|
@@ -298,7 +379,7 @@ function nodeEvents(t: ParsedTex, n: Node): readonly Event[] {
|
|
|
298
379
|
case "whitespace":
|
|
299
380
|
return textAt(n, " ");
|
|
300
381
|
case "group":
|
|
301
|
-
return
|
|
382
|
+
return groupEvents(t, n);
|
|
302
383
|
case "environment":
|
|
303
384
|
case "mathenv":
|
|
304
385
|
return environmentEvents(t, n);
|
|
@@ -346,20 +427,12 @@ function step(
|
|
|
346
427
|
* macro the parser gave no signature — `\institution{…}`, `\ccsdesc[500]{…}`, `\tool{}`,
|
|
347
428
|
* `\if\conference1` — which are its arguments, not text. A formatting macro's group (`\enquote{…}` without csquotes' signature) stays prose.
|
|
348
429
|
*/
|
|
349
|
-
const proseNodes = (list: readonly Node[]): readonly Node[] =>
|
|
350
|
-
list.
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
const next = step(acc.state, n);
|
|
356
|
-
return {
|
|
357
|
-
kept: next.skip ? acc.kept : [...acc.kept, n],
|
|
358
|
-
state: next.state,
|
|
359
|
-
};
|
|
360
|
-
},
|
|
361
|
-
{ kept: [], state: "prose" },
|
|
362
|
-
).kept;
|
|
430
|
+
const proseNodes = (list: readonly Node[]): readonly Node[] => {
|
|
431
|
+
// Each node's step, fed the state the one before left: a scan, linear in the list.
|
|
432
|
+
const start: ReturnType<typeof step> = { skip: false, state: "prose" };
|
|
433
|
+
const steps = mapWithFeedback(list, (prev, n) => step(prev.state, n), start);
|
|
434
|
+
return zip(list, steps).flatMap(([n, st]) => (st.skip ? [] : [n]));
|
|
435
|
+
};
|
|
363
436
|
|
|
364
437
|
/** Formatting macros a run-in heading is set in: `\textbf{Correctness gate.} Each task…`. */
|
|
365
438
|
const RUN_IN_MACROS: ReadonlySet<string> = new Set([
|
|
@@ -378,11 +451,33 @@ const typeset = (events: readonly Event[]): string =>
|
|
|
378
451
|
)
|
|
379
452
|
.join("");
|
|
380
453
|
|
|
381
|
-
/**
|
|
382
|
-
const
|
|
383
|
-
n.type
|
|
384
|
-
|
|
385
|
-
|
|
454
|
+
/** The one node a group holds besides spaces and comments — `{\textbf{…}}` → the `\textbf` — or null. */
|
|
455
|
+
const soleChild = (n: Node): Node | null => {
|
|
456
|
+
if (n.type !== "group") return null;
|
|
457
|
+
const kept = n.content.filter(
|
|
458
|
+
(c) => c.type !== "whitespace" && c.type !== "comment",
|
|
459
|
+
);
|
|
460
|
+
return only(kept) ?? null;
|
|
461
|
+
};
|
|
462
|
+
|
|
463
|
+
/** A node with the groups around it taken off: `{{\textbf{…}}}` → the `\textbf`. */
|
|
464
|
+
const unwrapped = (n: Node): Node => {
|
|
465
|
+
const inner = soleChild(n);
|
|
466
|
+
return inner === null ? n : unwrapped(inner);
|
|
467
|
+
};
|
|
468
|
+
|
|
469
|
+
/**
|
|
470
|
+
* A formatting macro whose phrase ends in `.` or `:` — a run-in heading, when it opens a paragraph.
|
|
471
|
+
* Braces around it change nothing on the page, so `{\textbf{Threats:}}` is one too.
|
|
472
|
+
*/
|
|
473
|
+
const isRunInHeading = (t: ParsedTex, node: Node): boolean => {
|
|
474
|
+
const n = unwrapped(node);
|
|
475
|
+
return (
|
|
476
|
+
n.type === "macro" &&
|
|
477
|
+
RUN_IN_MACROS.has(n.content) &&
|
|
478
|
+
/[.:]$/u.test(typeset(walkList(t, lastArgument(n))).trim())
|
|
479
|
+
);
|
|
480
|
+
};
|
|
386
481
|
|
|
387
482
|
/** Macros that typeset no text, and so leave a paragraph's opening where it was. */
|
|
388
483
|
const SILENT_AT_OPENING: ReadonlySet<string> = new Set([
|
|
@@ -405,28 +500,47 @@ const keepsOpening = (n: Node): boolean =>
|
|
|
405
500
|
const opensAfter = (n: Node): boolean =>
|
|
406
501
|
n.type === "parbreak" || (n.type === "macro" && BREAK_MACROS.has(n.content));
|
|
407
502
|
|
|
503
|
+
/**
|
|
504
|
+
* An emphasising node's events when it opens a paragraph: its own phrase — the first event — is a
|
|
505
|
+
* label, not inline; braces around it change nothing on the page (`{\textbf{…}}.`). Any other node
|
|
506
|
+
* (an environment, a footnote) is left as it is: what it holds opens nothing here.
|
|
507
|
+
*/
|
|
508
|
+
const asOpening = (node: Node, events: readonly Event[]): readonly Event[] => {
|
|
509
|
+
const [own, ...rest] = events;
|
|
510
|
+
const n = unwrapped(node);
|
|
511
|
+
const emphasises =
|
|
512
|
+
(n.type === "macro" && EMPHASIS_MACROS.has(n.content)) ||
|
|
513
|
+
(n.type === "group" && declaredStyle(n.content) !== undefined);
|
|
514
|
+
return emphasises && own?.kind === "emphasis"
|
|
515
|
+
? [
|
|
516
|
+
{ kind: "emphasis", emphasis: { ...own.emphasis, place: "opening" } },
|
|
517
|
+
...rest,
|
|
518
|
+
]
|
|
519
|
+
: events;
|
|
520
|
+
};
|
|
521
|
+
|
|
408
522
|
/**
|
|
409
523
|
* A list's events. `opens` says the list starts a paragraph (the body, an environment's content);
|
|
410
|
-
* a run-in heading that opens a paragraph ends the passage before it and is left out, like a heading
|
|
524
|
+
* a run-in heading that opens a paragraph ends the passage before it and is left out, like a heading,
|
|
525
|
+
* and a phrase emphasised there is a label (`opening`).
|
|
411
526
|
*/
|
|
412
527
|
function walkList(
|
|
413
528
|
t: ParsedTex,
|
|
414
529
|
list: readonly Node[],
|
|
415
530
|
opens = false,
|
|
416
531
|
): readonly Event[] {
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
(
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
).events;
|
|
532
|
+
const nodes = proseNodes(list);
|
|
533
|
+
// Whether a paragraph is open AFTER each node: a scan, so the walk stays linear in the list.
|
|
534
|
+
const after = mapWithFeedback(
|
|
535
|
+
nodes,
|
|
536
|
+
(opening, n) => opensAfter(n) || (opening && keepsOpening(n)),
|
|
537
|
+
opens,
|
|
538
|
+
);
|
|
539
|
+
return nodes.flatMap((n, i) => {
|
|
540
|
+
const opening = i === 0 ? opens : after[i - 1] === true;
|
|
541
|
+
if (!opening) return nodeEvents(t, n);
|
|
542
|
+
return isRunInHeading(t, n) ? [BREAK] : asOpening(n, nodeEvents(t, n));
|
|
543
|
+
});
|
|
430
544
|
}
|
|
431
545
|
|
|
432
546
|
/** The events before the back matter starts. */
|
|
@@ -437,27 +551,35 @@ const untilEnd = (events: readonly Event[]): readonly Event[] => {
|
|
|
437
551
|
|
|
438
552
|
/** Events → passages: pieces between breaks, each footnote a passage of its own. */
|
|
439
553
|
function passagesOf(events: readonly Event[]): readonly Passage[] {
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
? { done: acc.done, current: [...acc.current, e.piece] }
|
|
447
|
-
: e.kind === "break"
|
|
448
|
-
? { done: [...acc.done, acc.current], current: [] }
|
|
449
|
-
: acc,
|
|
450
|
-
{ done: [], current: [] },
|
|
554
|
+
// Where each passage starts and ends: between breaks. Slicing between them keeps this linear in
|
|
555
|
+
// the events — a paragraph of thousands of words is one slice, not a copy per word.
|
|
556
|
+
const breaks = events.flatMap((e, i) => (e.kind === "break" ? [i] : []));
|
|
557
|
+
const bounds = zip(
|
|
558
|
+
[0, ...breaks.map((b) => b + 1)],
|
|
559
|
+
[...breaks, events.length],
|
|
451
560
|
);
|
|
561
|
+
const own = bounds.flatMap(([from, to]) => {
|
|
562
|
+
const pieces = events
|
|
563
|
+
.slice(from, to)
|
|
564
|
+
.flatMap((e) => (e.kind === "piece" ? [e.piece] : []));
|
|
565
|
+
return hasAtLeast(pieces, 1) ? [{ pieces }] : [];
|
|
566
|
+
});
|
|
452
567
|
const asides = events.flatMap((e) =>
|
|
453
568
|
e.kind === "aside" ? passagesOf(untilEnd(e.events)) : [],
|
|
454
569
|
);
|
|
455
|
-
const own = [...done, current].flatMap((pieces) =>
|
|
456
|
-
hasAtLeast(pieces, 1) ? [{ pieces }] : [],
|
|
457
|
-
);
|
|
458
570
|
return [...own, ...asides];
|
|
459
571
|
}
|
|
460
572
|
|
|
573
|
+
/** Every emphasised phrase among events, a footnote's included, up to the back matter. */
|
|
574
|
+
const emphasesOf = (events: readonly Event[]): readonly Emphasis[] =>
|
|
575
|
+
untilEnd(events).flatMap((e) =>
|
|
576
|
+
e.kind === "emphasis"
|
|
577
|
+
? [e.emphasis]
|
|
578
|
+
: e.kind === "aside"
|
|
579
|
+
? emphasesOf(e.events)
|
|
580
|
+
: [],
|
|
581
|
+
);
|
|
582
|
+
|
|
461
583
|
const isDocument = (n: Node): n is Readonly<Ast.Environment> =>
|
|
462
584
|
n.type === "environment" && n.env === "document";
|
|
463
585
|
|
|
@@ -476,9 +598,17 @@ const startOf = (p: Passage): number => {
|
|
|
476
598
|
* source when there is none), up to the first back-matter node.
|
|
477
599
|
*/
|
|
478
600
|
export function bodyProse(t: ParsedTex): readonly Passage[] {
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
601
|
+
return sortBy(passagesOf(untilEnd(bodyEvents(t))).filter(hasProse), startOf);
|
|
602
|
+
}
|
|
603
|
+
|
|
604
|
+
/** The walk of the body: the content of the `document` environment, or the whole source when there is none. */
|
|
605
|
+
const bodyEvents = (t: ParsedTex): readonly Event[] =>
|
|
606
|
+
walkList(t, t.root.content.find(isDocument)?.content ?? t.root.content, true);
|
|
607
|
+
|
|
608
|
+
/**
|
|
609
|
+
* The phrases set in bold, italics or underline inside the body's prose, in document order: what
|
|
610
|
+
* `bodyProse` reads, so never a heading, a run-in heading, a caption, a float or a table.
|
|
611
|
+
*/
|
|
612
|
+
export function bodyEmphasis(t: ParsedTex): readonly Emphasis[] {
|
|
613
|
+
return sortBy(emphasesOf(bodyEvents(t)), (e) => e.span.start);
|
|
484
614
|
}
|
package/src/cli.ts
CHANGED
|
@@ -65,6 +65,10 @@ import {
|
|
|
65
65
|
} from "./tex-venue-rules.ts";
|
|
66
66
|
import { claimProvenanceRule } from "./claim-provenance.ts";
|
|
67
67
|
import { registerRule } from "./register.ts";
|
|
68
|
+
import {
|
|
69
|
+
REGISTER_BAND_RULE_LEVELS,
|
|
70
|
+
registerBandRules,
|
|
71
|
+
} from "./register-bands.ts";
|
|
68
72
|
import {
|
|
69
73
|
paperRules,
|
|
70
74
|
identityField,
|
|
@@ -236,6 +240,13 @@ settings — paperlint.json, at two levels, one schema. Both are optional.
|
|
|
236
240
|
file, is an error.
|
|
237
241
|
`;
|
|
238
242
|
|
|
243
|
+
/** What the rules over a paper.tex read with: the disk, the shipped presets, the LaTeX reader. */
|
|
244
|
+
const TEX_RULE_DEPS = {
|
|
245
|
+
files: nodeFiles,
|
|
246
|
+
venuesDir: presetsDir(),
|
|
247
|
+
latex: latexReader,
|
|
248
|
+
};
|
|
249
|
+
|
|
239
250
|
/** The config the user would otherwise write by hand. The data comes from `opts`, the mechanism is here. */
|
|
240
251
|
export function buildConfig(
|
|
241
252
|
opts: PaperlintConfig = {},
|
|
@@ -325,30 +336,17 @@ export function buildConfig(
|
|
|
325
336
|
languages: { latex: texLanguage },
|
|
326
337
|
rules: {
|
|
327
338
|
...texBuild,
|
|
328
|
-
...texVenueRules(
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
}),
|
|
333
|
-
"claim-provenance": claimProvenanceRule({
|
|
334
|
-
files: nodeFiles,
|
|
335
|
-
latex: latexReader,
|
|
336
|
-
}),
|
|
337
|
-
register: registerRule({
|
|
338
|
-
files: nodeFiles,
|
|
339
|
-
latex: latexReader,
|
|
340
|
-
}),
|
|
339
|
+
...texVenueRules(TEX_RULE_DEPS),
|
|
340
|
+
"claim-provenance": claimProvenanceRule(TEX_RULE_DEPS),
|
|
341
|
+
register: registerRule(TEX_RULE_DEPS),
|
|
342
|
+
...registerBandRules(TEX_RULE_DEPS),
|
|
341
343
|
},
|
|
342
344
|
},
|
|
343
345
|
paper: { rules: texPaperRules },
|
|
344
346
|
bib: bibReachable,
|
|
345
347
|
format: {
|
|
346
348
|
rules: {
|
|
347
|
-
...formatRules(
|
|
348
|
-
files: nodeFiles,
|
|
349
|
-
venuesDir: presetsDir(),
|
|
350
|
-
latex: latexReader,
|
|
351
|
-
}),
|
|
349
|
+
...formatRules(TEX_RULE_DEPS),
|
|
352
350
|
...pageLimitRules({ files: nodeFiles, venuesDir: presetsDir() }),
|
|
353
351
|
},
|
|
354
352
|
},
|
|
@@ -364,6 +362,9 @@ export function buildConfig(
|
|
|
364
362
|
"tex/claim-provenance": "warn",
|
|
365
363
|
// Sentence-initial conjunctions over the whole body: register, not vocabulary.
|
|
366
364
|
"tex/register": "warn",
|
|
365
|
+
// Contrast frames, claims in bold, relation markers: each against the band the venue
|
|
366
|
+
// preset's anchors set, silent for a preset without anchors (src/register-bands.ts).
|
|
367
|
+
...REGISTER_BAND_RULE_LEVELS,
|
|
367
368
|
"tex/acm-frontmatter-override": "error",
|
|
368
369
|
// Silent for a paper whose paperlint.json names no venue (src/venue-rules.ts).
|
|
369
370
|
...VENUE_RULE_LEVELS,
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The register measures on real parses: what counts as a contrast frame, a relation marker and a
|
|
3
|
+
* claim in bold, and what does not; the band the anchors set; the excerpt a finding quotes.
|
|
4
|
+
* Every "does not count" case below is a sentence shape found in an accepted ACSAC paper.
|
|
5
|
+
*/
|
|
6
|
+
import { describe, expect, it } from "vitest";
|
|
7
|
+
import { latexReader } from "../adapters/latex/index.ts";
|
|
8
|
+
import {
|
|
9
|
+
bandOf,
|
|
10
|
+
bodySentences,
|
|
11
|
+
claimEmphasis,
|
|
12
|
+
contrastFrames,
|
|
13
|
+
excerpt,
|
|
14
|
+
rateOf,
|
|
15
|
+
relationMarkers,
|
|
16
|
+
type RegisterAnchor,
|
|
17
|
+
} from "./register.ts";
|
|
18
|
+
|
|
19
|
+
const doc = (body: string): string =>
|
|
20
|
+
`\\documentclass{article}\n\\begin{document}\n${body}\n\\end{document}\n`;
|
|
21
|
+
const sentencesOf = (body: string) =>
|
|
22
|
+
bodySentences(latexReader.bodyProse(doc(body)));
|
|
23
|
+
const frames = (body: string): number =>
|
|
24
|
+
contrastFrames(sentencesOf(body)).length;
|
|
25
|
+
const markers = (body: string): number =>
|
|
26
|
+
relationMarkers(sentencesOf(body)).length;
|
|
27
|
+
const claims = (body: string): readonly string[] =>
|
|
28
|
+
claimEmphasis(latexReader.bodyEmphasis(doc(body))).map((o) => o.match);
|
|
29
|
+
|
|
30
|
+
describe("contrastFrames — a claim set against a rejected alternative", () => {
|
|
31
|
+
it.each([
|
|
32
|
+
[
|
|
33
|
+
"X, not Y",
|
|
34
|
+
"They react to the dangerous word, not the dangerous operation.",
|
|
35
|
+
],
|
|
36
|
+
["X --- not Y", "It guarantees encryption --- not authenticity."],
|
|
37
|
+
["X; not Y", "We score the operation; not the attacker."],
|
|
38
|
+
["X, and not Y", "It reads the field, and not the raw input."],
|
|
39
|
+
["not X but Y", "Over-blocking is not a side metric but a precondition."],
|
|
40
|
+
["rather than", "It fires on the mention rather than the act."],
|
|
41
|
+
["instead of", "It reads the whole event instead of the command."],
|
|
42
|
+
["as opposed to", "It matches words as opposed to operations."],
|
|
43
|
+
])("🔴 %s is one frame", (_form, sentence) => {
|
|
44
|
+
expect(frames(sentence)).toBe(1);
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it.each([
|
|
48
|
+
["not only … but also", "It is not only fast but also exact."],
|
|
49
|
+
[
|
|
50
|
+
"a negated clause",
|
|
51
|
+
"The nature of the audit is not reported, but it did not assess quality.",
|
|
52
|
+
],
|
|
53
|
+
["«, not yet»", "The fix is merged, not yet released."],
|
|
54
|
+
[
|
|
55
|
+
"«, not already in the corpus»",
|
|
56
|
+
"We kept every guard published since, not already in the corpus.",
|
|
57
|
+
],
|
|
58
|
+
["«without»", "The attack works without any access to the device."],
|
|
59
|
+
["«unlike»", "Unlike prior work, we measure the installed guards."],
|
|
60
|
+
["a bare negation", "The guard does not block it."],
|
|
61
|
+
])("%s is no frame", (_form, sentence) => {
|
|
62
|
+
expect(frames(sentence)).toBe(0);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it("two frames in one sentence are two; one phrase matching two forms is one", () => {
|
|
66
|
+
expect(
|
|
67
|
+
frames("It reads the word, not the act, rather than the operation."),
|
|
68
|
+
).toBe(2);
|
|
69
|
+
expect(frames("It is not a word but rather than a verb.")).toBe(2);
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it("a frame in a table, a caption or a heading is not prose, so not counted", () => {
|
|
73
|
+
expect(
|
|
74
|
+
frames(
|
|
75
|
+
"\\section{Words, not operations}\n\\begin{table}\\caption{Words, not operations.}\\begin{tabular}{l}a, not b\\end{tabular}\\end{table}\nPlain text here.",
|
|
76
|
+
),
|
|
77
|
+
).toBe(0);
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
describe("relationMarkers — words that name how a sentence relates to the one before", () => {
|
|
82
|
+
it("🔴 each marker counts where it stands, sentence-initial or not", () => {
|
|
83
|
+
expect(
|
|
84
|
+
markers(
|
|
85
|
+
"However, the rate is low. It fails because the rule matches words. For example, echo is blocked. It is therefore unsafe.",
|
|
86
|
+
),
|
|
87
|
+
).toBe(4);
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
it("a marker inside a longer word is not one: «thusly» is no «thus», «sincere» no «since»", () => {
|
|
91
|
+
expect(
|
|
92
|
+
markers("The sincere author wrote thusly. Eventually it held."),
|
|
93
|
+
).toBe(0);
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
describe("claimEmphasis — a claim set in bold inside a sentence", () => {
|
|
98
|
+
it("🔴 a bold phrase of six words or more, or holding a number, inside a sentence", () => {
|
|
99
|
+
expect(
|
|
100
|
+
claims(
|
|
101
|
+
"We find that \\textbf{they react to the dangerous word}. The \\textbf{median coverage is 2.5/10} here.",
|
|
102
|
+
),
|
|
103
|
+
).toEqual([
|
|
104
|
+
"they react to the dangerous word",
|
|
105
|
+
"median coverage is 2.5/10",
|
|
106
|
+
]);
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
it("a term in bold, a label opening a paragraph or item, italics, and a run-in heading are not claims", () => {
|
|
110
|
+
expect(
|
|
111
|
+
claims(
|
|
112
|
+
"BaroVox offers a \\textbf{Pressure-Acoustic Transformation (PAT)} here.\n\n\\textbf{Varying the orientation of the sound source from the device}. We vary it.\n\\begin{itemize}\n\\item \\textbf{A corpus of user security questions with sources}: we release it.\n\\end{itemize}\nWe \\emph{find that the guards react to the word}.\n\n\\textbf{Threats to validity of the 46 guards.} None.",
|
|
113
|
+
),
|
|
114
|
+
).toEqual([]);
|
|
115
|
+
});
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
describe("bandOf — the anchors' range, widened by two Poisson standard deviations", () => {
|
|
119
|
+
const anchor = (words: number, contrast_frames: number): RegisterAnchor => ({
|
|
120
|
+
paper: "p",
|
|
121
|
+
words,
|
|
122
|
+
counts: { contrast_frames, claim_emphasis: 0, relation_markers: 0 },
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
it("🔴 the edges stand two standard deviations of the edge anchor's count beyond it", () => {
|
|
126
|
+
// 4 in 10,000 words: rate 4, sd 2 → max 8. 1 in 10,000: rate 1, sd 1 → min 1 - 2 < 0 → 0.
|
|
127
|
+
expect(
|
|
128
|
+
bandOf([anchor(10_000, 4), anchor(10_000, 1)], "contrast_frames"),
|
|
129
|
+
).toEqual({ min: 0, max: 8, anchorMin: 1, anchorMax: 4, anchors: 2 });
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
it("an anchor with no occurrence is widened as if it had one; a floor above zero stays", () => {
|
|
133
|
+
expect(bandOf([anchor(10_000, 0)], "contrast_frames")?.max).toBe(2);
|
|
134
|
+
expect(bandOf([anchor(10_000, 100)], "contrast_frames")?.min).toBe(80);
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
it("no anchors, no band; a body of no words has a rate of zero", () => {
|
|
138
|
+
expect(bandOf([], "contrast_frames")).toBeNull();
|
|
139
|
+
expect(rateOf(3, 0)).toBe(0);
|
|
140
|
+
});
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
describe("excerpt — the words around an occurrence, as a finding quotes them", () => {
|
|
144
|
+
it("the match with its neighbours, cut at a word, an ellipsis where the sentence goes on", () => {
|
|
145
|
+
const s =
|
|
146
|
+
"We score 46 gates and find that they react to the dangerous word, not the dangerous operation, in every one of the ten cases we built.";
|
|
147
|
+
const at = s.indexOf(", not");
|
|
148
|
+
expect(excerpt(s, at, at + 6)).toBe(
|
|
149
|
+
"…that they react to the dangerous word, not the dangerous operation, in every one…",
|
|
150
|
+
);
|
|
151
|
+
expect(excerpt("a, not b", 1, 7)).toBe("a, not b");
|
|
152
|
+
});
|
|
153
|
+
});
|