@sshkeda/check 4.3.0 → 4.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (22) hide show
  1. package/README.md +3 -1
  2. package/docs/how-to-grant-a-permission.md +4 -2
  3. package/docs/how-to-make-check-pass.md +36 -21
  4. package/package.json +2 -2
  5. package/src/internal/ban-promise-combinators.ts +222 -0
  6. package/src/internal/ban-writes-to-native-prototypes.ts +207 -0
  7. package/src/internal/define-the-lint-plugin-and-configs.ts +4 -1
  8. package/src/internal/resolve-globals-through-constant-aliases.ts +186 -0
  9. package/src/lib/tasks/internal/declare-the-checker-queries-task.ts +2 -0
  10. package/src/lib/tasks/lib/enforce-file-layout/internal/file-layout-errors.ts +10 -0
  11. package/src/lib/tasks/lib/enforce-file-layout/internal/find-export-path-mismatches.ts +51 -18
  12. package/src/lib/tasks/lib/enforce-file-layout/internal/find-file-layout-violations.ts +2 -0
  13. package/src/lib/tasks/lib/enforce-file-types/index.ts +4 -1
  14. package/src/lib/tasks/lib/refuse-disable-directives/internal/find-disable-directives.ts +69 -20
  15. package/src/lib/tasks/lib/refuse-promise-chains/index.ts +1 -0
  16. package/src/lib/tasks/lib/refuse-promise-chains/internal/find-promise-chains.ts +141 -0
  17. package/src/lib/tasks/lib/refuse-promise-chains/internal/promise-chain-errors.ts +21 -0
  18. package/src/lib/tasks/lib/type-check-with-bun-check/index.ts +2 -3
  19. package/src/lib/tasks/lib/type-check-with-bun-check/internal/check-types-with-bun-check.ts +21 -5
  20. package/src/lib/tasks/shared/print-failures-and-keep-detail-in-the-trace.ts +1 -1
  21. package/src/lib/tasks/shared/watch-the-typescript-api-process.ts +47 -20
  22. package/src/shared/lint-rule-messages-and-patterns.ts +11 -4
@@ -1,17 +1,23 @@
1
- import { Effect, FileSystem, Path } from "effect";
1
+ import { Effect, FileSystem, Path, Ref } from "effect";
2
2
 
3
+ import { inEachPackage } from "../../../shared/check-each-nested-package.ts";
3
4
  import { PACKAGE_MANIFEST_FILE } from "../../../shared/find-named-package-manifests.ts";
4
5
  import { isFormatConfigTextRefusedIn } from "../../../shared/parse-config-files-that-import-from-check.ts";
5
6
  import { quietToolFailure } from "../../../shared/print-failures-and-keep-detail-in-the-trace.ts";
6
7
  import { TYPESCRIPT_PROJECT_FILE } from "../../../shared/query-the-typescript-project.ts";
7
8
  import { absolutePathOf } from "../../../shared/resolve-absolute-paths.ts";
8
9
  import { runTool } from "../../../shared/run-tools-and-decode-their-reports.ts";
10
+ import { formatting } from "../../format-with-bun-fmt/index.ts";
9
11
  import { typeCheckReport } from "./read-bun-check-output.ts";
10
12
 
11
13
  const BUN = "bun";
12
14
  const EMPTY_PACKAGE_MANIFEST = "{}\n";
13
15
 
14
- const typeCheckRun = (directory: string, isFormatConfigRefused: boolean) =>
16
+ const typeCheckRun = (
17
+ directory: string,
18
+ isFormatConfigRefused: boolean,
19
+ leaveToTheFormatCheck: Effect.Effect<void>,
20
+ ) =>
15
21
  Effect.gen(function* () {
16
22
  const fileSystem = yield* FileSystem.FileSystem;
17
23
  const path = yield* Path.Path;
@@ -37,7 +43,7 @@ const typeCheckRun = (directory: string, isFormatConfigRefused: boolean) =>
37
43
  Effect.catchTag("ToolExited", (exited) =>
38
44
  typeCheckReport(exited.standardOutput, isFormatConfigRefused)
39
45
  .reportsOnlyWhatTheFormatCheckReports
40
- ? Effect.void
46
+ ? leaveToTheFormatCheck
41
47
  : Effect.fail(exited),
42
48
  ),
43
49
  );
@@ -48,7 +54,17 @@ const typeCheckRun = (directory: string, isFormatConfigRefused: boolean) =>
48
54
  ),
49
55
  );
50
56
 
