mirror of
https://github.com/astral-sh/ruff.git
synced 2025-10-03 07:04:37 +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,8 +74,13 @@ impl Emitter for GroupedEmitter {
|
||||||
}
|
}
|
||||||
)?;
|
)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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)?;
|
writeln!(writer)?;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -136,11 +141,9 @@ impl Display for DisplayGroupedMessage<'_> {
|
||||||
if self.show_source {
|
if self.show_source {
|
||||||
use std::fmt::Write;
|
use std::fmt::Write;
|
||||||
let mut padded = PadAdapter::new(f);
|
let mut padded = PadAdapter::new(f);
|
||||||
write!(padded, "{}", MessageCodeFrame { message })?;
|
writeln!(padded, "{}", MessageCodeFrame { message })?;
|
||||||
}
|
}
|
||||||
|
|
||||||
writeln!(f)?;
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -185,6 +188,14 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn default() {
|
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 mut emitter = GroupedEmitter::default().with_show_source(true);
|
||||||
let content = capture_emitter_output(&mut emitter, &create_messages());
|
let content = capture_emitter_output(&mut emitter, &create_messages());
|
||||||
|
|
||||||
|
|
|
@ -4,30 +4,9 @@ expression: content
|
||||||
---
|
---
|
||||||
fib.py:
|
fib.py:
|
||||||
1:8 F401 `os` imported but unused
|
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: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:
|
undef.py:
|
||||||
1:4 F821 Undefined name `a`
|
1:4 F821 Undefined name `a`
|
||||||
|
|
|
||||||
1 | if a == 1: pass
|
|
||||||
| ^ F821
|
|
||||||
|
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,6 @@ fib.py:
|
||||||
|
|
|
|
||||||
= help: Remove assignment to unused variable `x`
|
= help: Remove assignment to unused variable `x`
|
||||||
|
|
||||||
|
|
||||||
undef.py:
|
undef.py:
|
||||||
1:4 F821 Undefined name `a`
|
1:4 F821 Undefined name `a`
|
||||||
|
|
|
|
||||||
|
@ -30,4 +29,3 @@ undef.py:
|
||||||
|
|
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -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