@shivaedev/quality 0.66.0 → 0.67.1
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 +19 -0
- package/README.md +10 -8
- package/biome/declarations.json +7 -1
- package/biome/preset.json +7 -1
- 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/buildEntryPaths.d.ts +3 -0
- package/dist/adapters/buildEntryPaths.d.ts.map +1 -0
- package/dist/adapters/buildEntryPaths.js +48 -0
- package/dist/adapters/buildEntryPaths.js.map +1 -0
- package/dist/adapters/buildEntryValue.d.ts +4 -0
- package/dist/adapters/buildEntryValue.d.ts.map +1 -0
- package/dist/adapters/buildEntryValue.js +47 -0
- package/dist/adapters/buildEntryValue.js.map +1 -0
- package/dist/adapters/bundlerEntries.d.ts +3 -0
- package/dist/adapters/bundlerEntries.d.ts.map +1 -0
- package/dist/adapters/bundlerEntries.js +49 -0
- package/dist/adapters/bundlerEntries.js.map +1 -0
- package/dist/adapters/callbackEscapes.d.ts +3 -0
- package/dist/adapters/callbackEscapes.d.ts.map +1 -0
- package/dist/adapters/callbackEscapes.js +24 -0
- package/dist/adapters/callbackEscapes.js.map +1 -0
- package/dist/adapters/composedContext.d.ts +3 -0
- package/dist/adapters/composedContext.d.ts.map +1 -0
- package/dist/adapters/composedContext.js +42 -0
- package/dist/adapters/composedContext.js.map +1 -0
- package/dist/adapters/containerDependency.d.ts +4 -0
- package/dist/adapters/containerDependency.d.ts.map +1 -0
- package/dist/adapters/containerDependency.js +28 -0
- package/dist/adapters/containerDependency.js.map +1 -0
- package/dist/adapters/contextCaptureFindings.d.ts.map +1 -1
- package/dist/adapters/contextCaptureFindings.js +3 -1
- package/dist/adapters/contextCaptureFindings.js.map +1 -1
- package/dist/adapters/foreignResources.d.ts +3 -0
- package/dist/adapters/foreignResources.d.ts.map +1 -0
- package/dist/adapters/foreignResources.js +80 -0
- package/dist/adapters/foreignResources.js.map +1 -0
- package/dist/adapters/frameworkCallback.d.ts +4 -0
- package/dist/adapters/frameworkCallback.d.ts.map +1 -0
- package/dist/adapters/frameworkCallback.js +92 -0
- package/dist/adapters/frameworkCallback.js.map +1 -0
- package/dist/adapters/frameworkOwner.d.ts +3 -0
- package/dist/adapters/frameworkOwner.d.ts.map +1 -0
- package/dist/adapters/frameworkOwner.js +35 -0
- package/dist/adapters/frameworkOwner.js.map +1 -0
- package/dist/adapters/importedCall.d.ts +6 -0
- package/dist/adapters/importedCall.d.ts.map +1 -0
- package/dist/adapters/importedCall.js +26 -0
- package/dist/adapters/importedCall.js.map +1 -0
- package/dist/adapters/isToolConfig.d.ts +2 -0
- package/dist/adapters/isToolConfig.d.ts.map +1 -0
- package/dist/adapters/isToolConfig.js +7 -0
- package/dist/adapters/isToolConfig.js.map +1 -0
- package/dist/adapters/knip/configuration.d.ts +1 -1
- package/dist/adapters/knip/configuration.d.ts.map +1 -1
- package/dist/adapters/knip/configuration.js +5 -3
- package/dist/adapters/knip/configuration.js.map +1 -1
- package/dist/adapters/knip/run.d.ts.map +1 -1
- package/dist/adapters/knip/run.js +3 -1
- package/dist/adapters/knip/run.js.map +1 -1
- package/dist/adapters/localFunctions.d.ts +3 -0
- package/dist/adapters/localFunctions.d.ts.map +1 -0
- package/dist/adapters/localFunctions.js +20 -0
- package/dist/adapters/localFunctions.js.map +1 -0
- 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/reachableBuildEntries.d.ts +5 -0
- package/dist/adapters/reachableBuildEntries.d.ts.map +1 -0
- package/dist/adapters/reachableBuildEntries.js +52 -0
- package/dist/adapters/reachableBuildEntries.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/serviceStateProblems.d.ts.map +1 -1
- package/dist/adapters/serviceStateProblems.js +26 -14
- package/dist/adapters/serviceStateProblems.js.map +1 -1
- 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/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/inventory/programmaticEntries.d.ts +4 -0
- package/dist/inventory/programmaticEntries.d.ts.map +1 -0
- package/dist/inventory/programmaticEntries.js +9 -0
- package/dist/inventory/programmaticEntries.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/comments/kinds.js +1 -1
- package/dist/rules/comments/kinds.js.map +1 -1
- package/dist/rules/effect/contextCapture.js +1 -1
- package/dist/rules/effect/contextCapture.js.map +1 -1
- package/dist/rules/effect/program.d.ts +1 -0
- package/dist/rules/effect/program.d.ts.map +1 -1
- package/dist/rules/effect/program.js +17 -1
- package/dist/rules/effect/program.js.map +1 -1
- package/dist/rules/effect/serviceCatalog.d.ts.map +1 -1
- package/dist/rules/effect/serviceCatalog.js +10 -2
- package/dist/rules/effect/serviceCatalog.js.map +1 -1
- package/dist/rules/effect/serviceFindings.d.ts.map +1 -1
- package/dist/rules/effect/serviceFindings.js +33 -7
- package/dist/rules/effect/serviceFindings.js.map +1 -1
- package/dist/rules/effect/serviceOrigin.d.ts.map +1 -1
- package/dist/rules/effect/serviceOrigin.js +13 -1
- package/dist/rules/effect/serviceOrigin.js.map +1 -1
- package/dist/rules/effect/serviceParameters.d.ts.map +1 -1
- package/dist/rules/effect/serviceParameters.js +12 -12
- package/dist/rules/effect/serviceParameters.js.map +1 -1
- package/dist/rules/effect/serviceTypes.d.ts.map +1 -1
- package/dist/rules/effect/serviceTypes.js +5 -1
- 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 +36 -23
- 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 -3
- package/src/adapters/asymmetricMatcher.ts +33 -0
- package/src/adapters/buildEntryPaths.ts +52 -0
- package/src/adapters/buildEntryValue.ts +52 -0
- package/src/adapters/bundlerEntries.ts +53 -0
- package/src/adapters/callbackEscapes.ts +32 -0
- package/src/adapters/composedContext.ts +48 -0
- package/src/adapters/containerDependency.ts +40 -0
- package/src/adapters/contextCaptureFindings.ts +3 -1
- package/src/adapters/foreignResources.ts +83 -0
- package/src/adapters/frameworkCallback.ts +106 -0
- package/src/adapters/frameworkOwner.ts +41 -0
- package/src/adapters/importedCall.ts +27 -0
- package/src/adapters/isToolConfig.ts +10 -0
- package/src/adapters/knip/configuration.ts +5 -7
- package/src/adapters/knip/run.ts +3 -1
- package/src/adapters/localFunctions.ts +22 -0
- package/src/adapters/pureReader.ts +56 -0
- package/src/adapters/reachableBuildEntries.ts +58 -0
- package/src/adapters/readConfig.ts +1 -1
- package/src/adapters/scriptPaths.ts +5 -0
- package/src/adapters/serviceStateProblems.ts +42 -17
- 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/testComposition.ts +47 -0
- package/src/inventory/programmaticEntries.ts +10 -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/comments/kinds.ts +1 -1
- package/src/rules/effect/contextCapture.ts +1 -1
- package/src/rules/effect/program.ts +19 -1
- package/src/rules/effect/serviceCatalog.ts +12 -2
- package/src/rules/effect/serviceFindings.ts +38 -7
- package/src/rules/effect/serviceOrigin.ts +14 -1
- package/src/rules/effect/serviceParameters.ts +13 -14
- package/src/rules/effect/serviceTypes.ts +11 -1
- package/src/rules/files/namedAfterExport.ts +46 -23
- 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/initializerDependency.d.ts +0 -3
- package/dist/adapters/initializerDependency.d.ts.map +0 -1
- package/dist/adapters/initializerDependency.js +0 -53
- package/dist/adapters/initializerDependency.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/initializerDependency.ts +0 -57
- /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
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";
|
|
@@ -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,10 @@
|
|
|
1
|
+
import { Effect } from "effect";
|
|
2
|
+
import { reachableBuildEntries } from "#adapters/reachableBuildEntries.ts";
|
|
3
|
+
import { importGraph } from "#imports/graph.ts";
|
|
4
|
+
import { packageLayout } from "#naming/packageLayout.ts";
|
|
5
|
+
import type { RuleInputs } from "#rule.ts";
|
|
6
|
+
|
|
7
|
+
export const programmaticEntries = Effect.fn("Inventory.programmaticEntries")(function* (inputs: RuleInputs) {
|
|
8
|
+
const layout = yield* packageLayout(inputs);
|
|
9
|
+
return layout.scripts.size === 0 ? new Set<string>() : reachableBuildEntries(inputs, yield* importGraph(inputs), layout);
|
|
10
|
+
});
|
|
@@ -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
|
+
});
|
|
@@ -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[]>([])));
|
|
@@ -4,7 +4,7 @@ import { defineRule } from "#rule.ts";
|
|
|
4
4
|
export const contextCapture = defineRule({
|
|
5
5
|
check: contextCaptureFindings,
|
|
6
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/.",
|
|
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. Contexts assembled from Layers at composition roots and fully provided application harnesses are accepted. Runtime bridges belong in adapters/ or test-support/.",
|
|
8
8
|
id: "effect/context-capture",
|
|
9
9
|
registrable: false,
|
|
10
10
|
});
|
|
@@ -4,6 +4,10 @@ import { projectsFor } from "#adapters/imports/projects.ts";
|
|
|
4
4
|
import type { RuleInputs } from "#rule.ts";
|
|
5
5
|
|
|
6
6
|
export function effectProgram(inputs: RuleInputs, externalTypes = true, roots: readonly string[] = []): ts.Program {
|
|
7
|
+
return effectPrograms(inputs, externalTypes, roots)(inputs.sources);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function effectPrograms(inputs: RuleInputs, externalTypes = true, roots: readonly string[] = []) {
|
|
7
11
|
const projectOf = projectsFor(inputs.root);
|
|
8
12
|
const options: ts.CompilerOptions = {
|
|
9
13
|
allowJs: true,
|
|
@@ -25,5 +29,19 @@ export function effectProgram(inputs: RuleInputs, externalTypes = true, roots: r
|
|
|
25
29
|
const project = projectOf(from);
|
|
26
30
|
return ts.resolveModuleName(name, from, project.typesOptions, host, project.typesCache).resolvedModule;
|
|
27
31
|
});
|
|
28
|
-
|
|
32
|
+
const sourceFiles = new Map<string, ts.SourceFile>();
|
|
33
|
+
const readSource = host.getSourceFile;
|
|
34
|
+
host.getSourceFile = (file, languageVersion, onError, shouldCreateNewSourceFile) => {
|
|
35
|
+
const previous = sourceFiles.get(file);
|
|
36
|
+
if (previous !== undefined && !shouldCreateNewSourceFile) {
|
|
37
|
+
return previous;
|
|
38
|
+
}
|
|
39
|
+
const source = readSource(file, languageVersion, onError, shouldCreateNewSourceFile);
|
|
40
|
+
if (source !== undefined) {
|
|
41
|
+
sourceFiles.set(file, source);
|
|
42
|
+
}
|
|
43
|
+
return source;
|
|
44
|
+
};
|
|
45
|
+
return (sources: RuleInputs["sources"]): ts.Program =>
|
|
46
|
+
ts.createProgram([...sources.map((source) => join(inputs.root, source.path)), ...roots], options, host);
|
|
29
47
|
}
|
|
@@ -6,6 +6,11 @@ import { serviceTypes } from "#rules/effect/serviceTypes.ts";
|
|
|
6
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
8
|
const services = serviceTypes(checker, initializerState);
|
|
9
|
+
function runtimeSymbol(symbol: ts.Symbol): boolean {
|
|
10
|
+
return (
|
|
11
|
+
initializerState || (symbol.declarations ?? []).some((declaration) => !/(?:^|\/)test-support\//u.test(declaration.getSourceFile().fileName))
|
|
12
|
+
);
|
|
13
|
+
}
|
|
9
14
|
function imported(node: ts.ImportSpecifier | ts.NamespaceImport): void {
|
|
10
15
|
const symbol = checker.getSymbolAtLocation(node.name);
|
|
11
16
|
if (symbol === undefined) {
|
|
@@ -15,7 +20,7 @@ export function serviceCatalog(program: ts.Program, checker: ts.TypeChecker, pac
|
|
|
15
20
|
const candidates = target.flags & ts.SymbolFlags.Module ? checker.getExportsOfModule(target) : [target];
|
|
16
21
|
for (const candidate of candidates) {
|
|
17
22
|
const resolved = candidate.flags & ts.SymbolFlags.Alias ? checker.getAliasedSymbol(candidate) : candidate;
|
|
18
|
-
if (serviceOrigin(checker, resolved)) {
|
|
23
|
+
if (runtimeSymbol(resolved) && serviceOrigin(checker, resolved)) {
|
|
19
24
|
services.remember(checker.getTypeOfSymbol(resolved), resolved.name);
|
|
20
25
|
}
|
|
21
26
|
}
|
|
@@ -29,7 +34,9 @@ export function serviceCatalog(program: ts.Program, checker: ts.TypeChecker, pac
|
|
|
29
34
|
return;
|
|
30
35
|
}
|
|
31
36
|
const target = symbol.flags & ts.SymbolFlags.Alias ? checker.getAliasedSymbol(symbol) : symbol;
|
|
32
|
-
|
|
37
|
+
if (runtimeSymbol(target)) {
|
|
38
|
+
services.remember(checker.getTypeOfSymbol(target), target.name);
|
|
39
|
+
}
|
|
33
40
|
}
|
|
34
41
|
|
|
35
42
|
function named(node: ts.Node): void {
|
|
@@ -56,6 +63,9 @@ export function serviceCatalog(program: ts.Program, checker: ts.TypeChecker, pac
|
|
|
56
63
|
ts.forEachChild(node, discover);
|
|
57
64
|
}
|
|
58
65
|
for (const source of program.getSourceFiles()) {
|
|
66
|
+
if (!initializerState && /(?:^|\/)test-support\//u.test(source.fileName)) {
|
|
67
|
+
continue;
|
|
68
|
+
}
|
|
59
69
|
if (!source.fileName.includes("/node_modules/") || prefixes.some((prefix) => source.fileName.includes(`/${prefix}`))) {
|
|
60
70
|
discover(source);
|
|
61
71
|
}
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { relative } from "node:path";
|
|
2
2
|
import ts from "typescript";
|
|
3
|
+
import { foreignResources } from "#adapters/foreignResources.ts";
|
|
4
|
+
import { frameworkCallback, parameterSite } from "#adapters/frameworkCallback.ts";
|
|
5
|
+
import { localFunctions } from "#adapters/localFunctions.ts";
|
|
3
6
|
import type { Finding } from "#rule.ts";
|
|
4
7
|
import { layerConstructor } from "#rules/effect/layerConstructor.ts";
|
|
5
8
|
import { publicFunctions } from "#rules/effect/publicFunctions.ts";
|
|
@@ -12,36 +15,59 @@ function publicDeclaration(declaration: ts.Declaration, local: ReadonlySet<ts.So
|
|
|
12
15
|
return !((ts.isMethodDeclaration(declaration) || ts.isPropertyDeclaration(declaration)) && ts.isPrivateIdentifier(declaration.name));
|
|
13
16
|
}
|
|
14
17
|
|
|
18
|
+
function implementationParameter(checker: ts.TypeChecker, parameter: ts.ParameterDeclaration, services: ReturnType<typeof serviceTypes>): boolean {
|
|
19
|
+
const fn = parameter.parent;
|
|
20
|
+
const property = ts.isPropertyAssignment(fn.parent) ? fn.parent : fn;
|
|
21
|
+
const object = property.parent;
|
|
22
|
+
return ts.isObjectLiteralExpression(object) && services.implementation(checker.getTypeAtLocation(object));
|
|
23
|
+
}
|
|
24
|
+
|
|
15
25
|
export function serviceFindings(
|
|
16
26
|
root: string,
|
|
17
27
|
sources: readonly ts.SourceFile[],
|
|
18
28
|
checker: ts.TypeChecker,
|
|
19
29
|
services: ReturnType<typeof serviceTypes>,
|
|
20
30
|
): readonly Finding[] {
|
|
31
|
+
const resource = foreignResources(checker, sources);
|
|
21
32
|
const findings = new Map<ts.ParameterDeclaration, Finding>();
|
|
22
33
|
const visited = new Set<ts.Type>();
|
|
23
34
|
const activeSignatures = new Set<NonNullable<ts.Signature["declaration"]>>();
|
|
24
35
|
const local = new Set(sources);
|
|
25
|
-
function parameterFinding(symbol: ts.Symbol): void {
|
|
36
|
+
function parameterFinding(symbol: ts.Symbol, signature?: ts.Signature): void {
|
|
26
37
|
if (!services.carries(checker.getTypeOfSymbol(symbol))) {
|
|
27
38
|
return;
|
|
28
39
|
}
|
|
29
40
|
for (const parameter of symbol.declarations ?? []) {
|
|
30
|
-
if (
|
|
41
|
+
if (
|
|
42
|
+
!(ts.isParameter(parameter) && local.has(parameter.getSourceFile()))
|
|
43
|
+
|| implementationParameter(checker, parameter, services)
|
|
44
|
+
|| resource(parameter)
|
|
45
|
+
|| frameworkCallback(checker, parameter.parent, local)
|
|
46
|
+
|| (signature !== undefined
|
|
47
|
+
&& (checker.getTypePredicateOfSignature(signature) !== undefined
|
|
48
|
+
|| (signature.declaration !== undefined && layerConstructor(checker, signature.declaration))
|
|
49
|
+
|| signature.getReturnType().getProperty("~effect/Layer") !== undefined))
|
|
50
|
+
) {
|
|
31
51
|
continue;
|
|
32
52
|
}
|
|
33
|
-
const
|
|
53
|
+
const site = parameterSite(checker, parameter, local);
|
|
54
|
+
const source = site.getSourceFile();
|
|
34
55
|
const file = relative(root, source.fileName).replaceAll("\\", "/");
|
|
35
|
-
findings.set(
|
|
56
|
+
findings.set(site, {
|
|
36
57
|
file,
|
|
37
|
-
line: source.getLineAndCharacterOfPosition(
|
|
38
|
-
message: `Parameter ${
|
|
58
|
+
line: source.getLineAndCharacterOfPosition(site.getStart(source)).line + 1,
|
|
59
|
+
message: `Parameter ${site.name.getText(source)} carries a service. Read services from Effect's environment instead of passing them; return an Effect or Stream with requirements. Service implementation methods and Layer constructors are accepted; only test-support/ folders are exempt, not adapters/.`,
|
|
39
60
|
});
|
|
40
61
|
}
|
|
41
62
|
}
|
|
42
63
|
function signatureFinding(signature: ts.Signature): void {
|
|
43
64
|
const declaration = signature.declaration;
|
|
44
|
-
if (
|
|
65
|
+
if (
|
|
66
|
+
declaration === undefined
|
|
67
|
+
|| !local.has(declaration.getSourceFile())
|
|
68
|
+
|| layerConstructor(checker, declaration)
|
|
69
|
+
|| checker.getTypePredicateOfSignature(signature) !== undefined
|
|
70
|
+
) {
|
|
45
71
|
return;
|
|
46
72
|
}
|
|
47
73
|
const result = signature.getReturnType();
|
|
@@ -92,5 +118,10 @@ export function serviceFindings(
|
|
|
92
118
|
}
|
|
93
119
|
}
|
|
94
120
|
publicFunctions(sources, checker, surface);
|
|
121
|
+
localFunctions(sources, checker, (signature) => {
|
|
122
|
+
for (const parameter of signature.parameters) {
|
|
123
|
+
parameterFinding(parameter, signature);
|
|
124
|
+
}
|
|
125
|
+
});
|
|
95
126
|
return [...findings.values()];
|
|
96
127
|
}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import ts from "typescript";
|
|
2
2
|
import { returnValues } from "#rules/stories/returnValues.ts";
|
|
3
3
|
|
|
4
|
+
const origins = new WeakMap<ts.TypeChecker, Map<ts.Symbol, boolean>>();
|
|
5
|
+
|
|
4
6
|
const SERVICE_NAMES = new Set(["Service", "ServiceClass", "Key", "Reference", "Tag", "TagClass", "GenericTag"]);
|
|
5
7
|
|
|
6
8
|
function annotation(declaration: ts.Declaration): ts.TypeNode | undefined {
|
|
@@ -31,11 +33,18 @@ function declarationOrigin(checker: ts.TypeChecker, declaration: ts.Declaration,
|
|
|
31
33
|
|
|
32
34
|
function symbolOrigin(checker: ts.TypeChecker, symbol: ts.Symbol, seen: Set<ts.Symbol>): boolean {
|
|
33
35
|
const target = symbol.flags & ts.SymbolFlags.Alias ? checker.getAliasedSymbol(symbol) : symbol;
|
|
36
|
+
const known = origins.get(checker) ?? new Map<ts.Symbol, boolean>();
|
|
37
|
+
origins.set(checker, known);
|
|
38
|
+
const previous = known.get(target);
|
|
39
|
+
if (previous !== undefined) {
|
|
40
|
+
return previous;
|
|
41
|
+
}
|
|
42
|
+
const root = seen.size === 0;
|
|
34
43
|
if (seen.has(target)) {
|
|
35
44
|
return false;
|
|
36
45
|
}
|
|
37
46
|
seen.add(target);
|
|
38
|
-
|
|
47
|
+
const result = (target.declarations ?? []).some((declaration) => {
|
|
39
48
|
const file = declaration.getSourceFile().fileName.replaceAll("\\", "/");
|
|
40
49
|
if (
|
|
41
50
|
/\/effect\/(?:src|dist)\/(?:Context|Effect)(?:\.d)?\.ts$/u.test(file)
|
|
@@ -53,6 +62,10 @@ function symbolOrigin(checker: ts.TypeChecker, symbol: ts.Symbol, seen: Set<ts.S
|
|
|
53
62
|
}
|
|
54
63
|
return declarationOrigin(checker, declaration, seen);
|
|
55
64
|
});
|
|
65
|
+
if (root) {
|
|
66
|
+
known.set(target, result);
|
|
67
|
+
}
|
|
68
|
+
return result;
|
|
56
69
|
}
|
|
57
70
|
|
|
58
71
|
function reference(node: ts.Node): ts.Node | undefined {
|