@shivaedev/quality 0.50.0 → 0.52.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 (80) hide show
  1. package/CHANGELOG.md +28 -0
  2. package/README.md +20 -5
  3. package/biome/plugins/ambient-runtime.grit +1 -1
  4. package/dist/baseline/format.d.ts +1 -0
  5. package/dist/baseline/format.d.ts.map +1 -1
  6. package/dist/baseline/format.js +3 -2
  7. package/dist/baseline/format.js.map +1 -1
  8. package/dist/baseline/update.js +1 -1
  9. package/dist/baseline/update.js.map +1 -1
  10. package/dist/config/resolve.d.ts.map +1 -1
  11. package/dist/config/resolve.js +9 -6
  12. package/dist/config/resolve.js.map +1 -1
  13. package/dist/imports/fences/compilePolicy.d.ts.map +1 -1
  14. package/dist/imports/fences/compilePolicy.js +6 -2
  15. package/dist/imports/fences/compilePolicy.js.map +1 -1
  16. package/dist/inventory/shadcnAlias.js.map +1 -1
  17. package/dist/rules/builtIn.d.ts +1 -1
  18. package/dist/rules/builtIn.d.ts.map +1 -1
  19. package/dist/rules/builtIn.js +2 -0
  20. package/dist/rules/builtIn.js.map +1 -1
  21. package/dist/rules/effect/boundary.js +1 -1
  22. package/dist/rules/effect/boundary.js.map +1 -1
  23. package/dist/rules/effect/boundaryCalls.js +1 -1
  24. package/dist/rules/effect/boundaryCalls.js.map +1 -1
  25. package/dist/rules/effect/boundaryReference.js +1 -1
  26. package/dist/rules/effect/boundaryReference.js.map +1 -1
  27. package/dist/rules/effect/failureFindings.d.ts +8 -0
  28. package/dist/rules/effect/failureFindings.d.ts.map +1 -0
  29. package/dist/rules/effect/failureFindings.js +47 -0
  30. package/dist/rules/effect/failureFindings.js.map +1 -0
  31. package/dist/rules/effect/failureHonesty.d.ts +2 -0
  32. package/dist/rules/effect/failureHonesty.d.ts.map +1 -0
  33. package/dist/rules/effect/failureHonesty.js +53 -0
  34. package/dist/rules/effect/failureHonesty.js.map +1 -0
  35. package/dist/rules/effect/failureOperations.d.ts +9 -0
  36. package/dist/rules/effect/failureOperations.d.ts.map +1 -0
  37. package/dist/rules/effect/failureOperations.js +55 -0
  38. package/dist/rules/effect/failureOperations.js.map +1 -0
  39. package/dist/rules/effect/successRecovery.d.ts +3 -0
  40. package/dist/rules/effect/successRecovery.d.ts.map +1 -0
  41. package/dist/rules/effect/successRecovery.js +43 -0
  42. package/dist/rules/effect/successRecovery.js.map +1 -0
  43. package/dist/rules/noBarrel.js +1 -1
  44. package/dist/rules/noBarrel.js.map +1 -1
  45. package/dist/rules/secondNames.d.ts.map +1 -1
  46. package/dist/rules/secondNames.js +5 -1
  47. package/dist/rules/secondNames.js.map +1 -1
  48. package/dist/rules/suppressions/hiddenCast.d.ts +4 -0
  49. package/dist/rules/suppressions/hiddenCast.d.ts.map +1 -0
  50. package/dist/rules/suppressions/hiddenCast.js +80 -0
  51. package/dist/rules/suppressions/hiddenCast.js.map +1 -0
  52. package/dist/rules/suppressions/noDoubleCast.d.ts.map +1 -1
  53. package/dist/rules/suppressions/noDoubleCast.js +55 -4
  54. package/dist/rules/suppressions/noDoubleCast.js.map +1 -1
  55. package/dist/rules/suppressions/readonlyWrite.d.ts +4 -0
  56. package/dist/rules/suppressions/readonlyWrite.d.ts.map +1 -0
  57. package/dist/rules/suppressions/readonlyWrite.js +113 -0
  58. package/dist/rules/suppressions/readonlyWrite.js.map +1 -0
  59. package/dist/unitIoGuard.config.js +2 -2
  60. package/dist/unitIoGuard.config.js.map +1 -1
  61. package/package.json +2 -2
  62. package/src/baseline/format.ts +4 -2
  63. package/src/baseline/update.ts +1 -1
  64. package/src/config/resolve.ts +4 -6
  65. package/src/imports/fences/compilePolicy.ts +10 -2
  66. package/src/inventory/shadcnAlias.ts +1 -1
  67. package/src/rules/builtIn.ts +2 -0
  68. package/src/rules/effect/boundary.ts +1 -1
  69. package/src/rules/effect/boundaryCalls.ts +1 -1
  70. package/src/rules/effect/boundaryReference.ts +1 -1
  71. package/src/rules/effect/failureFindings.ts +55 -0
  72. package/src/rules/effect/failureHonesty.ts +59 -0
  73. package/src/rules/effect/failureOperations.ts +66 -0
  74. package/src/rules/effect/successRecovery.ts +44 -0
  75. package/src/rules/noBarrel.ts +1 -1
  76. package/src/rules/secondNames.ts +7 -1
  77. package/src/rules/suppressions/hiddenCast.ts +95 -0
  78. package/src/rules/suppressions/noDoubleCast.ts +61 -5
  79. package/src/rules/suppressions/readonlyWrite.ts +140 -0
  80. package/src/unitIoGuard.config.ts +3 -3
