Skip to content

Commit

Permalink
Avoid extra newline between diagnostics in grouped mode (#4776)
Browse files Browse the repository at this point in the history
  • Loading branch information
charliermarsh authored and konstin committed Jun 13, 2023
1 parent 2cde2ef commit c8166f2
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 30 deletions.
19 changes: 15 additions & 4 deletions crates/ruff/src/message/grouped.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,12 @@ impl Emitter for GroupedEmitter {
}
)?;
}
writeln!(writer)?;

// Print a blank line between files, unless we're showing the source, in which case
// we'll have already printed a blank line between messages.
if !self.show_source {
writeln!(writer)?;
}
}

Ok(())
Expand Down Expand Up @@ -136,11 +141,9 @@ impl Display for DisplayGroupedMessage<'_> {
if self.show_source {
use std::fmt::Write;
let mut padded = PadAdapter::new(f);
write!(padded, "{}", MessageCodeFrame { message })?;
writeln!(padded, "{}", MessageCodeFrame { message })?;
}

writeln!(f)?;

Ok(())
}
}
Expand Down Expand Up @@ -185,6 +188,14 @@ mod tests {

#[test]
fn default() {
let mut emitter = GroupedEmitter::default();
let content = capture_emitter_output(&mut emitter, &create_messages());

assert_snapshot!(content);
}

#[test]
fn show_source() {
let mut emitter = GroupedEmitter::default().with_show_source(true);
let content = capture_emitter_output(&mut emitter, &create_messages());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,9 @@ expression: content
---
fib.py:
1:8 F401 `os` imported but unused
|
1 | import os
| ^^ F401
|
= help: Remove unused import: `os`

6:5 F841 Local variable `x` is assigned to but never used
|
6 | def fibonacci(n):
7 | """Compute the nth number in the Fibonacci sequence."""
8 | x = 1
| ^ F841
9 | if n == 0:
10 | return 0
|
= help: Remove assignment to unused variable `x`


undef.py:
1:4 F821 Undefined name `a`
|
1 | if a == 1: pass
| ^ F821
|



Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ fib.py:
| ^^ F401
|
= help: Remove unused import: `os`

6:5 F841 [*] Local variable `x` is assigned to but never used
|
6 | def fibonacci(n):
Expand All @@ -20,14 +20,12 @@ fib.py:
10 | return 0
|
= help: Remove assignment to unused variable `x`



undef.py:
1:4 F821 Undefined name `a`
|
1 | if a == 1: pass
| ^ F821
|




Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
source: crates/ruff/src/message/grouped.rs
expression: content
---
fib.py:
1:8 F401 `os` imported but unused
|
1 | import os
| ^^ F401
|
= help: Remove unused import: `os`

6:5 F841 Local variable `x` is assigned to but never used
|
6 | def fibonacci(n):
7 | """Compute the nth number in the Fibonacci sequence."""
8 | x = 1
| ^ F841
9 | if n == 0:
10 | return 0
|
= help: Remove assignment to unused variable `x`

undef.py:
1:4 F821 Undefined name `a`
|
1 | if a == 1: pass
| ^ F821
|


0 comments on commit c8166f2

Please sign in to comment.