@sshkeda/check 0.0.0-stage → 1.0.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 (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 +827 -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,485 @@
1
+ import { Record, Schema } from "effect";
2
+
3
+ import { FORMAT_CONFIG_FILE } from "../../../shared/config-file-names.ts";
4
+ import { listedViolations } from "../../../shared/format-reported-failures.ts";
5
+ import { MalformedGrant } from "../../../shared/permission-grant-errors.ts";
6
+
7
+ export class TypeScriptApiFailed extends Schema.TaggedError<TypeScriptApiFailed>()(
8
+ "TypeScriptApiFailed",
9
+ { operation: Schema.String, reason: Schema.String },
10
+ ) {
11
+ public override get message() {
12
+ return `the TypeScript API failed to ${this.operation}: ${this.reason}`;
13
+ }
14
+ }
15
+
16
+ export class TypeScriptReturnedNothing extends Schema.TaggedError<TypeScriptReturnedNothing>()(
17
+ "TypeScriptReturnedNothing",
18
+ { operation: Schema.String },
19
+ ) {
20
+ public override get message() {
21
+ return `the TypeScript API returned nothing when asked to ${this.operation}`;
22
+ }
23
+ }
24
+
25
+ export class CheckCrashed extends Schema.TaggedError<CheckCrashed>()("CheckCrashed", {
26
+ check: Schema.String,
27
+ reason: Schema.String,
28
+ }) {
29
+ public override get message() {
30
+ return `${this.check} crashed: ${this.reason}`;
31
+ }
32
+ }
33
+
34
+ export class ModuleRequestUnresolvable extends Schema.TaggedError<ModuleRequestUnresolvable>()(
35
+ "ModuleRequestUnresolvable",
36
+ { request: Schema.String, importingFile: Schema.String, reason: Schema.String },
37
+ ) {
38
+ public get location() {
39
+ return this.importingFile;
40
+ }
41
+ public override get message() {
42
+ return `could not resolve ${this.request}: ${this.reason}`;
43
+ }
44
+ }
45
+
46
+ export class ProgramFilesOutsideProject extends Schema.TaggedError<ProgramFilesOutsideProject>()(
47
+ "ProgramFilesOutsideProject",
48
+ { projectFile: Schema.String, listedFile: Schema.String },
49
+ ) {
50
+ public get location() {
51
+ return this.projectFile;
52
+ }
53
+ public override get message() {
54
+ return `compiles no file inside its directory, only files such as ${this.listedFile}`;
55
+ }
56
+ }
57
+
58
+ export class ConfigFileMissing extends Schema.TaggedError<ConfigFileMissing>()(
59
+ "ConfigFileMissing",
60
+ { file: Schema.String },
61
+ ) {
62
+ public get location() {
63
+ return this.file;
64
+ }
65
+ public override get message() {
66
+ return `does not exist`;
67
+ }
68
+ }
69
+
70
+ export class ConfigFileUnparsable extends Schema.TaggedError<ConfigFileUnparsable>()(
71
+ "ConfigFileUnparsable",
72
+ { file: Schema.String, reason: Schema.String },
73
+ ) {
74
+ public get location() {
75
+ return this.file;
76
+ }
77
+ public override get message() {
78
+ return `does not parse: ${this.reason}`;
79
+ }
80
+ }
81
+
82
+ export class ConfigFileMissingDefaultExport extends Schema.TaggedError<ConfigFileMissingDefaultExport>()(
83
+ "ConfigFileMissingDefaultExport",
84
+ { file: Schema.String, defaultExport: Schema.String },
85
+ ) {
86
+ public get location() {
87
+ return this.file;
88
+ }
89
+ public override get message() {
90
+ return `has no export default ${this.defaultExport}`;
91
+ }
92
+ }
93
+
94
+ export class ConfigFileExportsSomethingElse extends Schema.TaggedError<ConfigFileExportsSomethingElse>()(
95
+ "ConfigFileExportsSomethingElse",
96
+ { location: Schema.String, defaultExport: Schema.String },
97
+ ) {
98
+ public override get message() {
99
+ return `exports something other than ${this.defaultExport}`;
100
+ }
101
+ }
102
+
103
+ export const CHECK_PACKAGE = "@sshkeda/check";
104
+
105
+ export class ConfigFileHoldsOtherStatement extends Schema.TaggedError<ConfigFileHoldsOtherStatement>()(
106
+ "ConfigFileHoldsOtherStatement",
107
+ { location: Schema.String, configImport: Schema.String, defaultExport: Schema.String },
108
+ ) {
109
+ public override get message() {
110
+ return `holds a statement other than ${this.configImport} and export default ${this.defaultExport}`;
111
+ }
112
+ }
113
+
114
+ export class ConfigFileHoldsSomethingElse extends Schema.TaggedError<ConfigFileHoldsSomethingElse>()(
115
+ "ConfigFileHoldsSomethingElse",
116
+ { file: Schema.String, configImport: Schema.String, defaultExport: Schema.String },
117
+ ) {
118
+ public get location() {
119
+ return this.file;
120
+ }
121
+ public override get message() {
122
+ return `holds something other than check's config`;
123
+ }
124
+ }
125
+
126
+ export class ConfigFileMissingImport extends Schema.TaggedError<ConfigFileMissingImport>()(
127
+ "ConfigFileMissingImport",
128
+ { file: Schema.String, configImport: Schema.String },
129
+ ) {
130
+ public get location() {
131
+ return this.file;
132
+ }
133
+ public override get message() {
134
+ return `has no ${this.configImport}`;
135
+ }
136
+ }
137
+
138
+ export class ConfigFileImportsFromOutsideCheck extends Schema.TaggedError<ConfigFileImportsFromOutsideCheck>()(
139
+ "ConfigFileImportsFromOutsideCheck",
140
+ {
141
+ location: Schema.String,
142
+ binding: Schema.String,
143
+ request: Schema.String,
144
+ resolvedFile: Schema.String,
145
+ },
146
+ ) {
147
+ public override get message() {
148
+ return `imports ${this.binding} from ${this.request}, which resolves to ${this.resolvedFile} instead of a file of ${CHECK_PACKAGE}`;
149
+ }
150
+ }
151
+
152
+ export class LintConfigArgumentNotLiteral extends Schema.TaggedError<LintConfigArgumentNotLiteral>()(
153
+ "LintConfigArgumentNotLiteral",
154
+ { location: Schema.String },
155
+ ) {
156
+ public override get message() {
157
+ return `passes lintConfig() something other than literals`;
158
+ }
159
+ }
160
+
161
+ export class LintConfigKeyRepeated extends Schema.TaggedError<LintConfigKeyRepeated>()(
162
+ "LintConfigKeyRepeated",
163
+ { location: Schema.String, key: Schema.String },
164
+ ) {
165
+ public override get message() {
166
+ return `names ${this.key} more than once in one object passed to lintConfig()`;
167
+ }
168
+ }
169
+
170
+ const CONFIG_FILE_VIOLATIONS = [
171
+ ConfigFileMissing,
172
+ ConfigFileUnparsable,
173
+ ConfigFileMissingDefaultExport,
174
+ ConfigFileExportsSomethingElse,
175
+ ConfigFileHoldsOtherStatement,
176
+ ConfigFileHoldsSomethingElse,
177
+ ConfigFileMissingImport,
178
+ ConfigFileImportsFromOutsideCheck,
179
+ ModuleRequestUnresolvable,
180
+ ] as const;
181
+
182
+ export const CONFIG_FILE_VIOLATION = Schema.Union(CONFIG_FILE_VIOLATIONS);
183
+
184
+ export const LINT_CONFIG_VIOLATION = Schema.Union([
185
+ MalformedGrant,
186
+ ...CONFIG_FILE_VIOLATIONS,
187
+ LintConfigArgumentNotLiteral,
188
+ LintConfigKeyRepeated,
189
+ ]);
190
+
191
+ export class LintConfigRefused extends Schema.TaggedError<LintConfigRefused>()(
192
+ "LintConfigRefused",
193
+ { violations: Schema.Array(LINT_CONFIG_VIOLATION) },
194
+ ) {
195
+ public override get message() {
196
+ return listedViolations(this.violations);
197
+ }
198
+ }
199
+
200
+ export class PackageManifestUnparsable extends Schema.TaggedError<PackageManifestUnparsable>()(
201
+ "PackageManifestUnparsable",
202
+ {
203
+ location: Schema.String,
204
+ reason: Schema.String,
205
+ },
206
+ ) {
207
+ public override get message() {
208
+ return `is not valid JSON: ${this.reason}`;
209
+ }
210
+ }
211
+
212
+ export class PackageManifestNotObject extends Schema.TaggedError<PackageManifestNotObject>()(
213
+ "PackageManifestNotObject",
214
+ {
215
+ location: Schema.String,
216
+ reason: Schema.String,
217
+ },
218
+ ) {
219
+ public override get message() {
220
+ return `does not hold a JSON object: ${this.reason}`;
221
+ }
222
+ }
223
+
224
+ export class PackageManifestUnreadable extends Schema.TaggedError<PackageManifestUnreadable>()(
225
+ "PackageManifestUnreadable",
226
+ {
227
+ location: Schema.String,
228
+ reason: Schema.String,
229
+ },
230
+ ) {
231
+ public override get message() {
232
+ return `cannot be read as a package.json whose name, if any, is a string: ${this.reason}`;
233
+ }
234
+ }
235
+
236
+ export class CompetingFormatterConfig extends Schema.TaggedError<CompetingFormatterConfig>()(
237
+ "CompetingFormatterConfig",
238
+ { location: Schema.String },
239
+ ) {
240
+ public override get message() {
241
+ return `competes with ${FORMAT_CONFIG_FILE}`;
242
+ }
243
+ }
244
+
245
+ export class PackagePrettierField extends Schema.TaggedError<PackagePrettierField>()(
246
+ "PackagePrettierField",
247
+ { location: Schema.String },
248
+ ) {
249
+ public override get message() {
250
+ return `has a "prettier" field, which competes with ${FORMAT_CONFIG_FILE}`;
251
+ }
252
+ }
253
+
254
+ export class FormatConfigRefused extends Schema.TaggedError<FormatConfigRefused>()(
255
+ "FormatConfigRefused",
256
+ {
257
+ violations: Schema.Array(CONFIG_FILE_VIOLATION),
258
+ },
259
+ ) {
260
+ public override get message() {
261
+ return listedViolations(this.violations);
262
+ }
263
+ }
264
+
265
+ export class FormatInputsRefused extends Schema.TaggedError<FormatInputsRefused>()(
266
+ "FormatInputsRefused",
267
+ {
268
+ violations: Schema.Array(
269
+ Schema.Union([
270
+ CompetingFormatterConfig,
271
+ PackagePrettierField,
272
+ PackageManifestUnparsable,
273
+ PackageManifestNotObject,
274
+ ]),
275
+ ),
276
+ },
277
+ ) {
278
+ public override get message() {
279
+ return listedViolations(this.violations);
280
+ }
281
+ }
282
+
283
+ export class SourceFileUnparsable extends Schema.TaggedError<SourceFileUnparsable>()(
284
+ "SourceFileUnparsable",
285
+ { file: Schema.String, reason: Schema.String },
286
+ ) {
287
+ public get location() {
288
+ return this.file;
289
+ }
290
+ public override get message() {
291
+ return `does not parse: ${this.reason}`;
292
+ }
293
+ }
294
+
295
+ export class PackageManifestFieldInvalid extends Schema.TaggedError<PackageManifestFieldInvalid>()(
296
+ "PackageManifestFieldInvalid",
297
+ { path: Schema.String, reason: Schema.String },
298
+ ) {
299
+ public get location() {
300
+ return this.path;
301
+ }
302
+ public override get message() {
303
+ return `has a field of an unexpected type: ${this.reason}`;
304
+ }
305
+ }
306
+
307
+ export class PackageNotInstalled extends Schema.TaggedError<PackageNotInstalled>()(
308
+ "PackageNotInstalled",
309
+ { packageName: Schema.String, packageDirectory: Schema.String, reason: Schema.String },
310
+ ) {
311
+ public override get message() {
312
+ return `${this.packageName} does not resolve from ${this.packageDirectory}: ${this.reason}`;
313
+ }
314
+ }
315
+
316
+ export class InstalledPackageHasNoBinary extends Schema.TaggedError<InstalledPackageHasNoBinary>()(
317
+ "InstalledPackageHasNoBinary",
318
+ { packageName: Schema.String, binaryName: Schema.String },
319
+ ) {
320
+ public override get message() {
321
+ return `${this.packageName} declares no ${this.binaryName} binary in its package.json bin field`;
322
+ }
323
+ }
324
+
325
+ export class ToolExited extends Schema.TaggedError<ToolExited>()("ToolExited", {
326
+ program: Schema.String,
327
+ command: Schema.String,
328
+ code: Schema.Int,
329
+ standardOutput: Schema.String,
330
+ standardError: Schema.String,
331
+ }) {
332
+ public override get message() {
333
+ return [`${this.program} exited with code ${this.code}`, this.standardError]
334
+ .filter((line) => line !== "")
335
+ .join("\n");
336
+ }
337
+ }
338
+
339
+ export class ToolStoppedBySignal extends Schema.TaggedError<ToolStoppedBySignal>()(
340
+ "ToolStoppedBySignal",
341
+ { program: Schema.String, command: Schema.String, signal: Schema.String },
342
+ ) {
343
+ public override get message() {
344
+ return `${this.program} was stopped by signal ${this.signal}`;
345
+ }
346
+ }
347
+
348
+ export class ToolReportedViolations extends Schema.TaggedError<ToolReportedViolations>()(
349
+ "ToolReportedViolations",
350
+ { program: Schema.String, command: Schema.String, code: Schema.Int, count: Schema.Int },
351
+ ) {
352
+ public override get message() {
353
+ return `${this.program} reported ${this.count} ${this.count === 1 ? "violation" : "violations"} and exited with code ${this.code}`;
354
+ }
355
+ }
356
+
357
+ export class ToolReportUndecodable extends Schema.TaggedError<ToolReportUndecodable>()(
358
+ "ToolReportUndecodable",
359
+ { program: Schema.String, reason: Schema.String, report: Schema.String },
360
+ ) {
361
+ public override get message() {
362
+ return [
363
+ `${this.program} printed a report that does not decode: ${this.reason}`,
364
+ this.report.replace(/\n+$/u, ""),
365
+ ]
366
+ .filter((line) => line !== "")
367
+ .join("\n");
368
+ }
369
+ }
370
+
371
+ export class TypeScriptProjectFileMissing extends Schema.TaggedError<TypeScriptProjectFileMissing>()(
372
+ "TypeScriptProjectFileMissing",
373
+ { projectFile: Schema.String },
374
+ ) {
375
+ public get location() {
376
+ return this.projectFile;
377
+ }
378
+ public override get message() {
379
+ return `does not exist`;
380
+ }
381
+ }
382
+
383
+ export const STRICT_OPTIONS = [
384
+ "strict",
385
+ "noImplicitAny",
386
+ "noImplicitThis",
387
+ "strictBindCallApply",
388
+ "strictBuiltinIteratorReturn",
389
+ "strictFunctionTypes",
390
+ "strictNullChecks",
391
+ "strictPropertyInitialization",
392
+ "useUnknownInCatchVariables",
393
+ ] as const;
394
+
395
+ export const REQUIRED_VALUES_OF_OPTIONS_OFF_BY_DEFAULT = {
396
+ noUncheckedIndexedAccess: true,
397
+ exactOptionalPropertyTypes: true,
398
+ allowImportingTsExtensions: true,
399
+ noCheck: false,
400
+ } as const;
401
+
402
+ export class LooseCompilerOption extends Schema.TaggedError<LooseCompilerOption>()(
403
+ "LooseCompilerOption",
404
+ {
405
+ projectFile: Schema.String,
406
+ option: Schema.Literals([
407
+ ...STRICT_OPTIONS,
408
+ ...Record.keys(REQUIRED_VALUES_OF_OPTIONS_OFF_BY_DEFAULT),
409
+ ]),
410
+ resolvedValue: Schema.Boolean,
411
+ },
412
+ ) {
413
+ public get location() {
414
+ return this.projectFile;
415
+ }
416
+ public override get message() {
417
+ return `${this.option} resolves to ${this.resolvedValue}`;
418
+ }
419
+ }
420
+
421
+ export class ProjectReferencesUndecodable extends Schema.TaggedError<ProjectReferencesUndecodable>()(
422
+ "ProjectReferencesUndecodable",
423
+ { projectFile: Schema.String, reason: Schema.String },
424
+ ) {
425
+ public get location() {
426
+ return this.projectFile;
427
+ }
428
+ public override get message() {
429
+ return `references do not decode: ${this.reason}`;
430
+ }
431
+ }
432
+
433
+ export class TypeScriptConfigUnparsable extends Schema.TaggedError<TypeScriptConfigUnparsable>()(
434
+ "TypeScriptConfigUnparsable",
435
+ { projectFile: Schema.String, reason: Schema.String },
436
+ ) {
437
+ public get location() {
438
+ return this.projectFile;
439
+ }
440
+ public override get message() {
441
+ return `does not parse as JSONC: ${this.reason}`;
442
+ }
443
+ }
444
+
445
+ export class TypeScriptConfigViolations extends Schema.TaggedError<TypeScriptConfigViolations>()(
446
+ "TypeScriptConfigViolations",
447
+ {
448
+ violations: Schema.Array(
449
+ Schema.Union([
450
+ TypeScriptProjectFileMissing,
451
+ TypeScriptConfigUnparsable,
452
+ ProjectReferencesUndecodable,
453
+ LooseCompilerOption,
454
+ ]),
455
+ ),
456
+ },
457
+ ) {
458
+ public override get message() {
459
+ return listedViolations(this.violations);
460
+ }
461
+ }
462
+
463
+ export class PackageExportsMixKeys extends Schema.TaggedError<PackageExportsMixKeys>()(
464
+ "PackageExportsMixKeys",
465
+ { path: Schema.String },
466
+ ) {
467
+ public get location() {
468
+ return this.path;
469
+ }
470
+ public override get message() {
471
+ return "has an exports object that mixes subpath keys starting with . and condition keys, which Node rejects";
472
+ }
473
+ }
474
+
475
+ export class BunConfigInvalid extends Schema.TaggedError<BunConfigInvalid>()("BunConfigInvalid", {
476
+ path: Schema.String,
477
+ reason: Schema.String,
478
+ }) {
479
+ public get location() {
480
+ return this.path;
481
+ }
482
+ public override get message() {
483
+ return `is not a bunfig.toml check can read: ${this.reason}`;
484
+ }
485
+ }