Wemake-python-styleguide: Forbid empty comments

Created on 30 Oct 2020  路  11Comments  路  Source: wemake-services/wemake-python-styleguide

Rule request

Thesis

We should ban comments like this one:

# 
my_var = 1

But, empty lines in the middle are fine:

# First line
# 
# Samples:
# One
# Two
my_var = 1

We ban only empty lines in the beginning and in the end.

Reasoning

Why not?

help wanted starter rule request

All 11 comments

Hello there,
@huangyunzen and I would like to work on this new rule. We have just started with the setup in the contribution page. We will report back when we get things ready and develop an initial plan. Thanks!

Thanks a lot!

We'd like to get some clarifications for the alerting style for consecutive empty comments. We think that it might make sense to only alert on the first empty line in this case, examples shown below:

#           <--- alert
#
my_var = 5
#           <--- alert
#
#           <--- alert
#
# A cat
#           <--- alert
#

What are you thoughts?

Yes, the second example should be:

#           <--- alert
#
# A cat
#           
#

Yes, the second one is fine.

Could you elaborate on this? Did you mean we shouldn't alert on my second example because there is actual content within the block of comments? I thought empty comments are only allowed if they are wrapped around with actual content like the example you gave previously. Thanks

@Elton-Lin updated, sorry. I have to read more carefully 馃檪

Thanks for the update. Just to be extra sure, if we only alert on the first line for my second example, does it imply the following case is valid? (I'm guessing no) or we would still alert line 2. (essentially we focus on one block of comments at a time, so there will only be one alert for a block of comments, if needed)

# A cat
#           <--- alert or not
#

Yes, this should also alert.

For writing unit tests under tests/test_visitors/test_tokenize/test_comments/, we are wondering if we need to assert the line number of the alert besides confirming the correct violation is created. If so, what would be the best way to do that ? (extracting the line number of the violation and assert with the expected one)

No, we don't usually assert the line number. We just assert that violation is there.

Thanks for the answer. We are pretty close to having a complete solution, but we are currently failing a style rule about code complexity.
Edited: We were actually able to simply the code enough to get pass that though it also deteriorates readability. We will continue to strive to meet both needs.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

orsinium picture orsinium  路  3Comments

sobolevn picture sobolevn  路  3Comments

orsinium picture orsinium  路  5Comments

sobolevn picture sobolevn  路  4Comments

sobolevn picture sobolevn  路  3Comments