Skip to content

Commit 09956b4

Browse files
authored
Use DisplayDiagnosticsConfig::program for Ruff's GitHub output (#23240)
Summary -- This is a follow-up to #22125, which added a `program` field to the shared `DisplayDiagnosticConfig` type. We can reuse this in the GitHub rendering too to avoid some of the special casing we had just for Ruff. The one wrinkle here is that we previously used capital `Ruff` for GitHub diagnostics, but we use `ruff` in the JUnit diagnostics. I think it's probably fine to change this in the GitHub diagnostics, but it felt worth calling out. Test Plan -- Existing tests with updated snapshots showing the case change
1 parent b4ca9ba commit 09956b4

6 files changed

Lines changed: 9 additions & 36 deletions

File tree

crates/ruff/tests/cli/snapshots/cli__format__output_format_github.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ info:
1414
success: false
1515
exit_code: 1
1616
----- stdout -----
17-
::error title=Ruff (unformatted),file=[TMP]/input.py,line=1,endLine=2::input.py:1:1: unformatted: File would be reformatted
17+
::error title=ruff (unformatted),file=[TMP]/input.py,line=1,endLine=2::input.py:1:1: unformatted: File would be reformatted
1818

1919
----- stderr -----

crates/ruff/tests/cli/snapshots/cli__lint__output_format_github.snap

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ info:
1616
success: false
1717
exit_code: 1
1818
----- stdout -----
19-
::error title=Ruff (F401),file=[TMP]/input.py,line=1,col=8,endLine=1,endColumn=10::input.py:1:8: F401 `os` imported but unused
20-
::error title=Ruff (F821),file=[TMP]/input.py,line=2,col=5,endLine=2,endColumn=6::input.py:2:5: F821 Undefined name `y`
21-
::error title=Ruff (invalid-syntax),file=[TMP]/input.py,line=3,col=1,endLine=3,endColumn=6::input.py:3:1: invalid-syntax: Cannot use `match` statement on Python 3.9 (syntax was added in Python 3.10)
19+
::error title=ruff (F401),file=[TMP]/input.py,line=1,col=8,endLine=1,endColumn=10::input.py:1:8: F401 `os` imported but unused
20+
::error title=ruff (F821),file=[TMP]/input.py,line=2,col=5,endLine=2,endColumn=6::input.py:2:5: F821 Undefined name `y`
21+
::error title=ruff (invalid-syntax),file=[TMP]/input.py,line=3,col=1,endLine=3,endColumn=6::input.py:3:1: invalid-syntax: Cannot use `match` statement on Python 3.9 (syntax was added in Python 3.10)
2222

2323
----- stderr -----

crates/ruff_db/src/diagnostic/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ use ruff_text_size::{Ranged, TextRange, TextSize};
88

99
pub use self::render::{
1010
DisplayDiagnostic, DisplayDiagnostics, DummyFileResolver, FileResolver, Input,
11-
github::{DisplayGithubDiagnostics, GithubRenderer},
1211
};
1312
use crate::cancellation::CancellationToken;
1413
use crate::{Db, files::File};

crates/ruff_db/src/diagnostic/render/github.rs

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
use crate::diagnostic::{Diagnostic, FileResolver, Severity};
22

3-
pub struct GithubRenderer<'a> {
3+
pub(super) struct GithubRenderer<'a> {
44
resolver: &'a dyn FileResolver,
55
program: &'a str,
66
}
77

88
impl<'a> GithubRenderer<'a> {
9-
pub fn new(resolver: &'a dyn FileResolver, program: &'a str) -> Self {
9+
pub(super) fn new(resolver: &'a dyn FileResolver, program: &'a str) -> Self {
1010
Self { resolver, program }
1111
}
1212

@@ -94,26 +94,6 @@ impl<'a> GithubRenderer<'a> {
9494
}
9595
}
9696

97-
pub struct DisplayGithubDiagnostics<'a> {
98-
renderer: &'a GithubRenderer<'a>,
99-
diagnostics: &'a [Diagnostic],
100-
}
101-
102-
impl<'a> DisplayGithubDiagnostics<'a> {
103-
pub fn new(renderer: &'a GithubRenderer<'a>, diagnostics: &'a [Diagnostic]) -> Self {
104-
Self {
105-
renderer,
106-
diagnostics,
107-
}
108-
}
109-
}
110-
111-
impl std::fmt::Display for DisplayGithubDiagnostics<'_> {
112-
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
113-
self.renderer.render(f, self.diagnostics)
114-
}
115-
}
116-
11797
#[cfg(test)]
11898
mod tests {
11999
use crate::diagnostic::{

crates/ruff_linter/src/message/mod.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ use rustc_hash::FxHashMap;
88

99
use ruff_db::diagnostic::{
1010
Annotation, Diagnostic, DiagnosticFormat, DiagnosticId, DisplayDiagnosticConfig,
11-
DisplayDiagnostics, DisplayGithubDiagnostics, FileResolver, GithubRenderer, Input, LintName,
12-
SecondaryCode, Severity, Span, SubDiagnostic, SubDiagnosticSeverity, UnifiedFile,
11+
DisplayDiagnostics, FileResolver, Input, LintName, SecondaryCode, Severity, Span,
12+
SubDiagnostic, SubDiagnosticSeverity, UnifiedFile,
1313
};
1414
use ruff_db::files::File;
1515

@@ -208,11 +208,6 @@ pub fn render_diagnostics(
208208
let value = DisplayDiagnostics::new(context, &config, diagnostics);
209209
write!(writer, "{value}")?;
210210
}
211-
Err(RuffOutputFormat::Github) => {
212-
let renderer = GithubRenderer::new(context, "Ruff");
213-
let value = DisplayGithubDiagnostics::new(&renderer, diagnostics);
214-
write!(writer, "{value}")?;
215-
}
216211
Err(RuffOutputFormat::Grouped) => {
217212
GroupedEmitter::default()
218213
.with_show_fix_status(config.show_fix_status())

crates/ruff_linter/src/settings/types.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -597,7 +597,6 @@ impl Display for OutputFormat {
597597

598598
/// The subset of output formats only implemented in Ruff, not in `ruff_db` via `DisplayDiagnostics`.
599599
pub enum RuffOutputFormat {
600-
Github,
601600
Grouped,
602601
Sarif,
603602
}
@@ -616,7 +615,7 @@ impl TryFrom<OutputFormat> for DiagnosticFormat {
616615
OutputFormat::Pylint => Ok(DiagnosticFormat::Pylint),
617616
OutputFormat::Rdjson => Ok(DiagnosticFormat::Rdjson),
618617
OutputFormat::Azure => Ok(DiagnosticFormat::Azure),
619-
OutputFormat::Github => Err(RuffOutputFormat::Github),
618+
OutputFormat::Github => Ok(DiagnosticFormat::Github),
620619
OutputFormat::Grouped => Err(RuffOutputFormat::Grouped),
621620
OutputFormat::Sarif => Err(RuffOutputFormat::Sarif),
622621
}

0 commit comments

Comments
 (0)