@sshkeda/check 3.0.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.
Files changed (32) hide show
  1. package/README.md +5 -41
  2. package/docs/how-to-grant-a-permission.md +28 -0
  3. package/docs/how-to-make-check-pass.md +4 -31
  4. package/package.json +2 -2
  5. package/scripts/check.ts +2 -3
  6. package/src/internal/ban-fixed-values-in-recoveries.ts +1 -1
  7. package/src/lib/project-directory/index.ts +0 -1
  8. package/src/lib/project-directory/internal/read-the-project-directory.ts +1 -5
  9. package/src/lib/tasks/internal/declare-the-check-task.ts +6 -6
  10. package/src/lib/tasks/internal/declare-the-checker-queries-task.ts +4 -4
  11. package/src/lib/tasks/internal/declare-the-typed-checks-task.ts +4 -4
  12. package/src/lib/tasks/lib/check-effect-diagnostics-with-effect-tsgo/index.ts +4 -4
  13. package/src/lib/tasks/lib/confine-layer-provides-to-program-starts/internal/find-layer-provides-outside-program-starts.ts +15 -1
  14. package/src/lib/tasks/lib/confine-layer-provides-to-program-starts/internal/resolve-imported-package-apis.ts +1 -2
  15. package/src/lib/tasks/lib/detect-duplicate-functions/index.ts +4 -4
  16. package/src/lib/tasks/lib/enforce-file-layout/index.ts +4 -4
  17. package/src/lib/tasks/lib/enforce-file-layout/internal/file-layout-errors.ts +7 -29
  18. package/src/lib/tasks/lib/enforce-file-layout/internal/find-file-layout-violations.ts +14 -181
  19. package/src/lib/tasks/lib/enforce-file-types/index.ts +4 -4
  20. package/src/lib/tasks/lib/format-with-bun-fmt/internal/declare-the-formatting-task.ts +28 -17
  21. package/src/lib/tasks/lib/lint-with-oxlint/index.ts +4 -4
  22. package/src/lib/tasks/lib/refuse-disable-directives/index.ts +4 -4
  23. package/src/lib/tasks/lib/require-type-checking-every-linted-file/index.ts +4 -4
  24. package/src/lib/tasks/lib/type-check-with-bun-check/index.ts +4 -4
  25. package/src/lib/tasks/shared/check-each-nested-package.ts +2 -0
  26. package/src/lib/tasks/shared/declare-lint-config-task.ts +4 -4
  27. package/src/lib/tasks/shared/declare-start-directory-task.ts +40 -0
  28. package/src/lib/tasks/shared/declare-typescript-config-task.ts +4 -4
  29. package/src/shared/bans-each-permission-lifts.ts +0 -7
  30. package/src/shared/record-and-grant-permissions-by-path.ts +1 -3
  31. package/src/lib/tasks/internal/verify-where-check-was-started.ts +0 -50
  32. package/src/lib/tasks/lib/enforce-file-layout/internal/resolve-task-imports.ts +0 -178
package/README.md CHANGED
@@ -4,9 +4,9 @@ Check sends your AI slop code back to the kitchen!
4
4
 
5
5
  Check holds your TypeScript code to a strict standard built around Effect and Bun, so the code stays type-safe, observable and predictable.
6
6
 
7
- It runs about 310 lint rules, 66 of them its own, and about 80 checks on your project's layout, imports and config. It also runs oxfmt, Effect's diagnostics and `bun check`. Your agent keeps fixing what it reports until the slop is gone.
7
+ It runs about 310 lint rules, 65 of them its own, and about 80 checks on your project's layout, imports and config. It also runs oxfmt, Effect's diagnostics and `bun check`. Your agent keeps fixing what it reports until the slop is gone.
8
8
 
