paperlint 19.0.0 → 19.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/plugin.json +1 -1
- package/CLAUDE.md +2 -2
- package/dist/adapters/eslint/index.d.ts +13 -0
- package/dist/adapters/eslint/index.d.ts.map +1 -0
- package/dist/adapters/eslint/index.js +44 -0
- package/dist/adapters/eslint/index.js.map +1 -0
- package/dist/adapters/eslint/report.io.d.ts +15 -0
- package/dist/adapters/eslint/report.io.d.ts.map +1 -0
- package/dist/adapters/eslint/report.io.js +48 -0
- package/dist/adapters/eslint/report.io.js.map +1 -0
- package/dist/cli.d.ts +7 -12
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +73 -110
- package/dist/cli.js.map +1 -1
- package/dist/domain/submission-lint.d.ts +29 -0
- package/dist/domain/submission-lint.d.ts.map +1 -0
- package/dist/domain/submission-lint.js +84 -0
- package/dist/domain/submission-lint.js.map +1 -0
- package/dist/ports/submission-lint.d.ts +6 -0
- package/dist/ports/submission-lint.d.ts.map +1 -0
- package/dist/ports/submission-lint.js +2 -0
- package/dist/ports/submission-lint.js.map +1 -0
- package/dist/structure.d.ts +17 -1
- package/dist/structure.d.ts.map +1 -1
- package/dist/structure.js.map +1 -1
- package/dist/submission-confirm-hook.d.ts +8 -1
- package/dist/submission-confirm-hook.d.ts.map +1 -1
- package/dist/submission-confirm-hook.js +75 -20
- package/dist/submission-confirm-hook.js.map +1 -1
- package/dist/submission.d.ts +5 -0
- package/dist/submission.d.ts.map +1 -1
- package/dist/submission.js +46 -7
- package/dist/submission.js.map +1 -1
- package/dist/types.d.ts +2 -0
- package/dist/types.d.ts.map +1 -1
- package/docs/submission.md +19 -8
- package/eslint.config.mjs +2 -0
- package/package.json +1 -1
- package/scripts/eslint-file-length.mjs +117 -0
- package/src/adapters/eslint/index.test.ts +152 -0
- package/src/adapters/eslint/index.ts +89 -0
- package/src/adapters/eslint/report.io.ts +82 -0
- package/src/cli.ts +103 -134
- package/src/domain/submission-lint.test.ts +211 -0
- package/src/domain/submission-lint.ts +166 -0
- package/src/ports/submission-lint.ts +10 -0
- package/src/structure.ts +2 -4
- package/src/submission-confirm-hook-lint.test.ts +47 -0
- package/src/submission-confirm-hook.test.ts +73 -6
- package/src/submission-confirm-hook.ts +133 -28
- package/src/submission-fields-run.test.ts +1 -1
- package/src/submission-new.test.ts +4 -2
- package/src/submission-update.test.ts +16 -11
- package/src/submission.ts +62 -8
- package/src/types.ts +2 -0
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import type { ESLint } from "eslint";
|
|
2
|
+
import { relative } from "node:path";
|
|
3
|
+
import { flatMap, map, partition } from "remeda";
|
|
4
|
+
import { z } from "zod";
|
|
5
|
+
import { err, ok, type Result } from "../../domain/result.ts";
|
|
6
|
+
import {
|
|
7
|
+
lintFindingLine,
|
|
8
|
+
submissionLint,
|
|
9
|
+
type LintFinding,
|
|
10
|
+
type PaperSections,
|
|
11
|
+
} from "../../domain/submission-lint.ts";
|
|
12
|
+
import { messageOf } from "../../domain/text.ts";
|
|
13
|
+
import type { SubmissionLinter } from "../../ports/submission-lint.ts";
|
|
14
|
+
|
|
15
|
+
export {
|
|
16
|
+
LINT_FORMAT,
|
|
17
|
+
lintExitCode,
|
|
18
|
+
lintResultFor,
|
|
19
|
+
lintText,
|
|
20
|
+
printLintResults,
|
|
21
|
+
} from "./report.io.ts";
|
|
22
|
+
|
|
23
|
+
const lintFailure = z
|
|
24
|
+
.object({
|
|
25
|
+
messageTemplate: z.string().optional(),
|
|
26
|
+
message: z.string().optional(),
|
|
27
|
+
})
|
|
28
|
+
.catch({});
|
|
29
|
+
|
|
30
|
+
/** ESLint throws when the paths match no files or only ignored files. */
|
|
31
|
+
export function isEmptyLintSet(e: unknown): boolean {
|
|
32
|
+
const { messageTemplate, message } = lintFailure.parse(e);
|
|
33
|
+
return (
|
|
34
|
+
messageTemplate === "file-not-found" ||
|
|
35
|
+
messageTemplate === "all-matched-files-ignored" ||
|
|
36
|
+
message?.toLowerCase().includes("no files matching") === true
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** Translate ESLint's structured diagnostics at the adapter boundary. */
|
|
41
|
+
export function lintFindings(
|
|
42
|
+
results: readonly ESLint.LintResult[],
|
|
43
|
+
paperDir: string,
|
|
44
|
+
): Result<readonly LintFinding[], string> {
|
|
45
|
+
const [fatal, findings] = partition(
|
|
46
|
+
flatMap(results, ({ filePath, messages }) =>
|
|
47
|
+
map(messages, (m) => ({
|
|
48
|
+
...m,
|
|
49
|
+
file: relative(paperDir, filePath).replaceAll("\\", "/") || ".",
|
|
50
|
+
})),
|
|
51
|
+
),
|
|
52
|
+
(m) => m.fatal === true,
|
|
53
|
+
);
|
|
54
|
+
return fatal.length === 0
|
|
55
|
+
? ok(findings)
|
|
56
|
+
: err(map(fatal, lintFindingLine).join("\n"));
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export type OnLintResults = (results: readonly ESLint.LintResult[]) => void;
|
|
60
|
+
type RunPaperLint = (
|
|
61
|
+
paperDir: string,
|
|
62
|
+
cwd: string,
|
|
63
|
+
onResults: OnLintResults,
|
|
64
|
+
) => Promise<string>;
|
|
65
|
+
|
|
66
|
+
export const submissionLinter =
|
|
67
|
+
(
|
|
68
|
+
runLint: RunPaperLint,
|
|
69
|
+
sectionsOf: (paperDir: string) => PaperSections | null,
|
|
70
|
+
): SubmissionLinter =>
|
|
71
|
+
(paperDir, cwd) =>
|
|
72
|
+
new Promise((settle) => {
|
|
73
|
+
const accept: OnLintResults = (results) => {
|
|
74
|
+
const findings = lintFindings(results, paperDir);
|
|
75
|
+
settle(
|
|
76
|
+
findings.ok
|
|
77
|
+
? ok(submissionLint(findings.value, sectionsOf(paperDir)))
|
|
78
|
+
: findings,
|
|
79
|
+
);
|
|
80
|
+
};
|
|
81
|
+
void runLint(paperDir, cwd, accept).then(
|
|
82
|
+
(problem) => {
|
|
83
|
+
settle(err(problem || "paperlint lint did not produce a report"));
|
|
84
|
+
},
|
|
85
|
+
(e: unknown) => {
|
|
86
|
+
settle(err(messageOf(e)));
|
|
87
|
+
},
|
|
88
|
+
);
|
|
89
|
+
});
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { ESLint } from "eslint";
|
|
2
|
+
import { map, omit, sumBy } from "remeda";
|
|
3
|
+
|
|
4
|
+
export const LINT_FORMAT = "stylish";
|
|
5
|
+
|
|
6
|
+
export function lintResultFor(
|
|
7
|
+
file: string,
|
|
8
|
+
messages: readonly ESLint.LintResult["messages"][number][],
|
|
9
|
+
): Readonly<ESLint.LintResult> {
|
|
10
|
+
const errorCount = messages.filter((m) => m.severity === 2).length;
|
|
11
|
+
return {
|
|
12
|
+
filePath: file,
|
|
13
|
+
messages: [...messages],
|
|
14
|
+
suppressedMessages: [],
|
|
15
|
+
errorCount,
|
|
16
|
+
fatalErrorCount: 0,
|
|
17
|
+
warningCount: messages.length - errorCount,
|
|
18
|
+
fixableErrorCount: 0,
|
|
19
|
+
fixableWarningCount: 0,
|
|
20
|
+
usedDeprecatedRules: [],
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** Print the venue findings in the same format as the standalone lint command. */
|
|
25
|
+
export async function lintText(
|
|
26
|
+
file: string,
|
|
27
|
+
messages: readonly ESLint.LintResult["messages"][number][],
|
|
28
|
+
): Promise<string> {
|
|
29
|
+
return (await new ESLint().loadFormatter(LINT_FORMAT)).format([
|
|
30
|
+
lintResultFor(file, messages),
|
|
31
|
+
]);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
interface ReportFormat {
|
|
35
|
+
readonly json: boolean;
|
|
36
|
+
readonly structure: readonly ESLint.LintResult[];
|
|
37
|
+
readonly structureText: string;
|
|
38
|
+
readonly log: (line: string) => void;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export async function printLintResults(
|
|
42
|
+
eslint: ESLint,
|
|
43
|
+
results: readonly ESLint.LintResult[],
|
|
44
|
+
{ json, structure, structureText, log }: ReportFormat,
|
|
45
|
+
): Promise<boolean> {
|
|
46
|
+
if (json) {
|
|
47
|
+
log(
|
|
48
|
+
JSON.stringify(
|
|
49
|
+
[...structure, ...map(results, (r) => omit(r, ["stats"]))],
|
|
50
|
+
null,
|
|
51
|
+
1,
|
|
52
|
+
),
|
|
53
|
+
);
|
|
54
|
+
return false;
|
|
55
|
+
}
|
|
56
|
+
if (structure.length > 0) log(structureText);
|
|
57
|
+
const out = await (
|
|
58
|
+
await eslint.loadFormatter(LINT_FORMAT)
|
|
59
|
+
).format([...results]);
|
|
60
|
+
const clean = out.trim() === "" && structure.length === 0;
|
|
61
|
+
log(
|
|
62
|
+
out.trim() ||
|
|
63
|
+
(clean ? `✓ ${String(results.length)} file(s) checked, no findings` : ""),
|
|
64
|
+
);
|
|
65
|
+
return clean;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export function lintExitCode(
|
|
69
|
+
results: readonly ESLint.LintResult[],
|
|
70
|
+
hasStructureErrors: boolean,
|
|
71
|
+
maxWarnings: number,
|
|
72
|
+
err: (line: string) => void,
|
|
73
|
+
): number {
|
|
74
|
+
if (hasStructureErrors || results.some((r) => r.errorCount > 0)) return 1;
|
|
75
|
+
if (maxWarnings < 0) return 0;
|
|
76
|
+
const warnings = sumBy(results, (r) => r.warningCount);
|
|
77
|
+
if (!(warnings > maxWarnings)) return 0;
|
|
78
|
+
err(
|
|
79
|
+
`${String(warnings)} warning(s) exceed the --max-warnings limit of ${String(maxWarnings)}`,
|
|
80
|
+
);
|
|
81
|
+
return 1;
|
|
82
|
+
}
|
package/src/cli.ts
CHANGED
|
@@ -56,7 +56,7 @@ import {
|
|
|
56
56
|
paperBodies,
|
|
57
57
|
type PaperBody,
|
|
58
58
|
} from "./paper-includes.ts";
|
|
59
|
-
import { hasAtLeast
|
|
59
|
+
import { hasAtLeast } from "remeda";
|
|
60
60
|
import { refusalOf } from "./unowned-file.ts";
|
|
61
61
|
import { ruleTimes, timingLines } from "./lint-timing.ts";
|
|
62
62
|
import { prepareEngine } from "./build-engine.ts";
|
|
@@ -85,7 +85,6 @@ import {
|
|
|
85
85
|
pageLimitRules,
|
|
86
86
|
VENUE_RULE_LEVELS,
|
|
87
87
|
venueRules,
|
|
88
|
-
type VenueMessage,
|
|
89
88
|
} from "./venue-rules.ts";
|
|
90
89
|
import {
|
|
91
90
|
FORMAT_RULE_LEVELS,
|
|
@@ -121,7 +120,17 @@ import { BIB_RULE_LEVELS, bibRules } from "./bib-rules.ts";
|
|
|
121
120
|
import { bibliographyReader } from "./references.ts";
|
|
122
121
|
import { onlineReferences } from "./adapters/references/index.ts";
|
|
123
122
|
import { hotcrpSite } from "./adapters/hotcrp/index.ts";
|
|
124
|
-
import { runSubmission } from "./submission.ts";
|
|
123
|
+
import { runSubmission, submissionSections } from "./submission.ts";
|
|
124
|
+
import {
|
|
125
|
+
LINT_FORMAT,
|
|
126
|
+
isEmptyLintSet,
|
|
127
|
+
lintExitCode,
|
|
128
|
+
lintResultFor,
|
|
129
|
+
lintText,
|
|
130
|
+
printLintResults,
|
|
131
|
+
submissionLinter,
|
|
132
|
+
} from "./adapters/eslint/index.ts";
|
|
133
|
+
export { lintText } from "./adapters/eslint/index.ts";
|
|
125
134
|
import type { PortalKind, SupportedPortal } from "./domain/submission.ts";
|
|
126
135
|
import type { PortalSite } from "./ports/submission-portal.ts";
|
|
127
136
|
import type { CheckReferences } from "./ports/check-references.ts";
|
|
@@ -266,6 +275,7 @@ import {
|
|
|
266
275
|
import {
|
|
267
276
|
submissionConfirm,
|
|
268
277
|
UNREADABLE_INPUT,
|
|
278
|
+
type Send,
|
|
269
279
|
type Upload,
|
|
270
280
|
} from "./submission-confirm-hook.ts";
|
|
271
281
|
import { leafCommandsNormalized } from "vigiles/hook";
|
|
@@ -324,7 +334,7 @@ const USAGE = `paperlint — machine-checkable gates for a paper kept in git
|
|
|
324
334
|
into ~/.cache/paperlint/texlive (PAPERLINT_TEXLIVE_DIR overrides); a second
|
|
325
335
|
run does nothing. --check: report what is missing, change nothing
|
|
326
336
|
npx paperlint doctor say what is actually wired — and what only LOOKS wired
|
|
327
|
-
npx paperlint submission new [paper] [--abstract <file>] [--save]
|
|
337
|
+
npx paperlint submission new [paper] [--abstract <file>] [--save] [--allow-lint-errors <reason>]
|
|
328
338
|
create the paper's submission on the venue's portal: the title
|
|
329
339
|
and abstract from the build, the authors from paperlint.json,
|
|
330
340
|
the PDF. A DRY RUN unless --save; a save records the new id in
|
|
@@ -335,6 +345,7 @@ const USAGE = `paperlint — machine-checkable gates for a paper kept in git
|
|
|
335
345
|
whether it is the local paper.pdf (sha256); flags a title,
|
|
336
346
|
abstract or authors that are not the paper's
|
|
337
347
|
npx paperlint submission update [paper] [--pdf <file>] [--abstract <file>] [--submit] [--save]
|
|
348
|
+
[--allow-lint-errors <reason>]
|
|
338
349
|
send the PDF (default: the paper's own), the paper's title
|
|
339
350
|
and abstract each when the portal holds another (--abstract:
|
|
340
351
|
that file's text instead), or "submitted". A DRY RUN unless --save: the portal checks the
|
|
@@ -425,6 +436,7 @@ submission:
|
|
|
425
436
|
--pdf <file> the PDF to compare (show) or send (update) instead of the paper's own
|
|
426
437
|
--abstract <file> new, update: a plain-text file whose text is sent as the abstract
|
|
427
438
|
--submit update: mark the submission submitted
|
|
439
|
+
--allow-lint-errors <reason> permit reported lint errors on a submission --save
|
|
428
440
|
--save new, update: really create or change the submission. Without it, nothing
|
|
429
441
|
is saved
|
|
430
442
|
|
|
@@ -1329,6 +1341,7 @@ const STRING_FLAGS: ReadonlyMap<
|
|
|
1329
1341
|
| "kind"
|
|
1330
1342
|
| "pdf"
|
|
1331
1343
|
| "abstract"
|
|
1344
|
+
| "allowLintErrors"
|
|
1332
1345
|
| "url"
|
|
1333
1346
|
| "host"
|
|
1334
1347
|
| "to"
|
|
@@ -1340,6 +1353,7 @@ const STRING_FLAGS: ReadonlyMap<
|
|
|
1340
1353
|
["--kind", "kind"],
|
|
1341
1354
|
["--pdf", "pdf"],
|
|
1342
1355
|
["--abstract", "abstract"],
|
|
1356
|
+
["--allow-lint-errors", "allowLintErrors"],
|
|
1343
1357
|
["--url", "url"],
|
|
1344
1358
|
["--host", "host"],
|
|
1345
1359
|
["--to", "to"],
|
|
@@ -1478,7 +1492,7 @@ const IN_PROCESS_HOOKS: Readonly<
|
|
|
1478
1492
|
},
|
|
1479
1493
|
// Never advisory-silent: an input it cannot read is refused, not let through.
|
|
1480
1494
|
"submission-confirm": ({ stdin, out }) => {
|
|
1481
|
-
const said = (()
|
|
1495
|
+
const said = (() => {
|
|
1482
1496
|
try {
|
|
1483
1497
|
return submissionConfirm(stdin(), {
|
|
1484
1498
|
...PRESET_DEPS,
|
|
@@ -1486,13 +1500,17 @@ const IN_PROCESS_HOOKS: Readonly<
|
|
|
1486
1500
|
shellLeaves: leafCommandsNormalized,
|
|
1487
1501
|
readSend: submissionSend,
|
|
1488
1502
|
readUpload: uploadSend,
|
|
1503
|
+
lintPaper: lintSubmissionPaper,
|
|
1489
1504
|
});
|
|
1490
1505
|
} catch {
|
|
1491
1506
|
return UNREADABLE_INPUT;
|
|
1492
1507
|
}
|
|
1493
1508
|
})();
|
|
1494
|
-
|
|
1495
|
-
|
|
1509
|
+
const write = (result: Awaited<typeof said>) => {
|
|
1510
|
+
if (result !== null) out(`${JSON.stringify(result)}\n`);
|
|
1511
|
+
return 0;
|
|
1512
|
+
};
|
|
1513
|
+
return said instanceof Promise ? said.then(write) : write(said);
|
|
1496
1514
|
},
|
|
1497
1515
|
};
|
|
1498
1516
|
|
|
@@ -1502,17 +1520,48 @@ const IN_PROCESS_HOOKS: Readonly<
|
|
|
1502
1520
|
* (a flag missing its value, an unknown flag, a stray operand), so `submission-confirm` says it
|
|
1503
1521
|
* cannot tell rather than guess.
|
|
1504
1522
|
*/
|
|
1505
|
-
export function submissionSend(
|
|
1506
|
-
words: readonly string[],
|
|
1507
|
-
): { readonly paper: string | null; readonly pdf: string | null } | null {
|
|
1523
|
+
export function submissionSend(words: readonly string[]): Send | null {
|
|
1508
1524
|
const a = parseArgs(["submission", ...words]);
|
|
1509
1525
|
const clean =
|
|
1510
1526
|
a.missingValue === undefined &&
|
|
1511
1527
|
a.unknownFlag === undefined &&
|
|
1512
1528
|
a.paths.length <= 2;
|
|
1513
|
-
return clean
|
|
1529
|
+
return clean
|
|
1530
|
+
? {
|
|
1531
|
+
paper: a.paths[1] ?? null,
|
|
1532
|
+
pdf: a.pdf,
|
|
1533
|
+
action:
|
|
1534
|
+
a.paths[0] === "new" ? "create" : a.submit ? "submit" : "update",
|
|
1535
|
+
allowLintErrors: a.allowLintErrors?.trim(),
|
|
1536
|
+
}
|
|
1537
|
+
: null;
|
|
1514
1538
|
}
|
|
1515
1539
|
|
|
1540
|
+
const lintSubmissionPaper = submissionLinter(
|
|
1541
|
+
async (paperDir, cwd, accept) => {
|
|
1542
|
+
const stderr = collector();
|
|
1543
|
+
await run(["lint", paperDir], {
|
|
1544
|
+
cwd,
|
|
1545
|
+
log: () => {},
|
|
1546
|
+
err: (line: string) => {
|
|
1547
|
+
stderr.write(`${line}\n`);
|
|
1548
|
+
},
|
|
1549
|
+
onLintResults: (results, structure) => {
|
|
1550
|
+
accept([
|
|
1551
|
+
...asEslintResults(structure).map((r) => ({
|
|
1552
|
+
...r,
|
|
1553
|
+
filePath: resolve(cwd, r.filePath),
|
|
1554
|
+
})),
|
|
1555
|
+
...results,
|
|
1556
|
+
]);
|
|
1557
|
+
},
|
|
1558
|
+
});
|
|
1559
|
+
return firstLine(stderr.text());
|
|
1560
|
+
},
|
|
1561
|
+
(paperDir) =>
|
|
1562
|
+
submissionSections(paperDir, { ...RECORD_DEPS, latex: latexReader }),
|
|
1563
|
+
);
|
|
1564
|
+
|
|
1516
1565
|
/**
|
|
1517
1566
|
* The words after `artifact`, read by this CLI's own parser, for an upload: the file it uploads, the
|
|
1518
1567
|
* paper (null for the current folder), and the host and project it goes to — or null when they would
|
|
@@ -2326,6 +2375,7 @@ const SIMPLE: Readonly<
|
|
|
2326
2375
|
abstract: a.abstract,
|
|
2327
2376
|
submit: a.submit,
|
|
2328
2377
|
save: a.save,
|
|
2378
|
+
allowLintErrors: a.allowLintErrors ?? undefined,
|
|
2329
2379
|
},
|
|
2330
2380
|
{
|
|
2331
2381
|
files: nodeFiles,
|
|
@@ -2336,6 +2386,7 @@ const SIMPLE: Readonly<
|
|
|
2336
2386
|
latex: latexReader,
|
|
2337
2387
|
codec: sourcesCodec,
|
|
2338
2388
|
lintText,
|
|
2389
|
+
lintPaper: lintSubmissionPaper,
|
|
2339
2390
|
yaml: parseYaml,
|
|
2340
2391
|
now: isoNow,
|
|
2341
2392
|
log,
|
|
@@ -2520,6 +2571,25 @@ const selfInstallDeps = (install: ProjectInstall): SelfInstallDeps => {
|
|
|
2520
2571
|
const loadLatexLanguage = async (): Promise<unknown> =>
|
|
2521
2572
|
(await import("#eslint-rules/latex-language")).texLanguage;
|
|
2522
2573
|
|
|
2574
|
+
type LintResults = (
|
|
2575
|
+
results: readonly ESLint.LintResult[],
|
|
2576
|
+
structure: Readonly<ReturnType<typeof checkStructure>>,
|
|
2577
|
+
) => void;
|
|
2578
|
+
|
|
2579
|
+
/** A missing flag value must be reported before falling back to any default. */
|
|
2580
|
+
function argumentProblem(a: Args): string | null {
|
|
2581
|
+
if (a.missingValue)
|
|
2582
|
+
return (
|
|
2583
|
+
`${a.missingValue} needs a value — it was given none.\n` +
|
|
2584
|
+
`Without it the run would silently fall back to whatever config it discovers, which is not what the command line said.`
|
|
2585
|
+
);
|
|
2586
|
+
if (a.unknownFlag !== undefined)
|
|
2587
|
+
return `unknown flag \`${a.unknownFlag}\` — \`paperlint --help\` lists every flag`;
|
|
2588
|
+
return !a.help && a.cmd && a.cmd !== "submission" && a.allowLintErrors != null
|
|
2589
|
+
? "--allow-lint-errors is only for submission new or update with --save"
|
|
2590
|
+
: null;
|
|
2591
|
+
}
|
|
2592
|
+
|
|
2523
2593
|
export async function run(
|
|
2524
2594
|
argv: readonly string[],
|
|
2525
2595
|
{
|
|
@@ -2532,6 +2602,7 @@ export async function run(
|
|
|
2532
2602
|
skillLinks = readSkillLinks,
|
|
2533
2603
|
install = projectInstall,
|
|
2534
2604
|
claude = claudeCode(),
|
|
2605
|
+
onLintResults,
|
|
2535
2606
|
}: {
|
|
2536
2607
|
log?: typeof console.log;
|
|
2537
2608
|
err?: typeof console.error;
|
|
@@ -2554,26 +2625,12 @@ export async function run(
|
|
|
2554
2625
|
checkReferences?: CheckReferences;
|
|
2555
2626
|
/** The skills report `lint`'s stderr line reads; a test hands a fixed one. */
|
|
2556
2627
|
skillLinks?: (root: string) => LinkReport;
|
|
2628
|
+
onLintResults?: LintResults;
|
|
2557
2629
|
} = {},
|
|
2558
2630
|
): Promise<number> {
|
|
2559
2631
|
const a = parseArgs(argv);
|
|
2560
|
-
|
|
2561
|
-
|
|
2562
|
-
// than what was asked for.
|
|
2563
|
-
if (a.missingValue) {
|
|
2564
|
-
err(
|
|
2565
|
-
`${a.missingValue} needs a value — it was given none.\n` +
|
|
2566
|
-
`Without it the run would silently fall back to whatever config it discovers, which is ` +
|
|
2567
|
-
`not what the command line said.`,
|
|
2568
|
-
);
|
|
2569
|
-
return 2;
|
|
2570
|
-
}
|
|
2571
|
-
if (a.unknownFlag !== undefined) {
|
|
2572
|
-
err(
|
|
2573
|
-
`unknown flag \`${a.unknownFlag}\` — \`paperlint --help\` lists every flag`,
|
|
2574
|
-
);
|
|
2575
|
-
return 2;
|
|
2576
|
-
}
|
|
2632
|
+
const problem = argumentProblem(a);
|
|
2633
|
+
if (problem !== null) return (err(problem), 2);
|
|
2577
2634
|
if (a.help || !a.cmd) {
|
|
2578
2635
|
log(USAGE);
|
|
2579
2636
|
return a.help ? 0 : 2;
|
|
@@ -2683,7 +2740,7 @@ export async function run(
|
|
|
2683
2740
|
try {
|
|
2684
2741
|
results = await eslint.lintFiles(paths);
|
|
2685
2742
|
} catch (e) {
|
|
2686
|
-
if (
|
|
2743
|
+
if (isEmptyLintSet(e)) results = [];
|
|
2687
2744
|
else throw e;
|
|
2688
2745
|
}
|
|
2689
2746
|
|
|
@@ -2713,6 +2770,7 @@ export async function run(
|
|
|
2713
2770
|
.map((d) => join(d, MAIN))
|
|
2714
2771
|
.filter((f) => existsSync(f)),
|
|
2715
2772
|
bodies,
|
|
2773
|
+
onLintResults,
|
|
2716
2774
|
});
|
|
2717
2775
|
hooksLine(root, err, skillLinks, claude);
|
|
2718
2776
|
// On stderr, so `--json` leaves stdout a clean array.
|
|
@@ -2833,25 +2891,11 @@ const editLinter =
|
|
|
2833
2891
|
};
|
|
2834
2892
|
|
|
2835
2893
|
/** A result of the hook's new errors, with the counts the formatter prints recomputed. */
|
|
2836
|
-
const counted = (r: LintResult): Readonly<ESLint.LintResult> =>
|
|
2837
|
-
|
|
2838
|
-
|
|
2839
|
-
|
|
2840
|
-
|
|
2841
|
-
message: m.message,
|
|
2842
|
-
line: m.line,
|
|
2843
|
-
column: m.column,
|
|
2844
|
-
endLine: m.endLine,
|
|
2845
|
-
severity: 2,
|
|
2846
|
-
})),
|
|
2847
|
-
suppressedMessages: [],
|
|
2848
|
-
errorCount: r.messages.length,
|
|
2849
|
-
fatalErrorCount: 0,
|
|
2850
|
-
warningCount: 0,
|
|
2851
|
-
fixableErrorCount: 0,
|
|
2852
|
-
fixableWarningCount: 0,
|
|
2853
|
-
usedDeprecatedRules: [],
|
|
2854
|
-
});
|
|
2894
|
+
const counted = (r: LintResult): Readonly<ESLint.LintResult> =>
|
|
2895
|
+
lintResultFor(
|
|
2896
|
+
r.filePath,
|
|
2897
|
+
r.messages.map((m) => ({ ...m, severity: 2 })),
|
|
2898
|
+
);
|
|
2855
2899
|
|
|
2856
2900
|
/**
|
|
2857
2901
|
* The first path that is a FILE paperlint does not lint, or null. ESLint would answer such a file
|
|
@@ -2873,54 +2917,6 @@ async function firstUnownedFile(
|
|
|
2873
2917
|
return null;
|
|
2874
2918
|
}
|
|
2875
2919
|
|
|
2876
|
-
/**
|
|
2877
|
-
* ESLint's refusals of an empty set: nothing matched (`file-not-found`), or everything that matched
|
|
2878
|
-
* is outside paperlint's scope (`all-matched-files-ignored` — a papers directory holding only
|
|
2879
|
-
* vendored scripts). Both mean "nothing was linted", which the caller reports itself.
|
|
2880
|
-
*/
|
|
2881
|
-
/** What a thrown ESLint error says about itself; anything else thrown says nothing. */
|
|
2882
|
-
const EslintFailure = z
|
|
2883
|
-
.object({
|
|
2884
|
-
messageTemplate: z.string().optional(),
|
|
2885
|
-
message: z.string().optional(),
|
|
2886
|
-
})
|
|
2887
|
-
.catch({});
|
|
2888
|
-
|
|
2889
|
-
const isEmptySet = (e: unknown): boolean => {
|
|
2890
|
-
const fail = EslintFailure.parse(e);
|
|
2891
|
-
return (
|
|
2892
|
-
fail.messageTemplate === "file-not-found" ||
|
|
2893
|
-
fail.messageTemplate === "all-matched-files-ignored" ||
|
|
2894
|
-
/No files matching/i.test(String(fail.message))
|
|
2895
|
-
);
|
|
2896
|
-
};
|
|
2897
|
-
|
|
2898
|
-
/**
|
|
2899
|
-
* Findings on one file, printed by the formatter `paperlint lint` prints with — what `paperlint
|
|
2900
|
-
* submission` shows of the venue rules before a send, so the two read the same.
|
|
2901
|
-
*/
|
|
2902
|
-
export async function lintText(
|
|
2903
|
-
file: string,
|
|
2904
|
-
messages: readonly VenueMessage[],
|
|
2905
|
-
): Promise<string> {
|
|
2906
|
-
const errorCount = messages.filter((m) => m.severity === 2).length;
|
|
2907
|
-
const result: Readonly<ESLint.LintResult> = {
|
|
2908
|
-
filePath: file,
|
|
2909
|
-
messages: [...messages],
|
|
2910
|
-
suppressedMessages: [],
|
|
2911
|
-
errorCount,
|
|
2912
|
-
fatalErrorCount: 0,
|
|
2913
|
-
warningCount: messages.length - errorCount,
|
|
2914
|
-
fixableErrorCount: 0,
|
|
2915
|
-
fixableWarningCount: 0,
|
|
2916
|
-
usedDeprecatedRules: [],
|
|
2917
|
-
};
|
|
2918
|
-
return (await new ESLint().loadFormatter(LINT_FORMAT)).format([result]);
|
|
2919
|
-
}
|
|
2920
|
-
|
|
2921
|
-
/** The formatter `paperlint lint` prints with. */
|
|
2922
|
-
const LINT_FORMAT = "stylish";
|
|
2923
|
-
|
|
2924
2920
|
/** Printed under a clean `lint`, the README's disclaimer in one line. */
|
|
2925
2921
|
const CLEAN_RUN_REMINDER =
|
|
2926
2922
|
"Check the venue's own call before you submit: a call can change between editions, and a check can miss a case.";
|
|
@@ -2932,7 +2928,7 @@ const CLEAN_RUN_REMINDER =
|
|
|
2932
2928
|
async function reportLint(
|
|
2933
2929
|
eslint: ESLint,
|
|
2934
2930
|
results: ESLint.LintResult[],
|
|
2935
|
-
structure: ReturnType<typeof checkStructure
|
|
2931
|
+
structure: Readonly<ReturnType<typeof checkStructure>>,
|
|
2936
2932
|
{
|
|
2937
2933
|
a,
|
|
2938
2934
|
log,
|
|
@@ -2941,6 +2937,7 @@ async function reportLint(
|
|
|
2941
2937
|
opts,
|
|
2942
2938
|
projectPapers,
|
|
2943
2939
|
bodies,
|
|
2940
|
+
onLintResults,
|
|
2944
2941
|
}: {
|
|
2945
2942
|
a: Args;
|
|
2946
2943
|
log: typeof console.log;
|
|
@@ -2950,6 +2947,7 @@ async function reportLint(
|
|
|
2950
2947
|
projectPapers: readonly string[];
|
|
2951
2948
|
/** The body files handed to ESLint, as read before the run. */
|
|
2952
2949
|
bodies: readonly PaperBody[];
|
|
2950
|
+
onLintResults: LintResults | undefined;
|
|
2953
2951
|
},
|
|
2954
2952
|
): Promise<number> {
|
|
2955
2953
|
const silent = await silentOptionalRules(
|
|
@@ -2966,46 +2964,17 @@ async function reportLint(
|
|
|
2966
2964
|
return 1;
|
|
2967
2965
|
}
|
|
2968
2966
|
|
|
2969
|
-
if (
|
|
2970
|
-
log(
|
|
2971
|
-
JSON.stringify(
|
|
2972
|
-
[
|
|
2973
|
-
...asEslintResults(structure),
|
|
2974
|
-
...results.map((r) => omit(r, ["stats"])),
|
|
2975
|
-
],
|
|
2976
|
-
null,
|
|
2977
|
-
1,
|
|
2978
|
-
),
|
|
2979
|
-
);
|
|
2967
|
+
if (onLintResults !== undefined) onLintResults(results, structure);
|
|
2980
2968
|
else {
|
|
2981
|
-
|
|
2982
|
-
|
|
2983
|
-
|
|
2984
|
-
|
|
2985
|
-
|
|
2986
|
-
|
|
2987
|
-
out.trim() ||
|
|
2988
|
-
(clean
|
|
2989
|
-
? `✓ ${String(results.length)} file(s) checked, no findings`
|
|
2990
|
-
: ""),
|
|
2991
|
-
);
|
|
2992
|
-
// A clean run is the one result a reader could take as a guarantee, so it, and only it,
|
|
2993
|
-
// carries the README's reminder. Findings speak for themselves; --json is for machines.
|
|
2969
|
+
const clean = await printLintResults(eslint, results, {
|
|
2970
|
+
json: a.json,
|
|
2971
|
+
structure: asEslintResults(structure),
|
|
2972
|
+
structureText: formatStructure(structure),
|
|
2973
|
+
log,
|
|
2974
|
+
});
|
|
2994
2975
|
if (clean) log(` ${CLEAN_RUN_REMINDER}`);
|
|
2995
2976
|
}
|
|
2996
|
-
|
|
2997
|
-
// Warnings fail the run only when the threshold is named EXPLICITLY. A negative threshold means
|
|
2998
|
-
// "do not count them at all", and that is the default.
|
|
2999
|
-
if (a.maxWarnings >= 0) {
|
|
3000
|
-
const warnings = results.reduce((n, r) => n + r.warningCount, 0);
|
|
3001
|
-
if (warnings > a.maxWarnings) {
|
|
3002
|
-
err(
|
|
3003
|
-
`${String(warnings)} warning(s) exceed the --max-warnings limit of ${String(a.maxWarnings)}`,
|
|
3004
|
-
);
|
|
3005
|
-
return 1;
|
|
3006
|
-
}
|
|
3007
|
-
}
|
|
3008
|
-
return 0;
|
|
2977
|
+
return lintExitCode(results, structure.length > 0, a.maxWarnings, err);
|
|
3009
2978
|
}
|
|
3010
2979
|
|
|
3011
2980
|
// 🔴 `isMain`, NOT A STRING COMPARISON. The first version wrote
|