From d30dc29ecebf74365e97827f77ae459b5963f290 Mon Sep 17 00:00:00 2001 From: Dhruv Manilawala Date: Sun, 10 Mar 2024 10:05:46 +0530 Subject: [PATCH] Ignore string if it is inside a f-string --- .../rules/flake8_quotes/rules/check_string_quotes.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/crates/ruff_linter/src/rules/flake8_quotes/rules/check_string_quotes.rs b/crates/ruff_linter/src/rules/flake8_quotes/rules/check_string_quotes.rs index e14ec91fac8f4..066d5ab13522a 100644 --- a/crates/ruff_linter/src/rules/flake8_quotes/rules/check_string_quotes.rs +++ b/crates/ruff_linter/src/rules/flake8_quotes/rules/check_string_quotes.rs @@ -358,6 +358,16 @@ fn strings(checker: &mut Checker, sequence: &[TextRange]) { /// Generate `flake8-quote` diagnostics from a token stream. pub(crate) fn check_string_quotes(checker: &mut Checker, string_like: StringLike) { + // If the string is part of a f-string, ignore it. + if checker + .indexer() + .fstring_ranges() + .outermost(string_like.start()) + .is_some_and(|outer_range| outer_range != string_like.range()) + { + return; + } + let ranges: Vec = match string_like { StringLike::String(node) => node.value.iter().map(Ranged::range).collect(), StringLike::Bytes(node) => node.value.iter().map(Ranged::range).collect(),