Style refactor and cleanup

This commit is contained in:
dhleong 2016-10-22 11:58:57 -04:00
parent bb793826b6
commit 18a25d45b3
2 changed files with 35 additions and 49 deletions

View File

@ -32,20 +32,18 @@ class DiagnosticFilter( object ):
self._filters = []
for filter_type in iterkeys( config ):
actual_filter_type = filter_type
compiler = FILTER_COMPILERS.get( filter_type )
if compiler is not None:
for filter_config in _ListOf( config[ actual_filter_type ] ):
fn = compiler( filter_config )
self._filters.append( fn )
for filter_config in _ListOf( config[ filter_type ] ):
compiledFilter = compiler( filter_config )
self._filters.append( compiledFilter )
def IsAllowed( self, diagnostic ):
# NOTE: a diagnostic IsAllowed() ONLY if
# NO filters match it
for f in self._filters:
if f( diagnostic ):
# NOTE: a diagnostic IsAllowed() ONLY if NO filters match it
for filterMatches in self._filters:
if filterMatches( diagnostic ):
return False
return True
@ -57,8 +55,8 @@ class DiagnosticFilter( object ):
all_filters = dict( user_options.get( 'filter_diagnostics', {} ) )
for typeSpec, filterValue in iteritems( dict( all_filters ) ):
if typeSpec.find(',') != -1:
for ft in typeSpec.split(','):
all_filters[ ft ] = filterValue
for filetype in typeSpec.split(','):
all_filters[ filetype ] = filterValue
for filetype in filetypes:
type_specific = all_filters.get( filetype, {} )
@ -77,8 +75,8 @@ def _ListOf( config_entry ):
def _Merge( into, other ):
for k in iterkeys( other ):
into[k] = _ListOf( into.get( k ) ) + _ListOf( other[ k ] )
for key in iterkeys( other ):
into[ key ] = _ListOf( into.get( key ) ) + _ListOf( other[ key ] )
return into
@ -95,7 +93,7 @@ def _CompileRegex( raw_regex ):
def _CompileLevel( level ):
# valid kinds 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()
def FilterLevel( diagnostic ):

View File

@ -23,9 +23,6 @@ from future import standard_library
standard_library.install_aliases()
from builtins import * # noqa
from ycm.test_utils import MockVimModule
MockVimModule()
from hamcrest import assert_that, equal_to
from ycm.diagnostic_filter import DiagnosticFilter
@ -57,12 +54,7 @@ def RegexFilter_test():
_assert_accepts( f, 'This is a Burrito' )
class ListOrSingle_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
def RegexSingleList_test():
opts = _JavaFilter( { 'regex' : [ 'taco' ] } )
f = DiagnosticFilter.from_filetype( opts, [ 'java' ] )
@ -70,9 +62,7 @@ class ListOrSingle_test():
_assert_accepts( f, 'This is a Burrito' )
def ListOrSingle_MultiList_test( self ):
# NB: if the filetype doesn't override the global,
# we would reject burrito and accept taco
def RegexMultiList_test():
opts = _JavaFilter( { 'regex' : [ 'taco', 'burrito' ] } )
f = DiagnosticFilter.from_filetype( opts, [ 'java' ] )
@ -80,9 +70,7 @@ class ListOrSingle_test():
_assert_rejects( f, 'This is a Burrito' )
class Level_test():
def Level_warnings_test( self ):
def LevelWarnings_test():
opts = _JavaFilter( { 'level' : 'warning' } )
f = DiagnosticFilter.from_filetype( opts, [ 'java' ] )
@ -92,7 +80,7 @@ class Level_test():
'kind' : 'ERROR' } )
def Level_errors_test( self ):
def LevelErrors_test():
opts = _JavaFilter( { 'level' : 'error' } )
f = DiagnosticFilter.from_filetype( opts, [ 'java' ] )