@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
|
@@ -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
|
);
|
|
@@ -7,5 +7,5 @@ import { checkTypesWithBunCheckIn } from "./internal/check-types-with-bun-check.
|
|
|
7
7
|
|
|
8
8
|
export const typeCheck = Task.make(
|
|
9
9
|
"type-check",
|
|
10
|
-
Effect.andThen(typeScriptConfig, inEachPackage("type-check",
|
|
10
|
+
Effect.andThen(typeScriptConfig, inEachPackage("type-check", checkTypesWithBunCheckIn)),
|
|
11
11
|
);
|
|
@@ -3,8 +3,10 @@ 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";
|
|
6
7
|
import { listedPackageFiles } from "./list-package-files.ts";
|
|
7
8
|
import { quietViolations } from "./print-failures-and-keep-detail-in-the-trace.ts";
|
|
9
|
+
import { locatedFromTheProject, printedFromTheProject } from "./report-paths-from-the-project.ts";
|
|
8
10
|
|
|
9
11
|
const CHECKED_PACKAGE = ".";
|
|
10
12
|
|
|
@@ -39,7 +41,7 @@ const locatedInPackage = (
|
|
|
39
41
|
message: printable.message,
|
|
40
42
|
};
|
|
41
43
|
|
|
42
|
-
const distinctPrintedErrors = (printables: readonly PrintableError[]) => {
|
|
44
|
+
export const distinctPrintedErrors = (printables: readonly PrintableError[]) => {
|
|
43
45
|
const printedByLocation = new Map<string | undefined, Set<string>>();
|
|
44
46
|
return printables.filter(({ tag, location, message }) => {
|
|
45
47
|
const printed = printedByLocation.get(location) ?? new Set<string>();
|
|
@@ -61,18 +63,22 @@ export const packageDirectoriesIn = (directory: string) =>
|
|
|
61
63
|
|
|
62
64
|
export const inEachPackage = <Requirements>(
|
|
63
65
|
tool: string,
|
|
64
|
-
directory: string,
|
|
65
66
|
checkPackage: (
|
|
66
67
|
packageDirectory: string,
|
|
68
|
+
packageDirectoryFromTheProject: string,
|
|
67
69
|
) => Effect.Effect<void, PlatformError.PlatformError | ReportedErrors, Requirements>,
|
|
68
70
|
) =>
|
|
69
71
|
Effect.gen(function* () {
|
|
70
72
|
const pathModule = yield* Path.Path;
|
|
71
|
-
const
|
|
73
|
+
const checkedProject = yield* projectDirectory.pipe(quietViolations(tool));
|
|
74
|
+
const packageDirectories = yield* packageDirectoriesIn(checkedProject).pipe(
|
|
75
|
+
quietViolations(tool),
|
|
76
|
+
locatedFromTheProject,
|
|
77
|
+
);
|
|
72
78
|
const reportedByPackage = yield* Effect.forEach(
|
|
73
79
|
packageDirectories,
|
|
74
80
|
(packageDirectory) =>
|
|
75
|
-
checkPackage(pathModule.join(
|
|
81
|
+
checkPackage(pathModule.join(checkedProject, packageDirectory), packageDirectory).pipe(
|
|
76
82
|
Effect.as([]),
|
|
77
83
|
Effect.catchTag("ReportedErrors", ({ reportedErrors }) =>
|
|
78
84
|
Effect.succeed(
|
|
@@ -84,7 +90,9 @@ export const inEachPackage = <Requirements>(
|
|
|
84
90
|
),
|
|
85
91
|
{ concurrency: "unbounded" },
|
|
86
92
|
);
|
|
87
|
-
const reportedErrors = distinctPrintedErrors(
|
|
93
|
+
const reportedErrors = distinctPrintedErrors(
|
|
94
|
+
yield* printedFromTheProject(reportedByPackage.flat()),
|
|
95
|
+
);
|
|
88
96
|
if (Arrays.isArrayNonEmpty(reportedErrors)) {
|
|
89
97
|
return yield* new ReportedErrors({ reportedErrors });
|
|
90
98
|
}
|
|
@@ -8,7 +8,7 @@ import { ProjectQueryCachesLive } from "./provide-project-query-caches.ts";
|
|
|
8
8
|
|
|
9
9
|
export const lintConfigFile = Task.make(
|
|
10
10
|
"lint-config",
|
|
11
|
-
inEachPackage("lint-config",
|
|
11
|
+
inEachPackage("lint-config", (packageDirectory) =>
|
|
12
12
|
loadedLintConfigIn(packageDirectory).pipe(Effect.asVoid, quietViolations("lint-config")),
|
|
13
13
|
).pipe(Effect.provide(ProjectQueryCachesLive)),
|
|
14
14
|
);
|
|
@@ -28,7 +28,7 @@ const locatedFromThePackage = (
|
|
|
28
28
|
|
|
29
29
|
export const typeScriptConfig = Task.make(
|
|
30
30
|
"typescript-config",
|
|
31
|
-
inEachPackage("typescript-config",
|
|
31
|
+
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"),
|
|
@@ -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 = (
|
|
@@ -3,6 +3,7 @@ import { Effect, FileSystem, Option, Path, References } from "effect";
|
|
|
3
3
|
|
|
4
4
|
import { enclosingDirectoriesOf } from "./classify-files-by-role.ts";
|
|
5
5
|
import { PACKAGE_MANIFEST_FILE } from "./find-named-package-manifests.ts";
|
|
6
|
+
import { isSymbolicLink } from "./find-symbolic-links.ts";
|
|
6
7
|
import { namedPackageManifestAt } from "./read-named-package-manifests.ts";
|
|
7
8
|
|
|
8
9
|
const isNamedPackageDirectory = (directory: string) =>
|
|
@@ -29,9 +30,21 @@ export const nestedPackageDirectoriesAmong = (
|
|
|
29
30
|
export const isInsideAnyDirectory = (relativePath: string, directories: readonly string[]) =>
|
|
30
31
|
directories.some((directory) => relativePath.startsWith(`${directory}/`));
|
|
31
32
|
|
|
32
|
-
const
|
|
33
|
+
const isExistingNonDirectory = (location: string) =>
|
|
33
34
|
Effect.gen(function* () {
|
|
34
35
|
const fileSystem = yield* FileSystem.FileSystem;
|
|
36
|
+
const exists = yield* fileSystem.exists(location);
|
|
37
|
+
if (!exists) {
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
if (yield* isSymbolicLink(location)) {
|
|
41
|
+
return true;
|
|
42
|
+
}
|
|
43
|
+
return (yield* fileSystem.stat(location)).type !== "Directory";
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
const existingListedFiles = (packageDirectory: string, pathspecs: readonly string[]) =>
|
|
47
|
+
Effect.gen(function* () {
|
|
35
48
|
const path = yield* Path.Path;
|
|
36
49
|
const listed = yield* Task.exec(
|
|
37
50
|
"git",
|
|
@@ -40,7 +53,7 @@ const existingListedFiles = (packageDirectory: string, pathspecs: readonly strin
|
|
|
40
53
|
).pipe(Effect.provideService(References.MinimumLogLevel, "Warn"));
|
|
41
54
|
return yield* Effect.filter(
|
|
42
55
|
new Set(listed.split("\0").filter((file) => file !== "")),
|
|
43
|
-
(file) =>
|
|
56
|
+
(file) => isExistingNonDirectory(path.join(packageDirectory, file)),
|
|
44
57
|
{ concurrency: "unbounded" },
|
|
45
58
|
);
|
|
46
59
|
});
|
|
@@ -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
|
+
);
|
|
@@ -401,6 +401,9 @@ export const BANS_NO_GRANT_LIFTS = "onlyThoseNoGrantLifts";
|
|
|
401
401
|
|
|
402
402
|
export const UNUSED_GRANT_REPORTED = "reported";
|
|
403
403
|
|
|
404
|
+
export const unusedGrantMessage = (permission: string) =>
|
|
405
|
+
`this file is granted ${permission}, but uses nothing ${permission} allows`;
|
|
406
|
+
|
|
404
407
|
export const bansNoGrantLifts = (permission: keyof typeof PERMISSION_BANS) => {
|
|
405
408
|
const entry = PERMISSION_BANS[permission];
|
|
406
409
|
return "bannedEvenWhenGranted" in entry ? entry.bannedEvenWhenGranted.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,
|
|
@@ -16,7 +16,7 @@ import {
|
|
|
16
16
|
} from "./bans-each-permission-lifts.ts";
|
|
17
17
|
import { isWithin } from "./match-file-names-and-path-prefixes.ts";
|
|
18
18
|
import { MalformedGrant, PermissionGrantsRefused } from "./permission-grant-errors.ts";
|
|
19
|
-
import { SCRIPTS_DIRECTORY, TEST_HOME } from "./test-home-directories.ts";
|
|
19
|
+
import { SCRIPTS_DIRECTORY, TEST_DIRECTORY, TEST_HOME } from "./test-home-directories.ts";
|
|
20
20
|
|
|
21
21
|
export const DIRECTORY = "isAnUnlistedDirectory";
|
|
22
22
|
export const GENERATED = "isGeneratedByATool";
|
|
@@ -26,11 +26,17 @@ export const TEST_TIMEOUTS_RULE = "no-test-timeouts";
|
|
|
26
26
|
export const TYPE_PREDICATES_RULE = "no-type-predicates";
|
|
27
27
|
export const STDIO_SERVICE_RULE = "no-stdio-service";
|
|
28
28
|
export const FAILURES_AS_RESULTS_RULE = "no-failures-as-results";
|
|
29
|
-
const UNNAMED_FALLBACKS_RULE = "no-unnamed-fallbacks";
|
|
29
|
+
export const UNNAMED_FALLBACKS_RULE = "no-unnamed-fallbacks";
|
|
30
|
+
export const FIXED_FALLBACKS = "fallsBackToFixedValues";
|
|
31
|
+
export const FIXED_FALLBACKS_RULE = "no-fixed-fallbacks";
|
|
32
|
+
export const FIXED_FALLBACKS_GRANTED = "granted";
|
|
30
33
|
const SCHEDULES = "pollsWithADeadline";
|
|
31
34
|
const TIMERS = "waitsOnTimers";
|
|
32
|
-
const
|
|
33
|
-
const
|
|
35
|
+
export const SCHEDULES_RULE = "no-schedules";
|
|
36
|
+
export const SLEEP_RULE = "no-sleep";
|
|
37
|
+
export const CLOCK_RULE = "no-clock-reads-and-sleeps";
|
|
38
|
+
export const UNUSED_CODE_GRANTS_RULE = "no-unused-code-grants";
|
|
39
|
+
export const INSIDE_THE_TEST_HOME = "inside";
|
|
34
40
|
const GLOB_CHARACTERS = /[*?[\]{}]/u;
|
|
35
41
|
const ROUTE_PARAMETER_SEGMENT = /^\[\[?(?:\.\.\.)?[A-Za-z0-9_-]+\]\]?$/u;
|
|
36
42
|
|
|
@@ -50,6 +56,7 @@ export const PERMISSION_NAMES = [
|
|
|
50
56
|
FILE_TYPE,
|
|
51
57
|
TRUSTS_UNVERIFIED_TYPES,
|
|
52
58
|
HANDLES_EVERY_FAILURE,
|
|
59
|
+
FIXED_FALLBACKS,
|
|
53
60
|
GENERATED,
|
|
54
61
|
] as const;
|
|
55
62
|
|
|
@@ -93,7 +100,7 @@ const rulesGrantedBy = (permission: (typeof PERMISSION_NAMES)[number]) => {
|
|
|
93
100
|
}
|
|
94
101
|
if (permission === SCHEDULES) {
|
|
95
102
|
return ruleSeverities({
|
|
96
|
-
|
|
103
|
+
[`sshkeda/${SCHEDULES_RULE}`]: ["error", { timedSchedules: "allowedWithDeadline" }],
|
|
97
104
|
[`sshkeda/${TEST_TIMEOUTS_RULE}`]: "off",
|
|
98
105
|
} as const);
|
|
99
106
|
}
|
|
@@ -116,6 +123,11 @@ const rulesGrantedBy = (permission: (typeof PERMISSION_NAMES)[number]) => {
|
|
|
116
123
|
[`sshkeda/${UNNAMED_FALLBACKS_RULE}`]: "off",
|
|
117
124
|
} as const);
|
|
118
125
|
}
|
|
126
|
+
if (permission === FIXED_FALLBACKS) {
|
|
127
|
+
return ruleSeverities({
|
|
128
|
+
[`sshkeda/${FIXED_FALLBACKS_RULE}`]: ["error", { fixedFallbacks: FIXED_FALLBACKS_GRANTED }],
|
|
129
|
+
} as const);
|
|
130
|
+
}
|
|
119
131
|
if (permission === TRUSTS_UNVERIFIED_TYPES) {
|
|
120
132
|
return ruleSeverities({
|
|
121
133
|
[permissionBanRuleId(permission)]: "off",
|
|
@@ -135,6 +147,16 @@ const rulesGrantedBy = (permission: (typeof PERMISSION_NAMES)[number]) => {
|
|
|
135
147
|
} as const);
|
|
136
148
|
};
|
|
137
149
|
|
|
150
|
+
export const CODE_GRANTS = [
|
|
151
|
+
HANDLES_EVERY_FAILURE,
|
|
152
|
+
TIMERS,
|
|
153
|
+
SCHEDULES,
|
|
154
|
+
SHORT_NAMES,
|
|
155
|
+
TRUSTS_UNVERIFIED_TYPES,
|
|
156
|
+
] as const;
|
|
157
|
+
|
|
158
|
+
const isCodeGrant = Schema.is(Schema.Literals(CODE_GRANTS));
|
|
159
|
+
|
|
138
160
|
const ABORT_ON_FAILURE = true;
|
|
139
161
|
|
|
140
162
|
const pathRule = (isAllowed: (path: string) => boolean, violation: (path: string) => string) =>
|
|
@@ -278,12 +300,23 @@ const GRANTS_AGAINST_THEIR_PATHS = Schema.Record(Schema.String, Schema.Unknown).
|
|
|
278
300
|
|
|
279
301
|
const STANDARD_SCHEMA_ISSUES = SchemaIssue.makeFormatterStandardSchemaV1();
|
|
280
302
|
|
|
303
|
+
const unusedCodeGrantsRule = (path: string, permissions: readonly string[]) => {
|
|
304
|
+
const codeGrants = permissions.filter((permission) => isCodeGrant(permission));
|
|
305
|
+
const place = isWithin(path, TEST_DIRECTORY) ? { testHome: INSIDE_THE_TEST_HOME } : {};
|
|
306
|
+
return codeGrants.length > 0
|
|
307
|
+
? Object.entries({
|
|
308
|
+
[`sshkeda/${UNUSED_CODE_GRANTS_RULE}`]: ["error", { permissions: codeGrants, ...place }],
|
|
309
|
+
} as const)
|
|
310
|
+
: [];
|
|
311
|
+
};
|
|
312
|
+
|
|
281
313
|
const grantOverride = (
|
|
282
314
|
grant: Extract<ReturnType<typeof recordedGrantsOf>, { grants: unknown }>["grants"][number],
|
|
283
315
|
) => ({
|
|
284
316
|
files: [`./${grant.path.replaceAll("[", String.raw`\[`).replaceAll("]", String.raw`\]`)}`],
|
|
285
317
|
rules: {
|
|
286
318
|
...Object.fromEntries(grant.allow.flatMap((permission) => rulesGrantedBy(permission))),
|
|
319
|
+
...Object.fromEntries(unusedCodeGrantsRule(grant.path, grant.allow)),
|
|
287
320
|
...Object.fromEntries(
|
|
288
321
|
grant.services.length > 0
|
|
289
322
|
? Object.entries({
|
|
@@ -300,16 +333,39 @@ const TEST_HOME_OVERRIDE = {
|
|
|
300
333
|
rules: {
|
|
301
334
|
"sshkeda/no-testing-helpers": "off",
|
|
302
335
|
"sshkeda/no-assertions": "off",
|
|
303
|
-
|
|
336
|
+
[`sshkeda/${SCHEDULES_RULE}`]: "off",
|
|
337
|
+
[`sshkeda/${FIXED_FALLBACKS_RULE}`]: "off",
|
|
304
338
|
"sshkeda/no-instant-retries": "off",
|
|
305
339
|
"sshkeda/no-shared-holders": "off",
|
|
306
340
|
[`sshkeda/${TEST_TIMEOUTS_RULE}`]: "error",
|
|
307
341
|
},
|
|
308
342
|
} as const;
|
|
309
343
|
|
|
344
|
+
const TEST_HOME_SEVERITIES: ReadonlyMap<string, string> = new Map(
|
|
345
|
+
Object.entries(TEST_HOME_OVERRIDE.rules),
|
|
346
|
+
);
|
|
347
|
+
|
|
348
|
+
const isOnWithoutAGrant = (ruleId: string, isInTheTestHome: boolean) => {
|
|
349
|
+
const testHomeSeverity = TEST_HOME_SEVERITIES.get(ruleId);
|
|
350
|
+
return isInTheTestHome ? testHomeSeverity !== "off" : testHomeSeverity !== "error";
|
|
351
|
+
};
|
|
352
|
+
|
|
353
|
+
export const rulesACodeGrantChanges = (
|
|
354
|
+
permission: (typeof CODE_GRANTS)[number],
|
|
355
|
+
isInTheTestHome: boolean,
|
|
356
|
+
) =>
|
|
357
|
+
rulesGrantedBy(permission).map(([ruleId, granted]) => ({
|
|
358
|
+
ruleId,
|
|
359
|
+
granted,
|
|
360
|
+
isOnWithoutTheGrant: isOnWithoutAGrant(ruleId, isInTheTestHome),
|
|
361
|
+
}));
|
|
362
|
+
|
|
310
363
|
const SCRIPTS_OVERRIDE = {
|
|
311
364
|
files: [`./${SCRIPTS_DIRECTORY}/*`],
|
|
312
|
-
rules: {
|
|
365
|
+
rules: {
|
|
366
|
+
[permissionBanRuleId(SCRIPT)]: "off",
|
|
367
|
+
"sshkeda/no-re-exports": ["error", { defaultExportOfAnImport: "allowed" }],
|
|
368
|
+
},
|
|
313
369
|
} as const;
|
|
314
370
|
|
|
315
371
|
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
|
-
});
|
|
File without changes
|