@theholocron/astromech 5.0.0-alpha.283 → 5.0.0-alpha.285
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/README.md +19 -1
- package/dist/index.mjs +1 -4
- package/dist/repo-validation/index.d.mts +141 -0
- package/dist/repo-validation/index.mjs +264 -0
- package/package.json +11 -6
package/README.md
CHANGED
|
@@ -74,7 +74,7 @@ documents, not a naming convention repos need to follow.
|
|
|
74
74
|
| `platform.notifyCheck` | _(none — manual workflow)_ | posts a labelled test message to every notification channel; fails per channel that does not work |
|
|
75
75
|
| `platform.repoSync` | `holocron repo sync` | keeps generated files current |
|
|
76
76
|
| `platform.commitStandards` | commitlint | no local equivalent — enforced by the `commit-msg` hook locally, over the PR's commit range in CI |
|
|
77
|
-
| `platform.repoValidation` | `
|
|
77
|
+
| `platform.repoValidation` | `holocron probe specs check`, `holocron probe docs presence` | a job-bearing task — spec/ADR frontmatter and docs-presence, not linters |
|
|
78
78
|
| `knowledge.wiki` | Fern | publishes `docs/wiki/*.md` — not a sync, a publish; carries `preview` |
|
|
79
79
|
| `knowledge.docs` | Astro build | the docs site itself; carries `preview` (defaults on) |
|
|
80
80
|
| `knowledge.components` | Storybook build | a browsable component catalog — "Storybook" is the tool, not the intent; carries `preview` (defaults on) |
|
|
@@ -248,3 +248,21 @@ config surface don't pull `@commitlint/*` in:
|
|
|
248
248
|
The root entry also exports the config-file generators `holocron repo setup`
|
|
249
249
|
writes (`createEditorconfig`, `createAlexrc`, `createPrePush`, …) and
|
|
250
250
|
`createHeader`.
|
|
251
|
+
|
|
252
|
+
## Repo validation — `@theholocron/astromech/repo-validation`
|
|
253
|
+
|
|
254
|
+
The rules of the `platform.repoValidation` checks, once, as pure functions over plain data (changed files, commit
|
|
255
|
+
subjects, the PR description, a manifest) that return findings. They do no git, no filesystem and no network, so the two
|
|
256
|
+
interfaces that run them only supply the data: the CLI (`holocron probe docs presence` and `holocron probe specs check`, the two jobs of
|
|
257
|
+
`holocron run platform.repoValidation`) from git and the filesystem, and [Sentinel](https://docs.theholocron.dev/holocron/sentinel/) from the
|
|
258
|
+
webhook and the GitHub API (#929).
|
|
259
|
+
|
|
260
|
+
- Docs presence: `isFeat(subjects)`, `packageOf(file, readPackage)`, `pageNames(dir)`, `hasDocsSignal(dir, changedFiles, addedCommentLines)`,
|
|
261
|
+
`isAddedDocComment(line)`, `parseSkipDocs(text)` (the `[skip docs] <reason>` marker) and
|
|
262
|
+
`evaluateDocsPresence({ packages, changedFiles, addedCommentLines, skip })`, which sorts a feature's packages into
|
|
263
|
+
those to warn about and those a marker excused.
|
|
264
|
+
- ADRs and specs: `checkSpecs(files)` takes `{ path, text }` pairs and returns `{ fileCount, findings }`, skipping a path that
|
|
265
|
+
is neither an ADR nor a spec; underneath it are `classifySpecPath(path)`, `parseFrontmatter(text)`,
|
|
266
|
+
`validateAdr(path, text)`, `validateSpec(path, text)` and `isValidIsoDate(value)`, and the folders and status sets
|
|
267
|
+
(`ADR_DIR`, `SPEC_DIRS`, `ADR_STATUSES`, `SPEC_STATUSES`). A `SpecFinding` is an `error` (fails the check) or a
|
|
268
|
+
`warning` (never does), with the file, the field's line and the rule.
|
package/dist/index.mjs
CHANGED
|
@@ -1192,10 +1192,7 @@ const TASKS = {
|
|
|
1192
1192
|
retiredJobs: ["registry"],
|
|
1193
1193
|
jobs: {
|
|
1194
1194
|
adrs: {
|
|
1195
|
-
local: {
|
|
1196
|
-
tool: "node",
|
|
1197
|
-
args: ["scripts/validate-adrs.mjs"]
|
|
1198
|
-
},
|
|
1195
|
+
local: { command: "probe specs check" },
|
|
1199
1196
|
checkContext: "platform.repoValidation / Validate ADRs and specs"
|
|
1200
1197
|
},
|
|
1201
1198
|
docsPresence: {
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
/** A `[skip docs]` marker found in a PR description or commit message. */
|
|
2
|
+
interface SkipDocs {
|
|
3
|
+
/** The packages it names (`[skip docs: array-utils]`), or `null` for every package. */
|
|
4
|
+
scope: string[] | null;
|
|
5
|
+
/** What follows the marker on its line; empty when the marker gives no reason, which does not count. */
|
|
6
|
+
reason: string;
|
|
7
|
+
}
|
|
8
|
+
/** What the docs-presence check found for the packages a feature changed. */
|
|
9
|
+
interface DocsPresenceResult {
|
|
10
|
+
/** Packages with no docs signal and no `[skip docs]` reason. */
|
|
11
|
+
warn: string[];
|
|
12
|
+
/** Packages a `[skip docs]` marker with a reason covered. */
|
|
13
|
+
skipped: Array<{
|
|
14
|
+
dir: string;
|
|
15
|
+
reason: string;
|
|
16
|
+
}>;
|
|
17
|
+
/** A marker covered a package but gave no reason, so the package is in `warn`. */
|
|
18
|
+
missingReason: boolean;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Sorts the packages a feature changed into those that need a warning (no docs signal, and no `[skip docs]` marker
|
|
22
|
+
* with a reason that covers them) and those a marker excused. A marker with no reason excuses nothing.
|
|
23
|
+
*/
|
|
24
|
+
export declare function evaluateDocsPresence(input: {
|
|
25
|
+
packages: readonly string[];
|
|
26
|
+
changedFiles: readonly string[];
|
|
27
|
+
addedCommentLines: (dir: string) => readonly string[];
|
|
28
|
+
skip: SkipDocs | null;
|
|
29
|
+
}): DocsPresenceResult;
|
|
30
|
+
/**
|
|
31
|
+
* Whether the PR touches a package's documentation: a doc comment added in its source, its `README.md`, or a docs
|
|
32
|
+
* page named after it (see `pageNames`).
|
|
33
|
+
*/
|
|
34
|
+
export declare function hasDocsSignal(dir: string, changedFiles: readonly string[], addedCommentLines: readonly string[]): boolean;
|
|
35
|
+
/** Whether a line of a unified diff adds part of a doc comment: its `/**` opener, a ` * text` line or the closer. */
|
|
36
|
+
export declare function isAddedDocComment(line: string): boolean;
|
|
37
|
+
/** Whether any subject is a Conventional Commit `feat`: `feat:`, `feat(scope):` or `feat!:`, in any case. */
|
|
38
|
+
export declare function isFeat(subjects: readonly string[]): boolean;
|
|
39
|
+
/**
|
|
40
|
+
* The public package a changed file is source of: the nearest folder above it with a `package.json`, when the file is
|
|
41
|
+
* under that package's `src/` or is its root `index`, and the package is not private. Tests, other package files and
|
|
42
|
+
* files in no package give `undefined`.
|
|
43
|
+
*/
|
|
44
|
+
export declare function packageOf(file: string, readPackage: (dir: string) => {
|
|
45
|
+
private?: boolean;
|
|
46
|
+
} | undefined): string | undefined;
|
|
47
|
+
/**
|
|
48
|
+
* The names a package's docs page can have: its folder name, and that name without the `-client` or
|
|
49
|
+
* `holocron-plugin-` part its page drops (`clients/axiom-client` is the page `clients/axiom.mdx`).
|
|
50
|
+
*/
|
|
51
|
+
export declare function pageNames(dir: string): string[];
|
|
52
|
+
/**
|
|
53
|
+
* Finds `[skip docs] reason`, or `[skip docs: pkg-a, pkg-b] reason`, on one line of a PR description or commit
|
|
54
|
+
* body. Like semantic-release's `[skip ci]`, except that the reason after it is what makes it count. `null` when the
|
|
55
|
+
* text has no marker.
|
|
56
|
+
*/
|
|
57
|
+
export declare function parseSkipDocs(text: string): SkipDocs | null;
|
|
58
|
+
/** One frontmatter field: its trimmed value and the 1-indexed line it sits on in the file. */
|
|
59
|
+
interface SpecField {
|
|
60
|
+
/** The text after the colon, trimmed; empty for a key that only opens a nested block (`discussion:`). */
|
|
61
|
+
value: string;
|
|
62
|
+
/** 1-indexed, counting the opening `---` as line 1. */
|
|
63
|
+
line: number;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* A file's frontmatter by key. One level of nesting is keyed `parent.child` (`discussion.github`), and the parent
|
|
67
|
+
* key is there too.
|
|
68
|
+
*/
|
|
69
|
+
type SpecFrontmatter = Map<string, SpecField>;
|
|
70
|
+
/** The kind of file the ADR and spec check reads: an architecture decision record or a design spec. */
|
|
71
|
+
type SpecKind = "adr" | "spec";
|
|
72
|
+
/** One problem the ADR and spec check found in a file. */
|
|
73
|
+
interface SpecFinding {
|
|
74
|
+
/** The file's repo-relative path, as it was given to the check. */
|
|
75
|
+
file: string;
|
|
76
|
+
/** 1-indexed: the offending field's own line, or the first line when the field (or the whole frontmatter) is missing. */
|
|
77
|
+
line: number;
|
|
78
|
+
/** The frontmatter field at fault (`id`, `status`, ...), or `frontmatter` when there is none at all. */
|
|
79
|
+
rule: string;
|
|
80
|
+
/** What is wrong, as a sentence. */
|
|
81
|
+
reason: string;
|
|
82
|
+
/** An `error` fails the check; a `warning` is reported and never fails it. */
|
|
83
|
+
severity: "error" | "warning";
|
|
84
|
+
}
|
|
85
|
+
/** A file to check: its repo-relative path and its text. */
|
|
86
|
+
interface SpecFile {
|
|
87
|
+
/** Repo-relative, with `/` separators. */
|
|
88
|
+
path: string;
|
|
89
|
+
/** The file's whole text. */
|
|
90
|
+
text: string;
|
|
91
|
+
}
|
|
92
|
+
/** What the ADR and spec check found across the files it was given. */
|
|
93
|
+
interface SpecsResult {
|
|
94
|
+
/** How many of the files were an ADR or a spec (the rest were not the check's business and were skipped). */
|
|
95
|
+
fileCount: number;
|
|
96
|
+
/** Every problem found, in file order. */
|
|
97
|
+
findings: SpecFinding[];
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* The ADR and spec check over the files it is given: each one that is an ADR or a spec (see `classifySpecPath`) goes to
|
|
101
|
+
* its rules, and every other file is skipped. Whoever calls it decides which files to read (the whole tree, a PR's
|
|
102
|
+
* changed files) and supplies their text; nothing here touches the filesystem or the network.
|
|
103
|
+
*/
|
|
104
|
+
export declare function checkSpecs(files: readonly SpecFile[]): SpecsResult;
|
|
105
|
+
/**
|
|
106
|
+
* What a repo-relative path is to the ADR and spec check: an `adr` (a `.md` file directly in the ADR folder, other
|
|
107
|
+
* than the template and the README), a `spec` (a `*.spec.md` file directly in `.notes` or the wiki's specifications
|
|
108
|
+
* folder), or `undefined` for anything else, which the check leaves alone. Subfolders are not searched.
|
|
109
|
+
*/
|
|
110
|
+
export declare function classifySpecPath(path: string): SpecKind | undefined;
|
|
111
|
+
/** Whether `value` is a `YYYY-MM-DD` date that exists as far as `Date.parse` can tell. */
|
|
112
|
+
export declare function isValidIsoDate(value: string): boolean;
|
|
113
|
+
/**
|
|
114
|
+
* Reads a leading `---` block of `key: value` lines, with the line each one is on, plus one level of nesting keyed
|
|
115
|
+
* `parent.child` (the ADR template's `discussion:` / ` github:`). Any other line is skipped. Returns `null` when the
|
|
116
|
+
* text does not open with such a block.
|
|
117
|
+
*/
|
|
118
|
+
export declare function parseFrontmatter(content: string): SpecFrontmatter | null;
|
|
119
|
+
/** Where ADRs live, relative to the repo root. */
|
|
120
|
+
export declare const ADR_DIR = "docs/wiki/decisions";
|
|
121
|
+
/** Where specs live, relative to the repo root: in-progress ones in `.notes`, settled ones under the wiki. */
|
|
122
|
+
export declare const SPEC_DIRS: readonly string[];
|
|
123
|
+
/** The statuses an ADR may have. */
|
|
124
|
+
export declare const ADR_STATUSES: readonly string[];
|
|
125
|
+
/** The statuses a spec may have. */
|
|
126
|
+
export declare const SPEC_STATUSES: readonly string[];
|
|
127
|
+
/** The files in the ADR folder that are not ADRs. */
|
|
128
|
+
export declare const ADR_EXEMPT: readonly string[];
|
|
129
|
+
/**
|
|
130
|
+
* The findings for one ADR's text. Errors: no frontmatter; a missing `id`, or one that is not `ADR-<the filename's
|
|
131
|
+
* four-digit prefix>`; a missing or empty `title`; a missing or unknown `status`; a missing or malformed `date`. A
|
|
132
|
+
* warning: an `accepted` ADR whose `discussion.github` is not set.
|
|
133
|
+
*/
|
|
134
|
+
export declare function validateAdr(file: string, content: string): SpecFinding[];
|
|
135
|
+
/**
|
|
136
|
+
* The findings for one spec's text. Errors: no frontmatter; a missing or unknown `status`. A warning: a missing
|
|
137
|
+
* `issue` (every spec has a companion GitHub issue), except on an `archived` or `superseded` spec, many of which
|
|
138
|
+
* predate the issue-first process.
|
|
139
|
+
*/
|
|
140
|
+
export declare function validateSpec(file: string, content: string): SpecFinding[];
|
|
141
|
+
export type { DocsPresenceResult, SkipDocs, SpecField, SpecFile, SpecFinding, SpecFrontmatter, SpecKind, SpecsResult };
|
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
// src/repo-validation/docs-presence/page-names/page-names.ts
|
|
2
|
+
/**
|
|
3
|
+
* The names a package's docs page can have: its folder name, and that name without the `-client` or
|
|
4
|
+
* `holocron-plugin-` part its page drops (`clients/axiom-client` is the page `clients/axiom.mdx`).
|
|
5
|
+
*/
|
|
6
|
+
function pageNames(dir) {
|
|
7
|
+
const name = dir.slice(dir.lastIndexOf("/") + 1);
|
|
8
|
+
return [.../* @__PURE__ */ new Set([
|
|
9
|
+
name,
|
|
10
|
+
name.replace(/-client$/, ""),
|
|
11
|
+
name.replace(/^holocron-plugin-/, "")
|
|
12
|
+
])];
|
|
13
|
+
}
|
|
14
|
+
// src/repo-validation/docs-presence/has-docs-signal/has-docs-signal.ts
|
|
15
|
+
/**
|
|
16
|
+
* Whether the PR touches a package's documentation: a doc comment added in its source, its `README.md`, or a docs
|
|
17
|
+
* page named after it (see `pageNames`).
|
|
18
|
+
*/
|
|
19
|
+
function hasDocsSignal(dir, changedFiles, addedCommentLines) {
|
|
20
|
+
if (addedCommentLines.length > 0) return true;
|
|
21
|
+
const names = pageNames(dir);
|
|
22
|
+
return changedFiles.some((f) => {
|
|
23
|
+
if (f === `${dir}/README.md`) return true;
|
|
24
|
+
if (!f.startsWith("docs/") || !/\.mdx?$/.test(f)) return false;
|
|
25
|
+
return names.includes(f.slice(f.lastIndexOf("/") + 1).replace(/\.mdx?$/, ""));
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
// src/repo-validation/docs-presence/evaluate-docs-presence/evaluate-docs-presence.ts
|
|
29
|
+
/**
|
|
30
|
+
* Sorts the packages a feature changed into those that need a warning (no docs signal, and no `[skip docs]` marker
|
|
31
|
+
* with a reason that covers them) and those a marker excused. A marker with no reason excuses nothing.
|
|
32
|
+
*/
|
|
33
|
+
function evaluateDocsPresence(input) {
|
|
34
|
+
const { packages, changedFiles, addedCommentLines, skip } = input;
|
|
35
|
+
const result = {
|
|
36
|
+
warn: [],
|
|
37
|
+
skipped: [],
|
|
38
|
+
missingReason: false
|
|
39
|
+
};
|
|
40
|
+
for (const dir of packages) {
|
|
41
|
+
if (hasDocsSignal(dir, changedFiles, addedCommentLines(dir))) continue;
|
|
42
|
+
const covered = skip !== null && (skip.scope === null || skip.scope.some((s) => s === dir || pageNames(dir).includes(s)));
|
|
43
|
+
if (covered && skip.reason) {
|
|
44
|
+
result.skipped.push({
|
|
45
|
+
dir,
|
|
46
|
+
reason: skip.reason
|
|
47
|
+
});
|
|
48
|
+
continue;
|
|
49
|
+
}
|
|
50
|
+
if (covered) result.missingReason = true;
|
|
51
|
+
result.warn.push(dir);
|
|
52
|
+
}
|
|
53
|
+
return result;
|
|
54
|
+
}
|
|
55
|
+
// src/repo-validation/docs-presence/is-added-doc-comment/is-added-doc-comment.ts
|
|
56
|
+
/** Whether a line of a unified diff adds part of a doc comment: its `/**` opener, a ` * text` line or the closer. */
|
|
57
|
+
function isAddedDocComment(line) {
|
|
58
|
+
return /^\+\s*(\/\*\*|\*(\s|\/|$))/.test(line);
|
|
59
|
+
}
|
|
60
|
+
// src/repo-validation/docs-presence/is-feat/is-feat.ts
|
|
61
|
+
/** Whether any subject is a Conventional Commit `feat`: `feat:`, `feat(scope):` or `feat!:`, in any case. */
|
|
62
|
+
function isFeat(subjects) {
|
|
63
|
+
return subjects.some((s) => /^feat(\([^)]*\))?!?:/i.test(s.trim()));
|
|
64
|
+
}
|
|
65
|
+
// src/repo-validation/docs-presence/package-of/package-of.ts
|
|
66
|
+
/**
|
|
67
|
+
* The public package a changed file is source of: the nearest folder above it with a `package.json`, when the file is
|
|
68
|
+
* under that package's `src/` or is its root `index`, and the package is not private. Tests, other package files and
|
|
69
|
+
* files in no package give `undefined`.
|
|
70
|
+
*/
|
|
71
|
+
function packageOf(file, readPackage) {
|
|
72
|
+
if (file.includes("node_modules/") || /\.(test|spec)\.[cm]?[jt]sx?$/.test(file)) return void 0;
|
|
73
|
+
const parts = file.split("/");
|
|
74
|
+
for (let i = parts.length - 1; i > 0; i--) {
|
|
75
|
+
const dir = parts.slice(0, i).join("/");
|
|
76
|
+
const pkg = readPackage(dir);
|
|
77
|
+
if (!pkg) continue;
|
|
78
|
+
if (pkg.private) return void 0;
|
|
79
|
+
const inside = parts.slice(i).join("/");
|
|
80
|
+
return inside.startsWith("src/") || /^index\.[cm]?[jt]s$/.test(inside) ? dir : void 0;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
// src/repo-validation/docs-presence/parse-skip-docs/parse-skip-docs.ts
|
|
84
|
+
/**
|
|
85
|
+
* Finds `[skip docs] reason`, or `[skip docs: pkg-a, pkg-b] reason`, on one line of a PR description or commit
|
|
86
|
+
* body. Like semantic-release's `[skip ci]`, except that the reason after it is what makes it count. `null` when the
|
|
87
|
+
* text has no marker.
|
|
88
|
+
*/
|
|
89
|
+
function parseSkipDocs(text) {
|
|
90
|
+
const match = /\[skip docs(?::\s*([^\]]*?))?\][ \t]*([^\n]*)/i.exec(text);
|
|
91
|
+
if (!match) return null;
|
|
92
|
+
return {
|
|
93
|
+
scope: match[1] ? match[1].split(",").map((s) => s.trim()).filter(Boolean) : null,
|
|
94
|
+
reason: match[2].trim()
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
// src/repo-validation/specs/spec-locations/spec-locations.ts
|
|
98
|
+
/** Where ADRs live, relative to the repo root. */
|
|
99
|
+
const ADR_DIR = "docs/wiki/decisions";
|
|
100
|
+
/** Where specs live, relative to the repo root: in-progress ones in `.notes`, settled ones under the wiki. */
|
|
101
|
+
const SPEC_DIRS = [".notes", "docs/wiki/specifications"];
|
|
102
|
+
/** The statuses an ADR may have. */
|
|
103
|
+
const ADR_STATUSES = [
|
|
104
|
+
"proposed",
|
|
105
|
+
"accepted",
|
|
106
|
+
"rejected",
|
|
107
|
+
"deprecated",
|
|
108
|
+
"superseded"
|
|
109
|
+
];
|
|
110
|
+
/** The statuses a spec may have. */
|
|
111
|
+
const SPEC_STATUSES = [
|
|
112
|
+
"draft",
|
|
113
|
+
"proposed",
|
|
114
|
+
"accepted",
|
|
115
|
+
"archived",
|
|
116
|
+
"superseded"
|
|
117
|
+
];
|
|
118
|
+
/** The files in the ADR folder that are not ADRs. */
|
|
119
|
+
const ADR_EXEMPT = ["template.md", "README.md"];
|
|
120
|
+
// src/repo-validation/specs/classify-spec-path/classify-spec-path.ts
|
|
121
|
+
/**
|
|
122
|
+
* What a repo-relative path is to the ADR and spec check: an `adr` (a `.md` file directly in the ADR folder, other
|
|
123
|
+
* than the template and the README), a `spec` (a `*.spec.md` file directly in `.notes` or the wiki's specifications
|
|
124
|
+
* folder), or `undefined` for anything else, which the check leaves alone. Subfolders are not searched.
|
|
125
|
+
*/
|
|
126
|
+
function classifySpecPath(path) {
|
|
127
|
+
const slash = path.lastIndexOf("/");
|
|
128
|
+
const dir = path.slice(0, slash);
|
|
129
|
+
const name = path.slice(slash + 1);
|
|
130
|
+
if (dir === "docs/wiki/decisions") return name.endsWith(".md") && !ADR_EXEMPT.includes(name) ? "adr" : void 0;
|
|
131
|
+
if (SPEC_DIRS.includes(dir)) return name.endsWith(".spec.md") ? "spec" : void 0;
|
|
132
|
+
}
|
|
133
|
+
// src/repo-validation/specs/is-valid-iso-date/is-valid-iso-date.ts
|
|
134
|
+
/** Whether `value` is a `YYYY-MM-DD` date that exists as far as `Date.parse` can tell. */
|
|
135
|
+
function isValidIsoDate(value) {
|
|
136
|
+
return /^\d{4}-\d{2}-\d{2}$/.test(value) && !Number.isNaN(Date.parse(value));
|
|
137
|
+
}
|
|
138
|
+
// src/repo-validation/specs/parse-frontmatter/parse-frontmatter.ts
|
|
139
|
+
/**
|
|
140
|
+
* Reads a leading `---` block of `key: value` lines, with the line each one is on, plus one level of nesting keyed
|
|
141
|
+
* `parent.child` (the ADR template's `discussion:` / ` github:`). Any other line is skipped. Returns `null` when the
|
|
142
|
+
* text does not open with such a block.
|
|
143
|
+
*/
|
|
144
|
+
function parseFrontmatter(content) {
|
|
145
|
+
const match = /^---\n([\s\S]*?)\n---/.exec(content);
|
|
146
|
+
if (!match) return null;
|
|
147
|
+
const fields = /* @__PURE__ */ new Map();
|
|
148
|
+
let parent;
|
|
149
|
+
match[1].split("\n").forEach((text, i) => {
|
|
150
|
+
const line = i + 2;
|
|
151
|
+
const kv = /^(\w[\w-]*):\s*(.*)/.exec(text);
|
|
152
|
+
if (kv) {
|
|
153
|
+
fields.set(kv[1], {
|
|
154
|
+
value: kv[2].trim(),
|
|
155
|
+
line
|
|
156
|
+
});
|
|
157
|
+
parent = kv[1];
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
const nested = /^\s+(\w[\w-]*):\s*(.*)/.exec(text);
|
|
161
|
+
if (nested && parent) fields.set(`${parent}.${nested[1]}`, {
|
|
162
|
+
value: nested[2].trim(),
|
|
163
|
+
line
|
|
164
|
+
});
|
|
165
|
+
});
|
|
166
|
+
return fields;
|
|
167
|
+
}
|
|
168
|
+
// src/repo-validation/specs/validate-adr/validate-adr.ts
|
|
169
|
+
/**
|
|
170
|
+
* The findings for one ADR's text. Errors: no frontmatter; a missing `id`, or one that is not `ADR-<the filename's
|
|
171
|
+
* four-digit prefix>`; a missing or empty `title`; a missing or unknown `status`; a missing or malformed `date`. A
|
|
172
|
+
* warning: an `accepted` ADR whose `discussion.github` is not set.
|
|
173
|
+
*/
|
|
174
|
+
function validateAdr(file, content) {
|
|
175
|
+
const findings = [];
|
|
176
|
+
const add = (rule, reason, line = 1, severity = "error") => {
|
|
177
|
+
findings.push({
|
|
178
|
+
file,
|
|
179
|
+
line,
|
|
180
|
+
rule,
|
|
181
|
+
reason,
|
|
182
|
+
severity
|
|
183
|
+
});
|
|
184
|
+
};
|
|
185
|
+
const fm = parseFrontmatter(content);
|
|
186
|
+
if (!fm) {
|
|
187
|
+
add("frontmatter", "no frontmatter found");
|
|
188
|
+
return findings;
|
|
189
|
+
}
|
|
190
|
+
const id = fm.get("id");
|
|
191
|
+
const sequence = /^(\d{4})-/.exec(file.slice(file.lastIndexOf("/") + 1))?.[1];
|
|
192
|
+
if (!id?.value) add("id", "missing `id` field", id?.line);
|
|
193
|
+
else if (sequence && id.value !== `ADR-${sequence}`) add("id", `id "${id.value}" does not match filename sequence (expected ADR-${sequence})`, id.line);
|
|
194
|
+
const title = fm.get("title");
|
|
195
|
+
if (!title?.value || title.value === "\"\"" || title.value === "''") add("title", "missing or empty `title` field", title?.line);
|
|
196
|
+
const status = fm.get("status");
|
|
197
|
+
if (!status?.value) add("status", "missing `status` field", status?.line);
|
|
198
|
+
else if (!ADR_STATUSES.includes(status.value)) add("status", `invalid status "${status.value}" — must be one of: ${ADR_STATUSES.join(", ")}`, status.line);
|
|
199
|
+
const date = fm.get("date");
|
|
200
|
+
if (!date?.value) add("date", "missing `date` field", date?.line);
|
|
201
|
+
else if (!isValidIsoDate(date.value)) add("date", `invalid date "${date.value}" — must be YYYY-MM-DD`, date.line);
|
|
202
|
+
if (status?.value === "accepted" && !fm.get("discussion.github")?.value && !fm.get("discussion")?.value) add("discussion", "status is accepted but `discussion.github` is not set", status.line, "warning");
|
|
203
|
+
return findings;
|
|
204
|
+
}
|
|
205
|
+
// src/repo-validation/specs/validate-spec/validate-spec.ts
|
|
206
|
+
/**
|
|
207
|
+
* The findings for one spec's text. Errors: no frontmatter; a missing or unknown `status`. A warning: a missing
|
|
208
|
+
* `issue` (every spec has a companion GitHub issue), except on an `archived` or `superseded` spec, many of which
|
|
209
|
+
* predate the issue-first process.
|
|
210
|
+
*/
|
|
211
|
+
function validateSpec(file, content) {
|
|
212
|
+
const fm = parseFrontmatter(content);
|
|
213
|
+
if (!fm) return [{
|
|
214
|
+
file,
|
|
215
|
+
line: 1,
|
|
216
|
+
rule: "frontmatter",
|
|
217
|
+
reason: "no frontmatter found",
|
|
218
|
+
severity: "error"
|
|
219
|
+
}];
|
|
220
|
+
const findings = [];
|
|
221
|
+
const status = fm.get("status");
|
|
222
|
+
if (!status?.value) findings.push({
|
|
223
|
+
file,
|
|
224
|
+
line: status?.line ?? 1,
|
|
225
|
+
rule: "status",
|
|
226
|
+
reason: "missing `status` field",
|
|
227
|
+
severity: "error"
|
|
228
|
+
});
|
|
229
|
+
else if (!SPEC_STATUSES.includes(status.value)) findings.push({
|
|
230
|
+
file,
|
|
231
|
+
line: status.line,
|
|
232
|
+
rule: "status",
|
|
233
|
+
reason: `invalid status "${status.value}" — must be one of: ${SPEC_STATUSES.join(", ")}`,
|
|
234
|
+
severity: "error"
|
|
235
|
+
});
|
|
236
|
+
if (!fm.get("issue")?.value && status?.value !== "archived" && status?.value !== "superseded") findings.push({
|
|
237
|
+
file,
|
|
238
|
+
line: 1,
|
|
239
|
+
rule: "issue",
|
|
240
|
+
reason: "missing `issue` field — every spec must have a companion GitHub issue",
|
|
241
|
+
severity: "warning"
|
|
242
|
+
});
|
|
243
|
+
return findings;
|
|
244
|
+
}
|
|
245
|
+
// src/repo-validation/specs/check-specs/check-specs.ts
|
|
246
|
+
/**
|
|
247
|
+
* The ADR and spec check over the files it is given: each one that is an ADR or a spec (see `classifySpecPath`) goes to
|
|
248
|
+
* its rules, and every other file is skipped. Whoever calls it decides which files to read (the whole tree, a PR's
|
|
249
|
+
* changed files) and supplies their text; nothing here touches the filesystem or the network.
|
|
250
|
+
*/
|
|
251
|
+
function checkSpecs(files) {
|
|
252
|
+
const result = {
|
|
253
|
+
fileCount: 0,
|
|
254
|
+
findings: []
|
|
255
|
+
};
|
|
256
|
+
for (const { path, text } of files) {
|
|
257
|
+
const kind = classifySpecPath(path);
|
|
258
|
+
if (!kind) continue;
|
|
259
|
+
result.fileCount++;
|
|
260
|
+
result.findings.push(...kind === "adr" ? validateAdr(path, text) : validateSpec(path, text));
|
|
261
|
+
}
|
|
262
|
+
return result;
|
|
263
|
+
}
|
|
264
|
+
export { ADR_DIR, ADR_EXEMPT, ADR_STATUSES, SPEC_DIRS, SPEC_STATUSES, checkSpecs, classifySpecPath, evaluateDocsPresence, hasDocsSignal, isAddedDocComment, isFeat, isValidIsoDate, packageOf, pageNames, parseFrontmatter, parseSkipDocs, validateAdr, validateSpec };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@theholocron/astromech",
|
|
3
|
-
"version": "5.0.0-alpha.
|
|
3
|
+
"version": "5.0.0-alpha.285",
|
|
4
4
|
"description": "The Holocron task runner — one task manifest drives `holocron run`, `holocron run ci`, the CI workflows, package.json scripts, linters, and required checks.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ci",
|
|
@@ -41,6 +41,11 @@
|
|
|
41
41
|
"types": "./dist/release/index.d.mts",
|
|
42
42
|
"import": "./dist/release/index.mjs",
|
|
43
43
|
"default": "./dist/release/index.mjs"
|
|
44
|
+
},
|
|
45
|
+
"./repo-validation": {
|
|
46
|
+
"types": "./dist/repo-validation/index.d.mts",
|
|
47
|
+
"import": "./dist/repo-validation/index.mjs",
|
|
48
|
+
"default": "./dist/repo-validation/index.mjs"
|
|
44
49
|
}
|
|
45
50
|
},
|
|
46
51
|
"files": [
|
|
@@ -50,7 +55,7 @@
|
|
|
50
55
|
"@commitlint/lint": "^21.2.3",
|
|
51
56
|
"@commitlint/load": "^21.2.3",
|
|
52
57
|
"@commitlint/types": "^21.2.3",
|
|
53
|
-
"@theholocron/datapad": "5.0.0-alpha.
|
|
58
|
+
"@theholocron/datapad": "5.0.0-alpha.285",
|
|
54
59
|
"@theholocron/fs-utils": "^1.16.1-alpha.3",
|
|
55
60
|
"@theholocron/json-utils": "^1.16.1-alpha.3",
|
|
56
61
|
"@theholocron/pkg-utils": "^1.16.1-alpha.3"
|
|
@@ -69,14 +74,14 @@
|
|
|
69
74
|
"tsdown": "^0.23.3",
|
|
70
75
|
"typescript": "^5.9.3",
|
|
71
76
|
"vitest": "^5.0.5",
|
|
72
|
-
"@theholocron/ci": "1.0.0",
|
|
73
77
|
"@theholocron/commitlint-config": "^8.9.0-alpha.5",
|
|
74
|
-
"@theholocron/eslint-config": "^8.9.0-alpha.5",
|
|
75
78
|
"@theholocron/rollup-plugin-transform-template": "^8.9.0-alpha.5",
|
|
76
|
-
"@theholocron/
|
|
79
|
+
"@theholocron/ci": "1.0.0",
|
|
77
80
|
"@theholocron/semantic-release-config": "^8.9.0-alpha.5",
|
|
81
|
+
"@theholocron/tsdown-config": "^8.9.0-alpha.5",
|
|
78
82
|
"@theholocron/tsconfig": "^8.9.0-alpha.5",
|
|
79
|
-
"@theholocron/vitest-config": "^8.9.0-alpha.5"
|
|
83
|
+
"@theholocron/vitest-config": "^8.9.0-alpha.5",
|
|
84
|
+
"@theholocron/eslint-config": "^8.9.0-alpha.5"
|
|
80
85
|
},
|
|
81
86
|
"peerDependencies": {
|
|
82
87
|
"@semantic-release/commit-analyzer": "^13",
|