Skip to content

Commit

Permalink
Fix biome fmt error case (#772)
Browse files Browse the repository at this point in the history
Fixes #771 for cases of
malformed config. `biome fmt` outputs an exit code of 1. For lint, we
have to have `success_codes: [0, 1]`, but for format we can just have
`success_codes: [0]` so that we better surface this error to users.

Also adds a relevant test case.
  • Loading branch information
TylerJang27 committed May 7, 2024
1 parent 887931c commit 7e2d554
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 2 deletions.
19 changes: 18 additions & 1 deletion linters/biome/biome.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,22 @@
import { linterCheckTest, linterFmtTest } from "tests";
import path from "path";
import { customLinterCheckTest, linterCheckTest, linterFmtTest } from "tests";
import { TrunkLintDriver } from "tests/driver";
import { TEST_DATA } from "tests/utils";

linterCheckTest({ linterName: "biome", namedTestPrefixes: ["basic_check"] });

linterFmtTest({ linterName: "biome", namedTestPrefixes: ["basic_fmt", "basic_json"] });

const preCheck = (driver: TrunkLintDriver) => {
// Write an invalid biome config and verify we surface an error for format.
// NOTE(Tyler): We should handle config errors better for 'lint' too, but the JSON
// output for biome is not stable and they don't support SARIF.
driver.writeFile("biome.json", JSON.stringify({ rules: { "no-foo": "error" } }));
};

customLinterCheckTest({
linterName: "biome",
testName: "error",
args: path.join(TEST_DATA, "basic_check.in.ts"),
preCheck,
});
2 changes: 1 addition & 1 deletion linters/biome/plugin.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ lint:
- name: fmt
output: rewrite
run: biome format --write "${target}"
success_codes: [0, 1]
success_codes: [0]
batch: true
cache_results: true
formatter: true
Expand Down
36 changes: 36 additions & 0 deletions linters/biome/test_data/biome_v1.4.1_error.check.shot
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Testing linter biome test error 1`] = `
{
"issues": [],
"lintActions": [
{
"command": "lint",
"fileGroupName": "typescript",
"linter": "biome",
"paths": [
"test_data/basic_check.in.ts",
],
"verb": "TRUNK_VERB_CHECK",
},
{
"command": "lint",
"fileGroupName": "typescript",
"linter": "biome",
"paths": [
"test_data/basic_check.in.ts",
],
"upstream": true,
"verb": "TRUNK_VERB_CHECK",
},
],
"taskFailures": [
{
"details": StringMatching /\\.\\*\\$/m,
"message": "test_data/basic_check.in.ts",
"name": "biome",
},
],
"unformattedFiles": [],
}
`;
36 changes: 36 additions & 0 deletions linters/biome/test_data/biome_v1.6.0_error.check.shot
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Testing linter biome test error 1`] = `
{
"issues": [],
"lintActions": [
{
"command": "lint",
"fileGroupName": "typescript",
"linter": "biome",
"paths": [
"test_data/basic_check.in.ts",
],
"verb": "TRUNK_VERB_CHECK",
},
{
"command": "lint",
"fileGroupName": "typescript",
"linter": "biome",
"paths": [
"test_data/basic_check.in.ts",
],
"upstream": true,
"verb": "TRUNK_VERB_CHECK",
},
],
"taskFailures": [
{
"details": StringMatching /\\.\\*\\$/m,
"message": "test_data/basic_check.in.ts",
"name": "biome",
},
],
"unformattedFiles": [],
}
`;

0 comments on commit 7e2d554

Please sign in to comment.