Skip to content

Commit

Permalink
Merge pull request #78 from SublimeLinter/reposition-ws-errors
Browse files Browse the repository at this point in the history
Reposition white-space errors
  • Loading branch information
kaste authored Mar 2, 2018
2 parents 50304c3 + a78cf34 commit 938b857
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions linter.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
from SublimeLinter.lint import PythonLinter
import re

CAPTURE_WS = re.compile('(\s+)')


class Flake8(PythonLinter):
Expand Down Expand Up @@ -47,3 +50,32 @@ def split_match(self, match):
col = None

return match, line, col, error, warning, message, near

def reposition_match(self, line, col, m, virtual_view):
"""Reposition white-space errors."""
code = m.error or m.warning

if code in ('W291', 'W293'):
txt = virtual_view.select_line(line).rstrip('\n')
return (line, col, len(txt))

if code.startswith('E1'):
return (line, 0, col)

if code.startswith('E2'):
txt = virtual_view.select_line(line).rstrip('\n')
match = CAPTURE_WS.match(txt[col:])
if match is not None:
length = len(match.group(1))
return (line, col, col + length)

if code == 'E302':
return line - 1, 0, 1

if code == 'E303':
match = re.match('too many blank lines \((\d+)', m.message.strip())
if match is not None:
count = int(match.group(1))
return (line - (count - 1), 0, count - 1)

return super().reposition_match(line, col, m, virtual_view)

0 comments on commit 938b857

Please sign in to comment.