9
- No comment or setting turns a rule off everywhere. A small set of rules was picked to allow an override, and you grant each one to a single file in `oxlint.config.ts`. See [Grant a permission](docs/how-to-make-check-pass.md#grant-a-permission).
9
+ No comment or setting turns a rule off everywhere. A small set of rules was picked to allow an override, and you grant each one to a single file in `oxlint.config.ts`. See [How to Grant a Permission](docs/how-to-grant-a-permission.md).
10
10
 
11
11
  Check is a command you run in your repo. It runs its checks with [Task](https://github.com/sshkeda/task), a task runner for Bun.
12
12
 
@@ -48,7 +48,8 @@ Here's what Check prints when it runs on that code:
48
48
  [typed-checks] error SettledTasksFailed: 2 of 6 tasks failed: oxlint, effect-tsgo
49
49
  [check] read node_modules/@sshkeda/check/docs/how-to-make-check-pass.md before you change the code
50
50
  [check] error SettledTasksFailed: 1 of 7 tasks failed: typed-checks
51
- failed: effect-tsgo, oxlint (2 of 17 tasks), 1.0s
51
+ failed: effect-tsgo, oxlint (2 of 18 tasks), 1.0s
52
+ ...
52
53
  ```
53
54
 
54
55
  Here's what each error catches:
@@ -150,44 +151,7 @@ Check needs Bun 1.4.4 or newer and a Git repository.
150
151
 
151
152
  Check checks the package in the directory you start it in.
152
153
 
153
- ## Run it from a script
154
-
155
- To run Check beside your own tasks, such as your tests, add Task and start the command from a task in `scripts/`.
156
-
157
- ```bash
158
- bun add @sshkeda/task
159
- ```
160
-
161
- `scripts/internal/start-check.ts` starts the command:
162
-
163
- ```ts
164
- import { Task } from "@sshkeda/task";
165
-
166
- export const check = Task.make("check", Task.exec("bunx", ["@sshkeda/check"]));
167
- ```
168
-
169
- `scripts/ci.ts` runs it:
170
-
171
- ```ts
172
- import { Task } from "@sshkeda/task";
173
-
174
- import { check } from "./internal/start-check.ts";
175
-
176
- if (import.meta.main) {
177
- Task.main(check);
178
- }
179
- ```
180
-
181
- To run your tests too, make one task in `scripts/internal/run-checks-and-tests.ts` that runs both, and pass it to `Task.main` in `scripts/ci.ts`:
182
-
183
- ```ts
184
- import { Task } from "@sshkeda/task";
185
-
186
- import { tests } from "../../tests/index.ts";
187
- import { check } from "./start-check.ts";
188
-
189
- export const ci = Task.make("ci", Task.allSettled([check, tests]));
190
- ```
154
+ To run one check alone, name it, as in `bunx @sshkeda/check oxlint`.
191
155
 
192
156
  ## Make it yours
193
157
 
@@ -0,0 +1,28 @@
1
+ # How to Grant a Permission
2
+
3
+ Grant a permission to one file or directory in `oxlint.config.ts`. The key is the path from the folder that holds `oxlint.config.ts`, with no glob. Each name in `allow` lifts one ban for that path only.
4
+
5
+ ```ts
6
+ export default lintConfig({
7
+ "src/config.ts": { allow: ["readsConfig"] },
8
+ "src/internal/run-all-checks.ts": { allow: ["handlesEveryFailure"] },
9
+ });
10
+ ```
11
+
12
+ - `readsConfig`: Allows Effect `Config`, `process.env` and `process.argv`.
13
+ - `spawnsCommands`: Allows Effect `ChildProcess`, `Bun.spawn` and `spawn` from `node:child_process`.
14
+ - `locksFiles`: Allows `open` from `node:fs/promises` and `constants` from `node:fs`.
15
+ - `importsDynamically`: Allows `import()` and `createRequire(…).resolve`.
16
+ - `exitsTheProcess`: Allows `process.exit`.
17
+ - `usesSqlDatabases`: Allows Effect SQL.
18
+ - `writesToTheTerminal`: Allows Effect `Stdio`.
19
+ - `usesAbbreviations`: Allows abbreviations in variable, function, type and other declared names.
20
+ - `pollsWithADeadline`: Allows `Effect.repeat` and `Effect.retry` with `Schedule.spaced` or `Schedule.exponential`, under a deadline. `Schedule.exponential` may be wrapped in or piped through `Schedule.jittered`.
21
+ - `waitsOnTimers`: Allows `Effect.sleep`, `Effect.delay`, `Clock.sleep` and the Stream operations that wait on a timer, such as `Stream.tick`.
22
+ - `hasAnUnlistedFileType`: Allows a file type Check doesn't list, such as Markdown.
23
+ - `isAnUnlistedDirectory`: Allows a directory Check doesn't list, such as `.github`. Check doesn't apply its directory-shape rules inside it, but files there still need their own `hasAnUnlistedFileType` grant.
24
+ - `patchesADependency`: Allows a patch file from `bun patch`.
25
+ - `trustsUnverifiedTypes`: Allows trusting a value's type without checking it, through `Schema.declare`.
26
+ - `handlesEveryFailure`: Allows catching every error, through `Effect.catch`, `Effect.exit`, a forked fiber or `Effect.runPromise`.
27
+ - `fallsBackToFixedValues`: Allows answering every failure, or a whole library error such as `PlatformError`, with a fixed value that never reads the failure.
28
+ - `isGeneratedByATool`: Check skips this path, so it can't have any other permission.
@@ -6,41 +6,13 @@ Check may not catch every violation of these principles. Review your code agains
6
6
 
7
7
  ## Meet the requirement behind the error
8
8
 
9
- - Use a grant only for an unavoidable exception.
9
+ - Use a grant only for an unavoidable exception. [How to Grant a Permission](how-to-grant-a-permission.md) lists each grant and what it allows.
10
10
  - Move the code that needs a grant into its own small file and grant that file. A grant covers the whole file, so Check stops reporting that ban for everything else in it.
11
11
  - Design for the current requirement as if you were starting fresh. Delete code the new design doesn't need.
12
12
  - Handle a forked effect's failure before the fork, or keep the fiber and join it.
13
+ - Return a fixed value only for the one failure you expect, such as a file that isn't there. Let every other failure fail.
13
14
  - Grant `isGeneratedByATool` only to a file a tool generates.
14
15
 
15
- ## Grant a permission
16
-
17
- Grant a permission to one file or directory in `oxlint.config.ts`. The key is the path from the folder that holds `oxlint.config.ts`, with no glob. Each name in `allow` lifts one ban for that path only.
18
-
19
- ```ts
20
- export default lintConfig({
21
- "src/config.ts": { allow: ["readsConfig"] },
22
- "src/internal/run-all-checks.ts": { allow: ["handlesEveryFailure"] },
23
- });
24
- ```
25
-
26
- - `readsConfig`: Allows Effect `Config`, `process.env` and `process.argv`.
27
- - `spawnsCommands`: Allows Effect `ChildProcess`, `Bun.spawn` and `spawn` from `node:child_process`.
28
- - `locksFiles`: Allows `open` from `node:fs/promises` and `constants` from `node:fs`.
29
- - `importsDynamically`: Allows `import()` and `createRequire(…).resolve`.
30
- - `exitsTheProcess`: Allows `process.exit`.
31
- - `usesSqlDatabases`: Allows Effect SQL.
32
- - `writesToTheTerminal`: Allows Effect `Stdio`.
33
- - `usesAbbreviations`: Allows abbreviations in variable, function, type and other declared names.
34
- - `pollsWithADeadline`: Allows `Effect.repeat` and `Effect.retry` with `Schedule.spaced` or `Schedule.exponential`, under a deadline. `Schedule.exponential` may be wrapped in or piped through `Schedule.jittered`.
35
- - `waitsOnTimers`: Allows `Effect.sleep`, `Effect.delay`, `Clock.sleep` and the Stream operations that wait on a timer, such as `Stream.tick`.
36
- - `hasAnUnlistedFileType`: Allows a file type Check doesn't list, such as Markdown.
37
- - `isAnUnlistedDirectory`: Allows a directory Check doesn't list, such as `.github`. Check doesn't apply its directory-shape rules inside it, but files there still need their own `hasAnUnlistedFileType` grant.
38
- - `patchesADependency`: Allows a patch file from `bun patch`.
39
- - `trustsUnverifiedTypes`: Allows trusting a value's type without checking it, through `Schema.declare`.
40
- - `handlesEveryFailure`: Allows catching every error, through `Effect.catch`, `Effect.exit`, a forked fiber or `Effect.runPromise`.
41
- - `fallsBackToFixedValues`: Allows answering every failure, or a whole library error such as `PlatformError`, with a fixed value that never reads the failure.
42
- - `isGeneratedByATool`: Check skips this path, so it can't have any other permission.
43
-
44
16
  ## Make the code explain itself
45
17
 
46
18
  - Use what Effect, Bun or a dependency already provides.
@@ -54,7 +26,8 @@ export default lintConfig({
54
26
  ## Make program output clear
55
27
 
56
28
  - Follow Git and uv's style. Say what failed, name the affected file or value and explain the cause.
57
- - Give the reader enough context to choose a fix. In a CLI people run by hand, add a hint only for a known command they can paste and run.
29
+ - Give the reader enough context to choose a fix.
30
+ - Put a fix in the message only when it is concrete and takes no thought, such as a command to paste and run or the exact code to write. Leave out any fix that needs a decision.
58
31
  - Report each cause once. Put the main failure first, supporting details below it and internal debugging details in the trace.
59
32
  - Preserve useful messages from underlying tools, including error codes and exact names.
60
33
  - Write short, full sentences. Use periods instead of semicolons between sentences.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sshkeda/check",
3
- "version": "3.0.0",
3
+ "version": "4.0.0",
4
4
  "homepage": "https://github.com/sshkeda/check#readme",
5
5
  "bugs": {
6
6
  "url": "https://github.com/sshkeda/check/issues"
@@ -30,7 +30,7 @@
30
30
  "@effect/platform-bun": "4.1.0",
31
31
  "@effect/tsgo": "0.67.4",
32
32
  "@oxlint/plugins": "1.88.0",
33
- "@sshkeda/task": "1.0.2",
33
+ "@sshkeda/task": "2.0.0",
34
34
  "oxc-parser": "0.153.0",
35
35
  "oxc-resolver": "11.24.2",
36
36
  "oxlint": "1.88.0",
package/scripts/check.ts CHANGED
@@ -1,10 +1,9 @@
1
1
  #!/usr/bin/env bun
2
- import { Task } from "@sshkeda/task";
3
-
4
2
  import { PROJECT_DIRECTORY_VARIABLE } from "../src/lib/project-directory/index.ts";
5
3
  import { check } from "../src/lib/tasks/index.ts";
6
4
 
7
5
  if (import.meta.main) {
8
6
  process.env[PROJECT_DIRECTORY_VARIABLE] = process.cwd();
9
- Task.main(check);
10
7
  }
8
+
9
+ export default check;
@@ -242,7 +242,7 @@ export const noFixedFallbacks = defineRule({
242
242
  type: "problem",
243
243
  messages: {
244
244
  fixed:
245
- "{{operation}} answers {{failure}} with the fixed value {{value}} and never reads the failure. Name the reason you expect, or fail",
245
+ "{{operation}} answers {{failure}} with the fixed value {{value}} and never reads the failure",
246
246
  unusedGrant: unusedGrantMessage(FIXED_FALLBACKS),
247
247
  },
248
248
  schema: ruleOptionsJsonSchema(FIXED_FALLBACK_OPTIONS),
@@ -1,5 +1,4 @@
1
1
  export {
2
- givenArguments,
3
2
  PROJECT_DIRECTORY_VARIABLE,
4
3
  projectDirectory,
5
4
  } from "./internal/read-the-project-directory.ts";
@@ -1,13 +1,9 @@
1
- import { Config, Effect } from "effect";
1
+ import { Config } from "effect";
2
2
 
3
3
  export const PROJECT_DIRECTORY_VARIABLE = "SSHKEDA_CHECK_PROJECT_DIRECTORY";
4
4
 
5
5
  const THE_PACKAGE_THAT_RUNS_THE_TASK = ".";
6
6
 
7
- const FIRST_SCRIPT_ARGUMENT = 2;
8
-
9
7
  export const projectDirectory = Config.String(PROJECT_DIRECTORY_VARIABLE).pipe(
10
8
  Config.withDefault(THE_PACKAGE_THAT_RUNS_THE_TASK),
11
9
  );
12
-
13
- export const givenArguments = Effect.sync(() => process.argv.slice(FIRST_SCRIPT_ARGUMENT));
@@ -7,9 +7,9 @@ import { layout } from "../lib/enforce-file-layout/index.ts";
7
7
  import { fileTypes } from "../lib/enforce-file-types/index.ts";
8
8
  import { formatting } from "../lib/format-with-bun-fmt/index.ts";
9
9
  import { lintConfigFile } from "../shared/declare-lint-config-task.ts";
10
+ import { startDirectory } from "../shared/declare-start-directory-task.ts";
10
11
  import { typeScriptConfig } from "../shared/declare-typescript-config-task.ts";
11
12
  import { typedChecks } from "./declare-the-typed-checks-task.ts";
12
- import { verifyWhereCheckWasStarted } from "./verify-where-check-was-started.ts";
13
13
 
14
14
  const GUIDE_FILE = new URL("../../../../docs/how-to-make-check-pass.md", import.meta.url);
15
15
 
@@ -22,10 +22,10 @@ const pointAtTheGuide = Effect.gen(function* () {
22
22
  yield* Effect.logError(`read ${guide} before you change the code`);
23
23
  });
24
24
 
25
- export const check: Task.Task<void> = Task.make(
26
- "check",
27
- Effect.andThen(
28
- verifyWhereCheckWasStarted,
25
+ export const check: Task.Task<void> = Task.make({
26
+ name: "check",
27
+ run: Effect.andThen(
28
+ startDirectory,
29
29
  Task.allSettled([
30
30
  typeScriptConfig,
31
31
  lintConfigFile,
@@ -36,4 +36,4 @@ export const check: Task.Task<void> = Task.make(
36
36
  duplicateFunctions,
37
37
  ]).pipe(Effect.tapError(() => pointAtTheGuide)),
38
38
  ),
39
- );
39
+ });
@@ -19,9 +19,9 @@ import { ProjectQueryCachesLive } from "../shared/provide-project-query-caches.t
19
19
  import { TYPESCRIPT_PROJECT_FILE } from "../shared/query-the-typescript-project.ts";
20
20
  import { runChecksOverOneTypeScriptProject } from "./run-checks-over-one-typescript-project.ts";
21
21
 
22
- export const checkerQueries = Task.make(
23
- "checker-queries",
24
- Effect.andThen(
22
+ export const checkerQueries = Task.make({
23
+ name: "checker-queries",
24
+ run: Effect.andThen(
25
25
  Task.all([typeScriptConfig, lintConfigFile]),
26
26
  inEachPackage("checker-queries", (packageDirectory) =>
27
27
  Path.Path.use((path) =>
@@ -41,4 +41,4 @@ export const checkerQueries = Task.make(
41
41
  ),
42
42
  ),
43
43
  ).pipe(Effect.provide(ProjectQueryCachesLive)),
44
- );
44
+ });
@@ -9,9 +9,9 @@ import { typeCheck } from "../lib/type-check-with-bun-check/index.ts";
9
9
  import { typeScriptConfig } from "../shared/declare-typescript-config-task.ts";
10
10
  import { checkerQueries } from "./declare-the-checker-queries-task.ts";
11
11
 
12
- export const typedChecks: Task.Task<void> = Task.make(
13
- "typed-checks",
14
- Effect.andThen(
12
+ export const typedChecks: Task.Task<void> = Task.make({
13
+ name: "typed-checks",
14
+ run: Effect.andThen(
15
15
  typeScriptConfig,
16
16
  Task.allSettled([
17
17
  typeCheck,
@@ -22,4 +22,4 @@ export const typedChecks: Task.Task<void> = Task.make(
22
22
  lintedFilesTypeChecked,
23
23
  ]),
24
24
  ),
25
- );
25
+ });
@@ -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 { effectDiagnosticsIn } from "./internal/check-effect-diagnostics-with-effect-tsgo.ts";
9
9
 
10
- export const effectStrict = Task.make(
11
- "effect-tsgo",
12
- Effect.andThen(
10
+ export const effectStrict = Task.make({
11
+ name: "effect-tsgo",
12
+ run: Effect.andThen(
13
13
  Task.all([typeScriptConfig, lintConfigFile]),
14
14
  inEachPackage("effect-tsgo", effectDiagnosticsIn),
15
15
  ).pipe(Effect.provide(ProjectQueryCachesLive)),
16
- );
16
+ });
@@ -13,6 +13,7 @@ import {
13
13
  isIdentifier,
14
14
  isObjectLiteralExpression,
15
15
  isParameterDeclaration,
16
+ isPropertyAssignment,
16
17
  isReturnStatement,
17
18
  isSpreadElement,
18
19
  isVariableDeclaration,
@@ -409,6 +410,12 @@ const isRunnerArgument = (
409
410
  return isArgument ? startsTheProgram(checker, apis, parent) : Effect.succeed(false);
410
411
  };
411
412
 
413
+ const objectHoldingAPropertyValue = (node: Node) => {
414
+ const { parent } = node;
415
+ const isPropertyValue = isPropertyAssignment(parent) && isObjectLiteralExpression(parent.parent);
416
+ return isPropertyValue ? parent.parent : node;
417
+ };
418
+
412
419
  const isExported = (declaration: Node) => {
413
420
  const statement = declaration.parent.parent;
414
421
  return (
@@ -448,7 +455,14 @@ const isConstOnlyRunByARunner = (
448
455
  (read) => read !== undefined && read.pos !== declaration.name.pos,
449
456
  );
450
457
  const isReadOnce = onlyRead !== undefined && otherReads.length === 0;
451
- return isReadOnce && (yield* isRunnerArgument(checker, apis, outermostWrapperOf(onlyRead)));
458
+ return (
459
+ isReadOnce &&
460
+ (yield* isRunnerArgument(
461
+ checker,
462
+ apis,
463
+ objectHoldingAPropertyValue(outermostWrapperOf(onlyRead)),
464
+ ))
465
+ );
452
466
  });
453
467
 
454
468
  const isWhereTheProgramStarts = (
@@ -11,7 +11,6 @@ import type { Checker, Symbol as TypeScriptSymbol } from "typescript/unstable/as
11
11
  import {
12
12
  TASK_NAMESPACE_EXPORT,
13
13
  TASK_PACKAGE,
14
- TASK_MAIN_MEMBER,
15
14
  TASK_MAKE_MEMBER,
16
15
  } from "../../../../../shared/bans-each-permission-lifts.ts";
17
16
  import {
@@ -94,7 +93,7 @@ const PROGRAM_STARTS = [
94
93
  isPackage: isTaskPackage,
95
94
  module: PACKAGE_ROOT,
96
95
  exports: [TASK_NAMESPACE_EXPORT],
97
- members: [TASK_MAIN_MEMBER, TASK_MAKE_MEMBER],
96
+ members: [TASK_MAKE_MEMBER],
98
97
  returnedBySignature: DIRECT_CALLS,
99
98
  },
100
99
  ] as const;
@@ -4,7 +4,7 @@ import { Effect } from "effect";
4
4
  import { ProjectQueryCachesLive } from "../../shared/provide-project-query-caches.ts";
5
5
  import { duplicateFunctionsOfEachPackage } from "./internal/find-duplicate-functions.ts";
6
6
 
7
- export const duplicateFunctions = Task.make(
8
- "duplicate-functions",
9
- duplicateFunctionsOfEachPackage.pipe(Effect.provide(ProjectQueryCachesLive)),
10
- );
7
+ export const duplicateFunctions = Task.make({
8
+ name: "duplicate-functions",
9
+ run: duplicateFunctionsOfEachPackage.pipe(Effect.provide(ProjectQueryCachesLive)),
10
+ });
@@ -4,7 +4,7 @@ import { Effect } from "effect";
4
4
  import { ProjectQueryCachesLive } from "../../shared/provide-project-query-caches.ts";
5
5
  import { fileLayoutViolationsOfEachPackage } from "./internal/check-the-layout-of-each-package.ts";
6
6
 
7
- export const layout = Task.make(
8
- "layout",
9
- fileLayoutViolationsOfEachPackage.pipe(Effect.provide(ProjectQueryCachesLive)),
10
- );
7
+ export const layout = Task.make({
8
+ name: "layout",
9
+ run: fileLayoutViolationsOfEachPackage.pipe(Effect.provide(ProjectQueryCachesLive)),
10
+ });
@@ -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,37 +64,21 @@ export class TopLevelNonScript extends Schema.TaggedError<TopLevelNonScript>()(
68
64
  }
69
65
  }
70
66
 
71
- export class TopLevelScriptWithoutMain extends Schema.TaggedError<TopLevelScriptWithoutMain>()(
72
- "TopLevelScriptWithoutMain",
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 neither calls ${TASK_NAMESPACE_EXPORT}.${TASK_MAIN_MEMBER} imported from ${TASK_PACKAGE} nor has a default export`;
72
+ return `sits directly in ${SCRIPTS_DIRECTORY}/ and has no default export`;
77
73
  }
78
74
  }
