Skip to content

Commit

Permalink
Add pragma comment to line length ignores (#463)
Browse files Browse the repository at this point in the history
* Add pragma comment to line length ignores

* Update b950.py

* Update bugbear.py

* Update test_bugbear.py
  • Loading branch information
Dreamsorcerer authored Feb 25, 2024
1 parent 6bf907c commit fa48bc1
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
4 changes: 3 additions & 1 deletion bugbear.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,9 @@ def gen_line_based_checks(self):
The following simple checks are based on the raw lines, not the AST.
"""
noqa_type_ignore_regex = re.compile(r"#\s*(noqa|type:\s*ignore)[^#\r\n]*$")
noqa_type_ignore_regex = re.compile(
r"#\s*(noqa|type:\s*ignore|pragma:)[^#\r\n]*$"
)
for lineno, line in enumerate(self.lines, start=1):
# Special case: ignore long shebang (following pycodestyle).
if lineno == 1 and line.startswith("#!"):
Expand Down
1 change: 1 addition & 0 deletions tests/b950.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"https://foooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo.com # noqa"
"https://foooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo.com # type: ignore"
"https://foooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo.com # noqa: F401"
"https://foooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo.com # pragma: no cover"
"https://foooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo.com#noqa:F401, B950"
"https://foooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo.com # type: ignore[some-code]"
"https://foooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo.com # type: ignore[some-code]"
Expand Down
6 changes: 3 additions & 3 deletions tests/test_bugbear.py
Original file line number Diff line number Diff line change
Expand Up @@ -894,8 +894,8 @@ def test_b950(self):
B950(12, 103, vars=(103, 79)),
B950(14, 103, vars=(103, 79)),
B950(21, 97, vars=(97, 79)),
B950(35, 104, vars=(104, 79)),
B950(36, 104, vars=(104, 79)),
B950(37, 104, vars=(104, 79)),
),
)

Expand All @@ -912,8 +912,8 @@ def test_b9_select(self):
B950(12, 103, vars=(103, 79)),
B950(14, 103, vars=(103, 79)),
B950(21, 97, vars=(97, 79)),
B950(35, 104, vars=(104, 79)),
B950(36, 104, vars=(104, 79)),
B950(37, 104, vars=(104, 79)),
),
)

Expand All @@ -932,8 +932,8 @@ def test_b9_extend_select(self):
B950(12, 103, vars=(103, 79)),
B950(14, 103, vars=(103, 79)),
B950(21, 97, vars=(97, 79)),
B950(35, 104, vars=(104, 79)),
B950(36, 104, vars=(104, 79)),
B950(37, 104, vars=(104, 79)),
),
)

Expand Down

0 comments on commit fa48bc1

Please sign in to comment.