Skip to content
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

BaseReport Messages Include Error Row and Column Info #852

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions pycodestyle.py
Original file line number Diff line number Diff line change
Expand Up @@ -2134,7 +2134,7 @@ def __init__(self, options):
self.elapsed = 0
self.total_errors = 0
self.counters = dict.fromkeys(self._benchmark_keys, 0)
self.messages = {}
self.messages = []

def start(self):
"""Start the timer."""
Expand Down Expand Up @@ -2167,7 +2167,7 @@ def error(self, line_number, offset, text, check):
self.counters[code] += 1
else:
self.counters[code] = 1
self.messages[code] = text[5:]
self.messages.append((line_number, offset, code, text[5:]))
# Don't care about expected errors or warnings
if code in self.expected:
return
Expand All @@ -2183,8 +2183,7 @@ def get_file_results(self):

def get_count(self, prefix=''):
"""Return the total count of errors and warnings."""
return sum(self.counters[key]
for key in self.messages if key.startswith(prefix))
return len(self.messages)

def get_statistics(self, prefix=''):
"""Get statistics for message codes that start with the prefix.
Expand All @@ -2194,8 +2193,8 @@ def get_statistics(self, prefix=''):
prefix='W' matches all warnings
prefix='E4' matches all errors that have to do with imports
"""
return ['%-7s %s %s' % (self.counters[key], key, self.messages[key])
for key in sorted(self.messages) if key.startswith(prefix)]
return ['%-7s %s %s' % (self.counters[key[2]], key[2], key[3])
for key in sorted(self.messages) if key[2].startswith(prefix)]

def print_statistics(self, prefix=''):
"""Print overall statistics (number of errors and warnings)."""
Expand Down
2 changes: 1 addition & 1 deletion testsuite/test_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def test_own_dog_food(self):
os.path.join(ROOT_DIR, 'setup.py')]
report = self._style.init_report(pycodestyle.StandardReport)
report = self._style.check_files(files)
self.assertEqual(list(report.messages.keys()), ['W504'],
self.assertEqual(report.messages[0][2], 'W504',
msg='Failures: %s' % report.messages)


Expand Down