@sshkeda/check 0.0.0-stage → 1.0.1
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 +848 -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,82 @@
|
|
|
1
|
+
import {
|
|
2
|
+
fileNameOf,
|
|
3
|
+
isEntryFileName,
|
|
4
|
+
LAYOUT_DIRECTORY_NAMES,
|
|
5
|
+
LIBRARY_DIRECTORY_NAME,
|
|
6
|
+
} from "../../../../../shared/match-file-names-and-path-prefixes.ts";
|
|
7
|
+
import { SOURCE_DIRECTORY, TEST_DIRECTORY } from "../../../../../shared/test-home-directories.ts";
|
|
8
|
+
import { directoryOf, enclosingDirectoriesOf } from "../../../shared/classify-files-by-role.ts";
|
|
9
|
+
import {
|
|
10
|
+
DirectoryOutsideModuleLayout,
|
|
11
|
+
FileInLibraryDirectory,
|
|
12
|
+
ModuleWithLayoutDirectoryName,
|
|
13
|
+
ModuleWithoutIndex,
|
|
14
|
+
} from "./file-layout-errors.ts";
|
|
15
|
+
|
|
16
|
+
export const isModuleDirectory = (directory: string): boolean => {
|
|
17
|
+
const parent = directoryOf(directory);
|
|
18
|
+
return (
|
|
19
|
+
directory === SOURCE_DIRECTORY ||
|
|
20
|
+
directory === TEST_DIRECTORY ||
|
|
21
|
+
(fileNameOf(parent) === LIBRARY_DIRECTORY_NAME && isModuleDirectory(directoryOf(parent)))
|
|
22
|
+
);
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export const isLibraryDirectoryOfAModule = (directory: string) =>
|
|
26
|
+
fileNameOf(directory) === LIBRARY_DIRECTORY_NAME && isModuleDirectory(directoryOf(directory));
|
|
27
|
+
|
|
28
|
+
const MODULE_SUBDIRECTORY_NAMES: ReadonlySet<string> = new Set([
|
|
29
|
+
...LAYOUT_DIRECTORY_NAMES,
|
|
30
|
+
LIBRARY_DIRECTORY_NAME,
|
|
31
|
+
]);
|
|
32
|
+
|
|
33
|
+
const isOutsideModuleLayout = (directory: string) =>
|
|
34
|
+
isModuleDirectory(directoryOf(directory)) &&
|
|
35
|
+
!MODULE_SUBDIRECTORY_NAMES.has(fileNameOf(directory));
|
|
36
|
+
|
|
37
|
+
export const directoriesOutsideModuleLayoutAmong = (paths: readonly string[]) => [
|
|
38
|
+
...new Set(
|
|
39
|
+
paths
|
|
40
|
+
.flatMap((path) => enclosingDirectoriesOf(path))
|
|
41
|
+
.filter((directory) => isOutsideModuleLayout(directory)),
|
|
42
|
+
),
|
|
43
|
+
];
|
|
44
|
+
|
|
45
|
+
export const moduleLayoutViolations = (paths: readonly string[]) => {
|
|
46
|
+
const directories = [...new Set(paths.flatMap((path) => enclosingDirectoriesOf(path)))];
|
|
47
|
+
const indexedDirectories = new Set(
|
|
48
|
+
paths.filter((path) => isEntryFileName(fileNameOf(path))).map((path) => directoryOf(path)),
|
|
49
|
+
);
|
|
50
|
+
return [
|
|
51
|
+
...directoriesOutsideModuleLayoutAmong(paths).map(
|
|
52
|
+
(directory) =>
|
|
53
|
+
new DirectoryOutsideModuleLayout({ location: directory, module: directoryOf(directory) }),
|
|
54
|
+
),
|
|
55
|
+
...directories
|
|
56
|
+
.filter(
|
|
57
|
+
(directory) =>
|
|
58
|
+
isLibraryDirectoryOfAModule(directoryOf(directory)) && !indexedDirectories.has(directory),
|
|
59
|
+
)
|
|
60
|
+
.map((directory) => new ModuleWithoutIndex({ location: directory })),
|
|
61
|
+
...paths
|
|
62
|
+
.filter((path) => isLibraryDirectoryOfAModule(directoryOf(path)))
|
|
63
|
+
.map((path) => new FileInLibraryDirectory({ location: path })),
|
|
64
|
+
];
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
export const modulesWithLayoutDirectoryNamesAmong = (paths: readonly string[]) => [
|
|
68
|
+
...new Set(
|
|
69
|
+
paths
|
|
70
|
+
.flatMap((path) => enclosingDirectoriesOf(path))
|
|
71
|
+
.filter(
|
|
72
|
+
(directory) =>
|
|
73
|
+
isLibraryDirectoryOfAModule(directoryOf(directory)) &&
|
|
74
|
+
MODULE_SUBDIRECTORY_NAMES.has(fileNameOf(directory)),
|
|
75
|
+
),
|
|
76
|
+
),
|
|
77
|
+
];
|
|
78
|
+
|
|
79
|
+
export const moduleWithLayoutDirectoryNameViolations = (paths: readonly string[]) =>
|
|
80
|
+
modulesWithLayoutDirectoryNamesAmong(paths).map(
|
|
81
|
+
(directory) => new ModuleWithLayoutDirectoryName({ location: directory }),
|
|
82
|
+
);
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import { Effect, FileSystem } from "effect";
|
|
2
|
+
import { parseSync, Visitor } from "oxc-parser";
|
|
3
|
+
import type { ExportSpecifier, Expression, ParseResult } from "oxc-parser";
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
TASK_MAIN_MEMBER,
|
|
7
|
+
TASK_MAKE_MEMBER,
|
|
8
|
+
TASK_PACKAGE,
|
|
9
|
+
} from "../../../../../shared/bans-each-permission-lifts.ts";
|
|
10
|
+
import {
|
|
11
|
+
directoryOf,
|
|
12
|
+
isRootSupportFile,
|
|
13
|
+
isScript,
|
|
14
|
+
isTopLevelScript,
|
|
15
|
+
} from "../../../shared/classify-files-by-role.ts";
|
|
16
|
+
import { resolveModuleRequest } from "../../../shared/resolve-module-requests.ts";
|
|
17
|
+
|
|
18
|
+
const exportNameOf = (name: ExportSpecifier["local"]) =>
|
|
19
|
+
name.type === "Identifier" ? name.name : name.value;
|
|
20
|
+
|
|
21
|
+
const candidateImportRoots = (parsed: ParseResult) => {
|
|
22
|
+
const names = new Set<string>();
|
|
23
|
+
const remember = (expression: Expression) => {
|
|
24
|
+
if (expression.type === "Identifier") {
|
|
25
|
+
names.add(expression.name);
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
const isTaskMember =
|
|
29
|
+
expression.type === "MemberExpression" &&
|
|
30
|
+
!expression.computed &&
|
|
31
|
+
expression.property.type === "Identifier" &&
|
|
32
|
+
[TASK_MAKE_MEMBER, TASK_MAIN_MEMBER].includes(expression.property.name);
|
|
33
|
+
if (!isTaskMember) {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
const { object } = expression;
|
|
37
|
+
const root = object.type === "MemberExpression" ? object.object : object;
|
|
38
|
+
if (root.type === "Identifier") {
|
|
39
|
+
names.add(root.name);
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
new Visitor({
|
|
43
|
+
CallExpression(node) {
|
|
44
|
+
remember(node.callee);
|
|
45
|
+
},
|
|
46
|
+
VariableDeclarator({ init: initializer }) {
|
|
47
|
+
if (initializer !== null) {
|
|
48
|
+
remember(initializer);
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
}).visit(parsed.program);
|
|
52
|
+
return names;
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
export const taskImportsIn = (file: string, text: string, directory: string) =>
|
|
56
|
+
Effect.gen(function* () {
|
|
57
|
+
const fileSystem = yield* FileSystem.FileSystem;
|
|
58
|
+
const projectRoot = yield* fileSystem.realPath(directory);
|
|
59
|
+
const taskExportFrom = (
|
|
60
|
+
importingFile: string,
|
|
61
|
+
request: string,
|
|
62
|
+
members: readonly string[],
|
|
63
|
+
seen: ReadonlySet<string> = new Set(),
|
|
64
|
+
): Effect.Effect<
|
|
65
|
+
readonly string[] | undefined,
|
|
66
|
+
| Effect.Error<ReturnType<typeof fileSystem.readFileString>>
|
|
67
|
+
| Effect.Error<ReturnType<typeof resolveModuleRequest>>,
|
|
68
|
+
Effect.Services<ReturnType<typeof resolveModuleRequest>>
|
|
69
|
+
> =>
|
|
70
|
+
Effect.gen(function* () {
|
|
71
|
+
if (request === TASK_PACKAGE) {
|
|
72
|
+
return members;
|
|
73
|
+
}
|
|
74
|
+
const target = yield* resolveModuleRequest({
|
|
75
|
+
importingFile,
|
|
76
|
+
request,
|
|
77
|
+
customConditions: [],
|
|
78
|
+
projectDirectory: directory,
|
|
79
|
+
});
|
|
80
|
+
if (target === undefined) {
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
const isTaskDependency =
|
|
84
|
+
target.packageName === TASK_PACKAGE && target.packageRoot !== projectRoot;
|
|
85
|
+
if (isTaskDependency) {
|
|
86
|
+
return members;
|
|
87
|
+
}
|
|
88
|
+
const key = `${target.file}\0${members.join(".")}`;
|
|
89
|
+
if (seen.has(key)) {
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
const followed = new Set([...seen, key]);
|
|
93
|
+
const parsed = parseSync(target.file, yield* fileSystem.readFileString(target.file));
|
|
94
|
+
const [name, ...rest] = members;
|
|
95
|
+
if (name === undefined) {
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
for (const statement of parsed.program.body) {
|
|
99
|
+
if (statement.type === "ExportNamedDeclaration") {
|
|
100
|
+
if (statement.exportKind === "type") {
|
|
101
|
+
continue;
|
|
102
|
+
}
|
|
103
|
+
const specifier = statement.specifiers.find(
|
|
104
|
+
(entry) => exportNameOf(entry.exported) === name && entry.exportKind !== "type",
|
|
105
|
+
);
|
|
106
|
+
if (specifier !== undefined) {
|
|
107
|
+
const localName = exportNameOf(specifier.local);
|
|
108
|
+
if (statement.source !== null) {
|
|
109
|
+
return yield* taskExportFrom(
|
|
110
|
+
target.file,
|
|
111
|
+
statement.source.value,
|
|
112
|
+
[localName, ...rest],
|
|
113
|
+
followed,
|
|
114
|
+
);
|
|
115
|
+
}
|
|
116
|
+
for (const declaration of parsed.module.staticImports) {
|
|
117
|
+
const binding = declaration.entries.find(
|
|
118
|
+
(entry) => !entry.isType && entry.localName.value === localName,
|
|
119
|
+
);
|
|
120
|
+
if (binding !== undefined) {
|
|
121
|
+
const importedMembers =
|
|
122
|
+
binding.importName.kind === "NamespaceObject"
|
|
123
|
+
? rest
|
|
124
|
+
: [binding.importName.name ?? "", ...rest];
|
|
125
|
+
return yield* taskExportFrom(
|
|
126
|
+
target.file,
|
|
127
|
+
declaration.moduleRequest.value,
|
|
128
|
+
importedMembers,
|
|
129
|
+
followed,
|
|
130
|
+
);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
const isValueStarExport =
|
|
136
|
+
statement.type === "ExportAllDeclaration" && statement.exportKind !== "type";
|
|
137
|
+
if (isValueStarExport) {
|
|
138
|
+
const exported =
|
|
139
|
+
statement.exported === null ? undefined : exportNameOf(statement.exported);
|
|
140
|
+
const forwardsName = exported === undefined || exported === name;
|
|
141
|
+
if (forwardsName) {
|
|
142
|
+
const found = yield* taskExportFrom(
|
|
143
|
+
target.file,
|
|
144
|
+
statement.source.value,
|
|
145
|
+
exported === undefined ? members : rest,
|
|
146
|
+
followed,
|
|
147
|
+
);
|
|
148
|
+
if (found !== undefined) {
|
|
149
|
+
return found;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
return yield* Effect.undefined;
|
|
155
|
+
});
|
|
156
|
+
const imports = new Map<string, readonly string[]>();
|
|
157
|
+
const parsed = parseSync(file, text);
|
|
158
|
+
const candidates = candidateImportRoots(parsed);
|
|
159
|
+
for (const declaration of parsed.module.staticImports) {
|
|
160
|
+
for (const entry of declaration.entries) {
|
|
161
|
+
const isCandidate = !entry.isType && candidates.has(entry.localName.value);
|
|
162
|
+
if (!isCandidate) {
|
|
163
|
+
continue;
|
|
164
|
+
}
|
|
165
|
+
const members =
|
|
166
|
+
entry.importName.kind === "NamespaceObject" ? [] : [entry.importName.name ?? ""];
|
|
167
|
+
const reference = yield* taskExportFrom(file, declaration.moduleRequest.value, members);
|
|
168
|
+
if (reference !== undefined) {
|
|
169
|
+
imports.set(entry.localName.value, reference);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
return imports;
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
export const isTaskLayoutFile = (file: string) =>
|
|
177
|
+
isScript(file) &&
|
|
178
|
+
(isTopLevelScript(file) || (directoryOf(file) === "" && !isRootSupportFile(file)));
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Schema } from "effect";
|
|
2
|
+
|
|
3
|
+
import { listedViolations } from "../../../../../shared/format-reported-failures.ts";
|
|
4
|
+
|
|
5
|
+
export class FileTypeNotGranted extends Schema.TaggedError<FileTypeNotGranted>()(
|
|
6
|
+
"FileTypeNotGranted",
|
|
7
|
+
{ location: Schema.String, fileType: Schema.String },
|
|
8
|
+
) {
|
|
9
|
+
public override get message() {
|
|
10
|
+
return `has file type ${this.fileType}, which is not allowed by default`;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export class FileTypeViolations extends Schema.TaggedError<FileTypeViolations>()(
|
|
15
|
+
"FileTypeViolations",
|
|
16
|
+
{ violations: Schema.Array(FileTypeNotGranted) },
|
|
17
|
+
) {
|
|
18
|
+
public override get message() {
|
|
19
|
+
return listedViolations(this.violations);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { Effect, Option } from "effect";
|
|
2
|
+
|
|
3
|
+
import { fileNameOf } from "../../../../../shared/match-file-names-and-path-prefixes.ts";
|
|
4
|
+
import {
|
|
5
|
+
FILE_TYPE,
|
|
6
|
+
GENERATED,
|
|
7
|
+
} from "../../../../../shared/record-and-grant-permissions-by-path.ts";
|
|
8
|
+
import type { PERMISSION_NAMES } from "../../../../../shared/record-and-grant-permissions-by-path.ts";
|
|
9
|
+
import { inEachPackage } from "../../../shared/check-each-nested-package.ts";
|
|
10
|
+
import { listedPackageFiles } from "../../../shared/list-package-files.ts";
|
|
11
|
+
import { loadedLintConfigIn } from "../../../shared/load-the-lint-config.ts";
|
|
12
|
+
import {
|
|
13
|
+
isGrantedPatchFile,
|
|
14
|
+
listedPatchesOf,
|
|
15
|
+
rootManifestIn,
|
|
16
|
+
} from "../../../shared/match-granted-patch-files.ts";
|
|
17
|
+
import { quietViolations } from "../../../shared/print-failures-and-keep-detail-in-the-trace.ts";
|
|
18
|
+
import { toolFileOf } from "../../../shared/tool-file-locations.ts";
|
|
19
|
+
import { FileTypeNotGranted, FileTypeViolations } from "./file-type-errors.ts";
|
|
20
|
+
|
|
21
|
+
const FILE_TYPES = "file-types";
|
|
22
|
+
const DEFAULT_EXTENSIONS = [".ts", ".tsx", ".md"] as const;
|
|
23
|
+
|
|
24
|
+
export const fileTypeViolations = (
|
|
25
|
+
paths: readonly string[],
|
|
26
|
+
grants: readonly {
|
|
27
|
+
readonly path: string;
|
|
28
|
+
readonly allow?: readonly (typeof PERMISSION_NAMES)[number][];
|
|
29
|
+
}[],
|
|
30
|
+
listedPatchPaths: ReadonlySet<string> = new Set(),
|
|
31
|
+
) =>
|
|
32
|
+
paths
|
|
33
|
+
.filter((path) => {
|
|
34
|
+
const allowedByDefault =
|
|
35
|
+
DEFAULT_EXTENSIONS.some((extension) => path.endsWith(extension)) ||
|
|
36
|
+
toolFileOf(path)?.allowsFileType === true;
|
|
37
|
+
const granted = grants.some(
|
|
38
|
+
(grant) =>
|
|
39
|
+
grant.path === path &&
|
|
40
|
+
grant.allow?.some(
|
|
41
|
+
(permission) => permission === FILE_TYPE || permission === GENERATED,
|
|
42
|
+
) === true,
|
|
43
|
+
);
|
|
44
|
+
const isListedGrantedPatch = listedPatchPaths.has(path) && isGrantedPatchFile(path, grants);
|
|
45
|
+
return !allowedByDefault && !granted && !isListedGrantedPatch;
|
|
46
|
+
})
|
|
47
|
+
.map(
|
|
48
|
+
(path) =>
|
|
49
|
+
new FileTypeNotGranted({
|
|
50
|
+
location: path,
|
|
51
|
+
fileType: /\.[^.]+$/u.exec(fileNameOf(path))?.[0] ?? fileNameOf(path),
|
|
52
|
+
}),
|
|
53
|
+
);
|
|
54
|
+
|
|
55
|
+
export const findFileTypeViolations = (directory: string) =>
|
|
56
|
+
Effect.gen(function* () {
|
|
57
|
+
const { packageFiles } = yield* listedPackageFiles(directory, []);
|
|
58
|
+
const grants = yield* loadedLintConfigIn(directory).pipe(
|
|
59
|
+
Effect.asSome,
|
|
60
|
+
Effect.catchTag("LintConfigRefused", () => Effect.succeedNone),
|
|
61
|
+
);
|
|
62
|
+
if (Option.isNone(grants)) {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
const listedPatchPaths = new Set(
|
|
66
|
+
listedPatchesOf(yield* rootManifestIn(directory, packageFiles)).map(
|
|
67
|
+
({ patchPath }) => patchPath,
|
|
68
|
+
),
|
|
69
|
+
);
|
|
70
|
+
const violations = fileTypeViolations(packageFiles, grants.value, listedPatchPaths);
|
|
71
|
+
if (violations.length > 0) {
|
|
72
|
+
return yield* new FileTypeViolations({ violations });
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
export const fileTypeViolationsOfEachPackage = inEachPackage(FILE_TYPES, ".", (packageDirectory) =>
|
|
77
|
+
findFileTypeViolations(packageDirectory).pipe(quietViolations(FILE_TYPES)),
|
|
78
|
+
);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { formatting } from "./internal/declare-the-formatting-task.ts";
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import { Array as Arrays, Effect, FileSystem, Path } from "effect";
|
|
2
|
+
|
|
3
|
+
import { FORMAT_CONFIG_FILE } from "../../../../../shared/config-file-names.ts";
|
|
4
|
+
import { printableError } from "../../../../../shared/format-reported-failures.ts";
|
|
5
|
+
import { enclosingDirectoriesOf } from "../../../shared/classify-files-by-role.ts";
|
|
6
|
+
import { encodeJson } from "../../../shared/encode-compact-json.ts";
|
|
7
|
+
import {
|
|
8
|
+
failQuietly,
|
|
9
|
+
quietViolations,
|
|
10
|
+
} from "../../../shared/print-failures-and-keep-detail-in-the-trace.ts";
|
|
11
|
+
import {
|
|
12
|
+
argumentsInRunsOfBoundedSize,
|
|
13
|
+
mergedExit,
|
|
14
|
+
runTool,
|
|
15
|
+
} from "../../../shared/run-tools-and-decode-their-reports.ts";
|
|
16
|
+
import { isSymbolicLink } from "./find-symbolic-links.ts";
|
|
17
|
+
import { UnformattedFile } from "./unformatted-file-errors.ts";
|
|
18
|
+
|
|
19
|
+
export const FORMATTED_PACKAGE_DIRECTORY = ".";
|
|
20
|
+
|
|
21
|
+
const BUN_FORMAT = "bun fmt";
|
|
22
|
+
|
|
23
|
+
const BUN_FORMAT_TASK = "bun-fmt";
|
|
24
|
+
|
|
25
|
+
const LISTED_FILE_SEPARATOR = "\n";
|
|
26
|
+
|
|
27
|
+
const BUN_FORMAT_ARGUMENTS = [
|
|
28
|
+
"fmt",
|
|
29
|
+
`--config=${FORMAT_CONFIG_FILE}`,
|
|
30
|
+
"--disable-nested-config",
|
|
31
|
+
"--list-different",
|
|
32
|
+
] as const;
|
|
33
|
+
|
|
34
|
+
const CONTROL_CHARACTER = /\p{Cc}/u;
|
|
35
|
+
|
|
36
|
+
const filesBunFormatFormatsAmong = (files: readonly string[]) =>
|
|
37
|
+
Effect.gen(function* () {
|
|
38
|
+
const fileSystem = yield* FileSystem.FileSystem;
|
|
39
|
+
const path = yield* Path.Path;
|
|
40
|
+
const onDisk = (file: string) => path.join(FORMATTED_PACKAGE_DIRECTORY, file);
|
|
41
|
+
const listed = files.filter((file) => file !== FORMAT_CONFIG_FILE);
|
|
42
|
+
const linkedDirectories = new Set(
|
|
43
|
+
yield* Effect.filter(
|
|
44
|
+
new Set(listed.flatMap((file) => enclosingDirectoriesOf(file))),
|
|
45
|
+
(directory) => isSymbolicLink(onDisk(directory)),
|
|
46
|
+
{ concurrency: "unbounded" },
|
|
47
|
+
),
|
|
48
|
+
);
|
|
49
|
+
const withNoLinkedDirectoryAbove = listed.filter(
|
|
50
|
+
(file) => !enclosingDirectoriesOf(file).some((directory) => linkedDirectories.has(directory)),
|
|
51
|
+
);
|
|
52
|
+
const isRegularFile = yield* Effect.forEach(
|
|
53
|
+
withNoLinkedDirectoryAbove,
|
|
54
|
+
(file) =>
|
|
55
|
+
Effect.gen(function* () {
|
|
56
|
+
if (linkedDirectories.has(file)) {
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
59
|
+
if (yield* isSymbolicLink(onDisk(file))) {
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
62
|
+
return (yield* fileSystem.stat(onDisk(file))).type === "File";
|
|
63
|
+
}),
|
|
64
|
+
{ concurrency: "unbounded" },
|
|
65
|
+
);
|
|
66
|
+
return withNoLinkedDirectoryAbove.filter((_file, index) => isRegularFile[index] === true);
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
const isPrintedOnOneLine = (file: string) => !file.includes(LISTED_FILE_SEPARATOR);
|
|
70
|
+
|
|
71
|
+
const outputBeforeItsEndingNewline = (standardOutput: string) =>
|
|
72
|
+
standardOutput.endsWith(LISTED_FILE_SEPARATOR)
|
|
73
|
+
? standardOutput.slice(0, -LISTED_FILE_SEPARATOR.length)
|
|
74
|
+
: standardOutput;
|
|
75
|
+
|
|
76
|
+
const listedLinesOf = (standardOutput: string) => {
|
|
77
|
+
const output = outputBeforeItsEndingNewline(standardOutput);
|
|
78
|
+
return output === "" ? [] : output.split(LISTED_FILE_SEPARATOR);
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
const filesListedInARunOfOneFileNotPrintedOnOneLine = (file: string, standardOutput: string) =>
|
|
82
|
+
[FORMAT_CONFIG_FILE, file].filter((listed) =>
|
|
83
|
+
listed === file
|
|
84
|
+
? standardOutput.includes(file)
|
|
85
|
+
: listedLinesOf(standardOutput).includes(FORMAT_CONFIG_FILE),
|
|
86
|
+
);
|
|
87
|
+
|
|
88
|
+
const formatArgumentOf = (file: string) => `./${file}`;
|
|
89
|
+
|
|
90
|
+
const ranBunFormat = (fileArguments: readonly string[]) =>
|
|
91
|
+
runTool(BUN_FORMAT, process.execPath, [
|
|
92
|
+
...BUN_FORMAT_ARGUMENTS,
|
|
93
|
+
formatArgumentOf(FORMAT_CONFIG_FILE),
|
|
94
|
+
...fileArguments,
|
|
95
|
+
]).pipe(
|
|
96
|
+
Effect.map(({ standardOutput }) => ({ exited: undefined, standardOutput })),
|
|
97
|
+
Effect.catchTag("ToolExited", (exited) =>
|
|
98
|
+
Effect.succeed({ exited, standardOutput: exited.standardOutput }),
|
|
99
|
+
),
|
|
100
|
+
);
|
|
101
|
+
|
|
102
|
+
const unformattedFileOf = (file: string) =>
|
|
103
|
+
Effect.gen(function* () {
|
|
104
|
+
const location = CONTROL_CHARACTER.test(file) ? yield* encodeJson(file) : file;
|
|
105
|
+
return printableError(new UnformattedFile({ file: location }));
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
const bunFormatReportOn = (packageFiles: readonly string[]) =>
|
|
109
|
+
Effect.gen(function* () {
|
|
110
|
+
const formatted = yield* filesBunFormatFormatsAmong(packageFiles);
|
|
111
|
+
const runs = [
|
|
112
|
+
...argumentsInRunsOfBoundedSize(
|
|
113
|
+
formatted.filter((file) => isPrintedOnOneLine(file)).map((file) => formatArgumentOf(file)),
|
|
114
|
+
).map((fileArguments) => ({
|
|
115
|
+
fileArguments,
|
|
116
|
+
listedIn: listedLinesOf,
|
|
117
|
+
})),
|
|
118
|
+
...formatted
|
|
119
|
+
.filter((file) => !isPrintedOnOneLine(file))
|
|
120
|
+
.map((file) => ({
|
|
121
|
+
fileArguments: [formatArgumentOf(file)],
|
|
122
|
+
listedIn: (standardOutput: string) =>
|
|
123
|
+
filesListedInARunOfOneFileNotPrintedOnOneLine(file, standardOutput),
|
|
124
|
+
})),
|
|
125
|
+
];
|
|
126
|
+
if (runs.length === 0) {
|
|
127
|
+
runs.push({ fileArguments: [], listedIn: listedLinesOf });
|
|
128
|
+
}
|
|
129
|
+
const ran = yield* Effect.forEach(runs, (run) =>
|
|
130
|
+
ranBunFormat(run.fileArguments).pipe(
|
|
131
|
+
Effect.map(({ exited, standardOutput }) => ({
|
|
132
|
+
exited,
|
|
133
|
+
listed: run.listedIn(standardOutput),
|
|
134
|
+
})),
|
|
135
|
+
),
|
|
136
|
+
);
|
|
137
|
+
const exits = ran.flatMap(({ exited }) => (exited === undefined ? [] : [exited]));
|
|
138
|
+
return {
|
|
139
|
+
unformatted: [...new Set(ran.flatMap(({ listed }) => listed))].toSorted(),
|
|
140
|
+
exited: Arrays.isReadonlyArrayNonEmpty(exits) ? mergedExit(exits) : undefined,
|
|
141
|
+
};
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
export const unformattedFilesAmong = (packageFiles: readonly string[]) =>
|
|
145
|
+
Effect.gen(function* () {
|
|
146
|
+
const report = yield* bunFormatReportOn(packageFiles).pipe(quietViolations(BUN_FORMAT_TASK));
|
|
147
|
+
if (report.exited !== undefined) {
|
|
148
|
+
return yield* failQuietly(
|
|
149
|
+
BUN_FORMAT_TASK,
|
|
150
|
+
report.exited,
|
|
151
|
+
Arrays.append(
|
|
152
|
+
yield* Effect.forEach(report.unformatted, unformattedFileOf),
|
|
153
|
+
printableError(report.exited),
|
|
154
|
+
),
|
|
155
|
+
);
|
|
156
|
+
}
|
|
157
|
+
});
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { Task } from "@sshkeda/task";
|
|
2
|
+
import { Effect, Path } from "effect";
|
|
3
|
+
|
|
4
|
+
import { inEachPackage, packageDirectoriesIn } from "../../../shared/check-each-nested-package.ts";
|
|
5
|
+
import { ownedFilesAmong } from "../../../shared/list-owned-files.ts";
|
|
6
|
+
import { listedPackageFiles } from "../../../shared/list-package-files.ts";
|
|
7
|
+
import { quietViolations } from "../../../shared/print-failures-and-keep-detail-in-the-trace.ts";
|
|
8
|
+
import {
|
|
9
|
+
FORMATTED_PACKAGE_DIRECTORY,
|
|
10
|
+
unformattedFilesAmong,
|
|
11
|
+
} from "./check-formatting-with-bun-fmt.ts";
|
|
12
|
+
import { checkedFormatConfigIn } from "./find-format-config-violations.ts";
|
|
13
|
+
import { checkedFormatInputsIn } from "./find-format-input-violations.ts";
|
|
14
|
+
|
|
15
|
+
const ownedFilesOfPackage = (packageDirectory: string) =>
|
|
16
|
+
Effect.gen(function* () {
|
|
17
|
+
const path = yield* Path.Path;
|
|
18
|
+
const directory = path.join(FORMATTED_PACKAGE_DIRECTORY, packageDirectory);
|
|
19
|
+
const { packageFiles } = yield* listedPackageFiles(directory, []);
|
|
20
|
+
return { directory, files: yield* ownedFilesAmong(directory, packageFiles) };
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
const formatterFiles = Task.make(
|
|
24
|
+
"formatter-files",
|
|
25
|
+
Effect.gen(function* () {
|
|
26
|
+
const path = yield* Path.Path;
|
|
27
|
+
const filesOfEachPackage = yield* Effect.forEach(
|
|
28
|
+
yield* packageDirectoriesIn(FORMATTED_PACKAGE_DIRECTORY),
|
|
29
|
+
ownedFilesOfPackage,
|
|
30
|
+
{ concurrency: "unbounded" },
|
|
31
|
+
);
|
|
32
|
+
return {
|
|
33
|
+
filesOfEachPackage,
|
|
34
|
+
packageFiles: filesOfEachPackage
|
|
35
|
+
.flatMap(({ directory, files }) => files.map((file) => path.join(directory, file)))
|
|
36
|
+
.toSorted(),
|
|
37
|
+
};
|
|
38
|
+
}).pipe(quietViolations("formatter-files")),
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
const formatInputs = Task.make(
|
|
42
|
+
"format-inputs",
|
|
43
|
+
Effect.flatMap(formatterFiles, ({ filesOfEachPackage }) =>
|
|
44
|
+
inEachPackage("format-inputs", FORMATTED_PACKAGE_DIRECTORY, (packageDirectory) =>
|
|
45
|
+
checkedFormatInputsIn(
|
|
46
|
+
packageDirectory,
|
|
47
|
+
filesOfEachPackage.find(({ directory }) => directory === packageDirectory)?.files ?? [],
|
|
48
|
+
).pipe(quietViolations("format-inputs")),
|
|
49
|
+
),
|
|
50
|
+
),
|
|
51
|
+
);
|
|
52
|
+
|
|
53
|
+
const unformattedFiles = Task.make(
|
|
54
|
+
"bun-fmt",
|
|
55
|
+
Effect.andThen(
|
|
56
|
+
inEachPackage("bun-fmt", FORMATTED_PACKAGE_DIRECTORY, (packageDirectory) =>
|
|
57
|
+
checkedFormatConfigIn(packageDirectory).pipe(quietViolations("bun-fmt")),
|
|
58
|
+
),
|
|
59
|
+
Effect.flatMap(formatterFiles, ({ packageFiles }) => unformattedFilesAmong(packageFiles)),
|
|
60
|
+
),
|
|
61
|
+
);
|
|
62
|
+
|
|
63
|
+
export const formatting = Task.make(
|
|
64
|
+
"formatting",
|
|
65
|
+
Task.allSettled([formatInputs, unformattedFiles]),
|
|
66
|
+
);
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Effect, Result } from "effect";
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
FORMAT_CONFIG,
|
|
5
|
+
parsedConfigFileIn,
|
|
6
|
+
} from "../../../shared/parse-config-files-that-import-from-check.ts";
|
|
7
|
+
import { FormatConfigRefused } from "../../../shared/project-config-and-tool-errors.ts";
|
|
8
|
+
|
|
9
|
+
export const checkedFormatConfigIn = (directory: string) =>
|
|
10
|
+
Effect.gen(function* () {
|
|
11
|
+
const parsed = yield* parsedConfigFileIn(directory, FORMAT_CONFIG);
|
|
12
|
+
const violations = Result.isFailure(parsed) ? parsed.failure : parsed.success.violations;
|
|
13
|
+
if (violations.length > 0) {
|
|
14
|
+
return yield* new FormatConfigRefused({ violations });
|
|
15
|
+
}
|
|
16
|
+
});
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { Effect, FileSystem, Path, Predicate, Result } from "effect";
|
|
2
|
+
|
|
3
|
+
import { FORMAT_CONFIG_FILE } from "../../../../../shared/config-file-names.ts";
|
|
4
|
+
import { fileNameOf } from "../../../../../shared/match-file-names-and-path-prefixes.ts";
|
|
5
|
+
import { PACKAGE_MANIFEST_FILE } from "../../../shared/find-named-package-manifests.ts";
|
|
6
|
+
import {
|
|
7
|
+
CompetingFormatterConfig,
|
|
8
|
+
FormatInputsRefused,
|
|
9
|
+
PackagePrettierField,
|
|
10
|
+
} from "../../../shared/project-config-and-tool-errors.ts";
|
|
11
|
+
import { packageManifestObject } from "../../../shared/read-package-manifest-object.ts";
|
|
12
|
+
|
|
13
|
+
const PRETTIER_IGNORE_FILE = ".prettierignore";
|
|
14
|
+
|
|
15
|
+
const COMPETING_FORMATTER_CONFIG_NAMES = [
|
|
16
|
+
".oxfmtrc*",
|
|
17
|
+
"oxfmt.config.*",
|
|
18
|
+
".prettierrc*",
|
|
19
|
+
"prettier.config.*",
|
|
20
|
+
PRETTIER_IGNORE_FILE,
|
|
21
|
+
];
|
|
22
|
+
|
|
23
|
+
const COMPETING_FORMATTER_CONFIG_GLOBS = COMPETING_FORMATTER_CONFIG_NAMES.map(
|
|
24
|
+
(nameGlob) => new Bun.Glob(nameGlob),
|
|
25
|
+
);
|
|
26
|
+
|
|
27
|
+
const isCompetingFormatterConfig = (file: string) =>
|
|
28
|
+
file !== FORMAT_CONFIG_FILE &&
|
|
29
|
+
COMPETING_FORMATTER_CONFIG_GLOBS.some((nameGlob) => nameGlob.match(fileNameOf(file)));
|
|
30
|
+
|
|
31
|
+
const prettierFieldViolationsIn = (directory: string, manifests: readonly string[]) =>
|
|
32
|
+
Effect.forEach(manifests, (manifest) =>
|
|
33
|
+
Effect.gen(function* () {
|
|
34
|
+
const fileSystem = yield* FileSystem.FileSystem;
|
|
35
|
+
const path = yield* Path.Path;
|
|
36
|
+
const parsed = packageManifestObject(
|
|
37
|
+
manifest,
|
|
38
|
+
yield* fileSystem.readFileString(path.join(directory, manifest)),
|
|
39
|
+
);
|
|
40
|
+
if (Result.isFailure(parsed)) {
|
|
41
|
+
return [parsed.failure];
|
|
42
|
+
}
|
|
43
|
+
return Predicate.hasProperty(parsed.success, "prettier")
|
|
44
|
+
? [new PackagePrettierField({ location: manifest })]
|
|
45
|
+
: [];
|
|
46
|
+
}),
|
|
47
|
+
).pipe(Effect.map((violations) => violations.flat()));
|
|
48
|
+
|
|
49
|
+
export const checkedFormatInputsIn = (directory: string, packageFiles: readonly string[]) =>
|
|
50
|
+
Effect.gen(function* () {
|
|
51
|
+
const fileSystem = yield* FileSystem.FileSystem;
|
|
52
|
+
const path = yield* Path.Path;
|
|
53
|
+
const competingConfigs = new Set([
|
|
54
|
+
...packageFiles.filter((file) => isCompetingFormatterConfig(file)),
|
|
55
|
+
...(yield* fileSystem.glob(`{${COMPETING_FORMATTER_CONFIG_NAMES.join(",")}}`, {
|
|
56
|
+
root: directory,
|
|
57
|
+
})).filter((file) => file !== FORMAT_CONFIG_FILE),
|
|
58
|
+
...((yield* fileSystem.exists(path.join(directory, PRETTIER_IGNORE_FILE)))
|
|
59
|
+
? [PRETTIER_IGNORE_FILE]
|
|
60
|
+
: []),
|
|
61
|
+
]);
|
|
62
|
+
const violations = [
|
|
63
|
+
...[...competingConfigs]
|
|
64
|
+
.toSorted()
|
|
65
|
+
.map((location) => new CompetingFormatterConfig({ location })),
|
|
66
|
+
...(yield* prettierFieldViolationsIn(
|
|
67
|
+
directory,
|
|
68
|
+
packageFiles.filter((file) => fileNameOf(file) === PACKAGE_MANIFEST_FILE),
|
|
69
|
+
)),
|
|
70
|
+
];
|
|
71
|
+
if (violations.length > 0) {
|
|
72
|
+
return yield* new FormatInputsRefused({ violations });
|
|
73
|
+
}
|
|
74
|
+
});
|