ruff/crates/ruff_python_ast/src
Micha Reiser c52aa8f065
Basic string formatting
<!--
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 implements formatting for non-f-string Strings that do not use implicit concatenation. 

Docstring formatting is out of the scope of this PR.

<!-- What's the purpose of the change? What does it do, and why? -->

## Test Plan

I added a few tests for simple string literals. 

## Performance

Ouch. This is hitting performance somewhat hard. This is probably because we now iterate each string a couple of times:

1. To detect if it is an implicit string continuation
2. To detect if the string contains any new lines
3. To detect the preferred quote
4. To normalize the string

Edit: I integrated the detection of newlines into the preferred quote detection so that we only iterate the string three time.
We can probably do better by merging the implicit string continuation with the quote detection and new line detection by iterating till the end of the string part and returning the offset. We then use our simple tokenizer to skip over any comments or whitespace until we find the first non trivia token. From there we keep continue doing this in a loop until we reach the end o the string. I'll leave this improvement for later.
2023-06-23 09:46:05 +02:00
..
source_code Upgrade RustPython to access ranged names (#5194) 2023-06-20 15:43:38 +00:00
visitor Fix annotation and format spec visitors (#5324) 2023-06-23 03:55:42 +00:00
all.rs Allow re-assignments to __all__ (#4967) 2023-06-08 17:19:56 +00:00
call_path.rs Refactor range from Attributed to Nodes (#4422) 2023-05-16 06:36:32 +00:00
cast.rs Upgrade RustPython (#4900) 2023-06-08 05:53:14 +00:00
comparable.rs Upgrade RustPython (#5192) 2023-06-19 21:09:53 +00:00
docstrings.rs Move Python whitespace utilities into new ruff_python_whitespace crate (#4993) 2023-06-10 00:59:57 +00:00
function.rs Format Function definitions (#4951) 2023-06-08 16:07:33 +00:00
hashable.rs Create a rust_python_ast crate (#3370) 2023-03-07 15:18:40 +00:00
helpers.rs Remove continuations when deleting statements (#5198) 2023-06-19 22:04:28 -04:00
identifier.rs Remove identifier lexing in favor of parser ranges (#5195) 2023-06-20 12:07:29 -04:00
imports.rs Run rustfmt on nightly to clean up erroneous comments (#5106) 2023-06-15 00:19:05 +00:00
lib.rs Always use identifier ranges to store bindings (#5110) 2023-06-15 18:43:19 +00:00
node.rs Fix ArgWithDefault comments handling (#5204) 2023-06-20 20:48:07 +00:00
prelude.rs Improve ruff_parse_simple to find UTF-8 violations (#5008) 2023-06-12 12:10:23 -04:00
relocate.rs Refactor range from Attributed to Nodes (#4422) 2023-05-16 06:36:32 +00:00
statement_visitor.rs Upgrade RustPython (#5192) 2023-06-19 21:09:53 +00:00
str.rs Basic string formatting 2023-06-23 09:46:05 +02:00
token_kind.rs Bring pycodestyle rules into full compatibility (on SciPy) (#4472) 2023-05-17 16:51:55 +00:00
types.rs Replace parents statement stack with a Nodes abstraction (#4233) 2023-05-06 16:12:41 +00:00
typing.rs Upgrade RustPython (#4747) 2023-05-31 08:26:35 +00:00
visitor.rs Fix annotation and format spec visitors (#5324) 2023-06-23 03:55:42 +00:00
whitespace.rs Move Python whitespace utilities into new ruff_python_whitespace crate (#4993) 2023-06-10 00:59:57 +00:00