@sshkeda/check 2.2.0 → 4.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 +18 -24
- package/docs/how-to-grant-a-permission.md +28 -0
- package/docs/how-to-make-check-pass.md +5 -31
- package/package.json +7 -10
- package/scripts/check.ts +9 -0
- package/src/internal/ban-fixed-values-in-recoveries.ts +1 -1
- package/src/internal/ban-re-exports.ts +14 -1
- package/src/internal/define-the-lint-plugin-and-configs.ts +0 -2
- package/src/lib/project-directory/index.ts +4 -0
- package/src/lib/project-directory/internal/read-the-project-directory.ts +9 -0
- package/src/lib/tasks/internal/declare-the-check-task.ts +21 -13
- package/src/lib/tasks/internal/declare-the-checker-queries-task.ts +7 -5
- package/src/lib/tasks/internal/declare-the-typed-checks-task.ts +4 -4
- package/src/lib/tasks/lib/check-effect-diagnostics-with-effect-tsgo/index.ts +5 -5
- package/src/lib/tasks/lib/confine-layer-provides-to-program-starts/internal/find-layer-provides-outside-program-starts.ts +21 -37
- package/src/lib/tasks/lib/confine-layer-provides-to-program-starts/internal/resolve-imported-package-apis.ts +1 -2
- package/src/lib/tasks/lib/detect-duplicate-functions/index.ts +4 -4
- package/src/lib/tasks/lib/detect-duplicate-functions/internal/find-duplicate-functions.ts +2 -3
- package/src/lib/tasks/lib/enforce-file-layout/index.ts +4 -4
- 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 +7 -12
- package/src/lib/tasks/lib/enforce-file-layout/internal/find-file-layout-violations.ts +37 -170
- package/src/lib/tasks/lib/enforce-file-types/index.ts +4 -4
- 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 +16 -15
- package/src/lib/tasks/lib/format-with-bun-fmt/internal/declare-the-formatting-task.ts +50 -31
- package/src/lib/tasks/lib/lint-with-oxlint/index.ts +5 -5
- 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 +5 -5
- 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/index.ts +4 -4
- 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 +4 -4
- package/src/lib/tasks/shared/check-each-nested-package.ts +14 -4
- package/src/lib/tasks/shared/declare-lint-config-task.ts +4 -4
- package/src/lib/tasks/shared/declare-start-directory-task.ts +40 -0
- package/src/lib/tasks/shared/declare-typescript-config-task.ts +4 -4
- package/src/lib/tasks/shared/find-installed-package-binaries.ts +10 -0
- 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 +0 -7
- package/src/shared/format-reported-failures.ts +8 -6
- package/src/shared/record-and-grant-permissions-by-path.ts +4 -3
- package/src/internal/ban-shebang-lines.ts +0 -22
- package/src/lib/tasks/lib/enforce-file-layout/internal/resolve-task-imports.ts +0 -178
|
@@ -36,6 +36,7 @@ const isTypeChecked = (
|
|
|
36
36
|
|
|
37
37
|
const violationFor = (
|
|
38
38
|
file: string,
|
|
39
|
+
shownPathOf: (configFile: string) => string,
|
|
39
40
|
projectFile: string,
|
|
40
41
|
compilingProjects: readonly {
|
|
41
42
|
readonly configFile: string;
|
|
@@ -44,17 +45,22 @@ const violationFor = (
|
|
|
44
45
|
) => {
|
|
45
46
|
const [firstProject] = compilingProjects;
|
|
46
47
|
if (firstProject === undefined) {
|
|
47
|
-
return new LintedFileOutsideTypeScriptProgram({
|
|
48
|
+
return new LintedFileOutsideTypeScriptProgram({
|
|
49
|
+
location: file,
|
|
50
|
+
projectFile: shownPathOf(projectFile),
|
|
51
|
+
});
|
|
48
52
|
}
|
|
49
|
-
const configFiles = compilingProjects.map(({ configFile }) => configFile);
|
|
53
|
+
const configFiles = compilingProjects.map(({ configFile }) => shownPathOf(configFile));
|
|
50
54
|
return firstProject.isDeclarationFile
|
|
51
55
|
? new LintedDeclarationFileNotTypeChecked({ location: file, configFiles })
|
|
52
56
|
: new LintedJavaScriptFileNotTypeChecked({ location: file, configFiles });
|
|
53
57
|
};
|
|
54
58
|
|
|
55
|
-
export const findLintedFilesNotTypeChecked = (projectFile: string) =>
|
|
59
|
+
export const findLintedFilesNotTypeChecked = (projectFile: string, shownPackageDirectory = ".") =>
|
|
56
60
|
Effect.gen(function* () {
|
|
57
61
|
const path = yield* Path.Path;
|
|
62
|
+
const shownPathOf = (configFile: string) =>
|
|
63
|
+
path.join(shownPackageDirectory, path.relative(path.dirname(projectFile), configFile));
|
|
58
64
|
const linted = yield* scriptFiles(projectFile);
|
|
59
65
|
const owned = new Set(yield* ownedFilesAmong(path.dirname(projectFile), linted));
|
|
60
66
|
const compilations = (yield* Effect.forEach(
|
|
@@ -94,7 +100,7 @@ export const findLintedFilesNotTypeChecked = (projectFile: string) =>
|
|
|
94
100
|
(isDeclarationFile(file) || compiling.some((compilation) => compilation.isDeclarationFile));
|
|
95
101
|
const isTypeCheckedOrExempt =
|
|
96
102
|
isGeneratedDeclarationFile || compiling.some(({ typeChecked }) => typeChecked);
|
|
97
|
-
return isTypeCheckedOrExempt ? [] : [violationFor(file, projectFile, compiling)];
|
|
103
|
+
return isTypeCheckedOrExempt ? [] : [violationFor(file, shownPathOf, projectFile, compiling)];
|
|
98
104
|
});
|
|
99
105
|
if (violations.length > 0) {
|
|
100
106
|
return yield* new LintedFilesNotTypeChecked({ violations });
|
|
@@ -105,11 +111,11 @@ const LINTED_FILES_TYPE_CHECKED = "linted-files-type-checked";
|
|
|
105
111
|
|
|
106
112
|
export const lintedFilesNotTypeCheckedInEachPackage = inEachPackage(
|
|
107
113
|
LINTED_FILES_TYPE_CHECKED,
|
|
108
|
-
|
|
109
|
-
(packageDirectory) =>
|
|
114
|
+
(packageDirectory, packageDirectoryFromTheProject) =>
|
|
110
115
|
Path.Path.use((path) =>
|
|
111
|
-
findLintedFilesNotTypeChecked(
|
|
112
|
-
|
|
113
|
-
|
|
116
|
+
findLintedFilesNotTypeChecked(
|
|
117
|
+
path.join(packageDirectory, TYPESCRIPT_PROJECT_FILE),
|
|
118
|
+
packageDirectoryFromTheProject,
|
|
119
|
+
).pipe(quietViolations(LINTED_FILES_TYPE_CHECKED)),
|
|
114
120
|
),
|
|
115
121
|
);
|
|
@@ -5,7 +5,7 @@ import { inEachPackage } from "../../shared/check-each-nested-package.ts";
|
|
|
5
5
|
import { typeScriptConfig } from "../../shared/declare-typescript-config-task.ts";
|
|
6
6
|
import { checkTypesWithBunCheckIn } from "./internal/check-types-with-bun-check.ts";
|
|
7
7
|
|
|
8
|
-
export const typeCheck = Task.make(
|
|
9
|
-
"type-check",
|
|
10
|
-
Effect.andThen(typeScriptConfig, inEachPackage("type-check",
|
|
11
|
-
);
|
|
8
|
+
export const typeCheck = Task.make({
|
|
9
|
+
name: "type-check",
|
|
10
|
+
run: Effect.andThen(typeScriptConfig, inEachPackage("type-check", checkTypesWithBunCheckIn)),
|
|
11
|
+
});
|
|
@@ -3,8 +3,11 @@ import type { PrintableError } from "@sshkeda/task/errors";
|
|
|
3
3
|
import { Array as Arrays, Effect, Path } from "effect";
|
|
4
4
|
import type { PlatformError } from "effect";
|
|
5
5
|
|
|
6
|
+
import { projectDirectory } from "../../project-directory/index.ts";
|
|
7
|
+
import { startDirectory } from "./declare-start-directory-task.ts";
|
|
6
8
|
import { listedPackageFiles } from "./list-package-files.ts";
|
|
7
9
|
import { quietViolations } from "./print-failures-and-keep-detail-in-the-trace.ts";
|
|
10
|
+
import { locatedFromTheProject, printedFromTheProject } from "./report-paths-from-the-project.ts";
|
|
8
11
|
|
|
9
12
|
const CHECKED_PACKAGE = ".";
|
|
10
13
|
|
|
@@ -61,18 +64,23 @@ export const packageDirectoriesIn = (directory: string) =>
|
|
|
61
64
|
|
|
62
65
|
export const inEachPackage = <Requirements>(
|
|
63
66
|
tool: string,
|
|
64
|
-
directory: string,
|
|
65
67
|
checkPackage: (
|
|
66
68
|
packageDirectory: string,
|
|
69
|
+
packageDirectoryFromTheProject: string,
|
|
67
70
|
) => Effect.Effect<void, PlatformError.PlatformError | ReportedErrors, Requirements>,
|
|
68
71
|
) =>
|
|
69
72
|
Effect.gen(function* () {
|
|
73
|
+
yield* startDirectory;
|
|
70
74
|
const pathModule = yield* Path.Path;
|
|
71
|
-
const
|
|
75
|
+
const checkedProject = yield* projectDirectory.pipe(quietViolations(tool));
|
|
76
|
+
const packageDirectories = yield* packageDirectoriesIn(checkedProject).pipe(
|
|
77
|
+
quietViolations(tool),
|
|
78
|
+
locatedFromTheProject,
|
|
79
|
+
);
|
|
72
80
|
const reportedByPackage = yield* Effect.forEach(
|
|
73
81
|
packageDirectories,
|
|
74
82
|
(packageDirectory) =>
|
|
75
|
-
checkPackage(pathModule.join(
|
|
83
|
+
checkPackage(pathModule.join(checkedProject, packageDirectory), packageDirectory).pipe(
|
|
76
84
|
Effect.as([]),
|
|
77
85
|
Effect.catchTag("ReportedErrors", ({ reportedErrors }) =>
|
|
78
86
|
Effect.succeed(
|
|
@@ -84,7 +92,9 @@ export const inEachPackage = <Requirements>(
|
|
|
84
92
|
),
|
|
85
93
|
{ concurrency: "unbounded" },
|
|
86
94
|
);
|
|
87
|
-
const reportedErrors = distinctPrintedErrors(
|
|
95
|
+
const reportedErrors = distinctPrintedErrors(
|
|
96
|
+
yield* printedFromTheProject(reportedByPackage.flat()),
|
|
97
|
+
);
|
|
88
98
|
if (Arrays.isArrayNonEmpty(reportedErrors)) {
|
|
89
99
|
return yield* new ReportedErrors({ reportedErrors });
|
|
90
100
|
}
|
|
@@ -6,9 +6,9 @@ import { loadedLintConfigIn } from "./load-the-lint-config.ts";
|
|
|
6
6
|
import { quietViolations } from "./print-failures-and-keep-detail-in-the-trace.ts";
|
|
7
7
|
import { ProjectQueryCachesLive } from "./provide-project-query-caches.ts";
|
|
8
8
|
|
|
9
|
-
export const lintConfigFile = Task.make(
|
|
10
|
-
"lint-config",
|
|
11
|
-
inEachPackage("lint-config",
|
|
9
|
+
export const lintConfigFile = Task.make({
|
|
10
|
+
name: "lint-config",
|
|
11
|
+
run: inEachPackage("lint-config", (packageDirectory) =>
|
|
12
12
|
loadedLintConfigIn(packageDirectory).pipe(Effect.asVoid, quietViolations("lint-config")),
|
|
13
13
|
).pipe(Effect.provide(ProjectQueryCachesLive)),
|
|
14
|
-
);
|
|
14
|
+
});
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { Task } from "@sshkeda/task";
|
|
2
|
+
import { Effect, FileSystem, Path, References, Schema } from "effect";
|
|
3
|
+
|
|
4
|
+
import { projectDirectory } from "../../project-directory/index.ts";
|
|
5
|
+
import { quietViolations } from "./print-failures-and-keep-detail-in-the-trace.ts";
|
|
6
|
+
|
|
7
|
+
const PACKAGE_MANIFEST_FILE = "package.json";
|
|
8
|
+
|
|
9
|
+
class PackageManifestMissing extends Schema.TaggedError<PackageManifestMissing>()(
|
|
10
|
+
"PackageManifestMissing",
|
|
11
|
+
{ directory: Schema.String },
|
|
12
|
+
) {
|
|
13
|
+
public override get message() {
|
|
14
|
+
return `${this.directory} has no ${PACKAGE_MANIFEST_FILE}`;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
class RepositoryNotFound extends Schema.TaggedError<RepositoryNotFound>()("RepositoryNotFound", {
|
|
19
|
+
directory: Schema.String,
|
|
20
|
+
}) {
|
|
21
|
+
public override get message() {
|
|
22
|
+
return `${this.directory} is not inside a git repository`;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export const startDirectory = Task.make({
|
|
27
|
+
name: "start-directory",
|
|
28
|
+
run: Effect.gen(function* () {
|
|
29
|
+
const fileSystem = yield* FileSystem.FileSystem;
|
|
30
|
+
const path = yield* Path.Path;
|
|
31
|
+
const directory = path.resolve(yield* projectDirectory);
|
|
32
|
+
if (!(yield* fileSystem.exists(path.join(directory, PACKAGE_MANIFEST_FILE)))) {
|
|
33
|
+
return yield* new PackageManifestMissing({ directory });
|
|
34
|
+
}
|
|
35
|
+
yield* Task.exec("git", ["rev-parse", "--show-toplevel"], { cwd: directory }).pipe(
|
|
36
|
+
Effect.provideService(References.MinimumLogLevel, "Warn"),
|
|
37
|
+
Effect.catchTag("CommandFailed", () => Effect.fail(new RepositoryNotFound({ directory }))),
|
|
38
|
+
);
|
|
39
|
+
}).pipe(quietViolations("start-directory")),
|
|
40
|
+
});
|
|
@@ -26,9 +26,9 @@ const locatedFromThePackage = (
|
|
|
26
26
|
: printable;
|
|
27
27
|
};
|
|
28
28
|
|
|
29
|
-
export const typeScriptConfig = Task.make(
|
|
30
|
-
"typescript-config",
|
|
31
|
-
inEachPackage("typescript-config",
|
|
29
|
+
export const typeScriptConfig = Task.make({
|
|
30
|
+
name: "typescript-config",
|
|
31
|
+
run: inEachPackage("typescript-config", (packageDirectory) =>
|
|
32
32
|
Path.Path.use((path) =>
|
|
33
33
|
findTypeScriptConfigViolations(path.join(packageDirectory, TYPESCRIPT_PROJECT_FILE)).pipe(
|
|
34
34
|
quietViolations("typescript-config"),
|
|
@@ -43,4 +43,4 @@ export const typeScriptConfig = Task.make(
|
|
|
43
43
|
),
|
|
44
44
|
),
|
|
45
45
|
).pipe(Effect.provide(ProjectQueryCachesLive)),
|
|
46
|
-
);
|
|
46
|
+
});
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Effect, FileSystem, Path, Predicate, Schema } from "effect";
|
|
2
2
|
|
|
3
|
+
import { normalizedPath } from "../../../shared/record-and-grant-permissions-by-path.ts";
|
|
3
4
|
import { PACKAGE_MANIFEST_FILE } from "./find-named-package-manifests.ts";
|
|
4
5
|
import {
|
|
5
6
|
InstalledPackageHasNoBinary,
|
|
@@ -7,6 +8,7 @@ import {
|
|
|
7
8
|
PackageNotInstalled,
|
|
8
9
|
} from "./project-config-and-tool-errors.ts";
|
|
9
10
|
import { packageManifestObject } from "./read-package-manifest-object.ts";
|
|
11
|
+
import type { JSON_OBJECT } from "./read-package-manifest-object.ts";
|
|
10
12
|
|
|
11
13
|
const MANIFEST_BINARIES = Schema.Struct({
|
|
12
14
|
bin: Schema.optionalKey(
|
|
@@ -14,6 +16,14 @@ const MANIFEST_BINARIES = Schema.Struct({
|
|
|
14
16
|
),
|
|
15
17
|
});
|
|
16
18
|
|
|
19
|
+
const isManifestWithBinaries = Schema.is(MANIFEST_BINARIES);
|
|
20
|
+
|
|
21
|
+
export const listedBinaryFilesOf = (manifest: typeof JSON_OBJECT.Type) => {
|
|
22
|
+
const bin = isManifestWithBinaries(manifest) ? manifest.bin : undefined;
|
|
23
|
+
const binaries = Predicate.isString(bin) ? [bin] : Object.values(bin ?? {});
|
|
24
|
+
return new Set(binaries.map((binary) => normalizedPath(binary)));
|
|
25
|
+
};
|
|
26
|
+
|
|
17
27
|
const unscopedName = (packageName: string) => packageName.split("/").at(-1) ?? packageName;
|
|
18
28
|
|
|
19
29
|
const declaredBinary = (
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { CallExpression, Node } from "typescript/unstable/ast";
|
|
2
|
+
import {
|
|
3
|
+
isAsExpression,
|
|
4
|
+
isIdentifier,
|
|
5
|
+
isNonNullExpression,
|
|
6
|
+
isParenthesizedExpression,
|
|
7
|
+
isPropertyAccessExpression,
|
|
8
|
+
isSatisfiesExpression,
|
|
9
|
+
} from "typescript/unstable/ast/is";
|
|
10
|
+
|
|
11
|
+
const PIPE = "pipe";
|
|
12
|
+
|
|
13
|
+
const isWrapper = (node: Node) =>
|
|
14
|
+
isParenthesizedExpression(node) ||
|
|
15
|
+
isAsExpression(node) ||
|
|
16
|
+
isSatisfiesExpression(node) ||
|
|
17
|
+
isNonNullExpression(node);
|
|
18
|
+
|
|
19
|
+
export const withoutWrappers = (node: Node): Node =>
|
|
20
|
+
isWrapper(node) ? withoutWrappers(node.expression) : node;
|
|
21
|
+
|
|
22
|
+
export const outermostWrapperOf = (node: Node): Node =>
|
|
23
|
+
isWrapper(node.parent) ? outermostWrapperOf(node.parent) : node;
|
|
24
|
+
|
|
25
|
+
export const referencedNameOf = (node: Node) => {
|
|
26
|
+
const reference = withoutWrappers(node);
|
|
27
|
+
if (isPropertyAccessExpression(reference)) {
|
|
28
|
+
return reference.name;
|
|
29
|
+
}
|
|
30
|
+
return isIdentifier(reference) ? reference : undefined;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export const pipedStepsOf = (call: CallExpression) => {
|
|
34
|
+
if (referencedNameOf(call.expression)?.text !== PIPE) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
const callee = withoutWrappers(call.expression);
|
|
38
|
+
return isPropertyAccessExpression(callee)
|
|
39
|
+
? [callee.expression, ...call.arguments]
|
|
40
|
+
: [...call.arguments];
|
|
41
|
+
};
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { ReportedErrors } from "@sshkeda/task/errors";
|
|
2
|
+
import type { PrintableError } from "@sshkeda/task/errors";
|
|
3
|
+
import { Array as Arrays, Effect, Path } from "effect";
|
|
4
|
+
|
|
5
|
+
import { printableError } from "../../../shared/format-reported-failures.ts";
|
|
6
|
+
import { projectDirectory } from "../../project-directory/index.ts";
|
|
7
|
+
|
|
8
|
+
const locationFromTheProject = (
|
|
9
|
+
pathModule: Path.Path,
|
|
10
|
+
checkedProject: string,
|
|
11
|
+
location: string,
|
|
12
|
+
) => {
|
|
13
|
+
if (!pathModule.isAbsolute(location)) {
|
|
14
|
+
return location;
|
|
15
|
+
}
|
|
16
|
+
const fromTheProject = pathModule.relative(checkedProject, location);
|
|
17
|
+
const isInsideTheProject =
|
|
18
|
+
fromTheProject !== "" &&
|
|
19
|
+
!fromTheProject.startsWith("..") &&
|
|
20
|
+
!pathModule.isAbsolute(fromTheProject);
|
|
21
|
+
return isInsideTheProject ? fromTheProject : location;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
const locatedWith = Effect.gen(function* () {
|
|
25
|
+
const pathModule = yield* Path.Path;
|
|
26
|
+
const checkedProject = pathModule.resolve(
|
|
27
|
+
yield* projectDirectory.pipe(
|
|
28
|
+
Effect.mapError(
|
|
29
|
+
(configError) => new ReportedErrors({ reportedErrors: [printableError(configError)] }),
|
|
30
|
+
),
|
|
31
|
+
),
|
|
32
|
+
);
|
|
33
|
+
return ({ tag, location, message }: PrintableError): PrintableError => ({
|
|
34
|
+
tag,
|
|
35
|
+
...(location === undefined
|
|
36
|
+
? {}
|
|
37
|
+
: { location: locationFromTheProject(pathModule, checkedProject, location) }),
|
|
38
|
+
message,
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
export const printedFromTheProject = (printables: readonly PrintableError[]) =>
|
|
43
|
+
locatedWith.pipe(Effect.map((located) => printables.map((printable) => located(printable))));
|
|
44
|
+
|
|
45
|
+
export const locatedFromTheProject = <Success, Requirements>(
|
|
46
|
+
effect: Effect.Effect<Success, ReportedErrors, Requirements>,
|
|
47
|
+
) =>
|
|
48
|
+
effect.pipe(
|
|
49
|
+
Effect.catchTag("ReportedErrors", ({ reportedErrors }) =>
|
|
50
|
+
locatedWith.pipe(
|
|
51
|
+
Effect.flatMap((located) =>
|
|
52
|
+
Effect.fail(new ReportedErrors({ reportedErrors: Arrays.map(reportedErrors, located) })),
|
|
53
|
+
),
|
|
54
|
+
),
|
|
55
|
+
),
|
|
56
|
+
);
|
|
@@ -61,7 +61,6 @@ export const isDeclaredSync = (name: string) =>
|
|
|
61
61
|
export const TASK_PACKAGE = "@sshkeda/task";
|
|
62
62
|
export const TASK_NAMESPACE_EXPORT = "Task";
|
|
63
63
|
export const TASK_MAKE_MEMBER = "make";
|
|
64
|
-
export const TASK_MAIN_MEMBER = "main";
|
|
65
64
|
|
|
66
65
|
export const IMPORT_META = "import.meta";
|
|
67
66
|
|
|
@@ -108,7 +107,6 @@ const CREATE_REQUIRE_IMPORTS = ["createRequire", "Module.createRequire"] as cons
|
|
|
108
107
|
export const CREATED_REQUIRE_USAGE = "a require createRequire returns";
|
|
109
108
|
export const CREATE_REQUIRE_VALUE_USAGE = "createRequire used other than by a call";
|
|
110
109
|
|
|
111
|
-
export const SCRIPT = "script";
|
|
112
110
|
export const TRUSTS_UNVERIFIED_TYPES = "trustsUnverifiedTypes";
|
|
113
111
|
export const WRITES_TO_THE_TERMINAL = "writesToTheTerminal";
|
|
114
112
|
export const READS_CONFIG = "readsConfig";
|
|
@@ -388,11 +386,6 @@ export const PERMISSION_BANS = {
|
|
|
388
386
|
memberNamesBan([...SYNC_READS, ...SYNC_WRITES]),
|
|
389
387
|
],
|
|
390
388
|
},
|
|
391
|
-
[SCRIPT]: {
|
|
392
|
-
ruleName: "no-task-main",
|
|
393
|
-
message: "{{usage}} runs tasks outside a script",
|
|
394
|
-
bans: [importsBan(TASK_PACKAGE, [`${TASK_NAMESPACE_EXPORT}.${TASK_MAIN_MEMBER}`])],
|
|
395
|
-
},
|
|
396
389
|
};
|
|
397
390
|
|
|
398
391
|
export const PERMISSION_BAN_NAMES = Record.keys(PERMISSION_BANS);
|
|
@@ -1,16 +1,18 @@
|
|
|
1
|
-
import type { PrintableError } from "@sshkeda/task/errors";
|
|
2
|
-
|
|
3
1
|
export const printableError = (failure: {
|
|
4
2
|
readonly _tag: string;
|
|
5
3
|
readonly message: string;
|
|
6
4
|
readonly location?: string;
|
|
7
|
-
})
|
|
5
|
+
}) => ({
|
|
8
6
|
tag: failure._tag,
|
|
9
7
|
...(failure.location === undefined ? {} : { location: failure.location }),
|
|
10
8
|
message: failure.message,
|
|
11
9
|
});
|
|
12
10
|
|
|
13
|
-
export const formattedError = (printable:
|
|
11
|
+
export const formattedError = (printable: {
|
|
12
|
+
readonly tag: string;
|
|
13
|
+
readonly location?: string | undefined;
|
|
14
|
+
readonly message: string;
|
|
15
|
+
}) => {
|
|
14
16
|
const [firstLine = "", ...continuationLines] = printable.message.split("\n");
|
|
15
17
|
return [
|
|
16
18
|
`${printable.location === undefined ? "" : `${printable.location}: `}error ${printable.tag}: ${firstLine}`,
|
|
@@ -22,9 +24,9 @@ export const listedViolations = (violations: readonly Parameters<typeof printabl
|
|
|
22
24
|
violations.map((found) => formattedError(printableError(found))).join("\n");
|
|
23
25
|
|
|
24
26
|
export const printableErrorWith = (
|
|
25
|
-
printable:
|
|
27
|
+
printable: Parameters<typeof formattedError>[0],
|
|
26
28
|
replacement: { readonly tag?: string; readonly message?: string },
|
|
27
|
-
)
|
|
29
|
+
) => ({
|
|
28
30
|
tag: replacement.tag ?? printable.tag,
|
|
29
31
|
...(printable.location === undefined ? {} : { location: printable.location }),
|
|
30
32
|
message: replacement.message ?? printable.message,
|
|
@@ -8,7 +8,6 @@ import {
|
|
|
8
8
|
PERMISSION_BANS,
|
|
9
9
|
READS_CONFIG,
|
|
10
10
|
RULES_EACH_PERMISSION_LIFTS,
|
|
11
|
-
SCRIPT,
|
|
12
11
|
SHORT_NAMES,
|
|
13
12
|
TRUSTS_UNVERIFIED_TYPES,
|
|
14
13
|
UNUSED_GRANT_REPORTED,
|
|
@@ -62,7 +61,7 @@ export const PERMISSION_NAMES = [
|
|
|
62
61
|
|
|
63
62
|
const RETIRED_PERMISSIONS = new Map([
|
|
64
63
|
["errors", "error classes may be declared in any file"],
|
|
65
|
-
[
|
|
64
|
+
["script", `files directly in ${SCRIPTS_DIRECTORY}/ run tasks`],
|
|
66
65
|
]);
|
|
67
66
|
|
|
68
67
|
export const isMarkdown = (path: string) =>
|
|
@@ -362,7 +361,9 @@ export const rulesACodeGrantChanges = (
|
|
|
362
361
|
|
|
363
362
|
const SCRIPTS_OVERRIDE = {
|
|
364
363
|
files: [`./${SCRIPTS_DIRECTORY}/*`],
|
|
365
|
-
rules: {
|
|
364
|
+
rules: {
|
|
365
|
+
"sshkeda/no-re-exports": ["error", { defaultExportOfAnImport: "allowed" }],
|
|
366
|
+
},
|
|
366
367
|
} as const;
|
|
367
368
|
|
|
368
369
|
const DECODE_OPTIONS = {
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { defineRule } from "@oxlint/plugins";
|
|
2
|
-
|
|
3
|
-
export const noShebang = defineRule({
|
|
4
|
-
meta: {
|
|
5
|
-
type: "suggestion",
|
|
6
|
-
messages: {
|
|
7
|
-
shebang: "file starts with a shebang line",
|
|
8
|
-
},
|
|
9
|
-
},
|
|
10
|
-
create(context) {
|
|
11
|
-
return {
|
|
12
|
-
Program() {
|
|
13
|
-
const shebang = context.sourceCode
|
|
14
|
-
.getAllComments()
|
|
15
|
-
.find((comment) => comment.type === "Shebang");
|
|
16
|
-
if (shebang !== undefined) {
|
|
17
|
-
context.report({ loc: shebang.loc, messageId: "shebang" });
|
|
18
|
-
}
|
|
19
|
-
},
|
|
20
|
-
};
|
|
21
|
-
},
|
|
22
|
-
});
|
|
@@ -1,178 +0,0 @@
|
|
|
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)));
|