@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.
- 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 +848 -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,135 @@
|
|
|
1
|
+
import { Effect, Path } from "effect";
|
|
2
|
+
import type { Cause } from "effect";
|
|
3
|
+
import type { SourceFile } from "typescript/unstable/ast";
|
|
4
|
+
import { SignatureKind } from "typescript/unstable/async";
|
|
5
|
+
import type { Checker, Type } from "typescript/unstable/async";
|
|
6
|
+
|
|
7
|
+
import {
|
|
8
|
+
CONCURRENT_TYPESCRIPT_REQUESTS,
|
|
9
|
+
nodePosition,
|
|
10
|
+
packageCalleesIn,
|
|
11
|
+
requiredTypeScriptRequest,
|
|
12
|
+
typeScriptRequest,
|
|
13
|
+
} from "../../../shared/query-the-typescript-project.ts";
|
|
14
|
+
import type { openTypeScriptProjects } from "../../../shared/query-the-typescript-project.ts";
|
|
15
|
+
import { absolutePathOf } from "../../../shared/resolve-absolute-paths.ts";
|
|
16
|
+
import { ErrorMappedToDone, ErrorMappingsRefused } from "./error-mapping-errors.ts";
|
|
17
|
+
|
|
18
|
+
const DONE_TYPE_ID = "~effect/Cause/Done" satisfies keyof Cause.Done;
|
|
19
|
+
const FAILURE_HANDLER = "onFailure";
|
|
20
|
+
const ERROR_MAPPINGS = new Set(["mapError", "mapErrorEager"]);
|
|
21
|
+
const BOTH_MAPPINGS = new Set(["mapBoth", "mapBothEager"]);
|
|
22
|
+
const MODULE_OF_DECLARATION_FILE = new Map([
|
|
23
|
+
["effect/dist/effect.d.ts", "Effect"],
|
|
24
|
+
["effect/dist/stream.d.ts", "Stream"],
|
|
25
|
+
["effect/dist/channel.d.ts", "Channel"],
|
|
26
|
+
["effect/dist/sink.d.ts", "Sink"],
|
|
27
|
+
]);
|
|
28
|
+
|
|
29
|
+
const typeMembers = (type: Type) =>
|
|
30
|
+
type.isUnionType()
|
|
31
|
+
? typeScriptRequest("read union members", () => type.getTypes())
|
|
32
|
+
: Effect.succeed([type]);
|
|
33
|
+
|
|
34
|
+
const canBeDone = (checker: Checker, type: Type) =>
|
|
35
|
+
typeMembers(type).pipe(
|
|
36
|
+
Effect.flatMap((members) =>
|
|
37
|
+
Effect.forEach(members, (member) =>
|
|
38
|
+
typeScriptRequest("read the Done type id", () =>
|
|
39
|
+
checker.getPropertyOfType(member, DONE_TYPE_ID),
|
|
40
|
+
),
|
|
41
|
+
),
|
|
42
|
+
),
|
|
43
|
+
Effect.map((properties) => properties.some((property) => property !== undefined)),
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
const returnsDone = (checker: Checker, mapping: Type) =>
|
|
47
|
+
Effect.gen(function* () {
|
|
48
|
+
const signatures = yield* typeScriptRequest("read the mapping's signatures", () =>
|
|
49
|
+
checker.getSignaturesOfType(mapping, SignatureKind.Call),
|
|
50
|
+
);
|
|
51
|
+
const returned = yield* Effect.forEach(signatures, (signature) =>
|
|
52
|
+
requiredTypeScriptRequest("read the mapping's return type", () =>
|
|
53
|
+
checker.getReturnTypeOfSignature(signature),
|
|
54
|
+
).pipe(Effect.flatMap((type) => canBeDone(checker, type))),
|
|
55
|
+
);
|
|
56
|
+
return returned.some(Boolean);
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
const failureMappingOf = (checker: Checker, argument: Type, name: string) =>
|
|
60
|
+
Effect.gen(function* () {
|
|
61
|
+
if (!BOTH_MAPPINGS.has(name)) {
|
|
62
|
+
return argument;
|
|
63
|
+
}
|
|
64
|
+
const handler = yield* typeScriptRequest("read the onFailure handler", () =>
|
|
65
|
+
checker.getPropertyOfType(argument, FAILURE_HANDLER),
|
|
66
|
+
);
|
|
67
|
+
return handler === undefined
|
|
68
|
+
? undefined
|
|
69
|
+
: yield* typeScriptRequest("read the onFailure handler's type", () =>
|
|
70
|
+
checker.getTypeOfSymbol(handler),
|
|
71
|
+
);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
const fileViolations = (
|
|
75
|
+
checker: Checker,
|
|
76
|
+
projectDirectory: string,
|
|
77
|
+
sourceFile: SourceFile,
|
|
78
|
+
displayName: string,
|
|
79
|
+
) =>
|
|
80
|
+
Effect.gen(function* () {
|
|
81
|
+
const callees = yield* packageCalleesIn(checker, projectDirectory, sourceFile);
|
|
82
|
+
const mappings = callees.flatMap(({ call, file, name }) => {
|
|
83
|
+
const moduleName = MODULE_OF_DECLARATION_FILE.get(file);
|
|
84
|
+
const isMapping = ERROR_MAPPINGS.has(name) || BOTH_MAPPINGS.has(name);
|
|
85
|
+
const mapping = call.arguments.at(-1);
|
|
86
|
+
const isEffectMapping = moduleName !== undefined && isMapping && mapping !== undefined;
|
|
87
|
+
return isEffectMapping ? [{ call, mapping, name, operation: `${moduleName}.${name}` }] : [];
|
|
88
|
+
});
|
|
89
|
+
const violations = yield* Effect.forEach(
|
|
90
|
+
mappings,
|
|
91
|
+
({ call, mapping, name, operation }) =>
|
|
92
|
+
Effect.gen(function* () {
|
|
93
|
+
const argument = yield* typeScriptRequest("read the mapping's type", () =>
|
|
94
|
+
checker.getTypeAtLocation(mapping),
|
|
95
|
+
);
|
|
96
|
+
const failureMapping =
|
|
97
|
+
argument === undefined ? undefined : yield* failureMappingOf(checker, argument, name);
|
|
98
|
+
const mapsToDone =
|
|
99
|
+
failureMapping !== undefined && (yield* returnsDone(checker, failureMapping));
|
|
100
|
+
if (!mapsToDone) {
|
|
101
|
+
return [];
|
|
102
|
+
}
|
|
103
|
+
const { line, column } = nodePosition(sourceFile, call);
|
|
104
|
+
return [
|
|
105
|
+
new ErrorMappedToDone({ location: `${displayName}:${line}:${column}`, operation }),
|
|
106
|
+
];
|
|
107
|
+
}),
|
|
108
|
+
{ concurrency: CONCURRENT_TYPESCRIPT_REQUESTS },
|
|
109
|
+
);
|
|
110
|
+
return violations.flat();
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
export const findErrorMappingsToDone = <OpeningError, OpeningRequirement>(
|
|
114
|
+
projectFile: string,
|
|
115
|
+
openedProjects: Effect.Effect<
|
|
116
|
+
Effect.Success<ReturnType<typeof openTypeScriptProjects>>,
|
|
117
|
+
OpeningError,
|
|
118
|
+
OpeningRequirement
|
|
119
|
+
>,
|
|
120
|
+
) =>
|
|
121
|
+
Effect.gen(function* () {
|
|
122
|
+
const path = yield* Path.Path;
|
|
123
|
+
const projectDirectory = path.dirname(yield* absolutePathOf(projectFile));
|
|
124
|
+
const violations: ErrorMappedToDone[] = [];
|
|
125
|
+
for (const { checker, sourceFiles } of yield* openedProjects) {
|
|
126
|
+
for (const { sourceFile, displayName } of sourceFiles) {
|
|
127
|
+
violations.push(
|
|
128
|
+
...(yield* fileViolations(checker, projectDirectory, sourceFile, displayName)),
|
|
129
|
+
);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
if (violations.length > 0) {
|
|
133
|
+
return yield* new ErrorMappingsRefused({ violations });
|
|
134
|
+
}
|
|
135
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { findServiceLayerViolations } from "./internal/find-service-layer-violations.ts";
|
package/src/lib/tasks/lib/require-separate-service-layers/internal/find-service-layer-violations.ts
ADDED
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
import { Effect } from "effect";
|
|
2
|
+
import type { Layer } from "effect";
|
|
3
|
+
import { SyntaxKind } from "typescript/unstable/ast";
|
|
4
|
+
import type { Node, SourceFile } from "typescript/unstable/ast";
|
|
5
|
+
import {
|
|
6
|
+
isBinaryExpression,
|
|
7
|
+
isClassDeclaration,
|
|
8
|
+
isClassExpression,
|
|
9
|
+
isElementAccessExpression,
|
|
10
|
+
isGetAccessorDeclaration,
|
|
11
|
+
isMethodDeclaration,
|
|
12
|
+
isPropertyAccessExpression,
|
|
13
|
+
isPropertyDeclaration,
|
|
14
|
+
isStaticKeyword,
|
|
15
|
+
} from "typescript/unstable/ast/is";
|
|
16
|
+
import { SignatureKind } from "typescript/unstable/async";
|
|
17
|
+
import type { Checker, Type } from "typescript/unstable/async";
|
|
18
|
+
|
|
19
|
+
import {
|
|
20
|
+
CONCURRENT_TYPESCRIPT_REQUESTS,
|
|
21
|
+
nodePosition,
|
|
22
|
+
requiredTypeScriptRequest,
|
|
23
|
+
resolvedSymbols,
|
|
24
|
+
typeScriptRequest,
|
|
25
|
+
} from "../../../shared/query-the-typescript-project.ts";
|
|
26
|
+
import type { openTypeScriptProjects } from "../../../shared/query-the-typescript-project.ts";
|
|
27
|
+
import { ServiceLayerNotSeparate, ServiceLayersRefused } from "./service-layer-errors.ts";
|
|
28
|
+
|
|
29
|
+
const LAYER_TYPE_ID = "~effect/Layer" satisfies keyof Layer.Any;
|
|
30
|
+
const SERVICE_TYPE_ID = "~effect/Context/Service";
|
|
31
|
+
const LAYER_ASSIGNMENTS = new Set([
|
|
32
|
+
SyntaxKind.EqualsToken,
|
|
33
|
+
SyntaxKind.QuestionQuestionEqualsToken,
|
|
34
|
+
SyntaxKind.BarBarEqualsToken,
|
|
35
|
+
SyntaxKind.AmpersandAmpersandEqualsToken,
|
|
36
|
+
]);
|
|
37
|
+
|
|
38
|
+
const typeMembers = (type: Type) =>
|
|
39
|
+
type.isUnionType()
|
|
40
|
+
? typeScriptRequest("read union members", () => type.getTypes())
|
|
41
|
+
: Effect.succeed([type]);
|
|
42
|
+
|
|
43
|
+
const hasTypeProperty = (checker: Checker, type: Type, name: string) =>
|
|
44
|
+
typeScriptRequest("read a service layer property", () =>
|
|
45
|
+
checker.getPropertyOfType(type, name),
|
|
46
|
+
).pipe(Effect.map((property) => property !== undefined));
|
|
47
|
+
|
|
48
|
+
const isLayerType = (checker: Checker, type: Type) =>
|
|
49
|
+
typeMembers(type).pipe(
|
|
50
|
+
Effect.flatMap((members) =>
|
|
51
|
+
Effect.forEach(members, (member) => hasTypeProperty(checker, member, LAYER_TYPE_ID)),
|
|
52
|
+
),
|
|
53
|
+
Effect.map((layers) => layers.some(Boolean)),
|
|
54
|
+
);
|
|
55
|
+
|
|
56
|
+
const isLayerOrFactory = (checker: Checker, type: Type) =>
|
|
57
|
+
Effect.gen(function* () {
|
|
58
|
+
const members = yield* typeMembers(type);
|
|
59
|
+
const matches = yield* Effect.forEach(members, (member) =>
|
|
60
|
+
Effect.gen(function* () {
|
|
61
|
+
if (yield* isLayerType(checker, member)) {
|
|
62
|
+
return true;
|
|
63
|
+
}
|
|
64
|
+
const signatures = yield* typeScriptRequest("read layer factory signatures", () =>
|
|
65
|
+
checker.getSignaturesOfType(member, SignatureKind.Call),
|
|
66
|
+
);
|
|
67
|
+
const returnsLayer = yield* Effect.forEach(signatures, (signature) =>
|
|
68
|
+
requiredTypeScriptRequest("read a layer factory return type", () =>
|
|
69
|
+
checker.getReturnTypeOfSignature(signature),
|
|
70
|
+
).pipe(Effect.flatMap((returned) => isLayerType(checker, returned))),
|
|
71
|
+
);
|
|
72
|
+
return returnsLayer.some(Boolean);
|
|
73
|
+
}),
|
|
74
|
+
);
|
|
75
|
+
return matches.some(Boolean);
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
const candidatesIn = (sourceFile: SourceFile) => {
|
|
79
|
+
const candidates: {
|
|
80
|
+
readonly node: Node;
|
|
81
|
+
readonly value: Node;
|
|
82
|
+
readonly owner: Node;
|
|
83
|
+
}[] = [];
|
|
84
|
+
const visit = (node: Node) => {
|
|
85
|
+
const isClassMember =
|
|
86
|
+
(isPropertyDeclaration(node) ||
|
|
87
|
+
isMethodDeclaration(node) ||
|
|
88
|
+
isGetAccessorDeclaration(node)) &&
|
|
89
|
+
node.modifiers?.some(isStaticKeyword) === true;
|
|
90
|
+
const parent = node.parent;
|
|
91
|
+
const isServiceMemberCandidate =
|
|
92
|
+
isClassMember &&
|
|
93
|
+
(isClassDeclaration(parent) || isClassExpression(parent)) &&
|
|
94
|
+
parent.name !== undefined;
|
|
95
|
+
if (isServiceMemberCandidate) {
|
|
96
|
+
candidates.push({ node, value: node.name, owner: parent.name });
|
|
97
|
+
}
|
|
98
|
+
const isAssignment = isBinaryExpression(node) && LAYER_ASSIGNMENTS.has(node.operatorToken.kind);
|
|
99
|
+
const isPropertyAssignment =
|
|
100
|
+
isAssignment &&
|
|
101
|
+
(isPropertyAccessExpression(node.left) || isElementAccessExpression(node.left));
|
|
102
|
+
if (isPropertyAssignment) {
|
|
103
|
+
candidates.push({ node, value: node.right, owner: node.left.expression });
|
|
104
|
+
}
|
|
105
|
+
node.forEachChild(visit);
|
|
106
|
+
};
|
|
107
|
+
sourceFile.forEachChild(visit);
|
|
108
|
+
return candidates;
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
const fileViolations = (checker: Checker, sourceFile: SourceFile, displayName: string) =>
|
|
112
|
+
Effect.gen(function* () {
|
|
113
|
+
const violations = yield* Effect.forEach(
|
|
114
|
+
candidatesIn(sourceFile),
|
|
115
|
+
(candidate) =>
|
|
116
|
+
Effect.gen(function* () {
|
|
117
|
+
const [symbol] = yield* resolvedSymbols(checker, [candidate.owner]);
|
|
118
|
+
if (symbol === undefined) {
|
|
119
|
+
return [];
|
|
120
|
+
}
|
|
121
|
+
const ownerType = yield* typeScriptRequest("read a possible service class", () =>
|
|
122
|
+
checker.getTypeOfSymbol(symbol),
|
|
123
|
+
);
|
|
124
|
+
if (ownerType === undefined) {
|
|
125
|
+
return [];
|
|
126
|
+
}
|
|
127
|
+
if (!(yield* hasTypeProperty(checker, ownerType, SERVICE_TYPE_ID))) {
|
|
128
|
+
return [];
|
|
129
|
+
}
|
|
130
|
+
const type = yield* typeScriptRequest("read a possible service layer", () =>
|
|
131
|
+
checker.getTypeAtLocation(candidate.value),
|
|
132
|
+
);
|
|
133
|
+
if (type === undefined) {
|
|
134
|
+
return [];
|
|
135
|
+
}
|
|
136
|
+
if (!(yield* isLayerOrFactory(checker, type))) {
|
|
137
|
+
return [];
|
|
138
|
+
}
|
|
139
|
+
const { line, column } = nodePosition(sourceFile, candidate.node);
|
|
140
|
+
return [
|
|
141
|
+
new ServiceLayerNotSeparate({
|
|
142
|
+
location: `${displayName}:${line}:${column}`,
|
|
143
|
+
service: symbol.name,
|
|
144
|
+
}),
|
|
145
|
+
];
|
|
146
|
+
}),
|
|
147
|
+
{ concurrency: CONCURRENT_TYPESCRIPT_REQUESTS },
|
|
148
|
+
);
|
|
149
|
+
return violations.flat();
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
export const findServiceLayerViolations = <OpeningError, OpeningRequirement>(
|
|
153
|
+
_projectFile: string,
|
|
154
|
+
openedProjects: Effect.Effect<
|
|
155
|
+
Effect.Success<ReturnType<typeof openTypeScriptProjects>>,
|
|
156
|
+
OpeningError,
|
|
157
|
+
OpeningRequirement
|
|
158
|
+
>,
|
|
159
|
+
) =>
|
|
160
|
+
Effect.gen(function* () {
|
|
161
|
+
const violations: ServiceLayerNotSeparate[] = [];
|
|
162
|
+
for (const { checker, sourceFiles } of yield* openedProjects) {
|
|
163
|
+
for (const { sourceFile, displayName } of sourceFiles) {
|
|
164
|
+
violations.push(...(yield* fileViolations(checker, sourceFile, displayName)));
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
if (violations.length > 0) {
|
|
168
|
+
return yield* new ServiceLayersRefused({ violations });
|
|
169
|
+
}
|
|
170
|
+
});
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Schema } from "effect";
|
|
2
|
+
|
|
3
|
+
import { listedViolations } from "../../../../../shared/format-reported-failures.ts";
|
|
4
|
+
|
|
5
|
+
export class ServiceLayerNotSeparate extends Schema.TaggedError<ServiceLayerNotSeparate>()(
|
|
6
|
+
"ServiceLayerNotSeparate",
|
|
7
|
+
{ location: Schema.String, service: Schema.String },
|
|
8
|
+
) {
|
|
9
|
+
public override get message() {
|
|
10
|
+
return `${this.service}'s layer is inside the service class`;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export class ServiceLayersRefused extends Schema.TaggedError<ServiceLayersRefused>()(
|
|
15
|
+
"ServiceLayersRefused",
|
|
16
|
+
{ violations: Schema.Array(ServiceLayerNotSeparate) },
|
|
17
|
+
) {
|
|
18
|
+
public override get message() {
|
|
19
|
+
return listedViolations(this.violations);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Task } from "@sshkeda/task";
|
|
2
|
+
import { Effect } from "effect";
|
|
3
|
+
|
|
4
|
+
import { lintConfigFile } from "../../shared/declare-lint-config-task.ts";
|
|
5
|
+
import { typeScriptConfig } from "../../shared/declare-typescript-config-task.ts";
|
|
6
|
+
import { lintedFilesNotTypeCheckedInEachPackage } from "./internal/find-linted-files-not-type-checked.ts";
|
|
7
|
+
|
|
8
|
+
export const lintedFilesTypeChecked = Task.make(
|
|
9
|
+
"linted-files-type-checked",
|
|
10
|
+
Effect.andThen(
|
|
11
|
+
Task.all([typeScriptConfig, lintConfigFile]),
|
|
12
|
+
lintedFilesNotTypeCheckedInEachPackage,
|
|
13
|
+
),
|
|
14
|
+
);
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { Effect, FileSystem, Path, Schema } from "effect";
|
|
2
|
+
import { ScriptKind } from "typescript/unstable/ast";
|
|
3
|
+
|
|
4
|
+
import { inEachPackage } from "../../../shared/check-each-nested-package.ts";
|
|
5
|
+
import { isDeclarationFile } from "../../../shared/classify-files-by-role.ts";
|
|
6
|
+
import { scriptFiles } from "../../../shared/list-linted-files.ts";
|
|
7
|
+
import { ownedFilesAmong } from "../../../shared/list-owned-files.ts";
|
|
8
|
+
import { quietViolations } from "../../../shared/print-failures-and-keep-detail-in-the-trace.ts";
|
|
9
|
+
import {
|
|
10
|
+
effectiveCompilerOptions,
|
|
11
|
+
packageSourceFilesOfEachProject,
|
|
12
|
+
TYPESCRIPT_PROJECT_FILE,
|
|
13
|
+
} from "../../../shared/query-the-typescript-project.ts";
|
|
14
|
+
import {
|
|
15
|
+
LintedDeclarationFileNotTypeChecked,
|
|
16
|
+
LintedFileOutsideTypeScriptProgram,
|
|
17
|
+
LintedFilesNotTypeChecked,
|
|
18
|
+
LintedJavaScriptFileNotTypeChecked,
|
|
19
|
+
} from "./linted-file-errors.ts";
|
|
20
|
+
|
|
21
|
+
const OPTIONS_THAT_SKIP_FILES = Schema.Struct({
|
|
22
|
+
checkJs: Schema.optionalKey(Schema.Boolean),
|
|
23
|
+
skipLibCheck: Schema.optionalKey(Schema.Boolean),
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
const JAVASCRIPT_SCRIPT_KINDS = new Set([ScriptKind.JS, ScriptKind.JSX]);
|
|
27
|
+
|
|
28
|
+
const isTypeChecked = (
|
|
29
|
+
sourceFile: { readonly isDeclarationFile: boolean; readonly scriptKind: ScriptKind },
|
|
30
|
+
options: typeof OPTIONS_THAT_SKIP_FILES.Type,
|
|
31
|
+
) =>
|
|
32
|
+
sourceFile.isDeclarationFile
|
|
33
|
+
? options.skipLibCheck !== true
|
|
34
|
+
: !JAVASCRIPT_SCRIPT_KINDS.has(sourceFile.scriptKind) || options.checkJs === true;
|
|
35
|
+
|
|
36
|
+
const realPathOf = (file: string) =>
|
|
37
|
+
FileSystem.FileSystem.use((fileSystem) => fileSystem.realPath(file));
|
|
38
|
+
|
|
39
|
+
const violationFor = (
|
|
40
|
+
file: string,
|
|
41
|
+
projectFile: string,
|
|
42
|
+
compilingProjects: readonly {
|
|
43
|
+
readonly configFile: string;
|
|
44
|
+
readonly isDeclarationFile: boolean;
|
|
45
|
+
}[],
|
|
46
|
+
) => {
|
|
47
|
+
const [firstProject] = compilingProjects;
|
|
48
|
+
if (firstProject === undefined) {
|
|
49
|
+
return new LintedFileOutsideTypeScriptProgram({ location: file, projectFile });
|
|
50
|
+
}
|
|
51
|
+
const configFiles = compilingProjects.map(({ configFile }) => configFile);
|
|
52
|
+
return firstProject.isDeclarationFile
|
|
53
|
+
? new LintedDeclarationFileNotTypeChecked({ location: file, configFiles })
|
|
54
|
+
: new LintedJavaScriptFileNotTypeChecked({ location: file, configFiles });
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
export const findLintedFilesNotTypeChecked = (projectFile: string) =>
|
|
58
|
+
Effect.gen(function* () {
|
|
59
|
+
const path = yield* Path.Path;
|
|
60
|
+
const linted = yield* scriptFiles(projectFile);
|
|
61
|
+
const owned = new Set(yield* ownedFilesAmong(path.dirname(projectFile), linted));
|
|
62
|
+
const compilations = (yield* Effect.forEach(
|
|
63
|
+
yield* packageSourceFilesOfEachProject(projectFile),
|
|
64
|
+
({ configFile, sourceFiles }) =>
|
|
65
|
+
Effect.gen(function* () {
|
|
66
|
+
const options = yield* effectiveCompilerOptions(configFile).pipe(
|
|
67
|
+
Effect.flatMap(Schema.decodeUnknownEffect(OPTIONS_THAT_SKIP_FILES)),
|
|
68
|
+
);
|
|
69
|
+
return yield* Effect.forEach(
|
|
70
|
+
sourceFiles,
|
|
71
|
+
([file, sourceFile]) =>
|
|
72
|
+
realPathOf(path.join(path.dirname(projectFile), file)).pipe(
|
|
73
|
+
Effect.map((realFile) => ({
|
|
74
|
+
realFile,
|
|
75
|
+
configFile,
|
|
76
|
+
isDeclarationFile: sourceFile.isDeclarationFile,
|
|
77
|
+
typeChecked: isTypeChecked(sourceFile, options),
|
|
78
|
+
})),
|
|
79
|
+
),
|
|
80
|
+
{ concurrency: "unbounded" },
|
|
81
|
+
);
|
|
82
|
+
}),
|
|
83
|
+
)).flat();
|
|
84
|
+
const lintedRealFiles = yield* Effect.forEach(
|
|
85
|
+
linted,
|
|
86
|
+
(file) =>
|
|
87
|
+
realPathOf(path.join(path.dirname(projectFile), file)).pipe(
|
|
88
|
+
Effect.map((realFile) => ({ file, realFile })),
|
|
89
|
+
),
|
|
90
|
+
{ concurrency: "unbounded" },
|
|
91
|
+
);
|
|
92
|
+
const violations = lintedRealFiles.flatMap(({ file, realFile }) => {
|
|
93
|
+
const compiling = compilations.filter((compilation) => compilation.realFile === realFile);
|
|
94
|
+
const isGeneratedDeclarationFile =
|
|
95
|
+
!owned.has(file) &&
|
|
96
|
+
(isDeclarationFile(file) || compiling.some((compilation) => compilation.isDeclarationFile));
|
|
97
|
+
const isTypeCheckedOrExempt =
|
|
98
|
+
isGeneratedDeclarationFile || compiling.some(({ typeChecked }) => typeChecked);
|
|
99
|
+
return isTypeCheckedOrExempt ? [] : [violationFor(file, projectFile, compiling)];
|
|
100
|
+
});
|
|
101
|
+
if (violations.length > 0) {
|
|
102
|
+
return yield* new LintedFilesNotTypeChecked({ violations });
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
const LINTED_FILES_TYPE_CHECKED = "linted-files-type-checked";
|
|
107
|
+
|
|
108
|
+
export const lintedFilesNotTypeCheckedInEachPackage = inEachPackage(
|
|
109
|
+
LINTED_FILES_TYPE_CHECKED,
|
|
110
|
+
".",
|
|
111
|
+
(packageDirectory) =>
|
|
112
|
+
Path.Path.use((path) =>
|
|
113
|
+
findLintedFilesNotTypeChecked(path.join(packageDirectory, TYPESCRIPT_PROJECT_FILE)).pipe(
|
|
114
|
+
quietViolations(LINTED_FILES_TYPE_CHECKED),
|
|
115
|
+
),
|
|
116
|
+
),
|
|
117
|
+
);
|
package/src/lib/tasks/lib/require-type-checking-every-linted-file/internal/linted-file-errors.ts
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { Schema } from "effect";
|
|
2
|
+
|
|
3
|
+
import { listedViolations } from "../../../../../shared/format-reported-failures.ts";
|
|
4
|
+
import { joinedWithAnd } from "../../../shared/classify-files-by-role.ts";
|
|
5
|
+
|
|
6
|
+
const compilingConfigFiles = (configFiles: readonly string[]) =>
|
|
7
|
+
`${joinedWithAnd(configFiles)} ${configFiles.length === 1 ? "compiles" : "compile"}`;
|
|
8
|
+
|
|
9
|
+
export class LintedFileOutsideTypeScriptProgram extends Schema.TaggedError<LintedFileOutsideTypeScriptProgram>()(
|
|
10
|
+
"LintedFileOutsideTypeScriptProgram",
|
|
11
|
+
{ location: Schema.String, projectFile: Schema.String },
|
|
12
|
+
) {
|
|
13
|
+
public override get message() {
|
|
14
|
+
return `must be type-checked, but no program of ${this.projectFile} compiles it`;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export class LintedJavaScriptFileNotTypeChecked extends Schema.TaggedError<LintedJavaScriptFileNotTypeChecked>()(
|
|
19
|
+
"LintedJavaScriptFileNotTypeChecked",
|
|
20
|
+
{ location: Schema.String, configFiles: Schema.Array(Schema.String) },
|
|
21
|
+
) {
|
|
22
|
+
public override get message() {
|
|
23
|
+
return `must be type-checked, but ${compilingConfigFiles(this.configFiles)} it without checking JavaScript`;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export class LintedDeclarationFileNotTypeChecked extends Schema.TaggedError<LintedDeclarationFileNotTypeChecked>()(
|
|
28
|
+
"LintedDeclarationFileNotTypeChecked",
|
|
29
|
+
{ location: Schema.String, configFiles: Schema.Array(Schema.String) },
|
|
30
|
+
) {
|
|
31
|
+
public override get message() {
|
|
32
|
+
return `must be type-checked, but ${compilingConfigFiles(this.configFiles)} it without checking declaration files`;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export class LintedFilesNotTypeChecked extends Schema.TaggedError<LintedFilesNotTypeChecked>()(
|
|
37
|
+
"LintedFilesNotTypeChecked",
|
|
38
|
+
{
|
|
39
|
+
violations: Schema.Array(
|
|
40
|
+
Schema.Union([
|
|
41
|
+
LintedFileOutsideTypeScriptProgram,
|
|
42
|
+
LintedJavaScriptFileNotTypeChecked,
|
|
43
|
+
LintedDeclarationFileNotTypeChecked,
|
|
44
|
+
]),
|
|
45
|
+
),
|
|
46
|
+
},
|
|
47
|
+
) {
|
|
48
|
+
public override get message() {
|
|
49
|
+
return listedViolations(this.violations);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Task } from "@sshkeda/task";
|
|
2
|
+
import { Effect } from "effect";
|
|
3
|
+
|
|
4
|
+
import { inEachPackage } from "../../shared/check-each-nested-package.ts";
|
|
5
|
+
import { typeScriptConfig } from "../../shared/declare-typescript-config-task.ts";
|
|
6
|
+
import { checkTypesWithBunCheckIn } from "./internal/check-types-with-bun-check.ts";
|
|
7
|
+
|
|
8
|
+
export const typeCheck = Task.make(
|
|
9
|
+
"type-check",
|
|
10
|
+
Effect.andThen(typeScriptConfig, inEachPackage("type-check", ".", checkTypesWithBunCheckIn)),
|
|
11
|
+
);
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { Effect, FileSystem, Path } from "effect";
|
|
2
|
+
|
|
3
|
+
import { PACKAGE_MANIFEST_FILE } from "../../../shared/find-named-package-manifests.ts";
|
|
4
|
+
import { isFormatConfigTextRefusedIn } from "../../../shared/parse-config-files-that-import-from-check.ts";
|
|
5
|
+
import { quietToolFailure } from "../../../shared/print-failures-and-keep-detail-in-the-trace.ts";
|
|
6
|
+
import { TYPESCRIPT_PROJECT_FILE } from "../../../shared/query-the-typescript-project.ts";
|
|
7
|
+
import { absolutePathOf } from "../../../shared/resolve-absolute-paths.ts";
|
|
8
|
+
import { runTool } from "../../../shared/run-tools-and-decode-their-reports.ts";
|
|
9
|
+
import { typeCheckReport } from "./read-bun-check-output.ts";
|
|
10
|
+
|
|
11
|
+
const BUN = "bun";
|
|
12
|
+
const EMPTY_PACKAGE_MANIFEST = "{}\n";
|
|
13
|
+
|
|
14
|
+
const typeCheckRun = (directory: string, isFormatConfigRefused: boolean) =>
|
|
15
|
+
Effect.gen(function* () {
|
|
16
|
+
const fileSystem = yield* FileSystem.FileSystem;
|
|
17
|
+
const path = yield* Path.Path;
|
|
18
|
+
const directoryWithoutPackageScripts = yield* fileSystem.makeTempDirectoryScoped();
|
|
19
|
+
yield* fileSystem.writeFileString(
|
|
20
|
+
path.join(directoryWithoutPackageScripts, PACKAGE_MANIFEST_FILE),
|
|
21
|
+
EMPTY_PACKAGE_MANIFEST,
|
|
22
|
+
);
|
|
23
|
+
yield* runTool(
|
|
24
|
+
BUN,
|
|
25
|
+
BUN,
|
|
26
|
+
[
|
|
27
|
+
"check",
|
|
28
|
+
"--project",
|
|
29
|
+
TYPESCRIPT_PROJECT_FILE,
|
|
30
|
+
"--no-pretty",
|
|
31
|
+
"--all",
|
|
32
|
+
"--build",
|
|
33
|
+
`--cwd=${yield* absolutePathOf(directory)}`,
|
|
34
|
+
],
|
|
35
|
+
directoryWithoutPackageScripts,
|
|
36
|
+
).pipe(
|
|
37
|
+
Effect.catchTag("ToolExited", (exited) =>
|
|
38
|
+
typeCheckReport(exited.standardOutput, isFormatConfigRefused)
|
|
39
|
+
.reportsOnlyWhatTheFormatCheckReports
|
|
40
|
+
? Effect.void
|
|
41
|
+
: Effect.fail(exited),
|
|
42
|
+
),
|
|
43
|
+
);
|
|
44
|
+
}).pipe(
|
|
45
|
+
Effect.scoped,
|
|
46
|
+
quietToolFailure("type-check", (exited) =>
|
|
47
|
+
Effect.succeed(typeCheckReport(exited.standardOutput, isFormatConfigRefused)),
|
|
48
|
+
),
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
export const checkTypesWithBunCheckIn = (directory: string) =>
|
|
52
|
+
Effect.flatMap(isFormatConfigTextRefusedIn(directory), (isFormatConfigRefused) =>
|
|
53
|
+
typeCheckRun(directory, isFormatConfigRefused),
|
|
54
|
+
);
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import type { PrintableError } from "@sshkeda/task/errors";
|
|
2
|
+
|
|
3
|
+
import { FORMAT_CONFIG_FILE } from "../../../../../shared/config-file-names.ts";
|
|
4
|
+
import {
|
|
5
|
+
printableError,
|
|
6
|
+
printableErrorWith,
|
|
7
|
+
} from "../../../../../shared/format-reported-failures.ts";
|
|
8
|
+
import { linesOf } from "../../../shared/run-tools-and-decode-their-reports.ts";
|
|
9
|
+
import { TypeCheckLineUnrecognized } from "./type-check-errors.ts";
|
|
10
|
+
|
|
11
|
+
const LOCATED_TYPE_CHECK_VIOLATION =
|
|
12
|
+
/^(?<file>.+)\((?<line>\d+),(?<column>\d+)\): error (?<code>TS\d+): (?<message>.*)$/u;
|
|
13
|
+
const UNLOCATED_TYPE_CHECK_VIOLATION = /^error (?<code>TS\d+): (?<message>.*)$/u;
|
|
14
|
+
const CONTINUATION = /^\s+\S/u;
|
|
15
|
+
|
|
16
|
+
const readLine = (
|
|
17
|
+
read: { readonly violations: PrintableError[]; readonly continues: boolean },
|
|
18
|
+
line: string,
|
|
19
|
+
) => {
|
|
20
|
+
const [, file, lineNumber, columnNumber, locatedCode, locatedMessage] =
|
|
21
|
+
LOCATED_TYPE_CHECK_VIOLATION.exec(line) ?? [];
|
|
22
|
+
const [, unlocatedCode, unlocatedMessage] = UNLOCATED_TYPE_CHECK_VIOLATION.exec(line) ?? [];
|
|
23
|
+
const previous = read.violations.at(-1);
|
|
24
|
+
const isLocatedViolation =
|
|
25
|
+
file !== undefined &&
|
|
26
|
+
lineNumber !== undefined &&
|
|
27
|
+
columnNumber !== undefined &&
|
|
28
|
+
locatedCode !== undefined &&
|
|
29
|
+
locatedMessage !== undefined;
|
|
30
|
+
if (isLocatedViolation) {
|
|
31
|
+
read.violations.push({
|
|
32
|
+
tag: locatedCode,
|
|
33
|
+
location: `${file}:${lineNumber}:${columnNumber}`,
|
|
34
|
+
message: locatedMessage,
|
|
35
|
+
});
|
|
36
|
+
return { violations: read.violations, continues: true };
|
|
37
|
+
}
|
|
38
|
+
const isUnlocatedViolation = unlocatedCode !== undefined && unlocatedMessage !== undefined;
|
|
39
|
+
if (isUnlocatedViolation) {
|
|
40
|
+
read.violations.push({ tag: unlocatedCode, message: unlocatedMessage });
|
|
41
|
+
return { violations: read.violations, continues: true };
|
|
42
|
+
}
|
|
43
|
+
const continuesPreviousViolation =
|
|
44
|
+
read.continues && previous !== undefined && CONTINUATION.test(line);
|
|
45
|
+
if (continuesPreviousViolation) {
|
|
46
|
+
read.violations.splice(
|
|
47
|
+
-1,
|
|
48
|
+
1,
|
|
49
|
+
printableErrorWith(previous, { message: `${previous.message}\n${line.trim()}` }),
|
|
50
|
+
);
|
|
51
|
+
return { violations: read.violations, continues: true };
|
|
52
|
+
}
|
|
53
|
+
read.violations.push(printableError(new TypeCheckLineUnrecognized({ line })));
|
|
54
|
+
return { violations: read.violations, continues: false };
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
const isInTheFormatConfig = (violation: PrintableError) =>
|
|
58
|
+
violation.location?.startsWith(`${FORMAT_CONFIG_FILE}:`) === true;
|
|
59
|
+
|
|
60
|
+
export const typeCheckReport = (standardOutput: string, isFormatConfigRefused: boolean) => {
|
|
61
|
+
const read = { violations: new Array<PrintableError>(), continues: false };
|
|
62
|
+
for (const line of linesOf(standardOutput)) {
|
|
63
|
+
read.continues = readLine(read, line).continues;
|
|
64
|
+
}
|
|
65
|
+
const isReportedByTheFormatCheck = (violation: PrintableError) =>
|
|
66
|
+
isFormatConfigRefused && isInTheFormatConfig(violation);
|
|
67
|
+
return {
|
|
68
|
+
violations: read.violations.filter((violation) => !isReportedByTheFormatCheck(violation)),
|
|
69
|
+
reportsOnlyWhatTheFormatCheckReports:
|
|
70
|
+
read.violations.length > 0 && read.violations.every(isReportedByTheFormatCheck),
|
|
71
|
+
notes: [],
|
|
72
|
+
};
|
|
73
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Schema } from "effect";
|
|
2
|
+
|
|
3
|
+
export class TypeCheckLineUnrecognized extends Schema.TaggedError<TypeCheckLineUnrecognized>()(
|
|
4
|
+
"TypeCheckLineUnrecognized",
|
|
5
|
+
{ line: Schema.String },
|
|
6
|
+
) {
|
|
7
|
+
public override get message() {
|
|
8
|
+
return `type-check printed a line that is not a diagnostic or its continuation: ${this.line}`;
|
|
9
|
+
}
|
|
10
|
+
}
|