|
1 | 1 | from SublimeLinter.lint import PythonLinter |
| 2 | +import re |
| 3 | + |
| 4 | +CAPTURE_WS = re.compile('(\s+)') |
2 | 5 |
|
3 | 6 |
|
4 | 7 | class Flake8(PythonLinter): |
@@ -47,3 +50,32 @@ def split_match(self, match): |
47 | 50 | col = None |
48 | 51 |
|
49 | 52 | return match, line, col, error, warning, message, near |
| 53 | + |
| 54 | + def reposition_match(self, line, col, m, virtual_view): |
| 55 | + """Reposition white-space errors.""" |
| 56 | + code = m.error or m.warning |
| 57 | + |
| 58 | + if code in ('W291', 'W293'): |
| 59 | + txt = virtual_view.select_line(line).rstrip('\n') |
| 60 | + return (line, col, len(txt)) |
| 61 | + |
| 62 | + if code.startswith('E1'): |
| 63 | + return (line, 0, col) |
| 64 | + |
| 65 | + if code.startswith('E2'): |
| 66 | + txt = virtual_view.select_line(line).rstrip('\n') |
| 67 | + match = CAPTURE_WS.match(txt[col:]) |
| 68 | + if match is not None: |
| 69 | + length = len(match.group(1)) |
| 70 | + return (line, col, col + length) |
| 71 | + |
| 72 | + if code == 'E302': |
| 73 | + return line - 1, 0, 1 |
| 74 | + |
| 75 | + if code == 'E303': |
| 76 | + match = re.match('too many blank lines \((\d+)', m.message.strip()) |
| 77 | + if match is not None: |
| 78 | + count = int(match.group(1)) |
| 79 | + return (line - (count - 1), 0, count - 1) |
| 80 | + |
| 81 | + return super().reposition_match(line, col, m, virtual_view) |
0 commit comments