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