mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-27 20:42:10 +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
|
@ -39,13 +39,13 @@ impl FormatNodeRule<ExprSlice> for FormatExprSlice {
|
|||
let slice_dangling_comments = comments.dangling(item.as_any_node_ref());
|
||||
// Put the dangling comments (where the nodes are missing) into buckets
|
||||
let first_colon_partition_index =
|
||||
slice_dangling_comments.partition_point(|x| x.slice().start() < first_colon.start());
|
||||
slice_dangling_comments.partition_point(|x| x.start() < first_colon.start());
|
||||
let (dangling_lower_comments, dangling_upper_step_comments) =
|
||||
slice_dangling_comments.split_at(first_colon_partition_index);
|
||||
let (dangling_upper_comments, dangling_step_comments) =
|
||||
if let Some(second_colon) = &second_colon {
|
||||
let second_colon_partition_index = dangling_upper_step_comments
|
||||
.partition_point(|x| x.slice().start() < second_colon.start());
|
||||
.partition_point(|x| x.start() < second_colon.start());
|
||||
dangling_upper_step_comments.split_at(second_colon_partition_index)
|
||||
} else {
|
||||
// Without a second colon they remaining dangling comments belong between the first
|
||||
|
|
|
@ -212,7 +212,7 @@ impl Format<PyFormatContext<'_>> for FormatStringContinuation<'_> {
|
|||
// )
|
||||
// ```
|
||||
let leading_comments_end = dangling_comments
|
||||
.partition_point(|comment| comment.slice().start() <= token_range.start());
|
||||
.partition_point(|comment| comment.start() <= token_range.start());
|
||||
|
||||
let (leading_part_comments, rest) =
|
||||
dangling_comments.split_at(leading_comments_end);
|
||||
|
@ -227,7 +227,7 @@ impl Format<PyFormatContext<'_>> for FormatStringContinuation<'_> {
|
|||
comment.line_position().is_end_of_line()
|
||||
&& !locator.contains_line_break(TextRange::new(
|
||||
token_range.end(),
|
||||
comment.slice().start(),
|
||||
comment.start(),
|
||||
))
|
||||
});
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue