forked from SublimeLinter/SublimeLinter-pydocstyle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlinter.py
85 lines (73 loc) · 2.48 KB
/
linter.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#
# linter.py
# Linter for SublimeLinter3, a code checking framework for Sublime Text 3
#
# Written by Aparajita Fishman
# Copyright (c) 2015-2016 The SublimeLinter Community
# Copyright (c) 2013-2014 Aparajita Fishman
#
# License: MIT
#
"""This module exports the Pydocstyle plugin linter class."""
from contextlib import contextmanager
from functools import partial
from SublimeLinter.lint import PythonLinter, highlight, persist, util
class Pydocstyle(PythonLinter):
"""Provides an interface to the pydocstyle python module/script."""
syntax = 'python'
cmd = 'pydocstyle@python'
version_args = '--version'
version_re = r'(?P<version>\d+\.\d+\.\d+)'
version_requirement = '>= 0.3.0'
regex = r'^.+?:(?P<line>\d+).*:\r?\n\s*(?P<message>.+)$'
multiline = True
default_type = highlight.WARNING
error_stream = util.STREAM_BOTH
line_col_base = (1, 0) # uses one-based line and zero-based column numbers
tempfile_suffix = 'py'
module = 'pydocstyle'
defaults = {
'--add-ignore=': '',
'--add-select=': '',
'--ignore=': '',
'--select=': '',
'--config=': '',
'--convention=': '',
'--ignore-decorators=': ''
}
inline_overrides = [
'add-ignore',
'add-select',
'ignore',
'select',
'config',
'convention',
'ignore-decorators'
]
def check(self, code, filename):
"""Run pydocstyle on code and return the output."""
args = self.build_args(self.get_view_settings(inline=True))
if persist.settings.get('debug'):
persist.printf('{} args: {}'.format(self.name, args))
conf = self.module.config.ConfigurationParser()
with partialpatched(conf,
'_parse_args',
args=args + [filename],
values=None):
conf.parse()
errors = []
for fname, checked_codes, ignore_decorators in \
conf.get_files_to_check():
errors.extend(
self.module.check(
[fname],
select=checked_codes,
ignore_decorators=ignore_decorators))
return errors
@contextmanager
def partialpatched(obj, name, **kwargs):
"""Monkey patch instance method with partial application."""
pre_patched_value = getattr(obj, name)
setattr(obj, name, partial(pre_patched_value, **kwargs))
yield
setattr(obj, name, pre_patched_value)