51
- export const checkTypesWithBunCheckIn = (directory: string) =>
57
+ const checkTypesWithBunCheckIn = (directory: string, leaveToTheFormatCheck: Effect.Effect<void>) =>
52
58
  Effect.flatMap(isFormatConfigTextRefusedIn(directory), (isFormatConfigRefused) =>
53
- typeCheckRun(directory, isFormatConfigRefused),
59
+ typeCheckRun(directory, isFormatConfigRefused, leaveToTheFormatCheck),
54
60
  );
61
+
62
+ export const typesCheckedInEachPackage = Effect.gen(function* () {
63
+ const isLeftToTheFormatCheck = yield* Ref.make(false);
64
+ yield* inEachPackage("type-check", (packageDirectory) =>
65
+ checkTypesWithBunCheckIn(packageDirectory, Ref.set(isLeftToTheFormatCheck, true)),
66
+ );
67
+ if (yield* Ref.get(isLeftToTheFormatCheck)) {
68
+ yield* formatting;
69
+ }
70
+ });
@@ -78,7 +78,7 @@ export const quietToolFailure =
78
78
  failQuietly(
79
79
  tool,
80
80
  exited,
81
- Arrays.append(report.violations, exitError(exited, report.notes)),
81
+ Arrays.prepend(report.violations, exitError(exited, report.notes)),
82
82
  ),
83
83
  ),
84
84
  Effect.catchTag("ToolReportUndecodable", (unreadableReport) =>
@@ -44,21 +44,36 @@ const TYPESCRIPT_API_CLIENT = Schema.declare(
44
44
  CLIENT_MEMBERS.every((member) => Predicate.hasProperty(value, member)),
45
45
  );
46
46
 
47
- const PROCESS_MEMBERS = ["once", "on", "kill", "stdout"] as const;
47
+ const PROCESS_MEMBERS = ["once", "on", "kill", "stdout", "exitCode", "signalCode"] as const;
48
+
49
+ const OUTPUT_MEMBERS = ["once", "destroyed"] as const;
48
50
 
49
51
  const isWatchableProcess = Schema.is(
50
52
  Schema.declare(
51
53
  (
52
54
  value,
53
55
  ): value is {
54
- readonly stdout: { once(event: "close", listener: () => void): void } | null;
56
+ readonly stdout: {
57
+ readonly destroyed: boolean;
58
+ once(event: "close", listener: () => void): void;
59
+ } | null;
60
+ readonly exitCode: number | null;
61
+ readonly signalCode: NodeJS.Signals | null;
55
62
  once(
56
63
  event: "exit",
57
64
  listener: (code: number | null, signal: NodeJS.Signals | null) => void,
58
65
  ): void;
59
66
  on(event: "error", listener: (error: Error) => void): void;
60
67
  kill(signal: NodeJS.Signals): boolean;
61
- } => PROCESS_MEMBERS.every((member) => Predicate.hasProperty(value, member)),
68
+ } => {
69
+ const hasProcessMembers = PROCESS_MEMBERS.every((member) =>
70
+ Predicate.hasProperty(value, member),
71
+ );
72
+ const output = Predicate.hasProperty(value, "stdout") ? value.stdout : undefined;
73
+ const hasOutputMembers =
74
+ output === null || OUTPUT_MEMBERS.every((member) => Predicate.hasProperty(output, member));
75
+ return hasProcessMembers && hasOutputMembers;
76
+ },
62
77
  ),
63
78
  );
64
79
 
