ruff/crates/ruff_python_formatter/src/comments/snapshots
Micha Reiser d6daa61563
Handle trailing end-of-line comments in-between-bodies (#4812)
<!--
Thank you for contributing to Ruff! To help us out with reviewing, please consider the following:

- Does this pull request include a summary of the change? (See below.)
- Does this pull request include a descriptive title?
- Does this pull request include references to any relevant issues?
-->

## Summary

And more custom logic around comments in bodies... uff. 

Let's say we have the following code

```python
if x == y:
    pass # trailing comment of pass
else: # trailing comment of `else`
    print("I have no comments")
```

Right now, the formatter attaches the `# trailing comment of `else` as a trailing comment of `pass` because it doesn't "see" that there's an `else` keyword in between (because the else body is just a Vec and not a node). 

This PR adds custom logic that attaches the trailing comments after the `else` as dangling comments to the `if` statement. The if statement must then split the dangling comments by `comments.text_position()`:
* All comments up to the first end-of-line comment are leading comments of the `else` keyword.
* All end-of-line comments coming after are `trailing` comments for the `else` keyword.


## Test Plan

I added new unit tests.
2023-06-03 15:29:22 +02:00
..
ruff_python_formatter__comments__debug__tests__debug.snap Generic "comment to node" association logic (#4642) 2023-05-30 09:28:01 +00:00
ruff_python_formatter__comments__tests__base_test.snap Generic "comment to node" association logic (#4642) 2023-05-30 09:28:01 +00:00
ruff_python_formatter__comments__tests__binary_expression_left_operand_comment.snap Place comments of left and right binary expression operands (#4751) 2023-06-01 07:01:32 +00:00
ruff_python_formatter__comments__tests__binary_expression_left_operand_trailing_end_of_line_comment.snap Place comments of left and right binary expression operands (#4751) 2023-06-01 07:01:32 +00:00
ruff_python_formatter__comments__tests__dangling_comment.snap Generic "comment to node" association logic (#4642) 2023-05-30 09:28:01 +00:00
ruff_python_formatter__comments__tests__empty_file.snap Generic "comment to node" association logic (#4642) 2023-05-30 09:28:01 +00:00
ruff_python_formatter__comments__tests__if_elif_else_comments.snap Correctly associate own-line comments in bodies (#4671) 2023-06-01 08:12:53 +02:00
ruff_python_formatter__comments__tests__if_elif_if_else_comments.snap Correctly associate own-line comments in bodies (#4671) 2023-06-01 08:12:53 +02:00
ruff_python_formatter__comments__tests__leading_most_outer.snap Generic "comment to node" association logic (#4642) 2023-05-30 09:28:01 +00:00
ruff_python_formatter__comments__tests__match_cases.snap Correctly associate own-line comments in bodies (#4671) 2023-06-01 08:12:53 +02:00
ruff_python_formatter__comments__tests__nested_binary_expression.snap Place comments of left and right binary expression operands (#4751) 2023-06-01 07:01:32 +00:00
ruff_python_formatter__comments__tests__non_positional_arguments_slash_on_same_line.snap Handle positional-only-arguments separator comments (#4748) 2023-06-01 06:22:49 +00:00
ruff_python_formatter__comments__tests__non_positional_arguments_with_defaults.snap Handle positional-only-arguments separator comments (#4748) 2023-06-01 06:22:49 +00:00
ruff_python_formatter__comments__tests__only_comments.snap Generic "comment to node" association logic (#4642) 2023-05-30 09:28:01 +00:00
ruff_python_formatter__comments__tests__parenthesized_expression.snap Generic "comment to node" association logic (#4642) 2023-05-30 09:28:01 +00:00
ruff_python_formatter__comments__tests__parenthesized_trailing_comment.snap Generic "comment to node" association logic (#4642) 2023-05-30 09:28:01 +00:00
ruff_python_formatter__comments__tests__positional_argument_only_comment.snap Handle positional-only-arguments separator comments (#4748) 2023-06-01 06:22:49 +00:00
ruff_python_formatter__comments__tests__positional_argument_only_comment_without_following_node.snap Handle positional-only-arguments separator comments (#4748) 2023-06-01 06:22:49 +00:00
ruff_python_formatter__comments__tests__positional_argument_only_leading_comma_comment.snap Handle positional-only-arguments separator comments (#4748) 2023-06-01 06:22:49 +00:00
ruff_python_formatter__comments__tests__trailing_after_comma.snap Generic "comment to node" association logic (#4642) 2023-05-30 09:28:01 +00:00
ruff_python_formatter__comments__tests__trailing_comment_after_single_statement_body.snap Correctly associate own-line comments in bodies (#4671) 2023-06-01 08:12:53 +02:00
ruff_python_formatter__comments__tests__trailing_function_comment.snap Correctly associate own-line comments in bodies (#4671) 2023-06-01 08:12:53 +02:00
ruff_python_formatter__comments__tests__trailing_most_outer.snap Generic "comment to node" association logic (#4642) 2023-05-30 09:28:01 +00:00
ruff_python_formatter__comments__tests__trailing_most_outer_nested.snap Correctly associate own-line comments in bodies (#4671) 2023-06-01 08:12:53 +02:00
ruff_python_formatter__comments__tests__try_except.snap Correctly associate own-line comments in bodies (#4671) 2023-06-01 08:12:53 +02:00
ruff_python_formatter__comments__tests__try_except_finally_else.snap Correctly associate own-line comments in bodies (#4671) 2023-06-01 08:12:53 +02:00
ruff_python_formatter__comments__tests__while_trailing_else_end_of_line_comment.snap Handle trailing end-of-line comments in-between-bodies (#4812) 2023-06-03 15:29:22 +02:00
ruff_python_formatter__comments__tests__while_trailing_end_of_line_comment.snap Handle trailing body end-of-line comments (#4811) 2023-06-03 15:17:33 +02:00