@shivaedev/quality 0.49.0 → 0.51.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 +33 -0
- package/README.md +20 -2
- package/dist/cli/args.d.ts +1 -0
- package/dist/cli/args.d.ts.map +1 -1
- package/dist/cli/args.js +8 -34
- package/dist/cli/args.js.map +1 -1
- package/dist/cli/baseline.d.ts +1 -1
- package/dist/cli/baseline.d.ts.map +1 -1
- package/dist/cli/baseline.js +9 -3
- package/dist/cli/baseline.js.map +1 -1
- package/dist/cli/messages.d.ts +1 -1
- package/dist/cli/messages.d.ts.map +1 -1
- package/dist/cli/messages.js +2 -1
- package/dist/cli/messages.js.map +1 -1
- package/dist/cli/options.d.ts +45 -0
- package/dist/cli/options.d.ts.map +1 -0
- package/dist/cli/options.js +35 -0
- package/dist/cli/options.js.map +1 -0
- package/dist/cli/program.js +1 -1
- package/dist/cli/program.js.map +1 -1
- package/dist/config/resolve.d.ts.map +1 -1
- package/dist/config/resolve.js +9 -6
- package/dist/config/resolve.js.map +1 -1
- package/dist/imports/classifyRuntime.d.ts.map +1 -1
- package/dist/imports/classifyRuntime.js +4 -1
- package/dist/imports/classifyRuntime.js.map +1 -1
- package/dist/imports/runtime.d.ts +6 -3
- package/dist/imports/runtime.d.ts.map +1 -1
- package/dist/imports/runtime.js +15 -21
- package/dist/imports/runtime.js.map +1 -1
- package/dist/naming/migrationFile.d.ts.map +1 -1
- package/dist/naming/migrationFile.js +3 -1
- package/dist/naming/migrationFile.js.map +1 -1
- package/dist/naming/moduleRoot.d.ts +2 -0
- package/dist/naming/moduleRoot.d.ts.map +1 -0
- package/dist/naming/moduleRoot.js +13 -0
- package/dist/naming/moduleRoot.js.map +1 -0
- package/dist/rules/builtIn.d.ts +2 -2
- package/dist/rules/builtIn.d.ts.map +1 -1
- package/dist/rules/builtIn.js +2 -0
- package/dist/rules/builtIn.js.map +1 -1
- package/dist/rules/effect/boundary.d.ts.map +1 -1
- package/dist/rules/effect/boundary.js +30 -6
- package/dist/rules/effect/boundary.js.map +1 -1
- package/dist/rules/effect/boundaryCalls.d.ts +3 -0
- package/dist/rules/effect/boundaryCalls.d.ts.map +1 -0
- package/dist/rules/effect/boundaryCalls.js +121 -0
- package/dist/rules/effect/boundaryCalls.js.map +1 -0
- package/dist/rules/effect/boundaryReference.d.ts +4 -0
- package/dist/rules/effect/boundaryReference.d.ts.map +1 -0
- package/dist/rules/effect/boundaryReference.js +80 -0
- package/dist/rules/effect/boundaryReference.js.map +1 -0
- package/dist/rules/effect/failureFindings.d.ts +8 -0
- package/dist/rules/effect/failureFindings.d.ts.map +1 -0
- package/dist/rules/effect/failureFindings.js +47 -0
- package/dist/rules/effect/failureFindings.js.map +1 -0
- package/dist/rules/effect/failureHonesty.d.ts +2 -0
- package/dist/rules/effect/failureHonesty.d.ts.map +1 -0
- package/dist/rules/effect/failureHonesty.js +53 -0
- package/dist/rules/effect/failureHonesty.js.map +1 -0
- package/dist/rules/effect/failureOperations.d.ts +9 -0
- package/dist/rules/effect/failureOperations.d.ts.map +1 -0
- package/dist/rules/effect/failureOperations.js +55 -0
- package/dist/rules/effect/failureOperations.js.map +1 -0
- package/dist/rules/effect/program.d.ts +1 -1
- package/dist/rules/effect/program.d.ts.map +1 -1
- package/dist/rules/effect/program.js +4 -1
- package/dist/rules/effect/program.js.map +1 -1
- package/dist/rules/effect/promiseParameter.d.ts +3 -0
- package/dist/rules/effect/promiseParameter.d.ts.map +1 -0
- package/dist/rules/effect/promiseParameter.js +24 -0
- package/dist/rules/effect/promiseParameter.js.map +1 -0
- package/dist/rules/effect/successRecovery.d.ts +3 -0
- package/dist/rules/effect/successRecovery.d.ts.map +1 -0
- package/dist/rules/effect/successRecovery.js +43 -0
- package/dist/rules/effect/successRecovery.js.map +1 -0
- package/dist/rules/imports/runtime.d.ts +1 -1
- package/dist/rules/imports/runtime.d.ts.map +1 -1
- package/dist/rules/stories/groupedOutcomes.js +1 -1
- package/dist/rules/stories/groupedOutcomes.js.map +1 -1
- package/docs/debt-and-hooks.md +3 -1
- package/package.json +2 -2
- package/src/cli/args.ts +15 -43
- package/src/cli/baseline.ts +9 -2
- package/src/cli/messages.ts +2 -1
- package/src/cli/options.ts +43 -0
- package/src/cli/program.ts +1 -1
- package/src/config/resolve.ts +4 -6
- package/src/imports/classifyRuntime.ts +4 -1
- package/src/imports/runtime.ts +19 -21
- package/src/naming/migrationFile.ts +3 -1
- package/src/naming/moduleRoot.ts +13 -0
- package/src/rules/builtIn.ts +2 -0
- package/src/rules/effect/boundary.ts +48 -24
- package/src/rules/effect/boundaryCalls.ts +130 -0
- package/src/rules/effect/boundaryReference.ts +85 -0
- package/src/rules/effect/failureFindings.ts +55 -0
- package/src/rules/effect/failureHonesty.ts +59 -0
- package/src/rules/effect/failureOperations.ts +66 -0
- package/src/rules/effect/program.ts +4 -1
- package/src/rules/effect/promiseParameter.ts +26 -0
- package/src/rules/effect/successRecovery.ts +44 -0
- package/src/rules/stories/groupedOutcomes.ts +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"failureHonesty.d.ts","sourceRoot":"","sources":["../../../src/rules/effect/failureHonesty.ts"],"names":[],"mappings":"AAmCA,eAAO,MAAM,cAAc,qEAuBzB,CAAC"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { join } from "node:path";
|
|
2
|
+
import ts from "typescript";
|
|
3
|
+
import { defineRule } from "#rule.ts";
|
|
4
|
+
import { failureFindings } from "./failureFindings.js";
|
|
5
|
+
import { effectProgram } from "./program.js";
|
|
6
|
+
function checkFailures(inputs) {
|
|
7
|
+
const program = effectProgram(inputs, false);
|
|
8
|
+
const checker = program.getTypeChecker();
|
|
9
|
+
return inputs.sources.flatMap((file) => {
|
|
10
|
+
const source = program.getSourceFile(join(inputs.root, file.path));
|
|
11
|
+
const findings = [];
|
|
12
|
+
const reported = new Set();
|
|
13
|
+
function report(node, message) {
|
|
14
|
+
const key = `${node.pos}:${message}`;
|
|
15
|
+
if (source !== undefined && !reported.has(key)) {
|
|
16
|
+
reported.add(key);
|
|
17
|
+
findings.push({ file: file.path, line: source.getLineAndCharacterOfPosition(node.getStart(source)).line + 1, message });
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
function visit(node) {
|
|
21
|
+
if (ts.isCallExpression(node)) {
|
|
22
|
+
for (const finding of failureFindings(checker, node)) {
|
|
23
|
+
report(finding.node, finding.message);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
ts.forEachChild(node, visit);
|
|
27
|
+
}
|
|
28
|
+
if (source !== undefined) {
|
|
29
|
+
visit(source);
|
|
30
|
+
}
|
|
31
|
+
return findings;
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
export const failureHonesty = defineRule({
|
|
35
|
+
check: (inputs) => {
|
|
36
|
+
const groups = new Map();
|
|
37
|
+
for (const source of inputs.sources) {
|
|
38
|
+
if (!(/\.[cm]?[jt]sx?$/u.test(source.path)
|
|
39
|
+
&& /\b(?:catch|catchAll|catchCause|catchAllCause|retry|forever|option|orElseSucceed)\b/u.test(source.text))) {
|
|
40
|
+
continue;
|
|
41
|
+
}
|
|
42
|
+
const group = /^(?:packages|examples)\/[^/]+/u.exec(source.path)?.[0] ?? ".";
|
|
43
|
+
const sources = groups.get(group) ?? [];
|
|
44
|
+
sources.push(source);
|
|
45
|
+
groups.set(group, sources);
|
|
46
|
+
}
|
|
47
|
+
return [...groups.values()].flatMap((sources) => checkFailures({ ...inputs, sources }));
|
|
48
|
+
},
|
|
49
|
+
description: "Keep failures typed and observable: no forked forever/orDie loops, retry({ while }) without a bound, blanket catch-to-success, or FileSystem option/orElseSucceed. Catch a named reason, use a Schedule-bounded retry or model an explicit unavailable state. No config exceptions or inline suppressions; baseline existing debt.",
|
|
50
|
+
id: "effect/failure-honesty",
|
|
51
|
+
registrable: false,
|
|
52
|
+
});
|
|
53
|
+
//# sourceMappingURL=failureHonesty.js.map
|
|
@@ -0,0 +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CAAC,MAAM,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,aAAa,CAAC,EAAE,GAAG,MAAM,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC;IACzF,CAAC;IACD,WAAW,EACV,oUAAoU;IACrU,EAAE,EAAE,wBAAwB;IAC5B,WAAW,EAAE,KAAK;CAClB,CAAC,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
export interface FailureOperation {
|
|
3
|
+
readonly name: string;
|
|
4
|
+
readonly node: ts.Node;
|
|
5
|
+
}
|
|
6
|
+
export declare function effectName(checker: ts.TypeChecker, node: ts.Node): string | undefined;
|
|
7
|
+
export declare function failureOperations(checker: ts.TypeChecker, node: ts.Node, seen?: Set<ts.Symbol>): FailureOperation[];
|
|
8
|
+
export declare function fileSystemCall(checker: ts.TypeChecker, node: ts.Node): boolean;
|
|
9
|
+
//# sourceMappingURL=failureOperations.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"failureOperations.d.ts","sourceRoot":"","sources":["../../../src/rules/effect/failureOperations.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,YAAY,CAAC;AAG5B,MAAM,WAAW,gBAAgB;IAChC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC;CACvB;AAED,wBAAgB,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC,WAAW,EAAE,IAAI,EAAE,EAAE,CAAC,IAAI,GAAG,MAAM,GAAG,SAAS,CAErF;AAED,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,EAAE,CAAC,WAAW,EAAE,IAAI,EAAE,EAAE,CAAC,IAAI,EAAE,IAAI,iBAAuB,GAAG,gBAAgB,EAAE,CA2BzH;AAoBD,wBAAgB,cAAc,CAAC,OAAO,EAAE,EAAE,CAAC,WAAW,EAAE,IAAI,EAAE,EAAE,CAAC,IAAI,GAAG,OAAO,CAM9E"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
import { boundaryReference } from "./boundaryReference.js";
|
|
3
|
+
export function effectName(checker, node) {
|
|
4
|
+
return /^effect(?:\.Effect|\/Effect)\.(?<name>\w+)$/u.exec(boundaryReference(checker, node) ?? "")?.groups?.name;
|
|
5
|
+
}
|
|
6
|
+
export function failureOperations(checker, node, seen = new Set()) {
|
|
7
|
+
if (ts.isParenthesizedExpression(node)) {
|
|
8
|
+
return failureOperations(checker, node.expression, seen);
|
|
9
|
+
}
|
|
10
|
+
if (ts.isIdentifier(node)) {
|
|
11
|
+
const symbol = checker.getSymbolAtLocation(node);
|
|
12
|
+
if (symbol !== undefined && !seen.has(symbol)) {
|
|
13
|
+
seen.add(symbol);
|
|
14
|
+
const declaration = symbol.valueDeclaration;
|
|
15
|
+
if (declaration !== undefined && ts.isVariableDeclaration(declaration) && declaration.initializer !== undefined) {
|
|
16
|
+
return failureOperations(checker, declaration.initializer, seen);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
if (ts.isCallExpression(node) && ts.isPropertyAccessExpression(node.expression) && node.expression.name.text === "pipe") {
|
|
21
|
+
return [
|
|
22
|
+
failureOperations(checker, node.expression.expression, seen),
|
|
23
|
+
...node.arguments.map((part) => failureOperations(checker, part, new Set(seen))),
|
|
24
|
+
].flat();
|
|
25
|
+
}
|
|
26
|
+
const name = effectName(checker, ts.isCallExpression(node) ? node.expression : node);
|
|
27
|
+
if (name === undefined) {
|
|
28
|
+
return [{ name: "source", node }];
|
|
29
|
+
}
|
|
30
|
+
const args = ts.isCallExpression(node) ? node.arguments : [];
|
|
31
|
+
const first = args[0];
|
|
32
|
+
return [...(first === undefined ? [] : failureOperations(checker, first, seen)), { name, node }];
|
|
33
|
+
}
|
|
34
|
+
function fileSystemService(checker, node, seen = new Set()) {
|
|
35
|
+
if (/^effect(?:\.FileSystem|\/FileSystem)\.FileSystem$/u.test(boundaryReference(checker, node) ?? "")) {
|
|
36
|
+
return true;
|
|
37
|
+
}
|
|
38
|
+
if (ts.isYieldExpression(node) || ts.isParenthesizedExpression(node)) {
|
|
39
|
+
return node.expression !== undefined && fileSystemService(checker, node.expression, seen);
|
|
40
|
+
}
|
|
41
|
+
const symbol = checker.getSymbolAtLocation(node);
|
|
42
|
+
if (symbol === undefined || seen.has(symbol)) {
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
seen.add(symbol);
|
|
46
|
+
return (symbol.declarations ?? []).some((declaration) => ts.isVariableDeclaration(declaration) && declaration.initializer !== undefined && fileSystemService(checker, declaration.initializer, seen));
|
|
47
|
+
}
|
|
48
|
+
export function fileSystemCall(checker, node) {
|
|
49
|
+
if (!ts.isCallExpression(node)) {
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
const callee = node.expression;
|
|
53
|
+
return (ts.isPropertyAccessExpression(callee) || ts.isElementAccessExpression(callee)) && fileSystemService(checker, callee.expression);
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=failureOperations.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"failureOperations.js","sourceRoot":"","sources":["../../../src/rules/effect/failureOperations.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,YAAY,CAAC;AAC5B,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAO3D,MAAM,UAAU,UAAU,CAAC,OAAuB,EAAE,IAAa;IAChE,OAAO,8CAA8C,CAAC,IAAI,CAAC,iBAAiB,CAAC,OAAO,EAAE,IAAI,CAAC,IAAI,EAAE,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC;AAClH,CAAC;AAED,MAAM,UAAU,iBAAiB,CAAC,OAAuB,EAAE,IAAa,EAAE,IAAI,GAAG,IAAI,GAAG,EAAa;IACpG,IAAI,EAAE,CAAC,yBAAyB,CAAC,IAA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;IACD,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IACjB,OAAO,CAAC,MAAM,CAAC,YAAY,IAAI,EAAE,CAAC,CAAC,IAAI,CACtC,CAAC,WAAW,EAAE,EAAE,CACf,EAAE,CAAC,qBAAqB,CAAC,WAAW,CAAC,IAAI,WAAW,CAAC,WAAW,KAAK,SAAS,IAAI,iBAAiB,CAAC,OAAO,EAAE,WAAW,CAAC,WAAW,EAAE,IAAI,CAAC,CAC5I,CAAC;AACH,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,OAAuB,EAAE,IAAa;IACpE,IAAI,CAAC,EAAE,CAAC,gBAAgB,CAAC,IAAI,CAAC,EAAE,CAAC;QAChC,OAAO,KAAK,CAAC;IACd,CAAC;IACD,MAAM,MAAM,GAAG,IAAI,CAAC,UAAU,CAAC;IAC/B,OAAO,CAAC,EAAE,CAAC,0BAA0B,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,yBAAyB,CAAC,MAAM,CAAC,CAAC,IAAI,iBAAiB,CAAC,OAAO,EAAE,MAAM,CAAC,UAAU,CAAC,CAAC;AACzI,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import ts from "typescript";
|
|
2
2
|
import type { RuleInputs } from "#rule.ts";
|
|
3
|
-
export declare function effectProgram(inputs: RuleInputs): ts.Program;
|
|
3
|
+
export declare function effectProgram(inputs: RuleInputs, externalTypes?: boolean): ts.Program;
|
|
4
4
|
//# sourceMappingURL=program.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"program.d.ts","sourceRoot":"","sources":["../../../src/rules/effect/program.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,YAAY,CAAC;AAE5B,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAE3C,wBAAgB,aAAa,CAAC,MAAM,EAAE,UAAU,GAAG,EAAE,CAAC,OAAO,
|
|
1
|
+
{"version":3,"file":"program.d.ts","sourceRoot":"","sources":["../../../src/rules/effect/program.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,YAAY,CAAC;AAE5B,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAE3C,wBAAgB,aAAa,CAAC,MAAM,EAAE,UAAU,EAAE,aAAa,UAAO,GAAG,EAAE,CAAC,OAAO,CAuBlF"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { join } from "node:path";
|
|
2
2
|
import ts from "typescript";
|
|
3
3
|
import { projectsFor } from "#imports/projects.ts";
|
|
4
|
-
export function effectProgram(inputs) {
|
|
4
|
+
export function effectProgram(inputs, externalTypes = true) {
|
|
5
5
|
const projectOf = projectsFor(inputs.root);
|
|
6
6
|
const options = {
|
|
7
7
|
allowJs: true,
|
|
@@ -16,6 +16,9 @@ export function effectProgram(inputs) {
|
|
|
16
16
|
const read = host.readFile;
|
|
17
17
|
host.readFile = (path) => texts.get(path) ?? read(path);
|
|
18
18
|
host.resolveModuleNames = (names, from) => names.map((name) => {
|
|
19
|
+
if (!(externalTypes || name.startsWith(".") || name.startsWith("#") || name.startsWith("@shivaedev/"))) {
|
|
20
|
+
return undefined;
|
|
21
|
+
}
|
|
19
22
|
const project = projectOf(from);
|
|
20
23
|
return ts.resolveModuleName(name, from, project.typesOptions, host, project.typesCache).resolvedModule;
|
|
21
24
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"program.js","sourceRoot":"","sources":["../../../src/rules/effect/program.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,MAAM,YAAY,CAAC;AAC5B,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAGnD,MAAM,UAAU,aAAa,CAAC,MAAkB;
|
|
1
|
+
{"version":3,"file":"program.js","sourceRoot":"","sources":["../../../src/rules/effect/program.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAA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C;YACxG,OAAO,SAAS,CAAC;QAClB,CAAC;QACD,MAAM,OAAO,GAAG,SAAS,CAAC,IAAI,CAAC,CAAC;QAChC,OAAO,EAAE,CAAC,iBAAiB,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,CAAC,YAAY,EAAE,IAAI,EAAE,OAAO,CAAC,UAAU,CAAC,CAAC,cAAc,CAAC;IACxG,CAAC,CAAC,CAAC;IACJ,OAAO,EAAE,CAAC,aAAa,CAAC,CAAC,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC,EAAE,OAAO,EAAE,IAAI,CAAC,CAAC;AAC3D,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"promiseParameter.d.ts","sourceRoot":"","sources":["../../../src/rules/effect/promiseParameter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,YAAY,CAAC;AAE5B,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,EAAE,CAAC,WAAW,EAAE,IAAI,EAAE,EAAE,CAAC,IAAI,GAAG,MAAM,GAAG,SAAS,CAuB3F"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
export function promiseParameter(checker, node) {
|
|
3
|
+
if (!ts.isParameter(node)) {
|
|
4
|
+
return undefined;
|
|
5
|
+
}
|
|
6
|
+
const seen = new Set();
|
|
7
|
+
function carries(type) {
|
|
8
|
+
if (seen.has(type)) {
|
|
9
|
+
return false;
|
|
10
|
+
}
|
|
11
|
+
seen.add(type);
|
|
12
|
+
if (["Promise", "PromiseLike"].includes(type.getSymbol()?.name ?? "")) {
|
|
13
|
+
return true;
|
|
14
|
+
}
|
|
15
|
+
if (type.isUnionOrIntersection()) {
|
|
16
|
+
return type.types.some(carries);
|
|
17
|
+
}
|
|
18
|
+
const constraint = checker.getBaseConstraintOfType(type);
|
|
19
|
+
return ((constraint !== undefined && carries(constraint))
|
|
20
|
+
|| type.getCallSignatures().some((signature) => carries(checker.getReturnTypeOfSignature(signature))));
|
|
21
|
+
}
|
|
22
|
+
return carries(checker.getTypeAtLocation(node)) ? `Promise-typed parameter (${node.name.getText()})` : undefined;
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=promiseParameter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"promiseParameter.js","sourceRoot":"","sources":["../../../src/rules/effect/promiseParameter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,YAAY,CAAC;AAE5B,MAAM,UAAU,gBAAgB,CAAC,OAAuB,EAAE,IAAa;IACtE,IAAI,CAAC,EAAE,CAAC,WAAW,CAAC,IAAI,CAAC,EAAE,CAAC;QAC3B,OAAO,SAAS,CAAC;IAClB,CAAC;IACD,MAAM,IAAI,GAAG,IAAI,GAAG,EAAW,CAAC;IAChC,SAAS,OAAO,CAAC,IAAa;QAC7B,IAAI,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC;YACpB,OAAO,KAAK,CAAC;QACd,CAAC;QACD,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QACf,IAAI,CAAC,SAAS,EAAE,aAAa,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,SAAS,EAAE,EAAE,IAAI,IAAI,EAAE,CAAC,EAAE,CAAC;YACvE,OAAO,IAAI,CAAC;QACb,CAAC;QACD,IAAI,IAAI,CAAC,qBAAqB,EAAE,EAAE,CAAC;YAClC,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QACjC,CAAC;QACD,MAAM,UAAU,GAAG,OAAO,CAAC,uBAAuB,CAAC,IAAI,CAAC,CAAC;QACzD,OAAO,CACN,CAAC,UAAU,KAAK,SAAS,IAAI,OAAO,CAAC,UAAU,CAAC,CAAC;eAC9C,IAAI,CAAC,iBAAiB,EAAE,CAAC,IAAI,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,wBAAwB,CAAC,SAAS,CAAC,CAAC,CAAC,CACrG,CAAC;IACH,CAAC;IACD,OAAO,OAAO,CAAC,OAAO,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,4BAA4B,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC,CAAC,SAAS,CAAC;AAClH,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"successRecovery.d.ts","sourceRoot":"","sources":["../../../src/rules/effect/successRecovery.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,YAAY,CAAC;AAwB5B,wBAAgB,eAAe,CAAC,OAAO,EAAE,EAAE,CAAC,WAAW,EAAE,OAAO,EAAE,EAAE,CAAC,IAAI,EAAE,IAAI,iBAAuB,GAAG,OAAO,CAmB/G"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
import { returnValues } from "#rules/stories/returnValues.ts";
|
|
3
|
+
import { effectName } from "./failureOperations.js";
|
|
4
|
+
function success(checker, node, seen) {
|
|
5
|
+
if (ts.isParenthesizedExpression(node)) {
|
|
6
|
+
return success(checker, node.expression, seen);
|
|
7
|
+
}
|
|
8
|
+
if (ts.isConditionalExpression(node)) {
|
|
9
|
+
return success(checker, node.whenTrue, new Set(seen)) && success(checker, node.whenFalse, new Set(seen));
|
|
10
|
+
}
|
|
11
|
+
if (ts.isIdentifier(node)) {
|
|
12
|
+
const symbol = checker.getSymbolAtLocation(node);
|
|
13
|
+
if (symbol !== undefined && !seen.has(symbol)) {
|
|
14
|
+
seen.add(symbol);
|
|
15
|
+
const declaration = symbol.valueDeclaration;
|
|
16
|
+
if (declaration !== undefined && ts.isVariableDeclaration(declaration) && declaration.initializer !== undefined) {
|
|
17
|
+
return success(checker, declaration.initializer, seen);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return effectName(checker, ts.isCallExpression(node) ? node.expression : node) === (ts.isCallExpression(node) ? "succeed" : "void");
|
|
22
|
+
}
|
|
23
|
+
export function successRecovery(checker, handler, seen = new Set()) {
|
|
24
|
+
if (ts.isArrowFunction(handler) || ts.isFunctionExpression(handler) || ts.isFunctionDeclaration(handler)) {
|
|
25
|
+
const values = returnValues(handler);
|
|
26
|
+
return values.length > 0 && values.every((value) => value !== undefined && success(checker, value, new Set()));
|
|
27
|
+
}
|
|
28
|
+
if (effectName(checker, handler) === "succeed") {
|
|
29
|
+
return true;
|
|
30
|
+
}
|
|
31
|
+
const symbol = checker.getSymbolAtLocation(handler);
|
|
32
|
+
if (symbol === undefined || seen.has(symbol)) {
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
seen.add(symbol);
|
|
36
|
+
return (symbol.declarations ?? []).some((declaration) => {
|
|
37
|
+
if (ts.isVariableDeclaration(declaration) && declaration.initializer !== undefined) {
|
|
38
|
+
return successRecovery(checker, declaration.initializer, seen);
|
|
39
|
+
}
|
|
40
|
+
return ts.isFunctionDeclaration(declaration) && successRecovery(checker, declaration, seen);
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=successRecovery.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"successRecovery.js","sourceRoot":"","sources":["../../../src/rules/effect/successRecovery.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,YAAY,CAAC;AAC5B,OAAO,EAAE,YAAY,EAAE,MAAM,gCAAgC,CAAC;AAC9D,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAEpD,SAAS,OAAO,CAAC,OAAuB,EAAE,IAAa,EAAE,IAAoB;IAC5E,IAAI,EAAE,CAAC,yBAAyB,CAAC,IAAI,CAAC,EAAE,CAAC;QACxC,OAAO,OAAO,CAAC,OAAO,EAAE,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC;IAChD,CAAC;IACD,IAAI,EAAE,CAAC,uBAAuB,CAAC,IAAI,CAAC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C,qBAAqB,CAAC,OAAO,CAAC,EAAE,CAAC;QAC1G,MAAM,MAAM,GAAG,YAAY,CAAC,OAAO,CAAC,CAAC;QACrC,OAAO,MAAM,CAAC,MAAM,GAAG,CAAC,IAAI,MAAM,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,KAAK,SAAS,IAAI,OAAO,CAAC,OAAO,EAAE,KAAK,EAAE,IAAI,GAAG,EAAE,CAAC,CAAC,CAAC;IAChH,CAAC;IACD,IAAI,UAAU,CAAC,OAAO,EAAE,OAAO,CAAC,KAAK,SAAS,EAAE,CAAC;QAChD,OAAO,IAAI,CAAC;IACb,CAAC;IACD,MAAM,MAAM,GAAG,OAAO,CAAC,mBAAmB,CAAC,OAAO,CAAC,CAAC;IACpD,IAAI,MAAM,KAAK,SAAS,IAAI,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC;QAC9C,OAAO,KAAK,CAAC;IACd,CAAC;IACD,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IACjB,OAAO,CAAC,MAAM,CAAC,YAAY,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,WAAW,EAAE,EAAE;QACvD,IAAI,EAAE,CAAC,qBAAqB,CAAC,WAAW,CAAC,IAAI,WAAW,CAAC,WAAW,KAAK,SAAS,EAAE,CAAC;YACpF,OAAO,eAAe,CAAC,OAAO,EAAE,WAAW,CAAC,WAAW,EAAE,IAAI,CAAC,CAAC;QAChE,CAAC;QACD,OAAO,EAAE,CAAC,qBAAqB,CAAC,WAAW,CAAC,IAAI,eAAe,CAAC,OAAO,EAAE,WAAW,EAAE,IAAI,CAAC,CAAC;IAC7F,CAAC,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const importsRuntime: import("#rule.ts").Rule<"imports/runtime", undefined,
|
|
1
|
+
export declare const importsRuntime: import("#rule.ts").Rule<"imports/runtime", undefined, import("effect/FileSystem").FileSystem>;
|
|
2
2
|
//# sourceMappingURL=runtime.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../../../src/rules/imports/runtime.ts"],"names":[],"mappings":"AAoCA,eAAO,MAAM,cAAc,
|
|
1
|
+
{"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../../../src/rules/imports/runtime.ts"],"names":[],"mappings":"AAoCA,eAAO,MAAM,cAAc,+FAsBzB,CAAC"}
|
|
@@ -4,7 +4,7 @@ import { defineRule } from "#rule.ts";
|
|
|
4
4
|
import { importBindings } from "./importBindings.js";
|
|
5
5
|
import { storySources } from "./sources.js";
|
|
6
6
|
import { memberName, syntaxFindings, unwrapped } from "./syntax.js";
|
|
7
|
-
const MESSAGE = 'Checks several outcomes with consecutive expect(yield* …) lines. Let the story\'s words lead: yield* outcomes(
|
|
7
|
+
const MESSAGE = 'Checks several outcomes with consecutive expect(yield* …) lines. Let the story\'s words lead: yield* outcomes([["label", () => readout(), expected], …]) from @shivaedev/test-story/server/outcomes.ts, one row per outcome. Keep a plain expect for a single outcome.';
|
|
8
8
|
const EXPECT_MODULES = ["vitest", "@effect/vitest"];
|
|
9
9
|
function yields(node) {
|
|
10
10
|
return ((ts.isYieldExpression(node) && node.asteriskToken !== undefined)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"groupedOutcomes.js","sourceRoot":"","sources":["../../../src/rules/stories/groupedOutcomes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,MAAM,YAAY,CAAC;AAC5B,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AACtC,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,aA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C,IAAI,EAAE,EAAE,CAAC,cAAc,CAAC,IAAI,EAAE,iBAAiB,EAAE,OAAO,CAAC,CAAC,CAAC;IAC7I,WAAW,EAAE,uGAAuG;IACpH,EAAE,EAAE,wBAAwB;CAC5B,CAAC,CAAC"}
|
package/docs/debt-and-hooks.md
CHANGED
|
@@ -4,6 +4,8 @@ The [README](../README.md) introduces the gate. This page explains how the basel
|
|
|
4
4
|
|
|
5
5
|
## Baseline
|
|
6
6
|
|
|
7
|
+
For a shared policy upgrade, `quality baseline write --first-adoption --rule <id>` records existing findings of explicitly named rules that refuse config exceptions, including unchanged files. This mode covers first adoption of a rule or new detection shapes; it does not change ordinary file-scoped writes. Review each new or raised entry and state why that debt needs a separate migration. Rules that permit exceptions and unnamed rules refuse this mode.
|
|
8
|
+
|
|
7
9
|
```jsonl
|
|
8
10
|
{"path":"src/legacy/sync.ts","rule":"comments/no-jsdoc","count":3}
|
|
9
11
|
{"path":"src/server/db.ts","rule":"structure/max-lines","count":262}
|
|
@@ -12,7 +14,7 @@ The [README](../README.md) introduces the gate. This page explains how the basel
|
|
|
12
14
|
The baseline is sharded: `packages/<package>/quality-baseline.jsonl` holds paths inside that package, and the root `quality-baseline.jsonl` holds all other paths. Packages without entries have no file. Each shard is JSON Lines with one entry per line: the violations of one rule in one file. `count` is how many violations the file may have. For a rule that counts occurrences, such as `comments/no-jsdoc`, that is the number of occurrences. For a rule with a limit, it is the amount over the limit: the entry above lets `src/server/db.ts` have 412 lines under a limit of 150. A new baseline is sorted by path and then rule. Later edits preserve unrelated lines, including their formatting and order, so the diff shows the entries that changed.
|
|
13
15
|
|
|
14
16
|
`quality lint` fails when a baselined file has more violations than its `count`; the report then lists all of that file's violations for the rule. A file at or below its entry passes. An entry that allows more than is left, including a file with no violations left, is listed as a note and does not fail, so fixing debt never breaks the build; `tighten` and `prune` lower it. An entry for an unknown rule fails until it is pruned.
|
|
15
|
-
- `quality baseline write` records every error-level violation when there is no baseline yet.
|
|
17
|
+
- `quality baseline write` records every error-level violation when there is no baseline yet. For ordinary writes after a baseline exists, both `--rule <id>` and `--file <path>` are required. Repeat either option for multiple selections. Each path is relative to the config folder and must be changed since `HEAD`, staged or unstaged; new files need `git add` first. An unchanged file refuses the whole write. Only selected rule/file entries are replaced; all other entries stay as they are. With no baseline and no file selection, initial adoption records the repository once.
|
|
16
18
|
- `quality baseline tighten` lowers and removes the entries of files changed since `HEAD`, and with `--staged`, of the files staged for the next commit. It carries the entry of a file that git sees as moved to the new path. Every other line stays byte for byte.
|
|
17
19
|
- `quality baseline prune` does the same for every entry. It carries the entries of files moved since the merge base (see `--against` under [Command line](../README.md#command-line)), and prunes without following moves outside a git work tree.
|
|
18
20
|
- `quality baseline migrate` moves a baseline from the earlier JSON format, `quality/baseline.json` or the file `--from` names, to the root and package shards, and removes the old one. `--from quality/baseline.jsonl` splits a single JSON Lines baseline without changing its counts. An old entry that stored a size, such as a line count, becomes that size less the rule's current limit; an entry whose file is now within the limit is dropped.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shivaedev/quality",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.51.0",
|
|
4
4
|
"description": "Repository quality gate with typed rules, a baseline of existing debt and a registry of reasoned exceptions",
|
|
5
5
|
"homepage": "https://github.com/ShivaeDev/platform/tree/main/packages/quality#readme",
|
|
6
6
|
"bugs": {
|
|
@@ -62,7 +62,7 @@
|
|
|
62
62
|
"@effect/platform-node": "4.0.6",
|
|
63
63
|
"@effect/platform-node-shared": "4.0.6",
|
|
64
64
|
"@effect/vitest": "4.0.6",
|
|
65
|
-
"@shivaedev/test-story": "0.
|
|
65
|
+
"@shivaedev/test-story": "0.31.0",
|
|
66
66
|
"@types/node": "24.19.2",
|
|
67
67
|
"@typescript/native": "npm:typescript@7.0.2",
|
|
68
68
|
"effect": "4.0.6",
|
package/src/cli/args.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { parseArgs } from "node:util";
|
|
2
2
|
import { Result } from "effect";
|
|
3
3
|
import { SUBCOMMANDS } from "./messages.ts";
|
|
4
|
+
import { ACCEPTS, misplaced, OPTIONS, type Values } from "./options.ts";
|
|
4
5
|
|
|
5
6
|
export type Command =
|
|
6
7
|
| { readonly _tag: "Ci"; readonly coverage: boolean }
|
|
@@ -10,7 +11,13 @@ export type Command =
|
|
|
10
11
|
| { readonly _tag: "Fix"; readonly config: string | undefined; readonly rules: readonly string[] }
|
|
11
12
|
| { readonly _tag: "BaselineMerge"; readonly base: string; readonly ours: string; readonly theirs: string }
|
|
12
13
|
| { readonly _tag: "BaselineInstallDriver" }
|
|
13
|
-
| {
|
|
14
|
+
| {
|
|
15
|
+
readonly _tag: "BaselineWrite";
|
|
16
|
+
readonly config: string | undefined;
|
|
17
|
+
readonly rules: readonly string[];
|
|
18
|
+
readonly files: readonly string[];
|
|
19
|
+
readonly firstAdoption: boolean;
|
|
20
|
+
}
|
|
14
21
|
| { readonly _tag: "BaselinePrune"; readonly config: string | undefined; readonly against: string | undefined }
|
|
15
22
|
| { readonly _tag: "BaselineTighten"; readonly config: string | undefined; readonly staged: boolean }
|
|
16
23
|
| { readonly _tag: "BaselineMigrate"; readonly config: string | undefined; readonly from: string | undefined }
|
|
@@ -22,18 +29,6 @@ export type Command =
|
|
|
22
29
|
|
|
23
30
|
export type Parsed = { readonly _tag: "Parsed"; readonly command: Command } | { readonly _tag: "Usage"; readonly problem: string };
|
|
24
31
|
|
|
25
|
-
const OPTIONS = {
|
|
26
|
-
against: { type: "string" },
|
|
27
|
-
config: { type: "string" },
|
|
28
|
-
coverage: { type: "boolean" },
|
|
29
|
-
file: { multiple: true, type: "string" },
|
|
30
|
-
force: { type: "boolean" },
|
|
31
|
-
from: { type: "string" },
|
|
32
|
-
help: { short: "h", type: "boolean" },
|
|
33
|
-
rule: { multiple: true, type: "string" },
|
|
34
|
-
staged: { type: "boolean" },
|
|
35
|
-
} as const;
|
|
36
|
-
|
|
37
32
|
function usage(problem: string): Parsed {
|
|
38
33
|
return { _tag: "Usage", problem };
|
|
39
34
|
}
|
|
@@ -42,35 +37,6 @@ function parsed(command: Command): Parsed {
|
|
|
42
37
|
return { _tag: "Parsed", command };
|
|
43
38
|
}
|
|
44
39
|
|
|
45
|
-
type Values = ReturnType<typeof parseArgs<{ options: typeof OPTIONS; allowPositionals: true }>>["values"];
|
|
46
|
-
|
|
47
|
-
type Option = Exclude<keyof Values, "config" | "help">;
|
|
48
|
-
|
|
49
|
-
const COMMAND_OPTIONS: readonly Option[] = ["against", "coverage", "file", "force", "from", "rule", "staged"];
|
|
50
|
-
|
|
51
|
-
const ACCEPTS: Readonly<Record<string, readonly Option[]>> = {
|
|
52
|
-
"baseline install-driver": [],
|
|
53
|
-
"baseline migrate": ["from"],
|
|
54
|
-
"baseline prune": ["against"],
|
|
55
|
-
"baseline tighten": ["staged"],
|
|
56
|
-
"baseline write": ["rule", "file"],
|
|
57
|
-
ci: ["coverage"],
|
|
58
|
-
"exceptions migrate": ["from"],
|
|
59
|
-
fix: ["rule"],
|
|
60
|
-
"hooks install": ["force"],
|
|
61
|
-
"hooks pre-commit": [],
|
|
62
|
-
"hooks status": [],
|
|
63
|
-
"hooks uninstall": [],
|
|
64
|
-
lint: [],
|
|
65
|
-
setup: [],
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
function misplaced(name: string, values: Values): string | undefined {
|
|
69
|
-
const option = COMMAND_OPTIONS.find((key) => values[key] !== undefined && !(ACCEPTS[name] ?? []).includes(key));
|
|
70
|
-
const owners = Object.keys(ACCEPTS).filter((owner) => option !== undefined && (ACCEPTS[owner] ?? []).includes(option));
|
|
71
|
-
return option === undefined ? undefined : `--${option} applies only to ${owners.join(" and ")}.`;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
40
|
function ref(against: string | undefined, command: Command): Parsed {
|
|
75
41
|
return against?.startsWith("-") === true ? usage(`--against takes a git ref, not "${against}".`) : parsed(command);
|
|
76
42
|
}
|
|
@@ -91,7 +57,13 @@ function commandFor(name: string, values: Values): Parsed {
|
|
|
91
57
|
case "baseline install-driver":
|
|
92
58
|
return parsed({ _tag: "BaselineInstallDriver" });
|
|
93
59
|
case "baseline write":
|
|
94
|
-
return parsed({
|
|
60
|
+
return parsed({
|
|
61
|
+
_tag: "BaselineWrite",
|
|
62
|
+
config,
|
|
63
|
+
files: values.file ?? [],
|
|
64
|
+
firstAdoption: values["first-adoption"] === true,
|
|
65
|
+
rules: values.rule ?? [],
|
|
66
|
+
});
|
|
95
67
|
case "baseline prune":
|
|
96
68
|
return ref(values.against, { _tag: "BaselinePrune", against: values.against, config });
|
|
97
69
|
case "baseline tighten":
|
package/src/cli/baseline.ts
CHANGED
|
@@ -4,6 +4,7 @@ import type { BaselineEntry } from "#baseline/format.ts";
|
|
|
4
4
|
import { saveShards } from "#baseline/shards.ts";
|
|
5
5
|
import { adopt, type Pruned, prune, type Scope } from "#baseline/update.ts";
|
|
6
6
|
import { openSession, type Session } from "#engine/session.ts";
|
|
7
|
+
import { registrable } from "#engine/violation.ts";
|
|
7
8
|
import { applyRegistry } from "#exceptions/registry.ts";
|
|
8
9
|
import { SetupFailure } from "#failure.ts";
|
|
9
10
|
import { changesSince } from "#git/history.ts";
|
|
@@ -23,16 +24,22 @@ export const writeBaseline = Effect.fn("Cli.writeBaseline")(function* (
|
|
|
23
24
|
config: string | undefined,
|
|
24
25
|
rules: readonly string[],
|
|
25
26
|
files: readonly string[],
|
|
27
|
+
firstAdoption = false,
|
|
26
28
|
): Effect.fn.Return<void, SetupFailure, RuleServices> {
|
|
27
29
|
const session = yield* openSession(cwd, config);
|
|
28
30
|
const existing = session.baseline.files.size === 0 ? undefined : session.baseline.entries;
|
|
29
|
-
if (
|
|
31
|
+
if (firstAdoption && (rules.length === 0 || rules.some((rule) => registrable(session.config, rule)))) {
|
|
32
|
+
return yield* new SetupFailure({
|
|
33
|
+
message: "baseline write refused: --first-adoption requires explicit --rule ids that refuse config exceptions.",
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
if (existing !== undefined && files.length === 0 && !firstAdoption) {
|
|
30
37
|
return yield* new SetupFailure({
|
|
31
38
|
message: "baseline write refused: a baseline exists. Record a rule with --rule <id> and --file <path>; use prune for moved or fixed debt.",
|
|
32
39
|
});
|
|
33
40
|
}
|
|
34
41
|
const selected = files.length === 0 ? undefined : new Set(files.map((file) => relative(session.config.root, resolve(session.config.root, file))));
|
|
35
|
-
if (selected !== undefined) {
|
|
42
|
+
if (selected !== undefined && !firstAdoption) {
|
|
36
43
|
const changed = yield* changesSince(session.config.root, ["HEAD"]);
|
|
37
44
|
const outside = [...selected].filter((file) => !changed.files.has(file));
|
|
38
45
|
if (outside.length > 0) {
|
package/src/cli/messages.ts
CHANGED
|
@@ -6,7 +6,7 @@ export const USAGE = `Usage:
|
|
|
6
6
|
quality exceptions migrate [--config <file>] [--from <registry>]
|
|
7
7
|
quality baseline merge <ancestor> <current> <other>
|
|
8
8
|
quality baseline install-driver
|
|
9
|
-
quality baseline write [--config <file>] [--rule <id>]... [--file <path>]...
|
|
9
|
+
quality baseline write [--config <file>] [--rule <id>]... [--file <path>]... [--first-adoption]
|
|
10
10
|
quality baseline prune [--config <file>] [--against <ref>]
|
|
11
11
|
quality baseline tighten [--config <file>] [--staged]
|
|
12
12
|
quality baseline migrate [--config <file>] [--from <file>]
|
|
@@ -25,6 +25,7 @@ exceptions migrate Move legacy registry entries and Biome declarations into qual
|
|
|
25
25
|
baseline merge Merge Git baseline versions into <current>: deletions win and counts take the minimum.
|
|
26
26
|
baseline install-driver Configure only the repository-local merge.quality-baseline.driver setting.
|
|
27
27
|
baseline write Adopt initial debt once, or record named rules only for --file paths changed since HEAD. Stage new files first.
|
|
28
|
+
--first-adoption records a shared policy upgrade for explicit rules that refuse config exceptions, including unchanged files.
|
|
28
29
|
baseline prune Drop fixed debt, lower entries to what is left and carry entries to files git saw move. Never adds or raises an entry.
|
|
29
30
|
baseline tighten Prune only the entries of files changed since HEAD, or with --staged, in the index.
|
|
30
31
|
baseline migrate Move a JSON or JSON Lines baseline (--from, quality/baseline.json by default) into root and package shards.
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { parseArgs } from "node:util";
|
|
2
|
+
|
|
3
|
+
export const OPTIONS = {
|
|
4
|
+
against: { type: "string" },
|
|
5
|
+
config: { type: "string" },
|
|
6
|
+
coverage: { type: "boolean" },
|
|
7
|
+
file: { multiple: true, type: "string" },
|
|
8
|
+
"first-adoption": { type: "boolean" },
|
|
9
|
+
force: { type: "boolean" },
|
|
10
|
+
from: { type: "string" },
|
|
11
|
+
help: { short: "h", type: "boolean" },
|
|
12
|
+
rule: { multiple: true, type: "string" },
|
|
13
|
+
staged: { type: "boolean" },
|
|
14
|
+
} as const;
|
|
15
|
+
|
|
16
|
+
export type Values = ReturnType<typeof parseArgs<{ options: typeof OPTIONS; allowPositionals: true }>>["values"];
|
|
17
|
+
|
|
18
|
+
type Option = Exclude<keyof Values, "config" | "help">;
|
|
19
|
+
|
|
20
|
+
const COMMAND_OPTIONS: readonly Option[] = ["against", "coverage", "file", "first-adoption", "force", "from", "rule", "staged"];
|
|
21
|
+
|
|
22
|
+
export const ACCEPTS: Readonly<Record<string, readonly Option[]>> = {
|
|
23
|
+
"baseline install-driver": [],
|
|
24
|
+
"baseline migrate": ["from"],
|
|
25
|
+
"baseline prune": ["against"],
|
|
26
|
+
"baseline tighten": ["staged"],
|
|
27
|
+
"baseline write": ["rule", "file", "first-adoption"],
|
|
28
|
+
ci: ["coverage"],
|
|
29
|
+
"exceptions migrate": ["from"],
|
|
30
|
+
fix: ["rule"],
|
|
31
|
+
"hooks install": ["force"],
|
|
32
|
+
"hooks pre-commit": [],
|
|
33
|
+
"hooks status": [],
|
|
34
|
+
"hooks uninstall": [],
|
|
35
|
+
lint: [],
|
|
36
|
+
setup: [],
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
export function misplaced(name: string, values: Values): string | undefined {
|
|
40
|
+
const option = COMMAND_OPTIONS.find((key) => values[key] !== undefined && !(ACCEPTS[name] ?? []).includes(key));
|
|
41
|
+
const owners = Object.keys(ACCEPTS).filter((owner) => option !== undefined && (ACCEPTS[owner] ?? []).includes(option));
|
|
42
|
+
return option === undefined ? undefined : `--${option} applies only to ${owners.join(" and ")}.`;
|
|
43
|
+
}
|
package/src/cli/program.ts
CHANGED
|
@@ -46,7 +46,7 @@ export const program = Effect.fn("Cli.program")(function* (args: readonly string
|
|
|
46
46
|
case "BaselineInstallDriver":
|
|
47
47
|
return yield* installDriver(cwd, launch);
|
|
48
48
|
case "BaselineWrite":
|
|
49
|
-
return yield* writeBaseline(cwd, command.config, command.rules, command.files);
|
|
49
|
+
return yield* writeBaseline(cwd, command.config, command.rules, command.files, command.firstAdoption);
|
|
50
50
|
case "BaselinePrune":
|
|
51
51
|
return yield* pruneBaseline(cwd, command.config, command.against);
|
|
52
52
|
case "BaselineTighten":
|
package/src/config/resolve.ts
CHANGED
|
@@ -39,18 +39,16 @@ function activeRule(rule: Rule, check: ActiveRule["check"]): ActiveRule {
|
|
|
39
39
|
|
|
40
40
|
function activate(rule: Rule, setting: Setting | undefined): Effect.Effect<Decoded<ActiveRule>> {
|
|
41
41
|
return Effect.tryPromise({ catch: messageOf, try: () => rule.configure(optionsOf(setting)) }).pipe(
|
|
42
|
-
Effect.
|
|
43
|
-
(
|
|
42
|
+
Effect.match({
|
|
43
|
+
onFailure: (failure): Decoded<ActiveRule> => ({ _tag: "Invalid", issues: [`rules.${rule.id}.options: validation threw: ${failure}`] }),
|
|
44
|
+
onSuccess: (configured): Decoded<ActiveRule> =>
|
|
44
45
|
configured._tag === "Invalid"
|
|
45
46
|
? { _tag: "Invalid", issues: configured.issues.map((issue) => `rules.${rule.id}.options: ${issue}`) }
|
|
46
47
|
: {
|
|
47
48
|
_tag: "Valid",
|
|
48
49
|
value: activeRule(rule, configured.check),
|
|
49
50
|
},
|
|
50
|
-
),
|
|
51
|
-
Effect.catch((failure: string) =>
|
|
52
|
-
Effect.succeed<Decoded<ActiveRule>>({ _tag: "Invalid", issues: [`rules.${rule.id}.options: validation threw: ${failure}`] }),
|
|
53
|
-
),
|
|
51
|
+
}),
|
|
54
52
|
);
|
|
55
53
|
}
|
|
56
54
|
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { posix } from "node:path";
|
|
2
|
+
import { moduleRoot } from "#naming/moduleRoot.ts";
|
|
2
3
|
import { isTooling } from "./isTooling.ts";
|
|
3
4
|
import type { DeclaredRuntime, Runtime } from "./runtime.ts";
|
|
4
5
|
import { packageOf, type WorkspacePackage } from "./workspace.ts";
|
|
@@ -22,7 +23,9 @@ export function classifyRuntime(policy: RuntimePolicy, path: string): Runtime |
|
|
|
22
23
|
if (!policy.adopted.has(owner)) {
|
|
23
24
|
return policy.executable.has(owner) ? "server" : undefined;
|
|
24
25
|
}
|
|
25
|
-
const
|
|
26
|
+
const source = posix.relative(owner, path);
|
|
27
|
+
const module = moduleRoot(source);
|
|
28
|
+
const local = module === undefined ? source : `src/${posix.relative(module, source)}`;
|
|
26
29
|
if (local.startsWith("src/client/")) {
|
|
27
30
|
return "client";
|
|
28
31
|
}
|