ruff/crates
Charlie Marsh 2759db6604
Allow up to two newlines after trailing clause body comments (#7557)
## Summary

The number of newlines after a trailing comment in a clause body needs
to follow the usual rules -- so, up to two for top-level, up to one for
nested, etc.

For example, Black preserves both newlines after `# comment` here:

```python
if True:
    pass

    # comment


else:
    pass
```

But it truncates to one newline here:

```python
if True:
    if True:
        pass
        # comment


    else:
        pass
else:
    pass
```

## Test Plan

Significant improvement on `transformers`.

Before:

| project | similarity index | total files | changed files |

|--------------|------------------:|------------------:|------------------:|
| cpython | 0.76083 | 1789 | 1631 |
| django | 0.99983 | 2760 | 36 |
| transformers | 0.99957 | 2587 | 402 |
| twine | 1.00000 | 33 | 0 |
| typeshed | 0.99979 | 3496 | 22 |
| warehouse | 0.99967 | 648 | 15 |
| zulip | 0.99972 | 1437 | 21 |


After:

| project | similarity index | total files | changed files |

|--------------|------------------:|------------------:|------------------:|
| cpython | 0.76083 | 1789 | 1631 |
| django | 0.99983 | 2760 | 36 |
| **transformers** | **0.99963** | **2587** | **323** |
| twine | 1.00000 | 33 | 0 |
| typeshed | 0.99979 | 3496 | 22 |
| warehouse | 0.99967 | 648 | 15 |
| zulip | 0.99972 | 1437 | 21 |
2023-09-21 14:04:49 +00:00
..
flake8_to_ruff Rename ruff crate to ruff_linter (#7529) 2023-09-20 08:38:27 +02:00
ruff_benchmark Introduce LinterSettings 2023-09-20 17:02:34 +02:00
ruff_cache Introduce FormatterSettings (#7545) 2023-09-21 08:01:24 +02:00
ruff_cli Bump rayon from 1.7.0 to 1.8.0 (#7564) 2023-09-21 11:52:41 +02:00
ruff_dev Bump rayon from 1.7.0 to 1.8.0 (#7564) 2023-09-21 11:52:41 +02:00
ruff_diagnostics Create ruff_notebook crate (#7039) 2023-09-01 13:56:44 +00:00
ruff_formatter Introduce FormatterSettings (#7545) 2023-09-21 08:01:24 +02:00
ruff_index Add unreachable code rule (#5384) 2023-07-04 14:27:23 +00:00
ruff_linter Detect asyncio.get_running_loop calls in RUF006 (#7562) 2023-09-21 04:37:38 +00:00
ruff_macros Unify Settings and AllSettings (#7532) 2023-09-20 13:56:07 +00:00
ruff_notebook chore: Upgrade pyproject-toml crate (#7335) 2023-09-13 17:55:03 +02:00
ruff_python_ast Treat parameters-with-newline as empty in function formatting (#7550) 2023-09-20 16:20:22 -04:00
ruff_python_codegen Fix stylist indentation with a formfeed (#7489) 2023-09-19 12:01:16 +02:00
ruff_python_formatter Allow up to two newlines after trailing clause body comments (#7557) 2023-09-21 14:04:49 +00:00
ruff_python_index Remove triple-quoted string ranges computation (#7476) 2023-09-18 20:57:49 +05:30
ruff_python_literal Avoid parsing other parts of a format specification if replacements are present (#6858) 2023-08-25 17:42:57 +00:00
ruff_python_parser Add range to lexer test snapshots (#7265) 2023-09-11 19:12:46 +00:00
ruff_python_resolver Replace .map_or(false, $closure) with .is_some_and(closure) (#6244) 2023-08-01 19:29:42 +02:00
ruff_python_semantic Detect asyncio.get_running_loop calls in RUF006 (#7562) 2023-09-21 04:37:38 +00:00
ruff_python_stdlib [flake8-logging] Implement LOG002: invalid-get-logger-argument (#7399) 2023-09-16 12:21:30 -04:00
ruff_python_trivia Tokenizer: Emit only a single bogus token (#7425) 2023-09-19 16:06:03 +02:00
ruff_shrinking Bump shlex from 1.1.0 to 1.2.0 (#7381) 2023-09-14 09:40:05 -05:00
ruff_source_file Use dot references in docs for methods (#7391) 2023-09-14 14:35:34 -04:00
ruff_text_size Unify line size settings between ruff and the formatter (#6873) 2023-08-28 06:44:56 +00:00
ruff_wasm Introduce FormatterSettings (#7545) 2023-09-21 08:01:24 +02:00
ruff_workspace Introduce FormatterSettings (#7545) 2023-09-21 08:01:24 +02:00