Make # noqa detection case-insensitive (#728)

This commit is contained in:
Charlie Marsh
2022-11-13 16:09:44 -05:00
committed by GitHub
parent d2d84cf5bf
commit 8a97a76038

View File

@@ -10,7 +10,7 @@ use regex::Regex;
use crate::checks::{Check, CheckCode};
static NO_QA_REGEX: Lazy<Regex> = Lazy::new(|| {
Regex::new(r"(?P<noqa>\s*# noqa(?::\s?(?P<codes>([A-Z]+[0-9]+(?:[,\s]+)?)+))?)")
Regex::new(r"(?P<noqa>\s*(?i:# noqa)(?::\s?(?P<codes>([A-Z]+[0-9]+(?:[,\s]+)?)+))?)")
.expect("Invalid regex")
});
static SPLIT_COMMA_REGEX: Lazy<Regex> = Lazy::new(|| Regex::new(r"[,\s]").expect("Invalid regex"));
@@ -118,7 +118,21 @@ mod tests {
use crate::ast::types::Range;
use crate::checks::{Check, CheckKind};
use crate::noqa::add_noqa_inner;
use crate::noqa::{add_noqa_inner, NO_QA_REGEX};
#[test]
fn regex() {
assert!(NO_QA_REGEX.is_match("# noqa"));
assert!(NO_QA_REGEX.is_match("# NoQA"));
assert!(NO_QA_REGEX.is_match("# noqa: F401"));
assert!(NO_QA_REGEX.is_match("# NoQA: F401"));
assert!(NO_QA_REGEX.is_match("# noqa: F401, E501"));
assert!(NO_QA_REGEX.is_match("# noqa:F401"));
assert!(NO_QA_REGEX.is_match("# NoQA:F401"));
assert!(NO_QA_REGEX.is_match("# noqa:F401, E501"));
}
#[test]
fn modification() -> Result<()> {