summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAnthony Sottile <asottile@umich.edu>2018-12-10 17:47:05 +0000
committerAnthony Sottile <asottile@umich.edu>2018-12-10 17:47:05 +0000
commitcad4e5be6fd0bf025d2789f08fb6c9ba832e782f (patch)
tree5a987994369ff6ff22cc9191a4faec4fb5ad00c8 /src
parent9a9237a3386acb4a28b3eeb237e24cce973f17f6 (diff)
parent2803d0a81045fb144cd874807809d5b6fcb91786 (diff)
downloadflake8-cad4e5be6fd0bf025d2789f08fb6c9ba832e782f.tar.gz
Merge branch 'physical-line-multiple' into 'master'
Allow physical checks to return multiple results See merge request pycqa/flake8!269
Diffstat (limited to 'src')
-rw-r--r--src/flake8/checker.py39
1 files changed, 28 insertions, 11 deletions
diff --git a/src/flake8/checker.py b/src/flake8/checker.py
index 8b1655b..b0e0644 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.