diff options
| author | Tom Milligan <tommilligan@users.noreply.github.com> | 2018-12-05 22:04:32 +0000 |
|---|---|---|
| committer | Tom Milligan <tom@reinfer.io> | 2018-12-10 17:42:53 +0000 |
| commit | 2803d0a81045fb144cd874807809d5b6fcb91786 (patch) | |
| tree | fd9c281830b00b3bb6a0f7a1807756c79ef19409 /src | |
| parent | 93ad9617b0a192836cbc9a591b5abe74e2c85ba7 (diff) | |
| download | flake8-2803d0a81045fb144cd874807809d5b6fcb91786.tar.gz | |
checker: allow physical checks to return multiple results, add tests
Diffstat (limited to 'src')
| -rw-r--r-- | src/flake8/checker.py | 39 |
1 files changed, 28 insertions, 11 deletions
diff --git a/src/flake8/checker.py b/src/flake8/checker.py index 3b97414..98c2b50 100644 --- a/src/flake8/checker.py +++ b/src/flake8/checker.py @@ -541,21 +541,38 @@ class FileChecker(object): self.processor.next_logical_line() def run_physical_checks(self, physical_line, override_error_line=None): - """Run all checks for a given physical line.""" + """Run all checks for a given physical line. + + A single physical check may return multiple errors. + """ for plugin in self.checks["physical_line_plugins"]: self.processor.update_checker_state_for(plugin) result = self.run_check(plugin, physical_line=physical_line) - if result is not None: - column_offset, text = result - error_code = self.report( - error_code=None, - line_number=self.processor.line_number, - column=column_offset, - text=text, - line=(override_error_line or physical_line), - ) - self.processor.check_physical_error(error_code, physical_line) + if result is not None: + # This is a single result if first element is an int + column_offset = None + try: + column_offset = result[0] + except (IndexError, TypeError): + pass + + if isinstance(column_offset, int): + # If we only have a single result, convert to a collection + result = (result,) + + for result_single in result: + column_offset, text = result_single + error_code = self.report( + error_code=None, + line_number=self.processor.line_number, + column=column_offset, + text=text, + line=(override_error_line or physical_line), + ) + self.processor.check_physical_error( + error_code, physical_line + ) def process_tokens(self): """Process tokens and trigger checks. |
