mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-28 04:45:01 +00:00
Rename Comments methods (#6649)
This commit is contained in:
parent
3ceb6fbeb0
commit
0cea4975fc
44 changed files with 128 additions and 172 deletions
|
@ -24,7 +24,7 @@ impl FormatNodeRule<Arguments> for FormatArguments {
|
|||
// ```
|
||||
if item.args.is_empty() && item.keywords.is_empty() {
|
||||
let comments = f.context().comments().clone();
|
||||
let dangling = comments.dangling_comments(item);
|
||||
let dangling = comments.dangling(item);
|
||||
return write!(f, [empty_parenthesized("(", dangling, ")")]);
|
||||
}
|
||||
|
||||
|
@ -77,7 +77,7 @@ impl FormatNodeRule<Arguments> for FormatArguments {
|
|||
// c,
|
||||
// )
|
||||
let comments = f.context().comments().clone();
|
||||
let dangling_comments = comments.dangling_comments(item.as_any_node_ref());
|
||||
let dangling_comments = comments.dangling(item.as_any_node_ref());
|
||||
|
||||
write!(
|
||||
f,
|
||||
|
|
|
@ -15,7 +15,7 @@ impl FormatNodeRule<Comprehension> for FormatComprehension {
|
|||
|
||||
impl Format<PyFormatContext<'_>> for Spacer<'_> {
|
||||
fn fmt(&self, f: &mut PyFormatter) -> FormatResult<()> {
|
||||
if f.context().comments().has_leading_comments(self.0) {
|
||||
if f.context().comments().has_leading(self.0) {
|
||||
soft_line_break_or_space().fmt(f)
|
||||
} else {
|
||||
space().fmt(f)
|
||||
|
@ -36,13 +36,13 @@ impl FormatNodeRule<Comprehension> for FormatComprehension {
|
|||
}
|
||||
|
||||
let comments = f.context().comments().clone();
|
||||
let dangling_item_comments = comments.dangling_comments(item);
|
||||
let dangling_item_comments = comments.dangling(item);
|
||||
let (before_target_comments, before_in_comments) = dangling_item_comments.split_at(
|
||||
dangling_item_comments
|
||||
.partition_point(|comment| comment.slice().end() < target.start()),
|
||||
);
|
||||
|
||||
let trailing_in_comments = comments.dangling_comments(iter);
|
||||
let trailing_in_comments = comments.dangling(iter);
|
||||
|
||||
let in_spacer = format_with(|f| {
|
||||
if before_in_comments.is_empty() {
|
||||
|
@ -73,7 +73,7 @@ impl FormatNodeRule<Comprehension> for FormatComprehension {
|
|||
let joined = format_with(|f| {
|
||||
let mut joiner = f.join_with(soft_line_break_or_space());
|
||||
for if_case in ifs {
|
||||
let dangling_if_comments = comments.dangling_comments(if_case);
|
||||
let dangling_if_comments = comments.dangling(if_case);
|
||||
|
||||
let (own_line_if_comments, end_of_line_if_comments) = dangling_if_comments
|
||||
.split_at(
|
||||
|
|
|
@ -46,7 +46,7 @@ impl FormatNodeRule<ExceptHandlerExceptHandler> for FormatExceptHandlerExceptHan
|
|||
} = item;
|
||||
|
||||
let comments_info = f.context().comments().clone();
|
||||
let dangling_comments = comments_info.dangling_comments(item);
|
||||
let dangling_comments = comments_info.dangling(item);
|
||||
|
||||
write!(
|
||||
f,
|
||||
|
|
|
@ -22,7 +22,7 @@ impl FormatNodeRule<MatchCase> for FormatMatchCase {
|
|||
} = item;
|
||||
|
||||
let comments = f.context().comments().clone();
|
||||
let dangling_item_comments = comments.dangling_comments(item);
|
||||
let dangling_item_comments = comments.dangling(item);
|
||||
|
||||
write!(
|
||||
f,
|
||||
|
@ -33,7 +33,7 @@ impl FormatNodeRule<MatchCase> for FormatMatchCase {
|
|||
&format_with(|f| {
|
||||
write!(f, [text("case"), space()])?;
|
||||
|
||||
let leading_pattern_comments = comments.leading_comments(pattern);
|
||||
let leading_pattern_comments = comments.leading(pattern);
|
||||
if !leading_pattern_comments.is_empty() {
|
||||
parenthesized(
|
||||
"(",
|
||||
|
|
|
@ -63,7 +63,7 @@ impl FormatNodeRule<Parameters> for FormatParameters {
|
|||
let (slash, star) = find_parameter_separators(f.context().source(), item);
|
||||
|
||||
let comments = f.context().comments().clone();
|
||||
let dangling = comments.dangling_comments(item);
|
||||
let dangling = comments.dangling(item);
|
||||
|
||||
// First dangling comment: trailing the opening parenthesis, e.g.:
|
||||
// ```python
|
||||
|
|
|
@ -19,7 +19,7 @@ impl FormatNodeRule<WithItem> for FormatWithItem {
|
|||
} = item;
|
||||
|
||||
let comments = f.context().comments().clone();
|
||||
let trailing_as_comments = comments.dangling_comments(item);
|
||||
let trailing_as_comments = comments.dangling(item);
|
||||
|
||||
write!(
|
||||
f,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue