Skip to content

Commit 8bd8fff

Browse files
committed
Process whole output
This commit modifies process_output to process all the detected problems instead of just the first one. Fixes #2882
1 parent fd5a5a7 commit 8bd8fff

File tree

2 files changed

+27
-14
lines changed

2 files changed

+27
-14
lines changed

bears/python/PycodestyleBear.py

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -74,20 +74,22 @@ def create_arguments(
7474
def process_output(self, output, filename, file):
7575
if not output: # backwards compatible no results
7676
return
77-
result = re.match(OUTPUT_REGEX, output)
77+
result = re.findall(OUTPUT_REGEX, output)
7878
if not result: # backwards compatible no results
7979
self.warn('{}: Unexpected output {}'.format(filename, output))
8080
return
81-
line, column, message, rule = result.groups()
82-
if rule == 'E501':
83-
aspect = LineLength('py')
84-
else:
85-
aspect = None
86-
yield Result.from_values(
87-
origin='{} ({})'.format(self.name, rule),
88-
message=message,
89-
file=filename,
90-
line=int(line),
91-
column=int(column),
92-
aspect=aspect,
93-
)
81+
82+
for line, column, message, rule in result:
83+
if rule == 'E501':
84+
aspect = LineLength('py')
85+
else:
86+
aspect = None
87+
88+
yield Result.from_values(
89+
origin='{} ({})'.format(self.name, rule),
90+
message=message,
91+
file=filename,
92+
line=int(line),
93+
column=int(column),
94+
aspect=aspect,
95+
)

tests/python/PycodestyleBearTest.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ def hello():
2727
print("hello world")
2828
'''
2929

30+
multiple_error_file = '''
31+
y = 10;
32+
print( 'hello' )
33+
'''
34+
3035
file_with_very_long_line = ('def ' + 'h' * 1000 + '():\n' +
3136
' print("hello")')
3237

@@ -114,3 +119,9 @@ def test_line_length(self):
114119
'E501 line too long (106 > 30 characters)')
115120
self.assertEqual(result.origin, 'PycodestyleBear (E501)')
116121
self.assertEqual(result.aspect, LineLength('py'))
122+
123+
def test_multiple_errors(self):
124+
content = multiple_error_file.splitlines()
125+
with prepare_file(content, None) as (file, fname):
126+
with execute_bear(self.uut, fname, file) as results:
127+
self.assertTrue(len(results) == 3)

0 commit comments

Comments
 (0)