Fix Flake8 errors

Fix invalid escape sequences in string literals. Ignore E301 and W504.
This commit is contained in:
micbou 2018-10-26 22:19:50 +02:00
parent 34dee0ebcb
commit 88bdfc01f9
No known key found for this signature in database
GPG Key ID: C7E8FD1F3BDA1E05
5 changed files with 48 additions and 46 deletions

View File

@ -37,30 +37,30 @@ import sys
from ycmd.utils import GetCurrentDirectory, ToBytes, ToUnicode from ycmd.utils import GetCurrentDirectory, ToBytes, ToUnicode
BUFNR_REGEX = re.compile( '^bufnr\(\'(?P<buffer_filename>.+)\', ([01])\)$' ) BUFNR_REGEX = re.compile( '^bufnr\\(\'(?P<buffer_filename>.+)\', ([01])\\)$' )
BUFWINNR_REGEX = re.compile( '^bufwinnr\((?P<buffer_number>[0-9]+)\)$' ) BUFWINNR_REGEX = re.compile( '^bufwinnr\\((?P<buffer_number>[0-9]+)\\)$' )
BWIPEOUT_REGEX = re.compile( BWIPEOUT_REGEX = re.compile(
'^(?:silent! )bwipeout!? (?P<buffer_number>[0-9]+)$' ) '^(?:silent! )bwipeout!? (?P<buffer_number>[0-9]+)$' )
GETBUFVAR_REGEX = re.compile( GETBUFVAR_REGEX = re.compile(
'^getbufvar\((?P<buffer_number>[0-9]+), "(?P<option>.+)"\)$' ) '^getbufvar\\((?P<buffer_number>[0-9]+), "(?P<option>.+)"\\)$' )
MATCHADD_REGEX = re.compile( MATCHADD_REGEX = re.compile(
'^matchadd\(\'(?P<group>.+)\', \'(?P<pattern>.+)\'\)$' ) '^matchadd\\(\'(?P<group>.+)\', \'(?P<pattern>.+)\'\\)$' )
MATCHDELETE_REGEX = re.compile( '^matchdelete\((?P<id>\d+)\)$' ) MATCHDELETE_REGEX = re.compile( '^matchdelete\\((?P<id>\\d+)\\)$' )
OMNIFUNC_REGEX_FORMAT = ( OMNIFUNC_REGEX_FORMAT = (
'^{omnifunc_name}\((?P<findstart>[01]),[\'"](?P<base>.*)[\'"]\)$' ) '^{omnifunc_name}\\((?P<findstart>[01]),[\'"](?P<base>.*)[\'"]\\)$' )
FNAMEESCAPE_REGEX = re.compile( '^fnameescape\(\'(?P<filepath>.+)\'\)$' ) FNAMEESCAPE_REGEX = re.compile( '^fnameescape\\(\'(?P<filepath>.+)\'\\)$' )
SIGN_LIST_REGEX = re.compile( SIGN_LIST_REGEX = re.compile(
"^silent! sign place buffer=(?P<bufnr>\d+)$" ) '^silent! sign place buffer=(?P<bufnr>\\d+)$' )
SIGN_PLACE_REGEX = re.compile( SIGN_PLACE_REGEX = re.compile(
'^sign place (?P<id>\d+) name=(?P<name>\w+) line=(?P<line>\d+) ' '^sign place (?P<id>\\d+) name=(?P<name>\\w+) line=(?P<line>\\d+) '
'buffer=(?P<bufnr>\d+)$' ) 'buffer=(?P<bufnr>\\d+)$' )
SIGN_UNPLACE_REGEX = re.compile( SIGN_UNPLACE_REGEX = re.compile(
'^sign unplace (?P<id>\d+) buffer=(?P<bufnr>\d+)$' ) '^sign unplace (?P<id>\\d+) buffer=(?P<bufnr>\\d+)$' )
REDIR_START_REGEX = re.compile( '^redir => (?P<variable>[\w:]+)$' ) REDIR_START_REGEX = re.compile( '^redir => (?P<variable>[\\w:]+)$' )
REDIR_END_REGEX = re.compile( '^redir END$' ) REDIR_END_REGEX = re.compile( '^redir END$' )
EXISTS_REGEX = re.compile( '^exists\( \'(?P<option>[\w:]+)\' \)$' ) EXISTS_REGEX = re.compile( '^exists\\( \'(?P<option>[\\w:]+)\' \\)$' )
LET_REGEX = re.compile( '^let (?P<option>[\w:]+) = (?P<value>.*)$' ) LET_REGEX = re.compile( '^let (?P<option>[\\w:]+) = (?P<value>.*)$' )
HAS_PATCH_REGEX = re.compile( '^has\( \'patch(?P<patch>\d+)\' \)$' ) HAS_PATCH_REGEX = re.compile( '^has\\( \'patch(?P<patch>\\d+)\' \\)$' )
# One-and only instance of mocked Vim object. The first 'import vim' that is # One-and only instance of mocked Vim object. The first 'import vim' that is
# executed binds the vim module to the instance of MagicMock that is created, # executed binds the vim module to the instance of MagicMock that is created,