79
75
 
80
- const SCRIPT_ENTRY_POINTS = ["main-guard", "default-export"] as const;
81
-
82
- const STATEMENTS_A_SCRIPT_MAY_HOLD = {
83
- "main-guard": `an import and if (import.meta.main) { ${TASK_NAMESPACE_EXPORT}.${TASK_MAIN_MEMBER}(task); }`,
84
- "default-export": "an import and export default task",
85
- } satisfies Record<(typeof SCRIPT_ENTRY_POINTS)[number], string>;
86
-
87
76
  export class TopLevelScriptHoldsOtherStatement extends Schema.TaggedError<TopLevelScriptHoldsOtherStatement>()(
88
77
  "TopLevelScriptHoldsOtherStatement",
89
- { location: Schema.String, entryPoint: Schema.Literals(SCRIPT_ENTRY_POINTS) },
90
- ) {
91
- public override get message() {
92
- return `holds a statement other than ${STATEMENTS_A_SCRIPT_MAY_HOLD[this.entryPoint]}`;
93
- }
94
- }
95
-
96
- export class TopLevelScriptWithMainAndDefaultExport extends Schema.TaggedError<TopLevelScriptWithMainAndDefaultExport>()(
97
- "TopLevelScriptWithMainAndDefaultExport",
98
78
  { location: Schema.String },
99
79
  ) {
100
80
  public override get message() {
101
- return `calls ${TASK_NAMESPACE_EXPORT}.${TASK_MAIN_MEMBER} and also has a default export. Keep one of them`;
81
+ return "holds a statement other than an import and export default task";
102
82
  }
103
83
  }
