Skip to content

Commit

Permalink
normalize path returned by biome
Browse files Browse the repository at this point in the history
  • Loading branch information
KurtGokhan committed Jul 8, 2024
1 parent e9c4791 commit a06f0df
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 26 deletions.
8 changes: 6 additions & 2 deletions packages/vite-plugin-checker/src/checkers/biome/cli.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { exec } from 'node:child_process'
import path from 'node:path'
import strip from 'strip-ansi'
import { createFrame } from '../../codeFrame.js'
import type { NormalizedDiagnostic } from '../../logger.js'
Expand Down Expand Up @@ -39,8 +40,11 @@ function parseBiomeOutput(output: string) {
}

const diagnostics: NormalizedDiagnostic[] = parsed.diagnostics.map((d) => {
let file = d.location.path?.file
if (file) file = path.normalize(file)

const loc = {
file: d.location.path?.file || '',
file: file || '',
start: getLineAndColumn(d.location.sourceCode, d.location.span?.[0]),
end: getLineAndColumn(d.location.sourceCode, d.location.span?.[1]),
}
Expand All @@ -52,7 +56,7 @@ function parseBiomeOutput(output: string) {
conclusion: '',
level: severityMap[d.severity as keyof typeof severityMap] ?? DiagnosticLevel.Error,
checker: 'Biome',
id: d.location.path?.file,
id: file,
codeFrame,
stripedCodeFrame: codeFrame && strip(codeFrame),
loc,
Expand Down
5 changes: 2 additions & 3 deletions packages/vite-plugin-checker/src/checkers/biome/main.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { fileURLToPath } from 'node:url'
import chokidar from 'chokidar'

import path from 'node:path'
import { fileURLToPath } from 'node:url'
import { parentPort } from 'node:worker_threads'
import chokidar from 'chokidar'
import { Checker } from '../../Checker.js'
import { FileDiagnosticManager } from '../../FileDiagnosticManager.js'
import {
Expand Down
23 changes: 2 additions & 21 deletions playground/biome-default/__tests__/__snapshots__/test.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -27,30 +27,11 @@ exports[`biome > serve > get initial error and subsequent error 2`] = `
]
`;
exports[`biome > serve > get initial error and subsequent error 3`] = `"[{"checkerId":"Biome","frame":" 1 | const a = 'hello'/n > 2 | var b = 'world'/n | ^^^^^^^^^^^^^^^/n 3 | const c = '!'/n 4 | var d = a + b + c/n 5 |","id":"<PROJECT_ROOT>/playground-temp/biome-default/src/index.js","level":1,"loc":{"column":1,"file":"<PROJECT_ROOT>/playground-temp/biome-default/src/index.js","line":2},"message":"[lint/style/noVar] Use let or const instead of var.","stack":""},{"checkerId":"Biome","frame":" 2 | var b = 'world'/n 3 | const c = '!'/n > 4 | var d = a + b + c/n | ^^^^^^^^^^^^^^^^^/n 5 |","id":"<PROJECT_ROOT>/playground-temp/biome-default/src/index.js","level":1,"loc":{"column":1,"file":"<PROJECT_ROOT>/playground-temp/biome-default/src/index.js","line":4},"message":"[lint/style/noVar] Use let or const instead of var.","stack":""},{"checkerId":"Biome","frame":" 2 | const b = 'world'/n 3 | const c = '!'/n > 4 | var d = a + b + c/n | ^^^^^^^^^^^^^^^^^/n 5 |","id":"<PROJECT_ROOT>/playground-temp/biome-default/src/index.js","level":1,"loc":{"column":1,"file":"<PROJECT_ROOT>/playground-temp/biome-default/src/index.js","line":4},"message":"[lint/style/noVar] Use let or const instead of var.","stack":""}]"`;
exports[`biome > serve > get initial error and subsequent error 3`] = `"[{"checkerId":"Biome","frame":" 2 | const b = 'world'/n 3 | const c = '!'/n > 4 | var d = a + b + c/n | ^^^^^^^^^^^^^^^^^/n 5 |","id":"<PROJECT_ROOT>/playground-temp/biome-default/src/index.js","level":1,"loc":{"column":1,"file":"<PROJECT_ROOT>/playground-temp/biome-default/src/index.js","line":4},"message":"[lint/style/noVar] Use let or const instead of var.","stack":""}]"`;
exports[`biome > serve > get initial error and subsequent error 4`] = `
[
" ERROR(Biome) [lint/style/noVar] Use let or const instead of var.
FILE <PROJECT_ROOT>/playground-temp/biome-default/src/index.js:2:1
1 | const a = 'hello'
> 2 | var b = 'world'
| ^^^^^^^^^^^^^^^
3 | const c = '!'
4 | var d = a + b + c
5 |
",
" ERROR(Biome) [lint/style/noVar] Use let or const instead of var.
FILE <PROJECT_ROOT>/playground-temp/biome-default/src/index.js:4:1
2 | var b = 'world'
3 | const c = '!'
> 4 | var d = a + b + c
| ^^^^^^^^^^^^^^^^^
5 |
",
" ERROR(Biome) [lint/style/noVar] Use let or const instead of var.
FILE <PROJECT_ROOT>/playground-temp/biome-default/src/index.js:4:1
2 | const b = 'world'
Expand All @@ -59,6 +40,6 @@ exports[`biome > serve > get initial error and subsequent error 4`] = `
| ^^^^^^^^^^^^^^^^^
5 |
",
"[Biome] Found 3 errors and 0 warning",
"[Biome] Found 1 error and 0 warning",
]
`;

0 comments on commit a06f0df

Please sign in to comment.