From 0172cc51a7057c1ca8e4c2a2247f0d2dd621c78f Mon Sep 17 00:00:00 2001 From: Calum Young <32770960+calumy@users.noreply.github.com> Date: Sat, 29 Apr 2023 04:19:00 +0100 Subject: [PATCH] Document `flake8-print` (#4144) --- .../rules/flake8_print/rules/print_call.rs | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/crates/ruff/src/rules/flake8_print/rules/print_call.rs b/crates/ruff/src/rules/flake8_print/rules/print_call.rs index 150609beb6..80d5046318 100644 --- a/crates/ruff/src/rules/flake8_print/rules/print_call.rs +++ b/crates/ruff/src/rules/flake8_print/rules/print_call.rs @@ -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;