@sshkeda/check 2.2.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 +1 -0
- package/package.json +7 -10
- package/scripts/check.ts +10 -0
- 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 +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/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 +16 -15
- 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 +12 -4
- 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/read-piped-steps-through-wrappers.ts +41 -0
- package/src/lib/tasks/shared/report-paths-from-the-project.ts +56 -0
- package/src/shared/format-reported-failures.ts +8 -6
- package/src/shared/record-and-grant-permissions-by-path.ts +4 -1
- package/src/internal/ban-shebang-lines.ts +0 -22
|
@@ -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
|
);
|
|
@@ -16,8 +16,6 @@ import {
|
|
|
16
16
|
} from "../../../shared/run-tools-and-decode-their-reports.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
|
+
});
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Schema } from "effect";
|
|
2
|
+
|
|
3
|
+
import { listedViolations } from "../../../../../shared/format-reported-failures.ts";
|
|
4
|
+
import { PACKAGE_MANIFEST_FILE } from "../../../shared/find-named-package-manifests.ts";
|
|
5
|
+
|
|
6
|
+
export class ShebangOutsideBin extends Schema.TaggedError<ShebangOutsideBin>()(
|
|
7
|
+
"ShebangOutsideBin",
|
|
8
|
+
{ location: Schema.String },
|
|
9
|
+
) {
|
|
10
|
+
public override get message() {
|
|
11
|
+
return `starts with a shebang line, but ${PACKAGE_MANIFEST_FILE} does not list it under bin`;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export class ShebangsOutsideBin extends Schema.TaggedError<ShebangsOutsideBin>()(
|
|
16
|
+
"ShebangsOutsideBin",
|
|
17
|
+
{ violations: Schema.Array(ShebangOutsideBin) },
|
|
18
|
+
) {
|
|
19
|
+
public override get message() {
|
|
20
|
+
return listedViolations(this.violations);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -376,6 +376,7 @@ export const findExportPlacementViolations = <Failure, Requirements>(
|
|
|
376
376
|
reach,
|
|
377
377
|
exportsAreReadFromOutside,
|
|
378
378
|
roots,
|
|
379
|
+
runsItsDefaultExport,
|
|
379
380
|
reachable,
|
|
380
381
|
moduleDirectories,
|
|
381
382
|
} = graph;
|
|
@@ -402,6 +403,7 @@ export const findExportPlacementViolations = <Failure, Requirements>(
|
|
|
402
403
|
: [],
|
|
403
404
|
),
|
|
404
405
|
);
|
|
406
|
+
const servedByThePackage = reach(graph.binaryEntries, (use) => use.kind !== "type");
|
|
405
407
|
const isServedOnlyToScripts = (file: string) =>
|
|
406
408
|
isWithin(file, SOURCE_DIRECTORY) &&
|
|
407
409
|
!builtByScripts.has(file) &&
|
|
@@ -506,6 +508,10 @@ export const findExportPlacementViolations = <Failure, Requirements>(
|
|
|
506
508
|
continue;
|
|
507
509
|
}
|
|
508
510
|
for (const [name, { line }] of parsed.exports) {
|
|
511
|
+
const isATaskDefaultExport = name === DEFAULT_EXPORT && runsItsDefaultExport.has(file);
|
|
512
|
+
if (isATaskDefaultExport) {
|
|
513
|
+
continue;
|
|
514
|
+
}
|
|
509
515
|
const location = `${file}:${line}`;
|
|
510
516
|
const recordedUsers = [...allUsersOf(file, name)];
|
|
511
517
|
const everyUser = recordedUsers.filter((user) => reachable.has(user));
|
|
@@ -518,7 +524,9 @@ export const findExportPlacementViolations = <Failure, Requirements>(
|
|
|
518
524
|
elsewhere.every(
|
|
519
525
|
(user) =>
|
|
520
526
|
isUnderTestDirectory(user) ||
|
|
521
|
-
(isWithin(user, SCRIPTS_DIRECTORY) &&
|
|
527
|
+
(isWithin(user, SCRIPTS_DIRECTORY) &&
|
|
528
|
+
!servedByThePackage.has(user) &&
|
|
529
|
+
isServedOnlyToScripts(file)),
|
|
522
530
|
) &&
|
|
523
531
|
!(usedInOwnFile && elsewhere.length > 0) &&
|
|
524
532
|
(elsewhere.length === 0 || !isWithin(file, SCRIPTS_DIRECTORY));
|
|
@@ -16,9 +16,12 @@ import {
|
|
|
16
16
|
packagePathOf,
|
|
17
17
|
} from "../../../shared/classify-files-by-role.ts";
|
|
18
18
|
import { lineNumbersIn, lineOfTheFirstLabel } from "../../../shared/count-the-line-of-an-offset.ts";
|
|
19
|
+
import { listedBinaryFilesOf } from "../../../shared/find-installed-package-binaries.ts";
|
|
19
20
|
import { moduleRequestsIn, URL_REQUESTS } from "../../../shared/find-module-requests.ts";
|
|
20
21
|
import type { MODULE_REQUEST_KINDS } from "../../../shared/find-module-requests.ts";
|
|
22
|
+
import { PACKAGE_MANIFEST_FILE } from "../../../shared/find-named-package-manifests.ts";
|
|
21
23
|
import { existingPackageFiles } from "../../../shared/list-package-files.ts";
|
|
24
|
+
import { rootManifestIn } from "../../../shared/match-granted-patch-files.ts";
|
|
22
25
|
import { isFormatConfigTextRefusedIn } from "../../../shared/parse-config-files-that-import-from-check.ts";
|
|
23
26
|
import {
|
|
24
27
|
BunConfigInvalid,
|
|
@@ -33,6 +36,7 @@ import {
|
|
|
33
36
|
import { resolveModuleRequest } from "../../../shared/resolve-module-requests.ts";
|
|
34
37
|
import { ImportUnresolvableInTheImportBoundaryCheck } from "./export-placement-errors.ts";
|
|
35
38
|
import { packageEntrySourcesAmong } from "./find-package-entry-sources.ts";
|
|
39
|
+
import { makesATaskInItsDefaultExport } from "./recognise-task-default-exports.ts";
|
|
36
40
|
|
|
37
41
|
export const EVERY_EXPORT = "*";
|
|
38
42
|
export const DEFAULT_EXPORT = "default";
|
|
@@ -190,6 +194,11 @@ export const findTheImporterGraph = (projectFile: string) =>
|
|
|
190
194
|
const text = yield* fileSystem.readFileString(path.join(packageDirectory, file));
|
|
191
195
|
files.set(file, yield* moduleUsesIn(file, text, resolverFor(file)));
|
|
192
196
|
}
|
|
197
|
+
const runsItsDefaultExport = new Set(
|
|
198
|
+
[...files].flatMap(([file, { parsed }]) =>
|
|
199
|
+
makesATaskInItsDefaultExport(parsed) ? [file] : [],
|
|
200
|
+
),
|
|
201
|
+
);
|
|
193
202
|
|
|
194
203
|
const trackedPackageFiles = new Set(
|
|
195
204
|
yield* existingPackageFiles(packageDirectory, [BUN_CONFIG_FILE]),
|
|
@@ -250,8 +259,18 @@ export const findTheImporterGraph = (projectFile: string) =>
|
|
|
250
259
|
...preloaded,
|
|
251
260
|
...testPreloaded,
|
|
252
261
|
]);
|
|
262
|
+
const binaryEntries = [
|
|
263
|
+
...listedBinaryFilesOf(
|
|
264
|
+
yield* rootManifestIn(
|
|
265
|
+
packageDirectory,
|
|
266
|
+
yield* existingPackageFiles(packageDirectory, [PACKAGE_MANIFEST_FILE]),
|
|
267
|
+
),
|
|
268
|
+
),
|
|
269
|
+
];
|
|
253
270
|
const reachable = reach([
|
|
254
271
|
...roots,
|
|
272
|
+
...binaryEntries,
|
|
273
|
+
...runsItsDefaultExport,
|
|
255
274
|
...[...files.keys()].filter((file) => isDeclarationFile(file) || isUnderTestDirectory(file)),
|
|
256
275
|
]);
|
|
257
276
|
const importers = new Map<string, Set<string>>();
|
|
@@ -278,6 +297,8 @@ export const findTheImporterGraph = (projectFile: string) =>
|
|
|
278
297
|
reach,
|
|
279
298
|
exportsAreReadFromOutside,
|
|
280
299
|
roots,
|
|
300
|
+
runsItsDefaultExport,
|
|
301
|
+
binaryEntries,
|
|
281
302
|
reachable,
|
|
282
303
|
moduleDirectories,
|
|
283
304
|
importersOf,
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import type { Expression, ParseResult } from "oxc-parser";
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
TASK_MAKE_MEMBER,
|
|
5
|
+
TASK_NAMESPACE_EXPORT,
|
|
6
|
+
TASK_PACKAGE,
|
|
7
|
+
} from "../../../../../shared/bans-each-permission-lifts.ts";
|
|
8
|
+
|
|
9
|
+
const TASK_GROUP_MEMBERS = ["all", "allSettled"] as const;
|
|
10
|
+
|
|
11
|
+
const MEMBERS_THAT_MAKE_TASKS: ReadonlySet<string> = new Set([
|
|
12
|
+
TASK_MAKE_MEMBER,
|
|
13
|
+
...TASK_GROUP_MEMBERS,
|
|
14
|
+
]);
|
|
15
|
+
|
|
16
|
+
const withoutWrappers = (expression: Expression): Expression => {
|
|
17
|
+
const isTransparentWrapper =
|
|
18
|
+
expression.type === "ParenthesizedExpression" ||
|
|
19
|
+
expression.type === "TSAsExpression" ||
|
|
20
|
+
expression.type === "TSSatisfiesExpression" ||
|
|
21
|
+
expression.type === "TSTypeAssertion" ||
|
|
22
|
+
expression.type === "TSNonNullExpression";
|
|
23
|
+
return isTransparentWrapper ? withoutWrappers(expression.expression) : expression;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
const importedMemberPath = (
|
|
27
|
+
expression: Expression,
|
|
28
|
+
imports: ReadonlyMap<string, readonly string[]>,
|
|
29
|
+
): readonly string[] | undefined => {
|
|
30
|
+
const unwrapped = withoutWrappers(expression);
|
|
31
|
+
if (unwrapped.type === "Identifier") {
|
|
32
|
+
return imports.get(unwrapped.name);
|
|
33
|
+
}
|
|
34
|
+
const isStaticMember =
|
|
35
|
+
unwrapped.type === "MemberExpression" &&
|
|
36
|
+
!unwrapped.computed &&
|
|
37
|
+
unwrapped.property.type === "Identifier";
|
|
38
|
+
if (!isStaticMember) {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
const object = importedMemberPath(unwrapped.object, imports);
|
|
42
|
+
return object === undefined ? undefined : [...object, unwrapped.property.name];
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
export const makesATaskInItsDefaultExport = (parsed: ParseResult) => {
|
|
46
|
+
const exported = parsed.program.body.find(
|
|
47
|
+
(statement) => statement.type === "ExportDefaultDeclaration",
|
|
48
|
+
);
|
|
49
|
+
const declaration =
|
|
50
|
+
exported?.type === "ExportDefaultDeclaration" ? exported.declaration : undefined;
|
|
51
|
+
const isNotAnExpression =
|
|
52
|
+
declaration === undefined ||
|
|
53
|
+
declaration.type === "FunctionDeclaration" ||
|
|
54
|
+
declaration.type === "ClassDeclaration" ||
|
|
55
|
+
declaration.type === "TSInterfaceDeclaration";
|
|
56
|
+
const value = isNotAnExpression ? undefined : withoutWrappers(declaration);
|
|
57
|
+
if (value?.type !== "CallExpression") {
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
60
|
+
const literalTaskImports = new Map(
|
|
61
|
+
parsed.module.staticImports
|
|
62
|
+
.filter((statement) => statement.moduleRequest.value === TASK_PACKAGE)
|
|
63
|
+
.flatMap((statement) => statement.entries)
|
|
64
|
+
.filter((entry) => !entry.isType)
|
|
65
|
+
.map(
|
|
66
|
+
(entry) =>
|
|
67
|
+
[
|
|
68
|
+
entry.localName.value,
|
|
69
|
+
entry.importName.kind === "NamespaceObject" ? [] : [entry.importName.name ?? ""],
|
|
70
|
+
] as const,
|
|
71
|
+
),
|
|
72
|
+
);
|
|
73
|
+
const member = importedMemberPath(value.callee, literalTaskImports) ?? [];
|
|
74
|
+
const isTaskMember = member.slice(0, -1).join(".") === TASK_NAMESPACE_EXPORT;
|
|
75
|
+
return isTaskMember && MEMBERS_THAT_MAKE_TASKS.has(member.at(-1) ?? "");
|
|
76
|
+
};
|
|
@@ -11,6 +11,6 @@ export const directives = Task.make(
|
|
|
11
11
|
"directives",
|
|
12
12
|
Effect.andThen(
|
|
13
13
|
Task.all([typeScriptConfig, lintConfigFile]),
|
|
14
|
-
inEachPackage("directives",
|
|
14
|
+
inEachPackage("directives", findDisableDirectivesInLintedFilesOf),
|
|
15
15
|
).pipe(Effect.provide(ProjectQueryCachesLive)),
|
|
16
16
|
);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { findUnobservedForkFailures } from "./internal/find-unobserved-fork-failures.ts";
|