104
84
 
@@ -376,10 +356,9 @@ export class DirectoryGrantedPermissions extends Schema.TaggedError<DirectoryGra
376
356
  }
377
357
  }
378
358
 
379
- const MISPLACEMENT_PLACES = ["root-task-script", "root-code-file", "docs-non-markdown"] as const;
359
+ const MISPLACEMENT_PLACES = ["root-code-file", "docs-non-markdown"] as const;
380
360
 
381
361
  const MISPLACEMENTS = {
382
- "root-task-script": "is a task script at the package root",
383
362
  "root-code-file": "is code at the package root",
384
363
  "docs-non-markdown": `is not markdown but sits in ${DOCS_DIRECTORY}/`,
385
364
  } satisfies Record<(typeof MISPLACEMENT_PLACES)[number], string>;
@@ -402,9 +381,8 @@ export class FileLayoutViolations extends Schema.TaggedError<FileLayoutViolation
402
381
  MisplacedToolFile,
403
382
  BunTestFileName,
404
383
  TopLevelNonScript,
405
- TopLevelScriptWithoutMain,
384
+ TopLevelScriptWithoutDefaultExport,
406
385
  TopLevelScriptHoldsOtherStatement,
407
- TopLevelScriptWithMainAndDefaultExport,
408
386
  LibraryDirectory,
409
387
  DirectoryOutsideModuleLayout,
410
388
  ModuleWithoutIndex,
@@ -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, Visitor } from "oxc-parser";
4
- import type { CallExpression, Expression, ParseResult, Statement } from "oxc-parser";
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,
@@ -65,7 +61,6 @@ import {
65
61
  JSON_OBJECT,
66
62
  packageManifestObject,
67
63
  } from "../../../shared/read-package-manifest-object.ts";
68
- import { absolutePathOf } from "../../../shared/resolve-absolute-paths.ts";
69
64
  import { toolFileOf, toolFileIsPlaced } from "../../../shared/tool-file-locations.ts";
