mirror of
https://github.com/astral-sh/ruff.git
synced 2025-11-02 12:58:20 +00:00
Consider Flask app logger as logger candidate (#4253)
This commit is contained in:
parent
11e1380df4
commit
2c91412321
3 changed files with 38 additions and 1 deletions
|
|
@ -7,3 +7,12 @@ foo.info("Hello {}".format("World!"))
|
||||||
logging.log(logging.INFO, msg="Hello {}".format("World!"))
|
logging.log(logging.INFO, msg="Hello {}".format("World!"))
|
||||||
logging.log(level=logging.INFO, msg="Hello {}".format("World!"))
|
logging.log(level=logging.INFO, msg="Hello {}".format("World!"))
|
||||||
logging.log(msg="Hello {}".format("World!"), level=logging.INFO)
|
logging.log(msg="Hello {}".format("World!"), level=logging.INFO)
|
||||||
|
|
||||||
|
# Flask support
|
||||||
|
import flask
|
||||||
|
from flask import current_app
|
||||||
|
from flask import current_app as app
|
||||||
|
|
||||||
|
flask.current_app.logger.info("Hello {}".format("World!"))
|
||||||
|
current_app.logger.info("Hello {}".format("World!"))
|
||||||
|
app.logger.log(logging.INFO, "Hello {}".format("World!"))
|
||||||
|
|
|
||||||
|
|
@ -55,6 +55,34 @@ G001.py:9:17: G001 Logging statement uses `string.format()`
|
||||||
10 | logging.log(level=logging.INFO, msg="Hello {}".format("World!"))
|
10 | logging.log(level=logging.INFO, msg="Hello {}".format("World!"))
|
||||||
11 | logging.log(msg="Hello {}".format("World!"), level=logging.INFO)
|
11 | logging.log(msg="Hello {}".format("World!"), level=logging.INFO)
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ G001
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ G001
|
||||||
|
12 |
|
||||||
|
13 | # Flask support
|
||||||
|
|
|
||||||
|
|
||||||
|
G001.py:16:31: G001 Logging statement uses `string.format()`
|
||||||
|
|
|
||||||
|
16 | from flask import current_app as app
|
||||||
|
17 |
|
||||||
|
18 | flask.current_app.logger.info("Hello {}".format("World!"))
|
||||||
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ G001
|
||||||
|
19 | current_app.logger.info("Hello {}".format("World!"))
|
||||||
|
20 | app.logger.log(logging.INFO, "Hello {}".format("World!"))
|
||||||
|
|
|
||||||
|
|
||||||
|
G001.py:17:25: G001 Logging statement uses `string.format()`
|
||||||
|
|
|
||||||
|
17 | flask.current_app.logger.info("Hello {}".format("World!"))
|
||||||
|
18 | current_app.logger.info("Hello {}".format("World!"))
|
||||||
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ G001
|
||||||
|
19 | app.logger.log(logging.INFO, "Hello {}".format("World!"))
|
||||||
|
|
|
||||||
|
|
||||||
|
G001.py:18:30: G001 Logging statement uses `string.format()`
|
||||||
|
|
|
||||||
|
18 | flask.current_app.logger.info("Hello {}".format("World!"))
|
||||||
|
19 | current_app.logger.info("Hello {}".format("World!"))
|
||||||
|
20 | app.logger.log(logging.INFO, "Hello {}".format("World!"))
|
||||||
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ G001
|
||||||
|
|
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@ use crate::context::Context;
|
||||||
pub fn is_logger_candidate(context: &Context, func: &Expr) -> bool {
|
pub fn is_logger_candidate(context: &Context, func: &Expr) -> bool {
|
||||||
if let ExprKind::Attribute { value, .. } = &func.node {
|
if let ExprKind::Attribute { value, .. } = &func.node {
|
||||||
let Some(call_path) = (if let Some(call_path) = context.resolve_call_path(value) {
|
let Some(call_path) = (if let Some(call_path) = context.resolve_call_path(value) {
|
||||||
if call_path.first().map_or(false, |module| *module == "logging") {
|
if call_path.first().map_or(false, |module| *module == "logging") || call_path.as_slice() == ["flask", "current_app", "logger"] {
|
||||||
Some(call_path)
|
Some(call_path)
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue