mirror of https://github.com/astral-sh/ruff
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?plain=1#L267-L296)
This commit is contained in:
parent
d16216a2c2
commit
bb08eea5cc
|
|
@ -5,6 +5,26 @@ use ruff_python_parser::TokenKind;
|
||||||
use crate::checkers::logical_lines::LogicalLinesContext;
|
use crate::checkers::logical_lines::LogicalLinesContext;
|
||||||
use crate::rules::pycodestyle::rules::logical_lines::LogicalLine;
|
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
|
// E225
|
||||||
#[violation]
|
#[violation]
|
||||||
pub struct MissingWhitespaceAroundOperator;
|
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
|
// E226
|
||||||
#[violation]
|
#[violation]
|
||||||
pub struct MissingWhitespaceAroundArithmeticOperator;
|
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
|
// E227
|
||||||
#[violation]
|
#[violation]
|
||||||
pub struct MissingWhitespaceAroundBitwiseOrShiftOperator;
|
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
|
// E228
|
||||||
#[violation]
|
#[violation]
|
||||||
pub struct MissingWhitespaceAroundModuloOperator;
|
pub struct MissingWhitespaceAroundModuloOperator;
|
||||||
|
|
|
||||||
|
|
@ -37,6 +37,10 @@ KNOWN_FORMATTING_VIOLATIONS = [
|
||||||
"indentation-with-invalid-multiple",
|
"indentation-with-invalid-multiple",
|
||||||
"line-too-long",
|
"line-too-long",
|
||||||
"missing-trailing-comma",
|
"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",
|
"multi-line-implicit-string-concatenation",
|
||||||
"multiple-leading-hashes-for-block-comment",
|
"multiple-leading-hashes-for-block-comment",
|
||||||
"multiple-spaces-after-keyword",
|
"multiple-spaces-after-keyword",
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue