@shivaedev/quality 0.65.0 → 0.67.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 +20 -0
- package/README.md +17 -7
- package/dist/adapters/asymmetricMatcher.d.ts +3 -0
- package/dist/adapters/asymmetricMatcher.d.ts.map +1 -0
- package/dist/adapters/asymmetricMatcher.js +27 -0
- package/dist/adapters/asymmetricMatcher.js.map +1 -0
- package/dist/adapters/callerContextData.d.ts +3 -0
- package/dist/adapters/callerContextData.d.ts.map +1 -0
- package/dist/adapters/callerContextData.js +42 -0
- package/dist/adapters/callerContextData.js.map +1 -0
- package/dist/adapters/contextCaptureFindings.d.ts +4 -0
- package/dist/adapters/contextCaptureFindings.d.ts.map +1 -0
- package/dist/adapters/contextCaptureFindings.js +49 -0
- package/dist/adapters/contextCaptureFindings.js.map +1 -0
- package/dist/adapters/import-compiler/browserChecker.d.ts +4 -0
- package/dist/adapters/import-compiler/browserChecker.d.ts.map +1 -0
- package/dist/adapters/import-compiler/browserChecker.js +4 -0
- package/dist/adapters/import-compiler/browserChecker.js.map +1 -0
- package/dist/adapters/import-compiler/departures.d.ts +5 -0
- package/dist/adapters/import-compiler/departures.d.ts.map +1 -0
- package/dist/adapters/import-compiler/departures.js +5 -0
- package/dist/adapters/import-compiler/departures.js.map +1 -0
- package/dist/adapters/import-compiler/graph.d.ts +4 -0
- package/dist/adapters/import-compiler/graph.d.ts.map +1 -0
- package/dist/adapters/import-compiler/graph.js +6 -0
- package/dist/adapters/import-compiler/graph.js.map +1 -0
- package/dist/adapters/import-compiler/service.d.ts +10 -0
- package/dist/adapters/import-compiler/service.d.ts.map +1 -0
- package/dist/adapters/import-compiler/service.js +16 -0
- package/dist/adapters/import-compiler/service.js.map +1 -0
- package/dist/adapters/initializerDependency.d.ts +3 -0
- package/dist/adapters/initializerDependency.d.ts.map +1 -0
- package/dist/adapters/initializerDependency.js +53 -0
- package/dist/adapters/initializerDependency.js.map +1 -0
- package/dist/adapters/knip/configuration.d.ts.map +1 -1
- package/dist/adapters/knip/configuration.js +2 -1
- package/dist/adapters/knip/configuration.js.map +1 -1
- package/dist/adapters/pureReader.d.ts +3 -0
- package/dist/adapters/pureReader.d.ts.map +1 -0
- package/dist/adapters/pureReader.js +52 -0
- package/dist/adapters/pureReader.js.map +1 -0
- package/dist/adapters/readConfig.js +1 -1
- package/dist/adapters/readConfig.js.map +1 -1
- package/dist/adapters/scriptPaths.d.ts +2 -0
- package/dist/adapters/scriptPaths.d.ts.map +1 -0
- package/dist/adapters/scriptPaths.js +5 -0
- package/dist/adapters/scriptPaths.js.map +1 -0
- package/dist/adapters/serviceDefinitionProblems.js +1 -1
- package/dist/adapters/serviceDefinitionProblems.js.map +1 -1
- package/dist/adapters/serviceFolderFindings.d.ts.map +1 -1
- package/dist/adapters/serviceFolderFindings.js +12 -0
- package/dist/adapters/serviceFolderFindings.js.map +1 -1
- package/dist/adapters/serviceModelFindings.d.ts +4 -0
- package/dist/adapters/serviceModelFindings.d.ts.map +1 -0
- package/dist/adapters/serviceModelFindings.js +48 -0
- package/dist/adapters/serviceModelFindings.js.map +1 -0
- package/dist/adapters/serviceModelSyntax.d.ts +5 -0
- package/dist/adapters/serviceModelSyntax.d.ts.map +1 -0
- package/dist/adapters/serviceModelSyntax.js +53 -0
- package/dist/adapters/serviceModelSyntax.js.map +1 -0
- package/dist/adapters/serviceOperationProblems.d.ts +8 -0
- package/dist/adapters/serviceOperationProblems.d.ts.map +1 -0
- package/dist/adapters/serviceOperationProblems.js +108 -0
- package/dist/adapters/serviceOperationProblems.js.map +1 -0
- package/dist/adapters/serviceStateProblems.d.ts +7 -0
- package/dist/adapters/serviceStateProblems.d.ts.map +1 -0
- package/dist/adapters/serviceStateProblems.js +66 -0
- package/dist/adapters/serviceStateProblems.js.map +1 -0
- package/dist/adapters/specReaderSources.d.ts +7 -0
- package/dist/adapters/specReaderSources.d.ts.map +1 -0
- package/dist/adapters/specReaderSources.js +73 -0
- package/dist/adapters/specReaderSources.js.map +1 -0
- package/dist/cli/args.js +2 -2
- package/dist/cli/args.js.map +1 -1
- package/dist/cli/fix.d.ts +0 -1
- package/dist/cli/fix.d.ts.map +1 -1
- package/dist/cli/fix.js +1 -1
- package/dist/cli/fix.js.map +1 -1
- package/dist/cli/limits.d.ts +2 -0
- package/dist/cli/limits.d.ts.map +1 -0
- package/dist/cli/limits.js +2 -0
- package/dist/cli/limits.js.map +1 -0
- package/dist/cli/{options.d.ts → misplaced.d.ts} +1 -1
- package/dist/cli/misplaced.d.ts.map +1 -0
- package/dist/cli/{options.js → misplaced.js} +1 -1
- package/dist/cli/misplaced.js.map +1 -0
- package/dist/cli/program.js +1 -1
- package/dist/cli/program.js.map +1 -1
- package/dist/cli/subcommands.d.ts +2 -0
- package/dist/cli/subcommands.d.ts.map +1 -0
- package/dist/cli/subcommands.js +6 -0
- package/dist/cli/subcommands.js.map +1 -0
- package/dist/cli/{messages.d.ts → usage.d.ts} +1 -2
- package/dist/cli/usage.d.ts.map +1 -0
- package/{src/cli/messages.ts → dist/cli/usage.js} +1 -6
- package/dist/cli/usage.js.map +1 -0
- package/dist/config/defaultExtensions.d.ts +2 -0
- package/dist/config/defaultExtensions.d.ts.map +1 -0
- package/{src/config/constants.ts → dist/config/defaultExtensions.js} +1 -2
- package/dist/config/defaultExtensions.js.map +1 -0
- package/dist/config/file.d.ts +2 -0
- package/dist/config/file.d.ts.map +1 -0
- package/dist/config/file.js +2 -0
- package/dist/config/file.js.map +1 -0
- package/dist/config/load.js +1 -1
- package/dist/config/load.js.map +1 -1
- package/dist/hooks/install.js +1 -1
- package/dist/hooks/install.js.map +1 -1
- package/dist/imports/browserGlobals.js +1 -1
- package/dist/imports/browserGlobals.js.map +1 -1
- package/dist/imports/departures.js +1 -1
- package/dist/imports/departures.js.map +1 -1
- package/dist/imports/graph.js +1 -1
- package/dist/imports/graph.js.map +1 -1
- package/dist/imports/testComposition.d.ts +4 -0
- package/dist/imports/testComposition.d.ts.map +1 -0
- package/dist/imports/testComposition.js +38 -0
- package/dist/imports/testComposition.js.map +1 -0
- package/dist/naming/adapters/plainData.d.ts +5 -0
- package/dist/naming/adapters/plainData.d.ts.map +1 -0
- package/dist/naming/adapters/plainData.js +77 -0
- package/dist/naming/adapters/plainData.js.map +1 -0
- package/dist/naming/constantModule.d.ts +3 -0
- package/dist/naming/constantModule.d.ts.map +1 -0
- package/dist/naming/constantModule.js +25 -0
- package/dist/naming/constantModule.js.map +1 -0
- package/dist/naming/{migrationFile.d.ts → isMigrationFile.d.ts} +1 -1
- package/dist/naming/isMigrationFile.d.ts.map +1 -0
- package/dist/naming/{migrationFile.js → isMigrationFile.js} +1 -1
- package/dist/naming/isMigrationFile.js.map +1 -0
- package/dist/naming/ownExports.d.ts +0 -1
- package/dist/naming/ownExports.d.ts.map +1 -1
- package/dist/naming/ownExports.js +11 -25
- package/dist/naming/ownExports.js.map +1 -1
- package/dist/naming/packageTests.d.ts +7 -0
- package/dist/naming/packageTests.d.ts.map +1 -0
- package/dist/naming/packageTests.js +21 -0
- package/dist/naming/packageTests.js.map +1 -0
- package/dist/naming/testCode.d.ts +4 -0
- package/dist/naming/testCode.d.ts.map +1 -0
- package/dist/naming/testCode.js +46 -0
- package/dist/naming/testCode.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 -20
- package/dist/rules/builtIn.js.map +1 -1
- package/dist/rules/comments/kinds.js +1 -1
- package/dist/rules/comments/kinds.js.map +1 -1
- package/dist/rules/effect/contextCapture.d.ts +2 -0
- package/dist/rules/effect/contextCapture.d.ts.map +1 -0
- package/dist/rules/effect/contextCapture.js +9 -0
- package/dist/rules/effect/contextCapture.js.map +1 -0
- package/dist/rules/effect/policy.d.ts +2 -0
- package/dist/rules/effect/policy.d.ts.map +1 -0
- package/dist/rules/effect/policy.js +27 -0
- package/dist/rules/effect/policy.js.map +1 -0
- package/dist/rules/effect/serviceCatalog.d.ts +2 -2
- package/dist/rules/effect/serviceCatalog.d.ts.map +1 -1
- package/dist/rules/effect/serviceCatalog.js +14 -10
- package/dist/rules/effect/serviceCatalog.js.map +1 -1
- package/dist/rules/effect/serviceDefinitionAssembly.js +1 -1
- package/dist/rules/effect/serviceDefinitionAssembly.js.map +1 -1
- package/dist/rules/effect/serviceFolders.js +1 -1
- package/dist/rules/effect/serviceFolders.js.map +1 -1
- package/dist/rules/effect/serviceModel.d.ts +2 -0
- package/dist/rules/effect/serviceModel.d.ts.map +1 -0
- package/dist/rules/effect/serviceModel.js +9 -0
- package/dist/rules/effect/serviceModel.js.map +1 -0
- package/dist/rules/effect/serviceTypes.d.ts +2 -2
- package/dist/rules/effect/serviceTypes.d.ts.map +1 -1
- package/dist/rules/effect/serviceTypes.js +15 -3
- package/dist/rules/effect/serviceTypes.js.map +1 -1
- package/dist/rules/files/namedAfterExport.d.ts.map +1 -1
- package/dist/rules/files/namedAfterExport.js +38 -13
- package/dist/rules/files/namedAfterExport.js.map +1 -1
- package/dist/rules/imports/manifest.d.ts.map +1 -1
- package/dist/rules/imports/manifest.js +9 -11
- package/dist/rules/imports/manifest.js.map +1 -1
- package/dist/rules/imports/noTestCode.d.ts.map +1 -1
- package/dist/rules/imports/noTestCode.js +13 -9
- package/dist/rules/imports/noTestCode.js.map +1 -1
- package/dist/rules/maxLines.d.ts.map +1 -1
- package/dist/rules/maxLines.js +7 -2
- package/dist/rules/maxLines.js.map +1 -1
- package/dist/rules/stories/specHelpers.d.ts.map +1 -1
- package/dist/rules/stories/specHelpers.js +8 -4
- package/dist/rules/stories/specHelpers.js.map +1 -1
- package/dist/rules/suppressions/{directives.d.ts → in.d.ts} +1 -1
- package/dist/rules/suppressions/in.d.ts.map +1 -0
- package/dist/rules/suppressions/{directives.js → in.js} +1 -1
- package/dist/rules/suppressions/in.js.map +1 -0
- package/dist/rules/suppressions/noInline.js +1 -1
- package/dist/rules/suppressions/noInline.js.map +1 -1
- package/dist/rules/test-names/colocated.d.ts.map +1 -1
- package/dist/rules/test-names/colocated.js +7 -4
- package/dist/rules/test-names/colocated.js.map +1 -1
- package/dist/rules/test-names/follow.d.ts.map +1 -1
- package/dist/rules/test-names/follow.js +13 -6
- package/dist/rules/test-names/follow.js.map +1 -1
- package/package.json +4 -4
- package/src/adapters/asymmetricMatcher.ts +33 -0
- package/src/adapters/callerContextData.ts +46 -0
- package/src/adapters/contextCaptureFindings.ts +58 -0
- package/src/adapters/import-compiler/browserChecker.ts +5 -0
- package/src/adapters/import-compiler/departures.ts +9 -0
- package/src/adapters/import-compiler/graph.ts +9 -0
- package/src/adapters/import-compiler/service.ts +17 -0
- package/src/adapters/initializerDependency.ts +57 -0
- package/src/adapters/knip/configuration.ts +2 -5
- package/src/adapters/pureReader.ts +56 -0
- package/src/adapters/readConfig.ts +1 -1
- package/src/adapters/scriptPaths.ts +5 -0
- package/src/adapters/serviceDefinitionProblems.ts +1 -1
- package/src/adapters/serviceFolderFindings.ts +14 -0
- package/src/adapters/serviceModelFindings.ts +52 -0
- package/src/adapters/serviceModelSyntax.ts +58 -0
- package/src/adapters/serviceOperationProblems.ts +131 -0
- package/src/adapters/serviceStateProblems.ts +86 -0
- package/src/adapters/specReaderSources.ts +77 -0
- package/src/cli/args.ts +2 -2
- package/src/cli/fix.ts +1 -2
- package/src/cli/limits.ts +1 -0
- package/src/cli/program.ts +1 -1
- package/src/cli/subcommands.ts +5 -0
- package/{dist/cli/messages.js → src/cli/usage.ts} +0 -6
- package/{dist/config/constants.js → src/config/defaultExtensions.ts} +0 -2
- package/src/config/file.ts +1 -0
- package/src/config/load.ts +1 -1
- package/src/hooks/install.ts +1 -1
- package/src/imports/browserGlobals.ts +1 -1
- package/src/imports/departures.ts +1 -1
- package/src/imports/graph.ts +1 -1
- package/src/imports/testComposition.ts +47 -0
- package/src/naming/adapters/plainData.ts +88 -0
- package/src/naming/constantModule.ts +28 -0
- package/src/naming/ownExports.ts +11 -28
- package/src/naming/packageTests.ts +24 -0
- package/src/naming/testCode.ts +62 -0
- package/src/rules/builtIn.ts +2 -20
- package/src/rules/comments/kinds.ts +1 -1
- package/src/rules/effect/contextCapture.ts +10 -0
- package/src/rules/effect/policy.ts +27 -0
- package/src/rules/effect/serviceCatalog.ts +15 -10
- package/src/rules/effect/serviceDefinitionAssembly.ts +1 -1
- package/src/rules/effect/serviceFolders.ts +1 -1
- package/src/rules/effect/serviceModel.ts +10 -0
- package/src/rules/effect/serviceTypes.ts +15 -3
- package/src/rules/files/namedAfterExport.ts +43 -13
- package/src/rules/imports/manifest.ts +18 -10
- package/src/rules/imports/noTestCode.ts +13 -12
- package/src/rules/maxLines.ts +7 -3
- package/src/rules/stories/specHelpers.ts +14 -4
- package/src/rules/suppressions/noInline.ts +1 -1
- package/src/rules/test-names/colocated.ts +7 -4
- package/src/rules/test-names/follow.ts +13 -6
- package/dist/adapters/ImportCompiler.d.ts +0 -10
- package/dist/adapters/ImportCompiler.d.ts.map +0 -1
- package/dist/adapters/ImportCompiler.js +0 -16
- package/dist/adapters/ImportCompiler.js.map +0 -1
- package/dist/adapters/imports/analyzeDepartures.d.ts +0 -5
- package/dist/adapters/imports/analyzeDepartures.d.ts.map +0 -1
- package/dist/adapters/imports/analyzeDepartures.js +0 -5
- package/dist/adapters/imports/analyzeDepartures.js.map +0 -1
- package/dist/adapters/imports/analyzeGraph.d.ts +0 -4
- package/dist/adapters/imports/analyzeGraph.d.ts.map +0 -1
- package/dist/adapters/imports/analyzeGraph.js +0 -6
- package/dist/adapters/imports/analyzeGraph.js.map +0 -1
- package/dist/adapters/imports/checkBrowser.d.ts +0 -4
- package/dist/adapters/imports/checkBrowser.d.ts.map +0 -1
- package/dist/adapters/imports/checkBrowser.js +0 -4
- package/dist/adapters/imports/checkBrowser.js.map +0 -1
- package/dist/cli/messages.d.ts.map +0 -1
- package/dist/cli/messages.js.map +0 -1
- package/dist/cli/options.d.ts.map +0 -1
- package/dist/cli/options.js.map +0 -1
- package/dist/config/constants.d.ts +0 -3
- package/dist/config/constants.d.ts.map +0 -1
- package/dist/config/constants.js.map +0 -1
- package/dist/naming/migrationFile.d.ts.map +0 -1
- package/dist/naming/migrationFile.js.map +0 -1
- package/dist/rules/suppressions/directives.d.ts.map +0 -1
- package/dist/rules/suppressions/directives.js.map +0 -1
- package/src/adapters/ImportCompiler.ts +0 -17
- package/src/adapters/imports/analyzeDepartures.ts +0 -9
- package/src/adapters/imports/analyzeGraph.ts +0 -9
- package/src/adapters/imports/checkBrowser.ts +0 -5
- /package/src/cli/{options.ts → misplaced.ts} +0 -0
- /package/src/naming/{migrationFile.ts → isMigrationFile.ts} +0 -0
- /package/src/rules/suppressions/{directives.ts → in.ts} +0 -0
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { contextCaptureFindings } from "#adapters/contextCaptureFindings.ts";
|
|
2
|
+
import { defineRule } from "#rule.ts";
|
|
3
|
+
|
|
4
|
+
export const contextCapture = defineRule({
|
|
5
|
+
check: contextCaptureFindings,
|
|
6
|
+
description:
|
|
7
|
+
"Core code yields dependencies and the caller rather than re-providing captured contexts with Effect.provideContext, runPromiseWith, runForkWith or the Context overload of provide. Runtime bridges belong in adapters/ or test-support/.",
|
|
8
|
+
id: "effect/context-capture",
|
|
9
|
+
registrable: false,
|
|
10
|
+
});
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { adapterImports } from "#rules/effect/adapterImports.ts";
|
|
2
|
+
import { effectBoundary } from "#rules/effect/boundary.ts";
|
|
3
|
+
import { contextCapture } from "#rules/effect/contextCapture.ts";
|
|
4
|
+
import { failureHonesty } from "#rules/effect/failureHonesty.ts";
|
|
5
|
+
import { rpcBoundary } from "#rules/effect/rpcBoundary.ts";
|
|
6
|
+
import { serviceDefinitionAssembly } from "#rules/effect/serviceDefinitionAssembly.ts";
|
|
7
|
+
import { serviceFolders } from "#rules/effect/serviceFolders.ts";
|
|
8
|
+
import { serviceIds } from "#rules/effect/serviceIds.ts";
|
|
9
|
+
import { serviceModel } from "#rules/effect/serviceModel.ts";
|
|
10
|
+
import { serviceParameters } from "#rules/effect/serviceParameters.ts";
|
|
11
|
+
import { sharedErrorClasses } from "#rules/effect/sharedErrorClasses.ts";
|
|
12
|
+
import { sqlTransact } from "#rules/effect/sqlTransact.ts";
|
|
13
|
+
|
|
14
|
+
export const effectPolicy = [
|
|
15
|
+
adapterImports,
|
|
16
|
+
effectBoundary,
|
|
17
|
+
contextCapture,
|
|
18
|
+
failureHonesty,
|
|
19
|
+
rpcBoundary,
|
|
20
|
+
serviceDefinitionAssembly,
|
|
21
|
+
serviceFolders,
|
|
22
|
+
serviceIds,
|
|
23
|
+
serviceModel,
|
|
24
|
+
serviceParameters,
|
|
25
|
+
sharedErrorClasses,
|
|
26
|
+
sqlTransact,
|
|
27
|
+
] as const;
|
|
@@ -3,9 +3,9 @@ import servicePackage from "@shivaedev/service/package.json" with { type: "json"
|
|
|
3
3
|
import { serviceOrigin } from "#rules/effect/serviceOrigin.ts";
|
|
4
4
|
import { serviceTypes } from "#rules/effect/serviceTypes.ts";
|
|
5
5
|
|
|
6
|
-
export function serviceCatalog(program: ts.Program, checker: ts.TypeChecker, packages: readonly string[] = []) {
|
|
6
|
+
export function serviceCatalog(program: ts.Program, checker: ts.TypeChecker, packages: readonly string[] = [], initializerState = false) {
|
|
7
7
|
const prefixes = [servicePackage.name, ...packages].map((name) => `${name.startsWith("@") ? name.split("/")[0] : name}/`);
|
|
8
|
-
const services = serviceTypes(checker);
|
|
8
|
+
const services = serviceTypes(checker, initializerState);
|
|
9
9
|
function imported(node: ts.ImportSpecifier | ts.NamespaceImport): void {
|
|
10
10
|
const symbol = checker.getSymbolAtLocation(node.name);
|
|
11
11
|
if (symbol === undefined) {
|
|
@@ -16,7 +16,7 @@ export function serviceCatalog(program: ts.Program, checker: ts.TypeChecker, pac
|
|
|
16
16
|
for (const candidate of candidates) {
|
|
17
17
|
const resolved = candidate.flags & ts.SymbolFlags.Alias ? checker.getAliasedSymbol(candidate) : candidate;
|
|
18
18
|
if (serviceOrigin(checker, resolved)) {
|
|
19
|
-
services.remember(checker.getTypeOfSymbol(resolved));
|
|
19
|
+
services.remember(checker.getTypeOfSymbol(resolved), resolved.name);
|
|
20
20
|
}
|
|
21
21
|
}
|
|
22
22
|
}
|
|
@@ -29,7 +29,17 @@ export function serviceCatalog(program: ts.Program, checker: ts.TypeChecker, pac
|
|
|
29
29
|
return;
|
|
30
30
|
}
|
|
31
31
|
const target = symbol.flags & ts.SymbolFlags.Alias ? checker.getAliasedSymbol(symbol) : symbol;
|
|
32
|
-
services.remember(checker.getTypeOfSymbol(target));
|
|
32
|
+
services.remember(checker.getTypeOfSymbol(target), target.name);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function named(node: ts.Node): void {
|
|
36
|
+
if (!(ts.isClassDeclaration(node) || ts.isVariableDeclaration(node)) || node.name === undefined || !serviceOrigin(checker, node.name)) {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
const symbol = checker.getSymbolAtLocation(node.name);
|
|
40
|
+
if (symbol !== undefined) {
|
|
41
|
+
services.remember(checker.getTypeOfSymbol(symbol), symbol.name);
|
|
42
|
+
}
|
|
33
43
|
}
|
|
34
44
|
|
|
35
45
|
function discover(node: ts.Node): void {
|
|
@@ -39,12 +49,7 @@ export function serviceCatalog(program: ts.Program, checker: ts.TypeChecker, pac
|
|
|
39
49
|
if (ts.isImportSpecifier(node) || ts.isNamespaceImport(node)) {
|
|
40
50
|
imported(node);
|
|
41
51
|
}
|
|
42
|
-
|
|
43
|
-
services.remember(checker.getTypeAtLocation(node.name));
|
|
44
|
-
}
|
|
45
|
-
if (ts.isVariableDeclaration(node) && serviceOrigin(checker, node.name)) {
|
|
46
|
-
services.remember(checker.getTypeAtLocation(node.name));
|
|
47
|
-
}
|
|
52
|
+
named(node);
|
|
48
53
|
if (ts.isTypeReferenceNode(node)) {
|
|
49
54
|
referenced(node);
|
|
50
55
|
}
|
|
@@ -40,7 +40,7 @@ function fileFindings(file: SourceFile): readonly Finding[] {
|
|
|
40
40
|
export const serviceDefinitionAssembly = defineRule({
|
|
41
41
|
check: ({ sources }) => sources.flatMap(fileFindings),
|
|
42
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
|
|
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 Effect.fn operations from focused files; state factories capture only owned lifetime state; genericMethod may wrap those references. Move implementation bodies out of the assembly file. The service-model rule verifies tracing and owned state. Includes adapters and tests; no config exceptions or inline suppressions.",
|
|
44
44
|
id: "effect/service-definition-assembly",
|
|
45
45
|
registrable: false,
|
|
46
46
|
});
|
|
@@ -4,7 +4,7 @@ import { defineRule } from "#rule.ts";
|
|
|
4
4
|
export const serviceFolders = defineRule({
|
|
5
5
|
check: serviceFolderFindings,
|
|
6
6
|
description:
|
|
7
|
-
"
|
|
7
|
+
"Every folder containing a defineService declaration, and each services/<name> folder, has service.ts, and its service.ts exports one named const initialized by defineService. The service-definition-assembly rule checks its operation inventory.",
|
|
8
8
|
id: "effect/service-folders",
|
|
9
9
|
registrable: false,
|
|
10
10
|
});
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { serviceModelFindings } from "#adapters/serviceModelFindings.ts";
|
|
2
|
+
import { defineRule } from "#rule.ts";
|
|
3
|
+
|
|
4
|
+
export const serviceModel = defineRule({
|
|
5
|
+
check: serviceModelFindings,
|
|
6
|
+
description:
|
|
7
|
+
"defineService initializer state owns lifetime state, never dependencies. Every inventoried operation, including factory returns and piped bodies, is a sibling Effect.fn export with its Service.operation span. Dependencies and the caller come from the environment; the Layer registration chooses lifetime.",
|
|
8
|
+
id: "effect/service-model",
|
|
9
|
+
registrable: false,
|
|
10
|
+
});
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import ts from "typescript";
|
|
2
|
+
import { callerContextData } from "#adapters/callerContextData.ts";
|
|
2
3
|
|
|
3
4
|
const SERVICE = "~effect/Context/Service";
|
|
4
5
|
const CONTEXT = "~effect/Context";
|
|
5
6
|
|
|
6
|
-
export function serviceTypes(checker: ts.TypeChecker) {
|
|
7
|
+
export function serviceTypes(checker: ts.TypeChecker, initializerState = false) {
|
|
7
8
|
const shapes = new Set<ts.Type>();
|
|
9
|
+
const contextData = new Set<ts.Type>();
|
|
8
10
|
const carried = new Map<ts.Type, boolean>();
|
|
9
11
|
function propertyType(type: ts.Type, name: string): ts.Type | undefined {
|
|
10
12
|
const property = type.getProperty(name);
|
|
@@ -22,17 +24,26 @@ export function serviceTypes(checker: ts.TypeChecker) {
|
|
|
22
24
|
&& checker.getNonNullableType(checker.getTypeOfSymbol(property)).getCallSignatures().length === 0,
|
|
23
25
|
);
|
|
24
26
|
}
|
|
25
|
-
function remember(type: ts.Type): void {
|
|
27
|
+
function remember(type: ts.Type, name?: string): void {
|
|
26
28
|
if (type.getProperty(SERVICE) === undefined) {
|
|
27
29
|
return;
|
|
28
30
|
}
|
|
29
31
|
const shape = propertyType(type, "Service");
|
|
32
|
+
if (initializerState && name !== undefined && shape !== undefined && callerContextData(checker, shape, name)) {
|
|
33
|
+
contextData.add(type);
|
|
34
|
+
contextData.add(shape);
|
|
35
|
+
shapes.delete(shape);
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
if (shape !== undefined && contextData.has(shape)) {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
30
41
|
if (
|
|
31
42
|
shape !== undefined
|
|
32
43
|
&& shape.flags & ts.TypeFlags.Object
|
|
33
44
|
&& (shape.getProperties().length > 0 || shape.getCallSignatures().length > 0)
|
|
34
45
|
&& checker.getIndexInfosOfType(shape).length === 0
|
|
35
|
-
&& !options(shape)
|
|
46
|
+
&& (initializerState || !options(shape))
|
|
36
47
|
&& (shape.getCallSignatures().length === 0 || type.getProperty("~effect/Context/Reference") === undefined)
|
|
37
48
|
) {
|
|
38
49
|
shapes.add(shape);
|
|
@@ -61,6 +72,7 @@ export function serviceTypes(checker: ts.TypeChecker) {
|
|
|
61
72
|
function carries(type: ts.Type, seen = new Set<ts.Type>()): boolean {
|
|
62
73
|
if (
|
|
63
74
|
seen.has(type)
|
|
75
|
+
|| contextData.has(type)
|
|
64
76
|
|| type.flags
|
|
65
77
|
& (ts.TypeFlags.Any
|
|
66
78
|
| ts.TypeFlags.Unknown
|
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
import { posix } from "node:path";
|
|
2
2
|
import { Effect, Schema } from "effect";
|
|
3
3
|
import { ignorePatterns } from "#adapters/ignore.ts";
|
|
4
|
+
import { serviceAssemblyImports } from "#adapters/serviceAssemblyImports.ts";
|
|
5
|
+
import { directServiceDefinitions } from "#adapters/serviceAssemblySyntax.ts";
|
|
4
6
|
import { GlobDeclarations, globPatterns, validateGlobs } from "#config/globs.ts";
|
|
5
7
|
import { routeFiles } from "#inventory/routeFiles.ts";
|
|
8
|
+
import { knownDataExports } from "#naming/adapters/plainData.ts";
|
|
9
|
+
import { constantModule } from "#naming/constantModule.ts";
|
|
6
10
|
import { exportFits } from "#naming/exportFits.ts";
|
|
11
|
+
import { isMigrationFile } from "#naming/isMigrationFile.ts";
|
|
7
12
|
import { mainExport } from "#naming/mainExport.ts";
|
|
8
|
-
import { isMigrationFile } from "#naming/migrationFile.ts";
|
|
9
13
|
import { moduleRoot } from "#naming/moduleRoot.ts";
|
|
10
|
-
import {
|
|
14
|
+
import { ownExports } from "#naming/ownExports.ts";
|
|
11
15
|
import { type PackageLayout, packageLayout } from "#naming/packageLayout.ts";
|
|
12
16
|
import { CAMEL, KEBAB, sameWord, wordsOf } from "#naming/words.ts";
|
|
13
17
|
import { defineRule, type Finding, type SourceFile } from "#rule.ts";
|
|
@@ -49,9 +53,24 @@ function repeated(stem: string, folders: readonly string[]): string | undefined
|
|
|
49
53
|
function nameFinding(file: SourceFile, stem: string, folders: readonly string[]): string | undefined {
|
|
50
54
|
const source = parse(file);
|
|
51
55
|
const exports = source === undefined ? [] : ownExports(source);
|
|
52
|
-
const constants =
|
|
53
|
-
if (
|
|
54
|
-
|
|
56
|
+
const constants = exports.filter((entry) => entry.kind === "value" && entry.constant);
|
|
57
|
+
if (
|
|
58
|
+
source !== undefined
|
|
59
|
+
&& constants.length > 0
|
|
60
|
+
&& exports.every((entry) => entry.constant)
|
|
61
|
+
&& knownDataExports(
|
|
62
|
+
source,
|
|
63
|
+
exports.map((entry) => entry.name),
|
|
64
|
+
)
|
|
65
|
+
) {
|
|
66
|
+
return constantModule(stem, constants);
|
|
67
|
+
}
|
|
68
|
+
const remaining = exports.filter((entry) => entry.kind === "value" && !entry.constant);
|
|
69
|
+
const main = constants.length > 0 && remaining.length === 1 ? remaining[0] : undefined;
|
|
70
|
+
if (main !== undefined) {
|
|
71
|
+
return exportFits(main.name, stem, folders)
|
|
72
|
+
? undefined
|
|
73
|
+
: `"${stem}" does not name its export ${main.name}. ${SHAPES} Rename the file or the export.`;
|
|
55
74
|
}
|
|
56
75
|
const [only] = exports;
|
|
57
76
|
if (only === undefined) {
|
|
@@ -59,25 +78,34 @@ function nameFinding(file: SourceFile, stem: string, folders: readonly string[])
|
|
|
59
78
|
? undefined
|
|
60
79
|
: `"${stem}" exports nothing, so it is named in camelCase, such as setupTests.ts. A file that a package.json script or bin runs is kebab-case.`;
|
|
61
80
|
}
|
|
62
|
-
if (exports.some((entry) => exportFits(entry.name, stem, folders))) {
|
|
81
|
+
if (exports.some((entry) => !(entry.kind === "value" && entry.constant && remaining.length > 0) && exportFits(entry.name, stem, folders))) {
|
|
63
82
|
return undefined;
|
|
64
83
|
}
|
|
65
|
-
const
|
|
66
|
-
if (
|
|
67
|
-
return `"${stem}" does not name its export ${
|
|
84
|
+
const primary = mainExport(exports);
|
|
85
|
+
if (primary !== undefined) {
|
|
86
|
+
return `"${stem}" does not name its export ${primary.name}. ${SHAPES} Rename the file or the export.`;
|
|
68
87
|
}
|
|
69
88
|
return CAMEL.test(stem)
|
|
70
89
|
? undefined
|
|
71
|
-
: `"${stem}" exports several things, so it is a topic file named in camelCase, such as
|
|
90
|
+
: `"${stem}" exports several things, so it is a topic file named in camelCase, such as helpers.ts. Or split it so each file has one main export. ${SHAPES}`;
|
|
72
91
|
}
|
|
73
92
|
|
|
74
93
|
function findingsOf(file: SourceFile, layout: PackageLayout): readonly Finding[] {
|
|
94
|
+
const source = posix.basename(file.path) === "service.ts" ? parse(file) : undefined;
|
|
95
|
+
if (source !== undefined && directServiceDefinitions(source, serviceAssemblyImports(source).definitions).length > 0) {
|
|
96
|
+
return [];
|
|
97
|
+
}
|
|
75
98
|
const stem = stemOf(file.path);
|
|
76
99
|
const folders = layout.foldersOf(file.path);
|
|
77
100
|
if (layout.scripts.has(file.path) || file.text.startsWith(SHEBANG)) {
|
|
78
101
|
return KEBAB.test(stem)
|
|
79
102
|
? []
|
|
80
|
-
: [
|
|
103
|
+
: [
|
|
104
|
+
{
|
|
105
|
+
file: file.path,
|
|
106
|
+
message: `"${stem}" is run as a script, so it is named in kebab-case, such as build-docs.ts.`,
|
|
107
|
+
},
|
|
108
|
+
];
|
|
81
109
|
}
|
|
82
110
|
const root = moduleRoot(file.path);
|
|
83
111
|
const admin = root === undefined ? undefined : /^(?:client|server)\/(?<path>admin\/.+)$/u.exec(file.path.slice(root.length + 1))?.groups?.path;
|
|
@@ -100,8 +128,10 @@ export const namedAfterExport = defineRule({
|
|
|
100
128
|
.flatMap((file) => findingsOf(file, layout));
|
|
101
129
|
}),
|
|
102
130
|
description:
|
|
103
|
-
"A file is named after its main export
|
|
131
|
+
"A file is named after its main runtime export, ignoring private constants and plain-data constants beside it, with its folders as the prefix, including in test-support; module client/admin and server/admin files may repeat names from above the admin folder. defineService declarations use service.ts; TanStack Router configuration owns route filenames. A constants module holds only plain data and derived types, in a camelCase file named for words every constant shares (timeouts.ts), limits for max/min/limit constants, or defaults for default constants. Split unrelated constants. A file of several non-constant exports is a camelCase topic file, and a script is kebab-case. Rename the file or the export; nothing renames them for you.",
|
|
104
132
|
id: "files/named-after-export",
|
|
105
|
-
options: Schema.toStandardSchemaV1(NamedAfterExportOptions, {
|
|
133
|
+
options: Schema.toStandardSchemaV1(NamedAfterExportOptions, {
|
|
134
|
+
parseOptions: { errors: "all", onExcessProperty: "error" },
|
|
135
|
+
}),
|
|
106
136
|
validate: validateGlobs,
|
|
107
137
|
});
|
|
@@ -6,7 +6,7 @@ import { isTooling } from "#imports/isTooling.ts";
|
|
|
6
6
|
import { builtinName } from "#imports/packageName.ts";
|
|
7
7
|
import { packageOf, type WorkspacePackage } from "#imports/workspace.ts";
|
|
8
8
|
import { dependencyNames, type EntryPoint, entryPointsOf, isApplication, provider, SHIPPED_FIELDS } from "#manifests/entryPoints.ts";
|
|
9
|
-
import {
|
|
9
|
+
import { testCode } from "#naming/testCode.ts";
|
|
10
10
|
import { defineRule, type RuleInputs } from "#rule.ts";
|
|
11
11
|
import { bundleInputs } from "./bundleInputs.ts";
|
|
12
12
|
|
|
@@ -38,6 +38,7 @@ const manifestDependencies = Effect.fn("Imports.manifestDependencies")(function*
|
|
|
38
38
|
owner: WorkspacePackage,
|
|
39
39
|
graph: ImportGraph,
|
|
40
40
|
workspace: ReadonlyMap<string, string>,
|
|
41
|
+
isTestCode: (path: string) => boolean,
|
|
41
42
|
): Effect.fn.Return<ManifestDependencies> {
|
|
42
43
|
const path = posix.join(owner.directory, "package.json");
|
|
43
44
|
const manifest = yield* Effect.promise(() => readPackageManifest(inputs.readText, path));
|
|
@@ -45,7 +46,7 @@ const manifestDependencies = Effect.fn("Imports.manifestDependencies")(function*
|
|
|
45
46
|
return yield* Effect.die(new Error("the manifest is missing"));
|
|
46
47
|
}
|
|
47
48
|
return {
|
|
48
|
-
...bundleInputs(graph, owner, manifest, (candidate) => developmentFile(owner, candidate)),
|
|
49
|
+
...bundleInputs(graph, owner, manifest, (candidate) => developmentFile(owner, candidate, isTestCode)),
|
|
49
50
|
application: isApplication(manifest),
|
|
50
51
|
development: new Set(dependencyNames(manifest, "devDependencies")),
|
|
51
52
|
entryPoints: yield* Effect.promise(() => entryPointsOf(inputs, owner.directory, manifest, workspace)),
|
|
@@ -54,15 +55,21 @@ const manifestDependencies = Effect.fn("Imports.manifestDependencies")(function*
|
|
|
54
55
|
};
|
|
55
56
|
});
|
|
56
57
|
|
|
57
|
-
function developmentFile(owner: WorkspacePackage, path: string): boolean {
|
|
58
|
+
function developmentFile(owner: WorkspacePackage, path: string, isTestCode: (path: string) => boolean): boolean {
|
|
58
59
|
return isTestCode(path) || isTooling(owner.directory, path);
|
|
59
60
|
}
|
|
60
61
|
|
|
61
|
-
function developmentImport(
|
|
62
|
+
function developmentImport(
|
|
63
|
+
policy: ManifestDependencies | undefined,
|
|
64
|
+
owner: WorkspacePackage,
|
|
65
|
+
path: string,
|
|
66
|
+
runtime: ReadonlySet<string>,
|
|
67
|
+
isTestCode: (path: string) => boolean,
|
|
68
|
+
) {
|
|
62
69
|
if (runtime.has(path)) {
|
|
63
70
|
return false;
|
|
64
71
|
}
|
|
65
|
-
return developmentFile(owner, path) || policy?.privateFiles.has(path);
|
|
72
|
+
return developmentFile(owner, path, isTestCode) || policy?.privateFiles.has(path);
|
|
66
73
|
}
|
|
67
74
|
|
|
68
75
|
function declares(policy: ManifestDependencies, target: string, development: boolean): boolean {
|
|
@@ -88,6 +95,7 @@ function undeclared(owner: WorkspacePackage, policy: ManifestDependencies | unde
|
|
|
88
95
|
export const importsManifest = defineRule({
|
|
89
96
|
check: Effect.fn("Imports.check")(function* (inputs) {
|
|
90
97
|
const graph = yield* importGraph(inputs);
|
|
98
|
+
const isTestCode = yield* testCode(inputs);
|
|
91
99
|
const root: WorkspacePackage | undefined =
|
|
92
100
|
(yield* Effect.promise(() => readPackageManifest(inputs.readText, "package.json"))) === undefined ? undefined : { directory: ".", name: "." };
|
|
93
101
|
const owners = [...graph.packages, ...(root === undefined ? [] : [root])];
|
|
@@ -96,10 +104,10 @@ export const importsManifest = defineRule({
|
|
|
96
104
|
yield* Effect.forEach(
|
|
97
105
|
owners,
|
|
98
106
|
(owner) =>
|
|
99
|
-
Effect.map(
|
|
100
|
-
owner,
|
|
101
|
-
policy,
|
|
102
|
-
|
|
107
|
+
Effect.map(
|
|
108
|
+
manifestDependencies(inputs, owner, graph, workspace, isTestCode),
|
|
109
|
+
(policy): readonly [WorkspacePackage, ManifestDependencies] => [owner, policy],
|
|
110
|
+
),
|
|
103
111
|
{ concurrency: "unbounded" },
|
|
104
112
|
),
|
|
105
113
|
);
|
|
@@ -115,7 +123,7 @@ export const importsManifest = defineRule({
|
|
|
115
123
|
return [];
|
|
116
124
|
}
|
|
117
125
|
const policy = policies.get(owner);
|
|
118
|
-
const development = developmentImport(policy, owner, request.from, runtime) === true;
|
|
126
|
+
const development = developmentImport(policy, owner, request.from, runtime, isTestCode) === true;
|
|
119
127
|
if (policy !== undefined && declares(policy, target.name, development)) {
|
|
120
128
|
return [];
|
|
121
129
|
}
|
|
@@ -1,20 +1,21 @@
|
|
|
1
1
|
import { Effect } from "effect";
|
|
2
2
|
import { importGraph } from "#imports/graph.ts";
|
|
3
|
-
import {
|
|
3
|
+
import { testCode } from "#naming/testCode.ts";
|
|
4
4
|
import { defineRule } from "#rule.ts";
|
|
5
5
|
|
|
6
6
|
export const noTestCode = defineRule({
|
|
7
|
-
check: (inputs)
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
7
|
+
check: Effect.fn("Imports.check")(function* (inputs) {
|
|
8
|
+
const graph = yield* importGraph(inputs);
|
|
9
|
+
const isTestCode = yield* testCode(inputs);
|
|
10
|
+
return graph.edges
|
|
11
|
+
.filter((edge) => !isTestCode(edge.from) && edge.to.kind === "file" && isTestCode(edge.to.path))
|
|
12
|
+
.map((edge) => ({
|
|
13
|
+
file: edge.from,
|
|
14
|
+
line: edge.line,
|
|
15
|
+
message: `Imports test code through "${edge.specifier}". Move the shared code into a production module and import it from both production and tests.`,
|
|
16
|
+
subject: edge.specifier,
|
|
17
|
+
}));
|
|
18
|
+
}),
|
|
18
19
|
description: "Production modules import production code. Move shared code out of test files and test-support/ into a production module.",
|
|
19
20
|
id: "imports/no-test-code",
|
|
20
21
|
registrable: false,
|
package/src/rules/maxLines.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Effect, Schema } from "effect";
|
|
2
|
-
import {
|
|
2
|
+
import { testCode } from "#naming/testCode.ts";
|
|
3
3
|
import { defineRule, type Finding, type SourceFile } from "#rule.ts";
|
|
4
4
|
|
|
5
5
|
const DECLARATION = /\.d\.[cm]?ts$/u;
|
|
@@ -25,8 +25,12 @@ function oversized(file: SourceFile, limit: number): readonly Finding[] {
|
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
export const maxLines = defineRule({
|
|
28
|
-
check: (
|
|
29
|
-
|
|
28
|
+
check: Effect.fn("Structure.check")(function* (inputs) {
|
|
29
|
+
const isTestCode = yield* testCode(inputs);
|
|
30
|
+
return inputs.sources
|
|
31
|
+
.filter((file) => !DECLARATION.test(file.path))
|
|
32
|
+
.flatMap((file) => oversized(file, isTestCode(file.path) ? inputs.options.test : inputs.options.source));
|
|
33
|
+
}),
|
|
30
34
|
description: "Keep each module to one job. Split a long file along its responsibilities; never golf it under the limit.",
|
|
31
35
|
id: "structure/max-lines",
|
|
32
36
|
options: Schema.toStandardSchemaV1(MaxLinesOptions, { parseOptions: { errors: "all", onExcessProperty: "error" } }),
|
|
@@ -1,12 +1,22 @@
|
|
|
1
1
|
import { Effect } from "effect";
|
|
2
|
+
import { pureReader } from "#adapters/pureReader.ts";
|
|
3
|
+
import { specReaderSources } from "#adapters/specReaderSources.ts";
|
|
2
4
|
import { defineRule } from "#rule.ts";
|
|
3
5
|
import { storySources } from "./sources.ts";
|
|
4
|
-
import {
|
|
6
|
+
import { findingAt, topLevelHelpers } from "./syntax.ts";
|
|
5
7
|
|
|
6
|
-
const MESSAGE =
|
|
8
|
+
const MESSAGE =
|
|
9
|
+
"Declares a setup or action helper in a spec. Move the action into the story kit's verbs or the setup into its traits in test-support/.";
|
|
7
10
|
|
|
8
11
|
export const specHelpers = defineRule({
|
|
9
|
-
check: (inputs) =>
|
|
10
|
-
|
|
12
|
+
check: (inputs) =>
|
|
13
|
+
Effect.map(storySources(inputs), (stories) =>
|
|
14
|
+
specReaderSources(stories).flatMap(({ source, readCall }) =>
|
|
15
|
+
topLevelHelpers(source)
|
|
16
|
+
.filter((node) => !pureReader(node, readCall))
|
|
17
|
+
.map((node) => findingAt(source, node, MESSAGE)),
|
|
18
|
+
),
|
|
19
|
+
),
|
|
20
|
+
description: "Specs state expectations and may keep pure matchers and readers; story-kit traits and verbs in test-support own setup and actions.",
|
|
11
21
|
id: "tests/spec-helpers",
|
|
12
22
|
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { defineRule, type Finding, type RuleInputs } from "#rule.ts";
|
|
2
2
|
import { type SourceComment, scanComments } from "#rules/comments/scan.ts";
|
|
3
|
-
import { suppressionIn } from "./
|
|
3
|
+
import { suppressionIn } from "./in.ts";
|
|
4
4
|
import { STYLESHEET, stylesheetComments } from "./stylesheetComments.ts";
|
|
5
5
|
|
|
6
6
|
const TYPE_TEST = /(?:(?:^|\/)typecheck\.test|\.typecheck\.(?:test|spec))\.[cm]?[jt]sx?$/u;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { posix } from "node:path";
|
|
2
|
-
import { Schema } from "effect";
|
|
2
|
+
import { Effect, Schema } from "effect";
|
|
3
3
|
import { ignorePatterns } from "#adapters/ignore.ts";
|
|
4
4
|
import { GlobDeclarations, globPatterns, validateGlobs } from "#config/globs.ts";
|
|
5
|
+
import { packageTests } from "#naming/packageTests.ts";
|
|
5
6
|
import { isTestCode, testName } from "#naming/testName.ts";
|
|
6
7
|
import { defineRule, type Finding } from "#rule.ts";
|
|
7
8
|
|
|
@@ -31,11 +32,13 @@ function findingOf(path: string, sourceFolders: ReadonlySet<string>): readonly F
|
|
|
31
32
|
}
|
|
32
33
|
|
|
33
34
|
export const testsColocated = defineRule({
|
|
34
|
-
check: (
|
|
35
|
+
check: Effect.fn("Tests.check")(function* (inputs) {
|
|
36
|
+
const { files, options } = inputs;
|
|
37
|
+
const trees = yield* packageTests(inputs);
|
|
35
38
|
const suites = ignorePatterns([...globPatterns(options.suites)]);
|
|
36
39
|
const sourceFolders = new Set(files.filter((path) => !isTestCode(path)).map((path) => posix.dirname(path)));
|
|
37
|
-
return files.filter((path) => !suites.ignores(path)).flatMap((path) => findingOf(path, sourceFolders));
|
|
38
|
-
},
|
|
40
|
+
return files.filter((path) => !suites.ignores(path) && trees.sourcePath(path) === undefined).flatMap((path) => findingOf(path, sourceFolders));
|
|
41
|
+
}),
|
|
39
42
|
description:
|
|
40
43
|
"A test sits beside the code it covers, at its module root or directly beside its module folder. Outside declared suites, __tests__ is always a test folder; test, tests and spec are test folders only when their directly contained checked files are all tests or test support. Shared test support belongs in test-support/.",
|
|
41
44
|
id: "tests/colocated",
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { posix } from "node:path";
|
|
2
|
-
import { Schema } from "effect";
|
|
2
|
+
import { Effect, Schema } from "effect";
|
|
3
3
|
import { ignorePatterns } from "#adapters/ignore.ts";
|
|
4
4
|
import { GlobDeclarations, globPatterns, validateGlobs } from "#config/globs.ts";
|
|
5
|
+
import { packageTests } from "#naming/packageTests.ts";
|
|
5
6
|
import { ENVIRONMENTS, type TestName, testName } from "#naming/testName.ts";
|
|
6
7
|
import { CAMEL } from "#naming/words.ts";
|
|
7
8
|
import { defineRule, type Finding, type SourceFile } from "#rule.ts";
|
|
@@ -67,22 +68,28 @@ function environmentMessage(file: string, name: TestName, source: SourceFile): s
|
|
|
67
68
|
return `"${file}" uses the DOM, so it is ${name.stem}.dom.${name.kind}${name.extension}${unit} and runs in the dom project.`;
|
|
68
69
|
}
|
|
69
70
|
|
|
70
|
-
function findingsOf(source: SourceFile, siblings: ReadonlySet<string
|
|
71
|
+
function findingsOf(source: SourceFile, siblings: ReadonlySet<string>, sourcePath: (path: string) => string | undefined): readonly Finding[] {
|
|
71
72
|
const name = testName(source.path);
|
|
72
73
|
if (name === undefined) {
|
|
73
74
|
return [];
|
|
74
75
|
}
|
|
75
76
|
const file = posix.basename(source.path);
|
|
76
|
-
const messages = [
|
|
77
|
+
const messages = [
|
|
78
|
+
suffixMessage(file, name),
|
|
79
|
+
placeMessage(file, { ...name, folder: posix.dirname(sourcePath(source.path) ?? source.path) }, siblings),
|
|
80
|
+
environmentMessage(file, name, source),
|
|
81
|
+
];
|
|
77
82
|
return messages.flatMap((message) => (message === undefined ? [] : [{ file: source.path, message }]));
|
|
78
83
|
}
|
|
79
84
|
|
|
80
85
|
export const testsFollow = defineRule({
|
|
81
|
-
check: (
|
|
86
|
+
check: Effect.fn("Tests.check")(function* (inputs) {
|
|
87
|
+
const { files, options, sources } = inputs;
|
|
88
|
+
const trees = yield* packageTests(inputs);
|
|
82
89
|
const suites = ignorePatterns([...globPatterns(options.suites)]);
|
|
83
90
|
const siblings = siblingsIn(files);
|
|
84
|
-
return sources.filter((source) => !suites.ignores(source.path)).flatMap((source) => findingsOf(source, siblings));
|
|
85
|
-
},
|
|
91
|
+
return sources.filter((source) => !suites.ignores(source.path)).flatMap((source) => findingsOf(source, siblings, trees.sourcePath));
|
|
92
|
+
}),
|
|
86
93
|
description:
|
|
87
94
|
"A .test file follows the file beside it, a .spec names a behaviour of its folder, the only suffix is one modifier of dom, heavy, slow, typecheck and unit, and a test that uses the DOM is a .dom test.",
|
|
88
95
|
id: "tests/follow",
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { Effect } from "effect";
|
|
2
|
-
import type ts from "typescript";
|
|
3
|
-
export declare const ImportCompiler: import("effect/Context").Service<"@shivaedev/quality/ImportCompiler", Readonly<{
|
|
4
|
-
readonly browserChecker: (source: ts.SourceFile) => Effect.Effect<ts.TypeChecker, never, never>;
|
|
5
|
-
readonly departures: (inputs: import("../rule.ts").RuleInputs, packages: readonly import("../imports/workspace.ts").WorkspacePackage[]) => Effect.Effect<readonly import("../imports/departures.ts").Departure[], import("./ImportAnalysisFailure.ts").ImportAnalysisFailure, never>;
|
|
6
|
-
readonly graph: (inputs: import("../rule.ts").RuleInputs) => Effect.Effect<Pick<import("../imports/graph.ts").ImportGraph, "configFindings" | "edges" | "modules" | "unresolved">, import("./ImportAnalysisFailure.ts").ImportAnalysisFailure, never>;
|
|
7
|
-
}>> & {
|
|
8
|
-
readonly layer: import("effect/Layer").Layer<"@shivaedev/quality/ImportCompiler", never, never>;
|
|
9
|
-
};
|
|
10
|
-
//# sourceMappingURL=ImportCompiler.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ImportCompiler.d.ts","sourceRoot":"","sources":["../../src/adapters/ImportCompiler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,KAAK,EAAE,MAAM,YAAY,CAAC;AAMjC,eAAO,MAAM,cAAc;;;;;;CASzB,CAAC"}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { Effect } from "effect";
|
|
2
|
-
import { defineService } from "@shivaedev/service/defineService.ts";
|
|
3
|
-
import { analyzeDepartures } from "#adapters/imports/analyzeDepartures.ts";
|
|
4
|
-
import { analyzeGraph } from "#adapters/imports/analyzeGraph.ts";
|
|
5
|
-
import { checkBrowser } from "#adapters/imports/checkBrowser.ts";
|
|
6
|
-
export const ImportCompiler = defineService({
|
|
7
|
-
id: "@shivaedev/quality/ImportCompiler",
|
|
8
|
-
initialize: Effect.void,
|
|
9
|
-
methods: () => ({
|
|
10
|
-
browserChecker: checkBrowser,
|
|
11
|
-
departures: analyzeDepartures,
|
|
12
|
-
graph: analyzeGraph,
|
|
13
|
-
}),
|
|
14
|
-
requires: [],
|
|
15
|
-
});
|
|
16
|
-
//# sourceMappingURL=ImportCompiler.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ImportCompiler.js","sourceRoot":"","sources":["../../src/adapters/ImportCompiler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,OAAO,EAAE,aAAa,EAAE,MAAM,qCAAqC,CAAC;AACpE,OAAO,EAAE,iBAAiB,EAAE,MAAM,wCAAwC,CAAC;AAC3E,OAAO,EAAE,YAAY,EAAE,MAAM,mCAAmC,CAAC;AACjE,OAAO,EAAE,YAAY,EAAE,MAAM,mCAAmC,CAAC;AAEjE,MAAM,CAAC,MAAM,cAAc,GAAG,aAAa,CAAC;IAC3C,EAAE,EAAE,mCAAmC;IACvC,UAAU,EAAE,MAAM,CAAC,IAAI;IACvB,OAAO,EAAE,GAAG,EAAE,CAAC,CAAC;QACf,cAAc,EAAE,YAA+E;QAC/F,UAAU,EAAE,iBAAiB;QAC7B,KAAK,EAAE,YAAY;KACnB,CAAC;IACF,QAAQ,EAAE,EAAE;CACZ,CAAC,CAAC"}
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import { Effect } from "effect";
|
|
2
|
-
import type { WorkspacePackage } from "#imports/workspace.ts";
|
|
3
|
-
import type { RuleInputs } from "#rule.ts";
|
|
4
|
-
export declare const analyzeDepartures: (inputs: RuleInputs, packages: readonly WorkspacePackage[]) => Effect.Effect<readonly import("../../imports/departures.ts").Departure[], import("../ImportAnalysisFailure.ts").ImportAnalysisFailure, never>;
|
|
5
|
-
//# sourceMappingURL=analyzeDepartures.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"analyzeDepartures.d.ts","sourceRoot":"","sources":["../../../src/adapters/imports/analyzeDepartures.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAC9D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAI3C,eAAO,MAAM,iBAAiB,8MAE7B,CAAC"}
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import { Effect } from "effect";
|
|
2
|
-
import { analysisFailure } from "./analysisFailure.js";
|
|
3
|
-
import { departures } from "./departures.js";
|
|
4
|
-
export const analyzeDepartures = Effect.fn("ImportCompiler.analyzeDepartures")((inputs, packages) => Effect.try({ catch: (cause) => analysisFailure(inputs.root, cause), try: () => departures(inputs, packages) }));
|
|
5
|
-
//# sourceMappingURL=analyzeDepartures.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"analyzeDepartures.js","sourceRoot":"","sources":["../../../src/adapters/imports/analyzeDepartures.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAGhC,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAE7C,MAAM,CAAC,MAAM,iBAAiB,GAAG,MAAM,CAAC,EAAE,CAAC,kCAAkC,CAAC,CAAC,CAAC,MAAkB,EAAE,QAAqC,EAAE,EAAE,CAC5I,MAAM,CAAC,GAAG,CAAC,EAAE,KAAK,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,eAAe,CAAC,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC,UAAU,CAAC,MAAM,EAAE,QAAQ,CAAC,EAAE,CAAC,CAC9G,CAAC"}
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import { Effect } from "effect";
|
|
2
|
-
import type { RuleInputs } from "#rule.ts";
|
|
3
|
-
export declare const analyzeGraph: (inputs: RuleInputs) => Effect.Effect<Pick<import("../../imports/graph.ts").ImportGraph, "configFindings" | "edges" | "modules" | "unresolved">, import("../ImportAnalysisFailure.ts").ImportAnalysisFailure, never>;
|
|
4
|
-
//# sourceMappingURL=analyzeGraph.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"analyzeGraph.d.ts","sourceRoot":"","sources":["../../../src/adapters/imports/analyzeGraph.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAI3C,eAAO,MAAM,YAAY,sNAExB,CAAC"}
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { realpathSync } from "node:fs";
|
|
2
|
-
import { Effect } from "effect";
|
|
3
|
-
import { analysisFailure } from "./analysisFailure.js";
|
|
4
|
-
import { graph } from "./graph.js";
|
|
5
|
-
export const analyzeGraph = Effect.fn("ImportCompiler.analyzeGraph")((inputs) => Effect.try({ catch: (cause) => analysisFailure(inputs.root, cause), try: () => graph(inputs, realpathSync(inputs.root)) }));
|
|
6
|
-
//# sourceMappingURL=analyzeGraph.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"analyzeGraph.js","sourceRoot":"","sources":["../../../src/adapters/imports/analyzeGraph.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAEnC,MAAM,CAAC,MAAM,YAAY,GAAG,MAAM,CAAC,EAAE,CAAC,6BAA6B,CAAC,CAAC,CAAC,MAAkB,EAAE,EAAE,CAC3F,MAAM,CAAC,GAAG,CAAC,EAAE,KAAK,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,eAAe,CAAC,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC,KAAK,CAAC,MAAM,EAAE,YAAY,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,CAC1H,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"checkBrowser.d.ts","sourceRoot":"","sources":["../../../src/adapters/imports/checkBrowser.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,KAAK,EAAE,MAAM,YAAY,CAAC;AAGjC,eAAO,MAAM,YAAY,wEAAiH,CAAC"}
|