@sshkeda/check 1.1.0 → 2.1.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 (102) hide show
  1. package/README.md +7 -6
  2. package/docs/how-to-make-check-pass.md +4 -14
  3. package/package.json +4 -4
  4. package/src/internal/ban-abbreviated-words-in-declared-names.ts +0 -4
  5. package/src/internal/ban-checked-members-outside-calls.ts +8 -8
  6. package/src/internal/ban-comments.ts +0 -1
  7. package/src/internal/ban-comparing-or-switching-on-tag.ts +50 -10
  8. package/src/internal/ban-deadlines-inside-tests.ts +3 -4
  9. package/src/internal/ban-declared-values.ts +2 -5
  10. package/src/internal/ban-dropped-failures-detached-fibers-sleeps-and-untraced-functions.ts +0 -2
  11. package/src/internal/ban-failures-collected-as-results.ts +0 -4
  12. package/src/internal/ban-fallbacks-of-named-recoveries.ts +1 -29
  13. package/src/internal/ban-function-overloads.ts +0 -4
  14. package/src/internal/ban-global-error-in-failure-types.ts +10 -15
  15. package/src/internal/ban-instanceof-in-effect-recovery-callbacks.ts +17 -26
  16. package/src/internal/ban-let-and-effect-mutable-ref.ts +0 -8
  17. package/src/internal/ban-logic-in-index-files.ts +0 -3
  18. package/src/internal/ban-namespaces-used-without-a-member.ts +0 -3
  19. package/src/internal/ban-node-builtins-that-effect-replaces.ts +0 -3
  20. package/src/internal/ban-parsing-outside-data-without-a-schema.ts +0 -4
  21. package/src/internal/ban-re-exports.ts +54 -18
  22. package/src/internal/ban-reading-the-clock-and-sleeping-outside-effect.ts +88 -4
  23. package/src/internal/ban-recovering-file-system-exists.ts +300 -0
  24. package/src/internal/ban-retired-words-in-names.ts +1 -4
  25. package/src/internal/ban-retries-without-a-wait.ts +292 -0
  26. package/src/internal/ban-scanning-directories-with-bun-glob.ts +0 -3
  27. package/src/internal/ban-shebang-lines.ts +0 -4
  28. package/src/internal/ban-timer-globals-and-the-global-object.ts +0 -1
  29. package/src/internal/ban-timer-schedules-without-deadlines.ts +129 -45
  30. package/src/internal/ban-type-and-interface-declarations.ts +0 -4
  31. package/src/internal/ban-type-predicates.ts +0 -4
  32. package/src/internal/ban-unknown-in-function-signatures.ts +49 -13
  33. package/src/internal/ban-vague-error-class-names.ts +0 -4
  34. package/src/internal/ban-vague-file-names.ts +3 -7
  35. package/src/internal/ban-what-a-file-is-not-granted.ts +37 -14
  36. package/src/internal/ban-while-do-while-and-for-loops.ts +0 -4
  37. package/src/internal/ban-writing-captured-objects-inside-effect-callbacks.ts +210 -0
  38. package/src/internal/confine-service-declarations-to-granted-files.ts +0 -7
  39. package/src/internal/confine-the-stdio-service-to-terminal-output.ts +2 -16
  40. package/src/internal/define-the-lint-plugin-and-configs.ts +6 -0
  41. package/src/internal/keep-assertions-in-the-test-home-and-ban-test-runners.ts +0 -6
  42. package/src/internal/keep-effect-testing-helpers-in-test-files.ts +2 -14
  43. package/src/internal/require-a-named-const-for-compound-conditions.ts +0 -4
  44. package/src/internal/require-capital-snake-case-and-as-const-on-literal-constants.ts +0 -4
  45. package/src/internal/require-service-keys-to-end-with-their-class-name.ts +5 -2
  46. package/src/internal/resolve-what-an-expression-imports.ts +115 -28
  47. package/src/internal/visit-every-declared-name.ts +13 -0
  48. package/src/lib/tasks/internal/declare-the-check-task.ts +2 -0
  49. package/src/lib/tasks/internal/declare-the-checker-queries-task.ts +2 -1
  50. package/src/lib/tasks/lib/check-effect-diagnostics-with-effect-tsgo/index.ts +2 -1
  51. package/src/lib/tasks/lib/check-effect-diagnostics-with-effect-tsgo/internal/check-effect-diagnostics-with-effect-tsgo.ts +17 -0
  52. package/src/lib/tasks/lib/check-import-boundaries/internal/decide-what-each-home-may-import.ts +62 -0
  53. package/src/lib/tasks/lib/check-import-boundaries/internal/find-import-boundary-violations.ts +215 -187
  54. package/src/lib/tasks/lib/confine-layer-provides-to-program-starts/internal/find-layer-provides-outside-program-starts.ts +13 -16
  55. package/src/lib/tasks/lib/confine-layer-provides-to-program-starts/internal/layer-provide-errors.ts +2 -1
  56. package/src/lib/tasks/lib/confine-layer-provides-to-program-starts/internal/resolve-imported-package-apis.ts +3 -1
  57. package/src/lib/tasks/lib/detect-duplicate-functions/index.ts +10 -0
  58. package/src/lib/tasks/lib/detect-duplicate-functions/internal/duplicate-function-errors.ts +23 -0
  59. package/src/lib/tasks/lib/detect-duplicate-functions/internal/find-duplicate-functions.ts +150 -0
  60. package/src/lib/tasks/lib/detect-duplicate-functions/internal/list-named-functions.ts +416 -0
  61. package/src/lib/tasks/lib/detect-inferrable-annotations/internal/find-inferrable-annotations.ts +31 -12
  62. package/src/lib/tasks/lib/enforce-file-layout/index.ts +6 -1
  63. package/src/lib/tasks/lib/enforce-file-layout/internal/file-layout-errors.ts +11 -1
  64. package/src/lib/tasks/lib/enforce-file-layout/internal/find-export-path-mismatches.ts +39 -7
  65. package/src/lib/tasks/lib/enforce-file-layout/internal/find-file-layout-violations.ts +11 -4
  66. package/src/lib/tasks/lib/enforce-file-layout/internal/find-module-layout-violations.ts +6 -4
  67. package/src/lib/tasks/lib/enforce-file-types/index.ts +6 -1
  68. package/src/lib/tasks/lib/format-with-bun-fmt/internal/declare-the-formatting-task.ts +3 -2
  69. package/src/lib/tasks/lib/judge-index-re-exports/internal/find-index-re-export-violations.ts +27 -21
  70. package/src/lib/tasks/lib/lint-with-oxlint/index.ts +2 -1
  71. package/src/lib/tasks/lib/lint-with-oxlint/internal/check-lint-rules-with-oxlint.ts +11 -8
  72. package/src/lib/tasks/lib/lint-with-oxlint/internal/read-oxlint-json-report.ts +18 -2
  73. package/src/lib/tasks/lib/place-exports-in-the-narrowest-directory/internal/export-placement-errors.ts +12 -1
  74. package/src/lib/tasks/lib/place-exports-in-the-narrowest-directory/internal/find-export-placement-violations.ts +75 -21
  75. package/src/lib/tasks/lib/place-exports-in-the-narrowest-directory/internal/find-package-entry-sources.ts +146 -0
  76. package/src/lib/tasks/lib/place-exports-in-the-narrowest-directory/internal/find-the-importer-graph.ts +24 -190
  77. package/src/lib/tasks/lib/refuse-disable-directives/index.ts +2 -1
  78. package/src/lib/tasks/lib/refuse-disable-directives/internal/find-disable-directives.ts +9 -3
  79. package/src/lib/tasks/lib/refuse-error-mappings-that-end-streams/internal/find-error-mappings-to-done.ts +108 -9
  80. package/src/lib/tasks/lib/require-separate-service-layers/internal/find-service-layer-violations.ts +1 -5
  81. package/src/lib/tasks/lib/require-type-checking-every-linted-file/index.ts +2 -1
  82. package/src/lib/tasks/lib/require-type-checking-every-linted-file/internal/find-linted-files-not-type-checked.ts +2 -4
  83. package/src/lib/tasks/shared/check-each-nested-package.ts +13 -1
  84. package/src/lib/tasks/shared/classify-files-by-role.ts +12 -2
  85. package/src/lib/tasks/shared/count-the-line-of-an-offset.ts +20 -2
  86. package/src/lib/tasks/shared/create-the-module-resolver.ts +39 -23
  87. package/src/lib/tasks/shared/declare-lint-config-task.ts +2 -1
  88. package/src/lib/tasks/shared/declare-typescript-config-task.ts +30 -2
  89. package/src/lib/tasks/shared/find-unmet-typescript-config-requirements.ts +19 -6
  90. package/src/lib/tasks/shared/list-ignored-files-imported-by-source.ts +25 -16
  91. package/src/lib/tasks/shared/load-the-lint-config.ts +14 -12
  92. package/src/lib/tasks/shared/parse-config-files-that-import-from-check.ts +6 -7
  93. package/src/lib/tasks/shared/project-config-and-tool-errors.ts +46 -2
  94. package/src/lib/tasks/shared/provide-project-query-caches.ts +11 -0
  95. package/src/lib/tasks/shared/query-the-typescript-project.ts +108 -43
  96. package/src/lib/tasks/shared/resolve-absolute-paths.ts +4 -1
  97. package/src/lib/tasks/shared/resolve-module-requests.ts +131 -90
  98. package/src/lib/tasks/shared/run-tools-and-decode-their-reports.ts +15 -11
  99. package/src/shared/bans-each-permission-lifts.ts +4 -21
  100. package/src/shared/find-retired-words.ts +1 -1
  101. package/src/shared/lint-rule-messages-and-patterns.ts +7 -12
  102. package/src/shared/record-and-grant-permissions-by-path.ts +41 -65
