From e12e5c912cd42abe4aebf54c21f57f5a8c735dc6 Mon Sep 17 00:00:00 2001 From: w0rp Date: Wed, 15 Nov 2017 12:00:08 +0000 Subject: [PATCH] Complain about stray echo lines in the codebase --- autoload/ale/cursor.vim | 6 ++-- autoload/ale/debugging.vim | 58 ++++++++++++++++++++------------------ autoload/ale/engine.vim | 4 +-- autoload/ale/fix.vim | 7 +++-- autoload/ale/toggle.vim | 2 +- plugin/ale.vim | 4 +-- test/script/custom-checks | 1 + 7 files changed, 44 insertions(+), 38 deletions(-) diff --git a/autoload/ale/cursor.vim b/autoload/ale/cursor.vim index 6907610..5a1d778 100644 --- a/autoload/ale/cursor.vim +++ b/autoload/ale/cursor.vim @@ -18,7 +18,7 @@ function! s:EchoWithShortMess(setting, message) abort elseif a:setting is# 'off' setlocal shortmess-=T " Regular echo is needed for printing newline characters. - echo a:message + execute 'echo a:message' else throw 'Invalid setting: ' . string(a:setting) endif @@ -78,7 +78,7 @@ function! s:EchoImpl() abort elseif get(l:info, 'echoed') " We'll only clear the echoed message when moving off errors once, " so we don't continually clear the echo line. - echo + execute 'echo' let l:info.echoed = 0 endif endfunction @@ -126,6 +126,6 @@ function! ale#cursor#ShowCursorDetail() abort let l:message = get(l:loc, 'detail', l:loc.text) call ale#preview#Show(split(l:message, "\n")) - echo + execute 'echo' endif endfunction diff --git a/autoload/ale/debugging.vim b/autoload/ale/debugging.vim index 7454bb1..9ce69ce 100644 --- a/autoload/ale/debugging.vim +++ b/autoload/ale/debugging.vim @@ -29,6 +29,10 @@ let s:global_variable_list = [ \ 'ale_warn_about_trailing_whitespace', \] +function! s:Echo(message) abort + execute 'echo a:message' +endfunction + function! s:GetLinterVariables(filetype, linter_names) abort let l:variable_list = [] let l:filetype_parts = split(a:filetype, '\.') @@ -52,20 +56,20 @@ endfunction function! s:EchoLinterVariables(variable_list) abort for l:key in a:variable_list - echom 'let g:' . l:key . ' = ' . string(g:[l:key]) + call s:Echo('let g:' . l:key . ' = ' . string(g:[l:key])) if has_key(b:, l:key) - echom 'let b:' . l:key . ' = ' . string(b:[l:key]) + call s:Echo('let b:' . l:key . ' = ' . string(b:[l:key])) endif endfor endfunction function! s:EchoGlobalVariables() abort for l:key in s:global_variable_list - echom 'let g:' . l:key . ' = ' . string(get(g:, l:key, v:null)) + call s:Echo('let g:' . l:key . ' = ' . string(get(g:, l:key, v:null))) if has_key(b:, l:key) - echom 'let b:' . l:key . ' = ' . string(b:[l:key]) + call s:Echo('let b:' . l:key . ' = ' . string(b:[l:key])) endif endfor endfunction @@ -79,34 +83,34 @@ function! s:EchoCommand(item) abort let l:status_message .= ' - exit code ' . a:item.exit_code endif - echom '(' . l:status_message . ') ' . string(a:item.command) + call s:Echo('(' . l:status_message . ') ' . string(a:item.command)) if g:ale_history_log_output && has_key(a:item, 'output') if empty(a:item.output) - echom '' - echom '<<>>' - echom '' + call s:Echo('') + call s:Echo('<<>>') + call s:Echo('') else - echom '' - echom '<<>>' + call s:Echo('') + call s:Echo('<<>>') for l:line in a:item.output - echom l:line + call s:Echo(l:line) endfor - echom '<<>>' - echom '' + call s:Echo('<<>>') + call s:Echo('') endif endif endfunction " Echo the results of an executable check. function! s:EchoExecutable(item) abort - echom printf( + call s:Echo(printf( \ '(executable check - %s) %s', \ a:item.status ? 'success' : 'failure', \ a:item.command, - \) + \)) endfunction function! s:EchoCommandHistory() abort @@ -127,12 +131,12 @@ function! s:EchoLinterAliases(all_linters) abort for l:linter in a:all_linters if !empty(l:linter.aliases) if l:first - echom ' Linter Aliases:' + call s:Echo(' Linter Aliases:') endif let l:first = 0 - echom string(l:linter.name) . ' -> ' . string(l:linter.aliases) + call s:Echo(string(l:linter.name) . ' -> ' . string(l:linter.aliases)) endif endfor endfunction @@ -159,18 +163,18 @@ function! ale#debugging#Info() abort " This must be done after linters are loaded. let l:variable_list = s:GetLinterVariables(l:filetype, l:enabled_names) - echom ' Current Filetype: ' . l:filetype - echom 'Available Linters: ' . string(l:all_names) + call s:Echo(' Current Filetype: ' . l:filetype) + call s:Echo('Available Linters: ' . string(l:all_names)) call s:EchoLinterAliases(l:all_linters) - echom ' Enabled Linters: ' . string(l:enabled_names) - echom ' Linter Variables:' - echom '' + call s:Echo(' Enabled Linters: ' . string(l:enabled_names)) + call s:Echo(' Linter Variables:') + call s:Echo('') call s:EchoLinterVariables(l:variable_list) - echom ' Global Variables:' - echom '' + call s:Echo(' Global Variables:') + call s:Echo('') call s:EchoGlobalVariables() - echom ' Command History:' - echom '' + call s:Echo(' Command History:') + call s:Echo('') call s:EchoCommandHistory() endfunction @@ -179,5 +183,5 @@ function! ale#debugging#InfoToClipboard() abort silent call ale#debugging#Info() redir END - echom 'ALEInfo copied to your clipboard' + call s:Echo('ALEInfo copied to your clipboard') endfunction diff --git a/autoload/ale/engine.vim b/autoload/ale/engine.vim index e08de16..f65108f 100644 --- a/autoload/ale/engine.vim +++ b/autoload/ale/engine.vim @@ -251,10 +251,10 @@ function! s:HandleTSServerDiagnostics(response, error_type) abort endfunction function! s:HandleLSPErrorMessage(error_message) abort - echoerr 'Error from LSP:' + execute 'echoerr ''Error from LSP:''' for l:line in split(a:error_message, "\n") - echoerr l:line + execute 'echoerr l:line' endfor endfunction diff --git a/autoload/ale/fix.vim b/autoload/ale/fix.vim index 5a42b74..c4143aa 100644 --- a/autoload/ale/fix.vim +++ b/autoload/ale/fix.vim @@ -75,7 +75,7 @@ function! ale#fix#ApplyFixes(buffer, output) abort if l:data.lines_before != l:lines call remove(g:ale_fix_buffer_data, a:buffer) - echoerr 'The file was changed before fixing finished' + execute 'echoerr ''The file was changed before fixing finished''' return endif endif @@ -406,17 +406,18 @@ function! ale#fix#Fix(...) abort let l:callback_list = s:GetCallbacks() catch /E700/ let l:function_name = join(split(split(v:exception, ':')[3])) - echom printf( + let l:echo_message = printf( \ 'There is no fixer named `%s`. Check :ALEFixSuggest', \ l:function_name, \) + execute 'echom l:echo_message' return 0 endtry if empty(l:callback_list) if l:fixing_flag is# '' - echom 'No fixers have been defined. Try :ALEFixSuggest' + execute 'echom ''No fixers have been defined. Try :ALEFixSuggest''' endif return 0 diff --git a/autoload/ale/toggle.vim b/autoload/ale/toggle.vim index aa6d113..7197498 100644 --- a/autoload/ale/toggle.vim +++ b/autoload/ale/toggle.vim @@ -158,7 +158,7 @@ function! ale#toggle#ToggleBuffer(buffer) abort " Disabling ALE globally removes autocmd events, so we cannot enable " linting locally when linting is disabled globally if l:enabled && !g:ale_enabled - echom 'ALE cannot be enabled locally when disabled globally' + execute 'echom ''ALE cannot be enabled locally when disabled globally''' return endif diff --git a/plugin/ale.vim b/plugin/ale.vim index 31c3377..d9710fa 100644 --- a/plugin/ale.vim +++ b/plugin/ale.vim @@ -24,8 +24,8 @@ endif if !s:has_features " Only output a warning if editing some special files. if index(['', 'gitcommit'], &filetype) == -1 - echoerr 'ALE requires NeoVim >= 0.1.5 or Vim 8 with +timers +job +channel' - echoerr 'Please update your editor appropriately.' + execute 'echoerr ''ALE requires NeoVim >= 0.1.5 or Vim 8 with +timers +job +channel''' + execute 'echoerr ''Please update your editor appropriately.''' endif " Stop here, as it won't work. diff --git a/test/script/custom-checks b/test/script/custom-checks index a1a734d..e2c906b 100755 --- a/test/script/custom-checks +++ b/test/script/custom-checks @@ -90,5 +90,6 @@ check_errors '==#' "Use 'is#' instead of '==#'. 0 ==# 'foobar' is true" check_errors '==?' "Use 'is?' instead of '==?'. 0 ==? 'foobar' is true" check_errors '!=#' "Use 'isnot#' instead of '!=#'. 0 !=# 'foobar' is false" check_errors '!=?' "Use 'isnot?' instead of '!=?'. 0 !=? 'foobar' is false" +check_errors '^ *:\?echo' "Stray echo line. Use \`execute echo\` if you want to echo something" exit $RETURN_CODE