mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-28 04:45:01 +00:00
[pylint
] Implement empty-comment
(PLR2044
) (#9174)
## Summary Part of #970. This adds Pylint's [R0244 empty_comment](https://pylint.pycqa.org/en/latest/user_guide/messages/refactor/empty-comment.html) lint as well as an always-safe fix. ## Test Plan The included snapshot verifies the following: - A line containing only a non-empty comment is not changed - A line containing leading whitespace before a non-empty comment is not changed - A line containing only an empty comment has its content deleted - A line containing only leading whitespace before an empty comment has its content deleted - A line containing only leading and trailing whitespace on an empty comment has its content deleted - A line containing trailing whitespace after a non-empty comment is not changed - A line containing only a single newline character (i.e. a blank line) is not changed - A line containing code followed by a non-empty comment is not changed - A line containing code followed by an empty comment has its content deleted after the last non-whitespace character - Lines containing code and no comments are not changed - Empty comment lines within block comments are ignored - Empty comments within triple-quoted sections are ignored ## Comparison to Pylint Running Ruff and Pylint 3.0.3 with Python 3.12.0 against the `empty_comment.py` file added in this PR, we see the following: * Identical behavior: * empty_comment.py:3:0: R2044: Line with empty comment (empty-comment) * empty_comment.py:4:0: R2044: Line with empty comment (empty-comment) * empty_comment.py:5:0: R2044: Line with empty comment (empty-comment) * empty_comment.py:18:0: R2044: Line with empty comment (empty-comment) * Differing behavior: * Pylint doesn't ignore empty comments in block comments commonly used for visual spacing; I decided these were fine in this implementation since many projects use these and likely do not want them removed. * empty_comment.py:28:0: R2044: Line with empty comment (empty-comment) * Pylint detects "empty comments" within the triple-quoted section at the bottom of the file, which is arguably a bug in the Pylint implementation since these are not truly comments. These are ignored by this implementation. * empty_comment.py:37:0: R2044: Line with empty comment (empty-comment) * empty_comment.py:38:0: R2044: Line with empty comment (empty-comment) * empty_comment.py:39:0: R2044: Line with empty comment (empty-comment)
This commit is contained in:
parent
57b6a8cedd
commit
375c175d53
13 changed files with 581 additions and 1 deletions
|
@ -265,6 +265,7 @@ pub fn code_to_rule(linter: Linter, code: &str) -> Option<(RuleGroup, Rule)> {
|
|||
(Pylint, "R1733") => (RuleGroup::Preview, rules::pylint::rules::UnnecessaryDictIndexLookup),
|
||||
(Pylint, "R1736") => (RuleGroup::Preview, rules::pylint::rules::UnnecessaryListIndexLookup),
|
||||
(Pylint, "R2004") => (RuleGroup::Stable, rules::pylint::rules::MagicValueComparison),
|
||||
(Pylint, "R2044") => (RuleGroup::Preview, rules::pylint::rules::EmptyComment),
|
||||
(Pylint, "R5501") => (RuleGroup::Stable, rules::pylint::rules::CollapsibleElseIf),
|
||||
(Pylint, "R6201") => (RuleGroup::Preview, rules::pylint::rules::LiteralMembership),
|
||||
#[allow(deprecated)]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue