@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
package/README.md
CHANGED
|
@@ -4,11 +4,11 @@ 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,
|
|
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
|
|
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
|
-
Check is
|
|
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
|
|
|
13
13
|
## See it catch slop
|
|
14
14
|
|
|
@@ -37,18 +37,19 @@ Here's what Check prints when it runs on that code:
|
|
|
37
37
|
[effect-tsgo] src/index.ts:1:25: error effect(asyncFunction): This code declares an async function, consider representing this async control flow with Effect values and `Effect.gen`.
|
|
38
38
|
[effect-tsgo] src/index.ts:3:28: error effect(globalFetch): This code uses the global `fetch` function, HTTP requests are represented through `HttpClient` from `effect/http`.
|
|
39
39
|
[effect-tsgo] error ToolExited: effect-tsgo exited with code 1
|
|
40
|
-
[oxlint] src/index.ts:4:12: error typescript(consistent-type-assertions): Do not use any type assertions.
|
|
41
|
-
[oxlint] src/index.ts:4:39: error typescript(no-explicit-any): Unexpected `any`. Specify a different type.
|
|
42
|
-
[oxlint] src/index.ts:7:5: error eslint(no-console): Unexpected console statement.
|
|
43
40
|
[oxlint] src/index.ts:1:25: error sshkeda(no-index-logic): index file holds an arrow function expression
|
|
41
|
+
[oxlint] src/index.ts:4:5: error typescript(no-unsafe-return): Unsafe return of a value of type `any`.
|
|
42
|
+
[oxlint] src/index.ts:4:12: error typescript(consistent-type-assertions): Do not use any type assertions.
|
|
44
43
|
[oxlint] src/index.ts:4:19: error sshkeda(no-unchecked-parsing): json() parses JSON without a Schema
|
|
44
|
+
[oxlint] src/index.ts:4:39: error typescript(no-explicit-any): Unexpected `any`. Specify a different type.
|
|
45
45
|
[oxlint] src/index.ts:6:5: error sshkeda(no-comments): comment in code
|
|
46
|
-
[oxlint] src/index.ts:
|
|
46
|
+
[oxlint] src/index.ts:7:5: error eslint(no-console): Unexpected console statement.
|
|
47
47
|
[oxlint] error ToolExited: oxlint exited with code 1
|
|
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
|
|
51
|
+
failed: effect-tsgo, oxlint (2 of 18 tasks), 1.0s
|
|
52
|
+
...
|
|
52
53
|
```
|
|
53
54
|
|
|
54
55
|
Here's what each error catches:
|
|
@@ -84,7 +85,7 @@ Check passes.
|
|
|
84
85
|
|
|
85
86
|
- **No comments.** When code is hard to follow, the fix is better names and simpler code, which stay true as the code changes. Comments drift out of date, and agents fill them with noise. When you need more explanation, ask your agent to explain the code.
|
|
86
87
|
- **No `type` or `interface` declarations.** Types are inferred from the code that produces each value, so every type has one source of truth and nothing to keep in sync.
|
|
87
|
-
- **No `let
|
|
88
|
+
- **No `let`, and no `while` or counting `for` loops.** Values don't change after they're made, which leaves an agent fewer ways to get state wrong.
|
|
88
89
|
- **Modules with `internal/`, `shared/` and `lib/`.** Each module exposes its public code in `index.ts`, keeps private code in `internal/`, which only that module may import, puts code its parts share in `shared/` and holds its child modules in `lib/`. Code stays easy to organize and hard to tangle.
|
|
89
90
|
- **No abbreviations.** `imABigFanWhenVariablesAreLongBecauseThenItsEasierToUnderstandWhatTheCodeDoes`. Full words read the same to every person and every agent.
|
|
90
91
|
- **No unchecked data.** JSON and other input pass through a Schema before the code trusts them, because a type assertion or a hand-written type guard proves nothing.
|
|
@@ -93,17 +94,17 @@ Check passes.
|
|
|
93
94
|
- **Tests are tasks.** Every test is a Task task in `tests/`, never a Vitest, Jest or `bun:test` suite. Tests run in parallel and clean up after themselves.
|
|
94
95
|
- **Each service in its own layer.** Services are declared only in files you grant, which keeps their wiring in one place.
|
|
95
96
|
- **No polling.** Code waits for an event or a signal instead of checking on a timer, so it reacts right away. When there's nothing to listen to, such as a server that's still starting, polling needs a grant and a time limit.
|
|
96
|
-
- **No dropped failures.** Every error is handled or passed on, so nothing fails silently.
|
|
97
|
+
- **No dropped failures.** Every error is handled or passed on, and a fork that can fail must keep its fiber, so nothing fails silently.
|
|
97
98
|
- **Risky access only where you grant it.** Reading environment variables, starting commands and printing to the terminal each need a grant on the exact file that does it.
|
|
98
99
|
|
|
99
100
|
## Get started
|
|
100
101
|
|
|
101
102
|
Check needs Bun 1.4.4 or newer and a Git repository.
|
|
102
103
|
|
|
103
|
-
1. Install Check,
|
|
104
|
+
1. Install Check, Effect and Bun's types.
|
|
104
105
|
|
|
105
106
|
```bash
|
|
106
|
-
bun add @sshkeda/check
|
|
107
|
+
bun add @sshkeda/check effect
|
|
107
108
|
bun add -d @types/bun
|
|
108
109
|
```
|
|
109
110
|
|
|
@@ -142,22 +143,15 @@ Check needs Bun 1.4.4 or newer and a Git repository.
|
|
|
142
143
|
export default FORMAT_CONFIG;
|
|
143
144
|
```
|
|
144
145
|
|
|
145
|
-
5.
|
|
146
|
-
|
|
147
|
-
```ts
|
|
148
|
-
import { check } from "@sshkeda/check/tasks";
|
|
149
|
-
import { Task } from "@sshkeda/task";
|
|
146
|
+
5. Run Check, and have your agent fix what it reports. Expect the first run to fail, even on a new project from `bun init`.
|
|
150
147
|
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
}
|
|
148
|
+
```bash
|
|
149
|
+
bunx @sshkeda/check
|
|
154
150
|
```
|
|
155
151
|
|
|
156
|
-
|
|
152
|
+
Check checks the package in the directory you start it in.
|
|
157
153
|
|
|
158
|
-
|
|
159
|
-
bun scripts/ci.ts
|
|
160
|
-
```
|
|
154
|
+
To run one check alone, name it, as in `bunx @sshkeda/check oxlint`.
|
|
161
155
|
|
|
162
156
|
## Make it yours
|
|
163
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,40 +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
|
+
- 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.
|
|
12
14
|
- Grant `isGeneratedByATool` only to a file a tool generates.
|
|
13
15
|
|
|
14
|
-
## Grant a permission
|
|
15
|
-
|
|
16
|
-
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.
|
|
17
|
-
|
|
18
|
-
```ts
|
|
19
|
-
export default lintConfig({
|
|
20
|
-
"src/config.ts": { allow: ["readsConfig"] },
|
|
21
|
-
"src/internal/run-all-checks.ts": { allow: ["handlesEveryFailure"] },
|
|
22
|
-
});
|
|
23
|
-
```
|
|
24
|
-
|
|
25
|
-
- `readsConfig`: Allows Effect `Config`, `process.env` and `process.argv`.
|
|
26
|
-
- `spawnsCommands`: Allows Effect `ChildProcess`, `Bun.spawn` and `spawn` from `node:child_process`.
|
|
27
|
-
- `locksFiles`: Allows `open` from `node:fs/promises` and `constants` from `node:fs`.
|
|
28
|
-
- `importsDynamically`: Allows `import()` and `createRequire(…).resolve`.
|
|
29
|
-
- `exitsTheProcess`: Allows `process.exit`.
|
|
30
|
-
- `usesSqlDatabases`: Allows Effect SQL.
|
|
31
|
-
- `writesToTheTerminal`: Allows Effect `Stdio`.
|
|
32
|
-
- `usesAbbreviations`: Allows abbreviations in variable, function, type and other declared names.
|
|
33
|
-
- `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`.
|
|
34
|
-
- `waitsOnTimers`: Allows `Effect.sleep`, `Effect.delay`, `Clock.sleep` and the Stream operations that wait on a timer, such as `Stream.tick`.
|
|
35
|
-
- `hasAnUnlistedFileType`: Allows a file type Check doesn't list, such as Markdown.
|
|
36
|
-
- `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.
|
|
37
|
-
- `patchesADependency`: Allows a patch file from `bun patch`.
|
|
38
|
-
- `trustsUnverifiedTypes`: Allows trusting a value's type without checking it, through `Schema.declare`.
|
|
39
|
-
- `handlesEveryFailure`: Allows catching every error, through `Effect.catch`, `Effect.exit`, a forked fiber or `Effect.runPromise`.
|
|
40
|
-
- `fallsBackToFixedValues`: Allows answering every failure, or a whole library error such as `PlatformError`, with a fixed value that never reads the failure.
|
|
41
|
-
- `isGeneratedByATool`: Check skips this path, so it can't have any other permission.
|
|
42
|
-
|
|
43
16
|
## Make the code explain itself
|
|
44
17
|
|
|
45
18
|
- Use what Effect, Bun or a dependency already provides.
|
|
@@ -53,7 +26,8 @@ export default lintConfig({
|
|
|
53
26
|
## Make program output clear
|
|
54
27
|
|
|
55
28
|
- Follow Git and uv's style. Say what failed, name the affected file or value and explain the cause.
|
|
56
|
-
- Give the reader enough context to choose a fix.
|
|
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.
|
|
57
31
|
- Report each cause once. Put the main failure first, supporting details below it and internal debugging details in the trace.
|
|
58
32
|
- Preserve useful messages from underlying tools, including error codes and exact names.
|
|
59
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
|
+
"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"
|
|
@@ -10,14 +10,17 @@
|
|
|
10
10
|
"type": "git",
|
|
11
11
|
"url": "git+https://github.com/sshkeda/check.git"
|
|
12
12
|
},
|
|
13
|
+
"bin": {
|
|
14
|
+
"check": "./scripts/check.ts"
|
|
15
|
+
},
|
|
13
16
|
"files": [
|
|
14
17
|
"docs",
|
|
18
|
+
"scripts/check.ts",
|
|
15
19
|
"src"
|
|
16
20
|
],
|
|
17
21
|
"type": "module",
|
|
18
22
|
"exports": {
|
|
19
|
-
".": "./src/index.ts"
|
|
20
|
-
"./tasks": "./src/lib/tasks/index.ts"
|
|
23
|
+
".": "./src/index.ts"
|
|
21
24
|
},
|
|
22
25
|
"publishConfig": {
|
|
23
26
|
"access": "public",
|
|
@@ -27,6 +30,7 @@
|
|
|
27
30
|
"@effect/platform-bun": "4.1.0",
|
|
28
31
|
"@effect/tsgo": "0.67.4",
|
|
29
32
|
"@oxlint/plugins": "1.88.0",
|
|
33
|
+
"@sshkeda/task": "2.0.0",
|
|
30
34
|
"oxc-parser": "0.153.0",
|
|
31
35
|
"oxc-resolver": "11.24.2",
|
|
32
36
|
"oxlint": "1.88.0",
|
|
@@ -34,19 +38,12 @@
|
|
|
34
38
|
"typescript": "7.0.2"
|
|
35
39
|
},
|
|
36
40
|
"devDependencies": {
|
|
37
|
-
"@sshkeda/task": "^1.0.0",
|
|
38
41
|
"@types/bun": "1.4.3",
|
|
39
42
|
"effect": "4.1.0"
|
|
40
43
|
},
|
|
41
44
|
"peerDependencies": {
|
|
42
|
-
"@sshkeda/task": "^1.0.0",
|
|
43
45
|
"effect": "^4.1.0"
|
|
44
46
|
},
|
|
45
|
-
"peerDependenciesMeta": {
|
|
46
|
-
"@sshkeda/task": {
|
|
47
|
-
"optional": true
|
|
48
|
-
}
|
|
49
|
-
},
|
|
50
47
|
"engines": {
|
|
51
48
|
"bun": ">=1.4.4"
|
|
52
49
|
}
|
package/scripts/check.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
#!/usr/bin/env bun
|
|
2
|
+
import { PROJECT_DIRECTORY_VARIABLE } from "../src/lib/project-directory/index.ts";
|
|
3
|
+
import { check } from "../src/lib/tasks/index.ts";
|
|
4
|
+
|
|
5
|
+
if (import.meta.main) {
|
|
6
|
+
process.env[PROJECT_DIRECTORY_VARIABLE] = process.cwd();
|
|
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
|
|
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,8 +1,10 @@
|
|
|
1
1
|
import { defineRule } from "@oxlint/plugins";
|
|
2
2
|
import type { ESTree } from "@oxlint/plugins";
|
|
3
|
+
import { Schema } from "effect";
|
|
3
4
|
|
|
4
5
|
import { FORMAT_CONFIG_BINDING, FORMAT_CONFIG_FILE } from "../shared/config-file-names.ts";
|
|
5
6
|
import { fileNameOf, isEntryFileName } from "../shared/match-file-names-and-path-prefixes.ts";
|
|
7
|
+
import { decodeRuleOptions, ruleOptionsJsonSchema } from "./describe-and-decode-rule-options.ts";
|
|
6
8
|
import {
|
|
7
9
|
DEFAULT_EXPORT,
|
|
8
10
|
importedBindingOf,
|
|
@@ -13,6 +15,12 @@ import {
|
|
|
13
15
|
unwrappedExpression,
|
|
14
16
|
} from "./resolve-what-an-expression-imports.ts";
|
|
15
17
|
|
|
18
|
+
const DEFAULT_EXPORTS_OF_IMPORTS = ["banned", "allowed"] as const;
|
|
19
|
+
|
|
20
|
+
const RE_EXPORTS_OPTIONS = Schema.Struct({
|
|
21
|
+
defaultExportOfAnImport: Schema.optionalKey(Schema.Literals(DEFAULT_EXPORTS_OF_IMPORTS)),
|
|
22
|
+
});
|
|
23
|
+
|
|
16
24
|
export const noReExports = defineRule({
|
|
17
25
|
meta: {
|
|
18
26
|
type: "suggestion",
|
|
@@ -30,8 +38,11 @@ export const noReExports = defineRule({
|
|
|
30
38
|
importEquals: "export import {{name}} re-exports another module",
|
|
31
39
|
exportAssignment: "export = replaces the module's exports",
|
|
32
40
|
},
|
|
41
|
+
schema: ruleOptionsJsonSchema(RE_EXPORTS_OPTIONS),
|
|
33
42
|
},
|
|
34
43
|
create(context) {
|
|
44
|
+
const defaultExportOfAnImport =
|
|
45
|
+
decodeRuleOptions(RE_EXPORTS_OPTIONS, context.options)?.defaultExportOfAnImport ?? "banned";
|
|
35
46
|
const isIndexFile = isEntryFileName(fileNameOf(context.filename));
|
|
36
47
|
const isFormatConfigFile = fileNameOf(context.filename) === FORMAT_CONFIG_FILE;
|
|
37
48
|
const reportImport = (
|
|
@@ -195,7 +206,9 @@ export const noReExports = defineRule({
|
|
|
195
206
|
statement.declaration.name === FORMAT_CONFIG_BINDING &&
|
|
196
207
|
importedExpression(statement.declaration, context.sourceCode)?.members.join() ===
|
|
197
208
|
FORMAT_CONFIG_BINDING;
|
|
198
|
-
|
|
209
|
+
const isAllowedDefaultExport =
|
|
210
|
+
exportsTheFormatConfig || defaultExportOfAnImport === "allowed";
|
|
211
|
+
if (!isAllowedDefaultExport) {
|
|
199
212
|
reportImported(statement, DEFAULT_EXPORT, statement.declaration);
|
|
200
213
|
}
|
|
201
214
|
} else if (statement.type === "TSExportAssignment") {
|
|
@@ -50,7 +50,6 @@ import { noExistsRecovery } from "./ban-recovering-file-system-exists.ts";
|
|
|
50
50
|
import { noRetiredWords } from "./ban-retired-words-in-names.ts";
|
|
51
51
|
import { noInstantRetries } from "./ban-retries-without-a-wait.ts";
|
|
52
52
|
import { noGlobScan } from "./ban-scanning-directories-with-bun-glob.ts";
|
|
53
|
-
import { noShebang } from "./ban-shebang-lines.ts";
|
|
54
53
|
import { globalRule } from "./ban-timer-globals-and-the-global-object.ts";
|
|
55
54
|
import { noSchedules } from "./ban-timer-schedules-without-deadlines.ts";
|
|
56
55
|
import { noTypeDeclarations } from "./ban-type-and-interface-declarations.ts";
|
|
@@ -158,7 +157,6 @@ const NAMED_RULES = {
|
|
|
158
157
|
"no-let": noLet,
|
|
159
158
|
"no-mutable-ref": noMutableRef,
|
|
160
159
|
"no-while": noWhile,
|
|
161
|
-
"no-shebang": noShebang,
|
|
162
160
|
"no-shared-holders": noSharedHolders,
|
|
163
161
|
"no-uncalled-members": noUncalledMembers,
|
|
164
162
|
"no-unnamed-fallbacks": noUnnamedFallbacks,
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Config } from "effect";
|
|
2
|
+
|
|
3
|
+
export const PROJECT_DIRECTORY_VARIABLE = "SSHKEDA_CHECK_PROJECT_DIRECTORY";
|
|
4
|
+
|
|
5
|
+
const THE_PACKAGE_THAT_RUNS_THE_TASK = ".";
|
|
6
|
+
|
|
7
|
+
export const projectDirectory = Config.String(PROJECT_DIRECTORY_VARIABLE).pipe(
|
|
8
|
+
Config.withDefault(THE_PACKAGE_THAT_RUNS_THE_TASK),
|
|
9
|
+
);
|
|
@@ -1,11 +1,13 @@
|
|
|
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 { duplicateFunctions } from "../lib/detect-duplicate-functions/index.ts";
|
|
5
6
|
import { layout } from "../lib/enforce-file-layout/index.ts";
|
|
6
7
|
import { fileTypes } from "../lib/enforce-file-types/index.ts";
|
|
7
8
|
import { formatting } from "../lib/format-with-bun-fmt/index.ts";
|
|
8
9
|
import { lintConfigFile } from "../shared/declare-lint-config-task.ts";
|
|
10
|
+
import { startDirectory } from "../shared/declare-start-directory-task.ts";
|
|
9
11
|
import { typeScriptConfig } from "../shared/declare-typescript-config-task.ts";
|
|
10
12
|
import { typedChecks } from "./declare-the-typed-checks-task.ts";
|
|
11
13
|
|
|
@@ -13,19 +15,25 @@ const GUIDE_FILE = new URL("../../../../docs/how-to-make-check-pass.md", import.
|
|
|
13
15
|
|
|
14
16
|
const pointAtTheGuide = Effect.gen(function* () {
|
|
15
17
|
const path = yield* Path.Path;
|
|
16
|
-
const guide = path.relative(
|
|
18
|
+
const guide = path.relative(
|
|
19
|
+
path.resolve(yield* projectDirectory),
|
|
20
|
+
yield* path.fromFileUrl(GUIDE_FILE),
|
|
21
|
+
);
|
|
17
22
|
yield* Effect.logError(`read ${guide} before you change the code`);
|
|
18
23
|
});
|
|
19
24
|
|
|
20
|
-
export const check: Task.Task<void> = Task.make(
|
|
21
|
-
"check",
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
25
|
+
export const check: Task.Task<void> = Task.make({
|
|
26
|
+
name: "check",
|
|
27
|
+
run: Effect.andThen(
|
|
28
|
+
startDirectory,
|
|
29
|
+
Task.allSettled([
|
|
30
|
+
typeScriptConfig,
|
|
31
|
+
lintConfigFile,
|
|
32
|
+
typedChecks,
|
|
33
|
+
formatting,
|
|
34
|
+
layout,
|
|
35
|
+
fileTypes,
|
|
36
|
+
duplicateFunctions,
|
|
37
|
+
]).pipe(Effect.tapError(() => pointAtTheGuide)),
|
|
38
|
+
),
|
|
39
|
+
});
|
|
@@ -10,6 +10,7 @@ import { findRepeatedServiceYields } from "../lib/detect-repeated-service-yields
|
|
|
10
10
|
import { findIndexReExportViolations } from "../lib/judge-index-re-exports/index.ts";
|
|
11
11
|
import { findExportPlacementViolations } from "../lib/place-exports-in-the-narrowest-directory/index.ts";
|
|
12
12
|
import { findErrorMappingsToDone } from "../lib/refuse-error-mappings-that-end-streams/index.ts";
|
|
13
|
+
import { findUnobservedForkFailures } from "../lib/refuse-forks-whose-failures-nothing-observes/index.ts";
|
|
13
14
|
import { findServiceLayerViolations } from "../lib/require-separate-service-layers/index.ts";
|
|
14
15
|
import { inEachPackage } from "../shared/check-each-nested-package.ts";
|
|
15
16
|
import { lintConfigFile } from "../shared/declare-lint-config-task.ts";
|
|
@@ -18,11 +19,11 @@ import { ProjectQueryCachesLive } from "../shared/provide-project-query-caches.t
|
|
|
18
19
|
import { TYPESCRIPT_PROJECT_FILE } from "../shared/query-the-typescript-project.ts";
|
|
19
20
|
import { runChecksOverOneTypeScriptProject } from "./run-checks-over-one-typescript-project.ts";
|
|
20
21
|
|
|
21
|
-
export const checkerQueries = Task.make(
|
|
22
|
-
"checker-queries",
|
|
23
|
-
Effect.andThen(
|
|
22
|
+
export const checkerQueries = Task.make({
|
|
23
|
+
name: "checker-queries",
|
|
24
|
+
run: Effect.andThen(
|
|
24
25
|
Task.all([typeScriptConfig, lintConfigFile]),
|
|
25
|
-
inEachPackage("checker-queries",
|
|
26
|
+
inEachPackage("checker-queries", (packageDirectory) =>
|
|
26
27
|
Path.Path.use((path) =>
|
|
27
28
|
runChecksOverOneTypeScriptProject(path.join(packageDirectory, TYPESCRIPT_PROJECT_FILE), {
|
|
28
29
|
"service-yields": findRepeatedServiceYields,
|
|
@@ -34,9 +35,10 @@ export const checkerQueries = Task.make(
|
|
|
34
35
|
"export-placement": findExportPlacementViolations,
|
|
35
36
|
"layer-provides": findLayerProvidesOutsideProgramStarts,
|
|
36
37
|
"error-mappings": findErrorMappingsToDone,
|
|
38
|
+
"fork-failures": findUnobservedForkFailures,
|
|
37
39
|
"re-exports": findIndexReExportViolations,
|
|
38
40
|
}),
|
|
39
41
|
),
|
|
40
42
|
),
|
|
41
43
|
).pipe(Effect.provide(ProjectQueryCachesLive)),
|
|
42
|
-
);
|
|
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
|
-
inEachPackage("effect-tsgo",
|
|
14
|
+
inEachPackage("effect-tsgo", effectDiagnosticsIn),
|
|
15
15
|
).pipe(Effect.provide(ProjectQueryCachesLive)),
|
|
16
|
-
);
|
|
16
|
+
});
|
|
@@ -4,7 +4,6 @@ import { NodeFlags } from "typescript/unstable/ast";
|
|
|
4
4
|
import type { CallExpression, Node, SourceFile } from "typescript/unstable/ast";
|
|
5
5
|
import {
|
|
6
6
|
isArrowFunction,
|
|
7
|
-
isAsExpression,
|
|
8
7
|
isBlock,
|
|
9
8
|
isCallExpression,
|
|
10
9
|
isConditionalExpression,
|
|
@@ -12,13 +11,10 @@ import {
|
|
|
12
11
|
isFunctionDeclaration,
|
|
13
12
|
isFunctionExpression,
|
|
14
13
|
isIdentifier,
|
|
15
|
-
isNonNullExpression,
|
|
16
14
|
isObjectLiteralExpression,
|
|
17
15
|
isParameterDeclaration,
|
|
18
|
-
|
|
19
|
-
isPropertyAccessExpression,
|
|
16
|
+
isPropertyAssignment,
|
|
20
17
|
isReturnStatement,
|
|
21
|
-
isSatisfiesExpression,
|
|
22
18
|
isSpreadElement,
|
|
23
19
|
isVariableDeclaration,
|
|
24
20
|
isVariableStatement,
|
|
@@ -37,6 +33,12 @@ import {
|
|
|
37
33
|
typeScriptRequest,
|
|
38
34
|
} from "../../../shared/query-the-typescript-project.ts";
|
|
39
35
|
import type { openTypeScriptProjects } from "../../../shared/query-the-typescript-project.ts";
|
|
36
|
+
import {
|
|
37
|
+
outermostWrapperOf,
|
|
38
|
+
pipedStepsOf,
|
|
39
|
+
referencedNameOf,
|
|
40
|
+
withoutWrappers,
|
|
41
|
+
} from "../../../shared/read-piped-steps-through-wrappers.ts";
|
|
40
42
|
import { absolutePathOf } from "../../../shared/resolve-absolute-paths.ts";
|
|
41
43
|
import {
|
|
42
44
|
LayerProvidedOutsideProgramStart,
|
|
@@ -78,7 +80,6 @@ const EFFECT_OPERATIONS = [
|
|
|
78
80
|
{ module: STREAM_MODULE, names: PROVIDE_OPERATIONS },
|
|
79
81
|
];
|
|
80
82
|
const PROVIDING_MODULES = [EFFECT_MODULE, STREAM_MODULE];
|
|
81
|
-
const PIPE = "pipe";
|
|
82
83
|
const PROVIDED_ARGUMENTS = 2;
|
|
83
84
|
|
|
84
85
|
const anyOf = <Item, Failure>(
|
|
@@ -86,18 +87,6 @@ const anyOf = <Item, Failure>(
|
|
|
86
87
|
predicate: (item: Item) => Effect.Effect<boolean, Failure>,
|
|
87
88
|
) => Effect.findFirst(items, predicate).pipe(Effect.map(Option.isSome));
|
|
88
89
|
|
|
89
|
-
const isWrapper = (node: Node) =>
|
|
90
|
-
isParenthesizedExpression(node) ||
|
|
91
|
-
isAsExpression(node) ||
|
|
92
|
-
isSatisfiesExpression(node) ||
|
|
93
|
-
isNonNullExpression(node);
|
|
94
|
-
|
|
95
|
-
const withoutWrappers = (node: Node): Node =>
|
|
96
|
-
isWrapper(node) ? withoutWrappers(node.expression) : node;
|
|
97
|
-
|
|
98
|
-
const outermostWrapperOf = (node: Node): Node =>
|
|
99
|
-
isWrapper(node.parent) ? outermostWrapperOf(node.parent) : node;
|
|
100
|
-
|
|
101
90
|
const isFunctionLike = (node: Node) =>
|
|
102
91
|
isFunctionDeclaration(node) || isFunctionExpression(node) || isArrowFunction(node);
|
|
103
92
|
|
|
@@ -122,14 +111,6 @@ const returnedBy = (callable: Node) => {
|
|
|
122
111
|
return returned;
|
|
123
112
|
};
|
|
124
113
|
|
|
125
|
-
const referencedNameOf = (node: Node) => {
|
|
126
|
-
const reference = withoutWrappers(node);
|
|
127
|
-
if (isPropertyAccessExpression(reference)) {
|
|
128
|
-
return reference.name;
|
|
129
|
-
}
|
|
130
|
-
return isIdentifier(reference) ? reference : undefined;
|
|
131
|
-
};
|
|
132
|
-
|
|
133
114
|
const isExportOf = (
|
|
134
115
|
apis: Effect.Success<ReturnType<typeof importedPackageApis>>,
|
|
135
116
|
symbol: TypeScriptSymbol | undefined,
|
|
@@ -137,16 +118,6 @@ const isExportOf = (
|
|
|
137
118
|
names: ReadonlySet<string>,
|
|
138
119
|
) => symbol !== undefined && names.has(symbol.name) && apis.effectExports.get(symbol.id) === module;
|
|
139
120
|
|
|
140
|
-
const pipedStepsOf = (call: CallExpression) => {
|
|
141
|
-
if (referencedNameOf(call.expression)?.text !== PIPE) {
|
|
142
|
-
return;
|
|
143
|
-
}
|
|
144
|
-
const callee = withoutWrappers(call.expression);
|
|
145
|
-
return isPropertyAccessExpression(callee)
|
|
146
|
-
? [callee.expression, ...call.arguments]
|
|
147
|
-
: [...call.arguments];
|
|
148
|
-
};
|
|
149
|
-
|
|
150
121
|
const stepsBefore = (step: Node) => {
|
|
151
122
|
const { parent } = step;
|
|
152
123
|
if (!isCallExpression(parent)) {
|
|
@@ -439,6 +410,12 @@ const isRunnerArgument = (
|
|
|
439
410
|
return isArgument ? startsTheProgram(checker, apis, parent) : Effect.succeed(false);
|
|
440
411
|
};
|
|
441
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
|
+
|
|
442
419
|
const isExported = (declaration: Node) => {
|
|
443
420
|
const statement = declaration.parent.parent;
|
|
444
421
|
return (
|
|
@@ -478,7 +455,14 @@ const isConstOnlyRunByARunner = (
|
|
|
478
455
|
(read) => read !== undefined && read.pos !== declaration.name.pos,
|
|
479
456
|
);
|
|
480
457
|
const isReadOnce = onlyRead !== undefined && otherReads.length === 0;
|
|
481
|
-
return
|
|
458
|
+
return (
|
|
459
|
+
isReadOnce &&
|
|
460
|
+
(yield* isRunnerArgument(
|
|
461
|
+
checker,
|
|
462
|
+
apis,
|
|
463
|
+
objectHoldingAPropertyValue(outermostWrapperOf(onlyRead)),
|
|
464
|
+
))
|
|
465
|
+
);
|
|
482
466
|
});
|
|
483
467
|
|
|
484
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: [
|
|
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
|
+
});
|
|
@@ -142,9 +142,8 @@ export const findDuplicateFunctions = (directory: string, shownDirectory = ".")
|
|
|
142
142
|
|
|
143
143
|
export const duplicateFunctionsOfEachPackage = inEachPackage(
|
|
144
144
|
DUPLICATE_FUNCTIONS,
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
findDuplicateFunctions(packageDirectory, packageDirectory).pipe(
|
|
145
|
+
(packageDirectory, packageDirectoryFromTheProject) =>
|
|
146
|
+
findDuplicateFunctions(packageDirectory, packageDirectoryFromTheProject).pipe(
|
|
148
147
|
quietViolations(DUPLICATE_FUNCTIONS),
|
|
149
148
|
),
|
|
150
149
|
);
|
|
@@ -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
|
+
});
|
|
@@ -4,6 +4,6 @@ import { findFileLayoutViolations } from "./find-file-layout-violations.ts";
|
|
|
4
4
|
|
|
5
5
|
const LAYOUT = "layout";
|
|
6
6
|
|
|
7
|
-
export const fileLayoutViolationsOfEachPackage = inEachPackage(LAYOUT,
|
|
7
|
+
export const fileLayoutViolationsOfEachPackage = inEachPackage(LAYOUT, (packageDirectory) =>
|
|
8
8
|
findFileLayoutViolations(packageDirectory).pipe(quietViolations(LAYOUT)),
|
|
9
9
|
);
|