Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Track casing of r-string prefixes in the tokenizer and AST #10314

Merged
merged 11 commits into from
Mar 18, 2024
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
Loading