@theholocron/astromech 5.0.0-alpha.36 → 5.0.0-alpha.360

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.
@@ -0,0 +1,106 @@
1
+ import { QualifiedConfig } from "@commitlint/types";
2
+ /**
3
+ * The org's canonical `alex` (inclusive-language) config, as raw parsed
4
+ * data rather than the pre-rendered file strings `createRcConfig()`/
5
+ * `createIgnoreConfig()` produce for `holocron repo setup` to write into a
6
+ * repo's own `.alexrc.json`/`.alexignore`.
7
+ *
8
+ * `.alexrc.json` is explicitly "generated by `holocron repo setup` — do not
9
+ * edit manually" (this repo's own `AGENTS.md`) — the real source of truth
10
+ * is this JSON file, one canonical copy, not each repo's synced one. A
11
+ * central Sentinel check (holocron#769/#793) reads it directly rather
12
+ * than fetching each repo's own copy via the Contents API — the same "one
13
+ * config, not N copies" reasoning `@theholocron/commitlint-config` already
14
+ * established for commit-message linting.
15
+ */
16
+ /**
17
+ * The org's canonical `alex` (inclusive-language) config as data: the words it allows, from the one JSON file
18
+ * `holocron repo setup` writes into each repo's `.alexrc.json`.
19
+ */
20
+ export declare const ALEX_CONFIG: {
21
+ /** The words `alex` accepts despite its default rules. */
22
+ allow: string[];
23
+ };
24
+ /**
25
+ * Glob-ish path patterns `alex` skips. Kept as a literal here rather than
26
+ * importing `../templates/configs/alexjs/alexignore` directly — that file
27
+ * (like `commit-msg`/`pre-push`) is deliberately extensionless, matching
28
+ * the real filename `holocron repo setup` writes, which ECMAScript's own
29
+ * module resolution (`moduleResolution: "nodenext"`) can't import across
30
+ * a package boundary without an extension. Keep in sync with that file by
31
+ * hand; it changes rarely.
32
+ */
33
+ export declare const ALEX_IGNORE_PATTERNS: string[];
34
+ /**
35
+ * The paths editorconfig-checker skips, read from the same
36
+ * `editorconfig-checker.json` template `holocron repo setup` writes as a repo's
37
+ * `.editorconfig-checker.json` — so Sentinel's central editorconfig check
38
+ * (holocron#927) excludes exactly what CI's editorconfig-checker does, from
39
+ * one source.
40
+ *
41
+ * The exclusion that matters most is `\.md$` / `\.mdx$`: the generated
42
+ * `.editorconfig` gives every file tab indentation, but
43
+ * `@theholocron/prettier-config` formats markdown with spaces, so a README's
44
+ * indented code example would fail one tool or the other. Markdown is left
45
+ * to prettier and markdownlint.
46
+ *
47
+ * Each entry is a regular-expression source, matched against a
48
+ * repo-relative path, as editorconfig-checker itself treats them.
49
+ */
50
+ /**
51
+ * The paths editorconfig-checker skips, as regular-expression sources matched against a repo-relative path; the
52
+ * list `holocron repo setup` writes into `.editorconfig-checker.json`.
53
+ */
54
+ export declare const EDITORCONFIG_CHECKER_EXCLUDE: readonly string[];
55
+ /** `true` when `path` matches any {@link EDITORCONFIG_CHECKER_EXCLUDE} pattern. */
56
+ export declare function isEditorConfigExcluded(path: string): boolean;
57
+ /** One commitlint rule a commit message broke. */
58
+ interface CommitMessageViolation {
59
+ /** Rule name, e.g. `"subject-empty"`. */
60
+ rule: string;
61
+ /** commitlint's own message for the failure, e.g. `"subject may not be empty"`. */
62
+ message: string;
63
+ }
64
+ /**
65
+ * Lints one commit message against an already-loaded commitlint config and returns each rule it breaks; an empty
66
+ * list means it is valid.
67
+ */
68
+ export declare function lintCommitMessage(message: string, loaded: QualifiedConfig): Promise<CommitMessageViolation[]>;
69
+ /** What linting a commit message file found. */
70
+ interface LintCommitMsgFileResult {
71
+ /** Whether the message broke no rule. */
72
+ valid: boolean;
73
+ /** Each rule the message broke; empty when it is valid. */
74
+ violations: CommitMessageViolation[];
75
+ }
76
+ /**
77
+ * Lints the commit message in `filePath` (what git's `commit-msg` hook passes as `$1`) against the commitlint
78
+ * config found by searching up from `cwd`.
79
+ */
80
+ export declare function lintCommitMsgFile(filePath: string, cwd?: string): Promise<LintCommitMsgFileResult>;
81
+ /**
82
+ * The org's canonical prettier ignore-pattern list for a central Sentinel
83
+ * check (holocron#769/#819) — the `PRETTIER_CONFIG` object itself doesn't
84
+ * need a home here, since `@theholocron/prettier-config`'s default export
85
+ * already *is* one canonical, importable config (the same "one config,
86
+ * not N copies" reasoning `@theholocron/commitlint-config` established for
87
+ * commit-message linting, and `ALEX_CONFIG` established for inclusive
88
+ * language) — only the ignore list is a Sentinel-specific decision that
89
+ * belongs alongside `ALEX_IGNORE_PATTERNS`, not inside the config package.
90
+ *
91
+ * Reuses `ALEX_IGNORE_PATTERNS`' own entries (`.github/*`, `CHANGELOG.md`,
92
+ * `LICENSE` all independently confirmed to fail a real `prettier.check()`
93
+ * today — machine-generated or unparseable content, same reasoning that
94
+ * excluded them from alex), plus `pnpm-lock.yaml` — prettier-specific
95
+ * (alex never reads a lockfile, but prettier would try to reformat it):
96
+ * machine-written by pnpm's own writer, and not gitignored (lockfiles are
97
+ * tracked), so prettier picks it up by default. Reformatting it
98
+ * fights every subsequent `pnpm install` (this repo's own `.prettierignore`
99
+ * already excludes it for that exact reason).
100
+ */
101
+ /**
102
+ * The paths Prettier skips in every repo: the ones inclusive-language checking skips, plus the pnpm lockfile, which
103
+ * pnpm writes itself.
104
+ */
105
+ export declare const PRETTIER_IGNORE_PATTERNS: string[];
106
+ export type { CommitMessageViolation, LintCommitMsgFileResult };
@@ -0,0 +1,156 @@
1
+ import { n as alexrc_default, t as editorconfig_checker_default } from "../editorconfig-checker-HPpphHhI.mjs";
2
+ import { readFile } from "node:fs/promises";
3
+ import load from "@commitlint/load";
4
+ import lint from "@commitlint/lint";
5
+ // src/lint/alex-config/alex-config.ts
6
+ /**
7
+ * The org's canonical `alex` (inclusive-language) config, as raw parsed
8
+ * data rather than the pre-rendered file strings `createRcConfig()`/
9
+ * `createIgnoreConfig()` produce for `holocron repo setup` to write into a
10
+ * repo's own `.alexrc.json`/`.alexignore`.
11
+ *
12
+ * `.alexrc.json` is explicitly "generated by `holocron repo setup` — do not
13
+ * edit manually" (this repo's own `AGENTS.md`) — the real source of truth
14
+ * is this JSON file, one canonical copy, not each repo's synced one. A
15
+ * central Sentinel check (holocron#769/#793) reads it directly rather
16
+ * than fetching each repo's own copy via the Contents API — the same "one
17
+ * config, not N copies" reasoning `@theholocron/commitlint-config` already
18
+ * established for commit-message linting.
19
+ */
20
+ /**
21
+ * The org's canonical `alex` (inclusive-language) config as data: the words it allows, from the one JSON file
22
+ * `holocron repo setup` writes into each repo's `.alexrc.json`.
23
+ */
24
+ const ALEX_CONFIG = alexrc_default;
25
+ // src/lint/alex-ignore-patterns/alex-ignore-patterns.ts
26
+ /**
27
+ * Glob-ish path patterns `alex` skips. Kept as a literal here rather than
28
+ * importing `../templates/configs/alexjs/alexignore` directly — that file
29
+ * (like `commit-msg`/`pre-push`) is deliberately extensionless, matching
30
+ * the real filename `holocron repo setup` writes, which ECMAScript's own
31
+ * module resolution (`moduleResolution: "nodenext"`) can't import across
32
+ * a package boundary without an extension. Keep in sync with that file by
33
+ * hand; it changes rarely.
34
+ */
35
+ const ALEX_IGNORE_PATTERNS = [
36
+ ".github/*",
37
+ "CHANGELOG.md",
38
+ "LICENSE"
39
+ ];
40
+ // src/lint/editorconfig-checker-exclude/editorconfig-checker-exclude.ts
41
+ /**
42
+ * The paths editorconfig-checker skips, read from the same
43
+ * `editorconfig-checker.json` template `holocron repo setup` writes as a repo's
44
+ * `.editorconfig-checker.json` — so Sentinel's central editorconfig check
45
+ * (holocron#927) excludes exactly what CI's editorconfig-checker does, from
46
+ * one source.
47
+ *
48
+ * The exclusion that matters most is `\.md$` / `\.mdx$`: the generated
49
+ * `.editorconfig` gives every file tab indentation, but
50
+ * `@theholocron/prettier-config` formats markdown with spaces, so a README's
51
+ * indented code example would fail one tool or the other. Markdown is left
52
+ * to prettier and markdownlint.
53
+ *
54
+ * Each entry is a regular-expression source, matched against a
55
+ * repo-relative path, as editorconfig-checker itself treats them.
56
+ */
57
+ /**
58
+ * The paths editorconfig-checker skips, as regular-expression sources matched against a repo-relative path; the
59
+ * list `holocron repo setup` writes into `.editorconfig-checker.json`.
60
+ */
61
+ const EDITORCONFIG_CHECKER_EXCLUDE = editorconfig_checker_default.Exclude;
62
+ // src/lint/is-editorconfig-excluded/is-editorconfig-excluded.ts
63
+ /** `true` when `path` matches any {@link EDITORCONFIG_CHECKER_EXCLUDE} pattern. */
64
+ function isEditorConfigExcluded(path) {
65
+ return EDITORCONFIG_CHECKER_EXCLUDE.some((pattern) => new RegExp(pattern).test(path));
66
+ }
67
+ // src/lint/lint-message/lint-message.ts
68
+ /**
69
+ * Lints one commit message string against an already-loaded commitlint
70
+ * config. The genuinely environment-independent half of commit-message
71
+ * linting (holocron#789) — *obtaining* a `QualifiedConfig` differs by
72
+ * caller (Sentinel isolates itself from any ambient config since it runs
73
+ * standalone, away from a real repo checkout; `lintCommitMsgFile` below
74
+ * lets cosmiconfig discover the invoking repo's own
75
+ * `commitlint.config.*`, matching `commitlint --edit`'s own contract) —
76
+ * but linting one message against a loaded config is identical either way.
77
+ *
78
+ * Real `@commitlint/lint` — the same programmatic API `@commitlint/cli`
79
+ * itself uses internally — never a reimplementation of commitlint's rules.
80
+ */
81
+ /** `parserPreset.parserOpts`, if the loaded config sets one — same lookup `@commitlint/cli`'s own `selectParserOpts()` does. */
82
+ function selectParserOpts(parserPreset) {
83
+ return parserPreset?.parserOpts;
84
+ }
85
+ /**
86
+ * Lints one commit message against an already-loaded commitlint config and returns each rule it breaks; an empty
87
+ * list means it is valid.
88
+ */
89
+ async function lintCommitMessage(message, loaded) {
90
+ const opts = {
91
+ /* istanbul ignore next -- see comment above */
92
+ parserOpts: selectParserOpts(loaded.parserPreset) ?? {},
93
+ plugins: loaded.plugins,
94
+ /* istanbul ignore next -- see comment above */
95
+ ignores: loaded.ignores ?? [],
96
+ defaultIgnores: loaded.defaultIgnores !== false
97
+ };
98
+ const outcome = await lint(message, loaded.rules, opts);
99
+ if (outcome.valid) return [];
100
+ return outcome.errors.map((error) => ({
101
+ rule: error.name,
102
+ message: error.message
103
+ }));
104
+ }
105
+ // src/lint/lint-commit-msg-file/lint-commit-msg-file.ts
106
+ /**
107
+ * `holocron run lint commit-msg <file>` — a real programmatic replacement for
108
+ * shelling out to `commitlint --edit "$1"` from `.husky/commit-msg`
109
+ * (holocron#789). Matches that CLI's own contract exactly: `file` is a
110
+ * path to the commit message being written (the arg git's `commit-msg`
111
+ * hook passes as `$1`), no `--config` override needed — `@commitlint/load`
112
+ * runs from `cwd` with no seed, so cosmiconfig's own normal upward search
113
+ * discovers the invoking repo's real `commitlint.config.*` file, exactly
114
+ * as `commitlint --edit` (no `--config` flag) already does today. Unlike
115
+ * Sentinel's `loadIsolatedConfig()`, no isolation is needed here — this
116
+ * runs inside a real repo checkout with a real `node_modules`, not
117
+ * standalone on a server.
118
+ */
119
+ /**
120
+ * Lints the commit message in `filePath` (what git's `commit-msg` hook passes as `$1`) against the commitlint
121
+ * config found by searching up from `cwd`.
122
+ */
123
+ async function lintCommitMsgFile(filePath, cwd = process.cwd()) {
124
+ const violations = await lintCommitMessage(await readFile(filePath, "utf8"), await load({}, { cwd }));
125
+ return {
126
+ valid: violations.length === 0,
127
+ violations
128
+ };
129
+ }
130
+ // src/lint/prettier-ignore-patterns/prettier-ignore-patterns.ts
131
+ /**
132
+ * The org's canonical prettier ignore-pattern list for a central Sentinel
133
+ * check (holocron#769/#819) — the `PRETTIER_CONFIG` object itself doesn't
134
+ * need a home here, since `@theholocron/prettier-config`'s default export
135
+ * already *is* one canonical, importable config (the same "one config,
136
+ * not N copies" reasoning `@theholocron/commitlint-config` established for
137
+ * commit-message linting, and `ALEX_CONFIG` established for inclusive
138
+ * language) — only the ignore list is a Sentinel-specific decision that
139
+ * belongs alongside `ALEX_IGNORE_PATTERNS`, not inside the config package.
140
+ *
141
+ * Reuses `ALEX_IGNORE_PATTERNS`' own entries (`.github/*`, `CHANGELOG.md`,
142
+ * `LICENSE` all independently confirmed to fail a real `prettier.check()`
143
+ * today — machine-generated or unparseable content, same reasoning that
144
+ * excluded them from alex), plus `pnpm-lock.yaml` — prettier-specific
145
+ * (alex never reads a lockfile, but prettier would try to reformat it):
146
+ * machine-written by pnpm's own writer, and not gitignored (lockfiles are
147
+ * tracked), so prettier picks it up by default. Reformatting it
148
+ * fights every subsequent `pnpm install` (this repo's own `.prettierignore`
149
+ * already excludes it for that exact reason).
150
+ */
151
+ /**
152
+ * The paths Prettier skips in every repo: the ones inclusive-language checking skips, plus the pnpm lockfile, which
153
+ * pnpm writes itself.
154
+ */
155
+ const PRETTIER_IGNORE_PATTERNS = [...ALEX_IGNORE_PATTERNS, "pnpm-lock.yaml"];
156
+ export { ALEX_CONFIG, ALEX_IGNORE_PATTERNS, EDITORCONFIG_CHECKER_EXCLUDE, PRETTIER_IGNORE_PATTERNS, isEditorConfigExcluded, lintCommitMessage, lintCommitMsgFile };