Skip to content

Commit

Permalink
Tidy up some pygrep-hooks rules (#3942)
Browse files Browse the repository at this point in the history
  • Loading branch information
charliermarsh authored Apr 12, 2023
1 parent 523515f commit 8ce2270
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 13 deletions.
4 changes: 1 addition & 3 deletions crates/ruff/src/checkers/physical_lines.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,7 @@ pub fn check_physical_lines(
}

if enforce_blanket_noqa {
if let Some(diagnostic) = blanket_noqa(index, line) {
diagnostics.push(diagnostic);
}
blanket_noqa(&mut diagnostics, index, line);
}

if enforce_shebang_missing
Expand Down
18 changes: 10 additions & 8 deletions crates/ruff/src/rules/pygrep_hooks/rules/blanket_noqa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,17 @@ impl Violation for BlanketNOQA {
static BLANKET_NOQA_REGEX: Lazy<Regex> =
Lazy::new(|| Regex::new(r"(?i)# noqa($|\s|:[^ ])").unwrap());

/// PGH004 - use of blanket noqa comments
pub fn blanket_noqa(lineno: usize, line: &str) -> Option<Diagnostic> {
BLANKET_NOQA_REGEX.find(line).map(|m| {
Diagnostic::new(
/// PGH004
pub fn blanket_noqa(diagnostics: &mut Vec<Diagnostic>, lineno: usize, line: &str) {
if let Some(match_) = BLANKET_NOQA_REGEX.find(line) {
let start = line[..match_.start()].chars().count();
let end = start + line[match_.start()..match_.end()].chars().count();
diagnostics.push(Diagnostic::new(
BlanketNOQA,
Range::new(
Location::new(lineno + 1, m.start()),
Location::new(lineno + 1, m.end()),
Location::new(lineno + 1, start),
Location::new(lineno + 1, end),
),
)
})
));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
if checker
.ctx
Expand Down
3 changes: 2 additions & 1 deletion crates/ruff/src/rules/pygrep_hooks/rules/no_eval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ impl Violation for Eval {
format!("No builtin `eval()` allowed")
}
}
/// PGH001 - no eval

/// PGH001
pub fn no_eval(checker: &mut Checker, func: &Expr) {
let ExprKind::Name { id, .. } = &func.node else {
return;
Expand Down

0 comments on commit 8ce2270

Please sign in to comment.