@shivaedev/quality 0.60.0 → 0.61.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.
Files changed (107) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/README.md +37 -16
  3. package/dist/adapters/biome/relocateConfig.d.ts +1 -1
  4. package/dist/adapters/biome/relocateConfig.d.ts.map +1 -1
  5. package/dist/adapters/biome/relocateConfig.js +6 -5
  6. package/dist/adapters/biome/relocateConfig.js.map +1 -1
  7. package/dist/adapters/biome/run.d.ts +1 -1
  8. package/dist/adapters/biome/run.d.ts.map +1 -1
  9. package/dist/adapters/biome/run.js +2 -2
  10. package/dist/adapters/biome/run.js.map +1 -1
  11. package/dist/adapters/biome/withExceptionConfig.d.ts +1 -1
  12. package/dist/adapters/biome/withExceptionConfig.d.ts.map +1 -1
  13. package/dist/adapters/biome/withExceptionConfig.js +3 -3
  14. package/dist/adapters/biome/withExceptionConfig.js.map +1 -1
  15. package/dist/adapters/queueReadoutFindings.d.ts.map +1 -1
  16. package/dist/adapters/queueReadoutFindings.js +5 -2
  17. package/dist/adapters/queueReadoutFindings.js.map +1 -1
  18. package/dist/adapters/queueTestingOrigin.js +1 -1
  19. package/dist/adapters/queueTestingOrigin.js.map +1 -1
  20. package/dist/biome/nonEffectPlugins.d.ts +7 -0
  21. package/dist/biome/nonEffectPlugins.d.ts.map +1 -0
  22. package/dist/biome/nonEffectPlugins.js +24 -0
  23. package/dist/biome/nonEffectPlugins.js.map +1 -0
  24. package/dist/biome/report.d.ts +1 -1
  25. package/dist/biome/report.d.ts.map +1 -1
  26. package/dist/biome/report.js +5 -5
  27. package/dist/biome/report.js.map +1 -1
  28. package/dist/cli/baseline.d.ts.map +1 -1
  29. package/dist/cli/baseline.js +0 -6
  30. package/dist/cli/baseline.js.map +1 -1
  31. package/dist/cli/fix.d.ts.map +1 -1
  32. package/dist/cli/fix.js +7 -7
  33. package/dist/cli/fix.js.map +1 -1
  34. package/dist/cli/messages.d.ts +1 -1
  35. package/dist/cli/messages.d.ts.map +1 -1
  36. package/dist/cli/messages.js +1 -1
  37. package/dist/config/decode.d.ts +1 -0
  38. package/dist/config/decode.d.ts.map +1 -1
  39. package/dist/config/decode.js +2 -0
  40. package/dist/config/decode.js.map +1 -1
  41. package/dist/config/load.d.ts +1 -0
  42. package/dist/config/load.d.ts.map +1 -1
  43. package/dist/config/load.js +1 -0
  44. package/dist/config/load.js.map +1 -1
  45. package/dist/config/nonEffectFolders.d.ts +5 -0
  46. package/dist/config/nonEffectFolders.d.ts.map +1 -0
  47. package/dist/config/nonEffectFolders.js +17 -0
  48. package/dist/config/nonEffectFolders.js.map +1 -0
  49. package/dist/config/resolve.d.ts +1 -0
  50. package/dist/config/resolve.d.ts.map +1 -1
  51. package/dist/config.d.ts +1 -0
  52. package/dist/config.d.ts.map +1 -1
  53. package/dist/config.js.map +1 -1
  54. package/dist/engine/runRules.d.ts.map +1 -1
  55. package/dist/engine/runRules.js +4 -1
  56. package/dist/engine/runRules.js.map +1 -1
  57. package/dist/engine/session.d.ts.map +1 -1
  58. package/dist/engine/session.js +1 -0
  59. package/dist/engine/session.js.map +1 -1
  60. package/dist/rule.d.ts +1 -0
  61. package/dist/rule.d.ts.map +1 -1
  62. package/dist/rule.js.map +1 -1
  63. package/dist/rules/biome.js +2 -2
  64. package/dist/rules/biome.js.map +1 -1
  65. package/dist/rules/effect/boundary.js +1 -1
  66. package/dist/rules/effect/boundary.js.map +1 -1
  67. package/dist/rules/effect/serviceParameters.js +1 -1
  68. package/dist/rules/effect/serviceParameters.js.map +1 -1
  69. package/dist/rules/stories/queueReadouts.js +1 -1
  70. package/dist/rules/stories/queueReadouts.js.map +1 -1
  71. package/dist/rules/stories/sources.d.ts +1 -0
  72. package/dist/rules/stories/sources.d.ts.map +1 -1
  73. package/dist/rules/stories/sources.js +17 -0
  74. package/dist/rules/stories/sources.js.map +1 -1
  75. package/dist/rules/stories/waitOnEvents.d.ts.map +1 -1
  76. package/dist/rules/stories/waitOnEvents.js +74 -10
  77. package/dist/rules/stories/waitOnEvents.js.map +1 -1
  78. package/dist/testing/ruleStory.d.ts +1 -0
  79. package/dist/testing/ruleStory.d.ts.map +1 -1
  80. package/dist/testing/ruleStory.js +4 -0
  81. package/dist/testing/ruleStory.js.map +1 -1
  82. package/docs/debt-and-hooks.md +1 -1
  83. package/package.json +14 -14
  84. package/src/adapters/biome/relocateConfig.ts +6 -4
  85. package/src/adapters/biome/run.ts +17 -12
  86. package/src/adapters/biome/withExceptionConfig.ts +3 -2
  87. package/src/adapters/queueReadoutFindings.ts +5 -2
  88. package/src/adapters/queueTestingOrigin.ts +1 -1
  89. package/src/biome/nonEffectPlugins.ts +27 -0
  90. package/src/biome/report.ts +5 -3
  91. package/src/cli/baseline.ts +0 -6
  92. package/src/cli/fix.ts +13 -5
  93. package/src/cli/messages.ts +1 -1
  94. package/src/config/decode.ts +2 -0
  95. package/src/config/load.ts +2 -0
  96. package/src/config/nonEffectFolders.ts +26 -0
  97. package/src/config.ts +1 -0
  98. package/src/engine/runRules.ts +9 -1
  99. package/src/engine/session.ts +1 -0
  100. package/src/rule.ts +1 -0
  101. package/src/rules/biome.ts +2 -2
  102. package/src/rules/effect/boundary.ts +1 -1
  103. package/src/rules/effect/serviceParameters.ts +1 -1
  104. package/src/rules/stories/queueReadouts.ts +1 -1
  105. package/src/rules/stories/sources.ts +18 -0
  106. package/src/rules/stories/waitOnEvents.ts +89 -10
  107. package/src/testing/ruleStory.ts +7 -0
