55"""
66import logging
77import re
8-
9- from . import utils
10-
11-
12- #: A default checkers
13- DEFAULT_LINTERS = 'pep8' , 'pyflakes' , 'mccabe'
8+ from .lint import LINTERS
149
1510#: The skip pattern
1611SKIP_PATTERN = re .compile (r'# *noqa\b' , re .I ).search
2520LOGGER .addHandler (STREAM )
2621
2722
28- def run (path , ignore = None , select = None , linters = DEFAULT_LINTERS , config = None ,
29- ** meta ):
23+ def run (path , ignore = None , select = None , linters = None , config = None , ** meta ):
3024 """ Run a code checkers with given params.
3125
3226 :return errors: list of dictionaries with error's information
3327
3428 """
3529 errors = []
30+ linters = linters or LINTERS .items ()
3631 params = dict (ignore = ignore , select = select )
3732 code = None
3833 try :
@@ -46,21 +41,24 @@ def run(path, ignore=None, select=None, linters=DEFAULT_LINTERS, config=None,
4641 if not params ['lint' ]:
4742 return errors
4843
49- for lint in linters :
50- try :
51- linter = getattr (utils , lint )
52- except AttributeError :
53- LOGGER .warning ("Linter `%s` not found." , lint )
44+ for item in linters :
45+
46+ if not isinstance (item , tuple ):
47+ item = (item , LINTERS .get (item ))
48+
49+ name , linter = item
50+
51+ if not linter or not linter .allow (path ):
5452 continue
5553
56- result = linter (path , code = code , ** meta )
54+ result = linter . run (path , code = code , ** meta )
5755 for e in result :
5856 e ['col' ] = e .get ('col' ) or 0
5957 e ['lnum' ] = e .get ('lnum' ) or 0
6058 e ['type' ] = e .get ('type' ) or 'E'
6159 e ['text' ] = "{0} [{1}]" .format ((e .get (
6260 'text' ) or '' ).strip ()
63- .replace ("'" , "\" " ).split ('\n ' )[0 ], lint )
61+ .replace ("'" , "\" " ).split ('\n ' )[0 ], name )
6462 e ['filename' ] = path or ''
6563 errors .append (e )
6664
@@ -71,7 +69,7 @@ def run(path, ignore=None, select=None, linters=DEFAULT_LINTERS, config=None,
7169 except SyntaxError as e :
7270 errors .append (dict (
7371 lnum = e .lineno or 0 , type = 'E' , col = e .offset or 0 ,
74- text = e .args [0 ] + ' [%s]' % lint , filename = path or ''
72+ text = e .args [0 ] + ' [%s]' % name , filename = path or ''
7573 ))
7674
7775 except Exception :
@@ -128,7 +126,6 @@ def filter_errors(e, select=None, ignore=None, **params):
128126 :return bool:
129127
130128 """
131-
132129 if select :
133130 for s in select :
134131 if e ['text' ].startswith (s ):
0 commit comments