package/README.md CHANGED
@@ -4,7 +4,7 @@ Check sends your AI slop code back to the kitchen!
4
4
 
5
5
  Check holds your TypeScript code to a strict standard built around Effect and Bun, so the code stays type-safe, observable and predictable.
6
6
 
7
- It runs about 310 lint rules, 62 of them its own, and about 80 checks on your project's layout, imports and config. It also runs oxfmt, Effect's diagnostics and `bun check`. Your agent keeps fixing what it reports until the slop is gone.
7
+ It runs about 308 lint rules, 65 of them its own, and about 80 checks on your project's layout, imports and config. It also runs oxfmt, Effect's diagnostics and `bun check`. Your agent keeps fixing what it reports until the slop is gone.
8
8
 
9
9
  No comment or setting turns a rule off everywhere. A small set of rules was picked to allow an override, and you grant each one to a single file in `oxlint.config.ts`. See [Grant a permission](docs/how-to-make-check-pass.md#grant-a-permission).
10
10
 
@@ -47,8 +47,8 @@ Here's what Check prints when it runs on that code:
47
47
  [oxlint] error ToolExited: oxlint exited with code 1
48
48
  [typed-checks] error SettledTasksFailed: 2 of 6 tasks failed: oxlint, effect-tsgo
49
49
  [check] read node_modules/@sshkeda/check/docs/how-to-make-check-pass.md before you change the code
50
- [check] error SettledTasksFailed: 1 of 6 tasks failed: typed-checks
51
- failed: effect-tsgo, oxlint (2 of 16 tasks), 1.0s
50
+ [check] error SettledTasksFailed: 1 of 7 tasks failed: typed-checks
51
+ failed: effect-tsgo, oxlint (2 of 17 tasks), 1.0s
52
52
  ```
53
53
 
54
54
  Here's what each error catches:
@@ -88,9 +88,9 @@ Check passes.
88
88
  - **Modules with `internal/`, `shared/` and `lib/`.** Each module exposes its public code in `index.ts`, keeps private code in `internal/`, which only that module may import, puts code its parts share in `shared/` and holds its child modules in `lib/`. Code stays easy to organize and hard to tangle.
89
89
  - **No abbreviations.** `imABigFanWhenVariablesAreLongBecauseThenItsEasierToUnderstandWhatTheCodeDoes`. Full words read the same to every person and every agent.
90
90
  - **No unchecked data.** JSON and other input pass through a Schema before the code trusts them, because a type assertion or a hand-written type guard proves nothing.
91
- - **No dead exports.** Check reports any export that nothing uses, or that only tests use, so unused code doesn't pile up.
91
+ - **No dead exports.** Check reports any export that nothing uses, or that only tests use, so unused code doesn't pile up. It also reports an export in `src/` that only tests and scripts use, so code that tests or deploys your app lives in `tests/` or `scripts/`. A script still counts as a user of what `src/index.ts` exports, such as your app's entry point, and of a file it builds.
92
92
  - **Effect in place of Node's built-ins.** File, path and process work goes through Effect, so its errors stay typed.
93
- - **Tests are tasks.** Check bans Vitest and Jest. Each test is a task in Task, so tests run in parallel and clean up after themselves.
93
+ - **Tests are tasks.** Every test is a Task task in `tests/`, never a Vitest, Jest or `bun:test` suite. Tests run in parallel and clean up after themselves.
94
94
  - **Each service in its own layer.** Services are declared only in files you grant, which keeps their wiring in one place.
95
95
  - **No polling.** Code waits for an event or a signal instead of checking on a timer, so it reacts right away. When there's nothing to listen to, such as a server that's still starting, polling needs a grant and a time limit.
96
96
  - **No dropped failures.** Every error is handled or passed on, so nothing fails silently.
@@ -122,6 +122,7 @@ Check needs Bun 1.4.4 or newer and a Git repository.
122
122
  "allowUnreachableCode": false,
123
123
  "allowUnusedLabels": false,
124
124
  "allowImportingTsExtensions": true,
125
+ "noEmit": true,
125
126
  "types": ["bun"]
126
127
  ```
127
128
 
@@ -152,7 +153,7 @@ Check needs Bun 1.4.4 or newer and a Git repository.
152
153
  }
