From a0a6327faecdb9f0fed8c69f4c84947677a8577d Mon Sep 17 00:00:00 2001 From: Charlie Marsh Date: Thu, 8 Dec 2022 23:10:36 -0500 Subject: [PATCH] Only allowlist noqa et al at the start of a comment (#1157) --- resources/test/fixtures/eradicate/ERA001.py | 4 +++- src/eradicate/detection.rs | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/resources/test/fixtures/eradicate/ERA001.py b/resources/test/fixtures/eradicate/ERA001.py index e4ee9bfad7..4d79010d35 100644 --- a/resources/test/fixtures/eradicate/ERA001.py +++ b/resources/test/fixtures/eradicate/ERA001.py @@ -5,9 +5,11 @@ a = 4 #foo(1, 2, 3) def foo(x, y, z): - contentet = 1 # print('hello') + content = 1 # print('hello') print(x, y, z) # This is a real comment. #return True return False + +#import os # noqa: ERA001 diff --git a/src/eradicate/detection.rs b/src/eradicate/detection.rs index 000cec2726..ad1b2c2bc9 100644 --- a/src/eradicate/detection.rs +++ b/src/eradicate/detection.rs @@ -4,7 +4,7 @@ use regex::Regex; static ALLOWLIST_REGEX: Lazy = Lazy::new(|| { Regex::new( - r"(?i)pylint|pyright|noqa|nosec|type:\s*ignore|fmt:\s*(on|off)|isort:\s*(on|off|skip|skip_file|split|dont-add-imports(:\s*\[.*?])?)|TODO|FIXME|XXX" + r"^(?i)(?:pylint|pyright|noqa|nosec|type:\s*ignore|fmt:\s*(on|off)|isort:\s*(on|off|skip|skip_file|split|dont-add-imports(:\s*\[.*?])?)|TODO|FIXME|XXX)" ).unwrap() }); static BRACKET_REGEX: Lazy = Lazy::new(|| Regex::new(r"^[()\[\]{}\s]+$").unwrap());