@sshkeda/check 1.1.0 → 2.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 +7 -6
- package/docs/how-to-make-check-pass.md +4 -14
- package/package.json +4 -4
- package/src/internal/ban-abbreviated-words-in-declared-names.ts +0 -4
- package/src/internal/ban-checked-members-outside-calls.ts +8 -8
- package/src/internal/ban-comments.ts +0 -1
- package/src/internal/ban-comparing-or-switching-on-tag.ts +50 -10
- package/src/internal/ban-deadlines-inside-tests.ts +3 -4
- package/src/internal/ban-declared-values.ts +2 -5
- package/src/internal/ban-dropped-failures-detached-fibers-sleeps-and-untraced-functions.ts +0 -2
- package/src/internal/ban-failures-collected-as-results.ts +0 -4
- package/src/internal/ban-fallbacks-of-named-recoveries.ts +1 -29
- package/src/internal/ban-function-overloads.ts +0 -4
- package/src/internal/ban-global-error-in-failure-types.ts +10 -15
- package/src/internal/ban-instanceof-in-effect-recovery-callbacks.ts +17 -26
- package/src/internal/ban-let-and-effect-mutable-ref.ts +0 -8
- package/src/internal/ban-logic-in-index-files.ts +0 -3
- package/src/internal/ban-namespaces-used-without-a-member.ts +0 -3
- package/src/internal/ban-node-builtins-that-effect-replaces.ts +0 -3
- package/src/internal/ban-parsing-outside-data-without-a-schema.ts +0 -4
- package/src/internal/ban-re-exports.ts +54 -18
- package/src/internal/ban-reading-the-clock-and-sleeping-outside-effect.ts +88 -4
- package/src/internal/ban-recovering-file-system-exists.ts +300 -0
- package/src/internal/ban-retired-words-in-names.ts +1 -4
- package/src/internal/ban-retries-without-a-wait.ts +292 -0
- package/src/internal/ban-scanning-directories-with-bun-glob.ts +0 -3
- package/src/internal/ban-shebang-lines.ts +0 -4
- package/src/internal/ban-timer-globals-and-the-global-object.ts +0 -1
- package/src/internal/ban-timer-schedules-without-deadlines.ts +129 -45
- package/src/internal/ban-type-and-interface-declarations.ts +0 -4
- package/src/internal/ban-type-predicates.ts +0 -4
- package/src/internal/ban-unknown-in-function-signatures.ts +49 -13
- package/src/internal/ban-vague-error-class-names.ts +0 -4
- package/src/internal/ban-vague-file-names.ts +3 -7
- package/src/internal/ban-what-a-file-is-not-granted.ts +37 -14
- package/src/internal/ban-while-do-while-and-for-loops.ts +0 -4
- package/src/internal/ban-writing-captured-objects-inside-effect-callbacks.ts +210 -0
- package/src/internal/confine-service-declarations-to-granted-files.ts +0 -7
- package/src/internal/confine-the-stdio-service-to-terminal-output.ts +2 -16
- package/src/internal/define-the-lint-plugin-and-configs.ts +6 -0
- package/src/internal/keep-assertions-in-the-test-home-and-ban-test-runners.ts +0 -6
- package/src/internal/keep-effect-testing-helpers-in-test-files.ts +2 -14
- package/src/internal/require-a-named-const-for-compound-conditions.ts +0 -4
- package/src/internal/require-capital-snake-case-and-as-const-on-literal-constants.ts +0 -4
- package/src/internal/require-service-keys-to-end-with-their-class-name.ts +5 -2
- package/src/internal/resolve-what-an-expression-imports.ts +115 -28
- package/src/internal/visit-every-declared-name.ts +13 -0
- package/src/lib/tasks/internal/declare-the-check-task.ts +2 -0
- package/src/lib/tasks/internal/declare-the-checker-queries-task.ts +2 -1
- package/src/lib/tasks/lib/check-effect-diagnostics-with-effect-tsgo/index.ts +2 -1
- package/src/lib/tasks/lib/check-effect-diagnostics-with-effect-tsgo/internal/check-effect-diagnostics-with-effect-tsgo.ts +17 -0
- package/src/lib/tasks/lib/check-import-boundaries/internal/decide-what-each-home-may-import.ts +62 -0
- package/src/lib/tasks/lib/check-import-boundaries/internal/find-import-boundary-violations.ts +215 -187
- package/src/lib/tasks/lib/confine-layer-provides-to-program-starts/internal/find-layer-provides-outside-program-starts.ts +13 -16
- package/src/lib/tasks/lib/confine-layer-provides-to-program-starts/internal/layer-provide-errors.ts +2 -1
- package/src/lib/tasks/lib/confine-layer-provides-to-program-starts/internal/resolve-imported-package-apis.ts +3 -1
- package/src/lib/tasks/lib/detect-duplicate-functions/index.ts +10 -0
- package/src/lib/tasks/lib/detect-duplicate-functions/internal/duplicate-function-errors.ts +23 -0
- package/src/lib/tasks/lib/detect-duplicate-functions/internal/find-duplicate-functions.ts +150 -0
- package/src/lib/tasks/lib/detect-duplicate-functions/internal/list-named-functions.ts +416 -0
- package/src/lib/tasks/lib/detect-inferrable-annotations/internal/find-inferrable-annotations.ts +31 -12
- package/src/lib/tasks/lib/enforce-file-layout/index.ts +6 -1
- package/src/lib/tasks/lib/enforce-file-layout/internal/file-layout-errors.ts +10 -0
- package/src/lib/tasks/lib/enforce-file-layout/internal/find-export-path-mismatches.ts +39 -7
- package/src/lib/tasks/lib/enforce-file-layout/internal/find-file-layout-violations.ts +8 -3
- package/src/lib/tasks/lib/enforce-file-types/index.ts +6 -1
- package/src/lib/tasks/lib/format-with-bun-fmt/internal/declare-the-formatting-task.ts +3 -2
- package/src/lib/tasks/lib/judge-index-re-exports/internal/find-index-re-export-violations.ts +27 -21
- package/src/lib/tasks/lib/lint-with-oxlint/index.ts +2 -1
- package/src/lib/tasks/lib/lint-with-oxlint/internal/check-lint-rules-with-oxlint.ts +11 -8
- package/src/lib/tasks/lib/lint-with-oxlint/internal/read-oxlint-json-report.ts +18 -2
- package/src/lib/tasks/lib/place-exports-in-the-narrowest-directory/internal/export-placement-errors.ts +12 -1
- package/src/lib/tasks/lib/place-exports-in-the-narrowest-directory/internal/find-export-placement-violations.ts +75 -21
- package/src/lib/tasks/lib/place-exports-in-the-narrowest-directory/internal/find-package-entry-sources.ts +146 -0
- package/src/lib/tasks/lib/place-exports-in-the-narrowest-directory/internal/find-the-importer-graph.ts +13 -188
- package/src/lib/tasks/lib/refuse-disable-directives/index.ts +2 -1
- package/src/lib/tasks/lib/refuse-disable-directives/internal/find-disable-directives.ts +9 -3
- package/src/lib/tasks/lib/refuse-error-mappings-that-end-streams/internal/find-error-mappings-to-done.ts +108 -9
- package/src/lib/tasks/lib/require-separate-service-layers/internal/find-service-layer-violations.ts +1 -5
- package/src/lib/tasks/lib/require-type-checking-every-linted-file/index.ts +2 -1
- package/src/lib/tasks/lib/require-type-checking-every-linted-file/internal/find-linted-files-not-type-checked.ts +2 -4
- package/src/lib/tasks/shared/check-each-nested-package.ts +13 -1
- package/src/lib/tasks/shared/classify-files-by-role.ts +5 -0
- package/src/lib/tasks/shared/count-the-line-of-an-offset.ts +20 -2
- package/src/lib/tasks/shared/create-the-module-resolver.ts +39 -23
- package/src/lib/tasks/shared/declare-lint-config-task.ts +2 -1
- package/src/lib/tasks/shared/declare-typescript-config-task.ts +30 -2
- package/src/lib/tasks/shared/find-unmet-typescript-config-requirements.ts +19 -6
- package/src/lib/tasks/shared/list-ignored-files-imported-by-source.ts +25 -16
- package/src/lib/tasks/shared/load-the-lint-config.ts +14 -12
- package/src/lib/tasks/shared/parse-config-files-that-import-from-check.ts +6 -7
- package/src/lib/tasks/shared/project-config-and-tool-errors.ts +46 -2
- package/src/lib/tasks/shared/provide-project-query-caches.ts +11 -0
- package/src/lib/tasks/shared/query-the-typescript-project.ts +108 -43
- package/src/lib/tasks/shared/resolve-absolute-paths.ts +4 -1
- package/src/lib/tasks/shared/resolve-module-requests.ts +131 -90
- package/src/lib/tasks/shared/run-tools-and-decode-their-reports.ts +15 -11
- package/src/shared/bans-each-permission-lifts.ts +4 -21
- package/src/shared/find-retired-words.ts +1 -1
- package/src/shared/lint-rule-messages-and-patterns.ts +7 -12
- package/src/shared/record-and-grant-permissions-by-path.ts +41 -65
package/src/lib/tasks/lib/check-import-boundaries/internal/find-import-boundary-violations.ts
CHANGED
|
@@ -1,12 +1,8 @@
|
|
|
1
|
-
import { Effect, FileSystem, Path, Schema } from "effect";
|
|
1
|
+
import { Effect, FileSystem, Path, Result, Schema } from "effect";
|
|
2
2
|
import { parseSync } from "oxc-parser";
|
|
3
3
|
|
|
4
4
|
import { fileNameOf, isWithin } from "../../../../../shared/match-file-names-and-path-prefixes.ts";
|
|
5
|
-
import {
|
|
6
|
-
SCRIPTS_DIRECTORY,
|
|
7
|
-
SOURCE_DIRECTORY,
|
|
8
|
-
TEST_DIRECTORY,
|
|
9
|
-
} from "../../../../../shared/test-home-directories.ts";
|
|
5
|
+
import { TEST_DIRECTORY } from "../../../../../shared/test-home-directories.ts";
|
|
10
6
|
import {
|
|
11
7
|
isFileSpecifier,
|
|
12
8
|
isScript,
|
|
@@ -16,7 +12,7 @@ import {
|
|
|
16
12
|
repeatsSourceNeverImportsScripts,
|
|
17
13
|
SOURCE_NEVER_IMPORTS_SCRIPTS,
|
|
18
14
|
} from "../../../shared/classify-files-by-role.ts";
|
|
19
|
-
import {
|
|
15
|
+
import { lineNumbersIn } from "../../../shared/count-the-line-of-an-offset.ts";
|
|
20
16
|
import {
|
|
21
17
|
moduleRequestsIn,
|
|
22
18
|
moduleUrlMisusesIn,
|
|
@@ -36,6 +32,7 @@ import {
|
|
|
36
32
|
} from "../../../shared/query-the-typescript-project.ts";
|
|
37
33
|
import { packageManifestObject } from "../../../shared/read-package-manifest-object.ts";
|
|
38
34
|
import { resolveModuleRequest } from "../../../shared/resolve-module-requests.ts";
|
|
35
|
+
import { importPolicyOf } from "./decide-what-each-home-may-import.ts";
|
|
39
36
|
import { packageRequestBehindSubpathImport } from "./find-subpath-import-targets.ts";
|
|
40
37
|
import { whatHidesTheImport } from "./find-what-hides-an-import.ts";
|
|
41
38
|
import type { IMPORT_BOUNDARY_VIOLATION } from "./import-boundary-errors.ts";
|
|
@@ -201,192 +198,223 @@ export const findImportBoundaryViolations = (projectFile: string) =>
|
|
|
201
198
|
isTypeChecked: boolean;
|
|
202
199
|
isReportedByNoRequireImports: boolean;
|
|
203
200
|
}[] = [];
|
|
204
|
-
const
|
|
201
|
+
const addViolation = (found: typeof IMPORT_BOUNDARY_VIOLATION.Type) =>
|
|
205
202
|
violations.set(`${found.location} ${found.message}`, found);
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
: new ModuleUrlNotInline({ location, usage: misuse.usage }),
|
|
228
|
-
);
|
|
229
|
-
}
|
|
230
|
-
for (const { start, property } of directoryPaths) {
|
|
231
|
-
add(
|
|
232
|
-
new ModulePathFromDirectory({
|
|
233
|
-
location: `${displayName}:${lineNumberAt(text, start)}`,
|
|
234
|
-
property,
|
|
235
|
-
}),
|
|
236
|
-
);
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
const importingFile = path.join(packageDirectory, displayName);
|
|
240
|
-
const { requests, reportedByNoRequireImports } = moduleRequestsIn(parsed);
|
|
241
|
-
for (const request of requests) {
|
|
242
|
-
if (request.kind === "build") {
|
|
243
|
-
continue;
|
|
244
|
-
}
|
|
245
|
-
const resolvesAPackage = request.kind === "resolve" && !isFileSpecifier(request.specifier);
|
|
246
|
-
const isUrlToNonScript =
|
|
247
|
-
URL_REQUESTS.has(request.kind) && !isScript(request.specifier) && !resolvesAPackage;
|
|
248
|
-
if (isUrlToNonScript) {
|
|
249
|
-
continue;
|
|
250
|
-
}
|
|
251
|
-
const location = `${displayName}:${lineNumberAt(text, request.start)}`;
|
|
252
|
-
const isTypeChecked =
|
|
253
|
-
REQUESTS_BUN_CHECK_RESOLVES.has(request.kind) && typeCheckedFiles.has(displayName);
|
|
254
|
-
const specifierText = request.specifier;
|
|
255
|
-
const resolved = yield* resolveModuleRequest({
|
|
256
|
-
request: specifierText,
|
|
257
|
-
importingFile,
|
|
258
|
-
customConditions,
|
|
259
|
-
projectDirectory: packageDirectory,
|
|
260
|
-
});
|
|
261
|
-
if (resolved === undefined) {
|
|
262
|
-
if (isFileSpecifier(specifierText)) {
|
|
263
|
-
unresolved.push({
|
|
264
|
-
location,
|
|
265
|
-
specifier: specifierText,
|
|
266
|
-
missingPath: packagePathOf(
|
|
267
|
-
path,
|
|
268
|
-
packageDirectory,
|
|
269
|
-
path.resolve(path.dirname(importingFile), specifierText),
|
|
270
|
-
),
|
|
271
|
-
isTypeChecked,
|
|
272
|
-
isReportedByNoRequireImports: reportedByNoRequireImports.has(request.start),
|
|
273
|
-
});
|
|
274
|
-
}
|
|
275
|
-
continue;
|
|
276
|
-
}
|
|
277
|
-
const written = withoutScriptExtension(
|
|
278
|
-
path.resolve(path.dirname(importingFile), specifierText),
|
|
203
|
+
const violationsIn = (displayName: string) =>
|
|
204
|
+
Effect.gen(function* () {
|
|
205
|
+
const found: (typeof IMPORT_BOUNDARY_VIOLATION.Type)[] = [];
|
|
206
|
+
const add = (violation: typeof IMPORT_BOUNDARY_VIOLATION.Type) => {
|
|
207
|
+
found.push(violation);
|
|
208
|
+
};
|
|
209
|
+
const unresolvedInFile = new Array<(typeof unresolved)[number]>();
|
|
210
|
+
const text = yield* fileSystem.readFileString(path.join(packageDirectory, displayName));
|
|
211
|
+
const parsed = parseSync(displayName, text);
|
|
212
|
+
const lineAt = lineNumbersIn(text);
|
|
213
|
+
const policy = importPolicyOf(displayName);
|
|
214
|
+
const bans = boundaries.flatMap((boundary) =>
|
|
215
|
+
isWithin(displayName, boundary.path)
|
|
216
|
+
? boundary.cannotImport
|
|
217
|
+
.filter((target) => !isWithin(displayName, target))
|
|
218
|
+
.map((target) => ({
|
|
219
|
+
target,
|
|
220
|
+
grantPath: boundary.path,
|
|
221
|
+
isBuiltIn: boundary === SOURCE_NEVER_IMPORTS_SCRIPTS,
|
|
222
|
+
}))
|
|
223
|
+
: [],
|
|
279
224
|
);
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
const requestedPackage = BARE_PACKAGE_NAME.exec(specifierText)?.[0];
|
|
299
|
-
const isDeclaredDependency =
|
|
300
|
-
requestedPackage !== undefined && dependencies.declared.has(requestedPackage);
|
|
301
|
-
const dependencyName = isDeclaredDependency ? requestedPackage : packageName;
|
|
302
|
-
const isDevOnlyPackageImportedBySource =
|
|
303
|
-
!isUrlLoad &&
|
|
304
|
-
isWithin(displayName, SOURCE_DIRECTORY) &&
|
|
305
|
-
dependencyName !== null &&
|
|
306
|
-
packageRoot !== packageDirectory &&
|
|
307
|
-
dependencies.devOnly.has(dependencyName);
|
|
308
|
-
if (isDevOnlyPackageImportedBySource) {
|
|
309
|
-
add(
|
|
310
|
-
new DevDependencyImported({
|
|
311
|
-
location,
|
|
312
|
-
specifier: specifierText,
|
|
313
|
-
packageName: dependencyName,
|
|
314
|
-
}),
|
|
315
|
-
);
|
|
225
|
+
if (policy.checksModuleUrls) {
|
|
226
|
+
const { misuses, directoryPaths } = moduleUrlMisusesIn(parsed);
|
|
227
|
+
for (const { start, ...misuse } of misuses) {
|
|
228
|
+
const location = `${displayName}:${lineAt(start)}`;
|
|
229
|
+
add(
|
|
230
|
+
"callee" in misuse
|
|
231
|
+
? new ModuleUrlPassedToFunction({ location, callee: misuse.callee })
|
|
232
|
+
: new ModuleUrlNotInline({ location, usage: misuse.usage }),
|
|
233
|
+
);
|
|
234
|
+
}
|
|
235
|
+
for (const { start, property } of directoryPaths) {
|
|
236
|
+
add(
|
|
237
|
+
new ModulePathFromDirectory({
|
|
238
|
+
location: `${displayName}:${lineAt(start)}`,
|
|
239
|
+
property,
|
|
240
|
+
}),
|
|
241
|
+
);
|
|
242
|
+
}
|
|
316
243
|
}
|
|
317
|
-
const
|
|
318
|
-
const
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
244
|
+
const importingFile = path.join(packageDirectory, displayName);
|
|
245
|
+
const { requests, reportedByNoRequireImports } = moduleRequestsIn(parsed);
|
|
246
|
+
for (const request of requests) {
|
|
247
|
+
if (request.kind === "build") {
|
|
248
|
+
continue;
|
|
249
|
+
}
|
|
250
|
+
const resolvesAPackage =
|
|
251
|
+
request.kind === "resolve" && !isFileSpecifier(request.specifier);
|
|
252
|
+
const isUrlToNonScript =
|
|
253
|
+
URL_REQUESTS.has(request.kind) && !isScript(request.specifier) && !resolvesAPackage;
|
|
254
|
+
if (isUrlToNonScript) {
|
|
255
|
+
continue;
|
|
256
|
+
}
|
|
257
|
+
const location = `${displayName}:${lineAt(request.start)}`;
|
|
258
|
+
const isTypeChecked =
|
|
259
|
+
REQUESTS_BUN_CHECK_RESOLVES.has(request.kind) && typeCheckedFiles.has(displayName);
|
|
260
|
+
const specifierText = request.specifier;
|
|
261
|
+
const resolved = yield* resolveModuleRequest({
|
|
262
|
+
request: specifierText,
|
|
263
|
+
importingFile,
|
|
264
|
+
customConditions,
|
|
265
|
+
projectDirectory: packageDirectory,
|
|
266
|
+
});
|
|
267
|
+
if (resolved === undefined) {
|
|
268
|
+
if (isFileSpecifier(specifierText)) {
|
|
269
|
+
unresolvedInFile.push({
|
|
270
|
+
location,
|
|
271
|
+
specifier: specifierText,
|
|
272
|
+
missingPath: packagePathOf(
|
|
273
|
+
path,
|
|
274
|
+
packageDirectory,
|
|
275
|
+
path.resolve(path.dirname(importingFile), specifierText),
|
|
276
|
+
),
|
|
277
|
+
isTypeChecked,
|
|
278
|
+
isReportedByNoRequireImports: reportedByNoRequireImports.has(request.start),
|
|
279
|
+
});
|
|
280
|
+
}
|
|
281
|
+
continue;
|
|
282
|
+
}
|
|
283
|
+
const written = withoutScriptExtension(
|
|
284
|
+
path.resolve(path.dirname(importingFile), specifierText),
|
|
336
285
|
);
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
286
|
+
const actual = withoutScriptExtension(resolved.file);
|
|
287
|
+
const importedFile = path.relative(packageDirectory, resolved.file);
|
|
288
|
+
const differsFromWrittenPathOnlyInCase =
|
|
289
|
+
!(isTypeChecked && includedByTheProject.has(importedFile)) &&
|
|
290
|
+
isFileSpecifier(specifierText) &&
|
|
291
|
+
!actual.startsWith(written) &&
|
|
292
|
+
actual.toLowerCase().startsWith(written.toLowerCase());
|
|
293
|
+
if (differsFromWrittenPathOnlyInCase) {
|
|
294
|
+
add(
|
|
295
|
+
new ImportCaseMismatch({
|
|
296
|
+
location,
|
|
297
|
+
specifier: specifierText,
|
|
298
|
+
importedFile,
|
|
299
|
+
}),
|
|
300
|
+
);
|
|
301
|
+
}
|
|
302
|
+
const isUrlLoad = request.kind === "url" || request.kind === "launch";
|
|
303
|
+
const { packageName, packageRoot } = resolved;
|
|
304
|
+
const requestedPackage = BARE_PACKAGE_NAME.exec(specifierText)?.[0];
|
|
305
|
+
const isDeclaredDependency =
|
|
306
|
+
requestedPackage !== undefined && dependencies.declared.has(requestedPackage);
|
|
307
|
+
const dependencyName = isDeclaredDependency ? requestedPackage : packageName;
|
|
308
|
+
const isDevOnlyPackageImportedBySource =
|
|
309
|
+
!isUrlLoad &&
|
|
310
|
+
!policy.mayImportDevDependencies &&
|
|
311
|
+
dependencyName !== null &&
|
|
312
|
+
packageRoot !== packageDirectory &&
|
|
313
|
+
dependencies.devOnly.has(dependencyName);
|
|
314
|
+
if (isDevOnlyPackageImportedBySource) {
|
|
315
|
+
add(
|
|
316
|
+
new DevDependencyImported({
|
|
317
|
+
location,
|
|
318
|
+
specifier: specifierText,
|
|
319
|
+
packageName: dependencyName,
|
|
320
|
+
}),
|
|
321
|
+
);
|
|
322
|
+
}
|
|
323
|
+
const place = placeOf(resolved.file);
|
|
324
|
+
const packageRequest = yield* packageRequestBehindSubpathImport({
|
|
325
|
+
request: specifierText,
|
|
326
|
+
importingFile,
|
|
327
|
+
customConditions,
|
|
328
|
+
projectDirectory: packageDirectory,
|
|
329
|
+
});
|
|
330
|
+
const importedThroughPackage = importsPackageEntry(
|
|
331
|
+
packageRequest ?? specifierText,
|
|
332
|
+
resolved,
|
|
362
333
|
);
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
fileNameOf(importedPath) === PACKAGE_MANIFEST_FILE ||
|
|
372
|
-
isTestImportingOutsideTests;
|
|
373
|
-
const isResolvedIntoAnotherPackage =
|
|
374
|
-
packageRoot !== null && packageRoot !== packageDirectory;
|
|
375
|
-
const hidden = isExemptFromVisibilityCheck
|
|
376
|
-
? undefined
|
|
377
|
-
: visibilityViolationOf(
|
|
378
|
-
displayName,
|
|
379
|
-
importedPath,
|
|
380
|
-
moduleDirectories,
|
|
381
|
-
location,
|
|
382
|
-
isResolvedIntoAnotherPackage
|
|
383
|
-
? packagePathOf(path, packageDirectory, packageRoot)
|
|
384
|
-
: undefined,
|
|
334
|
+
const importsFileOutsidePackage = "outside" in place && !importedThroughPackage;
|
|
335
|
+
if (importsFileOutsidePackage) {
|
|
336
|
+
add(
|
|
337
|
+
new ImportOutsidePackage({
|
|
338
|
+
location,
|
|
339
|
+
specifier: specifierText,
|
|
340
|
+
importedFile: resolved.file,
|
|
341
|
+
}),
|
|
385
342
|
);
|
|
386
|
-
|
|
387
|
-
|
|
343
|
+
}
|
|
344
|
+
if (!("packagePath" in place)) {
|
|
345
|
+
continue;
|
|
346
|
+
}
|
|
347
|
+
const importedPath = place.packagePath;
|
|
348
|
+
const isRefusedTestImport =
|
|
349
|
+
isWithin(importedPath, TEST_DIRECTORY) && !policy.mayImportTests;
|
|
350
|
+
if (isRefusedTestImport) {
|
|
351
|
+
add(new TestImported({ location, importedPath }));
|
|
352
|
+
}
|
|
353
|
+
if (isUrlLoad) {
|
|
354
|
+
continue;
|
|
355
|
+
}
|
|
356
|
+
const crossedBans = bans.filter((candidate) => isWithin(importedPath, candidate.target));
|
|
357
|
+
for (const ban of crossedBans) {
|
|
358
|
+
add(
|
|
359
|
+
new CannotImportCrossed({
|
|
360
|
+
location,
|
|
361
|
+
importedPath,
|
|
362
|
+
grantPath: ban.grantPath,
|
|
363
|
+
target: ban.target,
|
|
364
|
+
}),
|
|
365
|
+
);
|
|
366
|
+
}
|
|
367
|
+
if (isRefusedTestImport) {
|
|
368
|
+
continue;
|
|
369
|
+
}
|
|
370
|
+
const isResolvedIntoAnotherPackage =
|
|
371
|
+
packageRoot !== null && packageRoot !== packageDirectory;
|
|
372
|
+
const isExemptFromVisibilityCheck =
|
|
373
|
+
crossedBans.some((ban) => ban.isBuiltIn) ||
|
|
374
|
+
(importedThroughPackage && packageRoot !== packageDirectory) ||
|
|
375
|
+
fileNameOf(importedPath) === PACKAGE_MANIFEST_FILE ||
|
|
376
|
+
policy.seesPastModuleBoundaries({
|
|
377
|
+
path: importedPath,
|
|
378
|
+
isInAnotherPackage: isResolvedIntoAnotherPackage,
|
|
379
|
+
moduleDirectories,
|
|
380
|
+
});
|
|
381
|
+
const hidden = isExemptFromVisibilityCheck
|
|
382
|
+
? undefined
|
|
383
|
+
: visibilityViolationOf(
|
|
384
|
+
displayName,
|
|
385
|
+
importedPath,
|
|
386
|
+
moduleDirectories,
|
|
387
|
+
location,
|
|
388
|
+
isResolvedIntoAnotherPackage
|
|
389
|
+
? packagePathOf(path, packageDirectory, packageRoot)
|
|
390
|
+
: undefined,
|
|
391
|
+
);
|
|
392
|
+
if (hidden !== undefined) {
|
|
393
|
+
add(hidden);
|
|
394
|
+
}
|
|
388
395
|
}
|
|
396
|
+
return { found, unresolvedInFile };
|
|
397
|
+
});
|
|
398
|
+
const scannedFiles = yield* Effect.forEach(
|
|
399
|
+
checkedFiles,
|
|
400
|
+
(displayName) =>
|
|
401
|
+
violationsIn(displayName).pipe(
|
|
402
|
+
Effect.map(Result.succeed),
|
|
403
|
+
Effect.catchTag("ModuleRequestUnresolvable", (unresolvable) =>
|
|
404
|
+
Effect.succeed(Result.fail(unresolvable)),
|
|
405
|
+
),
|
|
406
|
+
),
|
|
407
|
+
{ concurrency: "unbounded" },
|
|
408
|
+
);
|
|
409
|
+
for (const scanned of scannedFiles) {
|
|
410
|
+
if (Result.isFailure(scanned)) {
|
|
411
|
+
return yield* scanned.failure;
|
|
412
|
+
}
|
|
413
|
+
const { found, unresolvedInFile } = scanned.success;
|
|
414
|
+
for (const violation of found) {
|
|
415
|
+
addViolation(violation);
|
|
389
416
|
}
|
|
417
|
+
unresolved.push(...unresolvedInFile);
|
|
390
418
|
}
|
|
391
419
|
const ignored = new Set(
|
|
392
420
|
yield* ignoredPackagePathsAmong(
|
|
@@ -404,9 +432,9 @@ export const findImportBoundaryViolations = (projectFile: string) =>
|
|
|
404
432
|
const isReportedByTheTypeCheckOrNoRequireImports =
|
|
405
433
|
isTypeChecked || isReportedByNoRequireImports;
|
|
406
434
|
if (ignored.has(missingPath)) {
|
|
407
|
-
|
|
435
|
+
addViolation(new ImportOfMissingIgnoredFile({ location, specifier, missingPath }));
|
|
408
436
|
} else if (!isReportedByTheTypeCheckOrNoRequireImports) {
|
|
409
|
-
|
|
437
|
+
addViolation(new ImportResolvesToNoFile({ location, specifier }));
|
|
410
438
|
}
|
|
411
439
|
}
|
|
412
440
|
if (violations.size > 0) {
|
|
@@ -29,6 +29,7 @@ import type { Checker, Symbol as TypeScriptSymbol, Type } from "typescript/unsta
|
|
|
29
29
|
|
|
30
30
|
import { isUnderTestDirectory } from "../../../shared/classify-files-by-role.ts";
|
|
31
31
|
import {
|
|
32
|
+
callsIn,
|
|
32
33
|
CONCURRENT_TYPESCRIPT_REQUESTS,
|
|
33
34
|
nodePosition,
|
|
34
35
|
packageCalleeOf,
|
|
@@ -46,6 +47,7 @@ import {
|
|
|
46
47
|
EFFECT_MODULE,
|
|
47
48
|
importedPackageApis,
|
|
48
49
|
LAYER_MODULE,
|
|
50
|
+
STREAM_MODULE,
|
|
49
51
|
} from "./resolve-imported-package-apis.ts";
|
|
50
52
|
|
|
51
53
|
const LAYER_TYPE_ID = "~effect/Layer" satisfies keyof Layer.Any;
|
|
@@ -73,7 +75,9 @@ const EFFECT_OPERATIONS = [
|
|
|
73
75
|
]),
|
|
74
76
|
},
|
|
75
77
|
{ module: LAYER_MODULE, names: LAYER_BUILDERS },
|
|
78
|
+
{ module: STREAM_MODULE, names: PROVIDE_OPERATIONS },
|
|
76
79
|
];
|
|
80
|
+
const PROVIDING_MODULES = [EFFECT_MODULE, STREAM_MODULE];
|
|
77
81
|
const PIPE = "pipe";
|
|
78
82
|
const PROVIDED_ARGUMENTS = 2;
|
|
79
83
|
|
|
@@ -97,18 +101,6 @@ const outermostWrapperOf = (node: Node): Node =>
|
|
|
97
101
|
const isFunctionLike = (node: Node) =>
|
|
98
102
|
isFunctionDeclaration(node) || isFunctionExpression(node) || isArrowFunction(node);
|
|
99
103
|
|
|
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
104
|
const returnedBy = (callable: Node) => {
|
|
113
105
|
const body = isFunctionLike(callable) ? callable.body : undefined;
|
|
114
106
|
if (body === undefined) {
|
|
@@ -549,9 +541,13 @@ const provideOperationsIn = (
|
|
|
549
541
|
return named.flatMap(({ call }, index) => {
|
|
550
542
|
const symbol = symbols[index];
|
|
551
543
|
const target = symbol === undefined ? undefined : (aliased.get(symbol.id) ?? symbol);
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
544
|
+
if (target === undefined) {
|
|
545
|
+
return [];
|
|
546
|
+
}
|
|
547
|
+
const module = PROVIDING_MODULES.find((candidate) =>
|
|
548
|
+
isExportOf(apis, target, candidate, PROVIDE_OPERATIONS),
|
|
549
|
+
);
|
|
550
|
+
return module === undefined ? [] : [{ call, module, operation: target.name }];
|
|
555
551
|
});
|
|
556
552
|
});
|
|
557
553
|
|
|
@@ -584,7 +580,7 @@ const fileViolations = (
|
|
|
584
580
|
) =>
|
|
585
581
|
Effect.gen(function* () {
|
|
586
582
|
const provides = yield* provideOperationsIn(checker, apis, callsIn(sourceFile));
|
|
587
|
-
const violations = yield* Effect.forEach(provides, ({ call, operation }) =>
|
|
583
|
+
const violations = yield* Effect.forEach(provides, ({ call, module, operation }) =>
|
|
588
584
|
Effect.gen(function* () {
|
|
589
585
|
const provided = yield* providedValueOf(checker, isBuiltContext, call, operation);
|
|
590
586
|
if (provided === undefined) {
|
|
@@ -597,6 +593,7 @@ const fileViolations = (
|
|
|
597
593
|
return [
|
|
598
594
|
new LayerProvidedOutsideProgramStart({
|
|
599
595
|
location: `${displayName}:${line}:${column}`,
|
|
596
|
+
module,
|
|
600
597
|
operation,
|
|
601
598
|
provided,
|
|
602
599
|
}),
|
package/src/lib/tasks/lib/confine-layer-provides-to-program-starts/internal/layer-provide-errors.ts
CHANGED
|
@@ -8,12 +8,13 @@ export class LayerProvidedOutsideProgramStart extends Schema.TaggedError<LayerPr
|
|
|
8
8
|
"LayerProvidedOutsideProgramStart",
|
|
9
9
|
{
|
|
10
10
|
location: Schema.String,
|
|
11
|
+
module: Schema.String,
|
|
11
12
|
operation: Schema.String,
|
|
12
13
|
provided: Schema.Literals(PROVIDED_VALUES),
|
|
13
14
|
},
|
|
14
15
|
) {
|
|
15
16
|
public override get message() {
|
|
16
|
-
return
|
|
17
|
+
return `${this.module}.${this.operation} with ${this.provided} outside the call that starts the program`;
|
|
17
18
|
}
|
|
18
19
|
}
|
|
19
20
|
|
|
@@ -12,6 +12,7 @@ import {
|
|
|
12
12
|
TASK_NAMESPACE_EXPORT,
|
|
13
13
|
TASK_PACKAGE,
|
|
14
14
|
TASK_MAIN_MEMBER,
|
|
15
|
+
TASK_MAKE_MEMBER,
|
|
15
16
|
} from "../../../../../shared/bans-each-permission-lifts.ts";
|
|
16
17
|
import {
|
|
17
18
|
CONCURRENT_TYPESCRIPT_REQUESTS,
|
|
@@ -29,6 +30,7 @@ const NO_MEMBERS = [] as const;
|
|
|
29
30
|
const PACKAGE_ROOT = "";
|
|
30
31
|
export const EFFECT_MODULE = "Effect";
|
|
31
32
|
export const LAYER_MODULE = "Layer";
|
|
33
|
+
export const STREAM_MODULE = "Stream";
|
|
32
34
|
const MANAGED_RUNTIME = "ManagedRuntime";
|
|
33
35
|
const RUNTIME_MODULE = "Runtime";
|
|
34
36
|
const MAKE_RUN_MAIN = "makeRunMain";
|
|
@@ -92,7 +94,7 @@ const PROGRAM_STARTS = [
|
|
|
92
94
|
isPackage: isTaskPackage,
|
|
93
95
|
module: PACKAGE_ROOT,
|
|
94
96
|
exports: [TASK_NAMESPACE_EXPORT],
|
|
95
|
-
members: [TASK_MAIN_MEMBER],
|
|
97
|
+
members: [TASK_MAIN_MEMBER, TASK_MAKE_MEMBER],
|
|
96
98
|
returnedBySignature: DIRECT_CALLS,
|
|
97
99
|
},
|
|
98
100
|
] as const;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Task } from "@sshkeda/task";
|
|
2
|
+
import { Effect } from "effect";
|
|
3
|
+
|
|
4
|
+
import { ProjectQueryCachesLive } from "../../shared/provide-project-query-caches.ts";
|
|
5
|
+
import { duplicateFunctionsOfEachPackage } from "./internal/find-duplicate-functions.ts";
|
|
6
|
+
|
|
7
|
+
export const duplicateFunctions = Task.make(
|
|
8
|
+
"duplicate-functions",
|
|
9
|
+
duplicateFunctionsOfEachPackage.pipe(Effect.provide(ProjectQueryCachesLive)),
|
|
10
|
+
);
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Schema } from "effect";
|
|
2
|
+
|
|
3
|
+
import { listedViolations } from "../../../../../shared/format-reported-failures.ts";
|
|
4
|
+
import { joinedWithAnd } from "../../../shared/classify-files-by-role.ts";
|
|
5
|
+
|
|
6
|
+
export class DuplicateFunction extends Schema.TaggedError<DuplicateFunction>()(
|
|
7
|
+
"DuplicateFunction",
|
|
8
|
+
{ location: Schema.String, functionName: Schema.String, copies: Schema.Array(Schema.String) },
|
|
9
|
+
) {
|
|
10
|
+
public override get message() {
|
|
11
|
+
const copies = this.copies.length === 1 ? "an exact copy" : "exact copies";
|
|
12
|
+
return `${this.functionName} has ${copies} in ${joinedWithAnd(this.copies)}`;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export class DuplicateFunctions extends Schema.TaggedError<DuplicateFunctions>()(
|
|
17
|
+
"DuplicateFunctions",
|
|
18
|
+
{ violations: Schema.Array(DuplicateFunction) },
|
|
19
|
+
) {
|
|
20
|
+
public override get message() {
|
|
21
|
+
return listedViolations(this.violations);
|
|
22
|
+
}
|
|
23
|
+
}
|