Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork768
Expand file tree
/
Copy pathlint.py
More file actions
105 lines (80 loc) · 3.04 KB
/
lint.py
File metadata and controls
105 lines (80 loc) · 3.04 KB
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
"""Pylama integration."""
from .environmentimportenv
from .utilsimportsilence_stderr
importos.path
frompylama.lintimportLINTERS
try:
frompylama.lint.pylama_pylintimportLinter
LINTERS['pylint']=Linter()
exceptException:# noqa
pass
defcode_check():
"""Run pylama and check current file.
:return bool:
"""
withsilence_stderr():
frompylama.coreimportrun
frompylama.configimportparse_options
ifnotenv.curbuf.name:
returnenv.stop()
linters=env.var('g:pymode_lint_checkers')
env.debug(linters)
# Fixed in v0.9.3: these two parameters may be passed as strings.
# DEPRECATE: v:0.10.0: need to be set as lists.
ifisinstance(env.var('g:pymode_lint_ignore'),str):
raiseValueError('g:pymode_lint_ignore should have a list type')
else:
ignore=env.var('g:pymode_lint_ignore')
ifisinstance(env.var('g:pymode_lint_select'),str):
raiseValueError('g:pymode_lint_select should have a list type')
else:
select=env.var('g:pymode_lint_select')
if'pep8'inlinters:
# TODO: Add a user visible deprecation warning here
env.message('pep8 linter is deprecated, please use pycodestyle.')
linters.remove('pep8')
linters.append('pycodestyle')
options=parse_options(
linters=linters,force=1,
ignore=ignore,
select=select,
)
env.debug(options)
forlinterinlinters:
opts=env.var('g:pymode_lint_options_%s'%linter,silence=True)
ifopts:
options.linters_params[linter]=options.linters_params.get(
linter, {})
options.linters_params[linter].update(opts)
path=os.path.relpath(env.curbuf.name,env.curdir)
env.debug("Start code check: ",path)
ifgetattr(options,'skip',None)andany(p.match(path)forpinoptions.skip):# noqa
env.message('Skip code checking.')
env.debug("Skipped")
returnenv.stop()
ifenv.options.get('debug'):
importlogging
frompylama.coreimportLOGGER
LOGGER.setLevel(logging.DEBUG)
errors=run(path,code='\n'.join(env.curbuf)+'\n',options=options)
env.debug("Find errors: ",len(errors))
sort_rules=env.var('g:pymode_lint_sort')
def__sort(e):
try:
returnsort_rules.index(e.get('type'))
exceptValueError:
return999
ifsort_rules:
env.debug("Find sorting: ",sort_rules)
errors=sorted(errors,key=__sort)
errors_list= []
foreinerrors:
ife.colisNone:
e.col=1
err_dict=e.to_dict()
err_dict['bufnr']=env.curbuf.number
err_dict['type']=e.etype
err_dict['text']=e.message
errors_list.append(err_dict)
env.run('g:PymodeLocList.current().extend',errors_list)
# pylama:ignore=W0212,E1103