mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-29 13:25:17 +00:00
Revert "Avoid inserting trailing commas within f-strings" (#8576)
Reverts astral-sh/ruff#8574. This caused a bunch of ecosystem changes -- needs more work.
This commit is contained in:
parent
9d1027c239
commit
9e184a9067
3 changed files with 4 additions and 24 deletions
|
@ -639,10 +639,3 @@ foo = namedtuple(
|
||||||
:20
|
:20
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
# Make sure we don't insert commas within f-strings.
|
|
||||||
f"""This is a test. {
|
|
||||||
"Another sentence."
|
|
||||||
if True else
|
|
||||||
"Alternative route!"
|
|
||||||
}"""
|
|
||||||
|
|
|
@ -223,24 +223,11 @@ pub(crate) fn trailing_commas(
|
||||||
tokens: &[LexResult],
|
tokens: &[LexResult],
|
||||||
locator: &Locator,
|
locator: &Locator,
|
||||||
) {
|
) {
|
||||||
let mut fstrings = 0u32;
|
|
||||||
let tokens = tokens
|
let tokens = tokens
|
||||||
.iter()
|
.iter()
|
||||||
.flatten()
|
.flatten()
|
||||||
.filter(|(tok, _)| match tok {
|
|
||||||
// Completely ignore comments -- they just interfere with the logic.
|
// Completely ignore comments -- they just interfere with the logic.
|
||||||
Tok::Comment(_) => false,
|
.filter(|&r| !matches!(r, (Tok::Comment(_), _)))
|
||||||
// Ignore content within f-strings.
|
|
||||||
Tok::FStringStart => {
|
|
||||||
fstrings = fstrings.saturating_add(1);
|
|
||||||
false
|
|
||||||
}
|
|
||||||
Tok::FStringEnd => {
|
|
||||||
fstrings = fstrings.saturating_sub(1);
|
|
||||||
false
|
|
||||||
}
|
|
||||||
_ => fstrings == 0,
|
|
||||||
})
|
|
||||||
.map(Token::from_spanned);
|
.map(Token::from_spanned);
|
||||||
let tokens = [Token::irrelevant(), Token::irrelevant()]
|
let tokens = [Token::irrelevant(), Token::irrelevant()]
|
||||||
.into_iter()
|
.into_iter()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue