From 98125cc09c1069dc68f866826f40db940e1447c0 Mon Sep 17 00:00:00 2001 From: Aldo Mateli Date: Sun, 20 Apr 2025 19:56:18 +0100 Subject: [PATCH 1/2] Fix false positives with jira issues/gitlab mr references --- crates/ruff_linter/src/rules/eradicate/detection.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/crates/ruff_linter/src/rules/eradicate/detection.rs b/crates/ruff_linter/src/rules/eradicate/detection.rs index a5beac11af..0066a52ec2 100644 --- a/crates/ruff_linter/src/rules/eradicate/detection.rs +++ b/crates/ruff_linter/src/rules/eradicate/detection.rs @@ -55,7 +55,10 @@ static ALLOWLIST_REGEX: LazyLock = LazyLock::new(|| { .unwrap() }); -static HASH_NUMBER: LazyLock = LazyLock::new(|| Regex::new(r"#\d").unwrap()); +// Regex that matches references to Jira issues, github/gitlab issues (#123), gitlab merge requests (!123) +// and others that follow this format. +static ISSUE_REFERENCE: LazyLock = + LazyLock::new(|| Regex::new(r"([A-Z][A-Z]+-|#|!)\d+").unwrap()); static POSITIVE_CASES: LazyLock = LazyLock::new(|| { RegexSet::new([ @@ -102,8 +105,8 @@ pub(crate) fn comment_contains_code(line: &str, task_tags: &[String]) -> bool { return false; } - // Ignore non-comment related hashes (e.g., "# Issue #999"). - if HASH_NUMBER.is_match(line) { + // Ignore lines with references to issues. + if ISSUE_REFERENCE.is_match(line) { return false; } @@ -155,6 +158,8 @@ mod tests { "# Issue #999: This is not code", &[] )); + assert!(!comment_contains_code("# See: PROJ-999", &[])); + assert!(!comment_contains_code("# See !999: This is not code", &[])); assert!(!comment_contains_code("# mypy: allow-untyped-calls", &[])); assert!(!comment_contains_code( "# SPDX-License-Identifier: MIT", From 678ff6a165c6c957efd6d123fa9ff8cfce7931dc Mon Sep 17 00:00:00 2001 From: Aldo Mateli Date: Sun, 20 Apr 2025 20:09:48 +0100 Subject: [PATCH 2/2] wip --- crates/ruff_linter/src/rules/eradicate/detection.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/ruff_linter/src/rules/eradicate/detection.rs b/crates/ruff_linter/src/rules/eradicate/detection.rs index 0066a52ec2..e1b56827e1 100644 --- a/crates/ruff_linter/src/rules/eradicate/detection.rs +++ b/crates/ruff_linter/src/rules/eradicate/detection.rs @@ -105,7 +105,7 @@ pub(crate) fn comment_contains_code(line: &str, task_tags: &[String]) -> bool { return false; } - // Ignore lines with references to issues. + // Ignore lines with references to github/gitlab/jira (#999, PROJ-123, !54). if ISSUE_REFERENCE.is_match(line) { return false; }