View File

@ -1339,7 +1339,7 @@ def GetDiagnosticMatchPattern_ErrorInMiddleOfLine_test():
with patch( 'vim.current.buffer', current_buffer ): with patch( 'vim.current.buffer', current_buffer ):
assert_that( assert_that(
vimsupport.GetDiagnosticMatchPattern( 1, 16, 1, 21 ), vimsupport.GetDiagnosticMatchPattern( 1, 16, 1, 21 ),
equal_to( '\%1l\%16c\_.\{-}\%1l\%21c' ) equal_to( '\\%1l\\%16c\\_.\\{-}\\%1l\\%21c' )
) )
@ -1352,7 +1352,7 @@ def AddDiagnosticSyntaxMatch_WarningAtEndOfLine_test():
with patch( 'vim.current.buffer', current_buffer ): with patch( 'vim.current.buffer', current_buffer ):
assert_that( assert_that(
vimsupport.GetDiagnosticMatchPattern( 1, 16, 1, 23 ), vimsupport.GetDiagnosticMatchPattern( 1, 16, 1, 23 ),
equal_to( '\%1l\%16c\_.\{-}\%1l\%23c' ) equal_to( '\\%1l\\%16c\\_.\\{-}\\%1l\\%23c' )
) )
@ -1365,7 +1365,7 @@ def AddDiagnosticSyntaxMatch_UnicodeAtEndOfLine_test():
with patch( 'vim.current.buffer', current_buffer ): with patch( 'vim.current.buffer', current_buffer ):
assert_that( assert_that(
vimsupport.GetDiagnosticMatchPattern( 1, 16, 1, 19 ), vimsupport.GetDiagnosticMatchPattern( 1, 16, 1, 19 ),
equal_to( '\%1l\%16c\_.\{-}\%1l\%19c' ) equal_to( '\\%1l\\%16c\\_.\\{-}\\%1l\\%19c' )
) )

View File

@ -126,9 +126,10 @@ def RunNotifyUserIfServerCrashed( ycm, test, post_vim_message ):
def YouCompleteMe_NotifyUserIfServerCrashed_UnexpectedCore_test(): def YouCompleteMe_NotifyUserIfServerCrashed_UnexpectedCore_test():
message = ( "The ycmd server SHUT DOWN \(restart with ':YcmRestartServer'\). " message = (
"Unexpected error while loading the YCM core library. Type " "The ycmd server SHUT DOWN \\(restart with ':YcmRestartServer'\\). "
"':YcmToggleLogs ycmd_\d+_stderr_.+.log' to check the logs." ) "Unexpected error while loading the YCM core library. Type "
"':YcmToggleLogs ycmd_\\d+_stderr_.+.log' to check the logs." )
RunNotifyUserIfServerCrashed( { RunNotifyUserIfServerCrashed( {
'return_code': 3, 'return_code': 3,
'expected_message': matches_regexp( message ) 'expected_message': matches_regexp( message )
@ -178,9 +179,10 @@ def YouCompleteMe_NotifyUserIfServerCrashed_OutdatedCore_test():
def YouCompleteMe_NotifyUserIfServerCrashed_UnexpectedExitCode_test(): def YouCompleteMe_NotifyUserIfServerCrashed_UnexpectedExitCode_test():
message = ( "The ycmd server SHUT DOWN \(restart with ':YcmRestartServer'\). " message = (
"Unexpected exit code 1. Type " "The ycmd server SHUT DOWN \\(restart with ':YcmRestartServer'\\). "
"':YcmToggleLogs ycmd_\d+_stderr_.+.log' to check the logs." ) "Unexpected exit code 1. Type "
"':YcmToggleLogs ycmd_\\d+_stderr_.+.log' to check the logs." )
RunNotifyUserIfServerCrashed( { RunNotifyUserIfServerCrashed( {
'return_code': 1, 'return_code': 1,
'expected_message': matches_regexp( message ) 'expected_message': matches_regexp( message )
@ -212,7 +214,7 @@ def YouCompleteMe_DebugInfo_ServerRunning_test( ycm ):
' Flags: \\[u?\'_TEMP_FILE_\'.*\\]\n' ' Flags: \\[u?\'_TEMP_FILE_\'.*\\]\n'
' Translation unit: .+\n)' ' Translation unit: .+\n)'
'Server running at: .+\n' 'Server running at: .+\n'
'Server process ID: \d+\n' 'Server process ID: \\d+\n'
'Server logfiles:\n' 'Server logfiles:\n'
' .+\n' ' .+\n'
' .+' ) ' .+' )
@ -231,7 +233,7 @@ def YouCompleteMe_DebugInfo_ServerNotRunning_test( ycm ):
'Client logfile: .+\n' 'Client logfile: .+\n'
'Server errored, no debug info from server\n' 'Server errored, no debug info from server\n'
'Server running at: .+\n' 'Server running at: .+\n'
'Server process ID: \d+\n' 'Server process ID: \\d+\n'
'Server logfiles:\n' 'Server logfiles:\n'
' .+\n' ' .+\n'
' .+' ) ' .+' )
@ -626,9 +628,9 @@ def YouCompleteMe_UpdateDiagnosticInterface_PrioritizeErrorsOverWarnings_test(
test_utils.VIM_MATCHES_FOR_WINDOW, test_utils.VIM_MATCHES_FOR_WINDOW,
has_entries( { has_entries( {
1: contains( 1: contains(
VimMatch( 'YcmWarningSection', '\%3l\%5c\_.\{-}\%3l\%7c' ), VimMatch( 'YcmWarningSection', '\\%3l\\%5c\\_.\\{-}\\%3l\\%7c' ),
VimMatch( 'YcmWarningSection', '\%3l\%3c\_.\{-}\%3l\%9c' ), VimMatch( 'YcmWarningSection', '\\%3l\\%3c\\_.\\{-}\\%3l\\%9c' ),
VimMatch( 'YcmErrorSection', '\%3l\%8c' ) VimMatch( 'YcmErrorSection', '\\%3l\\%8c' )
) )
} ) } )
) )
@ -670,8 +672,8 @@ def YouCompleteMe_UpdateDiagnosticInterface_PrioritizeErrorsOverWarnings_test(
test_utils.VIM_MATCHES_FOR_WINDOW, test_utils.VIM_MATCHES_FOR_WINDOW,
has_entries( { has_entries( {
1: contains( 1: contains(
VimMatch( 'YcmWarningSection', '\%3l\%5c\_.\{-}\%3l\%7c' ), VimMatch( 'YcmWarningSection', '\\%3l\\%5c\\_.\\{-}\\%3l\\%7c' ),
VimMatch( 'YcmWarningSection', '\%3l\%3c\_.\{-}\%3l\%9c' ) VimMatch( 'YcmWarningSection', '\\%3l\\%3c\\_.\\{-}\\%3l\\%9c' )
) )
} ) } )
) )
@ -692,9 +694,9 @@ def YouCompleteMe_UpdateMatches_ClearDiagnosticMatchesInNewBuffer_test( ycm ):
test_utils.VIM_MATCHES_FOR_WINDOW.clear() test_utils.VIM_MATCHES_FOR_WINDOW.clear()
test_utils.VIM_MATCHES_FOR_WINDOW[ 1 ] = [ test_utils.VIM_MATCHES_FOR_WINDOW[ 1 ] = [
VimMatch( 'YcmWarningSection', '\%3l\%5c\_.\{-}\%3l\%7c' ), VimMatch( 'YcmWarningSection', '\\%3l\\%5c\\_.\\{-}\\%3l\\%7c' ),
VimMatch( 'YcmWarningSection', '\%3l\%3c\_.\{-}\%3l\%9c' ), VimMatch( 'YcmWarningSection', '\\%3l\\%3c\\_.\\{-}\\%3l\\%9c' ),
VimMatch( 'YcmErrorSection', '\%3l\%8c' ) VimMatch( 'YcmErrorSection', '\\%3l\\%8c' )
] ]
with MockVimBuffers( [ current_buffer ], [ current_buffer ] ): with MockVimBuffers( [ current_buffer ], [ current_buffer ] ):
@ -862,7 +864,7 @@ def YouCompleteMe_AsyncDiagnosticUpdate_SingleFile_test( ycm,
test_utils.VIM_MATCHES_FOR_WINDOW, test_utils.VIM_MATCHES_FOR_WINDOW,
has_entries( { has_entries( {
1: contains( 1: contains(
VimMatch( 'YcmErrorSection', '\%1l\%1c\_.\{-}\%1l\%1c' ) VimMatch( 'YcmErrorSection', '\\%1l\\%1c\\_.\\{-}\\%1l\\%1c' )
) )
} ) } )
) )
@ -1049,10 +1051,10 @@ def YouCompleteMe_AsyncDiagnosticUpdate_PerFile_test( ycm,
test_utils.VIM_MATCHES_FOR_WINDOW, test_utils.VIM_MATCHES_FOR_WINDOW,
has_entries( { has_entries( {
1: contains( 1: contains(
VimMatch( 'YcmErrorSection', '\%1l\%1c\_.\{-}\%1l\%1c' ) VimMatch( 'YcmErrorSection', '\\%1l\\%1c\\_.\\{-}\\%1l\\%1c' )
), ),
3: contains( 3: contains(
VimMatch( 'YcmErrorSection', '\%3l\%3c\_.\{-}\%3l\%3c' ) VimMatch( 'YcmErrorSection', '\\%3l\\%3c\\_.\\{-}\\%3l\\%3c' )
) )
} ) } )
) )

View File

@ -257,16 +257,16 @@ def GetDiagnosticMatchPattern( line_num,
line_num, column_num = LineAndColumnNumbersClamped( line_num, column_num ) line_num, column_num = LineAndColumnNumbersClamped( line_num, column_num )
if not line_end_num or not column_end_num: if not line_end_num or not column_end_num:
return '\%{}l\%{}c'.format( line_num, column_num ) return '\\%{}l\\%{}c'.format( line_num, column_num )
# -1 and then +1 to account for column end not included in the range. # -1 and then +1 to account for column end not included in the range.
line_end_num, column_end_num = LineAndColumnNumbersClamped( line_end_num, column_end_num = LineAndColumnNumbersClamped(
line_end_num, column_end_num - 1 ) line_end_num, column_end_num - 1 )
column_end_num += 1 column_end_num += 1
return '\%{}l\%{}c\_.\\{{-}}\%{}l\%{}c'.format( line_num, return '\\%{}l\\%{}c\\_.\\{{-}}\\%{}l\\%{}c'.format( line_num,
column_num, column_num,
line_end_num, line_end_num,
column_end_num ) column_end_num )
# Clamps the line and column numbers so that they are not past the contents of # Clamps the line and column numbers so that they are not past the contents of
@ -993,13 +993,13 @@ def InsertNamespace( namespace ):
vim.eval( expr ) vim.eval( expr )
return return
pattern = '^\s*using\(\s\+[a-zA-Z0-9]\+\s\+=\)\?\s\+[a-zA-Z0-9.]\+\s*;\s*' pattern = r'^\s*using\(\s\+[a-zA-Z0-9]\+\s\+=\)\?\s\+[a-zA-Z0-9.]\+\s*;\s*'
existing_indent = '' existing_indent = ''
line = SearchInCurrentBuffer( pattern ) line = SearchInCurrentBuffer( pattern )
if line: if line:
existing_line = LineTextInCurrentBuffer( line ) existing_line = LineTextInCurrentBuffer( line )
existing_indent = re.sub( r"\S.*", "", existing_line ) existing_indent = re.sub( r'\S.*', '', existing_line )
new_line = "{0}using {1};\n".format( existing_indent, namespace ) new_line = '{0}using {1};\n'.format( existing_indent, namespace )
replace_pos = { 'line_num': line + 1, 'column_num': 1 } replace_pos = { 'line_num': line + 1, 'column_num': 1 }
ReplaceChunk( replace_pos, replace_pos, new_line, vim.current.buffer ) ReplaceChunk( replace_pos, replace_pos, new_line, vim.current.buffer )
PostVimMessage( 'Add namespace: {0}'.format( namespace ), warning = False ) PostVimMessage( 'Add namespace: {0}'.format( namespace ), warning = False )

View File

@ -1,4 +1,4 @@
[flake8] [flake8]
ignore = E111,E114,E121,E125,E126,E127,E128,E129,E131,E133,E201,E202,E203,E221,E222,E241,E251,E261,E303,E402,W503 ignore = E111,E114,E121,E125,E126,E127,E128,E129,E131,E133,E201,E202,E203,E221,E222,E241,E251,E261,E301,E303,E402,W503,W504
max-complexity = 10 max-complexity = 10
max-line-length = 80 max-line-length = 80