Fix test for echoing messages

The previous linter rule about stray echo lines has been restored, and
now all problems for custom linting rules can be ignored by adding a
comment above problem lines.
This commit is contained in:
w0rp 2022-04-01 14:35:07 +01:00
parent b3d1d6eecf
commit d3df00b898
No known key found for this signature in database
GPG Key ID: 0FC1ECAA8C81CD83
12 changed files with 77 additions and 43 deletions

View File

@ -776,7 +776,8 @@ function! s:OnReady(linter, lsp_details) abort
if a:linter.lsp is# 'tsserver' if a:linter.lsp is# 'tsserver'
if get(g:, 'ale_completion_tsserver_autoimport') is 1 if get(g:, 'ale_completion_tsserver_autoimport') is 1
execute 'echom `g:ale_completion_tsserver_autoimport` is deprecated. Use `g:ale_completion_autoimport` instead.''' " no-custom-checks
echom '`g:ale_completion_tsserver_autoimport` is deprecated. Use `g:ale_completion_autoimport` instead.'
endif endif
let l:message = ale#lsp#tsserver_message#Completions( let l:message = ale#lsp#tsserver_message#Completions(

View File

@ -10,6 +10,12 @@ let g:ale_echo_msg_format = get(g:, 'ale_echo_msg_format', '%code: %%s')
let s:cursor_timer = -1 let s:cursor_timer = -1
" A wrapper for echon so we can test messages we echo in Vader tests.
function! ale#cursor#Echon(message) abort
" no-custom-checks
echon a:message
endfunction
function! ale#cursor#TruncatedEcho(original_message) abort function! ale#cursor#TruncatedEcho(original_message) abort
let l:message = a:original_message let l:message = a:original_message
" Change tabs to spaces. " Change tabs to spaces.
@ -37,7 +43,7 @@ function! ale#cursor#TruncatedEcho(original_message) abort
let l:message = l:message[:&columns - 5] . '...' let l:message = l:message[:&columns - 5] . '...'
endif endif
echon l:message call ale#cursor#Echon(l:message)
catch /^Vim\%((\a\+)\)\=:E523/ catch /^Vim\%((\a\+)\)\=:E523/
" Fallback into manual truncate (#1987) " Fallback into manual truncate (#1987)
let l:winwidth = winwidth(0) let l:winwidth = winwidth(0)
@ -97,7 +103,9 @@ function! ale#cursor#EchoCursorWarning(...) abort
elseif get(l:info, 'echoed') elseif get(l:info, 'echoed')
" We'll only clear the echoed message when moving off errors once, " We'll only clear the echoed message when moving off errors once,
" so we don't continually clear the echo line. " so we don't continually clear the echo line.
execute 'echo' "
" no-custom-checks
echo
let l:info.echoed = 0 let l:info.echoed = 0
endif endif
endif endif
@ -160,7 +168,8 @@ function! s:ShowCursorDetailForItem(loc, options) abort
" Clear the echo message if we manually displayed details. " Clear the echo message if we manually displayed details.
if !l:stay_here if !l:stay_here
execute 'echo' " no-custom-checks
echo
endif endif
endif endif
endfunction endfunction

View File

@ -62,7 +62,8 @@ let s:global_variable_list = [
\] \]
function! s:Echo(message) abort function! s:Echo(message) abort
execute 'echo a:message' " no-custom-checks
echo a:message
endfunction endfunction
function! s:GetLinterVariables(filetype, exclude_linter_names) abort function! s:GetLinterVariables(filetype, exclude_linter_names) abort

View File

@ -77,7 +77,8 @@ function! ale#fix#ApplyFixes(buffer, output) abort
call remove(g:ale_fix_buffer_data, a:buffer) call remove(g:ale_fix_buffer_data, a:buffer)
if !l:data.ignore_file_changed_errors if !l:data.ignore_file_changed_errors
execute 'echoerr ''The file was changed before fixing finished''' " no-custom-checks
echoerr 'The file was changed before fixing finished'
endif endif
return return
@ -358,7 +359,8 @@ function! ale#fix#Fix(buffer, fixing_flag, ...) abort
\ 'There is no fixer named `%s`. Check :ALEFixSuggest', \ 'There is no fixer named `%s`. Check :ALEFixSuggest',
\ l:function_name, \ l:function_name,
\) \)
execute 'echom l:echo_message' " no-custom-checks
echom l:echo_message
endif endif
return 0 return 0
@ -366,7 +368,8 @@ function! ale#fix#Fix(buffer, fixing_flag, ...) abort
if empty(l:callback_list) if empty(l:callback_list)
if a:fixing_flag is# '' if a:fixing_flag is# ''
execute 'echom ''No fixers have been defined. Try :ALEFixSuggest''' " no-custom-checks
echom 'No fixers have been defined. Try :ALEFixSuggest'
endif endif
return 0 return 0

