forked from astral-sh/ruff
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Respect tab width in line-length heuristic (astral-sh#6491)
## 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.
- Loading branch information
1 parent
5c730a5
commit cf9e652
Showing
8 changed files
with
294 additions
and
173 deletions.
There are no files selected for viewing
25 changes: 15 additions & 10 deletions
25
crates/ruff/resources/test/fixtures/pycodestyle/E501_2.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,16 @@ | ||
a = """ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A6""" | ||
a = """ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A6""" | ||
# aaaa | ||
# aaaaa | ||
# a | ||
# a | ||
# aa | ||
# aaa | ||
# aaaa | ||
# a | ||
# aa | ||
# aaa | ||
|
||
b = """ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A6""" | ||
b = """ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A6""" | ||
|
||
c = """2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A6""" | ||
c = """2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A6""" | ||
|
||
d = """💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A6""" | ||
d = """💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A6""" | ||
if True: # noqa: E501 | ||
[12] | ||
[12 ] | ||
[1,2] | ||
[1, 2] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 34 additions & 39 deletions
73
crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__tab_size_1.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,51 @@ | ||
--- | ||
source: crates/ruff/src/rules/pycodestyle/mod.rs | ||
--- | ||
E501_2.py:1:81: E501 Line too long (89 > 88 characters) | ||
E501_2.py:2:7: E501 Line too long (7 > 6 characters) | ||
| | ||
1 | a = """ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A6""" | ||
| ^ E501 | ||
2 | a = """ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A6""" | ||
1 | # aaaa | ||
2 | # aaaaa | ||
| ^ E501 | ||
3 | # a | ||
4 | # a | ||
| | ||
|
||
E501_2.py:2:81: E501 Line too long (89 > 88 characters) | ||
E501_2.py:3:7: E501 Line too long (7 > 6 characters) | ||
| | ||
1 | a = """ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A6""" | ||
2 | a = """ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A6""" | ||
| ^ E501 | ||
3 | | ||
4 | b = """ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A6""" | ||
1 | # aaaa | ||
2 | # aaaaa | ||
3 | # a | ||
| ^ E501 | ||
4 | # a | ||
5 | # aa | ||
| | ||
|
||
E501_2.py:4:81: E501 Line too long (89 > 88 characters) | ||
E501_2.py:7:7: E501 Line too long (7 > 6 characters) | ||
| | ||
2 | a = """ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A6""" | ||
3 | | ||
4 | b = """ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A6""" | ||
| ^ E501 | ||
5 | b = """ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A6""" | ||
5 | # aa | ||
6 | # aaa | ||
7 | # aaaa | ||
| ^ E501 | ||
8 | # a | ||
9 | # aa | ||
| | ||
|
||
E501_2.py:5:81: E501 Line too long (89 > 88 characters) | ||
| | ||
4 | b = """ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A6""" | ||
5 | b = """ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A6""" | ||
| ^ E501 | ||
6 | | ||
7 | c = """2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A6""" | ||
| | ||
|
||
E501_2.py:7:82: E501 Line too long (89 > 88 characters) | ||
| | ||
5 | b = """ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A6""" | ||
6 | | ||
7 | c = """2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A6""" | ||
| ^ E501 | ||
8 | c = """2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A6""" | ||
| | ||
E501_2.py:10:7: E501 Line too long (7 > 6 characters) | ||
| | ||
8 | # a | ||
9 | # aa | ||
10 | # aaa | ||
| ^ E501 | ||
11 | | ||
12 | if True: # noqa: E501 | ||
| | ||
|
||
E501_2.py:10:82: E501 Line too long (89 > 88 characters) | ||
E501_2.py:16:7: E501 Line too long (7 > 6 characters) | ||
| | ||
8 | c = """2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A6""" | ||
9 | | ||
10 | d = """💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A6""" | ||
| ^ E501 | ||
11 | d = """💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A6""" | ||
14 | [12 ] | ||
15 | [1,2] | ||
16 | [1, 2] | ||
| ^ E501 | ||
| | ||
|
||
|
106 changes: 70 additions & 36 deletions
106
crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__tab_size_2.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,90 @@ | ||
--- | ||
source: crates/ruff/src/rules/pycodestyle/mod.rs | ||
--- | ||
E501_2.py:1:81: E501 Line too long (89 > 88 characters) | ||
E501_2.py:2:7: E501 Line too long (7 > 6 characters) | ||
| | ||
1 | a = """ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A6""" | ||
| ^ E501 | ||
2 | a = """ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A6""" | ||
1 | # aaaa | ||
2 | # aaaaa | ||
| ^ E501 | ||
3 | # a | ||
4 | # a | ||
| | ||
|
||
E501_2.py:2:81: E501 Line too long (89 > 88 characters) | ||
E501_2.py:3:7: E501 Line too long (7 > 6 characters) | ||
| | ||
1 | a = """ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A6""" | ||
2 | a = """ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A6""" | ||
| ^ E501 | ||
3 | | ||
4 | b = """ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A6""" | ||
1 | # aaaa | ||
2 | # aaaaa | ||
3 | # a | ||
| ^ E501 | ||
4 | # a | ||
5 | # aa | ||
| | ||
|
||
E501_2.py:4:81: E501 Line too long (89 > 88 characters) | ||
E501_2.py:6:6: E501 Line too long (7 > 6 characters) | ||
| | ||
2 | a = """ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A6""" | ||
3 | | ||
4 | b = """ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A6""" | ||
| ^ E501 | ||
5 | b = """ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A6""" | ||
4 | # a | ||
5 | # aa | ||
6 | # aaa | ||
| ^ E501 | ||
7 | # aaaa | ||
8 | # a | ||
| | ||
|
||
E501_2.py:5:81: E501 Line too long (89 > 88 characters) | ||
E501_2.py:7:6: E501 Line too long (8 > 6 characters) | ||
| | ||
4 | b = """ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A6""" | ||
5 | b = """ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A6""" | ||
| ^ E501 | ||
6 | | ||
7 | c = """2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A6""" | ||
5 | # aa | ||
6 | # aaa | ||
7 | # aaaa | ||
| ^^ E501 | ||
8 | # a | ||
9 | # aa | ||
| | ||
|
||
E501_2.py:7:82: E501 Line too long (89 > 88 characters) | ||
| | ||
5 | b = """ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A6""" | ||
6 | | ||
7 | c = """2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A6""" | ||
| ^ E501 | ||
8 | c = """2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A6""" | ||
| | ||
E501_2.py:8:5: E501 Line too long (7 > 6 characters) | ||
| | ||
6 | # aaa | ||
7 | # aaaa | ||
8 | # a | ||
| ^ E501 | ||
9 | # aa | ||
10 | # aaa | ||
| | ||
|
||
E501_2.py:9:5: E501 Line too long (8 > 6 characters) | ||
| | ||
7 | # aaaa | ||
8 | # a | ||
9 | # aa | ||
| ^^ E501 | ||
10 | # aaa | ||
| | ||
|
||
E501_2.py:10:5: E501 Line too long (9 > 6 characters) | ||
| | ||
8 | # a | ||
9 | # aa | ||
10 | # aaa | ||
| ^^^ E501 | ||
11 | | ||
12 | if True: # noqa: E501 | ||
| | ||
|
||
E501_2.py:14:6: E501 Line too long (7 > 6 characters) | ||
| | ||
12 | if True: # noqa: E501 | ||
13 | [12] | ||
14 | [12 ] | ||
| ^ E501 | ||
15 | [1,2] | ||
16 | [1, 2] | ||
| | ||
|
||
E501_2.py:10:82: E501 Line too long (89 > 88 characters) | ||
E501_2.py:16:6: E501 Line too long (8 > 6 characters) | ||
| | ||
8 | c = """2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A6""" | ||
9 | | ||
10 | d = """💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A6""" | ||
| ^ E501 | ||
11 | d = """💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A67ß9💣2ℝ4A6""" | ||
14 | [12 ] | ||
15 | [1,2] | ||
16 | [1, 2] | ||
| ^^ E501 | ||
| | ||
|
||
|
Oops, something went wrong.