Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
InSyncWithFoo committed Dec 5, 2024
1 parent 7bf1ff4 commit d8cda1d
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions crates/ruff_linter/src/rules/ruff/rules/dotless_with_suffix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ impl AlwaysFixableViolation for DotlessWithSuffix {
pub(crate) fn dotless_with_suffix(checker: &mut Checker, call: &ExprCall) {
let (func, arguments) = (&call.func, &call.arguments);

if is_path_with_suffix_call(checker.semantic(), func) {
if !is_path_with_suffix_call(checker.semantic(), func) {
return;
}

Expand Down Expand Up @@ -85,7 +85,7 @@ fn single_string_literal_argument(arguments: &Arguments) -> Option<&ExprStringLi
}

match arguments.find_argument("suffix", 0)? {
Expr::StringLiteral(string) => Some(&string),
Expr::StringLiteral(string) => Some(string),
_ => None,
}
}
Expand All @@ -95,12 +95,14 @@ fn add_leading_dot_fix(string: &ExprStringLiteral) -> Option<Fix> {

// |r"foo"
let before_prefix = first_part.range.start();

// r|"foo"
let prefix_length = first_part.flags.prefix().as_str().len();
let after_prefix = before_prefix.checked_add((prefix_length as u32).into())?;
let after_prefix = before_prefix.checked_add(u32::try_from(prefix_length).ok()?.into())?;

// r"|foo"
let quote_length = first_part.flags.is_triple_quoted().then(|| 3).unwrap_or(1);
let after_leading_quote = after_prefix.checked_add((quote_length as u32).into())?;
let quote_length = first_part.flags.quote_str().len();
let after_leading_quote = after_prefix.checked_add(u32::try_from(quote_length).ok()?.into())?;

let edit = Edit::insertion(".".to_string(), after_leading_quote);

Expand Down

0 comments on commit d8cda1d

Please sign in to comment.