ruff/crates
Micha Reiser 6ab3fc60f4
Correctly handle newlines after/before comments (#4895)
<!--
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

This issue fixes the removal of empty lines between a leading comment and the previous statement:

```python
a  = 20

# leading comment
b = 10
```

Ruff removed the empty line between `a` and `b` because:
* The leading comments formatting does not preserve leading newlines (to avoid adding new lines at the top of a body)
* The `JoinNodesBuilder` counted the lines before `b`, which is 1 -> Doesn't insert a new line

This is fixed by changing the `JoinNodesBuilder` to count the lines instead *after* the last node. This correctly gives 1, and the `# leading comment` will insert the empty lines between any other leading comment or the node.



## Test Plan

I added a new test for empty lines.
2023-06-07 14:49:43 +02:00
..
flake8_to_ruff Bump version to 0.0.271 (#4890) 2023-06-06 15:11:48 -04:00
ruff Clarify requires-python inference requirements (#4918) 2023-06-07 04:18:56 +00:00
ruff_benchmark Add Formatter benchmark (#4860) 2023-06-05 21:05:42 +02:00
ruff_cache
ruff_cli Bump version to 0.0.271 (#4890) 2023-06-06 15:11:48 -04: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 Rename ruff_formatter::builders::BestFitting to FormatBestFitting (#4841) 2023-06-04 00:13:51 +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 Introduce AnyFunctionDefinition Node (#4898) 2023-06-06 20:37:46 +02:00
ruff_python_formatter Correctly handle newlines after/before comments (#4895) 2023-06-07 14:49:43 +02:00
ruff_python_semantic Replace one-off locals property with ScopeFlags (#4912) 2023-06-06 21:22:21 -04:00
ruff_python_stdlib Lint pyproject.toml (#4496) 2023-05-25 12:05:28 +00:00
ruff_rustpython
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