70
65
  import {
71
66
  BunTestFileName,
@@ -93,8 +88,7 @@ import {
93
88
  MisplacedToolFile,
94
89
  TopLevelNonScript,
95
90
  TopLevelScriptHoldsOtherStatement,
96
- TopLevelScriptWithMainAndDefaultExport,
97
- TopLevelScriptWithoutMain,
91
+ TopLevelScriptWithoutDefaultExport,
98
92
  UngrantedDocument,
99
93
  UngrantedDirectory,
100
94
  UnlistedPatchGranted,
@@ -111,7 +105,6 @@ import {
111
105
  modulesWithLayoutDirectoryNamesAmong,
112
106
  moduleWithLayoutDirectoryNameViolations,
113
107
  } from "./find-module-layout-violations.ts";
114
- import { taskImportsIn, isTaskLayoutFile } from "./resolve-task-imports.ts";
115
108
 
116
109
  const KEBAB_CASE_PART = /^[a-z0-9]+(?:-[a-z0-9]+)*$/u;
117
110
  const BUN_TEST_FILE_EXTENSION = /\.(?:test|spec)(?<extension>\.[^.]+)$/u;
@@ -163,116 +156,6 @@ export const pathViolations = (path: string, isNamedByBunPatch = false) => {
163
156
  return violations;
164
157
  };
165
158
 
166
- const directTaskImports = (parsed: ParseResult) =>
167
- new Map(
168
- parsed.module.staticImports
169
- .filter((declaration) => declaration.moduleRequest.value === TASK_PACKAGE)
170
- .flatMap((declaration) =>
171
- declaration.entries
172
- .filter((entry) => !entry.isType)
173
- .map(
174
- (entry) =>
175
- [
176
- entry.localName.value,
177
- entry.importName.kind === "NamespaceObject" ? [] : [entry.importName.name ?? ""],
178
- ] as const,
179
- ),
180
- ),
181
- );
182
-
183
- const callsTaskMember = (
184
- parsed: ParseResult,
185
- member: string,
186
- imports: ReadonlyMap<string, readonly string[]>,
187
- ) => {
188
- const calls: CallExpression[] = [];
189
- const aliases = new Map<string, Expression>();
190
- new Visitor({
191
- CallExpression(node) {
192
- calls.push(node);
193
- },
194
- VariableDeclarator({ id, init: initializer }) {
195
- const isNamedInitializer = id.type === "Identifier" && initializer !== null;
196
- if (isNamedInitializer) {
197
- aliases.set(id.name, initializer);
198
- }
199
- },
200
- }).visit(parsed.program);
201
- const taskReference = (
202
- expression: Expression,
203
- seen: ReadonlySet<string> = new Set(),
204
- ): readonly string[] | undefined => {
205
- if (expression.type === "Identifier") {
206
- const imported = imports.get(expression.name);
207
- if (imported !== undefined) {
208
- return imported;
209
- }
210
- const alias = aliases.get(expression.name);
211
- const isUnfollowedAlias = alias !== undefined && !seen.has(expression.name);
212
- return isUnfollowedAlias
213
- ? taskReference(alias, new Set([...seen, expression.name]))
214
- : undefined;
215
- }
216
- const isStaticMember =
217
- expression.type === "MemberExpression" &&
218
- !expression.computed &&
219
- expression.property.type === "Identifier";
220
- if (!isStaticMember) {
221
- return;
222
- }
223
- const object = taskReference(expression.object, seen);
224
- return object === undefined ? undefined : [...object, expression.property.name];
225
- };
226
- return calls.some(
227
- ({ callee }) => taskReference(callee)?.join(".") === `${TASK_NAMESPACE_EXPORT}.${member}`,
228
- );
229
- };
230
-
231
- const importedMemberPath = (
232
- expression: Expression,
233
- imports: ReadonlyMap<string, readonly string[]>,
234
- ): readonly string[] | undefined => {
235
- if (expression.type === "Identifier") {
236
- return imports.get(expression.name);
237
- }
238
- const isStaticMember =
239
- expression.type === "MemberExpression" &&
240
- !expression.computed &&
241
- expression.property.type === "Identifier";
242
- if (!isStaticMember) {
243
- return;
244
- }
245
- const object = importedMemberPath(expression.object, imports);
246
- return object === undefined ? undefined : [...object, expression.property.name];
247
- };
248
-
249
- const isMainGuard = (statement: Statement, imports: ReadonlyMap<string, readonly string[]>) => {
250
- if (statement.type !== "IfStatement") {
251
- return false;
252
- }
253
- const { test, consequent, alternate } = statement;
254
- const testsImportMetaMain =
255
- test.type === "MemberExpression" &&
256
- !test.computed &&
257
- test.object.type === "MetaProperty" &&
258
- test.object.meta.name === "import" &&
259
- test.object.property.name === "meta" &&
260
- test.property.type === "Identifier" &&
261
- test.property.name === "main";
262
- const [only, ...others] = consequent.type === "BlockStatement" ? consequent.body : [];
263
- const expression = only?.type === "ExpressionStatement" ? only.expression : undefined;
264
- const call = expression?.type === "CallExpression" ? expression : undefined;
265
- const [task, ...otherArguments] = call?.arguments ?? [];
266
- const runsOneNamedTask =
267
- call !== undefined &&
268
- others.length === 0 &&
269
- otherArguments.length === 0 &&
270
- task?.type === "Identifier" &&
271
- importedMemberPath(call.callee, imports)?.join(".") ===
272
- `${TASK_NAMESPACE_EXPORT}.${TASK_MAIN_MEMBER}`;
273
- return testsImportMetaMain && alternate === null && runsOneNamedTask;
274
- };
275
-
276
159
  const isDefaultExport = (statement: Statement) =>
277
160
  statement.type === "ExportDefaultDeclaration" &&
278
161
  statement.declaration.type !== "TSInterfaceDeclaration";
@@ -280,30 +163,6 @@ const isDefaultExport = (statement: Statement) =>
280
163
  const statementsOtherThanImports = (parsed: ParseResult) =>
281
164
  parsed.program.body.filter((statement) => statement.type !== "ImportDeclaration");
282
165
 
283
- const statementsOtherThanImportsAndMain = (
284
- parsed: ParseResult,
285
- imports: ReadonlyMap<string, readonly string[]>,
286
- ) => {
287
- const nonImports = statementsOtherThanImports(parsed);
288
- const firstGuard = nonImports.findIndex((statement) => isMainGuard(statement, imports));
289
- return nonImports.filter((_statement, index) => index !== firstGuard);
290
- };
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
166
  const defaultExportScriptViolations = (path: string, text: string, parsed: ParseResult) => {
308
167
  const lineAt = lineNumbersIn(text);
309
168
  return statementsOtherThanImports(parsed)
@@ -312,23 +171,16 @@ const defaultExportScriptViolations = (path: string, text: string, parsed: Parse
312
171
  (statement) =>
313
172
  new TopLevelScriptHoldsOtherStatement({
314
173
  location: `${path}:${lineAt(statement.start)}`,
315
- entryPoint: "default-export",
316
174
  }),
317
175
  );
318
176
  };
319
177
 
320
- export const sourceViolations = (
321
- path: string,
322
- text: string,
323
- resolvedImports?: ReadonlyMap<string, readonly string[]>,
324
- isListedUnderBin = false,
325
- ) => {
178
+ export const sourceViolations = (path: string, text: string, isListedUnderBin = false) => {
326
179
  const violations: (
327
180
  | MisplacedAtPackageRoot
328
181
  | SourceOutsideInternalOrShared
329
182
  | TopLevelScriptHoldsOtherStatement
330
- | TopLevelScriptWithMainAndDefaultExport
331
- | TopLevelScriptWithoutMain
183
+ | TopLevelScriptWithoutDefaultExport
332
184
  )[] = [];
333
185
  const isMisplacedTool = toolFileOf(path) !== undefined && !toolFileIsPlaced(path);
334
186
  if (isMisplacedTool) {
@@ -348,32 +200,21 @@ export const sourceViolations = (
348
200
  violations.push(new SourceOutsideInternalOrShared({ location: path }));
349
201
  }
350
202
 
351
- const parsed = parseSync(path, text);
352
- const imports = resolvedImports ?? directTaskImports(parsed);
353
203
  const isRootCodeFile = !path.includes("/") && !isRootSupportFile(path);
354
204
  if (isRootCodeFile) {
355
- violations.push(
356
- new MisplacedAtPackageRoot({
357
- location: path,
358
- place: callsTaskMember(parsed, TASK_MAIN_MEMBER, imports)
359
- ? "root-task-script"
360
- : "root-code-file",
361
- }),
362
- );
205
+ violations.push(new MisplacedAtPackageRoot({ location: path, place: "root-code-file" }));
363
206
  }
364
207
  const isTaskScript = isTopLevelScript(path) && !isListedUnderBin;
365
208
  if (!isTaskScript) {
366
209
  return violations;
367
210
  }
368
- const callsMain = callsTaskMember(parsed, TASK_MAIN_MEMBER, imports);
211
+ const parsed = parseSync(path, text);
369
212
  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 }));
376
- }
213
+ violations.push(
214
+ ...(hasDefaultExport
215
+ ? defaultExportScriptViolations(path, text, parsed)
216
+ : [new TopLevelScriptWithoutDefaultExport({ location: path })]),
217
+ );
377
218
  return violations;
378
219
  };
379
220
 
@@ -852,18 +693,10 @@ export const findFileLayoutViolations = (directory: string) =>
852
693
  return found;
