forked from python-mode/python-mode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlint.py
More file actions
73 lines (51 loc) · 1.96 KB
/
lint.py
File metadata and controls
73 lines (51 loc) · 1.96 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
""" Pylama integration. """
from .environment import env
from .utils import silence_stderr
import os.path
def code_check():
""" Run pylama and check current file.
:return bool:
"""
with silence_stderr():
from pylama.main import parse_options
from pylama.tasks import check_path
if not env.curbuf.name:
return env.stop()
linters = env.var('g:pymode_lint_checkers')
env.debug(linters)
options = parse_options(
linters=linters, force=1,
ignore=env.var('g:pymode_lint_ignore'),
select=env.var('g:pymode_lint_select'),
)
for linter in linters:
opts = env.var('g:pymode_lint_options_%s' % linter, silence=True)
if opts:
options.linters_params[linter] = options.linters_params.get(linter, {})
options.linters_params[linter].update(opts)
env.debug(options)
path = os.path.relpath(env.curbuf.name, env.curdir)
env.debug("Start code check: ", path)
if getattr(options, 'skip', None) and any(p.match(path) for p in options.skip): # noqa
env.message('Skip code checking.')
env.debug("Skipped")
return env.stop()
if env.options.get('debug'):
from pylama.core import LOGGER, logging
LOGGER.setLevel(logging.DEBUG)
errors = check_path(
path, options=options, code='\n'.join(env.curbuf) + '\n')
env.debug("Find errors: ", len(errors))
sort_rules = env.var('g:pymode_lint_sort')
def __sort(e):
try:
return sort_rules.index(e.get('type'))
except ValueError:
return 999
if sort_rules:
env.debug("Find sorting: ", sort_rules)
errors = sorted(errors, key=__sort)
for e in errors:
e._info['bufnr'] = env.curbuf.number
env.run('g:PymodeLocList.current().extend', [e._info for e in errors])
# pylama:ignore=W0212,E1103