@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
|
@@ -1,10 +1,6 @@
|
|
|
1
1
|
import { Effect, Schema } from "effect";
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
TASK_MAIN_MEMBER,
|
|
5
|
-
TASK_NAMESPACE_EXPORT,
|
|
6
|
-
TASK_PACKAGE,
|
|
7
|
-
} from "../../../../../shared/bans-each-permission-lifts.ts";
|
|
3
|
+
import { TASK_PACKAGE } from "../../../../../shared/bans-each-permission-lifts.ts";
|
|
8
4
|
import { LINT_CONFIG_FILE } from "../../../../../shared/config-file-names.ts";
|
|
9
5
|
import { listedViolations } from "../../../../../shared/format-reported-failures.ts";
|
|
10
6
|
import {
|
|
@@ -68,12 +64,12 @@ export class TopLevelNonScript extends Schema.TaggedError<TopLevelNonScript>()(
|
|
|
68
64
|
}
|
|
69
65
|
}
|
|
70
66
|
|
|
71
|
-
export class
|
|
72
|
-
"
|
|
67
|
+
export class TopLevelScriptWithoutDefaultExport extends Schema.TaggedError<TopLevelScriptWithoutDefaultExport>()(
|
|
68
|
+
"TopLevelScriptWithoutDefaultExport",
|
|
73
69
|
{ location: Schema.String },
|
|
74
70
|
) {
|
|
75
71
|
public override get message() {
|
|
76
|
-
return `sits directly in ${SCRIPTS_DIRECTORY}/ and
|
|
72
|
+
return `sits directly in ${SCRIPTS_DIRECTORY}/ and has no default export`;
|
|
77
73
|
}
|
|
78
74
|
}
|
|
79
75
|
|
|
@@ -82,7 +78,7 @@ export class TopLevelScriptHoldsOtherStatement extends Schema.TaggedError<TopLev
|
|
|
82
78
|
{ location: Schema.String },
|
|
83
79
|
) {
|
|
84
80
|
public override get message() {
|
|
85
|
-
return
|
|
81
|
+
return "holds a statement other than an import and export default task";
|
|
86
82
|
}
|
|
87
83
|
}
|
|
88
84
|
|
|
@@ -360,10 +356,9 @@ export class DirectoryGrantedPermissions extends Schema.TaggedError<DirectoryGra
|
|
|
360
356
|
}
|
|
361
357
|
}
|
|
362
358
|
|
|
363
|
-
const MISPLACEMENT_PLACES = ["root-
|
|
359
|
+
const MISPLACEMENT_PLACES = ["root-code-file", "docs-non-markdown"] as const;
|
|
364
360
|
|
|
365
361
|
const MISPLACEMENTS = {
|
|
366
|
-
"root-task-script": "is a task script at the package root",
|
|
367
362
|
"root-code-file": "is code at the package root",
|
|
368
363
|
"docs-non-markdown": `is not markdown but sits in ${DOCS_DIRECTORY}/`,
|
|
369
364
|
} satisfies Record<(typeof MISPLACEMENT_PLACES)[number], string>;
|
|
@@ -386,7 +381,7 @@ export class FileLayoutViolations extends Schema.TaggedError<FileLayoutViolation
|
|
|
386
381
|
MisplacedToolFile,
|
|
387
382
|
BunTestFileName,
|
|
388
383
|
TopLevelNonScript,
|
|
389
|
-
|
|
384
|
+
TopLevelScriptWithoutDefaultExport,
|
|
390
385
|
TopLevelScriptHoldsOtherStatement,
|
|
391
386
|
LibraryDirectory,
|
|
392
387
|
DirectoryOutsideModuleLayout,
|
|
@@ -1,13 +1,9 @@
|
|
|
1
1
|
import { Task } from "@sshkeda/task";
|
|
2
2
|
import { Effect, FileSystem, Option, Path, Predicate, References, Result, Schema } from "effect";
|
|
3
|
-
import { parseSync
|
|
4
|
-
import type {
|
|
3
|
+
import { parseSync } from "oxc-parser";
|
|
4
|
+
import type { ParseResult, Statement } from "oxc-parser";
|
|
5
5
|
|
|
6
|
-
import {
|
|
7
|
-
TASK_PACKAGE,
|
|
8
|
-
TASK_NAMESPACE_EXPORT,
|
|
9
|
-
TASK_MAIN_MEMBER,
|
|
10
|
-
} from "../../../../../shared/bans-each-permission-lifts.ts";
|
|
6
|
+
import { TASK_PACKAGE } from "../../../../../shared/bans-each-permission-lifts.ts";
|
|
11
7
|
import { retiredWordIn } from "../../../../../shared/find-retired-words.ts";
|
|
12
8
|
import {
|
|
13
9
|
isEntryFileName,
|
|
@@ -49,6 +45,7 @@ import {
|
|
|
49
45
|
directoriesNestedInLayoutDirectoriesOf,
|
|
50
46
|
} from "../../../shared/classify-files-by-role.ts";
|
|
51
47
|
import { lineNumbersIn } from "../../../shared/count-the-line-of-an-offset.ts";
|
|
48
|
+
import { listedBinaryFilesOf } from "../../../shared/find-installed-package-binaries.ts";
|
|
52
49
|
import { PACKAGE_MANIFEST_FILE } from "../../../shared/find-named-package-manifests.ts";
|
|
53
50
|
import { isInsideAnyDirectory, listedPackageFiles } from "../../../shared/list-package-files.ts";
|
|
54
51
|
import { loadedLintConfigIn } from "../../../shared/load-the-lint-config.ts";
|
|
@@ -64,7 +61,6 @@ import {
|
|
|
64
61
|
JSON_OBJECT,
|
|
65
62
|
packageManifestObject,
|
|
66
63
|
} from "../../../shared/read-package-manifest-object.ts";
|
|
67
|
-
import { absolutePathOf } from "../../../shared/resolve-absolute-paths.ts";
|
|
68
64
|
import { toolFileOf, toolFileIsPlaced } from "../../../shared/tool-file-locations.ts";
|
|
69
65
|
import {
|
|
70
66
|
BunTestFileName,
|
|
@@ -92,7 +88,7 @@ import {
|
|
|
92
88
|
MisplacedToolFile,
|
|
93
89
|
TopLevelNonScript,
|
|
94
90
|
TopLevelScriptHoldsOtherStatement,
|
|
95
|
-
|
|
91
|
+
TopLevelScriptWithoutDefaultExport,
|
|
96
92
|
UngrantedDocument,
|
|
97
93
|
UngrantedDirectory,
|
|
98
94
|
UnlistedPatchGranted,
|
|
@@ -109,7 +105,6 @@ import {
|
|
|
109
105
|
modulesWithLayoutDirectoryNamesAmong,
|
|
110
106
|
moduleWithLayoutDirectoryNameViolations,
|
|
111
107
|
} from "./find-module-layout-violations.ts";
|
|
112
|
-
import { taskImportsIn, isTaskLayoutFile } from "./resolve-task-imports.ts";
|
|
113
108
|
|
|
114
109
|
const KEBAB_CASE_PART = /^[a-z0-9]+(?:-[a-z0-9]+)*$/u;
|
|
115
110
|
const BUN_TEST_FILE_EXTENSION = /\.(?:test|spec)(?<extension>\.[^.]+)$/u;
|
|
@@ -161,137 +156,31 @@ export const pathViolations = (path: string, isNamedByBunPatch = false) => {
|
|
|
161
156
|
return violations;
|
|
162
157
|
};
|
|
163
158
|
|
|
164
|
-
const
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
const callsTaskMember = (
|
|
182
|
-
parsed: ParseResult,
|
|
183
|
-
member: string,
|
|
184
|
-
imports: ReadonlyMap<string, readonly string[]>,
|
|
185
|
-
) => {
|
|
186
|
-
const calls: CallExpression[] = [];
|
|
187
|
-
const aliases = new Map<string, Expression>();
|
|
188
|
-
new Visitor({
|
|
189
|
-
CallExpression(node) {
|
|
190
|
-
calls.push(node);
|
|
191
|
-
},
|
|
192
|
-
VariableDeclarator({ id, init: initializer }) {
|
|
193
|
-
const isNamedInitializer = id.type === "Identifier" && initializer !== null;
|
|
194
|
-
if (isNamedInitializer) {
|
|
195
|
-
aliases.set(id.name, initializer);
|
|
196
|
-
}
|
|
197
|
-
},
|
|
198
|
-
}).visit(parsed.program);
|
|
199
|
-
const taskReference = (
|
|
200
|
-
expression: Expression,
|
|
201
|
-
seen: ReadonlySet<string> = new Set(),
|
|
202
|
-
): readonly string[] | undefined => {
|
|
203
|
-
if (expression.type === "Identifier") {
|
|
204
|
-
const imported = imports.get(expression.name);
|
|
205
|
-
if (imported !== undefined) {
|
|
206
|
-
return imported;
|
|
207
|
-
}
|
|
208
|
-
const alias = aliases.get(expression.name);
|
|
209
|
-
const isUnfollowedAlias = alias !== undefined && !seen.has(expression.name);
|
|
210
|
-
return isUnfollowedAlias
|
|
211
|
-
? taskReference(alias, new Set([...seen, expression.name]))
|
|
212
|
-
: undefined;
|
|
213
|
-
}
|
|
214
|
-
const isStaticMember =
|
|
215
|
-
expression.type === "MemberExpression" &&
|
|
216
|
-
!expression.computed &&
|
|
217
|
-
expression.property.type === "Identifier";
|
|
218
|
-
if (!isStaticMember) {
|
|
219
|
-
return;
|
|
220
|
-
}
|
|
221
|
-
const object = taskReference(expression.object, seen);
|
|
222
|
-
return object === undefined ? undefined : [...object, expression.property.name];
|
|
223
|
-
};
|
|
224
|
-
return calls.some(
|
|
225
|
-
({ callee }) => taskReference(callee)?.join(".") === `${TASK_NAMESPACE_EXPORT}.${member}`,
|
|
226
|
-
);
|
|
227
|
-
};
|
|
228
|
-
|
|
229
|
-
const importedMemberPath = (
|
|
230
|
-
expression: Expression,
|
|
231
|
-
imports: ReadonlyMap<string, readonly string[]>,
|
|
232
|
-
): readonly string[] | undefined => {
|
|
233
|
-
if (expression.type === "Identifier") {
|
|
234
|
-
return imports.get(expression.name);
|
|
235
|
-
}
|
|
236
|
-
const isStaticMember =
|
|
237
|
-
expression.type === "MemberExpression" &&
|
|
238
|
-
!expression.computed &&
|
|
239
|
-
expression.property.type === "Identifier";
|
|
240
|
-
if (!isStaticMember) {
|
|
241
|
-
return;
|
|
242
|
-
}
|
|
243
|
-
const object = importedMemberPath(expression.object, imports);
|
|
244
|
-
return object === undefined ? undefined : [...object, expression.property.name];
|
|
245
|
-
};
|
|
246
|
-
|
|
247
|
-
const isMainGuard = (statement: Statement, imports: ReadonlyMap<string, readonly string[]>) => {
|
|
248
|
-
if (statement.type !== "IfStatement") {
|
|
249
|
-
return false;
|
|
250
|
-
}
|
|
251
|
-
const { test, consequent, alternate } = statement;
|
|
252
|
-
const testsImportMetaMain =
|
|
253
|
-
test.type === "MemberExpression" &&
|
|
254
|
-
!test.computed &&
|
|
255
|
-
test.object.type === "MetaProperty" &&
|
|
256
|
-
test.object.meta.name === "import" &&
|
|
257
|
-
test.object.property.name === "meta" &&
|
|
258
|
-
test.property.type === "Identifier" &&
|
|
259
|
-
test.property.name === "main";
|
|
260
|
-
const [only, ...others] = consequent.type === "BlockStatement" ? consequent.body : [];
|
|
261
|
-
const expression = only?.type === "ExpressionStatement" ? only.expression : undefined;
|
|
262
|
-
const call = expression?.type === "CallExpression" ? expression : undefined;
|
|
263
|
-
const [task, ...otherArguments] = call?.arguments ?? [];
|
|
264
|
-
const runsOneNamedTask =
|
|
265
|
-
call !== undefined &&
|
|
266
|
-
others.length === 0 &&
|
|
267
|
-
otherArguments.length === 0 &&
|
|
268
|
-
task?.type === "Identifier" &&
|
|
269
|
-
importedMemberPath(call.callee, imports)?.join(".") ===
|
|
270
|
-
`${TASK_NAMESPACE_EXPORT}.${TASK_MAIN_MEMBER}`;
|
|
271
|
-
return testsImportMetaMain && alternate === null && runsOneNamedTask;
|
|
272
|
-
};
|
|
273
|
-
|
|
274
|
-
const statementsOtherThanImportsAndMain = (
|
|
275
|
-
parsed: ParseResult,
|
|
276
|
-
imports: ReadonlyMap<string, readonly string[]>,
|
|
277
|
-
) => {
|
|
278
|
-
const nonImports = parsed.program.body.filter(
|
|
279
|
-
(statement) => statement.type !== "ImportDeclaration",
|
|
280
|
-
);
|
|
281
|
-
const firstGuard = nonImports.findIndex((statement) => isMainGuard(statement, imports));
|
|
282
|
-
return nonImports.filter((_statement, index) => index !== firstGuard);
|
|
159
|
+
const isDefaultExport = (statement: Statement) =>
|
|
160
|
+
statement.type === "ExportDefaultDeclaration" &&
|
|
161
|
+
statement.declaration.type !== "TSInterfaceDeclaration";
|
|
162
|
+
|
|
163
|
+
const statementsOtherThanImports = (parsed: ParseResult) =>
|
|
164
|
+
parsed.program.body.filter((statement) => statement.type !== "ImportDeclaration");
|
|
165
|
+
|
|
166
|
+
const defaultExportScriptViolations = (path: string, text: string, parsed: ParseResult) => {
|
|
167
|
+
const lineAt = lineNumbersIn(text);
|
|
168
|
+
return statementsOtherThanImports(parsed)
|
|
169
|
+
.filter((statement) => !isDefaultExport(statement))
|
|
170
|
+
.map(
|
|
171
|
+
(statement) =>
|
|
172
|
+
new TopLevelScriptHoldsOtherStatement({
|
|
173
|
+
location: `${path}:${lineAt(statement.start)}`,
|
|
174
|
+
}),
|
|
175
|
+
);
|
|
283
176
|
};
|
|
284
177
|
|
|
285
|
-
export const sourceViolations = (
|
|
286
|
-
path: string,
|
|
287
|
-
text: string,
|
|
288
|
-
resolvedImports?: ReadonlyMap<string, readonly string[]>,
|
|
289
|
-
) => {
|
|
178
|
+
export const sourceViolations = (path: string, text: string, isListedUnderBin = false) => {
|
|
290
179
|
const violations: (
|
|
291
180
|
| MisplacedAtPackageRoot
|
|
292
181
|
| SourceOutsideInternalOrShared
|
|
293
182
|
| TopLevelScriptHoldsOtherStatement
|
|
294
|
-
|
|
|
183
|
+
| TopLevelScriptWithoutDefaultExport
|
|
295
184
|
)[] = [];
|
|
296
185
|
const isMisplacedTool = toolFileOf(path) !== undefined && !toolFileIsPlaced(path);
|
|
297
186
|
if (isMisplacedTool) {
|
|
@@ -311,36 +200,21 @@ export const sourceViolations = (
|
|
|
311
200
|
violations.push(new SourceOutsideInternalOrShared({ location: path }));
|
|
312
201
|
}
|
|
313
202
|
|
|
314
|
-
const parsed = parseSync(path, text);
|
|
315
|
-
const imports = resolvedImports ?? directTaskImports(parsed);
|
|
316
203
|
const isRootCodeFile = !path.includes("/") && !isRootSupportFile(path);
|
|
317
204
|
if (isRootCodeFile) {
|
|
318
|
-
violations.push(
|
|
319
|
-
new MisplacedAtPackageRoot({
|
|
320
|
-
location: path,
|
|
321
|
-
place: callsTaskMember(parsed, TASK_MAIN_MEMBER, imports)
|
|
322
|
-
? "root-task-script"
|
|
323
|
-
: "root-code-file",
|
|
324
|
-
}),
|
|
325
|
-
);
|
|
205
|
+
violations.push(new MisplacedAtPackageRoot({ location: path, place: "root-code-file" }));
|
|
326
206
|
}
|
|
327
|
-
const
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
violations.push(new TopLevelScriptWithoutMain({ location: path }));
|
|
331
|
-
}
|
|
332
|
-
const isTopLevelScriptWithMain = isTopLevelScript(path) && !isTopLevelScriptWithoutMain;
|
|
333
|
-
if (isTopLevelScriptWithMain) {
|
|
334
|
-
const lineAt = lineNumbersIn(text);
|
|
335
|
-
violations.push(
|
|
336
|
-
...statementsOtherThanImportsAndMain(parsed, imports).map(
|
|
337
|
-
(statement) =>
|
|
338
|
-
new TopLevelScriptHoldsOtherStatement({
|
|
339
|
-
location: `${path}:${lineAt(statement.start)}`,
|
|
340
|
-
}),
|
|
341
|
-
),
|
|
342
|
-
);
|
|
207
|
+
const isTaskScript = isTopLevelScript(path) && !isListedUnderBin;
|
|
208
|
+
if (!isTaskScript) {
|
|
209
|
+
return violations;
|
|
343
210
|
}
|
|
211
|
+
const parsed = parseSync(path, text);
|
|
212
|
+
const hasDefaultExport = parsed.program.body.some((statement) => isDefaultExport(statement));
|
|
213
|
+
violations.push(
|
|
214
|
+
...(hasDefaultExport
|
|
215
|
+
? defaultExportScriptViolations(path, text, parsed)
|
|
216
|
+
: [new TopLevelScriptWithoutDefaultExport({ location: path })]),
|
|
217
|
+
);
|
|
344
218
|
return violations;
|
|
345
219
|
};
|
|
346
220
|
|
|
@@ -772,6 +646,7 @@ export const findFileLayoutViolations = (directory: string) =>
|
|
|
772
646
|
),
|
|
773
647
|
);
|
|
774
648
|
const rootManifest = yield* rootManifestIn(directory, paths);
|
|
649
|
+
const binaryFiles = listedBinaryFilesOf(rootManifest);
|
|
775
650
|
const generated = Option.match(grants, {
|
|
776
651
|
onNone: () => new Set<string>(),
|
|
777
652
|
onSome: generatedPathsOf,
|
|
@@ -818,18 +693,10 @@ export const findFileLayoutViolations = (directory: string) =>
|
|
|
818
693
|
return found;
|
|
819
694
|
}
|
|
820
695
|
const text = yield* fileSystem.readFileString(pathModule.join(directory, path));
|
|
821
|
-
const absoluteDirectory = yield* absolutePathOf(directory);
|
|
822
|
-
const imports = isTaskLayoutFile(path)
|
|
823
|
-
? yield* taskImportsIn(
|
|
824
|
-
pathModule.join(absoluteDirectory, path),
|
|
825
|
-
text,
|
|
826
|
-
absoluteDirectory,
|
|
827
|
-
)
|
|
828
|
-
: undefined;
|
|
829
696
|
return [
|
|
830
697
|
...found,
|
|
831
698
|
...(isScriptFile
|
|
832
|
-
? sourceViolations(path, text,
|
|
699
|
+
? sourceViolations(path, text, binaryFiles.has(path))
|
|
833
700
|
: yield* manifestViolations(path, text, repository)),
|
|
834
701
|
];
|
|
835
702
|
}),
|
|
@@ -4,7 +4,7 @@ import { Effect } from "effect";
|
|
|
4
4
|
import { ProjectQueryCachesLive } from "../../shared/provide-project-query-caches.ts";
|
|
5
5
|
import { fileTypeViolationsOfEachPackage } from "./internal/find-file-type-violations.ts";
|
|
6
6
|
|
|
7
|
-
export const fileTypes = Task.make(
|
|
8
|
-
"file-types",
|
|
9
|
-
fileTypeViolationsOfEachPackage.pipe(Effect.provide(ProjectQueryCachesLive)),
|
|
10
|
-
);
|
|
7
|
+
export const fileTypes = Task.make({
|
|
8
|
+
name: "file-types",
|
|
9
|
+
run: fileTypeViolationsOfEachPackage.pipe(Effect.provide(ProjectQueryCachesLive)),
|
|
10
|
+
});
|
|
@@ -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,67 +1,86 @@
|
|
|
1
1
|
import { Task } from "@sshkeda/task";
|
|
2
|
-
import { Effect, Path } from "effect";
|
|
2
|
+
import { Effect, Path, Schema } from "effect";
|
|
3
3
|
|
|
4
|
+
import { projectDirectory } from "../../../../project-directory/index.ts";
|
|
4
5
|
import { inEachPackage, packageDirectoriesIn } from "../../../shared/check-each-nested-package.ts";
|
|
6
|
+
import { startDirectory } from "../../../shared/declare-start-directory-task.ts";
|
|
5
7
|
import { ownedFilesAmong } from "../../../shared/list-owned-files.ts";
|
|
6
8
|
import { listedPackageFiles } from "../../../shared/list-package-files.ts";
|
|
7
9
|
import { quietViolations } from "../../../shared/print-failures-and-keep-detail-in-the-trace.ts";
|
|
8
10
|
import { ProjectQueryCachesLive } from "../../../shared/provide-project-query-caches.ts";
|
|
9
|
-
import {
|
|
10
|
-
|
|
11
|
-
unformattedFilesAmong,
|
|
12
|
-
} from "./check-formatting-with-bun-fmt.ts";
|
|
11
|
+
import { locatedFromTheProject } from "../../../shared/report-paths-from-the-project.ts";
|
|
12
|
+
import { unformattedFilesAmong } from "./check-formatting-with-bun-fmt.ts";
|
|
13
13
|
import { checkedFormatConfigIn } from "./find-format-config-violations.ts";
|
|
14
14
|
import { checkedFormatInputsIn } from "./find-format-input-violations.ts";
|
|
15
15
|
|
|
16
|
-
const ownedFilesOfPackage = (packageDirectory: string) =>
|
|
16
|
+
const ownedFilesOfPackage = (checkedProject: string, packageDirectory: string) =>
|
|
17
17
|
Effect.gen(function* () {
|
|
18
18
|
const path = yield* Path.Path;
|
|
19
|
-
const directory = path.join(
|
|
19
|
+
const directory = path.join(checkedProject, packageDirectory);
|
|
20
20
|
const { packageFiles } = yield* listedPackageFiles(directory, []);
|
|
21
|
-
return { directory, files: yield* ownedFilesAmong(directory, packageFiles) };
|
|
21
|
+
return { directory: packageDirectory, files: yield* ownedFilesAmong(directory, packageFiles) };
|
|
22
22
|
});
|
|
23
23
|
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
|
|
24
|
+
const FilesOfEachPackage = Schema.Struct({
|
|
25
|
+
checkedProject: Schema.String,
|
|
26
|
+
filesOfEachPackage: Schema.Array(
|
|
27
|
+
Schema.Struct({ directory: Schema.String, files: Schema.Array(Schema.String) }),
|
|
28
|
+
),
|
|
29
|
+
packageFiles: Schema.Array(Schema.String),
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
const formatterFiles = Task.make({
|
|
33
|
+
name: "formatter-files",
|
|
34
|
+
output: FilesOfEachPackage,
|
|
35
|
+
run: Effect.gen(function* () {
|
|
36
|
+
yield* startDirectory;
|
|
27
37
|
const path = yield* Path.Path;
|
|
38
|
+
const checkedProject = yield* projectDirectory;
|
|
28
39
|
const filesOfEachPackage = yield* Effect.forEach(
|
|
29
|
-
yield* packageDirectoriesIn(
|
|
30
|
-
ownedFilesOfPackage,
|
|
40
|
+
yield* packageDirectoriesIn(checkedProject),
|
|
41
|
+
(packageDirectory) => ownedFilesOfPackage(checkedProject, packageDirectory),
|
|
31
42
|
{ concurrency: "unbounded" },
|
|
32
43
|
);
|
|
33
44
|
return {
|
|
45
|
+
checkedProject,
|
|
34
46
|
filesOfEachPackage,
|
|
35
47
|
packageFiles: filesOfEachPackage
|
|
36
48
|
.flatMap(({ directory, files }) => files.map((file) => path.join(directory, file)))
|
|
37
49
|
.toSorted(),
|
|
38
50
|
};
|
|
39
|
-
}).pipe(
|
|
40
|
-
)
|
|
51
|
+
}).pipe(
|
|
52
|
+
quietViolations("formatter-files"),
|
|
53
|
+
locatedFromTheProject,
|
|
54
|
+
Effect.provide(ProjectQueryCachesLive),
|
|
55
|
+
),
|
|
56
|
+
});
|
|
41
57
|
|
|
42
|
-
const formatInputs = Task.make(
|
|
43
|
-
"format-inputs",
|
|
44
|
-
Effect.flatMap(formatterFiles, ({ filesOfEachPackage }) =>
|
|
45
|
-
inEachPackage("format-inputs",
|
|
58
|
+
const formatInputs = Task.make({
|
|
59
|
+
name: "format-inputs",
|
|
60
|
+
run: Effect.flatMap(formatterFiles, ({ filesOfEachPackage }) =>
|
|
61
|
+
inEachPackage("format-inputs", (packageDirectory, packageDirectoryFromTheProject) =>
|
|
46
62
|
checkedFormatInputsIn(
|
|
47
63
|
packageDirectory,
|
|
48
|
-
filesOfEachPackage.find(({ directory }) => directory ===
|
|
64
|
+
filesOfEachPackage.find(({ directory }) => directory === packageDirectoryFromTheProject)
|
|
65
|
+
?.files ?? [],
|
|
49
66
|
).pipe(quietViolations("format-inputs")),
|
|
50
67
|
),
|
|
51
68
|
),
|
|
52
|
-
);
|
|
69
|
+
});
|
|
53
70
|
|
|
54
|
-
const unformattedFiles = Task.make(
|
|
55
|
-
"bun-fmt",
|
|
56
|
-
Effect.andThen(
|
|
57
|
-
inEachPackage("bun-fmt",
|
|
71
|
+
const unformattedFiles = Task.make({
|
|
72
|
+
name: "bun-fmt",
|
|
73
|
+
run: Effect.andThen(
|
|
74
|
+
inEachPackage("bun-fmt", (packageDirectory) =>
|
|
58
75
|
checkedFormatConfigIn(packageDirectory).pipe(quietViolations("bun-fmt")),
|
|
59
76
|
),
|
|
60
|
-
Effect.flatMap(formatterFiles, ({ packageFiles }) =>
|
|
77
|
+
Effect.flatMap(formatterFiles, ({ checkedProject, packageFiles }) =>
|
|
78
|
+
unformattedFilesAmong(checkedProject, packageFiles),
|
|
79
|
+
),
|
|
61
80
|
).pipe(Effect.provide(ProjectQueryCachesLive)),
|
|
62
|
-
);
|
|
81
|
+
});
|
|
63
82
|
|
|
64
|
-
export const formatting = Task.make(
|
|
65
|
-
"formatting",
|
|
66
|
-
Task.allSettled([formatInputs, unformattedFiles]),
|
|
67
|
-
);
|
|
83
|
+
export const formatting = Task.make({
|
|
84
|
+
name: "formatting",
|
|
85
|
+
run: Task.allSettled([formatInputs, unformattedFiles]),
|
|
86
|
+
});
|
|
@@ -7,10 +7,10 @@ import { typeScriptConfig } from "../../shared/declare-typescript-config-task.ts
|
|
|
7
7
|
import { ProjectQueryCachesLive } from "../../shared/provide-project-query-caches.ts";
|
|
8
8
|
import { checkLintRulesWithOxlintIn } from "./internal/check-lint-rules-with-oxlint.ts";
|
|
9
9
|
|
|
10
|
-
export const oxlint = Task.make(
|
|
11
|
-
"oxlint",
|
|
12
|
-
Effect.andThen(
|
|
10
|
+
export const oxlint = Task.make({
|
|
11
|
+
name: "oxlint",
|
|
12
|
+
run: 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
|
+
}
|