paperlint 18.3.2 → 18.4.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/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.map +1 -1
- package/dist/cli.js +7 -1
- 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/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-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.ts +7 -0
- package/src/domain/artifact.test.ts +154 -0
- package/src/domain/artifact.ts +171 -0
- package/src/new-paper.test.ts +1 -1
- 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/src/rule-cases.test.ts
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
* `EXEMPT` with the reason; a case for a rule that is not registered fails too. A `_build/` file a
|
|
11
11
|
* rule reads is planted as the build would write it — no pdflatex, no network.
|
|
12
12
|
*/
|
|
13
|
-
import { readFileSync } from "node:fs";
|
|
13
|
+
import { mkdirSync, readFileSync } from "node:fs";
|
|
14
14
|
import { dirname, join } from "node:path";
|
|
15
15
|
import { fileURLToPath } from "node:url";
|
|
16
16
|
import { describe, expect, it } from "vitest";
|
|
@@ -813,7 +813,61 @@ const CHANGES_AT = `${P}/versions/beta-2027/changes.yaml`;
|
|
|
813
813
|
const DECLARED_CUT =
|
|
814
814
|
'- type: cut\n before: "We measured 63 repositories."\n why: too long\n reader_loses: the sample size\n drops: ["63"]\n';
|
|
815
815
|
|
|
816
|
+
/** A paper whose paperlint.json declares `artifact`, with the artifact's own files. */
|
|
817
|
+
const withArtifact = (
|
|
818
|
+
artifact: Readonly<Record<string, unknown>>,
|
|
819
|
+
files: Readonly<Record<string, string>> = {},
|
|
820
|
+
): Record<string, string> =>
|
|
821
|
+
paper(tex("x"), {
|
|
822
|
+
[`${P}/paperlint.json`]: JSON.stringify({ extends: null, artifact }),
|
|
823
|
+
...files,
|
|
824
|
+
});
|
|
825
|
+
/** The artifact in `extra/`, a folder the layout never judges. */
|
|
826
|
+
const ARTIFACT_DIR = "extra/artifact";
|
|
827
|
+
const LIST = "submission/artifact-files.txt";
|
|
828
|
+
const ARTIFACT_FILES: Readonly<Record<string, string>> = {
|
|
829
|
+
[`${P}/${ARTIFACT_DIR}/README.md`]: "# artifact\n",
|
|
830
|
+
[`${P}/${ARTIFACT_DIR}/LICENSE`]: "MIT\n",
|
|
831
|
+
[`${P}/${ARTIFACT_DIR}/data/prompts/a.md`]: "a\n",
|
|
832
|
+
};
|
|
833
|
+
const REQUIRED = ["README", "LICENSE"];
|
|
834
|
+
const PROMISES = { prompts: "**/prompts/*.md" };
|
|
835
|
+
|
|
816
836
|
const CASES: Readonly<Record<string, RuleCases>> = {
|
|
837
|
+
// A paper that requires README and LICENSE of an artifact holding only a README.
|
|
838
|
+
"artifact/required-files": {
|
|
839
|
+
reports: {
|
|
840
|
+
tree: withArtifact(
|
|
841
|
+
{ dir: ARTIFACT_DIR, required: REQUIRED },
|
|
842
|
+
{ [`${P}/${ARTIFACT_DIR}/README.md`]: "# artifact\n" },
|
|
843
|
+
),
|
|
844
|
+
file: `${P}/PIPELINE-STATUS.md`,
|
|
845
|
+
severity: 2,
|
|
846
|
+
line: 1,
|
|
847
|
+
},
|
|
848
|
+
// The same artifact with its LICENSE.
|
|
849
|
+
silent: withArtifact(
|
|
850
|
+
{ dir: ARTIFACT_DIR, required: REQUIRED },
|
|
851
|
+
ARTIFACT_FILES,
|
|
852
|
+
),
|
|
853
|
+
},
|
|
854
|
+
// A promise of prompts the artifact does not hold.
|
|
855
|
+
"artifact/promised": {
|
|
856
|
+
reports: {
|
|
857
|
+
tree: withArtifact(
|
|
858
|
+
{ dir: ARTIFACT_DIR, promises: PROMISES },
|
|
859
|
+
{ [`${P}/${ARTIFACT_DIR}/README.md`]: "# artifact\n" },
|
|
860
|
+
),
|
|
861
|
+
file: `${P}/PIPELINE-STATUS.md`,
|
|
862
|
+
severity: 2,
|
|
863
|
+
line: 1,
|
|
864
|
+
},
|
|
865
|
+
// The same promise in a committed list of a zip wrapped in one folder, the prompts there.
|
|
866
|
+
silent: withArtifact(
|
|
867
|
+
{ files: LIST, promises: PROMISES },
|
|
868
|
+
{ [`${P}/${LIST}`]: "artifact/\nartifact/data/prompts/a.md\n" },
|
|
869
|
+
),
|
|
870
|
+
},
|
|
817
871
|
"cycle/changes-since-approved": {
|
|
818
872
|
reports: {
|
|
819
873
|
tree: paper(tex("The rest is as before."), {
|
|
@@ -1629,11 +1683,13 @@ type Message = z.infer<typeof LintResults>[number]["messages"][number] & {
|
|
|
1629
1683
|
/** `paperlint lint --json` over the tree, in-process through the CLI: every message, by file. */
|
|
1630
1684
|
async function lintTree(
|
|
1631
1685
|
tree: Record<string, string | Uint8Array>,
|
|
1686
|
+
emptyDirs: readonly string[] = [],
|
|
1632
1687
|
): Promise<Message[]> {
|
|
1633
1688
|
const dir = writeTree(useTempDir("paperlint-rule-cases-"), {
|
|
1634
1689
|
"package.json": '{"name":"consumer","private":true}',
|
|
1635
1690
|
...tree,
|
|
1636
1691
|
});
|
|
1692
|
+
emptyDirs.forEach((d) => mkdirSync(join(dir, d), { recursive: true }));
|
|
1637
1693
|
const out: string[] = [];
|
|
1638
1694
|
await run(["lint", "--json"], {
|
|
1639
1695
|
cwd: dir,
|
|
@@ -1934,6 +1990,83 @@ describe("cycle/camera-ready-source, before the camera-ready is frozen", () => {
|
|
|
1934
1990
|
);
|
|
1935
1991
|
});
|
|
1936
1992
|
|
|
1993
|
+
const STATUS_AT = `${P}/PIPELINE-STATUS.md`;
|
|
1994
|
+
/** What the artifact rules say about `tree` (`emptyDirs` made too), as `file:line rule message`. */
|
|
1995
|
+
const said = async (
|
|
1996
|
+
tree: Record<string, string>,
|
|
1997
|
+
emptyDirs: readonly string[] = [],
|
|
1998
|
+
) =>
|
|
1999
|
+
(await lintTree(tree, emptyDirs))
|
|
2000
|
+
.filter((m) => (m.ruleId ?? "").startsWith("artifact/"))
|
|
2001
|
+
.map((m) => `${m.file}:${String(m.line)} ${m.ruleId ?? ""} ${m.message}`);
|
|
2002
|
+
|
|
2003
|
+
describe("the artifact rules through real ESLint: each message, both halves", () => {
|
|
2004
|
+
it(
|
|
2005
|
+
"🔴 a folder that does not exist: each rule says what it cannot check",
|
|
2006
|
+
{ timeout: CASE_TIMEOUT_MS },
|
|
2007
|
+
async () => {
|
|
2008
|
+
expect(
|
|
2009
|
+
await said(
|
|
2010
|
+
withArtifact({
|
|
2011
|
+
dir: ARTIFACT_DIR,
|
|
2012
|
+
required: ["README"],
|
|
2013
|
+
promises: PROMISES,
|
|
2014
|
+
}),
|
|
2015
|
+
),
|
|
2016
|
+
).toEqual([
|
|
2017
|
+
`${STATUS_AT}:1 artifact/required-files the artifact folder ${ARTIFACT_DIR} ("artifact.dir" in paperlint.json, relative to the paper) does not exist or is not a folder, so its required names cannot be checked`,
|
|
2018
|
+
`${STATUS_AT}:1 artifact/promised the artifact folder ${ARTIFACT_DIR} ("artifact.dir" in paperlint.json, relative to the paper) does not exist or is not a folder, so its promises cannot be checked`,
|
|
2019
|
+
]);
|
|
2020
|
+
},
|
|
2021
|
+
);
|
|
2022
|
+
|
|
2023
|
+
it(
|
|
2024
|
+
"🔴 a folder that exists and is empty: the name missing and the promise matching nothing, not the folder",
|
|
2025
|
+
{ timeout: CASE_TIMEOUT_MS },
|
|
2026
|
+
async () => {
|
|
2027
|
+
expect(
|
|
2028
|
+
await said(
|
|
2029
|
+
withArtifact({
|
|
2030
|
+
dir: ARTIFACT_DIR,
|
|
2031
|
+
required: ["README"],
|
|
2032
|
+
promises: PROMISES,
|
|
2033
|
+
}),
|
|
2034
|
+
[`${P}/${ARTIFACT_DIR}`],
|
|
2035
|
+
),
|
|
2036
|
+
).toEqual([
|
|
2037
|
+
`${STATUS_AT}:1 artifact/required-files the artifact (${ARTIFACT_DIR}) has no top-level README — any extension counts (README.md, README.txt, README); "artifact.required" in paperlint.json asks for one`,
|
|
2038
|
+
`${STATUS_AT}:1 artifact/promised the artifact promise "prompts" (**/prompts/*.md) matches no path of the artifact (${ARTIFACT_DIR}): the paper says the artifact holds it — add the files, or correct the glob in "artifact.promises"`,
|
|
2039
|
+
]);
|
|
2040
|
+
},
|
|
2041
|
+
);
|
|
2042
|
+
});
|
|
2043
|
+
|
|
2044
|
+
describe("the artifact rules through real ESLint: a committed list of paths", () => {
|
|
2045
|
+
it(
|
|
2046
|
+
"🔴 a list that does not exist, and one that names no file",
|
|
2047
|
+
{ timeout: CASE_TIMEOUT_MS },
|
|
2048
|
+
async () => {
|
|
2049
|
+
const declared = { files: LIST, required: ["README"] };
|
|
2050
|
+
expect(await said(withArtifact(declared))).toEqual([
|
|
2051
|
+
`${STATUS_AT}:1 artifact/required-files the artifact's list of paths ${LIST} ("artifact.files" in paperlint.json, relative to the paper) does not exist, so its required names cannot be checked`,
|
|
2052
|
+
]);
|
|
2053
|
+
expect(
|
|
2054
|
+
await said(withArtifact(declared, { [`${P}/${LIST}`]: "artifact/\n" })),
|
|
2055
|
+
).toEqual([
|
|
2056
|
+
`${STATUS_AT}:1 artifact/required-files the artifact's list of paths ${LIST} names no file, so its required names cannot be checked — write one path per line, relative to the artifact's root, as \`zipinfo -1\` or \`find . -type f\` print them`,
|
|
2057
|
+
]);
|
|
2058
|
+
},
|
|
2059
|
+
);
|
|
2060
|
+
|
|
2061
|
+
it(
|
|
2062
|
+
"a paper that declares no artifact: silent, the rules on by default all the same",
|
|
2063
|
+
{ timeout: CASE_TIMEOUT_MS },
|
|
2064
|
+
async () => {
|
|
2065
|
+
expect(await said(paper(tex("x")))).toEqual([]);
|
|
2066
|
+
},
|
|
2067
|
+
);
|
|
2068
|
+
});
|
|
2069
|
+
|
|
1937
2070
|
describe.each(Object.entries(CASES))("%s, through real ESLint", (id, c) => {
|
|
1938
2071
|
it(
|
|
1939
2072
|
`reports on ${c.reports.file}:${String(c.reports.line)} at severity ${String(c.reports.severity)}`,
|