paperlint 19.0.0 → 19.0.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/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 +80 -121
- 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/folder-layout-hook.js +1 -1
- package/dist/hooks-notice.d.ts +2 -0
- package/dist/hooks-notice.d.ts.map +1 -1
- package/dist/hooks-notice.js +4 -1
- package/dist/hooks-notice.js.map +1 -1
- 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/install.md +4 -4
- package/docs/layout.md +0 -1
- package/docs/submission.md +19 -8
- package/eslint.config.mjs +2 -0
- package/hooks/hooks.harness.ts +2 -140
- package/hooks/paper-skills-nudge.hook.mjs +0 -6
- package/lib/paper-config.harness.mjs +1 -2
- package/package.json +1 -1
- package/plugin/hooks/hooks.json +0 -9
- 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.harness.mjs +9 -8
- package/src/cli.test.ts +4 -4
- package/src/cli.ts +110 -144
- package/src/domain/submission-lint.test.ts +211 -0
- package/src/domain/submission-lint.ts +166 -0
- package/src/folder-layout-hook.ts +1 -1
- package/src/hooks-notice.test.ts +2 -2
- package/src/hooks-notice.ts +10 -1
- package/src/hooks-settings.harness.ts +8 -8
- 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
- package/hooks/paper-status-gates.hook.mjs +0 -158
- package/hooks/paper-status-gates.sh +0 -93
- package/hooks/paper-status-gates.test.ts +0 -101
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
// JavaScript, not TypeScript: config-loader — ESLint loads this fragment before repository TypeScript tooling.
|
|
2
|
+
const fileLength = { max: 300, skipBlankLines: true, skipComments: true };
|
|
3
|
+
|
|
4
|
+
// Existing files keep a measured ceiling. Lower it when the file shrinks,
|
|
5
|
+
// and remove the entry when it fits the common limit.
|
|
6
|
+
const legacyCeilings = {
|
|
7
|
+
"eslint-rules/latex-language.harness.mjs": 416,
|
|
8
|
+
"eslint-rules/latex-language.ts": 610,
|
|
9
|
+
"eslint-rules/paper-stages.ts": 313,
|
|
10
|
+
"eslint-rules/paper-typography.test.mjs": 420,
|
|
11
|
+
"eslint-rules/paper-typography.ts": 397,
|
|
12
|
+
"eslint-rules/prereg-coverage.test.ts": 407,
|
|
13
|
+
"eslint-rules/prereg-coverage.ts": 320,
|
|
14
|
+
"eslint-rules/tex-build.harness.mjs": 535,
|
|
15
|
+
"eslint.config.mjs": 622,
|
|
16
|
+
"hooks/hooks.harness.ts": 382,
|
|
17
|
+
"scripts/coverage-config.test.ts": 376,
|
|
18
|
+
"scripts/pipeline.ts": 380,
|
|
19
|
+
"src/adapters/git/history.test.ts": 327,
|
|
20
|
+
"src/adapters/git/index.test.ts": 327,
|
|
21
|
+
"src/adapters/git/index.ts": 301,
|
|
22
|
+
"src/adapters/hotcrp/portal.test.ts": 684,
|
|
23
|
+
"src/adapters/latex/index.test.ts": 1001,
|
|
24
|
+
"src/adapters/latex/prose.ts": 472,
|
|
25
|
+
"src/adapters/references/index.test.ts": 537,
|
|
26
|
+
"src/adapters/study-registry/index.test.ts": 450,
|
|
27
|
+
"src/adapters/study-registry/index.ts": 539,
|
|
28
|
+
"src/artifact.test.ts": 451,
|
|
29
|
+
"src/artifact.ts": 332,
|
|
30
|
+
"src/bib-rules.test.ts": 324,
|
|
31
|
+
"src/build.harness.mjs": 604,
|
|
32
|
+
"src/build.test.ts": 583,
|
|
33
|
+
"src/build.ts": 689,
|
|
34
|
+
"src/claim-provenance.test.ts": 342,
|
|
35
|
+
"src/cli.harness.mjs": 1628,
|
|
36
|
+
"src/cli.test.ts": 1420,
|
|
37
|
+
"src/cli.ts": 2321,
|
|
38
|
+
"src/domain/body-pages.test.ts": 418,
|
|
39
|
+
"src/domain/cycle.test.ts": 532,
|
|
40
|
+
"src/domain/cycle.ts": 357,
|
|
41
|
+
"src/domain/deadline.test.ts": 380,
|
|
42
|
+
"src/domain/deadline.ts": 358,
|
|
43
|
+
"src/domain/decide-first.test.ts": 497,
|
|
44
|
+
"src/domain/decide-first.ts": 306,
|
|
45
|
+
"src/domain/heading-case.test.ts": 593,
|
|
46
|
+
"src/domain/heading-case.ts": 360,
|
|
47
|
+
"src/domain/study-measurements.test.ts": 700,
|
|
48
|
+
"src/domain/study-registry.test.ts": 656,
|
|
49
|
+
"src/domain/study-registry.ts": 995,
|
|
50
|
+
"src/domain/submission-fields.test.ts": 342,
|
|
51
|
+
"src/domain/submission-fields.ts": 304,
|
|
52
|
+
"src/domain/versions-migration.test.ts": 407,
|
|
53
|
+
"src/domain/versions-migration.ts": 324,
|
|
54
|
+
"src/domain/versions.test.ts": 539,
|
|
55
|
+
"src/domain/versions.ts": 536,
|
|
56
|
+
"src/facts-file.test.ts": 449,
|
|
57
|
+
"src/facts-file.ts": 337,
|
|
58
|
+
"src/heading-case.test.ts": 460,
|
|
59
|
+
"src/hooks-notice.test.ts": 578,
|
|
60
|
+
"src/hooks-settings.harness.ts": 331,
|
|
61
|
+
"src/hooks-settings.ts": 330,
|
|
62
|
+
"src/init.test.ts": 622,
|
|
63
|
+
"src/init.ts": 828,
|
|
64
|
+
"src/latex-log.harness.ts": 328,
|
|
65
|
+
"src/latex-loop.harness.ts": 463,
|
|
66
|
+
"src/lint-edited-hook.test.ts": 542,
|
|
67
|
+
"src/new-paper.test.ts": 783,
|
|
68
|
+
"src/outputs-before-decision-rule.test.ts": 406,
|
|
69
|
+
"src/paper-files.test.ts": 436,
|
|
70
|
+
"src/paper-includes.test.ts": 321,
|
|
71
|
+
"src/paper-settings-commands.test.ts": 318,
|
|
72
|
+
"src/paper-settings.test.ts": 519,
|
|
73
|
+
"src/pdf-facts.ts": 343,
|
|
74
|
+
"src/presets.test.ts": 1238,
|
|
75
|
+
"src/presets.ts": 505,
|
|
76
|
+
"src/readability.test.ts": 331,
|
|
77
|
+
"src/references.test.ts": 715,
|
|
78
|
+
"src/register-bands.test.ts": 353,
|
|
79
|
+
"src/rule-cases.test.ts": 1888,
|
|
80
|
+
"src/studies.test.ts": 354,
|
|
81
|
+
"src/study-gate.test.ts": 420,
|
|
82
|
+
"src/study-registry-rule.test.ts": 712,
|
|
83
|
+
"src/submission-confirm-hook.test.ts": 887,
|
|
84
|
+
"src/submission-confirm-hook.ts": 604,
|
|
85
|
+
"src/submission-fields-run.test.ts": 318,
|
|
86
|
+
"src/submission-freeze.test.ts": 336,
|
|
87
|
+
"src/submission-new.test.ts": 585,
|
|
88
|
+
"src/submission-update.test.ts": 434,
|
|
89
|
+
"src/submission.test.ts": 327,
|
|
90
|
+
"src/submission.ts": 1155,
|
|
91
|
+
"src/talk-rules.test.ts": 427,
|
|
92
|
+
"src/talk-rules.ts": 562,
|
|
93
|
+
"src/tex-requirements.ts": 482,
|
|
94
|
+
"src/tex-venue-rules.test.ts": 2152,
|
|
95
|
+
"src/tex-venue-rules.ts": 695,
|
|
96
|
+
"src/toolchain.harness.mjs": 616,
|
|
97
|
+
"src/toolchain.ts": 605,
|
|
98
|
+
"src/venue-rules.test.ts": 1684,
|
|
99
|
+
"src/venue-rules.ts": 807,
|
|
100
|
+
"src/versions-approve.test.ts": 326,
|
|
101
|
+
"src/versions-command.test.ts": 552,
|
|
102
|
+
"src/versions-command.ts": 306,
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
export default [
|
|
106
|
+
{
|
|
107
|
+
files: [
|
|
108
|
+
"{bin,eslint-rules,hooks,lib,scripts,src}/**/*.{js,cjs,mjs,ts,cts,mts}",
|
|
109
|
+
"*.{js,cjs,mjs,ts,cts,mts}",
|
|
110
|
+
],
|
|
111
|
+
rules: { "max-lines": ["error", fileLength] },
|
|
112
|
+
},
|
|
113
|
+
...Object.entries(legacyCeilings).map(([file, max]) => ({
|
|
114
|
+
files: [file],
|
|
115
|
+
rules: { "max-lines": ["error", { ...fileLength, max }] },
|
|
116
|
+
})),
|
|
117
|
+
];
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import type { ESLint, Linter } from "eslint";
|
|
2
|
+
import { expect, test } from "vitest";
|
|
3
|
+
import { err, ok } from "../../domain/result.ts";
|
|
4
|
+
import {
|
|
5
|
+
isEmptyLintSet,
|
|
6
|
+
lintFindings,
|
|
7
|
+
submissionLinter,
|
|
8
|
+
type OnLintResults,
|
|
9
|
+
} from "./index.ts";
|
|
10
|
+
|
|
11
|
+
const paperDir = "/work/paper";
|
|
12
|
+
const result = (
|
|
13
|
+
filePath: string,
|
|
14
|
+
messages: readonly Linter.LintMessage[],
|
|
15
|
+
): ESLint.LintResult => ({
|
|
16
|
+
filePath,
|
|
17
|
+
messages: [...messages],
|
|
18
|
+
suppressedMessages: [],
|
|
19
|
+
errorCount: 0,
|
|
20
|
+
fatalErrorCount: 0,
|
|
21
|
+
warningCount: 0,
|
|
22
|
+
fixableErrorCount: 0,
|
|
23
|
+
fixableWarningCount: 0,
|
|
24
|
+
usedDeprecatedRules: [],
|
|
25
|
+
});
|
|
26
|
+
const warning: Linter.LintMessage = {
|
|
27
|
+
ruleId: "tex/example",
|
|
28
|
+
severity: 1,
|
|
29
|
+
message: "a warning",
|
|
30
|
+
line: 3,
|
|
31
|
+
column: 2,
|
|
32
|
+
};
|
|
33
|
+
const fatal: Linter.LintMessage = {
|
|
34
|
+
ruleId: null,
|
|
35
|
+
severity: 2,
|
|
36
|
+
fatal: true,
|
|
37
|
+
message: "Parsing error",
|
|
38
|
+
line: 5,
|
|
39
|
+
column: 1,
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
test("a finding's file is relative to the paper directory, with forward slashes, or a dot for the directory itself", () => {
|
|
43
|
+
const found = lintFindings(
|
|
44
|
+
[
|
|
45
|
+
result(`${paperDir}/sections/intro.tex`, [warning]),
|
|
46
|
+
result("/work/paper/sections\\win.tex", [warning]),
|
|
47
|
+
result(paperDir, [warning]),
|
|
48
|
+
],
|
|
49
|
+
paperDir,
|
|
50
|
+
);
|
|
51
|
+
expect(found).toStrictEqual(
|
|
52
|
+
ok([
|
|
53
|
+
{ ...warning, file: "sections/intro.tex" },
|
|
54
|
+
{ ...warning, file: "sections/win.tex" },
|
|
55
|
+
{ ...warning, file: "." },
|
|
56
|
+
]),
|
|
57
|
+
);
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
test("a fatal message makes the whole lint fail, one line per fatal message", () => {
|
|
61
|
+
const found = lintFindings(
|
|
62
|
+
[
|
|
63
|
+
result(`${paperDir}/a.tex`, [warning, fatal]),
|
|
64
|
+
result(`${paperDir}/b.tex`, [{ ...fatal, line: 9, message: "Broken" }]),
|
|
65
|
+
],
|
|
66
|
+
paperDir,
|
|
67
|
+
);
|
|
68
|
+
expect(found).toStrictEqual(
|
|
69
|
+
err("a.tex:5:1 — Parsing error\nb.tex:9:1 — Broken"),
|
|
70
|
+
);
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
test("the linter reports the lint of what the run produced", async () => {
|
|
74
|
+
const lint = submissionLinter(
|
|
75
|
+
(_dir, _cwd, onResults: OnLintResults) => {
|
|
76
|
+
onResults([result(`${paperDir}/a.tex`, [warning])]);
|
|
77
|
+
return Promise.resolve("");
|
|
78
|
+
},
|
|
79
|
+
() => null,
|
|
80
|
+
);
|
|
81
|
+
expect(await lint(paperDir, "/work")).toStrictEqual(
|
|
82
|
+
ok({
|
|
83
|
+
errors: [],
|
|
84
|
+
warnings: [{ ...warning, file: "a.tex" }],
|
|
85
|
+
abstractWarnings: [],
|
|
86
|
+
introductionWarnings: [],
|
|
87
|
+
}),
|
|
88
|
+
);
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
test("the linter passes the paper and the working directory to the run", async () => {
|
|
92
|
+
const seen: (readonly [string, string])[] = [];
|
|
93
|
+
const lint = submissionLinter(
|
|
94
|
+
(dir, cwd, onResults) => {
|
|
95
|
+
seen.push([dir, cwd]);
|
|
96
|
+
onResults([]);
|
|
97
|
+
return Promise.resolve("");
|
|
98
|
+
},
|
|
99
|
+
() => null,
|
|
100
|
+
);
|
|
101
|
+
await lint(paperDir, "/elsewhere");
|
|
102
|
+
expect(seen).toStrictEqual([[paperDir, "/elsewhere"]]);
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
test("a fatal message in the run's results is the linter's failure", async () => {
|
|
106
|
+
const lint = submissionLinter(
|
|
107
|
+
(_dir, _cwd, onResults) => {
|
|
108
|
+
onResults([result(`${paperDir}/a.tex`, [fatal])]);
|
|
109
|
+
return Promise.resolve("");
|
|
110
|
+
},
|
|
111
|
+
() => null,
|
|
112
|
+
);
|
|
113
|
+
expect(await lint(paperDir, "/work")).toStrictEqual(
|
|
114
|
+
err("a.tex:5:1 — Parsing error"),
|
|
115
|
+
);
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
test("a run that ends with a problem and no report is the linter's failure with that problem", async () => {
|
|
119
|
+
const lint = submissionLinter(
|
|
120
|
+
() => Promise.resolve("no config found"),
|
|
121
|
+
() => null,
|
|
122
|
+
);
|
|
123
|
+
expect(await lint(paperDir, "/work")).toStrictEqual(err("no config found"));
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
test("a run that ends silently without a report fails, and says so", async () => {
|
|
127
|
+
const lint = submissionLinter(
|
|
128
|
+
() => Promise.resolve(""),
|
|
129
|
+
() => null,
|
|
130
|
+
);
|
|
131
|
+
expect(await lint(paperDir, "/work")).toStrictEqual(
|
|
132
|
+
err("paperlint lint did not produce a report"),
|
|
133
|
+
);
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
test("a run that throws is the linter's failure with the error's message", async () => {
|
|
137
|
+
const lint = submissionLinter(
|
|
138
|
+
() => Promise.reject(new Error("boom")),
|
|
139
|
+
() => null,
|
|
140
|
+
);
|
|
141
|
+
expect(await lint(paperDir, "/work")).toStrictEqual(err("boom"));
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
test("an empty lint set is recognised by ESLint's message template or its wording, and nothing else is", () => {
|
|
145
|
+
expect([
|
|
146
|
+
isEmptyLintSet({ messageTemplate: "file-not-found" }),
|
|
147
|
+
isEmptyLintSet({ messageTemplate: "all-matched-files-ignored" }),
|
|
148
|
+
isEmptyLintSet(new Error("No files matching 'x' were found.")),
|
|
149
|
+
isEmptyLintSet(new Error("disk on fire")),
|
|
150
|
+
isEmptyLintSet("not an error object"),
|
|
151
|
+
]).toStrictEqual([true, true, true, false, false]);
|
|
152
|
+
});
|
|
@@ -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.harness.mjs
CHANGED
|
@@ -1185,17 +1185,18 @@ check(
|
|
|
1185
1185
|
|
|
1186
1186
|
said = "";
|
|
1187
1187
|
check(
|
|
1188
|
-
"no name —
|
|
1189
|
-
runHook(undefined, { err }) ===
|
|
1188
|
+
"no name — the right invocation is suggested, and it does not deny",
|
|
1189
|
+
runHook(undefined, { err }) === 1 &&
|
|
1190
1190
|
/paperlint hook paper-edit-guard/.test(said),
|
|
1191
1191
|
);
|
|
1192
1192
|
|
|
1193
|
+
// An unknown name cannot run, the same failure as a missing runtime below, so it must not deny (#324).
|
|
1193
1194
|
said = "";
|
|
1195
|
+
const named =
|
|
1196
|
+
/unknown hook `no-such-hook`.*no-such-hook\.hook\.mjs.*paperlint \d+\.\d+\.\d+.*npm install/s;
|
|
1194
1197
|
check(
|
|
1195
|
-
"an unknown hook is NAMED
|
|
1196
|
-
runHook("no-such-hook", { err }) ===
|
|
1197
|
-
/unknown hook `no-such-hook`/.test(said) &&
|
|
1198
|
-
/no-such-hook\.hook\.mjs/.test(said),
|
|
1198
|
+
"an unknown hook is NAMED with its path, the installed version and the remedy, and does not deny",
|
|
1199
|
+
runHook("no-such-hook", { err }) === 1 && named.test(said),
|
|
1199
1200
|
);
|
|
1200
1201
|
|
|
1201
1202
|
// 🔴 THE MAIN ASSERTION. A runtime that cannot be found HAS NO RIGHT to return 2: on
|
|
@@ -1213,8 +1214,8 @@ check(
|
|
|
1213
1214
|
resolve: brokenResolve,
|
|
1214
1215
|
});
|
|
1215
1216
|
check(
|
|
1216
|
-
"the runtime does not resolve — work is NOT blocked (code
|
|
1217
|
-
code ===
|
|
1217
|
+
"the runtime does not resolve — work is NOT blocked (code 1: shown to the person, not 2)",
|
|
1218
|
+
code === 1,
|
|
1218
1219
|
);
|
|
1219
1220
|
check(
|
|
1220
1221
|
"and the complaint is LOUD: the hook is named, the effect is named, the remedy is named",
|
package/src/cli.test.ts
CHANGED
|
@@ -224,7 +224,7 @@ test("runHook: a runtime with no cli.js beside it, and a hook killed by a signal
|
|
|
224
224
|
assert.deepEqual(
|
|
225
225
|
{ noCli, killed, messages: messages.map((m) => m.split(" from ")[0]) },
|
|
226
226
|
{
|
|
227
|
-
noCli:
|
|
227
|
+
noCli: 1,
|
|
228
228
|
killed: 0,
|
|
229
229
|
messages: ["paperlint: the hook runtime (vigiles) is not resolvable"],
|
|
230
230
|
},
|
|
@@ -1219,11 +1219,11 @@ test("lint with its LaTeX language missing from the install still lints the scor
|
|
|
1219
1219
|
assert.match(whole.out, /missing all of `paper\.tex`/);
|
|
1220
1220
|
});
|
|
1221
1221
|
|
|
1222
|
-
test("`paperlint hook` with no name: exit
|
|
1222
|
+
test("`paperlint hook` with no name: exit 1, so it cannot deny and is shown, and the usage names an example", async () => {
|
|
1223
1223
|
assert.deepEqual(await cli(["hook"], root), {
|
|
1224
|
-
code:
|
|
1224
|
+
code: 1,
|
|
1225
1225
|
out: "",
|
|
1226
|
-
err: "`hook` needs a name, e.g. `paperlint hook paper-edit-guard
|
|
1226
|
+
err: "paperlint: `hook` needs a name, e.g. `paperlint hook paper-edit-guard`; no hook is running.",
|
|
1227
1227
|
});
|
|
1228
1228
|
});
|
|
1229
1229
|
|