View File

@ -7,7 +7,8 @@
function! ale#floating_preview#Show(lines, ...) abort function! ale#floating_preview#Show(lines, ...) abort
if !exists('*nvim_open_win') && !has('popupwin') if !exists('*nvim_open_win') && !has('popupwin')
execute 'echom ''Floating windows not supported in this vim instance.''' " no-custom-checks
echom 'Floating windows not supported in this vim instance.'
return return
endif endif

View File

@ -64,7 +64,8 @@ function! ale#toggle#ToggleBuffer(buffer) abort
" Disabling ALE globally removes autocmd events, so we cannot enable " Disabling ALE globally removes autocmd events, so we cannot enable
" linting locally when linting is disabled globally " linting locally when linting is disabled globally
if l:enabled && !g:ale_enabled if l:enabled && !g:ale_enabled
execute 'echom ''ALE cannot be enabled locally when disabled globally''' " no-custom-checks
echom 'ALE cannot be enabled locally when disabled globally'
return return
endif endif

View File

@ -3,7 +3,8 @@
function! s:OpenJDTLink(root, uri, line, column, options, result) abort function! s:OpenJDTLink(root, uri, line, column, options, result) abort
if has_key(a:result, 'error') if has_key(a:result, 'error')
execute 'echoerr a:result.error.message' " no-custom-checks
echoerr a:result.error.message
return return
endif endif
@ -11,7 +12,8 @@ function! s:OpenJDTLink(root, uri, line, column, options, result) abort
let l:contents = a:result['result'] let l:contents = a:result['result']
if type(l:contents) is# type(v:null) if type(l:contents) is# type(v:null)
execute 'echoerr ''File content not found''' " no-custom-checks
echoerr 'File content not found'
endif endif
" disable autocmd when opening buffer " disable autocmd when opening buffer
@ -59,7 +61,8 @@ endfunction
function! s:ReadClassFileContents(uri, result) abort function! s:ReadClassFileContents(uri, result) abort
if has_key(a:result, 'error') if has_key(a:result, 'error')
execute 'echoerr a:result.error.message' " no-custom-checks
echoerr a:result.error.message
return return
endif endif
@ -67,7 +70,8 @@ function! s:ReadClassFileContents(uri, result) abort
let l:contents = a:result['result'] let l:contents = a:result['result']
if type(l:contents) is# type(v:null) if type(l:contents) is# type(v:null)
execute 'echoerr ''File content not found''' " no-custom-checks
echoerr 'File content not found'
endif endif
call setline(1, split(l:contents, '\n')) call setline(1, split(l:contents, '\n'))

View File

