From f1e578d284fca9e75379e2ddd853b7309eab2084 Mon Sep 17 00:00:00 2001 From: herr kaste Date: Sat, 16 Jul 2022 21:33:45 +0200 Subject: [PATCH 1/4] Allow setting some error types to `null` or the empty list Fixes #39 A user might want to disable our "infos". Typically you would do so by setting `"infos": null` or `"infos": []` but this was not supported. Redo how we construct our regex and prohibit empty matching groups. --- linter.py | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/linter.py b/linter.py index 8e057df..d21f0a0 100644 --- a/linter.py +++ b/linter.py @@ -47,8 +47,7 @@ class Annotations(Linter): # We use this to do the matching mark_regex_template = ( - r'(?P(?P{infos})|(?P{warnings})|(?P{errors})):?\s*' - r'(?P.*)' + r'(?P{}):?\s*'r'(?P.*)' ) # Words to look for @@ -71,11 +70,19 @@ def run(self, cmd, code): def find_errors(self, output): # type: (str) -> Iterator[LintMatch] options = { - option: '|'.join(_escape_words(self.settings.get(option))) + option: '|'.join(_escape_words(self.settings[option])) for option in ('errors', 'warnings', 'infos') + if self.settings[option] } + if not options: + return - mark_regex = re.compile(self.mark_regex_template.format_map(options)) + mark_regex = re.compile(self.mark_regex_template.format( + "|".join( + "(?P<{}>{})".format(key, value) + for key, value in options.items() + ) + )) regions = self.view.find_by_selector(self.settings['selector_']) @@ -90,7 +97,12 @@ def find_errors(self, output): message = match.group('message') or '' word = match.group('word') - error_type = next(et for et in ('error', 'warning', 'info') if match.group(et)) + match_groups = match.groupdict() + error_type = next( + et + for et in ('errors', 'warnings', 'infos') + if et in match_groups + ) row, col = self.view.rowcol(offset + match.start()) text_to_mark = match.group() if self.settings.get('mark_message') else word From d5f0bfd57a771f4d9cdc1d25856dff885b4cd659 Mon Sep 17 00:00:00 2001 From: herr kaste Date: Sat, 16 Jul 2022 21:34:08 +0200 Subject: [PATCH 2/4] Remove unnecessary early return --- linter.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/linter.py b/linter.py index d21f0a0..6ba1a2f 100644 --- a/linter.py +++ b/linter.py @@ -24,8 +24,6 @@ def _escape_words(values): - if not values: - return for value in values: # Add \b word separator fences around the value # if it begins or ends with a word character. From e19138aca81022e8d440ca5e721fdc43585f6a82 Mon Sep 17 00:00:00 2001 From: herr kaste Date: Sat, 16 Jul 2022 22:54:27 +0200 Subject: [PATCH 3/4] WS --- linter.py | 1 - 1 file changed, 1 deletion(-) diff --git a/linter.py b/linter.py index 6ba1a2f..5d190b1 100644 --- a/linter.py +++ b/linter.py @@ -83,7 +83,6 @@ def find_errors(self, output): )) regions = self.view.find_by_selector(self.settings['selector_']) - for region in regions: region_text = self.view.substr(region) lines = region_text.splitlines(keepends=True) From 022628681ffbd1a2c896fdb5dd00873cd70914bf Mon Sep 17 00:00:00 2001 From: herr kaste Date: Sat, 16 Jul 2022 22:57:07 +0200 Subject: [PATCH 4/4] Spell out variable name --- linter.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/linter.py b/linter.py index 5d190b1..04e189a 100644 --- a/linter.py +++ b/linter.py @@ -96,9 +96,9 @@ def find_errors(self, output): word = match.group('word') match_groups = match.groupdict() error_type = next( - et - for et in ('errors', 'warnings', 'infos') - if et in match_groups + error_type_ + for error_type_ in ('errors', 'warnings', 'infos') + if error_type_ in match_groups ) row, col = self.view.rowcol(offset + match.start())