ruff/crates
Charlie Marsh 1044d66c1c
Add support for PatternMatchMapping formatting (#6836)
<!--
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

Adds support for `PatternMatchMapping` -- i.e., cases like:

```python
match foo:
    case {"a": 1, "b": 2, **rest}:
        pass
```

Unfortunately, this node has _three_ kinds of dangling comments:

```python
{  # "open parenthesis comment"
   key: pattern,
   **  # end-of-line "double star comment"
   # own-line "double star comment"
   rest  # end-of-line "after rest comment"
   # own-line "after rest comment"
}
```

Some of the complexity comes from the fact that in `**rest`, `rest` is
an _identifier_, not a node, so we have to handle comments _after_ it as
dangling on the enclosing node, rather than trailing on `**rest`. (We
could change the AST to use `PatternMatchAs` there, which would be more
permissive than the grammar but not totally crazy -- `PatternMatchAs` is
used elsewhere to mean "a single identifier".)

Closes https://github.com/astral-sh/ruff/issues/6644.

## Test Plan

`cargo test`
2023-08-25 04:33:34 +00:00
..
flake8_to_ruff Bump version to 0.0.285 (#6660) 2023-08-17 15:46:28 -05:00
ruff Make isort's detect-same-package behavior configurable (#6833) 2023-08-24 14:09:26 -04:00
ruff_benchmark Extend BestFitting with mode (#6814) 2023-08-23 17:23:45 +02:00
ruff_cache Error on zero tab width (#6429) 2023-08-08 16:51:37 -04:00
ruff_cli Remove some indexing (#6728) 2023-08-21 16:56:15 +02:00
ruff_dev Improve formatter contributor docs (#6776) 2023-08-24 10:45:08 +00:00
ruff_diagnostics Avoid attempting to fix PT018 in multi-statement lines (#6829) 2023-08-23 19:09:34 -04:00
ruff_formatter Printer: Slice based queue and stack (#6819) 2023-08-24 14:49:27 +02:00
ruff_index
ruff_macros Remove parser dependency from ruff-python-ast (#6096) 2023-07-26 17:47:22 +02:00
ruff_python_ast Avoid attempting to fix PT018 in multi-statement lines (#6829) 2023-08-23 19:09:34 -04:00
ruff_python_codegen Make Parameters an optional field on ExprLambda (#6669) 2023-08-18 15:34:54 +00:00
ruff_python_formatter Add support for PatternMatchMapping formatting (#6836) 2023-08-25 04:33:34 +00:00
ruff_python_index Avoid attempting to fix PT018 in multi-statement lines (#6829) 2023-08-23 19:09:34 -04:00
ruff_python_literal Add support for nested replacements inside format specifications (#6616) 2023-08-17 09:07:30 -05:00
ruff_python_parser Remove lexing for colon-matching use cases (#6803) 2023-08-23 04:44:51 +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 Update mutable-argument-default (B006) to use extend-immutable-calls when determining if annotations are immutable (#6781) 2023-08-23 15:44:35 +00:00
ruff_python_stdlib Replace .map_or(false, $closure) with .is_some_and(closure) (#6244) 2023-08-01 19:29:42 +02:00
ruff_python_trivia Format all attribute dot comments manually (#6825) 2023-08-25 03:50:56 +00:00
ruff_shrinking Implement Ranged on more structs (#6639) 2023-08-17 11:22:39 -04:00
ruff_source_file Skip BOM when determining Locator's line starts (#6159) 2023-07-29 11:47:13 +00:00
ruff_text_size Pull in RustPython parser (#6099) 2023-07-27 09:29:11 +00:00
ruff_wasm Set a default on PythonVersion (#6446) 2023-08-09 15:19:27 +00:00