mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-04 10:48:32 +00:00
missing-whitespace-around-operators comment (#6106)
**Summary**
Updated doc comments for `missing_whitespace_around_operator.rs`. Online
docs also benefit from this update.
**Test Plan**
Checked docs via
[mkdocs](389fe13c93/CONTRIBUTING.md (L267-L296)
)
This commit is contained in:
parent
d16216a2c2
commit
bb08eea5cc
2 changed files with 78 additions and 0 deletions
|
@ -5,6 +5,26 @@ use ruff_python_parser::TokenKind;
|
|||
use crate::checkers::logical_lines::LogicalLinesContext;
|
||||
use crate::rules::pycodestyle::rules::logical_lines::LogicalLine;
|
||||
|
||||
/// ## What it does
|
||||
/// Checks for missing whitespace around all operators.
|
||||
///
|
||||
/// ## Why is this bad?
|
||||
/// According to [PEP 8], there should be one space before and after all
|
||||
/// operators.
|
||||
///
|
||||
/// ## Example
|
||||
/// ```python
|
||||
/// if number==42:
|
||||
/// print('you have found the meaning of life')
|
||||
/// ```
|
||||
///
|
||||
/// Use instead:
|
||||
/// ```python
|
||||
/// if number == 42:
|
||||
/// print('you have found the meaning of life')
|
||||
/// ```
|
||||
///
|
||||
/// [PEP 8]: https://peps.python.org/pep-0008/#pet-peeves
|
||||
// E225
|
||||
#[violation]
|
||||
pub struct MissingWhitespaceAroundOperator;
|
||||
|
@ -16,6 +36,24 @@ impl Violation for MissingWhitespaceAroundOperator {
|
|||
}
|
||||
}
|
||||
|
||||
/// ## What it does
|
||||
/// Checks for missing whitespace arithmetic operators.
|
||||
///
|
||||
/// ## Why is this bad?
|
||||
/// According to [PEP 8], there should be one space before and after an
|
||||
/// arithmetic operator (+, -, /, and *).
|
||||
///
|
||||
/// ## Example
|
||||
/// ```python
|
||||
/// number = 40+2
|
||||
/// ```
|
||||
///
|
||||
/// Use instead:
|
||||
/// ```python
|
||||
/// number = 40 + 2
|
||||
/// ```
|
||||
///
|
||||
/// [PEP 8]: https://peps.python.org/pep-0008/#pet-peeves
|
||||
// E226
|
||||
#[violation]
|
||||
pub struct MissingWhitespaceAroundArithmeticOperator;
|
||||
|
@ -27,6 +65,24 @@ impl Violation for MissingWhitespaceAroundArithmeticOperator {
|
|||
}
|
||||
}
|
||||
|
||||
/// ## What it does
|
||||
/// Checks for missing whitespace around bitwise and shift operators.
|
||||
///
|
||||
/// ## Why is this bad?
|
||||
/// According to [PEP 8], there should be one space before and after bitwise and
|
||||
/// shift operators (<<, >>, &, |, ^).
|
||||
///
|
||||
/// ## Example
|
||||
/// ```python
|
||||
/// x = 128<<1
|
||||
/// ```
|
||||
///
|
||||
/// Use instead:
|
||||
/// ```python
|
||||
/// x = 128 << 1
|
||||
/// ```
|
||||
///
|
||||
/// [PEP 8]: https://peps.python.org/pep-0008/#pet-peeves
|
||||
// E227
|
||||
#[violation]
|
||||
pub struct MissingWhitespaceAroundBitwiseOrShiftOperator;
|
||||
|
@ -38,6 +94,24 @@ impl Violation for MissingWhitespaceAroundBitwiseOrShiftOperator {
|
|||
}
|
||||
}
|
||||
|
||||
/// ## What it does
|
||||
/// Checks for missing whitespace around the modulo operator.
|
||||
///
|
||||
/// ## Why is this bad?
|
||||
/// According to [PEP 8], the modulo operator (%) should have whitespace on
|
||||
/// either side of it.
|
||||
///
|
||||
/// ## Example
|
||||
/// ```python
|
||||
/// remainder = 10%2
|
||||
/// ```
|
||||
///
|
||||
/// Use instead:
|
||||
/// ```python
|
||||
/// remainder = 10 % 2
|
||||
/// ```
|
||||
///
|
||||
/// [PEP 8]: https://peps.python.org/pep-0008/#other-recommendations
|
||||
// E228
|
||||
#[violation]
|
||||
pub struct MissingWhitespaceAroundModuloOperator;
|
||||
|
|
|
@ -37,6 +37,10 @@ KNOWN_FORMATTING_VIOLATIONS = [
|
|||
"indentation-with-invalid-multiple",
|
||||
"line-too-long",
|
||||
"missing-trailing-comma",
|
||||
"missing-whitespace-around-arithmetic-operator",
|
||||
"missing-whitespace-around-bitwise-or-shift-operator",
|
||||
"missing-whitespace-around-modulo-operator",
|
||||
"missing-whitespace-around-operator",
|
||||
"multi-line-implicit-string-concatenation",
|
||||
"multiple-leading-hashes-for-block-comment",
|
||||
"multiple-spaces-after-keyword",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue