Ville Skyttä 2023-02-05 22:04:36 +02:00 committed by GitHub
parent 452b5a4b79
commit f03c8fff14
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -4,7 +4,7 @@ use regex::Regex;
static ALLOWLIST_REGEX: Lazy<Regex> = Lazy::new(|| { static ALLOWLIST_REGEX: Lazy<Regex> = Lazy::new(|| {
Regex::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() ).unwrap()
}); });
static BRACKET_REGEX: Lazy<Regex> = Lazy::new(|| Regex::new(r"^[()\[\]{}\s]+$").unwrap()); static BRACKET_REGEX: Lazy<Regex> = Lazy::new(|| Regex::new(r"^[()\[\]{}\s]+$").unwrap());
@ -128,6 +128,11 @@ mod tests {
"# Issue #999: This is not code", "# 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. // TODO(charlie): This should be `true` under aggressive mode.
assert!(!comment_contains_code("#},", &[])); assert!(!comment_contains_code("#},", &[]));