mirror of https://github.com/astral-sh/ruff
Deprecate PGH002 in favor of G010
This commit is contained in:
parent
49d596c29d
commit
68b228f9dd
|
|
@ -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")
|
||||
|
|
@ -1,5 +0,0 @@
|
|||
import logging
|
||||
from logging import warn
|
||||
|
||||
logging.warn("this is not ok")
|
||||
warn("not ok")
|
||||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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),
|
||||
|
|
|
|||
|
|
@ -99,5 +99,6 @@ static REDIRECTS: Lazy<HashMap<&'static str, &'static str>> = Lazy::new(|| {
|
|||
("T003", "FIX003"),
|
||||
("T004", "FIX004"),
|
||||
("PGH001", "S307"),
|
||||
("PGH002", "G010"),
|
||||
])
|
||||
});
|
||||
|
|
|
|||
|
|
@ -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"))]
|
||||
|
|
|
|||
|
|
@ -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()));
|
||||
}
|
||||
}
|
||||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -1,4 +0,0 @@
|
|||
---
|
||||
source: crates/ruff/src/rules/pygrep_hooks/mod.rs
|
||||
---
|
||||
|
||||
|
|
@ -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
|
||||
|
|
||||
|
||||
|
||||
Loading…
Reference in New Issue