853
694
  }
854
695
  const text = yield* fileSystem.readFileString(pathModule.join(directory, path));
855
- const absoluteDirectory = yield* absolutePathOf(directory);
856
- const imports = isTaskLayoutFile(path)
857
- ? yield* taskImportsIn(
858
- pathModule.join(absoluteDirectory, path),
859
- text,
860
- absoluteDirectory,
861
- )
862
- : undefined;
863
696
  return [
864
697
  ...found,
865
698
  ...(isScriptFile
866
- ? sourceViolations(path, text, imports, binaryFiles.has(path))
699
+ ? sourceViolations(path, text, binaryFiles.has(path))
867
700
  : yield* manifestViolations(path, text, repository)),
868
701
  ];
869
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
+ });
@@ -1,8 +1,9 @@
1
1
  import { Task } from "@sshkeda/task";
2
- import { Effect, Path } from "effect";
2
+ import { Effect, Path, Schema } from "effect";
3
3
 
4
4
  import { projectDirectory } from "../../../../project-directory/index.ts";
5
5
  import { inEachPackage, packageDirectoriesIn } from "../../../shared/check-each-nested-package.ts";
6
+ import { startDirectory } from "../../../shared/declare-start-directory-task.ts";
6
7
  import { ownedFilesAmong } from "../../../shared/list-owned-files.ts";
7
8
  import { listedPackageFiles } from "../../../shared/list-package-files.ts";
8
9
  import { quietViolations } from "../../../shared/print-failures-and-keep-detail-in-the-trace.ts";
@@ -20,9 +21,19 @@ const ownedFilesOfPackage = (checkedProject: string, packageDirectory: string) =
20
21
  return { directory: packageDirectory, files: yield* ownedFilesAmong(directory, packageFiles) };
21
22
  });
22
23
 
23
- const formatterFiles = Task.make(
24
- "formatter-files",
25
- Effect.gen(function* () {
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;
26
37
  const path = yield* Path.Path;
27
38
  const checkedProject = yield* projectDirectory;
28
39
  const filesOfEachPackage = yield* Effect.forEach(
@@ -42,11 +53,11 @@ const formatterFiles = Task.make(
42
53
  locatedFromTheProject,
43
54
  Effect.provide(ProjectQueryCachesLive),
44
55
  ),
45
- );
56
+ });
46
57
 
47
- const formatInputs = Task.make(
48
- "format-inputs",
49
- Effect.flatMap(formatterFiles, ({ filesOfEachPackage }) =>
58
+ const formatInputs = Task.make({
59
+ name: "format-inputs",
60
+ run: Effect.flatMap(formatterFiles, ({ filesOfEachPackage }) =>
50
61
  inEachPackage("format-inputs", (packageDirectory, packageDirectoryFromTheProject) =>
51
62
  checkedFormatInputsIn(
52
63
  packageDirectory,
@@ -55,11 +66,11 @@ const formatInputs = Task.make(
55
66
  ).pipe(quietViolations("format-inputs")),
56
67
  ),
57
68
  ),
58
- );
69
+ });
59
70
 
60
- const unformattedFiles = Task.make(
61
- "bun-fmt",
62
- Effect.andThen(
71
+ const unformattedFiles = Task.make({
72
+ name: "bun-fmt",
73
+ run: Effect.andThen(
63
74
  inEachPackage("bun-fmt", (packageDirectory) =>
64
75
  checkedFormatConfigIn(packageDirectory).pipe(quietViolations("bun-fmt")),
65
76
  ),
@@ -67,9 +78,9 @@ const unformattedFiles = Task.make(
67
78
  unformattedFilesAmong(checkedProject, packageFiles),
68
79
  ),
69
80
  ).pipe(Effect.provide(ProjectQueryCachesLive)),
70
- );
81
+ });
71
82
 
72
- export const formatting = Task.make(
73
- "formatting",
74
- Task.allSettled([formatInputs, unformattedFiles]),
75
- );
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
14
  inEachPackage("oxlint", checkLintRulesWithOxlintIn),
15
15
  ).pipe(Effect.provide(ProjectQueryCachesLive)),
16
- );
16
+ });
@@ -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 { findDisableDirectivesInLintedFilesOf } from "./internal/find-disable-directives.ts";
9
9
 
