@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.
- package/LICENSE +21 -0
- package/README.md +156 -2
- package/docs/how-to-make-check-pass.md +71 -0
- package/package.json +51 -4
- package/src/index.ts +8 -0
- package/src/internal/ban-abbreviated-words-in-declared-names.ts +165 -0
- package/src/internal/ban-checked-members-outside-calls.ts +151 -0
- package/src/internal/ban-comments.ts +23 -0
- package/src/internal/ban-comparing-or-switching-on-tag.ts +114 -0
- package/src/internal/ban-deadlines-inside-tests.ts +41 -0
- package/src/internal/ban-declared-values.ts +70 -0
- package/src/internal/ban-dropped-failures-detached-fibers-sleeps-and-untraced-functions.ts +67 -0
- package/src/internal/ban-failures-collected-as-results.ts +57 -0
- package/src/internal/ban-fallbacks-of-named-recoveries.ts +118 -0
- package/src/internal/ban-function-overloads.ts +107 -0
- package/src/internal/ban-global-error-in-failure-types.ts +146 -0
- package/src/internal/ban-instanceof-in-effect-recovery-callbacks.ts +63 -0
- package/src/internal/ban-let-and-effect-mutable-ref.ts +79 -0
- package/src/internal/ban-logic-in-index-files.ts +178 -0
- package/src/internal/ban-namespaces-used-without-a-member.ts +176 -0
- package/src/internal/ban-node-builtins-that-effect-replaces.ts +42 -0
- package/src/internal/ban-parsing-outside-data-without-a-schema.ts +299 -0
- package/src/internal/ban-re-exports.ts +172 -0
- package/src/internal/ban-reading-the-clock-and-sleeping-outside-effect.ts +239 -0
- package/src/internal/ban-retired-words-in-names.ts +49 -0
- package/src/internal/ban-scanning-directories-with-bun-glob.ts +79 -0
- package/src/internal/ban-shebang-lines.ts +26 -0
- package/src/internal/ban-timer-globals-and-the-global-object.ts +34 -0
- package/src/internal/ban-timer-schedules-without-deadlines.ts +240 -0
- package/src/internal/ban-type-and-interface-declarations.ts +48 -0
- package/src/internal/ban-type-predicates.ts +82 -0
- package/src/internal/ban-unknown-in-function-signatures.ts +143 -0
- package/src/internal/ban-vague-error-class-names.ts +28 -0
- package/src/internal/ban-vague-file-names.ts +51 -0
- package/src/internal/ban-what-a-file-is-not-granted.ts +512 -0
- package/src/internal/ban-while-do-while-and-for-loops.ts +27 -0
- package/src/internal/confine-service-declarations-to-granted-files.ts +116 -0
- package/src/internal/confine-the-stdio-service-to-terminal-output.ts +190 -0
- package/src/internal/define-the-lint-plugin-and-configs.ts +361 -0
- package/src/internal/describe-and-decode-rule-options.ts +22 -0
- package/src/internal/keep-assertions-in-the-test-home-and-ban-test-runners.ts +128 -0
- package/src/internal/keep-effect-testing-helpers-in-test-files.ts +157 -0
- package/src/internal/match-banned-modules-and-globals.ts +71 -0
- package/src/internal/match-effect-service-factories.ts +20 -0
- package/src/internal/require-a-named-const-for-compound-conditions.ts +44 -0
- package/src/internal/require-capital-snake-case-and-as-const-on-literal-constants.ts +141 -0
- package/src/internal/require-service-keys-to-end-with-their-class-name.ts +64 -0
- package/src/internal/resolve-what-an-expression-imports.ts +295 -0
- package/src/internal/sort-type-constituents.ts +82 -0
- package/src/internal/split-names-into-words.ts +12 -0
- package/src/internal/visit-every-declared-name.ts +264 -0
- package/src/lib/tasks/index.ts +1 -0
- package/src/lib/tasks/internal/declare-the-check-task.ts +29 -0
- package/src/lib/tasks/internal/declare-the-checker-queries-task.ts +41 -0
- package/src/lib/tasks/internal/declare-the-typed-checks-task.ts +25 -0
- package/src/lib/tasks/internal/run-checks-over-one-typescript-project.ts +68 -0
- package/src/lib/tasks/lib/check-effect-diagnostics-with-effect-tsgo/index.ts +15 -0
- package/src/lib/tasks/lib/check-effect-diagnostics-with-effect-tsgo/internal/check-effect-diagnostics-with-effect-tsgo.ts +211 -0
- package/src/lib/tasks/lib/check-effect-diagnostics-with-effect-tsgo/internal/read-effect-tsgo-json-report.ts +39 -0
- package/src/lib/tasks/lib/check-import-boundaries/index.ts +1 -0
- package/src/lib/tasks/lib/check-import-boundaries/internal/find-import-boundary-violations.ts +415 -0
- package/src/lib/tasks/lib/check-import-boundaries/internal/find-subpath-import-targets.ts +117 -0
- package/src/lib/tasks/lib/check-import-boundaries/internal/find-what-hides-an-import.ts +65 -0
- package/src/lib/tasks/lib/check-import-boundaries/internal/import-boundary-errors.ts +176 -0
- package/src/lib/tasks/lib/check-uses-by-their-declarations/index.ts +1 -0
- package/src/lib/tasks/lib/check-uses-by-their-declarations/internal/declared-use-errors.ts +32 -0
- package/src/lib/tasks/lib/check-uses-by-their-declarations/internal/find-declared-use-violations.ts +38 -0
- package/src/lib/tasks/lib/check-uses-by-their-declarations/internal/find-sync-calls.ts +23 -0
- package/src/lib/tasks/lib/check-uses-by-their-declarations/internal/find-type-only-schemas.ts +375 -0
- package/src/lib/tasks/lib/confine-layer-provides-to-program-starts/index.ts +1 -0
- package/src/lib/tasks/lib/confine-layer-provides-to-program-starts/internal/find-layer-provides-outside-program-starts.ts +648 -0
- package/src/lib/tasks/lib/confine-layer-provides-to-program-starts/internal/layer-provide-errors.ts +27 -0
- package/src/lib/tasks/lib/confine-layer-provides-to-program-starts/internal/resolve-imported-package-apis.ts +262 -0
- package/src/lib/tasks/lib/confine-stdio-to-granted-files/index.ts +1 -0
- package/src/lib/tasks/lib/confine-stdio-to-granted-files/internal/find-ungranted-stdio-uses.ts +219 -0
- package/src/lib/tasks/lib/confine-stdio-to-granted-files/internal/stdio-use-errors.ts +31 -0
- package/src/lib/tasks/lib/detect-inferrable-annotations/index.ts +1 -0
- package/src/lib/tasks/lib/detect-inferrable-annotations/internal/find-inferrable-annotations.ts +357 -0
- package/src/lib/tasks/lib/detect-inferrable-annotations/internal/inferrable-annotation-errors.ts +33 -0
- package/src/lib/tasks/lib/detect-repeated-service-yields/index.ts +1 -0
- package/src/lib/tasks/lib/detect-repeated-service-yields/internal/find-repeated-service-yields.ts +162 -0
- package/src/lib/tasks/lib/detect-repeated-service-yields/internal/repeated-service-yield-errors.ts +25 -0
- package/src/lib/tasks/lib/enforce-file-layout/index.ts +5 -0
- package/src/lib/tasks/lib/enforce-file-layout/internal/check-the-layout-of-each-package.ts +9 -0
- package/src/lib/tasks/lib/enforce-file-layout/internal/file-layout-errors.ts +417 -0
- package/src/lib/tasks/lib/enforce-file-layout/internal/find-export-path-mismatches.ts +83 -0
- package/src/lib/tasks/lib/enforce-file-layout/internal/find-file-layout-violations.ts +827 -0
- package/src/lib/tasks/lib/enforce-file-layout/internal/find-module-layout-violations.ts +82 -0
- package/src/lib/tasks/lib/enforce-file-layout/internal/resolve-task-imports.ts +178 -0
- package/src/lib/tasks/lib/enforce-file-types/index.ts +5 -0
- package/src/lib/tasks/lib/enforce-file-types/internal/file-type-errors.ts +21 -0
- package/src/lib/tasks/lib/enforce-file-types/internal/find-file-type-violations.ts +78 -0
- package/src/lib/tasks/lib/format-with-bun-fmt/index.ts +1 -0
- package/src/lib/tasks/lib/format-with-bun-fmt/internal/check-formatting-with-bun-fmt.ts +157 -0
- package/src/lib/tasks/lib/format-with-bun-fmt/internal/declare-the-formatting-task.ts +66 -0
- package/src/lib/tasks/lib/format-with-bun-fmt/internal/find-format-config-violations.ts +16 -0
- package/src/lib/tasks/lib/format-with-bun-fmt/internal/find-format-input-violations.ts +74 -0
- package/src/lib/tasks/lib/format-with-bun-fmt/internal/find-symbolic-links.ts +14 -0
- package/src/lib/tasks/lib/format-with-bun-fmt/internal/unformatted-file-errors.ts +12 -0
- package/src/lib/tasks/lib/judge-index-re-exports/index.ts +1 -0
- package/src/lib/tasks/lib/judge-index-re-exports/internal/find-index-re-export-violations.ts +353 -0
- package/src/lib/tasks/lib/judge-index-re-exports/internal/index-re-export-errors.ts +21 -0
- package/src/lib/tasks/lib/lint-with-oxlint/index.ts +15 -0
- package/src/lib/tasks/lib/lint-with-oxlint/internal/check-lint-rules-with-oxlint.ts +123 -0
- package/src/lib/tasks/lib/lint-with-oxlint/internal/check-unsafe-enum-assignments.ts +152 -0
- package/src/lib/tasks/lib/lint-with-oxlint/internal/find-tsgolint-executable.ts +21 -0
- package/src/lib/tasks/lib/lint-with-oxlint/internal/read-oxlint-json-report.ts +82 -0
- package/src/lib/tasks/lib/lint-with-oxlint/internal/read-tsgolint-rule-messages.ts +68 -0
- package/src/lib/tasks/lib/place-exports-in-the-narrowest-directory/index.ts +1 -0
- package/src/lib/tasks/lib/place-exports-in-the-narrowest-directory/internal/export-placement-errors.ts +135 -0
- package/src/lib/tasks/lib/place-exports-in-the-narrowest-directory/internal/find-export-placement-violations.ts +507 -0
- package/src/lib/tasks/lib/place-exports-in-the-narrowest-directory/internal/find-misplaced-files.ts +116 -0
- package/src/lib/tasks/lib/place-exports-in-the-narrowest-directory/internal/find-subdivided-directories.ts +29 -0
- package/src/lib/tasks/lib/place-exports-in-the-narrowest-directory/internal/find-the-importer-graph.ts +451 -0
- package/src/lib/tasks/lib/place-exports-in-the-narrowest-directory/internal/list-binding-names.ts +49 -0
- package/src/lib/tasks/lib/refuse-disable-directives/index.ts +15 -0
- package/src/lib/tasks/lib/refuse-disable-directives/internal/disable-directive-errors.ts +45 -0
- package/src/lib/tasks/lib/refuse-disable-directives/internal/find-disable-directives.ts +66 -0
- package/src/lib/tasks/lib/refuse-error-mappings-that-end-streams/index.ts +1 -0
- package/src/lib/tasks/lib/refuse-error-mappings-that-end-streams/internal/error-mapping-errors.ts +21 -0
- package/src/lib/tasks/lib/refuse-error-mappings-that-end-streams/internal/find-error-mappings-to-done.ts +135 -0
- package/src/lib/tasks/lib/require-separate-service-layers/index.ts +1 -0
- package/src/lib/tasks/lib/require-separate-service-layers/internal/find-service-layer-violations.ts +170 -0
- package/src/lib/tasks/lib/require-separate-service-layers/internal/service-layer-errors.ts +21 -0
- package/src/lib/tasks/lib/require-type-checking-every-linted-file/index.ts +14 -0
- package/src/lib/tasks/lib/require-type-checking-every-linted-file/internal/find-linted-files-not-type-checked.ts +117 -0
- package/src/lib/tasks/lib/require-type-checking-every-linted-file/internal/linted-file-errors.ts +51 -0
- package/src/lib/tasks/lib/type-check-with-bun-check/index.ts +11 -0
- package/src/lib/tasks/lib/type-check-with-bun-check/internal/check-types-with-bun-check.ts +54 -0
- package/src/lib/tasks/lib/type-check-with-bun-check/internal/read-bun-check-output.ts +73 -0
- package/src/lib/tasks/lib/type-check-with-bun-check/internal/type-check-errors.ts +10 -0
- package/src/lib/tasks/shared/check-each-nested-package.ts +79 -0
- package/src/lib/tasks/shared/classify-files-by-role.ts +115 -0
- package/src/lib/tasks/shared/count-the-line-of-an-offset.ts +2 -0
- package/src/lib/tasks/shared/create-the-module-resolver.ts +38 -0
- package/src/lib/tasks/shared/declare-lint-config-task.ts +13 -0
- package/src/lib/tasks/shared/declare-typescript-config-task.ts +18 -0
- package/src/lib/tasks/shared/encode-compact-json.ts +5 -0
- package/src/lib/tasks/shared/find-installed-package-binaries.ts +62 -0
- package/src/lib/tasks/shared/find-module-requests.ts +482 -0
- package/src/lib/tasks/shared/find-named-package-manifests.ts +94 -0
- package/src/lib/tasks/shared/find-unmet-typescript-config-requirements.ts +60 -0
- package/src/lib/tasks/shared/list-ignored-files-imported-by-source.ts +79 -0
- package/src/lib/tasks/shared/list-linted-files.ts +28 -0
- package/src/lib/tasks/shared/list-owned-files.ts +13 -0
- package/src/lib/tasks/shared/list-package-files.ts +66 -0
- package/src/lib/tasks/shared/load-the-lint-config.ts +176 -0
- package/src/lib/tasks/shared/match-granted-patch-files.ts +88 -0
- package/src/lib/tasks/shared/parse-config-files-that-import-from-check.ts +310 -0
- package/src/lib/tasks/shared/print-failures-and-keep-detail-in-the-trace.ts +99 -0
- package/src/lib/tasks/shared/project-config-and-tool-errors.ts +485 -0
- package/src/lib/tasks/shared/query-the-typescript-project.ts +635 -0
- package/src/lib/tasks/shared/read-named-package-manifests.ts +53 -0
- package/src/lib/tasks/shared/read-package-manifest-object.ts +28 -0
- package/src/lib/tasks/shared/resolve-absolute-paths.ts +4 -0
- package/src/lib/tasks/shared/resolve-module-requests.ts +121 -0
- package/src/lib/tasks/shared/run-tools-and-decode-their-reports.ts +98 -0
- package/src/lib/tasks/shared/tool-file-locations.ts +38 -0
- package/src/shared/bans-each-permission-lifts.ts +454 -0
- package/src/shared/config-file-names.ts +3 -0
- package/src/shared/find-retired-words.ts +17 -0
- package/src/shared/format-reported-failures.ts +31 -0
- package/src/shared/lint-rule-messages-and-patterns.ts +104 -0
- package/src/shared/match-file-names-and-path-prefixes.ts +18 -0
- package/src/shared/permission-grant-errors.ts +42 -0
- package/src/shared/record-and-grant-permissions-by-path.ts +419 -0
- package/src/shared/test-home-directories.ts +4 -0
|
@@ -0,0 +1,451 @@
|
|
|
1
|
+
import { Effect, FileSystem, Option, Path, Schema } from "effect";
|
|
2
|
+
import { parseSync } from "oxc-parser";
|
|
3
|
+
import type { ImportNameKind } from "oxc-parser";
|
|
4
|
+
|
|
5
|
+
import { FORMAT_CONFIG_FILE } from "../../../../../shared/config-file-names.ts";
|
|
6
|
+
import { isWithin } from "../../../../../shared/match-file-names-and-path-prefixes.ts";
|
|
7
|
+
import {
|
|
8
|
+
isDeclarationFile,
|
|
9
|
+
isTopLevelScript,
|
|
10
|
+
isRootSupportFile,
|
|
11
|
+
isUnderTestDirectory,
|
|
12
|
+
isScript,
|
|
13
|
+
moduleDirectoriesAmong,
|
|
14
|
+
packagePathOf,
|
|
15
|
+
} from "../../../shared/classify-files-by-role.ts";
|
|
16
|
+
import { lineNumberAt } from "../../../shared/count-the-line-of-an-offset.ts";
|
|
17
|
+
import { moduleRequestsIn, URL_REQUESTS } from "../../../shared/find-module-requests.ts";
|
|
18
|
+
import type { MODULE_REQUEST_KINDS } from "../../../shared/find-module-requests.ts";
|
|
19
|
+
import { PACKAGE_MANIFEST_FILE } from "../../../shared/find-named-package-manifests.ts";
|
|
20
|
+
import { existingPackageFiles } from "../../../shared/list-package-files.ts";
|
|
21
|
+
import { isFormatConfigTextRefusedIn } from "../../../shared/parse-config-files-that-import-from-check.ts";
|
|
22
|
+
import {
|
|
23
|
+
BunConfigInvalid,
|
|
24
|
+
PackageExportsMixKeys,
|
|
25
|
+
PackageManifestFieldInvalid,
|
|
26
|
+
SourceFileUnparsable,
|
|
27
|
+
} from "../../../shared/project-config-and-tool-errors.ts";
|
|
28
|
+
import type { ModuleRequestUnresolvable } from "../../../shared/project-config-and-tool-errors.ts";
|
|
29
|
+
import {
|
|
30
|
+
checkedSourceFiles,
|
|
31
|
+
CUSTOM_CONDITIONS,
|
|
32
|
+
effectiveCompilerOptions,
|
|
33
|
+
} from "../../../shared/query-the-typescript-project.ts";
|
|
34
|
+
import { JSON_OBJECT } from "../../../shared/read-package-manifest-object.ts";
|
|
35
|
+
import { resolveModuleRequest } from "../../../shared/resolve-module-requests.ts";
|
|
36
|
+
import { ImportUnresolvableInTheImportBoundaryCheck } from "./export-placement-errors.ts";
|
|
37
|
+
|
|
38
|
+
export const EVERY_EXPORT = "*";
|
|
39
|
+
export const DEFAULT_EXPORT = "default";
|
|
40
|
+
const SOURCE_EXTENSION = /(?:\.d)?\.[cm]?[jt]sx?$/u;
|
|
41
|
+
const TYPESCRIPT_PROJECT_PATTERN = "tsconfig*.json";
|
|
42
|
+
const TYPESCRIPT_PROJECT_FILE_NAME = /^tsconfig(?:\.[\w-]+)?\.json$/u;
|
|
43
|
+
const BUILD_DIRECTORIES = Schema.Struct({
|
|
44
|
+
outDir: Schema.optionalKey(Schema.String),
|
|
45
|
+
rootDir: Schema.optionalKey(Schema.String),
|
|
46
|
+
});
|
|
47
|
+
const BUN_CONFIG_FILE = "bunfig.toml";
|
|
48
|
+
const PRELOADS = Schema.optionalKey(Schema.Union([Schema.String, Schema.Array(Schema.String)]));
|
|
49
|
+
const BUN_CONFIG = Schema.Struct({
|
|
50
|
+
preload: PRELOADS,
|
|
51
|
+
test: Schema.optionalKey(Schema.Struct({ preload: PRELOADS })),
|
|
52
|
+
});
|
|
53
|
+
const PACKAGE_PATTERN_WILDCARD = "*";
|
|
54
|
+
const PARTS_AROUND_ONE_WILDCARD = 2;
|
|
55
|
+
|
|
56
|
+
const PACKAGE_ENTRIES = Schema.fromJsonString(
|
|
57
|
+
Schema.Struct({
|
|
58
|
+
main: Schema.optionalKey(Schema.String),
|
|
59
|
+
module: Schema.optionalKey(Schema.String),
|
|
60
|
+
exports: Schema.optionalKey(Schema.Json),
|
|
61
|
+
}),
|
|
62
|
+
);
|
|
63
|
+
|
|
64
|
+
const stringsIn = (value: Schema.Json): readonly string[] => {
|
|
65
|
+
if (typeof value === "string") {
|
|
66
|
+
return [value];
|
|
67
|
+
}
|
|
68
|
+
if (Array.isArray(value)) {
|
|
69
|
+
return value.flatMap((item: Schema.Json) => stringsIn(item));
|
|
70
|
+
}
|
|
71
|
+
return Schema.is(JSON_OBJECT)(value)
|
|
72
|
+
? Object.values(value).flatMap((item) => stringsIn(item))
|
|
73
|
+
: [];
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
const importedNameOf = (importName: {
|
|
77
|
+
readonly kind: `${ImportNameKind}`;
|
|
78
|
+
readonly name: string | null;
|
|
79
|
+
}) => {
|
|
80
|
+
if (importName.kind === "Default") {
|
|
81
|
+
return DEFAULT_EXPORT;
|
|
82
|
+
}
|
|
83
|
+
return importName.kind === "Name" ? (importName.name ?? DEFAULT_EXPORT) : EVERY_EXPORT;
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
const CURRENT_DIRECTORY_PREFIX = /^\.\//u;
|
|
87
|
+
|
|
88
|
+
const fromPackageRoot = (importer: string, specifier: string) =>
|
|
89
|
+
specifier.startsWith("/")
|
|
90
|
+
? specifier
|
|
91
|
+
: `${"../".repeat(importer.split("/").length - 1) || "./"}${specifier.replace(CURRENT_DIRECTORY_PREFIX, "")}`;
|
|
92
|
+
|
|
93
|
+
const failedAlsoInTheImportBoundaryCheck = Effect.mapError(
|
|
94
|
+
(failure: ModuleRequestUnresolvable) =>
|
|
95
|
+
new ImportUnresolvableInTheImportBoundaryCheck({
|
|
96
|
+
request: failure.request,
|
|
97
|
+
importingFile: failure.importingFile,
|
|
98
|
+
}),
|
|
99
|
+
);
|
|
100
|
+
|
|
101
|
+
const moduleUsesIn = (
|
|
102
|
+
path: string,
|
|
103
|
+
text: string,
|
|
104
|
+
resolve: (
|
|
105
|
+
specifier: string,
|
|
106
|
+
) => Effect.Effect<
|
|
107
|
+
string | undefined,
|
|
108
|
+
ModuleRequestUnresolvable,
|
|
109
|
+
FileSystem.FileSystem | Path.Path
|
|
110
|
+
>,
|
|
111
|
+
) =>
|
|
112
|
+
Effect.gen(function* () {
|
|
113
|
+
const parsed = parseSync(path, text);
|
|
114
|
+
if (parsed.errors.length > 0) {
|
|
115
|
+
return yield* new SourceFileUnparsable({
|
|
116
|
+
file: path,
|
|
117
|
+
reason: parsed.errors.map((error) => error.message).join("; "),
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
const uses: {
|
|
121
|
+
readonly file: string;
|
|
122
|
+
readonly names: readonly string[];
|
|
123
|
+
readonly line: number;
|
|
124
|
+
readonly kind: (typeof MODULE_REQUEST_KINDS)[number];
|
|
125
|
+
}[] = [];
|
|
126
|
+
for (const declaration of parsed.module.staticImports) {
|
|
127
|
+
const file = yield* resolve(declaration.moduleRequest.value).pipe(
|
|
128
|
+
failedAlsoInTheImportBoundaryCheck,
|
|
129
|
+
);
|
|
130
|
+
const importsOnlyTypes =
|
|
131
|
+
declaration.entries.length > 0 && declaration.entries.every((entry) => entry.isType);
|
|
132
|
+
if (file !== undefined) {
|
|
133
|
+
uses.push({
|
|
134
|
+
file,
|
|
135
|
+
names: declaration.entries.map((entry) => importedNameOf(entry.importName)),
|
|
136
|
+
line: lineNumberAt(text, declaration.start),
|
|
137
|
+
kind: importsOnlyTypes ? "type" : "static",
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
for (const declaration of parsed.module.staticExports) {
|
|
142
|
+
for (const entry of declaration.entries) {
|
|
143
|
+
const file =
|
|
144
|
+
entry.moduleRequest === null
|
|
145
|
+
? undefined
|
|
146
|
+
: yield* resolve(entry.moduleRequest.value).pipe(failedAlsoInTheImportBoundaryCheck);
|
|
147
|
+
if (file !== undefined) {
|
|
148
|
+
uses.push({
|
|
149
|
+
file,
|
|
150
|
+
names: [
|
|
151
|
+
entry.importName.kind === "Name"
|
|
152
|
+
? (entry.importName.name ?? DEFAULT_EXPORT)
|
|
153
|
+
: EVERY_EXPORT,
|
|
154
|
+
],
|
|
155
|
+
line: lineNumberAt(text, entry.start),
|
|
156
|
+
kind: entry.isType ? "type" : "static",
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
const { requests } = moduleRequestsIn(parsed);
|
|
162
|
+
for (const request of requests) {
|
|
163
|
+
if (request.kind === "static") {
|
|
164
|
+
continue;
|
|
165
|
+
}
|
|
166
|
+
const isSkippedByTheImportBoundaryCheck =
|
|
167
|
+
request.kind === "build" ||
|
|
168
|
+
(URL_REQUESTS.has(request.kind) && !isScript(request.specifier));
|
|
169
|
+
const file = isSkippedByTheImportBoundaryCheck
|
|
170
|
+
? yield* resolve(
|
|
171
|
+
request.kind === "build" ? fromPackageRoot(path, request.specifier) : request.specifier,
|
|
172
|
+
)
|
|
173
|
+
: yield* resolve(request.specifier).pipe(failedAlsoInTheImportBoundaryCheck);
|
|
174
|
+
if (file !== undefined) {
|
|
175
|
+
uses.push({
|
|
176
|
+
file,
|
|
177
|
+
names: request.kind === "launch" ? [] : [request.namedExport ?? EVERY_EXPORT],
|
|
178
|
+
line: lineNumberAt(text, request.start),
|
|
179
|
+
kind: request.kind,
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
return { uses, parsed, text };
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
const withoutExtension = (path: string) => path.replace(SOURCE_EXTENSION, "");
|
|
187
|
+
|
|
188
|
+
const capturingPattern = (entry: string) =>
|
|
189
|
+
new RegExp(
|
|
190
|
+
`^${withoutExtension(entry)
|
|
191
|
+
.split(PACKAGE_PATTERN_WILDCARD)
|
|
192
|
+
.map((part) => RegExp.escape(part))
|
|
193
|
+
.join("(.+)")}$`,
|
|
194
|
+
"u",
|
|
195
|
+
);
|
|
196
|
+
|
|
197
|
+
const packageEntryMatches = (entries: readonly string[]) => {
|
|
198
|
+
const patterns = entries.map((entry) => capturingPattern(entry));
|
|
199
|
+
return (path: string) =>
|
|
200
|
+
SOURCE_EXTENSION.test(path)
|
|
201
|
+
? patterns.flatMap((pattern) => {
|
|
202
|
+
const matched = pattern.exec(withoutExtension(path));
|
|
203
|
+
return matched === null ? [] : [{ capture: matched[1] }];
|
|
204
|
+
})
|
|
205
|
+
: [];
|
|
206
|
+
};
|
|
207
|
+
|
|
208
|
+
const exportsSubpathEntries = (exportsField: Schema.Json) => {
|
|
209
|
+
const isSingleExportTarget =
|
|
210
|
+
exportsField === null || typeof exportsField !== "object" || Array.isArray(exportsField);
|
|
211
|
+
if (isSingleExportTarget) {
|
|
212
|
+
return [[".", exportsField] as const];
|
|
213
|
+
}
|
|
214
|
+
const keys = Object.keys(exportsField);
|
|
215
|
+
const subpathKeys = keys.filter((key) => key.startsWith("."));
|
|
216
|
+
if (subpathKeys.length === 0) {
|
|
217
|
+
return [[".", exportsField] as const];
|
|
218
|
+
}
|
|
219
|
+
return subpathKeys.length === keys.length ? Object.entries(exportsField) : undefined;
|
|
220
|
+
};
|
|
221
|
+
|
|
222
|
+
const subpathMatcher = (subpathPattern: string) =>
|
|
223
|
+
new RegExp(
|
|
224
|
+
`^${subpathPattern
|
|
225
|
+
.split(PACKAGE_PATTERN_WILDCARD)
|
|
226
|
+
.map((part) => RegExp.escape(part))
|
|
227
|
+
.join(".+")}$`,
|
|
228
|
+
"u",
|
|
229
|
+
);
|
|
230
|
+
|
|
231
|
+
const patternPrefixLength = (key: string) => key.indexOf(PACKAGE_PATTERN_WILDCARD);
|
|
232
|
+
|
|
233
|
+
const isSubpathPattern = (key: string) =>
|
|
234
|
+
key.split(PACKAGE_PATTERN_WILDCARD).length === PARTS_AROUND_ONE_WILDCARD;
|
|
235
|
+
|
|
236
|
+
const subpathKeyFor = (keys: readonly string[], subpath: string) => {
|
|
237
|
+
if (keys.includes(subpath)) {
|
|
238
|
+
return subpath;
|
|
239
|
+
}
|
|
240
|
+
return keys
|
|
241
|
+
.filter((key) => isSubpathPattern(key) && subpathMatcher(key).test(subpath))
|
|
242
|
+
.toSorted(
|
|
243
|
+
(first, second) =>
|
|
244
|
+
patternPrefixLength(second) - patternPrefixLength(first) || second.length - first.length,
|
|
245
|
+
)[0];
|
|
246
|
+
};
|
|
247
|
+
|
|
248
|
+
export const findTheImporterGraph = (projectFile: string) =>
|
|
249
|
+
Effect.gen(function* () {
|
|
250
|
+
const fileSystem = yield* FileSystem.FileSystem;
|
|
251
|
+
const path = yield* Path.Path;
|
|
252
|
+
const packageDirectory = yield* fileSystem.realPath(path.dirname(projectFile));
|
|
253
|
+
const { customConditions = [] } = yield* Schema.decodeEffect(CUSTOM_CONDITIONS)(
|
|
254
|
+
yield* effectiveCompilerOptions(projectFile),
|
|
255
|
+
);
|
|
256
|
+
const isFormatConfigRefused = yield* isFormatConfigTextRefusedIn(packageDirectory);
|
|
257
|
+
const paths = (yield* checkedSourceFiles(projectFile)).filter(
|
|
258
|
+
(file) => !isFormatConfigRefused || file !== FORMAT_CONFIG_FILE,
|
|
259
|
+
);
|
|
260
|
+
const known = new Set(paths);
|
|
261
|
+
const knownPackagePathOf = (file: string) => {
|
|
262
|
+
const relative = packagePathOf(path, packageDirectory, file);
|
|
263
|
+
return known.has(relative) ? relative : undefined;
|
|
264
|
+
};
|
|
265
|
+
const resolverFor = (importer: string) => (specifier: string) =>
|
|
266
|
+
resolveModuleRequest({
|
|
267
|
+
request: specifier,
|
|
268
|
+
importingFile: path.join(packageDirectory, importer),
|
|
269
|
+
customConditions,
|
|
270
|
+
projectDirectory: packageDirectory,
|
|
271
|
+
}).pipe(
|
|
272
|
+
Effect.map((resolved) =>
|
|
273
|
+
resolved === undefined ? undefined : knownPackagePathOf(resolved.file),
|
|
274
|
+
),
|
|
275
|
+
);
|
|
276
|
+
const files = new Map<string, Effect.Success<ReturnType<typeof moduleUsesIn>>>();
|
|
277
|
+
for (const file of paths) {
|
|
278
|
+
const text = yield* fileSystem.readFileString(path.join(packageDirectory, file));
|
|
279
|
+
files.set(file, yield* moduleUsesIn(file, text, resolverFor(file)));
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
const trackedPackageFiles = new Set(
|
|
283
|
+
yield* existingPackageFiles(packageDirectory, [
|
|
284
|
+
PACKAGE_MANIFEST_FILE,
|
|
285
|
+
BUN_CONFIG_FILE,
|
|
286
|
+
TYPESCRIPT_PROJECT_PATTERN,
|
|
287
|
+
]),
|
|
288
|
+
);
|
|
289
|
+
const readTrackedFile = (name: string) =>
|
|
290
|
+
trackedPackageFiles.has(name)
|
|
291
|
+
? fileSystem.readFileString(path.join(packageDirectory, name)).pipe(Effect.asSome)
|
|
292
|
+
: Effect.succeedNone;
|
|
293
|
+
const manifestText = yield* readTrackedFile(PACKAGE_MANIFEST_FILE);
|
|
294
|
+
const manifest = Option.isNone(manifestText)
|
|
295
|
+
? {}
|
|
296
|
+
: yield* Schema.decodeEffect(PACKAGE_ENTRIES)(manifestText.value).pipe(
|
|
297
|
+
Effect.mapError(
|
|
298
|
+
(error) =>
|
|
299
|
+
new PackageManifestFieldInvalid({
|
|
300
|
+
path: path.join(packageDirectory, PACKAGE_MANIFEST_FILE),
|
|
301
|
+
reason: error.message,
|
|
302
|
+
}),
|
|
303
|
+
),
|
|
304
|
+
);
|
|
305
|
+
const buildDirectories = yield* Effect.forEach(
|
|
306
|
+
[...trackedPackageFiles].filter((name) => TYPESCRIPT_PROJECT_FILE_NAME.test(name)),
|
|
307
|
+
(name) =>
|
|
308
|
+
effectiveCompilerOptions(path.join(packageDirectory, name)).pipe(
|
|
309
|
+
Effect.flatMap(Schema.decodeUnknownEffect(BUILD_DIRECTORIES)),
|
|
310
|
+
Effect.map((options) =>
|
|
311
|
+
options.outDir === undefined
|
|
312
|
+
? []
|
|
313
|
+
: [{ outDirectory: options.outDir, rootDirectory: options.rootDir ?? "" }],
|
|
314
|
+
),
|
|
315
|
+
),
|
|
316
|
+
);
|
|
317
|
+
const sourcesOfEntry = (entry: string) => {
|
|
318
|
+
const normalized = path.normalize(entry).split(path.sep).join("/");
|
|
319
|
+
const mapped = buildDirectories
|
|
320
|
+
.flat()
|
|
321
|
+
.flatMap(({ outDirectory, rootDirectory }) =>
|
|
322
|
+
isWithin(normalized, outDirectory)
|
|
323
|
+
? [
|
|
324
|
+
path
|
|
325
|
+
.join(rootDirectory, path.relative(outDirectory, normalized))
|
|
326
|
+
.split(path.sep)
|
|
327
|
+
.join("/"),
|
|
328
|
+
]
|
|
329
|
+
: [],
|
|
330
|
+
);
|
|
331
|
+
const matchesOf = packageEntryMatches([normalized, ...mapped]);
|
|
332
|
+
return paths.flatMap((file) =>
|
|
333
|
+
matchesOf(file)
|
|
334
|
+
.slice(0, 1)
|
|
335
|
+
.map(({ capture }) => ({ file, capture })),
|
|
336
|
+
);
|
|
337
|
+
};
|
|
338
|
+
const manifestEntries = [manifest.main, manifest.module]
|
|
339
|
+
.filter((entry) => entry !== undefined)
|
|
340
|
+
.filter((entry) => SOURCE_EXTENSION.test(entry));
|
|
341
|
+
const subpaths = manifest.exports === undefined ? [] : exportsSubpathEntries(manifest.exports);
|
|
342
|
+
if (subpaths === undefined) {
|
|
343
|
+
return yield* new PackageExportsMixKeys({
|
|
344
|
+
path: path.join(packageDirectory, PACKAGE_MANIFEST_FILE),
|
|
345
|
+
});
|
|
346
|
+
}
|
|
347
|
+
const subpathKeys = subpaths.map(([subpath]) => subpath);
|
|
348
|
+
const entrySources = [
|
|
349
|
+
...manifestEntries.map((entry) => {
|
|
350
|
+
const sources = sourcesOfEntry(entry).map(({ file }) => file);
|
|
351
|
+
return { entry, sources, started: sources };
|
|
352
|
+
}),
|
|
353
|
+
...subpaths.flatMap(([subpath, target]) =>
|
|
354
|
+
stringsIn(target)
|
|
355
|
+
.filter((entry) => SOURCE_EXTENSION.test(entry))
|
|
356
|
+
.map((entry) => {
|
|
357
|
+
const matched = sourcesOfEntry(entry);
|
|
358
|
+
return {
|
|
359
|
+
entry,
|
|
360
|
+
sources: matched.map(({ file }) => file),
|
|
361
|
+
started: matched
|
|
362
|
+
.filter(({ capture }) => {
|
|
363
|
+
const exposed =
|
|
364
|
+
capture === undefined
|
|
365
|
+
? subpath
|
|
366
|
+
: subpath.replace(PACKAGE_PATTERN_WILDCARD, capture);
|
|
367
|
+
return subpathKeyFor(subpathKeys, exposed) === subpath;
|
|
368
|
+
})
|
|
369
|
+
.map(({ file }) => file),
|
|
370
|
+
};
|
|
371
|
+
}),
|
|
372
|
+
),
|
|
373
|
+
];
|
|
374
|
+
const bunConfig = yield* readTrackedFile(BUN_CONFIG_FILE);
|
|
375
|
+
const bunConfigPath = path.join(packageDirectory, BUN_CONFIG_FILE);
|
|
376
|
+
const bunOptions = Option.isNone(bunConfig)
|
|
377
|
+
? {}
|
|
378
|
+
: yield* Effect.try({
|
|
379
|
+
try: () => Bun.TOML.parse(bunConfig.value),
|
|
380
|
+
catch: (error) => new BunConfigInvalid({ path: bunConfigPath, reason: String(error) }),
|
|
381
|
+
}).pipe(
|
|
382
|
+
Effect.flatMap((parsed) =>
|
|
383
|
+
Schema.decodeEffect(BUN_CONFIG)(parsed).pipe(
|
|
384
|
+
Effect.mapError(
|
|
385
|
+
(error) => new BunConfigInvalid({ path: bunConfigPath, reason: error.message }),
|
|
386
|
+
),
|
|
387
|
+
),
|
|
388
|
+
),
|
|
389
|
+
);
|
|
390
|
+
const preloadedBy = (preloads: (typeof BUN_CONFIG.Type)["preload"]) =>
|
|
391
|
+
(preloads === undefined ? [] : [preloads].flat()).flatMap((preload) => {
|
|
392
|
+
const loaded = knownPackagePathOf(path.join(packageDirectory, preload));
|
|
393
|
+
return loaded === undefined ? [] : [loaded];
|
|
394
|
+
});
|
|
395
|
+
const preloaded = preloadedBy(bunOptions.preload);
|
|
396
|
+
const testPreloaded = preloadedBy(bunOptions.test?.preload);
|
|
397
|
+
|
|
398
|
+
const reach = (
|
|
399
|
+
seeds: Iterable<string>,
|
|
400
|
+
isFollowed: (
|
|
401
|
+
use: Effect.Success<ReturnType<typeof moduleUsesIn>>["uses"][number],
|
|
402
|
+
) => boolean = () => true,
|
|
403
|
+
) => {
|
|
404
|
+
const reached = new Set<string>();
|
|
405
|
+
const pending = [...seeds];
|
|
406
|
+
for (const next of pending) {
|
|
407
|
+
const parsed = files.get(next);
|
|
408
|
+
const isUnreachedParsedFile = !reached.has(next) && parsed !== undefined;
|
|
409
|
+
if (!isUnreachedParsedFile) {
|
|
410
|
+
continue;
|
|
411
|
+
}
|
|
412
|
+
reached.add(next);
|
|
413
|
+
pending.push(...parsed.uses.filter(isFollowed).map((use) => use.file));
|
|
414
|
+
}
|
|
415
|
+
return reached;
|
|
416
|
+
};
|
|
417
|
+
const packageEntries = new Set(entrySources.flatMap(({ started }) => started));
|
|
418
|
+
const exportsAreReadFromOutside = (file: string) =>
|
|
419
|
+
packageEntries.has(file) || isTopLevelScript(file) || isRootSupportFile(file);
|
|
420
|
+
const roots = new Set([
|
|
421
|
+
...paths.filter((file) => exportsAreReadFromOutside(file)),
|
|
422
|
+
...preloaded,
|
|
423
|
+
...testPreloaded,
|
|
424
|
+
]);
|
|
425
|
+
const reachable = reach([
|
|
426
|
+
...roots,
|
|
427
|
+
...[...files.keys()].filter((file) => isDeclarationFile(file) || isUnderTestDirectory(file)),
|
|
428
|
+
]);
|
|
429
|
+
const importers = new Map<string, Set<string>>();
|
|
430
|
+
for (const [importer, parsed] of files) {
|
|
431
|
+
const isCountedImporter = reachable.has(importer) && !isUnderTestDirectory(importer);
|
|
432
|
+
for (const use of isCountedImporter ? parsed.uses : []) {
|
|
433
|
+
if (use.file !== importer) {
|
|
434
|
+
importers.set(use.file, (importers.get(use.file) ?? new Set()).add(importer));
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
const importersOf = (file: string) => [...(importers.get(file) ?? [])];
|
|
439
|
+
const moduleDirectories = moduleDirectoriesAmong(paths);
|
|
440
|
+
return {
|
|
441
|
+
paths,
|
|
442
|
+
files,
|
|
443
|
+
entrySources,
|
|
444
|
+
reach,
|
|
445
|
+
exportsAreReadFromOutside,
|
|
446
|
+
roots,
|
|
447
|
+
reachable,
|
|
448
|
+
moduleDirectories,
|
|
449
|
+
importersOf,
|
|
450
|
+
};
|
|
451
|
+
});
|
package/src/lib/tasks/lib/place-exports-in-the-narrowest-directory/internal/list-binding-names.ts
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
BindingIdentifier,
|
|
3
|
+
BindingPattern,
|
|
4
|
+
BindingRestElement,
|
|
5
|
+
ParamPattern,
|
|
6
|
+
} from "oxc-parser";
|
|
7
|
+
|
|
8
|
+
const bindingIdentifiersOf = (
|
|
9
|
+
pattern: BindingPattern | BindingRestElement | null,
|
|
10
|
+
): readonly BindingIdentifier[] => {
|
|
11
|
+
if (pattern === null) {
|
|
12
|
+
return [];
|
|
13
|
+
}
|
|
14
|
+
switch (pattern.type) {
|
|
15
|
+
case "Identifier": {
|
|
16
|
+
return [pattern];
|
|
17
|
+
}
|
|
18
|
+
case "ObjectPattern": {
|
|
19
|
+
return pattern.properties.flatMap((property) =>
|
|
20
|
+
bindingIdentifiersOf(property.type === "RestElement" ? property : property.value),
|
|
21
|
+
);
|
|
22
|
+
}
|
|
23
|
+
case "ArrayPattern": {
|
|
24
|
+
return pattern.elements.flatMap(bindingIdentifiersOf);
|
|
25
|
+
}
|
|
26
|
+
case "AssignmentPattern": {
|
|
27
|
+
return bindingIdentifiersOf(pattern.left);
|
|
28
|
+
}
|
|
29
|
+
case "RestElement": {
|
|
30
|
+
return bindingIdentifiersOf(pattern.argument);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export const bindingNamesOf = (
|
|
36
|
+
pattern: BindingPattern | BindingRestElement | null,
|
|
37
|
+
): readonly string[] => bindingIdentifiersOf(pattern).map(({ name }) => name);
|
|
38
|
+
|
|
39
|
+
const parameterIdentifiersOf = (parameter: ParamPattern): readonly BindingIdentifier[] => {
|
|
40
|
+
if (parameter.type === "TSParameterProperty") {
|
|
41
|
+
return bindingIdentifiersOf(parameter.parameter);
|
|
42
|
+
}
|
|
43
|
+
return parameter.type === "RestElement"
|
|
44
|
+
? bindingIdentifiersOf(parameter.argument)
|
|
45
|
+
: bindingIdentifiersOf(parameter);
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
export const parameterNamesOf = (parameter: ParamPattern): readonly string[] =>
|
|
49
|
+
parameterIdentifiersOf(parameter).map(({ name }) => name);
|
|
@@ -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 { findDisableDirectivesInLintedFilesOf } from "./internal/find-disable-directives.ts";
|
|
8
|
+
|
|
9
|
+
export const directives = Task.make(
|
|
10
|
+
"directives",
|
|
11
|
+
Effect.andThen(
|
|
12
|
+
Task.all([typeScriptConfig, lintConfigFile]),
|
|
13
|
+
inEachPackage("directives", ".", findDisableDirectivesInLintedFilesOf),
|
|
14
|
+
),
|
|
15
|
+
);
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { Schema } from "effect";
|
|
2
|
+
|
|
3
|
+
import { listedViolations } from "../../../../../shared/format-reported-failures.ts";
|
|
4
|
+
import { SourceFileUnparsable } from "../../../shared/project-config-and-tool-errors.ts";
|
|
5
|
+
|
|
6
|
+
export class SourceFileUnreadable extends Schema.TaggedError<SourceFileUnreadable>()(
|
|
7
|
+
"SourceFileUnreadable",
|
|
8
|
+
{
|
|
9
|
+
file: Schema.String,
|
|
10
|
+
reason: Schema.String,
|
|
11
|
+
},
|
|
12
|
+
) {
|
|
13
|
+
public get location() {
|
|
14
|
+
return this.file;
|
|
15
|
+
}
|
|
16
|
+
public override get message() {
|
|
17
|
+
return `could not be read: ${this.reason}`;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export class DisableDirective extends Schema.TaggedError<DisableDirective>()("DisableDirective", {
|
|
22
|
+
file: Schema.String,
|
|
23
|
+
line: Schema.Int,
|
|
24
|
+
directive: Schema.String,
|
|
25
|
+
}) {
|
|
26
|
+
public get location() {
|
|
27
|
+
return `${this.file}:${this.line}`;
|
|
28
|
+
}
|
|
29
|
+
public override get message() {
|
|
30
|
+
return `has disable directive ${this.directive}`;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export class DirectiveScanViolations extends Schema.TaggedError<DirectiveScanViolations>()(
|
|
35
|
+
"DirectiveScanViolations",
|
|
36
|
+
{
|
|
37
|
+
violations: Schema.Array(
|
|
38
|
+
Schema.Union([DisableDirective, SourceFileUnparsable, SourceFileUnreadable]),
|
|
39
|
+
),
|
|
40
|
+
},
|
|
41
|
+
) {
|
|
42
|
+
public override get message() {
|
|
43
|
+
return listedViolations(this.violations);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { Array as Arrays, Effect, FileSystem, Path, Result } from "effect";
|
|
2
|
+
import { parseSync } from "oxc-parser";
|
|
3
|
+
|
|
4
|
+
import { FORMAT_CONFIG_FILE } from "../../../../../shared/config-file-names.ts";
|
|
5
|
+
import { isDirective } from "../../../../../shared/lint-rule-messages-and-patterns.ts";
|
|
6
|
+
import { lineNumberAt } from "../../../shared/count-the-line-of-an-offset.ts";
|
|
7
|
+
import { lintedFiles } from "../../../shared/list-linted-files.ts";
|
|
8
|
+
import { isFormatConfigTextRefusedIn } from "../../../shared/parse-config-files-that-import-from-check.ts";
|
|
9
|
+
import { quietViolations } from "../../../shared/print-failures-and-keep-detail-in-the-trace.ts";
|
|
10
|
+
import { SourceFileUnparsable } from "../../../shared/project-config-and-tool-errors.ts";
|
|
11
|
+
import { TYPESCRIPT_PROJECT_FILE } from "../../../shared/query-the-typescript-project.ts";
|
|
12
|
+
import {
|
|
13
|
+
DirectiveScanViolations,
|
|
14
|
+
DisableDirective,
|
|
15
|
+
SourceFileUnreadable,
|
|
16
|
+
} from "./disable-directive-errors.ts";
|
|
17
|
+
|
|
18
|
+
export const disableDirectivesIn = (file: string, directory = ".") =>
|
|
19
|
+
Effect.gen(function* () {
|
|
20
|
+
const fileSystem = yield* FileSystem.FileSystem;
|
|
21
|
+
const path = yield* Path.Path;
|
|
22
|
+
const text = yield* fileSystem
|
|
23
|
+
.readFileString(path.isAbsolute(file) ? file : path.join(directory, file))
|
|
24
|
+
.pipe(Effect.mapError((error) => new SourceFileUnreadable({ file, reason: error.message })));
|
|
25
|
+
const parsed = parseSync(file, text);
|
|
26
|
+
if (parsed.errors.length > 0) {
|
|
27
|
+
return parsed.errors.map(
|
|
28
|
+
(error) => new SourceFileUnparsable({ file, reason: error.message }),
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
return parsed.comments
|
|
32
|
+
.filter((comment) => isDirective(comment.value))
|
|
33
|
+
.map(
|
|
34
|
+
(comment) =>
|
|
35
|
+
new DisableDirective({
|
|
36
|
+
file,
|
|
37
|
+
line: lineNumberAt(text, comment.start),
|
|
38
|
+
directive: comment.value.trim(),
|
|
39
|
+
}),
|
|
40
|
+
);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
export const findDisableDirectivesInLintedFilesOf = (directory: string) =>
|
|
44
|
+
Effect.gen(function* () {
|
|
45
|
+
const path = yield* Path.Path;
|
|
46
|
+
const isFormatConfigRefused = yield* isFormatConfigTextRefusedIn(directory);
|
|
47
|
+
const files = (yield* lintedFiles(path.join(directory, TYPESCRIPT_PROJECT_FILE))).filter(
|
|
48
|
+
(file) => !isFormatConfigRefused || file !== FORMAT_CONFIG_FILE,
|
|
49
|
+
);
|
|
50
|
+
const scans = yield* Effect.forEach(
|
|
51
|
+
files,
|
|
52
|
+
(file) =>
|
|
53
|
+
disableDirectivesIn(file, directory).pipe(
|
|
54
|
+
Effect.map(Result.succeed),
|
|
55
|
+
Effect.catchTag("SourceFileUnreadable", (unscanned) =>
|
|
56
|
+
Effect.succeed(Result.fail(unscanned)),
|
|
57
|
+
),
|
|
58
|
+
),
|
|
59
|
+
{ concurrency: "unbounded" },
|
|
60
|
+
);
|
|
61
|
+
const [directivesByFile, unscannedFiles] = Arrays.separate(scans);
|
|
62
|
+
const violations = [...unscannedFiles, ...Arrays.flatten(directivesByFile)];
|
|
63
|
+
if (violations.length > 0) {
|
|
64
|
+
return yield* new DirectiveScanViolations({ violations });
|
|
65
|
+
}
|
|
66
|
+
}).pipe(quietViolations("directives"));
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { findErrorMappingsToDone } from "./internal/find-error-mappings-to-done.ts";
|
package/src/lib/tasks/lib/refuse-error-mappings-that-end-streams/internal/error-mapping-errors.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Schema } from "effect";
|
|
2
|
+
|
|
3
|
+
import { listedViolations } from "../../../../../shared/format-reported-failures.ts";
|
|
4
|
+
|
|
5
|
+
export class ErrorMappedToDone extends Schema.TaggedError<ErrorMappedToDone>()(
|
|
6
|
+
"ErrorMappedToDone",
|
|
7
|
+
{ location: Schema.String, operation: Schema.String },
|
|
8
|
+
) {
|
|
9
|
+
public override get message() {
|
|
10
|
+
return `${this.operation} can map a failure to Cause.Done, which ends a stream as if it completed`;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export class ErrorMappingsRefused extends Schema.TaggedError<ErrorMappingsRefused>()(
|
|
15
|
+
"ErrorMappingsRefused",
|
|
16
|
+
{ violations: Schema.Array(ErrorMappedToDone) },
|
|
17
|
+
) {
|
|
18
|
+
public override get message() {
|
|
19
|
+
return listedViolations(this.violations);
|
|
20
|
+
}
|
|
21
|
+
}
|