@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
|
@@ -3,6 +3,7 @@ import { Effect } from "effect";
|
|
|
3
3
|
|
|
4
4
|
import { lintConfigFile } from "../../shared/declare-lint-config-task.ts";
|
|
5
5
|
import { typeScriptConfig } from "../../shared/declare-typescript-config-task.ts";
|
|
6
|
+
import { ProjectQueryCachesLive } from "../../shared/provide-project-query-caches.ts";
|
|
6
7
|
import { lintedFilesNotTypeCheckedInEachPackage } from "./internal/find-linted-files-not-type-checked.ts";
|
|
7
8
|
|
|
8
9
|
export const lintedFilesTypeChecked = Task.make(
|
|
@@ -10,5 +11,5 @@ export const lintedFilesTypeChecked = Task.make(
|
|
|
10
11
|
Effect.andThen(
|
|
11
12
|
Task.all([typeScriptConfig, lintConfigFile]),
|
|
12
13
|
lintedFilesNotTypeCheckedInEachPackage,
|
|
13
|
-
),
|
|
14
|
+
).pipe(Effect.provide(ProjectQueryCachesLive)),
|
|
14
15
|
);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Effect,
|
|
1
|
+
import { Effect, Path, Schema } from "effect";
|
|
2
2
|
import { ScriptKind } from "typescript/unstable/ast";
|
|
3
3
|
|
|
4
4
|
import { inEachPackage } from "../../../shared/check-each-nested-package.ts";
|
|
@@ -11,6 +11,7 @@ import {
|
|
|
11
11
|
packageSourceFilesOfEachProject,
|
|
12
12
|
TYPESCRIPT_PROJECT_FILE,
|
|
13
13
|
} from "../../../shared/query-the-typescript-project.ts";
|
|
14
|
+
import { realPathOf } from "../../../shared/resolve-absolute-paths.ts";
|
|
14
15
|
import {
|
|
15
16
|
LintedDeclarationFileNotTypeChecked,
|
|
16
17
|
LintedFileOutsideTypeScriptProgram,
|
|
@@ -33,9 +34,6 @@ const isTypeChecked = (
|
|
|
33
34
|
? options.skipLibCheck !== true
|
|
34
35
|
: !JAVASCRIPT_SCRIPT_KINDS.has(sourceFile.scriptKind) || options.checkJs === true;
|
|
35
36
|
|
|
36
|
-
const realPathOf = (file: string) =>
|
|
37
|
-
FileSystem.FileSystem.use((fileSystem) => fileSystem.realPath(file));
|
|
38
|
-
|
|
39
37
|
const violationFor = (
|
|
40
38
|
file: string,
|
|
41
39
|
projectFile: string,
|
|
@@ -39,6 +39,18 @@ const locatedInPackage = (
|
|
|
39
39
|
message: printable.message,
|
|
40
40
|
};
|
|
41
41
|
|
|
42
|
+
const distinctPrintedErrors = (printables: readonly PrintableError[]) => {
|
|
43
|
+
const printedByLocation = new Map<string | undefined, Set<string>>();
|
|
44
|
+
return printables.filter(({ tag, location, message }) => {
|
|
45
|
+
const printed = printedByLocation.get(location) ?? new Set<string>();
|
|
46
|
+
printedByLocation.set(location, printed);
|
|
47
|
+
const printedLine = `${tag}: ${message}`;
|
|
48
|
+
const isFirstPrinted = !printed.has(printedLine);
|
|
49
|
+
printed.add(printedLine);
|
|
50
|
+
return isFirstPrinted;
|
|
51
|
+
});
|
|
52
|
+
};
|
|
53
|
+
|
|
42
54
|
export const packageDirectoriesIn = (directory: string) =>
|
|
43
55
|
listedPackageFiles(directory, []).pipe(
|
|
44
56
|
Effect.map(({ nestedPackageDirectories }) => [
|
|
@@ -72,7 +84,7 @@ export const inEachPackage = <Requirements>(
|
|
|
72
84
|
),
|
|
73
85
|
{ concurrency: "unbounded" },
|
|
74
86
|
);
|
|
75
|
-
const reportedErrors = reportedByPackage.flat();
|
|
87
|
+
const reportedErrors = distinctPrintedErrors(reportedByPackage.flat());
|
|
76
88
|
if (Arrays.isArrayNonEmpty(reportedErrors)) {
|
|
77
89
|
return yield* new ReportedErrors({ reportedErrors });
|
|
78
90
|
}
|
|
@@ -37,6 +37,11 @@ const DECLARATION_FILE = /\.d\.[cm]?ts$/u;
|
|
|
37
37
|
|
|
38
38
|
export const isDeclarationFile = (path: string) => DECLARATION_FILE.test(path);
|
|
39
39
|
|
|
40
|
+
const TYPESCRIPT_SOURCE_FILE = /\.tsx?$/u;
|
|
41
|
+
|
|
42
|
+
export const isTypeScriptSourceFile = (path: string) =>
|
|
43
|
+
TYPESCRIPT_SOURCE_FILE.test(path) && !isDeclarationFile(path);
|
|
44
|
+
|
|
40
45
|
export const isPackageManifest = (path: string) => fileNameOf(path) === PACKAGE_MANIFEST_FILE;
|
|
41
46
|
|
|
42
47
|
export const directoryOf = (path: string) => path.split("/").slice(0, -1).join("/");
|
|
@@ -1,2 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
const LINE_BREAK = /\n/gu;
|
|
2
|
+
|
|
3
|
+
export const lineNumbersIn = (text: string) => {
|
|
4
|
+
const lineStarts = [0, ...Array.from(text.matchAll(LINE_BREAK), (match) => match.index + 1)];
|
|
5
|
+
const linesStartingBy = (offset: number, low: number, high: number): number => {
|
|
6
|
+
if (low >= high) {
|
|
7
|
+
return low;
|
|
8
|
+
}
|
|
9
|
+
const middle = (low + high) >>> 1;
|
|
10
|
+
return (lineStarts[middle] ?? 0) <= offset
|
|
11
|
+
? linesStartingBy(offset, middle + 1, high)
|
|
12
|
+
: linesStartingBy(offset, low, middle);
|
|
13
|
+
};
|
|
14
|
+
return (offset: number) => linesStartingBy(offset, 0, lineStarts.length);
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export const lineOfTheFirstLabel = (
|
|
18
|
+
text: string,
|
|
19
|
+
[label]: readonly { readonly start: number }[],
|
|
20
|
+
) => (label === undefined ? {} : { line: lineNumbersIn(text)(label.start) });
|
|
@@ -1,30 +1,42 @@
|
|
|
1
|
+
import { Context, Effect, Layer } from "effect";
|
|
1
2
|
import { ResolverFactory } from "oxc-resolver";
|
|
2
3
|
|
|
3
4
|
const RUNTIME_CONDITION_NAMES = ["bun", "import", "node", "default"] as const;
|
|
4
5
|
|
|
5
6
|
const TYPES_CONDITION_NAME = "types";
|
|
6
7
|
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
8
|
+
const newModuleResolver = (conditionNames: readonly string[]) =>
|
|
9
|
+
new ResolverFactory({
|
|
10
|
+
extensions: [".ts", ".tsx", ".mts", ".cts", ".d.ts", ".js", ".jsx", ".mjs", ".cjs", ".json"],
|
|
11
|
+
extensionAlias: {
|
|
12
|
+
".js": [".ts", ".tsx", ".js"],
|
|
13
|
+
".jsx": [".tsx", ".jsx"],
|
|
14
|
+
".mjs": [".mts", ".mjs"],
|
|
15
|
+
".cjs": [".cts", ".cjs"],
|
|
16
|
+
},
|
|
17
|
+
tsconfig: "auto",
|
|
18
|
+
builtinModules: true,
|
|
19
|
+
conditionNames: [...conditionNames],
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
const makeModuleResolvers = Effect.sync(() => {
|
|
23
|
+
const resolversByConditions = new Map<string, ResolverFactory>();
|
|
24
|
+
return {
|
|
25
|
+
resolverWith: (conditionNames: readonly string[]) => {
|
|
26
|
+
const key = conditionNames.join("\0");
|
|
27
|
+
const resolver = resolversByConditions.get(key) ?? newModuleResolver(conditionNames);
|
|
28
|
+
resolversByConditions.set(key, resolver);
|
|
29
|
+
return resolver;
|
|
30
|
+
},
|
|
31
|
+
};
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
class ModuleResolvers extends Context.Service<
|
|
35
|
+
ModuleResolvers,
|
|
36
|
+
Effect.Success<typeof makeModuleResolvers>
|
|
37
|
+
>()("@sshkeda/check/ModuleResolvers") {}
|
|
38
|
+
|
|
39
|
+
export const ModuleResolversLive = Layer.effect(ModuleResolvers, makeModuleResolvers);
|
|
28
40
|
|
|
29
41
|
export const conditionNamesWith = (customConditions: readonly string[]) => [
|
|
30
42
|
...customConditions,
|
|
@@ -33,6 +45,10 @@ export const conditionNamesWith = (customConditions: readonly string[]) => [
|
|
|
33
45
|
];
|
|
34
46
|
|
|
35
47
|
export const moduleResolverFor = (customConditions: readonly string[]) =>
|
|
36
|
-
|
|
48
|
+
ModuleResolvers.use(({ resolverWith }) =>
|
|
49
|
+
Effect.sync(() => resolverWith(conditionNamesWith(customConditions))),
|
|
50
|
+
);
|
|
37
51
|
|
|
38
|
-
export const runtimeModuleResolver = () =>
|
|
52
|
+
export const runtimeModuleResolver = ModuleResolvers.use(({ resolverWith }) =>
|
|
53
|
+
Effect.sync(() => resolverWith(RUNTIME_CONDITION_NAMES)),
|
|
54
|
+
);
|
|
@@ -4,10 +4,11 @@ import { Effect } from "effect";
|
|
|
4
4
|
import { inEachPackage } from "./check-each-nested-package.ts";
|
|
5
5
|
import { loadedLintConfigIn } from "./load-the-lint-config.ts";
|
|
6
6
|
import { quietViolations } from "./print-failures-and-keep-detail-in-the-trace.ts";
|
|
7
|
+
import { ProjectQueryCachesLive } from "./provide-project-query-caches.ts";
|
|
7
8
|
|
|
8
9
|
export const lintConfigFile = Task.make(
|
|
9
10
|
"lint-config",
|
|
10
11
|
inEachPackage("lint-config", ".", (packageDirectory) =>
|
|
11
12
|
loadedLintConfigIn(packageDirectory).pipe(Effect.asVoid, quietViolations("lint-config")),
|
|
12
|
-
),
|
|
13
|
+
).pipe(Effect.provide(ProjectQueryCachesLive)),
|
|
13
14
|
);
|
|
@@ -1,18 +1,46 @@
|
|
|
1
1
|
import { Task } from "@sshkeda/task";
|
|
2
|
-
import {
|
|
2
|
+
import { ReportedErrors } from "@sshkeda/task/errors";
|
|
3
|
+
import type { PrintableError } from "@sshkeda/task/errors";
|
|
4
|
+
import { Array as Arrays, Effect, Path } from "effect";
|
|
3
5
|
|
|
4
6
|
import { inEachPackage } from "./check-each-nested-package.ts";
|
|
5
7
|
import { findTypeScriptConfigViolations } from "./find-unmet-typescript-config-requirements.ts";
|
|
6
8
|
import { quietViolations } from "./print-failures-and-keep-detail-in-the-trace.ts";
|
|
9
|
+
import { ProjectQueryCachesLive } from "./provide-project-query-caches.ts";
|
|
7
10
|
import { TYPESCRIPT_PROJECT_FILE } from "./query-the-typescript-project.ts";
|
|
8
11
|
|
|
12
|
+
const locatedFromThePackage = (
|
|
13
|
+
path: Path.Path,
|
|
14
|
+
packageDirectory: string,
|
|
15
|
+
printable: PrintableError,
|
|
16
|
+
): PrintableError => {
|
|
17
|
+
const { location } = printable;
|
|
18
|
+
const isRelativeLocation = location !== undefined && !path.isAbsolute(location);
|
|
19
|
+
if (!isRelativeLocation) {
|
|
20
|
+
return printable;
|
|
21
|
+
}
|
|
22
|
+
const locationFromThePackage = path.relative(packageDirectory, location);
|
|
23
|
+
const isOutsideThePackage = locationFromThePackage.startsWith(`..${path.sep}`);
|
|
24
|
+
return isOutsideThePackage
|
|
25
|
+
? { tag: printable.tag, location: locationFromThePackage, message: printable.message }
|
|
26
|
+
: printable;
|
|
27
|
+
};
|
|
28
|
+
|
|
9
29
|
export const typeScriptConfig = Task.make(
|
|
10
30
|
"typescript-config",
|
|
11
31
|
inEachPackage("typescript-config", ".", (packageDirectory) =>
|
|
12
32
|
Path.Path.use((path) =>
|
|
13
33
|
findTypeScriptConfigViolations(path.join(packageDirectory, TYPESCRIPT_PROJECT_FILE)).pipe(
|
|
14
34
|
quietViolations("typescript-config"),
|
|
35
|
+
Effect.mapError(
|
|
36
|
+
({ reportedErrors }) =>
|
|
37
|
+
new ReportedErrors({
|
|
38
|
+
reportedErrors: Arrays.map(reportedErrors, (printable) =>
|
|
39
|
+
locatedFromThePackage(path, packageDirectory, printable),
|
|
40
|
+
),
|
|
41
|
+
}),
|
|
42
|
+
),
|
|
15
43
|
),
|
|
16
44
|
),
|
|
17
|
-
),
|
|
45
|
+
).pipe(Effect.provide(ProjectQueryCachesLive)),
|
|
18
46
|
);
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { Effect, Record } from "effect";
|
|
2
2
|
|
|
3
3
|
import {
|
|
4
|
+
BUILD_OUTPUT_OPTIONS,
|
|
5
|
+
BuildOutputCompilerOption,
|
|
4
6
|
LooseCompilerOption,
|
|
5
7
|
OPTIONS_TSC_LEAVES_UNSET,
|
|
6
8
|
REQUIRED_VALUES_OF_OPTIONS_OFF_BY_DEFAULT,
|
|
@@ -13,10 +15,11 @@ import {
|
|
|
13
15
|
projectConfigFiles,
|
|
14
16
|
} from "./query-the-typescript-project.ts";
|
|
15
17
|
|
|
16
|
-
const optionViolationsOf = (configFile: string) =>
|
|
18
|
+
const optionViolationsOf = (configFile: string, isReferenced: boolean) =>
|
|
17
19
|
effectiveCompilerOptions(configFile).pipe(
|
|
18
|
-
Effect.map((options) =>
|
|
19
|
-
|
|
20
|
+
Effect.map((options) => {
|
|
21
|
+
const emitOption = isReferenced ? "emitDeclarationOnly" : "noEmit";
|
|
22
|
+
const looseOptions = [
|
|
20
23
|
...STRICT_OPTIONS.map((option) => ({
|
|
21
24
|
option,
|
|
22
25
|
required: true,
|
|
@@ -32,6 +35,7 @@ const optionViolationsOf = (configFile: string) =>
|
|
|
32
35
|
(options[option] ?? (OPTIONS_TSC_LEAVES_UNSET.has(option) ? undefined : false)),
|
|
33
36
|
}),
|
|
34
37
|
),
|
|
38
|
+
{ option: emitOption, required: true, resolvedValue: options[emitOption] } as const,
|
|
35
39
|
].flatMap(({ option, required, resolvedValue }) => {
|
|
36
40
|
if (resolvedValue === undefined) {
|
|
37
41
|
return [new LooseCompilerOption({ projectFile: configFile, option })];
|
|
@@ -40,8 +44,12 @@ const optionViolationsOf = (configFile: string) =>
|
|
|
40
44
|
return isLoose
|
|
41
45
|
? [new LooseCompilerOption({ projectFile: configFile, option, resolvedValue })]
|
|
42
46
|
: [];
|
|
43
|
-
})
|
|
44
|
-
|
|
47
|
+
});
|
|
48
|
+
const buildOutputOptions = (isReferenced ? [] : BUILD_OUTPUT_OPTIONS)
|
|
49
|
+
.filter((option) => options[option] !== undefined && options[option] !== false)
|
|
50
|
+
.map((option) => new BuildOutputCompilerOption({ projectFile: configFile, option }));
|
|
51
|
+
return [...looseOptions, ...buildOutputOptions];
|
|
52
|
+
}),
|
|
45
53
|
);
|
|
46
54
|
|
|
47
55
|
export const findTypeScriptConfigViolations = (projectFile: string) =>
|
|
@@ -54,10 +62,15 @@ export const findTypeScriptConfigViolations = (projectFile: string) =>
|
|
|
54
62
|
Effect.fail(new TypeScriptConfigViolations({ violations: [unparsable] })),
|
|
55
63
|
ProjectReferencesUndecodable: (undecodable) =>
|
|
56
64
|
Effect.fail(new TypeScriptConfigViolations({ violations: [undecodable] })),
|
|
65
|
+
AbsoluteProjectReference: (absolute) =>
|
|
66
|
+
Effect.fail(new TypeScriptConfigViolations({ violations: [absolute] })),
|
|
57
67
|
}),
|
|
58
68
|
);
|
|
69
|
+
const [rootConfigFile] = builtConfigFiles;
|
|
59
70
|
const compilingConfigFiles = yield* Effect.filter(builtConfigFiles, compilesFiles);
|
|
60
|
-
const violations = (yield* Effect.forEach(compilingConfigFiles,
|
|
71
|
+
const violations = (yield* Effect.forEach(compilingConfigFiles, (configFile) =>
|
|
72
|
+
optionViolationsOf(configFile, configFile !== rootConfigFile),
|
|
73
|
+
)).flat();
|
|
61
74
|
if (violations.length > 0) {
|
|
62
75
|
return yield* new TypeScriptConfigViolations({ violations });
|
|
63
76
|
}
|
|
@@ -12,6 +12,8 @@ import {
|
|
|
12
12
|
import { resolveModuleRequest } from "./resolve-module-requests.ts";
|
|
13
13
|
|
|
14
14
|
const CHECK_IGNORE_EXIT_CODE_WHEN_NO_PATH_IS_IGNORED = 1;
|
|
15
|
+
const CONCURRENT_SOURCE_FILE_SCANS = 32;
|
|
16
|
+
|
|
15
17
|
export const ignoredPackagePathsAmong = (
|
|
16
18
|
packagePaths: readonly string[],
|
|
17
19
|
packageDirectory: string,
|
|
@@ -47,23 +49,30 @@ export const ignoredFilesImportedIn = (projectFile: string) =>
|
|
|
47
49
|
const { customConditions = [] } = yield* Schema.decodeEffect(CUSTOM_CONDITIONS)(
|
|
48
50
|
yield* effectiveCompilerOptions(projectFile),
|
|
49
51
|
);
|
|
50
|
-
const
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
52
|
+
const importedPathsOf = (displayName: string) =>
|
|
53
|
+
Effect.gen(function* () {
|
|
54
|
+
const importingFile = path.join(packageDirectory, displayName);
|
|
55
|
+
const parsed = parseSync(displayName, yield* fileSystem.readFileString(importingFile));
|
|
56
|
+
const importedPaths: string[] = [];
|
|
57
|
+
for (const { specifier } of moduleRequestsIn(parsed).requests) {
|
|
58
|
+
if (isFileSpecifier(specifier)) {
|
|
59
|
+
const importedFile =
|
|
60
|
+
(yield* resolveModuleRequest({
|
|
61
|
+
request: specifier,
|
|
62
|
+
importingFile,
|
|
63
|
+
customConditions,
|
|
64
|
+
projectDirectory: packageDirectory,
|
|
65
|
+
}))?.file ?? path.resolve(path.dirname(importingFile), specifier);
|
|
66
|
+
importedPaths.push(packagePathOf(path, packageDirectory, importedFile));
|
|
67
|
+
}
|
|
64
68
|
}
|
|
65
|
-
|
|
66
|
-
|
|
69
|
+
return importedPaths;
|
|
70
|
+
});
|
|
71
|
+
const importedPaths = (yield* Effect.forEach(
|
|
72
|
+
yield* checkedSourceFiles(projectFile),
|
|
73
|
+
importedPathsOf,
|
|
74
|
+
{ concurrency: CONCURRENT_SOURCE_FILE_SCANS },
|
|
75
|
+
)).flat();
|
|
67
76
|
const ignoredFiles: string[] = [];
|
|
68
77
|
for (const ignoredPath of yield* ignoredPackagePathsAmong(importedPaths, packageDirectory)) {
|
|
69
78
|
const absolutePath = path.join(packageDirectory, ignoredPath);
|
|
@@ -33,11 +33,11 @@ const literalKeysOf = (node: Expression) =>
|
|
|
33
33
|
return [];
|
|
34
34
|
}
|
|
35
35
|
if (property.key.type === "Identifier") {
|
|
36
|
-
return [{ name: property.key.name, value: property.value }];
|
|
36
|
+
return [{ name: property.key.name, value: property.value, start: property.start }];
|
|
37
37
|
}
|
|
38
38
|
const literalKeyValue = property.key.type === "Literal" ? property.key.value : undefined;
|
|
39
39
|
return typeof literalKeyValue === "string"
|
|
40
|
-
? [{ name: literalKeyValue, value: property.value }]
|
|
40
|
+
? [{ name: literalKeyValue, value: property.value, start: property.start }]
|
|
41
41
|
: [];
|
|
42
42
|
})
|
|
43
43
|
: [];
|
|
@@ -47,14 +47,14 @@ const isLiteralObject = (node: Expression, isLiteralValue: (value: Expression) =
|
|
|
47
47
|
literalKeysOf(node).length === node.properties.length &&
|
|
48
48
|
literalKeysOf(node).every((key) => isLiteralValue(key.value));
|
|
49
49
|
|
|
50
|
-
const
|
|
51
|
-
isLiteralObject(node, (
|
|
50
|
+
const isLiteralStringObject = (node: Expression) =>
|
|
51
|
+
isLiteralObject(node, (value) => literalStringOf(value) !== undefined);
|
|
52
52
|
|
|
53
53
|
const isLiteralGrantList = (node: Expression) =>
|
|
54
54
|
node.type === "ArrayExpression" &&
|
|
55
55
|
node.elements.every((element) => {
|
|
56
|
-
const
|
|
57
|
-
return
|
|
56
|
+
const isStringObject = element?.type === "ObjectExpression" && isLiteralStringObject(element);
|
|
57
|
+
return isStringObject || literalStringOf(element) !== undefined;
|
|
58
58
|
});
|
|
59
59
|
|
|
60
60
|
const isLiteralLintConfigArgument = (node: Expression) =>
|
|
@@ -65,8 +65,8 @@ const literalGrantItemOf = (element: ArrayExpressionElement) => {
|
|
|
65
65
|
return [
|
|
66
66
|
Object.fromEntries(
|
|
67
67
|
literalKeysOf(element).flatMap(({ name, value }) => {
|
|
68
|
-
const
|
|
69
|
-
return
|
|
68
|
+
const literal = literalStringOf(value);
|
|
69
|
+
return literal === undefined ? [] : [[name, literal]];
|
|
70
70
|
}),
|
|
71
71
|
),
|
|
72
72
|
];
|
|
@@ -102,9 +102,11 @@ const objectsIn = (node: ArrayExpressionElement): readonly Expression[] => {
|
|
|
102
102
|
|
|
103
103
|
const repeatedKeysIn = (argument: Expression) =>
|
|
104
104
|
objectsIn(argument).flatMap((object) => {
|
|
105
|
-
const
|
|
106
|
-
const
|
|
107
|
-
return
|
|
105
|
+
const keys = literalKeysOf(object);
|
|
106
|
+
const names = keys.map(({ name }) => name);
|
|
107
|
+
return keys
|
|
108
|
+
.filter(({ name }, index) => names.indexOf(name, names.indexOf(name) + 1) === index)
|
|
109
|
+
.map(({ name, start }) => ({ key: name, start }));
|
|
108
110
|
});
|
|
109
111
|
|
|
110
112
|
export const lintConfigOf = (parsed: Effect.Success<ReturnType<typeof parsedConfigFileIn>>) => {
|
|
@@ -129,7 +131,7 @@ export const lintConfigOf = (parsed: Effect.Success<ReturnType<typeof parsedConf
|
|
|
129
131
|
};
|
|
130
132
|
}
|
|
131
133
|
const repeatedKeys = repeatedKeysIn(argument).map(
|
|
132
|
-
({
|
|
134
|
+
({ key, start }) => new LintConfigKeyRepeated({ location: lineOf(start), key }),
|
|
133
135
|
);
|
|
134
136
|
if (violations.length + repeatedKeys.length > 0) {
|
|
135
137
|
return { violations: [...violations, ...repeatedKeys] };
|
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
FORMAT_CONFIG_FILE,
|
|
8
8
|
LINT_CONFIG_FILE,
|
|
9
9
|
} from "../../../shared/config-file-names.ts";
|
|
10
|
-
import {
|
|
10
|
+
import { lineNumbersIn } from "./count-the-line-of-an-offset.ts";
|
|
11
11
|
import { runtimeModuleResolver } from "./create-the-module-resolver.ts";
|
|
12
12
|
import type { CONFIG_FILE_VIOLATION } from "./project-config-and-tool-errors.ts";
|
|
13
13
|
import {
|
|
@@ -23,6 +23,7 @@ import {
|
|
|
23
23
|
ModuleRequestUnresolvable,
|
|
24
24
|
} from "./project-config-and-tool-errors.ts";
|
|
25
25
|
import { namedPackageManifestAt } from "./read-named-package-manifests.ts";
|
|
26
|
+
import { realPathOf } from "./resolve-absolute-paths.ts";
|
|
26
27
|
|
|
27
28
|
export const LINT_CONFIG = {
|
|
28
29
|
file: LINT_CONFIG_FILE,
|
|
@@ -38,9 +39,6 @@ export const FORMAT_CONFIG = {
|
|
|
38
39
|
|
|
39
40
|
const INSTALLED_PACKAGES_DIRECTORY = "node_modules";
|
|
40
41
|
|
|
41
|
-
const realPathOf = (file: string) =>
|
|
42
|
-
FileSystem.FileSystem.use((fileSystem) => fileSystem.realPath(file));
|
|
43
|
-
|
|
44
42
|
const defaultExportOf = (config: typeof FORMAT_CONFIG | typeof LINT_CONFIG) =>
|
|
45
43
|
config.argumentShapes === undefined
|
|
46
44
|
? config.binding
|
|
@@ -184,7 +182,8 @@ export const parsedConfigFile = (
|
|
|
184
182
|
parsed.errors.map((error) => new ConfigFileUnparsable({ file, reason: error.message })),
|
|
185
183
|
);
|
|
186
184
|
}
|
|
187
|
-
const
|
|
185
|
+
const lineAt = lineNumbersIn(text);
|
|
186
|
+
const lineOf = (offset: number) => `${file}:${lineAt(offset)}`;
|
|
188
187
|
const { body } = parsed.program;
|
|
189
188
|
const exported = body.find((statement) => statement.type === "ExportDefaultDeclaration");
|
|
190
189
|
const bindingImport = body
|
|
@@ -245,9 +244,9 @@ const importViolationsOf = (
|
|
|
245
244
|
const projectDirectory = yield* realPathOf(directory);
|
|
246
245
|
const request = bindingImport.source.value;
|
|
247
246
|
const location = lineOf(bindingImport.start);
|
|
247
|
+
const resolver = yield* runtimeModuleResolver;
|
|
248
248
|
const resolved = yield* Effect.tryPromise({
|
|
249
|
-
try: () =>
|
|
250
|
-
runtimeModuleResolver().resolveFileAsync(path.join(projectDirectory, config.file), request),
|
|
249
|
+
try: () => resolver.resolveFileAsync(path.join(projectDirectory, config.file), request),
|
|
251
250
|
catch: (cause) =>
|
|
252
251
|
new ModuleRequestUnresolvable({ request, importingFile: location, reason: String(cause) }),
|
|
253
252
|
});
|
|
@@ -282,10 +282,10 @@ export class FormatInputsRefused extends Schema.TaggedError<FormatInputsRefused>
|
|
|
282
282
|
|
|
283
283
|
export class SourceFileUnparsable extends Schema.TaggedError<SourceFileUnparsable>()(
|
|
284
284
|
"SourceFileUnparsable",
|
|
285
|
-
{ file: Schema.String, reason: Schema.String },
|
|
285
|
+
{ file: Schema.String, line: Schema.optionalKey(Schema.Int), reason: Schema.String },
|
|
286
286
|
) {
|
|
287
287
|
public get location() {
|
|
288
|
-
return this.file
|
|
288
|
+
return this.line === undefined ? this.file : `${this.file}:${this.line}`;
|
|
289
289
|
}
|
|
290
290
|
public override get message() {
|
|
291
291
|
return `does not parse: ${this.reason}`;
|
|
@@ -345,6 +345,15 @@ export class ToolNotStarted extends Schema.TaggedError<ToolNotStarted>()("ToolNo
|
|
|
345
345
|
}
|
|
346
346
|
}
|
|
347
347
|
|
|
348
|
+
export class ToolNotStopped extends Schema.TaggedError<ToolNotStopped>()("ToolNotStopped", {
|
|
349
|
+
command: Schema.String,
|
|
350
|
+
reason: Schema.String,
|
|
351
|
+
}) {
|
|
352
|
+
public override get message() {
|
|
353
|
+
return `${this.command} could not be stopped: ${this.reason}`;
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
|
|
348
357
|
export class ToolStoppedBySignal extends Schema.TaggedError<ToolStoppedBySignal>()(
|
|
349
358
|
"ToolStoppedBySignal",
|
|
350
359
|
{ program: Schema.String, command: Schema.String, signal: Schema.String },
|
|
@@ -416,6 +425,13 @@ export const REQUIRED_VALUES_OF_OPTIONS_OFF_BY_DEFAULT = {
|
|
|
416
425
|
noCheck: false,
|
|
417
426
|
} as const;
|
|
418
427
|
|
|
428
|
+
export const BUILD_OUTPUT_OPTIONS = [
|
|
429
|
+
"outDir",
|
|
430
|
+
"declaration",
|
|
431
|
+
"declarationDir",
|
|
432
|
+
"emitDeclarationOnly",
|
|
433
|
+
] as const;
|
|
434
|
+
|
|
419
435
|
export const OPTIONS_TSC_LEAVES_UNSET: ReadonlySet<string> = new Set([
|
|
420
436
|
"allowUnreachableCode",
|
|
421
437
|
"allowUnusedLabels",
|
|
@@ -428,6 +444,8 @@ export class LooseCompilerOption extends Schema.TaggedError<LooseCompilerOption>
|
|
|
428
444
|
option: Schema.Literals([
|
|
429
445
|
...STRICT_OPTIONS,
|
|
430
446
|
...Record.keys(REQUIRED_VALUES_OF_OPTIONS_OFF_BY_DEFAULT),
|
|
447
|
+
"noEmit",
|
|
448
|
+
"emitDeclarationOnly",
|
|
431
449
|
]),
|
|
432
450
|
resolvedValue: Schema.optionalKey(Schema.Boolean),
|
|
433
451
|
},
|
|
@@ -442,6 +460,18 @@ export class LooseCompilerOption extends Schema.TaggedError<LooseCompilerOption>
|
|
|
442
460
|
}
|
|
443
461
|
}
|
|
444
462
|
|
|
463
|
+
export class BuildOutputCompilerOption extends Schema.TaggedError<BuildOutputCompilerOption>()(
|
|
464
|
+
"BuildOutputCompilerOption",
|
|
465
|
+
{ projectFile: Schema.String, option: Schema.Literals(BUILD_OUTPUT_OPTIONS) },
|
|
466
|
+
) {
|
|
467
|
+
public get location() {
|
|
468
|
+
return this.projectFile;
|
|
469
|
+
}
|
|
470
|
+
public override get message() {
|
|
471
|
+
return `${this.option} is set, but the package ships its TypeScript source and builds nothing`;
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
|
|
445
475
|
export class ProjectReferencesUndecodable extends Schema.TaggedError<ProjectReferencesUndecodable>()(
|
|
446
476
|
"ProjectReferencesUndecodable",
|
|
447
477
|
{ projectFile: Schema.String, reason: Schema.String },
|
|
@@ -454,6 +484,18 @@ export class ProjectReferencesUndecodable extends Schema.TaggedError<ProjectRefe
|
|
|
454
484
|
}
|
|
455
485
|
}
|
|
456
486
|
|
|
487
|
+
export class AbsoluteProjectReference extends Schema.TaggedError<AbsoluteProjectReference>()(
|
|
488
|
+
"AbsoluteProjectReference",
|
|
489
|
+
{ projectFile: Schema.String, reference: Schema.String },
|
|
490
|
+
) {
|
|
491
|
+
public get location() {
|
|
492
|
+
return this.projectFile;
|
|
493
|
+
}
|
|
494
|
+
public override get message() {
|
|
495
|
+
return `references ${this.reference} by an absolute path`;
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
|
|
457
499
|
export class TypeScriptConfigUnparsable extends Schema.TaggedError<TypeScriptConfigUnparsable>()(
|
|
458
500
|
"TypeScriptConfigUnparsable",
|
|
459
501
|
{ projectFile: Schema.String, reason: Schema.String },
|
|
@@ -474,7 +516,9 @@ export class TypeScriptConfigViolations extends Schema.TaggedError<TypeScriptCon
|
|
|
474
516
|
TypeScriptProjectFileMissing,
|
|
475
517
|
TypeScriptConfigUnparsable,
|
|
476
518
|
ProjectReferencesUndecodable,
|
|
519
|
+
AbsoluteProjectReference,
|
|
477
520
|
LooseCompilerOption,
|
|
521
|
+
BuildOutputCompilerOption,
|
|
478
522
|
]),
|
|
479
523
|
),
|
|
480
524
|
},
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Layer } from "effect";
|
|
2
|
+
|
|
3
|
+
import { ModuleResolversLive } from "./create-the-module-resolver.ts";
|
|
4
|
+
import { TypeScriptProjectListingsLive } from "./query-the-typescript-project.ts";
|
|
5
|
+
import { ModuleResolutionsLive } from "./resolve-module-requests.ts";
|
|
6
|
+
|
|
7
|
+
export const ProjectQueryCachesLive = Layer.mergeAll(
|
|
8
|
+
ModuleResolversLive,
|
|
9
|
+
ModuleResolutionsLive,
|
|
10
|
+
TypeScriptProjectListingsLive,
|
|
11
|
+
);
|