10
- export const directives = Task.make(
11
- "directives",
12
- Effect.andThen(
10
+ export const directives = Task.make({
11
+ name: "directives",
12
+ run: Effect.andThen(
13
13
  Task.all([typeScriptConfig, lintConfigFile]),
14
14
  inEachPackage("directives", findDisableDirectivesInLintedFilesOf),
15
15
  ).pipe(Effect.provide(ProjectQueryCachesLive)),
16
- );
16
+ });
@@ -6,10 +6,10 @@ import { typeScriptConfig } from "../../shared/declare-typescript-config-task.ts
6
6
  import { ProjectQueryCachesLive } from "../../shared/provide-project-query-caches.ts";
7
7
  import { lintedFilesNotTypeCheckedInEachPackage } from "./internal/find-linted-files-not-type-checked.ts";
8
8
 
9
- export const lintedFilesTypeChecked = Task.make(
10
- "linted-files-type-checked",
11
- Effect.andThen(
9
+ export const lintedFilesTypeChecked = Task.make({
10
+ name: "linted-files-type-checked",
11
+ run: Effect.andThen(
12
12
  Task.all([typeScriptConfig, lintConfigFile]),
13
13
  lintedFilesNotTypeCheckedInEachPackage,
14
14
  ).pipe(Effect.provide(ProjectQueryCachesLive)),
15
- );
15
+ });
@@ -5,7 +5,7 @@ import { inEachPackage } from "../../shared/check-each-nested-package.ts";
5
5
  import { typeScriptConfig } from "../../shared/declare-typescript-config-task.ts";
6
6
  import { checkTypesWithBunCheckIn } from "./internal/check-types-with-bun-check.ts";
7
7
 
8
- export const typeCheck = Task.make(
9
- "type-check",
10
- Effect.andThen(typeScriptConfig, inEachPackage("type-check", checkTypesWithBunCheckIn)),
11
- );
8
+ export const typeCheck = Task.make({
9
+ name: "type-check",
10
+ run: Effect.andThen(typeScriptConfig, inEachPackage("type-check", checkTypesWithBunCheckIn)),
11
+ });
@@ -4,6 +4,7 @@ import { Array as Arrays, Effect, Path } from "effect";
4
4
  import type { PlatformError } from "effect";
5
5
 
6
6
  import { projectDirectory } from "../../project-directory/index.ts";
7
+ import { startDirectory } from "./declare-start-directory-task.ts";
7
8
  import { listedPackageFiles } from "./list-package-files.ts";
8
9
  import { quietViolations } from "./print-failures-and-keep-detail-in-the-trace.ts";
9
10
  import { locatedFromTheProject, printedFromTheProject } from "./report-paths-from-the-project.ts";
@@ -69,6 +70,7 @@ export const inEachPackage = <Requirements>(
69
70
  ) => Effect.Effect<void, PlatformError.PlatformError | ReportedErrors, Requirements>,
70
71
  ) =>
71
72
  Effect.gen(function* () {
73
+ yield* startDirectory;
72
74
  const pathModule = yield* Path.Path;
73
75
  const checkedProject = yield* projectDirectory.pipe(quietViolations(tool));
74
76
  const packageDirectories = yield* packageDirectoriesIn(checkedProject).pipe(
@@ -6,9 +6,9 @@ import { loadedLintConfigIn } from "./load-the-lint-config.ts";
6
6
  import { quietViolations } from "./print-failures-and-keep-detail-in-the-trace.ts";
7
7
  import { ProjectQueryCachesLive } from "./provide-project-query-caches.ts";
8
8
 
9
- export const lintConfigFile = Task.make(
10
- "lint-config",
11
- inEachPackage("lint-config", (packageDirectory) =>
9
+ export const lintConfigFile = Task.make({
10
+ name: "lint-config",
11
+ run: inEachPackage("lint-config", (packageDirectory) =>
12
12
  loadedLintConfigIn(packageDirectory).pipe(Effect.asVoid, quietViolations("lint-config")),
13
13
  ).pipe(Effect.provide(ProjectQueryCachesLive)),
14
- );
14
+ });
@@ -0,0 +1,40 @@
1
+ import { Task } from "@sshkeda/task";
2
+ import { Effect, FileSystem, Path, References, Schema } from "effect";
3
+
4
+ import { projectDirectory } from "../../project-directory/index.ts";
5
+ import { quietViolations } from "./print-failures-and-keep-detail-in-the-trace.ts";
6
+
7
+ const PACKAGE_MANIFEST_FILE = "package.json";
8
+
9
+ class PackageManifestMissing extends Schema.TaggedError<PackageManifestMissing>()(
10
+ "PackageManifestMissing",
11
+ { directory: Schema.String },
12
+ ) {
13
+ public override get message() {
14
+ return `${this.directory} has no ${PACKAGE_MANIFEST_FILE}`;
15
+ }
16
+ }
17
+
18
+ class RepositoryNotFound extends Schema.TaggedError<RepositoryNotFound>()("RepositoryNotFound", {
19
+ directory: Schema.String,
20
+ }) {
21
+ public override get message() {
22
+ return `${this.directory} is not inside a git repository`;
23
+ }
24
+ }
25
+
26
+ export const startDirectory = Task.make({
27
+ name: "start-directory",
28
+ run: Effect.gen(function* () {
29
+ const fileSystem = yield* FileSystem.FileSystem;
30
+ const path = yield* Path.Path;
31
+ const directory = path.resolve(yield* projectDirectory);
32
+ if (!(yield* fileSystem.exists(path.join(directory, PACKAGE_MANIFEST_FILE)))) {
33
+ return yield* new PackageManifestMissing({ directory });
34
+ }
35
+ yield* Task.exec("git", ["rev-parse", "--show-toplevel"], { cwd: directory }).pipe(
36
+ Effect.provideService(References.MinimumLogLevel, "Warn"),
37
+ Effect.catchTag("CommandFailed", () => Effect.fail(new RepositoryNotFound({ directory }))),
38
+ );
39
+ }).pipe(quietViolations("start-directory")),
40
+ });
@@ -26,9 +26,9 @@ const locatedFromThePackage = (
26
26
  : printable;
27
27
  };
28
28
 
29
- export const typeScriptConfig = Task.make(
30
- "typescript-config",
31
- inEachPackage("typescript-config", (packageDirectory) =>
29
+ export const typeScriptConfig = Task.make({
30
+ name: "typescript-config",
31
+ run: inEachPackage("typescript-config", (packageDirectory) =>
32
32
  Path.Path.use((path) =>
33
33
  findTypeScriptConfigViolations(path.join(packageDirectory, TYPESCRIPT_PROJECT_FILE)).pipe(
34
34
  quietViolations("typescript-config"),
@@ -43,4 +43,4 @@ export const typeScriptConfig = Task.make(
43
43
  ),
44
44
  ),
45
45
  ).pipe(Effect.provide(ProjectQueryCachesLive)),
46
- );
46
+ });
@@ -61,7 +61,6 @@ export const isDeclaredSync = (name: string) =>
61
61
  export const TASK_PACKAGE = "@sshkeda/task";
62
62
  export const TASK_NAMESPACE_EXPORT = "Task";
63
63
  export const TASK_MAKE_MEMBER = "make";
64
- export const TASK_MAIN_MEMBER = "main";
65
64
 
66
65
  export const IMPORT_META = "import.meta";
67
66
 
@@ -108,7 +107,6 @@ const CREATE_REQUIRE_IMPORTS = ["createRequire", "Module.createRequire"] as cons
108
107
  export const CREATED_REQUIRE_USAGE = "a require createRequire returns";
109
108
  export const CREATE_REQUIRE_VALUE_USAGE = "createRequire used other than by a call";
110
109
 
111
- export const SCRIPT = "script";
112
110
  export const TRUSTS_UNVERIFIED_TYPES = "trustsUnverifiedTypes";
113
111
  export const WRITES_TO_THE_TERMINAL = "writesToTheTerminal";
114
112
  export const READS_CONFIG = "readsConfig";
@@ -388,11 +386,6 @@ export const PERMISSION_BANS = {
388
386
  memberNamesBan([...SYNC_READS, ...SYNC_WRITES]),
389
387
  ],
390
388
  },
391
- [SCRIPT]: {
392
- ruleName: "no-task-main",
393
- message: "{{usage}} runs tasks outside a script",
394
- bans: [importsBan(TASK_PACKAGE, [`${TASK_NAMESPACE_EXPORT}.${TASK_MAIN_MEMBER}`])],
395
- },
396
389
  };
397
390
 
398
391
  export const PERMISSION_BAN_NAMES = Record.keys(PERMISSION_BANS);
@@ -8,7 +8,6 @@ import {
8
8
  PERMISSION_BANS,
9
9
  READS_CONFIG,
10
10
  RULES_EACH_PERMISSION_LIFTS,
11
- SCRIPT,
12
11
  SHORT_NAMES,
13
12
  TRUSTS_UNVERIFIED_TYPES,
14
13
  UNUSED_GRANT_REPORTED,
@@ -62,7 +61,7 @@ export const PERMISSION_NAMES = [
62
61
 
63
62
  const RETIRED_PERMISSIONS = new Map([
64
63
  ["errors", "error classes may be declared in any file"],
65
- [SCRIPT, `files directly in ${SCRIPTS_DIRECTORY}/ run tasks`],
64
+ ["script", `files directly in ${SCRIPTS_DIRECTORY}/ run tasks`],
66
65
  ]);
67
66
 
68
67
  export const isMarkdown = (path: string) =>
@@ -363,7 +362,6 @@ export const rulesACodeGrantChanges = (
363
362
  const SCRIPTS_OVERRIDE = {
364
363
  files: [`./${SCRIPTS_DIRECTORY}/*`],
365
364
  rules: {
366
- [permissionBanRuleId(SCRIPT)]: "off",
367
365
  "sshkeda/no-re-exports": ["error", { defaultExportOfAnImport: "allowed" }],
368
366
  },
369
367
  } as const;
@@ -1,50 +0,0 @@
1
- import { Task } from "@sshkeda/task";
2
- import { Effect, FileSystem, Path, References, Schema } from "effect";
3
-
4
- import { givenArguments, projectDirectory } from "../../project-directory/index.ts";
5
- import { quietViolations } from "../shared/print-failures-and-keep-detail-in-the-trace.ts";
6
-
7
- const PACKAGE_MANIFEST_FILE = "package.json";
8
-
9
- class ArgumentsNotAccepted extends Schema.TaggedError<ArgumentsNotAccepted>()(
10
- "ArgumentsNotAccepted",
11
- { givenArguments: Schema.Array(Schema.String) },
12
- ) {
13
- public override get message() {
14
- return `check takes no arguments, and was given ${this.givenArguments.join(" ")}`;
15
- }
16
- }
17
-
18
- class PackageManifestMissing extends Schema.TaggedError<PackageManifestMissing>()(
19
- "PackageManifestMissing",
20
- { directory: Schema.String },
21
- ) {
22
- public override get message() {
23
- return `${this.directory} has no ${PACKAGE_MANIFEST_FILE}`;
24
- }
25
- }
26
-
27
- class RepositoryNotFound extends Schema.TaggedError<RepositoryNotFound>()("RepositoryNotFound", {
28
- directory: Schema.String,
29
- }) {
30
- public override get message() {
31
- return `${this.directory} is not inside a git repository`;
32
- }
33
- }
34
-
35
- export const verifyWhereCheckWasStarted = Effect.gen(function* () {
36
- const fileSystem = yield* FileSystem.FileSystem;
37
- const path = yield* Path.Path;
38
- const given = yield* givenArguments;
39
- if (given.length > 0) {
40
- return yield* new ArgumentsNotAccepted({ givenArguments: given });
41
- }
42
- const directory = path.resolve(yield* projectDirectory);
43
- if (!(yield* fileSystem.exists(path.join(directory, PACKAGE_MANIFEST_FILE)))) {
44
- return yield* new PackageManifestMissing({ directory });
45
- }
46
- yield* Task.exec("git", ["rev-parse", "--show-toplevel"], { cwd: directory }).pipe(
47
- Effect.provideService(References.MinimumLogLevel, "Warn"),
48
- Effect.catchTag("CommandFailed", () => Effect.fail(new RepositoryNotFound({ directory }))),
49
- );
50
- }).pipe(quietViolations("check"));
@@ -1,178 +0,0 @@
1
- import { Effect, FileSystem } from "effect";
2
- import { parseSync, Visitor } from "oxc-parser";
3
- import type { ExportSpecifier, Expression, ParseResult } from "oxc-parser";
4
-
5
- import {
6
- TASK_MAIN_MEMBER,
7
- TASK_MAKE_MEMBER,
8
- TASK_PACKAGE,
9
- } from "../../../../../shared/bans-each-permission-lifts.ts";
10
- import {
11
- directoryOf,
12
- isRootSupportFile,
13
- isScript,
14
- isTopLevelScript,
15
- } from "../../../shared/classify-files-by-role.ts";
16
- import { resolveModuleRequest } from "../../../shared/resolve-module-requests.ts";
17
-
18
- const exportNameOf = (name: ExportSpecifier["local"]) =>
19
- name.type === "Identifier" ? name.name : name.value;
20
-
21
- const candidateImportRoots = (parsed: ParseResult) => {
22
- const names = new Set<string>();
23
- const remember = (expression: Expression) => {
24
- if (expression.type === "Identifier") {
25
- names.add(expression.name);
26
- return;
27
- }
28
- const isTaskMember =
29
- expression.type === "MemberExpression" &&
30
- !expression.computed &&
31
- expression.property.type === "Identifier" &&
32
- [TASK_MAKE_MEMBER, TASK_MAIN_MEMBER].includes(expression.property.name);
33
- if (!isTaskMember) {
34
- return;
35
- }
36
- const { object } = expression;
37
- const root = object.type === "MemberExpression" ? object.object : object;
38
- if (root.type === "Identifier") {
39
- names.add(root.name);
40
- }
41
- };
42
- new Visitor({
43
- CallExpression(node) {
44
- remember(node.callee);
45
- },
46
- VariableDeclarator({ init: initializer }) {
47
- if (initializer !== null) {
48
- remember(initializer);
49
- }
50
- },
51
- }).visit(parsed.program);
52
- return names;
53
- };
54
-
55
- export const taskImportsIn = (file: string, text: string, directory: string) =>
56
- Effect.gen(function* () {
57
- const fileSystem = yield* FileSystem.FileSystem;
58
- const projectRoot = yield* fileSystem.realPath(directory);
59
- const taskExportFrom = (
60
- importingFile: string,
61
- request: string,
62
- members: readonly string[],
63
- seen: ReadonlySet<string> = new Set(),
64
- ): Effect.Effect<
65
- readonly string[] | undefined,
66
- | Effect.Error<ReturnType<typeof fileSystem.readFileString>>
67
- | Effect.Error<ReturnType<typeof resolveModuleRequest>>,
68
- Effect.Services<ReturnType<typeof resolveModuleRequest>>
69
- > =>
70
- Effect.gen(function* () {
71
- if (request === TASK_PACKAGE) {
72
- return members;
73
- }
74
- const target = yield* resolveModuleRequest({
75
- importingFile,
76
- request,
77
- customConditions: [],
78
- projectDirectory: directory,
79
- });
80
- if (target === undefined) {
81
- return;
82
- }
83
- const isTaskDependency =
84
- target.packageName === TASK_PACKAGE && target.packageRoot !== projectRoot;
85
- if (isTaskDependency) {
86
- return members;
87
- }
88
- const key = `${target.file}\0${members.join(".")}`;
89
- if (seen.has(key)) {
90
- return;
91
- }
92
- const followed = new Set([...seen, key]);
93
- const parsed = parseSync(target.file, yield* fileSystem.readFileString(target.file));
94
- const [name, ...rest] = members;
95
- if (name === undefined) {
96
- return;
97
- }
98
- for (const statement of parsed.program.body) {
99
- if (statement.type === "ExportNamedDeclaration") {
100
- if (statement.exportKind === "type") {
101
- continue;
102
- }
103
- const specifier = statement.specifiers.find(
104
- (entry) => exportNameOf(entry.exported) === name && entry.exportKind !== "type",
105
- );
106
- if (specifier !== undefined) {
107
- const localName = exportNameOf(specifier.local);
108
- if (statement.source !== null) {
109
- return yield* taskExportFrom(
110
- target.file,
111
- statement.source.value,
112
- [localName, ...rest],
113
- followed,
114
- );
115
- }
116
- for (const declaration of parsed.module.staticImports) {
117
- const binding = declaration.entries.find(
118
- (entry) => !entry.isType && entry.localName.value === localName,
119
- );
120
- if (binding !== undefined) {
121
- const importedMembers =
122
- binding.importName.kind === "NamespaceObject"
123
- ? rest
124
- : [binding.importName.name ?? "", ...rest];
125
- return yield* taskExportFrom(
126
- target.file,
127
- declaration.moduleRequest.value,
128
- importedMembers,
129
- followed,
130
- );
131
- }
132
- }
133
- }
134
- }
135
- const isValueStarExport =
136
- statement.type === "ExportAllDeclaration" && statement.exportKind !== "type";
137
- if (isValueStarExport) {
138
- const exported =
139
- statement.exported === null ? undefined : exportNameOf(statement.exported);
140
- const forwardsName = exported === undefined || exported === name;
141
- if (forwardsName) {
142
- const found = yield* taskExportFrom(
143
- target.file,
144
- statement.source.value,
145
- exported === undefined ? members : rest,
146
- followed,
147
- );
148
- if (found !== undefined) {
149
- return found;
150
- }
151
- }
152
- }
153
- }
154
- return yield* Effect.undefined;
155
- });
156
- const imports = new Map<string, readonly string[]>();
157
- const parsed = parseSync(file, text);
158
- const candidates = candidateImportRoots(parsed);
159
- for (const declaration of parsed.module.staticImports) {
160
- for (const entry of declaration.entries) {
161
- const isCandidate = !entry.isType && candidates.has(entry.localName.value);
162
- if (!isCandidate) {
163
- continue;
164
- }
165
- const members =
166
- entry.importName.kind === "NamespaceObject" ? [] : [entry.importName.name ?? ""];
167
- const reference = yield* taskExportFrom(file, declaration.moduleRequest.value, members);
168
- if (reference !== undefined) {
169
- imports.set(entry.localName.value, reference);
170
- }
171
- }
172
- }
173
- return imports;
174
- });
175
-
176
- export const isTaskLayoutFile = (file: string) =>
177
- isScript(file) &&
178
- (isTopLevelScript(file) || (directoryOf(file) === "" && !isRootSupportFile(file)));