Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add docs for E275, E231, E251, and E252 #6700

Merged
merged 6 commits into from
Aug 20, 2023
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,21 @@ use crate::checkers::logical_lines::LogicalLinesContext;

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]
pub struct MissingWhitespace {
token: TokenKind,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,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 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]
pub struct MissingWhitespaceAfterKeyword;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,31 @@ use ruff_text_size::{TextRange, TextSize};
use crate::checkers::logical_lines::LogicalLinesContext;
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]
pub struct UnexpectedSpacesAroundKeywordParameterEquals;

Expand All @@ -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]
pub struct MissingWhitespaceAroundParameterEquals;

Expand Down
4 changes: 4 additions & 0 deletions scripts/check_docs_formatted.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,13 @@
"indentation-with-invalid-multiple",
"line-too-long",
"missing-trailing-comma",
"missing-whitespace",
"missing-whitespace-after-keyword",
"missing-whitespace-around-arithmetic-operator",
"missing-whitespace-around-bitwise-or-shift-operator",
"missing-whitespace-around-modulo-operator",
"missing-whitespace-around-operator",
"missing-whitespace-around-parameter-equals",
"multi-line-implicit-string-concatenation",
"multiple-leading-hashes-for-block-comment",
"multiple-spaces-after-comma",
Expand All @@ -66,6 +69,7 @@
"triple-single-quotes",
"under-indentation",
"unexpected-indentation-comment",
"unexpected-spaces-around-keyword-parameter-equals",
"unicode-kind-prefix",
"unnecessary-class-parentheses",
"useless-semicolon",
Expand Down