Skip to content

Commit

Permalink
Merge pull request #40 from SublimeLinter/fix-39
Browse files Browse the repository at this point in the history
  • Loading branch information
kaste authored Jul 16, 2022
2 parents e4686c8 + 0226286 commit cbfa014
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions linter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -47,8 +45,7 @@ class Annotations(Linter):

# We use this to do the matching
mark_regex_template = (
r'(?P<word>(?P<info>{infos})|(?P<warning>{warnings})|(?P<error>{errors})):?\s*'
r'(?P<message>.*)'
r'(?P<word>{}):?\s*'r'(?P<message>.*)'
)

# Words to look for
Expand All @@ -71,14 +68,21 @@ 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_'])

for region in regions:
region_text = self.view.substr(region)
lines = region_text.splitlines(keepends=True)
Expand All @@ -90,7 +94,12 @@ def find_errors(self, output):

message = match.group('message') or '<no message>'
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(
error_type_
for error_type_ in ('errors', 'warnings', 'infos')
if error_type_ in match_groups
)

row, col = self.view.rowcol(offset + match.start())
text_to_mark = match.group() if self.settings.get('mark_message') else word
Expand Down

0 comments on commit cbfa014

Please sign in to comment.