summaryrefslogtreecommitdiff
path: root/flake8
diff options
context:
space:
mode:
authorIan Cordasco <graffatcolmingov@gmail.com>2016-06-07 18:02:53 -0500
committerIan Cordasco <graffatcolmingov@gmail.com>2016-06-07 18:02:53 -0500
commit8362fa7acdf90693fa745dc3ada33406170f43bd (patch)
tree007f67c317503e26dfcabcab2283cc9b4e04295b /flake8
parent9ebaa5c69c7dc7077d1f59141a863d22e23284c0 (diff)
downloadflake8-8362fa7acdf90693fa745dc3ada33406170f43bd.tar.gz
Add distinction between reported and ignored errors
This allows us to properly exit if no errors were reported (due to, for example, # noqa).
Diffstat (limited to 'flake8')
-rw-r--r--flake8/checker.py17
-rw-r--r--flake8/main/cli.py6
-rw-r--r--flake8/style_guide.py27
3 files changed, 43 insertions, 7 deletions
diff --git a/flake8/checker.py b/flake8/checker.py
index 8b1a8ec..eefc5fd 100644
--- a/flake8/checker.py
+++ b/flake8/checker.py
@@ -163,8 +163,9 @@ class Manager(object):
def _handle_results(self, filename, results):
style_guide = self.style_guide
+ reported_results_count = 0
for (error_code, line_number, column, text, physical_line) in results:
- style_guide.handle_error(
+ reported_results_count += style_guide.handle_error(
code=error_code,
filename=filename,
line_number=line_number,
@@ -172,6 +173,7 @@ class Manager(object):
text=text,
physical_line=physical_line,
)
+ return reported_results_count
def _run_checks_from_queue(self):
LOG.info('Running checks in parallel')
@@ -221,17 +223,24 @@ class Manager(object):
]
def report(self):
+ # type: () -> (int, int)
"""Report all of the errors found in the managed file checkers.
This iterates over each of the checkers and reports the errors sorted
by line number.
+
+ :returns:
+ A tuple of the total results found and the results reported.
+ :rtype:
+ tuple(int, int)
"""
- results_found = 0
+ results_reported = results_found = 0
for checker in self.checkers:
results = sorted(checker.results, key=lambda tup: (tup[2], tup[3]))
- self._handle_results(checker.filename, results)
+ results_reported += self._handle_results(checker.filename,
+ results)
results_found += len(results)
- return results_found
+ return (results_found, results_reported)
def run_parallel(self):
"""Run the checkers in parallel."""
diff --git a/flake8/main/cli.py b/flake8/main/cli.py
index 0b50e27..93c4a14 100644
--- a/flake8/main/cli.py
+++ b/flake8/main/cli.py
@@ -403,7 +403,11 @@ class Application(object):
number of errors, warnings, and other messages found.
"""
LOG.info('Reporting errors')
- self.result_count = self.file_checker_manager.report()
+ results = self.file_checker_manager.report()
+ self.total_result_count, self.result_count = results
+ LOG.info('Found a total of %d results and reported %d',
+ self.total_result_count,
+ self.result_count)
def _run(self, argv):
# type: (Union[NoneType, List[str]]) -> NoneType
diff --git a/flake8/style_guide.py b/flake8/style_guide.py
index 6be9ff6..89890ba 100644
--- a/flake8/style_guide.py
+++ b/flake8/style_guide.py
@@ -233,8 +233,29 @@ class StyleGuide(object):
def handle_error(self, code, filename, line_number, column_number, text,
physical_line=None):
- # type: (str, str, int, int, str) -> NoneType
- """Handle an error reported by a check."""
+ # type: (str, str, int, int, str) -> int
+ """Handle an error reported by a check.
+
+ :param str code:
+ The error code found, e.g., E123.
+ :param str filename:
+ The file in which the error was found.
+ :param int line_number:
+ The line number (where counting starts at 1) at which the error
+ occurs.
+ :param int column_number:
+ The column number (where counting starts at 1) at which the error
+ occurs.
+ :param str text:
+ The text of the error message.
+ :param str physical_line:
+ The actual physical line causing the error.
+ :returns:
+ 1 if the error was reported. 0 if it was ignored. This is to allow
+ for counting of the number of errors found that were not ignored.
+ :rtype:
+ int
+ """
error = Error(code, filename, line_number, column_number, text,
physical_line)
if error.filename is None or error.filename == '-':
@@ -247,6 +268,8 @@ class StyleGuide(object):
is_included_in_diff):
self.formatter.handle(error)
self.listener.notify(error.code, error)
+ return 1
+ return 0
def add_diff_ranges(self, diffinfo):
"""Update the StyleGuide to filter out information not in the diff.