@sshkeda/check 2.1.0 → 3.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 +52 -22
- package/docs/how-to-make-check-pass.md +3 -0
- package/package.json +7 -10
- package/scripts/check.ts +10 -0
- package/src/internal/ban-abbreviated-words-in-declared-names.ts +4 -5
- package/src/internal/ban-deadlines-inside-tests.ts +4 -5
- package/src/internal/ban-dropped-failures-detached-fibers-sleeps-and-untraced-functions.ts +4 -5
- package/src/internal/ban-failures-collected-as-results.ts +4 -5
- package/src/internal/ban-fallbacks-of-named-recoveries.ts +6 -7
- package/src/internal/ban-fixed-values-in-recoveries.ts +331 -0
- package/src/internal/ban-re-exports.ts +14 -1
- package/src/internal/ban-reading-the-clock-and-sleeping-outside-effect.ts +4 -5
- package/src/internal/ban-recovering-file-system-exists.ts +12 -79
- package/src/internal/ban-timer-schedules-without-deadlines.ts +5 -6
- package/src/internal/ban-type-predicates.ts +4 -5
- package/src/internal/ban-what-a-file-is-not-granted.ts +9 -9
- package/src/internal/define-the-lint-plugin-and-configs.ts +6 -2
- package/src/internal/follow-the-steps-applied-to-an-effect.ts +100 -0
- package/src/internal/recognize-fixed-values.ts +318 -0
- package/src/internal/recognize-whole-library-error-tags.ts +6 -0
- package/src/internal/report-code-grants-nothing-uses.ts +122 -0
- package/src/lib/project-directory/index.ts +5 -0
- package/src/lib/project-directory/internal/read-the-project-directory.ts +13 -0
- package/src/lib/tasks/internal/declare-the-check-task.ts +18 -10
- package/src/lib/tasks/internal/declare-the-checker-queries-task.ts +3 -1
- package/src/lib/tasks/internal/verify-where-check-was-started.ts +50 -0
- package/src/lib/tasks/lib/check-effect-diagnostics-with-effect-tsgo/index.ts +1 -1
- package/src/lib/tasks/lib/check-effect-diagnostics-with-effect-tsgo/internal/read-effect-tsgo-json-report.ts +13 -9
- package/src/lib/tasks/lib/confine-layer-provides-to-program-starts/internal/find-layer-provides-outside-program-starts.ts +6 -36
- package/src/lib/tasks/lib/detect-duplicate-functions/internal/find-duplicate-functions.ts +2 -3
- package/src/lib/tasks/lib/enforce-file-layout/internal/check-the-layout-of-each-package.ts +1 -1
- package/src/lib/tasks/lib/enforce-file-layout/internal/file-layout-errors.ts +19 -2
- package/src/lib/tasks/lib/enforce-file-layout/internal/find-file-layout-violations.ts +53 -19
- package/src/lib/tasks/lib/enforce-file-types/internal/find-file-type-violations.ts +1 -1
- package/src/lib/tasks/lib/format-with-bun-fmt/internal/check-formatting-with-bun-fmt.ts +17 -16
- package/src/lib/tasks/lib/format-with-bun-fmt/internal/declare-the-formatting-task.ts +22 -14
- package/src/lib/tasks/lib/lint-with-oxlint/index.ts +1 -1
- package/src/lib/tasks/lib/lint-with-oxlint/internal/check-lint-rules-with-oxlint.ts +7 -0
- package/src/lib/tasks/lib/lint-with-oxlint/internal/find-shebangs-outside-bin.ts +38 -0
- package/src/lib/tasks/lib/lint-with-oxlint/internal/shebang-errors.ts +22 -0
- package/src/lib/tasks/lib/place-exports-in-the-narrowest-directory/internal/find-export-placement-violations.ts +9 -1
- package/src/lib/tasks/lib/place-exports-in-the-narrowest-directory/internal/find-the-importer-graph.ts +21 -0
- package/src/lib/tasks/lib/place-exports-in-the-narrowest-directory/internal/recognise-task-default-exports.ts +76 -0
- package/src/lib/tasks/lib/refuse-disable-directives/index.ts +1 -1
- package/src/lib/tasks/lib/refuse-forks-whose-failures-nothing-observes/index.ts +1 -0
- package/src/lib/tasks/lib/refuse-forks-whose-failures-nothing-observes/internal/find-unobserved-fork-failures.ts +402 -0
- package/src/lib/tasks/lib/refuse-forks-whose-failures-nothing-observes/internal/fork-failure-errors.ts +28 -0
- package/src/lib/tasks/lib/require-type-checking-every-linted-file/internal/find-linted-files-not-type-checked.ts +15 -9
- package/src/lib/tasks/lib/type-check-with-bun-check/index.ts +1 -1
- package/src/lib/tasks/shared/check-each-nested-package.ts +13 -5
- package/src/lib/tasks/shared/declare-lint-config-task.ts +1 -1
- package/src/lib/tasks/shared/declare-typescript-config-task.ts +1 -1
- package/src/lib/tasks/shared/find-installed-package-binaries.ts +10 -0
- package/src/lib/tasks/shared/list-package-files.ts +15 -2
- package/src/lib/tasks/shared/read-piped-steps-through-wrappers.ts +41 -0
- package/src/lib/tasks/shared/report-paths-from-the-project.ts +56 -0
- package/src/shared/bans-each-permission-lifts.ts +3 -0
- package/src/shared/format-reported-failures.ts +8 -6
- package/src/shared/record-and-grant-permissions-by-path.ts +63 -7
- package/src/internal/ban-shebang-lines.ts +0 -22
- /package/src/lib/tasks/{lib/format-with-bun-fmt/internal → shared}/find-symbolic-links.ts +0 -0
|
@@ -10,6 +10,7 @@ import { findRepeatedServiceYields } from "../lib/detect-repeated-service-yields
|
|
|
10
10
|
import { findIndexReExportViolations } from "../lib/judge-index-re-exports/index.ts";
|
|
11
11
|
import { findExportPlacementViolations } from "../lib/place-exports-in-the-narrowest-directory/index.ts";
|
|
12
12
|
import { findErrorMappingsToDone } from "../lib/refuse-error-mappings-that-end-streams/index.ts";
|
|
13
|
+
import { findUnobservedForkFailures } from "../lib/refuse-forks-whose-failures-nothing-observes/index.ts";
|
|
13
14
|
import { findServiceLayerViolations } from "../lib/require-separate-service-layers/index.ts";
|
|
14
15
|
import { inEachPackage } from "../shared/check-each-nested-package.ts";
|
|
15
16
|
import { lintConfigFile } from "../shared/declare-lint-config-task.ts";
|
|
@@ -22,7 +23,7 @@ export const checkerQueries = Task.make(
|
|
|
22
23
|
"checker-queries",
|
|
23
24
|
Effect.andThen(
|
|
24
25
|
Task.all([typeScriptConfig, lintConfigFile]),
|
|
25
|
-
inEachPackage("checker-queries",
|
|
26
|
+
inEachPackage("checker-queries", (packageDirectory) =>
|
|
26
27
|
Path.Path.use((path) =>
|
|
27
28
|
runChecksOverOneTypeScriptProject(path.join(packageDirectory, TYPESCRIPT_PROJECT_FILE), {
|
|
28
29
|
"service-yields": findRepeatedServiceYields,
|
|
@@ -34,6 +35,7 @@ export const checkerQueries = Task.make(
|
|
|
34
35
|
"export-placement": findExportPlacementViolations,
|
|
35
36
|
"layer-provides": findLayerProvidesOutsideProgramStarts,
|
|
36
37
|
"error-mappings": findErrorMappingsToDone,
|
|
38
|
+
"fork-failures": findUnobservedForkFailures,
|
|
37
39
|
"re-exports": findIndexReExportViolations,
|
|
38
40
|
}),
|
|
39
41
|
),
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { Task } from "@sshkeda/task";
|
|
2
|
+
import { Effect, FileSystem, Path, References, Schema } from "effect";
|
|
3
|
+
|
|
4
|
+
import { givenArguments, projectDirectory } from "../../project-directory/index.ts";
|
|
5
|
+
import { quietViolations } from "../shared/print-failures-and-keep-detail-in-the-trace.ts";
|
|
6
|
+
|
|
7
|
+
const PACKAGE_MANIFEST_FILE = "package.json";
|
|
8
|
+
|
|
9
|
+
class ArgumentsNotAccepted extends Schema.TaggedError<ArgumentsNotAccepted>()(
|
|
10
|
+
"ArgumentsNotAccepted",
|
|
11
|
+
{ givenArguments: Schema.Array(Schema.String) },
|
|
12
|
+
) {
|
|
13
|
+
public override get message() {
|
|
14
|
+
return `check takes no arguments, and was given ${this.givenArguments.join(" ")}`;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
class PackageManifestMissing extends Schema.TaggedError<PackageManifestMissing>()(
|
|
19
|
+
"PackageManifestMissing",
|
|
20
|
+
{ directory: Schema.String },
|
|
21
|
+
) {
|
|
22
|
+
public override get message() {
|
|
23
|
+
return `${this.directory} has no ${PACKAGE_MANIFEST_FILE}`;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
class RepositoryNotFound extends Schema.TaggedError<RepositoryNotFound>()("RepositoryNotFound", {
|
|
28
|
+
directory: Schema.String,
|
|
29
|
+
}) {
|
|
30
|
+
public override get message() {
|
|
31
|
+
return `${this.directory} is not inside a git repository`;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export const verifyWhereCheckWasStarted = Effect.gen(function* () {
|
|
36
|
+
const fileSystem = yield* FileSystem.FileSystem;
|
|
37
|
+
const path = yield* Path.Path;
|
|
38
|
+
const given = yield* givenArguments;
|
|
39
|
+
if (given.length > 0) {
|
|
40
|
+
return yield* new ArgumentsNotAccepted({ givenArguments: given });
|
|
41
|
+
}
|
|
42
|
+
const directory = path.resolve(yield* projectDirectory);
|
|
43
|
+
if (!(yield* fileSystem.exists(path.join(directory, PACKAGE_MANIFEST_FILE)))) {
|
|
44
|
+
return yield* new PackageManifestMissing({ directory });
|
|
45
|
+
}
|
|
46
|
+
yield* Task.exec("git", ["rev-parse", "--show-toplevel"], { cwd: directory }).pipe(
|
|
47
|
+
Effect.provideService(References.MinimumLogLevel, "Warn"),
|
|
48
|
+
Effect.catchTag("CommandFailed", () => Effect.fail(new RepositoryNotFound({ directory }))),
|
|
49
|
+
);
|
|
50
|
+
}).pipe(quietViolations("check"));
|
|
@@ -11,6 +11,6 @@ export const effectStrict = Task.make(
|
|
|
11
11
|
"effect-tsgo",
|
|
12
12
|
Effect.andThen(
|
|
13
13
|
Task.all([typeScriptConfig, lintConfigFile]),
|
|
14
|
-
inEachPackage("effect-tsgo",
|
|
14
|
+
inEachPackage("effect-tsgo", effectDiagnosticsIn),
|
|
15
15
|
).pipe(Effect.provide(ProjectQueryCachesLive)),
|
|
16
16
|
);
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import { Effect, Schema } from "effect";
|
|
2
2
|
|
|
3
|
+
import { distinctPrintedErrors } from "../../../shared/check-each-nested-package.ts";
|
|
3
4
|
import { decodedReport } from "../../../shared/run-tools-and-decode-their-reports.ts";
|
|
4
5
|
|
|
6
|
+
const PROJECT_WIDE_DIAGNOSTICS: ReadonlySet<string> = new Set(["duplicatePackage"]);
|
|
7
|
+
|
|
5
8
|
const UPSTREAM_MESSAGE_REWRITES: ReadonlyMap<string, string> = new Map([
|
|
6
9
|
["effect(schemaNumber)", "Schema.Number accepts NaN, Infinity and -Infinity"],
|
|
7
10
|
]);
|
|
@@ -25,15 +28,16 @@ export const effectViolationsReport = (program: string, standardOutput: string)
|
|
|
25
28
|
? Effect.succeed({ violations: [], notes: [] })
|
|
26
29
|
: decodedReport(program, Schema.decodeEffect(EFFECT_VIOLATIONS_REPORT), standardOutput).pipe(
|
|
27
30
|
Effect.map((report) => ({
|
|
28
|
-
violations:
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
31
|
+
violations: distinctPrintedErrors(
|
|
32
|
+
report.diagnostics.map((reported) => {
|
|
33
|
+
const tag = `effect(${reported.name})`;
|
|
34
|
+
const message = UPSTREAM_MESSAGE_REWRITES.get(tag) ?? reported.message;
|
|
35
|
+
const location = `${reported.file}:${reported.line}:${reported.column}`;
|
|
36
|
+
return PROJECT_WIDE_DIAGNOSTICS.has(reported.name)
|
|
37
|
+
? { tag, message }
|
|
38
|
+
: { tag, location, message };
|
|
39
|
+
}),
|
|
40
|
+
),
|
|
37
41
|
notes: [],
|
|
38
42
|
})),
|
|
39
43
|
);
|
|
@@ -4,7 +4,6 @@ import { NodeFlags } from "typescript/unstable/ast";
|
|
|
4
4
|
import type { CallExpression, Node, SourceFile } from "typescript/unstable/ast";
|
|
5
5
|
import {
|
|
6
6
|
isArrowFunction,
|
|
7
|
-
isAsExpression,
|
|
8
7
|
isBlock,
|
|
9
8
|
isCallExpression,
|
|
10
9
|
isConditionalExpression,
|
|
@@ -12,13 +11,9 @@ import {
|
|
|
12
11
|
isFunctionDeclaration,
|
|
13
12
|
isFunctionExpression,
|
|
14
13
|
isIdentifier,
|
|
15
|
-
isNonNullExpression,
|
|
16
14
|
isObjectLiteralExpression,
|
|
17
15
|
isParameterDeclaration,
|
|
18
|
-
isParenthesizedExpression,
|
|
19
|
-
isPropertyAccessExpression,
|
|
20
16
|
isReturnStatement,
|
|
21
|
-
isSatisfiesExpression,
|
|
22
17
|
isSpreadElement,
|
|
23
18
|
isVariableDeclaration,
|
|
24
19
|
isVariableStatement,
|
|
@@ -37,6 +32,12 @@ import {
|
|
|
37
32
|
typeScriptRequest,
|
|
38
33
|
} from "../../../shared/query-the-typescript-project.ts";
|
|
39
34
|
import type { openTypeScriptProjects } from "../../../shared/query-the-typescript-project.ts";
|
|
35
|
+
import {
|
|
36
|
+
outermostWrapperOf,
|
|
37
|
+
pipedStepsOf,
|
|
38
|
+
referencedNameOf,
|
|
39
|
+
withoutWrappers,
|
|
40
|
+
} from "../../../shared/read-piped-steps-through-wrappers.ts";
|
|
40
41
|
import { absolutePathOf } from "../../../shared/resolve-absolute-paths.ts";
|
|
41
42
|
import {
|
|
42
43
|
LayerProvidedOutsideProgramStart,
|
|
@@ -78,7 +79,6 @@ const EFFECT_OPERATIONS = [
|
|
|
78
79
|
{ module: STREAM_MODULE, names: PROVIDE_OPERATIONS },
|
|
79
80
|
];
|
|
80
81
|
const PROVIDING_MODULES = [EFFECT_MODULE, STREAM_MODULE];
|
|
81
|
-
const PIPE = "pipe";
|
|
82
82
|
const PROVIDED_ARGUMENTS = 2;
|
|
83
83
|
|
|
84
84
|
const anyOf = <Item, Failure>(
|
|
@@ -86,18 +86,6 @@ const anyOf = <Item, Failure>(
|
|
|
86
86
|
predicate: (item: Item) => Effect.Effect<boolean, Failure>,
|
|
87
87
|
) => Effect.findFirst(items, predicate).pipe(Effect.map(Option.isSome));
|
|
88
88
|
|
|
89
|
-
const isWrapper = (node: Node) =>
|
|
90
|
-
isParenthesizedExpression(node) ||
|
|
91
|
-
isAsExpression(node) ||
|
|
92
|
-
isSatisfiesExpression(node) ||
|
|
93
|
-
isNonNullExpression(node);
|
|
94
|
-
|
|
95
|
-
const withoutWrappers = (node: Node): Node =>
|
|
96
|
-
isWrapper(node) ? withoutWrappers(node.expression) : node;
|
|
97
|
-
|
|
98
|
-
const outermostWrapperOf = (node: Node): Node =>
|
|
99
|
-
isWrapper(node.parent) ? outermostWrapperOf(node.parent) : node;
|
|
100
|
-
|
|
101
89
|
const isFunctionLike = (node: Node) =>
|
|
102
90
|
isFunctionDeclaration(node) || isFunctionExpression(node) || isArrowFunction(node);
|
|
103
91
|
|
|
@@ -122,14 +110,6 @@ const returnedBy = (callable: Node) => {
|
|
|
122
110
|
return returned;
|
|
123
111
|
};
|
|
124
112
|
|
|
125
|
-
const referencedNameOf = (node: Node) => {
|
|
126
|
-
const reference = withoutWrappers(node);
|
|
127
|
-
if (isPropertyAccessExpression(reference)) {
|
|
128
|
-
return reference.name;
|
|
129
|
-
}
|
|
130
|
-
return isIdentifier(reference) ? reference : undefined;
|
|
131
|
-
};
|
|
132
|
-
|
|
133
113
|
const isExportOf = (
|
|
134
114
|
apis: Effect.Success<ReturnType<typeof importedPackageApis>>,
|
|
135
115
|
symbol: TypeScriptSymbol | undefined,
|
|
@@ -137,16 +117,6 @@ const isExportOf = (
|
|
|
137
117
|
names: ReadonlySet<string>,
|
|
138
118
|
) => symbol !== undefined && names.has(symbol.name) && apis.effectExports.get(symbol.id) === module;
|
|
139
119
|
|
|
140
|
-
const pipedStepsOf = (call: CallExpression) => {
|
|
141
|
-
if (referencedNameOf(call.expression)?.text !== PIPE) {
|
|
142
|
-
return;
|
|
143
|
-
}
|
|
144
|
-
const callee = withoutWrappers(call.expression);
|
|
145
|
-
return isPropertyAccessExpression(callee)
|
|
146
|
-
? [callee.expression, ...call.arguments]
|
|
147
|
-
: [...call.arguments];
|
|
148
|
-
};
|
|
149
|
-
|
|
150
120
|
const stepsBefore = (step: Node) => {
|
|
151
121
|
const { parent } = step;
|
|
152
122
|
if (!isCallExpression(parent)) {
|
|
@@ -142,9 +142,8 @@ export const findDuplicateFunctions = (directory: string, shownDirectory = ".")
|
|
|
142
142
|
|
|
143
143
|
export const duplicateFunctionsOfEachPackage = inEachPackage(
|
|
144
144
|
DUPLICATE_FUNCTIONS,
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
findDuplicateFunctions(packageDirectory, packageDirectory).pipe(
|
|
145
|
+
(packageDirectory, packageDirectoryFromTheProject) =>
|
|
146
|
+
findDuplicateFunctions(packageDirectory, packageDirectoryFromTheProject).pipe(
|
|
148
147
|
quietViolations(DUPLICATE_FUNCTIONS),
|
|
149
148
|
),
|
|
150
149
|
);
|
|
@@ -4,6 +4,6 @@ import { findFileLayoutViolations } from "./find-file-layout-violations.ts";
|
|
|
4
4
|
|
|
5
5
|
const LAYOUT = "layout";
|
|
6
6
|
|
|
7
|
-
export const fileLayoutViolationsOfEachPackage = inEachPackage(LAYOUT,
|
|
7
|
+
export const fileLayoutViolationsOfEachPackage = inEachPackage(LAYOUT, (packageDirectory) =>
|
|
8
8
|
findFileLayoutViolations(packageDirectory).pipe(quietViolations(LAYOUT)),
|
|
9
9
|
);
|
|
@@ -73,16 +73,32 @@ export class TopLevelScriptWithoutMain extends Schema.TaggedError<TopLevelScript
|
|
|
73
73
|
{ location: Schema.String },
|
|
74
74
|
) {
|
|
75
75
|
public override get message() {
|
|
76
|
-
return `sits directly in ${SCRIPTS_DIRECTORY}/ and
|
|
76
|
+
return `sits directly in ${SCRIPTS_DIRECTORY}/ and neither calls ${TASK_NAMESPACE_EXPORT}.${TASK_MAIN_MEMBER} imported from ${TASK_PACKAGE} nor has a default export`;
|
|
77
77
|
}
|
|
78
78
|
}
|
|
79
79
|
|
|
80
|
+
const SCRIPT_ENTRY_POINTS = ["main-guard", "default-export"] as const;
|
|
81
|
+
|
|
82
|
+
const STATEMENTS_A_SCRIPT_MAY_HOLD = {
|
|
83
|
+
"main-guard": `an import and if (import.meta.main) { ${TASK_NAMESPACE_EXPORT}.${TASK_MAIN_MEMBER}(task); }`,
|
|
84
|
+
"default-export": "an import and export default task",
|
|
85
|
+
} satisfies Record<(typeof SCRIPT_ENTRY_POINTS)[number], string>;
|
|
86
|
+
|
|
80
87
|
export class TopLevelScriptHoldsOtherStatement extends Schema.TaggedError<TopLevelScriptHoldsOtherStatement>()(
|
|
81
88
|
"TopLevelScriptHoldsOtherStatement",
|
|
89
|
+
{ location: Schema.String, entryPoint: Schema.Literals(SCRIPT_ENTRY_POINTS) },
|
|
90
|
+
) {
|
|
91
|
+
public override get message() {
|
|
92
|
+
return `holds a statement other than ${STATEMENTS_A_SCRIPT_MAY_HOLD[this.entryPoint]}`;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export class TopLevelScriptWithMainAndDefaultExport extends Schema.TaggedError<TopLevelScriptWithMainAndDefaultExport>()(
|
|
97
|
+
"TopLevelScriptWithMainAndDefaultExport",
|
|
82
98
|
{ location: Schema.String },
|
|
83
99
|
) {
|
|
84
100
|
public override get message() {
|
|
85
|
-
return `
|
|
101
|
+
return `calls ${TASK_NAMESPACE_EXPORT}.${TASK_MAIN_MEMBER} and also has a default export. Keep one of them`;
|
|
86
102
|
}
|
|
87
103
|
}
|
|
88
104
|
|
|
@@ -388,6 +404,7 @@ export class FileLayoutViolations extends Schema.TaggedError<FileLayoutViolation
|
|
|
388
404
|
TopLevelNonScript,
|
|
389
405
|
TopLevelScriptWithoutMain,
|
|
390
406
|
TopLevelScriptHoldsOtherStatement,
|
|
407
|
+
TopLevelScriptWithMainAndDefaultExport,
|
|
391
408
|
LibraryDirectory,
|
|
392
409
|
DirectoryOutsideModuleLayout,
|
|
393
410
|
ModuleWithoutIndex,
|
|
@@ -49,6 +49,7 @@ import {
|
|
|
49
49
|
directoriesNestedInLayoutDirectoriesOf,
|
|
50
50
|
} from "../../../shared/classify-files-by-role.ts";
|
|
51
51
|
import { lineNumbersIn } from "../../../shared/count-the-line-of-an-offset.ts";
|
|
52
|
+
import { listedBinaryFilesOf } from "../../../shared/find-installed-package-binaries.ts";
|
|
52
53
|
import { PACKAGE_MANIFEST_FILE } from "../../../shared/find-named-package-manifests.ts";
|
|
53
54
|
import { isInsideAnyDirectory, listedPackageFiles } from "../../../shared/list-package-files.ts";
|
|
54
55
|
import { loadedLintConfigIn } from "../../../shared/load-the-lint-config.ts";
|
|
@@ -92,6 +93,7 @@ import {
|
|
|
92
93
|
MisplacedToolFile,
|
|
93
94
|
TopLevelNonScript,
|
|
94
95
|
TopLevelScriptHoldsOtherStatement,
|
|
96
|
+
TopLevelScriptWithMainAndDefaultExport,
|
|
95
97
|
TopLevelScriptWithoutMain,
|
|
96
98
|
UngrantedDocument,
|
|
97
99
|
UngrantedDirectory,
|
|
@@ -271,26 +273,61 @@ const isMainGuard = (statement: Statement, imports: ReadonlyMap<string, readonly
|
|
|
271
273
|
return testsImportMetaMain && alternate === null && runsOneNamedTask;
|
|
272
274
|
};
|
|
273
275
|
|
|
276
|
+
const isDefaultExport = (statement: Statement) =>
|
|
277
|
+
statement.type === "ExportDefaultDeclaration" &&
|
|
278
|
+
statement.declaration.type !== "TSInterfaceDeclaration";
|
|
279
|
+
|
|
280
|
+
const statementsOtherThanImports = (parsed: ParseResult) =>
|
|
281
|
+
parsed.program.body.filter((statement) => statement.type !== "ImportDeclaration");
|
|
282
|
+
|
|
274
283
|
const statementsOtherThanImportsAndMain = (
|
|
275
284
|
parsed: ParseResult,
|
|
276
285
|
imports: ReadonlyMap<string, readonly string[]>,
|
|
277
286
|
) => {
|
|
278
|
-
const nonImports = parsed
|
|
279
|
-
(statement) => statement.type !== "ImportDeclaration",
|
|
280
|
-
);
|
|
287
|
+
const nonImports = statementsOtherThanImports(parsed);
|
|
281
288
|
const firstGuard = nonImports.findIndex((statement) => isMainGuard(statement, imports));
|
|
282
289
|
return nonImports.filter((_statement, index) => index !== firstGuard);
|
|
283
290
|
};
|
|
284
291
|
|
|
292
|
+
const mainScriptViolations = (
|
|
293
|
+
path: string,
|
|
294
|
+
text: string,
|
|
295
|
+
parsed: ParseResult,
|
|
296
|
+
imports: ReadonlyMap<string, readonly string[]>,
|
|
297
|
+
) => {
|
|
298
|
+
const lineAt = lineNumbersIn(text);
|
|
299
|
+
return statementsOtherThanImportsAndMain(parsed, imports).map((statement) => {
|
|
300
|
+
const location = `${path}:${lineAt(statement.start)}`;
|
|
301
|
+
return isDefaultExport(statement)
|
|
302
|
+
? new TopLevelScriptWithMainAndDefaultExport({ location })
|
|
303
|
+
: new TopLevelScriptHoldsOtherStatement({ location, entryPoint: "main-guard" });
|
|
304
|
+
});
|
|
305
|
+
};
|
|
306
|
+
|
|
307
|
+
const defaultExportScriptViolations = (path: string, text: string, parsed: ParseResult) => {
|
|
308
|
+
const lineAt = lineNumbersIn(text);
|
|
309
|
+
return statementsOtherThanImports(parsed)
|
|
310
|
+
.filter((statement) => !isDefaultExport(statement))
|
|
311
|
+
.map(
|
|
312
|
+
(statement) =>
|
|
313
|
+
new TopLevelScriptHoldsOtherStatement({
|
|
314
|
+
location: `${path}:${lineAt(statement.start)}`,
|
|
315
|
+
entryPoint: "default-export",
|
|
316
|
+
}),
|
|
317
|
+
);
|
|
318
|
+
};
|
|
319
|
+
|
|
285
320
|
export const sourceViolations = (
|
|
286
321
|
path: string,
|
|
287
322
|
text: string,
|
|
288
323
|
resolvedImports?: ReadonlyMap<string, readonly string[]>,
|
|
324
|
+
isListedUnderBin = false,
|
|
289
325
|
) => {
|
|
290
326
|
const violations: (
|
|
291
327
|
| MisplacedAtPackageRoot
|
|
292
328
|
| SourceOutsideInternalOrShared
|
|
293
329
|
| TopLevelScriptHoldsOtherStatement
|
|
330
|
+
| TopLevelScriptWithMainAndDefaultExport
|
|
294
331
|
| TopLevelScriptWithoutMain
|
|
295
332
|
)[] = [];
|
|
296
333
|
const isMisplacedTool = toolFileOf(path) !== undefined && !toolFileIsPlaced(path);
|
|
@@ -324,22 +361,18 @@ export const sourceViolations = (
|
|
|
324
361
|
}),
|
|
325
362
|
);
|
|
326
363
|
}
|
|
327
|
-
const
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
violations.push(new TopLevelScriptWithoutMain({ location: path }));
|
|
364
|
+
const isTaskScript = isTopLevelScript(path) && !isListedUnderBin;
|
|
365
|
+
if (!isTaskScript) {
|
|
366
|
+
return violations;
|
|
331
367
|
}
|
|
332
|
-
const
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
violations.push(
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
}),
|
|
341
|
-
),
|
|
342
|
-
);
|
|
368
|
+
const callsMain = callsTaskMember(parsed, TASK_MAIN_MEMBER, imports);
|
|
369
|
+
const hasDefaultExport = parsed.program.body.some((statement) => isDefaultExport(statement));
|
|
370
|
+
if (callsMain) {
|
|
371
|
+
violations.push(...mainScriptViolations(path, text, parsed, imports));
|
|
372
|
+
} else if (hasDefaultExport) {
|
|
373
|
+
violations.push(...defaultExportScriptViolations(path, text, parsed));
|
|
374
|
+
} else {
|
|
375
|
+
violations.push(new TopLevelScriptWithoutMain({ location: path }));
|
|
343
376
|
}
|
|
344
377
|
return violations;
|
|
345
378
|
};
|
|
@@ -772,6 +805,7 @@ export const findFileLayoutViolations = (directory: string) =>
|
|
|
772
805
|
),
|
|
773
806
|
);
|
|
774
807
|
const rootManifest = yield* rootManifestIn(directory, paths);
|
|
808
|
+
const binaryFiles = listedBinaryFilesOf(rootManifest);
|
|
775
809
|
const generated = Option.match(grants, {
|
|
776
810
|
onNone: () => new Set<string>(),
|
|
777
811
|
onSome: generatedPathsOf,
|
|
@@ -829,7 +863,7 @@ export const findFileLayoutViolations = (directory: string) =>
|
|
|
829
863
|
return [
|
|
830
864
|
...found,
|
|
831
865
|
...(isScriptFile
|
|
832
|
-
? sourceViolations(path, text, imports)
|
|
866
|
+
? sourceViolations(path, text, imports, binaryFiles.has(path))
|
|
833
867
|
: yield* manifestViolations(path, text, repository)),
|
|
834
868
|
];
|
|
835
869
|
}),
|
|
@@ -73,6 +73,6 @@ export const findFileTypeViolations = (directory: string) =>
|
|
|
73
73
|
}
|
|
74
74
|
});
|
|
75
75
|
|
|
76
|
-
export const fileTypeViolationsOfEachPackage = inEachPackage(FILE_TYPES,
|
|
76
|
+
export const fileTypeViolationsOfEachPackage = inEachPackage(FILE_TYPES, (packageDirectory) =>
|
|
77
77
|
findFileTypeViolations(packageDirectory).pipe(quietViolations(FILE_TYPES)),
|
|
78
78
|
);
|
|
@@ -4,6 +4,7 @@ import { FORMAT_CONFIG_FILE } from "../../../../../shared/config-file-names.ts";
|
|
|
4
4
|
import { printableError } from "../../../../../shared/format-reported-failures.ts";
|
|
5
5
|
import { enclosingDirectoriesOf } from "../../../shared/classify-files-by-role.ts";
|
|
6
6
|
import { encodeJson } from "../../../shared/encode-compact-json.ts";
|
|
7
|
+
import { isSymbolicLink } from "../../../shared/find-symbolic-links.ts";
|
|
7
8
|
import {
|
|
8
9
|
failQuietly,
|
|
9
10
|
quietViolations,
|
|
@@ -13,11 +14,8 @@ import {
|
|
|
13
14
|
mergedExit,
|
|
14
15
|
runTool,
|
|
15
16
|
} from "../../../shared/run-tools-and-decode-their-reports.ts";
|
|
16
|
-
import { isSymbolicLink } from "./find-symbolic-links.ts";
|
|
17
17
|
import { UnformattedFile } from "./unformatted-file-errors.ts";
|
|
18
18
|
|
|
19
|
-
export const FORMATTED_PACKAGE_DIRECTORY = ".";
|
|
20
|
-
|
|
21
19
|
const BUN_FORMAT = "bun fmt";
|
|
22
20
|
|
|
23
21
|
const BUN_FORMAT_TASK = "bun-fmt";
|
|
@@ -33,11 +31,11 @@ const BUN_FORMAT_ARGUMENTS = [
|
|
|
33
31
|
|
|
34
32
|
const CONTROL_CHARACTER = /\p{Cc}/u;
|
|
35
33
|
|
|
36
|
-
const filesBunFormatFormatsAmong = (files: readonly string[]) =>
|
|
34
|
+
const filesBunFormatFormatsAmong = (checkedProject: string, files: readonly string[]) =>
|
|
37
35
|
Effect.gen(function* () {
|
|
38
36
|
const fileSystem = yield* FileSystem.FileSystem;
|
|
39
37
|
const path = yield* Path.Path;
|
|
40
|
-
const onDisk = (file: string) => path.join(
|
|
38
|
+
const onDisk = (file: string) => path.join(checkedProject, file);
|
|
41
39
|
const listed = files.filter((file) => file !== FORMAT_CONFIG_FILE);
|
|
42
40
|
const linkedDirectories = new Set(
|
|
43
41
|
yield* Effect.filter(
|
|
@@ -87,12 +85,13 @@ const filesListedInARunOfOneFileNotPrintedOnOneLine = (file: string, standardOut
|
|
|
87
85
|
|
|
88
86
|
const formatArgumentOf = (file: string) => `./${file}`;
|
|
89
87
|
|
|
90
|
-
const ranBunFormat = (fileArguments: readonly string[]) =>
|
|
91
|
-
runTool(
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
...fileArguments,
|
|
95
|
-
|
|
88
|
+
const ranBunFormat = (checkedProject: string, fileArguments: readonly string[]) =>
|
|
89
|
+
runTool(
|
|
90
|
+
BUN_FORMAT,
|
|
91
|
+
process.execPath,
|
|
92
|
+
[...BUN_FORMAT_ARGUMENTS, formatArgumentOf(FORMAT_CONFIG_FILE), ...fileArguments],
|
|
93
|
+
checkedProject,
|
|
94
|
+
).pipe(
|
|
96
95
|
Effect.map(({ standardOutput }) => ({ exited: undefined, standardOutput })),
|
|
97
96
|
Effect.catchTag("ToolExited", (exited) =>
|
|
98
97
|
Effect.succeed({ exited, standardOutput: exited.standardOutput }),
|
|
@@ -105,9 +104,9 @@ const unformattedFileOf = (file: string) =>
|
|
|
105
104
|
return printableError(new UnformattedFile({ file: location }));
|
|
106
105
|
});
|
|
107
106
|
|
|
108
|
-
const bunFormatReportOn = (packageFiles: readonly string[]) =>
|
|
107
|
+
const bunFormatReportOn = (checkedProject: string, packageFiles: readonly string[]) =>
|
|
109
108
|
Effect.gen(function* () {
|
|
110
|
-
const formatted = yield* filesBunFormatFormatsAmong(packageFiles);
|
|
109
|
+
const formatted = yield* filesBunFormatFormatsAmong(checkedProject, packageFiles);
|
|
111
110
|
const runs = [
|
|
112
111
|
...argumentsInRunsOfBoundedSize(
|
|
113
112
|
formatted.filter((file) => isPrintedOnOneLine(file)).map((file) => formatArgumentOf(file)),
|
|
@@ -127,7 +126,7 @@ const bunFormatReportOn = (packageFiles: readonly string[]) =>
|
|
|
127
126
|
runs.push({ fileArguments: [], listedIn: listedLinesOf });
|
|
128
127
|
}
|
|
129
128
|
const ran = yield* Effect.forEach(runs, (run) =>
|
|
130
|
-
ranBunFormat(run.fileArguments).pipe(
|
|
129
|
+
ranBunFormat(checkedProject, run.fileArguments).pipe(
|
|
131
130
|
Effect.map(({ exited, standardOutput }) => ({
|
|
132
131
|
exited,
|
|
133
132
|
listed: run.listedIn(standardOutput),
|
|
@@ -141,9 +140,11 @@ const bunFormatReportOn = (packageFiles: readonly string[]) =>
|
|
|
141
140
|
};
|
|
142
141
|
});
|
|
143
142
|
|
|
144
|
-
export const unformattedFilesAmong = (packageFiles: readonly string[]) =>
|
|
143
|
+
export const unformattedFilesAmong = (checkedProject: string, packageFiles: readonly string[]) =>
|
|
145
144
|
Effect.gen(function* () {
|
|
146
|
-
const report = yield* bunFormatReportOn(packageFiles).pipe(
|
|
145
|
+
const report = yield* bunFormatReportOn(checkedProject, packageFiles).pipe(
|
|
146
|
+
quietViolations(BUN_FORMAT_TASK),
|
|
147
|
+
);
|
|
147
148
|
if (report.exited !== undefined) {
|
|
148
149
|
return yield* failQuietly(
|
|
149
150
|
BUN_FORMAT_TASK,
|
|
@@ -1,51 +1,57 @@
|
|
|
1
1
|
import { Task } from "@sshkeda/task";
|
|
2
2
|
import { Effect, Path } from "effect";
|
|
3
3
|
|
|
4
|
+
import { projectDirectory } from "../../../../project-directory/index.ts";
|
|
4
5
|
import { inEachPackage, packageDirectoriesIn } from "../../../shared/check-each-nested-package.ts";
|
|
5
6
|
import { ownedFilesAmong } from "../../../shared/list-owned-files.ts";
|
|
6
7
|
import { listedPackageFiles } from "../../../shared/list-package-files.ts";
|
|
7
8
|
import { quietViolations } from "../../../shared/print-failures-and-keep-detail-in-the-trace.ts";
|
|
8
9
|
import { ProjectQueryCachesLive } from "../../../shared/provide-project-query-caches.ts";
|
|
9
|
-
import {
|
|
10
|
-
|
|
11
|
-
unformattedFilesAmong,
|
|
12
|
-
} from "./check-formatting-with-bun-fmt.ts";
|
|
10
|
+
import { locatedFromTheProject } from "../../../shared/report-paths-from-the-project.ts";
|
|
11
|
+
import { unformattedFilesAmong } from "./check-formatting-with-bun-fmt.ts";
|
|
13
12
|
import { checkedFormatConfigIn } from "./find-format-config-violations.ts";
|
|
14
13
|
import { checkedFormatInputsIn } from "./find-format-input-violations.ts";
|
|
15
14
|
|
|
16
|
-
const ownedFilesOfPackage = (packageDirectory: string) =>
|
|
15
|
+
const ownedFilesOfPackage = (checkedProject: string, packageDirectory: string) =>
|
|
17
16
|
Effect.gen(function* () {
|
|
18
17
|
const path = yield* Path.Path;
|
|
19
|
-
const directory = path.join(
|
|
18
|
+
const directory = path.join(checkedProject, packageDirectory);
|
|
20
19
|
const { packageFiles } = yield* listedPackageFiles(directory, []);
|
|
21
|
-
return { directory, files: yield* ownedFilesAmong(directory, packageFiles) };
|
|
20
|
+
return { directory: packageDirectory, files: yield* ownedFilesAmong(directory, packageFiles) };
|
|
22
21
|
});
|
|
23
22
|
|
|
24
23
|
const formatterFiles = Task.make(
|
|
25
24
|
"formatter-files",
|
|
26
25
|
Effect.gen(function* () {
|
|
27
26
|
const path = yield* Path.Path;
|
|
27
|
+
const checkedProject = yield* projectDirectory;
|
|
28
28
|
const filesOfEachPackage = yield* Effect.forEach(
|
|
29
|
-
yield* packageDirectoriesIn(
|
|
30
|
-
ownedFilesOfPackage,
|
|
29
|
+
yield* packageDirectoriesIn(checkedProject),
|
|
30
|
+
(packageDirectory) => ownedFilesOfPackage(checkedProject, packageDirectory),
|
|
31
31
|
{ concurrency: "unbounded" },
|
|
32
32
|
);
|
|
33
33
|
return {
|
|
34
|
+
checkedProject,
|
|
34
35
|
filesOfEachPackage,
|
|
35
36
|
packageFiles: filesOfEachPackage
|
|
36
37
|
.flatMap(({ directory, files }) => files.map((file) => path.join(directory, file)))
|
|
37
38
|
.toSorted(),
|
|
38
39
|
};
|
|
39
|
-
}).pipe(
|
|
40
|
+
}).pipe(
|
|
41
|
+
quietViolations("formatter-files"),
|
|
42
|
+
locatedFromTheProject,
|
|
43
|
+
Effect.provide(ProjectQueryCachesLive),
|
|
44
|
+
),
|
|
40
45
|
);
|
|
41
46
|
|
|
42
47
|
const formatInputs = Task.make(
|
|
43
48
|
"format-inputs",
|
|
44
49
|
Effect.flatMap(formatterFiles, ({ filesOfEachPackage }) =>
|
|
45
|
-
inEachPackage("format-inputs",
|
|
50
|
+
inEachPackage("format-inputs", (packageDirectory, packageDirectoryFromTheProject) =>
|
|
46
51
|
checkedFormatInputsIn(
|
|
47
52
|
packageDirectory,
|
|
48
|
-
filesOfEachPackage.find(({ directory }) => directory ===
|
|
53
|
+
filesOfEachPackage.find(({ directory }) => directory === packageDirectoryFromTheProject)
|
|
54
|
+
?.files ?? [],
|
|
49
55
|
).pipe(quietViolations("format-inputs")),
|
|
50
56
|
),
|
|
51
57
|
),
|
|
@@ -54,10 +60,12 @@ const formatInputs = Task.make(
|
|
|
54
60
|
const unformattedFiles = Task.make(
|
|
55
61
|
"bun-fmt",
|
|
56
62
|
Effect.andThen(
|
|
57
|
-
inEachPackage("bun-fmt",
|
|
63
|
+
inEachPackage("bun-fmt", (packageDirectory) =>
|
|
58
64
|
checkedFormatConfigIn(packageDirectory).pipe(quietViolations("bun-fmt")),
|
|
59
65
|
),
|
|
60
|
-
Effect.flatMap(formatterFiles, ({ packageFiles }) =>
|
|
66
|
+
Effect.flatMap(formatterFiles, ({ checkedProject, packageFiles }) =>
|
|
67
|
+
unformattedFilesAmong(checkedProject, packageFiles),
|
|
68
|
+
),
|
|
61
69
|
).pipe(Effect.provide(ProjectQueryCachesLive)),
|
|
62
70
|
);
|
|
63
71
|
|
|
@@ -11,6 +11,6 @@ export const oxlint = Task.make(
|
|
|
11
11
|
"oxlint",
|
|
12
12
|
Effect.andThen(
|
|
13
13
|
Task.all([typeScriptConfig, lintConfigFile]),
|
|
14
|
-
inEachPackage("oxlint",
|
|
14
|
+
inEachPackage("oxlint", checkLintRulesWithOxlintIn),
|
|
15
15
|
).pipe(Effect.provide(ProjectQueryCachesLive)),
|
|
16
16
|
);
|
|
@@ -17,6 +17,7 @@ import {
|
|
|
17
17
|
runTool,
|
|
18
18
|
} from "../../../shared/run-tools-and-decode-their-reports.ts";
|
|
19
19
|
import { checkUnsafeEnumAssignmentsIn } from "./check-unsafe-enum-assignments.ts";
|
|
20
|
+
import { findShebangsOutsideBin } from "./find-shebangs-outside-bin.ts";
|
|
20
21
|
import { tsgolintExecutable } from "./find-tsgolint-executable.ts";
|
|
21
22
|
import {
|
|
22
23
|
OXLINT_TASK,
|
|
@@ -116,6 +117,12 @@ export const checkLintRulesWithOxlintIn = (directory: string) =>
|
|
|
116
117
|
Effect.withSpan("unsafe-enum-assignments"),
|
|
117
118
|
),
|
|
118
119
|
),
|
|
120
|
+
reportedErrorsOf(
|
|
121
|
+
findShebangsOutsideBin(directory, files).pipe(
|
|
122
|
+
Effect.withSpan("shebangs-outside-bin"),
|
|
123
|
+
quietViolations(OXLINT_TASK),
|
|
124
|
+
),
|
|
125
|
+
),
|
|
119
126
|
],
|
|
120
127
|
{ concurrency: "unbounded" },
|
|
121
128
|
);
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { Effect, FileSystem, Path } from "effect";
|
|
2
|
+
|
|
3
|
+
import { listedBinaryFilesOf } from "../../../shared/find-installed-package-binaries.ts";
|
|
4
|
+
import { PACKAGE_MANIFEST_FILE } from "../../../shared/find-named-package-manifests.ts";
|
|
5
|
+
import { existingPackageFiles } from "../../../shared/list-package-files.ts";
|
|
6
|
+
import { rootManifestIn } from "../../../shared/match-granted-patch-files.ts";
|
|
7
|
+
import { ShebangOutsideBin, ShebangsOutsideBin } from "./shebang-errors.ts";
|
|
8
|
+
|
|
9
|
+
const SHEBANG = /^?#!/u;
|
|
10
|
+
|
|
11
|
+
const FIRST_LINE = 1;
|
|
12
|
+
|
|
13
|
+
export const findShebangsOutsideBin = (directory: string, files: readonly string[]) =>
|
|
14
|
+
Effect.gen(function* () {
|
|
15
|
+
const fileSystem = yield* FileSystem.FileSystem;
|
|
16
|
+
const path = yield* Path.Path;
|
|
17
|
+
const binaryFiles = listedBinaryFilesOf(
|
|
18
|
+
yield* rootManifestIn(
|
|
19
|
+
directory,
|
|
20
|
+
yield* existingPackageFiles(directory, [PACKAGE_MANIFEST_FILE]),
|
|
21
|
+
),
|
|
22
|
+
);
|
|
23
|
+
const startingWithAShebang = yield* Effect.filter(
|
|
24
|
+
files.filter((file) => !binaryFiles.has(file)),
|
|
25
|
+
(file) =>
|
|
26
|
+
fileSystem
|
|
27
|
+
.readFileString(path.join(directory, file))
|
|
28
|
+
.pipe(Effect.map((text) => SHEBANG.test(text))),
|
|
29
|
+
{ concurrency: "unbounded" },
|
|
30
|
+
);
|
|
31
|
+
if (startingWithAShebang.length > 0) {
|
|
32
|
+
return yield* new ShebangsOutsideBin({
|
|
33
|
+
violations: startingWithAShebang.map(
|
|
34
|
+
(file) => new ShebangOutsideBin({ location: `${file}:${FIRST_LINE}` }),
|
|
35
|
+
),
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
});
|