-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Unexpected line length check behaviour when line has tabs. #6425
Comments
Do you mind clarifying what behavior here is unexpected? "...then the size is recomputed taking into account..." sounds like an implementation detail as-described, and not a behavior per se. |
Of course. The issue is that tab-indented lines that are longer than the
That might be. This is simply the behaviour I was able to infer. |
Ah, I think that's a result of the performance optimization I proposed in https://github.com/astral-sh/ruff/pull/5811/files, which doesn't hold true for tabs (for which a single-byte character can be wider than one byte). |
## Summary In #5811, I suggested that we add a heuristic to the overlong-lines check such that if the line had fewer bytes than the character limit, we return early -- the idea being that a single byte per character was the "worst case". I overlooked that this isn't true for tabs -- with tabs, the "worst case" scenario is that every byte is a tab, which can have a width greater than 1. Closes #6425. ## Test Plan `cargo test` with a new fixture borrowed from the issue, plus manual testing.
## Summary In astral-sh#5811, I suggested that we add a heuristic to the overlong-lines check such that if the line had fewer bytes than the character limit, we return early -- the idea being that a single byte per character was the "worst case". I overlooked that this isn't true for tabs -- with tabs, the "worst case" scenario is that every byte is a tab, which can have a width greater than 1. Closes astral-sh#6425. ## Test Plan `cargo test` with a new fixture borrowed from the issue, plus manual testing.
Hi.
It seems like the counting of line length with tabs has an unexpected behaviour.
From what I can infer, the length of each line is first counted considering that tabs have a size of 1.
If the resulting length is equal to or greater than the
line-length
setting, then the size is recomputed taking into account thetab-size
setting.Furthermore, the line needs to have at least 1 space (as discussed in #6424).
Is this the intended behaviour? If so, is there some place that explains the reasoning behind it?
This was tested for
ruff 0.0.282
.MWE:
pyproject.toml
test file (note that github uses a default tab size of 8)
ruff's output
The text was updated successfully, but these errors were encountered: