@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,86 @@
|
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
import { initializerDependency } from "#adapters/initializerDependency.ts";
|
|
3
|
+
import { serviceProperty } from "#adapters/serviceAssemblySyntax.ts";
|
|
4
|
+
import { effectSuccess, resolvedValue } from "#adapters/serviceModelSyntax.ts";
|
|
5
|
+
import type { serviceTypes } from "#rules/effect/serviceTypes.ts";
|
|
6
|
+
import { returnValues } from "#rules/stories/returnValues.ts";
|
|
7
|
+
|
|
8
|
+
function capturesDependency(
|
|
9
|
+
checker: ts.TypeChecker,
|
|
10
|
+
value: ts.Node,
|
|
11
|
+
services: ReturnType<typeof serviceTypes>,
|
|
12
|
+
seen = new Set<ts.Node>(),
|
|
13
|
+
closing = false,
|
|
14
|
+
): boolean {
|
|
15
|
+
if (seen.has(value)) {
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
seen.add(value);
|
|
19
|
+
if (ts.isYieldExpression(value) && value.expression !== undefined && services.carries(checker.getTypeAtLocation(value.expression))) {
|
|
20
|
+
return true;
|
|
21
|
+
}
|
|
22
|
+
if (
|
|
23
|
+
!closing
|
|
24
|
+
&& ts.isExpression(value)
|
|
25
|
+
&& checker.getTypeAtLocation(value).flags & (ts.TypeFlags.StringLike | ts.TypeFlags.NumberLike | ts.TypeFlags.BooleanLike)
|
|
26
|
+
) {
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
if (ts.isCallExpression(value)) {
|
|
30
|
+
const owner = ts.isPropertyAccessExpression(value.expression) ? value.expression.expression : undefined;
|
|
31
|
+
return (
|
|
32
|
+
(owner !== undefined && services.implementation(checker.getTypeAtLocation(owner)))
|
|
33
|
+
|| value.arguments.some((argument) => capturesDependency(checker, argument, services, seen, closing))
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
if (ts.isIdentifier(value)) {
|
|
37
|
+
if (services.carries(checker.getTypeAtLocation(value))) {
|
|
38
|
+
return true;
|
|
39
|
+
}
|
|
40
|
+
const resolved = resolvedValue(checker, value);
|
|
41
|
+
return resolved !== value && capturesDependency(checker, resolved, services, seen, closing);
|
|
42
|
+
}
|
|
43
|
+
return (
|
|
44
|
+
ts.forEachChild(value, (child) => capturesDependency(checker, child, services, seen, closing || ts.isFunctionLike(value)) || undefined) ?? false
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export function serviceStateProblems(
|
|
49
|
+
checker: ts.TypeChecker,
|
|
50
|
+
config: ts.ObjectLiteralExpression,
|
|
51
|
+
services: ReturnType<typeof serviceTypes>,
|
|
52
|
+
): readonly { node: ts.Node; message: string }[] {
|
|
53
|
+
const initialize = serviceProperty(config, "initialize");
|
|
54
|
+
if (initialize === undefined) {
|
|
55
|
+
return [];
|
|
56
|
+
}
|
|
57
|
+
const state = effectSuccess(checker, checker.getTypeAtLocation(initialize));
|
|
58
|
+
let dependency =
|
|
59
|
+
services.carries(checker.getTypeAtLocation(initialize))
|
|
60
|
+
|| (state !== undefined && (services.carries(state) || initializerDependency(checker, state)));
|
|
61
|
+
const initializer = resolvedValue(checker, initialize);
|
|
62
|
+
// A function in state can hide a service even when its public type does not carry it.
|
|
63
|
+
function inspect(node: ts.Node): void {
|
|
64
|
+
if (ts.isFunctionLike(node)) {
|
|
65
|
+
for (const value of returnValues(node)) {
|
|
66
|
+
if (value !== undefined && capturesDependency(checker, value, services)) {
|
|
67
|
+
dependency = true;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
ts.forEachChild(node, inspect);
|
|
73
|
+
}
|
|
74
|
+
if (!dependency) {
|
|
75
|
+
inspect(initializer);
|
|
76
|
+
}
|
|
77
|
+
return dependency
|
|
78
|
+
? [
|
|
79
|
+
{
|
|
80
|
+
message:
|
|
81
|
+
"Initializer state carries a dependency. Declare it in requires and yield it in each operation. Keep only owned caches, refs, locks and captured context data in initialize; choose their lifetime where the Layer is registered.",
|
|
82
|
+
node: initialize,
|
|
83
|
+
},
|
|
84
|
+
]
|
|
85
|
+
: [];
|
|
86
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
import type { SourceFile } from "#rule.ts";
|
|
3
|
+
import { parse } from "#rules/parse.ts";
|
|
4
|
+
import { topLevelHelpers, unwrapped } from "#rules/stories/syntax.ts";
|
|
5
|
+
import { asymmetricMatcher } from "./asymmetricMatcher.ts";
|
|
6
|
+
|
|
7
|
+
const READ_METHODS = new Set([
|
|
8
|
+
"at",
|
|
9
|
+
"concat",
|
|
10
|
+
"endsWith",
|
|
11
|
+
"entries",
|
|
12
|
+
"every",
|
|
13
|
+
"filter",
|
|
14
|
+
"find",
|
|
15
|
+
"findIndex",
|
|
16
|
+
"flat",
|
|
17
|
+
"flatMap",
|
|
18
|
+
"get",
|
|
19
|
+
"has",
|
|
20
|
+
"includes",
|
|
21
|
+
"indexOf",
|
|
22
|
+
"join",
|
|
23
|
+
"keys",
|
|
24
|
+
"lastIndexOf",
|
|
25
|
+
"map",
|
|
26
|
+
"match",
|
|
27
|
+
"reduce",
|
|
28
|
+
"replace",
|
|
29
|
+
"slice",
|
|
30
|
+
"some",
|
|
31
|
+
"split",
|
|
32
|
+
"startsWith",
|
|
33
|
+
"substring",
|
|
34
|
+
"toLowerCase",
|
|
35
|
+
"toUpperCase",
|
|
36
|
+
"trim",
|
|
37
|
+
"values",
|
|
38
|
+
]);
|
|
39
|
+
|
|
40
|
+
export function specReaderSources(files: readonly SourceFile[]) {
|
|
41
|
+
const sources = files.flatMap((file) => {
|
|
42
|
+
const source = parse(file);
|
|
43
|
+
return source === undefined || topLevelHelpers(source).length === 0 ? [] : [source];
|
|
44
|
+
});
|
|
45
|
+
if (sources.length === 0) {
|
|
46
|
+
return [];
|
|
47
|
+
}
|
|
48
|
+
const options: ts.CompilerOptions = { allowJs: true, noResolve: true, target: ts.ScriptTarget.ESNext, types: [] };
|
|
49
|
+
const host = ts.createCompilerHost(options);
|
|
50
|
+
const getSourceFile = host.getSourceFile;
|
|
51
|
+
const parsed = new Map(sources.map((source) => [source.fileName, source]));
|
|
52
|
+
host.getSourceFile = (path, ...args) => parsed.get(path) ?? getSourceFile(path, ...args);
|
|
53
|
+
const program = ts.createProgram([...parsed.keys()], options, host);
|
|
54
|
+
const checker = program.getTypeChecker();
|
|
55
|
+
function readCall(call: ts.CallExpression): boolean {
|
|
56
|
+
if (asymmetricMatcher(call, checker)) {
|
|
57
|
+
return true;
|
|
58
|
+
}
|
|
59
|
+
const target = unwrapped(call.expression);
|
|
60
|
+
if (!(ts.isPropertyAccessExpression(target) && READ_METHODS.has(target.name.text))) {
|
|
61
|
+
return false;
|
|
62
|
+
}
|
|
63
|
+
const declaration = checker.getResolvedSignature(call)?.declaration;
|
|
64
|
+
return (
|
|
65
|
+
declaration !== undefined
|
|
66
|
+
&& program.isSourceFileDefaultLibrary(declaration.getSourceFile())
|
|
67
|
+
&& call.arguments.every((argument) => {
|
|
68
|
+
if (ts.isArrowFunction(argument) || ts.isFunctionExpression(argument)) {
|
|
69
|
+
return true;
|
|
70
|
+
}
|
|
71
|
+
const type = checker.getTypeAtLocation(argument);
|
|
72
|
+
return (type.flags & (ts.TypeFlags.Any | ts.TypeFlags.Unknown)) === 0 && type.getCallSignatures().length === 0;
|
|
73
|
+
})
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
return sources.map((source) => ({ readCall, source }));
|
|
77
|
+
}
|
package/src/cli/args.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { parseArgs } from "node:util";
|
|
2
2
|
import { Result } from "effect";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import { ACCEPTS, misplaced, OPTIONS, type Values } from "./misplaced.ts";
|
|
4
|
+
import { SUBCOMMANDS } from "./subcommands.ts";
|
|
5
5
|
|
|
6
6
|
export type Command =
|
|
7
7
|
| { readonly _tag: "Ci"; readonly coverage: boolean }
|
package/src/cli/fix.ts
CHANGED
|
@@ -10,8 +10,7 @@ import { walk } from "#inventory/walk.ts";
|
|
|
10
10
|
import { sortManifests } from "#manifests/sorted.ts";
|
|
11
11
|
import { plural } from "#report/plural.ts";
|
|
12
12
|
import type { RuleServices } from "#rule.ts";
|
|
13
|
-
|
|
14
|
-
export const MAX_FIX_ROUNDS = 5;
|
|
13
|
+
import { MAX_FIX_ROUNDS } from "./limits.ts";
|
|
15
14
|
|
|
16
15
|
function isBinary(bytes: Uint8Array): boolean {
|
|
17
16
|
return bytes.includes(0);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const MAX_FIX_ROUNDS = 5;
|
package/src/cli/program.ts
CHANGED
|
@@ -18,7 +18,7 @@ import { preCommitHook } from "#hooks/preCommit.ts";
|
|
|
18
18
|
import { setupHook } from "#hooks/setup.ts";
|
|
19
19
|
import { hookStatus } from "#hooks/status.ts";
|
|
20
20
|
import { uninstallHook } from "#hooks/uninstall.ts";
|
|
21
|
-
import { USAGE } from "./
|
|
21
|
+
import { USAGE } from "./usage.ts";
|
|
22
22
|
|
|
23
23
|
export interface Invocation {
|
|
24
24
|
readonly cwd: string;
|
|
@@ -39,9 +39,3 @@ hooks pre-commit Check lint and staged baseline counts, then package.json scrip
|
|
|
39
39
|
--against <ref> The branch the work merges into, whose merge base prune follows moves from. Defaults to origin/HEAD, then origin/main, then origin/master.
|
|
40
40
|
--coverage Collect V8 coverage and JUnit from ci's single test run into coverage/, including failed tests.
|
|
41
41
|
Exit codes: 0 passed, 1 failed the gate, 2 could not run.`;
|
|
42
|
-
export const SUBCOMMANDS = {
|
|
43
|
-
baseline: "baseline takes write, prune, tighten, migrate, merge or install-driver.",
|
|
44
|
-
exceptions: "exceptions takes migrate.",
|
|
45
|
-
hooks: "hooks takes install, uninstall, status or pre-commit.",
|
|
46
|
-
};
|
|
47
|
-
//# sourceMappingURL=messages.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const CONFIG_FILE = "quality.config.ts";
|
package/src/config/load.ts
CHANGED
|
@@ -7,8 +7,8 @@ import type { SetupFailure } from "#failure.ts";
|
|
|
7
7
|
import type { InventoryScope } from "#inventory/collect.ts";
|
|
8
8
|
import { ConsumerDeclaration } from "#rules/suppressions/biome/ConsumerDeclaration.ts";
|
|
9
9
|
import type { Declaration } from "#rules/suppressions/biome/declarations.ts";
|
|
10
|
-
import { DEFAULT_EXTENSIONS } from "./constants.ts";
|
|
11
10
|
import { type ConfigInput, decodeConfig } from "./decode.ts";
|
|
11
|
+
import { DEFAULT_EXTENSIONS } from "./defaultExtensions.ts";
|
|
12
12
|
import { type ResolvedRules, resolveRules } from "./resolve.ts";
|
|
13
13
|
|
|
14
14
|
export interface ResolvedConfig extends ResolvedRules, InventoryScope {
|
package/src/hooks/install.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as NodePath from "@effect/platform-node/NodePath";
|
|
2
2
|
import { Console, Effect, FileSystem, Path } from "effect";
|
|
3
|
-
import { CONFIG_FILE } from "#config/
|
|
3
|
+
import { CONFIG_FILE } from "#config/file.ts";
|
|
4
4
|
import { loadConfig } from "#config/load.ts";
|
|
5
5
|
import { SetupFailure } from "#failure.ts";
|
|
6
6
|
import { gitOrFail } from "#git/command.ts";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Effect } from "effect";
|
|
2
2
|
import ts from "typescript";
|
|
3
|
-
import { ImportCompiler } from "#adapters/
|
|
3
|
+
import { ImportCompiler } from "#adapters/import-compiler/service.ts";
|
|
4
4
|
import type { Finding, SourceFile } from "#rule.ts";
|
|
5
5
|
import { parse } from "#rules/parse.ts";
|
|
6
6
|
import { browserNames } from "./browserNames.ts";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Effect } from "effect";
|
|
2
|
-
import { ImportCompiler } from "#adapters/
|
|
2
|
+
import { ImportCompiler } from "#adapters/import-compiler/service.ts";
|
|
3
3
|
import type { RuleInputs } from "#rule.ts";
|
|
4
4
|
import type { SpecifierSite } from "./specifiers.ts";
|
|
5
5
|
import { workspacePackages } from "./workspace.ts";
|
package/src/imports/graph.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Effect } from "effect";
|
|
2
|
-
import { ImportCompiler } from "#adapters/
|
|
2
|
+
import { ImportCompiler } from "#adapters/import-compiler/service.ts";
|
|
3
3
|
import type { Findings, RuleInputs, SourceFile } from "#rule.ts";
|
|
4
4
|
import type { Endpoint } from "./Endpoint.ts";
|
|
5
5
|
import type { ImportKind } from "./extract.ts";
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { ImportGraph } from "./graph.ts";
|
|
2
|
+
import { packageOf, type WorkspacePackage } from "./workspace.ts";
|
|
3
|
+
|
|
4
|
+
export function testComposition(graph: ImportGraph, privatePackages: readonly WorkspacePackage[], testFile: (path: string) => boolean) {
|
|
5
|
+
const candidates = new Set(privatePackages);
|
|
6
|
+
const imports = graph.edges.flatMap((edge) => {
|
|
7
|
+
const from = packageOf(graph.packages, edge.from);
|
|
8
|
+
const to = edge.to.kind === "file" ? packageOf(graph.packages, edge.to.path) : undefined;
|
|
9
|
+
return to === undefined || from === to ? [] : [{ from, path: edge.from, to }];
|
|
10
|
+
});
|
|
11
|
+
return compositions(imports, candidates, testFile);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
interface Consumer {
|
|
15
|
+
readonly from: WorkspacePackage | undefined;
|
|
16
|
+
readonly path: string;
|
|
17
|
+
readonly to: WorkspacePackage;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function compositions(imports: readonly Consumer[], candidates: ReadonlySet<WorkspacePackage>, testFile: (path: string) => boolean) {
|
|
21
|
+
const reached = new Set<WorkspacePackage>();
|
|
22
|
+
let changed = true;
|
|
23
|
+
while (changed) {
|
|
24
|
+
changed = false;
|
|
25
|
+
for (const edge of imports) {
|
|
26
|
+
if (candidates.has(edge.to) && !reached.has(edge.to) && (testFile(edge.path) || (edge.from !== undefined && reached.has(edge.from)))) {
|
|
27
|
+
reached.add(edge.to);
|
|
28
|
+
changed = true;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return withoutProductionConsumers(imports, reached, testFile);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function withoutProductionConsumers(imports: readonly Consumer[], reached: Set<WorkspacePackage>, testFile: (path: string) => boolean) {
|
|
36
|
+
let changed = true;
|
|
37
|
+
while (changed) {
|
|
38
|
+
changed = false;
|
|
39
|
+
for (const edge of imports) {
|
|
40
|
+
if (reached.has(edge.to) && !testFile(edge.path) && (edge.from === undefined || !reached.has(edge.from))) {
|
|
41
|
+
reached.delete(edge.to);
|
|
42
|
+
changed = true;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return reached;
|
|
47
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
|
|
3
|
+
const CONSTANT_CASE = /^[A-Z][A-Z0-9]*(?:_[A-Z0-9]+)*$/u;
|
|
4
|
+
|
|
5
|
+
const LITERALS: ReadonlySet<ts.SyntaxKind> = new Set([
|
|
6
|
+
ts.SyntaxKind.BigIntLiteral,
|
|
7
|
+
ts.SyntaxKind.FalseKeyword,
|
|
8
|
+
ts.SyntaxKind.NoSubstitutionTemplateLiteral,
|
|
9
|
+
ts.SyntaxKind.NullKeyword,
|
|
10
|
+
ts.SyntaxKind.NumericLiteral,
|
|
11
|
+
ts.SyntaxKind.RegularExpressionLiteral,
|
|
12
|
+
ts.SyntaxKind.StringLiteral,
|
|
13
|
+
ts.SyntaxKind.TrueKeyword,
|
|
14
|
+
]);
|
|
15
|
+
|
|
16
|
+
export function plainData(node: ts.Expression | undefined): boolean {
|
|
17
|
+
if (node === undefined) {
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
if (ts.isParenthesizedExpression(node) || ts.isAsExpression(node) || ts.isTypeAssertionExpression(node) || ts.isSatisfiesExpression(node)) {
|
|
21
|
+
return plainData(node.expression);
|
|
22
|
+
}
|
|
23
|
+
if (ts.isIdentifier(node)) {
|
|
24
|
+
return CONSTANT_CASE.test(node.text);
|
|
25
|
+
}
|
|
26
|
+
if (ts.isPrefixUnaryExpression(node)) {
|
|
27
|
+
return (
|
|
28
|
+
(node.operator === ts.SyntaxKind.PlusToken || node.operator === ts.SyntaxKind.MinusToken)
|
|
29
|
+
&& (ts.isNumericLiteral(node.operand) || ts.isBigIntLiteral(node.operand))
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
if (ts.isArrayLiteralExpression(node)) {
|
|
33
|
+
return node.elements.every(plainData);
|
|
34
|
+
}
|
|
35
|
+
if (ts.isObjectLiteralExpression(node)) {
|
|
36
|
+
return node.properties.every((property) =>
|
|
37
|
+
ts.isPropertyAssignment(property)
|
|
38
|
+
? !ts.isComputedPropertyName(property.name) && plainData(property.initializer)
|
|
39
|
+
: ts.isShorthandPropertyAssignment(property) && CONSTANT_CASE.test(property.name.text),
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
return LITERALS.has(node.kind);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function constantType(node: ts.TypeNode, constants: readonly string[]): boolean {
|
|
46
|
+
let queries = 0;
|
|
47
|
+
let valid = true;
|
|
48
|
+
function visit(child: ts.Node): void {
|
|
49
|
+
if (ts.isTypeQueryNode(child)) {
|
|
50
|
+
queries += 1;
|
|
51
|
+
let name = child.exprName;
|
|
52
|
+
while (ts.isQualifiedName(name)) {
|
|
53
|
+
name = name.left;
|
|
54
|
+
}
|
|
55
|
+
valid &&= constants.includes(name.text);
|
|
56
|
+
} else {
|
|
57
|
+
ts.forEachChild(child, visit);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
visit(node);
|
|
61
|
+
return valid && queries > 0;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export function knownDataExports(source: ts.SourceFile, names: readonly string[]): boolean {
|
|
65
|
+
return source.statements.every((statement) => {
|
|
66
|
+
if (ts.isExportDeclaration(statement)) {
|
|
67
|
+
return (
|
|
68
|
+
statement.moduleSpecifier === undefined
|
|
69
|
+
&& statement.exportClause !== undefined
|
|
70
|
+
&& ts.isNamedExports(statement.exportClause)
|
|
71
|
+
&& statement.exportClause.elements.every((entry) =>
|
|
72
|
+
names.includes(entry.name.text === "default" ? (entry.propertyName ?? entry.name).text : entry.name.text),
|
|
73
|
+
)
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
if (ts.isExportAssignment(statement)) {
|
|
77
|
+
return plainData(statement.expression);
|
|
78
|
+
}
|
|
79
|
+
const exported = ts.canHaveModifiers(statement) && ts.getModifiers(statement)?.some((modifier) => modifier.kind === ts.SyntaxKind.ExportKeyword);
|
|
80
|
+
if (!exported) {
|
|
81
|
+
return true;
|
|
82
|
+
}
|
|
83
|
+
if (ts.isVariableStatement(statement)) {
|
|
84
|
+
return statement.declarationList.declarations.every((entry) => ts.isIdentifier(entry.name));
|
|
85
|
+
}
|
|
86
|
+
return !(ts.isFunctionDeclaration(statement) || ts.isClassDeclaration(statement));
|
|
87
|
+
});
|
|
88
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { OwnExport } from "#naming/ownExports.ts";
|
|
2
|
+
import { CAMEL, sameWord, wordsOf } from "#naming/words.ts";
|
|
3
|
+
|
|
4
|
+
function sharedWords(constants: readonly OwnExport[]): readonly string[] {
|
|
5
|
+
return wordsOf(constants[0]?.name ?? "").filter((word) => constants.every((entry) => wordsOf(entry.name).some((own) => sameWord(own, word))));
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
function fits(stem: string, constants: readonly OwnExport[]): boolean {
|
|
9
|
+
if (!CAMEL.test(stem)) {
|
|
10
|
+
return false;
|
|
11
|
+
}
|
|
12
|
+
const words = wordsOf(stem);
|
|
13
|
+
return constants.every((entry) => {
|
|
14
|
+
const own = wordsOf(entry.name);
|
|
15
|
+
return stem === "limits"
|
|
16
|
+
? own.some((word) => ["max", "min", "limit"].some((limit) => sameWord(word, limit)))
|
|
17
|
+
: words.every((word) => own.some((constant) => sameWord(word, constant)));
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function constantModule(stem: string, constants: readonly OwnExport[]): string | undefined {
|
|
22
|
+
if (fits(stem, constants)) {
|
|
23
|
+
return undefined;
|
|
24
|
+
}
|
|
25
|
+
const candidates = sharedWords(constants);
|
|
26
|
+
const suggestion = candidates.length === 0 ? "" : ` Shared words: ${candidates.join(", ")}.`;
|
|
27
|
+
return `"${stem}" holds only plain-data constants. Name the module in camelCase after a word each constant carries, such as timeouts.ts for INSPECT_TIMEOUT_MILLIS and REMOTE_TIMEOUT_MILLIS, or split it.${suggestion} Put MAX_/MIN_ constants in limits.ts and DEFAULT_ constants in defaults.ts; every constant must fit the name.`;
|
|
28
|
+
}
|
package/src/naming/ownExports.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import ts from "typescript";
|
|
2
|
+
import { constantType, plainData } from "#naming/adapters/plainData.ts";
|
|
2
3
|
|
|
3
4
|
export interface OwnExport {
|
|
4
5
|
readonly constant: boolean;
|
|
@@ -6,27 +7,6 @@ export interface OwnExport {
|
|
|
6
7
|
readonly name: string;
|
|
7
8
|
}
|
|
8
9
|
|
|
9
|
-
const CONSTANT_CASE = /^[A-Z][A-Z0-9]*(?:_[A-Z0-9]+)*$/u;
|
|
10
|
-
|
|
11
|
-
const PRIMITIVE_LITERALS: ReadonlySet<ts.SyntaxKind> = new Set([
|
|
12
|
-
ts.SyntaxKind.BigIntLiteral,
|
|
13
|
-
ts.SyntaxKind.FalseKeyword,
|
|
14
|
-
ts.SyntaxKind.NoSubstitutionTemplateLiteral,
|
|
15
|
-
ts.SyntaxKind.NumericLiteral,
|
|
16
|
-
ts.SyntaxKind.StringLiteral,
|
|
17
|
-
ts.SyntaxKind.TrueKeyword,
|
|
18
|
-
]);
|
|
19
|
-
|
|
20
|
-
function isPrimitiveLiteral(node: ts.Expression | undefined): boolean {
|
|
21
|
-
if (node === undefined) {
|
|
22
|
-
return false;
|
|
23
|
-
}
|
|
24
|
-
if (ts.isPrefixUnaryExpression(node)) {
|
|
25
|
-
return isPrimitiveLiteral(node.operand);
|
|
26
|
-
}
|
|
27
|
-
return PRIMITIVE_LITERALS.has(node.kind);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
10
|
function isExported(statement: ts.Statement): boolean {
|
|
31
11
|
const modifiers = ts.canHaveModifiers(statement) ? ts.getModifiers(statement) : undefined;
|
|
32
12
|
return modifiers?.some((modifier) => modifier.kind === ts.SyntaxKind.ExportKeyword) ?? false;
|
|
@@ -38,7 +18,7 @@ function variables(statement: ts.VariableStatement): readonly OwnExport[] {
|
|
|
38
18
|
ts.isIdentifier(declaration.name)
|
|
39
19
|
? [
|
|
40
20
|
{
|
|
41
|
-
constant: constant && (
|
|
21
|
+
constant: constant && plainData(declaration.initializer),
|
|
42
22
|
kind: "value" as const,
|
|
43
23
|
name: declaration.name.text,
|
|
44
24
|
},
|
|
@@ -47,12 +27,12 @@ function variables(statement: ts.VariableStatement): readonly OwnExport[] {
|
|
|
47
27
|
);
|
|
48
28
|
}
|
|
49
29
|
|
|
50
|
-
function declared(statement: ts.Statement): readonly OwnExport[] {
|
|
30
|
+
function declared(statement: ts.Statement, constants: readonly string[] = []): readonly OwnExport[] {
|
|
51
31
|
if (ts.isVariableStatement(statement)) {
|
|
52
32
|
return variables(statement);
|
|
53
33
|
}
|
|
54
34
|
if (ts.isInterfaceDeclaration(statement) || ts.isTypeAliasDeclaration(statement)) {
|
|
55
|
-
return [{ constant:
|
|
35
|
+
return [{ constant: ts.isTypeAliasDeclaration(statement) && constantType(statement.type, constants), kind: "type", name: statement.name.text }];
|
|
56
36
|
}
|
|
57
37
|
const named =
|
|
58
38
|
ts.isFunctionDeclaration(statement) || ts.isClassDeclaration(statement) || ts.isEnumDeclaration(statement) || ts.isModuleDeclaration(statement)
|
|
@@ -61,8 +41,10 @@ function declared(statement: ts.Statement): readonly OwnExport[] {
|
|
|
61
41
|
return named !== undefined && ts.isIdentifier(named) ? [{ constant: false, kind: "value", name: named.text }] : [];
|
|
62
42
|
}
|
|
63
43
|
|
|
64
|
-
|
|
65
|
-
|
|
44
|
+
function ownDeclarations(source: ts.SourceFile): readonly OwnExport[] {
|
|
45
|
+
const values = source.statements.flatMap((statement) => (ts.isVariableStatement(statement) ? variables(statement) : []));
|
|
46
|
+
const constants = values.filter((entry) => entry.constant).map((entry) => entry.name);
|
|
47
|
+
return source.statements.flatMap((statement) => declared(statement, constants));
|
|
66
48
|
}
|
|
67
49
|
|
|
68
50
|
function locals(source: ts.SourceFile): ReadonlyMap<string, OwnExport> {
|
|
@@ -108,7 +90,8 @@ function defaulted(statement: ts.ExportAssignment, known: ReadonlyMap<string, Ow
|
|
|
108
90
|
if (name === undefined) {
|
|
109
91
|
return [];
|
|
110
92
|
}
|
|
111
|
-
|
|
93
|
+
const local = known.get(name);
|
|
94
|
+
return [{ constant: local?.constant === true && plainData(statement.expression), kind: local?.kind ?? "value", name }];
|
|
112
95
|
}
|
|
113
96
|
|
|
114
97
|
function exportsOf(statement: ts.Statement, known: ReadonlyMap<string, OwnExport>): readonly OwnExport[] {
|
|
@@ -118,7 +101,7 @@ function exportsOf(statement: ts.Statement, known: ReadonlyMap<string, OwnExport
|
|
|
118
101
|
if (ts.isExportAssignment(statement)) {
|
|
119
102
|
return defaulted(statement, known);
|
|
120
103
|
}
|
|
121
|
-
return isExported(statement) ? declared(statement) : [];
|
|
104
|
+
return isExported(statement) ? declared(statement).map((entry) => known.get(entry.name) ?? entry) : [];
|
|
122
105
|
}
|
|
123
106
|
|
|
124
107
|
export function ownExports(source: ts.SourceFile): readonly OwnExport[] {
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Effect, Path } from "effect";
|
|
2
|
+
import { readPackageManifest } from "#adapters/manifestInventory.ts";
|
|
3
|
+
import { packageOf, workspacePackages } from "#imports/workspace.ts";
|
|
4
|
+
import type { RuleInputs } from "#rule.ts";
|
|
5
|
+
|
|
6
|
+
export const packageTests = Effect.fn("Tests.packageTests")(function* (inputs: RuleInputs) {
|
|
7
|
+
const posix = yield* Path.Path.pipe(Effect.provide(Path.layer));
|
|
8
|
+
const packages = [...(yield* Effect.promise(() => workspacePackages(inputs)))];
|
|
9
|
+
if ((yield* Effect.promise(() => readPackageManifest(inputs.readText, "package.json"))) !== undefined) {
|
|
10
|
+
packages.push({ directory: ".", name: "." });
|
|
11
|
+
}
|
|
12
|
+
const withSource = new Set(
|
|
13
|
+
packages.filter((owner) => inputs.files.some((path) => path.startsWith(`${owner.directory === "." ? "" : `${owner.directory}/`}src/`))),
|
|
14
|
+
);
|
|
15
|
+
function sourcePath(path: string): string | undefined {
|
|
16
|
+
const owner = packageOf(packages, path) ?? packages.find((candidate) => candidate.directory === ".");
|
|
17
|
+
if (owner === undefined || !withSource.has(owner)) {
|
|
18
|
+
return undefined;
|
|
19
|
+
}
|
|
20
|
+
const local = posix.relative(owner.directory, path);
|
|
21
|
+
return local.startsWith("test/") ? posix.join(owner.directory, "src", local.slice("test/".length)) : undefined;
|
|
22
|
+
}
|
|
23
|
+
return { packages, sourcePath };
|
|
24
|
+
});
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { Effect, Path } from "effect";
|
|
2
|
+
import { readPackageManifest } from "#adapters/manifestInventory.ts";
|
|
3
|
+
import { scriptPaths } from "#adapters/scriptPaths.ts";
|
|
4
|
+
import { importGraph } from "#imports/graph.ts";
|
|
5
|
+
import { isTooling } from "#imports/isTooling.ts";
|
|
6
|
+
import { testComposition } from "#imports/testComposition.ts";
|
|
7
|
+
import { packageOf } from "#imports/workspace.ts";
|
|
8
|
+
import type { RuleInputs } from "#rule.ts";
|
|
9
|
+
import { packageTests } from "./packageTests.ts";
|
|
10
|
+
import { isTestCode } from "./testName.ts";
|
|
11
|
+
|
|
12
|
+
export const testCode = Effect.fn("Tests.testCode")(function* (inputs: RuleInputs) {
|
|
13
|
+
const posix = yield* Path.Path.pipe(Effect.provide(Path.layer));
|
|
14
|
+
const trees = yield* packageTests(inputs);
|
|
15
|
+
function testFile(path: string) {
|
|
16
|
+
return isTestCode(path) || trees.sourcePath(path) !== undefined;
|
|
17
|
+
}
|
|
18
|
+
const policies = yield* Effect.forEach(trees.packages, (owner) =>
|
|
19
|
+
Effect.map(
|
|
20
|
+
Effect.promise(() => readPackageManifest(inputs.readText, posix.join(owner.directory, "package.json"))),
|
|
21
|
+
(manifest) => ({
|
|
22
|
+
owner,
|
|
23
|
+
private: manifest?.private === true && manifest.bin === undefined && owner.directory !== ".",
|
|
24
|
+
scripts: scriptPaths(
|
|
25
|
+
owner.directory,
|
|
26
|
+
Object.fromEntries(Object.entries(manifest?.scripts ?? {}).filter(([name]) => !/^test(?::|$)/u.test(name))),
|
|
27
|
+
),
|
|
28
|
+
}),
|
|
29
|
+
),
|
|
30
|
+
);
|
|
31
|
+
if (!(policies.some((policy) => policy.private) && inputs.sources.some((file) => /\.[cm]?[jt]sx?$/u.test(file.path)))) {
|
|
32
|
+
return testFile;
|
|
33
|
+
}
|
|
34
|
+
const graph = yield* importGraph(inputs);
|
|
35
|
+
const directories = new Set(policies.filter((policy) => policy.private).map((policy) => policy.owner.directory));
|
|
36
|
+
const scripted = new Set(policies.flatMap((policy) => policy.scripts));
|
|
37
|
+
for (const path of graph.modules) {
|
|
38
|
+
const owner = packageOf(graph.packages, path);
|
|
39
|
+
if (owner === undefined) {
|
|
40
|
+
continue;
|
|
41
|
+
}
|
|
42
|
+
const built = posix.join(
|
|
43
|
+
owner.directory,
|
|
44
|
+
posix
|
|
45
|
+
.relative(owner.directory, path)
|
|
46
|
+
.replace(/^src\//u, "dist/")
|
|
47
|
+
.replace(/\.(?<mode>[cm]?)tsx?$/u, ".$<mode>js"),
|
|
48
|
+
);
|
|
49
|
+
if (!(testFile(path) || isTooling(owner.directory, path)) && (scripted.has(path) || scripted.has(built))) {
|
|
50
|
+
directories.delete(owner.directory);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
const composition = testComposition(
|
|
54
|
+
graph,
|
|
55
|
+
graph.packages.filter((owner) => directories.has(owner.directory)),
|
|
56
|
+
testFile,
|
|
57
|
+
);
|
|
58
|
+
return (path: string) => {
|
|
59
|
+
const owner = packageOf(graph.packages, path);
|
|
60
|
+
return testFile(path) || (owner !== undefined && composition.has(owner));
|
|
61
|
+
};
|
|
62
|
+
});
|
package/src/rules/builtIn.ts
CHANGED
|
@@ -9,16 +9,7 @@ import { agentLinks } from "#rules/docs/agentLinks.ts";
|
|
|
9
9
|
import { docsReferences } from "#rules/docs/references.ts";
|
|
10
10
|
import { repositoryPaths } from "#rules/docs/repositoryPaths.ts";
|
|
11
11
|
import { docsUnversionedInstalls } from "#rules/docs/unversionedInstalls.ts";
|
|
12
|
-
import {
|
|
13
|
-
import { effectBoundary } from "#rules/effect/boundary.ts";
|
|
14
|
-
import { failureHonesty } from "#rules/effect/failureHonesty.ts";
|
|
15
|
-
import { rpcBoundary } from "#rules/effect/rpcBoundary.ts";
|
|
16
|
-
import { serviceDefinitionAssembly } from "#rules/effect/serviceDefinitionAssembly.ts";
|
|
17
|
-
import { serviceFolders } from "#rules/effect/serviceFolders.ts";
|
|
18
|
-
import { serviceIds } from "#rules/effect/serviceIds.ts";
|
|
19
|
-
import { serviceParameters } from "#rules/effect/serviceParameters.ts";
|
|
20
|
-
import { sharedErrorClasses } from "#rules/effect/sharedErrorClasses.ts";
|
|
21
|
-
import { sqlTransact } from "#rules/effect/sqlTransact.ts";
|
|
12
|
+
import { effectPolicy } from "#rules/effect/policy.ts";
|
|
22
13
|
import { ascii } from "#rules/files/ascii.ts";
|
|
23
14
|
import { distinctCase } from "#rules/files/distinctCase.ts";
|
|
24
15
|
import { folderNames } from "#rules/files/folderNames.ts";
|
|
@@ -73,21 +64,12 @@ import { noBarrel } from "./noBarrel.ts";
|
|
|
73
64
|
import { unusedCode } from "./unusedCode.ts";
|
|
74
65
|
|
|
75
66
|
export const builtInRules = [
|
|
67
|
+
...effectPolicy,
|
|
76
68
|
agentLinks,
|
|
77
69
|
repositoryPaths,
|
|
78
|
-
serviceFolders,
|
|
79
70
|
ascii,
|
|
80
71
|
manifestsDependencyPins,
|
|
81
72
|
unusedCode,
|
|
82
|
-
adapterImports,
|
|
83
|
-
effectBoundary,
|
|
84
|
-
failureHonesty,
|
|
85
|
-
rpcBoundary,
|
|
86
|
-
serviceDefinitionAssembly,
|
|
87
|
-
serviceIds,
|
|
88
|
-
serviceParameters,
|
|
89
|
-
sharedErrorClasses,
|
|
90
|
-
sqlTransact,
|
|
91
73
|
jsxConditionals,
|
|
92
74
|
maxLines,
|
|
93
75
|
maxDepth,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Effect, Schema } from "effect";
|
|
2
|
-
import { SUPPRESSIONS } from "#rules/suppressions/
|
|
2
|
+
import { SUPPRESSIONS } from "#rules/suppressions/in.ts";
|
|
3
3
|
import type { SourceComment } from "./scan.ts";
|
|
4
4
|
|
|
5
5
|
export const Pragmas = Schema.Array(Schema.String).pipe(Schema.withDecodingDefaultKey(Effect.succeed<readonly string[]>([])));
|