mirror of
https://github.com/astral-sh/ruff.git
synced 2025-10-02 14:51:25 +00:00
Avoid extra newline between diagnostics in grouped mode (#4776)
This commit is contained in:
parent
bdff4a66ac
commit
3180f9978a
4 changed files with 49 additions and 30 deletions
|
@ -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());
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
||||
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue