@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,14 @@
1
+ import { Effect, FileSystem, Predicate } from "effect";
2
+
3
+ const NOT_A_SYMBOLIC_LINK = "EINVAL";
4
+
5
+ export const isSymbolicLink = (file: string) =>
6
+ FileSystem.FileSystem.use((fileSystem) => fileSystem.readLink(file)).pipe(
7
+ Effect.as(true),
8
+ Effect.catchTag("PlatformError", (error) => {
9
+ const isNotASymbolicLink =
10
+ Predicate.hasProperty(error.reason.cause, "code") &&
11
+ error.reason.cause.code === NOT_A_SYMBOLIC_LINK;
12
+ return isNotASymbolicLink ? Effect.succeed(false) : Effect.fail(error);
13
+ }),
14
+ );
@@ -0,0 +1,12 @@
1
+ import { Schema } from "effect";
2
+
3
+ export class UnformattedFile extends Schema.TaggedError<UnformattedFile>()("UnformattedFile", {
4
+ file: Schema.String,
5
+ }) {
6
+ public get location() {
7
+ return this.file;
8
+ }
9
+ public override get message() {
10
+ return `is not formatted`;
11
+ }
12
+ }
@@ -0,0 +1 @@
1
+ export { findIndexReExportViolations } from "./internal/find-index-re-export-violations.ts";
@@ -0,0 +1,353 @@
1
+ import { isBuiltin } from "node:module";
2
+
3
+ import { Effect, FileSystem, Option, Path, Result } from "effect";
4
+ import { parseSync } from "oxc-parser";
5
+ import type { ResolveResult } from "oxc-resolver";
6
+
7
+ import { nodeBuiltinNameOf } from "../../../../../shared/lint-rule-messages-and-patterns.ts";
8
+ import {
9
+ directoryHolding,
10
+ fileNameOf,
11
+ INTERNAL_DIRECTORY_NAME,
12
+ isEntryFileName,
13
+ isWithin,
14
+ LAYOUT_DIRECTORY_NAMES,
15
+ SHARED_DIRECTORY_NAME,
16
+ } from "../../../../../shared/match-file-names-and-path-prefixes.ts";
17
+ import { lineNumberAt } from "../../../shared/count-the-line-of-an-offset.ts";
18
+ import { moduleResolverFor } from "../../../shared/create-the-module-resolver.ts";
19
+ import {
20
+ directoriesAFailedResolutionReads,
21
+ enclosingPackageManifestsOf,
22
+ resolutionNamesNoFile,
23
+ } from "../../../shared/find-named-package-manifests.ts";
24
+ import { ownedFilesAmong } from "../../../shared/list-owned-files.ts";
25
+ import { ModuleRequestUnresolvable } from "../../../shared/project-config-and-tool-errors.ts";
26
+ import type { PackageManifestUnreadable } from "../../../shared/project-config-and-tool-errors.ts";
27
+ import { checkedSourceFiles } from "../../../shared/query-the-typescript-project.ts";
28
+ import { namedPackageManifestAt } from "../../../shared/read-named-package-manifests.ts";
29
+ import { IndexReExportRefused, IndexReExportsRefused } from "./index-re-export-errors.ts";
30
+
31
+ const OWN_LAYOUT_DIRECTORIES = `${INTERNAL_DIRECTORY_NAME}/ and ${SHARED_DIRECTORY_NAME}/`;
32
+ const RE_EXPORTABLE_EXTENSIONS = ".ts or .tsx";
33
+ const RE_EXPORTABLE_FILE = /^.+\.tsx?$/u;
34
+ const INDEX_FILE = /^index(?:\.d)?\.tsx?$/u;
35
+ const NAMESPACE_INDEX = /^\.\/lib\/[^/.][^/]*\/index\.ts$/u;
36
+ const INSTALLED_PACKAGES_DIRECTORY = "node_modules";
37
+ const FILE_SYSTEM_ROOT = "/";
38
+ const GIT_DIRECTORY_NAME = ".git";
39
+ const DECLARATION_FILE_EXTENSION = ".d.ts";
40
+ const BUN_BUILT_IN_MODULES: ReadonlySet<string> = new Set([
41
+ "bun",
42
+ "bun:ffi",
43
+ "bun:jsc",
44
+ "bun:sqlite",
45
+ "bun:test",
46
+ ]);
47
+
48
+ const isBuiltInModule = (specifier: string) =>
49
+ isBuiltin(nodeBuiltinNameOf(specifier)) || BUN_BUILT_IN_MODULES.has(specifier);
50
+
51
+ const FACTS = {
52
+ fromPackage: () => "re-exports a package or built-in",
53
+ fromOutsideLayout: () => `re-exports a file outside this index's own ${OWN_LAYOUT_DIRECTORIES}`,
54
+ fromLayoutSubdirectory: (directory: string) =>
55
+ `re-exports a file in a subdirectory of ${directory}/`,
56
+ fromOtherExtension: () => `re-exports a file without a ${RE_EXPORTABLE_EXTENSIONS} extension`,
57
+ fromLayoutIndex: () => "re-exports an index file",
58
+ fromDeclarationFile: () => "re-exports a declaration file",
59
+ badManifest: (manifest: string, reason: string) =>
60
+ `cannot be judged, since ${manifest} cannot be read as a package.json: ${reason}`,
61
+ unresolvable: (reason: string) => `cannot be judged, since the resolver failed: ${reason}`,
62
+ } as const;
63
+
64
+ const relativePathFrom = (directory: string, file: string) => {
65
+ const directorySegments = directory.split("/");
66
+ const fileSegments = file.split("/");
67
+ const differingSegment = directorySegments.findIndex(
68
+ (segment, at) => segment !== fileSegments[at],
69
+ );
70
+ const firstOwnSegment = differingSegment === -1 ? directorySegments.length : differingSegment;
71
+ const parents = directorySegments.slice(firstOwnSegment).map(() => "..");
72
+ const start = parents.length === 0 ? "." : parents.join("/");
73
+ return [start, ...fileSegments.slice(firstOwnSegment)].join("/");
74
+ };
75
+
76
+ const repositoryRootHolding = Effect.fn("repositoryRootHolding")(function* (directory: string) {
77
+ const fileSystem = yield* FileSystem.FileSystem;
78
+ for (const manifestFile of enclosingPackageManifestsOf(directory, FILE_SYSTEM_ROOT)) {
79
+ const enclosing = directoryHolding(manifestFile);
80
+ const holdsGit = yield* fileSystem
81
+ .exists(`${enclosing}/${GIT_DIRECTORY_NAME}`)
82
+ .pipe(Effect.catchTag("PlatformError", () => Effect.succeed(false)));
83
+ if (holdsGit) {
84
+ return enclosing;
85
+ }
86
+ }
87
+ return FILE_SYSTEM_ROOT;
88
+ });
89
+
90
+ const namedPackageEnclosing = Effect.fn("namedPackageEnclosing")(function* (directory: string) {
91
+ for (const manifestFile of enclosingPackageManifestsOf(
92
+ directory,
93
+ yield* repositoryRootHolding(directory),
94
+ )) {
95
+ const named = yield* namedPackageManifestAt(manifestFile);
96
+ if (Option.isSome(named)) {
97
+ return Option.some(manifestFile);
98
+ }
99
+ }
100
+ return Option.none<string>();
101
+ });
102
+
103
+ const namedPackageOrItsFailure = (directory: string) =>
104
+ namedPackageEnclosing(directory).pipe(
105
+ Effect.map((named) => Result.succeed<Option.Option<string>>(named)),
106
+ Effect.catchTag("PackageManifestUnreadable", (failure) =>
107
+ Effect.succeed(Result.fail<PackageManifestUnreadable>(failure)),
108
+ ),
109
+ );
110
+
111
+ const realIndexOf = Effect.fn("realIndexOf")(function* (indexFile: string) {
112
+ const fileSystem = yield* FileSystem.FileSystem;
113
+ const file = yield* fileSystem.realPath(indexFile);
114
+ const directory = directoryHolding(file);
115
+ return { file, directory, namedPackage: yield* namedPackageOrItsFailure(directory) };
116
+ });
117
+
118
+ const badManifestOf = (directory: string, failure: PackageManifestUnreadable) =>
119
+ ({
120
+ judgment: FACTS.badManifest(relativePathFrom(directory, failure.location), failure.reason),
121
+ }) as const;
122
+
123
+ const resolvedRequest = (importingFile: string, request: string) =>
124
+ Effect.tryPromise({
125
+ try: () => moduleResolverFor([]).resolveFileAsync(importingFile, request),
126
+ catch: (cause) =>
127
+ new ModuleRequestUnresolvable({ request, importingFile, reason: String(cause) }),
128
+ });
129
+
130
+ const unresolvedFactOf = Effect.fn("unresolvedFactOf")(function* (
131
+ index: Effect.Success<ReturnType<typeof realIndexOf>>,
132
+ request: string,
133
+ resolved: ResolveResult,
134
+ ) {
135
+ for (const directory of directoriesAFailedResolutionReads({
136
+ importingFile: index.file,
137
+ request,
138
+ })) {
139
+ const named = yield* namedPackageOrItsFailure(directory);
140
+ if (Result.isFailure(named)) {
141
+ return badManifestOf(index.directory, named.failure);
142
+ }
143
+ }
144
+ const reason = resolved.error ?? "returned no file and no error";
145
+ return resolutionNamesNoFile(resolved, reason)
146
+ ? undefined
147
+ : ({ judgment: FACTS.unresolvable(reason) } as const);
148
+ });
149
+
150
+ const resolvedFactOf = Effect.fn("resolvedFactOf")(function* (
151
+ index: Effect.Success<ReturnType<typeof realIndexOf>>,
152
+ source: string,
153
+ ) {
154
+ if (isBuiltInModule(source)) {
155
+ return { judgment: FACTS.fromPackage() } as const;
156
+ }
157
+ const resolved = yield* resolvedRequest(index.file, source);
158
+ const file = resolved.path;
159
+ if (file === undefined) {
160
+ return yield* unresolvedFactOf(index, source, resolved);
161
+ }
162
+ if (Result.isFailure(index.namedPackage)) {
163
+ return badManifestOf(index.directory, index.namedPackage.failure);
164
+ }
165
+ const filePackage = yield* namedPackageOrItsFailure(directoryHolding(file));
166
+ if (Result.isFailure(filePackage)) {
167
+ return badManifestOf(index.directory, filePackage.failure);
168
+ }
169
+ const indexSegments = index.directory.split("/");
170
+ const fileSegments = file.split("/");
171
+ const firstOwnSegment = fileSegments.findIndex((segment, at) => segment !== indexSegments[at]);
172
+ const isFromAPackage =
173
+ fileSegments.slice(firstOwnSegment).includes(INSTALLED_PACKAGES_DIRECTORY) ||
174
+ Option.getOrNull(filePackage.success) !== Option.getOrNull(index.namedPackage.success);
175
+ if (isFromAPackage) {
176
+ return { judgment: FACTS.fromPackage() } as const;
177
+ }
178
+ const [layoutDirectory, fileName, ...deeper] = isWithin(file, index.directory)
179
+ ? fileSegments.slice(indexSegments.length)
180
+ : [];
181
+ const isInOwnLayoutDirectory =
182
+ layoutDirectory !== undefined &&
183
+ LAYOUT_DIRECTORY_NAMES.has(layoutDirectory) &&
184
+ fileName !== undefined;
185
+ if (!isInOwnLayoutDirectory) {
186
+ return { judgment: FACTS.fromOutsideLayout() } as const;
187
+ }
188
+ if (deeper.length > 0) {
189
+ return { judgment: FACTS.fromLayoutSubdirectory(layoutDirectory) } as const;
190
+ }
191
+ if (INDEX_FILE.test(fileName)) {
192
+ return { judgment: FACTS.fromLayoutIndex() } as const;
193
+ }
194
+ if (fileName.endsWith(DECLARATION_FILE_EXTENSION)) {
195
+ return { judgment: FACTS.fromDeclarationFile() } as const;
196
+ }
197
+ return RE_EXPORTABLE_FILE.test(fileName)
198
+ ? ({ allowed: true } as const)
199
+ : ({ judgment: FACTS.fromOtherExtension() } as const);
200
+ });
201
+
202
+ const exportedName = (name: {
203
+ readonly type: string;
204
+ readonly name?: string;
205
+ readonly value?: string;
206
+ }) => name.name ?? name.value;
207
+
208
+ const exportsOwnInternalNames = Effect.fn("exportsOwnInternalNames")(function* (
209
+ index: Effect.Success<ReturnType<typeof realIndexOf>>,
210
+ ) {
211
+ const fileSystem = yield* FileSystem.FileSystem;
212
+ const parsed = parseSync(index.file, yield* fileSystem.readFileString(index.file));
213
+ const hasStatements = parsed.errors.length === 0 && parsed.program.body.length > 0;
214
+ if (!hasStatements) {
215
+ return false;
216
+ }
217
+ for (const statement of parsed.program.body) {
218
+ if (statement.type !== "ExportNamedDeclaration") {
219
+ return false;
220
+ }
221
+ const { source } = statement;
222
+ const isDirectReExport = source !== null && statement.declaration === null;
223
+ if (!isDirectReExport) {
224
+ return false;
225
+ }
226
+ const fact = yield* resolvedFactOf(index, source.value);
227
+ const exportsUnrenamedNames =
228
+ statement.specifiers.length > 0 &&
229
+ statement.specifiers.every(
230
+ (specifier) => exportedName(specifier.local) === exportedName(specifier.exported),
231
+ );
232
+ const isOwnInternalReExport =
233
+ fact !== undefined &&
234
+ "allowed" in fact &&
235
+ exportsUnrenamedNames &&
236
+ source.value.startsWith(`./${INTERNAL_DIRECTORY_NAME}/`);
237
+ if (!isOwnInternalReExport) {
238
+ return false;
239
+ }
240
+ }
241
+ return true;
242
+ });
243
+
244
+ const exportsChildModuleNamespace = Effect.fn("exportsChildModuleNamespace")(function* (
245
+ index: Effect.Success<ReturnType<typeof realIndexOf>>,
246
+ source: string,
247
+ ) {
248
+ if (!NAMESPACE_INDEX.test(source)) {
249
+ return false;
250
+ }
251
+ const resolved = (yield* resolvedRequest(index.file, source)).path;
252
+ if (resolved === undefined) {
253
+ return false;
254
+ }
255
+ const child = yield* realIndexOf(resolved);
256
+ const isOwnChildIndex = child.file === `${index.directory}/${source.slice("./".length)}`;
257
+ const isSamePackage =
258
+ Result.isSuccess(index.namedPackage) &&
259
+ Result.isSuccess(child.namedPackage) &&
260
+ Option.getOrNull(index.namedPackage.success) === Option.getOrNull(child.namedPackage.success);
261
+ const isOwnChildModule = isOwnChildIndex && isSamePackage;
262
+ return isOwnChildModule && (yield* exportsOwnInternalNames(child));
263
+ });
264
+
265
+ export const indexReExportJudgmentsOf = Effect.fn("indexReExportJudgmentsOf")(function* (
266
+ indexFile: string,
267
+ text: string,
268
+ ) {
269
+ moduleResolverFor([]).clearCache();
270
+ const { program } = parseSync(indexFile, text);
271
+ const judgments: { readonly start: number; readonly judgment: string }[] = [];
272
+ const exportsFromAModule = program.body.some(
273
+ (statement) =>
274
+ (statement.type === "ExportNamedDeclaration" && statement.source !== null) ||
275
+ (statement.type === "ExportAllDeclaration" && statement.exported !== null),
276
+ );
277
+ if (!exportsFromAModule) {
278
+ return judgments;
279
+ }
280
+ const index = yield* realIndexOf(indexFile);
281
+ for (const statement of program.body) {
282
+ if (statement.type === "ExportAllDeclaration") {
283
+ const source = statement.source.value;
284
+ const isNamespaceOfAChildModule =
285
+ statement.exported === null || (yield* exportsChildModuleNamespace(index, source));
286
+ if (!isNamespaceOfAChildModule) {
287
+ judgments.push({
288
+ start: statement.start,
289
+ judgment: `export * from ${source} re-exports another module`,
290
+ });
291
+ }
292
+ continue;
293
+ }
294
+ const isExportFrom = statement.type === "ExportNamedDeclaration" && statement.source !== null;
295
+ if (!isExportFrom) {
296
+ continue;
297
+ }
298
+ const source = statement.source?.value ?? "";
299
+ const fact = yield* resolvedFactOf(index, source);
300
+ if (fact === undefined) {
301
+ continue;
302
+ }
303
+ if ("judgment" in fact) {
304
+ judgments.push({
305
+ start: statement.start,
306
+ judgment: `export from ${source} ${fact.judgment}`,
307
+ });
308
+ continue;
309
+ }
310
+ for (const specifier of statement.specifiers) {
311
+ const local = exportedName(specifier.local);
312
+ const exported = exportedName(specifier.exported);
313
+ if (local !== exported) {
314
+ judgments.push({
315
+ start: specifier.start,
316
+ judgment: `export from ${source} renames ${text.slice(specifier.local.start, specifier.local.end)} to ${text.slice(specifier.exported.start, specifier.exported.end)}`,
317
+ });
318
+ }
319
+ }
320
+ }
321
+ return judgments;
322
+ });
323
+
324
+ export const findIndexReExportViolations = (projectFile: string) =>
325
+ Effect.gen(function* () {
326
+ const fileSystem = yield* FileSystem.FileSystem;
327
+ const path = yield* Path.Path;
328
+ const packageDirectory = path.dirname(projectFile);
329
+ const indexFiles = (yield* ownedFilesAmong(
330
+ packageDirectory,
331
+ yield* checkedSourceFiles(projectFile),
332
+ )).filter((file) => isEntryFileName(fileNameOf(file)));
333
+ const violations = yield* Effect.forEach(indexFiles, (displayName) =>
334
+ Effect.gen(function* () {
335
+ const text = yield* fileSystem.readFileString(path.join(packageDirectory, displayName));
336
+ const judgments = yield* indexReExportJudgmentsOf(
337
+ path.join(packageDirectory, displayName),
338
+ text,
339
+ );
340
+ return judgments.map(
341
+ ({ start, judgment }) =>
342
+ new IndexReExportRefused({
343
+ location: `${displayName}:${lineNumberAt(text, start)}`,
344
+ judgment,
345
+ }),
346
+ );
347
+ }),
348
+ );
349
+ const found = violations.flat();
350
+ if (found.length > 0) {
351
+ return yield* new IndexReExportsRefused({ violations: found });
352
+ }
353
+ });
@@ -0,0 +1,21 @@
1
+ import { Schema } from "effect";
2
+
3
+ import { listedViolations } from "../../../../../shared/format-reported-failures.ts";
4
+
5
+ export class IndexReExportRefused extends Schema.TaggedError<IndexReExportRefused>()(
6
+ "IndexReExportRefused",
7
+ { location: Schema.String, judgment: Schema.String },
8
+ ) {
9
+ public override get message() {
10
+ return this.judgment;
11
+ }
12
+ }
13
+
14
+ export class IndexReExportsRefused extends Schema.TaggedError<IndexReExportsRefused>()(
15
+ "IndexReExportsRefused",
16
+ { violations: Schema.Array(IndexReExportRefused) },
17
+ ) {
18
+ public override get message() {
19
+ return listedViolations(this.violations);
20
+ }
21
+ }
@@ -0,0 +1,15 @@
1
+ import { Task } from "@sshkeda/task";
2
+ import { Effect } from "effect";
3
+
4
+ import { inEachPackage } from "../../shared/check-each-nested-package.ts";
5
+ import { lintConfigFile } from "../../shared/declare-lint-config-task.ts";
6
+ import { typeScriptConfig } from "../../shared/declare-typescript-config-task.ts";
7
+ import { checkLintRulesWithOxlintIn } from "./internal/check-lint-rules-with-oxlint.ts";
8
+
9
+ export const oxlint = Task.make(
10
+ "oxlint",
11
+ Effect.andThen(
12
+ Task.all([typeScriptConfig, lintConfigFile]),
13
+ inEachPackage("oxlint", ".", checkLintRulesWithOxlintIn),
14
+ ),
15
+ );
@@ -0,0 +1,123 @@
1
+ import { ReportedErrors } from "@sshkeda/task/errors";
2
+ import { Array as Arrays, Effect, Path } from "effect";
3
+
4
+ import { FORMAT_CONFIG_FILE, LINT_CONFIG_FILE } from "../../../../../shared/config-file-names.ts";
5
+ import { installedBinary } from "../../../shared/find-installed-package-binaries.ts";
6
+ import { lintedFiles } from "../../../shared/list-linted-files.ts";
7
+ import { isFormatConfigTextRefusedIn } from "../../../shared/parse-config-files-that-import-from-check.ts";
8
+ import {
9
+ quietToolFailure,
10
+ quietViolations,
11
+ } from "../../../shared/print-failures-and-keep-detail-in-the-trace.ts";
12
+ import { ToolExited } from "../../../shared/project-config-and-tool-errors.ts";
13
+ import { TYPESCRIPT_PROJECT_FILE } from "../../../shared/query-the-typescript-project.ts";
14
+ import {
15
+ argumentsInRunsOfBoundedSize,
16
+ mergedExit,
17
+ runTool,
18
+ } from "../../../shared/run-tools-and-decode-their-reports.ts";
19
+ import { checkUnsafeEnumAssignmentsIn } from "./check-unsafe-enum-assignments.ts";
20
+ import { tsgolintExecutable } from "./find-tsgolint-executable.ts";
21
+ import {
22
+ OXLINT_TASK,
23
+ oxlintReport,
24
+ lintReportWithOriginalFileNames,
25
+ } from "./read-oxlint-json-report.ts";
26
+
27
+ const OXLINT = "oxlint";
28
+
29
+ const oxlintBinary = Effect.gen(function* () {
30
+ const path = yield* Path.Path;
31
+ const packageDirectory = yield* path.fromFileUrl(new URL(".", import.meta.url));
32
+ return yield* installedBinary(packageDirectory, "oxlint", "oxlint");
33
+ });
34
+
35
+ const OXLINT_ARGUMENTS = [
36
+ "--config",
37
+ LINT_CONFIG_FILE,
38
+ "--disable-nested-config",
39
+ "--no-ignore",
40
+ "--tsconfig",
41
+ TYPESCRIPT_PROJECT_FILE,
42
+ "--format",
43
+ "json",
44
+ "--",
45
+ ] as const;
46
+
47
+ const exitsOfOxlintOn = (directory: string) => (files: readonly string[]) =>
48
+ Effect.gen(function* () {
49
+ const binary = yield* oxlintBinary;
50
+ const backend = yield* tsgolintExecutable;
51
+ return yield* runTool(
52
+ OXLINT,
53
+ process.execPath,
54
+ [binary, ...OXLINT_ARGUMENTS, ...files],
55
+ directory,
56
+ { OXLINT_TSGOLINT_PATH: backend },
57
+ );
58
+ }).pipe(
59
+ Effect.as([]),
60
+ Effect.catchTag("ToolExited", (exited) =>
61
+ lintReportWithOriginalFileNames(OXLINT, exited.standardOutput, files).pipe(
62
+ Effect.map((standardOutput) => [
63
+ new ToolExited({
64
+ program: exited.program,
65
+ command: exited.command,
66
+ code: exited.code,
67
+ standardError: exited.standardError,
68
+ standardOutput,
69
+ }),
70
+ ]),
71
+ ),
72
+ ),
73
+ );
74
+
75
+ const filesToLintIn = (directory: string) =>
76
+ Effect.gen(function* () {
77
+ const path = yield* Path.Path;
78
+ const files = yield* lintedFiles(path.join(directory, TYPESCRIPT_PROJECT_FILE));
79
+ const isFormatConfigRefused = yield* isFormatConfigTextRefusedIn(directory);
80
+ return files.filter((file) => !isFormatConfigRefused || file !== FORMAT_CONFIG_FILE);
81
+ }).pipe(quietViolations(OXLINT_TASK));
82
+
83
+ const checkLintRulesWithOxlintOn = (directory: string, files: readonly string[]) =>
84
+ Effect.gen(function* () {
85
+ const exits = yield* Effect.forEach(
86
+ [
87
+ ...argumentsInRunsOfBoundedSize(files.filter((file) => !file.includes("\\"))),
88
+ ...files.filter((file) => file.includes("\\")).map((file) => [file]),
89
+ ],
90
+ exitsOfOxlintOn(directory),
91
+ ).pipe(quietViolations(OXLINT_TASK));
92
+ const flatExits = exits.flat();
93
+ if (Arrays.isReadonlyArrayNonEmpty(flatExits)) {
94
+ return yield* Effect.fail(mergedExit(flatExits)).pipe(
95
+ quietToolFailure(OXLINT_TASK, (exited) =>
96
+ oxlintReport(exited.program, ...flatExits.map(({ standardOutput }) => standardOutput)),
97
+ ),
98
+ );
99
+ }
100
+ });
101
+
102
+ const reportedErrorsOf = <Requirements>(check: Effect.Effect<void, ReportedErrors, Requirements>) =>
103
+ check.pipe(
104
+ Effect.as([]),
105
+ Effect.catchTag("ReportedErrors", (reported) => Effect.succeed(reported.reportedErrors)),
106
+ );
107
+
108
+ export const checkLintRulesWithOxlintIn = (directory: string) =>
109
+ Effect.gen(function* () {
110
+ const files = yield* filesToLintIn(directory);
111
+ const reportedErrors = yield* Effect.all([
112
+ reportedErrorsOf(checkLintRulesWithOxlintOn(directory, files)),
113
+ reportedErrorsOf(
114
+ checkUnsafeEnumAssignmentsIn(directory, files).pipe(
115
+ Effect.withSpan("unsafe-enum-assignments"),
116
+ ),
117
+ ),
118
+ ]);
119
+ const allReportedErrors = reportedErrors.flat();
120
+ if (Arrays.isReadonlyArrayNonEmpty(allReportedErrors)) {
121
+ return yield* new ReportedErrors({ reportedErrors: allReportedErrors });
122
+ }
123
+ });