@shivaedev/quality 0.57.0 → 0.58.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.
Files changed (229) hide show
  1. package/CHANGELOG.md +28 -0
  2. package/README.md +11 -4
  3. package/dist/adapters/ImportAnalysisFailure.d.ts +10 -0
  4. package/dist/adapters/ImportAnalysisFailure.d.ts.map +1 -0
  5. package/dist/adapters/ImportAnalysisFailure.js +4 -0
  6. package/dist/adapters/ImportAnalysisFailure.js.map +1 -0
  7. package/dist/adapters/ImportCompiler.d.ts +2 -13
  8. package/dist/adapters/ImportCompiler.d.ts.map +1 -1
  9. package/dist/adapters/ImportCompiler.js +7 -13
  10. package/dist/adapters/ImportCompiler.js.map +1 -1
  11. package/dist/adapters/executable.d.ts +3 -0
  12. package/dist/adapters/executable.d.ts.map +1 -0
  13. package/dist/adapters/executable.js +14 -0
  14. package/dist/adapters/executable.js.map +1 -0
  15. package/dist/adapters/imports/analysisFailure.d.ts +3 -0
  16. package/dist/adapters/imports/analysisFailure.d.ts.map +1 -0
  17. package/dist/adapters/imports/analysisFailure.js +5 -0
  18. package/dist/adapters/imports/analysisFailure.js.map +1 -0
  19. package/dist/adapters/imports/analyzeDepartures.d.ts +5 -0
  20. package/dist/adapters/imports/analyzeDepartures.d.ts.map +1 -0
  21. package/dist/adapters/imports/analyzeDepartures.js +5 -0
  22. package/dist/adapters/imports/analyzeDepartures.js.map +1 -0
  23. package/dist/adapters/imports/analyzeGraph.d.ts +4 -0
  24. package/dist/adapters/imports/analyzeGraph.d.ts.map +1 -0
  25. package/dist/adapters/imports/analyzeGraph.js +6 -0
  26. package/dist/adapters/imports/analyzeGraph.js.map +1 -0
  27. package/dist/adapters/imports/checkBrowser.d.ts +4 -0
  28. package/dist/adapters/imports/checkBrowser.d.ts.map +1 -0
  29. package/dist/adapters/imports/checkBrowser.js +4 -0
  30. package/dist/adapters/imports/checkBrowser.js.map +1 -0
  31. package/dist/adapters/indirectServiceReferences.d.ts +3 -0
  32. package/dist/adapters/indirectServiceReferences.d.ts.map +1 -0
  33. package/dist/adapters/indirectServiceReferences.js +19 -0
  34. package/dist/adapters/indirectServiceReferences.js.map +1 -0
  35. package/dist/adapters/knip/entryPointFindings.d.ts +1 -1
  36. package/dist/adapters/knip/entryPointFindings.d.ts.map +1 -1
  37. package/dist/adapters/nativeTransactionFindings.d.ts +4 -0
  38. package/dist/adapters/nativeTransactionFindings.d.ts.map +1 -0
  39. package/dist/adapters/nativeTransactionFindings.js +98 -0
  40. package/dist/adapters/nativeTransactionFindings.js.map +1 -0
  41. package/dist/adapters/outsideImportFindings.d.ts +1 -1
  42. package/dist/adapters/outsideImportFindings.d.ts.map +1 -1
  43. package/dist/adapters/queueReadoutFindings.d.ts +1 -1
  44. package/dist/adapters/queueReadoutFindings.d.ts.map +1 -1
  45. package/dist/adapters/serviceAssemblyImports.d.ts +10 -0
  46. package/dist/adapters/serviceAssemblyImports.d.ts.map +1 -0
  47. package/dist/adapters/serviceAssemblyImports.js +71 -0
  48. package/dist/adapters/serviceAssemblyImports.js.map +1 -0
  49. package/dist/adapters/serviceAssemblySyntax.d.ts +10 -0
  50. package/dist/adapters/serviceAssemblySyntax.d.ts.map +1 -0
  51. package/dist/adapters/serviceAssemblySyntax.js +105 -0
  52. package/dist/adapters/serviceAssemblySyntax.js.map +1 -0
  53. package/dist/adapters/serviceDefinitionProblems.d.ts +7 -0
  54. package/dist/adapters/serviceDefinitionProblems.d.ts.map +1 -0
  55. package/dist/adapters/serviceDefinitionProblems.js +43 -0
  56. package/dist/adapters/serviceDefinitionProblems.js.map +1 -0
  57. package/dist/adapters/serviceIdFindings.d.ts.map +1 -1
  58. package/dist/adapters/serviceIdFindings.js +12 -7
  59. package/dist/adapters/serviceIdFindings.js.map +1 -1
  60. package/dist/adapters/transactionChanges.d.ts +3 -0
  61. package/dist/adapters/transactionChanges.d.ts.map +1 -0
  62. package/dist/adapters/transactionChanges.js +81 -0
  63. package/dist/adapters/transactionChanges.js.map +1 -0
  64. package/dist/baseline/cleanupMergeFiles.d.ts.map +1 -1
  65. package/dist/baseline/cleanupMergeFiles.js +3 -2
  66. package/dist/baseline/cleanupMergeFiles.js.map +1 -1
  67. package/dist/baseline/shards.d.ts.map +1 -1
  68. package/dist/baseline/shards.js +4 -2
  69. package/dist/baseline/shards.js.map +1 -1
  70. package/dist/biome/recommendedRules.d.ts.map +1 -1
  71. package/dist/biome/recommendedRules.js +3 -2
  72. package/dist/biome/recommendedRules.js.map +1 -1
  73. package/dist/biome/report.d.ts.map +1 -1
  74. package/dist/biome/report.js +3 -2
  75. package/dist/biome/report.js.map +1 -1
  76. package/dist/cli/baseline.d.ts.map +1 -1
  77. package/dist/cli/baseline.js +3 -2
  78. package/dist/cli/baseline.js.map +1 -1
  79. package/dist/cli/fix.d.ts.map +1 -1
  80. package/dist/cli/fix.js +3 -2
  81. package/dist/cli/fix.js.map +1 -1
  82. package/dist/cli/fixRule.d.ts.map +1 -1
  83. package/dist/cli/fixRule.js +3 -2
  84. package/dist/cli/fixRule.js.map +1 -1
  85. package/dist/cli/lint.d.ts.map +1 -1
  86. package/dist/cli/lint.js +2 -2
  87. package/dist/cli/lint.js.map +1 -1
  88. package/dist/cli/migrateBaseline.d.ts.map +1 -1
  89. package/dist/cli/migrateBaseline.js +3 -2
  90. package/dist/cli/migrateBaseline.js.map +1 -1
  91. package/dist/cli/migrateExceptions.d.ts.map +1 -1
  92. package/dist/cli/migrateExceptions.js +3 -2
  93. package/dist/cli/migrateExceptions.js.map +1 -1
  94. package/dist/config/load.d.ts.map +1 -1
  95. package/dist/config/load.js +3 -2
  96. package/dist/config/load.js.map +1 -1
  97. package/dist/engine/session.d.ts.map +1 -1
  98. package/dist/engine/session.js +3 -2
  99. package/dist/engine/session.js.map +1 -1
  100. package/dist/hooks/install.d.ts.map +1 -1
  101. package/dist/hooks/install.js +4 -2
  102. package/dist/hooks/install.js.map +1 -1
  103. package/dist/hooks/location.d.ts.map +1 -1
  104. package/dist/hooks/location.js +3 -2
  105. package/dist/hooks/location.js.map +1 -1
  106. package/dist/hooks/preCommit.d.ts.map +1 -1
  107. package/dist/hooks/preCommit.js +3 -2
  108. package/dist/hooks/preCommit.js.map +1 -1
  109. package/dist/hooks/setup.d.ts.map +1 -1
  110. package/dist/hooks/setup.js +3 -2
  111. package/dist/hooks/setup.js.map +1 -1
  112. package/dist/hooks/status.d.ts.map +1 -1
  113. package/dist/hooks/status.js +5 -15
  114. package/dist/hooks/status.js.map +1 -1
  115. package/dist/hooks/uninstall.d.ts.map +1 -1
  116. package/dist/hooks/uninstall.js +3 -2
  117. package/dist/hooks/uninstall.js.map +1 -1
  118. package/dist/imports/departures.d.ts +1 -1
  119. package/dist/imports/departures.d.ts.map +1 -1
  120. package/dist/imports/fences/check.d.ts +1 -1
  121. package/dist/imports/fences/check.d.ts.map +1 -1
  122. package/dist/imports/graph.d.ts +1 -1
  123. package/dist/imports/graph.d.ts.map +1 -1
  124. package/dist/inventory/filesystem.d.ts.map +1 -1
  125. package/dist/inventory/filesystem.js +3 -2
  126. package/dist/inventory/filesystem.js.map +1 -1
  127. package/dist/inventory/shadcnFolders.d.ts.map +1 -1
  128. package/dist/inventory/shadcnFolders.js +4 -2
  129. package/dist/inventory/shadcnFolders.js.map +1 -1
  130. package/dist/inventory/trackedPaths.d.ts.map +1 -1
  131. package/dist/inventory/trackedPaths.js +4 -2
  132. package/dist/inventory/trackedPaths.js.map +1 -1
  133. package/dist/rules/builtIn.d.ts +1 -1
  134. package/dist/rules/builtIn.d.ts.map +1 -1
  135. package/dist/rules/builtIn.js +4 -0
  136. package/dist/rules/builtIn.js.map +1 -1
  137. package/dist/rules/effect/serviceCatalog.d.ts +1 -1
  138. package/dist/rules/effect/serviceCatalog.d.ts.map +1 -1
  139. package/dist/rules/effect/serviceCatalog.js +4 -2
  140. package/dist/rules/effect/serviceCatalog.js.map +1 -1
  141. package/dist/rules/effect/serviceDefinitionAssembly.d.ts +2 -0
  142. package/dist/rules/effect/serviceDefinitionAssembly.d.ts.map +1 -0
  143. package/dist/rules/effect/serviceDefinitionAssembly.js +43 -0
  144. package/dist/rules/effect/serviceDefinitionAssembly.js.map +1 -0
  145. package/dist/rules/effect/serviceIds.js +1 -1
  146. package/dist/rules/effect/serviceIds.js.map +1 -1
  147. package/dist/rules/effect/serviceParameters.d.ts.map +1 -1
  148. package/dist/rules/effect/serviceParameters.js +12 -6
  149. package/dist/rules/effect/serviceParameters.js.map +1 -1
  150. package/dist/rules/effect/sqlTransact.d.ts +2 -0
  151. package/dist/rules/effect/sqlTransact.d.ts.map +1 -0
  152. package/dist/rules/effect/sqlTransact.js +9 -0
  153. package/dist/rules/effect/sqlTransact.js.map +1 -0
  154. package/dist/rules/imports/manifest.d.ts.map +1 -1
  155. package/dist/rules/imports/manifest.js +9 -6
  156. package/dist/rules/imports/manifest.js.map +1 -1
  157. package/dist/rules/stories/sources.d.ts +1 -1
  158. package/dist/rules/stories/sources.d.ts.map +1 -1
  159. package/dist/rules/suppressions/noIgnoreDeprecations.d.ts.map +1 -1
  160. package/dist/rules/suppressions/noIgnoreDeprecations.js +3 -2
  161. package/dist/rules/suppressions/noIgnoreDeprecations.js.map +1 -1
  162. package/dist/testing/adapters/assertThat.d.ts +5 -0
  163. package/dist/testing/adapters/assertThat.d.ts.map +1 -0
  164. package/dist/testing/adapters/assertThat.js +9 -0
  165. package/dist/testing/adapters/assertThat.js.map +1 -0
  166. package/dist/testing/adapters/cli.d.ts +2 -2
  167. package/dist/testing/adapters/cli.d.ts.map +1 -1
  168. package/dist/testing/adapters/cli.js +11 -14
  169. package/dist/testing/adapters/cli.js.map +1 -1
  170. package/dist/testing/adapters/git.d.ts +10 -0
  171. package/dist/testing/adapters/git.d.ts.map +1 -1
  172. package/dist/testing/adapters/git.js +6 -2
  173. package/dist/testing/adapters/git.js.map +1 -1
  174. package/dist/testing/adapters/hookRepository.d.ts.map +1 -1
  175. package/dist/testing/adapters/hookRepository.js +6 -2
  176. package/dist/testing/adapters/hookRepository.js.map +1 -1
  177. package/dist/testing/ruleStory.d.ts.map +1 -1
  178. package/dist/testing/ruleStory.js +1 -2
  179. package/dist/testing/ruleStory.js.map +1 -1
  180. package/package.json +6 -5
  181. package/src/adapters/ImportAnalysisFailure.ts +6 -0
  182. package/src/adapters/ImportCompiler.ts +7 -20
  183. package/src/adapters/executable.ts +14 -0
  184. package/src/adapters/imports/analysisFailure.ts +5 -0
  185. package/src/adapters/imports/analyzeDepartures.ts +9 -0
  186. package/src/adapters/imports/analyzeGraph.ts +9 -0
  187. package/src/adapters/imports/checkBrowser.ts +5 -0
  188. package/src/adapters/indirectServiceReferences.ts +25 -0
  189. package/src/adapters/nativeTransactionFindings.ts +108 -0
  190. package/src/adapters/outsideImportFindings.ts +1 -1
  191. package/src/adapters/serviceAssemblyImports.ts +93 -0
  192. package/src/adapters/serviceAssemblySyntax.ts +129 -0
  193. package/src/adapters/serviceDefinitionProblems.ts +63 -0
  194. package/src/adapters/serviceIdFindings.ts +16 -13
  195. package/src/adapters/transactionChanges.ts +85 -0
  196. package/src/baseline/cleanupMergeFiles.ts +4 -2
  197. package/src/baseline/shards.ts +6 -2
  198. package/src/biome/recommendedRules.ts +4 -2
  199. package/src/biome/report.ts +4 -2
  200. package/src/cli/baseline.ts +4 -2
  201. package/src/cli/fix.ts +4 -2
  202. package/src/cli/fixRule.ts +4 -2
  203. package/src/cli/lint.ts +3 -2
  204. package/src/cli/migrateBaseline.ts +4 -2
  205. package/src/cli/migrateExceptions.ts +4 -2
  206. package/src/config/load.ts +4 -2
  207. package/src/engine/session.ts +4 -2
  208. package/src/hooks/install.ts +6 -2
  209. package/src/hooks/location.ts +4 -2
  210. package/src/hooks/preCommit.ts +4 -2
  211. package/src/hooks/setup.ts +4 -2
  212. package/src/hooks/status.ts +7 -15
  213. package/src/hooks/uninstall.ts +4 -2
  214. package/src/inventory/filesystem.ts +4 -2
  215. package/src/inventory/shadcnFolders.ts +6 -2
  216. package/src/inventory/trackedPaths.ts +6 -2
  217. package/src/rules/builtIn.ts +4 -0
  218. package/src/rules/effect/serviceCatalog.ts +4 -2
  219. package/src/rules/effect/serviceDefinitionAssembly.ts +46 -0
  220. package/src/rules/effect/serviceIds.ts +1 -1
  221. package/src/rules/effect/serviceParameters.ts +12 -6
  222. package/src/rules/effect/sqlTransact.ts +10 -0
  223. package/src/rules/imports/manifest.ts +14 -8
  224. package/src/rules/suppressions/noIgnoreDeprecations.ts +4 -2
  225. package/src/testing/adapters/assertThat.ts +12 -0
  226. package/src/testing/adapters/cli.ts +22 -14
  227. package/src/testing/adapters/git.ts +7 -2
  228. package/src/testing/adapters/hookRepository.ts +6 -2
  229. package/src/testing/ruleStory.ts +1 -2
