paperlint 18.3.2 → 18.4.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/dist/adapters/memory/index.d.ts +6 -0
- package/dist/adapters/memory/index.d.ts.map +1 -1
- package/dist/adapters/memory/index.js +11 -0
- package/dist/adapters/memory/index.js.map +1 -1
- package/dist/adapters/node/index.d.ts +1 -0
- package/dist/adapters/node/index.d.ts.map +1 -1
- package/dist/adapters/node/index.js +1 -0
- package/dist/adapters/node/index.js.map +1 -1
- package/dist/adapters/node/list-tree.io.d.ts +3 -0
- package/dist/adapters/node/list-tree.io.d.ts.map +1 -0
- package/dist/adapters/node/list-tree.io.js +23 -0
- package/dist/adapters/node/list-tree.io.js.map +1 -0
- package/dist/adapters/study-registry/index.d.ts +2 -2
- package/dist/artifact-rules.d.ts +26 -0
- package/dist/artifact-rules.d.ts.map +1 -0
- package/dist/artifact-rules.js +117 -0
- package/dist/artifact-rules.js.map +1 -0
- package/dist/cli.d.ts +2 -1
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +49 -20
- package/dist/cli.js.map +1 -1
- package/dist/domain/artifact.d.ts +36 -0
- package/dist/domain/artifact.d.ts.map +1 -0
- package/dist/domain/artifact.js +116 -0
- package/dist/domain/artifact.js.map +1 -0
- package/dist/domain/paper-dirs.d.ts +16 -0
- package/dist/domain/paper-dirs.d.ts.map +1 -0
- package/dist/domain/paper-dirs.js +42 -0
- package/dist/domain/paper-dirs.js.map +1 -0
- package/dist/lib/paper-config.d.ts.map +1 -1
- package/dist/lib/paper-config.js +2 -0
- package/dist/lib/paper-config.js.map +1 -1
- package/dist/paper-files.d.ts +25 -42
- package/dist/paper-files.d.ts.map +1 -1
- package/dist/paper-files.js +101 -9
- package/dist/paper-files.js.map +1 -1
- package/dist/paper-settings.d.ts +3 -0
- package/dist/paper-settings.d.ts.map +1 -1
- package/dist/paper-settings.js +19 -16
- package/dist/paper-settings.js.map +1 -1
- package/dist/ports/list-tree.d.ts +11 -0
- package/dist/ports/list-tree.d.ts.map +1 -0
- package/dist/ports/list-tree.js +2 -0
- package/dist/ports/list-tree.js.map +1 -0
- package/docs/configuration.md +2 -1
- package/docs/rules/artifact/promised.md +64 -0
- package/docs/rules/artifact/required-files.md +65 -0
- package/docs/rules.md +2 -0
- package/lib/paper-config.ts +3 -0
- package/package.json +1 -1
- package/src/adapters/memory/index.test.ts +9 -0
- package/src/adapters/memory/index.ts +15 -0
- package/src/adapters/node/index.ts +1 -0
- package/src/adapters/node/list-tree.io.ts +27 -0
- package/src/adapters/node/list-tree.test.ts +38 -0
- package/src/artifact-rules.test.ts +50 -0
- package/src/artifact-rules.ts +188 -0
- package/src/cli.test.ts +122 -0
- package/src/cli.ts +59 -18
- package/src/domain/artifact.test.ts +154 -0
- package/src/domain/artifact.ts +171 -0
- package/src/domain/paper-dirs.test.ts +91 -0
- package/src/domain/paper-dirs.ts +62 -0
- package/src/new-paper.test.ts +9 -3
- package/src/paper-files.test.ts +88 -0
- package/src/paper-files.ts +98 -9
- package/src/paper-settings-commands.test.ts +18 -0
- package/src/paper-settings.test.ts +19 -0
- package/src/paper-settings.ts +21 -16
- package/src/ports/list-tree.ts +11 -0
- package/src/rule-cases.test.ts +134 -1
package/package.json
CHANGED
|
@@ -6,6 +6,7 @@ import {
|
|
|
6
6
|
fixedDownload,
|
|
7
7
|
memoryFiles,
|
|
8
8
|
memoryListEntries,
|
|
9
|
+
memoryListTree,
|
|
9
10
|
memoryCopyFile,
|
|
10
11
|
memoryMoveFile,
|
|
11
12
|
memoryWorkspace,
|
|
@@ -59,3 +60,11 @@ test("memoryListEntries: each name directly under a directory, a file or a direc
|
|
|
59
60
|
{ name: "out", kind: "dir" },
|
|
60
61
|
]);
|
|
61
62
|
});
|
|
63
|
+
|
|
64
|
+
test("memoryListTree: every file under a folder, relative and sorted; none under it is null", () => {
|
|
65
|
+
const files = memoryFiles({ "/a/z.md": "", "/a/p/b.md": "", "/ab/c": "" });
|
|
66
|
+
const tree = memoryListTree(files);
|
|
67
|
+
// Guards: a sibling whose name only starts like the folder (`/ab`) is not under it.
|
|
68
|
+
assert.deepEqual(tree(absolutePath("/a")), ["p/b.md", "z.md"]);
|
|
69
|
+
assert.equal(tree(absolutePath("/none")), null);
|
|
70
|
+
});
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
import { absolutePath } from "../../domain/paths.ts";
|
|
6
6
|
import type { Download } from "../../ports/download.ts";
|
|
7
7
|
import type { Files } from "../../ports/files.ts";
|
|
8
|
+
import type { ListTree } from "../../ports/list-tree.ts";
|
|
8
9
|
import type { ListDir } from "../../ports/talk-media.ts";
|
|
9
10
|
import type { ListEntries } from "../../ports/list-entries.ts";
|
|
10
11
|
import type { CopyFile, MoveFile } from "../../ports/move-file.ts";
|
|
@@ -74,6 +75,20 @@ export const memoryListDir =
|
|
|
74
75
|
),
|
|
75
76
|
];
|
|
76
77
|
|
|
78
|
+
/**
|
|
79
|
+
* `ListTree` over `memoryFiles`: every file under a folder, relative and sorted; null when no file is
|
|
80
|
+
* under it (memory holds no empty folder).
|
|
81
|
+
*/
|
|
82
|
+
export const memoryListTree =
|
|
83
|
+
(files: MemoryFiles): ListTree =>
|
|
84
|
+
(dir) => {
|
|
85
|
+
const under = [...files.map.keys()]
|
|
86
|
+
.filter((k) => k.startsWith(`${dir}/`))
|
|
87
|
+
.map((k) => k.slice(dir.length + 1))
|
|
88
|
+
.toSorted();
|
|
89
|
+
return under.length === 0 ? null : under;
|
|
90
|
+
};
|
|
91
|
+
|
|
77
92
|
/** `MoveFile` over `memoryFiles`: the bytes under the new path, none under the old; nothing there throws. */
|
|
78
93
|
/** `CopyFile` over `memoryFiles`: the bytes under the new path too; nothing there throws. */
|
|
79
94
|
export const memoryCopyFile =
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/** `ListTree` over `node:fs`: a recursive `readdirSync` under a folder, its regular files only. */
|
|
2
|
+
import { readdirSync, statSync } from "node:fs";
|
|
3
|
+
import { join, relative, sep } from "node:path";
|
|
4
|
+
import type { AbsolutePath } from "../../domain/paths.ts";
|
|
5
|
+
import type { ListTree } from "../../ports/list-tree.ts";
|
|
6
|
+
import { codeOf } from "../../domain/text.ts";
|
|
7
|
+
|
|
8
|
+
/** Whether `dir` is a directory; a path that is absent or runs through a file is not. */
|
|
9
|
+
function isDir(dir: AbsolutePath): boolean {
|
|
10
|
+
try {
|
|
11
|
+
return statSync(dir).isDirectory();
|
|
12
|
+
} catch (e) {
|
|
13
|
+
const code = codeOf(e);
|
|
14
|
+
if (code === "ENOENT" || code === "ENOTDIR") return false;
|
|
15
|
+
throw e;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export const nodeListTree: ListTree = (dir) =>
|
|
20
|
+
isDir(dir)
|
|
21
|
+
? readdirSync(dir, { recursive: true, withFileTypes: true })
|
|
22
|
+
.filter((d) => d.isFile())
|
|
23
|
+
.map((d) =>
|
|
24
|
+
relative(dir, join(d.parentPath, d.name)).split(sep).join("/"),
|
|
25
|
+
)
|
|
26
|
+
.toSorted()
|
|
27
|
+
: null;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/** `nodeListTree`: every file under a folder; null for a folder that is not one; other errors thrown. */
|
|
2
|
+
import { mkdirSync, writeFileSync } from "node:fs";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import { describe, expect, it } from "vitest";
|
|
5
|
+
import { absolutePath } from "../../domain/paths.ts";
|
|
6
|
+
import { useTempDir } from "../../../test/support.ts";
|
|
7
|
+
import { nodeListTree } from "./list-tree.io.ts";
|
|
8
|
+
|
|
9
|
+
const root = useTempDir("paperlint-list-tree-");
|
|
10
|
+
|
|
11
|
+
describe("nodeListTree", () => {
|
|
12
|
+
it("lists every file at any depth, relative and sorted; folders are not files; an empty folder is []", () => {
|
|
13
|
+
mkdirSync(join(root, "a", "prompts", "deep"), { recursive: true });
|
|
14
|
+
mkdirSync(join(root, "a", "empty"));
|
|
15
|
+
writeFileSync(join(root, "a", "README.md"), "");
|
|
16
|
+
writeFileSync(join(root, "a", ".env"), "");
|
|
17
|
+
writeFileSync(join(root, "a", "prompts", "b.md"), "");
|
|
18
|
+
writeFileSync(join(root, "a", "prompts", "deep", "c.md"), "");
|
|
19
|
+
expect(nodeListTree(absolutePath(join(root, "a")))).toEqual([
|
|
20
|
+
".env",
|
|
21
|
+
"README.md",
|
|
22
|
+
"prompts/b.md",
|
|
23
|
+
"prompts/deep/c.md",
|
|
24
|
+
]);
|
|
25
|
+
expect(nodeListTree(absolutePath(join(root, "a", "empty")))).toEqual([]);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it("is null for a folder that does not exist, a file, or a path through one", () => {
|
|
29
|
+
expect(nodeListTree(absolutePath(join(root, "none")))).toBeNull();
|
|
30
|
+
writeFileSync(join(root, "f"), "");
|
|
31
|
+
expect(nodeListTree(absolutePath(join(root, "f")))).toBeNull();
|
|
32
|
+
expect(nodeListTree(absolutePath(join(root, "f", "x")))).toBeNull();
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it("throws any other error", () => {
|
|
36
|
+
expect(() => nodeListTree(absolutePath(`${root}/a\0b`))).toThrow();
|
|
37
|
+
});
|
|
38
|
+
});
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `artifact/required-files` and `artifact/promised` (`src/artifact-rules.ts`) where real ESLint never
|
|
3
|
+
* takes them: a `paperlint.json` that `paperlint lint` refuses before ESLint runs, and a file other
|
|
4
|
+
* than `PIPELINE-STATUS.md`. Each finding is in `src/rule-cases.test.ts`, through the CLI.
|
|
5
|
+
*/
|
|
6
|
+
import { describe, expect, it } from "vitest";
|
|
7
|
+
import { memoryFiles, memoryListTree } from "./adapters/memory/index.ts";
|
|
8
|
+
import { ARTIFACT_RULE_LEVELS, artifactRules } from "./artifact-rules.ts";
|
|
9
|
+
|
|
10
|
+
const DIR = "/work/papers/p";
|
|
11
|
+
const DECLARED = JSON.stringify({
|
|
12
|
+
artifact: { dir: "gone", required: ["README"], promises: { p: "*.md" } },
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
/** How many findings each rule makes on the paper's `file`, its paperlint.json being `settings`. */
|
|
16
|
+
function counts(settings: string, file = "PIPELINE-STATUS.md"): number[] {
|
|
17
|
+
const files = memoryFiles({ [`${DIR}/paperlint.json`]: settings });
|
|
18
|
+
const rules = artifactRules({ files, listTree: memoryListTree(files) });
|
|
19
|
+
return [rules["required-files"], rules.promised].map((rule) => {
|
|
20
|
+
const out: string[] = [];
|
|
21
|
+
rule
|
|
22
|
+
.create({
|
|
23
|
+
filename: `${DIR}/${file}`,
|
|
24
|
+
sourceCode: { getLocFromIndex: () => ({ line: 1, column: 0 }) },
|
|
25
|
+
report: (d) => {
|
|
26
|
+
out.push(d.messageId);
|
|
27
|
+
},
|
|
28
|
+
})
|
|
29
|
+
.root?.();
|
|
30
|
+
return out.length;
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
describe("the artifact rules", () => {
|
|
35
|
+
it("🔴 the declared folder missing: each rule reports it on PIPELINE-STATUS.md", () => {
|
|
36
|
+
expect(counts(DECLARED)).toEqual([1, 1]);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it("silent on any file but PIPELINE-STATUS.md, and on a paperlint.json that does not parse", () => {
|
|
40
|
+
expect(counts(DECLARED, "paper.tex")).toEqual([0, 0]);
|
|
41
|
+
expect(counts("{")).toEqual([0, 0]);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it("the level: both on, as errors — silent for a paper that declares no artifact", () => {
|
|
45
|
+
expect(ARTIFACT_RULE_LEVELS).toEqual({
|
|
46
|
+
"artifact/required-files": "error",
|
|
47
|
+
"artifact/promised": "error",
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
});
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* THE ARTIFACT RULES — the artifact holds what the paper's own `paperlint.json` says it must
|
|
3
|
+
* (`src/domain/artifact.ts`): `artifact/required-files` (each `artifact.required` name at its top
|
|
4
|
+
* level) and `artifact/promised` (each `artifact.promises` glob matches a path). The paths are every
|
|
5
|
+
* file under `artifact.dir` (the `ListTree` port) or the lines of the committed list `artifact.files`.
|
|
6
|
+
*
|
|
7
|
+
* On by default and silent for a paper that declares nothing they read, as the talk rules are for a
|
|
8
|
+
* paper without `talk`; silent on a `paperlint.json` that does not parse (`pdf/profile` says why). A
|
|
9
|
+
* missing folder, or a list missing or empty: each rule says so, naming what it could not check.
|
|
10
|
+
*/
|
|
11
|
+
import { basename, dirname, resolve } from "node:path";
|
|
12
|
+
import { callerPath } from "./caller-path.ts";
|
|
13
|
+
import {
|
|
14
|
+
brokenPromises,
|
|
15
|
+
listedPaths,
|
|
16
|
+
missingRequired,
|
|
17
|
+
type PaperArtifact,
|
|
18
|
+
} from "./domain/artifact.ts";
|
|
19
|
+
import type { Files } from "./ports/files.ts";
|
|
20
|
+
import type { ListTree } from "./ports/list-tree.ts";
|
|
21
|
+
import type {
|
|
22
|
+
FolderRuleContext,
|
|
23
|
+
FolderRuleModule,
|
|
24
|
+
} from "./folder-venue-rule.ts";
|
|
25
|
+
import { readPaperSettings } from "./paper-settings.ts";
|
|
26
|
+
import { rulePageUrl, type Finding } from "./venue-rules.ts";
|
|
27
|
+
|
|
28
|
+
/** The file the rules report on: one per paper folder, whatever the paper's source format. */
|
|
29
|
+
const STATUS_FILE = "PIPELINE-STATUS.md";
|
|
30
|
+
|
|
31
|
+
export interface ArtifactRuleDeps {
|
|
32
|
+
readonly files: Files;
|
|
33
|
+
readonly listTree: ListTree;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
type ArtifactRuleName = "required-files" | "promised";
|
|
37
|
+
|
|
38
|
+
/** A rule of this file: a folder rule that reports a problem, not a suggestion. */
|
|
39
|
+
interface ArtifactRuleModule {
|
|
40
|
+
readonly meta: Omit<FolderRuleModule["meta"], "type"> & {
|
|
41
|
+
readonly type: "problem";
|
|
42
|
+
};
|
|
43
|
+
create(context: FolderRuleContext): { root?: () => void };
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** The artifact's paths, relative to its root, or why there are none to judge. */
|
|
47
|
+
type Listing =
|
|
48
|
+
| { readonly kind: "paths"; readonly paths: readonly string[] }
|
|
49
|
+
| { readonly kind: "noDir" | "noList" | "emptyList"; readonly path: string };
|
|
50
|
+
|
|
51
|
+
/** The paths of the artifact `a` declares, read through `deps`; `paperDir` is what its paths are relative to. */
|
|
52
|
+
function listing(
|
|
53
|
+
paperDir: string,
|
|
54
|
+
a: PaperArtifact,
|
|
55
|
+
deps: ArtifactRuleDeps,
|
|
56
|
+
): Listing {
|
|
57
|
+
const at = callerPath(resolve(paperDir, a.source.path));
|
|
58
|
+
const { path } = a.source;
|
|
59
|
+
if (a.source.kind === "dir") {
|
|
60
|
+
const paths = deps.listTree(at);
|
|
61
|
+
return paths === null ? { kind: "noDir", path } : { kind: "paths", paths };
|
|
62
|
+
}
|
|
63
|
+
const bytes = deps.files.readBytes(at);
|
|
64
|
+
if (bytes === null) return { kind: "noList", path };
|
|
65
|
+
const paths = listedPaths(new TextDecoder().decode(bytes));
|
|
66
|
+
return paths.length === 0
|
|
67
|
+
? { kind: "emptyList", path }
|
|
68
|
+
: { kind: "paths", paths };
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** The three messages about where the paths come from, naming what `what` could not be checked. */
|
|
72
|
+
const sourceMessages = (what: string): Readonly<Record<string, string>> => ({
|
|
73
|
+
noDir: `the artifact folder {{path}} ("artifact.dir" in paperlint.json, relative to the paper) does not exist or is not a folder, so ${what} cannot be checked`,
|
|
74
|
+
noList: `the artifact's list of paths {{path}} ("artifact.files" in paperlint.json, relative to the paper) does not exist, so ${what} cannot be checked`,
|
|
75
|
+
emptyList: `the artifact's list of paths {{path}} names no file, so ${what} cannot be checked — write one path per line, relative to the artifact's root, as \`zipinfo -1\` or \`find . -type f\` print them`,
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
/** Each rule: its page's line, its messages, whether the paper declared what it reads, and its judgement over the paths. */
|
|
79
|
+
const RULES: Readonly<
|
|
80
|
+
Record<
|
|
81
|
+
ArtifactRuleName,
|
|
82
|
+
{
|
|
83
|
+
readonly description: string;
|
|
84
|
+
readonly messages: Readonly<Record<string, string>>;
|
|
85
|
+
readonly declared: (a: PaperArtifact) => boolean;
|
|
86
|
+
readonly judge: (
|
|
87
|
+
a: PaperArtifact,
|
|
88
|
+
paths: readonly string[],
|
|
89
|
+
) => readonly Finding[];
|
|
90
|
+
}
|
|
91
|
+
>
|
|
92
|
+
> = {
|
|
93
|
+
"required-files": {
|
|
94
|
+
description:
|
|
95
|
+
"each name the paper's artifact.required lists is at the top level of the artifact, with any extension",
|
|
96
|
+
messages: {
|
|
97
|
+
...sourceMessages("its required names"),
|
|
98
|
+
missing:
|
|
99
|
+
'the artifact ({{where}}) has no top-level {{name}} — any extension counts ({{name}}.md, {{name}}.txt, {{name}}); "artifact.required" in paperlint.json asks for one',
|
|
100
|
+
},
|
|
101
|
+
declared: (a) => a.required.length > 0,
|
|
102
|
+
judge: (a, paths) =>
|
|
103
|
+
missingRequired(a.required, paths).map((name) => ({
|
|
104
|
+
messageId: "missing",
|
|
105
|
+
data: { name, where: a.source.path },
|
|
106
|
+
})),
|
|
107
|
+
},
|
|
108
|
+
promised: {
|
|
109
|
+
description:
|
|
110
|
+
"each glob the paper's artifact.promises lists matches a path of the artifact",
|
|
111
|
+
messages: {
|
|
112
|
+
...sourceMessages("its promises"),
|
|
113
|
+
broken:
|
|
114
|
+
'the artifact promise "{{label}}" ({{glob}}) matches no path of the artifact ({{where}}): the paper says the artifact holds it — add the files, or correct the glob in "artifact.promises"',
|
|
115
|
+
},
|
|
116
|
+
declared: (a) => Object.keys(a.promises).length > 0,
|
|
117
|
+
judge: (a, paths) =>
|
|
118
|
+
brokenPromises(a.promises, paths).map(([label, glob]) => ({
|
|
119
|
+
messageId: "broken",
|
|
120
|
+
data: { label, glob, where: a.source.path },
|
|
121
|
+
})),
|
|
122
|
+
},
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
/** The findings of rule `name` for the paper folder `dir`. Reads through `deps`; never throws. */
|
|
126
|
+
export function artifactFindings(
|
|
127
|
+
name: ArtifactRuleName,
|
|
128
|
+
dir: string,
|
|
129
|
+
deps: ArtifactRuleDeps,
|
|
130
|
+
): readonly Finding[] {
|
|
131
|
+
const settings = readPaperSettings(deps.files, dir);
|
|
132
|
+
const a = settings.ok ? (settings.value?.artifact ?? null) : null;
|
|
133
|
+
const { declared, judge } = RULES[name];
|
|
134
|
+
if (a === null || !declared(a)) return [];
|
|
135
|
+
const l = listing(dir, a, deps);
|
|
136
|
+
return l.kind === "paths"
|
|
137
|
+
? judge(a, l.paths)
|
|
138
|
+
: [{ messageId: l.kind, data: { path: l.path } }];
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
function rule(
|
|
142
|
+
name: ArtifactRuleName,
|
|
143
|
+
deps: ArtifactRuleDeps,
|
|
144
|
+
): ArtifactRuleModule {
|
|
145
|
+
const meta = RULES[name];
|
|
146
|
+
return {
|
|
147
|
+
meta: {
|
|
148
|
+
type: "problem",
|
|
149
|
+
docs: {
|
|
150
|
+
description: meta.description,
|
|
151
|
+
url: rulePageUrl(`artifact/${name}`),
|
|
152
|
+
},
|
|
153
|
+
schema: [],
|
|
154
|
+
messages: meta.messages,
|
|
155
|
+
},
|
|
156
|
+
create(context) {
|
|
157
|
+
if (basename(context.filename) !== STATUS_FILE) return {};
|
|
158
|
+
return {
|
|
159
|
+
root() {
|
|
160
|
+
const at = context.sourceCode.getLocFromIndex(0);
|
|
161
|
+
artifactFindings(name, dirname(context.filename), deps).forEach(
|
|
162
|
+
(f) => {
|
|
163
|
+
context.report({ loc: { start: at, end: at }, ...f });
|
|
164
|
+
},
|
|
165
|
+
);
|
|
166
|
+
},
|
|
167
|
+
};
|
|
168
|
+
},
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/** The artifact rules, as the rules of the `artifact` plugin. */
|
|
173
|
+
export function artifactRules(
|
|
174
|
+
deps: ArtifactRuleDeps,
|
|
175
|
+
): Readonly<Record<ArtifactRuleName, ArtifactRuleModule>> {
|
|
176
|
+
return {
|
|
177
|
+
"required-files": rule("required-files", deps),
|
|
178
|
+
promised: rule("promised", deps),
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/** The level each artifact rule is on at, for every paper's `PIPELINE-STATUS.md`. Silent for a paper without `artifact`. */
|
|
183
|
+
export const ARTIFACT_RULE_LEVELS: Readonly<
|
|
184
|
+
Record<`artifact/${ArtifactRuleName}`, "error">
|
|
185
|
+
> = {
|
|
186
|
+
"artifact/required-files": "error",
|
|
187
|
+
"artifact/promised": "error",
|
|
188
|
+
};
|
package/src/cli.test.ts
CHANGED
|
@@ -824,6 +824,128 @@ test("lint: a path that shares nothing with the project but the filesystem root
|
|
|
824
824
|
);
|
|
825
825
|
});
|
|
826
826
|
|
|
827
|
+
/** A scorecard that fails `paper/stages`: its stage names a PDF that does not exist. */
|
|
828
|
+
const FAILING_STATUS =
|
|
829
|
+
"---\nstages:\n - stage: submitted\n date: 2026-07-22\n pdf: versions/none.pdf\n bytes: 1\n---\n";
|
|
830
|
+
|
|
831
|
+
test("lint: a copy of a paper inside it (a review snapshot, a build copy) is not linted as a paper (#582)", async () => {
|
|
832
|
+
const dir = writeTree(join(root, "lint-copies"), {
|
|
833
|
+
"paperlint.json": JSON.stringify({ papersDir: "papers" }),
|
|
834
|
+
"papers/p/paper.tex": "% P\n",
|
|
835
|
+
"papers/p/PIPELINE-STATUS.md": "---\n---\n",
|
|
836
|
+
"papers/p/reviews/2026-11-20-second-opinion/paper.tex": "% P\n",
|
|
837
|
+
"papers/p/reviews/2026-11-20-second-opinion/PIPELINE-STATUS.md":
|
|
838
|
+
FAILING_STATUS,
|
|
839
|
+
"papers/p/research/data/cut/runs/a/paper.tex": "% P\n",
|
|
840
|
+
"papers/p/research/data/cut/runs/a/PIPELINE-STATUS.md": FAILING_STATUS,
|
|
841
|
+
});
|
|
842
|
+
const r = await cli(["lint"], dir);
|
|
843
|
+
assert.deepEqual(
|
|
844
|
+
{ code: r.code, copies: /second-opinion|runs\/a/.test(r.out) },
|
|
845
|
+
{ code: 0, copies: false },
|
|
846
|
+
);
|
|
847
|
+
});
|
|
848
|
+
|
|
849
|
+
test.each([
|
|
850
|
+
["a review card", "archive/p/reviews/r.md"],
|
|
851
|
+
["its reviews/ folder", "archive/p/reviews"],
|
|
852
|
+
])(
|
|
853
|
+
"lint: %s named outside the papers directory is judged as its paper's own (#582)",
|
|
854
|
+
async (_, path) => {
|
|
855
|
+
const dir = writeTree(
|
|
856
|
+
join(root, `lint-owner-${path.replaceAll("/", "-")}`),
|
|
857
|
+
{
|
|
858
|
+
"paperlint.json": JSON.stringify({ papersDir: "papers" }),
|
|
859
|
+
"archive/p/paper.tex": "% P\n",
|
|
860
|
+
"archive/p/PIPELINE-STATUS.md": "---\n---\n",
|
|
861
|
+
// A finding without a status: the review schema refuses it.
|
|
862
|
+
"archive/p/reviews/r.md": "---\nfindings:\n - id: 1\n---\n# R\n",
|
|
863
|
+
// A snapshot of the paper beside the card: the paper still owns the card.
|
|
864
|
+
"archive/p/reviews/snapshot/paper.tex": "% P\n",
|
|
865
|
+
"archive/p/reviews/snapshot/PIPELINE-STATUS.md": FAILING_STATUS,
|
|
866
|
+
},
|
|
867
|
+
);
|
|
868
|
+
const r = await cli(["lint", path], dir);
|
|
869
|
+
assert.deepEqual(
|
|
870
|
+
{
|
|
871
|
+
code: r.code,
|
|
872
|
+
card: /archive\/p\/reviews\/r\.md/.test(r.out),
|
|
873
|
+
snapshot: /reviews\/snapshot/.test(r.out),
|
|
874
|
+
},
|
|
875
|
+
{ code: 1, card: true, snapshot: false },
|
|
876
|
+
);
|
|
877
|
+
},
|
|
878
|
+
);
|
|
879
|
+
|
|
880
|
+
test("lint: a review card of a paper with only its source, outside the papers directory, is judged (#582)", async () => {
|
|
881
|
+
const dir = writeTree(join(root, "lint-owner-source-only"), {
|
|
882
|
+
"paperlint.json": JSON.stringify({ papersDir: "papers" }),
|
|
883
|
+
"archive/p/paper.tex": "% P\n",
|
|
884
|
+
"archive/p/reviews/r.md": "---\nfindings:\n - id: 1\n---\n# R\n",
|
|
885
|
+
});
|
|
886
|
+
const r = await cli(["lint", "archive/p/reviews/r.md"], dir);
|
|
887
|
+
assert.deepEqual(
|
|
888
|
+
{ code: r.code, card: /archive\/p\/reviews\/r\.md/.test(r.out) },
|
|
889
|
+
{ code: 1, card: true },
|
|
890
|
+
);
|
|
891
|
+
});
|
|
892
|
+
|
|
893
|
+
test("lint: a copy straight under a paper is not linted as a paper (#582)", async () => {
|
|
894
|
+
// The layout rule reports the stray `old/` itself; what must not happen is the copy's own
|
|
895
|
+
// scorecard being judged as a second paper's.
|
|
896
|
+
const dir = writeTree(join(root, "lint-direct-copy"), {
|
|
897
|
+
"paperlint.json": JSON.stringify({ papersDir: "papers" }),
|
|
898
|
+
"papers/p/paper.tex": "% P\n",
|
|
899
|
+
"papers/p/PIPELINE-STATUS.md": "---\n---\n",
|
|
900
|
+
"papers/p/old/paper.tex": "% P\n",
|
|
901
|
+
"papers/p/old/PIPELINE-STATUS.md": FAILING_STATUS,
|
|
902
|
+
});
|
|
903
|
+
const r = await cli(["lint", "papers/p"], dir);
|
|
904
|
+
assert.equal(/papers\/p\/old\/PIPELINE-STATUS\.md/.test(r.out), false);
|
|
905
|
+
});
|
|
906
|
+
|
|
907
|
+
test("lint: a paper more than one folder below a named folder is found and judged (#582)", async () => {
|
|
908
|
+
const dir = writeTree(join(root, "lint-deep-container"), {
|
|
909
|
+
"paperlint.json": JSON.stringify({ papersDir: "papers" }),
|
|
910
|
+
"archive/2025/p/paper.tex": "% P\n",
|
|
911
|
+
"archive/2025/p/PIPELINE-STATUS.md": FAILING_STATUS,
|
|
912
|
+
});
|
|
913
|
+
const r = await cli(["lint", "archive"], dir);
|
|
914
|
+
assert.deepEqual(
|
|
915
|
+
{ code: r.code, deep: /archive\/2025\/p\/PIPELINE-STATUS\.md/.test(r.out) },
|
|
916
|
+
{ code: 1, deep: true },
|
|
917
|
+
);
|
|
918
|
+
});
|
|
919
|
+
|
|
920
|
+
test("lint: `lint .` from the project root reaches papers outside papersDir (#582)", async () => {
|
|
921
|
+
// The root holds paperlint.json, the project's settings, and is no paper: the walk goes on.
|
|
922
|
+
const dir = writeTree(join(root, "lint-project-root"), {
|
|
923
|
+
"paperlint.json": JSON.stringify({ papersDir: "papers" }),
|
|
924
|
+
"papers/p/paper.tex": "% P\n",
|
|
925
|
+
"papers/p/PIPELINE-STATUS.md": "---\n---\n",
|
|
926
|
+
"archive/2025/q/paper.tex": "% P\n",
|
|
927
|
+
"archive/2025/q/PIPELINE-STATUS.md": FAILING_STATUS,
|
|
928
|
+
});
|
|
929
|
+
const r = await cli(["lint", "."], dir);
|
|
930
|
+
assert.deepEqual(
|
|
931
|
+
{ code: r.code, q: /archive\/2025\/q\/PIPELINE-STATUS\.md/.test(r.out) },
|
|
932
|
+
{ code: 1, q: true },
|
|
933
|
+
);
|
|
934
|
+
});
|
|
935
|
+
|
|
936
|
+
test("lint: the same failing scorecard as the paper's own is reported, so the test above can fail (#582)", async () => {
|
|
937
|
+
const dir = writeTree(join(root, "lint-own-status"), {
|
|
938
|
+
"paperlint.json": JSON.stringify({ papersDir: "papers" }),
|
|
939
|
+
"papers/p/paper.tex": "% P\n",
|
|
940
|
+
"papers/p/PIPELINE-STATUS.md": FAILING_STATUS,
|
|
941
|
+
});
|
|
942
|
+
const r = await cli(["lint"], dir);
|
|
943
|
+
assert.deepEqual(
|
|
944
|
+
{ code: r.code, own: /papers\/p\/PIPELINE-STATUS\.md/.test(r.out) },
|
|
945
|
+
{ code: 1, own: true },
|
|
946
|
+
);
|
|
947
|
+
});
|
|
948
|
+
|
|
827
949
|
/**
|
|
828
950
|
* `new` at a terminal: stdin and stdout claim to be TTYs (a preload), and each prompt is answered
|
|
829
951
|
* when it appears — a pipe written all at once is swallowed by the first question.
|