@sshkeda/check 0.0.0-stage → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +156 -2
- package/docs/how-to-make-check-pass.md +71 -0
- package/package.json +51 -4
- package/src/index.ts +8 -0
- package/src/internal/ban-abbreviated-words-in-declared-names.ts +165 -0
- package/src/internal/ban-checked-members-outside-calls.ts +151 -0
- package/src/internal/ban-comments.ts +23 -0
- package/src/internal/ban-comparing-or-switching-on-tag.ts +114 -0
- package/src/internal/ban-deadlines-inside-tests.ts +41 -0
- package/src/internal/ban-declared-values.ts +70 -0
- package/src/internal/ban-dropped-failures-detached-fibers-sleeps-and-untraced-functions.ts +67 -0
- package/src/internal/ban-failures-collected-as-results.ts +57 -0
- package/src/internal/ban-fallbacks-of-named-recoveries.ts +118 -0
- package/src/internal/ban-function-overloads.ts +107 -0
- package/src/internal/ban-global-error-in-failure-types.ts +146 -0
- package/src/internal/ban-instanceof-in-effect-recovery-callbacks.ts +63 -0
- package/src/internal/ban-let-and-effect-mutable-ref.ts +79 -0
- package/src/internal/ban-logic-in-index-files.ts +178 -0
- package/src/internal/ban-namespaces-used-without-a-member.ts +176 -0
- package/src/internal/ban-node-builtins-that-effect-replaces.ts +42 -0
- package/src/internal/ban-parsing-outside-data-without-a-schema.ts +299 -0
- package/src/internal/ban-re-exports.ts +172 -0
- package/src/internal/ban-reading-the-clock-and-sleeping-outside-effect.ts +239 -0
- package/src/internal/ban-retired-words-in-names.ts +49 -0
- package/src/internal/ban-scanning-directories-with-bun-glob.ts +79 -0
- package/src/internal/ban-shebang-lines.ts +26 -0
- package/src/internal/ban-timer-globals-and-the-global-object.ts +34 -0
- package/src/internal/ban-timer-schedules-without-deadlines.ts +240 -0
- package/src/internal/ban-type-and-interface-declarations.ts +48 -0
- package/src/internal/ban-type-predicates.ts +82 -0
- package/src/internal/ban-unknown-in-function-signatures.ts +143 -0
- package/src/internal/ban-vague-error-class-names.ts +28 -0
- package/src/internal/ban-vague-file-names.ts +51 -0
- package/src/internal/ban-what-a-file-is-not-granted.ts +512 -0
- package/src/internal/ban-while-do-while-and-for-loops.ts +27 -0
- package/src/internal/confine-service-declarations-to-granted-files.ts +116 -0
- package/src/internal/confine-the-stdio-service-to-terminal-output.ts +190 -0
- package/src/internal/define-the-lint-plugin-and-configs.ts +361 -0
- package/src/internal/describe-and-decode-rule-options.ts +22 -0
- package/src/internal/keep-assertions-in-the-test-home-and-ban-test-runners.ts +128 -0
- package/src/internal/keep-effect-testing-helpers-in-test-files.ts +157 -0
- package/src/internal/match-banned-modules-and-globals.ts +71 -0
- package/src/internal/match-effect-service-factories.ts +20 -0
- package/src/internal/require-a-named-const-for-compound-conditions.ts +44 -0
- package/src/internal/require-capital-snake-case-and-as-const-on-literal-constants.ts +141 -0
- package/src/internal/require-service-keys-to-end-with-their-class-name.ts +64 -0
- package/src/internal/resolve-what-an-expression-imports.ts +295 -0
- package/src/internal/sort-type-constituents.ts +82 -0
- package/src/internal/split-names-into-words.ts +12 -0
- package/src/internal/visit-every-declared-name.ts +264 -0
- package/src/lib/tasks/index.ts +1 -0
- package/src/lib/tasks/internal/declare-the-check-task.ts +29 -0
- package/src/lib/tasks/internal/declare-the-checker-queries-task.ts +41 -0
- package/src/lib/tasks/internal/declare-the-typed-checks-task.ts +25 -0
- package/src/lib/tasks/internal/run-checks-over-one-typescript-project.ts +68 -0
- package/src/lib/tasks/lib/check-effect-diagnostics-with-effect-tsgo/index.ts +15 -0
- package/src/lib/tasks/lib/check-effect-diagnostics-with-effect-tsgo/internal/check-effect-diagnostics-with-effect-tsgo.ts +211 -0
- package/src/lib/tasks/lib/check-effect-diagnostics-with-effect-tsgo/internal/read-effect-tsgo-json-report.ts +39 -0
- package/src/lib/tasks/lib/check-import-boundaries/index.ts +1 -0
- package/src/lib/tasks/lib/check-import-boundaries/internal/find-import-boundary-violations.ts +415 -0
- package/src/lib/tasks/lib/check-import-boundaries/internal/find-subpath-import-targets.ts +117 -0
- package/src/lib/tasks/lib/check-import-boundaries/internal/find-what-hides-an-import.ts +65 -0
- package/src/lib/tasks/lib/check-import-boundaries/internal/import-boundary-errors.ts +176 -0
- package/src/lib/tasks/lib/check-uses-by-their-declarations/index.ts +1 -0
- package/src/lib/tasks/lib/check-uses-by-their-declarations/internal/declared-use-errors.ts +32 -0
- package/src/lib/tasks/lib/check-uses-by-their-declarations/internal/find-declared-use-violations.ts +38 -0
- package/src/lib/tasks/lib/check-uses-by-their-declarations/internal/find-sync-calls.ts +23 -0
- package/src/lib/tasks/lib/check-uses-by-their-declarations/internal/find-type-only-schemas.ts +375 -0
- package/src/lib/tasks/lib/confine-layer-provides-to-program-starts/index.ts +1 -0
- package/src/lib/tasks/lib/confine-layer-provides-to-program-starts/internal/find-layer-provides-outside-program-starts.ts +648 -0
- package/src/lib/tasks/lib/confine-layer-provides-to-program-starts/internal/layer-provide-errors.ts +27 -0
- package/src/lib/tasks/lib/confine-layer-provides-to-program-starts/internal/resolve-imported-package-apis.ts +262 -0
- package/src/lib/tasks/lib/confine-stdio-to-granted-files/index.ts +1 -0
- package/src/lib/tasks/lib/confine-stdio-to-granted-files/internal/find-ungranted-stdio-uses.ts +219 -0
- package/src/lib/tasks/lib/confine-stdio-to-granted-files/internal/stdio-use-errors.ts +31 -0
- package/src/lib/tasks/lib/detect-inferrable-annotations/index.ts +1 -0
- package/src/lib/tasks/lib/detect-inferrable-annotations/internal/find-inferrable-annotations.ts +357 -0
- package/src/lib/tasks/lib/detect-inferrable-annotations/internal/inferrable-annotation-errors.ts +33 -0
- package/src/lib/tasks/lib/detect-repeated-service-yields/index.ts +1 -0
- package/src/lib/tasks/lib/detect-repeated-service-yields/internal/find-repeated-service-yields.ts +162 -0
- package/src/lib/tasks/lib/detect-repeated-service-yields/internal/repeated-service-yield-errors.ts +25 -0
- package/src/lib/tasks/lib/enforce-file-layout/index.ts +5 -0
- package/src/lib/tasks/lib/enforce-file-layout/internal/check-the-layout-of-each-package.ts +9 -0
- package/src/lib/tasks/lib/enforce-file-layout/internal/file-layout-errors.ts +417 -0
- package/src/lib/tasks/lib/enforce-file-layout/internal/find-export-path-mismatches.ts +83 -0
- package/src/lib/tasks/lib/enforce-file-layout/internal/find-file-layout-violations.ts +827 -0
- package/src/lib/tasks/lib/enforce-file-layout/internal/find-module-layout-violations.ts +82 -0
- package/src/lib/tasks/lib/enforce-file-layout/internal/resolve-task-imports.ts +178 -0
- package/src/lib/tasks/lib/enforce-file-types/index.ts +5 -0
- package/src/lib/tasks/lib/enforce-file-types/internal/file-type-errors.ts +21 -0
- package/src/lib/tasks/lib/enforce-file-types/internal/find-file-type-violations.ts +78 -0
- package/src/lib/tasks/lib/format-with-bun-fmt/index.ts +1 -0
- package/src/lib/tasks/lib/format-with-bun-fmt/internal/check-formatting-with-bun-fmt.ts +157 -0
- package/src/lib/tasks/lib/format-with-bun-fmt/internal/declare-the-formatting-task.ts +66 -0
- package/src/lib/tasks/lib/format-with-bun-fmt/internal/find-format-config-violations.ts +16 -0
- package/src/lib/tasks/lib/format-with-bun-fmt/internal/find-format-input-violations.ts +74 -0
- package/src/lib/tasks/lib/format-with-bun-fmt/internal/find-symbolic-links.ts +14 -0
- package/src/lib/tasks/lib/format-with-bun-fmt/internal/unformatted-file-errors.ts +12 -0
- package/src/lib/tasks/lib/judge-index-re-exports/index.ts +1 -0
- package/src/lib/tasks/lib/judge-index-re-exports/internal/find-index-re-export-violations.ts +353 -0
- package/src/lib/tasks/lib/judge-index-re-exports/internal/index-re-export-errors.ts +21 -0
- package/src/lib/tasks/lib/lint-with-oxlint/index.ts +15 -0
- package/src/lib/tasks/lib/lint-with-oxlint/internal/check-lint-rules-with-oxlint.ts +123 -0
- package/src/lib/tasks/lib/lint-with-oxlint/internal/check-unsafe-enum-assignments.ts +152 -0
- package/src/lib/tasks/lib/lint-with-oxlint/internal/find-tsgolint-executable.ts +21 -0
- package/src/lib/tasks/lib/lint-with-oxlint/internal/read-oxlint-json-report.ts +82 -0
- package/src/lib/tasks/lib/lint-with-oxlint/internal/read-tsgolint-rule-messages.ts +68 -0
- package/src/lib/tasks/lib/place-exports-in-the-narrowest-directory/index.ts +1 -0
- package/src/lib/tasks/lib/place-exports-in-the-narrowest-directory/internal/export-placement-errors.ts +135 -0
- package/src/lib/tasks/lib/place-exports-in-the-narrowest-directory/internal/find-export-placement-violations.ts +507 -0
- package/src/lib/tasks/lib/place-exports-in-the-narrowest-directory/internal/find-misplaced-files.ts +116 -0
- package/src/lib/tasks/lib/place-exports-in-the-narrowest-directory/internal/find-subdivided-directories.ts +29 -0
- package/src/lib/tasks/lib/place-exports-in-the-narrowest-directory/internal/find-the-importer-graph.ts +451 -0
- package/src/lib/tasks/lib/place-exports-in-the-narrowest-directory/internal/list-binding-names.ts +49 -0
- package/src/lib/tasks/lib/refuse-disable-directives/index.ts +15 -0
- package/src/lib/tasks/lib/refuse-disable-directives/internal/disable-directive-errors.ts +45 -0
- package/src/lib/tasks/lib/refuse-disable-directives/internal/find-disable-directives.ts +66 -0
- package/src/lib/tasks/lib/refuse-error-mappings-that-end-streams/index.ts +1 -0
- package/src/lib/tasks/lib/refuse-error-mappings-that-end-streams/internal/error-mapping-errors.ts +21 -0
- package/src/lib/tasks/lib/refuse-error-mappings-that-end-streams/internal/find-error-mappings-to-done.ts +135 -0
- package/src/lib/tasks/lib/require-separate-service-layers/index.ts +1 -0
- package/src/lib/tasks/lib/require-separate-service-layers/internal/find-service-layer-violations.ts +170 -0
- package/src/lib/tasks/lib/require-separate-service-layers/internal/service-layer-errors.ts +21 -0
- package/src/lib/tasks/lib/require-type-checking-every-linted-file/index.ts +14 -0
- package/src/lib/tasks/lib/require-type-checking-every-linted-file/internal/find-linted-files-not-type-checked.ts +117 -0
- package/src/lib/tasks/lib/require-type-checking-every-linted-file/internal/linted-file-errors.ts +51 -0
- package/src/lib/tasks/lib/type-check-with-bun-check/index.ts +11 -0
- package/src/lib/tasks/lib/type-check-with-bun-check/internal/check-types-with-bun-check.ts +54 -0
- package/src/lib/tasks/lib/type-check-with-bun-check/internal/read-bun-check-output.ts +73 -0
- package/src/lib/tasks/lib/type-check-with-bun-check/internal/type-check-errors.ts +10 -0
- package/src/lib/tasks/shared/check-each-nested-package.ts +79 -0
- package/src/lib/tasks/shared/classify-files-by-role.ts +115 -0
- package/src/lib/tasks/shared/count-the-line-of-an-offset.ts +2 -0
- package/src/lib/tasks/shared/create-the-module-resolver.ts +38 -0
- package/src/lib/tasks/shared/declare-lint-config-task.ts +13 -0
- package/src/lib/tasks/shared/declare-typescript-config-task.ts +18 -0
- package/src/lib/tasks/shared/encode-compact-json.ts +5 -0
- package/src/lib/tasks/shared/find-installed-package-binaries.ts +62 -0
- package/src/lib/tasks/shared/find-module-requests.ts +482 -0
- package/src/lib/tasks/shared/find-named-package-manifests.ts +94 -0
- package/src/lib/tasks/shared/find-unmet-typescript-config-requirements.ts +60 -0
- package/src/lib/tasks/shared/list-ignored-files-imported-by-source.ts +79 -0
- package/src/lib/tasks/shared/list-linted-files.ts +28 -0
- package/src/lib/tasks/shared/list-owned-files.ts +13 -0
- package/src/lib/tasks/shared/list-package-files.ts +66 -0
- package/src/lib/tasks/shared/load-the-lint-config.ts +176 -0
- package/src/lib/tasks/shared/match-granted-patch-files.ts +88 -0
- package/src/lib/tasks/shared/parse-config-files-that-import-from-check.ts +310 -0
- package/src/lib/tasks/shared/print-failures-and-keep-detail-in-the-trace.ts +99 -0
- package/src/lib/tasks/shared/project-config-and-tool-errors.ts +485 -0
- package/src/lib/tasks/shared/query-the-typescript-project.ts +635 -0
- package/src/lib/tasks/shared/read-named-package-manifests.ts +53 -0
- package/src/lib/tasks/shared/read-package-manifest-object.ts +28 -0
- package/src/lib/tasks/shared/resolve-absolute-paths.ts +4 -0
- package/src/lib/tasks/shared/resolve-module-requests.ts +121 -0
- package/src/lib/tasks/shared/run-tools-and-decode-their-reports.ts +98 -0
- package/src/lib/tasks/shared/tool-file-locations.ts +38 -0
- package/src/shared/bans-each-permission-lifts.ts +454 -0
- package/src/shared/config-file-names.ts +3 -0
- package/src/shared/find-retired-words.ts +17 -0
- package/src/shared/format-reported-failures.ts +31 -0
- package/src/shared/lint-rule-messages-and-patterns.ts +104 -0
- package/src/shared/match-file-names-and-path-prefixes.ts +18 -0
- package/src/shared/permission-grant-errors.ts +42 -0
- package/src/shared/record-and-grant-permissions-by-path.ts +419 -0
- package/src/shared/test-home-directories.ts +4 -0
|
@@ -0,0 +1,417 @@
|
|
|
1
|
+
import { Effect, Schema } from "effect";
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
TASK_MAIN_MEMBER,
|
|
5
|
+
TASK_NAMESPACE_EXPORT,
|
|
6
|
+
TASK_PACKAGE,
|
|
7
|
+
} from "../../../../../shared/bans-each-permission-lifts.ts";
|
|
8
|
+
import { LINT_CONFIG_FILE } from "../../../../../shared/config-file-names.ts";
|
|
9
|
+
import { listedViolations } from "../../../../../shared/format-reported-failures.ts";
|
|
10
|
+
import {
|
|
11
|
+
fileNameOf,
|
|
12
|
+
INTERNAL_DIRECTORY_NAME,
|
|
13
|
+
LIBRARY_DIRECTORY_NAME,
|
|
14
|
+
SHARED_DIRECTORY_NAME,
|
|
15
|
+
} from "../../../../../shared/match-file-names-and-path-prefixes.ts";
|
|
16
|
+
import { RedundantGrant } from "../../../../../shared/permission-grant-errors.ts";
|
|
17
|
+
import { DIRECTORY, PATCH } from "../../../../../shared/record-and-grant-permissions-by-path.ts";
|
|
18
|
+
import { SCRIPTS_DIRECTORY } from "../../../../../shared/test-home-directories.ts";
|
|
19
|
+
import { directoryOf } from "../../../shared/classify-files-by-role.ts";
|
|
20
|
+
import { PACKAGE_MANIFEST_FILE } from "../../../shared/find-named-package-manifests.ts";
|
|
21
|
+
import { PATCHED_DEPENDENCIES_FIELD } from "../../../shared/match-granted-patch-files.ts";
|
|
22
|
+
import {
|
|
23
|
+
CHECK_PACKAGE,
|
|
24
|
+
PackageManifestNotObject,
|
|
25
|
+
PackageManifestUnparsable,
|
|
26
|
+
} from "../../../shared/project-config-and-tool-errors.ts";
|
|
27
|
+
|
|
28
|
+
export const DOCS_DIRECTORY = "docs";
|
|
29
|
+
|
|
30
|
+
export class NotKebabCase extends Schema.TaggedError<NotKebabCase>()("NotKebabCase", {
|
|
31
|
+
location: Schema.String,
|
|
32
|
+
segment: Schema.String,
|
|
33
|
+
}) {
|
|
34
|
+
public override get message() {
|
|
35
|
+
return `${this.segment} is not kebab-case`;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export class MisplacedToolFile extends Schema.TaggedError<MisplacedToolFile>()(
|
|
40
|
+
"MisplacedToolFile",
|
|
41
|
+
{
|
|
42
|
+
location: Schema.String,
|
|
43
|
+
directories: Schema.Array(Schema.String),
|
|
44
|
+
},
|
|
45
|
+
) {
|
|
46
|
+
public override get message() {
|
|
47
|
+
const locations = this.directories.map((directory) =>
|
|
48
|
+
directory === "" ? "the package root" : `${directory}/`,
|
|
49
|
+
);
|
|
50
|
+
return `is a tool file that belongs in ${locations.join(" or ")}`;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export class BunTestFileName extends Schema.TaggedError<BunTestFileName>()("BunTestFileName", {
|
|
55
|
+
location: Schema.String,
|
|
56
|
+
}) {
|
|
57
|
+
public override get message() {
|
|
58
|
+
return "is named like a bun test";
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export class TopLevelNonScript extends Schema.TaggedError<TopLevelNonScript>()(
|
|
63
|
+
"TopLevelNonScript",
|
|
64
|
+
{ location: Schema.String },
|
|
65
|
+
) {
|
|
66
|
+
public override get message() {
|
|
67
|
+
return `sits directly in ${SCRIPTS_DIRECTORY}/ and is not a TypeScript or JavaScript file`;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export class TopLevelScriptWithoutMain extends Schema.TaggedError<TopLevelScriptWithoutMain>()(
|
|
72
|
+
"TopLevelScriptWithoutMain",
|
|
73
|
+
{ location: Schema.String },
|
|
74
|
+
) {
|
|
75
|
+
public override get message() {
|
|
76
|
+
return `sits directly in ${SCRIPTS_DIRECTORY}/ and does not call ${TASK_NAMESPACE_EXPORT}.${TASK_MAIN_MEMBER} imported from ${TASK_PACKAGE}`;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export class TopLevelScriptHoldsOtherStatement extends Schema.TaggedError<TopLevelScriptHoldsOtherStatement>()(
|
|
81
|
+
"TopLevelScriptHoldsOtherStatement",
|
|
82
|
+
{ location: Schema.String },
|
|
83
|
+
) {
|
|
84
|
+
public override get message() {
|
|
85
|
+
return `holds a statement other than an import and if (import.meta.main) { ${TASK_NAMESPACE_EXPORT}.${TASK_MAIN_MEMBER}(task); }`;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export class LibraryDirectory extends Schema.TaggedError<LibraryDirectory>()("LibraryDirectory", {
|
|
90
|
+
location: Schema.String,
|
|
91
|
+
}) {
|
|
92
|
+
public override get message() {
|
|
93
|
+
return `is a ${LIBRARY_DIRECTORY_NAME}/ directory that is not directly in a module`;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export class DirectoryOutsideModuleLayout extends Schema.TaggedError<DirectoryOutsideModuleLayout>()(
|
|
98
|
+
"DirectoryOutsideModuleLayout",
|
|
99
|
+
{ location: Schema.String, module: Schema.String },
|
|
100
|
+
) {
|
|
101
|
+
public override get message() {
|
|
102
|
+
return `is a directory in the module ${this.module}/ other than ${INTERNAL_DIRECTORY_NAME}/, ${SHARED_DIRECTORY_NAME}/ or ${LIBRARY_DIRECTORY_NAME}/`;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export class ModuleWithoutIndex extends Schema.TaggedError<ModuleWithoutIndex>()(
|
|
107
|
+
"ModuleWithoutIndex",
|
|
108
|
+
{ location: Schema.String },
|
|
109
|
+
) {
|
|
110
|
+
public override get message() {
|
|
111
|
+
return `is a directory in ${directoryOf(this.location)}/ without an index.ts or index.tsx`;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
export class ModuleWithLayoutDirectoryName extends Schema.TaggedError<ModuleWithLayoutDirectoryName>()(
|
|
116
|
+
"ModuleWithLayoutDirectoryName",
|
|
117
|
+
{ location: Schema.String },
|
|
118
|
+
) {
|
|
119
|
+
public override get message() {
|
|
120
|
+
return `is a module in ${directoryOf(this.location)}/ named ${INTERNAL_DIRECTORY_NAME}, ${SHARED_DIRECTORY_NAME} or ${LIBRARY_DIRECTORY_NAME}`;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
export class FileInLibraryDirectory extends Schema.TaggedError<FileInLibraryDirectory>()(
|
|
125
|
+
"FileInLibraryDirectory",
|
|
126
|
+
{ location: Schema.String },
|
|
127
|
+
) {
|
|
128
|
+
public override get message() {
|
|
129
|
+
return `is a file directly in ${directoryOf(this.location)}/`;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
export class DirectoryInInternalOrShared extends Schema.TaggedError<DirectoryInInternalOrShared>()(
|
|
134
|
+
"DirectoryInInternalOrShared",
|
|
135
|
+
{ location: Schema.String, directory: Schema.String },
|
|
136
|
+
) {
|
|
137
|
+
public override get message() {
|
|
138
|
+
return `holds the directory ${this.directory}/`;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
export class IndexInInternalOrShared extends Schema.TaggedError<IndexInInternalOrShared>()(
|
|
143
|
+
"IndexInInternalOrShared",
|
|
144
|
+
{ location: Schema.String },
|
|
145
|
+
) {
|
|
146
|
+
public override get message() {
|
|
147
|
+
return `is an index file directly in ${fileNameOf(directoryOf(this.location))}/`;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
export class SourceOutsideInternalOrShared extends Schema.TaggedError<SourceOutsideInternalOrShared>()(
|
|
152
|
+
"SourceOutsideInternalOrShared",
|
|
153
|
+
{ location: Schema.String },
|
|
154
|
+
) {
|
|
155
|
+
public override get message() {
|
|
156
|
+
return "is a non-index source file outside internal/ or shared/";
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
export class RetiredWordInPath extends Schema.TaggedError<RetiredWordInPath>()(
|
|
161
|
+
"RetiredWordInPath",
|
|
162
|
+
{ location: Schema.String, word: Schema.String },
|
|
163
|
+
) {
|
|
164
|
+
public override get message() {
|
|
165
|
+
return `uses the retired word ${this.word}`;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
export class DirectoryHoldsOnlyADirectory extends Schema.TaggedError<DirectoryHoldsOnlyADirectory>()(
|
|
170
|
+
"DirectoryHoldsOnlyADirectory",
|
|
171
|
+
{ location: Schema.String, child: Schema.String },
|
|
172
|
+
) {
|
|
173
|
+
public override get message() {
|
|
174
|
+
return `holds only the directory ${this.child}/`;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
export class DuplicateFileName extends Schema.TaggedError<DuplicateFileName>()(
|
|
179
|
+
"DuplicateFileName",
|
|
180
|
+
{ location: Schema.String, otherPaths: Schema.Array(Schema.String), scope: Schema.String },
|
|
181
|
+
) {
|
|
182
|
+
public override get message() {
|
|
183
|
+
return `has the same file name as ${this.otherPaths.join(", ")} in ${this.scope === "" ? "the package root" : `${this.scope}/`}`;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
export class PackageScriptsField extends Schema.TaggedError<PackageScriptsField>()(
|
|
188
|
+
"PackageScriptsField",
|
|
189
|
+
{ location: Schema.String },
|
|
190
|
+
) {
|
|
191
|
+
public override get message() {
|
|
192
|
+
return 'has a "scripts" field';
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
export class DependencyOutsideRepository extends Schema.TaggedError<DependencyOutsideRepository>()(
|
|
197
|
+
"DependencyOutsideRepository",
|
|
198
|
+
{ location: Schema.String, field: Schema.String, specifier: Schema.String },
|
|
199
|
+
) {
|
|
200
|
+
public override get message() {
|
|
201
|
+
return `${this.field} points to ${this.specifier}, outside the repository`;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
export const moduleDirectoryNamedBy = (subpath: string) =>
|
|
206
|
+
subpath
|
|
207
|
+
.slice("./".length)
|
|
208
|
+
.split("/")
|
|
209
|
+
.map((name) => `${LIBRARY_DIRECTORY_NAME}/${name}`)
|
|
210
|
+
.join("/");
|
|
211
|
+
|
|
212
|
+
export class ExportPathMismatch extends Schema.TaggedError<ExportPathMismatch>()(
|
|
213
|
+
"ExportPathMismatch",
|
|
214
|
+
{ location: Schema.String, field: Schema.String, target: Schema.String, subpath: Schema.String },
|
|
215
|
+
) {
|
|
216
|
+
public override get message() {
|
|
217
|
+
const index =
|
|
218
|
+
this.subpath === "." ? "the root index" : `${moduleDirectoryNamedBy(this.subpath)}/index`;
|
|
219
|
+
return `${this.field} points to ${this.target}, which is not ${index}`;
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
export class RepositoryRootNotFound extends Schema.TaggedError<RepositoryRootNotFound>()(
|
|
224
|
+
"RepositoryRootNotFound",
|
|
225
|
+
{ directory: Schema.String, reason: Schema.String },
|
|
226
|
+
) {
|
|
227
|
+
public override get message() {
|
|
228
|
+
return `git found no repository root for ${this.directory}, so package.json dependencies cannot be told inside or outside it: ${this.reason}`;
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
export class UngrantedDocument extends Schema.TaggedError<UngrantedDocument>()(
|
|
233
|
+
"UngrantedDocument",
|
|
234
|
+
{ location: Schema.String },
|
|
235
|
+
) {
|
|
236
|
+
public override get message() {
|
|
237
|
+
return `is a document that ${LINT_CONFIG_FILE} does not allow`;
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
export class UngrantedDirectory extends Schema.TaggedError<UngrantedDirectory>()(
|
|
242
|
+
"UngrantedDirectory",
|
|
243
|
+
{ location: Schema.String },
|
|
244
|
+
) {
|
|
245
|
+
public override get message() {
|
|
246
|
+
return `is a directory outside the default layout that ${LINT_CONFIG_FILE} does not allow`;
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
export class DirectoryGrantOnFile extends Schema.TaggedError<DirectoryGrantOnFile>()(
|
|
251
|
+
"DirectoryGrantOnFile",
|
|
252
|
+
{
|
|
253
|
+
path: Schema.String,
|
|
254
|
+
location: Schema.Literal(LINT_CONFIG_FILE).pipe(
|
|
255
|
+
Schema.optionalKey,
|
|
256
|
+
Schema.withConstructorDefault(Effect.succeed(LINT_CONFIG_FILE)),
|
|
257
|
+
),
|
|
258
|
+
},
|
|
259
|
+
) {
|
|
260
|
+
public override get message() {
|
|
261
|
+
return `${this.path} is granted ${DIRECTORY}, but is a file`;
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
export class CheckOrTaskPatched extends Schema.TaggedError<CheckOrTaskPatched>()(
|
|
266
|
+
"CheckOrTaskPatched",
|
|
267
|
+
{ location: Schema.String, dependency: Schema.String, patchPath: Schema.String },
|
|
268
|
+
) {
|
|
269
|
+
public override get message() {
|
|
270
|
+
return `patches ${this.dependency} with ${this.patchPath}; patches to ${CHECK_PACKAGE} or ${TASK_PACKAGE} are forbidden even when granted`;
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
export class PatchNotGranted extends Schema.TaggedError<PatchNotGranted>()("PatchNotGranted", {
|
|
275
|
+
location: Schema.String,
|
|
276
|
+
dependency: Schema.String,
|
|
277
|
+
patchPath: Schema.String,
|
|
278
|
+
}) {
|
|
279
|
+
public override get message() {
|
|
280
|
+
return `patches ${this.dependency} with ${this.patchPath}, which ${LINT_CONFIG_FILE} doesn't grant ${PATCH}`;
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
export class UnlistedPatchGranted extends Schema.TaggedError<UnlistedPatchGranted>()(
|
|
285
|
+
"UnlistedPatchGranted",
|
|
286
|
+
{
|
|
287
|
+
path: Schema.String,
|
|
288
|
+
location: Schema.Literal(LINT_CONFIG_FILE).pipe(
|
|
289
|
+
Schema.optionalKey,
|
|
290
|
+
Schema.withConstructorDefault(Effect.succeed(LINT_CONFIG_FILE)),
|
|
291
|
+
),
|
|
292
|
+
},
|
|
293
|
+
) {
|
|
294
|
+
public override get message() {
|
|
295
|
+
return `${this.path} is granted ${PATCH}, but ${PACKAGE_MANIFEST_FILE} doesn't list it in ${PATCHED_DEPENDENCIES_FIELD}`;
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
export class PatchedDependenciesMalformed extends Schema.TaggedError<PatchedDependenciesMalformed>()(
|
|
300
|
+
"PatchedDependenciesMalformed",
|
|
301
|
+
{ location: Schema.String, reason: Schema.String },
|
|
302
|
+
) {
|
|
303
|
+
public override get message() {
|
|
304
|
+
return `has a ${PATCHED_DEPENDENCIES_FIELD} field that isn't an object of patch paths: ${this.reason}`;
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
export class GrantedPathMissing extends Schema.TaggedError<GrantedPathMissing>()(
|
|
309
|
+
"GrantedPathMissing",
|
|
310
|
+
{
|
|
311
|
+
path: Schema.String,
|
|
312
|
+
location: Schema.Literal(LINT_CONFIG_FILE).pipe(
|
|
313
|
+
Schema.optionalKey,
|
|
314
|
+
Schema.withConstructorDefault(Effect.succeed(LINT_CONFIG_FILE)),
|
|
315
|
+
),
|
|
316
|
+
},
|
|
317
|
+
) {
|
|
318
|
+
public override get message() {
|
|
319
|
+
return `${this.path} is listed but is not a repository file or directory`;
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
export class CannotImportTargetMissing extends Schema.TaggedError<CannotImportTargetMissing>()(
|
|
324
|
+
"CannotImportTargetMissing",
|
|
325
|
+
{
|
|
326
|
+
path: Schema.String,
|
|
327
|
+
target: Schema.String,
|
|
328
|
+
location: Schema.Literal(LINT_CONFIG_FILE).pipe(
|
|
329
|
+
Schema.optionalKey,
|
|
330
|
+
Schema.withConstructorDefault(Effect.succeed(LINT_CONFIG_FILE)),
|
|
331
|
+
),
|
|
332
|
+
},
|
|
333
|
+
) {
|
|
334
|
+
public override get message() {
|
|
335
|
+
return `${this.target} is in cannotImport of ${this.path} but is not a repository file or directory`;
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
export class DirectoryGrantedPermissions extends Schema.TaggedError<DirectoryGrantedPermissions>()(
|
|
340
|
+
"DirectoryGrantedPermissions",
|
|
341
|
+
{
|
|
342
|
+
path: Schema.String,
|
|
343
|
+
location: Schema.Literal(LINT_CONFIG_FILE).pipe(
|
|
344
|
+
Schema.optionalKey,
|
|
345
|
+
Schema.withConstructorDefault(Effect.succeed(LINT_CONFIG_FILE)),
|
|
346
|
+
),
|
|
347
|
+
},
|
|
348
|
+
) {
|
|
349
|
+
public override get message() {
|
|
350
|
+
return `${this.path} is a directory but is granted file permissions or services`;
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
const MISPLACEMENT_PLACES = ["root-task-script", "root-code-file", "docs-non-markdown"] as const;
|
|
355
|
+
|
|
356
|
+
const MISPLACEMENTS = {
|
|
357
|
+
"root-task-script": "is a task script at the package root",
|
|
358
|
+
"root-code-file": "is code at the package root",
|
|
359
|
+
"docs-non-markdown": `is not markdown but sits in ${DOCS_DIRECTORY}/`,
|
|
360
|
+
} satisfies Record<(typeof MISPLACEMENT_PLACES)[number], string>;
|
|
361
|
+
|
|
362
|
+
export class MisplacedAtPackageRoot extends Schema.TaggedError<MisplacedAtPackageRoot>()(
|
|
363
|
+
"MisplacedAtPackageRoot",
|
|
364
|
+
{ location: Schema.String, place: Schema.Literals(MISPLACEMENT_PLACES) },
|
|
365
|
+
) {
|
|
366
|
+
public override get message() {
|
|
367
|
+
return MISPLACEMENTS[this.place];
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
export class FileLayoutViolations extends Schema.TaggedError<FileLayoutViolations>()(
|
|
372
|
+
"FileLayoutViolations",
|
|
373
|
+
{
|
|
374
|
+
violations: Schema.Array(
|
|
375
|
+
Schema.Union([
|
|
376
|
+
NotKebabCase,
|
|
377
|
+
MisplacedToolFile,
|
|
378
|
+
BunTestFileName,
|
|
379
|
+
TopLevelNonScript,
|
|
380
|
+
TopLevelScriptWithoutMain,
|
|
381
|
+
TopLevelScriptHoldsOtherStatement,
|
|
382
|
+
LibraryDirectory,
|
|
383
|
+
DirectoryOutsideModuleLayout,
|
|
384
|
+
ModuleWithoutIndex,
|
|
385
|
+
ModuleWithLayoutDirectoryName,
|
|
386
|
+
FileInLibraryDirectory,
|
|
387
|
+
DirectoryHoldsOnlyADirectory,
|
|
388
|
+
DirectoryInInternalOrShared,
|
|
389
|
+
IndexInInternalOrShared,
|
|
390
|
+
SourceOutsideInternalOrShared,
|
|
391
|
+
RetiredWordInPath,
|
|
392
|
+
DuplicateFileName,
|
|
393
|
+
PackageManifestUnparsable,
|
|
394
|
+
PackageManifestNotObject,
|
|
395
|
+
PackageScriptsField,
|
|
396
|
+
DependencyOutsideRepository,
|
|
397
|
+
ExportPathMismatch,
|
|
398
|
+
UngrantedDocument,
|
|
399
|
+
UngrantedDirectory,
|
|
400
|
+
DirectoryGrantOnFile,
|
|
401
|
+
CheckOrTaskPatched,
|
|
402
|
+
PatchNotGranted,
|
|
403
|
+
UnlistedPatchGranted,
|
|
404
|
+
PatchedDependenciesMalformed,
|
|
405
|
+
GrantedPathMissing,
|
|
406
|
+
CannotImportTargetMissing,
|
|
407
|
+
DirectoryGrantedPermissions,
|
|
408
|
+
RedundantGrant,
|
|
409
|
+
MisplacedAtPackageRoot,
|
|
410
|
+
]),
|
|
411
|
+
),
|
|
412
|
+
},
|
|
413
|
+
) {
|
|
414
|
+
public override get message() {
|
|
415
|
+
return listedViolations(this.violations);
|
|
416
|
+
}
|
|
417
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { Schema } from "effect";
|
|
2
|
+
|
|
3
|
+
import { JSON_OBJECT } from "../../../shared/read-package-manifest-object.ts";
|
|
4
|
+
import { ExportPathMismatch, moduleDirectoryNamedBy } from "./file-layout-errors.ts";
|
|
5
|
+
|
|
6
|
+
const ROOT_SUBPATH = ".";
|
|
7
|
+
const RELATIVE_PREFIX = "./";
|
|
8
|
+
const QUERY_OR_FRAGMENT = /[?#].*$/u;
|
|
9
|
+
const NOT_A_DIRECTORY_NAME: ReadonlySet<string> = new Set(["", ".", ".."]);
|
|
10
|
+
const CODE_FILE = /\.[cm]?[jt]sx?$/u;
|
|
11
|
+
const INDEX_FILE = /^index\.(?:d\.)?[cm]?[jt]sx?$/u;
|
|
12
|
+
const PROPERTY_NAME = /^[A-Za-z_$][\w$]*$/u;
|
|
13
|
+
const isJsonObject = Schema.is(JSON_OBJECT);
|
|
14
|
+
const isJsonArray = Schema.is(Schema.Array(Schema.Json));
|
|
15
|
+
|
|
16
|
+
const fieldWithKey = (field: string, key: string) =>
|
|
17
|
+
PROPERTY_NAME.test(key) ? `${field}.${key}` : `${field}["${key}"]`;
|
|
18
|
+
|
|
19
|
+
const targetsUnderEveryCondition = (
|
|
20
|
+
field: string,
|
|
21
|
+
value: Schema.Json,
|
|
22
|
+
): { field: string; target: string }[] => {
|
|
23
|
+
if (typeof value === "string") {
|
|
24
|
+
return [{ field, target: value }];
|
|
25
|
+
}
|
|
26
|
+
if (isJsonArray(value)) {
|
|
27
|
+
return value.flatMap((item, index) => targetsUnderEveryCondition(`${field}[${index}]`, item));
|
|
28
|
+
}
|
|
29
|
+
if (!isJsonObject(value)) {
|
|
30
|
+
return [];
|
|
31
|
+
}
|
|
32
|
+
return Object.entries(value).flatMap(([condition, nested]) =>
|
|
33
|
+
targetsUnderEveryCondition(fieldWithKey(field, condition), nested),
|
|
34
|
+
);
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
const subpathsWithTheirFields = (exports: Schema.Json) => {
|
|
38
|
+
const isSubpathMap =
|
|
39
|
+
isJsonObject(exports) && Object.keys(exports).some((key) => key.startsWith(ROOT_SUBPATH));
|
|
40
|
+
return isSubpathMap
|
|
41
|
+
? Object.entries(exports).map(([subpath, value]) => ({
|
|
42
|
+
subpath,
|
|
43
|
+
field: fieldWithKey("exports", subpath),
|
|
44
|
+
value,
|
|
45
|
+
}))
|
|
46
|
+
: [{ subpath: ROOT_SUBPATH, field: "exports", value: exports }];
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
const isIndexOfTheDirectoryTheSubpathNames = (subpath: string, target: string) => {
|
|
50
|
+
const relativeTarget = target.startsWith(RELATIVE_PREFIX)
|
|
51
|
+
? target.slice(RELATIVE_PREFIX.length)
|
|
52
|
+
: target;
|
|
53
|
+
const [sourceOrBuildDirectory = "", ...insideTheSourceOrBuildDirectory] = relativeTarget
|
|
54
|
+
.replace(QUERY_OR_FRAGMENT, "")
|
|
55
|
+
.split("/");
|
|
56
|
+
const fileName = insideTheSourceOrBuildDirectory.at(-1);
|
|
57
|
+
const namedDirectory = subpath === ROOT_SUBPATH ? "" : moduleDirectoryNamedBy(subpath);
|
|
58
|
+
return (
|
|
59
|
+
!NOT_A_DIRECTORY_NAME.has(sourceOrBuildDirectory) &&
|
|
60
|
+
fileName !== undefined &&
|
|
61
|
+
INDEX_FILE.test(fileName) &&
|
|
62
|
+
insideTheSourceOrBuildDirectory.slice(0, -1).join("/") === namedDirectory
|
|
63
|
+
);
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
export const exportPathMismatches = (path: string, manifest: typeof JSON_OBJECT.Type) => {
|
|
67
|
+
const exports = manifest["exports"];
|
|
68
|
+
if (exports === undefined) {
|
|
69
|
+
return [];
|
|
70
|
+
}
|
|
71
|
+
return subpathsWithTheirFields(exports).flatMap(({ subpath, field, value }) =>
|
|
72
|
+
targetsUnderEveryCondition(field, value)
|
|
73
|
+
.filter(
|
|
74
|
+
({ target }) =>
|
|
75
|
+
CODE_FILE.test(target.replace(QUERY_OR_FRAGMENT, "")) &&
|
|
76
|
+
!isIndexOfTheDirectoryTheSubpathNames(subpath, target),
|
|
77
|
+
)
|
|
78
|
+
.map(
|
|
79
|
+
({ field: conditionField, target }) =>
|
|
80
|
+
new ExportPathMismatch({ location: path, field: conditionField, target, subpath }),
|
|
81
|
+
),
|
|
82
|
+
);
|
|
83
|
+
};
|