Skip to content

Commit

Permalink
Integrate biome (#601)
Browse files Browse the repository at this point in the history
[Biome](https://biomejs.dev/) is the successor to rome, as noted in
#599.

Notes:
- Biome also supports formatting JSON files.
- It is available as a download, but it works better with our update
querying logic as a package install.
- We will still support rome, but biome will be suggested in its place
if a `rome.json` exists.
  • Loading branch information
TylerJang27 authored Dec 26, 2023
1 parent d9eae68 commit 182dd26
Show file tree
Hide file tree
Showing 10 changed files with 170 additions and 3 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ trunk check enable {linter}
| HAML | [haml-lint] |
| HTML Templates | [djlint] |
| Java | [google-java-format], [pmd], [semgrep] |
| Javascript | [deno], [eslint], [prettier], [rome], [semgrep] |
| JSON | [deno], [eslint], [prettier], [semgrep] |
| Javascript | [biome], [deno], [eslint], [prettier], [rome], [semgrep] |
| JSON | [biome], [deno], [eslint], [prettier], [semgrep] |
| Kotlin | [detekt], [ktlint] |
| Kubernetes | [kube-linter] |
| Lua | [stylua] |
Expand Down Expand Up @@ -87,6 +87,7 @@ trunk check enable {linter}
[ansible-lint]: https://github.com/ansible/ansible-lint#readme
[autopep8]: https://github.com/hhatto/autopep8#readme
[bandit]: https://github.com/PyCQA/bandit#readme
[biome]: https://github.com/biomejs/biome#readme
[black]: https://github.com/psf/black#readme
[brakeman]: https://github.com/presidentbeef/brakeman#readme
[buf]: https://github.com/bufbuild/buf#readme
Expand All @@ -104,6 +105,7 @@ trunk check enable {linter}
[detekt]: https://github.com/detekt/detekt#readme
[djlint]: https://github.com/Riverside-Healthcare/djlint#readme
[dotenv-linter]: https://github.com/dotenv-linter/dotenv-linter#readme
[dotnet-format]: https://github.com/dotnet/format#readme
[dustilock]: https://github.com/Checkmarx/dustilock
[eslint]: https://github.com/eslint/eslint#readme
[flake8]: https://github.com/PyCQA/flake8#readme
Expand Down
5 changes: 5 additions & 0 deletions linters/biome/biome.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { linterCheckTest, linterFmtTest } from "tests";

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

linterFmtTest({ linterName: "biome", namedTestPrefixes: ["basic_fmt", "basic_json"] });
48 changes: 48 additions & 0 deletions linters/biome/plugin.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
version: 0.1
tools:
definitions:
- name: biome
# Available as a download, but release name doesn't configure well to our schema
runtime: node
package: "@biomejs/biome"
shims: [biome]
known_good_version: 1.4.1
lint:
definitions:
# Successor to the rome linter+formatter
- name: biome
files:
- typescript
- javascript
- json
commands:
- name: lint
output: regex
parse_regex:
' *(?P<path>.*?):(?P<line>\d+):(?P<col>\d+) (?P<code>[^ ]+)(?:[^×]*\n).*×
(?P<message>.*)\n'
run: biome check ${target}
success_codes: [0, 1]
batch: true
cache_results: true
read_output_from: stderr
- name: fmt
output: rewrite
run: biome format --write "${target}"
success_codes: [0, 1]
batch: true
cache_results: true
formatter: true
in_place: true
tools: [biome]
suggest_if: config_present
direct_configs:
- biome.json
- rome.json # For backwards compatibility with rome
affects_cache:
- package.json
- .editorconfig # Undocumented config file
known_good_version: 1.4.1
version_command:
parse_regex: biome CLI version ${semver}
run: biome --version
14 changes: 14 additions & 0 deletions linters/biome/test_data/basic_check.in.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const foobar = () => { }
const barfoo = () => { }

enum Bar { Baz };

const foo = (bar: Bar) => {
switch (bar) {
case Bar.Baz:
foobar();
barfoo();
break;
}
{ !foo ? null : 1 }
}
14 changes: 14 additions & 0 deletions linters/biome/test_data/basic_fmt.in.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const foobar = () => { }
const barfoo = () => { }

enum Bar { Baz };

const foo = (bar: Bar) => {
switch (bar) {
case Bar.Baz:
foobar();
barfoo();
break;
}
{ !foo ? null : 1 }
}
4 changes: 4 additions & 0 deletions linters/biome/test_data/basic_json.in.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{"a":
"foo",
"b": 1,
"a": true}
50 changes: 50 additions & 0 deletions linters/biome/test_data/biome_v1.4.1_basic_check.check.shot
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Testing linter biome test basic_check 1`] = `
{
"issues": [
{
"code": "lint/style/useEnumInitializers",
"column": "6",
"file": "test_data/basic_check.in.ts",
"level": "LEVEL_HIGH",
"line": "4",
"linter": "biome",
"message": "This enum declaration contains members that are implicitly initialized.",
"targetType": "typescript",
},
],
"lintActions": [
{
"command": "fmt",
"fileGroupName": "typescript",
"linter": "biome",
"paths": [
"test_data/basic_check.in.ts",
],
"verb": "TRUNK_VERB_FMT",
},
{
"command": "lint",
"fileGroupName": "typescript",
"linter": "biome",
"paths": [
"test_data/basic_check.in.ts",
],
"verb": "TRUNK_VERB_CHECK",
},
],
"taskFailures": [],
"unformattedFiles": [
{
"column": "1",
"file": "test_data/basic_check.in.ts",
"issueClass": "ISSUE_CLASS_UNFORMATTED",
"level": "LEVEL_HIGH",
"line": "1",
"linter": "biome",
"message": "Incorrect formatting, autoformat by running 'trunk fmt'",
},
],
}
`;
23 changes: 23 additions & 0 deletions linters/biome/test_data/biome_v1.4.1_basic_fmt.fmt.shot
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Testing formatter biome test basic_fmt 1`] = `
"const foobar = () => {};
const barfoo = () => {};

enum Bar {
Baz,
}

const foo = (bar: Bar) => {
switch (bar) {
case Bar.Baz:
foobar();
barfoo();
break;
}
{
!foo ? null : 1;
}
};
"
`;
6 changes: 6 additions & 0 deletions linters/biome/test_data/biome_v1.4.1_basic_json.fmt.shot
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Testing formatter biome test basic_json 1`] = `
"{ "a": "foo", "b": 1, "a": true }
"
`;
3 changes: 2 additions & 1 deletion linters/rome/plugin.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ tools:
known_good_version: 10.0.1
lint:
definitions:
# No longer maintained. Succeeded by the biome linter+formatter
- name: rome
files:
- typescript
Expand All @@ -33,7 +34,7 @@ lint:
formatter: true
in_place: true
tools: [rome]
suggest_if: config_present
suggest_if: never
direct_configs:
- rome.json
affects_cache:
Expand Down

0 comments on commit 182dd26

Please sign in to comment.