Style refactor and cleanup
This commit is contained in:
parent
bb793826b6
commit
18a25d45b3
@ -32,20 +32,18 @@ class DiagnosticFilter( object ):
|
|||||||
self._filters = []
|
self._filters = []
|
||||||
|
|
||||||
for filter_type in iterkeys( config ):
|
for filter_type in iterkeys( config ):
|
||||||
actual_filter_type = filter_type
|
|
||||||
compiler = FILTER_COMPILERS.get( filter_type )
|
compiler = FILTER_COMPILERS.get( filter_type )
|
||||||
|
|
||||||
if compiler is not None:
|
if compiler is not None:
|
||||||
for filter_config in _ListOf( config[ actual_filter_type ] ):
|
for filter_config in _ListOf( config[ filter_type ] ):
|
||||||
fn = compiler( filter_config )
|
compiledFilter = compiler( filter_config )
|
||||||
self._filters.append( fn )
|
self._filters.append( compiledFilter )
|
||||||
|
|
||||||
|
|
||||||
def IsAllowed( self, diagnostic ):
|
def IsAllowed( self, diagnostic ):
|
||||||
# NOTE: a diagnostic IsAllowed() ONLY if
|
# NOTE: a diagnostic IsAllowed() ONLY if NO filters match it
|
||||||
# NO filters match it
|
for filterMatches in self._filters:
|
||||||
for f in self._filters:
|
if filterMatches( diagnostic ):
|
||||||
if f( diagnostic ):
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
return True
|
return True
|
||||||
@ -57,8 +55,8 @@ class DiagnosticFilter( object ):
|
|||||||
all_filters = dict( user_options.get( 'filter_diagnostics', {} ) )
|
all_filters = dict( user_options.get( 'filter_diagnostics', {} ) )
|
||||||
for typeSpec, filterValue in iteritems( dict( all_filters ) ):
|
for typeSpec, filterValue in iteritems( dict( all_filters ) ):
|
||||||
if typeSpec.find(',') != -1:
|
if typeSpec.find(',') != -1:
|
||||||
for ft in typeSpec.split(','):
|
for filetype in typeSpec.split(','):
|
||||||
all_filters[ ft ] = filterValue
|
all_filters[ filetype ] = filterValue
|
||||||
|
|
||||||
for filetype in filetypes:
|
for filetype in filetypes:
|
||||||
type_specific = all_filters.get( filetype, {} )
|
type_specific = all_filters.get( filetype, {} )
|
||||||
@ -77,8 +75,8 @@ def _ListOf( config_entry ):
|
|||||||
|
|
||||||
|
|
||||||
def _Merge( into, other ):
|
def _Merge( into, other ):
|
||||||
for k in iterkeys( other ):
|
for key in iterkeys( other ):
|
||||||
into[k] = _ListOf( into.get( k ) ) + _ListOf( other[ k ] )
|
into[ key ] = _ListOf( into.get( key ) ) + _ListOf( other[ key ] )
|
||||||
|
|
||||||
return into
|
return into
|
||||||
|
|
||||||
@ -95,7 +93,7 @@ def _CompileRegex( raw_regex ):
|
|||||||
def _CompileLevel( level ):
|
def _CompileLevel( level ):
|
||||||
# valid kinds are WARNING and ERROR;
|
# valid kinds are WARNING and ERROR;
|
||||||
# expected input levels are `warning` and `error`
|
# expected input levels are `warning` and `error`
|
||||||
# NB: we don't validate the input...
|
# NOTE: we don't validate the input...
|
||||||
expected_kind = level.upper()
|
expected_kind = level.upper()
|
||||||
|
|
||||||
def FilterLevel( diagnostic ):
|
def FilterLevel( diagnostic ):
|
||||||
|
@ -23,9 +23,6 @@ from future import standard_library
|
|||||||
standard_library.install_aliases()
|
standard_library.install_aliases()
|
||||||
from builtins import * # noqa
|
from builtins import * # noqa
|
||||||
|
|
||||||
from ycm.test_utils import MockVimModule
|
|
||||||
MockVimModule()
|
|
||||||
|
|
||||||
from hamcrest import assert_that, equal_to
|
from hamcrest import assert_that, equal_to
|
||||||
from ycm.diagnostic_filter import DiagnosticFilter
|
from ycm.diagnostic_filter import DiagnosticFilter
|
||||||
|
|
||||||
@ -57,12 +54,7 @@ def RegexFilter_test():
|
|||||||
_assert_accepts( f, 'This is a Burrito' )
|
_assert_accepts( f, 'This is a Burrito' )
|
||||||
|
|
||||||
|
|
||||||
class ListOrSingle_test():
|
def RegexSingleList_test():
|
||||||
# NB: we already test the single config above
|
|
||||||
|
|
||||||
def ListOrSingle_SingleList_test( self ):
|
|
||||||
# NB: if the filetype doesn't override the global,
|
|
||||||
# we would reject burrito and accept taco
|
|
||||||
opts = _JavaFilter( { 'regex' : [ 'taco' ] } )
|
opts = _JavaFilter( { 'regex' : [ 'taco' ] } )
|
||||||
f = DiagnosticFilter.from_filetype( opts, [ 'java' ] )
|
f = DiagnosticFilter.from_filetype( opts, [ 'java' ] )
|
||||||
|
|
||||||
@ -70,9 +62,7 @@ class ListOrSingle_test():
|
|||||||
_assert_accepts( f, 'This is a Burrito' )
|
_assert_accepts( f, 'This is a Burrito' )
|
||||||
|
|
||||||
|
|
||||||
def ListOrSingle_MultiList_test( self ):
|
def RegexMultiList_test():
|
||||||
# NB: if the filetype doesn't override the global,
|
|
||||||
# we would reject burrito and accept taco
|
|
||||||
opts = _JavaFilter( { 'regex' : [ 'taco', 'burrito' ] } )
|
opts = _JavaFilter( { 'regex' : [ 'taco', 'burrito' ] } )
|
||||||
f = DiagnosticFilter.from_filetype( opts, [ 'java' ] )
|
f = DiagnosticFilter.from_filetype( opts, [ 'java' ] )
|
||||||
|
|
||||||
@ -80,9 +70,7 @@ class ListOrSingle_test():
|
|||||||
_assert_rejects( f, 'This is a Burrito' )
|
_assert_rejects( f, 'This is a Burrito' )
|
||||||
|
|
||||||
|
|
||||||
class Level_test():
|
def LevelWarnings_test():
|
||||||
|
|
||||||
def Level_warnings_test( self ):
|
|
||||||
opts = _JavaFilter( { 'level' : 'warning' } )
|
opts = _JavaFilter( { 'level' : 'warning' } )
|
||||||
f = DiagnosticFilter.from_filetype( opts, [ 'java' ] )
|
f = DiagnosticFilter.from_filetype( opts, [ 'java' ] )
|
||||||
|
|
||||||
@ -92,7 +80,7 @@ class Level_test():
|
|||||||
'kind' : 'ERROR' } )
|
'kind' : 'ERROR' } )
|
||||||
|
|
||||||
|
|
||||||
def Level_errors_test( self ):
|
def LevelErrors_test():
|
||||||
opts = _JavaFilter( { 'level' : 'error' } )
|
opts = _JavaFilter( { 'level' : 'error' } )
|
||||||
f = DiagnosticFilter.from_filetype( opts, [ 'java' ] )
|
f = DiagnosticFilter.from_filetype( opts, [ 'java' ] )
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user