mirror of https://github.com/astral-sh/ruff
Move pygrep-hooks violations (#2539)
This commit is contained in:
parent
47e0b2521a
commit
d985473f4f
|
|
@ -367,10 +367,10 @@ ruff_macros::define_rule_mapping!(
|
|||
DTZ011 => rules::flake8_datetimez::rules::CallDateToday,
|
||||
DTZ012 => rules::flake8_datetimez::rules::CallDateFromtimestamp,
|
||||
// pygrep-hooks
|
||||
PGH001 => violations::NoEval,
|
||||
PGH002 => violations::DeprecatedLogWarn,
|
||||
PGH003 => violations::BlanketTypeIgnore,
|
||||
PGH004 => violations::BlanketNOQA,
|
||||
PGH001 => rules::pygrep_hooks::rules::NoEval,
|
||||
PGH002 => rules::pygrep_hooks::rules::DeprecatedLogWarn,
|
||||
PGH003 => rules::pygrep_hooks::rules::BlanketTypeIgnore,
|
||||
PGH004 => rules::pygrep_hooks::rules::BlanketNOQA,
|
||||
// pandas-vet
|
||||
PD002 => rules::pandas_vet::rules::UseOfInplaceArgument,
|
||||
PD003 => rules::pandas_vet::rules::UseOfDotIsNull,
|
||||
|
|
|
|||
|
|
@ -1,10 +1,22 @@
|
|||
use crate::define_violation;
|
||||
use crate::violation::Violation;
|
||||
use once_cell::sync::Lazy;
|
||||
use regex::Regex;
|
||||
use ruff_macros::derive_message_formats;
|
||||
use rustpython_ast::Location;
|
||||
|
||||
use crate::ast::types::Range;
|
||||
use crate::registry::Diagnostic;
|
||||
use crate::violations;
|
||||
|
||||
define_violation!(
|
||||
pub struct BlanketNOQA;
|
||||
);
|
||||
impl Violation for BlanketNOQA {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
format!("Use specific rule codes when using `noqa`")
|
||||
}
|
||||
}
|
||||
|
||||
static BLANKET_NOQA_REGEX: Lazy<Regex> =
|
||||
Lazy::new(|| Regex::new(r"(?i)# noqa($|\s|:[^ ])").unwrap());
|
||||
|
|
@ -13,7 +25,7 @@ static BLANKET_NOQA_REGEX: Lazy<Regex> =
|
|||
pub fn blanket_noqa(lineno: usize, line: &str) -> Option<Diagnostic> {
|
||||
BLANKET_NOQA_REGEX.find(line).map(|m| {
|
||||
Diagnostic::new(
|
||||
violations::BlanketNOQA,
|
||||
BlanketNOQA,
|
||||
Range::new(
|
||||
Location::new(lineno + 1, m.start()),
|
||||
Location::new(lineno + 1, m.end()),
|
||||
|
|
|
|||
|
|
@ -1,10 +1,22 @@
|
|||
use crate::define_violation;
|
||||
use crate::violation::Violation;
|
||||
use once_cell::sync::Lazy;
|
||||
use regex::Regex;
|
||||
use ruff_macros::derive_message_formats;
|
||||
use rustpython_ast::Location;
|
||||
|
||||
use crate::ast::types::Range;
|
||||
use crate::registry::Diagnostic;
|
||||
use crate::violations;
|
||||
|
||||
define_violation!(
|
||||
pub struct BlanketTypeIgnore;
|
||||
);
|
||||
impl Violation for BlanketTypeIgnore {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
format!("Use specific rule codes when ignoring type issues")
|
||||
}
|
||||
}
|
||||
|
||||
static BLANKET_TYPE_IGNORE_REGEX: Lazy<Regex> =
|
||||
Lazy::new(|| Regex::new(r"# type:? *ignore($|\s)").unwrap());
|
||||
|
|
@ -13,7 +25,7 @@ static BLANKET_TYPE_IGNORE_REGEX: Lazy<Regex> =
|
|||
pub fn blanket_type_ignore(lineno: usize, line: &str) -> Option<Diagnostic> {
|
||||
BLANKET_TYPE_IGNORE_REGEX.find(line).map(|m| {
|
||||
Diagnostic::new(
|
||||
violations::BlanketTypeIgnore,
|
||||
BlanketTypeIgnore,
|
||||
Range::new(
|
||||
Location::new(lineno + 1, m.start()),
|
||||
Location::new(lineno + 1, m.end()),
|
||||
|
|
|
|||
|
|
@ -1,9 +1,21 @@
|
|||
use crate::define_violation;
|
||||
use crate::violation::Violation;
|
||||
use ruff_macros::derive_message_formats;
|
||||
use rustpython_ast::Expr;
|
||||
|
||||
use crate::ast::types::Range;
|
||||
use crate::checkers::ast::Checker;
|
||||
use crate::registry::Diagnostic;
|
||||
use crate::violations;
|
||||
|
||||
define_violation!(
|
||||
pub struct DeprecatedLogWarn;
|
||||
);
|
||||
impl Violation for DeprecatedLogWarn {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
format!("`warn` is deprecated in favor of `warning`")
|
||||
}
|
||||
}
|
||||
|
||||
/// PGH002 - deprecated use of logging.warn
|
||||
pub fn deprecated_log_warn(checker: &mut Checker, func: &Expr) {
|
||||
|
|
@ -11,7 +23,7 @@ pub fn deprecated_log_warn(checker: &mut Checker, func: &Expr) {
|
|||
call_path.as_slice() == ["logging", "warn"]
|
||||
}) {
|
||||
checker.diagnostics.push(Diagnostic::new(
|
||||
violations::DeprecatedLogWarn,
|
||||
DeprecatedLogWarn,
|
||||
Range::from_located(func),
|
||||
));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
pub use blanket_noqa::blanket_noqa;
|
||||
pub use blanket_type_ignore::blanket_type_ignore;
|
||||
pub use deprecated_log_warn::deprecated_log_warn;
|
||||
pub use no_eval::no_eval;
|
||||
pub use blanket_noqa::{blanket_noqa, BlanketNOQA};
|
||||
pub use blanket_type_ignore::{blanket_type_ignore, BlanketTypeIgnore};
|
||||
pub use deprecated_log_warn::{deprecated_log_warn, DeprecatedLogWarn};
|
||||
pub use no_eval::{no_eval, NoEval};
|
||||
|
||||
mod blanket_noqa;
|
||||
mod blanket_type_ignore;
|
||||
|
|
|
|||
|
|
@ -1,10 +1,21 @@
|
|||
use crate::define_violation;
|
||||
use crate::violation::Violation;
|
||||
use ruff_macros::derive_message_formats;
|
||||
use rustpython_ast::{Expr, ExprKind};
|
||||
|
||||
use crate::ast::types::Range;
|
||||
use crate::checkers::ast::Checker;
|
||||
use crate::registry::Diagnostic;
|
||||
use crate::violations;
|
||||
|
||||
define_violation!(
|
||||
pub struct NoEval;
|
||||
);
|
||||
impl Violation for NoEval {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
format!("No builtin `eval()` allowed")
|
||||
}
|
||||
}
|
||||
/// PGH001 - no eval
|
||||
pub fn no_eval(checker: &mut Checker, func: &Expr) {
|
||||
let ExprKind::Name { id, .. } = &func.node else {
|
||||
|
|
@ -16,8 +27,7 @@ pub fn no_eval(checker: &mut Checker, func: &Expr) {
|
|||
if !checker.is_builtin("eval") {
|
||||
return;
|
||||
}
|
||||
checker.diagnostics.push(Diagnostic::new(
|
||||
violations::NoEval,
|
||||
Range::from_located(func),
|
||||
));
|
||||
checker
|
||||
.diagnostics
|
||||
.push(Diagnostic::new(NoEval, Range::from_located(func)));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -52,48 +52,6 @@ impl AlwaysAutofixableViolation for PPrintFound {
|
|||
}
|
||||
}
|
||||
|
||||
// pygrep-hooks
|
||||
|
||||
define_violation!(
|
||||
pub struct NoEval;
|
||||
);
|
||||
impl Violation for NoEval {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
format!("No builtin `eval()` allowed")
|
||||
}
|
||||
}
|
||||
|
||||
define_violation!(
|
||||
pub struct DeprecatedLogWarn;
|
||||
);
|
||||
impl Violation for DeprecatedLogWarn {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
format!("`warn` is deprecated in favor of `warning`")
|
||||
}
|
||||
}
|
||||
|
||||
define_violation!(
|
||||
pub struct BlanketTypeIgnore;
|
||||
);
|
||||
impl Violation for BlanketTypeIgnore {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
format!("Use specific rule codes when ignoring type issues")
|
||||
}
|
||||
}
|
||||
|
||||
define_violation!(
|
||||
pub struct BlanketNOQA;
|
||||
);
|
||||
impl Violation for BlanketNOQA {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
format!("Use specific rule codes when using `noqa`")
|
||||
}
|
||||
}
|
||||
|
||||
// flake8-errmsg
|
||||
|
||||
define_violation!(
|
||||
|
|
|
|||
Loading…
Reference in New Issue