From fdc2721493fdd796611af55b696a9de5d0898003 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ville=20Skytt=C3=A4?= Date: Sun, 5 Feb 2023 21:50:41 +0200 Subject: [PATCH] fix(commented-out-code): `mypy` and `SPDX-License-Identifier` false positives https://mypy.readthedocs.io/en/stable/inline_config.html#configuration-comment-format https://spdx.github.io/spdx-spec/v2.3/using-SPDX-short-identifiers-in-source-files/#e2-format-for-spdx-license-identifier --- src/rules/eradicate/detection.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/rules/eradicate/detection.rs b/src/rules/eradicate/detection.rs index 4080e23f99a6d..6caee16e7dea0 100644 --- a/src/rules/eradicate/detection.rs +++ b/src/rules/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*\[.*?])?))" + 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*\[.*?])?)|mypy:|SPDX-License-Identifier:)" ).unwrap() }); static BRACKET_REGEX: Lazy = Lazy::new(|| Regex::new(r"^[()\[\]{}\s]+$").unwrap()); @@ -128,6 +128,11 @@ mod tests { "# Issue #999: This is not code", &[] )); + assert!(!comment_contains_code("# mypy: allow-untyped-calls", &[])); + assert!(!comment_contains_code( + "# SPDX-License-Identifier: MIT", + &[] + )); // TODO(charlie): This should be `true` under aggressive mode. assert!(!comment_contains_code("#},", &[]));