@@ -1,5 +1,5 @@
1
- import { dirname } from "node:path";
2
- import { Console, Effect, FileSystem } from "effect";
1
+ import * as NodePath from "@effect/platform-node/NodePath";
2
+ import { Console, Effect, FileSystem, Path } from "effect";
3
3
  import { SetupFailure } from "#failure.ts";
4
4
  import { gitOrFail, run } from "#git/command.ts";
5
5
  import { readOptionalText } from "#inventory/filesystem.ts";
@@ -8,6 +8,8 @@ import { hookLocation } from "./location.ts";
8
8
  import { isHookShim } from "./shim.ts";
9
9
 
10
10
  export const uninstallHook = Effect.fn("Hooks.uninstallHook")(function* (cwd: string) {
11
+ const { dirname } = yield* Path.Path.pipe(Effect.provide(NodePath.layer));
12
+
11
13
  const fs = yield* FileSystem.FileSystem;
12
14
  const { file } = yield* hookLocation(cwd);
13
15
  const existing = yield* Effect.mapError(readOptionalText(file), (failure) => new SetupFailure({ cause: failure, message: failure.message }));
@@ -1,5 +1,5 @@
1
- import { dirname } from "node:path";
2
- import { Data, Effect, FileSystem } from "effect";
1
+ import * as NodePath from "@effect/platform-node/NodePath";
2
+ import { Data, Effect, FileSystem, Path } from "effect";
3
3
  import type { PlatformError } from "effect/PlatformError";
4
4
 
5
5
  export class FilesystemFailure extends Data.TaggedError("FilesystemFailure")<{
@@ -41,6 +41,8 @@ export const writeText = Effect.fn("Inventory.writeText")(function* (
41
41
  path: string,
42
42
  text: string,
43
43
  ): Effect.fn.Return<void, FilesystemFailure, FileSystem.FileSystem> {
44
+ const { dirname } = yield* Path.Path.pipe(Effect.provide(NodePath.layer));
45
+
44
46
  const fs = yield* FileSystem.FileSystem;
45
47
  const written = Effect.andThen(fs.makeDirectory(dirname(path), { recursive: true }), fs.writeFileString(path, text));
46
48
  return yield* Effect.mapError(written, (error) => new FilesystemFailure({ message: `cannot write ${path}: ${error.message}`, path }));
@@ -1,5 +1,5 @@
1
- import { basename, dirname, relative } from "node:path";
2
- import { Effect, Schema } from "effect";
1
+ import * as NodePath from "@effect/platform-node/NodePath";
2
+ import { Effect, Path, Schema } from "effect";
3
3
  import type { SetupFailure } from "#failure.ts";
4
4
  import type { RuleServices } from "#rule.ts";
5
5
  import { FilesystemFailure, readRequiredText } from "./filesystem.ts";
@@ -12,9 +12,13 @@ const Components = Schema.fromJsonString(Schema.Struct({ aliases: Schema.Struct(
12
12
  export const shadcnFolders = Effect.fn("Inventory.shadcnFolders")(function* (
13
13
  root: string,
14
14
  ): Effect.fn.Return<readonly string[], FilesystemFailure | SetupFailure, RuleServices> {
15
+ const { basename } = yield* Path.Path.pipe(Effect.provide(NodePath.layer));
16
+
15
17
  const paths = (yield* walk(root)).filter((path) => basename(path) === "components.json");
16
18
  return yield* Effect.forEach(paths, (path) =>
17
19
  Effect.gen(function* () {
20
+ const { dirname, relative } = yield* Path.Path.pipe(Effect.provide(NodePath.layer));
21
+
18
22
  const text = yield* readRequiredText(path);
19
23
  return yield* Effect.try({
20
24
  catch: (cause) => new FilesystemFailure({ message: `cannot resolve ${path}: ${String(cause)}`, path }),
@@ -1,9 +1,11 @@
1
- import { join, resolve } from "node:path";
2
- import { Effect } from "effect";
1
+ import * as NodePath from "@effect/platform-node/NodePath";
2
+ import { Effect, Path } from "effect";
3
3
  import { SetupFailure } from "#failure.ts";
4
4
  import { run } from "#git/command.ts";
5
5
 
6
6
  const listedPaths = Effect.fn("Inventory.listedPaths")(function* (directory: string, options: readonly string[], path = ".") {
7
+ const { join } = yield* Path.Path.pipe(Effect.provide(NodePath.layer));
8
+
7
9
  const result = yield* run(directory, ["ls-files", "-z", ...options, "--", path]);
8
10
  if (result.code !== 0) {
9
11
  if (result.stderr.includes("not a git repository")) {
@@ -26,6 +28,8 @@ export const ignoredTrackedPaths = Effect.fn("Inventory.ignoredTrackedPaths")(fu
26
28
  });
27
29
 
28
30
  export const ignoredPaths = Effect.fn("Inventory.ignoredPaths")(function* (directory: string) {
31
+ const { resolve } = yield* Path.Path.pipe(Effect.provide(NodePath.layer));
32
+
29
33
  const paths = yield* listedPaths(directory, ["--others", "--ignored", "--exclude-standard", "--directory"]);
30
34
  return paths?.map((path) => resolve(path));
31
35
  });
@@ -10,9 +10,11 @@ import { docsUnversionedInstalls } from "#rules/docs/unversionedInstalls.ts";
10
10
  import { adapterImports } from "#rules/effect/adapterImports.ts";
11
11
  import { effectBoundary } from "#rules/effect/boundary.ts";
12
12
  import { failureHonesty } from "#rules/effect/failureHonesty.ts";
13
+ import { serviceDefinitionAssembly } from "#rules/effect/serviceDefinitionAssembly.ts";
13
14
  import { serviceIds } from "#rules/effect/serviceIds.ts";
14
15
  import { serviceParameters } from "#rules/effect/serviceParameters.ts";
15
16
  import { sharedErrorClasses } from "#rules/effect/sharedErrorClasses.ts";
17
+ import { sqlTransact } from "#rules/effect/sqlTransact.ts";
16
18
  import { distinctCase } from "#rules/files/distinctCase.ts";
17
19
  import { folderNames } from "#rules/files/folderNames.ts";
18
20
  import { namedAfterExport } from "#rules/files/namedAfterExport.ts";
@@ -66,9 +68,11 @@ export const builtInRules = [
66
68
  adapterImports,
67
69
  effectBoundary,
68
70
  failureHonesty,
71
+ serviceDefinitionAssembly,
69
72
  serviceIds,
70
73
  serviceParameters,
71
74
  sharedErrorClasses,
75
+ sqlTransact,
72
76
  jsxConditionals,
73
77
  maxLines,
74
78
  maxDepth,
@@ -1,8 +1,10 @@
1
1
  import ts from "typescript";
2
+ import servicePackage from "@shivaedev/service/package.json" with { type: "json" };
2
3
  import { serviceOrigin } from "#rules/effect/serviceOrigin.ts";
3
4
  import { serviceTypes } from "#rules/effect/serviceTypes.ts";
4
5
 
5
- export function serviceCatalog(program: ts.Program, checker: ts.TypeChecker) {
6
+ export function serviceCatalog(program: ts.Program, checker: ts.TypeChecker, packages: readonly string[] = []) {
7
+ const prefixes = [servicePackage.name, ...packages].map((name) => `${name.startsWith("@") ? name.split("/")[0] : name}/`);
6
8
  const services = serviceTypes(checker);
7
9
  function imported(node: ts.ImportSpecifier | ts.NamespaceImport): void {
8
10
  const symbol = checker.getSymbolAtLocation(node.name);
@@ -49,7 +51,7 @@ export function serviceCatalog(program: ts.Program, checker: ts.TypeChecker) {
49
51
  ts.forEachChild(node, discover);
50
52
  }
51
53
  for (const source of program.getSourceFiles()) {
52
- if (!source.fileName.includes("/node_modules/") || source.fileName.includes("/@shivaedev/")) {
54
+ if (!source.fileName.includes("/node_modules/") || prefixes.some((prefix) => source.fileName.includes(`/${prefix}`))) {
53
55
  discover(source);
54
56
  }
55
57
  }
@@ -0,0 +1,46 @@
1
+ import type ts from "typescript";
2
+ import { indirectServiceReferences } from "#adapters/indirectServiceReferences.ts";
3
+ import { serviceAssemblyImports } from "#adapters/serviceAssemblyImports.ts";
4
+ import { directServiceDefinitions, implementationBodies } from "#adapters/serviceAssemblySyntax.ts";
5
+ import { serviceDefinitionProblems } from "#adapters/serviceDefinitionProblems.ts";
6
+ import { defineRule, type Finding, type SourceFile } from "#rule.ts";
7
+ import { parse } from "#rules/parse.ts";
8
+
9
+ function fileFindings(file: SourceFile): readonly Finding[] {
10
+ const source = parse(file);
11
+ if (source === undefined) {
12
+ return [];
13
+ }
14
+ const imports = serviceAssemblyImports(source);
15
+ if (imports.definitions.size === 0 && imports.unsupported.length === 0) {
16
+ return [];
17
+ }
18
+ const definitions = directServiceDefinitions(source, imports.definitions);
19
+ const found = imports.unsupported.map((node) => ({ message: "Import and call defineService directly.", node }));
20
+ for (const node of indirectServiceReferences(source, imports.definitions, definitions)) {
21
+ found.push({ message: "Call the imported defineService directly in a top-level service declaration.", node });
22
+ }
23
+ if (imports.definitions.size > 0 && definitions.length === 0) {
24
+ found.push({ message: "Call the imported defineService directly in a top-level service declaration.", node: source });
25
+ }
26
+ const allowedBodies = new Set<ts.Node>();
27
+ for (const definition of definitions) {
28
+ found.push(...serviceDefinitionProblems(definition, imports.effects, imports.values, allowedBodies, imports.generics));
29
+ }
30
+ for (const node of implementationBodies(source, allowedBodies)) {
31
+ found.push({ message: "Move this implementation body to a named export in its own focused file.", node });
32
+ }
33
+ return found.map(({ node, message }) => ({
34
+ file: file.path,
35
+ line: source.getLineAndCharacterOfPosition(node.getStart(source)).line + 1,
36
+ message,
37
+ }));
38
+ }
39
+
40
+ export const serviceDefinitionAssembly = defineRule({
41
+ check: ({ sources }) => sources.flatMap(fileFindings),
42
+ description:
43
+ "Keep defineService declarations as top-level operation inventories: list id, requires, initialize and methods directly. Import a named initializer (or use Effect.void) and named operations or state factories from focused files; genericMethod may wrap those references. Move implementation bodies out of the assembly file. Effect.fn span names follow the existing Biome checks. Includes adapters and tests; no config exceptions or inline suppressions.",
44
+ id: "effect/service-definition-assembly",
45
+ registrable: false,
46
+ });
@@ -4,7 +4,7 @@ import { defineRule } from "#rule.ts";
4
4
  export const serviceIds = defineRule({
5
5
  check: serviceIdFindings,
6
6
  description:
7
- "Literal Context.Service, Context.Reference, defineService and RPC middleware ids in packages/<name>/ start with @shivaedev/<name>/. Prefix the id and update its references. Includes adapters and tests; computed ids and files outside packages/ are not checked. No config exceptions or inline suppressions.",
7
+ "Literal Context.Service, Context.Reference, defineService and RPC middleware ids in workspace packages under packages/ start with the owning manifest's name and a slash. Prefix the id and update its references. Includes adapters and tests; computed ids, files without a named workspace owner and files outside packages/ are not checked. No config exceptions or inline suppressions.",
8
8
  id: "effect/service-ids",
9
9
  registrable: false,
10
10
  });
@@ -1,35 +1,41 @@
1
1
  import { join } from "node:path";
2
+ import { Effect } from "effect";
3
+ import { readPackageManifest } from "#adapters/manifestInventory.ts";
4
+ import { packageOf, workspacePackages } from "#imports/workspace.ts";
2
5
  import { defineRule, type Finding, type RuleInputs } from "#rule.ts";
3
6
  import { effectProgram } from "#rules/effect/program.ts";
4
7
  import { serviceCatalog } from "#rules/effect/serviceCatalog.ts";
5
8
  import { serviceFindings } from "#rules/effect/serviceFindings.ts";
6
9
 
7
10
  export const serviceParameters = defineRule({
8
- check: (inputs) => {
11
+ check: Effect.fn("Services.check")(function* (inputs: RuleInputs) {
12
+ const packages = yield* Effect.promise(() => workspacePackages(inputs));
13
+ const root = yield* Effect.promise(() => readPackageManifest(inputs.readText, "package.json"));
14
+ const names = [...packages.map((owner) => owner.name), ...(root?.name === undefined ? [] : [root.name])];
9
15
  const groups = new Map<string, RuleInputs["sources"][number][]>();
10
16
  for (const source of inputs.sources) {
11
17
  if (/(?:^|\/)test-support\//u.test(source.path)) {
12
18
  continue;
13
19
  }
14
- const group = /^(?:packages|examples)\/[^/]+/u.exec(source.path)?.[0] ?? ".";
20
+ const group = packageOf(packages, source.path)?.directory ?? ".";
15
21
  const files = groups.get(group) ?? [];
16
22
  files.push(source);
17
23
  groups.set(group, files);
18
24
  }
19
- return [...groups.values()].flatMap((sources) => checkServices({ ...inputs, sources }));
20
- },
25
+ return [...groups.values()].flatMap((sources) => checkServices({ ...inputs, sources }, names));
26
+ }),
21
27
  description:
22
28
  "Exported functions and public methods take services from Effect's environment, including aliases, constraints, inferred/destructured parameters and factory returns. Service keys/classes, non-empty Contexts and implementation shapes are services; Effect/Stream requirements are computations. Service implementation methods and Layer constructors are accepted. Only test-support/ folders are exempt. The fixed adapters/ convention bridges outside libraries to Effect values; adapters still follow this rule and ambient runtime bans. No config exceptions or inline suppressions; baseline existing debt.",
23
29
  id: "effect/service-parameters",
24
30
  registrable: false,
25
31
  });
26
32
 
27
- function checkServices(inputs: RuleInputs): readonly Finding[] {
33
+ function checkServices(inputs: RuleInputs, packages: readonly string[]): readonly Finding[] {
28
34
  const program = effectProgram(inputs);
29
35
  const checker = program.getTypeChecker();
30
36
  const sources = inputs.sources.flatMap((file) => {
31
37
  const source = program.getSourceFile(join(inputs.root, file.path));
32
38
  return source === undefined ? [] : [source];
33
39
  });
34
- return serviceFindings(inputs.root, sources, checker, serviceCatalog(program, checker));
40
+ return serviceFindings(inputs.root, sources, checker, serviceCatalog(program, checker, packages));
35
41
  }
@@ -0,0 +1,10 @@
1
+ import { nativeTransactionFindings } from "#adapters/nativeTransactionFindings.ts";
2
+ import { defineRule } from "#rule.ts";
3
+
4
+ export const sqlTransact = defineRule({
5
+ check: nativeTransactionFindings,
6
+ description:
7
+ "Repository writes and change announcements use transact for their outer transaction instead of native sql.withTransaction. Native transactions containing only reads or raw SQL remain supported.",
8
+ id: "effect/sql-transact",
9
+ registrable: false,
10
+ });
@@ -33,26 +33,26 @@ interface ManifestDependencies {
33
33
  readonly shipped: ReadonlySet<string>;
34
34
  }
35
35
 
36
- async function manifestDependencies(
36
+ const manifestDependencies = Effect.fn("Imports.manifestDependencies")(function* (
37
37
  inputs: RuleInputs,
38
38
  owner: WorkspacePackage,
39
39
  graph: ImportGraph,
40
40
  workspace: ReadonlyMap<string, string>,
41
- ): Promise<ManifestDependencies> {
41
+ ): Effect.fn.Return<ManifestDependencies> {
42
42
  const path = posix.join(owner.directory, "package.json");
43
- const manifest = await readPackageManifest(inputs.readText, path);
43
+ const manifest = yield* Effect.promise(() => readPackageManifest(inputs.readText, path));
44
44
  if (manifest === undefined) {
45
- throw new Error("the manifest is missing");
45
+ return yield* Effect.die(new Error("the manifest is missing"));
46
46
  }
47
47
  return {
48
48
  ...bundleInputs(graph, owner, manifest, (candidate) => developmentFile(owner, candidate)),
49
49
  application: isApplication(manifest),
50
50
  development: new Set(dependencyNames(manifest, "devDependencies")),
51
- entryPoints: await entryPointsOf(inputs, owner.directory, manifest, workspace),
51
+ entryPoints: yield* Effect.promise(() => entryPointsOf(inputs, owner.directory, manifest, workspace)),
52
52
  private: Reflect.get(manifest, "private") === true,
53
53
  shipped: new Set(SHIPPED_FIELDS.flatMap((field) => dependencyNames(manifest, field))),
54
54
  };
55
- }
55
+ });
56
56
 
57
57
  function developmentFile(owner: WorkspacePackage, path: string): boolean {
58
58
  return isTestCode(path) || isTooling(owner.directory, path);
@@ -93,8 +93,14 @@ export const importsManifest = defineRule({
93
93
  const owners = [...graph.packages, ...(root === undefined ? [] : [root])];
94
94
  const workspace = new Map(graph.packages.map((owner) => [owner.name, owner.directory]));
95
95
  const policies = new Map(
96
- yield* Effect.promise(() =>
97
- Promise.all(owners.map(async (owner) => [owner, await manifestDependencies(inputs, owner, graph, workspace)] as const)),
96
+ yield* Effect.forEach(
97
+ owners,
98
+ (owner) =>
99
+ Effect.map(manifestDependencies(inputs, owner, graph, workspace), (policy): readonly [WorkspacePackage, ManifestDependencies] => [
100
+ owner,
101
+ policy,
102
+ ]),
103
+ { concurrency: "unbounded" },
98
104
  ),
99
105
  );
100
106
  const runtime = new Set([...policies.values()].flatMap((policy) => [...policy.runtime]));
@@ -1,5 +1,5 @@
1
- import { join, relative } from "node:path";
2
- import { Effect } from "effect";
1
+ import * as NodePath from "@effect/platform-node/NodePath";
2
+ import { Effect, Path } from "effect";
3
3
  import { readRequiredText } from "#inventory/filesystem.ts";
4
4
  import { posix } from "#inventory/ignoreScope.ts";
5
5
  import { walk } from "#inventory/walk.ts";
@@ -19,6 +19,8 @@ function settingIn(path: string, text: string): readonly Finding[] {
19
19
  export const noIgnoreDeprecations = defineRule({
20
20
  check: ({ root }) =>
21
21
  Effect.gen(function* () {
22
+ const { join, relative } = yield* Path.Path.pipe(Effect.provide(NodePath.layer));
23
+
22
24
  const paths = yield* walk(root);
23
25
  const configs = paths.map((path) => posix(relative(root, path))).filter((path) => path.endsWith(".json"));
24
26
  const findings = yield* Effect.forEach(configs.toSorted(), (path) =>
@@ -0,0 +1,12 @@
1
+ import { Effect } from "effect";
2
+ import { type Assertion, type ExpectStatic, expect } from "vitest";
3
+
4
+ export function assertThat<TValue>(value: TValue, check: (actual: Assertion<void, TValue>, matchers: ExpectStatic) => void): Effect.Effect<void> {
5
+ return Effect.sync(() => check(expect(value), expect));
6
+ }
7
+
8
+ export function withMatchers<TValue, TError, TServices>(
9
+ check: (matchers: ExpectStatic) => Effect.Effect<TValue, TError, TServices>,
10
+ ): Effect.Effect<TValue, TError, TServices> {
11
+ return Effect.suspend(() => check(expect));
12
+ }
@@ -2,10 +2,10 @@ import { spawnSync } from "node:child_process";
2
2
  import { realpathSync } from "node:fs";
3
3
  import { fileURLToPath } from "node:url";
4
4
  import { format } from "node:util";
5
- import { Config, Console, Effect, Option } from "effect";
5
+ import { Config, ConfigProvider, Console, Effect, Option } from "effect";
6
6
  import { program } from "#cli/program.ts";
7
7
  import { exitCode, explained, services } from "#cli/runMain.ts";
8
- import { ISOLATED_ENV } from "#testing/adapters/git.ts";
8
+ import { ISOLATED_ENV, isolatedEnvironment } from "#testing/adapters/git.ts";
9
9
 
10
10
  export interface Run {
11
11
  readonly status: number | null;
@@ -84,21 +84,29 @@ export function capturing(output: Output): Console.Console {
84
84
  }
85
85
 
86
86
  // Runs the executable's program in this process, which imports each config path once: after a command rewrites the config, spawn `quality`.
87
- export async function runQuality(root: string, ...args: readonly string[]): Promise<Run> {
88
- const output: Output = { stderr: "", stdout: "" };
89
- const captured = capturing(output);
90
- const command = program(args, { cwd: realpathSync(root), launch: { options: OPTIONS, script: CLI } });
91
- const restore = await isolateGit();
92
- try {
93
- const exit = await Effect.runPromiseExit(explained(command).pipe(Effect.provideService(Console.Console, captured), Effect.provide(services)));
94
- return { status: exitCode(exit), ...output };
95
- } finally {
96
- restore();
97
- }
87
+ export function runQuality(root: string, ...args: readonly string[]): Effect.Effect<Run> {
88
+ return Effect.scoped(
89
+ Effect.gen(function* () {
90
+ const output: Output = { stderr: "", stdout: "" };
91
+ const command = program(args, { cwd: realpathSync(root), launch: { options: OPTIONS, script: CLI } });
92
+ const environment = ConfigProvider.orElse(
93
+ ConfigProvider.fromEnv({ env: { "HEAVY_PROCESS_LOCK": isolatedEnvironment(root).HEAVY_PROCESS_LOCK } }),
94
+ yield* ConfigProvider.ConfigProvider,
95
+ );
96
+ yield* Effect.acquireRelease(Effect.promise(isolateGit), (restore) => Effect.sync(restore));
97
+ const exit = yield* explained(command).pipe(
98
+ Effect.provideService(ConfigProvider.ConfigProvider, environment),
99
+ Effect.provideService(Console.Console, capturing(output)),
100
+ Effect.provide(services),
101
+ Effect.exit,
102
+ );
103
+ return { status: exitCode(exit), ...output };
104
+ }),
105
+ );
98
106
  }
99
107
 
100
108
  export function quality(root: string, ...args: readonly string[]): Run {
101
- const result = spawnSync("node", qualityArgs(args), { cwd: root, encoding: "utf8", env: ISOLATED_ENV });
109
+ const result = spawnSync("node", qualityArgs(args), { cwd: root, encoding: "utf8", env: isolatedEnvironment(root) });
102
110
  return { status: result.status, stderr: result.stderr, stdout: result.stdout };
103
111
  }
104
112
 
@@ -1,4 +1,5 @@
1
1
  import { execFileSync, spawnSync } from "node:child_process";
2
+ import { resolve } from "node:path";
2
3
  import { Config, Effect, Option } from "effect";
3
4
 
4
5
  const HEAVY_ENV = Object.fromEntries(
@@ -20,6 +21,10 @@ export const ISOLATED_ENV = {
20
21
  "PATH": Effect.runSync(Config.String("PATH")),
21
22
  };
22
23
 
24
+ export function isolatedEnvironment(root: string) {
25
+ return { ...ISOLATED_ENV, "HEAVY_PROCESS_LOCK": resolve(root, "heavy.lock") };
26
+ }
27
+
23
28
  const SETTINGS = [
24
29
  "user.name=Quality",
25
30
  "user.email=quality@example.invalid",
@@ -32,7 +37,7 @@ export function git(root: string, ...args: readonly string[]): string {
32
37
  return execFileSync("git", [...SETTINGS.flatMap((setting) => ["-c", setting]), ...args], {
33
38
  cwd: root,
34
39
  encoding: "utf8",
35
- env: ISOLATED_ENV,
40
+ env: isolatedEnvironment(root),
36
41
  stdio: ["ignore", "pipe", "pipe"],
37
42
  });
38
43
  }
@@ -46,7 +51,7 @@ export function mergeBranch(root: string, branch: string): "merged" | "conflicte
46
51
  const result = spawnSync("git", [...SETTINGS.flatMap((setting) => ["-c", setting]), "merge", "--quiet", "--no-edit", branch], {
47
52
  cwd: root,
48
53
  encoding: "utf8",
49
- env: ISOLATED_ENV,
54
+ env: isolatedEnvironment(root),
50
55
  });
51
56
  if (result.status !== 0 && result.status !== 1) {
52
57
  throw new Error(`git merge failed: ${result.error ?? result.stderr}`);
@@ -4,7 +4,7 @@ import { dirname, join } from "node:path";
4
4
  import sortPackageJson from "sort-package-json";
5
5
  import { shellWords } from "#hooks/command.ts";
6
6
  import { qualityArgs, type Run } from "./cli.ts";
7
- import { commitAll, git, ISOLATED_ENV } from "./git.ts";
7
+ import { commitAll, git, isolatedEnvironment } from "./git.ts";
8
8
  import { formatTree } from "./qualityTree.ts";
9
9
  import { DEFAULT_FILES, linkPackage, type SeedFile, seedTree } from "./tree.ts";
10
10
 
@@ -121,7 +121,11 @@ export function withWorktree(repository: HookRepository, name: string, at?: stri
121
121
  }
122
122
 
123
123
  export function commits(cwd: string, message: string): Run {
124
- const result = spawnSync("git", ["commit", "--quiet", "--allow-empty", "--message", message], { cwd, encoding: "utf8", env: ISOLATED_ENV });
124
+ const result = spawnSync("git", ["commit", "--quiet", "--allow-empty", "--message", message], {
125
+ cwd,
126
+ encoding: "utf8",
127
+ env: isolatedEnvironment(cwd),
128
+ });
125
129
  return { status: result.status, stderr: result.stderr, stdout: result.stdout };
126
130
  }
127
131
 
@@ -60,7 +60,6 @@ function outcomeOf({ status }: Run): string {
60
60
 
61
61
  export function makeRuleStory() {
62
62
  const ruleStory = storyKit({
63
- clock: "live",
64
63
  create: () =>
65
64
  Effect.gen(function* () {
66
65
  const fs = yield* FileSystem.FileSystem;
@@ -87,7 +86,7 @@ export function makeRuleStory() {
87
86
  findings: () => checked(engine),
88
87
  gate: Effect.fn("RuleStory.gate")(function* () {
89
88
  story.tell("quality runs the repository gate");
90
- engine.answer = yield* Effect.promise(() => runQuality(engine.root, "lint"));
89
+ engine.answer = yield* runQuality(engine.root, "lint");
91
90
  }),
92
91
  gateOutcome: () => Effect.map(answered(engine), outcomeOf),
93
92
  gateReport: () => Effect.map(answered(engine), (answer) => answer.stdout + answer.stderr),