153
154
  ```
154
155
 
155
- 6. Run it, and have your agent fix what it reports.
156
+ 6. Run it, and have your agent fix what it reports. Expect the first run to fail, even on a new project from `bun init`.
156
157
 
157
158
  ```bash
158
159
  bun scripts/ci.ts
@@ -8,7 +8,7 @@ Check may not catch every violation of these principles. Review your code agains
8
8
 
9
9
  - Use a grant only for an unavoidable exception.
10
10
  - Design for the current requirement as if you were starting fresh. Delete code the new design doesn't need.
11
- - Grant `isGeneratedByATool` only to a file a tool generates, and name the tool in its reason.
11
+ - Grant `isGeneratedByATool` only to a file a tool generates.
12
12
 
13
13
  ## Grant a permission
14
14
 
@@ -17,16 +17,10 @@ Grant a permission to one file or directory in `oxlint.config.ts`. The key is th
17
17
  ```ts
18
18
  export default lintConfig({
19
19
  "src/config.ts": { allow: ["readsConfig"] },
20
- "src/internal/run-all-checks.ts": {
21
- allow: [
22
- { handlesEveryFailure: "reports every check's failures together, so none hides another" },
23
- ],
24
- },
20
+ "src/internal/run-all-checks.ts": { allow: ["handlesEveryFailure"] },
25
21
  });
26
22
  ```
27
23
 
28
- These names need no reason:
29
-
30
24
  - `readsConfig`: Allows Effect `Config`, `process.env` and `process.argv`.
31
25
  - `spawnsCommands`: Allows Effect `ChildProcess`, `Bun.spawn` and `spawn` from `node:child_process`.
32
26
  - `locksFiles`: Allows `open` from `node:fs/promises` and `constants` from `node:fs`.
@@ -35,19 +29,15 @@ These names need no reason:
35
29
  - `usesSqlDatabases`: Allows Effect SQL.
36
30
  - `writesToTheTerminal`: Allows Effect `Stdio`.
