@sshkeda/check 2.2.0 → 4.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/README.md +18 -24
- package/docs/how-to-grant-a-permission.md +28 -0
- package/docs/how-to-make-check-pass.md +5 -31
- package/package.json +7 -10
- package/scripts/check.ts +9 -0
- package/src/internal/ban-fixed-values-in-recoveries.ts +1 -1
- package/src/internal/ban-re-exports.ts +14 -1
- package/src/internal/define-the-lint-plugin-and-configs.ts +0 -2
- package/src/lib/project-directory/index.ts +4 -0
- package/src/lib/project-directory/internal/read-the-project-directory.ts +9 -0
- package/src/lib/tasks/internal/declare-the-check-task.ts +21 -13
- package/src/lib/tasks/internal/declare-the-checker-queries-task.ts +7 -5
- package/src/lib/tasks/internal/declare-the-typed-checks-task.ts +4 -4
- package/src/lib/tasks/lib/check-effect-diagnostics-with-effect-tsgo/index.ts +5 -5
- package/src/lib/tasks/lib/confine-layer-provides-to-program-starts/internal/find-layer-provides-outside-program-starts.ts +21 -37
- package/src/lib/tasks/lib/confine-layer-provides-to-program-starts/internal/resolve-imported-package-apis.ts +1 -2
- package/src/lib/tasks/lib/detect-duplicate-functions/index.ts +4 -4
- package/src/lib/tasks/lib/detect-duplicate-functions/internal/find-duplicate-functions.ts +2 -3
- package/src/lib/tasks/lib/enforce-file-layout/index.ts +4 -4
- package/src/lib/tasks/lib/enforce-file-layout/internal/check-the-layout-of-each-package.ts +1 -1
- package/src/lib/tasks/lib/enforce-file-layout/internal/file-layout-errors.ts +7 -12
- package/src/lib/tasks/lib/enforce-file-layout/internal/find-file-layout-violations.ts +37 -170
- package/src/lib/tasks/lib/enforce-file-types/index.ts +4 -4
- package/src/lib/tasks/lib/enforce-file-types/internal/find-file-type-violations.ts +1 -1
- package/src/lib/tasks/lib/format-with-bun-fmt/internal/check-formatting-with-bun-fmt.ts +16 -15
- package/src/lib/tasks/lib/format-with-bun-fmt/internal/declare-the-formatting-task.ts +50 -31
- package/src/lib/tasks/lib/lint-with-oxlint/index.ts +5 -5
- package/src/lib/tasks/lib/lint-with-oxlint/internal/check-lint-rules-with-oxlint.ts +7 -0
- package/src/lib/tasks/lib/lint-with-oxlint/internal/find-shebangs-outside-bin.ts +38 -0
- package/src/lib/tasks/lib/lint-with-oxlint/internal/shebang-errors.ts +22 -0
- package/src/lib/tasks/lib/place-exports-in-the-narrowest-directory/internal/find-export-placement-violations.ts +9 -1
- package/src/lib/tasks/lib/place-exports-in-the-narrowest-directory/internal/find-the-importer-graph.ts +21 -0
- package/src/lib/tasks/lib/place-exports-in-the-narrowest-directory/internal/recognise-task-default-exports.ts +76 -0
- package/src/lib/tasks/lib/refuse-disable-directives/index.ts +5 -5
- package/src/lib/tasks/lib/refuse-forks-whose-failures-nothing-observes/index.ts +1 -0
- package/src/lib/tasks/lib/refuse-forks-whose-failures-nothing-observes/internal/find-unobserved-fork-failures.ts +402 -0
- package/src/lib/tasks/lib/refuse-forks-whose-failures-nothing-observes/internal/fork-failure-errors.ts +28 -0
- package/src/lib/tasks/lib/require-type-checking-every-linted-file/index.ts +4 -4
- package/src/lib/tasks/lib/require-type-checking-every-linted-file/internal/find-linted-files-not-type-checked.ts +15 -9
- package/src/lib/tasks/lib/type-check-with-bun-check/index.ts +4 -4
- package/src/lib/tasks/shared/check-each-nested-package.ts +14 -4
- package/src/lib/tasks/shared/declare-lint-config-task.ts +4 -4
- package/src/lib/tasks/shared/declare-start-directory-task.ts +40 -0
- package/src/lib/tasks/shared/declare-typescript-config-task.ts +4 -4
- package/src/lib/tasks/shared/find-installed-package-binaries.ts +10 -0
- package/src/lib/tasks/shared/read-piped-steps-through-wrappers.ts +41 -0
- package/src/lib/tasks/shared/report-paths-from-the-project.ts +56 -0
- package/src/shared/bans-each-permission-lifts.ts +0 -7
- package/src/shared/format-reported-failures.ts +8 -6
- package/src/shared/record-and-grant-permissions-by-path.ts +4 -3
- package/src/internal/ban-shebang-lines.ts +0 -22
- package/src/lib/tasks/lib/enforce-file-layout/internal/resolve-task-imports.ts +0 -178
|
@@ -376,6 +376,7 @@ export const findExportPlacementViolations = <Failure, Requirements>(
|
|
|
376
376
|
reach,
|
|
377
377
|
exportsAreReadFromOutside,
|
|
378
378
|
roots,
|
|
379
|
+
runsItsDefaultExport,
|
|
379
380
|
reachable,
|
|
380
381
|
moduleDirectories,
|
|
381
382
|
} = graph;
|
|
@@ -402,6 +403,7 @@ export const findExportPlacementViolations = <Failure, Requirements>(
|
|
|
402
403
|
: [],
|
|
403
404
|
),
|
|
404
405
|
);
|
|
406
|
+
const servedByThePackage = reach(graph.binaryEntries, (use) => use.kind !== "type");
|
|
405
407
|
const isServedOnlyToScripts = (file: string) =>
|
|
406
408
|
isWithin(file, SOURCE_DIRECTORY) &&
|
|
407
409
|
!builtByScripts.has(file) &&
|
|
@@ -506,6 +508,10 @@ export const findExportPlacementViolations = <Failure, Requirements>(
|
|
|
506
508
|
continue;
|
|
507
509
|
}
|
|
508
510
|
for (const [name, { line }] of parsed.exports) {
|
|
511
|
+
const isATaskDefaultExport = name === DEFAULT_EXPORT && runsItsDefaultExport.has(file);
|
|
512
|
+
if (isATaskDefaultExport) {
|
|
513
|
+
continue;
|
|
514
|
+
}
|
|
509
515
|
const location = `${file}:${line}`;
|
|
510
516
|
const recordedUsers = [...allUsersOf(file, name)];
|
|
511
517
|
const everyUser = recordedUsers.filter((user) => reachable.has(user));
|
|
@@ -518,7 +524,9 @@ export const findExportPlacementViolations = <Failure, Requirements>(
|
|
|
518
524
|
elsewhere.every(
|
|
519
525
|
(user) =>
|
|
520
526
|
isUnderTestDirectory(user) ||
|
|
521
|
-
(isWithin(user, SCRIPTS_DIRECTORY) &&
|
|
527
|
+
(isWithin(user, SCRIPTS_DIRECTORY) &&
|
|
528
|
+
!servedByThePackage.has(user) &&
|
|
529
|
+
isServedOnlyToScripts(file)),
|
|
522
530
|
) &&
|
|
523
531
|
!(usedInOwnFile && elsewhere.length > 0) &&
|
|
524
532
|
(elsewhere.length === 0 || !isWithin(file, SCRIPTS_DIRECTORY));
|
|
@@ -16,9 +16,12 @@ import {
|
|
|
16
16
|
packagePathOf,
|
|
17
17
|
} from "../../../shared/classify-files-by-role.ts";
|
|
18
18
|
import { lineNumbersIn, lineOfTheFirstLabel } from "../../../shared/count-the-line-of-an-offset.ts";
|
|
19
|
+
import { listedBinaryFilesOf } from "../../../shared/find-installed-package-binaries.ts";
|
|
19
20
|
import { moduleRequestsIn, URL_REQUESTS } from "../../../shared/find-module-requests.ts";
|
|
20
21
|
import type { MODULE_REQUEST_KINDS } from "../../../shared/find-module-requests.ts";
|
|
22
|
+
import { PACKAGE_MANIFEST_FILE } from "../../../shared/find-named-package-manifests.ts";
|
|
21
23
|
import { existingPackageFiles } from "../../../shared/list-package-files.ts";
|
|
24
|
+
import { rootManifestIn } from "../../../shared/match-granted-patch-files.ts";
|
|
22
25
|
import { isFormatConfigTextRefusedIn } from "../../../shared/parse-config-files-that-import-from-check.ts";
|
|
23
26
|
import {
|
|
24
27
|
BunConfigInvalid,
|
|
@@ -33,6 +36,7 @@ import {
|
|
|
33
36
|
import { resolveModuleRequest } from "../../../shared/resolve-module-requests.ts";
|
|
34
37
|
import { ImportUnresolvableInTheImportBoundaryCheck } from "./export-placement-errors.ts";
|
|
35
38
|
import { packageEntrySourcesAmong } from "./find-package-entry-sources.ts";
|
|
39
|
+
import { makesATaskInItsDefaultExport } from "./recognise-task-default-exports.ts";
|
|
36
40
|
|
|
37
41
|
export const EVERY_EXPORT = "*";
|
|
38
42
|
export const DEFAULT_EXPORT = "default";
|
|
@@ -190,6 +194,11 @@ export const findTheImporterGraph = (projectFile: string) =>
|
|
|
190
194
|
const text = yield* fileSystem.readFileString(path.join(packageDirectory, file));
|
|
191
195
|
files.set(file, yield* moduleUsesIn(file, text, resolverFor(file)));
|
|
192
196
|
}
|
|
197
|
+
const runsItsDefaultExport = new Set(
|
|
198
|
+
[...files].flatMap(([file, { parsed }]) =>
|
|
199
|
+
makesATaskInItsDefaultExport(parsed) ? [file] : [],
|
|
200
|
+
),
|
|
201
|
+
);
|
|
193
202
|
|
|
194
203
|
const trackedPackageFiles = new Set(
|
|
195
204
|
yield* existingPackageFiles(packageDirectory, [BUN_CONFIG_FILE]),
|
|
@@ -250,8 +259,18 @@ export const findTheImporterGraph = (projectFile: string) =>
|
|
|
250
259
|
...preloaded,
|
|
251
260
|
...testPreloaded,
|
|
252
261
|
]);
|
|
262
|
+
const binaryEntries = [
|
|
263
|
+
...listedBinaryFilesOf(
|
|
264
|
+
yield* rootManifestIn(
|
|
265
|
+
packageDirectory,
|
|
266
|
+
yield* existingPackageFiles(packageDirectory, [PACKAGE_MANIFEST_FILE]),
|
|
267
|
+
),
|
|
268
|
+
),
|
|
269
|
+
];
|
|
253
270
|
const reachable = reach([
|
|
254
271
|
...roots,
|
|
272
|
+
...binaryEntries,
|
|
273
|
+
...runsItsDefaultExport,
|
|
255
274
|
...[...files.keys()].filter((file) => isDeclarationFile(file) || isUnderTestDirectory(file)),
|
|
256
275
|
]);
|
|
257
276
|
const importers = new Map<string, Set<string>>();
|
|
@@ -278,6 +297,8 @@ export const findTheImporterGraph = (projectFile: string) =>
|
|
|
278
297
|
reach,
|
|
279
298
|
exportsAreReadFromOutside,
|
|
280
299
|
roots,
|
|
300
|
+
runsItsDefaultExport,
|
|
301
|
+
binaryEntries,
|
|
281
302
|
reachable,
|
|
282
303
|
moduleDirectories,
|
|
283
304
|
importersOf,
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import type { Expression, ParseResult } from "oxc-parser";
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
TASK_MAKE_MEMBER,
|
|
5
|
+
TASK_NAMESPACE_EXPORT,
|
|
6
|
+
TASK_PACKAGE,
|
|
7
|
+
} from "../../../../../shared/bans-each-permission-lifts.ts";
|
|
8
|
+
|
|
9
|
+
const TASK_GROUP_MEMBERS = ["all", "allSettled"] as const;
|
|
10
|
+
|
|
11
|
+
const MEMBERS_THAT_MAKE_TASKS: ReadonlySet<string> = new Set([
|
|
12
|
+
TASK_MAKE_MEMBER,
|
|
13
|
+
...TASK_GROUP_MEMBERS,
|
|
14
|
+
]);
|
|
15
|
+
|
|
16
|
+
const withoutWrappers = (expression: Expression): Expression => {
|
|
17
|
+
const isTransparentWrapper =
|
|
18
|
+
expression.type === "ParenthesizedExpression" ||
|
|
19
|
+
expression.type === "TSAsExpression" ||
|
|
20
|
+
expression.type === "TSSatisfiesExpression" ||
|
|
21
|
+
expression.type === "TSTypeAssertion" ||
|
|
22
|
+
expression.type === "TSNonNullExpression";
|
|
23
|
+
return isTransparentWrapper ? withoutWrappers(expression.expression) : expression;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
const importedMemberPath = (
|
|
27
|
+
expression: Expression,
|
|
28
|
+
imports: ReadonlyMap<string, readonly string[]>,
|
|
29
|
+
): readonly string[] | undefined => {
|
|
30
|
+
const unwrapped = withoutWrappers(expression);
|
|
31
|
+
if (unwrapped.type === "Identifier") {
|
|
32
|
+
return imports.get(unwrapped.name);
|
|
33
|
+
}
|
|
34
|
+
const isStaticMember =
|
|
35
|
+
unwrapped.type === "MemberExpression" &&
|
|
36
|
+
!unwrapped.computed &&
|
|
37
|
+
unwrapped.property.type === "Identifier";
|
|
38
|
+
if (!isStaticMember) {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
const object = importedMemberPath(unwrapped.object, imports);
|
|
42
|
+
return object === undefined ? undefined : [...object, unwrapped.property.name];
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
export const makesATaskInItsDefaultExport = (parsed: ParseResult) => {
|
|
46
|
+
const exported = parsed.program.body.find(
|
|
47
|
+
(statement) => statement.type === "ExportDefaultDeclaration",
|
|
48
|
+
);
|
|
49
|
+
const declaration =
|
|
50
|
+
exported?.type === "ExportDefaultDeclaration" ? exported.declaration : undefined;
|
|
51
|
+
const isNotAnExpression =
|
|
52
|
+
declaration === undefined ||
|
|
53
|
+
declaration.type === "FunctionDeclaration" ||
|
|
54
|
+
declaration.type === "ClassDeclaration" ||
|
|
55
|
+
declaration.type === "TSInterfaceDeclaration";
|
|
56
|
+
const value = isNotAnExpression ? undefined : withoutWrappers(declaration);
|
|
57
|
+
if (value?.type !== "CallExpression") {
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
60
|
+
const literalTaskImports = new Map(
|
|
61
|
+
parsed.module.staticImports
|
|
62
|
+
.filter((statement) => statement.moduleRequest.value === TASK_PACKAGE)
|
|
63
|
+
.flatMap((statement) => statement.entries)
|
|
64
|
+
.filter((entry) => !entry.isType)
|
|
65
|
+
.map(
|
|
66
|
+
(entry) =>
|
|
67
|
+
[
|
|
68
|
+
entry.localName.value,
|
|
69
|
+
entry.importName.kind === "NamespaceObject" ? [] : [entry.importName.name ?? ""],
|
|
70
|
+
] as const,
|
|
71
|
+
),
|
|
72
|
+
);
|
|
73
|
+
const member = importedMemberPath(value.callee, literalTaskImports) ?? [];
|
|
74
|
+
const isTaskMember = member.slice(0, -1).join(".") === TASK_NAMESPACE_EXPORT;
|
|
75
|
+
return isTaskMember && MEMBERS_THAT_MAKE_TASKS.has(member.at(-1) ?? "");
|
|
76
|
+
};
|
|
@@ -7,10 +7,10 @@ import { typeScriptConfig } from "../../shared/declare-typescript-config-task.ts
|
|
|
7
7
|
import { ProjectQueryCachesLive } from "../../shared/provide-project-query-caches.ts";
|
|
8
8
|
import { findDisableDirectivesInLintedFilesOf } from "./internal/find-disable-directives.ts";
|
|
9
9
|
|
|
10
|
-
export const directives = Task.make(
|
|
11
|
-
"directives",
|
|
12
|
-
Effect.andThen(
|
|
10
|
+
export const directives = Task.make({
|
|
11
|
+
name: "directives",
|
|
12
|
+
run: Effect.andThen(
|
|
13
13
|
Task.all([typeScriptConfig, lintConfigFile]),
|
|
14
|
-
inEachPackage("directives",
|
|
14
|
+
inEachPackage("directives", findDisableDirectivesInLintedFilesOf),
|
|
15
15
|
).pipe(Effect.provide(ProjectQueryCachesLive)),
|
|
16
|
-
);
|
|
16
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { findUnobservedForkFailures } from "./internal/find-unobserved-fork-failures.ts";
|
|
@@ -0,0 +1,402 @@
|
|
|
1
|
+
import { Effect, Path } from "effect";
|
|
2
|
+
import type { CallExpression, Node, SourceFile } from "typescript/unstable/ast";
|
|
3
|
+
import {
|
|
4
|
+
isCallExpression,
|
|
5
|
+
isExpressionStatement,
|
|
6
|
+
isPropertyAccessExpression,
|
|
7
|
+
isVoidExpression,
|
|
8
|
+
isYieldExpression,
|
|
9
|
+
} from "typescript/unstable/ast/is";
|
|
10
|
+
import {
|
|
11
|
+
ElementFlags,
|
|
12
|
+
isErrorType,
|
|
13
|
+
isObjectType,
|
|
14
|
+
isStringMappingType,
|
|
15
|
+
isTemplateLiteralType,
|
|
16
|
+
isTupleType,
|
|
17
|
+
isTypeReference,
|
|
18
|
+
ObjectFlags,
|
|
19
|
+
SignatureKind,
|
|
20
|
+
TypeFlags,
|
|
21
|
+
} from "typescript/unstable/async";
|
|
22
|
+
import type { Checker, Type } from "typescript/unstable/async";
|
|
23
|
+
|
|
24
|
+
import { isUnderTestDirectory } from "../../../shared/classify-files-by-role.ts";
|
|
25
|
+
import {
|
|
26
|
+
callsIn,
|
|
27
|
+
CONCURRENT_TYPESCRIPT_REQUESTS,
|
|
28
|
+
nodePosition,
|
|
29
|
+
packageCalleesIn,
|
|
30
|
+
packageFileOf,
|
|
31
|
+
requiredTypeScriptRequest,
|
|
32
|
+
resolvedSymbols,
|
|
33
|
+
typeMembers,
|
|
34
|
+
typeScriptRequest,
|
|
35
|
+
} from "../../../shared/query-the-typescript-project.ts";
|
|
36
|
+
import type { openTypeScriptProjects } from "../../../shared/query-the-typescript-project.ts";
|
|
37
|
+
import {
|
|
38
|
+
outermostWrapperOf,
|
|
39
|
+
pipedStepsOf,
|
|
40
|
+
referencedNameOf,
|
|
41
|
+
withoutWrappers,
|
|
42
|
+
} from "../../../shared/read-piped-steps-through-wrappers.ts";
|
|
43
|
+
import { absolutePathOf } from "../../../shared/resolve-absolute-paths.ts";
|
|
44
|
+
import { ForkFailureUnobserved, UnobservedForkFailuresRefused } from "./fork-failure-errors.ts";
|
|
45
|
+
|
|
46
|
+
const EFFECT_TYPE_ID = "~effect/Effect" satisfies keyof Effect.Effect<unknown>;
|
|
47
|
+
const FAILURE_VARIANCE = "_E";
|
|
48
|
+
const EFFECT_DECLARATION_FILE = "effect/dist/effect.d.ts";
|
|
49
|
+
const RUN_FORK = "runFork";
|
|
50
|
+
const RUN_FORK_WITH = "runForkWith";
|
|
51
|
+
const FIBER_FORKS: ReadonlySet<string> = new Set([RUN_FORK, RUN_FORK_WITH]);
|
|
52
|
+
const EFFECT_FORK_NAMES = ["forkChild", "forkScoped", "forkIn", "forkDetach"] as const;
|
|
53
|
+
const EFFECT_FORKS: ReadonlySet<string> = new Set(EFFECT_FORK_NAMES);
|
|
54
|
+
const BARE_FORKS: ReadonlySet<string> = new Set([RUN_FORK, ...EFFECT_FORK_NAMES]);
|
|
55
|
+
const FAILURE_HIDING_NAMES = ["exit", "result", "option"] as const;
|
|
56
|
+
const FAILURE_HIDING_STEPS: ReadonlySet<string> = new Set(FAILURE_HIDING_NAMES);
|
|
57
|
+
const VALUE_DISCARD_NAMES = ["asVoid", "as"] as const;
|
|
58
|
+
const VALUE_DISCARDS: ReadonlySet<string> = new Set(VALUE_DISCARD_NAMES);
|
|
59
|
+
const STEP_NAMES: ReadonlySet<string> = new Set([
|
|
60
|
+
RUN_FORK,
|
|
61
|
+
...EFFECT_FORK_NAMES,
|
|
62
|
+
...FAILURE_HIDING_NAMES,
|
|
63
|
+
...VALUE_DISCARD_NAMES,
|
|
64
|
+
]);
|
|
65
|
+
const OPEN_TYPES =
|
|
66
|
+
TypeFlags.TypeVariable |
|
|
67
|
+
TypeFlags.Conditional |
|
|
68
|
+
TypeFlags.Substitution |
|
|
69
|
+
TypeFlags.Index |
|
|
70
|
+
TypeFlags.Intersection;
|
|
71
|
+
|
|
72
|
+
const isSameNode = (left: Node, right: Node) => left.pos === right.pos && left.end === right.end;
|
|
73
|
+
|
|
74
|
+
const pipePositionOf = (node: Node) => {
|
|
75
|
+
const outer = outermostWrapperOf(node);
|
|
76
|
+
const { parent } = outer;
|
|
77
|
+
const isReceiver = isPropertyAccessExpression(parent) && parent.expression === outer;
|
|
78
|
+
const call = isReceiver ? parent.parent : parent;
|
|
79
|
+
if (!isCallExpression(call)) {
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
const steps = pipedStepsOf(call);
|
|
83
|
+
const index = steps?.findIndex((step) => isSameNode(step, outer)) ?? -1;
|
|
84
|
+
const isPiped = steps !== undefined && index >= 0;
|
|
85
|
+
return isPiped ? { pipe: call, steps, index } : undefined;
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
const isThrownAway = (value: Node) => {
|
|
89
|
+
const { parent } = outermostWrapperOf(value);
|
|
90
|
+
return isExpressionStatement(parent) || isVoidExpression(parent);
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
const isYieldedAndThrownAway = (value: Node) => {
|
|
94
|
+
const { parent } = outermostWrapperOf(value);
|
|
95
|
+
const isDelegated = isYieldExpression(parent) && parent.asteriskToken !== undefined;
|
|
96
|
+
return isDelegated && isThrownAway(parent);
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
const argumentIndexOf = (call: CallExpression, node: Node) => {
|
|
100
|
+
const outer = outermostWrapperOf(node);
|
|
101
|
+
return call.arguments.findIndex((argument) => isSameNode(argument, outer));
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
const pipeStepInputs = (checker: Checker, pipe: CallExpression, step: Node) =>
|
|
105
|
+
Effect.gen(function* () {
|
|
106
|
+
const signature = yield* typeScriptRequest("resolve a pipe's signature", () =>
|
|
107
|
+
checker.getResolvedSignature(pipe),
|
|
108
|
+
);
|
|
109
|
+
const stepType =
|
|
110
|
+
signature === undefined
|
|
111
|
+
? undefined
|
|
112
|
+
: yield* typeScriptRequest("read a pipe step's type", () =>
|
|
113
|
+
checker.getParameterType(signature, argumentIndexOf(pipe, step)),
|
|
114
|
+
);
|
|
115
|
+
const stepSignatures =
|
|
116
|
+
stepType === undefined
|
|
117
|
+
? []
|
|
118
|
+
: yield* typeScriptRequest("read a pipe step's signatures", () =>
|
|
119
|
+
checker.getSignaturesOfType(stepType, SignatureKind.Call),
|
|
120
|
+
);
|
|
121
|
+
const inputs = yield* Effect.forEach(stepSignatures, (stepSignature) =>
|
|
122
|
+
typeScriptRequest("read a pipe step's input", () =>
|
|
123
|
+
checker.getParameterType(stepSignature, 0),
|
|
124
|
+
),
|
|
125
|
+
);
|
|
126
|
+
return inputs.filter((input) => input !== undefined);
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
const failuresOf = (checker: Checker, effect: Type) =>
|
|
130
|
+
Effect.gen(function* () {
|
|
131
|
+
const members = yield* typeMembers(effect);
|
|
132
|
+
const failures = yield* Effect.forEach(members, (member) =>
|
|
133
|
+
Effect.gen(function* () {
|
|
134
|
+
const marker = yield* typeScriptRequest("read a type id", () =>
|
|
135
|
+
checker.getPropertyOfType(member, EFFECT_TYPE_ID),
|
|
136
|
+
);
|
|
137
|
+
if (marker === undefined) {
|
|
138
|
+
return [];
|
|
139
|
+
}
|
|
140
|
+
const markerType = yield* requiredTypeScriptRequest("read the type of a type id", () =>
|
|
141
|
+
checker.getTypeOfSymbol(marker),
|
|
142
|
+
);
|
|
143
|
+
const variance = yield* typeScriptRequest("read a failure variance", () =>
|
|
144
|
+
checker.getPropertyOfType(markerType, FAILURE_VARIANCE),
|
|
145
|
+
);
|
|
146
|
+
if (variance === undefined) {
|
|
147
|
+
return [];
|
|
148
|
+
}
|
|
149
|
+
const varianceType = yield* requiredTypeScriptRequest(
|
|
150
|
+
"read the type of a failure variance",
|
|
151
|
+
() => checker.getTypeOfSymbol(variance),
|
|
152
|
+
);
|
|
153
|
+
const signatures = yield* typeScriptRequest("read the signature of a variance", () =>
|
|
154
|
+
checker.getSignaturesOfType(varianceType, SignatureKind.Call),
|
|
155
|
+
);
|
|
156
|
+
return yield* Effect.forEach(signatures, (signature) =>
|
|
157
|
+
requiredTypeScriptRequest("read the failure a variance holds", () =>
|
|
158
|
+
checker.getReturnTypeOfSignature(signature),
|
|
159
|
+
),
|
|
160
|
+
);
|
|
161
|
+
}),
|
|
162
|
+
);
|
|
163
|
+
return failures.flat();
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
const isOpen = (
|
|
167
|
+
failure: Type,
|
|
168
|
+
): Effect.Effect<boolean, Effect.Error<ReturnType<typeof typeScriptRequest>>> =>
|
|
169
|
+
Effect.gen(function* () {
|
|
170
|
+
const isMapped = isObjectType(failure) && (failure.objectFlags & ObjectFlags.Mapped) !== 0;
|
|
171
|
+
const isOpenByKind = (failure.flags & OPEN_TYPES) !== 0 || isMapped;
|
|
172
|
+
if (isOpenByKind) {
|
|
173
|
+
return true;
|
|
174
|
+
}
|
|
175
|
+
const tuple = isTypeReference(failure)
|
|
176
|
+
? yield* typeScriptRequest("read the type a reference refers to", () => failure.getTarget())
|
|
177
|
+
: undefined;
|
|
178
|
+
const isSpreadTuple =
|
|
179
|
+
tuple !== undefined &&
|
|
180
|
+
isTupleType(tuple) &&
|
|
181
|
+
Array.isArray(tuple.elementFlags) &&
|
|
182
|
+
tuple.elementFlags.some((flags) => (flags & ElementFlags.Variadic) !== 0);
|
|
183
|
+
if (isSpreadTuple) {
|
|
184
|
+
return true;
|
|
185
|
+
}
|
|
186
|
+
const templateParts = isTemplateLiteralType(failure)
|
|
187
|
+
? yield* typeScriptRequest("read the parts of a template type", () => failure.getTypes())
|
|
188
|
+
: [];
|
|
189
|
+
const mappedStrings = isStringMappingType(failure)
|
|
190
|
+
? [yield* typeScriptRequest("read the type a string mapping maps", () => failure.getTarget())]
|
|
191
|
+
: [];
|
|
192
|
+
const openParts = yield* Effect.forEach([...templateParts, ...mappedStrings], isOpen);
|
|
193
|
+
return openParts.some(Boolean);
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
const namedFailures = (checker: Checker, failureTypes: readonly Type[]) =>
|
|
197
|
+
Effect.gen(function* () {
|
|
198
|
+
const members = (yield* Effect.forEach(failureTypes, (failure) => typeMembers(failure))).flat();
|
|
199
|
+
const isUnknown = members.some(
|
|
200
|
+
(member) => (member.flags & TypeFlags.AnyOrUnknown) !== 0 || isErrorType(member),
|
|
201
|
+
);
|
|
202
|
+
if (isUnknown) {
|
|
203
|
+
return [];
|
|
204
|
+
}
|
|
205
|
+
const failures = members.filter((member) => (member.flags & TypeFlags.Never) === 0);
|
|
206
|
+
const openness = yield* Effect.forEach(failures, isOpen);
|
|
207
|
+
const concreteFailures = failures.filter((_failure, index) => openness[index] !== true);
|
|
208
|
+
const names = yield* Effect.forEach(concreteFailures, (failure) =>
|
|
209
|
+
typeScriptRequest("name a failure type", () => checker.typeToString(failure)),
|
|
210
|
+
);
|
|
211
|
+
return [...new Set(names)].toSorted();
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
const fileViolations = (
|
|
215
|
+
checker: Checker,
|
|
216
|
+
projectDirectory: string,
|
|
217
|
+
sourceFile: SourceFile,
|
|
218
|
+
displayName: string,
|
|
219
|
+
) =>
|
|
220
|
+
Effect.gen(function* () {
|
|
221
|
+
const callees = yield* packageCalleesIn(checker, projectDirectory, sourceFile);
|
|
222
|
+
const operationOfCall = new Map(
|
|
223
|
+
callees.flatMap(({ call, file, name, returnedBySignature }) =>
|
|
224
|
+
file === EFFECT_DECLARATION_FILE ? [[call, { name, returnedBySignature }] as const] : [],
|
|
225
|
+
),
|
|
226
|
+
);
|
|
227
|
+
const bareSteps = callsIn(sourceFile)
|
|
228
|
+
.flatMap((call) => pipedStepsOf(call)?.slice(1) ?? [])
|
|
229
|
+
.map((step) => withoutWrappers(step))
|
|
230
|
+
.filter((step) => !isCallExpression(step))
|
|
231
|
+
.flatMap((step) => {
|
|
232
|
+
const name = referencedNameOf(step);
|
|
233
|
+
const isNamedLikeAStep = name !== undefined && STEP_NAMES.has(name.text);
|
|
234
|
+
return isNamedLikeAStep ? [{ step, name }] : [];
|
|
235
|
+
});
|
|
236
|
+
const stepSymbols = yield* resolvedSymbols(
|
|
237
|
+
checker,
|
|
238
|
+
bareSteps.map(({ name }) => name),
|
|
239
|
+
);
|
|
240
|
+
const operationOfStep = new Map(
|
|
241
|
+
bareSteps.flatMap(({ step }, index) => {
|
|
242
|
+
const symbol = stepSymbols[index];
|
|
243
|
+
const declaration = symbol?.declarations.at(0);
|
|
244
|
+
const file =
|
|
245
|
+
declaration === undefined ? undefined : packageFileOf(projectDirectory, declaration.path);
|
|
246
|
+
const isEffectStep = symbol !== undefined && file === EFFECT_DECLARATION_FILE;
|
|
247
|
+
return isEffectStep
|
|
248
|
+
? [[step, { name: symbol.name, returnedBySignature: false }] as const]
|
|
249
|
+
: [];
|
|
250
|
+
}),
|
|
251
|
+
);
|
|
252
|
+
const isOperation = (node: Node, names: ReadonlySet<string>) => {
|
|
253
|
+
const value = withoutWrappers(node);
|
|
254
|
+
const operation = isCallExpression(value)
|
|
255
|
+
? operationOfCall.get(value)
|
|
256
|
+
: operationOfStep.get(value);
|
|
257
|
+
return operation !== undefined && names.has(operation.name);
|
|
258
|
+
};
|
|
259
|
+
|
|
260
|
+
const typesAt = (node: Node) =>
|
|
261
|
+
typeScriptRequest("read a forked effect's type", () => checker.getTypeAtLocation(node)).pipe(
|
|
262
|
+
Effect.map((type) => (type === undefined ? [] : [type])),
|
|
263
|
+
);
|
|
264
|
+
|
|
265
|
+
const effectsBeforeHiding = (effect: Node) => {
|
|
266
|
+
const value = withoutWrappers(effect);
|
|
267
|
+
if (!isCallExpression(value)) {
|
|
268
|
+
return typesAt(effect);
|
|
269
|
+
}
|
|
270
|
+
const steps = pipedStepsOf(value);
|
|
271
|
+
const lastStep = steps?.at(-1);
|
|
272
|
+
if (lastStep === undefined) {
|
|
273
|
+
const [hidden] = value.arguments;
|
|
274
|
+
const isHidingCall = hidden !== undefined && isOperation(value, FAILURE_HIDING_STEPS);
|
|
275
|
+
return isHidingCall ? typesAt(hidden) : typesAt(effect);
|
|
276
|
+
}
|
|
277
|
+
const isHidingStep =
|
|
278
|
+
steps !== undefined && steps.length > 1 && isOperation(lastStep, FAILURE_HIDING_STEPS);
|
|
279
|
+
return isHidingStep ? pipeStepInputs(checker, value, lastStep) : typesAt(effect);
|
|
280
|
+
};
|
|
281
|
+
|
|
282
|
+
const forkedEffects = (fork: Node, input: Node | undefined) => {
|
|
283
|
+
if (input !== undefined) {
|
|
284
|
+
return effectsBeforeHiding(input);
|
|
285
|
+
}
|
|
286
|
+
const position = pipePositionOf(fork);
|
|
287
|
+
const isStep = position !== undefined && position.index > 0;
|
|
288
|
+
if (!isStep) {
|
|
289
|
+
return Effect.succeed([]);
|
|
290
|
+
}
|
|
291
|
+
const stepBefore = position.steps.at(position.index - 1);
|
|
292
|
+
if (stepBefore === undefined) {
|
|
293
|
+
return Effect.succeed([]);
|
|
294
|
+
}
|
|
295
|
+
if (position.index === 1) {
|
|
296
|
+
return effectsBeforeHiding(stepBefore);
|
|
297
|
+
}
|
|
298
|
+
return isOperation(stepBefore, FAILURE_HIDING_STEPS)
|
|
299
|
+
? pipeStepInputs(checker, position.pipe, stepBefore)
|
|
300
|
+
: pipeStepInputs(checker, position.pipe, fork);
|
|
301
|
+
};
|
|
302
|
+
|
|
303
|
+
const isDropped = (fork: Node, name: string) => {
|
|
304
|
+
const position = pipePositionOf(fork);
|
|
305
|
+
const laterSteps = position?.steps.slice(position.index + 1) ?? [];
|
|
306
|
+
const value = position?.pipe ?? fork;
|
|
307
|
+
if (FIBER_FORKS.has(name)) {
|
|
308
|
+
return laterSteps.length === 0 && isThrownAway(value);
|
|
309
|
+
}
|
|
310
|
+
const [nextStep] = laterSteps;
|
|
311
|
+
const isFiberDiscarded = nextStep === undefined || isOperation(nextStep, VALUE_DISCARDS);
|
|
312
|
+
return isFiberDiscarded && isYieldedAndThrownAway(value);
|
|
313
|
+
};
|
|
314
|
+
|
|
315
|
+
const forks = [
|
|
316
|
+
...[...operationOfCall].flatMap(([call, { name, returnedBySignature }]) => {
|
|
317
|
+
const isFork = FIBER_FORKS.has(name) || EFFECT_FORKS.has(name);
|
|
318
|
+
const position = pipePositionOf(call);
|
|
319
|
+
const isStep = position !== undefined && position.index > 0;
|
|
320
|
+
const isRunnerMade = name === RUN_FORK_WITH && !returnedBySignature;
|
|
321
|
+
const takesOptions = FIBER_FORKS.has(name) && call.arguments.length !== 1;
|
|
322
|
+
const isPipedRunFork = isStep && name === RUN_FORK;
|
|
323
|
+
const isSkipped = !isFork || isPipedRunFork;
|
|
324
|
+
if (isSkipped) {
|
|
325
|
+
return [];
|
|
326
|
+
}
|
|
327
|
+
if (isStep) {
|
|
328
|
+
return [{ fork: call, name, input: undefined }];
|
|
329
|
+
}
|
|
330
|
+
const curried = call.parent;
|
|
331
|
+
const isCalledAtOnce =
|
|
332
|
+
EFFECT_FORKS.has(name) &&
|
|
333
|
+
isCallExpression(curried) &&
|
|
334
|
+
curried.expression === call &&
|
|
335
|
+
!operationOfCall.has(curried);
|
|
336
|
+
if (isCalledAtOnce) {
|
|
337
|
+
return [{ fork: curried, name, input: curried.arguments.at(0) }];
|
|
338
|
+
}
|
|
339
|
+
const isNotAFork = isRunnerMade || takesOptions;
|
|
340
|
+
return isNotAFork ? [] : [{ fork: call, name, input: call.arguments.at(0) }];
|
|
341
|
+
}),
|
|
342
|
+
...[...operationOfStep].flatMap(([step, { name }]) =>
|
|
343
|
+
BARE_FORKS.has(name) ? [{ fork: step, name, input: undefined }] : [],
|
|
344
|
+
),
|
|
345
|
+
]
|
|
346
|
+
.filter(({ fork, name }) => isDropped(fork, name))
|
|
347
|
+
.toSorted((left, right) => left.fork.pos - right.fork.pos);
|
|
348
|
+
|
|
349
|
+
const violations = yield* Effect.forEach(
|
|
350
|
+
forks,
|
|
351
|
+
({ fork, name, input }) =>
|
|
352
|
+
Effect.gen(function* () {
|
|
353
|
+
const effects = yield* forkedEffects(fork, input);
|
|
354
|
+
const failureTypes = yield* Effect.forEach(effects, (effect) =>
|
|
355
|
+
failuresOf(checker, effect),
|
|
356
|
+
);
|
|
357
|
+
const [firstFailure, ...otherFailures] = yield* namedFailures(
|
|
358
|
+
checker,
|
|
359
|
+
failureTypes.flat(),
|
|
360
|
+
);
|
|
361
|
+
if (firstFailure === undefined) {
|
|
362
|
+
return [];
|
|
363
|
+
}
|
|
364
|
+
const { line, column } = nodePosition(sourceFile, fork);
|
|
365
|
+
return [
|
|
366
|
+
new ForkFailureUnobserved({
|
|
367
|
+
location: `${displayName}:${line}:${column}`,
|
|
368
|
+
fork: `Effect.${name}`,
|
|
369
|
+
failures: [firstFailure, ...otherFailures],
|
|
370
|
+
}),
|
|
371
|
+
];
|
|
372
|
+
}),
|
|
373
|
+
{ concurrency: CONCURRENT_TYPESCRIPT_REQUESTS },
|
|
374
|
+
);
|
|
375
|
+
return violations.flat();
|
|
376
|
+
});
|
|
377
|
+
|
|
378
|
+
export const findUnobservedForkFailures = <OpeningError, OpeningRequirement>(
|
|
379
|
+
projectFile: string,
|
|
380
|
+
openedProjects: Effect.Effect<
|
|
381
|
+
Effect.Success<ReturnType<typeof openTypeScriptProjects>>,
|
|
382
|
+
OpeningError,
|
|
383
|
+
OpeningRequirement
|
|
384
|
+
>,
|
|
385
|
+
) =>
|
|
386
|
+
Effect.gen(function* () {
|
|
387
|
+
const projectDirectory = (yield* Path.Path).dirname(yield* absolutePathOf(projectFile));
|
|
388
|
+
const violationsOfEachProject = yield* Effect.forEach(
|
|
389
|
+
yield* openedProjects,
|
|
390
|
+
({ checker, sourceFiles }) =>
|
|
391
|
+
Effect.forEach(
|
|
392
|
+
sourceFiles.filter(({ displayName }) => !isUnderTestDirectory(displayName)),
|
|
393
|
+
({ sourceFile, displayName }) =>
|
|
394
|
+
fileViolations(checker, projectDirectory, sourceFile, displayName),
|
|
395
|
+
{ concurrency: CONCURRENT_TYPESCRIPT_REQUESTS },
|
|
396
|
+
),
|
|
397
|
+
);
|
|
398
|
+
const violations = violationsOfEachProject.flat().flat();
|
|
399
|
+
if (violations.length > 0) {
|
|
400
|
+
return yield* new UnobservedForkFailuresRefused({ violations });
|
|
401
|
+
}
|
|
402
|
+
});
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { Schema } from "effect";
|
|
2
|
+
|
|
3
|
+
import { listedViolations } from "../../../../../shared/format-reported-failures.ts";
|
|
4
|
+
|
|
5
|
+
const joinedWithOr = (names: readonly string[]) =>
|
|
6
|
+
names.length > 1 ? `${names.slice(0, -1).join(", ")} or ${names.at(-1) ?? ""}` : names.join("");
|
|
7
|
+
|
|
8
|
+
export class ForkFailureUnobserved extends Schema.TaggedError<ForkFailureUnobserved>()(
|
|
9
|
+
"ForkFailureUnobserved",
|
|
10
|
+
{
|
|
11
|
+
location: Schema.String,
|
|
12
|
+
fork: Schema.String,
|
|
13
|
+
failures: Schema.Array(Schema.String),
|
|
14
|
+
},
|
|
15
|
+
) {
|
|
16
|
+
public override get message() {
|
|
17
|
+
return `${this.fork} forks an effect that can still fail with ${joinedWithOr(this.failures)}, and its fiber is dropped where it is made.`;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export class UnobservedForkFailuresRefused extends Schema.TaggedError<UnobservedForkFailuresRefused>()(
|
|
22
|
+
"UnobservedForkFailuresRefused",
|
|
23
|
+
{ violations: Schema.Array(ForkFailureUnobserved) },
|
|
24
|
+
) {
|
|
25
|
+
public override get message() {
|
|
26
|
+
return listedViolations(this.violations);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -6,10 +6,10 @@ import { typeScriptConfig } from "../../shared/declare-typescript-config-task.ts
|
|
|
6
6
|
import { ProjectQueryCachesLive } from "../../shared/provide-project-query-caches.ts";
|
|
7
7
|
import { lintedFilesNotTypeCheckedInEachPackage } from "./internal/find-linted-files-not-type-checked.ts";
|
|
8
8
|
|
|
9
|
-
export const lintedFilesTypeChecked = Task.make(
|
|
10
|
-
"linted-files-type-checked",
|
|
11
|
-
Effect.andThen(
|
|
9
|
+
export const lintedFilesTypeChecked = Task.make({
|
|
10
|
+
name: "linted-files-type-checked",
|
|
11
|
+
run: Effect.andThen(
|
|
12
12
|
Task.all([typeScriptConfig, lintConfigFile]),
|
|
13
13
|
lintedFilesNotTypeCheckedInEachPackage,
|
|
14
14
|
).pipe(Effect.provide(ProjectQueryCachesLive)),
|
|
15
|
-
);
|
|
15
|
+
});
|