Avoid extra newline between diagnostics in grouped mode (#4776)

This commit is contained in:
Charlie Marsh 2023-06-01 17:33:29 -04:00 committed by GitHub
parent bdff4a66ac
commit 3180f9978a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 49 additions and 30 deletions

View file

@ -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(())
@ -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(())
}
}
@ -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());

View file

@ -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
|

View file

@ -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):
@ -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
|

View file

@ -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
|