mirror of
https://github.com/astral-sh/ruff.git
synced 2025-11-25 14:24:10 +00:00
Add docs for E275, E231, E251, and E252 (#6700)
This commit is contained in:
parent
a742a562fd
commit
419615f29b
4 changed files with 89 additions and 0 deletions
|
|
@ -9,6 +9,21 @@ use crate::checkers::logical_lines::LogicalLinesContext;
|
||||||
|
|
||||||
use super::LogicalLine;
|
use super::LogicalLine;
|
||||||
|
|
||||||
|
/// ## What it does
|
||||||
|
/// Checks for missing whitespace after `,`, `;`, and `:`.
|
||||||
|
///
|
||||||
|
/// ## Why is this bad?
|
||||||
|
/// Missing whitespace after `,`, `;`, and `:` makes the code harder to read.
|
||||||
|
///
|
||||||
|
/// ## Example
|
||||||
|
/// ```python
|
||||||
|
/// a = (1,2)
|
||||||
|
/// ```
|
||||||
|
///
|
||||||
|
/// Use instead:
|
||||||
|
/// ```python
|
||||||
|
/// a = (1, 2)
|
||||||
|
/// ```
|
||||||
#[violation]
|
#[violation]
|
||||||
pub struct MissingWhitespace {
|
pub struct MissingWhitespace {
|
||||||
token: TokenKind,
|
token: TokenKind,
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,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 after keywords.
|
||||||
|
///
|
||||||
|
/// ## Why is this bad?
|
||||||
|
/// Missing whitespace after keywords makes the code harder to read.
|
||||||
|
///
|
||||||
|
/// ## Example
|
||||||
|
/// ```python
|
||||||
|
/// if(True):
|
||||||
|
/// pass
|
||||||
|
/// ```
|
||||||
|
///
|
||||||
|
/// Use instead:
|
||||||
|
/// ```python
|
||||||
|
/// if (True):
|
||||||
|
/// pass
|
||||||
|
/// ```
|
||||||
|
///
|
||||||
|
/// ## References
|
||||||
|
/// - [Python documentation: Keywords](https://docs.python.org/3/reference/lexical_analysis.html#keywords)
|
||||||
#[violation]
|
#[violation]
|
||||||
pub struct MissingWhitespaceAfterKeyword;
|
pub struct MissingWhitespaceAfterKeyword;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,31 @@ use ruff_text_size::{TextRange, TextSize};
|
||||||
use crate::checkers::logical_lines::LogicalLinesContext;
|
use crate::checkers::logical_lines::LogicalLinesContext;
|
||||||
use crate::rules::pycodestyle::rules::logical_lines::{LogicalLine, LogicalLineToken};
|
use crate::rules::pycodestyle::rules::logical_lines::{LogicalLine, LogicalLineToken};
|
||||||
|
|
||||||
|
/// ## What it does
|
||||||
|
/// Checks for missing whitespace around the equals sign in an unannotated
|
||||||
|
/// function keyword parameter.
|
||||||
|
///
|
||||||
|
/// ## Why is this bad?
|
||||||
|
/// According to [PEP 8], there should be no spaces around the equals sign in a
|
||||||
|
/// keyword parameter, if it is unannotated:
|
||||||
|
///
|
||||||
|
/// > Don’t use spaces around the = sign when used to indicate a keyword
|
||||||
|
/// > argument, or when used to indicate a default value for an unannotated
|
||||||
|
/// > function parameter.
|
||||||
|
///
|
||||||
|
/// ## Example
|
||||||
|
/// ```python
|
||||||
|
/// def add(a = 0) -> int:
|
||||||
|
/// return a + 1
|
||||||
|
/// ```
|
||||||
|
///
|
||||||
|
/// Use instead:
|
||||||
|
/// ```python
|
||||||
|
/// def add(a = 0) -> int:
|
||||||
|
/// return a + 1
|
||||||
|
/// ```
|
||||||
|
///
|
||||||
|
/// [PEP 8]: https://peps.python.org/pep-0008/#whitespace-in-expressions-and-statements
|
||||||
#[violation]
|
#[violation]
|
||||||
pub struct UnexpectedSpacesAroundKeywordParameterEquals;
|
pub struct UnexpectedSpacesAroundKeywordParameterEquals;
|
||||||
|
|
||||||
|
|
@ -17,6 +42,31 @@ impl Violation for UnexpectedSpacesAroundKeywordParameterEquals {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// ## What it does
|
||||||
|
/// Checks for missing whitespace around the equals sign in an annotated
|
||||||
|
/// function keyword parameter.
|
||||||
|
///
|
||||||
|
/// ## Why is this bad?
|
||||||
|
/// According to [PEP 8], the spaces around the equals sign in a keyword
|
||||||
|
/// parameter should only be omitted when the parameter is unannotated:
|
||||||
|
///
|
||||||
|
/// > Don’t use spaces around the = sign when used to indicate a keyword
|
||||||
|
/// > argument, or when used to indicate a default value for an unannotated
|
||||||
|
/// > function parameter.
|
||||||
|
///
|
||||||
|
/// ## Example
|
||||||
|
/// ```python
|
||||||
|
/// def add(a: int=0) -> int:
|
||||||
|
/// return a + 1
|
||||||
|
/// ```
|
||||||
|
///
|
||||||
|
/// Use instead:
|
||||||
|
/// ```python
|
||||||
|
/// def add(a: int = 0) -> int:
|
||||||
|
/// return a + 1
|
||||||
|
/// ```
|
||||||
|
///
|
||||||
|
/// [PEP 8]: https://peps.python.org/pep-0008/#whitespace-in-expressions-and-statements
|
||||||
#[violation]
|
#[violation]
|
||||||
pub struct MissingWhitespaceAroundParameterEquals;
|
pub struct MissingWhitespaceAroundParameterEquals;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -37,10 +37,13 @@ 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",
|
||||||
|
"missing-whitespace-after-keyword",
|
||||||
"missing-whitespace-around-arithmetic-operator",
|
"missing-whitespace-around-arithmetic-operator",
|
||||||
"missing-whitespace-around-bitwise-or-shift-operator",
|
"missing-whitespace-around-bitwise-or-shift-operator",
|
||||||
"missing-whitespace-around-modulo-operator",
|
"missing-whitespace-around-modulo-operator",
|
||||||
"missing-whitespace-around-operator",
|
"missing-whitespace-around-operator",
|
||||||
|
"missing-whitespace-around-parameter-equals",
|
||||||
"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-comma",
|
"multiple-spaces-after-comma",
|
||||||
|
|
@ -66,6 +69,7 @@ KNOWN_FORMATTING_VIOLATIONS = [
|
||||||
"triple-single-quotes",
|
"triple-single-quotes",
|
||||||
"under-indentation",
|
"under-indentation",
|
||||||
"unexpected-indentation-comment",
|
"unexpected-indentation-comment",
|
||||||
|
"unexpected-spaces-around-keyword-parameter-equals",
|
||||||
"unicode-kind-prefix",
|
"unicode-kind-prefix",
|
||||||
"unnecessary-class-parentheses",
|
"unnecessary-class-parentheses",
|
||||||
"useless-semicolon",
|
"useless-semicolon",
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue