Skip to content

Commit

Permalink
Track casing of r-string prefixes in the tokenizer and AST (#10314)
Browse files Browse the repository at this point in the history
Co-authored-by: Micha Reiser <[email protected]>
  • Loading branch information
AlexWaygood and MichaReiser authored Mar 18, 2024
1 parent 31db1b6 commit 162d2eb
Show file tree
Hide file tree
Showing 105 changed files with 1,066 additions and 501 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ pub(crate) fn avoidable_escaped_quote(
let mut diagnostic = Diagnostic::new(AvoidableEscapedQuote, tok_range);
let fixed_contents = format!(
"{prefix}{quote}{value}{quote}",
prefix = kind.prefix_str(),
prefix = kind.prefix(),
quote = quotes_settings.inline_quotes.opposite().as_char(),
value = unescape_string(
string_contents,
Expand Down Expand Up @@ -322,7 +322,7 @@ pub(crate) fn unnecessary_escaped_quote(
let mut diagnostic = Diagnostic::new(UnnecessaryEscapedQuote, tok_range);
let fixed_contents = format!(
"{prefix}{quote}{value}{quote}",
prefix = kind.prefix_str(),
prefix = kind.prefix(),
quote = leading.as_char(),
value = unescape_string(string_contents, leading.opposite().as_char())
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,9 +221,9 @@ fn check_os_environ_subscript(checker: &mut Checker, expr: &Expr) {
value: capital_env_var.into_boxed_str(),
flags: StringLiteralFlags::default().with_prefix({
if env_var.is_unicode() {
StringLiteralPrefix::UString
StringLiteralPrefix::Unicode
} else {
StringLiteralPrefix::None
StringLiteralPrefix::Empty
}
}),
..ast::StringLiteral::default()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ impl AlwaysFixableViolation for UnicodeKindPrefix {

/// UP025
pub(crate) fn unicode_kind_prefix(checker: &mut Checker, string: &StringLiteral) {
if string.flags.is_u_string() {
if string.flags.prefix().is_unicode() {
let mut diagnostic = Diagnostic::new(UnicodeKindPrefix, string.range);
diagnostic.set_fix(Fix::safe_edit(Edit::range_deletion(TextRange::at(
string.start(),
Expand Down
Loading

0 comments on commit 162d2eb

Please sign in to comment.