This commit is contained in:
Aldo Mateli 2025-12-16 17:02:47 -05:00 committed by GitHub
commit 7f1d9bd506
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 8 additions and 3 deletions

View File

@ -56,7 +56,10 @@ static ALLOWLIST_REGEX: LazyLock<Regex> = LazyLock::new(|| {
.unwrap()
});
static HASH_NUMBER: LazyLock<Regex> = 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<Regex> =
LazyLock::new(|| Regex::new(r"([A-Z][A-Z]+-|#|!)\d+").unwrap());
static POSITIVE_CASES: LazyLock<RegexSet> = LazyLock::new(|| {
RegexSet::new([
@ -103,8 +106,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 github/gitlab/jira (#999, PROJ-123, !54).
if ISSUE_REFERENCE.is_match(line) {
return false;
}
@ -156,6 +159,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",