@sshkeda/check 0.0.0-stage → 1.0.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 (167) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +156 -2
  3. package/docs/how-to-make-check-pass.md +71 -0
  4. package/package.json +51 -4
  5. package/src/index.ts +8 -0
  6. package/src/internal/ban-abbreviated-words-in-declared-names.ts +165 -0
  7. package/src/internal/ban-checked-members-outside-calls.ts +151 -0
  8. package/src/internal/ban-comments.ts +23 -0
  9. package/src/internal/ban-comparing-or-switching-on-tag.ts +114 -0
  10. package/src/internal/ban-deadlines-inside-tests.ts +41 -0
  11. package/src/internal/ban-declared-values.ts +70 -0
  12. package/src/internal/ban-dropped-failures-detached-fibers-sleeps-and-untraced-functions.ts +67 -0
  13. package/src/internal/ban-failures-collected-as-results.ts +57 -0
  14. package/src/internal/ban-fallbacks-of-named-recoveries.ts +118 -0
  15. package/src/internal/ban-function-overloads.ts +107 -0
  16. package/src/internal/ban-global-error-in-failure-types.ts +146 -0
  17. package/src/internal/ban-instanceof-in-effect-recovery-callbacks.ts +63 -0
  18. package/src/internal/ban-let-and-effect-mutable-ref.ts +79 -0
  19. package/src/internal/ban-logic-in-index-files.ts +178 -0
  20. package/src/internal/ban-namespaces-used-without-a-member.ts +176 -0
  21. package/src/internal/ban-node-builtins-that-effect-replaces.ts +42 -0
  22. package/src/internal/ban-parsing-outside-data-without-a-schema.ts +299 -0
  23. package/src/internal/ban-re-exports.ts +172 -0
  24. package/src/internal/ban-reading-the-clock-and-sleeping-outside-effect.ts +239 -0
  25. package/src/internal/ban-retired-words-in-names.ts +49 -0
  26. package/src/internal/ban-scanning-directories-with-bun-glob.ts +79 -0
  27. package/src/internal/ban-shebang-lines.ts +26 -0
  28. package/src/internal/ban-timer-globals-and-the-global-object.ts +34 -0
  29. package/src/internal/ban-timer-schedules-without-deadlines.ts +240 -0
  30. package/src/internal/ban-type-and-interface-declarations.ts +48 -0
  31. package/src/internal/ban-type-predicates.ts +82 -0
  32. package/src/internal/ban-unknown-in-function-signatures.ts +143 -0
  33. package/src/internal/ban-vague-error-class-names.ts +28 -0
  34. package/src/internal/ban-vague-file-names.ts +51 -0
  35. package/src/internal/ban-what-a-file-is-not-granted.ts +512 -0
  36. package/src/internal/ban-while-do-while-and-for-loops.ts +27 -0
  37. package/src/internal/confine-service-declarations-to-granted-files.ts +116 -0
  38. package/src/internal/confine-the-stdio-service-to-terminal-output.ts +190 -0
  39. package/src/internal/define-the-lint-plugin-and-configs.ts +361 -0
  40. package/src/internal/describe-and-decode-rule-options.ts +22 -0
  41. package/src/internal/keep-assertions-in-the-test-home-and-ban-test-runners.ts +128 -0
  42. package/src/internal/keep-effect-testing-helpers-in-test-files.ts +157 -0
  43. package/src/internal/match-banned-modules-and-globals.ts +71 -0
  44. package/src/internal/match-effect-service-factories.ts +20 -0
  45. package/src/internal/require-a-named-const-for-compound-conditions.ts +44 -0
  46. package/src/internal/require-capital-snake-case-and-as-const-on-literal-constants.ts +141 -0
  47. package/src/internal/require-service-keys-to-end-with-their-class-name.ts +64 -0
  48. package/src/internal/resolve-what-an-expression-imports.ts +295 -0
  49. package/src/internal/sort-type-constituents.ts +82 -0
  50. package/src/internal/split-names-into-words.ts +12 -0
  51. package/src/internal/visit-every-declared-name.ts +264 -0
  52. package/src/lib/tasks/index.ts +1 -0
  53. package/src/lib/tasks/internal/declare-the-check-task.ts +29 -0
  54. package/src/lib/tasks/internal/declare-the-checker-queries-task.ts +41 -0
  55. package/src/lib/tasks/internal/declare-the-typed-checks-task.ts +25 -0
  56. package/src/lib/tasks/internal/run-checks-over-one-typescript-project.ts +68 -0
  57. package/src/lib/tasks/lib/check-effect-diagnostics-with-effect-tsgo/index.ts +15 -0
  58. package/src/lib/tasks/lib/check-effect-diagnostics-with-effect-tsgo/internal/check-effect-diagnostics-with-effect-tsgo.ts +211 -0
  59. package/src/lib/tasks/lib/check-effect-diagnostics-with-effect-tsgo/internal/read-effect-tsgo-json-report.ts +39 -0
  60. package/src/lib/tasks/lib/check-import-boundaries/index.ts +1 -0
  61. package/src/lib/tasks/lib/check-import-boundaries/internal/find-import-boundary-violations.ts +415 -0
  62. package/src/lib/tasks/lib/check-import-boundaries/internal/find-subpath-import-targets.ts +117 -0
  63. package/src/lib/tasks/lib/check-import-boundaries/internal/find-what-hides-an-import.ts +65 -0
  64. package/src/lib/tasks/lib/check-import-boundaries/internal/import-boundary-errors.ts +176 -0
  65. package/src/lib/tasks/lib/check-uses-by-their-declarations/index.ts +1 -0
  66. package/src/lib/tasks/lib/check-uses-by-their-declarations/internal/declared-use-errors.ts +32 -0
  67. package/src/lib/tasks/lib/check-uses-by-their-declarations/internal/find-declared-use-violations.ts +38 -0
  68. package/src/lib/tasks/lib/check-uses-by-their-declarations/internal/find-sync-calls.ts +23 -0
  69. package/src/lib/tasks/lib/check-uses-by-their-declarations/internal/find-type-only-schemas.ts +375 -0
  70. package/src/lib/tasks/lib/confine-layer-provides-to-program-starts/index.ts +1 -0
  71. package/src/lib/tasks/lib/confine-layer-provides-to-program-starts/internal/find-layer-provides-outside-program-starts.ts +648 -0
  72. package/src/lib/tasks/lib/confine-layer-provides-to-program-starts/internal/layer-provide-errors.ts +27 -0
  73. package/src/lib/tasks/lib/confine-layer-provides-to-program-starts/internal/resolve-imported-package-apis.ts +262 -0
  74. package/src/lib/tasks/lib/confine-stdio-to-granted-files/index.ts +1 -0
  75. package/src/lib/tasks/lib/confine-stdio-to-granted-files/internal/find-ungranted-stdio-uses.ts +219 -0
  76. package/src/lib/tasks/lib/confine-stdio-to-granted-files/internal/stdio-use-errors.ts +31 -0
  77. package/src/lib/tasks/lib/detect-inferrable-annotations/index.ts +1 -0
  78. package/src/lib/tasks/lib/detect-inferrable-annotations/internal/find-inferrable-annotations.ts +357 -0
  79. package/src/lib/tasks/lib/detect-inferrable-annotations/internal/inferrable-annotation-errors.ts +33 -0
  80. package/src/lib/tasks/lib/detect-repeated-service-yields/index.ts +1 -0
  81. package/src/lib/tasks/lib/detect-repeated-service-yields/internal/find-repeated-service-yields.ts +162 -0
  82. package/src/lib/tasks/lib/detect-repeated-service-yields/internal/repeated-service-yield-errors.ts +25 -0
  83. package/src/lib/tasks/lib/enforce-file-layout/index.ts +5 -0
  84. package/src/lib/tasks/lib/enforce-file-layout/internal/check-the-layout-of-each-package.ts +9 -0
  85. package/src/lib/tasks/lib/enforce-file-layout/internal/file-layout-errors.ts +417 -0
  86. package/src/lib/tasks/lib/enforce-file-layout/internal/find-export-path-mismatches.ts +83 -0
  87. package/src/lib/tasks/lib/enforce-file-layout/internal/find-file-layout-violations.ts +848 -0
  88. package/src/lib/tasks/lib/enforce-file-layout/internal/find-module-layout-violations.ts +82 -0
  89. package/src/lib/tasks/lib/enforce-file-layout/internal/resolve-task-imports.ts +178 -0
  90. package/src/lib/tasks/lib/enforce-file-types/index.ts +5 -0
  91. package/src/lib/tasks/lib/enforce-file-types/internal/file-type-errors.ts +21 -0
  92. package/src/lib/tasks/lib/enforce-file-types/internal/find-file-type-violations.ts +78 -0
  93. package/src/lib/tasks/lib/format-with-bun-fmt/index.ts +1 -0
  94. package/src/lib/tasks/lib/format-with-bun-fmt/internal/check-formatting-with-bun-fmt.ts +157 -0
  95. package/src/lib/tasks/lib/format-with-bun-fmt/internal/declare-the-formatting-task.ts +66 -0
  96. package/src/lib/tasks/lib/format-with-bun-fmt/internal/find-format-config-violations.ts +16 -0
  97. package/src/lib/tasks/lib/format-with-bun-fmt/internal/find-format-input-violations.ts +74 -0
  98. package/src/lib/tasks/lib/format-with-bun-fmt/internal/find-symbolic-links.ts +14 -0
  99. package/src/lib/tasks/lib/format-with-bun-fmt/internal/unformatted-file-errors.ts +12 -0
  100. package/src/lib/tasks/lib/judge-index-re-exports/index.ts +1 -0
  101. package/src/lib/tasks/lib/judge-index-re-exports/internal/find-index-re-export-violations.ts +353 -0
  102. package/src/lib/tasks/lib/judge-index-re-exports/internal/index-re-export-errors.ts +21 -0
  103. package/src/lib/tasks/lib/lint-with-oxlint/index.ts +15 -0
  104. package/src/lib/tasks/lib/lint-with-oxlint/internal/check-lint-rules-with-oxlint.ts +123 -0
  105. package/src/lib/tasks/lib/lint-with-oxlint/internal/check-unsafe-enum-assignments.ts +152 -0
  106. package/src/lib/tasks/lib/lint-with-oxlint/internal/find-tsgolint-executable.ts +21 -0
  107. package/src/lib/tasks/lib/lint-with-oxlint/internal/read-oxlint-json-report.ts +82 -0
  108. package/src/lib/tasks/lib/lint-with-oxlint/internal/read-tsgolint-rule-messages.ts +68 -0
  109. package/src/lib/tasks/lib/place-exports-in-the-narrowest-directory/index.ts +1 -0
  110. package/src/lib/tasks/lib/place-exports-in-the-narrowest-directory/internal/export-placement-errors.ts +135 -0
  111. package/src/lib/tasks/lib/place-exports-in-the-narrowest-directory/internal/find-export-placement-violations.ts +507 -0
  112. package/src/lib/tasks/lib/place-exports-in-the-narrowest-directory/internal/find-misplaced-files.ts +116 -0
  113. package/src/lib/tasks/lib/place-exports-in-the-narrowest-directory/internal/find-subdivided-directories.ts +29 -0
  114. package/src/lib/tasks/lib/place-exports-in-the-narrowest-directory/internal/find-the-importer-graph.ts +451 -0
  115. package/src/lib/tasks/lib/place-exports-in-the-narrowest-directory/internal/list-binding-names.ts +49 -0
  116. package/src/lib/tasks/lib/refuse-disable-directives/index.ts +15 -0
  117. package/src/lib/tasks/lib/refuse-disable-directives/internal/disable-directive-errors.ts +45 -0
  118. package/src/lib/tasks/lib/refuse-disable-directives/internal/find-disable-directives.ts +66 -0
  119. package/src/lib/tasks/lib/refuse-error-mappings-that-end-streams/index.ts +1 -0
  120. package/src/lib/tasks/lib/refuse-error-mappings-that-end-streams/internal/error-mapping-errors.ts +21 -0
  121. package/src/lib/tasks/lib/refuse-error-mappings-that-end-streams/internal/find-error-mappings-to-done.ts +135 -0
  122. package/src/lib/tasks/lib/require-separate-service-layers/index.ts +1 -0
  123. package/src/lib/tasks/lib/require-separate-service-layers/internal/find-service-layer-violations.ts +170 -0
  124. package/src/lib/tasks/lib/require-separate-service-layers/internal/service-layer-errors.ts +21 -0
  125. package/src/lib/tasks/lib/require-type-checking-every-linted-file/index.ts +14 -0
  126. package/src/lib/tasks/lib/require-type-checking-every-linted-file/internal/find-linted-files-not-type-checked.ts +117 -0
  127. package/src/lib/tasks/lib/require-type-checking-every-linted-file/internal/linted-file-errors.ts +51 -0
  128. package/src/lib/tasks/lib/type-check-with-bun-check/index.ts +11 -0
  129. package/src/lib/tasks/lib/type-check-with-bun-check/internal/check-types-with-bun-check.ts +54 -0
  130. package/src/lib/tasks/lib/type-check-with-bun-check/internal/read-bun-check-output.ts +73 -0
  131. package/src/lib/tasks/lib/type-check-with-bun-check/internal/type-check-errors.ts +10 -0
  132. package/src/lib/tasks/shared/check-each-nested-package.ts +79 -0
  133. package/src/lib/tasks/shared/classify-files-by-role.ts +115 -0
  134. package/src/lib/tasks/shared/count-the-line-of-an-offset.ts +2 -0
  135. package/src/lib/tasks/shared/create-the-module-resolver.ts +38 -0
  136. package/src/lib/tasks/shared/declare-lint-config-task.ts +13 -0
  137. package/src/lib/tasks/shared/declare-typescript-config-task.ts +18 -0
  138. package/src/lib/tasks/shared/encode-compact-json.ts +5 -0
  139. package/src/lib/tasks/shared/find-installed-package-binaries.ts +62 -0
  140. package/src/lib/tasks/shared/find-module-requests.ts +482 -0
  141. package/src/lib/tasks/shared/find-named-package-manifests.ts +94 -0
  142. package/src/lib/tasks/shared/find-unmet-typescript-config-requirements.ts +60 -0
  143. package/src/lib/tasks/shared/list-ignored-files-imported-by-source.ts +79 -0
  144. package/src/lib/tasks/shared/list-linted-files.ts +28 -0
  145. package/src/lib/tasks/shared/list-owned-files.ts +13 -0
  146. package/src/lib/tasks/shared/list-package-files.ts +66 -0
  147. package/src/lib/tasks/shared/load-the-lint-config.ts +176 -0
  148. package/src/lib/tasks/shared/match-granted-patch-files.ts +88 -0
  149. package/src/lib/tasks/shared/parse-config-files-that-import-from-check.ts +310 -0
  150. package/src/lib/tasks/shared/print-failures-and-keep-detail-in-the-trace.ts +99 -0
  151. package/src/lib/tasks/shared/project-config-and-tool-errors.ts +485 -0
  152. package/src/lib/tasks/shared/query-the-typescript-project.ts +635 -0
  153. package/src/lib/tasks/shared/read-named-package-manifests.ts +53 -0
  154. package/src/lib/tasks/shared/read-package-manifest-object.ts +28 -0
  155. package/src/lib/tasks/shared/resolve-absolute-paths.ts +4 -0
  156. package/src/lib/tasks/shared/resolve-module-requests.ts +121 -0
  157. package/src/lib/tasks/shared/run-tools-and-decode-their-reports.ts +98 -0
  158. package/src/lib/tasks/shared/tool-file-locations.ts +38 -0
  159. package/src/shared/bans-each-permission-lifts.ts +454 -0
  160. package/src/shared/config-file-names.ts +3 -0
  161. package/src/shared/find-retired-words.ts +17 -0
  162. package/src/shared/format-reported-failures.ts +31 -0
  163. package/src/shared/lint-rule-messages-and-patterns.ts +104 -0
  164. package/src/shared/match-file-names-and-path-prefixes.ts +18 -0
  165. package/src/shared/permission-grant-errors.ts +42 -0
  166. package/src/shared/record-and-grant-permissions-by-path.ts +419 -0
  167. package/src/shared/test-home-directories.ts +4 -0