@@ -85,23 +100,37 @@ const watchedProcess = (
85
100
  ) => {
86
101
  const child: unknown = client[CLIENT_PROCESS_FIELD];
87
102
  if (!isWatchableProcess(child)) {
88
- return client.close().then(() => Option.none());
103
+ return Option.none();
89
104
  }
90
105
  const output = { closed: false };
91
- child.once("exit", (code, signal) => {
106
+ const onExit = (code: number | null, signal: NodeJS.Signals | null) => {
92
107
  stopWith(stopped, child, exitReason(code, signal, output.closed));
93
108
  Deferred.doneUnsafe(exited, Effect.void);
94
- });
95
- child.on("error", (error) => {
96
- stopWith(stopped, child, `the TypeScript API process failed: ${error.message}`);
97
- });
98
- child.stdout?.once("close", () => {
109
+ };
110
+ const onOutputClosed = () => {
99
111
  output.closed = true;
100
112
  child.kill(TERMINATING_SIGNAL);
113
+ };
114
+ child.once("exit", onExit);
115
+ child.on("error", (error) => {
116
+ stopWith(stopped, child, `the TypeScript API process failed: ${error.message}`);
101
117
  });
102
- return Promise.resolve(Option.some(child));
118
+ child.stdout?.once("close", onOutputClosed);
119
+ const hasExited = child.exitCode !== null || child.signalCode !== null;
120
+ if (hasExited) {
121
+ onExit(child.exitCode, child.signalCode);
122
+ }
123
+ if (child.stdout?.destroyed === true) {
124
+ onOutputClosed();
125
+ }
126
+ return Option.some(child);
103
127
  };
104
128
 
129
+ const startupFailed = (reason: string) => new TypeScriptApiFailed({ operation: STARTING, reason });
130
+
131
+ const startupStep = <Value>(step: () => Promise<Value>) =>
132
+ Effect.tryPromise({ try: step, catch: (cause) => startupFailed(String(cause)) });
133
+
105
134
  const answered = <Answer>(
106
135
  stopped: Deferred.Deferred<never, TypeScriptApiProcessStopped>,
107
136
  child: Parameters<typeof stopWith>[1],
@@ -137,19 +166,17 @@ const startedSession = (sourceTextOverrides: ReadonlyMap<string, string>) =>
137
166
  );
138
167
  const client = yield* Schema.decodeUnknownEffect(TYPESCRIPT_API_CLIENT)(
139
168
  api[API_CLIENT_FIELD],
140
- ).pipe(
141
- Effect.mapError(
142
- () => new TypeScriptApiFailed({ operation: STARTING, reason: CLIENT_CHANGED }),
143
- ),
144
- );
169
+ ).pipe(Effect.mapError(() => startupFailed(CLIENT_CHANGED)));
145
170
  const stopped = yield* Deferred.make<never, TypeScriptApiProcessStopped>();
146
171
  const exited = yield* Deferred.make<void>();
147
- const watched = yield* Effect.tryPromise({
148
- try: () => client.connect().then(() => watchedProcess(client, stopped, exited)),
149
- catch: (cause) => new TypeScriptApiFailed({ operation: STARTING, reason: String(cause) }),
172
+ yield* startupStep(() => client.connect());
173
+ const watched = yield* Effect.try({
174
+ try: () => watchedProcess(client, stopped, exited),
175
+ catch: (cause) => startupFailed(String(cause)),
150
176
  });
151
177
  if (Option.isNone(watched)) {
152
- return yield* new TypeScriptApiFailed({ operation: STARTING, reason: CLIENT_CHANGED });
178
+ yield* startupStep(() => client.close());
179
+ return yield* startupFailed(CLIENT_CHANGED);
153
180
  }
154
181
  const child = watched.value;
155
182
  const runPromise = Effect.runPromiseWith(yield* Effect.context());
@@ -1,12 +1,19 @@
1
1
  import { isBuiltin } from "node:module";
2
2
 
3
- const DIRECTIVE =
4
- /^\s*(?:(?:oxlint|eslint)-(?:disable|enable)|@ts-(?:ignore|expect-error|nocheck)|@effect-diagnostics)/u;
3
+ const DIRECTIVE = /^\s*(?:(?:oxlint|eslint)-(?:disable|enable)|@ts-nocheck|@effect-diagnostics)/u;
5
4
 
6
- const TYPESCRIPT_SUPPRESSION_ON_A_LAST_LINE = /\n[\s*/]*@ts-(?:ignore|expect-error)[^\n]*$/u;
5
+ const TYPESCRIPT_SUPPRESSION_ON_THE_LAST_LINE =
6
+ /(?:^|\n)[\s*/]*@ts-(?:ignore|expect-error)[^\n]*$/u;
7
+
8
+ export const TYPESCRIPT_NO_CHECK = /^\/?\s*@ts-nocheck(?![a-z-])/iu;
9
+
10
+ export const isTypeScriptSuppression = (commentText: string) =>
11
+ TYPESCRIPT_SUPPRESSION_ON_THE_LAST_LINE.test(commentText);
7
12
 
8
13
  export const isDirective = (commentText: string) =>
9
- DIRECTIVE.test(commentText) || TYPESCRIPT_SUPPRESSION_ON_A_LAST_LINE.test(commentText);
14
+ DIRECTIVE.test(commentText) ||
15
+ isTypeScriptSuppression(commentText) ||
16
+ TYPESCRIPT_NO_CHECK.test(commentText);
10
17
 
11
18
  export const EFFECT_OPERATION_RULES = {
12
19
  "no-dropped-failures": {