Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Nuno-Mota opened this issue Aug 9, 2023 · 5 comments
Open

Comments

@Nuno-Mota
Copy link

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
Copy link

Paebbels commented Jan 9, 2024

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
Copy link
Member

asottile commented Jan 9, 2024

feel free to send a patch instead of snark

@Paebbels
Copy link

Paebbels commented Jan 9, 2024

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
Copy link

Paebbels commented Feb 3, 2024

@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
Copy link
Member

@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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants