forked from astral-sh/ruff
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement PGH002 - deprecated use of logging.warn
Refs astral-sh#980
- Loading branch information
Showing
10 changed files
with
106 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import logging | ||
import warnings | ||
from warnings import warn | ||
|
||
warnings.warn("this is ok") | ||
warn("by itself is also ok") | ||
logging.warning("this is fine") | ||
log.warning("this is ok") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import logging | ||
from logging import warn | ||
|
||
logging.warn("this is not ok") | ||
log.warn("this is also not ok") | ||
warn("not ok") | ||
|
||
|
||
def foo(): | ||
from logging import warn | ||
|
||
def warn(): | ||
pass | ||
|
||
warn("has been redefined, but we will still report it") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
use rustpython_ast::Expr; | ||
|
||
use crate::ast::helpers::{collect_call_paths, dealias_call_path, match_call_path}; | ||
use crate::ast::types::Range; | ||
use crate::checkers::ast::Checker; | ||
use crate::checks::{Check, CheckKind}; | ||
|
||
/// PGH002 - deprecated use of logging.warn | ||
pub fn deprecated_log_warn(checker: &mut Checker, func: &Expr) { | ||
let call_path = dealias_call_path(collect_call_paths(func), &checker.import_aliases); | ||
if call_path == ["log", "warn"] | ||
|| match_call_path(&call_path, "logging", "warn", &checker.from_imports) | ||
{ | ||
checker.add_check(Check::new( | ||
CheckKind::DeprecatedLogWarn, | ||
Range::from_located(func), | ||
)); | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
src/pygrep_hooks/snapshots/ruff__pygrep_hooks__tests__PGH002_PGH002_0.py.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
source: src/pygrep_hooks/mod.rs | ||
expression: checks | ||
--- | ||
[] | ||
|
37 changes: 37 additions & 0 deletions
37
src/pygrep_hooks/snapshots/ruff__pygrep_hooks__tests__PGH002_PGH002_1.py.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
--- | ||
source: src/pygrep_hooks/mod.rs | ||
expression: checks | ||
--- | ||
- kind: DeprecatedLogWarn | ||
location: | ||
row: 4 | ||
column: 0 | ||
end_location: | ||
row: 4 | ||
column: 12 | ||
fix: ~ | ||
- kind: DeprecatedLogWarn | ||
location: | ||
row: 5 | ||
column: 0 | ||
end_location: | ||
row: 5 | ||
column: 8 | ||
fix: ~ | ||
- kind: DeprecatedLogWarn | ||
location: | ||
row: 6 | ||
column: 0 | ||
end_location: | ||
row: 6 | ||
column: 4 | ||
fix: ~ | ||
- kind: DeprecatedLogWarn | ||
location: | ||
row: 15 | ||
column: 4 | ||
end_location: | ||
row: 15 | ||
column: 8 | ||
fix: ~ | ||
|