Expand heuristic for detecting logging calls (#2279)

This commit is contained in:
Charlie Marsh
2023-01-27 18:41:16 -05:00
committed by GitHub
parent 0b34ca7107
commit b3e8b1b787
3 changed files with 32 additions and 2 deletions

View File

@@ -28,6 +28,16 @@ def bad():
logger.error("Context message here")
def bad():
try:
a = 1
except Exception:
log.error("Context message here")
if True:
log.error("Context message here")
def bad():
try:
a = 1

View File

@@ -1010,7 +1010,7 @@ pub fn is_logger_candidate(func: &Expr) -> bool {
if let ExprKind::Attribute { value, .. } = &func.node {
let call_path = collect_call_path(value);
if let Some(tail) = call_path.last() {
if *tail == "logging" || tail.ends_with("logger") {
if tail.starts_with("log") || tail.ends_with("logger") || tail.ends_with("logging") {
return true;
}
}

View File

@@ -49,7 +49,7 @@ expression: diagnostics
column: 8
end_location:
row: 35
column: 49
column: 41
fix: ~
parent: ~
- kind:
@@ -59,6 +59,26 @@ expression: diagnostics
column: 12
end_location:
row: 38
column: 45
fix: ~
parent: ~
- kind:
ErrorInsteadOfException: ~
location:
row: 45
column: 8
end_location:
row: 45
column: 49
fix: ~
parent: ~
- kind:
ErrorInsteadOfException: ~
location:
row: 48
column: 12
end_location:
row: 48
column: 53
fix: ~
parent: ~