From d253e189db8d69dff9522808a8b80bfc4f2df728 Mon Sep 17 00:00:00 2001 From: herr kaste Date: Sun, 4 Feb 2018 20:44:52 +0100 Subject: [PATCH 01/11] Reposition W291 trailing WS warning --- linter.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/linter.py b/linter.py index 5ed7ed7..3c5d51d 100644 --- a/linter.py +++ b/linter.py @@ -62,3 +62,11 @@ def split_match(self, match): col = None return match, line, col, error, warning, message, near + + def reposition_match(self, line, col, m, vv): + code = m.error or m.warning + if code == 'W291': + start, end = vv.full_line(line) + return (line, col, end - start - 1) + + return super().reposition_match(line, col, m, vv) From c545b2cac93e18be11efeacad28bb0d7e0d4bef8 Mon Sep 17 00:00:00 2001 From: herr kaste Date: Sun, 4 Feb 2018 20:51:43 +0100 Subject: [PATCH 02/11] Reposition W293 --- linter.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/linter.py b/linter.py index 3c5d51d..b37216a 100644 --- a/linter.py +++ b/linter.py @@ -63,10 +63,10 @@ def split_match(self, match): return match, line, col, error, warning, message, near - def reposition_match(self, line, col, m, vv): + def reposition_match(self, line, col, m, virtual_view): code = m.error or m.warning - if code == 'W291': - start, end = vv.full_line(line) - return (line, col, end - start - 1) + if code in ('W291', 'W293'): + txt = virtual_view.select_line(line).rstrip('\n') + return (line, col, len(txt)) - return super().reposition_match(line, col, m, vv) + return super().reposition_match(line, col, m, virtual_view) From be72db9af3cd1abc384d46941447327363f9bc3c Mon Sep 17 00:00:00 2001 From: herr kaste Date: Sun, 4 Feb 2018 21:10:25 +0100 Subject: [PATCH 03/11] Reposition E1x indentation errors --- linter.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/linter.py b/linter.py index b37216a..629db35 100644 --- a/linter.py +++ b/linter.py @@ -68,5 +68,7 @@ def reposition_match(self, line, col, m, virtual_view): 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) return super().reposition_match(line, col, m, virtual_view) From c2553f81b6d14f3a94c5c7399d88009d3d90a743 Mon Sep 17 00:00:00 2001 From: herr kaste Date: Sun, 4 Feb 2018 21:49:59 +0100 Subject: [PATCH 04/11] Capture WS for E2 errors --- linter.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/linter.py b/linter.py index 629db35..5a3315a 100644 --- a/linter.py +++ b/linter.py @@ -13,6 +13,9 @@ from SublimeLinter.lint import PythonLinter +import re + +CAPTURE_WS = re.compile('(\s+)') class Flake8(PythonLinter): @@ -70,5 +73,11 @@ def reposition_match(self, line, col, m, virtual_view): 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) return super().reposition_match(line, col, m, virtual_view) From a3430994485c7ee0bb69f89af8d1c71eb18375bd Mon Sep 17 00:00:00 2001 From: herr kaste Date: Sun, 4 Feb 2018 21:57:13 +0100 Subject: [PATCH 05/11] Reposition E303 (blank lines) errors --- linter.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/linter.py b/linter.py index 5a3315a..d6811ee 100644 --- a/linter.py +++ b/linter.py @@ -79,5 +79,11 @@ def reposition_match(self, line, col, m, virtual_view): if match is not None: length = len(match.group(1)) return (line, col, col + length) + if code == 'E303': + match = re.match('E303 too many blank lines \((\d+)', m.message) + if match is not None: + count = int(match.group(1)) + print(count) + return (line - (count - 1), 0, count - 1) return super().reposition_match(line, col, m, virtual_view) From ee7260f8c3f935cad410119979dd62e9c8973299 Mon Sep 17 00:00:00 2001 From: herr kaste Date: Wed, 7 Feb 2018 16:19:55 +0100 Subject: [PATCH 06/11] Ty, pydocstyle, you were awesome. --- .travis.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index f2a3b72..5d31db5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,8 +11,6 @@ matrix: install: - pip install flake8 - - pip install pydocstyle script: - flake8 - - pydocstyle From 24e40ac2e08834255891e481229cbcd4ed77ce0a Mon Sep 17 00:00:00 2001 From: herr kaste Date: Tue, 13 Feb 2018 09:39:09 +0100 Subject: [PATCH 07/11] Remove print statement and WS --- linter.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/linter.py b/linter.py index d6811ee..c798bcd 100644 --- a/linter.py +++ b/linter.py @@ -67,23 +67,27 @@ def split_match(self, match): 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 == 'E303': match = re.match('E303 too many blank lines \((\d+)', m.message) if match is not None: count = int(match.group(1)) - print(count) return (line - (count - 1), 0, count - 1) return super().reposition_match(line, col, m, virtual_view) From 90ade5c7aa828c06a275c90409ce8c98f49c9ccf Mon Sep 17 00:00:00 2001 From: herr kaste Date: Tue, 13 Feb 2018 11:16:35 +0100 Subject: [PATCH 08/11] Fix indentation error --- linter.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/linter.py b/linter.py index c798bcd..2659d5e 100644 --- a/linter.py +++ b/linter.py @@ -88,6 +88,6 @@ def reposition_match(self, line, col, m, virtual_view): match = re.match('E303 too many blank lines \((\d+)', m.message) if match is not None: count = int(match.group(1)) - return (line - (count - 1), 0, count - 1) + return (line - (count - 1), 0, count - 1) return super().reposition_match(line, col, m, virtual_view) From 5b9c45cdb3bc37b6b7a00aeac925038e17985e35 Mon Sep 17 00:00:00 2001 From: herr kaste Date: Tue, 13 Feb 2018 11:23:19 +0100 Subject: [PATCH 09/11] Fix E303 regex --- linter.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/linter.py b/linter.py index 2659d5e..b882ac8 100644 --- a/linter.py +++ b/linter.py @@ -85,7 +85,7 @@ def reposition_match(self, line, col, m, virtual_view): return (line, col, col + length) if code == 'E303': - match = re.match('E303 too many blank lines \((\d+)', m.message) + match = re.match('too many blank lines \((\d+)', m.message) if match is not None: count = int(match.group(1)) return (line - (count - 1), 0, count - 1) From af3dd93343fdb4f6124c6930ecd37365de7045f8 Mon Sep 17 00:00:00 2001 From: herr kaste Date: Sat, 17 Feb 2018 16:51:16 +0100 Subject: [PATCH 10/11] Fix: Must rstrip() message for my regex to match E303 errors --- linter.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/linter.py b/linter.py index b882ac8..68704e2 100644 --- a/linter.py +++ b/linter.py @@ -85,7 +85,7 @@ def reposition_match(self, line, col, m, virtual_view): return (line, col, col + length) if code == 'E303': - match = re.match('too many blank lines \((\d+)', m.message) + 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) From a78cf3421999a38c6b53c7e73447872dbfb9e1a8 Mon Sep 17 00:00:00 2001 From: herr kaste Date: Mon, 19 Feb 2018 11:00:29 +0100 Subject: [PATCH 11/11] Catch E302 error --- linter.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/linter.py b/linter.py index 68704e2..d5b8453 100644 --- a/linter.py +++ b/linter.py @@ -84,6 +84,9 @@ def reposition_match(self, line, col, m, virtual_view): 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: