mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-27 20:42:10 +00:00
Document flake8-print
(#4144)
This commit is contained in:
parent
12d64a223b
commit
0172cc51a7
1 changed files with 48 additions and 0 deletions
|
@ -7,6 +7,27 @@ use ruff_python_ast::helpers::is_const_none;
|
||||||
use crate::checkers::ast::Checker;
|
use crate::checkers::ast::Checker;
|
||||||
use crate::registry::AsRule;
|
use crate::registry::AsRule;
|
||||||
|
|
||||||
|
/// ## What it does
|
||||||
|
/// Checks for `print` statements.
|
||||||
|
///
|
||||||
|
/// ## Why is this bad?
|
||||||
|
/// `print` statements are useful in some situations (e.g., debugging), but
|
||||||
|
/// should typically be omitted from production code. `print` statements can
|
||||||
|
/// lead to the accidental inclusion of sensitive information in logs, and are
|
||||||
|
/// not configurable by clients, unlike `logging` statements.
|
||||||
|
///
|
||||||
|
/// ## Example
|
||||||
|
/// ```python
|
||||||
|
/// def add_numbers(a, b):
|
||||||
|
/// print(f"The sum of {a} and {b} is {a + b}")
|
||||||
|
/// return a + b
|
||||||
|
/// ```
|
||||||
|
///
|
||||||
|
/// Use instead:
|
||||||
|
/// ```python
|
||||||
|
/// def add_numbers(a, b):
|
||||||
|
/// return a + b
|
||||||
|
/// ```
|
||||||
#[violation]
|
#[violation]
|
||||||
pub struct Print;
|
pub struct Print;
|
||||||
|
|
||||||
|
@ -17,6 +38,33 @@ impl Violation for Print {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// ## What it does
|
||||||
|
/// Checks for `pprint` statements.
|
||||||
|
///
|
||||||
|
/// ## Why is this bad?
|
||||||
|
/// Like `print` statements, `pprint` statements are useful in some situations
|
||||||
|
/// (e.g., debugging), but should typically be omitted from production code.
|
||||||
|
/// `pprint` statements can lead to the accidental inclusion of sensitive
|
||||||
|
/// information in logs, and are not configurable by clients, unlike `logging`
|
||||||
|
/// statements.
|
||||||
|
///
|
||||||
|
/// ## Example
|
||||||
|
/// ```python
|
||||||
|
/// import pprint
|
||||||
|
///
|
||||||
|
///
|
||||||
|
/// def merge_dicts(dict_a, dict_b):
|
||||||
|
/// dict_c = {**dict_a, **dict_b}
|
||||||
|
/// pprint.pprint(dict_c)
|
||||||
|
/// return dict_c
|
||||||
|
/// ```
|
||||||
|
///
|
||||||
|
/// Use instead:
|
||||||
|
/// ```python
|
||||||
|
/// def merge_dicts(dict_a, dict_b):
|
||||||
|
/// dict_c = {**dict_a, **dict_b}
|
||||||
|
/// return dict_c
|
||||||
|
/// ```
|
||||||
#[violation]
|
#[violation]
|
||||||
pub struct PPrint;
|
pub struct PPrint;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue