mirror of
https://github.com/astral-sh/ruff.git
synced 2025-10-06 16:40:39 +00:00
Disallow newlines in format specifiers of single quoted f- or t-strings (#18708)
This commit is contained in:
parent
23261a38a0
commit
1188ffccc4
17 changed files with 521 additions and 513 deletions
|
@ -323,27 +323,18 @@ fn handle_enclosed_comment<'a>(
|
|||
AnyNodeRef::TString(tstring) => CommentPlacement::dangling(tstring, comment),
|
||||
AnyNodeRef::InterpolatedElement(element) => {
|
||||
if let Some(preceding) = comment.preceding_node() {
|
||||
if comment.line_position().is_own_line() && element.format_spec.is_some() {
|
||||
return if comment.following_node().is_some() {
|
||||
// Own line comment before format specifier
|
||||
// ```py
|
||||
// aaaaaaaaaaa = f"""asaaaaaaaaaaaaaaaa {
|
||||
// aaaaaaaaaaaa + bbbbbbbbbbbb + ccccccccccccccc + dddddddd
|
||||
// # comment
|
||||
// :.3f} cccccccccc"""
|
||||
// ```
|
||||
CommentPlacement::trailing(preceding, comment)
|
||||
} else {
|
||||
// TODO: This can be removed once format specifiers with a newline are a syntax error.
|
||||
// This is to handle cases like:
|
||||
// ```py
|
||||
// x = f"{x !s
|
||||
// :>0
|
||||
// # comment 21
|
||||
// }"
|
||||
// ```
|
||||
CommentPlacement::trailing(element, comment)
|
||||
};
|
||||
// Own line comment before format specifier
|
||||
// ```py
|
||||
// aaaaaaaaaaa = f"""asaaaaaaaaaaaaaaaa {
|
||||
// aaaaaaaaaaaa + bbbbbbbbbbbb + ccccccccccccccc + dddddddd
|
||||
// # comment
|
||||
// :.3f} cccccccccc"""
|
||||
// ```
|
||||
if comment.line_position().is_own_line()
|
||||
&& element.format_spec.is_some()
|
||||
&& comment.following_node().is_some()
|
||||
{
|
||||
return CommentPlacement::trailing(preceding, comment);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue