mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-27 20:42:10 +00:00
Format if
statements (#4961)
This commit is contained in:
parent
548a3cbb3f
commit
1accbeffd6
26 changed files with 882 additions and 357 deletions
|
@ -215,6 +215,26 @@ fn handle_in_between_bodies_own_line_comment<'a>(
|
|||
return CommentPlacement::Default(comment);
|
||||
}
|
||||
|
||||
// If there's any non-trivia token between the preceding node and the comment, than it means that
|
||||
// we're past the case of the alternate branch, defer to the default rules
|
||||
// ```python
|
||||
// if a:
|
||||
// pass
|
||||
// else:
|
||||
// # leading comment
|
||||
// def inline_after_else(): ...
|
||||
// ```
|
||||
if SimpleTokenizer::new(
|
||||
locator.contents(),
|
||||
TextRange::new(preceding.end(), comment.slice().start()),
|
||||
)
|
||||
.skip_trivia()
|
||||
.next()
|
||||
.is_some()
|
||||
{
|
||||
return CommentPlacement::Default(comment);
|
||||
}
|
||||
|
||||
// it now depends on the indentation level of the comment if it is a leading comment for e.g.
|
||||
// the following `elif` or indeed a trailing comment of the previous body's last statement.
|
||||
let comment_indentation =
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue