Document flake8-print (#4144)

This commit is contained in:
Calum Young 2023-04-29 04:19:00 +01:00 committed by GitHub
parent 12d64a223b
commit 0172cc51a7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -7,6 +7,27 @@ use ruff_python_ast::helpers::is_const_none;
use crate::checkers::ast::Checker;
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]
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]
pub struct PPrint;