ruff/crates
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
..
flake8_to_ruff Bump version to 0.0.270 (#4637) 2023-05-24 16:34:29 +00:00
ruff [`flake8-pyi`] Implement PYI035 (#4820) 2023-06-03 03:13:04 +00:00
ruff_benchmark Upgrade RustPython (#4747) 2023-05-31 08:26:35 +00:00
ruff_cache Rename ruff_python_semantic's `Context` struct to `SemanticModel` (#4565) 2023-05-22 02:35:03 +00:00
ruff_cli Replace deletion-tracking with enforced isolation levels (#4766) 2023-06-02 02:45:56 +00:00
ruff_dev Add a `ruff_textwrap` crate (#4731) 2023-05-31 16:35:23 +00:00
ruff_diagnostics Use a separate fix-isolation group for every parent node (#4774) 2023-06-02 03:07:55 +00:00
ruff_formatter Leading, Dangling, and Trailing comments formatting (#4785) 2023-06-02 09:26:36 +02:00
ruff_index Introduce `ruff_index` crate (#4597) 2023-05-23 17:40:35 +02:00
ruff_macros Merge registry into codes (#4651) 2023-06-02 10:33:01 +00:00
ruff_newlines Add a `ruff_textwrap` crate (#4731) 2023-05-31 16:35:23 +00:00
ruff_python_ast Add to `AnyNode` and `AnyNodeRef` conversion methods to `AstNode` (#4783) 2023-06-02 08:10:41 +02:00
ruff_python_formatter Handle trailing end-of-line comments in-between-bodies (#4812) 2023-06-03 15:29:22 +02:00
ruff_python_semantic Remove `name` field from import binding kinds (#4817) 2023-06-02 23:02:47 -04:00
ruff_python_stdlib Lint pyproject.toml (#4496) 2023-05-25 12:05:28 +00:00
ruff_rustpython Re-integrate RustPython parser repository (#4359) 2023-05-11 07:47:17 +00:00
ruff_testing_macros testing_macros: Add missing `full` feature to `syn` dependency (#4722) 2023-05-30 07:42:06 +00:00
ruff_textwrap Add a `ruff_textwrap` crate (#4731) 2023-05-31 16:35:23 +00:00
ruff_wasm Add `pyflakes.extend-generics` setting (#4677) 2023-06-01 22:19:37 +00:00