Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 35 additions & 17 deletions crates/ruff_linter/src/rules/flake8_print/rules/print_call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,42 @@ use crate::registry::AsRule;
/// 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.
/// `print` statements used for debugging should be omitted from production
/// code. They can lead the accidental inclusion of sensitive information in
/// logs, and are not configurable by clients, unlike `logging` statements.
///
/// `print` statements used to produce output as a part of a command-line
/// interface program are not typically a problem.
///
/// ## Example
/// ```python
/// def add_numbers(a, b):
/// print(f"The sum of {a} and {b} is {a + b}")
/// return a + b
/// def sum_less_than_four(a, b):
/// print(f"Calling sum_less_than_four")
/// return a + b < 4
/// ```
///
/// Use instead:
/// The automatic fix will remove the print statement entirely:
///
/// ```python
/// def add_numbers(a, b):
/// return a + b
/// def sum_less_than_four(a, b):
/// return a + b < 4
/// ```
///
/// To keep the line for logging purposes, instead use something like:
///
/// ```python
/// import logging
///
/// logging.basicConfig(level=logging.INFO)
///
///
/// def sum_less_than_four(a, b):
/// logging.debug("Calling sum_less_than_four")
/// return a + b < 4
/// ```
///
/// ## Fix safety
/// This rule's fix is marked as unsafe, as it may remove `print` statements
/// This rule's fix is marked as unsafe, as it will remove `print` statements
/// that are used beyond debugging purposes.
#[derive(ViolationMetadata)]
pub(crate) struct Print;
Expand All @@ -52,11 +68,13 @@ impl Violation for Print {
/// 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.
/// Like `print` statements, `pprint` statements used for debugging should
/// be omitted from production code. They can lead the accidental inclusion
/// of sensitive information in logs, and are not configurable by clients,
/// unlike `logging` statements.
///
/// `pprint` statements used to produce output as a part of a command-line
/// interface program are not typically a problem.
///
/// ## Example
/// ```python
Expand All @@ -77,7 +95,7 @@ impl Violation for Print {
/// ```
///
/// ## Fix safety
/// This rule's fix is marked as unsafe, as it may remove `pprint` statements
/// This rule's fix is marked as unsafe, as it will remove `pprint` statements
/// that are used beyond debugging purposes.
#[derive(ViolationMetadata)]
pub(crate) struct PPrint;
Expand Down
Loading