Skip to content

Commit 4a38b03

Browse files
authored
fix(biome): use absolute path in biome diagnostics (#555)
1 parent 4ded3d0 commit 4a38b03

File tree

3 files changed

+15
-31
lines changed

3 files changed

+15
-31
lines changed

packages/vite-plugin-checker/src/checkers/biome/cli.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,13 @@ export function runBiome(command: string, cwd: string) {
3434
maxBuffer: Number.POSITIVE_INFINITY,
3535
},
3636
(_error, stdout, _stderr) => {
37-
resolve([...parseBiomeOutput(stdout)])
37+
resolve([...parseBiomeOutput(stdout, cwd)])
3838
},
3939
)
4040
})
4141
}
4242

43-
function parseBiomeOutput(output: string) {
43+
function parseBiomeOutput(output: string, cwd: string) {
4444
let parsed: BiomeOutput
4545
try {
4646
parsed = JSON.parse(output)
@@ -50,7 +50,11 @@ function parseBiomeOutput(output: string) {
5050

5151
const diagnostics: NormalizedDiagnostic[] = parsed.diagnostics.map((d) => {
5252
let file = d.location.path?.file
53-
if (file) file = path.normalize(file)
53+
if (file) {
54+
// Convert relative path to absolute path
55+
file = path.isAbsolute(file) ? file : path.resolve(cwd, file)
56+
file = path.normalize(file)
57+
}
5458

5559
const loc = {
5660
file: file || '',

packages/vite-plugin-checker/src/checkers/vueTsc/languagePlugins.cjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ exports.getLanguagePlugins = (ts, options) => {
3636
configFilePath.replace(windowsPathReg, '/'),
3737
).vueOptions
3838
: getDefaultCompilerOptions()
39-
39+
4040
if (vue.writeGlobalTypes) {
4141
vue.writeGlobalTypes(vueOptions, ts.sys.writeFile)
4242
} else {
Lines changed: 7 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
22

3-
exports[`biome > serve > get initial error and subsequent error 1`] = `"[{"checkerId":"Biome","frame":" 2 | var b = 'world'/n 3 | const c = '!'/n > 4 | var d = a + b + c/n | ^/n 5 |/n 6 | export default c/n 7 |","id":"src/index.js","level":0,"loc":{"column":5,"file":"src/index.js","line":4},"message":"[lint/correctness/noUnusedVariables] This variable d is unused.","stack":""},{"checkerId":"Biome","frame":" 4 | var d = a + b + c/n 5 |/n > 6 | export default c/n | ^^^^^^^/n 7 |","id":"src/index.js","level":1,"loc":{"column":8,"file":"src/index.js","line":6},"message":"[lint/style/noDefaultExport] Avoid default exports.","stack":""}]"`;
3+
exports[`biome > serve > get initial error and subsequent error 1`] = `"[{"checkerId":"Biome","frame":" 2 | var b = 'world'/n 3 | const c = '!'/n > 4 | var d = a + b + c/n | ^/n 5 |/n 6 | export default c/n 7 |","id":"<PROJECT_ROOT>/playground-temp/biome-default/src/index.js","level":0,"loc":{"column":5,"file":"<PROJECT_ROOT>/playground-temp/biome-default/src/index.js","line":4},"message":"[lint/correctness/noUnusedVariables] This variable d is unused.","stack":""},{"checkerId":"Biome","frame":" 4 | var d = a + b + c/n 5 |/n > 6 | export default c/n | ^^^^^^^/n 7 |","id":"<PROJECT_ROOT>/playground-temp/biome-default/src/index.js","level":1,"loc":{"column":8,"file":"<PROJECT_ROOT>/playground-temp/biome-default/src/index.js","line":6},"message":"[lint/style/noDefaultExport] Avoid default exports.","stack":""}]"`;
44

55
exports[`biome > serve > get initial error and subsequent error 2`] = `
66
[
77
" WARNING(Biome) [lint/correctness/noUnusedVariables] This variable d is unused.
8-
FILE src/index.js:4:5
8+
FILE <PROJECT_ROOT>/playground-temp/biome-default/src/index.js:4:5
99
1010
2 | var b = 'world'
1111
3 | const c = '!'
@@ -16,7 +16,7 @@ exports[`biome > serve > get initial error and subsequent error 2`] = `
1616
7 |
1717
",
1818
" ERROR(Biome) [lint/style/noDefaultExport] Avoid default exports.
19-
FILE src/index.js:6:8
19+
FILE <PROJECT_ROOT>/playground-temp/biome-default/src/index.js:6:8
2020
2121
4 | var d = a + b + c
2222
5 |
@@ -28,32 +28,12 @@ exports[`biome > serve > get initial error and subsequent error 2`] = `
2828
]
2929
`;
3030
31-
exports[`biome > serve > get initial error and subsequent error 3`] = `"[{"checkerId":"Biome","frame":" 2 | var b = 'world'/n 3 | const c = '!'/n > 4 | var d = a + b + c/n | ^/n 5 |/n 6 | export default c/n 7 |","id":"src/index.js","level":0,"loc":{"column":5,"file":"src/index.js","line":4},"message":"[lint/correctness/noUnusedVariables] This variable d is unused.","stack":""},{"checkerId":"Biome","frame":" 4 | var d = a + b + c/n 5 |/n > 6 | export default c/n | ^^^^^^^/n 7 |","id":"src/index.js","level":1,"loc":{"column":8,"file":"src/index.js","line":6},"message":"[lint/style/noDefaultExport] Avoid default exports.","stack":""},{"checkerId":"Biome","frame":" 2 | const b = 'world'/n 3 | const c = '!'/n > 4 | var d = a + b + c/n | ^/n 5 |/n 6 | export default c/n 7 |","id":"src/index.js","level":0,"loc":{"column":5,"file":"src/index.js","line":4},"message":"[lint/correctness/noUnusedVariables] This variable d is unused.","stack":""},{"checkerId":"Biome","frame":" 4 | var d = a + b + c/n 5 |/n > 6 | export default c/n | ^^^^^^^/n 7 |","id":"src/index.js","level":1,"loc":{"column":8,"file":"src/index.js","line":6},"message":"[lint/style/noDefaultExport] Avoid default exports.","stack":""}]"`;
31+
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 |/n 6 | export default c/n 7 |","id":"<PROJECT_ROOT>/playground-temp/biome-default/src/index.js","level":0,"loc":{"column":5,"file":"<PROJECT_ROOT>/playground-temp/biome-default/src/index.js","line":4},"message":"[lint/correctness/noUnusedVariables] This variable d is unused.","stack":""},{"checkerId":"Biome","frame":" 4 | var d = a + b + c/n 5 |/n > 6 | export default c/n | ^^^^^^^/n 7 |","id":"<PROJECT_ROOT>/playground-temp/biome-default/src/index.js","level":1,"loc":{"column":8,"file":"<PROJECT_ROOT>/playground-temp/biome-default/src/index.js","line":6},"message":"[lint/style/noDefaultExport] Avoid default exports.","stack":""}]"`;
3232
3333
exports[`biome > serve > get initial error and subsequent error 4`] = `
3434
[
3535
" WARNING(Biome) [lint/correctness/noUnusedVariables] This variable d is unused.
36-
FILE src/index.js:4:5
37-
38-
2 | var b = 'world'
39-
3 | const c = '!'
40-
> 4 | var d = a + b + c
41-
| ^
42-
5 |
43-
6 | export default c
44-
7 |
45-
",
46-
" ERROR(Biome) [lint/style/noDefaultExport] Avoid default exports.
47-
FILE src/index.js:6:8
48-
49-
4 | var d = a + b + c
50-
5 |
51-
> 6 | export default c
52-
| ^^^^^^^
53-
7 |
54-
",
55-
" WARNING(Biome) [lint/correctness/noUnusedVariables] This variable d is unused.
56-
FILE src/index.js:4:5
36+
FILE <PROJECT_ROOT>/playground-temp/biome-default/src/index.js:4:5
5737
5838
2 | const b = 'world'
5939
3 | const c = '!'
@@ -64,14 +44,14 @@ exports[`biome > serve > get initial error and subsequent error 4`] = `
6444
7 |
6545
",
6646
" ERROR(Biome) [lint/style/noDefaultExport] Avoid default exports.
67-
FILE src/index.js:6:8
47+
FILE <PROJECT_ROOT>/playground-temp/biome-default/src/index.js:6:8
6848
6949
4 | var d = a + b + c
7050
5 |
7151
> 6 | export default c
7252
| ^^^^^^^
7353
7 |
7454
",
75-
"[Biome] Found 2 errors and 2 warnings",
55+
"[Biome] Found 1 error and 1 warning",
7656
]
7757
`;

0 commit comments

Comments
 (0)