@sshkeda/check 2.2.0 → 3.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 +52 -22
- package/docs/how-to-make-check-pass.md +1 -0
- package/package.json +7 -10
- package/scripts/check.ts +10 -0
- 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 +5 -0
- package/src/lib/project-directory/internal/read-the-project-directory.ts +13 -0
- package/src/lib/tasks/internal/declare-the-check-task.ts +18 -10
- package/src/lib/tasks/internal/declare-the-checker-queries-task.ts +3 -1
- package/src/lib/tasks/internal/verify-where-check-was-started.ts +50 -0
- package/src/lib/tasks/lib/check-effect-diagnostics-with-effect-tsgo/index.ts +1 -1
- package/src/lib/tasks/lib/confine-layer-provides-to-program-starts/internal/find-layer-provides-outside-program-starts.ts +6 -36
- package/src/lib/tasks/lib/detect-duplicate-functions/internal/find-duplicate-functions.ts +2 -3
- 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 +19 -2
- package/src/lib/tasks/lib/enforce-file-layout/internal/find-file-layout-violations.ts +53 -19
- 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 +22 -14
- package/src/lib/tasks/lib/lint-with-oxlint/index.ts +1 -1
- 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 +1 -1
- 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/internal/find-linted-files-not-type-checked.ts +15 -9
- package/src/lib/tasks/lib/type-check-with-bun-check/index.ts +1 -1
- package/src/lib/tasks/shared/check-each-nested-package.ts +12 -4
- package/src/lib/tasks/shared/declare-lint-config-task.ts +1 -1
- package/src/lib/tasks/shared/declare-typescript-config-task.ts +1 -1
- 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/format-reported-failures.ts +8 -6
- package/src/shared/record-and-grant-permissions-by-path.ts +4 -1
- package/src/internal/ban-shebang-lines.ts +0 -22
|
@@ -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
|
+
}
|
|
@@ -36,6 +36,7 @@ const isTypeChecked = (
|
|
|
36
36
|
|
|
37
37
|
const violationFor = (
|
|
38
38
|
file: string,
|
|
39
|
+
shownPathOf: (configFile: string) => string,
|
|
39
40
|
projectFile: string,
|
|
40
41
|
compilingProjects: readonly {
|
|
41
42
|
readonly configFile: string;
|
|
@@ -44,17 +45,22 @@ const violationFor = (
|
|
|
44
45
|
) => {
|
|
45
46
|
const [firstProject] = compilingProjects;
|
|
46
47
|
if (firstProject === undefined) {
|
|
47
|
-
return new LintedFileOutsideTypeScriptProgram({
|
|
48
|
+
return new LintedFileOutsideTypeScriptProgram({
|
|
49
|
+
location: file,
|
|
50
|
+
projectFile: shownPathOf(projectFile),
|
|
51
|
+
});
|
|
48
52
|
}
|
|
49
|
-
const configFiles = compilingProjects.map(({ configFile }) => configFile);
|
|
53
|
+
const configFiles = compilingProjects.map(({ configFile }) => shownPathOf(configFile));
|
|
50
54
|
return firstProject.isDeclarationFile
|
|
51
55
|
? new LintedDeclarationFileNotTypeChecked({ location: file, configFiles })
|
|
52
56
|
: new LintedJavaScriptFileNotTypeChecked({ location: file, configFiles });
|
|
53
57
|
};
|
|
54
58
|
|
|
55
|
-
export const findLintedFilesNotTypeChecked = (projectFile: string) =>
|
|
59
|
+
export const findLintedFilesNotTypeChecked = (projectFile: string, shownPackageDirectory = ".") =>
|
|
56
60
|
Effect.gen(function* () {
|
|
57
61
|
const path = yield* Path.Path;
|
|
62
|
+
const shownPathOf = (configFile: string) =>
|
|
63
|
+
path.join(shownPackageDirectory, path.relative(path.dirname(projectFile), configFile));
|
|
58
64
|
const linted = yield* scriptFiles(projectFile);
|
|
59
65
|
const owned = new Set(yield* ownedFilesAmong(path.dirname(projectFile), linted));
|
|
60
66
|
const compilations = (yield* Effect.forEach(
|
|
@@ -94,7 +100,7 @@ export const findLintedFilesNotTypeChecked = (projectFile: string) =>
|
|
|
94
100
|
(isDeclarationFile(file) || compiling.some((compilation) => compilation.isDeclarationFile));
|
|
95
101
|
const isTypeCheckedOrExempt =
|
|
96
102
|
isGeneratedDeclarationFile || compiling.some(({ typeChecked }) => typeChecked);
|
|
97
|
-
return isTypeCheckedOrExempt ? [] : [violationFor(file, projectFile, compiling)];
|
|
103
|
+
return isTypeCheckedOrExempt ? [] : [violationFor(file, shownPathOf, projectFile, compiling)];
|
|
98
104
|
});
|
|
99
105
|
if (violations.length > 0) {
|
|
100
106
|
return yield* new LintedFilesNotTypeChecked({ violations });
|
|
@@ -105,11 +111,11 @@ const LINTED_FILES_TYPE_CHECKED = "linted-files-type-checked";
|
|
|
105
111
|
|
|
106
112
|
export const lintedFilesNotTypeCheckedInEachPackage = inEachPackage(
|
|
107
113
|
LINTED_FILES_TYPE_CHECKED,
|
|
108
|
-
|
|
109
|
-
(packageDirectory) =>
|
|
114
|
+
(packageDirectory, packageDirectoryFromTheProject) =>
|
|
110
115
|
Path.Path.use((path) =>
|
|
111
|
-
findLintedFilesNotTypeChecked(
|
|
112
|
-
|
|
113
|
-
|
|
116
|
+
findLintedFilesNotTypeChecked(
|
|
117
|
+
path.join(packageDirectory, TYPESCRIPT_PROJECT_FILE),
|
|
118
|
+
packageDirectoryFromTheProject,
|
|
119
|
+
).pipe(quietViolations(LINTED_FILES_TYPE_CHECKED)),
|
|
114
120
|
),
|
|
115
121
|
);
|
|
@@ -7,5 +7,5 @@ import { checkTypesWithBunCheckIn } from "./internal/check-types-with-bun-check.
|
|
|
7
7
|
|
|
8
8
|
export const typeCheck = Task.make(
|
|
9
9
|
"type-check",
|
|
10
|
-
Effect.andThen(typeScriptConfig, inEachPackage("type-check",
|
|
10
|
+
Effect.andThen(typeScriptConfig, inEachPackage("type-check", checkTypesWithBunCheckIn)),
|
|
11
11
|
);
|
|
@@ -3,8 +3,10 @@ import type { PrintableError } from "@sshkeda/task/errors";
|
|
|
3
3
|
import { Array as Arrays, Effect, Path } from "effect";
|
|
4
4
|
import type { PlatformError } from "effect";
|
|
5
5
|
|
|
6
|
+
import { projectDirectory } from "../../project-directory/index.ts";
|
|
6
7
|
import { listedPackageFiles } from "./list-package-files.ts";
|
|
7
8
|
import { quietViolations } from "./print-failures-and-keep-detail-in-the-trace.ts";
|
|
9
|
+
import { locatedFromTheProject, printedFromTheProject } from "./report-paths-from-the-project.ts";
|
|
8
10
|
|
|
9
11
|
const CHECKED_PACKAGE = ".";
|
|
10
12
|
|
|
@@ -61,18 +63,22 @@ export const packageDirectoriesIn = (directory: string) =>
|
|
|
61
63
|
|
|
62
64
|
export const inEachPackage = <Requirements>(
|
|
63
65
|
tool: string,
|
|
64
|
-
directory: string,
|
|
65
66
|
checkPackage: (
|
|
66
67
|
packageDirectory: string,
|
|
68
|
+
packageDirectoryFromTheProject: string,
|
|
67
69
|
) => Effect.Effect<void, PlatformError.PlatformError | ReportedErrors, Requirements>,
|
|
68
70
|
) =>
|
|
69
71
|
Effect.gen(function* () {
|
|
70
72
|
const pathModule = yield* Path.Path;
|
|
71
|
-
const
|
|
73
|
+
const checkedProject = yield* projectDirectory.pipe(quietViolations(tool));
|
|
74
|
+
const packageDirectories = yield* packageDirectoriesIn(checkedProject).pipe(
|
|
75
|
+
quietViolations(tool),
|
|
76
|
+
locatedFromTheProject,
|
|
77
|
+
);
|
|
72
78
|
const reportedByPackage = yield* Effect.forEach(
|
|
73
79
|
packageDirectories,
|
|
74
80
|
(packageDirectory) =>
|
|
75
|
-
checkPackage(pathModule.join(
|
|
81
|
+
checkPackage(pathModule.join(checkedProject, packageDirectory), packageDirectory).pipe(
|
|
76
82
|
Effect.as([]),
|
|
77
83
|
Effect.catchTag("ReportedErrors", ({ reportedErrors }) =>
|
|
78
84
|
Effect.succeed(
|
|
@@ -84,7 +90,9 @@ export const inEachPackage = <Requirements>(
|
|
|
84
90
|
),
|
|
85
91
|
{ concurrency: "unbounded" },
|
|
86
92
|
);
|
|
87
|
-
const reportedErrors = distinctPrintedErrors(
|
|
93
|
+
const reportedErrors = distinctPrintedErrors(
|
|
94
|
+
yield* printedFromTheProject(reportedByPackage.flat()),
|
|
95
|
+
);
|
|
88
96
|
if (Arrays.isArrayNonEmpty(reportedErrors)) {
|
|
89
97
|
return yield* new ReportedErrors({ reportedErrors });
|
|
90
98
|
}
|
|
@@ -8,7 +8,7 @@ import { ProjectQueryCachesLive } from "./provide-project-query-caches.ts";
|
|
|
8
8
|
|
|
9
9
|
export const lintConfigFile = Task.make(
|
|
10
10
|
"lint-config",
|
|
11
|
-
inEachPackage("lint-config",
|
|
11
|
+
inEachPackage("lint-config", (packageDirectory) =>
|
|
12
12
|
loadedLintConfigIn(packageDirectory).pipe(Effect.asVoid, quietViolations("lint-config")),
|
|
13
13
|
).pipe(Effect.provide(ProjectQueryCachesLive)),
|
|
14
14
|
);
|
|
@@ -28,7 +28,7 @@ const locatedFromThePackage = (
|
|
|
28
28
|
|
|
29
29
|
export const typeScriptConfig = Task.make(
|
|
30
30
|
"typescript-config",
|
|
31
|
-
inEachPackage("typescript-config",
|
|
31
|
+
inEachPackage("typescript-config", (packageDirectory) =>
|
|
32
32
|
Path.Path.use((path) =>
|
|
33
33
|
findTypeScriptConfigViolations(path.join(packageDirectory, TYPESCRIPT_PROJECT_FILE)).pipe(
|
|
34
34
|
quietViolations("typescript-config"),
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Effect, FileSystem, Path, Predicate, Schema } from "effect";
|
|
2
2
|
|
|
3
|
+
import { normalizedPath } from "../../../shared/record-and-grant-permissions-by-path.ts";
|
|
3
4
|
import { PACKAGE_MANIFEST_FILE } from "./find-named-package-manifests.ts";
|
|
4
5
|
import {
|
|
5
6
|
InstalledPackageHasNoBinary,
|
|
@@ -7,6 +8,7 @@ import {
|
|
|
7
8
|
PackageNotInstalled,
|
|
8
9
|
} from "./project-config-and-tool-errors.ts";
|
|
9
10
|
import { packageManifestObject } from "./read-package-manifest-object.ts";
|
|
11
|
+
import type { JSON_OBJECT } from "./read-package-manifest-object.ts";
|
|
10
12
|
|
|
11
13
|
const MANIFEST_BINARIES = Schema.Struct({
|
|
12
14
|
bin: Schema.optionalKey(
|
|
@@ -14,6 +16,14 @@ const MANIFEST_BINARIES = Schema.Struct({
|
|
|
14
16
|
),
|
|
15
17
|
});
|
|
16
18
|
|
|
19
|
+
const isManifestWithBinaries = Schema.is(MANIFEST_BINARIES);
|
|
20
|
+
|
|
21
|
+
export const listedBinaryFilesOf = (manifest: typeof JSON_OBJECT.Type) => {
|
|
22
|
+
const bin = isManifestWithBinaries(manifest) ? manifest.bin : undefined;
|
|
23
|
+
const binaries = Predicate.isString(bin) ? [bin] : Object.values(bin ?? {});
|
|
24
|
+
return new Set(binaries.map((binary) => normalizedPath(binary)));
|
|
25
|
+
};
|
|
26
|
+
|
|
17
27
|
const unscopedName = (packageName: string) => packageName.split("/").at(-1) ?? packageName;
|
|
18
28
|
|
|
19
29
|
const declaredBinary = (
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { CallExpression, Node } from "typescript/unstable/ast";
|
|
2
|
+
import {
|
|
3
|
+
isAsExpression,
|
|
4
|
+
isIdentifier,
|
|
5
|
+
isNonNullExpression,
|
|
6
|
+
isParenthesizedExpression,
|
|
7
|
+
isPropertyAccessExpression,
|
|
8
|
+
isSatisfiesExpression,
|
|
9
|
+
} from "typescript/unstable/ast/is";
|
|
10
|
+
|
|
11
|
+
const PIPE = "pipe";
|
|
12
|
+
|
|
13
|
+
const isWrapper = (node: Node) =>
|
|
14
|
+
isParenthesizedExpression(node) ||
|
|
15
|
+
isAsExpression(node) ||
|
|
16
|
+
isSatisfiesExpression(node) ||
|
|
17
|
+
isNonNullExpression(node);
|
|
18
|
+
|
|
19
|
+
export const withoutWrappers = (node: Node): Node =>
|
|
20
|
+
isWrapper(node) ? withoutWrappers(node.expression) : node;
|
|
21
|
+
|
|
22
|
+
export const outermostWrapperOf = (node: Node): Node =>
|
|
23
|
+
isWrapper(node.parent) ? outermostWrapperOf(node.parent) : node;
|
|
24
|
+
|
|
25
|
+
export const referencedNameOf = (node: Node) => {
|
|
26
|
+
const reference = withoutWrappers(node);
|
|
27
|
+
if (isPropertyAccessExpression(reference)) {
|
|
28
|
+
return reference.name;
|
|
29
|
+
}
|
|
30
|
+
return isIdentifier(reference) ? reference : undefined;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export const pipedStepsOf = (call: CallExpression) => {
|
|
34
|
+
if (referencedNameOf(call.expression)?.text !== PIPE) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
const callee = withoutWrappers(call.expression);
|
|
38
|
+
return isPropertyAccessExpression(callee)
|
|
39
|
+
? [callee.expression, ...call.arguments]
|
|
40
|
+
: [...call.arguments];
|
|
41
|
+
};
|