diff --git a/crates/ruff/resources/test/fixtures/pygrep_hooks/PGH002_0.py b/crates/ruff/resources/test/fixtures/pygrep_hooks/PGH002_0.py deleted file mode 100644 index 523b65bf41c56..0000000000000 --- a/crates/ruff/resources/test/fixtures/pygrep_hooks/PGH002_0.py +++ /dev/null @@ -1,7 +0,0 @@ -import logging -import warnings -from warnings import warn - -warnings.warn("this is ok") -warn("by itself is also ok") -logging.warning("this is fine") diff --git a/crates/ruff/resources/test/fixtures/pygrep_hooks/PGH002_1.py b/crates/ruff/resources/test/fixtures/pygrep_hooks/PGH002_1.py deleted file mode 100644 index c2866d0969fd9..0000000000000 --- a/crates/ruff/resources/test/fixtures/pygrep_hooks/PGH002_1.py +++ /dev/null @@ -1,5 +0,0 @@ -import logging -from logging import warn - -logging.warn("this is not ok") -warn("not ok") diff --git a/crates/ruff/src/checkers/ast/analyze/expression.rs b/crates/ruff/src/checkers/ast/analyze/expression.rs index 406361eaba0cd..508534d4b1c88 100644 --- a/crates/ruff/src/checkers/ast/analyze/expression.rs +++ b/crates/ruff/src/checkers/ast/analyze/expression.rs @@ -736,9 +736,6 @@ pub(crate) fn expression(expr: &Expr, checker: &mut Checker) { if checker.enabled(Rule::CallDateFromtimestamp) { flake8_datetimez::rules::call_date_fromtimestamp(checker, func, expr.range()); } - if checker.enabled(Rule::DeprecatedLogWarn) { - pygrep_hooks::rules::deprecated_log_warn(checker, func); - } if checker.enabled(Rule::UnnecessaryDirectLambdaCall) { pylint::rules::unnecessary_direct_lambda_call(checker, expr, func); } diff --git a/crates/ruff/src/codes.rs b/crates/ruff/src/codes.rs index 2fafe5179ed58..e10c600de96a3 100644 --- a/crates/ruff/src/codes.rs +++ b/crates/ruff/src/codes.rs @@ -640,7 +640,6 @@ pub fn code_to_rule(linter: Linter, code: &str) -> Option<(RuleGroup, Rule)> { (Flake8Datetimez, "012") => (RuleGroup::Unspecified, rules::flake8_datetimez::rules::CallDateFromtimestamp), // pygrep-hooks - (PygrepHooks, "002") => (RuleGroup::Unspecified, rules::pygrep_hooks::rules::DeprecatedLogWarn), (PygrepHooks, "003") => (RuleGroup::Unspecified, rules::pygrep_hooks::rules::BlanketTypeIgnore), (PygrepHooks, "004") => (RuleGroup::Unspecified, rules::pygrep_hooks::rules::BlanketNOQA), (PygrepHooks, "005") => (RuleGroup::Unspecified, rules::pygrep_hooks::rules::InvalidMockAccess), diff --git a/crates/ruff/src/rule_redirects.rs b/crates/ruff/src/rule_redirects.rs index 82fb730ca99c0..56c849b8016f1 100644 --- a/crates/ruff/src/rule_redirects.rs +++ b/crates/ruff/src/rule_redirects.rs @@ -99,5 +99,6 @@ static REDIRECTS: Lazy> = Lazy::new(|| { ("T003", "FIX003"), ("T004", "FIX004"), ("PGH001", "S307"), + ("PGH002", "G010"), ]) }); diff --git a/crates/ruff/src/rules/pygrep_hooks/mod.rs b/crates/ruff/src/rules/pygrep_hooks/mod.rs index 959e234c99c7d..63509836db993 100644 --- a/crates/ruff/src/rules/pygrep_hooks/mod.rs +++ b/crates/ruff/src/rules/pygrep_hooks/mod.rs @@ -12,8 +12,6 @@ mod tests { use crate::test::test_path; use crate::{assert_messages, settings}; - #[test_case(Rule::DeprecatedLogWarn, Path::new("PGH002_0.py"))] - #[test_case(Rule::DeprecatedLogWarn, Path::new("PGH002_1.py"))] #[test_case(Rule::BlanketTypeIgnore, Path::new("PGH003_0.py"))] #[test_case(Rule::BlanketTypeIgnore, Path::new("PGH003_1.py"))] #[test_case(Rule::BlanketNOQA, Path::new("PGH004_0.py"))] diff --git a/crates/ruff/src/rules/pygrep_hooks/rules/deprecated_log_warn.rs b/crates/ruff/src/rules/pygrep_hooks/rules/deprecated_log_warn.rs deleted file mode 100644 index c91566f365532..0000000000000 --- a/crates/ruff/src/rules/pygrep_hooks/rules/deprecated_log_warn.rs +++ /dev/null @@ -1,56 +0,0 @@ -use ruff_python_ast::Expr; - -use ruff_diagnostics::{Diagnostic, Violation}; -use ruff_macros::{derive_message_formats, violation}; -use ruff_text_size::Ranged; - -use crate::checkers::ast::Checker; - -/// ## What it does -/// Check for usages of the deprecated `warn` method from the `logging` module. -/// -/// ## Why is this bad? -/// The `warn` method is deprecated. Use `warning` instead. -/// -/// ## Example -/// ```python -/// import logging -/// -/// -/// def foo(): -/// logging.warn("Something happened") -/// ``` -/// -/// Use instead: -/// ```python -/// import logging -/// -/// -/// def foo(): -/// logging.warning("Something happened") -/// ``` -/// -/// ## References -/// - [Python documentation: `logger.Logger.warning`](https://docs.python.org/3/library/logging.html#logging.Logger.warning) -#[violation] -pub struct DeprecatedLogWarn; - -impl Violation for DeprecatedLogWarn { - #[derive_message_formats] - fn message(&self) -> String { - format!("`warn` is deprecated in favor of `warning`") - } -} - -/// PGH002 -pub(crate) fn deprecated_log_warn(checker: &mut Checker, func: &Expr) { - if checker - .semantic() - .resolve_call_path(func) - .is_some_and(|call_path| matches!(call_path.as_slice(), ["logging", "warn"])) - { - checker - .diagnostics - .push(Diagnostic::new(DeprecatedLogWarn, func.range())); - } -} diff --git a/crates/ruff/src/rules/pygrep_hooks/rules/mod.rs b/crates/ruff/src/rules/pygrep_hooks/rules/mod.rs index 32e82b15aada9..3d0d2d6d83661 100644 --- a/crates/ruff/src/rules/pygrep_hooks/rules/mod.rs +++ b/crates/ruff/src/rules/pygrep_hooks/rules/mod.rs @@ -1,9 +1,7 @@ pub(crate) use blanket_noqa::*; pub(crate) use blanket_type_ignore::*; -pub(crate) use deprecated_log_warn::*; pub(crate) use invalid_mock_access::*; mod blanket_noqa; mod blanket_type_ignore; -mod deprecated_log_warn; mod invalid_mock_access; diff --git a/crates/ruff/src/rules/pygrep_hooks/snapshots/ruff__rules__pygrep_hooks__tests__PGH002_PGH002_0.py.snap b/crates/ruff/src/rules/pygrep_hooks/snapshots/ruff__rules__pygrep_hooks__tests__PGH002_PGH002_0.py.snap deleted file mode 100644 index 73d713dc73482..0000000000000 --- a/crates/ruff/src/rules/pygrep_hooks/snapshots/ruff__rules__pygrep_hooks__tests__PGH002_PGH002_0.py.snap +++ /dev/null @@ -1,4 +0,0 @@ ---- -source: crates/ruff/src/rules/pygrep_hooks/mod.rs ---- - diff --git a/crates/ruff/src/rules/pygrep_hooks/snapshots/ruff__rules__pygrep_hooks__tests__PGH002_PGH002_1.py.snap b/crates/ruff/src/rules/pygrep_hooks/snapshots/ruff__rules__pygrep_hooks__tests__PGH002_PGH002_1.py.snap deleted file mode 100644 index 917e9356caa2d..0000000000000 --- a/crates/ruff/src/rules/pygrep_hooks/snapshots/ruff__rules__pygrep_hooks__tests__PGH002_PGH002_1.py.snap +++ /dev/null @@ -1,20 +0,0 @@ ---- -source: crates/ruff/src/rules/pygrep_hooks/mod.rs ---- -PGH002_1.py:4:1: PGH002 `warn` is deprecated in favor of `warning` - | -2 | from logging import warn -3 | -4 | logging.warn("this is not ok") - | ^^^^^^^^^^^^ PGH002 -5 | warn("not ok") - | - -PGH002_1.py:5:1: PGH002 `warn` is deprecated in favor of `warning` - | -4 | logging.warn("this is not ok") -5 | warn("not ok") - | ^^^^ PGH002 - | - -