mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-04 02:39:12 +00:00
Preserve quote style in generated code (#15726)
## Summary This is a first step toward fixing #7799 by using the quoting style stored in the `flags` field on `ast::StringLiteral`s to select a quoting style. This PR does not include support for f-strings or byte strings. Several rules also needed small updates to pass along existing quoting styles instead of using `StringLiteralFlags::default()`. The remaining snapshot changes are intentional and should preserve the quotes from the input strings. ## Test Plan Existing tests with some accepted updates, plus a few new RUF055 tests for raw strings. --------- Co-authored-by: Alex Waygood <alex.waygood@gmail.com>
This commit is contained in:
parent
e994970538
commit
9bf138c45a
24 changed files with 550 additions and 343 deletions
|
@ -4,12 +4,12 @@ use {
|
|||
regex::Regex,
|
||||
};
|
||||
|
||||
use ruff_python_ast::visitor::transformer;
|
||||
use ruff_python_ast::visitor::transformer::Transformer;
|
||||
use ruff_python_ast::{
|
||||
self as ast, BytesLiteralFlags, Expr, FStringElement, FStringFlags, FStringLiteralElement,
|
||||
FStringPart, Stmt, StringFlags, StringLiteralFlags,
|
||||
FStringPart, Stmt, StringFlags,
|
||||
};
|
||||
use ruff_python_ast::{visitor::transformer, StringLiteralFlags};
|
||||
use ruff_text_size::{Ranged, TextRange};
|
||||
|
||||
/// A struct to normalize AST nodes for the purpose of comparing formatted representations for
|
||||
|
@ -81,7 +81,7 @@ impl Transformer for Normalizer {
|
|||
string.value = ast::StringLiteralValue::single(ast::StringLiteral {
|
||||
value: string.value.to_str().to_string().into_boxed_str(),
|
||||
range: string.range,
|
||||
flags: StringLiteralFlags::default(),
|
||||
flags: StringLiteralFlags::empty(),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue