-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix: False positive on multiline conditional expressions (#122)
Catch when: > 1 hanging opening character Instead of catch when: opening character > 1
- Loading branch information
Showing
3 changed files
with
56 additions
and
2 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Conditional expression where the third part of the expression is a | ||
# multiline container | ||
bar = 0 | ||
|
||
|
||
foo = {} if bar == 1 else { | ||
"foo": 42, | ||
} | ||
|
||
|
||
foo = [] if bar == 1 else [ | ||
42, | ||
} | ||
|
||
|
||
foo = () if bar == 1 else ( | ||
42, 42, | ||
} |
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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import os | ||
|
||
from flake8.api import legacy as flake8 | ||
|
||
import pytest | ||
|
||
|
||
@pytest.fixture | ||
def conditional_expression_file_path(dummy_file_path): | ||
return f'{dummy_file_path}/conditional_expression.py' | ||
|
||
|
||
@pytest.mark.doit1 | ||
def test_js101_conditional_block(conditional_expression_file_path): | ||
"""Conditional blocks should not trigger JS101.""" | ||
style_guide = flake8.get_style_guide( | ||
select=['JS101'], | ||
) | ||
|
||
p = os.path.abspath(conditional_expression_file_path) | ||
r = style_guide.check_files([p]) | ||
|
||
assert 0 == r.total_errors | ||
|
||
|
||
def test_js102_conditional_block(conditional_expression_file_path): | ||
"""Conditional blocks should not trigger JS102.""" | ||
style_guide = flake8.get_style_guide( | ||
select=['JS102'], | ||
) | ||
|
||
p = os.path.abspath(conditional_expression_file_path) | ||
r = style_guide.check_files([p]) | ||
|
||
assert 0 == r.total_errors |