@sshkeda/check 1.0.1 → 1.1.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 CHANGED
@@ -4,7 +4,7 @@ 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 a handpicked set of oxfmt, oxlint and Effect diagnostic rules, plus `bun check` and about 30 rules of its own. Your agent keeps fixing what it reports until the slop is gone.
7
+ It runs about 310 lint rules, 62 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
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).
10
10
 
@@ -113,6 +113,14 @@ Check needs Bun 1.4.4 or newer and a Git repository.
113
113
  "strict": true,
114
114
  "noUncheckedIndexedAccess": true,
115
115
  "exactOptionalPropertyTypes": true,
116
+ "noImplicitReturns": true,
117
+ "noUnusedLocals": true,
118
+ "noUnusedParameters": true,
119
+ "noPropertyAccessFromIndexSignature": true,
120
+ "noImplicitOverride": true,
121
+ "noFallthroughCasesInSwitch": true,
122
+ "allowUnreachableCode": false,
123
+ "allowUnusedLabels": false,
116
124
  "allowImportingTsExtensions": true,
117
125
  "types": ["bun"]
118
126
  ```
@@ -150,6 +158,10 @@ Check needs Bun 1.4.4 or newer and a Git repository.
150
158
  bun scripts/ci.ts
151
159
  ```
152
160
 
161
+ ## Make it yours
162
+
163
+ Check's rules are one opinion. To change them, clone the repo, add or remove rules, and use your copy instead of the npm package.
164
+
153
165
  ## Development
154
166
 
155
167
  To run its checks and tests, run `bun scripts/ci.ts`. Check checks itself!
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sshkeda/check",
3
- "version": "1.0.1",
3
+ "version": "1.1.0",
4
4
  "homepage": "https://github.com/sshkeda/check#readme",
5
5
  "bugs": {
6
6
  "url": "https://github.com/sshkeda/check/issues"
@@ -2,6 +2,7 @@ import { Effect, Record } from "effect";
2
2
 
3
3
  import {
4
4
  LooseCompilerOption,
5
+ OPTIONS_TSC_LEAVES_UNSET,
5
6
  REQUIRED_VALUES_OF_OPTIONS_OFF_BY_DEFAULT,
6
7
  STRICT_OPTIONS,
7
8
  TypeScriptConfigViolations,
@@ -28,10 +29,13 @@ const optionViolationsOf = (configFile: string) =>
28
29
  resolvedValue:
29
30
  (option === "allowImportingTsExtensions" &&
30
31
  options["rewriteRelativeImportExtensions"] === true) ||
31
- (options[option] ?? false),
32
+ (options[option] ?? (OPTIONS_TSC_LEAVES_UNSET.has(option) ? undefined : false)),
32
33
  }),
33
34
  ),
