mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-24 20:34:31 +00:00
Remove unnecessary Comment#slice
calls (#6997)
This commit is contained in:
parent
34e8de738e
commit
b404e54f33
11 changed files with 23 additions and 39 deletions
|
@ -42,7 +42,7 @@ impl FormatNodeRule<StmtFor> for FormatStmtFor {
|
|||
let dangling_comments = comments.dangling(item);
|
||||
let body_start = body.first().map_or(iter.end(), Stmt::start);
|
||||
let or_else_comments_start =
|
||||
dangling_comments.partition_point(|comment| comment.slice().end() < body_start);
|
||||
dangling_comments.partition_point(|comment| comment.end() < body_start);
|
||||
|
||||
let (trailing_condition_comments, or_else_comments) =
|
||||
dangling_comments.split_at(or_else_comments_start);
|
||||
|
|
|
@ -119,7 +119,7 @@ fn format_case<'a>(
|
|||
|
||||
Ok(if let Some(last) = body.last() {
|
||||
let case_comments_start =
|
||||
dangling_comments.partition_point(|comment| comment.slice().end() <= last.end());
|
||||
dangling_comments.partition_point(|comment| comment.end() <= last.end());
|
||||
let (case_comments, rest) = dangling_comments.split_at(case_comments_start);
|
||||
let partition_point =
|
||||
case_comments.partition_point(|comment| comment.line_position().is_own_line());
|
||||
|
|
|
@ -26,7 +26,7 @@ impl FormatNodeRule<StmtWhile> for FormatStmtWhile {
|
|||
|
||||
let body_start = body.first().map_or(test.end(), Stmt::start);
|
||||
let or_else_comments_start =
|
||||
dangling_comments.partition_point(|comment| comment.slice().end() < body_start);
|
||||
dangling_comments.partition_point(|comment| comment.end() < body_start);
|
||||
|
||||
let (trailing_condition_comments, or_else_comments) =
|
||||
dangling_comments.split_at(or_else_comments_start);
|
||||
|
|
|
@ -223,7 +223,7 @@ impl FormatRule<Suite, PyFormatContext<'_>> for FormatSuite {
|
|||
// the leading comment. This is why the suite handling counts the lines before the
|
||||
// start of the next statement or before the first leading comments for compound statements.
|
||||
let start = if let Some(first_leading) = comments.leading(following).first() {
|
||||
first_leading.slice().start()
|
||||
first_leading.start()
|
||||
} else {
|
||||
following.start()
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue