ruff/crates
Micha Reiser 3973836420
Correctly handle left/right breaking of binary expression
<!--
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
Black supports for layouts when it comes to breaking binary expressions:

```rust
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
enum BinaryLayout {
    /// Put each operand on their own line if either side expands
    Default,

    /// Try to expand the left to make it fit. Add parentheses if the left or right don't fit.
    ///
    ///```python
    /// [
    ///     a,
    ///     b
    /// ] & c
    ///```
    ExpandLeft,

    /// Try to expand the right to make it fix. Add parentheses if the left or right don't fit.
    ///
    /// ```python
    /// a & [
    ///     b,
    ///     c
    /// ]
    /// ```
    ExpandRight,

    /// Both the left and right side can be expanded. Try in the following order:
    /// * expand the right side
    /// * expand the left side
    /// * expand both sides
    ///
    /// to make the expression fit
    ///
    /// ```python
    /// [
    ///     a,
    ///     b
    /// ] & [
    ///     c,
    ///     d
    /// ]
    /// ```
    ExpandRightThenLeft,
}
```

Our current implementation only handles `ExpandRight` and `Default` correctly. This PR adds support for `ExpandRightThenLeft` and `ExpandLeft`. 

## Test Plan

I added tests that play through all 4 binary expression layouts.
2023-06-21 09:40:05 +02:00
..
flake8_to_ruff Bump version to 0.0.274 (#5230) 2023-06-20 22:12:32 -04:00
ruff Bump version to 0.0.274 (#5230) 2023-06-20 22:12:32 -04:00
ruff_benchmark Use consistent Cargo.toml metadata in all crates (#5015) 2023-06-12 00:02:40 +00:00
ruff_cache Only use a single cache file per Python package (#5117) 2023-06-19 17:46:13 +02:00
ruff_cli Bump version to 0.0.274 (#5230) 2023-06-20 22:12:32 -04:00
ruff_dev Add a script that tests formatter stability on repositories (#5055) 2023-06-19 14:13:38 +00:00
ruff_diagnostics Use consistent Cargo.toml metadata in all crates (#5015) 2023-06-12 00:02:40 +00:00
ruff_formatter Add BestFittingMode (#5184) 2023-06-20 18:16:01 +02:00
ruff_index Run rustfmt on nightly to clean up erroneous comments (#5106) 2023-06-15 00:19:05 +00:00
ruff_macros Refactor top llvm-lines entry (#5147) 2023-06-18 12:39:06 +02:00
ruff_python_ast Fix ArgWithDefault comments handling (#5204) 2023-06-20 20:48:07 +00:00
ruff_python_formatter Correctly handle left/right breaking of binary expression 2023-06-21 09:40:05 +02:00
ruff_python_semantic Move StarImport to its own module (#5186) 2023-06-20 13:12:46 -04:00
ruff_python_stdlib Replace static CallPath vectors with matches! macros (#5148) 2023-06-16 17:34:42 +00:00
ruff_python_whitespace Use consistent Cargo.toml metadata in all crates (#5015) 2023-06-12 00:02:40 +00:00
ruff_rustpython Use consistent Cargo.toml metadata in all crates (#5015) 2023-06-12 00:02:40 +00:00
ruff_testing_macros Use consistent Cargo.toml metadata in all crates (#5015) 2023-06-12 00:02:40 +00:00
ruff_textwrap Use consistent Cargo.toml metadata in all crates (#5015) 2023-06-12 00:02:40 +00:00
ruff_wasm Move copyright rules to flake8_copyright module (#5236) 2023-06-21 01:56:40 +00:00