mirror of
https://github.com/astral-sh/ruff.git
synced 2025-07-24 05:26:23 +00:00
Fix unnecessary space around power op in overlong f-string expressions (#14489)
This commit is contained in:
parent
a90e404c3f
commit
302fe76c2b
4 changed files with 113 additions and 19 deletions
|
@ -346,3 +346,6 @@ _ = (
|
|||
f'This string uses double quotes in an expression {"it's a quote"}'
|
||||
f'This f-string does not use any quotes.'
|
||||
)
|
||||
|
||||
# Regression test for https://github.com/astral-sh/ruff/issues/14487
|
||||
f"aaaaaaaaaaaaaaaaaaaaaaaaaa {10**27} bbbbbbbbbbbbbbbbbbbbbbbbbb ccccccccccccccccccccccccc"
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use ruff_formatter::{write, Argument, Arguments};
|
||||
use ruff_text_size::{Ranged, TextRange, TextSize};
|
||||
|
||||
use crate::context::{FStringState, NodeLevel, WithNodeLevel};
|
||||
use crate::context::{NodeLevel, WithNodeLevel};
|
||||
use crate::other::commas::has_magic_trailing_comma;
|
||||
use crate::prelude::*;
|
||||
|
||||
|
@ -206,16 +206,6 @@ impl<'fmt, 'ast, 'buf> JoinCommaSeparatedBuilder<'fmt, 'ast, 'buf> {
|
|||
|
||||
pub(crate) fn finish(&mut self) -> FormatResult<()> {
|
||||
self.result.and_then(|()| {
|
||||
// If the formatter is inside an f-string expression element, and the layout
|
||||
// is flat, then we don't need to add a trailing comma.
|
||||
if let FStringState::InsideExpressionElement(context) =
|
||||
self.fmt.context().f_string_state()
|
||||
{
|
||||
if !context.can_contain_line_breaks() {
|
||||
return Ok(());
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(last_end) = self.entries.position() {
|
||||
let magic_trailing_comma = has_magic_trailing_comma(
|
||||
TextRange::new(last_end, self.sequence_end),
|
||||
|
|
|
@ -353,6 +353,9 @@ _ = (
|
|||
f'This string uses double quotes in an expression {"it's a quote"}'
|
||||
f'This f-string does not use any quotes.'
|
||||
)
|
||||
|
||||
# Regression test for https://github.com/astral-sh/ruff/issues/14487
|
||||
f"aaaaaaaaaaaaaaaaaaaaaaaaaa {10**27} bbbbbbbbbbbbbbbbbbbbbbbbbb ccccccccccccccccccccccccc"
|
||||
```
|
||||
|
||||
## Outputs
|
||||
|
@ -728,6 +731,9 @@ _ = (
|
|||
f"This string uses double quotes in an expression {"it's a quote"}"
|
||||
f"This f-string does not use any quotes."
|
||||
)
|
||||
|
||||
# Regression test for https://github.com/astral-sh/ruff/issues/14487
|
||||
f"aaaaaaaaaaaaaaaaaaaaaaaaaa {10**27} bbbbbbbbbbbbbbbbbbbbbbbbbb ccccccccccccccccccccccccc"
|
||||
```
|
||||
|
||||
|
||||
|
@ -1091,6 +1097,9 @@ _ = (
|
|||
f'This string uses double quotes in an expression {"it's a quote"}'
|
||||
f'This f-string does not use any quotes.'
|
||||
)
|
||||
|
||||
# Regression test for https://github.com/astral-sh/ruff/issues/14487
|
||||
f"aaaaaaaaaaaaaaaaaaaaaaaaaa {10**27} bbbbbbbbbbbbbbbbbbbbbbbbbb ccccccccccccccccccccccccc"
|
||||
```
|
||||
|
||||
|
||||
|
@ -1444,7 +1453,7 @@ _ = (
|
|||
# comment 27
|
||||
# comment 28
|
||||
} woah {x}"
|
||||
@@ -318,27 +330,27 @@
|
||||
@@ -318,29 +330,29 @@
|
||||
if indent2:
|
||||
foo = f"""hello world
|
||||
hello {
|
||||
|
@ -1490,4 +1499,6 @@ _ = (
|
|||
+ f"This string uses double quotes in an expression {"it's a quote"}"
|
||||
+ f"This f-string does not use any quotes."
|
||||
)
|
||||
|
||||
# Regression test for https://github.com/astral-sh/ruff/issues/14487
|
||||
```
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue