Fix style/lint issues

This commit is contained in:
dhleong 2016-10-10 18:51:18 -04:00
parent d274dcd37a
commit f15f9f2255
3 changed files with 24 additions and 20 deletions

View File

@ -1,4 +1,4 @@
# Copyright (C) 2013 Google Inc. # Copyright (C) 2016 YouCompleteMe contributors
# #
# This file is part of YouCompleteMe. # This file is part of YouCompleteMe.
# #
@ -23,11 +23,7 @@ from future import standard_library
standard_library.install_aliases() standard_library.install_aliases()
from builtins import * # noqa from builtins import * # noqa
from future.utils import itervalues, iteritems
from collections import defaultdict, namedtuple
from ycm import vimsupport
import re import re
import vim
class DiagnosticFilter( object ): class DiagnosticFilter( object ):
@ -35,14 +31,14 @@ class DiagnosticFilter( object ):
self._filters = [] self._filters = []
for filter_type in config.iterkeys(): for filter_type in config.iterkeys():
wrapper = lambda x: x wrapper = _AsIs
actual_filter_type = filter_type actual_filter_type = filter_type
if filter_type[0] == '!': if filter_type[0] == '!':
wrapper = _Not wrapper = _Not
filter_type = filter_type[1:] filter_type = filter_type[1:]
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[ actual_filter_type ] ):
fn = wrapper( compiler( filter_config ) ) fn = wrapper( compiler( filter_config ) )
@ -56,7 +52,7 @@ class DiagnosticFilter( object ):
if f( diagnostic ): if f( diagnostic ):
return False return False
return True return True
@staticmethod @staticmethod
@ -64,18 +60,22 @@ class DiagnosticFilter( object ):
base = dict( user_options.get( 'quiet_messages', {} ) ) base = dict( user_options.get( 'quiet_messages', {} ) )
for filetype in filetypes: for filetype in filetypes:
type_specific = user_options.get( filetype + '_quiet_messages', {} ) type_specific = user_options.get( filetype + '_quiet_messages', {} )
base.update( type_specific ) base.update( type_specific )
return DiagnosticFilter( base ) return DiagnosticFilter( base )
def _ListOf( config_entry ): def _ListOf( config_entry ):
if type( config_entry ) == type( [] ): if isinstance( config_entry, list ):
return config_entry return config_entry
return [ config_entry ] return [ config_entry ]
def _AsIs( fn ):
return fn
def _Not( fn ): def _Not( fn ):
def Inverted( diagnostic ): def Inverted( diagnostic ):
return not fn( diagnostic ) return not fn( diagnostic )
@ -93,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 `warnings` and `errors` # expected input levels are `warnings` and `errors`
# NB: we don't validate the input... # NB: we don't validate the input...
expected_kind = level.upper()[:-1] expected_kind = level.upper()[:-1]

View File

@ -66,8 +66,11 @@ class DiagnosticInterface( object ):
def UpdateWithNewDiagnostics( self, diags ): def UpdateWithNewDiagnostics( self, diags ):
diag_filter = DiagnosticFilter.from_filetype( self._user_options, vimsupport.CurrentFiletypes() ) diag_filter = DiagnosticFilter.from_filetype(
normalized_diags = [ _NormalizeDiagnostic( x ) for x in diags if diag_filter.Accept(x) ] self._user_options,
vimsupport.CurrentFiletypes() )
normalized_diags = [ _NormalizeDiagnostic( x ) for x in diags
if diag_filter.Accept(x) ]
self._buffer_number_to_line_to_diags = _ConvertDiagListToDict( self._buffer_number_to_line_to_diags = _ConvertDiagListToDict(
normalized_diags ) normalized_diags )

View File

@ -1,4 +1,4 @@
# Copyright (C) 2013 Google Inc. # Copyright (C) 2016 YouCompleteMe contributors
# #
# This file is part of YouCompleteMe. # This file is part of YouCompleteMe.
# #
@ -26,20 +26,21 @@ from builtins import * # noqa
from ycm.test_utils import MockVimModule from ycm.test_utils import MockVimModule
MockVimModule() MockVimModule()
import os
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
def _assert_accept_equals( filter, text_or_obj, expected ): def _assert_accept_equals( filter, text_or_obj, expected ):
if type( text_or_obj ) is not type( {} ): if not isinstance( text_or_obj, dict ):
text_or_obj = { 'text': text_or_obj } text_or_obj = { 'text': text_or_obj }
assert_that( filter.Accept( text_or_obj ), equal_to( expected ) ) assert_that( filter.Accept( text_or_obj ), equal_to( expected ) )
def _assert_accepts( filter, text ): def _assert_accepts( filter, text ):
_assert_accept_equals( filter, text, True ) _assert_accept_equals( filter, text, True )
def _assert_rejects( filter, text ): def _assert_rejects( filter, text ):
_assert_accept_equals( filter, text, False ) _assert_accept_equals( filter, text, False )
@ -111,9 +112,9 @@ class Level_test():
opts = { 'quiet_messages' : { 'level': 'warnings' } } opts = { 'quiet_messages' : { 'level': 'warnings' } }
f = DiagnosticFilter.from_filetype( opts, [ 'java' ] ) f = DiagnosticFilter.from_filetype( opts, [ 'java' ] )
_assert_rejects( f, { 'text': 'This is an unimportant taco', _assert_rejects( f, { 'text': 'This is an unimportant taco',
'kind': 'WARNING' } ) 'kind': 'WARNING' } )
_assert_accepts( f, { 'text': 'This taco will be shown', _assert_accepts( f, { 'text': 'This taco will be shown',
'kind': 'ERROR' } ) 'kind': 'ERROR' } )
@ -121,7 +122,7 @@ class Level_test():
opts = { 'quiet_messages' : { 'level': 'errors' } } opts = { 'quiet_messages' : { 'level': 'errors' } }
f = DiagnosticFilter.from_filetype( opts, [ 'java' ] ) f = DiagnosticFilter.from_filetype( opts, [ 'java' ] )
_assert_accepts( f, { 'text': 'This is an IMPORTANT taco', _assert_accepts( f, { 'text': 'This is an IMPORTANT taco',
'kind': 'WARNING' } ) 'kind': 'WARNING' } )
_assert_rejects( f, { 'text': 'This taco will NOT be shown', _assert_rejects( f, { 'text': 'This taco will NOT be shown',
'kind': 'ERROR' } ) 'kind': 'ERROR' } )