@sshkeda/check 0.0.0-stage → 1.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/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 +827 -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,648 @@
|
|
|
1
|
+
import { Array as Arrays, Effect, Option, Path } from "effect";
|
|
2
|
+
import type { Layer } from "effect";
|
|
3
|
+
import { NodeFlags } from "typescript/unstable/ast";
|
|
4
|
+
import type { CallExpression, Node, SourceFile } from "typescript/unstable/ast";
|
|
5
|
+
import {
|
|
6
|
+
isArrowFunction,
|
|
7
|
+
isAsExpression,
|
|
8
|
+
isBlock,
|
|
9
|
+
isCallExpression,
|
|
10
|
+
isConditionalExpression,
|
|
11
|
+
isExportKeyword,
|
|
12
|
+
isFunctionDeclaration,
|
|
13
|
+
isFunctionExpression,
|
|
14
|
+
isIdentifier,
|
|
15
|
+
isNonNullExpression,
|
|
16
|
+
isObjectLiteralExpression,
|
|
17
|
+
isParameterDeclaration,
|
|
18
|
+
isParenthesizedExpression,
|
|
19
|
+
isPropertyAccessExpression,
|
|
20
|
+
isReturnStatement,
|
|
21
|
+
isSatisfiesExpression,
|
|
22
|
+
isSpreadElement,
|
|
23
|
+
isVariableDeclaration,
|
|
24
|
+
isVariableStatement,
|
|
25
|
+
isYieldExpression,
|
|
26
|
+
} from "typescript/unstable/ast/is";
|
|
27
|
+
import { SymbolFlags } from "typescript/unstable/async";
|
|
28
|
+
import type { Checker, Symbol as TypeScriptSymbol, Type } from "typescript/unstable/async";
|
|
29
|
+
|
|
30
|
+
import { isUnderTestDirectory } from "../../../shared/classify-files-by-role.ts";
|
|
31
|
+
import {
|
|
32
|
+
CONCURRENT_TYPESCRIPT_REQUESTS,
|
|
33
|
+
nodePosition,
|
|
34
|
+
packageCalleeOf,
|
|
35
|
+
parentOf,
|
|
36
|
+
typeScriptRequest,
|
|
37
|
+
} from "../../../shared/query-the-typescript-project.ts";
|
|
38
|
+
import type { openTypeScriptProjects } from "../../../shared/query-the-typescript-project.ts";
|
|
39
|
+
import { absolutePathOf } from "../../../shared/resolve-absolute-paths.ts";
|
|
40
|
+
import {
|
|
41
|
+
LayerProvidedOutsideProgramStart,
|
|
42
|
+
LayerProvidesOutsideProgramStarts,
|
|
43
|
+
PROVIDED_VALUES,
|
|
44
|
+
} from "./layer-provide-errors.ts";
|
|
45
|
+
import {
|
|
46
|
+
EFFECT_MODULE,
|
|
47
|
+
importedPackageApis,
|
|
48
|
+
LAYER_MODULE,
|
|
49
|
+
} from "./resolve-imported-package-apis.ts";
|
|
50
|
+
|
|
51
|
+
const LAYER_TYPE_ID = "~effect/Layer" satisfies keyof Layer.Any;
|
|
52
|
+
const PROVIDE = "provide";
|
|
53
|
+
const PROVIDE_OPERATIONS: ReadonlySet<string> = new Set([PROVIDE, "provideContext"]);
|
|
54
|
+
const LAYER_BUILDERS: ReadonlySet<string> = new Set([
|
|
55
|
+
"build",
|
|
56
|
+
"buildWithScope",
|
|
57
|
+
"buildWithMemoMap",
|
|
58
|
+
]);
|
|
59
|
+
const CONTEXT_KEEPING_OPERATIONS: ReadonlySet<string> = new Set([
|
|
60
|
+
"scoped",
|
|
61
|
+
"orDie",
|
|
62
|
+
"mapError",
|
|
63
|
+
"withSpan",
|
|
64
|
+
]);
|
|
65
|
+
const SUCCESS_CONTINUATIONS: ReadonlySet<string> = new Set(["flatMap", "andThen", "tap", "map"]);
|
|
66
|
+
const EFFECT_OPERATIONS = [
|
|
67
|
+
{
|
|
68
|
+
module: EFFECT_MODULE,
|
|
69
|
+
names: new Set([
|
|
70
|
+
...PROVIDE_OPERATIONS,
|
|
71
|
+
...CONTEXT_KEEPING_OPERATIONS,
|
|
72
|
+
...SUCCESS_CONTINUATIONS,
|
|
73
|
+
]),
|
|
74
|
+
},
|
|
75
|
+
{ module: LAYER_MODULE, names: LAYER_BUILDERS },
|
|
76
|
+
];
|
|
77
|
+
const PIPE = "pipe";
|
|
78
|
+
const PROVIDED_ARGUMENTS = 2;
|
|
79
|
+
|
|
80
|
+
const anyOf = <Item, Failure>(
|
|
81
|
+
items: Iterable<Item>,
|
|
82
|
+
predicate: (item: Item) => Effect.Effect<boolean, Failure>,
|
|
83
|
+
) => Effect.findFirst(items, predicate).pipe(Effect.map(Option.isSome));
|
|
84
|
+
|
|
85
|
+
const isWrapper = (node: Node) =>
|
|
86
|
+
isParenthesizedExpression(node) ||
|
|
87
|
+
isAsExpression(node) ||
|
|
88
|
+
isSatisfiesExpression(node) ||
|
|
89
|
+
isNonNullExpression(node);
|
|
90
|
+
|
|
91
|
+
const withoutWrappers = (node: Node): Node =>
|
|
92
|
+
isWrapper(node) ? withoutWrappers(node.expression) : node;
|
|
93
|
+
|
|
94
|
+
const outermostWrapperOf = (node: Node): Node =>
|
|
95
|
+
isWrapper(node.parent) ? outermostWrapperOf(node.parent) : node;
|
|
96
|
+
|
|
97
|
+
const isFunctionLike = (node: Node) =>
|
|
98
|
+
isFunctionDeclaration(node) || isFunctionExpression(node) || isArrowFunction(node);
|
|
99
|
+
|
|
100
|
+
const callsIn = (sourceFile: SourceFile) => {
|
|
101
|
+
const calls: CallExpression[] = [];
|
|
102
|
+
const visit = (node: Node) => {
|
|
103
|
+
if (isCallExpression(node)) {
|
|
104
|
+
calls.push(node);
|
|
105
|
+
}
|
|
106
|
+
node.forEachChild(visit);
|
|
107
|
+
};
|
|
108
|
+
sourceFile.forEachChild(visit);
|
|
109
|
+
return calls;
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
const returnedBy = (callable: Node) => {
|
|
113
|
+
const body = isFunctionLike(callable) ? callable.body : undefined;
|
|
114
|
+
if (body === undefined) {
|
|
115
|
+
return [];
|
|
116
|
+
}
|
|
117
|
+
if (!isBlock(body)) {
|
|
118
|
+
return [body];
|
|
119
|
+
}
|
|
120
|
+
const returned: Node[] = [];
|
|
121
|
+
const visit = (node: Node) => {
|
|
122
|
+
if (isReturnStatement(node)) {
|
|
123
|
+
returned.push(...(node.expression === undefined ? [] : [node.expression]));
|
|
124
|
+
}
|
|
125
|
+
if (!isFunctionLike(node)) {
|
|
126
|
+
node.forEachChild(visit);
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
body.forEachChild(visit);
|
|
130
|
+
return returned;
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
const referencedNameOf = (node: Node) => {
|
|
134
|
+
const reference = withoutWrappers(node);
|
|
135
|
+
if (isPropertyAccessExpression(reference)) {
|
|
136
|
+
return reference.name;
|
|
137
|
+
}
|
|
138
|
+
return isIdentifier(reference) ? reference : undefined;
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
const isExportOf = (
|
|
142
|
+
apis: Effect.Success<ReturnType<typeof importedPackageApis>>,
|
|
143
|
+
symbol: TypeScriptSymbol | undefined,
|
|
144
|
+
module: string,
|
|
145
|
+
names: ReadonlySet<string>,
|
|
146
|
+
) => symbol !== undefined && names.has(symbol.name) && apis.effectExports.get(symbol.id) === module;
|
|
147
|
+
|
|
148
|
+
const pipedStepsOf = (call: CallExpression) => {
|
|
149
|
+
if (referencedNameOf(call.expression)?.text !== PIPE) {
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
const callee = withoutWrappers(call.expression);
|
|
153
|
+
return isPropertyAccessExpression(callee)
|
|
154
|
+
? [callee.expression, ...call.arguments]
|
|
155
|
+
: [...call.arguments];
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
const stepsBefore = (step: Node) => {
|
|
159
|
+
const { parent } = step;
|
|
160
|
+
if (!isCallExpression(parent)) {
|
|
161
|
+
return [];
|
|
162
|
+
}
|
|
163
|
+
return Arrays.takeWhile(pipedStepsOf(parent) ?? [], (piped) => piped !== step);
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
const effectsContinuedBy = (callback: Node) => {
|
|
167
|
+
const { parent: step } = callback;
|
|
168
|
+
if (!isCallExpression(step)) {
|
|
169
|
+
return [];
|
|
170
|
+
}
|
|
171
|
+
const [first] = step.arguments;
|
|
172
|
+
const isDataFirst = step.arguments.length > 1 && first !== undefined && first !== callback;
|
|
173
|
+
return isDataFirst ? [first] : stepsBefore(step);
|
|
174
|
+
};
|
|
175
|
+
|
|
176
|
+
const isLayerType = (checker: Checker, type: Type | undefined) =>
|
|
177
|
+
Effect.gen(function* () {
|
|
178
|
+
if (type === undefined) {
|
|
179
|
+
return false;
|
|
180
|
+
}
|
|
181
|
+
const typeId = yield* typeScriptRequest("read the layer type id", () =>
|
|
182
|
+
checker.getPropertyOfType(type, LAYER_TYPE_ID),
|
|
183
|
+
);
|
|
184
|
+
if (typeId !== undefined) {
|
|
185
|
+
return true;
|
|
186
|
+
}
|
|
187
|
+
const isArray = yield* typeScriptRequest("check for an array of layers", () =>
|
|
188
|
+
checker.isArrayLikeType(type),
|
|
189
|
+
);
|
|
190
|
+
if (!isArray) {
|
|
191
|
+
return false;
|
|
192
|
+
}
|
|
193
|
+
const indexes = yield* typeScriptRequest("read the array element type", () =>
|
|
194
|
+
checker.getIndexInfosOfType(type),
|
|
195
|
+
);
|
|
196
|
+
return yield* anyOf(indexes, ({ valueType }) =>
|
|
197
|
+
typeScriptRequest("read the layer type id", () =>
|
|
198
|
+
checker.getPropertyOfType(valueType, LAYER_TYPE_ID),
|
|
199
|
+
).pipe(Effect.map((elementTypeId) => elementTypeId !== undefined)),
|
|
200
|
+
);
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
const tracedValues = (
|
|
204
|
+
checker: Checker,
|
|
205
|
+
apis: Effect.Success<ReturnType<typeof importedPackageApis>>,
|
|
206
|
+
) => {
|
|
207
|
+
const cycleCuts: Node[] = [];
|
|
208
|
+
const isAlreadyFollowed = (declaration: Node, seen: ReadonlySet<Node>) => {
|
|
209
|
+
const isFollowed = seen.has(declaration);
|
|
210
|
+
if (isFollowed) {
|
|
211
|
+
cycleCuts.push(declaration);
|
|
212
|
+
}
|
|
213
|
+
return isFollowed;
|
|
214
|
+
};
|
|
215
|
+
|
|
216
|
+
const symbolOf = (name: Node) =>
|
|
217
|
+
Effect.gen(function* () {
|
|
218
|
+
const symbol = yield* typeScriptRequest("resolve a referenced value", () =>
|
|
219
|
+
checker.getSymbolAtLocation(name),
|
|
220
|
+
);
|
|
221
|
+
const isImportAlias = symbol !== undefined && (symbol.flags & SymbolFlags.Alias) !== 0;
|
|
222
|
+
return isImportAlias
|
|
223
|
+
? yield* typeScriptRequest("follow an import alias", () => checker.getAliasedSymbol(symbol))
|
|
224
|
+
: symbol;
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
const declarationOf = (name: Node) =>
|
|
228
|
+
Effect.gen(function* () {
|
|
229
|
+
const symbol = yield* symbolOf(name);
|
|
230
|
+
const declaration = symbol?.valueDeclaration ?? symbol?.declarations.at(0);
|
|
231
|
+
return declaration === undefined
|
|
232
|
+
? undefined
|
|
233
|
+
: yield* typeScriptRequest("read a value's declaration", () => declaration.resolve());
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
const isLayerBuilder = (node: Node) =>
|
|
237
|
+
Effect.gen(function* () {
|
|
238
|
+
const name = referencedNameOf(node);
|
|
239
|
+
return (
|
|
240
|
+
name !== undefined && isExportOf(apis, yield* symbolOf(name), LAYER_MODULE, LAYER_BUILDERS)
|
|
241
|
+
);
|
|
242
|
+
});
|
|
243
|
+
|
|
244
|
+
const functionReturnsOf = (callee: Node, seen: ReadonlySet<Node>) =>
|
|
245
|
+
Effect.gen(function* () {
|
|
246
|
+
const name = referencedNameOf(callee);
|
|
247
|
+
const declaration = name === undefined ? undefined : yield* declarationOf(name);
|
|
248
|
+
const isUnfollowed = declaration !== undefined && !isAlreadyFollowed(declaration, seen);
|
|
249
|
+
if (!isUnfollowed) {
|
|
250
|
+
return;
|
|
251
|
+
}
|
|
252
|
+
const isInitializedVariable =
|
|
253
|
+
isVariableDeclaration(declaration) && declaration.initializer !== undefined;
|
|
254
|
+
const initializer = isInitializedVariable
|
|
255
|
+
? withoutWrappers(declaration.initializer)
|
|
256
|
+
: declaration;
|
|
257
|
+
return { returned: returnedBy(initializer), seen: new Set([...seen, declaration]) };
|
|
258
|
+
});
|
|
259
|
+
|
|
260
|
+
const isEffectOperation = (callee: Node, operations: ReadonlySet<string>) =>
|
|
261
|
+
Effect.gen(function* () {
|
|
262
|
+
const name = referencedNameOf(callee);
|
|
263
|
+
return (
|
|
264
|
+
name !== undefined && isExportOf(apis, yield* symbolOf(name), EFFECT_MODULE, operations)
|
|
265
|
+
);
|
|
266
|
+
});
|
|
267
|
+
|
|
268
|
+
const remembered = (
|
|
269
|
+
known: Map<Node, boolean>,
|
|
270
|
+
node: Node,
|
|
271
|
+
trace: Effect.Effect<boolean, Effect.Error<ReturnType<typeof symbolOf>>>,
|
|
272
|
+
) =>
|
|
273
|
+
Effect.suspend(() => {
|
|
274
|
+
const result = known.get(node);
|
|
275
|
+
if (result !== undefined) {
|
|
276
|
+
return Effect.succeed(result);
|
|
277
|
+
}
|
|
278
|
+
const cutsBefore = cycleCuts.length;
|
|
279
|
+
return trace.pipe(
|
|
280
|
+
Effect.tap((traced) =>
|
|
281
|
+
Effect.sync(() => {
|
|
282
|
+
const isDefinitive = traced || cycleCuts.length === cutsBefore;
|
|
283
|
+
if (isDefinitive) {
|
|
284
|
+
known.set(node, traced);
|
|
285
|
+
}
|
|
286
|
+
}),
|
|
287
|
+
),
|
|
288
|
+
);
|
|
289
|
+
});
|
|
290
|
+
|
|
291
|
+
const effectsBuildingContexts = new Map<Node, boolean>();
|
|
292
|
+
const builtContexts = new Map<Node, boolean>();
|
|
293
|
+
|
|
294
|
+
const tracers = {
|
|
295
|
+
buildsContext: (
|
|
296
|
+
node: Node,
|
|
297
|
+
seen: ReadonlySet<Node>,
|
|
298
|
+
): Effect.Effect<boolean, Effect.Error<ReturnType<typeof symbolOf>>> =>
|
|
299
|
+
remembered(
|
|
300
|
+
effectsBuildingContexts,
|
|
301
|
+
node,
|
|
302
|
+
Effect.gen(function* () {
|
|
303
|
+
const effect = withoutWrappers(node);
|
|
304
|
+
if (isConditionalExpression(effect)) {
|
|
305
|
+
return yield* anyOf([effect.whenTrue, effect.whenFalse], (branch) =>
|
|
306
|
+
tracers.buildsContext(branch, seen),
|
|
307
|
+
);
|
|
308
|
+
}
|
|
309
|
+
if (yield* isLayerBuilder(effect)) {
|
|
310
|
+
return true;
|
|
311
|
+
}
|
|
312
|
+
const reference = referencedNameOf(effect);
|
|
313
|
+
if (reference !== undefined) {
|
|
314
|
+
const declaration = yield* declarationOf(reference);
|
|
315
|
+
const isUnseenConst =
|
|
316
|
+
declaration !== undefined &&
|
|
317
|
+
!isAlreadyFollowed(declaration, seen) &&
|
|
318
|
+
isVariableDeclaration(declaration) &&
|
|
319
|
+
declaration.initializer !== undefined;
|
|
320
|
+
return (
|
|
321
|
+
isUnseenConst &&
|
|
322
|
+
(yield* tracers.buildsContext(
|
|
323
|
+
declaration.initializer,
|
|
324
|
+
new Set([...seen, declaration]),
|
|
325
|
+
))
|
|
326
|
+
);
|
|
327
|
+
}
|
|
328
|
+
if (!isCallExpression(effect)) {
|
|
329
|
+
return false;
|
|
330
|
+
}
|
|
331
|
+
const steps = pipedStepsOf(effect);
|
|
332
|
+
if (steps !== undefined) {
|
|
333
|
+
return yield* anyOf(steps, (step) => tracers.buildsContext(step, seen));
|
|
334
|
+
}
|
|
335
|
+
const callee = withoutWrappers(effect.expression);
|
|
336
|
+
const isCurriedOrBuilder = isCallExpression(callee) || (yield* isLayerBuilder(callee));
|
|
337
|
+
if (isCurriedOrBuilder) {
|
|
338
|
+
return yield* tracers.buildsContext(callee, seen);
|
|
339
|
+
}
|
|
340
|
+
const [input] = effect.arguments;
|
|
341
|
+
const keepsTheInputContext =
|
|
342
|
+
input !== undefined && (yield* isEffectOperation(callee, CONTEXT_KEEPING_OPERATIONS));
|
|
343
|
+
if (keepsTheInputContext) {
|
|
344
|
+
return yield* tracers.buildsContext(input, seen);
|
|
345
|
+
}
|
|
346
|
+
const generated = effect.arguments
|
|
347
|
+
.filter(
|
|
348
|
+
(argument) => isFunctionExpression(argument) && argument.asteriskToken !== undefined,
|
|
349
|
+
)
|
|
350
|
+
.flatMap((generator) => returnedBy(generator));
|
|
351
|
+
if (yield* anyOf(generated, (returned) => tracers.isBuiltContext(returned, seen))) {
|
|
352
|
+
return true;
|
|
353
|
+
}
|
|
354
|
+
const made = yield* functionReturnsOf(callee, seen);
|
|
355
|
+
return (
|
|
356
|
+
made !== undefined &&
|
|
357
|
+
(yield* anyOf(made.returned, (returned) => tracers.buildsContext(returned, made.seen)))
|
|
358
|
+
);
|
|
359
|
+
}),
|
|
360
|
+
),
|
|
361
|
+
isBuiltContext: (
|
|
362
|
+
node: Node,
|
|
363
|
+
seen: ReadonlySet<Node>,
|
|
364
|
+
): Effect.Effect<boolean, Effect.Error<ReturnType<typeof symbolOf>>> =>
|
|
365
|
+
remembered(
|
|
366
|
+
builtContexts,
|
|
367
|
+
node,
|
|
368
|
+
Effect.gen(function* () {
|
|
369
|
+
const value = withoutWrappers(node);
|
|
370
|
+
if (isYieldExpression(value)) {
|
|
371
|
+
const isDelegated = value.asteriskToken !== undefined && value.expression !== undefined;
|
|
372
|
+
return isDelegated && (yield* tracers.buildsContext(value.expression, seen));
|
|
373
|
+
}
|
|
374
|
+
const reference = referencedNameOf(value);
|
|
375
|
+
if (reference === undefined) {
|
|
376
|
+
return false;
|
|
377
|
+
}
|
|
378
|
+
const declaration = yield* declarationOf(reference);
|
|
379
|
+
const isUnfollowed = declaration !== undefined && !isAlreadyFollowed(declaration, seen);
|
|
380
|
+
if (!isUnfollowed) {
|
|
381
|
+
return false;
|
|
382
|
+
}
|
|
383
|
+
const followed = new Set([...seen, declaration]);
|
|
384
|
+
if (isVariableDeclaration(declaration)) {
|
|
385
|
+
return (
|
|
386
|
+
declaration.initializer !== undefined &&
|
|
387
|
+
(yield* tracers.isBuiltContext(declaration.initializer, followed))
|
|
388
|
+
);
|
|
389
|
+
}
|
|
390
|
+
if (!isParameterDeclaration(declaration)) {
|
|
391
|
+
return false;
|
|
392
|
+
}
|
|
393
|
+
const { parent: step } = declaration.parent;
|
|
394
|
+
const continuesTheSuccess =
|
|
395
|
+
isCallExpression(step) &&
|
|
396
|
+
(yield* isEffectOperation(step.expression, SUCCESS_CONTINUATIONS));
|
|
397
|
+
if (!continuesTheSuccess) {
|
|
398
|
+
return false;
|
|
399
|
+
}
|
|
400
|
+
return yield* anyOf(effectsContinuedBy(declaration.parent), (continued) =>
|
|
401
|
+
tracers.buildsContext(continued, followed),
|
|
402
|
+
);
|
|
403
|
+
}),
|
|
404
|
+
),
|
|
405
|
+
};
|
|
406
|
+
|
|
407
|
+
return tracers;
|
|
408
|
+
};
|
|
409
|
+
|
|
410
|
+
const RUNNER_CALLS = new WeakMap<CallExpression, boolean>();
|
|
411
|
+
|
|
412
|
+
const isRunnerCallee = (
|
|
413
|
+
apis: Effect.Success<ReturnType<typeof importedPackageApis>>,
|
|
414
|
+
callee: Effect.Success<ReturnType<typeof packageCalleeOf>>,
|
|
415
|
+
) =>
|
|
416
|
+
callee !== undefined &&
|
|
417
|
+
(apis.programStarts.get(callee.declaration)?.has(callee.returnedBySignature) ?? false);
|
|
418
|
+
|
|
419
|
+
const startsTheProgram = (
|
|
420
|
+
checker: Checker,
|
|
421
|
+
apis: Effect.Success<ReturnType<typeof importedPackageApis>>,
|
|
422
|
+
call: CallExpression,
|
|
423
|
+
) =>
|
|
424
|
+
Effect.gen(function* () {
|
|
425
|
+
const known = RUNNER_CALLS.get(call);
|
|
426
|
+
if (known !== undefined) {
|
|
427
|
+
return known;
|
|
428
|
+
}
|
|
429
|
+
const isRunner = isRunnerCallee(
|
|
430
|
+
apis,
|
|
431
|
+
yield* packageCalleeOf(checker, apis.projectDirectory, call, (file) =>
|
|
432
|
+
apis.programStartFiles.has(file),
|
|
433
|
+
),
|
|
434
|
+
);
|
|
435
|
+
RUNNER_CALLS.set(call, isRunner);
|
|
436
|
+
return isRunner;
|
|
437
|
+
});
|
|
438
|
+
|
|
439
|
+
const isRunnerArgument = (
|
|
440
|
+
checker: Checker,
|
|
441
|
+
apis: Effect.Success<ReturnType<typeof importedPackageApis>>,
|
|
442
|
+
node: Node,
|
|
443
|
+
) => {
|
|
444
|
+
const { parent } = node;
|
|
445
|
+
const isArgument =
|
|
446
|
+
isCallExpression(parent) && parent.arguments.some((argument) => argument === node);
|
|
447
|
+
return isArgument ? startsTheProgram(checker, apis, parent) : Effect.succeed(false);
|
|
448
|
+
};
|
|
449
|
+
|
|
450
|
+
const isExported = (declaration: Node) => {
|
|
451
|
+
const statement = declaration.parent.parent;
|
|
452
|
+
return (
|
|
453
|
+
isVariableStatement(statement) &&
|
|
454
|
+
(statement.modifiers?.some((modifier) => isExportKeyword(modifier)) ?? false)
|
|
455
|
+
);
|
|
456
|
+
};
|
|
457
|
+
|
|
458
|
+
const isConstOnlyRunByARunner = (
|
|
459
|
+
checker: Checker,
|
|
460
|
+
apis: Effect.Success<ReturnType<typeof importedPackageApis>>,
|
|
461
|
+
sourceFile: SourceFile,
|
|
462
|
+
declaration: Node,
|
|
463
|
+
) =>
|
|
464
|
+
Effect.gen(function* () {
|
|
465
|
+
const isLocalConst =
|
|
466
|
+
isVariableDeclaration(declaration) &&
|
|
467
|
+
isIdentifier(declaration.name) &&
|
|
468
|
+
(declaration.parent.flags & NodeFlags.BlockScoped) === NodeFlags.Const &&
|
|
469
|
+
!isExported(declaration);
|
|
470
|
+
if (!isLocalConst) {
|
|
471
|
+
return false;
|
|
472
|
+
}
|
|
473
|
+
const symbol = yield* typeScriptRequest("resolve a const", () =>
|
|
474
|
+
checker.getSymbolAtLocation(declaration.name),
|
|
475
|
+
);
|
|
476
|
+
if (symbol === undefined) {
|
|
477
|
+
return false;
|
|
478
|
+
}
|
|
479
|
+
const references = yield* typeScriptRequest("find a const's references", () =>
|
|
480
|
+
checker.getReferencesToSymbolInFile(sourceFile.fileName, symbol),
|
|
481
|
+
);
|
|
482
|
+
const reads = yield* Effect.forEach(references, (reference) =>
|
|
483
|
+
typeScriptRequest("read a const's reference", () => reference.resolve()),
|
|
484
|
+
);
|
|
485
|
+
const [onlyRead, ...otherReads] = reads.filter(
|
|
486
|
+
(read) => read !== undefined && read.pos !== declaration.name.pos,
|
|
487
|
+
);
|
|
488
|
+
const isReadOnce = onlyRead !== undefined && otherReads.length === 0;
|
|
489
|
+
return isReadOnce && (yield* isRunnerArgument(checker, apis, outermostWrapperOf(onlyRead)));
|
|
490
|
+
});
|
|
491
|
+
|
|
492
|
+
const isWhereTheProgramStarts = (
|
|
493
|
+
checker: Checker,
|
|
494
|
+
apis: Effect.Success<ReturnType<typeof importedPackageApis>>,
|
|
495
|
+
sourceFile: SourceFile,
|
|
496
|
+
node: Node,
|
|
497
|
+
): Effect.Effect<boolean, Effect.Error<ReturnType<typeof startsTheProgram>>> =>
|
|
498
|
+
Effect.gen(function* () {
|
|
499
|
+
const parent = parentOf(node);
|
|
500
|
+
if (parent === undefined) {
|
|
501
|
+
return false;
|
|
502
|
+
}
|
|
503
|
+
if (yield* isRunnerArgument(checker, apis, node)) {
|
|
504
|
+
return true;
|
|
505
|
+
}
|
|
506
|
+
const isInitializer = isVariableDeclaration(parent) && parent.initializer === node;
|
|
507
|
+
const isConstRunByARunner =
|
|
508
|
+
isInitializer && (yield* isConstOnlyRunByARunner(checker, apis, sourceFile, parent));
|
|
509
|
+
if (isConstRunByARunner) {
|
|
510
|
+
return true;
|
|
511
|
+
}
|
|
512
|
+
return yield* isWhereTheProgramStarts(checker, apis, sourceFile, parent);
|
|
513
|
+
});
|
|
514
|
+
|
|
515
|
+
const providedArgumentsOf = (call: CallExpression) =>
|
|
516
|
+
call.arguments
|
|
517
|
+
.slice(0, PROVIDED_ARGUMENTS)
|
|
518
|
+
.filter((argument) => !isObjectLiteralExpression(argument) && !isSpreadElement(argument));
|
|
519
|
+
|
|
520
|
+
const provideOperationsIn = (
|
|
521
|
+
checker: Checker,
|
|
522
|
+
apis: Effect.Success<ReturnType<typeof importedPackageApis>>,
|
|
523
|
+
calls: readonly CallExpression[],
|
|
524
|
+
) =>
|
|
525
|
+
Effect.gen(function* () {
|
|
526
|
+
const named = calls.flatMap((call) => {
|
|
527
|
+
const name = referencedNameOf(call.expression);
|
|
528
|
+
return name === undefined ? [] : [{ call, name }];
|
|
529
|
+
});
|
|
530
|
+
const symbols = yield* typeScriptRequest("resolve called values", () =>
|
|
531
|
+
checker.getSymbolAtLocation(named.map(({ name }) => name)),
|
|
532
|
+
);
|
|
533
|
+
const aliases = new Map(
|
|
534
|
+
symbols.flatMap((symbol) => {
|
|
535
|
+
const isAlias = symbol !== undefined && (symbol.flags & SymbolFlags.Alias) !== 0;
|
|
536
|
+
return isAlias ? [[symbol.id, symbol] as const] : [];
|
|
537
|
+
}),
|
|
538
|
+
);
|
|
539
|
+
const aliased = new Map(
|
|
540
|
+
yield* Effect.forEach(
|
|
541
|
+
aliases.values(),
|
|
542
|
+
(alias) =>
|
|
543
|
+
typeScriptRequest("follow an import alias", () => checker.getAliasedSymbol(alias)).pipe(
|
|
544
|
+
Effect.map((target) => [alias.id, target] as const),
|
|
545
|
+
),
|
|
546
|
+
{ concurrency: CONCURRENT_TYPESCRIPT_REQUESTS },
|
|
547
|
+
),
|
|
548
|
+
);
|
|
549
|
+
return named.flatMap(({ call }, index) => {
|
|
550
|
+
const symbol = symbols[index];
|
|
551
|
+
const target = symbol === undefined ? undefined : (aliased.get(symbol.id) ?? symbol);
|
|
552
|
+
const isProvide =
|
|
553
|
+
target !== undefined && isExportOf(apis, target, EFFECT_MODULE, PROVIDE_OPERATIONS);
|
|
554
|
+
return isProvide ? [{ call, operation: target.name }] : [];
|
|
555
|
+
});
|
|
556
|
+
});
|
|
557
|
+
|
|
558
|
+
const providedValueOf = (
|
|
559
|
+
checker: Checker,
|
|
560
|
+
isBuiltContext: ReturnType<typeof tracedValues>["isBuiltContext"],
|
|
561
|
+
call: CallExpression,
|
|
562
|
+
operation: string,
|
|
563
|
+
) =>
|
|
564
|
+
Effect.gen(function* () {
|
|
565
|
+
const provided = providedArgumentsOf(call);
|
|
566
|
+
if (operation === PROVIDE) {
|
|
567
|
+
const types = yield* typeScriptRequest("read the provided types", () =>
|
|
568
|
+
checker.getTypeAtLocation(provided),
|
|
569
|
+
);
|
|
570
|
+
if (yield* anyOf(types, (type) => isLayerType(checker, type))) {
|
|
571
|
+
return PROVIDED_VALUES[0];
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
const isBuilt = yield* anyOf(provided, (argument) => isBuiltContext(argument, new Set()));
|
|
575
|
+
return isBuilt ? PROVIDED_VALUES[1] : undefined;
|
|
576
|
+
});
|
|
577
|
+
|
|
578
|
+
const fileViolations = (
|
|
579
|
+
checker: Checker,
|
|
580
|
+
apis: Effect.Success<ReturnType<typeof importedPackageApis>>,
|
|
581
|
+
isBuiltContext: ReturnType<typeof tracedValues>["isBuiltContext"],
|
|
582
|
+
sourceFile: SourceFile,
|
|
583
|
+
displayName: string,
|
|
584
|
+
) =>
|
|
585
|
+
Effect.gen(function* () {
|
|
586
|
+
const provides = yield* provideOperationsIn(checker, apis, callsIn(sourceFile));
|
|
587
|
+
const violations = yield* Effect.forEach(provides, ({ call, operation }) =>
|
|
588
|
+
Effect.gen(function* () {
|
|
589
|
+
const provided = yield* providedValueOf(checker, isBuiltContext, call, operation);
|
|
590
|
+
if (provided === undefined) {
|
|
591
|
+
return [];
|
|
592
|
+
}
|
|
593
|
+
if (yield* isWhereTheProgramStarts(checker, apis, sourceFile, call)) {
|
|
594
|
+
return [];
|
|
595
|
+
}
|
|
596
|
+
const { line, column } = nodePosition(sourceFile, call);
|
|
597
|
+
return [
|
|
598
|
+
new LayerProvidedOutsideProgramStart({
|
|
599
|
+
location: `${displayName}:${line}:${column}`,
|
|
600
|
+
operation,
|
|
601
|
+
provided,
|
|
602
|
+
}),
|
|
603
|
+
];
|
|
604
|
+
}),
|
|
605
|
+
);
|
|
606
|
+
return violations.flat();
|
|
607
|
+
});
|
|
608
|
+
|
|
609
|
+
export const findLayerProvidesOutsideProgramStarts = <OpeningError, OpeningRequirement>(
|
|
610
|
+
projectFile: string,
|
|
611
|
+
openedProjects: Effect.Effect<
|
|
612
|
+
Effect.Success<ReturnType<typeof openTypeScriptProjects>>,
|
|
613
|
+
OpeningError,
|
|
614
|
+
OpeningRequirement
|
|
615
|
+
>,
|
|
616
|
+
) =>
|
|
617
|
+
Effect.gen(function* () {
|
|
618
|
+
const projectDirectory = (yield* Path.Path).dirname(yield* absolutePathOf(projectFile));
|
|
619
|
+
const projects = yield* Effect.forEach(yield* openedProjects, (project) =>
|
|
620
|
+
importedPackageApis(
|
|
621
|
+
project.checker,
|
|
622
|
+
projectDirectory,
|
|
623
|
+
project.allSourceFiles,
|
|
624
|
+
EFFECT_OPERATIONS,
|
|
625
|
+
).pipe(Effect.map((apis) => ({ ...project, apis }))),
|
|
626
|
+
);
|
|
627
|
+
const violationsOfEachFile = yield* Effect.forEach(
|
|
628
|
+
projects.flatMap(({ checker, apis, sourceFiles }) => {
|
|
629
|
+
const { isBuiltContext } = tracedValues(checker, apis);
|
|
630
|
+
return sourceFiles
|
|
631
|
+
.filter(({ displayName }) => !isUnderTestDirectory(displayName))
|
|
632
|
+
.map(({ sourceFile, displayName }) => ({
|
|
633
|
+
checker,
|
|
634
|
+
apis,
|
|
635
|
+
isBuiltContext,
|
|
636
|
+
sourceFile,
|
|
637
|
+
displayName,
|
|
638
|
+
}));
|
|
639
|
+
}),
|
|
640
|
+
({ checker, apis, isBuiltContext, sourceFile, displayName }) =>
|
|
641
|
+
fileViolations(checker, apis, isBuiltContext, sourceFile, displayName),
|
|
642
|
+
{ concurrency: CONCURRENT_TYPESCRIPT_REQUESTS },
|
|
643
|
+
);
|
|
644
|
+
const violations = violationsOfEachFile.flat();
|
|
645
|
+
if (violations.length > 0) {
|
|
646
|
+
return yield* new LayerProvidesOutsideProgramStarts({ violations });
|
|
647
|
+
}
|
|
648
|
+
});
|
package/src/lib/tasks/lib/confine-layer-provides-to-program-starts/internal/layer-provide-errors.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Schema } from "effect";
|
|
2
|
+
|
|
3
|
+
import { listedViolations } from "../../../../../shared/format-reported-failures.ts";
|
|
4
|
+
|
|
5
|
+
export const PROVIDED_VALUES = ["a layer", "a context built from a layer"] as const;
|
|
6
|
+
|
|
7
|
+
export class LayerProvidedOutsideProgramStart extends Schema.TaggedError<LayerProvidedOutsideProgramStart>()(
|
|
8
|
+
"LayerProvidedOutsideProgramStart",
|
|
9
|
+
{
|
|
10
|
+
location: Schema.String,
|
|
11
|
+
operation: Schema.String,
|
|
12
|
+
provided: Schema.Literals(PROVIDED_VALUES),
|
|
13
|
+
},
|
|
14
|
+
) {
|
|
15
|
+
public override get message() {
|
|
16
|
+
return `Effect.${this.operation} with ${this.provided} outside the call that starts the program`;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export class LayerProvidesOutsideProgramStarts extends Schema.TaggedError<LayerProvidesOutsideProgramStarts>()(
|
|
21
|
+
"LayerProvidesOutsideProgramStarts",
|
|
22
|
+
{ violations: Schema.Array(LayerProvidedOutsideProgramStart) },
|
|
23
|
+
) {
|
|
24
|
+
public override get message() {
|
|
25
|
+
return listedViolations(this.violations);
|
|
26
|
+
}
|
|
27
|
+
}
|