mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-29 21:34:57 +00:00
Tidy up some pygrep-hooks
rules (#3942)
This commit is contained in:
parent
523515f936
commit
8ce227047d
4 changed files with 14 additions and 13 deletions
|
@ -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
|
||||
|
|
|
@ -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),
|
||||
),
|
||||
)
|
||||
})
|
||||
));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue