@shivaedev/quality 0.57.1 → 0.59.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 +34 -0
- package/README.md +19 -6
- package/dist/adapters/ImportAnalysisFailure.d.ts +10 -0
- package/dist/adapters/ImportAnalysisFailure.d.ts.map +1 -0
- package/dist/adapters/ImportAnalysisFailure.js +4 -0
- package/dist/adapters/ImportAnalysisFailure.js.map +1 -0
- package/dist/adapters/ImportCompiler.d.ts +2 -13
- package/dist/adapters/ImportCompiler.d.ts.map +1 -1
- package/dist/adapters/ImportCompiler.js +7 -13
- package/dist/adapters/ImportCompiler.js.map +1 -1
- package/dist/adapters/bodyReferences.d.ts +10 -0
- package/dist/adapters/bodyReferences.d.ts.map +1 -0
- package/dist/adapters/bodyReferences.js +125 -0
- package/dist/adapters/bodyReferences.js.map +1 -0
- package/dist/adapters/engineEscapes.d.ts +10 -0
- package/dist/adapters/engineEscapes.d.ts.map +1 -0
- package/dist/adapters/engineEscapes.js +103 -0
- package/dist/adapters/engineEscapes.js.map +1 -0
- package/dist/adapters/imports/analysisFailure.d.ts +3 -0
- package/dist/adapters/imports/analysisFailure.d.ts.map +1 -0
- package/dist/adapters/imports/analysisFailure.js +5 -0
- package/dist/adapters/imports/analysisFailure.js.map +1 -0
- package/dist/adapters/imports/analyzeDepartures.d.ts +5 -0
- package/dist/adapters/imports/analyzeDepartures.d.ts.map +1 -0
- package/dist/adapters/imports/analyzeDepartures.js +5 -0
- package/dist/adapters/imports/analyzeDepartures.js.map +1 -0
- package/dist/adapters/imports/analyzeGraph.d.ts +4 -0
- package/dist/adapters/imports/analyzeGraph.d.ts.map +1 -0
- package/dist/adapters/imports/analyzeGraph.js +6 -0
- package/dist/adapters/imports/analyzeGraph.js.map +1 -0
- package/dist/adapters/imports/checkBrowser.d.ts +4 -0
- package/dist/adapters/imports/checkBrowser.d.ts.map +1 -0
- package/dist/adapters/imports/checkBrowser.js +4 -0
- package/dist/adapters/imports/checkBrowser.js.map +1 -0
- package/dist/adapters/indirectServiceReferences.d.ts +3 -0
- package/dist/adapters/indirectServiceReferences.d.ts.map +1 -0
- package/dist/adapters/indirectServiceReferences.js +19 -0
- package/dist/adapters/indirectServiceReferences.js.map +1 -0
- package/dist/adapters/knip/entryPointFindings.d.ts +1 -1
- package/dist/adapters/knip/entryPointFindings.d.ts.map +1 -1
- package/dist/adapters/nativeTransactionFindings.d.ts +4 -0
- package/dist/adapters/nativeTransactionFindings.d.ts.map +1 -0
- package/dist/adapters/nativeTransactionFindings.js +98 -0
- package/dist/adapters/nativeTransactionFindings.js.map +1 -0
- package/dist/adapters/outcomeAssertions.d.ts +9 -0
- package/dist/adapters/outcomeAssertions.d.ts.map +1 -0
- package/dist/adapters/outcomeAssertions.js +94 -0
- package/dist/adapters/outcomeAssertions.js.map +1 -0
- package/dist/adapters/outsideImportFindings.d.ts +1 -1
- package/dist/adapters/outsideImportFindings.d.ts.map +1 -1
- package/dist/adapters/positiveRefusalFindings.d.ts +4 -0
- package/dist/adapters/positiveRefusalFindings.d.ts.map +1 -0
- package/dist/adapters/positiveRefusalFindings.js +41 -0
- package/dist/adapters/positiveRefusalFindings.js.map +1 -0
- package/dist/adapters/queueReadoutFindings.d.ts +1 -1
- package/dist/adapters/queueReadoutFindings.d.ts.map +1 -1
- package/dist/adapters/rpcBoundaryFindings.d.ts +4 -0
- package/dist/adapters/rpcBoundaryFindings.d.ts.map +1 -0
- package/dist/adapters/rpcBoundaryFindings.js +90 -0
- package/dist/adapters/rpcBoundaryFindings.js.map +1 -0
- package/dist/adapters/serviceAccess.d.ts +4 -0
- package/dist/adapters/serviceAccess.d.ts.map +1 -0
- package/dist/adapters/serviceAccess.js +33 -0
- package/dist/adapters/serviceAccess.js.map +1 -0
- package/dist/adapters/serviceAssemblyImports.d.ts +10 -0
- package/dist/adapters/serviceAssemblyImports.d.ts.map +1 -0
- package/dist/adapters/serviceAssemblyImports.js +71 -0
- package/dist/adapters/serviceAssemblyImports.js.map +1 -0
- package/dist/adapters/serviceAssemblySyntax.d.ts +10 -0
- package/dist/adapters/serviceAssemblySyntax.d.ts.map +1 -0
- package/dist/adapters/serviceAssemblySyntax.js +105 -0
- package/dist/adapters/serviceAssemblySyntax.js.map +1 -0
- package/dist/adapters/serviceDefinitionProblems.d.ts +7 -0
- package/dist/adapters/serviceDefinitionProblems.d.ts.map +1 -0
- package/dist/adapters/serviceDefinitionProblems.js +43 -0
- package/dist/adapters/serviceDefinitionProblems.js.map +1 -0
- package/dist/adapters/serviceIdFindings.d.ts.map +1 -1
- package/dist/adapters/serviceIdFindings.js +12 -7
- package/dist/adapters/serviceIdFindings.js.map +1 -1
- package/dist/adapters/transactionChanges.d.ts +3 -0
- package/dist/adapters/transactionChanges.d.ts.map +1 -0
- package/dist/adapters/transactionChanges.js +81 -0
- package/dist/adapters/transactionChanges.js.map +1 -0
- package/dist/adapters/vitePort.d.ts +2 -0
- package/dist/adapters/vitePort.d.ts.map +1 -0
- package/dist/adapters/vitePort.js +5 -0
- package/dist/adapters/vitePort.js.map +1 -0
- package/dist/appViteConfig.d.ts +4 -1
- package/dist/appViteConfig.d.ts.map +1 -1
- package/dist/appViteConfig.js +7 -3
- package/dist/appViteConfig.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/graph.d.ts +1 -1
- package/dist/imports/graph.d.ts.map +1 -1
- package/dist/rules/builtIn.d.ts +2 -2
- package/dist/rules/builtIn.d.ts.map +1 -1
- package/dist/rules/builtIn.js +8 -0
- package/dist/rules/builtIn.js.map +1 -1
- package/dist/rules/effect/rpcBoundary.d.ts +2 -0
- package/dist/rules/effect/rpcBoundary.d.ts.map +1 -0
- package/dist/rules/effect/rpcBoundary.js +9 -0
- package/dist/rules/effect/rpcBoundary.js.map +1 -0
- package/dist/rules/effect/serviceCatalog.d.ts +1 -1
- package/dist/rules/effect/serviceCatalog.d.ts.map +1 -1
- package/dist/rules/effect/serviceCatalog.js +4 -2
- package/dist/rules/effect/serviceCatalog.js.map +1 -1
- package/dist/rules/effect/serviceDefinitionAssembly.d.ts +2 -0
- package/dist/rules/effect/serviceDefinitionAssembly.d.ts.map +1 -0
- package/dist/rules/effect/serviceDefinitionAssembly.js +43 -0
- package/dist/rules/effect/serviceDefinitionAssembly.js.map +1 -0
- package/dist/rules/effect/serviceIds.js +1 -1
- package/dist/rules/effect/serviceIds.js.map +1 -1
- package/dist/rules/effect/serviceParameters.d.ts.map +1 -1
- package/dist/rules/effect/serviceParameters.js +12 -6
- package/dist/rules/effect/serviceParameters.js.map +1 -1
- package/dist/rules/effect/sqlTransact.d.ts +2 -0
- package/dist/rules/effect/sqlTransact.d.ts.map +1 -0
- package/dist/rules/effect/sqlTransact.js +9 -0
- package/dist/rules/effect/sqlTransact.js.map +1 -0
- package/dist/rules/stories/engine.d.ts.map +1 -1
- package/dist/rules/stories/engine.js +24 -7
- package/dist/rules/stories/engine.js.map +1 -1
- package/dist/rules/stories/positiveRefusals.d.ts +2 -0
- package/dist/rules/stories/positiveRefusals.d.ts.map +1 -0
- package/dist/rules/stories/positiveRefusals.js +17 -0
- package/dist/rules/stories/positiveRefusals.js.map +1 -0
- package/dist/rules/stories/sources.d.ts +1 -1
- package/dist/rules/stories/sources.d.ts.map +1 -1
- package/dist/rules/stories/usesInputs.d.ts.map +1 -1
- package/dist/rules/stories/usesInputs.js +3 -2
- package/dist/rules/stories/usesInputs.js.map +1 -1
- package/dist/testing/adapters/cli.d.ts +2 -2
- package/dist/testing/adapters/cli.d.ts.map +1 -1
- package/dist/testing/adapters/cli.js +11 -14
- package/dist/testing/adapters/cli.js.map +1 -1
- package/dist/testing/adapters/git.d.ts +10 -0
- package/dist/testing/adapters/git.d.ts.map +1 -1
- package/dist/testing/adapters/git.js +6 -2
- package/dist/testing/adapters/git.js.map +1 -1
- package/dist/testing/adapters/hookRepository.d.ts.map +1 -1
- package/dist/testing/adapters/hookRepository.js +6 -2
- package/dist/testing/adapters/hookRepository.js.map +1 -1
- package/dist/testing/ruleStory.d.ts.map +1 -1
- package/dist/testing/ruleStory.js +1 -2
- package/dist/testing/ruleStory.js.map +1 -1
- package/package.json +6 -6
- package/src/adapters/ImportAnalysisFailure.ts +6 -0
- package/src/adapters/ImportCompiler.ts +7 -20
- package/src/adapters/bodyReferences.ts +141 -0
- package/src/adapters/engineEscapes.ts +119 -0
- package/src/adapters/imports/analysisFailure.ts +5 -0
- package/src/adapters/imports/analyzeDepartures.ts +9 -0
- package/src/adapters/imports/analyzeGraph.ts +9 -0
- package/src/adapters/imports/checkBrowser.ts +5 -0
- package/src/adapters/indirectServiceReferences.ts +25 -0
- package/src/adapters/nativeTransactionFindings.ts +108 -0
- package/src/adapters/outcomeAssertions.ts +110 -0
- package/src/adapters/outsideImportFindings.ts +1 -1
- package/src/adapters/positiveRefusalFindings.ts +52 -0
- package/src/adapters/rpcBoundaryFindings.ts +98 -0
- package/src/adapters/serviceAccess.ts +38 -0
- package/src/adapters/serviceAssemblyImports.ts +93 -0
- package/src/adapters/serviceAssemblySyntax.ts +129 -0
- package/src/adapters/serviceDefinitionProblems.ts +63 -0
- package/src/adapters/serviceIdFindings.ts +16 -13
- package/src/adapters/transactionChanges.ts +85 -0
- package/src/adapters/vitePort.ts +5 -0
- package/src/appViteConfig.ts +13 -3
- package/src/rules/builtIn.ts +8 -0
- package/src/rules/effect/rpcBoundary.ts +10 -0
- package/src/rules/effect/serviceCatalog.ts +4 -2
- package/src/rules/effect/serviceDefinitionAssembly.ts +46 -0
- package/src/rules/effect/serviceIds.ts +1 -1
- package/src/rules/effect/serviceParameters.ts +12 -6
- package/src/rules/effect/sqlTransact.ts +10 -0
- package/src/rules/stories/engine.ts +25 -9
- package/src/rules/stories/positiveRefusals.ts +17 -0
- package/src/rules/stories/usesInputs.ts +3 -2
- package/src/testing/adapters/cli.ts +22 -14
- package/src/testing/adapters/git.ts +7 -2
- package/src/testing/adapters/hookRepository.ts +6 -2
- package/src/testing/ruleStory.ts +1 -2
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
import { memberName, unwrapped } from "#rules/stories/syntax.ts";
|
|
3
|
+
|
|
4
|
+
const WRITES = new Set([
|
|
5
|
+
"insert",
|
|
6
|
+
"insertVoid",
|
|
7
|
+
"insertOrIgnore",
|
|
8
|
+
"insertMany",
|
|
9
|
+
"insertManyOrIgnore",
|
|
10
|
+
"insertFromSelect",
|
|
11
|
+
"insertFromSelectOrIgnore",
|
|
12
|
+
"update",
|
|
13
|
+
"updateVoid",
|
|
14
|
+
"upsert",
|
|
15
|
+
"upsertMany",
|
|
16
|
+
"delete",
|
|
17
|
+
"deleteBatched",
|
|
18
|
+
]);
|
|
19
|
+
|
|
20
|
+
function sqlModule(path: string): boolean {
|
|
21
|
+
return /\/(?:@shivaedev\/)?sql\/(?:src|dist)\//u.test(path.replaceAll("\\", "/"));
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function transactionChanges(checker: ts.TypeChecker, body: ts.Expression): boolean {
|
|
25
|
+
const seen = new Set<ts.Node>();
|
|
26
|
+
function repositoryWrite(expression: ts.Expression, name: string | undefined): boolean {
|
|
27
|
+
if (!WRITES.has(name ?? "")) {
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
const purge = checker.getTypeAtLocation(expression).getProperty("deleteBatched");
|
|
31
|
+
return purge?.declarations?.some((declaration) => sqlModule(declaration.getSourceFile().fileName)) ?? false;
|
|
32
|
+
}
|
|
33
|
+
function bindingWrite(declaration: ts.BindingElement): boolean {
|
|
34
|
+
if (!ts.isVariableDeclaration(declaration.parent.parent)) {
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
const value = declaration.parent.parent.initializer;
|
|
38
|
+
const property = declaration.propertyName ?? declaration.name;
|
|
39
|
+
return value !== undefined && repositoryWrite(value, ts.isIdentifier(property) ? property.text : undefined);
|
|
40
|
+
}
|
|
41
|
+
function declarationChanges(declaration: ts.Declaration, name: string): boolean {
|
|
42
|
+
const source = declaration.getSourceFile();
|
|
43
|
+
if (sqlModule(source.fileName)) {
|
|
44
|
+
return ["transact", "invalidateOnCommit"].includes(name) && /\/transact\.(?:d\.)?ts$/u.test(source.fileName);
|
|
45
|
+
}
|
|
46
|
+
if (source.isDeclarationFile || source.fileName.includes("/node_modules/")) {
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
if (ts.isVariableDeclaration(declaration)) {
|
|
50
|
+
return declaration.initializer !== undefined && visit(declaration.initializer);
|
|
51
|
+
}
|
|
52
|
+
if (ts.isFunctionDeclaration(declaration)) {
|
|
53
|
+
return declaration.body !== undefined && visit(declaration.body);
|
|
54
|
+
}
|
|
55
|
+
if (ts.isBindingElement(declaration)) {
|
|
56
|
+
return bindingWrite(declaration);
|
|
57
|
+
}
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
60
|
+
function reference(node: ts.Identifier): boolean {
|
|
61
|
+
const symbol = checker.getSymbolAtLocation(node);
|
|
62
|
+
if (symbol === undefined) {
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
const target = symbol.flags & ts.SymbolFlags.Alias ? checker.getAliasedSymbol(symbol) : symbol;
|
|
66
|
+
return target.declarations?.some((declaration) => declarationChanges(declaration, target.name)) ?? false;
|
|
67
|
+
}
|
|
68
|
+
function visit(node: ts.Node): boolean {
|
|
69
|
+
if (seen.has(node) || ts.isTypeNode(node)) {
|
|
70
|
+
return false;
|
|
71
|
+
}
|
|
72
|
+
seen.add(node);
|
|
73
|
+
if (ts.isIdentifier(node) && reference(node)) {
|
|
74
|
+
return true;
|
|
75
|
+
}
|
|
76
|
+
if (
|
|
77
|
+
(ts.isPropertyAccessExpression(node) || ts.isElementAccessExpression(node))
|
|
78
|
+
&& repositoryWrite(unwrapped(node.expression), memberName(node))
|
|
79
|
+
) {
|
|
80
|
+
return true;
|
|
81
|
+
}
|
|
82
|
+
return ts.forEachChild(node, (child) => visit(child) || undefined) ?? false;
|
|
83
|
+
}
|
|
84
|
+
return visit(body);
|
|
85
|
+
}
|
package/src/appViteConfig.ts
CHANGED
|
@@ -1,12 +1,22 @@
|
|
|
1
|
-
|
|
1
|
+
import { vitePort } from "#adapters/vitePort.ts";
|
|
2
|
+
|
|
3
|
+
export function appViteConfig<TPlugin>(
|
|
4
|
+
plugins: TPlugin[],
|
|
5
|
+
conditions: string[] = [],
|
|
6
|
+
proxyPaths: string[] = [],
|
|
7
|
+
{ webPort = vitePort("VITE_PORT", 5173), apiPort = vitePort("PORT", 3000) }: { webPort?: number; apiPort?: number } = {},
|
|
8
|
+
) {
|
|
2
9
|
return {
|
|
3
10
|
plugins,
|
|
4
11
|
resolve: { conditions, tsconfigPaths: true },
|
|
5
12
|
server: {
|
|
6
13
|
host: "127.0.0.1",
|
|
7
|
-
port:
|
|
14
|
+
port: webPort,
|
|
8
15
|
proxy: Object.fromEntries(
|
|
9
|
-
["/api/auth", "/rpc", ...proxyPaths].map((path) => [
|
|
16
|
+
["/api/auth", "/rpc", ...proxyPaths].map((path) => [
|
|
17
|
+
path,
|
|
18
|
+
{ changeOrigin: false, target: `http://127.0.0.1:${apiPort}`, ws: path === "/rpc" },
|
|
19
|
+
]),
|
|
10
20
|
),
|
|
11
21
|
strictPort: true,
|
|
12
22
|
},
|
package/src/rules/builtIn.ts
CHANGED
|
@@ -10,9 +10,12 @@ import { docsUnversionedInstalls } from "#rules/docs/unversionedInstalls.ts";
|
|
|
10
10
|
import { adapterImports } from "#rules/effect/adapterImports.ts";
|
|
11
11
|
import { effectBoundary } from "#rules/effect/boundary.ts";
|
|
12
12
|
import { failureHonesty } from "#rules/effect/failureHonesty.ts";
|
|
13
|
+
import { rpcBoundary } from "#rules/effect/rpcBoundary.ts";
|
|
14
|
+
import { serviceDefinitionAssembly } from "#rules/effect/serviceDefinitionAssembly.ts";
|
|
13
15
|
import { serviceIds } from "#rules/effect/serviceIds.ts";
|
|
14
16
|
import { serviceParameters } from "#rules/effect/serviceParameters.ts";
|
|
15
17
|
import { sharedErrorClasses } from "#rules/effect/sharedErrorClasses.ts";
|
|
18
|
+
import { sqlTransact } from "#rules/effect/sqlTransact.ts";
|
|
16
19
|
import { distinctCase } from "#rules/files/distinctCase.ts";
|
|
17
20
|
import { folderNames } from "#rules/files/folderNames.ts";
|
|
18
21
|
import { namedAfterExport } from "#rules/files/namedAfterExport.ts";
|
|
@@ -37,6 +40,7 @@ import { importedChangeKeys } from "#rules/stories/importedChangeKeys.ts";
|
|
|
37
40
|
import { namedValues } from "#rules/stories/namedValues.ts";
|
|
38
41
|
import { noExpect } from "#rules/stories/noExpect.ts";
|
|
39
42
|
import { noLimitImports } from "#rules/stories/noLimitImports.ts";
|
|
43
|
+
import { positiveRefusals } from "#rules/stories/positiveRefusals.ts";
|
|
40
44
|
import { queueReadouts } from "#rules/stories/queueReadouts.ts";
|
|
41
45
|
import { queueSql } from "#rules/stories/queueSql.ts";
|
|
42
46
|
import { storySetup } from "#rules/stories/setup.ts";
|
|
@@ -66,9 +70,12 @@ export const builtInRules = [
|
|
|
66
70
|
adapterImports,
|
|
67
71
|
effectBoundary,
|
|
68
72
|
failureHonesty,
|
|
73
|
+
rpcBoundary,
|
|
74
|
+
serviceDefinitionAssembly,
|
|
69
75
|
serviceIds,
|
|
70
76
|
serviceParameters,
|
|
71
77
|
sharedErrorClasses,
|
|
78
|
+
sqlTransact,
|
|
72
79
|
jsxConditionals,
|
|
73
80
|
maxLines,
|
|
74
81
|
maxDepth,
|
|
@@ -122,6 +129,7 @@ export const builtInRules = [
|
|
|
122
129
|
namedValues,
|
|
123
130
|
noLimitImports,
|
|
124
131
|
domainOutcomes,
|
|
132
|
+
positiveRefusals,
|
|
125
133
|
groupedOutcomes,
|
|
126
134
|
waitOnEvents,
|
|
127
135
|
] as const;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { rpcBoundaryFindings } from "#adapters/rpcBoundaryFindings.ts";
|
|
2
|
+
import { defineRule } from "#rule.ts";
|
|
3
|
+
|
|
4
|
+
export const rpcBoundary = defineRule({
|
|
5
|
+
check: rpcBoundaryFindings,
|
|
6
|
+
description:
|
|
7
|
+
"Apply rpcBoundary and rpcBoundaryHandlers only in modules building native RPC handlers; services keep their typed failures. Test-support kits and the handler boundary implementation are accepted. No config exceptions or inline suppressions; baseline existing debt.",
|
|
8
|
+
id: "effect/rpc-boundary",
|
|
9
|
+
registrable: false,
|
|
10
|
+
});
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import ts from "typescript";
|
|
2
|
+
import servicePackage from "@shivaedev/service/package.json" with { type: "json" };
|
|
2
3
|
import { serviceOrigin } from "#rules/effect/serviceOrigin.ts";
|
|
3
4
|
import { serviceTypes } from "#rules/effect/serviceTypes.ts";
|
|
4
5
|
|
|
5
|
-
export function serviceCatalog(program: ts.Program, checker: ts.TypeChecker) {
|
|
6
|
+
export function serviceCatalog(program: ts.Program, checker: ts.TypeChecker, packages: readonly string[] = []) {
|
|
7
|
+
const prefixes = [servicePackage.name, ...packages].map((name) => `${name.startsWith("@") ? name.split("/")[0] : name}/`);
|
|
6
8
|
const services = serviceTypes(checker);
|
|
7
9
|
function imported(node: ts.ImportSpecifier | ts.NamespaceImport): void {
|
|
8
10
|
const symbol = checker.getSymbolAtLocation(node.name);
|
|
@@ -49,7 +51,7 @@ export function serviceCatalog(program: ts.Program, checker: ts.TypeChecker) {
|
|
|
49
51
|
ts.forEachChild(node, discover);
|
|
50
52
|
}
|
|
51
53
|
for (const source of program.getSourceFiles()) {
|
|
52
|
-
if (!source.fileName.includes("/node_modules/") || source.fileName.includes(
|
|
54
|
+
if (!source.fileName.includes("/node_modules/") || prefixes.some((prefix) => source.fileName.includes(`/${prefix}`))) {
|
|
53
55
|
discover(source);
|
|
54
56
|
}
|
|
55
57
|
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type ts from "typescript";
|
|
2
|
+
import { indirectServiceReferences } from "#adapters/indirectServiceReferences.ts";
|
|
3
|
+
import { serviceAssemblyImports } from "#adapters/serviceAssemblyImports.ts";
|
|
4
|
+
import { directServiceDefinitions, implementationBodies } from "#adapters/serviceAssemblySyntax.ts";
|
|
5
|
+
import { serviceDefinitionProblems } from "#adapters/serviceDefinitionProblems.ts";
|
|
6
|
+
import { defineRule, type Finding, type SourceFile } from "#rule.ts";
|
|
7
|
+
import { parse } from "#rules/parse.ts";
|
|
8
|
+
|
|
9
|
+
function fileFindings(file: SourceFile): readonly Finding[] {
|
|
10
|
+
const source = parse(file);
|
|
11
|
+
if (source === undefined) {
|
|
12
|
+
return [];
|
|
13
|
+
}
|
|
14
|
+
const imports = serviceAssemblyImports(source);
|
|
15
|
+
if (imports.definitions.size === 0 && imports.unsupported.length === 0) {
|
|
16
|
+
return [];
|
|
17
|
+
}
|
|
18
|
+
const definitions = directServiceDefinitions(source, imports.definitions);
|
|
19
|
+
const found = imports.unsupported.map((node) => ({ message: "Import and call defineService directly.", node }));
|
|
20
|
+
for (const node of indirectServiceReferences(source, imports.definitions, definitions)) {
|
|
21
|
+
found.push({ message: "Call the imported defineService directly in a top-level service declaration.", node });
|
|
22
|
+
}
|
|
23
|
+
if (imports.definitions.size > 0 && definitions.length === 0) {
|
|
24
|
+
found.push({ message: "Call the imported defineService directly in a top-level service declaration.", node: source });
|
|
25
|
+
}
|
|
26
|
+
const allowedBodies = new Set<ts.Node>();
|
|
27
|
+
for (const definition of definitions) {
|
|
28
|
+
found.push(...serviceDefinitionProblems(definition, imports.effects, imports.values, allowedBodies, imports.generics));
|
|
29
|
+
}
|
|
30
|
+
for (const node of implementationBodies(source, allowedBodies)) {
|
|
31
|
+
found.push({ message: "Move this implementation body to a named export in its own focused file.", node });
|
|
32
|
+
}
|
|
33
|
+
return found.map(({ node, message }) => ({
|
|
34
|
+
file: file.path,
|
|
35
|
+
line: source.getLineAndCharacterOfPosition(node.getStart(source)).line + 1,
|
|
36
|
+
message,
|
|
37
|
+
}));
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export const serviceDefinitionAssembly = defineRule({
|
|
41
|
+
check: ({ sources }) => sources.flatMap(fileFindings),
|
|
42
|
+
description:
|
|
43
|
+
"Keep defineService declarations as top-level operation inventories: list id, requires, initialize and methods directly. Import a named initializer (or use Effect.void) and named operations or state factories from focused files; genericMethod may wrap those references. Move implementation bodies out of the assembly file. Effect.fn span names follow the existing Biome checks. Includes adapters and tests; no config exceptions or inline suppressions.",
|
|
44
|
+
id: "effect/service-definition-assembly",
|
|
45
|
+
registrable: false,
|
|
46
|
+
});
|
|
@@ -4,7 +4,7 @@ import { defineRule } from "#rule.ts";
|
|
|
4
4
|
export const serviceIds = defineRule({
|
|
5
5
|
check: serviceIdFindings,
|
|
6
6
|
description:
|
|
7
|
-
"Literal Context.Service, Context.Reference, defineService and RPC middleware ids in packages
|
|
7
|
+
"Literal Context.Service, Context.Reference, defineService and RPC middleware ids in workspace packages under packages/ start with the owning manifest's name and a slash. Prefix the id and update its references. Includes adapters and tests; computed ids, files without a named workspace owner and files outside packages/ are not checked. No config exceptions or inline suppressions.",
|
|
8
8
|
id: "effect/service-ids",
|
|
9
9
|
registrable: false,
|
|
10
10
|
});
|
|
@@ -1,35 +1,41 @@
|
|
|
1
1
|
import { join } from "node:path";
|
|
2
|
+
import { Effect } from "effect";
|
|
3
|
+
import { readPackageManifest } from "#adapters/manifestInventory.ts";
|
|
4
|
+
import { packageOf, workspacePackages } from "#imports/workspace.ts";
|
|
2
5
|
import { defineRule, type Finding, type RuleInputs } from "#rule.ts";
|
|
3
6
|
import { effectProgram } from "#rules/effect/program.ts";
|
|
4
7
|
import { serviceCatalog } from "#rules/effect/serviceCatalog.ts";
|
|
5
8
|
import { serviceFindings } from "#rules/effect/serviceFindings.ts";
|
|
6
9
|
|
|
7
10
|
export const serviceParameters = defineRule({
|
|
8
|
-
check: (inputs)
|
|
11
|
+
check: Effect.fn("Services.check")(function* (inputs: RuleInputs) {
|
|
12
|
+
const packages = yield* Effect.promise(() => workspacePackages(inputs));
|
|
13
|
+
const root = yield* Effect.promise(() => readPackageManifest(inputs.readText, "package.json"));
|
|
14
|
+
const names = [...packages.map((owner) => owner.name), ...(root?.name === undefined ? [] : [root.name])];
|
|
9
15
|
const groups = new Map<string, RuleInputs["sources"][number][]>();
|
|
10
16
|
for (const source of inputs.sources) {
|
|
11
17
|
if (/(?:^|\/)test-support\//u.test(source.path)) {
|
|
12
18
|
continue;
|
|
13
19
|
}
|
|
14
|
-
const group =
|
|
20
|
+
const group = packageOf(packages, source.path)?.directory ?? ".";
|
|
15
21
|
const files = groups.get(group) ?? [];
|
|
16
22
|
files.push(source);
|
|
17
23
|
groups.set(group, files);
|
|
18
24
|
}
|
|
19
|
-
return [...groups.values()].flatMap((sources) => checkServices({ ...inputs, sources }));
|
|
20
|
-
},
|
|
25
|
+
return [...groups.values()].flatMap((sources) => checkServices({ ...inputs, sources }, names));
|
|
26
|
+
}),
|
|
21
27
|
description:
|
|
22
28
|
"Exported functions and public methods take services from Effect's environment, including aliases, constraints, inferred/destructured parameters and factory returns. Service keys/classes, non-empty Contexts and implementation shapes are services; Effect/Stream requirements are computations. Service implementation methods and Layer constructors are accepted. Only test-support/ folders are exempt. The fixed adapters/ convention bridges outside libraries to Effect values; adapters still follow this rule and ambient runtime bans. No config exceptions or inline suppressions; baseline existing debt.",
|
|
23
29
|
id: "effect/service-parameters",
|
|
24
30
|
registrable: false,
|
|
25
31
|
});
|
|
26
32
|
|
|
27
|
-
function checkServices(inputs: RuleInputs): readonly Finding[] {
|
|
33
|
+
function checkServices(inputs: RuleInputs, packages: readonly string[]): readonly Finding[] {
|
|
28
34
|
const program = effectProgram(inputs);
|
|
29
35
|
const checker = program.getTypeChecker();
|
|
30
36
|
const sources = inputs.sources.flatMap((file) => {
|
|
31
37
|
const source = program.getSourceFile(join(inputs.root, file.path));
|
|
32
38
|
return source === undefined ? [] : [source];
|
|
33
39
|
});
|
|
34
|
-
return serviceFindings(inputs.root, sources, checker, serviceCatalog(program, checker));
|
|
40
|
+
return serviceFindings(inputs.root, sources, checker, serviceCatalog(program, checker, packages));
|
|
35
41
|
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { nativeTransactionFindings } from "#adapters/nativeTransactionFindings.ts";
|
|
2
|
+
import { defineRule } from "#rule.ts";
|
|
3
|
+
|
|
4
|
+
export const sqlTransact = defineRule({
|
|
5
|
+
check: nativeTransactionFindings,
|
|
6
|
+
description:
|
|
7
|
+
"Repository writes and change announcements use transact for their outer transaction instead of native sql.withTransaction. Native transactions containing only reads or raw SQL remain supported.",
|
|
8
|
+
id: "effect/sql-transact",
|
|
9
|
+
registrable: false,
|
|
10
|
+
});
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Effect } from "effect";
|
|
2
2
|
import ts from "typescript";
|
|
3
|
+
import { engineEscapes } from "#adapters/engineEscapes.ts";
|
|
3
4
|
import { importGraph } from "#imports/graph.ts";
|
|
4
5
|
import { packageOf } from "#imports/workspace.ts";
|
|
5
6
|
import { testName } from "#naming/testName.ts";
|
|
@@ -40,18 +41,33 @@ export const storyEngine = defineRule({
|
|
|
40
41
|
if (source === undefined) {
|
|
41
42
|
return [];
|
|
42
43
|
}
|
|
43
|
-
const stories = nodesWhere(
|
|
44
|
-
|
|
45
|
-
(node) => ts.isCallExpression(node) && origins.origin(node.expression) === "story" && ignoresEngine(node, origins.checker),
|
|
44
|
+
const stories = nodesWhere(source, (node) => ts.isCallExpression(node) && origins.origin(node.expression) === "story").filter(
|
|
45
|
+
ts.isCallExpression,
|
|
46
46
|
);
|
|
47
|
-
return stories.
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
47
|
+
return stories.flatMap((story) => {
|
|
48
|
+
const body = story.arguments[2];
|
|
49
|
+
const checked = body === undefined ? { drivesSubject: false, escapes: [] } : engineEscapes(body, origins.checker, file.path);
|
|
50
|
+
if (checked.escapes.length > 0) {
|
|
51
|
+
return checked.escapes.map(({ node, reason }) => ({
|
|
52
|
+
file: file.path,
|
|
53
|
+
line: source.getLineAndCharacterOfPosition(node.getStart(source)).line + 1,
|
|
54
|
+
message: `${reason} in a spec body. Move engine access and wiring into the story kit's verbs or traits in test-support/. Keep expectations in the spec. Constructor tests may call the constructor in their colocated module; native SQL transaction blocks may wrap kit verbs. See https://github.com/ShivaeDev/platform/tree/main/packages/quality#story-tests.`,
|
|
55
|
+
}));
|
|
56
|
+
}
|
|
57
|
+
if (checked.drivesSubject || !ignoresEngine(story, origins.checker)) {
|
|
58
|
+
return [];
|
|
59
|
+
}
|
|
60
|
+
return [
|
|
61
|
+
{
|
|
62
|
+
file: file.path,
|
|
63
|
+
line: source.getLineAndCharacterOfPosition(story.getStart(source)).line + 1,
|
|
64
|
+
message: `Declares a story without traits whose body never references its verbs, its story or its test context. Drive the engine through one of the kit's verbs or traits. If the code under test is pure, move the test to ${name.stem}.unit.${name.kind}${name.extension}, which reaches no engine and mocks nothing. See https://github.com/ShivaeDev/platform/tree/main/packages/quality#story-tests.`,
|
|
65
|
+
},
|
|
66
|
+
];
|
|
67
|
+
});
|
|
52
68
|
});
|
|
53
69
|
}),
|
|
54
70
|
description:
|
|
55
|
-
"
|
|
71
|
+
"Story bodies use their kit instead of raw services, story.engine or production wiring; constructor subjects and native transaction blocks remain explicit.",
|
|
56
72
|
id: "tests/story-engine",
|
|
57
73
|
});
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Effect } from "effect";
|
|
2
|
+
import { positiveRefusalFindings } from "#adapters/positiveRefusalFindings.ts";
|
|
3
|
+
import { importGraph } from "#imports/graph.ts";
|
|
4
|
+
import { defineRule } from "#rule.ts";
|
|
5
|
+
import { storyOrigins } from "./origins.ts";
|
|
6
|
+
import { storySources } from "./sources.ts";
|
|
7
|
+
|
|
8
|
+
export const positiveRefusals = defineRule({
|
|
9
|
+
check: Effect.fn("Stories.check")(function* (inputs) {
|
|
10
|
+
const files = yield* storySources(inputs);
|
|
11
|
+
const graph = yield* importGraph(inputs);
|
|
12
|
+
const origins = storyOrigins(inputs, graph);
|
|
13
|
+
return files.flatMap((file) => positiveRefusalFindings(file, origins));
|
|
14
|
+
}),
|
|
15
|
+
description: "Negative outcome comparisons in a story need a positive assertion of the expected refusal on the same outcome.",
|
|
16
|
+
id: "tests/positive-refusals",
|
|
17
|
+
});
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import ts from "typescript";
|
|
2
|
+
import { storyBody } from "#adapters/bodyReferences.ts";
|
|
2
3
|
|
|
3
4
|
export function storyUsesInputs(body: ts.Expression, checker: ts.TypeChecker): boolean | undefined {
|
|
4
|
-
const declaration =
|
|
5
|
-
if (declaration
|
|
5
|
+
const declaration = storyBody(body, checker);
|
|
6
|
+
if (declaration?.body === undefined) {
|
|
6
7
|
return undefined;
|
|
7
8
|
}
|
|
8
9
|
const inputs = new Set<ts.Symbol>();
|
|
@@ -2,10 +2,10 @@ import { spawnSync } from "node:child_process";
|
|
|
2
2
|
import { realpathSync } from "node:fs";
|
|
3
3
|
import { fileURLToPath } from "node:url";
|
|
4
4
|
import { format } from "node:util";
|
|
5
|
-
import { Config, Console, Effect, Option } from "effect";
|
|
5
|
+
import { Config, ConfigProvider, Console, Effect, Option } from "effect";
|
|
6
6
|
import { program } from "#cli/program.ts";
|
|
7
7
|
import { exitCode, explained, services } from "#cli/runMain.ts";
|
|
8
|
-
import { ISOLATED_ENV } from "#testing/adapters/git.ts";
|
|
8
|
+
import { ISOLATED_ENV, isolatedEnvironment } from "#testing/adapters/git.ts";
|
|
9
9
|
|
|
10
10
|
export interface Run {
|
|
11
11
|
readonly status: number | null;
|
|
@@ -84,21 +84,29 @@ export function capturing(output: Output): Console.Console {
|
|
|
84
84
|
}
|
|
85
85
|
|
|
86
86
|
// Runs the executable's program in this process, which imports each config path once: after a command rewrites the config, spawn `quality`.
|
|
87
|
-
export
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
87
|
+
export function runQuality(root: string, ...args: readonly string[]): Effect.Effect<Run> {
|
|
88
|
+
return Effect.scoped(
|
|
89
|
+
Effect.gen(function* () {
|
|
90
|
+
const output: Output = { stderr: "", stdout: "" };
|
|
91
|
+
const command = program(args, { cwd: realpathSync(root), launch: { options: OPTIONS, script: CLI } });
|
|
92
|
+
const environment = ConfigProvider.orElse(
|
|
93
|
+
ConfigProvider.fromEnv({ env: { "HEAVY_PROCESS_LOCK": isolatedEnvironment(root).HEAVY_PROCESS_LOCK } }),
|
|
94
|
+
yield* ConfigProvider.ConfigProvider,
|
|
95
|
+
);
|
|
96
|
+
yield* Effect.acquireRelease(Effect.promise(isolateGit), (restore) => Effect.sync(restore));
|
|
97
|
+
const exit = yield* explained(command).pipe(
|
|
98
|
+
Effect.provideService(ConfigProvider.ConfigProvider, environment),
|
|
99
|
+
Effect.provideService(Console.Console, capturing(output)),
|
|
100
|
+
Effect.provide(services),
|
|
101
|
+
Effect.exit,
|
|
102
|
+
);
|
|
103
|
+
return { status: exitCode(exit), ...output };
|
|
104
|
+
}),
|
|
105
|
+
);
|
|
98
106
|
}
|
|
99
107
|
|
|
100
108
|
export function quality(root: string, ...args: readonly string[]): Run {
|
|
101
|
-
const result = spawnSync("node", qualityArgs(args), { cwd: root, encoding: "utf8", env:
|
|
109
|
+
const result = spawnSync("node", qualityArgs(args), { cwd: root, encoding: "utf8", env: isolatedEnvironment(root) });
|
|
102
110
|
return { status: result.status, stderr: result.stderr, stdout: result.stdout };
|
|
103
111
|
}
|
|
104
112
|
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { execFileSync, spawnSync } from "node:child_process";
|
|
2
|
+
import { resolve } from "node:path";
|
|
2
3
|
import { Config, Effect, Option } from "effect";
|
|
3
4
|
|
|
4
5
|
const HEAVY_ENV = Object.fromEntries(
|
|
@@ -20,6 +21,10 @@ export const ISOLATED_ENV = {
|
|
|
20
21
|
"PATH": Effect.runSync(Config.String("PATH")),
|
|
21
22
|
};
|
|
22
23
|
|
|
24
|
+
export function isolatedEnvironment(root: string) {
|
|
25
|
+
return { ...ISOLATED_ENV, "HEAVY_PROCESS_LOCK": resolve(root, "heavy.lock") };
|
|
26
|
+
}
|
|
27
|
+
|
|
23
28
|
const SETTINGS = [
|
|
24
29
|
"user.name=Quality",
|
|
25
30
|
"user.email=quality@example.invalid",
|
|
@@ -32,7 +37,7 @@ export function git(root: string, ...args: readonly string[]): string {
|
|
|
32
37
|
return execFileSync("git", [...SETTINGS.flatMap((setting) => ["-c", setting]), ...args], {
|
|
33
38
|
cwd: root,
|
|
34
39
|
encoding: "utf8",
|
|
35
|
-
env:
|
|
40
|
+
env: isolatedEnvironment(root),
|
|
36
41
|
stdio: ["ignore", "pipe", "pipe"],
|
|
37
42
|
});
|
|
38
43
|
}
|
|
@@ -46,7 +51,7 @@ export function mergeBranch(root: string, branch: string): "merged" | "conflicte
|
|
|
46
51
|
const result = spawnSync("git", [...SETTINGS.flatMap((setting) => ["-c", setting]), "merge", "--quiet", "--no-edit", branch], {
|
|
47
52
|
cwd: root,
|
|
48
53
|
encoding: "utf8",
|
|
49
|
-
env:
|
|
54
|
+
env: isolatedEnvironment(root),
|
|
50
55
|
});
|
|
51
56
|
if (result.status !== 0 && result.status !== 1) {
|
|
52
57
|
throw new Error(`git merge failed: ${result.error ?? result.stderr}`);
|
|
@@ -4,7 +4,7 @@ import { dirname, join } from "node:path";
|
|
|
4
4
|
import sortPackageJson from "sort-package-json";
|
|
5
5
|
import { shellWords } from "#hooks/command.ts";
|
|
6
6
|
import { qualityArgs, type Run } from "./cli.ts";
|
|
7
|
-
import { commitAll, git,
|
|
7
|
+
import { commitAll, git, isolatedEnvironment } from "./git.ts";
|
|
8
8
|
import { formatTree } from "./qualityTree.ts";
|
|
9
9
|
import { DEFAULT_FILES, linkPackage, type SeedFile, seedTree } from "./tree.ts";
|
|
10
10
|
|
|
@@ -121,7 +121,11 @@ export function withWorktree(repository: HookRepository, name: string, at?: stri
|
|
|
121
121
|
}
|
|
122
122
|
|
|
123
123
|
export function commits(cwd: string, message: string): Run {
|
|
124
|
-
const result = spawnSync("git", ["commit", "--quiet", "--allow-empty", "--message", message], {
|
|
124
|
+
const result = spawnSync("git", ["commit", "--quiet", "--allow-empty", "--message", message], {
|
|
125
|
+
cwd,
|
|
126
|
+
encoding: "utf8",
|
|
127
|
+
env: isolatedEnvironment(cwd),
|
|
128
|
+
});
|
|
125
129
|
return { status: result.status, stderr: result.stderr, stdout: result.stdout };
|
|
126
130
|
}
|
|
127
131
|
|
package/src/testing/ruleStory.ts
CHANGED
|
@@ -60,7 +60,6 @@ function outcomeOf({ status }: Run): string {
|
|
|
60
60
|
|
|
61
61
|
export function makeRuleStory() {
|
|
62
62
|
const ruleStory = storyKit({
|
|
63
|
-
clock: "live",
|
|
64
63
|
create: () =>
|
|
65
64
|
Effect.gen(function* () {
|
|
66
65
|
const fs = yield* FileSystem.FileSystem;
|
|
@@ -87,7 +86,7 @@ export function makeRuleStory() {
|
|
|
87
86
|
findings: () => checked(engine),
|
|
88
87
|
gate: Effect.fn("RuleStory.gate")(function* () {
|
|
89
88
|
story.tell("quality runs the repository gate");
|
|
90
|
-
engine.answer = yield*
|
|
89
|
+
engine.answer = yield* runQuality(engine.root, "lint");
|
|
91
90
|
}),
|
|
92
91
|
gateOutcome: () => Effect.map(answered(engine), outcomeOf),
|
|
93
92
|
gateReport: () => Effect.map(answered(engine), (answer) => answer.stdout + answer.stderr),
|