34
35
  ].flatMap(({ option, required, resolvedValue }) => {
36
+ if (resolvedValue === undefined) {
37
+ return [new LooseCompilerOption({ projectFile: configFile, option })];
38
+ }
35
39
  const isLoose = typeof resolvedValue === "boolean" && resolvedValue !== required;
36
40
  return isLoose
37
41
  ? [new LooseCompilerOption({ projectFile: configFile, option, resolvedValue })]
@@ -336,6 +336,15 @@ export class ToolExited extends Schema.TaggedError<ToolExited>()("ToolExited", {
336
336
  }
337
337
  }
338
338
 
339
+ export class ToolNotStarted extends Schema.TaggedError<ToolNotStarted>()("ToolNotStarted", {
340
+ command: Schema.String,
341
+ reason: Schema.String,
342
+ }) {
343
+ public override get message() {
344
+ return `${this.command} did not start: ${this.reason}`;
345
+ }
346
+ }
347
+
339
348
  export class ToolStoppedBySignal extends Schema.TaggedError<ToolStoppedBySignal>()(
340
349
  "ToolStoppedBySignal",
341
350
  { program: Schema.String, command: Schema.String, signal: Schema.String },
@@ -396,9 +405,22 @@ export const REQUIRED_VALUES_OF_OPTIONS_OFF_BY_DEFAULT = {
396
405
  noUncheckedIndexedAccess: true,
397
406
  exactOptionalPropertyTypes: true,
398
407
  allowImportingTsExtensions: true,
408
+ noImplicitReturns: true,
409
+ noUnusedLocals: true,
410
+ noUnusedParameters: true,
411
+ noPropertyAccessFromIndexSignature: true,
412
+ noImplicitOverride: true,
413
+ noFallthroughCasesInSwitch: true,
414
+ allowUnreachableCode: false,
415
+ allowUnusedLabels: false,
399
416
  noCheck: false,
400
417
  } as const;
401
418
 
419
+ export const OPTIONS_TSC_LEAVES_UNSET: ReadonlySet<string> = new Set([
420
+ "allowUnreachableCode",
421
+ "allowUnusedLabels",
422
+ ]);
423
+
402
424
  export class LooseCompilerOption extends Schema.TaggedError<LooseCompilerOption>()(
403
425
  "LooseCompilerOption",
404
426
  {
@@ -407,14 +429,16 @@ export class LooseCompilerOption extends Schema.TaggedError<LooseCompilerOption>
407
429
  ...STRICT_OPTIONS,
408
430
  ...Record.keys(REQUIRED_VALUES_OF_OPTIONS_OFF_BY_DEFAULT),
409
431
  ]),
410
- resolvedValue: Schema.Boolean,
432
+ resolvedValue: Schema.optionalKey(Schema.Boolean),
411
433
  },
412
434
  ) {
413
435
  public get location() {
414
436
  return this.projectFile;
415
437
  }
416
438
  public override get message() {
417
- return `${this.option} resolves to ${this.resolvedValue}`;
439
+ return this.resolvedValue === undefined
440
+ ? `${this.option} is unset`
441
+ : `${this.option} resolves to ${this.resolvedValue}`;
418
442
  }
419
443
  }
420
444
 
@@ -280,7 +280,11 @@ const compiledFilesOf = (
280
280
  const projectDirectory = path.dirname(yield* absolutePathOf(projectFile));
281
281
  const listedFilesOfEachProject = yield* Effect.forEach(projects, ([configFile, { program }]) =>
282
282
  typeScriptRequest("list the program files", () => program.getSourceFileNames()).pipe(
283
- Effect.map((fileNames) => ({ configFile, program, fileNames })),
283
+ Effect.map((fileNames) => ({
284
+ configFile,
285
+ program,
286
+ fileNames: fileNames.filter((fileName) => path.isAbsolute(fileName)),
287
+ })),
284
288
  ),
285
289
  );
286
290
  const everyListedFile = listedFilesOfEachProject.flatMap(({ fileNames }) => fileNames);
@@ -1,8 +1,15 @@
1
+ import { open } from "node:fs/promises";
2
+
3
+ import type { Subprocess } from "bun";
1
4
  import type { Array as Arrays, Schema } from "effect";
2
- import { Effect, Stream } from "effect";
3
- import { ChildProcess } from "effect/process";
5
+ import { Effect, FileSystem } from "effect";
4
6
 
5
- import { ToolExited, ToolReportUndecodable } from "./project-config-and-tool-errors.ts";
7
+ import {
8
+ ToolExited,
9
+ ToolNotStarted,
10
+ ToolReportUndecodable,
11
+ ToolStoppedBySignal,
12
+ } from "./project-config-and-tool-errors.ts";
6
13
 
7
14
  const LINE_BREAK = "\n";
8
15
 
@@ -48,6 +55,65 @@ export const mergedExit = (exits: Arrays.NonEmptyReadonlyArray<ToolExited>) => {
48
55
  });
49
56
  };
50
57
 
