mirror of https://github.com/astral-sh/ruff
Merge 678ff6a165 into b0bc990cbf
This commit is contained in:
commit
7f1d9bd506
|
|
@ -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",
|
||||
|
|
|
|||
Loading…
Reference in New Issue