fi3ework/vite-plugin-checker

Biome + checker only emits warnings and errors for new files

mio-moto opened this issue · 1 comments

Describe the bug

When enabling the biome checker, it only emits errors for changed files since the startup of the server. That is generally problematic, by a quick glance, this seems to happen with project when building the project too.

$ bunx biome lint --reporter json some-directory/spa
-- snip --
The number of diagnostics exceeds the number allowed by Biome.
Diagnostics not shown: 465.
Checked 253 files in 100ms. No fixes applied.
Found 428 errors.
Found 7 warnings.
$ npm run dev

> a-project@version dev
> vite --port 3000 --clearScreen false


  VITE v5.4.11  ready in 654 ms

  ➜  Local:   http://localhost:3000/
  ➜  Network: use --host to expose
  ➜  press h + enter to show help
# I've overwritten some source files to see the CLI commands
[  'biome', 'lint',  '--reporter json', 'some-directory/spa' ]
[Biome] Found 0 error and 0 warning

```log
$ npm run build

> tms-spa@2024.PI36.1 build
> tsc && vite build -l info -d

# no errors

# now saving a file
[  'biome', 'check', '', '--reporter json', 'F:\\work\\tms-maic\\spa\\src\\App.tsx' ]
 ERROR(Biome)  [lint/style/useImportType] All these imports are only used as types.
 FILE  some-directory\App.tsx:8:8

Reproduction

export default defineConfig({
  plugins: [
    checker({ typescript: true, biome: { command: 'lint' } })
  ]
} 

Expected behavior

The checker should emit errors truthfully on all files.

System Info

$ bunx envinfo --system --npmPackages vite-plugin-checker --binaries --browsers

  System:
    OS: Windows 11 10.0.22631
    CPU: (16) x64 AMD Ryzen 7 7800X3D 8-Core Processor
    Memory: 39.28 GB / 63.64 GB
  Binaries:
    Node: 20.13.1 - c:\program files\nodejs\node.EXE
    npm: 10.5.2 - c:\program files\nodejs\npm.CMD
    bun: 1.1.22 - ~\.bun\bin\bun.EXE
  Browsers:
    Edge: Chromium (127.0.2651.74)
    Internet Explorer: 11.0.22621.3527
  npmPackages:
    vite-plugin-checker: ^0.8.0 => 0.8.0


### Additional context

_No response_

### Validations

- [X] Read the [docs](https://github.com/fi3ework/vite-plugin-checker#readme).
- [X] Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.

Digging myself some, this problem seems to be primarily caused by a too short stdout buffer. The checker does not reject the promise on error, so it silently ignored the error that the stdout buffer overflowed.

This improves the silent error:

function runBiome(command, cwd) {
  return new Promise((resolve, reject) => {
    exec(command, { cwd },
      (error, stdout, stderr) => {
        if(error) {
          reject(error)
        }
        resolve([...parseBiomeOutput(stdout)]);
      }
    );
  });
}

Then I hit other errors caused by parsing of the large JSON:

node:internal/event_target:1099
  process.nextTick(() => { throw err; });
                           ^
RangeError [Error]: Invalid count value: -1
    at String.repeat (<anonymous>)
    at F:\work\tms-maic\spa\node_modules\@babel\code-frame\lib\index.js:172:108
    at Array.map (<anonymous>)
    at codeFrameColumns (F:\work\tms-maic\spa\node_modules\@babel\code-frame\lib\index.js:161:70)
    at createFrame (file:///F:/work/tms-maic/spa/node_modules/vite-plugin-checker/dist/esm/codeFrame.js:4:10)
    at file:///F:/work/tms-maic/spa/node_modules/vite-plugin-checker/dist/esm/checkers/biome/cli.js:57:23
    at Array.map (<anonymous>)
    at parseBiomeOutput (file:///F:/work/tms-maic/spa/node_modules/vite-plugin-checker/dist/esm/checkers/biome/cli.js:47:42)
    at file:///F:/work/tms-maic/spa/node_modules/vite-plugin-checker/dist/esm/checkers/biome/cli.js:35:21
    at ChildProcess.exithandler (node:child_process:430:5)
Emitted 'error' event on Worker instance at:
    at [kOnErrorMessage] (node:internal/worker:326:10)
    at [kOnMessage] (node:internal/worker:337:37)
    at MessagePort.<anonymous> (node:internal/worker:232:57)
    at [nodejs.internal.kHybridDispatch] (node:internal/event_target:825:20)
    at MessagePort.<anonymous> (node:internal/per_context/messageport:23:28)

Node.js v20.13.1
error: script "dev" exited with code 1

The latter error is caused by a linter emitted error that I cannot reproduce right now in an isolated manner.