58
+ const WINDOWS = "win32";
59
+
60
+ const openedStandardOutputFile = (file: string) =>
61
+ Effect.acquireRelease(
62
+ Effect.promise(() => open(file, "w")),
63
+ (handle) => Effect.promise(() => handle.close()),
64
+ );
65
+
66
+ const stopTheProcessGroupOf = (child: Subprocess) =>
67
+ Effect.gen(function* () {
68
+ if (process.platform === WINDOWS) {
69
+ yield* Effect.try(() =>
70
+ Bun.spawn(["taskkill", "/pid", `${child.pid}`, "/T", "/F"], {
71
+ stdin: "ignore",
72
+ stdout: "ignore",
73
+ stderr: "ignore",
74
+ }),
75
+ ).pipe(
76
+ Effect.flatMap((taskkill) => Effect.promise(() => taskkill.exited)),
77
+ Effect.catchTag("UnknownError", () => Effect.void),
78
+ );
79
+ child.kill();
80
+ } else {
81
+ yield* Effect.try(() => process.kill(-child.pid, "SIGKILL")).pipe(
82
+ Effect.catchTag("UnknownError", () => Effect.void),
83
+ );
84
+ }
85
+ yield* Effect.promise(() => child.exited);
86
+ });
87
+
88
+ const spawnedTool = (
89
+ command: string,
90
+ binary: string,
91
+ toolArguments: readonly string[],
92
+ standardOutput: number,
93
+ workingDirectory?: string,
94
+ environment?: Record<string, string>,
95
+ ) =>
96
+ Effect.acquireRelease(
97
+ Effect.try({
98
+ try: () =>
99
+ Bun.spawn([binary, ...toolArguments], {
100
+ ...(workingDirectory === undefined ? {} : { cwd: workingDirectory }),
101
+ env: { ...process.env, ...environment },
102
+ detached: process.platform !== WINDOWS,
103
+ stdin: "ignore",
104
+ stdout: standardOutput,
105
+ stderr: "pipe",
106
+ }),
107
+ catch: (cause) =>
108
+ new ToolNotStarted({
109
+ command,
110
+ reason:
111
+ cause instanceof Error ? cause.message : "the spawn threw a value that is not an Error",
112
+ }),
113
+ }),
114
+ stopTheProcessGroupOf,
115
+ );
116
+
51
117
  export const runTool = (
52
118
  program: string,
53
119
  binary: string,
@@ -57,25 +123,33 @@ export const runTool = (
57
123
  ) =>
58
124
  Effect.scoped(
59
125
  Effect.gen(function* () {
60
- const child = yield* ChildProcess.make(binary, toolArguments, {
61
- ...(workingDirectory === undefined ? {} : { cwd: workingDirectory }),
62
- extendEnv: true,
63
- env: environment,
64
- stdin: "ignore",
65
- stderr: "pipe",
66
- });
67
- const [standardOutput, standardError, code] = yield* Effect.all(
126
+ const fileSystem = yield* FileSystem.FileSystem;
127
+ const standardOutputFile = yield* fileSystem.makeTempFileScoped();
128
+ const handle = yield* openedStandardOutputFile(standardOutputFile);
129
+ const command = [binary, ...toolArguments].join(" ");
130
+ const child = yield* spawnedTool(
131
+ command,
132
+ binary,
133
+ toolArguments,
134
+ handle.fd,
135
+ workingDirectory,
136
+ environment,
137
+ );
138
+ const [standardError, code] = yield* Effect.all(
68
139
  [
69
- Stream.mkString(Stream.decodeText(child.stdout)),
70
- Stream.mkString(Stream.decodeText(child.stderr)),
71
- child.exitCode,
140
+ Effect.promise(() => new Response(child.stderr).text()),
141
+ Effect.promise(() => child.exited),
72
142
  ],
73
143
  { concurrency: "unbounded" },
74
144
  );
145
+ const standardOutput = yield* fileSystem.readFileString(standardOutputFile);
146
+ if (child.signalCode !== null) {
147
+ return yield* new ToolStoppedBySignal({ program, command, signal: `${child.signalCode}` });
148
+ }
75
149
  if (code !== 0) {
76
150
  return yield* new ToolExited({
77
151
  program,
78
- command: [binary, ...toolArguments].join(" "),
152
+ command,
79
153
  code,
80
154
  standardOutput,
81
155
  standardError: standardError.trim(),