@shivaedev/quality 0.75.0 → 0.76.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/CHANGELOG.md +14 -0
- package/README.md +1 -1
- package/dist/adapters/databaseUrlFindings.d.ts +1 -1
- package/dist/adapters/databaseUrlFindings.d.ts.map +1 -1
- package/dist/adapters/knip/configuration.d.ts +1 -1
- package/dist/adapters/knip/configuration.d.ts.map +1 -1
- package/dist/adapters/knip/configuration.js +5 -1
- package/dist/adapters/knip/configuration.js.map +1 -1
- package/dist/adapters/knip/entryPointFindings.d.ts +1 -1
- package/dist/adapters/knip/entryPointFindings.d.ts.map +1 -1
- package/dist/adapters/knip/run.d.ts +1 -1
- package/dist/adapters/knip/run.d.ts.map +1 -1
- package/dist/adapters/outsideImportFindings.d.ts +2 -1
- package/dist/adapters/outsideImportFindings.d.ts.map +1 -1
- package/dist/adapters/outsideImportFindings.js.map +1 -1
- package/dist/adapters/queueReadoutFindings.d.ts +1 -1
- package/dist/adapters/queueReadoutFindings.d.ts.map +1 -1
- package/dist/adapters/rpcBoundaryFindings.d.ts +1 -1
- package/dist/adapters/rpcBoundaryFindings.d.ts.map +1 -1
- package/dist/adapters/serviceIdFindings.d.ts +1 -1
- package/dist/adapters/serviceIdFindings.d.ts.map +1 -1
- package/dist/cli/lint.d.ts +8 -1
- package/dist/cli/lint.d.ts.map +1 -1
- package/dist/cli/lint.js +9 -4
- package/dist/cli/lint.js.map +1 -1
- package/dist/cli/migrateExceptions.d.ts.map +1 -1
- package/dist/cli/migrateExceptions.js +5 -8
- package/dist/cli/migrateExceptions.js.map +1 -1
- package/dist/exceptions/MigrationFailure.d.ts +9 -0
- package/dist/exceptions/MigrationFailure.d.ts.map +1 -0
- package/dist/exceptions/MigrationFailure.js +4 -0
- package/dist/exceptions/MigrationFailure.js.map +1 -0
- package/dist/exceptions/migrateBiome.d.ts +3 -1
- package/dist/exceptions/migrateBiome.d.ts.map +1 -1
- package/dist/exceptions/migrateBiome.js +5 -3
- package/dist/exceptions/migrateBiome.js.map +1 -1
- package/dist/exceptions/migrateConfig.d.ts +3 -1
- package/dist/exceptions/migrateConfig.d.ts.map +1 -1
- package/dist/exceptions/migrateConfig.js +40 -25
- package/dist/exceptions/migrateConfig.js.map +1 -1
- package/dist/hooks/preCommit.d.ts.map +1 -1
- package/dist/hooks/preCommit.js +7 -3
- package/dist/hooks/preCommit.js.map +1 -1
- package/dist/imports/departures.d.ts +1 -1
- package/dist/imports/departures.d.ts.map +1 -1
- package/dist/imports/fences/check.d.ts +1 -1
- package/dist/imports/fences/check.d.ts.map +1 -1
- package/dist/imports/fences/check.js +1 -1
- package/dist/imports/fences/check.js.map +1 -1
- package/dist/imports/fences/compilePolicy.d.ts +3 -1
- package/dist/imports/fences/compilePolicy.d.ts.map +1 -1
- package/dist/imports/fences/compilePolicy.js +4 -2
- package/dist/imports/fences/compilePolicy.js.map +1 -1
- package/dist/imports/globMatcher.d.ts.map +1 -1
- package/dist/imports/globMatcher.js +33 -31
- package/dist/imports/globMatcher.js.map +1 -1
- package/dist/imports/graph.d.ts +1 -1
- package/dist/imports/graph.d.ts.map +1 -1
- package/dist/imports/pnpmWorkspacePatterns.d.ts +12 -2
- package/dist/imports/pnpmWorkspacePatterns.d.ts.map +1 -1
- package/dist/imports/pnpmWorkspacePatterns.js +31 -32
- package/dist/imports/pnpmWorkspacePatterns.js.map +1 -1
- package/dist/imports/workspace.d.ts +1 -1
- package/dist/imports/workspace.d.ts.map +1 -1
- package/dist/imports/workspace.js +1 -1
- package/dist/imports/workspace.js.map +1 -1
- package/dist/inventory/programmaticBuilds.d.ts +1 -1
- package/dist/inventory/programmaticBuilds.d.ts.map +1 -1
- package/dist/manifests/deliveredDependencies.d.ts +3 -0
- package/dist/manifests/deliveredDependencies.d.ts.map +1 -0
- package/dist/manifests/deliveredDependencies.js +8 -0
- package/dist/manifests/deliveredDependencies.js.map +1 -0
- package/dist/naming/developmentCode.d.ts +1 -1
- package/dist/naming/developmentCode.d.ts.map +1 -1
- package/dist/naming/packageTests.d.ts +1 -1
- package/dist/naming/packageTests.d.ts.map +1 -1
- package/dist/naming/testCode.d.ts +1 -1
- package/dist/naming/testCode.d.ts.map +1 -1
- package/dist/report/recap.d.ts +4 -0
- package/dist/report/recap.d.ts.map +1 -0
- package/dist/report/recap.js +23 -0
- package/dist/report/recap.js.map +1 -0
- package/dist/report/render.d.ts +1 -0
- package/dist/report/render.d.ts.map +1 -1
- package/dist/report/render.js +1 -1
- package/dist/report/render.js.map +1 -1
- package/dist/rules/manifestsApplication.d.ts.map +1 -1
- package/dist/rules/manifestsApplication.js +4 -5
- package/dist/rules/manifestsApplication.js.map +1 -1
- package/dist/rules/stories/sources.d.ts +2 -2
- package/dist/rules/stories/sources.d.ts.map +1 -1
- package/docs/debt-and-hooks.md +3 -1
- package/package.json +4 -4
- package/src/adapters/knip/configuration.ts +5 -1
- package/src/adapters/outsideImportFindings.ts +2 -1
- package/src/cli/lint.ts +24 -16
- package/src/cli/migrateExceptions.ts +8 -9
- package/src/exceptions/MigrationFailure.ts +5 -0
- package/src/exceptions/migrateBiome.ts +10 -4
- package/src/exceptions/migrateConfig.ts +66 -29
- package/src/hooks/preCommit.ts +7 -6
- package/src/imports/fences/check.ts +1 -1
- package/src/imports/fences/compilePolicy.ts +5 -3
- package/src/imports/globMatcher.ts +42 -35
- package/src/imports/pnpmWorkspacePatterns.ts +44 -39
- package/src/imports/workspace.ts +1 -1
- package/src/manifests/deliveredDependencies.ts +11 -0
- package/src/report/recap.ts +29 -0
- package/src/report/render.ts +1 -1
- package/src/rules/manifestsApplication.ts +4 -5
package/src/hooks/preCommit.ts
CHANGED
|
@@ -3,9 +3,11 @@ import { Console, Effect, Path } from "effect";
|
|
|
3
3
|
import { ChildProcess, ChildProcessSpawner } from "effect/process";
|
|
4
4
|
import { readPackageManifest } from "#adapters/manifestInventory.ts";
|
|
5
5
|
import { manifestReader } from "#adapters/manifestReader.ts";
|
|
6
|
-
import {
|
|
6
|
+
import { reportLint } from "#cli/lint.ts";
|
|
7
7
|
import { loadConfig } from "#config/load.ts";
|
|
8
|
+
import { passes } from "#engine/evaluate.ts";
|
|
8
9
|
import { GateFailed, SetupFailure } from "#failure.ts";
|
|
10
|
+
import { recap } from "#report/recap.ts";
|
|
9
11
|
|
|
10
12
|
const COMMIT_AGAIN =
|
|
11
13
|
"help: fix what the output above reports, then commit again; `quality hooks pre-commit` repeats these checks without committing.";
|
|
@@ -44,10 +46,8 @@ const runScript = Effect.fnUntraced(
|
|
|
44
46
|
export const preCommitHook = Effect.fn("Hooks.preCommitHook")(function* (cwd: string, path: string | undefined) {
|
|
45
47
|
const config = yield* loadConfig(cwd, path);
|
|
46
48
|
const { manager, scripts } = yield* commitScripts(config.root);
|
|
47
|
-
const
|
|
48
|
-
|
|
49
|
-
Effect.catchTag("GateFailed", () => Effect.succeed(false)),
|
|
50
|
-
);
|
|
49
|
+
const { context, outcome } = yield* reportLint(cwd, path, true);
|
|
50
|
+
const linted = passes(outcome);
|
|
51
51
|
const failed = linted ? [] : ["quality lint"];
|
|
52
52
|
for (const script of scripts) {
|
|
53
53
|
const command = `${manager} run ${script}`;
|
|
@@ -58,7 +58,8 @@ export const preCommitHook = Effect.fn("Hooks.preCommitHook")(function* (cwd: st
|
|
|
58
58
|
}
|
|
59
59
|
}
|
|
60
60
|
if (failed.length > 0) {
|
|
61
|
-
|
|
61
|
+
const findings = linted ? [] : [recap(outcome, context)];
|
|
62
|
+
yield* Console.error([...findings, `quality: pre-commit failed: ${failed.join(", ")}.`, COMMIT_AGAIN].join("\n"));
|
|
62
63
|
return yield* new GateFailed();
|
|
63
64
|
}
|
|
64
65
|
});
|
|
@@ -8,6 +8,6 @@ import type { RuleInputs } from "#rule.ts";
|
|
|
8
8
|
export const checkFences = Effect.fn("Imports.checkFences")(function* (inputs: RuleInputs, configured: readonly Fence[]) {
|
|
9
9
|
const graph = yield* importGraph(inputs);
|
|
10
10
|
const fences = [...configured, ...(yield* discoverFences(inputs, graph.packages))];
|
|
11
|
-
const policy = compilePolicy(fences, { files: inputs.files, packages: graph.packages });
|
|
11
|
+
const policy = yield* Effect.fromResult(compilePolicy(fences, { files: inputs.files, packages: graph.packages }));
|
|
12
12
|
return policy.flatMap((compiled) => compiled.evaluate(graph));
|
|
13
13
|
});
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
import { Result } from "effect";
|
|
1
2
|
import type { Endpoint } from "#imports/Endpoint.ts";
|
|
3
|
+
import { BoundaryFailure } from "#imports/fences/BoundaryFailure.ts";
|
|
2
4
|
import { type CompiledFence, compileFence, type FenceGraph } from "#imports/fences/evaluate.ts";
|
|
3
5
|
import type { PolicyScope } from "#imports/fences/match.ts";
|
|
4
6
|
import type { Chain, ExampleStep, Fence } from "#imports/fences/model.ts";
|
|
@@ -66,14 +68,14 @@ function declarationIssues(fences: readonly Fence[]): readonly string[] {
|
|
|
66
68
|
]);
|
|
67
69
|
}
|
|
68
70
|
|
|
69
|
-
export function compilePolicy(fences: readonly Fence[], scope: PolicyScope): readonly CompiledFence[] {
|
|
71
|
+
export function compilePolicy(fences: readonly Fence[], scope: PolicyScope): Result.Result<readonly CompiledFence[], BoundaryFailure> {
|
|
70
72
|
const issues = [...declarationIssues(fences)];
|
|
71
73
|
const policy = fences.map((fence) => compileFence({ issues, scope }, fence));
|
|
72
74
|
if (issues.length === 0) {
|
|
73
75
|
issues.push(...fences.flatMap((fence) => exampleIssues(policy, fence, scope)));
|
|
74
76
|
}
|
|
75
77
|
if (issues.length > 0) {
|
|
76
|
-
|
|
78
|
+
return Result.fail(new BoundaryFailure({ message: `the fence policy is invalid:\n${issues.map((issue) => ` - ${issue}`).join("\n")}` }));
|
|
77
79
|
}
|
|
78
|
-
return policy;
|
|
80
|
+
return Result.succeed(policy);
|
|
79
81
|
}
|
|
@@ -36,8 +36,8 @@ function charSource(char: string): string {
|
|
|
36
36
|
return REGEX_SYNTAX.test(char) ? `\\${char}` : char;
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
-
function unreadable(pattern: string, problem: string):
|
|
40
|
-
return new
|
|
39
|
+
function unreadable(pattern: string, problem: string): GlobFailure {
|
|
40
|
+
return new GlobFailure({ message: `cannot read the workspace pattern "${pattern}": ${problem}` });
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
function closingBrace(text: string, open: number): number {
|
|
@@ -65,72 +65,79 @@ function choices(body: string): readonly string[] {
|
|
|
65
65
|
return parts;
|
|
66
66
|
}
|
|
67
67
|
|
|
68
|
-
function expanded(pattern: string, whole: string): readonly string[] {
|
|
68
|
+
function expanded(pattern: string, whole: string): Result.Result<readonly string[], GlobFailure> {
|
|
69
69
|
const open = pattern.indexOf("{");
|
|
70
70
|
if (open === -1) {
|
|
71
|
-
return [pattern];
|
|
71
|
+
return Result.succeed([pattern]);
|
|
72
72
|
}
|
|
73
73
|
const close = closingBrace(pattern, open);
|
|
74
74
|
if (close === -1) {
|
|
75
|
-
|
|
75
|
+
return Result.fail(unreadable(whole, "a { never closes"));
|
|
76
76
|
}
|
|
77
77
|
const body = pattern.slice(open + 1, close);
|
|
78
78
|
if (BRACE_RANGE.test(body)) {
|
|
79
|
-
|
|
79
|
+
return Result.fail(unreadable(whole, "brace ranges are not supported"));
|
|
80
80
|
}
|
|
81
81
|
const options = choices(body);
|
|
82
82
|
if (options.length < 2) {
|
|
83
|
-
|
|
83
|
+
return Result.fail(unreadable(whole, "a { } needs two or more choices"));
|
|
84
84
|
}
|
|
85
|
-
return options.
|
|
85
|
+
return Result.map(Result.all(options.map((option) => expanded(`${pattern.slice(0, open)}${option}${pattern.slice(close + 1)}`, whole))), (found) =>
|
|
86
|
+
found.flat(),
|
|
87
|
+
);
|
|
86
88
|
}
|
|
87
89
|
|
|
88
|
-
function characterClass(
|
|
90
|
+
function characterClass(
|
|
91
|
+
segment: string,
|
|
92
|
+
start: number,
|
|
93
|
+
whole: string,
|
|
94
|
+
): Result.Result<{ readonly end: number; readonly source: string }, GlobFailure> {
|
|
89
95
|
const negated = segment[start + 1] === "!" || segment[start + 1] === "^";
|
|
90
96
|
const first = start + (negated ? 2 : 1);
|
|
91
97
|
const end = segment.indexOf("]", segment[first] === "]" ? first + 1 : first);
|
|
92
98
|
if (end === -1) {
|
|
93
|
-
|
|
99
|
+
return Result.fail(unreadable(whole, "a [ never closes"));
|
|
94
100
|
}
|
|
95
101
|
const body = segment.slice(first, end);
|
|
96
102
|
if (body.includes("[:")) {
|
|
97
|
-
|
|
103
|
+
return Result.fail(unreadable(whole, "character class names are not supported"));
|
|
98
104
|
}
|
|
99
|
-
return { end, source: `[${negated ? "^" : ""}${body.replace(CLASS_SYNTAX, "\\$&")}]` };
|
|
105
|
+
return Result.succeed({ end, source: `[${negated ? "^" : ""}${body.replace(CLASS_SYNTAX, "\\$&")}]` });
|
|
100
106
|
}
|
|
101
107
|
|
|
102
|
-
function segmentOf(segment: string, whole: string): Segment {
|
|
108
|
+
function segmentOf(segment: string, whole: string): Result.Result<Segment, GlobFailure> {
|
|
103
109
|
if (segment === GLOBSTAR) {
|
|
104
|
-
return GLOBSTAR;
|
|
110
|
+
return Result.succeed(GLOBSTAR);
|
|
105
111
|
}
|
|
106
112
|
if (EXTGLOB.test(segment)) {
|
|
107
|
-
|
|
113
|
+
return Result.fail(unreadable(whole, "extended globs are not supported"));
|
|
108
114
|
}
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
115
|
+
return Result.gen(function* () {
|
|
116
|
+
let source = "";
|
|
117
|
+
for (let index = 0; index < segment.length; index += 1) {
|
|
118
|
+
const char = segment[index] ?? "";
|
|
119
|
+
if (char === "[") {
|
|
120
|
+
const found = yield* characterClass(segment, index, whole);
|
|
121
|
+
source += found.source;
|
|
122
|
+
index = found.end;
|
|
123
|
+
} else {
|
|
124
|
+
source += charSource(char);
|
|
125
|
+
}
|
|
118
126
|
}
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
const alternatives = expanded(pattern, pattern).map((alternative) => alternative.split("/").map((segment) => segmentOf(segment, pattern)));
|
|
125
|
-
return (path) => alternatives.some((segments) => segmentsMatch(segments, path.split("/")));
|
|
127
|
+
return yield* Result.try({
|
|
128
|
+
catch: (cause) => new GlobFailure({ message: cause instanceof Error ? cause.message : String(cause) }),
|
|
129
|
+
try: (): Segment => new RegExp(`^${segment.startsWith(DOT) ? "" : NO_DOT}${source}$`, "u"),
|
|
130
|
+
});
|
|
131
|
+
});
|
|
126
132
|
}
|
|
127
133
|
|
|
128
134
|
export function globMatcher(pattern: string): Result.Result<(path: string) => boolean, GlobFailure> {
|
|
129
135
|
if (pattern.includes("\\")) {
|
|
130
|
-
return Result.fail(
|
|
136
|
+
return Result.fail(unreadable(pattern, "escapes are not supported"));
|
|
131
137
|
}
|
|
132
|
-
return Result.
|
|
133
|
-
|
|
134
|
-
|
|
138
|
+
return Result.gen(function* () {
|
|
139
|
+
const options = yield* expanded(pattern, pattern);
|
|
140
|
+
const alternatives = yield* Result.all(options.map((option) => Result.all(option.split("/").map((segment) => segmentOf(segment, pattern)))));
|
|
141
|
+
return (path: string) => alternatives.some((segments) => segmentsMatch(segments, path.split("/")));
|
|
135
142
|
});
|
|
136
143
|
}
|
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
import { Schema } from "effect";
|
|
1
|
+
import { Data, Result, Schema } from "effect";
|
|
2
|
+
|
|
3
|
+
export class PnpmWorkspaceFailure extends Data.TaggedError("PnpmWorkspaceFailure")<{
|
|
4
|
+
readonly cause?: unknown;
|
|
5
|
+
readonly message: string;
|
|
6
|
+
}> {}
|
|
2
7
|
|
|
3
8
|
function keyPattern(key: string): RegExp {
|
|
4
9
|
return new RegExp(`^(?:${key}|"${key}"|'${key}')\\s*:`, "u");
|
|
@@ -10,8 +15,8 @@ const SPACE = /\s/u;
|
|
|
10
15
|
|
|
11
16
|
const LINE_BREAK = /\r?\n/u;
|
|
12
17
|
|
|
13
|
-
function failure(problem: string, cause?: unknown):
|
|
14
|
-
return new
|
|
18
|
+
function failure(problem: string, cause?: unknown): PnpmWorkspaceFailure {
|
|
19
|
+
return new PnpmWorkspaceFailure({ cause, message: `pnpm-workspace.yaml: ${problem}` });
|
|
15
20
|
}
|
|
16
21
|
|
|
17
22
|
function withoutComment(line: string): string {
|
|
@@ -29,22 +34,20 @@ function withoutComment(line: string): string {
|
|
|
29
34
|
return line.trimEnd();
|
|
30
35
|
}
|
|
31
36
|
|
|
32
|
-
function scalar(raw: string, key: string): string {
|
|
37
|
+
function scalar(raw: string, key: string): Result.Result<string, PnpmWorkspaceFailure> {
|
|
33
38
|
const value = raw.trim();
|
|
34
39
|
if (value.startsWith('"') && value.endsWith('"') && value.length > 1) {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
throw failure(`cannot read "${value}" in ${key}`, error);
|
|
39
|
-
}
|
|
40
|
+
return Result.mapError(Schema.decodeUnknownResult(Schema.fromJsonString(Schema.String))(value), (error) =>
|
|
41
|
+
failure(`cannot read "${value}" in ${key}`, error),
|
|
42
|
+
);
|
|
40
43
|
}
|
|
41
44
|
if (value.startsWith("'") && value.endsWith("'") && value.length > 1) {
|
|
42
|
-
return value.slice(1, -1).replaceAll("''", "'");
|
|
45
|
+
return Result.succeed(value.slice(1, -1).replaceAll("''", "'"));
|
|
43
46
|
}
|
|
44
47
|
if (value === "" || value.includes(": ") || value.endsWith(":") || ["[", "{", "'", '"'].some((opening) => value.startsWith(opening))) {
|
|
45
|
-
|
|
48
|
+
return Result.fail(failure(`cannot read "${value}" in ${key}`));
|
|
46
49
|
}
|
|
47
|
-
return value;
|
|
50
|
+
return Result.succeed(value);
|
|
48
51
|
}
|
|
49
52
|
|
|
50
53
|
const FLOW_INDICATOR = /[{}[\]]/u;
|
|
@@ -55,20 +58,20 @@ interface FlowScan {
|
|
|
55
58
|
quote: string | undefined;
|
|
56
59
|
}
|
|
57
60
|
|
|
58
|
-
function flowScalar(raw: string, key: string): string {
|
|
61
|
+
function flowScalar(raw: string, key: string): Result.Result<string, PnpmWorkspaceFailure> {
|
|
59
62
|
const value = raw.trim();
|
|
60
63
|
const quoted = value.startsWith('"') || value.startsWith("'");
|
|
61
64
|
if (!quoted && FLOW_INDICATOR.test(value)) {
|
|
62
|
-
|
|
65
|
+
return Result.fail(failure(`cannot read "${value}" in ${key}; quote a pattern that holds { } [ ] or ,`));
|
|
63
66
|
}
|
|
64
67
|
return scalar(value, key);
|
|
65
68
|
}
|
|
66
69
|
|
|
67
|
-
function closed(scan: FlowScan, rest: string, key: string): readonly string[] {
|
|
70
|
+
function closed(scan: FlowScan, rest: string, key: string): Result.Result<readonly string[], PnpmWorkspaceFailure> {
|
|
68
71
|
if (rest.trim() !== "") {
|
|
69
|
-
|
|
72
|
+
return Result.fail(failure(`cannot read "${rest.trim()}" after the ${key} list`));
|
|
70
73
|
}
|
|
71
|
-
return [...scan.entries, scan.current].filter((entry) => entry.trim() !== "").map((entry) => flowScalar(entry, key));
|
|
74
|
+
return Result.all([...scan.entries, scan.current].filter((entry) => entry.trim() !== "").map((entry) => flowScalar(entry, key)));
|
|
72
75
|
}
|
|
73
76
|
|
|
74
77
|
function scanned(scan: FlowScan, char: string): "close" | undefined {
|
|
@@ -87,7 +90,7 @@ function scanned(scan: FlowScan, char: string): "close" | undefined {
|
|
|
87
90
|
return undefined;
|
|
88
91
|
}
|
|
89
92
|
|
|
90
|
-
function flowList(lines: readonly string[], key: string): readonly string[] {
|
|
93
|
+
function flowList(lines: readonly string[], key: string): Result.Result<readonly string[], PnpmWorkspaceFailure> {
|
|
91
94
|
const scan: FlowScan = { current: "", entries: [], quote: undefined };
|
|
92
95
|
for (const [number, line] of lines.map(withoutComment).entries()) {
|
|
93
96
|
for (let index = number === 0 ? 1 : 0; index < line.length; index += 1) {
|
|
@@ -97,34 +100,36 @@ function flowList(lines: readonly string[], key: string): readonly string[] {
|
|
|
97
100
|
}
|
|
98
101
|
scan.current += " ";
|
|
99
102
|
}
|
|
100
|
-
|
|
103
|
+
return Result.fail(failure(`the ${key} list never closes`));
|
|
101
104
|
}
|
|
102
105
|
|
|
103
|
-
function blockList(lines: readonly string[], key: string): readonly string[] {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
const
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
106
|
+
function blockList(lines: readonly string[], key: string): Result.Result<readonly string[], PnpmWorkspaceFailure> {
|
|
107
|
+
return Result.gen(function* () {
|
|
108
|
+
const patterns: string[] = [];
|
|
109
|
+
for (const line of lines.map(withoutComment)) {
|
|
110
|
+
const trimmed = line.trim();
|
|
111
|
+
if (trimmed === "") {
|
|
112
|
+
continue;
|
|
113
|
+
}
|
|
114
|
+
const item = trimmed === ITEM || trimmed.startsWith(`${ITEM} `);
|
|
115
|
+
if (!(item || line.startsWith(" ") || line.startsWith("\t"))) {
|
|
116
|
+
break;
|
|
117
|
+
}
|
|
118
|
+
if (!item) {
|
|
119
|
+
return yield* Result.fail(failure(`cannot read "${trimmed}" in ${key}`));
|
|
120
|
+
}
|
|
121
|
+
patterns.push(yield* scalar(trimmed.slice(ITEM.length), key));
|
|
116
122
|
}
|
|
117
|
-
patterns
|
|
118
|
-
}
|
|
119
|
-
return patterns;
|
|
123
|
+
return patterns;
|
|
124
|
+
});
|
|
120
125
|
}
|
|
121
126
|
|
|
122
|
-
export function pnpmWorkspaceList(text: string, key: string): readonly string[] {
|
|
127
|
+
export function pnpmWorkspaceList(text: string, key: string): Result.Result<readonly string[], PnpmWorkspaceFailure> {
|
|
123
128
|
const pattern = keyPattern(key);
|
|
124
129
|
const lines = text.split(LINE_BREAK);
|
|
125
130
|
const start = lines.findIndex((line) => pattern.test(line));
|
|
126
131
|
if (start === -1) {
|
|
127
|
-
return [];
|
|
132
|
+
return Result.succeed([]);
|
|
128
133
|
}
|
|
129
134
|
const rest = withoutComment(lines[start] ?? "")
|
|
130
135
|
.replace(pattern, "")
|
|
@@ -133,11 +138,11 @@ export function pnpmWorkspaceList(text: string, key: string): readonly string[]
|
|
|
133
138
|
return flowList([rest, ...lines.slice(start + 1)], key);
|
|
134
139
|
}
|
|
135
140
|
if (rest !== "") {
|
|
136
|
-
|
|
141
|
+
return Result.fail(failure(`cannot read "${rest}" in ${key}`));
|
|
137
142
|
}
|
|
138
143
|
return blockList(lines.slice(start + 1), key);
|
|
139
144
|
}
|
|
140
145
|
|
|
141
|
-
export function pnpmWorkspacePatterns(text: string): readonly string[] {
|
|
146
|
+
export function pnpmWorkspacePatterns(text: string): Result.Result<readonly string[], PnpmWorkspaceFailure> {
|
|
142
147
|
return pnpmWorkspaceList(text, "packages");
|
|
143
148
|
}
|
package/src/imports/workspace.ts
CHANGED
|
@@ -46,7 +46,7 @@ function matchers(patterns: readonly string[]) {
|
|
|
46
46
|
const memberOf = Effect.fn("Imports.memberOf")(function* (inputs: Reader) {
|
|
47
47
|
const pnpm = yield* inputs.readText(PNPM_WORKSPACE);
|
|
48
48
|
const patterns = [
|
|
49
|
-
...(pnpm === undefined ? [] : pnpmWorkspacePatterns(pnpm)),
|
|
49
|
+
...(pnpm === undefined ? [] : yield* Effect.fromResult(pnpmWorkspacePatterns(pnpm))),
|
|
50
50
|
...npmPatterns(yield* readPackageManifest(inputs.readText, MANIFEST)),
|
|
51
51
|
];
|
|
52
52
|
const included = yield* matchers(patterns.filter((pattern) => !pattern.startsWith(NEGATION)).map(normalized));
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { PackageManifest } from "#PackageManifest.ts";
|
|
2
|
+
|
|
3
|
+
const MANIFEST_EXPORT = "./package.json";
|
|
4
|
+
|
|
5
|
+
// A package that exports only its manifest and holds no sources ships no code: the dependencies it installs are what it delivers.
|
|
6
|
+
export function deliveredDependencies(manifest: PackageManifest, sources: readonly string[]): readonly string[] {
|
|
7
|
+
const exported = typeof manifest.exports === "object" && manifest.exports !== null ? Object.keys(manifest.exports) : [];
|
|
8
|
+
const shell =
|
|
9
|
+
sources.length === 0 && manifest.bin === undefined && manifest.main === undefined && exported.length === 1 && exported[0] === MANIFEST_EXPORT;
|
|
10
|
+
return shell ? Object.keys(manifest.dependencies ?? {}) : [];
|
|
11
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { Outcome } from "#engine/evaluate.ts";
|
|
2
|
+
import { groupBy } from "#engine/violation.ts";
|
|
3
|
+
import { plural } from "#report/plural.ts";
|
|
4
|
+
import { failures, type ReportContext } from "#report/render.ts";
|
|
5
|
+
|
|
6
|
+
const FILES_SHOWN = 3;
|
|
7
|
+
|
|
8
|
+
function firstFiles(files: readonly string[]): string {
|
|
9
|
+
const distinct = [...new Set(files)];
|
|
10
|
+
const shown = distinct.slice(0, FILES_SHOWN).join(", ");
|
|
11
|
+
return distinct.length > FILES_SHOWN ? `${shown} and ${plural(distinct.length - FILES_SHOWN, "more file")}` : shown;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function staleLine(file: string, entries: readonly { readonly entry: { readonly file: string } }[]): readonly string[] {
|
|
15
|
+
return entries.length === 0
|
|
16
|
+
? []
|
|
17
|
+
: [` error ${file} (${plural(entries.length, "stale entry", "stale entries")}): ${firstFiles(entries.map(({ entry }) => entry.file))}`];
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function recap(outcome: Outcome, context: ReportContext): string {
|
|
21
|
+
return [
|
|
22
|
+
`quality lint failed with ${failures(outcome)}:`,
|
|
23
|
+
...[...groupBy(outcome.errors, (violation) => violation.rule).entries()].map(
|
|
24
|
+
([rule, inRule]) => ` error ${rule} (${inRule.length}): ${firstFiles(inRule.map((violation) => violation.file))}`,
|
|
25
|
+
),
|
|
26
|
+
...staleLine(context.baseline, outcome.staleBaseline),
|
|
27
|
+
...staleLine(context.registry, outcome.staleRegistry),
|
|
28
|
+
].join("\n");
|
|
29
|
+
}
|
package/src/report/render.ts
CHANGED
|
@@ -41,7 +41,7 @@ function ruleSections(violations: readonly Violation[], context: ReportContext,
|
|
|
41
41
|
);
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
-
function failures(outcome: Outcome): string {
|
|
44
|
+
export function failures(outcome: Outcome): string {
|
|
45
45
|
const stale = outcome.staleBaseline.length + outcome.staleRegistry.length;
|
|
46
46
|
return [
|
|
47
47
|
...(outcome.errors.length > 0 ? [plural(outcome.errors.length, "error")] : []),
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { dirname, posix, relative, resolve, sep } from "node:path";
|
|
2
|
-
import { Effect } from "effect";
|
|
2
|
+
import { Effect, Result } from "effect";
|
|
3
3
|
import { type ManifestReadFailure, readPackageManifest } from "#adapters/manifestInventory.ts";
|
|
4
4
|
import { pnpmWorkspaceList } from "#imports/pnpmWorkspacePatterns.ts";
|
|
5
5
|
import { workspacePackages } from "#imports/workspace.ts";
|
|
@@ -48,10 +48,9 @@ const hoistFindings = Effect.fn("Manifests.hoistFindings")(function* (
|
|
|
48
48
|
if (workspace === undefined) {
|
|
49
49
|
return [{ file: manifestPath, message: `Depends on "${PLATFORM}" without a pnpm-workspace.yaml. ${repair}`, subject: HOIST_KEY }];
|
|
50
50
|
}
|
|
51
|
-
const parsed =
|
|
52
|
-
if (parsed
|
|
53
|
-
|
|
54
|
-
return [{ file: workspace.path, message: `${cause instanceof Error ? cause.message : String(cause)}. Write ${HOIST_LINE}.`, subject: HOIST_KEY }];
|
|
51
|
+
const parsed = pnpmWorkspaceList(workspace.text, HOIST_KEY);
|
|
52
|
+
if (Result.isFailure(parsed)) {
|
|
53
|
+
return [{ file: workspace.path, message: `${parsed.failure.message}. Write ${HOIST_LINE}.`, subject: HOIST_KEY }];
|
|
55
54
|
}
|
|
56
55
|
const patterns = parsed.success;
|
|
57
56
|
const included = patterns.some((pattern) => !pattern.startsWith("!") && hoists(pattern));
|