@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,152 @@
|
|
|
1
|
+
import { Array as Arrays, Effect, FileSystem, Path, Schema, Stream } from "effect";
|
|
2
|
+
import type { PlatformError } from "effect";
|
|
3
|
+
import { ChildProcess } from "effect/process";
|
|
4
|
+
|
|
5
|
+
import { printableError } from "../../../../../shared/format-reported-failures.ts";
|
|
6
|
+
import { encodeJson } from "../../../shared/encode-compact-json.ts";
|
|
7
|
+
import {
|
|
8
|
+
failQuietly,
|
|
9
|
+
quietToolFailure,
|
|
10
|
+
quietViolations,
|
|
11
|
+
} from "../../../shared/print-failures-and-keep-detail-in-the-trace.ts";
|
|
12
|
+
import {
|
|
13
|
+
ToolExited,
|
|
14
|
+
ToolReportedViolations,
|
|
15
|
+
ToolStoppedBySignal,
|
|
16
|
+
} from "../../../shared/project-config-and-tool-errors.ts";
|
|
17
|
+
import { tsgolintExecutable } from "./find-tsgolint-executable.ts";
|
|
18
|
+
import { EnumLintFailed, tsgolintRuleMessages } from "./read-tsgolint-rule-messages.ts";
|
|
19
|
+
|
|
20
|
+
const TSGOLINT = "tsgolint";
|
|
21
|
+
const HEADLESS_ARGUMENTS = ["headless"] as const;
|
|
22
|
+
const RULE_NAME = "no-unsafe-enum-assignment";
|
|
23
|
+
const PAYLOAD_VERSION = 2;
|
|
24
|
+
const STOPPING_SIGNAL = /signal:? '?(?<signal>SIG[A-Z0-9]+)/u;
|
|
25
|
+
|
|
26
|
+
const failureNamingTheSignal = (command: string, failure: PlatformError.PlatformError) => {
|
|
27
|
+
const described = `${failure.message}\n${String(failure.cause)}`;
|
|
28
|
+
const signal = STOPPING_SIGNAL.exec(described)?.groups?.["signal"];
|
|
29
|
+
return signal === undefined
|
|
30
|
+
? failure
|
|
31
|
+
: new ToolStoppedBySignal({ program: TSGOLINT, command, signal });
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
const decodedRuleMessages = (output: Buffer) =>
|
|
35
|
+
Effect.try({
|
|
36
|
+
try: () => tsgolintRuleMessages(output),
|
|
37
|
+
catch: (cause) =>
|
|
38
|
+
Schema.is(EnumLintFailed)(cause) ? cause : new EnumLintFailed({ reason: String(cause) }),
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
const errorsTsgolintReportedOnExit = (output: Buffer) =>
|
|
42
|
+
decodedRuleMessages(output).pipe(
|
|
43
|
+
Effect.as({ violations: [], notes: [] }),
|
|
44
|
+
Effect.catchTag("EnumLintFailed", (failed) =>
|
|
45
|
+
Effect.succeed({ violations: [printableError(failed)], notes: [] }),
|
|
46
|
+
),
|
|
47
|
+
);
|
|
48
|
+
|
|
49
|
+
const unsafeEnumViolationsIn = (
|
|
50
|
+
directory: string,
|
|
51
|
+
reports: ReturnType<typeof tsgolintRuleMessages>,
|
|
52
|
+
) =>
|
|
53
|
+
Effect.gen(function* () {
|
|
54
|
+
const path = yield* Path.Path;
|
|
55
|
+
const fileSystem = yield* FileSystem.FileSystem;
|
|
56
|
+
return yield* Effect.forEach(
|
|
57
|
+
reports.filter((report) => report.rule === RULE_NAME && report.file_path !== null),
|
|
58
|
+
(report) =>
|
|
59
|
+
Effect.gen(function* () {
|
|
60
|
+
const filename = report.file_path ?? "";
|
|
61
|
+
const source = yield* fileSystem.readFile(filename);
|
|
62
|
+
const preceding = Buffer.from(source)
|
|
63
|
+
.subarray(0, report.range?.pos ?? 0)
|
|
64
|
+
.toString("utf8");
|
|
65
|
+
const lines = preceding.split("\n");
|
|
66
|
+
const column = (lines.at(-1)?.length ?? 0) + 1;
|
|
67
|
+
return {
|
|
68
|
+
tag: `typescript(${RULE_NAME})`,
|
|
69
|
+
location: `${path.relative(directory, filename)}:${lines.length}:${column}`,
|
|
70
|
+
message: report.message.description,
|
|
71
|
+
};
|
|
72
|
+
}),
|
|
73
|
+
);
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
const ranTsgolint = (binary: string, directory: string, files: readonly string[]) =>
|
|
77
|
+
Effect.scoped(
|
|
78
|
+
Effect.gen(function* () {
|
|
79
|
+
const path = yield* Path.Path;
|
|
80
|
+
const command = [binary, ...HEADLESS_ARGUMENTS].join(" ");
|
|
81
|
+
const input = yield* encodeJson({
|
|
82
|
+
version: PAYLOAD_VERSION,
|
|
83
|
+
configs: [
|
|
84
|
+
{
|
|
85
|
+
file_paths: files.map((file) => path.resolve(directory, file)),
|
|
86
|
+
rules: [{ name: RULE_NAME }],
|
|
87
|
+
},
|
|
88
|
+
],
|
|
89
|
+
});
|
|
90
|
+
const child = yield* ChildProcess.make(binary, HEADLESS_ARGUMENTS, {
|
|
91
|
+
extendEnv: true,
|
|
92
|
+
stdin: Stream.make(Buffer.from(input)),
|
|
93
|
+
stderr: "pipe",
|
|
94
|
+
});
|
|
95
|
+
const [chunks, standardError, code] = yield* Effect.all(
|
|
96
|
+
[
|
|
97
|
+
Stream.runCollect(child.stdout),
|
|
98
|
+
Stream.mkString(Stream.decodeText(child.stderr)),
|
|
99
|
+
child.exitCode.pipe(
|
|
100
|
+
Effect.mapError((failure) => failureNamingTheSignal(command, failure)),
|
|
101
|
+
),
|
|
102
|
+
],
|
|
103
|
+
{ concurrency: "unbounded" },
|
|
104
|
+
);
|
|
105
|
+
return { command, code, output: Buffer.concat(chunks), standardError: standardError.trim() };
|
|
106
|
+
}),
|
|
107
|
+
);
|
|
108
|
+
|
|
109
|
+
export const checkUnsafeEnumAssignmentsWith = (
|
|
110
|
+
binary: string,
|
|
111
|
+
directory: string,
|
|
112
|
+
files: readonly string[],
|
|
113
|
+
) =>
|
|
114
|
+
Effect.gen(function* () {
|
|
115
|
+
const { command, code, output, standardError } = yield* ranTsgolint(
|
|
116
|
+
binary,
|
|
117
|
+
directory,
|
|
118
|
+
files,
|
|
119
|
+
).pipe(quietViolations(TSGOLINT));
|
|
120
|
+
if (code !== 0) {
|
|
121
|
+
return yield* Effect.fail(
|
|
122
|
+
new ToolExited({
|
|
123
|
+
program: TSGOLINT,
|
|
124
|
+
command,
|
|
125
|
+
code,
|
|
126
|
+
standardOutput: output.toString("utf8"),
|
|
127
|
+
standardError,
|
|
128
|
+
}),
|
|
129
|
+
).pipe(quietToolFailure(TSGOLINT, () => errorsTsgolintReportedOnExit(output)));
|
|
130
|
+
}
|
|
131
|
+
const violations = yield* Effect.flatMap(decodedRuleMessages(output), (reports) =>
|
|
132
|
+
unsafeEnumViolationsIn(directory, reports),
|
|
133
|
+
).pipe(quietViolations(TSGOLINT));
|
|
134
|
+
if (Arrays.isReadonlyArrayNonEmpty(violations)) {
|
|
135
|
+
const reported = new ToolReportedViolations({
|
|
136
|
+
program: TSGOLINT,
|
|
137
|
+
command,
|
|
138
|
+
code,
|
|
139
|
+
count: violations.length,
|
|
140
|
+
});
|
|
141
|
+
return yield* failQuietly(
|
|
142
|
+
TSGOLINT,
|
|
143
|
+
reported,
|
|
144
|
+
Arrays.append(violations, printableError(reported)),
|
|
145
|
+
);
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
export const checkUnsafeEnumAssignmentsIn = (directory: string, files: readonly string[]) =>
|
|
150
|
+
Effect.flatMap(tsgolintExecutable.pipe(quietViolations(TSGOLINT)), (binary) =>
|
|
151
|
+
checkUnsafeEnumAssignmentsWith(binary, directory, files),
|
|
152
|
+
);
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Effect, Path } from "effect";
|
|
2
|
+
|
|
3
|
+
import { installedBinary } from "../../../shared/find-installed-package-binaries.ts";
|
|
4
|
+
import { PackageNotInstalled } from "../../../shared/project-config-and-tool-errors.ts";
|
|
5
|
+
|
|
6
|
+
export const tsgolintExecutable = Effect.gen(function* () {
|
|
7
|
+
const path = yield* Path.Path;
|
|
8
|
+
const packageDirectory = yield* path.fromFileUrl(new URL(".", import.meta.url));
|
|
9
|
+
const launcher = yield* installedBinary(packageDirectory, "oxlint-tsgolint", "tsgolint");
|
|
10
|
+
const platformPackage = `@oxlint-tsgolint/${process.platform}-${process.arch}`;
|
|
11
|
+
const executable = process.platform === "win32" ? "tsgolint.exe" : "tsgolint";
|
|
12
|
+
return yield* Effect.tryPromise({
|
|
13
|
+
try: () => Bun.resolve(`${platformPackage}/${executable}`, path.dirname(launcher)),
|
|
14
|
+
catch: (cause) =>
|
|
15
|
+
new PackageNotInstalled({
|
|
16
|
+
packageName: platformPackage,
|
|
17
|
+
packageDirectory: path.dirname(launcher),
|
|
18
|
+
reason: String(cause),
|
|
19
|
+
}),
|
|
20
|
+
});
|
|
21
|
+
});
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { Effect, Schema } from "effect";
|
|
2
|
+
|
|
3
|
+
import { encodeJson } from "../../../shared/encode-compact-json.ts";
|
|
4
|
+
import { decodedReport } from "../../../shared/run-tools-and-decode-their-reports.ts";
|
|
5
|
+
|
|
6
|
+
const OXLINT_WARNING = "warning";
|
|
7
|
+
export const OXLINT_TASK = "oxlint";
|
|
8
|
+
|
|
9
|
+
const OXLINT_REPORT = Schema.fromJsonString(
|
|
10
|
+
Schema.Struct({
|
|
11
|
+
diagnostics: Schema.Array(
|
|
12
|
+
Schema.Struct({
|
|
13
|
+
message: Schema.String,
|
|
14
|
+
code: Schema.optionalKey(Schema.String),
|
|
15
|
+
severity: Schema.String,
|
|
16
|
+
filename: Schema.String,
|
|
17
|
+
labels: Schema.Array(
|
|
18
|
+
Schema.Struct({
|
|
19
|
+
span: Schema.Struct({
|
|
20
|
+
line: Schema.NullOr(Schema.Int),
|
|
21
|
+
column: Schema.NullOr(Schema.Int),
|
|
22
|
+
}),
|
|
23
|
+
}),
|
|
24
|
+
),
|
|
25
|
+
}),
|
|
26
|
+
),
|
|
27
|
+
}),
|
|
28
|
+
);
|
|
29
|
+
|
|
30
|
+
const oxlintError = (reported: (typeof OXLINT_REPORT.Type)["diagnostics"][number]) => {
|
|
31
|
+
const label = reported.labels.find(({ span }) => span.line !== null)?.span;
|
|
32
|
+
const location =
|
|
33
|
+
label === undefined
|
|
34
|
+
? reported.filename
|
|
35
|
+
: `${reported.filename}:${label.line}${label.column === null ? "" : `:${label.column}`}`;
|
|
36
|
+
return { tag: reported.code ?? OXLINT_TASK, location, message: reported.message };
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
export const oxlintReport = (program: string, ...standardOutputs: readonly string[]) =>
|
|
40
|
+
Effect.forEach(
|
|
41
|
+
standardOutputs.filter((standardOutput) => standardOutput.trim() !== ""),
|
|
42
|
+
(standardOutput) => decodedReport(program, Schema.decodeEffect(OXLINT_REPORT), standardOutput),
|
|
43
|
+
).pipe(
|
|
44
|
+
Effect.map((reports) => {
|
|
45
|
+
const diagnostics = reports.flatMap((report) => report.diagnostics);
|
|
46
|
+
const warnings = diagnostics.filter((reported) => reported.severity === OXLINT_WARNING);
|
|
47
|
+
return {
|
|
48
|
+
violations: diagnostics
|
|
49
|
+
.filter((reported) => reported.severity !== OXLINT_WARNING)
|
|
50
|
+
.map((reported) => oxlintError(reported)),
|
|
51
|
+
notes:
|
|
52
|
+
warnings.length === 0
|
|
53
|
+
? []
|
|
54
|
+
: [
|
|
55
|
+
`${program} also reported ${warnings.length} ${warnings.length === 1 ? "warning" : "warnings"}, which this printer cannot show as warnings`,
|
|
56
|
+
],
|
|
57
|
+
};
|
|
58
|
+
}),
|
|
59
|
+
);
|
|
60
|
+
|
|
61
|
+
export const lintReportWithOriginalFileNames = (
|
|
62
|
+
program: string,
|
|
63
|
+
standardOutput: string,
|
|
64
|
+
files: readonly string[],
|
|
65
|
+
) => {
|
|
66
|
+
const keepsReport = standardOutput.trim() === "" || !files.some((file) => file.includes("\\"));
|
|
67
|
+
if (keepsReport) {
|
|
68
|
+
return Effect.succeed(standardOutput);
|
|
69
|
+
}
|
|
70
|
+
return decodedReport(program, Schema.decodeEffect(OXLINT_REPORT), standardOutput).pipe(
|
|
71
|
+
Effect.flatMap((report) =>
|
|
72
|
+
encodeJson({
|
|
73
|
+
diagnostics: report.diagnostics.map((diagnostic) => ({
|
|
74
|
+
...diagnostic,
|
|
75
|
+
filename:
|
|
76
|
+
files.find((file) => file.replaceAll("\\", "/") === diagnostic.filename) ??
|
|
77
|
+
diagnostic.filename,
|
|
78
|
+
})),
|
|
79
|
+
}),
|
|
80
|
+
),
|
|
81
|
+
);
|
|
82
|
+
};
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { Array as Arrays, Option, Result, Schema } from "effect";
|
|
2
|
+
|
|
3
|
+
const HEADER_BYTES = 5;
|
|
4
|
+
const MESSAGE_KIND_OFFSET = 4;
|
|
5
|
+
const ERROR_MESSAGE = 0;
|
|
6
|
+
const DIAGNOSTIC_MESSAGE = 1;
|
|
7
|
+
const TIMING_MESSAGE = 2;
|
|
8
|
+
|
|
9
|
+
const DIAGNOSTIC = Schema.fromJsonString(
|
|
10
|
+
Schema.Struct({
|
|
11
|
+
kind: Schema.Int,
|
|
12
|
+
file_path: Schema.NullOr(Schema.String),
|
|
13
|
+
range: Schema.optionalKey(Schema.Struct({ pos: Schema.Int, end: Schema.Int })),
|
|
14
|
+
rule: Schema.optionalKey(Schema.String),
|
|
15
|
+
message: Schema.Struct({ id: Schema.String, description: Schema.String }),
|
|
16
|
+
}),
|
|
17
|
+
);
|
|
18
|
+
|
|
19
|
+
const FAILURE = Schema.fromJsonString(Schema.Struct({ error: Schema.String }));
|
|
20
|
+
|
|
21
|
+
export class EnumLintFailed extends Schema.TaggedError<EnumLintFailed>()("EnumLintFailed", {
|
|
22
|
+
reason: Schema.String,
|
|
23
|
+
}) {
|
|
24
|
+
public override get message() {
|
|
25
|
+
return `no-unsafe-enum-assignment failed: ${this.reason}`;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const decodeMessage = <Message extends Schema.Codec<unknown, string>>(
|
|
30
|
+
schema: Message,
|
|
31
|
+
body: string,
|
|
32
|
+
) =>
|
|
33
|
+
Schema.decodeResult(schema)(body).pipe(
|
|
34
|
+
Result.match({
|
|
35
|
+
onFailure: (error) => {
|
|
36
|
+
throw new EnumLintFailed({ reason: error.message });
|
|
37
|
+
},
|
|
38
|
+
onSuccess: (message) => message,
|
|
39
|
+
}),
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
const nextFrame = (output: Buffer) => {
|
|
43
|
+
if (output.length === 0) {
|
|
44
|
+
return Option.none();
|
|
45
|
+
}
|
|
46
|
+
if (output.length < HEADER_BYTES) {
|
|
47
|
+
throw new EnumLintFailed({ reason: "truncated message header" });
|
|
48
|
+
}
|
|
49
|
+
const end = HEADER_BYTES + output.readUInt32LE(0);
|
|
50
|
+
if (end > output.length) {
|
|
51
|
+
throw new EnumLintFailed({ reason: "truncated message body" });
|
|
52
|
+
}
|
|
53
|
+
const kind = output[MESSAGE_KIND_OFFSET];
|
|
54
|
+
const body = output.subarray(HEADER_BYTES, end).toString("utf8");
|
|
55
|
+
if (kind === ERROR_MESSAGE) {
|
|
56
|
+
throw new EnumLintFailed({
|
|
57
|
+
reason: decodeMessage(FAILURE, body).error,
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
const isUnknownKind = kind !== DIAGNOSTIC_MESSAGE && kind !== TIMING_MESSAGE;
|
|
61
|
+
if (isUnknownKind) {
|
|
62
|
+
throw new EnumLintFailed({ reason: `unknown message kind ${kind}` });
|
|
63
|
+
}
|
|
64
|
+
const diagnostics = kind === DIAGNOSTIC_MESSAGE ? [decodeMessage(DIAGNOSTIC, body)] : [];
|
|
65
|
+
return Option.some([diagnostics, output.subarray(end)] as const);
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
export const tsgolintRuleMessages = (output: Buffer) => Arrays.unfold(output, nextFrame).flat();
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { findExportPlacementViolations } from "./internal/find-export-placement-violations.ts";
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { Effect, Schema } from "effect";
|
|
2
|
+
|
|
3
|
+
import { listedViolations } from "../../../../../shared/format-reported-failures.ts";
|
|
4
|
+
import {
|
|
5
|
+
INTERNAL_DIRECTORY_NAME,
|
|
6
|
+
LIBRARY_DIRECTORY_NAME,
|
|
7
|
+
SHARED_DIRECTORY_NAME,
|
|
8
|
+
} from "../../../../../shared/match-file-names-and-path-prefixes.ts";
|
|
9
|
+
import { SCRIPTS_DIRECTORY } from "../../../../../shared/test-home-directories.ts";
|
|
10
|
+
import { directoryOf, joinedWithAnd } from "../../../shared/classify-files-by-role.ts";
|
|
11
|
+
import { PACKAGE_MANIFEST_FILE } from "../../../shared/find-named-package-manifests.ts";
|
|
12
|
+
import {
|
|
13
|
+
PackageManifestFieldInvalid,
|
|
14
|
+
SourceFileUnparsable,
|
|
15
|
+
} from "../../../shared/project-config-and-tool-errors.ts";
|
|
16
|
+
|
|
17
|
+
export class UnusedExport extends Schema.TaggedError<UnusedExport>()("UnusedExport", {
|
|
18
|
+
location: Schema.String,
|
|
19
|
+
exportName: Schema.String,
|
|
20
|
+
unreachableUser: Schema.optionalKey(Schema.String),
|
|
21
|
+
}) {
|
|
22
|
+
public override get message() {
|
|
23
|
+
if (this.unreachableUser !== undefined) {
|
|
24
|
+
return `export ${this.exportName} is used only by unreached code, such as ${this.unreachableUser}`;
|
|
25
|
+
}
|
|
26
|
+
return `export ${this.exportName} is used by nothing`;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export class TestOnlyExport extends Schema.TaggedError<TestOnlyExport>()("TestOnlyExport", {
|
|
31
|
+
location: Schema.String,
|
|
32
|
+
exportName: Schema.String,
|
|
33
|
+
}) {
|
|
34
|
+
public override get message() {
|
|
35
|
+
return `export ${this.exportName} is used only by tests`;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const UNCOUNTED_USERS = "outside tests and unreached code";
|
|
40
|
+
|
|
41
|
+
export class FileBesideSubdirectories extends Schema.TaggedError<FileBesideSubdirectories>()(
|
|
42
|
+
"FileBesideSubdirectories",
|
|
43
|
+
{ location: Schema.String },
|
|
44
|
+
) {
|
|
45
|
+
public override get message() {
|
|
46
|
+
return `sits directly in ${directoryOf(this.location)}/, which has subdirectories that hold code`;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export class FileOutsideModuleLayout extends Schema.TaggedError<FileOutsideModuleLayout>()(
|
|
51
|
+
"FileOutsideModuleLayout",
|
|
52
|
+
{ location: Schema.String, module: Schema.String },
|
|
53
|
+
) {
|
|
54
|
+
public override get message() {
|
|
55
|
+
const directory = directoryOf(this.location);
|
|
56
|
+
return directory === this.module
|
|
57
|
+
? `sits directly in the module ${this.module}/, not in its ${INTERNAL_DIRECTORY_NAME}/ or ${SHARED_DIRECTORY_NAME}/`
|
|
58
|
+
: `sits in ${directory}/, which is inside the module ${this.module}/ but is not its ${INTERNAL_DIRECTORY_NAME}/, its ${SHARED_DIRECTORY_NAME}/ or a module in its ${LIBRARY_DIRECTORY_NAME}/`;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export class SharedFileWithOneUser extends Schema.TaggedError<SharedFileWithOneUser>()(
|
|
63
|
+
"SharedFileWithOneUser",
|
|
64
|
+
{
|
|
65
|
+
location: Schema.String,
|
|
66
|
+
module: Schema.String,
|
|
67
|
+
part: Schema.optionalKey(Schema.String),
|
|
68
|
+
through: Schema.optionalKey(Schema.Array(Schema.String)),
|
|
69
|
+
},
|
|
70
|
+
) {
|
|
71
|
+
public override get message() {
|
|
72
|
+
const users =
|
|
73
|
+
this.part === undefined
|
|
74
|
+
? `no submodule of ${this.module}/ uses it`
|
|
75
|
+
: `only ${this.part}/ uses it`;
|
|
76
|
+
const through =
|
|
77
|
+
this.through === undefined ? "" : `, counting the users of ${joinedWithAnd(this.through)}`;
|
|
78
|
+
return `is in ${this.module}/${SHARED_DIRECTORY_NAME}/, but ${users} ${UNCOUNTED_USERS}${through}`;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export class TestNotRun extends Schema.TaggedError<TestNotRun>()("TestNotRun", {
|
|
83
|
+
location: Schema.String,
|
|
84
|
+
}) {
|
|
85
|
+
public override get message() {
|
|
86
|
+
return `is a test that no file directly in ${SCRIPTS_DIRECTORY}/ reaches through its imports`;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export class PackageEntryWithoutSource extends Schema.TaggedError<PackageEntryWithoutSource>()(
|
|
91
|
+
"PackageEntryWithoutSource",
|
|
92
|
+
{
|
|
93
|
+
entry: Schema.String,
|
|
94
|
+
location: Schema.Literal(PACKAGE_MANIFEST_FILE).pipe(
|
|
95
|
+
Schema.optionalKey,
|
|
96
|
+
Schema.withConstructorDefault(Effect.succeed(PACKAGE_MANIFEST_FILE)),
|
|
97
|
+
),
|
|
98
|
+
},
|
|
99
|
+
) {
|
|
100
|
+
public override get message() {
|
|
101
|
+
return `lists the entry ${this.entry}, which maps to no source file through any tsconfig outDir and rootDir`;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export class ImportUnresolvableInTheImportBoundaryCheck extends Schema.TaggedError<ImportUnresolvableInTheImportBoundaryCheck>()(
|
|
106
|
+
"ImportUnresolvableInTheImportBoundaryCheck",
|
|
107
|
+
{ request: Schema.String, importingFile: Schema.String },
|
|
108
|
+
) {
|
|
109
|
+
public override get message() {
|
|
110
|
+
return `could not resolve ${this.request}`;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export class ExportPlacementViolations extends Schema.TaggedError<ExportPlacementViolations>()(
|
|
115
|
+
"ExportPlacementViolations",
|
|
116
|
+
{
|
|
117
|
+
violations: Schema.Array(
|
|
118
|
+
Schema.Union([
|
|
119
|
+
UnusedExport,
|
|
120
|
+
TestOnlyExport,
|
|
121
|
+
FileBesideSubdirectories,
|
|
122
|
+
FileOutsideModuleLayout,
|
|
123
|
+
SharedFileWithOneUser,
|
|
124
|
+
TestNotRun,
|
|
125
|
+
PackageEntryWithoutSource,
|
|
126
|
+
PackageManifestFieldInvalid,
|
|
127
|
+
SourceFileUnparsable,
|
|
128
|
+
]),
|
|
129
|
+
),
|
|
130
|
+
},
|
|
131
|
+
) {
|
|
132
|
+
public override get message() {
|
|
133
|
+
return listedViolations(this.violations);
|
|
134
|
+
}
|
|
135
|
+
}
|