@@ -1,6 +1,7 @@
1
1
  import { basename, isAbsolute, relative } from "node:path";
2
2
  import { Effect } from "effect";
3
3
  import { ManifestFailure } from "#adapters/manifestInventory.ts";
4
+ import { inNonEffectFolder } from "#config/nonEffectFolders.ts";
4
5
  import { SetupFailure } from "#failure.ts";
5
6
  import { FilesystemFailure } from "#inventory/filesystem.ts";
6
7
  import { posix } from "#inventory/ignoreScope.ts";
@@ -67,7 +68,14 @@ function expectedFailure(rule: ActiveRule, root: string, cause: unknown): readon
67
68
 
68
69
  function runRule(rule: ActiveRule, inputs: RuleInputs, exceptionFile: string): Effect.Effect<readonly Violation[], SetupFailure, RuleServices> {
69
70
  return Effect.suspend(() => rule.check(inputs)).pipe(
70
- Effect.map((findings) => findings.map((finding) => violationOf(rule, inputs.root, finding, exceptionFile))),
71
+ Effect.map((findings) =>
72
+ findings
73
+ .filter(
74
+ (finding) =>
75
+ !(rule.id.startsWith("effect/") && inNonEffectFolder(repositoryPath(inputs.root, finding.file), inputs.nonEffectFolders ?? [])),
76
+ )
77
+ .map((finding) => violationOf(rule, inputs.root, finding, exceptionFile)),
78
+ ),
71
79
  Effect.catch((cause) => {
72
80
  const findings = expectedFailure(rule, inputs.root, cause);
73
81
  if (findings !== undefined) {
@@ -40,6 +40,7 @@ export const scan = Effect.fn("Engine.scan")(function* (
40
40
  configFile: relative(config.root, config.file),
41
41
  exceptions: config.exceptions,
42
42
  files: inventory.files,
43
+ nonEffectFolders: config.nonEffectFolders,
43
44
  readText,
44
45
  root: config.root,
45
46
  sources: inventory.sources,
package/src/rule.ts CHANGED
@@ -25,6 +25,7 @@ export interface RuleInputs {
25
25
  readonly configFile?: string;
26
26
  readonly exceptions?: readonly ExceptionDeclaration[];
27
27
  readonly files: readonly string[];
28
+ readonly nonEffectFolders?: readonly string[];
28
29
  readonly readText: (path: string) => Promise<string | undefined>;
29
30
  readonly root: string;
30
31
  readonly signal?: AbortSignal;
@@ -26,9 +26,9 @@ const presetFinding = Effect.fn("Biome.presetFinding")(function* (inputs: Pick<R
26
26
  });
27
27
 
28
28
  const bridge = defineRule({
29
- check: ({ exceptions, readText, root }) =>
29
+ check: ({ exceptions, nonEffectFolders, readText, root }) =>
30
30
  Effect.gen(function* () {
31
- const [preset, report] = yield* Effect.all([presetFinding({ readText }), biomeReport(root, ["check"], exceptions)], {
31
+ const [preset, report] = yield* Effect.all([presetFinding({ readText }), biomeReport(root, ["check"], exceptions, ["."], nonEffectFolders)], {
32
32
  concurrency: "unbounded",
33
33
  });
34
34
  const failing = report.diagnostics.filter((diagnostic) => FAILING.has(diagnostic.severity));
@@ -93,7 +93,7 @@ export const effectBoundary = defineRule({
93
93
  return [...groups.values()].flatMap((sources) => checkBoundary({ ...inputs, sources }));
94
94
  },
95
95
  description:
96
- "Use Effect instead of Promise syntax and parameters, synchronous Node IO, throwing helper calls or Effect.sync with throwing APIs. Runners belong at entry points (including main.tsx and entry.tsx), tool configs and tests. Only adapters/ and test-support/ folders are exempt; calls to throwing helpers defined in adapters/ are accepted. Use Effect services and tagged errors; bridge outside libraries in adapters/. No config exceptions or inline suppressions; baseline existing debt.",
96
+ "Use Effect instead of Promise syntax and parameters, synchronous Node IO, throwing helper calls or Effect.sync with throwing APIs. Runners belong at entry points (including main.tsx and entry.tsx), tool configs and tests. Within Effect code, adapters/ and test-support/ folders are exempt; calls to throwing helpers defined in adapters/ are accepted. Use Effect services and tagged errors; bridge outside libraries in adapters/. No config exceptions or inline suppressions; baseline existing debt.",
97
97
  id: "effect/boundary",
98
98
  registrable: false,
99
99
  });
@@ -25,7 +25,7 @@ export const serviceParameters = defineRule({
25
25
  return [...groups.values()].flatMap((sources) => checkServices({ ...inputs, sources }, names));
26
26
  }),
27
27
  description:
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.",
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. Within Effect code, 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.",
29
29
  id: "effect/service-parameters",
30
30
  registrable: false,
31
31
  });
@@ -3,7 +3,7 @@ import { defineRule } from "#rule.ts";
3
3
 
4
4
  export const queueReadouts = defineRule({
5
5
  check: queueReadoutFindings,
6
- description: "Application tests assert job results, never jobs-testing queue storage; only the jobs package tests its readouts.",
6
+ description: "Application tests assert job results, never jobs-testing queue storage; jobs and the test-kits controller test their own readouts.",
7
7
  id: "tests/queue-readouts",
8
8
  registrable: false,
9
9
  });
@@ -1,5 +1,6 @@
1
1
  import { Effect } from "effect";
2
2
  import ts from "typescript";
3
+ import { outgoing } from "#imports/fences/reach.ts";
3
4
  import { importGraph } from "#imports/graph.ts";
4
5
  import { packageOf } from "#imports/workspace.ts";
5
6
  import { isTestSupport, testName } from "#naming/testName.ts";
@@ -30,3 +31,20 @@ export const storySources = Effect.fn("Stories.storySources")(function* (inputs:
30
31
  return source !== undefined && hasStory(source);
31
32
  });
32
33
  });
34
+
35
+ export const storyWaitSources = Effect.fn("Stories.storyWaitSources")(function* (inputs: RuleInputs) {
36
+ const stories = yield* storySources(inputs);
37
+ const graph = yield* importGraph(inputs);
38
+ const edges = outgoing(graph.edges.filter((edge) => edge.kind === "import" && !edge.type));
39
+ const reached = new Set(stories.map((file) => file.path));
40
+ const queue = [...reached];
41
+ for (const file of queue) {
42
+ for (const edge of edges.get(file) ?? []) {
43
+ if (edge.to.kind === "file" && !reached.has(edge.to.path)) {
44
+ reached.add(edge.to.path);
45
+ queue.push(edge.to.path);
46
+ }
47
+ }
48
+ }
49
+ return inputs.sources.filter((file) => stories.includes(file) || (isTestSupport(file.path) && reached.has(file.path)));
50
+ });
@@ -1,17 +1,93 @@
1
1
  import { Effect } from "effect";
2
2
  import ts from "typescript";
3
+ import { isTestSupport } from "#naming/testName.ts";
3
4
  import { defineRule } from "#rule.ts";
4
5
  import { bindsModule, type ImportBinding, importBindings } from "./importBindings.ts";
5
- import { storySources } from "./sources.ts";
6
+ import { storyWaitSources } from "./sources.ts";
6
7
  import { memberName, syntaxFindings, unwrapped } from "./syntax.ts";
7
8
 
8
9
  const MESSAGE =
9
- "Waits on time in a story: a sleep, a timer, polling with eventually or waitFor, fake timers or a TestClock adjustment. Settle on the engine's own signal through a kit verb, such as a Deferred the engine completes, story.runUntil or screenDriver's settle(); when time passing is the behaviour, name it in a kit verb that advances the clock.";
10
+ "Waits on time in a story or reachable test-support: a sleep, a timer, polling with eventually or waitFor, fake timers or a clock adjustment in the spec. Settle on the engine's own signal through a kit verb, such as a Deferred the engine completes, story.runUntil or screenDriver's settle(). A deadline bounds a failure but does not prove completion; reaching it must fail the story. When time passing is the behaviour, name it in a kit verb that advances TestClock.";
10
11
 
11
12
  const TIMERS = new Set(["setInterval", "setTimeout"]);
12
13
  const VI_TIMING = /^(?:useFakeTimers|advanceTimers\w*|runAllTimers\w*|runOnlyPendingTimers\w*|runAllTicks|setSystemTime|waitFor|waitUntil)$/u;
13
14
  const CLOCK_CHANGES = new Set(["adjust", "setTime"]);
14
15
 
16
+ function terminal(body: ts.ConciseBody): ts.Expression | undefined {
17
+ if (!ts.isBlock(body)) {
18
+ return unwrapped(body);
19
+ }
20
+ const last = body.statements.at(-1);
21
+ return last !== undefined && (ts.isReturnStatement(last) || ts.isExpressionStatement(last)) ? last.expression : undefined;
22
+ }
23
+
24
+ function fails(expression: ts.Expression, bindings: ReadonlyMap<string, ImportBinding>): boolean {
25
+ const value = unwrapped(expression);
26
+ if (ts.isArrowFunction(value) || ts.isFunctionExpression(value)) {
27
+ const result = terminal(value.body);
28
+ return result !== undefined && fails(result, bindings);
29
+ }
30
+ if (!(ts.isCallExpression(value) && ts.isPropertyAccessExpression(value.expression))) {
31
+ return false;
32
+ }
33
+ const receiver = value.expression.expression;
34
+ return (
35
+ ts.isIdentifier(receiver)
36
+ && bindsModule(bindings.get(receiver.text), "Effect", ["effect"])
37
+ && ["die", "fail"].includes(value.expression.name.text)
38
+ );
39
+ }
40
+
41
+ function failingSleep(call: ts.CallExpression, bindings: ReadonlyMap<string, ImportBinding>): boolean {
42
+ const access = call.parent;
43
+ const pipe = access.parent;
44
+ if (!(ts.isPropertyAccessExpression(access) && access.name.text === "pipe" && ts.isCallExpression(pipe) && pipe.arguments.length === 1)) {
45
+ return false;
46
+ }
47
+ const step = pipe.arguments[0];
48
+ if (step === undefined || !ts.isCallExpression(step) || memberName(step.expression) !== "andThen") {
49
+ return false;
50
+ }
51
+ const receiver = ts.isPropertyAccessExpression(step.expression) ? step.expression.expression : undefined;
52
+ return (
53
+ receiver !== undefined
54
+ && ts.isIdentifier(receiver)
55
+ && bindsModule(bindings.get(receiver.text), "Effect", ["effect"])
56
+ && step.arguments.length === 1
57
+ && step.arguments[0] !== undefined
58
+ && fails(step.arguments[0], bindings)
59
+ );
60
+ }
61
+
62
+ function rejectionName(call: ts.CallExpression): string | undefined {
63
+ for (let node: ts.Node | undefined = call.parent; node !== undefined; node = node.parent) {
64
+ if (
65
+ (ts.isArrowFunction(node) || ts.isFunctionExpression(node))
66
+ && ts.isNewExpression(node.parent)
67
+ && ts.isIdentifier(node.parent.expression)
68
+ && node.parent.expression.text === "Promise"
69
+ ) {
70
+ const name = node.parameters[1]?.name;
71
+ return name !== undefined && ts.isIdentifier(name) ? name.text : undefined;
72
+ }
73
+ }
74
+ return undefined;
75
+ }
76
+
77
+ function rejectingTimer(call: ts.CallExpression): boolean {
78
+ const reject = rejectionName(call);
79
+ const callback = call.arguments[0];
80
+ if (reject === undefined || callback === undefined) {
81
+ return false;
82
+ }
83
+ const body = ts.isArrowFunction(callback) || ts.isFunctionExpression(callback) ? terminal(callback.body) : callback;
84
+ return (
85
+ body !== undefined
86
+ && ((ts.isIdentifier(body) && body.text === reject)
87
+ || (ts.isCallExpression(body) && ts.isIdentifier(body.expression) && body.expression.text === reject))
88
+ );
89
+ }
90
+
15
91
  function receiverOf(callee: ts.Expression): ts.Identifier | undefined {
16
92
  const receiver = ts.isPropertyAccessExpression(callee) ? unwrapped(callee.expression) : undefined;
17
93
  return receiver !== undefined && ts.isIdentifier(receiver) ? receiver : undefined;
@@ -22,10 +98,12 @@ function vitestTiming(receiver: ts.Identifier, bindings: ReadonlyMap<string, Imp
22
98
  return binding === undefined ? receiver.text === "vi" : bindsModule(binding, "vi", ["vitest", "@effect/vitest"]);
23
99
  }
24
100
 
25
- function timedWait(call: ts.CallExpression, bindings: ReadonlyMap<string, ImportBinding>): boolean {
101
+ function timedWait(call: ts.CallExpression, bindings: ReadonlyMap<string, ImportBinding>, support: boolean): boolean {
26
102
  const callee = unwrapped(call.expression);
27
103
  if (ts.isIdentifier(callee)) {
28
- return TIMERS.has(callee.text) || bindings.get(callee.text)?.imported === "eventually";
104
+ return (
105
+ (TIMERS.has(callee.text) && !(callee.text === "setTimeout" && rejectingTimer(call))) || bindings.get(callee.text)?.imported === "eventually"
106
+ );
29
107
  }
30
108
  const member = memberName(callee) ?? "";
31
109
  const receiver = receiverOf(callee);
@@ -34,18 +112,19 @@ function timedWait(call: ts.CallExpression, bindings: ReadonlyMap<string, Import
34
112
  }
35
113
  const binding = bindings.get(receiver.text);
36
114
  return (
37
- (member === "sleep" && bindsModule(binding, "Effect", ["effect"]))
115
+ (member === "sleep" && bindsModule(binding, "Effect", ["effect"]) && !failingSleep(call, bindings))
38
116
  || (VI_TIMING.test(member) && vitestTiming(receiver, bindings))
39
- || (CLOCK_CHANGES.has(member) && bindsModule(binding, "TestClock", ["effect/testing"]))
40
- || (TIMERS.has(member) && receiver.text === "globalThis")
117
+ || (!support && CLOCK_CHANGES.has(member) && bindsModule(binding, "TestClock", ["effect/testing"]))
118
+ || (TIMERS.has(member) && receiver.text === "globalThis" && !(member === "setTimeout" && rejectingTimer(call)))
41
119
  );
42
120
  }
43
121
 
44
122
  function timedWaits(source: ts.SourceFile): readonly ts.Node[] {
45
123
  const bindings = importBindings(source);
124
+ const support = isTestSupport(source.fileName);
46
125
  const found: ts.Node[] = [];
47
126
  function visit(node: ts.Node): void {
48
- if (ts.isCallExpression(node) && timedWait(node, bindings)) {
127
+ if (ts.isCallExpression(node) && timedWait(node, bindings, support)) {
49
128
  found.push(node);
50
129
  }
51
130
  ts.forEachChild(node, visit);
@@ -55,7 +134,7 @@ function timedWaits(source: ts.SourceFile): readonly ts.Node[] {
55
134
  }
56
135
 
57
136
  export const waitOnEvents = defineRule({
58
- check: (inputs) => Effect.map(storySources(inputs), (stories) => stories.flatMap((file) => syntaxFindings(file, timedWaits, MESSAGE))),
59
- description: "Stories settle on the engine's own signals, never on sleeps, polling, fake timers or clock adjustments in the story.",
137
+ check: (inputs) => Effect.map(storyWaitSources(inputs), (sources) => sources.flatMap((file) => syntaxFindings(file, timedWaits, MESSAGE))),
138
+ description: "Stories and reachable test-support settle on the engine's own signals; controlled clock advances belong in kit verbs.",
60
139
  id: "tests/wait-on-events",
61
140
  });
@@ -90,6 +90,13 @@ export function makeRuleStory() {
90
90
  }),
91
91
  gateOutcome: () => Effect.map(answered(engine), outcomeOf),
92
92
  gateReport: () => Effect.map(answered(engine), (answer) => answer.stdout + answer.stderr),
93
+ gateReports: (prefix: string) =>
94
+ Effect.map(answered(engine), (answer) =>
95
+ answer.stdout
96
+ .split("\n\n")
97
+ .filter((section) => section.startsWith(`error ${prefix}`))
98
+ .join("\n\n"),
99
+ ),
93
100
  locations: () => Effect.map(checked(engine), (findings) => findings.map(locationOf)),
94
101
  messages: () => Effect.map(checked(engine), (findings) => findings.map((finding) => finding.message)),
95
102
  optionIssues: Effect.fn("RuleStory.optionIssues")(function* (rule: RegisteredRule, options: unknown) {