ruff/crates/ruff_python_formatter/src
Dhruv Manilawala 6f9c128d77
Separate StringNormalizer from StringPart (#9954)
## 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.
2024-02-13 18:14:56 +05:30
..
comments Range formatting: Fix invalid syntax after parenthesizing expression (#9751) 2024-02-02 17:56:25 +01:00
expression Range formatting: Fix invalid syntax after parenthesizing expression (#9751) 2024-02-02 17:56:25 +01:00
module Attach dangling comments to the comprehension instead of the if or iter nodes (#7693) 2023-09-29 10:45:01 +01:00
other Separate StringNormalizer from StringPart (#9954) 2024-02-13 18:14:56 +05:30
pattern New Singleton enum for PatternMatchSingleton node (#8063) 2023-10-30 05:48:53 +00:00
snapshots Remove exception-handler lexing from unused-bound-exception fix (#5851) 2023-07-18 18:27:46 +00:00
statement Disable top-level docstring formatting for notebooks (#9957) 2024-02-12 18:14:02 +00:00
string Separate StringNormalizer from StringPart (#9954) 2024-02-13 18:14:56 +05:30
type_param Don't move type param opening parenthesis comment (#8163) 2023-10-24 12:02:27 +00:00
builders.rs Implement multiline dictionary and list hugging for preview style (#8293) 2023-11-30 21:11:14 -05:00
cli.rs Remove type parameter from parse_* methods (#9466) 2024-01-11 19:41:19 +01:00
context.rs Split string formatting to individual nodes (#9058) 2023-12-14 12:55:10 -06:00
generated.rs Split string formatting to individual nodes (#9058) 2023-12-14 12:55:10 -06:00
lib.rs Reduce Result<Tok, LexicalError> size by using Box<str> instead of String (#9885) 2024-02-08 20:36:22 +00:00
main.rs Formatter and parser refactoring (#7569) 2023-09-26 15:29:43 +02:00
options.rs Stabilize quote-style preserve (#9922) 2024-02-12 09:30:07 +00:00
prelude.rs Accept any Into<AnyNodeRef> as Comments arguments (#5205) 2023-06-20 16:49:21 +00:00
preview.rs Preview Style: Format module level docstring (#9725) 2024-02-05 15:03:34 +00:00
range.rs Disable top-level docstring formatting for notebooks (#9957) 2024-02-12 18:14:02 +00:00
shared_traits.rs ruff_python_formatter: copy and inline shared traits (#8656) 2023-11-13 12:16:04 -05:00
verbatim.rs Range formatting: Fix invalid syntax after parenthesizing expression (#9751) 2024-02-02 17:56:25 +01:00