@ -25,7 +25,8 @@ function! ale#util#ShowMessage(string, ...) abort
" We have to assume the user is using a monospace font. " We have to assume the user is using a monospace font.
if has('nvim') || (a:string !~? "\n" && len(a:string) < &columns) if has('nvim') || (a:string !~? "\n" && len(a:string) < &columns)
execute 'echo a:string' " no-custom-checks
echo a:string
else else
call ale#preview#Show(split(a:string, "\n"), extend( call ale#preview#Show(split(a:string, "\n"), extend(
\ { \ {

View File

@ -98,8 +98,8 @@ should also follow some additional rules designed to prevent mistakes. Some of
these are reported with ALE's `custom-linting-rules` script. See these are reported with ALE's `custom-linting-rules` script. See
|ale-development-tests|. |ale-development-tests|.
* Don't leave stray `:echo` lines in code. Use `execute 'echo' ...` if you must * Don't leave stray `:echo` lines in code. Write `" no-custom-checks` above
echo something. the line if you must echo something.
* For strings use |is#| instead of |==#|, `is?` instead of `==?`, `isnot#` * For strings use |is#| instead of |==#|, `is?` instead of `==?`, `isnot#`
instead of `!=#`, and `isnot?` instead of `!=?`. This is because `'x' ==# 0` instead of `!=#`, and `isnot?` instead of `!=?`. This is because `'x' ==# 0`
returns 1, while `'x' is# 0` returns 0, so you will experience fewer issues returns 1, while `'x' is# 0` returns 0, so you will experience fewer issues

View File

@ -24,8 +24,10 @@ endif
if !s:has_features if !s:has_features
" Only output a warning if editing some special files. " Only output a warning if editing some special files.
if index(['', 'gitcommit'], &filetype) == -1 if index(['', 'gitcommit'], &filetype) == -1
execute 'echoerr ''ALE requires NeoVim >= 0.2.0 or Vim 8 with +timers +job +channel''' " no-custom-checks
execute 'echoerr ''Please update your editor appropriately.''' echoerr 'ALE requires NeoVim >= 0.2.0 or Vim 8 with +timers +job +channel'
" no-custom-checks
echoerr 'Please update your editor appropriately.'
endif endif
" Stop here, as it won't work. " Stop here, as it won't work.

View File

@ -73,6 +73,17 @@ check_errors() {
for directory in "${directories[@]}"; do for directory in "${directories[@]}"; do
# shellcheck disable=SC2086 # shellcheck disable=SC2086
while read -r; do while read -r; do
line=$(cut -d ":" -f2 <<< "$REPLY")
if ((line > 1)); then
line=$((line - 1))
file=$(cut -d ":" -f1 <<< "$REPLY")
if sed -n "${line},${line}p" $file | grep -q '^ *" *no-custom-checks$'; then
continue
fi
fi
RETURN_CODE=1 RETURN_CODE=1
echo "$REPLY $message" echo "$REPLY $message"
done < <(grep -H -n "$regex" $include_arg $exclude_arg "$directory"/**/*.vim \ done < <(grep -H -n "$regex" $include_arg $exclude_arg "$directory"/**/*.vim \
@ -125,7 +136,7 @@ check_errors '==#' "Use 'is#' instead of '==#'. 0 ==# 'foobar' is true"
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 '!=?' "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" check_errors '^ *:\?echo' "Stray echo line. Ignore with \" no-custom-checks if needed"
check_errors '^ *:\?redir' 'User execute() instead of redir' check_errors '^ *:\?redir' 'User execute() instead of redir'
# Exclusions for grandfathered-in exceptions # Exclusions for grandfathered-in exceptions
exclusions="clojure/clj_kondo.vim elixir/elixir_ls.vim go/golangci_lint.vim swift/swiftformat.vim" exclusions="clojure/clj_kondo.vim elixir/elixir_ls.vim go/golangci_lint.vim swift/swiftformat.vim"

View File

@ -85,14 +85,12 @@ Before:
let g:ale_set_highlights = 0 let g:ale_set_highlights = 0
let g:ale_echo_cursor = 1 let g:ale_echo_cursor = 1
function GetLastMessage() runtime autoload/ale/cursor.vim
redir => l:output
silent mess
redir END
let l:lines = split(l:output, "\n") let g:last_message = ''
return empty(l:lines) ? '' : l:lines[-1] function! ale#cursor#Echon(message) abort
let g:last_message = a:message
endfunction endfunction
call ale#linter#Reset() call ale#linter#Reset()
@ -101,6 +99,10 @@ Before:
After: After:
Restore Restore
unlet! g:last_message
runtime autoload/ale/cursor.vim
call cursor(1, 1) call cursor(1, 1)
let g:ale_set_loclist = 1 let g:ale_set_loclist = 1
@ -112,8 +114,6 @@ After:
unlet! g:output unlet! g:output
unlet! b:ale_loclist_msg_format unlet! b:ale_loclist_msg_format
delfunction GetLastMessage
" Clearing the messages breaks tests on NeoVim for some reason, but all " Clearing the messages breaks tests on NeoVim for some reason, but all
" we need to do for these tests is just make it so the last message isn't " we need to do for these tests is just make it so the last message isn't
" carried over between test cases. " carried over between test cases.
@ -135,19 +135,19 @@ Execute(Messages should be shown for the correct lines):
call cursor(1, 1) call cursor(1, 1)
call ale#cursor#EchoCursorWarning() call ale#cursor#EchoCursorWarning()
AssertEqual 'semi: Missing semicolon.', GetLastMessage() AssertEqual 'semi: Missing semicolon.', g:last_message
Execute(Messages should be shown for earlier columns): Execute(Messages should be shown for earlier columns):
call cursor(2, 1) call cursor(2, 1)
call ale#cursor#EchoCursorWarning() call ale#cursor#EchoCursorWarning()
AssertEqual 'space-infix-ops: Infix operators must be spaced.', GetLastMessage() AssertEqual 'space-infix-ops: Infix operators must be spaced.', g:last_message
Execute(Messages should be shown for later columns): Execute(Messages should be shown for later columns):
call cursor(2, 16) call cursor(2, 16)
call ale#cursor#EchoCursorWarning() call ale#cursor#EchoCursorWarning()
AssertEqual 'radix: Missing radix parameter', GetLastMessage() AssertEqual 'radix: Missing radix parameter', g:last_message
Execute(The message at the cursor should be shown when linting ends): Execute(The message at the cursor should be shown when linting ends):
call cursor(1, 1) call cursor(1, 1)
@ -156,13 +156,13 @@ Execute(The message at the cursor should be shown when linting ends):
\ g:ale_buffer_info[bufnr('%')].loclist, \ g:ale_buffer_info[bufnr('%')].loclist,
\) \)
AssertEqual 'semi: Missing semicolon.', GetLastMessage() AssertEqual 'semi: Missing semicolon.', g:last_message
Execute(The message at the cursor should be shown on InsertLeave): Execute(The message at the cursor should be shown on InsertLeave):
call cursor(2, 9) call cursor(2, 9)
doautocmd InsertLeave doautocmd InsertLeave
AssertEqual 'space-infix-ops: Infix operators must be spaced.', GetLastMessage() AssertEqual 'space-infix-ops: Infix operators must be spaced.', g:last_message
Execute(ALEDetail should print 'detail' attributes): Execute(ALEDetail should print 'detail' attributes):
call cursor(1, 1) call cursor(1, 1)
@ -187,7 +187,7 @@ Execute(ALEDetail should not capitlise cursor messages):
call cursor(3, 1) call cursor(3, 1)
call ale#cursor#EchoCursorWarning() call ale#cursor#EchoCursorWarning()
AssertEqual 'lowercase error', GetLastMessage() AssertEqual 'lowercase error', g:last_message
Execute(The linter name should be formatted into the message correctly): Execute(The linter name should be formatted into the message correctly):
let g:ale_echo_msg_format = '%linter%: %s' let g:ale_echo_msg_format = '%linter%: %s'
@ -197,7 +197,7 @@ Execute(The linter name should be formatted into the message correctly):
AssertEqual AssertEqual
\ 'bettercode: Infix operators must be spaced.', \ 'bettercode: Infix operators must be spaced.',
\ GetLastMessage() \ g:last_message
Execute(The severity should be formatted into the message correctly): Execute(The severity should be formatted into the message correctly):
let g:ale_echo_msg_format = '%severity%: %s' let g:ale_echo_msg_format = '%severity%: %s'
@ -207,17 +207,17 @@ Execute(The severity should be formatted into the message correctly):
AssertEqual AssertEqual
\ 'Warning: Infix operators must be spaced.', \ 'Warning: Infix operators must be spaced.',
\ GetLastMessage() \ g:last_message
call cursor(1, 10) call cursor(1, 10)
call ale#cursor#EchoCursorWarning() call ale#cursor#EchoCursorWarning()
AssertEqual 'Error: Missing semicolon.', GetLastMessage() AssertEqual 'Error: Missing semicolon.', g:last_message
call cursor(1, 14) call cursor(1, 14)
call ale#cursor#EchoCursorWarning() call ale#cursor#EchoCursorWarning()
AssertEqual 'Info: Some information', GetLastMessage() AssertEqual 'Info: Some information', g:last_message
Execute(The %code% and %ifcode% should show the code and some text): Execute(The %code% and %ifcode% should show the code and some text):
let g:ale_echo_msg_format = '%(code) %%s' let g:ale_echo_msg_format = '%(code) %%s'
@ -227,7 +227,7 @@ Execute(The %code% and %ifcode% should show the code and some text):
AssertEqual AssertEqual
\ '(space-infix-ops) Infix operators must be spaced.', \ '(space-infix-ops) Infix operators must be spaced.',
\ GetLastMessage() \ g:last_message
Execute(The %code% and %ifcode% should be removed when there's no code): Execute(The %code% and %ifcode% should be removed when there's no code):
let g:ale_echo_msg_format = '%(code) %%s' let g:ale_echo_msg_format = '%(code) %%s'
@ -235,7 +235,7 @@ Execute(The %code% and %ifcode% should be removed when there's no code):
call cursor(1, 14) call cursor(1, 14)
call ale#cursor#EchoCursorWarning() call ale#cursor#EchoCursorWarning()
AssertEqual 'Some information', GetLastMessage() AssertEqual 'Some information', g:last_message
Execute(The buffer message format option should take precedence): Execute(The buffer message format option should take precedence):
let g:ale_echo_msg_format = '%(code) %%s' let g:ale_echo_msg_format = '%(code) %%s'
@ -244,13 +244,13 @@ Execute(The buffer message format option should take precedence):
call cursor(1, 14) call cursor(1, 14)
call ale#cursor#EchoCursorWarning() call ale#cursor#EchoCursorWarning()
AssertEqual 'FOO Some information', GetLastMessage() AssertEqual 'FOO Some information', g:last_message
Execute(The cursor message shouldn't be echoed if the option is off): Execute(The cursor message shouldn't be echoed if the option is off):
let g:ale_echo_cursor = 0 let g:ale_echo_cursor = 0
echom 'foo' let g:last_message = 'foo'
call cursor(1, 1) call cursor(1, 1)
call ale#cursor#EchoCursorWarning() call ale#cursor#EchoCursorWarning()
AssertEqual 'foo', GetLastMessage() AssertEqual 'foo', g:last_message