PyCQA / pycodestyle

Simple Python style checker in one Python file
https://pycodestyle.pycqa.org
Other
5.03k stars 754 forks source link

`indent-size` not considered when computing length of tab-indented lines. #1189

Open Nuno-Mota opened 1 year ago

Nuno-Mota commented 1 year ago

Hi.

It seems like the indent-size option is not considered for the computation of line-length (looking at the code appears to confirm my suspicion). This means that there can be a significant number of false negatives for tab-indented lines.

This was tested for pycodestyle 2.10.0 and pycodestyle 2.11.0.

MWE: All non-ignored test file's lines are longer than the maximum line length, when taking into account the indent-size. However, only 2 of them are flagged as such. Each tab counts only 1 space, instead of indent-size spaces.

tox.ini

[pycodestyle]
max-line-length = 5
indent-size = 4
show-source = true
ignore=E261, W191

Test file

if True: # noqa: E501
    # aa
    # aaa
    if True: # noqa: E501
        # a
        # aa

Pycodestyle's output

pycodestyle test.py
test.py:3:6: E501 line too long (6 > 5 characters)
    # aaa
        ^
test.py:6:6: E501 line too long (6 > 5 characters)
        # aa
           ^
✗ - status code 1
Paebbels commented 9 months ago

Looks like line length computation is still an unknown secret algorithm in 2024 because another tool doesn't get it right - especially it it claims be be a style checker ...

Any plans to get this issue triaged and worked on?

asottile commented 9 months ago

feel free to send a patch instead of snark

Paebbels commented 9 months ago

I believe I can provide a patch after I reading https://pycodestyle.pycqa.org/en/latest/developer.html#contribute

Let me do some tests on how to solve it efficiently, as it touches every byte.

Paebbels commented 8 months ago

@asottile I checked on available options to pycodestyle. It misses a tab-size parameter; only indent-size is available. Such a parameter is needed to implement the correct calculation if whitespace width.

Are you going to provide such a parameter, or is it up to me to add this with my PR?
(So solving the problem and adding new CLI options.)

--indent-size=n      set how many spaces make up an indent (default: 4)

Source: https://pycodestyle.pycqa.org/en/latest/intro.html#configuration

sigmavirus24 commented 8 months ago

@Paebbels honestly you're attitude or the attitude you convey with your choice of language has biased me against any improvement here since 99% of people writing Python use spaces. If you want traction in this assume you're doing all the work and we'll do our best to review it, assuming you also improve your behavior. If you seem to think another option is necessary at it with a very detailed justification because I don't expect this should require what you are proposing (and thus neither Anthony nor I will be providing that for you)