@@ -0,0 +1,454 @@
1
+ import { Record } from "effect";
2
+
3
+ import {
4
+ isNodeBuiltinThatBunAliases,
5
+ nodeBuiltinNameOf,
6
+ } from "./lint-rule-messages-and-patterns.ts";
7
+ import { SCRIPTS_DIRECTORY } from "./test-home-directories.ts";
8
+
9
+ export const SYNC_WRITES = [
10
+ "appendFileSync",
11
+ "writeFileSync",
12
+ "writeSync",
13
+ "writevSync",
14
+ "fsyncSync",
15
+ "fdatasyncSync",
16
+ "openSync",
17
+ "closeSync",
18
+ ] as const;
19
+
20
+ const SYNC_READS = [
21
+ "accessSync",
22
+ "existsSync",
23
+ "fstatSync",
24
+ "lstatSync",
25
+ "opendirSync",
26
+ "readFileSync",
27
+ "readSync",
28
+ "readdirSync",
29
+ "readlinkSync",
30
+ "readvSync",
31
+ "realpathSync",
32
+ "statSync",
33
+ "statfsSync",
34
+ ] as const;
35
+
36
+ const IN_MEMORY_SYNC = [
37
+ "parseSync",
38
+ "decodeSync",
39
+ "decodeUnknownSync",
40
+ "encodeSync",
41
+ "encodeUnknownSync",
42
+ "failSync",
43
+ "failCauseSync",
44
+ "dieSync",
45
+ "endSync",
46
+ ] as const;
47
+
48
+ const EFFECT_RUNNERS = ["runSync", "runSyncExit"] as const;
49
+
50
+ const SYNC_NAME = /.Sync$/u;
51
+
52
+ const NAMES_OUTSIDE_THE_SYNC_CALL_CHECK: ReadonlySet<string> = new Set([
53
+ ...IN_MEMORY_SYNC,
54
+ ...EFFECT_RUNNERS,
55
+ ...SYNC_WRITES,
56
+ ...SYNC_READS,
57
+ ]);
58
+
59
+ export const isDeclaredSync = (name: string) =>
60
+ SYNC_NAME.test(name) && !NAMES_OUTSIDE_THE_SYNC_CALL_CHECK.has(name);
61
+
62
+ export const TASK_PACKAGE = "@sshkeda/task";
63
+ export const TASK_NAMESPACE_EXPORT = "Task";
64
+ export const TASK_MAKE_MEMBER = "make";
65
+ export const TASK_MAIN_MEMBER = "main";
66
+
67
+ export const IMPORT_META = "import.meta";
68
+
69
+ export const MODULE_PATTERN_WILDCARD = "*";
70
+
71
+ const MODULES_OF_GLOBAL_OBJECTS = {
72
+ Bun: "bun",
73
+ process: "node:process",
74
+ } as const;
75
+
76
+ export const moduleOfGlobalObject = (globalObject: string) =>
77
+ Object.entries(MODULES_OF_GLOBAL_OBJECTS).find(([object]) => object === globalObject)?.[1];
78
+
79
+ export const moduleBan = (
80
+ modulePatterns: readonly string[],
81
+ exceptImportNames: readonly string[] = [],
82
+ ) => ({ kind: "module", modulePatterns, exceptImportNames }) as const;
83
+
84
+ export const importsBan = (modulePattern: string, importNames: readonly string[]) =>
85
+ ({ kind: "imports", modulePattern, importNames }) as const;
86
+
87
+ const globalMembersBan = (
88
+ globalObject: keyof typeof MODULES_OF_GLOBAL_OBJECTS | typeof IMPORT_META,
89
+ memberNames: readonly string[],
90
+ ) => ({ kind: "global-members", globalObject, memberNames }) as const;
91
+
92
+ const effectMembersBan = (
93
+ memberPathPrefixes: readonly (readonly [string, ...string[]])[],
94
+ exceptExactMemberPaths: typeof memberPathPrefixes = [],
95
+ ) => ({ kind: "effect-members", memberPathPrefixes, exceptExactMemberPaths }) as const;
96
+
97
+ const memberNamesBan = (memberNames: readonly string[]) =>
98
+ ({ kind: "member-names", memberNames }) as const;
99
+
100
+ const DYNAMIC_IMPORT_BAN = { kind: "dynamic-import" } as const;
101
+
102
+ const createdRequireBan = (
103
+ modulePattern: string,
104
+ importNames: readonly string[],
105
+ exceptMemberNames: readonly string[],
106
+ ) => ({ kind: "created-require", modulePattern, importNames, exceptMemberNames }) as const;
107
+
108
+ const CREATE_REQUIRE_IMPORTS = ["createRequire", "Module.createRequire"] as const;
109
+ export const CREATED_REQUIRE_USAGE = "a require createRequire returns";
110
+ export const CREATE_REQUIRE_VALUE_USAGE = "createRequire used other than by a call";
111
+
112
+ export const SCRIPT = "script";
113
+ export const TRUSTS_UNVERIFIED_TYPES = "trustsUnverifiedTypes";
114
+ export const WRITES_TO_THE_TERMINAL = "writesToTheTerminal";
115
+ const LOCKS_FILES = "locksFiles";
116
+ export const HANDLES_EVERY_FAILURE = "handlesEveryFailure";
117
+
118
+ const CATCH_ALLS = ["catch", "catchCause", "catchDefect"] as const;
119
+ const PREDICATE_CATCHES = ["catchIf", "catchFilter", "catchCauseIf", "catchCauseFilter"] as const;
120
+ const IGNORES = ["ignore", "ignoreCause"] as const;
121
+ const FIBER_COLLECTION_RUNNERS = [
122
+ "makeRuntime",
123
+ "makeRuntimePromise",
124
+ "run",
125
+ "runtime",
126
+ "runtimePromise",
127
+ ] as const;
128
+
129
+ export const OPERATIONS_THAT_HANDLE_UNNAMED_FAILURES = {
130
+ Effect: [
131
+ ...CATCH_ALLS,
132
+ ...PREDICATE_CATCHES,
133
+ ...IGNORES,
134
+ "catchEager",
135
+ "eventually",
136
+ "exit",
137
+ "firstSuccessOf",
138
+ "flip",
139
+ "forkChild",
140
+ "forkIn",
141
+ "forkScoped",
142
+ "isFailure",
143
+ "isSuccess",
144
+ "match",
145
+ "matchCause",
146
+ "matchCauseEager",
147
+ "matchCauseEffect",
148
+ "matchCauseEffectEager",
149
+ "matchEager",
150
+ "matchEffect",
151
+ "option",
152
+ "orElseSucceed",
153
+ "partition",
154
+ "race",
155
+ "raceAll",
156
+ "repeatOrElse",
157
+ "result",
158
+ "retryOrElse",
159
+ "runCallback",
160
+ "runCallbackWith",
161
+ "runFork",
162
+ "runForkWith",
163
+ "runPromise",
164
+ "runPromiseExit",
165
+ "runPromiseExitWith",
166
+ "runPromiseWith",
167
+ "runSync",
168
+ "runSyncExit",
169
+ "runSyncExitWith",
170
+ "runSyncWith",
171
+ "sandbox",
172
+ "validate",
173
+ ],
174
+ Stream: [
175
+ ...CATCH_ALLS,
176
+ ...PREDICATE_CATCHES,
177
+ ...IGNORES,
178
+ "orElseSucceed",
179
+ "race",
180
+ "raceAll",
181
+ "result",
182
+ "callback",
183
+ "runIntoPubSub",
184
+ "runIntoQueue",
185
+ "toAsyncIterable",
186
+ "toAsyncIterableEffect",
187
+ "toAsyncIterableWith",
188
+ "toPubSub",
189
+ "toPubSubTake",
190
+ "toQueue",
191
+ "toReadableStream",
192
+ "toReadableStreamEffect",
193
+ "toReadableStreamWith",
194
+ ],
195
+ Channel: [
196
+ ...CATCH_ALLS,
197
+ ...PREDICATE_CATCHES,
198
+ ...IGNORES,
199
+ "callback",
200
+ "callbackArray",
201
+ "runIntoPubSub",
202
+ "runIntoPubSubArray",
203
+ "runIntoQueue",
204
+ "runIntoQueueArray",
205
+ "toPubSub",
206
+ "toPubSubArray",
207
+ "toPubSubTake",
208
+ "toQueue",
209
+ "toQueueArray",
210
+ ],
211
+ Layer: ["catch", "catchCause"],
212
+ Sink: ["catch", "catchCause", "orElse"],
213
+ Fiber: ["await", "awaitAll"],
214
+ Pull: ["matchEffect"],
215
+ Deferred: ["complete", "into"],
216
+ Queue: ["into", "poll", "takeUnsafe"],
217
+ FiberSet: FIBER_COLLECTION_RUNNERS,
218
+ FiberMap: FIBER_COLLECTION_RUNNERS,
219
+ FiberHandle: FIBER_COLLECTION_RUNNERS,
220
+ Pool: ["make", "makeWithStrategy", "makeWithTTL"],
221
+ Runtime: ["makeRunMain"],
222
+ } as const;
223
+
224
+ const PLATFORM_RUNNER = "runMain";
225
+
226
+ const OUTCOME_MEMBERS = [
227
+ "addObserver",
228
+ "pollUnsafe",
229
+ "runCallback",
230
+ "runFork",
231
+ "runPromise",
232
+ "runPromiseExit",
233
+ "runSync",
234
+ "runSyncExit",
235
+ ] as const;
236
+
237
+ const GRANTABLE_BANS = {
238
+ readsConfig: {
239
+ ruleName: "no-config-reads",
240
+ description:
241
+ "Read environment variables, raw command-line arguments and Effect Config only in files allowed readsConfig; no file reads process.argv0, Bun.env, Bun.argv, import.meta.env or parseArgs.",
242
+ message: `{{usage}} reads configuration`,
243
+ bans: [
244
+ globalMembersBan("process", ["env", "argv"]),
245
+ effectMembersBan(
246
+ [["Config"]],
247
+ [
248
+ ["Config", "ConfigError"],
249
+ ["Config", "isConfigError"],
250
+ ],
251
+ ),
252
+ ],
253
+ bannedEvenWhenGranted: {
254
+ message:
255
+ "{{usage}} reads configuration, which no file may do; read it through Effect Config, process.env or process.argv in a file allowed readsConfig",
256
+ bans: [
257
+ globalMembersBan("process", ["argv0"]),
258
+ globalMembersBan("Bun", ["env", "argv"]),
259
+ globalMembersBan(IMPORT_META, ["env"]),
260
+ importsBan("node:util", ["parseArgs"]),
261
+ ],
262
+ },
263
+ },
264
+ spawnsCommands: {
265
+ ruleName: "no-command-spawn",
266
+ description:
267
+ "Start commands only in files allowed spawnsCommands, through Effect ChildProcess, Bun.spawn or spawn from node:child_process; no file uses Bun.spawnSync, Bun.$, the rest of node:child_process or a platform ChildProcessSpawner.",
268
+ message: "{{usage}} starts a command directly",
269
+ bans: [
270
+ moduleBan(["effect/process/ChildProcess", "effect/process/ChildProcessSpawner"]),
271
+ importsBan("effect/process", ["ChildProcess", "ChildProcessSpawner"]),
272
+ globalMembersBan("Bun", ["spawn"]),
273
+ importsBan("node:child_process", ["spawn"]),
274
+ ],
275
+ bannedEvenWhenGranted: {
276
+ message:
277
+ "{{usage}} starts a command in a way no file may; start it through Effect ChildProcess in a file allowed spawnsCommands",
278
+ bans: [
279
+ moduleBan(["node:child_process"], ["spawn"]),
280
+ moduleBan(["@effect/platform-*/*ChildProcessSpawner"]),
281
+ importsBan("@effect/platform-*", ["BunChildProcessSpawner", "NodeChildProcessSpawner"]),
282
+ globalMembersBan("Bun", ["spawnSync", "$"]),
283
+ ],
284
+ },
285
+ },
286
+ [LOCKS_FILES]: {
287
+ ruleName: "no-node-file-system",
288
+ description:
289
+ "Take file locks with open from node:fs/promises and constants from node:fs only in files allowed locksFiles; no file uses the rest of node:fs or node:fs/promises, under any of their names.",
290
+ message: "{{usage}} reaches the file system directly",
291
+ bans: [importsBan("node:fs", ["constants"]), importsBan("node:fs/promises", ["open"])],
292
+ bannedEvenWhenGranted: {
293
+ message:
294
+ "{{usage}} reaches the file system in a way no file may; use the Effect FileSystem service, or take a file lock with open from node:fs/promises and constants from node:fs in a file allowed locksFiles",
295
+ bans: [
296
+ moduleBan(["node:fs"], ["constants", ...SYNC_WRITES, ...SYNC_READS]),
297
+ moduleBan(["node:fs/promises"], ["open"]),
298
+ ],
299
+ },
300
+ },
301
+ importsDynamically: {
302
+ ruleName: "no-dynamic-import",
303
+ description:
304
+ "Keep the module graph static so tools see every dependency; only files allowed importsDynamically use import() or createRequire, no file loads a module through the require createRequire returns, only resolves one, and no file uses import.meta.require or node:vm.",
305
+ message: "{{usage}} is banned",
306
+ bans: [DYNAMIC_IMPORT_BAN, importsBan("node:module", CREATE_REQUIRE_IMPORTS)],
307
+ bannedEvenWhenGranted: {
308
+ message:
309
+ "{{usage}} loads code in a way no file may; use import() in a file allowed importsDynamically",
310
+ bans: [
311
+ globalMembersBan(IMPORT_META, ["require"]),
312
+ moduleBan(["node:vm"]),
313
+ createdRequireBan("node:module", CREATE_REQUIRE_IMPORTS, ["resolve"]),
314
+ ],
315
+ },
316
+ },
317
+ exitsTheProcess: {
318
+ ruleName: "no-process-exit",
319
+ description: "Exit the process directly only in files allowed exitsTheProcess.",
320
+ message: "{{usage}} exits the process directly",
321
+ bans: [globalMembersBan("process", ["exit"])],
322
+ },
323
+ usesSqlDatabases: {
324
+ ruleName: "no-sql-clients",
325
+ description:
326
+ "Talk to SQL databases through Effect SQL only in files allowed usesSqlDatabases; no file uses another SQL client.",
327
+ message: "{{usage}} uses a SQL client outside a usesSqlDatabases file",
328
+ bans: [
329
+ moduleBan(["@effect/sql", "@effect/sql-*", "effect/sql", "effect/sql/*"]),
330
+ importsBan(MODULE_PATTERN_WILDCARD, ["SqlClient"]),
331
+ ],
332
+ bannedEvenWhenGranted: {
333
+ message:
334
+ "{{usage}} is a SQL client no file may use; use Effect SQL in a file allowed usesSqlDatabases",
335
+ bans: [
336
+ moduleBan([
337
+ "bun:sqlite",
338
+ "node:sqlite",
339
+ "sqlite3",
340
+ "better-sqlite3",
341
+ "pg",
342
+ "pg/*",
343
+ "postgres",
344
+ "mysql2",
345
+ "mysql2/*",
346
+ ]),
347
+ globalMembersBan("Bun", ["SQL", "sql"]),
348
+ ],
349
+ },
350
+ },
351
+ [WRITES_TO_THE_TERMINAL]: {
352
+ ruleName: "no-terminal-writes",
353
+ description:
354
+ "Write to the terminal through the Effect Stdio service, and use it for more than reading stdin, args or whether a stream is a terminal, only in files allowed writesToTheTerminal; no file uses Effect Console, node:console, process.stdout, process.stderr, Bun.stdout or Bun.stderr.",
355
+ message: "{{usage}} writes to the terminal",
356
+ bans: [],
357
+ bannedEvenWhenGranted: {
358
+ message:
359
+ "{{usage}} writes to the terminal in a way no file may; write through the Effect Stdio service in a file allowed writesToTheTerminal",
360
+ bans: [
361
+ effectMembersBan([["Console"]]),
362
+ moduleBan(["node:console"]),
363
+ globalMembersBan("process", ["stdout", "stderr"]),
364
+ globalMembersBan("Bun", ["stdout", "stderr"]),
365
+ ],
366
+ },
367
+ },
368
+ };
369
+
370
+ export const PERMISSION_BANS = {
371
+ ...GRANTABLE_BANS,
372
+ [TRUSTS_UNVERIFIED_TYPES]: {
373
+ ruleName: "no-unverified-types",
374
+ description:
375
+ "Declare a schema from a type guard with Schema.declare or Schema.declareConstructor only in files allowed trustsUnverifiedTypes, whose grant gives a reason.",
376
+ message: `{{usage}} declares a type nothing verifies`,
377
+ bans: [
378
+ effectMembersBan([
379
+ ["Schema", "declare"],
380
+ ["Schema", "declareConstructor"],
381
+ ]),
382
+ ],
383
+ },
384
+ [HANDLES_EVERY_FAILURE]: {
385
+ ruleName: "no-unnamed-recovery",
386
+ description:
387
+ "Handle failures by name with catchTag, catchTags or catchReason, and turn a failure you have not named into a success or a value only in files allowed handlesEveryFailure, whose grant gives a reason.",
388
+ message: "{{usage}} handles failures it does not name",
389
+ bans: [
390
+ effectMembersBan(
391
+ Object.entries(OPERATIONS_THAT_HANDLE_UNNAMED_FAILURES).flatMap(
392
+ ([moduleName, operations]) =>
393
+ operations.map((operation) => [moduleName, operation] as const),
394
+ ),
395
+ ),
396
+ memberNamesBan([...OUTCOME_MEMBERS, PLATFORM_RUNNER]),
397
+ importsBan(MODULE_PATTERN_WILDCARD, [PLATFORM_RUNNER]),
398
+ ],
399
+ },
400
+ syncFileAccess: {
401
+ ruleName: "no-sync-file-access",
402
+ description: "Read and write files without blocking; no file may read or write synchronously.",
403
+ message: "{{usage}} reaches the file system synchronously",
404
+ bans: [
405
+ importsBan(MODULE_PATTERN_WILDCARD, [...SYNC_READS, ...SYNC_WRITES]),
406
+ memberNamesBan([...SYNC_READS, ...SYNC_WRITES]),
407
+ ],
408
+ },
409
+ [SCRIPT]: {
410
+ ruleName: "no-task-main",
411
+ description: `Run tasks with ${TASK_NAMESPACE_EXPORT}.${TASK_MAIN_MEMBER} from ${TASK_PACKAGE} only in files directly in ${SCRIPTS_DIRECTORY}/.`,
412
+ message: "{{usage}} runs tasks outside a script",
413
+ bans: [importsBan(TASK_PACKAGE, [`${TASK_NAMESPACE_EXPORT}.${TASK_MAIN_MEMBER}`])],
414
+ },
415
+ };
416
+
417
+ export const PERMISSION_BAN_NAMES = Record.keys(PERMISSION_BANS);
418
+
419
+ export const BANS_NO_GRANT_LIFTS = "onlyThoseNoGrantLifts";
420
+
421
+ export const bansNoGrantLifts = (permission: keyof typeof PERMISSION_BANS) => {
422
+ const entry = PERMISSION_BANS[permission];
423
+ return "bannedEvenWhenGranted" in entry ? entry.bannedEvenWhenGranted.bans : [];
424
+ };
425
+
426
+ export const everyBanOf = (entry: (typeof PERMISSION_BANS)[keyof typeof PERMISSION_BANS]) => [
427
+ ...entry.bans,
428
+ ...("bannedEvenWhenGranted" in entry ? entry.bannedEvenWhenGranted.bans : []),
429
+ ];
430
+
431
+ export const SHORT_NAMES = "usesAbbreviations";
432
+
433
+ export const RULES_EACH_PERMISSION_LIFTS = {
434
+ [SHORT_NAMES]: "no-abbreviations",
435
+ } as const;
436
+
437
+ export const GRANTABLE_BAN_NAMES = Record.keys(GRANTABLE_BANS);
438
+
439
+ export const equivalentModuleSpecifiers = (specifier: string) => {
440
+ const builtinName = nodeBuiltinNameOf(specifier);
441
+ if (builtinName === specifier) {
442
+ return [specifier];
443
+ }
444
+ return [
445
+ `node:${builtinName}`,
446
+ builtinName,
447
+ ...(isNodeBuiltinThatBunAliases(builtinName) ? [`bun:${builtinName}`] : []),
448
+ ];
449
+ };
450
+
451
+ export const moduleSpecifiersOfGlobalObject = (globalObject: string) => {
452
+ const module = moduleOfGlobalObject(globalObject);
453
+ return module === undefined ? [] : equivalentModuleSpecifiers(module);
454
+ };
@@ -0,0 +1,3 @@
1
+ export const LINT_CONFIG_FILE = "oxlint.config.ts";
2
+ export const FORMAT_CONFIG_FILE = "oxfmt.config.ts";
3
+ export const FORMAT_CONFIG_BINDING = "FORMAT_CONFIG";
@@ -0,0 +1,17 @@
1
+ export const RETIRED_WORDS: ReadonlySet<string> = new Set([
2
+ "fingerprint",
3
+ "fingerprints",
4
+ "folder",
5
+ "folders",
6
+ "settings",
7
+ "finding",
8
+ "findings",
9
+ "problem",
10
+ "problems",
11
+ ]);
12
+
13
+ export const retiredWordIn = (candidates: readonly string[]) =>
14
+ candidates
15
+ .map((candidate) => candidate.toLowerCase())
16
+ .filter((word) => RETIRED_WORDS.has(word))
17
+ .map((word) => ({ word }))[0];
@@ -0,0 +1,31 @@
1
+ import type { PrintableError } from "@sshkeda/task/errors";
2
+
3
+ export const printableError = (failure: {
4
+ readonly _tag: string;
5
+ readonly message: string;
6
+ readonly location?: string;
7
+ }): PrintableError => ({
8
+ tag: failure._tag,
9
+ ...(failure.location === undefined ? {} : { location: failure.location }),
10
+ message: failure.message,
11
+ });
12
+
13
+ export const formattedError = (printable: PrintableError) => {
14
+ const [firstLine = "", ...continuationLines] = printable.message.split("\n");
15
+ return [
16
+ `${printable.location === undefined ? "" : `${printable.location}: `}error ${printable.tag}: ${firstLine}`,
17
+ ...continuationLines.map((line) => ` ${line}`),
18
+ ].join("\n");
19
+ };
20
+
21
+ export const listedViolations = (violations: readonly Parameters<typeof printableError>[0][]) =>
22
+ violations.map((found) => formattedError(printableError(found))).join("\n");
23
+
24
+ export const printableErrorWith = (
25
+ printable: PrintableError,
26
+ replacement: { readonly tag?: string; readonly message?: string },
27
+ ): PrintableError => ({
28
+ tag: replacement.tag ?? printable.tag,
29
+ ...(printable.location === undefined ? {} : { location: printable.location }),
30
+ message: replacement.message ?? printable.message,
31
+ });
@@ -0,0 +1,104 @@
1
+ import { isBuiltin } from "node:module";
2
+
3
+ const DIRECTIVE =
4
+ /^\s*(?:(?:oxlint|eslint)-(?:disable|enable)|@ts-(?:ignore|expect-error|nocheck)|@effect-diagnostics)/u;
5
+
6
+ const TYPESCRIPT_SUPPRESSION_ON_A_LAST_LINE = /\n[\s*/]*@ts-(?:ignore|expect-error)[^\n]*$/u;
7
+
8
+ export const isDirective = (commentText: string) =>
9
+ DIRECTIVE.test(commentText) || TYPESCRIPT_SUPPRESSION_ON_A_LAST_LINE.test(commentText);
10
+
11
+ export const EFFECT_OPERATION_RULES = {
12
+ "no-dropped-failures": {
13
+ description:
14
+ "Handle Effect, Layer, Stream and Channel failures instead of dying, and read an Option or Result without throwing.",
15
+ operations: {
16
+ Effect: ["orDie", "orDieWith"],
17
+ Layer: ["orDie"],
18
+ Stream: ["orDie"],
19
+ Channel: ["orDie"],
20
+ Option: ["getOrThrow", "getOrThrowWith"],
21
+ Result: ["getOrThrow", "getOrThrowWith"],
22
+ },
23
+ },
24
+ "no-detached-fibers": {
25
+ description: "Fork fibers into a scope instead of detaching them.",
26
+ operations: { Effect: ["forkDetach"] },
27
+ },
28
+ "no-sleep": {
29
+ description: "Wait on signals instead of sleeping.",
30
+ operations: { Effect: ["sleep", "delay"] },
31
+ },
32
+ "no-untraced-functions": {
33
+ description: "Trace Effect functions.",
34
+ operations: { Effect: ["fnUntraced"] },
35
+ },
36
+ } as const satisfies Readonly<
37
+ Record<
38
+ string,
39
+ {
40
+ readonly description: string;
41
+ readonly operations: Readonly<Record<string, readonly string[]>>;
42
+ }
43
+ >
44
+ >;
45
+
46
+ export const GLOBAL_RULES = {
47
+ "no-timer-globals": { globals: ["setTimeout", "setInterval", "performance"] },
48
+ "no-global-object": { globals: ["globalThis", "global", "self"] },
49
+ } as const satisfies Readonly<Record<string, { readonly globals: readonly string[] }>>;
50
+
51
+ export const NODE_BUILTIN_RULES = {
52
+ "no-node-path": { modules: ["path", "path/posix", "path/win32"] },
53
+ "no-node-crypto": { modules: ["crypto"] },
54
+ "no-node-os": { modules: ["os"] },
55
+ "no-node-http": { modules: ["http", "https"] },
56
+ "no-node-stream": { modules: ["stream"] },
57
+ "no-node-timers": { modules: ["timers", "timers/promises", "perf_hooks"] },
58
+ } as const satisfies Readonly<Record<string, { readonly modules: readonly string[] }>>;
59
+
60
+ export const SCHEDULE_MESSAGES = {
61
+ polling: "{{usage}} polls on a timer",
62
+ deadline: "{{usage}} polls without a deadline",
63
+ retrying: "{{usage}} retries on a timer",
64
+ retryingEvenWhenGranted:
65
+ "{{usage}} retries on a timer, which no file may do, even with a deadline",
66
+ scheduleEvenWhenGranted:
67
+ "{{usage}} is a timed schedule no file may use; repeat with Schedule.spaced under a deadline in a file allowed pollsWithADeadline",
68
+ } as const;
69
+
70
+ export const BUN_TEST = "bun:test";
71
+ export const BUN_TEST_ASSERTIONS = new Set(["expect"]);
72
+
73
+ const NODE_PROTOCOL = "node:";
74
+ export const TEST_RUNNER_MODULES = new Set(["vitest", "jest", "@jest/globals", "@effect/vitest"]);
75
+ export const ASSERTION_MODULES = new Set([
76
+ "assert",
77
+ "assert/strict",
78
+ "node:assert",
79
+ "node:assert/strict",
80
+ "bun:assert",
81
+ "bun:assert/strict",
82
+ ]);
83
+
84
+ const BUN_PROTOCOL = "bun:";
85
+ const BUN_MODULES_UNLIKE_THE_NODE_BUILTIN_OF_THE_SAME_NAME: ReadonlySet<string> = new Set([
86
+ "sqlite",
87
+ "test",
88
+ ]);
89
+
90
+ export const isNodeBuiltinThatBunAliases = (name: string) =>
91
+ isBuiltin(name) && !BUN_MODULES_UNLIKE_THE_NODE_BUILTIN_OF_THE_SAME_NAME.has(name);
92
+
93
+ export const nodeBuiltinNameOf = (source: string) => {
94
+ if (source.startsWith(NODE_PROTOCOL)) {
95
+ return source.slice(NODE_PROTOCOL.length);
96
+ }
97
+ const bunName = source.slice(BUN_PROTOCOL.length);
98
+ const isBunAliasOfANodeBuiltin =
99
+ source.startsWith(BUN_PROTOCOL) && isNodeBuiltinThatBunAliases(bunName);
100
+ return isBunAliasOfANodeBuiltin ? bunName : source;
101
+ };
102
+
103
+ export const isTestRunnerModule = (source: string) =>
104
+ TEST_RUNNER_MODULES.has(source) || source.startsWith("vitest/");
@@ -0,0 +1,18 @@
1
+ const ENTRY_FILE_NAMES: ReadonlySet<string> = new Set(["index.ts", "index.tsx"]);
2
+
3
+ export const isWithin = (path: string, enclosingPath: string) =>
4
+ path === enclosingPath || path.startsWith(`${enclosingPath}/`);
5
+
6
+ export const fileNameOf = (path: string) => path.split("/").at(-1) ?? path;
7
+
8
+ export const directoryHolding = (file: string) => file.slice(0, file.lastIndexOf("/"));
9
+
10
+ export const isEntryFileName = (fileName: string) => ENTRY_FILE_NAMES.has(fileName);
11
+
12
+ export const SHARED_DIRECTORY_NAME = "shared";
13
+ export const INTERNAL_DIRECTORY_NAME = "internal";
14
+ export const LIBRARY_DIRECTORY_NAME = "lib";
15
+ export const LAYOUT_DIRECTORY_NAMES: ReadonlySet<string> = new Set([
16
+ SHARED_DIRECTORY_NAME,
17
+ INTERNAL_DIRECTORY_NAME,
18
+ ]);
@@ -0,0 +1,42 @@
1
+ import { Effect, Schema } from "effect";
2
+
3
+ import { LINT_CONFIG_FILE } from "./config-file-names.ts";
4
+ import { listedViolations } from "./format-reported-failures.ts";
5
+
6
+ export class MalformedGrant extends Schema.TaggedError<MalformedGrant>()("MalformedGrant", {
7
+ issuePath: Schema.String,
8
+ issueMessage: Schema.String,
9
+ location: Schema.Literal(LINT_CONFIG_FILE).pipe(
10
+ Schema.optionalKey,
11
+ Schema.withConstructorDefault(Effect.succeed(LINT_CONFIG_FILE)),
12
+ ),
13
+ }) {
14
+ public override get message() {
15
+ return `${this.issuePath}: ${this.issueMessage}`;
16
+ }
17
+ }
18
+
19
+ export const cannotImportPermission = (target: string) => `cannotImport: ["${target}"]`;
20
+
21
+ export class RedundantGrant extends Schema.TaggedError<RedundantGrant>()("RedundantGrant", {
22
+ path: Schema.String,
23
+ permission: Schema.String,
24
+ reason: Schema.String,
25
+ location: Schema.Literal(LINT_CONFIG_FILE).pipe(
26
+ Schema.optionalKey,
27
+ Schema.withConstructorDefault(Effect.succeed(LINT_CONFIG_FILE)),
28
+ ),
29
+ }) {
30
+ public override get message() {
31
+ return `${this.path} is granted ${this.permission}, but ${this.reason}`;
32
+ }
33
+ }
34
+
35
+ export class PermissionGrantsRefused extends Schema.TaggedError<PermissionGrantsRefused>()(
36
+ "PermissionGrantsRefused",
37
+ { violations: Schema.Array(MalformedGrant) },
38
+ ) {
39
+ public override get message() {
40
+ return listedViolations(this.violations);
41
+ }
42
+ }