From ddefdb0ba898251fbb7ff9b1e125e677ff86968f Mon Sep 17 00:00:00 2001 From: alin23 Date: Wed, 31 Aug 2016 17:24:47 +0300 Subject: [PATCH 1/2] Fix 'lines_list referenced before assignment' error --- commands/next_lint_error.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/commands/next_lint_error.py b/commands/next_lint_error.py index e378e1e7..a3578c56 100644 --- a/commands/next_lint_error.py +++ b/commands/next_lint_error.py @@ -57,16 +57,25 @@ def _harvest_next(self) -> int: self.window.active_view().sel()[0].begin() ) lines = set([]) + next_change = None vid = self.window.active_view().id() for error_type in ['ERRORS', 'WARNINGS', 'VIOLATIONS']: for line, _ in ANACONDA[error_type].get(vid, {}).items(): lines.add(int(line)) - lines = set(sorted(lines)) + lines = list(set(sorted(lines))) if not len(lines): return None - if cur_line and list(lines)[-1] > cur_line: - lines_list = [l for l in lines if l > cur_line] + if not cur_line: + return None + + if lines[-1] > cur_line: + for l in lines: + if l > cur_line: + next_change = l + break + else: + next_change = lines[0] - return lines_list[0] + return next_change From 513bd67d34f641096df8bc55b8268fdfd72b230d Mon Sep 17 00:00:00 2001 From: alin23 Date: Wed, 31 Aug 2016 22:01:39 +0300 Subject: [PATCH 2/2] Cleaner approach --- commands/next_lint_error.py | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/commands/next_lint_error.py b/commands/next_lint_error.py index a3578c56..58b81251 100644 --- a/commands/next_lint_error.py +++ b/commands/next_lint_error.py @@ -57,25 +57,17 @@ def _harvest_next(self) -> int: self.window.active_view().sel()[0].begin() ) lines = set([]) - next_change = None vid = self.window.active_view().id() for error_type in ['ERRORS', 'WARNINGS', 'VIOLATIONS']: for line, _ in ANACONDA[error_type].get(vid, {}).items(): lines.add(int(line)) - lines = list(set(sorted(lines))) + lines = set(sorted(lines)) if not len(lines): return None - if not cur_line: - return None - - if lines[-1] > cur_line: - for l in lines: - if l > cur_line: - next_change = l - break - else: - next_change = lines[0] + lines_list = [] + if cur_line and list(lines)[-1] > cur_line: + lines_list = [l for l in lines if l > cur_line] - return next_change + return lines_list[0] if len(lines_list) > 0 else lines.pop()