37
31
  - `usesAbbreviations`: Allows abbreviations in variable, function, type and other declared names.
38
- - `pollsWithADeadline`: Allows `Effect.repeat` with `Schedule.spaced`, under a deadline.
32
+ - `pollsWithADeadline`: Allows `Effect.repeat` and `Effect.retry` with `Schedule.spaced` or `Schedule.exponential`, under a deadline. `Schedule.exponential` may be wrapped in or piped through `Schedule.jittered`.
33
+ - `waitsOnTimers`: Allows `Effect.sleep`, `Effect.delay`, `Clock.sleep` and the Stream operations that wait on a timer, such as `Stream.tick`.
39
34
  - `hasAnUnlistedFileType`: Allows a file type Check doesn't list, such as Markdown.
40
35
  - `isAnUnlistedDirectory`: Allows a directory Check doesn't list, such as `.github`. Check doesn't apply its directory-shape rules inside it, but files there still need their own `hasAnUnlistedFileType` grant.
41
36
  - `patchesADependency`: Allows a patch file from `bun patch`.
42
-
43
- These names need a reason, written as `{ name: "reason" }`:
44
-
45
37
  - `trustsUnverifiedTypes`: Allows trusting a value's type without checking it, through `Schema.declare`.
46
38
  - `handlesEveryFailure`: Allows catching every error, through `Effect.catch`, `Effect.exit`, a forked fiber or `Effect.runPromise`.
47
39
  - `isGeneratedByATool`: Check skips this path, so it can't have any other permission.
48
40
 
49
- A reason can't be blank.
50
-
51
41
  ## Make the code explain itself
52
42
 
53
43
  - Use what Effect, Bun or a dependency already provides.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sshkeda/check",
3
- "version": "1.1.0",
3
+ "version": "2.1.0",
4
4
  "homepage": "https://github.com/sshkeda/check#readme",
5
5
  "bugs": {
6
6
  "url": "https://github.com/sshkeda/check/issues"
@@ -25,11 +25,11 @@
25
25
  },
26
26
  "dependencies": {
27
27
  "@effect/platform-bun": "4.1.0",
28
- "@effect/tsgo": "0.55.0",
29
- "@oxlint/plugins": "1.87.0",
28
+ "@effect/tsgo": "0.67.4",
29
+ "@oxlint/plugins": "1.88.0",
30
30
  "oxc-parser": "0.153.0",
31
31
  "oxc-resolver": "11.24.2",
32
- "oxlint": "1.87.0",
32
+ "oxlint": "1.88.0",
33
33
  "oxlint-tsgolint": "7.0.2005",
34
34
  "typescript": "7.0.2"
35
35
  },