@@ -6,8 +6,8 @@ const installed = Symbol.for("@shivaedev/quality/unitIoGuard");
6
6
  let loading = 0;
7
7
  function assertUnitIoAllowed(call, boundary) {
8
8
  const worker = Reflect.get(globalThis, "__vitest_worker__");
9
- const file = worker?.filepath;
10
- if (loading > 0 || file === undefined || !/\.unit\.(?:test|spec)\.[cm]?[jt]sx?$/u.test(file)) {
9
+ const file = typeof worker === "object" && worker !== null && "filepath" in worker ? worker.filepath : undefined;
10
+ if (loading > 0 || typeof file !== "string" || !/\.unit\.(?:test|spec)\.[cm]?[jt]sx?$/u.test(file)) {
11
11
  return;
12
12
  }
13
13
  const error = new Error(`Unit test ${file} cannot call ${call}; use a story through the package's kit for I/O.`);
@@ -1 +1 @@
1
- {"version":3,"file":"unitIoGuard.config.js","sourceRoot":"","sources":["../src/unitIoGuard.config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AACnE,6EAA6E;AAC7E,OAAO,cAAc,CAAC;AAEtB,MAAM,IAAI,GAAG,aAAa,CAAC,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC;AAC5C,MAAM,SAAS,GAAG,MAAM,CAAC,GAAG,CAAC,gCAAgC,CAAC,CAAC;AAC/D,IAAI,OAAO,GAAG,CAAC,CAAC;AAEhB,SAAS,mBAAmB,CAAC,IAAY,EAAE,QAAuC;IACjF,MAAM,MAAM,GAA+C,OAAO,CAAC,GAAG,CAAC,UAAU,EAAE,mBAAmB,CAAC,C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AE,SAAS,CAAC,CAAC,CAAC;QACrE,CAAC,CAAC;QACF,MAAM,CAAC,cAAc,CAAC,MAAM,EAAE,GAAG,EAAE;YAClC,YAAY,EAAE,IAAI;YAClB,UAAU,EAAE,IAAI;YAChB,KAAK,EAAE,IAAI,KAAK,CAAC,QAAQ,EAAE,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC;YAChD,QAAQ,EAAE,IAAI;SACd,CAAC,CAAC;IACJ,CAAC;AACF,CAAC;AAED,IAAI,OAAO,CAAC,GAAG,CAAC,UAAU,EAAE,SAAS,CAAC,KAAK,IAAI,EAAE,CAAC;IACjD,OAAO,CAAC,GAAG,CAAC,UAAU,EAAE,SAAS,EAAE,IAAI,CAAC,CAAC;IACzC,KAAK,MAAM,IAAI,IAAI,CAAC,SAAS,EAAE,kBAAkB,EAAE,UAAU,EAAE,WAAW,EAAE,YAAY,EAAE,oBAAoB,EAAE,qBAAqB,CAAC,EAAE,CAAC;QACxI,WAAW,CAAC,IAAI,CAAC,CAAC;IACnB,CAAC;IACD,MAAM,KAAK,GAAG,UAAU,CAAC,KAAK,CAAC;IAC/B,UAAU,CAAC,KAAK,GAAG,SAAS,WAAW,CAAC,GAAG,IAAI;QAC9C,mBAAmB,CAAC,OAAO,EAAE,WAAW,CAAC,CAAC;QAC1C,OAAO,KAAK,CAAC,GAAG,IAAI,CAAC,CAAC;IACvB,CAAC,CAAC;IACF,qBAAqB,EAAE,CAAC;AACzB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shivaedev/quality",
3
- "version": "0.50.0",
3
+ "version": "0.52.0",
4
4
  "description": "Repository quality gate with typed rules, a baseline of existing debt and a registry of reasoned exceptions",
5
5
  "homepage": "https://github.com/ShivaeDev/platform/tree/main/packages/quality#readme",
6
6
  "bugs": {
@@ -62,7 +62,7 @@
62
62
  "@effect/platform-node": "4.0.6",
63
63
  "@effect/platform-node-shared": "4.0.6",
64
64
  "@effect/vitest": "4.0.6",
65
- "@shivaedev/test-story": "0.30.0",
65
+ "@shivaedev/test-story": "0.31.1",
66
66
  "@types/node": "24.19.2",
67
67
  "@typescript/native": "npm:typescript@7.0.2",
68
68
  "effect": "4.0.6",
@@ -5,6 +5,7 @@ import { keyOf } from "#engine/violation.ts";
5
5
  const Line = Schema.Struct({
6
6
  count: Schema.Int.check(Schema.isGreaterThan(0)),
7
7
  path: Schema.NonEmptyString,
8
+ reason: Schema.optionalKey(Schema.NonEmptyString),
8
9
  rule: Schema.NonEmptyString,
9
10
  });
10
11
 
@@ -13,6 +14,7 @@ const BaselineLine = Schema.fromJsonString(Line);
13
14
  export interface BaselineEntry {
14
15
  readonly count: number;
15
16
  readonly file: string;
17
+ readonly reason?: string;
16
18
  readonly rule: string;
17
19
  }
18
20
 
@@ -51,10 +53,10 @@ export async function decodeBaseline(raw: string | undefined): Promise<Decoded<r
51
53
  return issues.length === 0 ? { _tag: "Valid", value: entries } : { _tag: "Invalid", issues };
52
54
  }
53
55
 
54
- const LINE_KEYS = ["path", "rule", "count"];
56
+ const LINE_KEYS = ["path", "rule", "count", "reason"];
55
57
 
56
58
  export function encodeEntry(entry: BaselineEntry): string {
57
- return JSON.stringify({ count: entry.count, path: entry.file, rule: entry.rule }, LINE_KEYS);
59
+ return JSON.stringify({ count: entry.count, path: entry.file, reason: entry.reason, rule: entry.rule }, LINE_KEYS);
58
60
  }
59
61
 
60
62
  export function encodeBaseline(entries: readonly BaselineEntry[]): string {
@@ -96,7 +96,7 @@ export function prune(
96
96
  return [];
97
97
  }
98
98
  moved += Number(now.file !== before.file);
99
- return [{ after: { count: Math.min(before.count, now.count), file: now.file, rule: before.rule }, before }];
99
+ return [{ after: { ...before, count: Math.min(before.count, now.count), file: now.file }, before }];
100
100
  });
101
101
  return {
102
102
  entries: kept.map(({ after }) => after),
@@ -39,18 +39,16 @@ function activeRule(rule: Rule, check: ActiveRule["check"]): ActiveRule {
39
39
 
40
40
  function activate(rule: Rule, setting: Setting | undefined): Effect.Effect<Decoded<ActiveRule>> {
41
41
  return Effect.tryPromise({ catch: messageOf, try: () => rule.configure(optionsOf(setting)) }).pipe(
42
- Effect.map(
43
- (configured): Decoded<ActiveRule> =>
42
+ Effect.match({
43
+ onFailure: (failure): Decoded<ActiveRule> => ({ _tag: "Invalid", issues: [`rules.${rule.id}.options: validation threw: ${failure}`] }),
44
+ onSuccess: (configured): Decoded<ActiveRule> =>
44
45
  configured._tag === "Invalid"
45
46
  ? { _tag: "Invalid", issues: configured.issues.map((issue) => `rules.${rule.id}.options: ${issue}`) }
46
47
  : {
47
48
  _tag: "Valid",
48
49
  value: activeRule(rule, configured.check),
49
50
  },
50
- ),
51
- Effect.catch((failure: string) =>
52
- Effect.succeed<Decoded<ActiveRule>>({ _tag: "Invalid", issues: [`rules.${rule.id}.options: validation threw: ${failure}`] }),
53
- ),
51
+ }),
54
52
  );
55
53
  }
56
54
 
@@ -31,8 +31,16 @@ function crossedBy(policy: readonly CompiledFence[], graph: FenceGraph): readonl
31
31
  return policy.filter((compiled) => compiled.evaluate(graph).length > 0).map((compiled) => compiled.fence.name);
32
32
  }
33
33
 
34
- function exampleIssues(policy: readonly CompiledFence[], fence: Fence): readonly string[] {
34
+ function exampleIssues(policy: readonly CompiledFence[], fence: Fence, scope: PolicyScope): readonly string[] {
35
35
  const where = `fence "${fence.name}"`;
36
+ const missing = (["illegal", "legal"] as const).flatMap((kind) =>
37
+ fence.examples[kind].flatMap((step) =>
38
+ typeof step === "string" && !scope.files.includes(step) ? [`${where}: the ${kind} example names "${step}", which is no checked file`] : [],
39
+ ),
40
+ );
41
+ if (missing.length > 0) {
42
+ return missing;
43
+ }
36
44
  const illegal = graphOf(fence.examples.illegal);
37
45
  const legal = graphOf(fence.examples.legal);
38
46
  if (illegal === undefined || legal === undefined) {
@@ -62,7 +70,7 @@ export function compilePolicy(fences: readonly Fence[], scope: PolicyScope): rea
62
70
  const issues = [...declarationIssues(fences)];
63
71
  const policy = fences.map((fence) => compileFence({ issues, scope }, fence));
64
72
  if (issues.length === 0) {
65
- issues.push(...fences.flatMap((fence) => exampleIssues(policy, fence)));
73
+ issues.push(...fences.flatMap((fence) => exampleIssues(policy, fence, scope)));
66
74
  }
67
75
  if (issues.length > 0) {
68
76
  throw new Error(`the fence policy is invalid:\n${issues.map((issue) => ` - ${issue}`).join("\n")}`);
@@ -16,7 +16,7 @@ function capture(pattern: string, alias: string): string | undefined {
16
16
  }
17
17
 
18
18
  function pathTarget(alias: string, options: ts.CompilerOptions, directory: string): string | undefined {
19
- const pathsBase = Reflect.get(options, "pathsBasePath");
19
+ const pathsBase: unknown = Reflect.get(options, "pathsBasePath");
20
20
  const base = options.baseUrl ?? (typeof pathsBase === "string" ? pathsBase : directory);
21
21
  const patterns = Object.entries(options.paths ?? {}).toSorted(([left], [right]) => right.indexOf("*") - left.indexOf("*"));
22
22
  const exact = options.paths?.[alias]?.[0];
@@ -8,6 +8,7 @@ import { noTodo } from "#rules/comments/noTodo.ts";
8
8
  import { docsReferences } from "#rules/docs/references.ts";
9
9
  import { docsUnversionedInstalls } from "#rules/docs/unversionedInstalls.ts";
10
10
  import { effectBoundary } from "#rules/effect/boundary.ts";
11
+ import { failureHonesty } from "#rules/effect/failureHonesty.ts";
11
12
  import { serviceParameters } from "#rules/effect/serviceParameters.ts";
12
13
  import { distinctCase } from "#rules/files/distinctCase.ts";
13
14
  import { folderNames } from "#rules/files/folderNames.ts";
@@ -55,6 +56,7 @@ import { unusedCode } from "./unusedCode.ts";
55
56
  export const builtInRules = [
56
57
  unusedCode,
57
58
  effectBoundary,
59
+ failureHonesty,
58
60
  serviceParameters,
59
61
  jsxConditionals,
60
62
  maxLines,
@@ -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, tool configs and tests. Only adapters/ and test-support/ folders are exempt. 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. 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.",
97
97
  id: "effect/boundary",
98
98
  registrable: false,
99
99
  });
@@ -77,7 +77,7 @@ export function boundaryCalls(checker: ts.TypeChecker) {
77
77
  }
78
78
  function guard(call: ts.CallExpression): boolean {
79
79
  const body = functionBody(checker, call.expression);
80
- return body !== undefined && throws(body);
80
+ return body !== undefined && !/(?:^|\/)adapters\//u.test(body.getSourceFile().fileName) && throws(body);
81
81
  }
82
82
  function unsafeSync(call: ts.CallExpression): boolean {
83
83
  const callback = call.arguments[0];
@@ -66,7 +66,7 @@ export function boundaryReference(checker: ts.TypeChecker, node: ts.Node, seen =
66
66
  }
67
67
 
68
68
  export function boundaryEntryPoint(path: string, source: ts.SourceFile, checker: ts.TypeChecker): boolean {
69
- if (/(?:^|\/)(?:cli|main|[^/]+-cli)\.[cm]?[jt]sx?$|\.(?:config|test|spec)\.[cm]?[jt]sx?$/u.test(path)) {
69
+ if (/(?:^|\/)(?:cli|main|entry|[^/]+-cli)\.[cm]?[jt]sx?$|\.(?:config|test|spec)\.[cm]?[jt]sx?$/u.test(path)) {
70
70
  return true;
71
71
  }
72
72
  function visit(node: ts.Node): boolean {
@@ -0,0 +1,55 @@
1
+ import ts from "typescript";
2
+ import { effectName, type FailureOperation, failureOperations, fileSystemCall } from "./failureOperations.ts";
3
+ import { successRecovery } from "./successRecovery.ts";
4
+
5
+ interface FailureFinding {
6
+ readonly message: string;
7
+ readonly node: ts.Node;
8
+ }
9
+
10
+ function unboundedRetry(node: ts.CallExpression): boolean {
11
+ const options = node.arguments.at(-1);
12
+ if (options === undefined || !ts.isObjectLiteralExpression(options)) {
13
+ return false;
14
+ }
15
+ const names = options.properties.flatMap((property) => (property.name === undefined ? [] : [property.name.getText().replaceAll(/["']/gu, "")]));
16
+ return names.includes("while") && !names.includes("times") && !names.includes("schedule") && !options.properties.some(ts.isSpreadAssignment);
17
+ }
18
+
19
+ function operationFailure(checker: ts.TypeChecker, operation: FailureOperation, before: readonly FailureOperation[]): string | undefined {
20
+ if (["option", "orElseSucceed"].includes(operation.name) && before.some((part) => fileSystemCall(checker, part.node))) {
21
+ return "FileSystem failure becomes absence or success. Catch a named reason such as NotFound, re-fail other errors, or return an explicit unavailable state.";
22
+ }
23
+ if (/^fork(?:Scoped|In|Detach|Daemon|Child)?$/u.test(operation.name)) {
24
+ const names = before.map((part) => part.name);
25
+ const forever = names.indexOf("forever");
26
+ if (forever !== -1 && names.indexOf("orDie", forever + 1) !== -1) {
27
+ return "Forked forever loop dies on failure. Catch a named reason within each iteration with a Schedule-bounded retry, or expose an explicit unavailable state and supervise termination.";
28
+ }
29
+ }
30
+ return undefined;
31
+ }
32
+
33
+ export function failureFindings(checker: ts.TypeChecker, node: ts.CallExpression): readonly FailureFinding[] {
34
+ const findings: FailureFinding[] = [];
35
+ const name = effectName(checker, node.expression);
36
+ if (name === "retry" && unboundedRetry(node)) {
37
+ findings.push({ message: "Retry has while without times or schedule. Use a Schedule-bounded retry and preserve the final typed failure.", node });
38
+ }
39
+ const handler = node.arguments.at(-1);
40
+ if (["catch", "catchAll", "catchCause", "catchAllCause"].includes(name ?? "") && handler !== undefined && successRecovery(checker, handler)) {
41
+ findings.push({
42
+ message:
43
+ "Catch turns every failure into success. Catch a named reason with catchTag or catchIf and re-fail the rest, or model an explicit unavailable state.",
44
+ node,
45
+ });
46
+ }
47
+ const operations = failureOperations(checker, node);
48
+ for (const [index, operation] of operations.entries()) {
49
+ const message = operationFailure(checker, operation, operations.slice(0, index));
50
+ if (message !== undefined) {
51
+ findings.push({ message, node: operation.node });
52
+ }
53
+ }
54
+ return findings;
55
+ }
@@ -0,0 +1,59 @@
1
+ import { join } from "node:path";
2
+ import ts from "typescript";
3
+ import { defineRule, type Finding, type RuleInputs } from "#rule.ts";
4
+ import { failureFindings } from "./failureFindings.ts";
5
+ import { effectProgram } from "./program.ts";
6
+
7
+ function checkFailures(inputs: RuleInputs): readonly Finding[] {
8
+ const program = effectProgram(inputs, false);
9
+ const checker = program.getTypeChecker();
10
+ return inputs.sources.flatMap((file) => {
11
+ const source = program.getSourceFile(join(inputs.root, file.path));
12
+ const findings: Finding[] = [];
13
+ const reported = new Set<string>();
14
+ function report(node: ts.Node, message: string): void {
15
+ const key = `${node.pos}:${message}`;
16
+ if (source !== undefined && !reported.has(key)) {
17
+ reported.add(key);
18
+ findings.push({ file: file.path, line: source.getLineAndCharacterOfPosition(node.getStart(source)).line + 1, message });
19
+ }
20
+ }
21
+ function visit(node: ts.Node): void {
22
+ if (ts.isCallExpression(node)) {
23
+ for (const finding of failureFindings(checker, node)) {
24
+ report(finding.node, finding.message);
25
+ }
26
+ }
27
+ ts.forEachChild(node, visit);
28
+ }
29
+ if (source !== undefined) {
30
+ visit(source);
31
+ }
32
+ return findings;
33
+ });
34
+ }
35
+
36
+ export const failureHonesty = defineRule({
37
+ check: (inputs) => {
38
+ const groups = new Map<string, RuleInputs["sources"][number][]>();
39
+ for (const source of inputs.sources) {
40
+ if (
41
+ !(
42
+ /\.[cm]?[jt]sx?$/u.test(source.path)
43
+ && /\b(?:catch|catchAll|catchCause|catchAllCause|retry|forever|option|orElseSucceed)\b/u.test(source.text)
44
+ )
45
+ ) {
46
+ continue;
47
+ }
48
+ const group = /^(?:packages|examples)\/[^/]+/u.exec(source.path)?.[0] ?? ".";
49
+ const sources = groups.get(group) ?? [];
50
+ sources.push(source);
51
+ groups.set(group, sources);
52
+ }
53
+ return [...groups.values()].flatMap((sources) => checkFailures({ ...inputs, sources }));
54
+ },
55
+ description:
56
+ "Keep failures typed and observable: no forked forever/orDie loops, retry({ while }) without a bound, blanket catch-to-success, or FileSystem option/orElseSucceed. Catch a named reason, use a Schedule-bounded retry or model an explicit unavailable state. No config exceptions or inline suppressions; baseline existing debt.",
57
+ id: "effect/failure-honesty",
58
+ registrable: false,
59
+ });
@@ -0,0 +1,66 @@
1
+ import ts from "typescript";
2
+ import { boundaryReference } from "./boundaryReference.ts";
3
+
4
+ export interface FailureOperation {
5
+ readonly name: string;
6
+ readonly node: ts.Node;
7
+ }
8
+
9
+ export function effectName(checker: ts.TypeChecker, node: ts.Node): string | undefined {
10
+ return /^effect(?:\.Effect|\/Effect)\.(?<name>\w+)$/u.exec(boundaryReference(checker, node) ?? "")?.groups?.name;
11
+ }
12
+
13
+ export function failureOperations(checker: ts.TypeChecker, node: ts.Node, seen = new Set<ts.Symbol>()): FailureOperation[] {
14
+ if (ts.isParenthesizedExpression(node)) {
15
+ return failureOperations(checker, node.expression, seen);
16
+ }
17
+ if (ts.isIdentifier(node)) {
18
+ const symbol = checker.getSymbolAtLocation(node);
19
+ if (symbol !== undefined && !seen.has(symbol)) {
20
+ seen.add(symbol);
21
+ const declaration = symbol.valueDeclaration;
22
+ if (declaration !== undefined && ts.isVariableDeclaration(declaration) && declaration.initializer !== undefined) {
23
+ return failureOperations(checker, declaration.initializer, seen);
24
+ }
25
+ }
26
+ }
27
+ if (ts.isCallExpression(node) && ts.isPropertyAccessExpression(node.expression) && node.expression.name.text === "pipe") {
28
+ return [
29
+ failureOperations(checker, node.expression.expression, seen),
30
+ ...node.arguments.map((part) => failureOperations(checker, part, new Set(seen))),
31
+ ].flat();
32
+ }
33
+ const name = effectName(checker, ts.isCallExpression(node) ? node.expression : node);
34
+ if (name === undefined) {
35
+ return [{ name: "source", node }];
36
+ }
37
+ const args = ts.isCallExpression(node) ? node.arguments : [];
38
+ const first = args[0];
39
+ return [...(first === undefined ? [] : failureOperations(checker, first, seen)), { name, node }];
40
+ }
41
+
42
+ function fileSystemService(checker: ts.TypeChecker, node: ts.Node, seen = new Set<ts.Symbol>()): boolean {
43
+ if (/^effect(?:\.FileSystem|\/FileSystem)\.FileSystem$/u.test(boundaryReference(checker, node) ?? "")) {
44
+ return true;
45
+ }
46
+ if (ts.isYieldExpression(node) || ts.isParenthesizedExpression(node)) {
47
+ return node.expression !== undefined && fileSystemService(checker, node.expression, seen);
48
+ }
49
+ const symbol = checker.getSymbolAtLocation(node);
50
+ if (symbol === undefined || seen.has(symbol)) {
51
+ return false;
52
+ }
53
+ seen.add(symbol);
54
+ return (symbol.declarations ?? []).some(
55
+ (declaration) =>
56
+ ts.isVariableDeclaration(declaration) && declaration.initializer !== undefined && fileSystemService(checker, declaration.initializer, seen),
57
+ );
58
+ }
59
+
60
+ export function fileSystemCall(checker: ts.TypeChecker, node: ts.Node): boolean {
61
+ if (!ts.isCallExpression(node)) {
62
+ return false;
63
+ }
64
+ const callee = node.expression;
65
+ return (ts.isPropertyAccessExpression(callee) || ts.isElementAccessExpression(callee)) && fileSystemService(checker, callee.expression);
66
+ }
@@ -0,0 +1,44 @@
1
+ import ts from "typescript";
2
+ import { returnValues } from "#rules/stories/returnValues.ts";
3
+ import { effectName } from "./failureOperations.ts";
4
+
5
+ function success(checker: ts.TypeChecker, node: ts.Node, seen: Set<ts.Symbol>): boolean {
6
+ if (ts.isParenthesizedExpression(node)) {
7
+ return success(checker, node.expression, seen);
8
+ }
9
+ if (ts.isConditionalExpression(node)) {
10
+ return success(checker, node.whenTrue, new Set(seen)) && success(checker, node.whenFalse, new Set(seen));
11
+ }
12
+ if (ts.isIdentifier(node)) {
13
+ const symbol = checker.getSymbolAtLocation(node);
14
+ if (symbol !== undefined && !seen.has(symbol)) {
15
+ seen.add(symbol);
16
+ const declaration = symbol.valueDeclaration;
17
+ if (declaration !== undefined && ts.isVariableDeclaration(declaration) && declaration.initializer !== undefined) {
18
+ return success(checker, declaration.initializer, seen);
19
+ }
20
+ }
21
+ }
22
+ return effectName(checker, ts.isCallExpression(node) ? node.expression : node) === (ts.isCallExpression(node) ? "succeed" : "void");
23
+ }
24
+
25
+ export function successRecovery(checker: ts.TypeChecker, handler: ts.Node, seen = new Set<ts.Symbol>()): boolean {
26
+ if (ts.isArrowFunction(handler) || ts.isFunctionExpression(handler) || ts.isFunctionDeclaration(handler)) {
27
+ const values = returnValues(handler);
28
+ return values.length > 0 && values.every((value) => value !== undefined && success(checker, value, new Set()));
29
+ }
30
+ if (effectName(checker, handler) === "succeed") {
31
+ return true;
32
+ }
33
+ const symbol = checker.getSymbolAtLocation(handler);
34
+ if (symbol === undefined || seen.has(symbol)) {
35
+ return false;
36
+ }
37
+ seen.add(symbol);
38
+ return (symbol.declarations ?? []).some((declaration) => {
39
+ if (ts.isVariableDeclaration(declaration) && declaration.initializer !== undefined) {
40
+ return successRecovery(checker, declaration.initializer, seen);
41
+ }
42
+ return ts.isFunctionDeclaration(declaration) && successRecovery(checker, declaration, seen);
43
+ });
44
+ }
@@ -24,6 +24,6 @@ export const noBarrel = defineRule({
24
24
  return findings;
25
25
  }),
26
26
  description:
27
- "Name modules after their purpose; import values from their defining module instead of exporting aliases, facades or unchanged forwarding calls.",
27
+ "Name modules after their purpose; import values from their defining module instead of exporting aliases, facades or unchanged forwarding calls. Wrappers that supply explicit type arguments keep their own meaning.",
28
28
  id: "structure/no-barrel",
29
29
  });
@@ -18,7 +18,13 @@ function forwarding(node: ts.FunctionLikeDeclaration, origins: ReadonlyMap<strin
18
18
  return undefined;
19
19
  }
20
20
  const call = returned(node.body);
21
- if (call === undefined || !ts.isCallExpression(call) || call.questionDotToken !== undefined || call.arguments.length !== node.parameters.length) {
21
+ if (
22
+ call === undefined
23
+ || !ts.isCallExpression(call)
24
+ || call.questionDotToken !== undefined
25
+ || call.typeArguments !== undefined
26
+ || call.arguments.length !== node.parameters.length
27
+ ) {
22
28
  return undefined;
23
29
  }
24
30
  const visible = new Map(origins);
@@ -0,0 +1,95 @@
1
+ import ts from "typescript";
2
+
3
+ function concrete(type: ts.TypeNode | undefined): boolean {
4
+ return type !== undefined && type.kind !== ts.SyntaxKind.UnknownKeyword;
5
+ }
6
+
7
+ function called(node: ts.Node, owner: string, method: string): node is ts.CallExpression {
8
+ return (
9
+ ts.isCallExpression(node)
10
+ && ts.isPropertyAccessExpression(node.expression)
11
+ && ts.isIdentifier(node.expression.expression)
12
+ && ownerName(node.expression.expression) === owner
13
+ && node.expression.name.text === method
14
+ );
15
+ }
16
+
17
+ function ownerName(node: ts.Identifier): string {
18
+ for (const statement of node.getSourceFile().statements) {
19
+ if (!(ts.isImportDeclaration(statement) && ts.isStringLiteral(statement.moduleSpecifier))) {
20
+ continue;
21
+ }
22
+ const bindings = statement.importClause?.namedBindings;
23
+ if (bindings !== undefined && ts.isNamedImports(bindings)) {
24
+ const imported = bindings.elements.find((element) => element.name.text === node.text);
25
+ if (statement.moduleSpecifier.text === "effect" && imported !== undefined) {
26
+ return imported.propertyName?.text ?? imported.name.text;
27
+ }
28
+ }
29
+ if (
30
+ bindings !== undefined
31
+ && ts.isNamespaceImport(bindings)
32
+ && bindings.name.text === node.text
33
+ && statement.moduleSpecifier.text === "effect/Context"
34
+ ) {
35
+ return "Context";
36
+ }
37
+ }
38
+ return node.text;
39
+ }
40
+
41
+ function unwrapped(node: ts.Expression): ts.Expression {
42
+ return ts.isParenthesizedExpression(node) ? unwrapped(node.expression) : node;
43
+ }
44
+
45
+ function bindingCast(node: ts.Node): string | undefined {
46
+ if (!ts.isVariableDeclaration(node) || node.initializer === undefined) {
47
+ return undefined;
48
+ }
49
+ const value = unwrapped(node.initializer);
50
+ if (called(value, "JSON", "parse") && concrete(node.type)) {
51
+ return `Assigns JSON.parse directly to ${node.type?.getText()}. Keep the result unknown and use Schema.decodeUnknownEffect with a schema for that declared type.`;
52
+ }
53
+ if (called(value, "Reflect", "get") && node.type?.kind !== ts.SyntaxKind.UnknownKeyword) {
54
+ return "Binds an unchecked Reflect.get result. Declare the result unknown and narrow it or use Schema.decodeUnknownEffect with the required schema.";
55
+ }
56
+ return undefined;
57
+ }
58
+
59
+ function hasMapUnsafe(node: ts.Node): boolean {
60
+ return (ts.isPropertyAccessExpression(node) && node.name.text === "mapUnsafe") || ts.forEachChild(node, hasMapUnsafe) === true;
61
+ }
62
+
63
+ function identityOverload(node: ts.Node): string | undefined {
64
+ if (!ts.isFunctionDeclaration(node) || node.body === undefined || node.type?.kind !== ts.SyntaxKind.UnknownKeyword || node.name === undefined) {
65
+ return undefined;
66
+ }
67
+ const statement = node.body.statements[0];
68
+ if (node.body.statements.length !== 1 || statement === undefined || !ts.isReturnStatement(statement) || statement.expression === undefined) {
69
+ return undefined;
70
+ }
71
+ const returned = unwrapped(statement.expression);
72
+ if (!(ts.isIdentifier(returned) && node.parameters.some((parameter) => ts.isIdentifier(parameter.name) && parameter.name.text === returned.text))) {
73
+ return undefined;
74
+ }
75
+ const siblings = ts.isSourceFile(node.parent) || ts.isBlock(node.parent) || ts.isModuleBlock(node.parent) ? node.parent.statements : [];
76
+ const overload = siblings.find(
77
+ (sibling) => ts.isFunctionDeclaration(sibling) && sibling.body === undefined && sibling.name?.text === node.name?.text && concrete(sibling.type),
78
+ );
79
+ return overload === undefined || !ts.isFunctionDeclaration(overload)
80
+ ? undefined
81
+ : `An identity overload hides an unknown return value. Give the implementation the declared overload return type ${overload.type?.getText()} and let TypeScript check it; decode unknown input with Schema.decodeUnknownEffect.`;
82
+ }
83
+
84
+ export function hiddenCast(node: ts.Node): string | undefined {
85
+ if (ts.isTaggedTemplateExpression(node) && node.typeArguments?.length && ts.isIdentifier(node.tag) && node.tag.text === "sql") {
86
+ return SQL_ROW_CAST;
87
+ }
88
+ if (called(node, "Context", "makeUnsafe") && node.arguments.some(hasMapUnsafe)) {
89
+ return "Retags a Context through mapUnsafe. Preserve its declared Context service type and use Context.add or Effect.provideService for the required services.";
90
+ }
91
+ return bindingCast(node) ?? identityOverload(node);
92
+ }
93
+
94
+ export const SQL_ROW_CAST =
95
+ "Declares SQL rows with a generic instead of checking them. Use SqlSchema.findAll or SqlSchema.findOne with the declared row schema to decode the result.";
@@ -1,6 +1,10 @@
1
+ import { join } from "node:path";
1
2
  import ts from "typescript";
2
- import { defineRule, type Finding, type SourceFile } from "#rule.ts";
3
+ import { defineRule, type Finding, type RuleInputs, type SourceFile } from "#rule.ts";
4
+ import { effectProgram } from "#rules/effect/program.ts";
3
5
  import { parse } from "#rules/parse.ts";
6
+ import { hiddenCast, SQL_ROW_CAST } from "./hiddenCast.ts";
7
+ import { readonlyWrite, writeCandidate } from "./readonlyWrite.ts";
4
8
 
5
9
  const BRIDGES: ReadonlyMap<ts.SyntaxKind, string> = new Map([
6
10
  [ts.SyntaxKind.UnknownKeyword, "unknown"],
@@ -25,11 +29,14 @@ function bridgeOf(node: Assertion): string | undefined {
25
29
 
26
30
  function castsIn(path: string, source: ts.SourceFile): readonly Finding[] {
27
31
  const findings: Finding[] = [];
32
+ const hidden = !/(?:^|\/)(?:adapters|test-support)\//u.test(path);
28
33
  function visit(node: ts.Node): void {
29
34
  const bridge = isAssertion(node) ? bridgeOf(node) : undefined;
30
- if (bridge !== undefined) {
35
+ const implicit = hidden ? hiddenCast(node) : undefined;
36
+ const message = bridge === undefined ? implicit : `Casts through "${bridge}" to reach a type the value does not have.`;
37
+ if (message !== undefined) {
31
38
  const line = source.getLineAndCharacterOfPosition(node.getStart(source)).line + 1;
32
- findings.push({ file: path, line, message: `Casts through "${bridge}" to reach a type the value does not have.` });
39
+ findings.push({ file: path, line, message });
33
40
  }
34
41
  ts.forEachChild(node, visit);
35
42
  }
@@ -42,10 +49,59 @@ function doubleCasts(file: SourceFile): readonly Finding[] {
42
49
  return source === undefined ? [] : castsIn(file.path, source);
43
50
  }
44
51
 
52
+ function typedNodes(source: ts.SourceFile): readonly ts.Node[] {
53
+ const nodes: ts.Node[] = [];
54
+ function visit(node: ts.Node): void {
55
+ if (writeCandidate(node) || (ts.isTaggedTemplateExpression(node) && node.typeArguments?.length && node.tag.getText() !== "sql")) {
56
+ nodes.push(node);
57
+ }
58
+ ts.forEachChild(node, visit);
59
+ }
60
+ visit(source);
61
+ return nodes;
62
+ }
63
+
64
+ function typedCast(node: ts.Node, checker: ts.TypeChecker): string | undefined {
65
+ if (ts.isTaggedTemplateExpression(node)) {
66
+ const nativeSql = checker
67
+ .getTypeAtLocation(node.tag)
68
+ .getSymbol()
69
+ ?.getDeclarations()
70
+ ?.some((declaration) =>
71
+ /(?:^|\/)effect\/(?:src|dist(?:\/[^/]+)?)\/sql\/(?:SqlClient|Statement)\.(?:d\.)?ts$/u.test(declaration.getSourceFile().fileName),
72
+ );
73
+ return nativeSql ? SQL_ROW_CAST : undefined;
74
+ }
75
+ return readonlyWrite(node, checker);
76
+ }
77
+
78
+ function typedCasts(inputs: RuleInputs): readonly Finding[] {
79
+ const sources = inputs.sources.filter((file) => {
80
+ const source = parse(file);
81
+ return !/(?:^|\/)(?:adapters|test-support)\//u.test(file.path) && source !== undefined && typedNodes(source).length > 0;
82
+ });
83
+ if (sources.length === 0) {
84
+ return [];
85
+ }
86
+ const program = effectProgram({ ...inputs, sources });
87
+ const checker = program.getTypeChecker();
88
+ return sources.flatMap((file) => {
89
+ const source = program.getSourceFile(join(inputs.root, file.path));
90
+ return source === undefined
91
+ ? []
92
+ : typedNodes(source).flatMap((node) => {
93
+ const message = typedCast(node, checker);
94
+ return message === undefined
95
+ ? []
96
+ : [{ file: file.path, line: source.getLineAndCharacterOfPosition(node.getStart(source)).line + 1, message }];
97
+ });
98
+ });
99
+ }
100
+
45
101
  export const noDoubleCast = defineRule({
46
- check: ({ sources }) => sources.flatMap(doubleCasts),
102
+ check: (inputs) => [...inputs.sources.flatMap(doubleCasts), ...typedCasts(inputs)],
47
103
  description:
48
- "A cast through unknown, any or never silences the compiler the way a suppression does. Decode the value at its boundary, narrow it, or fix the type that disagrees.",
104
+ "Decode unknown values with Schema.decodeUnknownEffect and SQL rows with SqlSchema. Check declared overload returns and preserve Context service types and readonly native fields. Reports double casts everywhere and hidden casts outside adapters/ and test-support/.",
49
105
  id: "suppressions/no-double-cast",
50
106
  registrable: false,
51
107
  });