mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-04 02:38:25 +00:00
Allow aliased logging
module as a logger candidate (#3718)
This commit is contained in:
parent
7af83460ce
commit
63adf9f5e8
9 changed files with 47 additions and 11 deletions
|
@ -1288,9 +1288,20 @@ impl<'a> SimpleCallArgs<'a> {
|
|||
/// Return `true` if the given `Expr` is a potential logging call. Matches
|
||||
/// `logging.error`, `logger.error`, `self.logger.error`, etc., but not
|
||||
/// arbitrary `foo.error` calls.
|
||||
pub fn is_logger_candidate(func: &Expr) -> bool {
|
||||
///
|
||||
/// It even matches direct `logging.error` calls even if the `logging` module
|
||||
/// is aliased. Example:
|
||||
/// ```python
|
||||
/// import logging as bar
|
||||
///
|
||||
/// # This is detected to be a logger candidate
|
||||
/// bar.error()
|
||||
/// ```
|
||||
pub fn is_logger_candidate(context: &Context, func: &Expr) -> bool {
|
||||
if let ExprKind::Attribute { value, .. } = &func.node {
|
||||
let call_path = collect_call_path(value);
|
||||
let call_path = context
|
||||
.resolve_call_path(value)
|
||||
.unwrap_or_else(|| collect_call_path(value));
|
||||
if let Some(tail) = call_path.last() {
|
||||
if tail.starts_with("log") || tail.ends_with("logger") || tail.ends_with("logging") {
|
||||
return true;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue