Skip to content

Commit 3b6f5e3

Browse files
feat(cli): rdjson reporter (#7698)
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
1 parent 296627d commit 3b6f5e3

File tree

24 files changed

+2319
-89
lines changed

24 files changed

+2319
-89
lines changed

.changeset/eager-suns-smoke.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@biomejs/biome": patch
3+
---
4+
5+
Fixed an issue where the JUnit reporter returned a zero-based location. Now the location returned is one-based.

.changeset/gentle-pots-hunt.md

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
---
2+
"@biomejs/biome": minor
3+
---
4+
5+
Added a new reporter named `rdjson`. This reporter prints diagnostics following the [RDJSON format](https://deepwiki.com/reviewdog/reviewdog/3.2-reviewdog-diagnostic-format):
6+
7+
The following command:
8+
9+
```shell
10+
biome check --reporter=rdjson
11+
```
12+
13+
Will emit diagnostics in the following format:
14+
15+
```json
16+
{
17+
"source": {
18+
"name": "Biome",
19+
"url": "https://biomejs.dev"
20+
},
21+
"diagnostics": [
22+
{
23+
"code": {
24+
"url": "https://biomejs.dev/linter/rules/no-unused-imports",
25+
"value": "lint/correctness/noUnusedImports"
26+
},
27+
"location": {
28+
"path": "index.ts",
29+
"range": {
30+
"end": {
31+
"column": 11,
32+
"line": 0
33+
},
34+
"start": {
35+
"column": 7,
36+
"line": 0
37+
}
38+
}
39+
},
40+
"message": "This import is unused."
41+
},
42+
{
43+
"code": {
44+
"url": "https://biomejs.dev/linter/rules/no-unused-imports",
45+
"value": "lint/correctness/noUnusedImports"
46+
},
47+
"location": {
48+
"path": "index.ts",
49+
"range": {
50+
"end": {
51+
"column": 10,
52+
"line": 1
53+
},
54+
"start": {
55+
"column": 9,
56+
"line": 1
57+
}
58+
}
59+
},
60+
"message": "Several of these imports are unused."
61+
}
62+
]
63+
}
64+
```

crates/biome_cli/src/cli_options.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ pub struct CliOptions {
5656
/// Allows to change how diagnostics and summary are reported.
5757
#[bpaf(
5858
long("reporter"),
59-
argument("json|json-pretty|github|junit|summary|gitlab|checkstyle"),
59+
argument("json|json-pretty|github|junit|summary|gitlab|checkstyle|rdjson"),
6060
fallback(CliReporter::default())
6161
)]
6262
pub reporter: CliReporter,
@@ -154,12 +154,14 @@ pub enum CliReporter {
154154
GitHub,
155155
/// Diagnostics and summary are printed in JUnit format
156156
Junit,
157-
/// Reports linter diagnostics grouped by category and number of hits. Reports formatter diagnostics grouped by file.
157+
/// Reports diagnostics grouped by category and number of hits. Reports formatter diagnostics grouped by file.
158158
Summary,
159-
/// Reports linter diagnostics using the [GitLab Code Quality report](https://docs.gitlab.com/ee/ci/testing/code_quality.html#implement-a-custom-tool).
159+
/// Reports diagnostics using the [GitLab Code Quality report](https://docs.gitlab.com/ee/ci/testing/code_quality.html#implement-a-custom-tool).
160160
GitLab,
161161
/// Reports diagnostics in Checkstyle XML format
162162
Checkstyle,
163+
/// Reports diagnostics using the [Reviewdog JSON format](https://deepwiki.com/reviewdog/reviewdog/3.2-reviewdog-diagnostic-format)
164+
RdJson,
163165
}
164166

165167
impl CliReporter {
@@ -180,6 +182,7 @@ impl FromStr for CliReporter {
180182
"junit" => Ok(Self::Junit),
181183
"gitlab" => Ok(Self::GitLab),
182184
"checkstyle" => Ok(Self::Checkstyle),
185+
"rdjson" => Ok(Self::RdJson),
183186
_ => Err(format!(
184187
"value {s:?} is not valid for the --reporter argument"
185188
)),
@@ -198,6 +201,7 @@ impl Display for CliReporter {
198201
Self::Junit => f.write_str("junit"),
199202
Self::GitLab => f.write_str("gitlab"),
200203
Self::Checkstyle => f.write_str("checkstyle"),
204+
Self::RdJson => f.write_str("rdjson"),
201205
}
202206
}
203207
}

crates/biome_cli/src/execute/mod.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use crate::reporter::github::{GithubReporter, GithubReporterVisitor};
1414
use crate::reporter::gitlab::{GitLabReporter, GitLabReporterVisitor};
1515
use crate::reporter::json::{JsonReporter, JsonReporterVisitor};
1616
use crate::reporter::junit::{JunitReporter, JunitReporterVisitor};
17+
use crate::reporter::rdjson::{RdJsonReporter, RdJsonReporterVisitor};
1718
use crate::reporter::summary::{SummaryReporter, SummaryReporterVisitor};
1819
use crate::reporter::terminal::{ConsoleReporter, ConsoleReporterVisitor};
1920
use crate::{
@@ -249,6 +250,8 @@ pub enum ReportMode {
249250
GitLab,
250251
/// Reports diagnostics in [Checkstyle XML format](https://checkstyle.org/).
251252
Checkstyle,
253+
/// Reports information in [reviewdog JSON format](https://deepwiki.com/reviewdog/reviewdog/3.2-reviewdog-diagnostic-format)
254+
RdJson,
252255
}
253256

254257
impl Default for ReportMode {
@@ -272,6 +275,7 @@ impl From<CliReporter> for ReportMode {
272275
CliReporter::Junit => Self::Junit,
273276
CliReporter::GitLab => Self::GitLab {},
274277
CliReporter::Checkstyle => Self::Checkstyle,
278+
CliReporter::RdJson => Self::RdJson,
275279
}
276280
}
277281
}
@@ -718,6 +722,15 @@ pub fn execute_mode(
718722
reporter
719723
.write(&mut crate::reporter::checkstyle::CheckstyleReporterVisitor::new(console))?;
720724
}
725+
ReportMode::RdJson => {
726+
let reporter = RdJsonReporter {
727+
diagnostics_payload,
728+
execution: execution.clone(),
729+
verbose: cli_options.verbose,
730+
working_directory: fs.working_directory().clone(),
731+
};
732+
reporter.write(&mut RdJsonReporterVisitor(console))?;
733+
}
721734
}
722735

723736
// Processing emitted error diagnostics, exit with a non-zero code

crates/biome_cli/src/reporter/junit.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,8 @@ impl ReporterVisitor for JunitReporterVisitor<'_> {
9090

9191
status.set_description(format!(
9292
"line {row:?}, col {col:?}, {body}",
93-
row = start.line_number.to_zero_indexed(),
94-
col = start.column_number.to_zero_indexed(),
93+
row = start.line_number.get(),
94+
col = start.column_number.get(),
9595
body = message
9696
));
9797
let mut case = TestCase::new(

crates/biome_cli/src/reporter/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ pub(crate) mod github;
33
pub(crate) mod gitlab;
44
pub(crate) mod json;
55
pub(crate) mod junit;
6+
pub(crate) mod rdjson;
67
pub(crate) mod summary;
78
pub(crate) mod terminal;
89

0 commit comments

Comments
 (0)