mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-03 02:13:08 +00:00
![]() ## 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) |
||
---|---|---|
.. | ||
src | ||
Cargo.toml |