Skip to content

Commit

Permalink
Respect Q00* ignores in flake8-quotes rules
Browse files Browse the repository at this point in the history
  • Loading branch information
charliermarsh committed Apr 2, 2024
1 parent 67f0f61 commit a046e43
Showing 1 changed file with 18 additions and 3 deletions.
Expand Up @@ -5,6 +5,7 @@ use ruff_source_file::Locator;
use ruff_text_size::{Ranged, TextRange};

use crate::checkers::ast::Checker;
use crate::registry::Rule;

use super::super::settings::Quote;

Expand Down Expand Up @@ -334,6 +335,11 @@ fn strings(checker: &mut Checker, sequence: &[TextRange]) {

for (range, trivia) in sequence.iter().zip(trivia) {
if trivia.is_multiline {
// If multiline strings aren't enforced, ignore it.
if !checker.enabled(Rule::BadQuotesMultilineString) {
continue;
}

// If our string is or contains a known good string, ignore it.
if trivia
.raw_text
Expand Down Expand Up @@ -375,6 +381,11 @@ fn strings(checker: &mut Checker, sequence: &[TextRange]) {
// If we're not using the preferred type, only allow use to avoid escapes.
&& !relax_quote
{
// If inline strings aren't enforced, ignore it.
if !checker.enabled(Rule::BadQuotesInlineString) {
continue;
}

if trivia.has_empty_text()
&& text_ends_at_quote(locator, *range, quotes_settings.inline_quotes)
{
Expand Down Expand Up @@ -455,10 +466,14 @@ pub(crate) fn check_string_quotes(checker: &mut Checker, string_like: StringLike
};

if checker.semantic().in_docstring() {
for range in ranges {
docstring(checker, range);
if checker.enabled(Rule::BadQuotesDocstring) {
for range in ranges {
docstring(checker, range);
}
}
} else {
strings(checker, &ranges);
if checker.any_enabled(&[Rule::BadQuotesInlineString, Rule::BadQuotesMultilineString]) {
strings(checker, &ranges);
}
}
}

0 comments on commit a046e43

Please sign in to comment.