Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tidy up some pygrep-hooks rules #3942

Merged
merged 1 commit into from
Apr 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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