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
12 changed files with 77 additions and 43 deletions

View File

@@ -73,6 +73,17 @@ check_errors() {
for directory in "${directories[@]}"; do
# shellcheck disable=SC2086
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
echo "$REPLY $message"
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 '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'
# Exclusions for grandfathered-in exceptions
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_echo_cursor = 1
function GetLastMessage()
redir => l:output
silent mess
redir END
runtime autoload/ale/cursor.vim
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
call ale#linter#Reset()
@@ -101,6 +99,10 @@ Before:
After:
Restore
unlet! g:last_message
runtime autoload/ale/cursor.vim
call cursor(1, 1)
let g:ale_set_loclist = 1
@@ -112,8 +114,6 @@ After:
unlet! g:output
unlet! b:ale_loclist_msg_format
delfunction GetLastMessage
" 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
" carried over between test cases.
@@ -135,19 +135,19 @@ Execute(Messages should be shown for the correct lines):
call cursor(1, 1)
call ale#cursor#EchoCursorWarning()
AssertEqual 'semi: Missing semicolon.', GetLastMessage()
AssertEqual 'semi: Missing semicolon.', g:last_message
Execute(Messages should be shown for earlier columns):
call cursor(2, 1)
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):
call cursor(2, 16)
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):
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,
\)
AssertEqual 'semi: Missing semicolon.', GetLastMessage()
AssertEqual 'semi: Missing semicolon.', g:last_message
Execute(The message at the cursor should be shown on InsertLeave):
call cursor(2, 9)
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):
call cursor(1, 1)
@@ -187,7 +187,7 @@ Execute(ALEDetail should not capitlise cursor messages):
call cursor(3, 1)
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):
let g:ale_echo_msg_format = '%linter%: %s'
@@ -197,7 +197,7 @@ Execute(The linter name should be formatted into the message correctly):
AssertEqual
\ 'bettercode: Infix operators must be spaced.',
\ GetLastMessage()
\ g:last_message
Execute(The severity should be formatted into the message correctly):
let g:ale_echo_msg_format = '%severity%: %s'
@@ -207,17 +207,17 @@ Execute(The severity should be formatted into the message correctly):
AssertEqual
\ 'Warning: Infix operators must be spaced.',
\ GetLastMessage()
\ g:last_message
call cursor(1, 10)
call ale#cursor#EchoCursorWarning()
AssertEqual 'Error: Missing semicolon.', GetLastMessage()
AssertEqual 'Error: Missing semicolon.', g:last_message
call cursor(1, 14)
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):
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
\ '(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):
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 ale#cursor#EchoCursorWarning()
AssertEqual 'Some information', GetLastMessage()
AssertEqual 'Some information', g:last_message
Execute(The buffer message format option should take precedence):
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 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):
let g:ale_echo_cursor = 0
echom 'foo'
let g:last_message = 'foo'
call cursor(1, 1)
call ale#cursor#EchoCursorWarning()
AssertEqual 'foo', GetLastMessage()
AssertEqual 'foo', g:last_message