mirror of
https://github.com/astral-sh/ruff.git
synced 2025-11-25 06:13:01 +00:00
## Summary
This PR is a small refactor to extract out the logic for normalizing
string in the formatter from the `StringPart` struct. It also separates
the quote selection into a separate method on the new
`StringNormalizer`. Both of these will help in the f-string formatting
to use `StringPart` and `choose_quotes` irrespective of normalization.
The reason for having separate quote selection and normalization step is
so that the f-string formatting can perform quote selection on its own.
Unlike string and byte literals, the f-string formatting would require
that the normalization happens only for the literal elements of it i.e.,
the "foo" and "bar" in `f"foo {x + y} bar"`. This will automatically be
handled by the already separate `normalize_string` function.
Another use-case in the f-string formatting is to extract out the
relevant information from the `StringPart` like quotes and prefix which
is to be passed as context while formatting each element of an f-string.
## Test Plan
Ensure that clippy is happy and all tests pass.
|
||
|---|---|---|
| .. | ||
| comments | ||
| expression | ||
| module | ||
| other | ||
| pattern | ||
| snapshots | ||
| statement | ||
| string | ||
| type_param | ||
| builders.rs | ||
| cli.rs | ||
| context.rs | ||
| generated.rs | ||
| lib.rs | ||
| main.rs | ||
| options.rs | ||
| prelude.rs | ||
| preview.rs | ||
| range.rs | ||
| shared_traits.rs | ||
| verbatim.rs | ||