Tidy up some pygrep-hooks rules (#3942)

This commit is contained in:
Charlie Marsh 2023-04-11 23:35:15 -04:00 committed by GitHub
parent 523515f936
commit 8ce227047d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 14 additions and 13 deletions

View file

@ -80,9 +80,7 @@ pub fn check_physical_lines(
} }
if enforce_blanket_noqa { if enforce_blanket_noqa {
if let Some(diagnostic) = blanket_noqa(index, line) { blanket_noqa(&mut diagnostics, index, line);
diagnostics.push(diagnostic);
}
} }
if enforce_shebang_missing if enforce_shebang_missing

View file

@ -19,15 +19,17 @@ impl Violation for BlanketNOQA {
static BLANKET_NOQA_REGEX: Lazy<Regex> = static BLANKET_NOQA_REGEX: Lazy<Regex> =
Lazy::new(|| Regex::new(r"(?i)# noqa($|\s|:[^ ])").unwrap()); Lazy::new(|| Regex::new(r"(?i)# noqa($|\s|:[^ ])").unwrap());
/// PGH004 - use of blanket noqa comments /// PGH004
pub fn blanket_noqa(lineno: usize, line: &str) -> Option<Diagnostic> { pub fn blanket_noqa(diagnostics: &mut Vec<Diagnostic>, lineno: usize, line: &str) {
BLANKET_NOQA_REGEX.find(line).map(|m| { if let Some(match_) = BLANKET_NOQA_REGEX.find(line) {
Diagnostic::new( let start = line[..match_.start()].chars().count();
let end = start + line[match_.start()..match_.end()].chars().count();
diagnostics.push(Diagnostic::new(
BlanketNOQA, BlanketNOQA,
Range::new( Range::new(
Location::new(lineno + 1, m.start()), Location::new(lineno + 1, start),
Location::new(lineno + 1, m.end()), Location::new(lineno + 1, end),
), ),
) ));
}) }
} }

View file

@ -16,7 +16,7 @@ impl Violation for DeprecatedLogWarn {
} }
} }
/// PGH002 - deprecated use of logging.warn /// PGH002
pub fn deprecated_log_warn(checker: &mut Checker, func: &Expr) { pub fn deprecated_log_warn(checker: &mut Checker, func: &Expr) {
if checker if checker
.ctx .ctx

View file

@ -15,7 +15,8 @@ impl Violation for Eval {
format!("No builtin `eval()` allowed") format!("No builtin `eval()` allowed")
} }
} }
/// PGH001 - no eval
/// PGH001
pub fn no_eval(checker: &mut Checker, func: &Expr) { pub fn no_eval(checker: &mut Checker, func: &Expr) {
let ExprKind::Name { id, .. } = &func.node else { let ExprKind::Name { id, .. } = &func.node else {
return; return;