diff --git a/src/registry.rs b/src/registry.rs index 4240203390..fc42181ce7 100644 --- a/src/registry.rs +++ b/src/registry.rs @@ -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, diff --git a/src/rules/pygrep_hooks/rules/blanket_noqa.rs b/src/rules/pygrep_hooks/rules/blanket_noqa.rs index f145af6121..6c9bc98527 100644 --- a/src/rules/pygrep_hooks/rules/blanket_noqa.rs +++ b/src/rules/pygrep_hooks/rules/blanket_noqa.rs @@ -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 = Lazy::new(|| Regex::new(r"(?i)# noqa($|\s|:[^ ])").unwrap()); @@ -13,7 +25,7 @@ static BLANKET_NOQA_REGEX: Lazy = pub fn blanket_noqa(lineno: usize, line: &str) -> Option { 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()), diff --git a/src/rules/pygrep_hooks/rules/blanket_type_ignore.rs b/src/rules/pygrep_hooks/rules/blanket_type_ignore.rs index 06c1623de4..c8dbec0a48 100644 --- a/src/rules/pygrep_hooks/rules/blanket_type_ignore.rs +++ b/src/rules/pygrep_hooks/rules/blanket_type_ignore.rs @@ -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 = Lazy::new(|| Regex::new(r"# type:? *ignore($|\s)").unwrap()); @@ -13,7 +25,7 @@ static BLANKET_TYPE_IGNORE_REGEX: Lazy = pub fn blanket_type_ignore(lineno: usize, line: &str) -> Option { 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()), diff --git a/src/rules/pygrep_hooks/rules/deprecated_log_warn.rs b/src/rules/pygrep_hooks/rules/deprecated_log_warn.rs index cd41024029..f651fe4b5f 100644 --- a/src/rules/pygrep_hooks/rules/deprecated_log_warn.rs +++ b/src/rules/pygrep_hooks/rules/deprecated_log_warn.rs @@ -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), )); } diff --git a/src/rules/pygrep_hooks/rules/mod.rs b/src/rules/pygrep_hooks/rules/mod.rs index 744c2cbe91..d1cfb8d298 100644 --- a/src/rules/pygrep_hooks/rules/mod.rs +++ b/src/rules/pygrep_hooks/rules/mod.rs @@ -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; diff --git a/src/rules/pygrep_hooks/rules/no_eval.rs b/src/rules/pygrep_hooks/rules/no_eval.rs index 4b010caf96..26f43353d2 100644 --- a/src/rules/pygrep_hooks/rules/no_eval.rs +++ b/src/rules/pygrep_hooks/rules/no_eval.rs @@ -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))); } diff --git a/src/violations.rs b/src/violations.rs index 1f4dc41ce4..3d307400de 100644 --- a/src/violations.rs +++ b/src/violations.rs @@ -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!(