ruff/crates
Charlie Marsh 214eb707a6
Parenthesize expressions prior to LibCST parsing (#6742)
<!--
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 PR adds a utility for transforming expressions via LibCST that
automatically wraps the expression in parentheses, applies a
user-provided transformation, then strips the parentheses from the
generated code. LibCST can't parse arbitrary expression ranges, since
some expressions may require parenthesization in order to be parsed
properly. For example:

```python
option = (
    '{name}={value}'
    .format(nam=name, value=value)
)
```

In this case, the expression range is:

```python
'{name}={value}'
    .format(nam=name, value=value)
```

Which isn't valid on its own. So, instead, we add "fake" parentheses
around the expression.

We were already doing this in a few places, so this is mostly
formalizing and DRYing up that pattern.

Closes https://github.com/astral-sh/ruff/issues/6720.
2023-08-22 17:45:05 +00:00
..
flake8_to_ruff Bump version to 0.0.285 (#6660) 2023-08-17 15:46:28 -05:00
ruff Parenthesize expressions prior to LibCST parsing (#6742) 2023-08-22 17:45:05 +00:00
ruff_benchmark Refactor SourceKind to store file content (#6640) 2023-08-18 13:45:38 +00: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 Use a faster diffing library for the formatter ecosystem checks (#6497) 2023-08-11 15:51:54 +02:00
ruff_diagnostics Skip partial duplicates when applying multi-edit fixes (#6144) 2023-07-29 12:11:57 +00:00
ruff_formatter ruff_formatter crate doc comment fixes (#6677) 2023-08-19 17:42:02 +01:00
ruff_index Add unreachable code rule (#5384) 2023-07-04 14:27:23 +00:00
ruff_macros Remove parser dependency from ruff-python-ast (#6096) 2023-07-26 17:47:22 +02:00
ruff_python_ast Make Parameters an optional field on ExprLambda (#6669) 2023-08-18 15:34:54 +00:00
ruff_python_codegen Make Parameters an optional field on ExprLambda (#6669) 2023-08-18 15:34:54 +00:00
ruff_python_formatter Allow up to two empty lines after top-level imports (#6777) 2023-08-22 12:27:40 -04:00
ruff_python_index Remove some extraneous newlines in Cargo.toml (#6577) 2023-08-14 23:39:41 +00:00
ruff_python_literal Add support for nested replacements inside format specifications (#6616) 2023-08-17 09:07:30 -05:00
ruff_python_parser Make Parameters an optional field on ExprLambda (#6669) 2023-08-18 15:34:54 +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 Use a single node hierarchy to track statements and expressions (#6709) 2023-08-21 21:32:57 -04: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 Add support for multi-character operator tokens to SimpleTokenizer (#6563) 2023-08-16 09:09:19 -04: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