ruff icon indicating copy to clipboard operation
ruff copied to clipboard

Bad fixes with E266: multiple-leading-hashes-for-block-comment

Open Hnasar opened this issue 5 months ago • 3 comments

I'm trying out --preview with ruff 0.3.4. E266 which is a pycodestyle --preview rule has some weird fixes:

  1. Probably should try to leave headers alone if the comment ends in one or more #
-##################################### FOO #############################################
+# FOO #############################################
  1. Why is the space after the :?
-            #:::team.foo.bar.baz
+            #: ::team.foo.bar.baz
  1. Weird example in https://docs.astral.sh/ruff/rules/multiple-leading-hashes-for-block-comment/#example

Use instead:

# Block comments:
#  - Block comment list
# \xa0- Block comment list

Hnasar avatar Mar 27 '24 17:03 Hnasar

  1. I think flagging it (and the way its fixed) is in line with the intent of the rule. You might want to disable E266 if you want to keep header comments with this specific format.

  2. Pycodestyle both allows : or ! directly after the #

#: E265:2:1
m = 42
#! This is important
mx = 42 - 42
#: E266:3:5 E266:6:5
  1. I assume what you find weird about it is the \xa0? Or is it something else

MichaReiser avatar Mar 28 '24 12:03 MichaReiser

Pycodestyle also allows this style for headers:

#####
# Foo
#####

That is, lines that are only # are allowed.

charliermarsh avatar Mar 28 '24 13:03 charliermarsh

Thanks for the clarifications!

  1. Probably should try to leave headers alone

TIL about the pycodestyle suggested header style, thanks. IMO since PEP 8 doesn't specify a header style, tools should be more permissive (but I understand the desire for compatibility with pycodestyle)

  1. Why is the space after the :?

Pycodestyle both allows : or ! directly after the #

  • TIL that #: is for sphinx documentation, but the fact that pycodestyle supports this is undocumented.
  • FYI for #!: pycodestyle does not allow #! comment (except for shebangs on the first line) -- these comments result in E265 block comment should start with '# '
  1. Weird example in https://docs.astral.sh/ruff/rules/multiple-leading-hashes-for-block-comment/#example

I assume what you find weird about it is the \xa0? Or is it something else

  • the \xa0 is weird and
  • the "use instead" doesn't seem to follow from the "example" E.g. perhaps instead it should be

Example

### Public API
def say_hi():
    ## This is a block comment.
    print("hi")

Use instead

# Public API
def say_hi():
    # This is a block comment.
    print("hi")

or

Use instead

#############
# Public API
#############
def say_hi():
    # This is a block comment.
    print("hi")

Hnasar avatar Apr 01 '24 15:04 Hnasar