Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 23 additions & 4 deletions linter.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
from SublimeLinter.lint import PythonLinter, util, const
from SublimeLinter.lint import PythonLinter
from SublimeLinter.lint.linter import TransientError


class Pydocstyle(PythonLinter):
cmd = 'pydocstyle'
regex = r'^.+?:(?P<line>\d+).*:\r?\n\s*(?P<warning>D\d{3}):\s(?P<message>.+)$'
regex = r'''(?x)
^(?P<filename>.+):(?P<line>\d+)[^`\n]*(`(?P<near>.+)`)?.*:\n
\s*(?P<warning>D\d{3}):\s(?P<message>.+)
'''
multiline = True
default_type = const.WARNING
error_stream = util.STREAM_BOTH
line_col_base = (1, 0) # uses one-based line and zero-based column numbers
tempfile_suffix = 'py'
defaults = {
Expand All @@ -19,3 +21,20 @@ class Pydocstyle(PythonLinter):
'--convention=': '',
'--ignore-decorators=': ''
}

def on_stderr(self, stderr):
# For a doc style tester, parse errors can be treated 'transient',
# for the benefit, that we do not re-draw, but keep the errors from
# the last run.
if 'Cannot parse file' in stderr:
raise TransientError('Parse error.')

return super().on_stderr(stderr)

def split_match(self, match):
match = super().split_match(match)
if match.near and '__init__' not in match.message:
return match._replace(
message='{} `{}`'.format(match.message, match.near))

return match