@@ -131,10 +131,6 @@ const allowList = (options: readonly unknown[]): ReadonlySet<string> =>
131
131
  export const noAbbreviations = defineRule({
132
132
  meta: {
133
133
  type: "suggestion",
134
- docs: {
135
- description:
136
- "Disallow abbreviated words in the names a file declares, in camelCase, PascalCase and snake_case.",
137
- },
138
134
  messages: {
139
135
  abbreviation: "`{{name}}` contains {{abbreviations}} of {{fullWords}}",
140
136
  },
@@ -18,6 +18,7 @@ import {
18
18
  isImportBinding,
19
19
  isValueOperandOfTypeScriptOrExport,
20
20
  memberName,
21
+ rootOf,
21
22
  } from "./resolve-what-an-expression-imports.ts";
22
23
 
23
24
  const RECOVERY_PREFIX = "catch";
@@ -37,6 +38,8 @@ const isRecoveryCheckedAtItsCall = (
37
38
  (operation.startsWith(RECOVERY_PREFIX) || operation === ERROR_MAPPING) &&
38
39
  !isBannedRecovery(moduleName, operation);
39
40
 
41
+ const STREAM_RETRY = "retry";
42
+
40
43
  const EFFECT_MEMBERS_CHECKED_AT_THEIR_CALLS: ReadonlyMap<string, (operation: string) => boolean> =
41
44
  new Map([
42
45
  [
@@ -47,7 +50,11 @@ const EFFECT_MEMBERS_CHECKED_AT_THEIR_CALLS: ReadonlyMap<string, (operation: str
47
50
  POLLING_OPERATIONS.has(operation) ||
48
51
  DEADLINE_OPERATIONS.has(operation),
49
52
  ],
50
- ["Stream", (operation: string) => isRecoveryCheckedAtItsCall("Stream", operation)],
53
+ [
54
+ "Stream",
55
+ (operation: string) =>
56
+ isRecoveryCheckedAtItsCall("Stream", operation) || operation === STREAM_RETRY,
57
+ ],
51
58
  ["Channel", (operation: string) => isRecoveryCheckedAtItsCall("Channel", operation)],
52
59
  ["Context", (operation: string) => SERVICE_FACTORIES.has(operation)],
53
60
  ["PlatformError", (operation: string) => operation === "systemError"],
@@ -59,9 +66,6 @@ const GLOBAL_MEMBERS_CHECKED_AT_THEIR_CALLS: ReadonlyMap<string, ReadonlySet<str
59
66
  ["Number", NUMBER_PARSERS],
60
67
  ]);
61
68
 
62
- const rootOf = (node: ESTree.Node): ESTree.Node =>
63
- node.type === "MemberExpression" ? rootOf(node.object) : node;
64
-
65
69
  const effectMemberNamed = (node: ESTree.Node, sourceCode: SourceCode) => {
66
70
  if (!isImportBinding(rootOf(node), sourceCode)) {
67
71
  return;
@@ -121,10 +125,6 @@ const isValueReference = (node: ESTree.Node) => {
121
125
  export const noUncalledMembers = defineRule({
122
126
  meta: {
123
127
  type: "problem",
124
- docs: {
125
- description:
126
- "Call a member whose ban is checked at its call, such as Stream.catchTag or Effect.retry, where it is named, so no value carries it past the check.",
127
- },
128
128
  messages: {
129
129
  uncalled: "{{member}} is used as a value instead of being called where it is named",
130
130
  },
@@ -5,7 +5,6 @@ import { isDirective } from "../shared/lint-rule-messages-and-patterns.ts";
5
5
  export const noComments = defineRule({
6
6
  meta: {
7
7
  type: "suggestion",
8
- docs: { description: "Disallow comments in code." },
9
8
  messages: { comment: "comment in code" },
10
9
  },
11
10
  create(context) {
@@ -1,9 +1,16 @@
1
1
  import { defineRule } from "@oxlint/plugins";
2
2
  import type { ESTree, SourceCode } from "@oxlint/plugins";
3
3
 
4
- import { importedExpression } from "./resolve-what-an-expression-imports.ts";
4
+ import {
5
+ importedExpression,
6
+ isGlobalReference,
7
+ memberName,
8
+ resolvedVariable,
9
+ } from "./resolve-what-an-expression-imports.ts";
5
10
 
6
11
  const COMPARISONS: ReadonlySet<string> = new Set(["===", "!==", "==", "!="]);
12
+ const SAME_VALUE = "is";
13
+ const MEMBERSHIP = "includes";
7
14
 
8
15
  const isTagKey = (key: ESTree.Node, computed: boolean) =>
9
16
  computed
@@ -11,8 +18,10 @@ const isTagKey = (key: ESTree.Node, computed: boolean) =>
11
18
  : (key.type === "Identifier" && key.name === "_tag") ||
12
19
  (key.type === "Literal" && key.value === "_tag");
13
20
 
14
- const isTagRead = (node: ESTree.Node) =>
15
- node.type === "MemberExpression" && isTagKey(node.property, node.computed);
21
+ const isTagRead = (node: ESTree.Node): boolean =>
22
+ node.type === "ChainExpression"
23
+ ? isTagRead(node.expression)
24
+ : node.type === "MemberExpression" && isTagKey(node.property, node.computed);
16
25
 
17
26
  const memberOf = (node: ESTree.Node, owner: string) => {
18
27
  const isNamedMemberOfOwner =
@@ -52,10 +61,6 @@ const isPlatformSystemErrorOptions = (node: ESTree.Node, sourceCode: SourceCode)
52
61
  export const noManualTag = defineRule({
53
62
  meta: {
54
63
  type: "problem",
55
- docs: {
56
- description:
57
- "Disallow hand-written `_tag` values, except the reason tag Effect's PlatformError.systemError takes.",
58
- },
59
64
  messages: {
60
65
  construction: "`_tag` is written by hand",
61
66
  },
@@ -81,10 +86,25 @@ export const noManualTag = defineRule({
81
86
  },
82
87
  });
83
88
 
89
+ const isDestructuredTag = (node: ESTree.Node, sourceCode: SourceCode) => {
90
+ const variable = resolvedVariable(node, sourceCode);
91
+ if (variable?.references.some((reference) => reference.isWrite() && !reference.init) === true) {
92
+ return false;
93
+ }
94
+ const binding = variable?.defs[0]?.name;
95
+ const value = binding?.parent.type === "AssignmentPattern" ? binding.parent : binding;
96
+ const property = value?.parent;
97
+ return (
98
+ property?.type === "Property" &&
99
+ property.value === value &&
100
+ property.parent.type === "ObjectPattern" &&
101
+ isTagKey(property.key, property.computed)
102
+ );
103
+ };
104
+
84
105
  export const noTagBranching = defineRule({
85
106
  meta: {
86
107
  type: "problem",
87
- docs: { description: "Disallow comparing or switching on `_tag`." },
88
108
  messages: {
89
109
  comparison: "`_tag` is compared",
90
110
  switch: "`_tag` is switched on",
@@ -95,20 +115,40 @@ export const noTagBranching = defineRule({
95
115
  const branch = (node: ESTree.Node, messageId: "comparison" | "switch") => {
96
116
  context.report({ node, messageId: insideEffectCatch(node) ? "catchTag" : messageId });
97
117
  };
118
+ const readsTag = (node: ESTree.Node) =>
119
+ isTagRead(node) || isDestructuredTag(node, context.sourceCode);
98
120
 
99
121
  return {
100
122
  BinaryExpression(node) {
101
123
  const comparesTag =
102
- COMPARISONS.has(node.operator) && (isTagRead(node.left) || isTagRead(node.right));
124
+ COMPARISONS.has(node.operator) && (readsTag(node.left) || readsTag(node.right));
103
125
  if (comparesTag) {
104
126
  branch(node, "comparison");
105
127
  }
106
128
  },
107
129
  SwitchStatement(node) {
108
- if (isTagRead(node.discriminant)) {
130
+ if (readsTag(node.discriminant)) {
109
131
  branch(node.discriminant, "switch");
110
132
  }
111
133
  },
134
+ CallExpression(node) {
135
+ const { callee } = node;
136
+ if (callee.type !== "MemberExpression") {
137
+ return;
138
+ }
139
+ const method = memberName(callee);
140
+ const [first, second] = node.arguments;
141
+ const isSameValueCheckOnTag =
142
+ method === SAME_VALUE &&
143
+ isGlobalReference(callee.object, context.sourceCode, "Object") &&
144
+ [first, second].some((argument) => argument !== undefined && readsTag(argument));
145
+ const isMembershipCheckOfTag =
146
+ method === MEMBERSHIP && first !== undefined && readsTag(first);
147
+ const comparesTag = isSameValueCheckOnTag || isMembershipCheckOfTag;
148
+ if (comparesTag) {
149
+ branch(node, "comparison");
150
+ }
151
+ },
112
152
  };
113
153
  },
114
154
  });
@@ -2,7 +2,6 @@ import { defineRule } from "@oxlint/plugins";
2
2
  import type { ESTree } from "@oxlint/plugins";
3
3
 
4
4
  import { SCHEDULE_MESSAGES } from "../shared/lint-rule-messages-and-patterns.ts";
5
- import { TEST_HOME } from "../shared/test-home-directories.ts";
6
5
  import { scheduleVisitors } from "./ban-timer-schedules-without-deadlines.ts";
7
6
  import { effectModuleReference } from "./resolve-what-an-expression-imports.ts";
8
7
 
@@ -11,9 +10,6 @@ const TIMEOUT = "timeout";
11
10
  export const noTestTimeouts = defineRule({
12
11
  meta: {
13
12
  type: "problem",
14
- docs: {
15
- description: `Bound tests in ${TEST_HOME} only with the timeout option of their task and wait on signals or TestClock instead of timers; Effect timeouts and timed schedules put a second clock inside the test. A test file granted pollsWithADeadline may poll an outside system with Schedule.spaced under a deadline.`,
16
- },
17
13
  messages: { ...SCHEDULE_MESSAGES, timeout: "{{usage}} sets a deadline inside a test" },
18
14
  },
19
15
  create(context) {
@@ -36,6 +32,9 @@ export const noTestTimeouts = defineRule({
36
32
  schedules.MemberExpression(node);
37
33
  reportEffectTimeout(node);
38
34
  },
35
+ "Program:exit"() {
36
+ schedules["Program:exit"]();
37
+ },
39
38
  };
40
39
  },
41
40
  });
@@ -29,10 +29,6 @@ const bindingNames = (declaration: ESTree.VariableDeclaration) =>
29
29
  export const noDeclaredValues = defineRule({
30
30
  meta: {
31
31
  type: "problem",
32
- docs: {
33
- description:
34
- "Give every value and class field an implementation; anything declared with declare has a type nothing checks.",
35
- },
36
32
  messages: {
37
33
  declaredValue: "{{name}} is declared without an implementation",
38
34
  },
@@ -56,7 +52,8 @@ export const noDeclaredValues = defineRule({
56
52
  }
57
53
  },
58
54
  PropertyDefinition(node) {
59
- if (node.declare === true) {
55
+ const hasNoImplementation = node.declare === true || node.definite === true;
56
+ if (hasNoImplementation) {
60
57
  report(node, propertyName(node.key) ?? "a computed class field");
61
58
  }
62
59
  },
@@ -13,7 +13,6 @@ const operationsByModule = (operations: Readonly<Record<string, readonly string[
13
13
 
14
14
  export const effectOperationRule = (ruleName: keyof typeof EFFECT_OPERATION_RULES) => {
15
15
  const rule = EFFECT_OPERATION_RULES[ruleName];
16
- const { description } = rule;
17
16
  const bannedOperations = [["operation", operationsByModule(rule.operations)]] as const;
18
17
  const bannedModules: ReadonlySet<string> = new Set(
19
18
  bannedOperations.flatMap(([, operations]) => [...operations.keys()]),
@@ -21,7 +20,6 @@ export const effectOperationRule = (ruleName: keyof typeof EFFECT_OPERATION_RULE
21
20
  return defineRule({
22
21
  meta: {
23
22
  type: "problem",
24
- docs: { description },
25
23
  messages: {
26
24
  operation: "{{moduleName}}.{{operation}} is banned",
27
25
  },
@@ -31,10 +31,6 @@ const unsafeOptionsMessage = (options: ESTree.Node | undefined) => {
31
31
  export const noFailuresAsResults = defineRule({
32
32
  meta: {
33
33
  type: "problem",
34
- docs: {
35
- description:
36
- "Let Effect.all fail on the first failure, and collect failures as results only in files allowed handlesEveryFailure.",
37
- },
38
34
  messages: {
39
35
  results: "Effect.all turns each failure into a result",
40
36
  opaqueOptions: "Effect.all is given options that are not written inline",
@@ -1,34 +1,10 @@
1
1
  import { defineRule } from "@oxlint/plugins";
2
2
  import type { ESTree, SourceCode } from "@oxlint/plugins";
3
3
 
4
- import {
5
- effectModuleOperation,
6
- resolvedVariable,
7
- unwrappedExpression,
8
- } from "./resolve-what-an-expression-imports.ts";
4
+ import { constantValue, effectModuleOperation } from "./resolve-what-an-expression-imports.ts";
9
5
 
10
6
  const NAMED_RECOVERY_MODULES = ["Effect", "Stream", "Channel"] as const;
11
7
 
12
- const constantValue = (
13
- node: ESTree.Node,
14
- sourceCode: SourceCode,
15
- seen: ReadonlySet<ESTree.Node> = new Set(),
16
- ): ESTree.Node => {
17
- const expression = unwrappedExpression(node);
18
- const definitions = resolvedVariable(expression, sourceCode)?.defs ?? [];
19
- const declarator = definitions.length === 1 ? definitions[0]?.node : undefined;
20
- const isConstantDeclarator =
21
- declarator?.type === "VariableDeclarator" &&
22
- declarator.id.type === "Identifier" &&
23
- declarator.parent.type === "VariableDeclaration" &&
24
- declarator.parent.kind === "const" &&
25
- !seen.has(expression);
26
- const value = isConstantDeclarator ? declarator.init : null;
27
- return value === null
28
- ? expression
29
- : constantValue(value, sourceCode, new Set([...seen, expression]));
30
- };
31
-
32
8
  const isTagText = (node: ESTree.Node) =>
33
9
  (node.type === "Literal" && typeof node.value === "string") || node.type === "TemplateLiteral";
34
10
 
@@ -88,10 +64,6 @@ const hasFallback = (
88
64
  export const noUnnamedFallbacks = defineRule({
89
65
  meta: {
90
66
  type: "problem",
91
- docs: {
92
- description:
93
- "Recover by name with catchTag, catchTags, catchReason and catchReasons without their fallback for every failure they do not name.",
94
- },
95
67
  messages: {
96
68
  fallback: "{{member}} is given a fallback for failures it does not name",
97
69
  },
@@ -58,10 +58,6 @@ const namedFunctionMember = (
58
58
  export const noOverloads = defineRule({
59
59
  meta: {
60
60
  type: "suggestion",
61
- docs: {
62
- description:
63
- "Give each function one signature, written on its implementation, so ReturnType and Parameters see the signature callers use instead of only the last overload.",
64
- },
65
61
  messages: {
66
62
  overload: "{{name}} is overloaded",
67
63
  },
@@ -5,9 +5,18 @@ import {
5
5
  importedExpression,
6
6
  isGlobalReference,
7
7
  staticKeyName,
8
+ typeNameParts,
9
+ typeNameRoot,
8
10
  } from "./resolve-what-an-expression-imports.ts";
9
11
 
10
- const FAILING_TYPES = new Set(["Effect.Effect", "Stream.Stream", "Layer.Layer"]);
12
+ const FAILING_TYPES = new Set([
13
+ "Effect.Effect",
14
+ "Effect.fn.Return",
15
+ "Effect.gen.Return",
16
+ "Exit.Exit",
17
+ "Stream.Stream",
18
+ "Layer.Layer",
19
+ ]);
11
20
 
12
21
  const FAILURE_TYPE_ARGUMENT = 1;
13
22
 
@@ -17,16 +26,6 @@ const GLOBAL_OBJECT = "globalThis";
17
26
 
18
27
  const UNNAMED = "this type";
19
28
 
20
- const typeNameParts = (name: ESTree.Node): readonly string[] => {
21
- if (name.type === "TSQualifiedName") {
22
- return [...typeNameParts(name.left), name.right.name];
23
- }
24
- return name.type === "Identifier" ? [name.name] : [];
25
- };
26
-
27
- const typeNameRoot = (name: ESTree.Node): ESTree.Node =>
28
- name.type === "TSQualifiedName" ? typeNameRoot(name.left) : name;
29
-
30
29
  const effectModulePath = (module: string) => {
31
30
  if (module === "effect") {
32
31
  return [];
@@ -113,10 +112,6 @@ const enclosingName = (node: ESTree.Node): string => {
113
112
  export const noPlainErrorFailures = defineRule({
114
113
  meta: {
115
114
  type: "problem",
116
- docs: {
117
- description:
118
- "Name each tagged error an Effect, Stream or Layer fails with instead of the global Error.",
119
- },
120
115
  messages: {
121
116
  plainError: "{{name}} fails with Error",
122
117
  },
@@ -1,11 +1,7 @@
1
1
  import type { ESTree } from "@oxlint/plugins";
2
2
  import { defineRule } from "@oxlint/plugins";
3
3
 
4
- import {
5
- effectOperation,
6
- enclosingFunction,
7
- resolvedVariable,
8
- } from "./resolve-what-an-expression-imports.ts";
4
+ import { effectOperation, resolvedVariable } from "./resolve-what-an-expression-imports.ts";
9
5
 
10
6
  const innermostMemberObject = (node: ESTree.Node): ESTree.Node =>
11
7
  node.type === "MemberExpression" ? innermostMemberObject(node.object) : node;
@@ -13,7 +9,6 @@ const innermostMemberObject = (node: ESTree.Node): ESTree.Node =>
13
9
  export const noErrorInstanceof = defineRule({
14
10
  meta: {
15
11
  type: "problem",
16
- docs: { description: "Use tagged failures in Effect recovery callbacks." },
17
12
  messages: {
18
13
  tagged: "instanceof tests a value reached from the parameter of Effect.{{operation}}",
19
14
  },
@@ -24,8 +19,21 @@ export const noErrorInstanceof = defineRule({
24
19
  if (node.operator !== "instanceof") {
25
20
  return;
26
21
  }
27
- const callback = enclosingFunction(node);
28
- if (!callback) {
22
+ const subject = innermostMemberObject(node.left);
23
+ if (subject.type !== "Identifier") {
24
+ return;
25
+ }
26
+ const definition = resolvedVariable(subject, context.sourceCode)?.defs[0];
27
+ if (definition?.type !== "Parameter") {
28
+ return;
29
+ }
30
+ const callback = definition.node;
31
+ const isNamedParameter =
32
+ (callback.type === "ArrowFunctionExpression" ||
33
+ callback.type === "FunctionExpression" ||
34
+ callback.type === "FunctionDeclaration") &&
35
+ callback.params.some((parameter) => parameter === definition.name);
36
+ if (!isNamedParameter) {
29
37
  return;
30
38
  }
31
39
  const call = callback.parent;
@@ -37,24 +45,7 @@ export const noErrorInstanceof = defineRule({
37
45
  return;
38
46
  }
39
47
  const isRecoveryOperation = operation.startsWith("catch") || operation === "mapError";
40
- if (!isRecoveryOperation) {
41
- return;
42
- }
43
- const subject = innermostMemberObject(node.left);
44
- if (subject.type !== "Identifier") {
45
- return;
46
- }
47
- const subjectName = subject.name;
48
- const parameter = callback.params.find(
49
- (candidate) => candidate.type === "Identifier" && candidate.name === subjectName,
50
- );
51
- if (parameter?.type !== "Identifier") {
52
- return;
53
- }
54
- const parameterVariable = context.sourceCode
55
- .getDeclaredVariables(callback)
56
- .find((variable) => variable.identifiers.includes(parameter));
57
- if (resolvedVariable(subject, context.sourceCode) === parameterVariable) {
48
+ if (isRecoveryOperation) {
58
49
  context.report({ node, messageId: "tagged", data: { operation } });
59
50
  }
60
51
  },
@@ -24,10 +24,6 @@ const bindingNamesOf = (pattern: ESTree.Node): readonly string[] => {
24
24
  export const noLet = defineRule({
25
25
  meta: {
26
26
  type: "suggestion",
27
- docs: {
28
- description:
29
- "Declare every variable with const, including for...of and for...in loop variables, so no name is reassigned. A let that starts a for statement is left to no-while, which reports the whole loop.",
30
- },
31
27
  messages: {
32
28
  reassignable: "let declares {{names}}, which can be reassigned",
33
29
  },
@@ -56,10 +52,6 @@ export const noLet = defineRule({
56
52
  export const noMutableRef = defineRule({
57
53
  meta: {
58
54
  type: "suggestion",
59
- docs: {
60
- description:
61
- "Keep shared state in an Effect Ref instead of MutableRef, the synchronous box that would stand in for a banned let.",
62
- },
63
55
  messages: {
64
56
  boxedVariable: "{{usage}} keeps a reassignable value in a synchronous box",
65
57
  },
@@ -75,9 +75,6 @@ const partsOf = (node: ESTree.Node) => {
75
75
  export const noIndexLogic = defineRule({
76
76
  meta: {
77
77
  type: "suggestion",
78
- docs: {
79
- description: "Keep index.ts and index.tsx to wiring.",
80
- },
81
78
  messages: {
82
79
  holds: "index file holds {{kind}}",
83
80
  outsideAnExport: "index file holds {{kind}} outside an export statement",
@@ -119,9 +119,6 @@ export const noNamespaceAliases = (globalObjects: ReadonlySet<string>) => {
119
119
  return defineRule({
120
120
  meta: {
121
121
  type: "problem",
122
- docs: {
123
- description: `Use an Effect module, a module or namespace a permission ban names members of, or one of the globals ${[...globalObjects].join(", ")}, only through a named member, so no alias, destructuring or spread hides a banned member from the rules that ban it.`,
124
- },
125
122
  messages: {
126
123
  wholeNamespace:
127
124
  "{{name}} is used without naming a member, so the bans on its members can't see which one runs",
@@ -12,9 +12,6 @@ export const nodeBuiltinRule = (ruleName: keyof typeof NODE_BUILTIN_RULES) => {
12
12
  return defineRule({
13
13
  meta: {
14
14
  type: "problem",
15
- docs: {
16
- description: `Import ${[...bannedModules].join(", ")} from Node only through its Effect replacement, a literal import() included; a re-export is left to no-re-exports and an import {} to typescript(no-import-type-side-effects).`,
17
- },
18
15
  messages: { builtin: "importing {{source}} is banned" },
19
16
  },
20
17
  create(context) {
@@ -237,10 +237,6 @@ const isDecodedOrBoundAsUnknownRightAway = (
237
237
  export const noUncheckedParsing = defineRule({
238
238
  meta: {
239
239
  type: "problem",
240
- docs: {
241
- description:
242
- "Parse outside data with a Schema instead of json(), decimal parseInt, parseFloat or Schema.Any, which hand back values nothing checked. A json() body that goes straight into a Schema decoder or an unknown binding, and a parseInt with a constant radix other than 10, which no Schema decodes, pass.",
243
- },
244
240
  messages: {
245
241
  jsonBody: "json() parses JSON without a Schema",
246
242
  numberParse: "{{usage}} parses a number without a Schema",