@eserstack/codebase 0.0.0-stage → 5.0.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/README.md +301 -2
- package/dist/changelog-gen.d.ts +105 -0
- package/dist/changelog-gen.js +498 -0
- package/dist/changelog-text.d.ts +39 -0
- package/dist/changelog-text.js +82 -0
- package/dist/cli-support.d.ts +140 -0
- package/dist/cli-support.js +244 -0
- package/dist/cli-system/app-opts.d.ts +15 -0
- package/dist/cli-system/app-opts.js +13 -0
- package/dist/cli-system/app.d.ts +29 -0
- package/dist/cli-system/app.js +12 -0
- package/dist/cli-system/handlers/completions-setup.d.ts +14 -0
- package/dist/cli-system/handlers/completions-setup.js +139 -0
- package/dist/cli-system/handlers/completions.d.ts +3 -0
- package/dist/cli-system/handlers/completions.js +79 -0
- package/dist/cli-system/handlers/doctor.d.ts +8 -0
- package/dist/cli-system/handlers/doctor.js +146 -0
- package/dist/cli-system/handlers/info.d.ts +3 -0
- package/dist/cli-system/handlers/info.js +69 -0
- package/dist/cli-system/handlers/install.d.ts +8 -0
- package/dist/cli-system/handlers/install.js +137 -0
- package/dist/cli-system/handlers/mod.d.ts +12 -0
- package/dist/cli-system/handlers/mod.js +13 -0
- package/dist/cli-system/handlers/uninstall.d.ts +3 -0
- package/dist/cli-system/handlers/uninstall.js +60 -0
- package/dist/cli-system/handlers/update.d.ts +76 -0
- package/dist/cli-system/handlers/update.js +310 -0
- package/dist/cli-system/handlers/version-check.d.ts +16 -0
- package/dist/cli-system/handlers/version-check.js +176 -0
- package/dist/cli-system/handlers/version.d.ts +3 -0
- package/dist/cli-system/handlers/version.js +45 -0
- package/dist/cli-system/mod.d.ts +19 -0
- package/dist/cli-system/mod.js +52 -0
- package/dist/commitmsg.d.ts +28 -0
- package/dist/commitmsg.js +232 -0
- package/dist/directive-analysis.d.ts +75 -0
- package/dist/directive-analysis.js +223 -0
- package/dist/ffi-client.d.ts +11 -0
- package/dist/ffi-client.js +12 -0
- package/dist/file-tool.d.ts +96 -0
- package/dist/file-tool.js +274 -0
- package/dist/file-tools-shared.d.ts +81 -0
- package/dist/file-tools-shared.js +276 -0
- package/dist/gh-contributors.d.ts +89 -0
- package/dist/gh-contributors.js +205 -0
- package/dist/gh.d.ts +3 -0
- package/dist/gh.js +64 -0
- package/dist/git-listing.d.ts +27 -0
- package/dist/git-listing.js +69 -0
- package/dist/git.d.ts +172 -0
- package/dist/git.js +277 -0
- package/dist/install.d.ts +34 -0
- package/dist/install.js +421 -0
- package/dist/main.d.ts +22 -0
- package/dist/main.js +14 -0
- package/dist/mod.d.ts +25 -0
- package/dist/mod.js +8 -0
- package/dist/module.d.ts +10 -0
- package/dist/module.js +221 -0
- package/dist/native-functions.d.ts +1088 -0
- package/dist/native-functions.js +2 -0
- package/dist/npm-externals.d.ts +27 -0
- package/dist/npm-externals.js +34 -0
- package/dist/npm-workspace-specifiers.d.ts +6 -0
- package/dist/npm-workspace-specifiers.js +45 -0
- package/dist/package/loader.d.ts +34 -0
- package/dist/package/loader.js +203 -0
- package/dist/package/mod.d.ts +36 -0
- package/dist/package/mod.js +5 -0
- package/dist/package/types.d.ts +142 -0
- package/dist/package/types.js +32 -0
- package/dist/package/workspace.d.ts +33 -0
- package/dist/package/workspace.js +158 -0
- package/dist/package/writer.d.ts +52 -0
- package/dist/package/writer.js +278 -0
- package/dist/package.json +275 -0
- package/dist/release-notes.d.ts +90 -0
- package/dist/release-notes.js +236 -0
- package/dist/release-tag.d.ts +46 -0
- package/dist/release-tag.js +95 -0
- package/dist/release.d.ts +145 -0
- package/dist/release.js +584 -0
- package/dist/source-mask.d.ts +3 -0
- package/dist/source-mask.js +185 -0
- package/dist/validate-bom.d.ts +5 -0
- package/dist/validate-bom.js +43 -0
- package/dist/validate-case-conflict.d.ts +5 -0
- package/dist/validate-case-conflict.js +43 -0
- package/dist/validate-circular-deps.d.ts +11 -0
- package/dist/validate-circular-deps.js +53 -0
- package/dist/validate-code-conventions.d.ts +22 -0
- package/dist/validate-code-conventions.js +166 -0
- package/dist/validate-commit-msg.d.ts +50 -0
- package/dist/validate-commit-msg.js +182 -0
- package/dist/validate-docs.d.ts +20 -0
- package/dist/validate-docs.js +78 -0
- package/dist/validate-eof.d.ts +5 -0
- package/dist/validate-eof.js +61 -0
- package/dist/validate-error-coverage.d.ts +28 -0
- package/dist/validate-error-coverage.js +93 -0
- package/dist/validate-export-names.d.ts +17 -0
- package/dist/validate-export-names.js +56 -0
- package/dist/validate-filenames.d.ts +5 -0
- package/dist/validate-filenames.js +151 -0
- package/dist/validate-json.d.ts +5 -0
- package/dist/validate-json.js +71 -0
- package/dist/validate-large-files.d.ts +5 -0
- package/dist/validate-large-files.js +41 -0
- package/dist/validate-laroux-boundaries.d.ts +19 -0
- package/dist/validate-laroux-boundaries.js +59 -0
- package/dist/validate-licenses.d.ts +5 -0
- package/dist/validate-licenses.js +137 -0
- package/dist/validate-line-endings.d.ts +5 -0
- package/dist/validate-line-endings.js +47 -0
- package/dist/validate-merge-conflict.d.ts +5 -0
- package/dist/validate-merge-conflict.js +46 -0
- package/dist/validate-mod-exports.d.ts +16 -0
- package/dist/validate-mod-exports.js +56 -0
- package/dist/validate-naming-and-todos.d.ts +5 -0
- package/dist/validate-naming-and-todos.js +70 -0
- package/dist/validate-runtime-js-apis.d.ts +5 -0
- package/dist/validate-runtime-js-apis.js +78 -0
- package/dist/validate-secrets.d.ts +5 -0
- package/dist/validate-secrets.js +82 -0
- package/dist/validate-self-imports.d.ts +5 -0
- package/dist/validate-self-imports.js +78 -0
- package/dist/validate-server-loc.d.ts +32 -0
- package/dist/validate-server-loc.js +94 -0
- package/dist/validate-shebangs.d.ts +5 -0
- package/dist/validate-shebangs.js +33 -0
- package/dist/validate-stream.d.ts +25 -0
- package/dist/validate-stream.js +62 -0
- package/dist/validate-submodules.d.ts +5 -0
- package/dist/validate-submodules.js +43 -0
- package/dist/validate-symlinks.d.ts +5 -0
- package/dist/validate-symlinks.js +46 -0
- package/dist/validate-toml.d.ts +5 -0
- package/dist/validate-toml.js +40 -0
- package/dist/validate-trailing-whitespace.d.ts +5 -0
- package/dist/validate-trailing-whitespace.js +49 -0
- package/dist/validate-yaml.d.ts +5 -0
- package/dist/validate-yaml.js +40 -0
- package/dist/validation/config.d.ts +17 -0
- package/dist/validation/config.js +30 -0
- package/dist/validation/mod.d.ts +71 -0
- package/dist/validation/mod.js +479 -0
- package/dist/validation/registry.d.ts +57 -0
- package/dist/validation/registry.js +256 -0
- package/dist/validation/types.d.ts +101 -0
- package/dist/validation/types.js +2 -0
- package/dist/validation/validators/circular-deps.d.ts +7 -0
- package/dist/validation/validators/circular-deps.js +31 -0
- package/dist/validation/validators/docs.d.ts +7 -0
- package/dist/validation/validators/docs.js +38 -0
- package/dist/validation/validators/error-coverage.d.ts +2 -0
- package/dist/validation/validators/error-coverage.js +46 -0
- package/dist/validation/validators/export-names.d.ts +7 -0
- package/dist/validation/validators/export-names.js +31 -0
- package/dist/validation/validators/laroux-boundaries.d.ts +2 -0
- package/dist/validation/validators/laroux-boundaries.js +29 -0
- package/dist/validation/validators/mod-exports.d.ts +7 -0
- package/dist/validation/validators/mod-exports.js +32 -0
- package/dist/validation/validators/mod.d.ts +11 -0
- package/dist/validation/validators/mod.js +12 -0
- package/dist/validation/validators/server-loc.d.ts +2 -0
- package/dist/validation/validators/server-loc.js +48 -0
- package/dist/versions.d.ts +166 -0
- package/dist/versions.js +349 -0
- package/dist/violation-baseline.d.ts +58 -0
- package/dist/violation-baseline.js +144 -0
- package/dist/walk-stream.d.ts +24 -0
- package/dist/walk-stream.js +55 -0
- package/dist/workspace-discovery.d.ts +60 -0
- package/dist/workspace-discovery.js +130 -0
- package/package.json +222 -3
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
// Copyright 2023-present Eser Ozvataf and other contributors. All rights reserved. Apache-2.0 license.
|
|
2
|
+
/**
|
|
3
|
+
* Commit message checker — validates conventional commit format.
|
|
4
|
+
*
|
|
5
|
+
* Format: `type(scope): message`
|
|
6
|
+
*
|
|
7
|
+
* Can be used as a git commit-msg hook or standalone validator.
|
|
8
|
+
*
|
|
9
|
+
* @module
|
|
10
|
+
*/
|
|
11
|
+
import * as shellFlags from "@eserstack/shell/args/flags";
|
|
12
|
+
import * as primitives from "@eserstack/primitives";
|
|
13
|
+
import * as standards from "@eserstack/standards";
|
|
14
|
+
import * as span from "@eserstack/streams/span";
|
|
15
|
+
import * as cliSupport from "./cli-support.js";
|
|
16
|
+
import * as ffiClient from "./ffi-client.js";
|
|
17
|
+
// =============================================================================
|
|
18
|
+
// Validation logic (pure)
|
|
19
|
+
// =============================================================================
|
|
20
|
+
const DEFAULT_TYPES = [
|
|
21
|
+
"ci",
|
|
22
|
+
"chore",
|
|
23
|
+
"docs",
|
|
24
|
+
"feat",
|
|
25
|
+
"fix",
|
|
26
|
+
"perf",
|
|
27
|
+
"refactor",
|
|
28
|
+
"revert",
|
|
29
|
+
"test",
|
|
30
|
+
];
|
|
31
|
+
const CONVENTIONAL_PATTERN = /^(\w+)(?:\(([^)]+)\))?!?:\s{1,5}.+$/;
|
|
32
|
+
/**
|
|
33
|
+
* Validate a commit message against conventional commit format.
|
|
34
|
+
*
|
|
35
|
+
* The check is synchronous, so it uses the native validator only when the
|
|
36
|
+
* bridge has already loaded, and the TypeScript rules below otherwise. Await
|
|
37
|
+
* `ensureLib()` from `@eserstack/ajan/ffi/client` first to use the native one.
|
|
38
|
+
*/
|
|
39
|
+
export const validateCommitMsg = (message, options = {}) => {
|
|
40
|
+
// FFI path: a synchronous call, so it only runs when the caller already
|
|
41
|
+
// awaited ensureLib(). Falls through to TS if the library is not loaded or
|
|
42
|
+
// the call fails.
|
|
43
|
+
const lib = ffiClient.getLib();
|
|
44
|
+
if (lib !== null) {
|
|
45
|
+
try {
|
|
46
|
+
const parsed = lib.call("codebaseValidateCommitMsg", {
|
|
47
|
+
message,
|
|
48
|
+
allowAsterisk: options.allowAsterisk,
|
|
49
|
+
allowMultipleScopes: options.allowMultipleScopes,
|
|
50
|
+
forceScope: options.forceScope,
|
|
51
|
+
types: options.types !== undefined ? [...options.types] : undefined,
|
|
52
|
+
});
|
|
53
|
+
if (!parsed.error && parsed.valid !== undefined) {
|
|
54
|
+
return { valid: parsed.valid, issues: parsed.issues ?? [] };
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
catch {
|
|
58
|
+
/* fall through to TS */
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return validateCommitMsgLocal(message, options);
|
|
62
|
+
};
|
|
63
|
+
/**
|
|
64
|
+
* The TypeScript rules {@link validateCommitMsg} falls back to when the
|
|
65
|
+
* native library is not loaded. The Go validator implements the same rules;
|
|
66
|
+
* the parity test in go-validator-parity.test.ts keeps the two equal.
|
|
67
|
+
*/
|
|
68
|
+
export const validateCommitMsgLocal = (message, options = {}) => {
|
|
69
|
+
const allowAsterisk = options.allowAsterisk ?? true;
|
|
70
|
+
const allowMultipleScopes = options.allowMultipleScopes ?? true;
|
|
71
|
+
const forceScope = options.forceScope ?? false;
|
|
72
|
+
const validTypes = new Set(options.types ?? DEFAULT_TYPES);
|
|
73
|
+
const issues = [];
|
|
74
|
+
// Take first line only
|
|
75
|
+
const firstLine = message.split("\n")[0]?.trim() ?? "";
|
|
76
|
+
if (firstLine === "") {
|
|
77
|
+
return { valid: false, issues: ["commit message is empty"] };
|
|
78
|
+
}
|
|
79
|
+
// Skip merge commits
|
|
80
|
+
if (firstLine.startsWith("Merge ")) {
|
|
81
|
+
return { valid: true, issues: [] };
|
|
82
|
+
}
|
|
83
|
+
const match = firstLine.match(CONVENTIONAL_PATTERN);
|
|
84
|
+
if (match === null) {
|
|
85
|
+
issues.push(`invalid format: expected "type(scope): message", got: "${firstLine}"`);
|
|
86
|
+
return { valid: false, issues };
|
|
87
|
+
}
|
|
88
|
+
const type = match[1].toLowerCase();
|
|
89
|
+
const scope = match[2];
|
|
90
|
+
if (!validTypes.has(type)) {
|
|
91
|
+
issues.push(`invalid type "${type}". Must be one of: ${[...validTypes].join(", ")}`);
|
|
92
|
+
}
|
|
93
|
+
if (forceScope && (scope === undefined || scope.trim() === "")) {
|
|
94
|
+
issues.push("scope is required: use type(scope): message");
|
|
95
|
+
}
|
|
96
|
+
if (scope !== undefined && scope.trim() !== "") {
|
|
97
|
+
// Check asterisk scope
|
|
98
|
+
if (scope === "*" && !allowAsterisk) {
|
|
99
|
+
issues.push('wildcard scope "*" is not allowed (allowAsterisk is false)');
|
|
100
|
+
}
|
|
101
|
+
// Check multiple scopes
|
|
102
|
+
if (scope.includes(",")) {
|
|
103
|
+
if (!allowMultipleScopes) {
|
|
104
|
+
issues.push("multiple scopes are not allowed (allowMultipleScopes is false)");
|
|
105
|
+
}
|
|
106
|
+
else {
|
|
107
|
+
// Validate each scope is non-empty
|
|
108
|
+
const scopes = scope.split(",").map((s) => s.trim());
|
|
109
|
+
const emptyScopes = scopes.filter((s) => s === "");
|
|
110
|
+
if (emptyScopes.length > 0) {
|
|
111
|
+
issues.push("invalid scope: each comma-separated scope must be non-empty");
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
return { valid: issues.length === 0, issues };
|
|
117
|
+
};
|
|
118
|
+
/** Parse the validate-commit-msg arguments: `<file>`, `--message` (`-m`), `--help` (`-h`). */
|
|
119
|
+
export const parseCliArgs = (cliArgs) => {
|
|
120
|
+
const { values, positionals } = shellFlags.parseArgs(cliArgs ?? [], {
|
|
121
|
+
options: {
|
|
122
|
+
message: { type: "string", short: "m" },
|
|
123
|
+
help: { type: "boolean", short: "h" },
|
|
124
|
+
},
|
|
125
|
+
});
|
|
126
|
+
const message = values["message"];
|
|
127
|
+
return {
|
|
128
|
+
help: values["help"] === true,
|
|
129
|
+
message: typeof message === "string" ? message : null,
|
|
130
|
+
file: positionals[0] ?? null,
|
|
131
|
+
};
|
|
132
|
+
};
|
|
133
|
+
/**
|
|
134
|
+
* CLI entry point. Accepts a commit message file path as first argument
|
|
135
|
+
* (for use as git commit-msg hook) or --message flag.
|
|
136
|
+
*/
|
|
137
|
+
export const main = async (cliArgs) => {
|
|
138
|
+
const { output: out } = cliSupport.getCliContext();
|
|
139
|
+
const parsed = parseCliArgs(cliArgs);
|
|
140
|
+
if (parsed.help) {
|
|
141
|
+
out.writeln("eser codebase validate-commit-msg — Validate conventional commit format\n");
|
|
142
|
+
out.writeln("Usage:");
|
|
143
|
+
out.writeln(" eser codebase validate-commit-msg <commit-msg-file>");
|
|
144
|
+
out.writeln(" eser codebase validate-commit-msg --message 'feat(x): msg'");
|
|
145
|
+
return primitives.results.ok(undefined);
|
|
146
|
+
}
|
|
147
|
+
let message;
|
|
148
|
+
if (parsed.message !== null) {
|
|
149
|
+
message = parsed.message;
|
|
150
|
+
}
|
|
151
|
+
else if (parsed.file !== null) {
|
|
152
|
+
// Read from file (git commit-msg hook passes the file path)
|
|
153
|
+
try {
|
|
154
|
+
message = await standards.crossRuntime.runtime.fs.readTextFile(parsed.file);
|
|
155
|
+
}
|
|
156
|
+
catch {
|
|
157
|
+
out.writeln(span.red("✗"), span.text(` cannot read commit message file: ${parsed.file}`));
|
|
158
|
+
return primitives.results.fail({ exitCode: 1 });
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
else {
|
|
162
|
+
out.writeln(span.red("✗"), span.text(" no commit message provided"));
|
|
163
|
+
return primitives.results.fail({ exitCode: 1 });
|
|
164
|
+
}
|
|
165
|
+
// Load the bridge before the synchronous check so the native validator runs.
|
|
166
|
+
await ffiClient.ensureLib();
|
|
167
|
+
const result = validateCommitMsg(message);
|
|
168
|
+
if (result.valid) {
|
|
169
|
+
out.writeln(span.green("✓"), span.text(" commit message is valid"));
|
|
170
|
+
return primitives.results.ok(undefined);
|
|
171
|
+
}
|
|
172
|
+
for (const issue of result.issues) {
|
|
173
|
+
out.writeln(span.red("✗"), span.text(" " + issue));
|
|
174
|
+
}
|
|
175
|
+
return primitives.results.fail({ exitCode: 1 });
|
|
176
|
+
};
|
|
177
|
+
if (import.meta.main) {
|
|
178
|
+
// Entry point: the await only runs when this file is executed directly.
|
|
179
|
+
// oxlint-disable-next-line node/no-top-level-await
|
|
180
|
+
const result = await main(standards.crossRuntime.runtime.process.args);
|
|
181
|
+
cliSupport.runCliMain(result, cliSupport.getCliContext().output);
|
|
182
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type * as shellArgs from "@eserstack/shell/args";
|
|
2
|
+
export type CheckDocsOptions = {
|
|
3
|
+
readonly root?: string;
|
|
4
|
+
readonly requireExamples?: boolean;
|
|
5
|
+
};
|
|
6
|
+
export type DocIssueType = "missing-description" | "missing-param" | "missing-returns" | "missing-example" | "empty-description";
|
|
7
|
+
export type DocIssue = {
|
|
8
|
+
readonly file: string;
|
|
9
|
+
readonly symbol: string;
|
|
10
|
+
readonly issue: DocIssueType;
|
|
11
|
+
readonly line?: number;
|
|
12
|
+
};
|
|
13
|
+
export type CheckDocsResult = {
|
|
14
|
+
readonly isValid: boolean;
|
|
15
|
+
readonly issues: DocIssue[];
|
|
16
|
+
readonly filesChecked: number;
|
|
17
|
+
readonly symbolsChecked: number;
|
|
18
|
+
};
|
|
19
|
+
export declare const checkDocs: (options?: CheckDocsOptions) => Promise<CheckDocsResult>;
|
|
20
|
+
export declare const main: (_cliArgs?: readonly string[]) => Promise<shellArgs.CliResult<void>>;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
// Copyright 2023-present Eser Ozvataf and other contributors. All rights reserved. Apache-2.0 license.
|
|
2
|
+
/**
|
|
3
|
+
* Documentation validation tool.
|
|
4
|
+
*
|
|
5
|
+
* Validates JSDoc documentation for exported symbols.
|
|
6
|
+
*
|
|
7
|
+
* @module
|
|
8
|
+
*/
|
|
9
|
+
import * as primitives from "@eserstack/primitives";
|
|
10
|
+
import * as span from "@eserstack/streams/span";
|
|
11
|
+
import * as cliSupport from "./cli-support.js";
|
|
12
|
+
import * as ffiClient from "./ffi-client.js";
|
|
13
|
+
export const checkDocs = async (options = {}) => {
|
|
14
|
+
const { root = ".", requireExamples = false } = options;
|
|
15
|
+
await ffiClient.ensureLib();
|
|
16
|
+
const lib = ffiClient.getLib();
|
|
17
|
+
if (lib === null) {
|
|
18
|
+
throw new Error("native library not available for checkDocs");
|
|
19
|
+
}
|
|
20
|
+
const result = lib.call("codebaseCheckDocs", {
|
|
21
|
+
dir: root,
|
|
22
|
+
requireExamples,
|
|
23
|
+
});
|
|
24
|
+
if (result.error) {
|
|
25
|
+
throw new Error(result.error);
|
|
26
|
+
}
|
|
27
|
+
return result;
|
|
28
|
+
};
|
|
29
|
+
const formatIssue = (issue) => {
|
|
30
|
+
switch (issue) {
|
|
31
|
+
case "missing-description":
|
|
32
|
+
return "Missing JSDoc documentation";
|
|
33
|
+
case "missing-param":
|
|
34
|
+
return "Missing @param documentation";
|
|
35
|
+
case "missing-returns":
|
|
36
|
+
return "Missing @returns documentation";
|
|
37
|
+
case "missing-example":
|
|
38
|
+
return "Missing @example";
|
|
39
|
+
case "empty-description":
|
|
40
|
+
return "Empty description";
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
export const main = async (_cliArgs) => {
|
|
44
|
+
const { output: out } = cliSupport.getCliContext();
|
|
45
|
+
try {
|
|
46
|
+
const value = await checkDocs({ root: "." });
|
|
47
|
+
out.writeln(span.blue("ℹ"), span.text(` Checked ${value.filesChecked} files, ${value.symbolsChecked} symbols.`));
|
|
48
|
+
if (!value.isValid) {
|
|
49
|
+
out.writeln(span.red("✗"), span.text(` Found ${value.issues.length} documentation issues:`));
|
|
50
|
+
const byFile = new Map();
|
|
51
|
+
for (const issue of value.issues) {
|
|
52
|
+
const existing = byFile.get(issue.file) ?? [];
|
|
53
|
+
existing.push(issue);
|
|
54
|
+
byFile.set(issue.file, existing);
|
|
55
|
+
}
|
|
56
|
+
for (const [file, fileIssues] of byFile) {
|
|
57
|
+
out.writeln(span.yellow("⚠"), span.text(" " + file));
|
|
58
|
+
for (const issue of fileIssues) {
|
|
59
|
+
const lineInfo = issue.line !== undefined ? `:${issue.line}` : "";
|
|
60
|
+
out.writeln(span.blue("ℹ"), span.text(` ${issue.symbol}${lineInfo}: ${formatIssue(issue.issue)}`));
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return primitives.results.fail({ exitCode: 1 });
|
|
64
|
+
}
|
|
65
|
+
out.writeln(span.green("✓"), span.text(" All documentation is valid."));
|
|
66
|
+
return primitives.results.ok(undefined);
|
|
67
|
+
}
|
|
68
|
+
catch (err) {
|
|
69
|
+
out.writeln(span.red("✗"), span.text(` ${String(err)}`));
|
|
70
|
+
return primitives.results.fail({ exitCode: 1 });
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
if (import.meta.main) {
|
|
74
|
+
// Entry point: the await only runs when this file is executed directly.
|
|
75
|
+
// oxlint-disable-next-line node/no-top-level-await
|
|
76
|
+
const result = await main();
|
|
77
|
+
cliSupport.runCliMain(result, cliSupport.getCliContext().output);
|
|
78
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
// Copyright 2023-present Eser Ozvataf and other contributors. All rights reserved. Apache-2.0 license.
|
|
2
|
+
/**
|
|
3
|
+
* End-of-file fixer — ensures files end with exactly one newline.
|
|
4
|
+
*
|
|
5
|
+
* @module
|
|
6
|
+
*/
|
|
7
|
+
import * as standards from "@eserstack/standards";
|
|
8
|
+
import * as cliSupport from "./cli-support.js";
|
|
9
|
+
import * as fileTool from "./file-tool.js";
|
|
10
|
+
export const tool = fileTool.withGoValidator(fileTool.createFileTool({
|
|
11
|
+
name: "validate-eof",
|
|
12
|
+
description: "Ensure files end with exactly one newline",
|
|
13
|
+
canFix: true,
|
|
14
|
+
stacks: [],
|
|
15
|
+
defaults: {},
|
|
16
|
+
checkFile(file, content) {
|
|
17
|
+
if (content === undefined) {
|
|
18
|
+
return [];
|
|
19
|
+
}
|
|
20
|
+
if (content.length === 0) {
|
|
21
|
+
return [];
|
|
22
|
+
}
|
|
23
|
+
if (!content.endsWith("\n")) {
|
|
24
|
+
return [
|
|
25
|
+
{
|
|
26
|
+
path: file.path,
|
|
27
|
+
message: "file does not end with a newline",
|
|
28
|
+
},
|
|
29
|
+
];
|
|
30
|
+
}
|
|
31
|
+
if (content.endsWith("\n\n")) {
|
|
32
|
+
return [
|
|
33
|
+
{
|
|
34
|
+
path: file.path,
|
|
35
|
+
message: "file has multiple trailing newlines",
|
|
36
|
+
},
|
|
37
|
+
];
|
|
38
|
+
}
|
|
39
|
+
return [];
|
|
40
|
+
},
|
|
41
|
+
fixFile(file, content) {
|
|
42
|
+
if (content.length === 0) {
|
|
43
|
+
return undefined;
|
|
44
|
+
}
|
|
45
|
+
const trimmed = content.replace(/\n+$/, "");
|
|
46
|
+
const fixed = `${trimmed}\n`;
|
|
47
|
+
if (fixed === content) {
|
|
48
|
+
return undefined;
|
|
49
|
+
}
|
|
50
|
+
return { path: file.path, oldContent: content, newContent: fixed };
|
|
51
|
+
},
|
|
52
|
+
}), "eof");
|
|
53
|
+
export const run = tool.run;
|
|
54
|
+
export const validator = tool.validator;
|
|
55
|
+
export const main = tool.main;
|
|
56
|
+
if (import.meta.main) {
|
|
57
|
+
// Entry point: the await only runs when this file is executed directly.
|
|
58
|
+
// oxlint-disable-next-line node/no-top-level-await
|
|
59
|
+
const result = await main(standards.crossRuntime.runtime.process.args);
|
|
60
|
+
cliSupport.runCliMain(result);
|
|
61
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type * as shellArgs from "@eserstack/shell/args";
|
|
2
|
+
export type CheckErrorCoverageOptions = {
|
|
3
|
+
readonly root?: string;
|
|
4
|
+
readonly file: string;
|
|
5
|
+
readonly errorObjects?: readonly string[];
|
|
6
|
+
readonly requiredFields?: readonly string[];
|
|
7
|
+
};
|
|
8
|
+
export type CheckErrorCoverageResult = {
|
|
9
|
+
readonly violations: readonly {
|
|
10
|
+
name: string;
|
|
11
|
+
missing: readonly string[];
|
|
12
|
+
}[];
|
|
13
|
+
readonly checked: number;
|
|
14
|
+
readonly passed: boolean;
|
|
15
|
+
};
|
|
16
|
+
export declare const checkErrorCoverage: (options: CheckErrorCoverageOptions) => Promise<CheckErrorCoverageResult>;
|
|
17
|
+
/** The arguments of `eser codebase validate-error-coverage`. */
|
|
18
|
+
export type ErrorCoverageArgs = {
|
|
19
|
+
/** The `--file` path; empty when not given. */
|
|
20
|
+
readonly file: string;
|
|
21
|
+
/** The comma-separated `--error-objects` list. */
|
|
22
|
+
readonly errorObjects: string[] | undefined;
|
|
23
|
+
/** The comma-separated `--required-fields` list. */
|
|
24
|
+
readonly requiredFields: string[] | undefined;
|
|
25
|
+
};
|
|
26
|
+
/** Parse the validate-error-coverage arguments: `--file`, `--error-objects`, `--required-fields`. */
|
|
27
|
+
export declare const parseCliArgs: (cliArgs?: readonly string[]) => ErrorCoverageArgs;
|
|
28
|
+
export declare const main: (cliArgs?: readonly string[]) => Promise<shellArgs.CliResult<void>>;
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
// Copyright 2023-present Eser Ozvataf and other contributors. All rights reserved. Apache-2.0 license.
|
|
2
|
+
/**
|
|
3
|
+
* Error struct field-coverage validator.
|
|
4
|
+
*
|
|
5
|
+
* Verifies that error-struct entries have non-empty required fields.
|
|
6
|
+
*
|
|
7
|
+
* @module
|
|
8
|
+
*/
|
|
9
|
+
import * as primitives from "@eserstack/primitives";
|
|
10
|
+
import * as shellFlags from "@eserstack/shell/args/flags";
|
|
11
|
+
import * as span from "@eserstack/streams/span";
|
|
12
|
+
import { runtime } from "@eserstack/standards/cross-runtime";
|
|
13
|
+
import * as cliSupport from "./cli-support.js";
|
|
14
|
+
const escapeRe = (s) => s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
15
|
+
export const checkErrorCoverage = async (options) => {
|
|
16
|
+
const { root = ".", file, errorObjects = ["NSError"], requiredFields = ["Code", "Cause", "Fix"], } = options;
|
|
17
|
+
const filePath = runtime.path.join(root, file);
|
|
18
|
+
const content = await runtime.fs.readTextFile(filePath);
|
|
19
|
+
const typeAlternation = errorObjects.map(escapeRe).join("|");
|
|
20
|
+
const blockRe = new RegExp(`(\\w+):\\s*&(?:${typeAlternation})\\{([^}]+)\\}`, "gs");
|
|
21
|
+
const violations = [];
|
|
22
|
+
let checked = 0;
|
|
23
|
+
for (const match of content.matchAll(blockRe)) {
|
|
24
|
+
const entryName = match[1] ?? "";
|
|
25
|
+
const body = match[2] ?? "";
|
|
26
|
+
checked++;
|
|
27
|
+
const missing = [];
|
|
28
|
+
for (const field of requiredFields) {
|
|
29
|
+
const fieldRe = new RegExp(`^\\s*${escapeRe(field)}:\\s*"([^"]*)"`, "m");
|
|
30
|
+
const fieldMatch = body.match(fieldRe);
|
|
31
|
+
if (!fieldMatch || (fieldMatch[1] ?? "").trim() === "") {
|
|
32
|
+
missing.push(field);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
if (missing.length > 0) {
|
|
36
|
+
violations.push({ name: entryName, missing });
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return { violations, checked, passed: violations.length === 0 };
|
|
40
|
+
};
|
|
41
|
+
const splitList = (value) => typeof value === "string" ? value.split(",").map((s) => s.trim()) : undefined;
|
|
42
|
+
/** Parse the validate-error-coverage arguments: `--file`, `--error-objects`, `--required-fields`. */
|
|
43
|
+
export const parseCliArgs = (cliArgs) => {
|
|
44
|
+
const { values } = shellFlags.parseArgs(cliArgs ?? [], {
|
|
45
|
+
options: {
|
|
46
|
+
file: { type: "string" },
|
|
47
|
+
"error-objects": { type: "string" },
|
|
48
|
+
"required-fields": { type: "string" },
|
|
49
|
+
},
|
|
50
|
+
});
|
|
51
|
+
const file = values["file"];
|
|
52
|
+
return {
|
|
53
|
+
file: typeof file === "string" ? file : "",
|
|
54
|
+
errorObjects: splitList(values["error-objects"]),
|
|
55
|
+
requiredFields: splitList(values["required-fields"]),
|
|
56
|
+
};
|
|
57
|
+
};
|
|
58
|
+
export const main = async (cliArgs) => {
|
|
59
|
+
const { output: out } = cliSupport.getCliContext();
|
|
60
|
+
const { file, errorObjects, requiredFields } = parseCliArgs(cliArgs);
|
|
61
|
+
if (file === "") {
|
|
62
|
+
out.writeln(span.red("✗"), span.text(" validate-error-coverage requires a --file argument"));
|
|
63
|
+
return primitives.results.fail({ exitCode: 1 });
|
|
64
|
+
}
|
|
65
|
+
try {
|
|
66
|
+
const result = await checkErrorCoverage({
|
|
67
|
+
root: ".",
|
|
68
|
+
file,
|
|
69
|
+
errorObjects,
|
|
70
|
+
requiredFields,
|
|
71
|
+
});
|
|
72
|
+
out.writeln(span.blue("ℹ"), span.text(` Checked ${result.checked} error entries in ${file}.`));
|
|
73
|
+
if (!result.passed) {
|
|
74
|
+
out.writeln(span.red("✗"), span.text(` Found ${result.violations.length} entry(ies) with missing fields:`));
|
|
75
|
+
for (const v of result.violations) {
|
|
76
|
+
out.writeln(span.yellow("⚠"), span.text(` ${v.name}: missing [${v.missing.join(", ")}]`));
|
|
77
|
+
}
|
|
78
|
+
return primitives.results.fail({ exitCode: 1 });
|
|
79
|
+
}
|
|
80
|
+
out.writeln(span.green("✓"), span.text(" All error entries have required fields populated."));
|
|
81
|
+
return primitives.results.ok(undefined);
|
|
82
|
+
}
|
|
83
|
+
catch (err) {
|
|
84
|
+
out.writeln(span.red("✗"), span.text(` ${String(err)}`));
|
|
85
|
+
return primitives.results.fail({ exitCode: 1 });
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
if (import.meta.main) {
|
|
89
|
+
// Entry point: the await only runs when this file is executed directly.
|
|
90
|
+
// oxlint-disable-next-line node/no-top-level-await
|
|
91
|
+
const result = await main(runtime.process.args);
|
|
92
|
+
cliSupport.runCliMain(result, cliSupport.getCliContext().output);
|
|
93
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type * as shellArgs from "@eserstack/shell/args";
|
|
2
|
+
export type CheckExportNamesOptions = {
|
|
3
|
+
readonly root?: string;
|
|
4
|
+
readonly ignoreWords?: string[];
|
|
5
|
+
};
|
|
6
|
+
export type ExportNameViolation = {
|
|
7
|
+
readonly packageName: string;
|
|
8
|
+
readonly exportPath: string;
|
|
9
|
+
readonly suggestion: string;
|
|
10
|
+
};
|
|
11
|
+
export type CheckExportNamesResult = {
|
|
12
|
+
readonly isValid: boolean;
|
|
13
|
+
readonly violations: ExportNameViolation[];
|
|
14
|
+
readonly packagesChecked: number;
|
|
15
|
+
};
|
|
16
|
+
export declare const checkExportNames: (options?: CheckExportNamesOptions) => Promise<CheckExportNamesResult>;
|
|
17
|
+
export declare const main: (_cliArgs?: readonly string[]) => Promise<shellArgs.CliResult<void>>;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
// Copyright 2023-present Eser Ozvataf and other contributors. All rights reserved. Apache-2.0 license.
|
|
2
|
+
/**
|
|
3
|
+
* Export naming convention checker.
|
|
4
|
+
*
|
|
5
|
+
* Validates that export paths in package.json follow kebab-case convention.
|
|
6
|
+
*
|
|
7
|
+
* @module
|
|
8
|
+
*/
|
|
9
|
+
import * as primitives from "@eserstack/primitives";
|
|
10
|
+
import * as span from "@eserstack/streams/span";
|
|
11
|
+
import * as cliSupport from "./cli-support.js";
|
|
12
|
+
import * as ffiClient from "./ffi-client.js";
|
|
13
|
+
export const checkExportNames = async (options = {}) => {
|
|
14
|
+
const { root = ".", ignoreWords = [] } = options;
|
|
15
|
+
await ffiClient.ensureLib();
|
|
16
|
+
const lib = ffiClient.getLib();
|
|
17
|
+
if (lib === null) {
|
|
18
|
+
throw new Error("native library not available for checkExportNames");
|
|
19
|
+
}
|
|
20
|
+
const result = lib.call("codebaseCheckExportNames", {
|
|
21
|
+
dir: root,
|
|
22
|
+
ignoreWords,
|
|
23
|
+
});
|
|
24
|
+
if (result.error) {
|
|
25
|
+
throw new Error(result.error);
|
|
26
|
+
}
|
|
27
|
+
return result;
|
|
28
|
+
};
|
|
29
|
+
export const main = async (_cliArgs) => {
|
|
30
|
+
const { output: out } = cliSupport.getCliContext();
|
|
31
|
+
try {
|
|
32
|
+
const value = await checkExportNames({ root: "." });
|
|
33
|
+
out.writeln(span.blue("ℹ"), span.text(` Checked ${value.packagesChecked} packages.`));
|
|
34
|
+
if (!value.isValid) {
|
|
35
|
+
out.writeln(span.red("✗"), span.text(` Found ${value.violations.length} naming violations:`));
|
|
36
|
+
for (const violation of value.violations) {
|
|
37
|
+
out.writeln(span.yellow("⚠"), span.text(" " + violation.packageName));
|
|
38
|
+
out.writeln(span.blue("ℹ"), span.text(` Export: ${violation.exportPath}`));
|
|
39
|
+
out.writeln(span.blue("ℹ"), span.text(` Suggestion: ${violation.suggestion}`));
|
|
40
|
+
}
|
|
41
|
+
return primitives.results.fail({ exitCode: 1 });
|
|
42
|
+
}
|
|
43
|
+
out.writeln(span.green("✓"), span.text(" All export names follow conventions."));
|
|
44
|
+
return primitives.results.ok(undefined);
|
|
45
|
+
}
|
|
46
|
+
catch (err) {
|
|
47
|
+
out.writeln(span.red("✗"), span.text(` ${String(err)}`));
|
|
48
|
+
return primitives.results.fail({ exitCode: 1 });
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
if (import.meta.main) {
|
|
52
|
+
// Entry point: the await only runs when this file is executed directly.
|
|
53
|
+
// oxlint-disable-next-line node/no-top-level-await
|
|
54
|
+
const result = await main();
|
|
55
|
+
cliSupport.runCliMain(result, cliSupport.getCliContext().output);
|
|
56
|
+
}
|