mirror of
https://github.com/PyCQA/flake8.git
synced 2026-04-05 20:46:54 +00:00
Refactor processor and file checker some more
This commit is contained in:
parent
f7a8b7ade7
commit
36fb688f97
3 changed files with 85 additions and 65 deletions
|
|
@ -223,16 +223,19 @@ class FileChecker(object):
|
|||
LOG.debug('Logical line: "%s"', logical_line.rstrip())
|
||||
|
||||
for plugin in self.checks.logical_line_plugins:
|
||||
result = self.run_check(plugin, logical_line=logical_line)
|
||||
if result is not None:
|
||||
column_offset, text = result
|
||||
results = self.run_check(plugin, logical_line=logical_line) or ()
|
||||
for offset, text in results:
|
||||
offset = find_offset(offset, mapping)
|
||||
line_number, column_offset = offset
|
||||
self.report(
|
||||
error_code=None,
|
||||
line_number=self.processor.line_number,
|
||||
line_number=line_number,
|
||||
column=column_offset,
|
||||
text=text,
|
||||
)
|
||||
|
||||
self.processor.next_logical_line()
|
||||
|
||||
def run_physical_checks(self, physical_line):
|
||||
"""Run all checks for a given physical line."""
|
||||
for plugin in self.checks.physical_line_plugins:
|
||||
|
|
@ -325,3 +328,14 @@ class FileChecker(object):
|
|||
with self.processor.inside_multiline(line_number=line_no):
|
||||
for line in self.processor.split_line(token):
|
||||
self.run_physical_checks(line + '\n')
|
||||
|
||||
|
||||
def find_offset(offset, mapping):
|
||||
"""Find the offset tuple for a single offset."""
|
||||
if isinstance(offset, tuple):
|
||||
return offset
|
||||
|
||||
for token_offset, position in mapping:
|
||||
if offset <= token_offset:
|
||||
break
|
||||
return (position[0], position[1] + offset - token_offset)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue