mirror of
https://github.com/astral-sh/ruff.git
synced 2025-11-02 04:48:07 +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)
29 lines
733 B
TOML
29 lines
733 B
TOML
[package]
|
|
name = "ruff_python_trivia"
|
|
version = "0.0.0"
|
|
publish = false
|
|
authors = { workspace = true }
|
|
edition = { workspace = true }
|
|
rust-version = { workspace = true }
|
|
homepage = { workspace = true }
|
|
documentation = { workspace = true }
|
|
repository = { workspace = true }
|
|
license = { workspace = true }
|
|
|
|
[lib]
|
|
|
|
[dependencies]
|
|
ruff_text_size = { path = "../ruff_text_size" }
|
|
ruff_source_file = { path = "../ruff_source_file" }
|
|
|
|
itertools = { workspace = true }
|
|
unicode-ident = { workspace = true }
|
|
|
|
[dev-dependencies]
|
|
insta = { workspace = true }
|
|
ruff_python_ast = { path = "../ruff_python_ast" }
|
|
ruff_python_parser = { path = "../ruff_python_parser" }
|
|
ruff_python_index = { path = "../ruff_python_index" }
|
|
|
|
[lints]
|
|
workspace = true
|