Merge remote-tracking branch 'upstream/master'

This commit is contained in:
Bartek thindil Jasicki
2021-01-15 09:42:14 +01:00
36 changed files with 683 additions and 72 deletions

View File

@@ -0,0 +1,40 @@
Before:
call ale#assert#SetUpLinterTest('erlang', 'erlc')
After:
call ale#assert#TearDownLinterTest()
Execute(The default command should be correct.):
let g:cmd = ale_linters#erlang#erlc#GetCommand(bufnr(''))
let g:regex = 'erlc.\+-o.\+%t'
let g:matched = match(g:cmd, g:regex)
" match returns -1 if not found
AssertNotEqual
\ g:matched,
\ -1,
\ 'Command error: expected [' . g:cmd . '] to match [' . g:regex . ']'
Execute(The command should accept configured executable.):
let b:ale_erlang_erlc_executable = '/usr/bin/erlc'
let g:cmd = ale_linters#erlang#erlc#GetCommand(bufnr(''))
let g:regex = '/usr/bin/erlc.\+-o.\+%t'
let g:matched = match(g:cmd, g:regex)
" match returns -1 if not found
AssertNotEqual
\ g:matched,
\ -1,
\ 'Command error: expected [' . g:cmd . '] to match [' . g:regex . ']'
Execute(The command should accept configured options.):
let b:ale_erlang_erlc_options = '-I include'
let g:cmd = ale_linters#erlang#erlc#GetCommand(bufnr(''))
let g:regex = 'erlc.\+-o.\+-I include.\+%t'
let g:matched = match(g:cmd, g:regex)
" match returns -1 if not found
AssertNotEqual
\ g:matched,
\ -1,
\ 'Command error: expected [' . g:cmd . '] to match [' . g:regex . ']'

View File

@@ -1,5 +1,6 @@
Before:
call ale#assert#SetUpLinterTest('javascript', 'fecs')
runtime autoload/ale/handlers/fecs.vim
After:
call ale#assert#TearDownLinterTest()

View File

@@ -0,0 +1,20 @@
Before:
call ale#assert#SetUpLinterTest('inko', 'inko')
call ale#test#SetFilename('inko_paths/test.inko')
After:
call ale#assert#TearDownLinterTest()
Execute(The default executable path should be correct):
AssertLinter 'inko', ale#Escape('inko') . ' build --check --format=json %s'
Execute(The inko callback should include tests/ for test paths):
call ale#engine#Cleanup(bufnr(''))
noautocmd e! inko_paths/tests/test/test_foo.inko
call ale#engine#InitBufferInfo(bufnr(''))
AssertLinter 'inko',
\ ale#Escape('inko')
\ . ' build --check --format=json --include '
\ . ale#Escape(ale#path#Simplify(g:dir . '/inko_paths/tests/'))
\ . ' %s'

View File

@@ -0,0 +1,54 @@
Before:
runtime ale_linters/inko/inko.vim
After:
call ale#linter#Reset()
Execute(The inko handler should parse errors correctly):
AssertEqual
\ [
\ {
\ 'filename': ale#path#Simplify('/tmp/foo.inko'),
\ 'lnum': 4,
\ 'col': 5,
\ 'text': 'this is an error',
\ 'type': 'E',
\ }
\ ],
\ ale#handlers#inko#Handle(bufnr(''), [
\ '[',
\ ' {',
\ ' "file": "/tmp/foo.inko",',
\ ' "line": 4,',
\ ' "column": 5,',
\ ' "message": "this is an error",',
\ ' "level": "error"',
\ ' }',
\ ']'
\ ])
Execute(The inko handler should parse warnings correctly):
AssertEqual
\ [
\ {
\ 'filename': ale#path#Simplify('/tmp/foo.inko'),
\ 'lnum': 4,
\ 'col': 5,
\ 'text': 'this is a warning',
\ 'type': 'W',
\ }
\ ],
\ ale#handlers#inko#Handle(bufnr(''), [
\ '[',
\ ' {',
\ ' "file": "/tmp/foo.inko",',
\ ' "line": 4,',
\ ' "column": 5,',
\ ' "message": "this is a warning",',
\ ' "level": "warning"',
\ ' }',
\ ']'
\ ])
Execute(The inko handler should handle empty output):
AssertEqual [], ale#handlers#inko#Handle(bufnr(''), [])

View File

@@ -0,0 +1,5 @@
#!/usr/bin/env bash
set -e
grep --exclude=tags -roh '\*.*\*$' doc | sort | uniq -d

View File

@@ -15,14 +15,13 @@ while read -r; do
if [[ "$REPLY" =~ ^! ]]; then
language="${REPLY/!/}"
else
# shellcheck disable=SC2001
echo "$language - $REPLY"
fi
done < <(
grep '^\*\|^ *\*' doc/ale-supported-languages-and-tools.txt \
| sed -e '1,2d' \
| sed 's/^\* */!/' \
| sed 's/^ *\* *\|!!\|\^\|(.*)\|`//g' \
| sed -E 's/^ *\* *|!!|\^|\(.*\)|`//g' \
| sed 's/ *$//'
) > "$doc_file"
@@ -30,13 +29,12 @@ while read -r; do
if [[ "$REPLY" =~ ^! ]]; then
language="${REPLY/!/}"
else
# shellcheck disable=SC2001
echo "$language - $REPLY"
fi
done < <(
grep '^\*\|^ *\*' supported-tools.md \
| sed 's/^\* */!/' \
| sed 's/^ *\* *\|:floppy_disk:\|:warning:\|(.*)\|\[\|\].*\|-n flag//g' \
| sed -E 's/^ *\* *|:floppy_disk:|:warning:|\(.*\)|\[|\].*|-n flag//g' \
| sed 's/ *$//'
) > "$readme_file"

11
test/script/check-tag-alignment Executable file
View File

@@ -0,0 +1,11 @@
#!/usr/bin/env bash
exit_code=0
# Documentation tags need to be aligned to the right margin, so look for
# tags which aren't at the right margin.
grep ' \*[^*]\+\*$' doc/ -r \
| awk '{ sep = index($0, ":"); if (length(substr($0, sep + 1 )) < 79) { print } }' \
| grep . && exit_code=1
exit $exit_code

View File

@@ -0,0 +1,22 @@
#!/usr/bin/env bash
set -e
exit_code=0
tag_regex='[gb]\?:\?\(ale\|ALE\)[a-zA-Z_\-]\+'
tags="$(mktemp -t tags.XXXXXXXX)"
refs="$(mktemp -t refs.XXXXXXXX)"
# Grep for tags and references, and complain if we find a reference without
# a tag for the reference. Only our tags will be included.
grep --exclude=tags -roh "\\*$tag_regex\\*" doc | sed 's/*//g' | sort -u > "$tags"
grep --exclude=tags -roh "|$tag_regex|" doc | sed 's/|//g' | sort -u > "$refs"
exit_code=0
if ! [[ $(comm -23 $refs $tags | wc -l) -eq 0 ]]; then
exit_code=1
fi
rm "$tags"
rm "$refs"

View File

@@ -35,7 +35,7 @@ sed -n "$toc_start_line,$toc_end_line"p doc/ale.txt \
> "$toc_file"
# Get all of the doc files in a natural sorted order.
doc_files="$(/usr/bin/env ls -1v doc | grep ^ale- | sed 's/^/doc\//' | paste -sd ' ' -)"
doc_files="$(/usr/bin/env ls -1v doc | grep '^ale-' | sed 's/^/doc\//' | paste -sd ' ' -)"
# shellcheck disable=SC2086
grep -h '\*ale-.*-options\|^[a-z].*\*ale-.*\*$' $doc_files \

View File

@@ -13,7 +13,7 @@ echo 'Custom warnings/errors follow:'
echo
set -o pipefail
docker run -a stdout "${docker_flags[@]}" test/script/custom-linting-rules . || exit_code=$?
docker run "${docker_flags[@]}" test/script/custom-linting-rules . || exit_code=$?
set +o pipefail
echo
@@ -23,7 +23,10 @@ echo '========================================'
echo 'Duplicate tags follow:'
echo
grep --exclude=tags -roh '\*.*\*$' doc | sort | uniq -d || exit_code=$?
set -o pipefail
docker run "${docker_flags[@]}" test/script/check-duplicate-tags . || exit_code=$?
set +o pipefail
echo
echo '========================================'
echo 'Checking for invalid tag references'
@@ -31,14 +34,9 @@ echo '========================================'
echo 'Invalid tag references tags follow:'
echo
tag_regex='[gb]\?:\?\(ale\|ALE\)[a-zA-Z_\-]\+'
# Grep for tags and references, and complain if we find a reference without
# a tag for the reference. Only our tags will be included.
diff -u \
<(grep --exclude=tags -roh "\\*$tag_regex\\*" doc | sort -u | sed 's/*//g') \
<(grep --exclude=tags -roh "|$tag_regex|" doc | sort -u | sed 's/|//g') \
| grep '^+[^+]' && exit_code=1
set -o pipefail
docker run "${docker_flags[@]}" test/script/check-tag-references || exit_code=$?
set +o pipefail
echo '========================================'
echo 'diff supported-tools.md and doc/ale-supported-languages-and-tools.txt tables'
@@ -46,7 +44,9 @@ echo '========================================'
echo 'Differences follow:'
echo
test/script/check-supported-tools-tables || exit_code=$?
set -o pipefail
docker run "${docker_flags[@]}" test/script/check-supported-tools-tables || exit_code=$?
set +o pipefail
echo '========================================'
echo 'Look for badly aligned doc tags'
@@ -54,18 +54,18 @@ echo '========================================'
echo 'Badly aligned tags follow:'
echo
# Documentation tags need to be aligned to the right margin, so look for
# tags which aren't at the right margin.
grep ' \*[^*]\+\*$' doc/ -r \
| awk '{ sep = index($0, ":"); if (length(substr($0, sep + 1 )) < 79) { print } }' \
| grep . && exit_code=1
set -o pipefail
docker run "${docker_flags[@]}" test/script/check-tag-alignment || exit_code=$?
set +o pipefail
echo '========================================'
echo 'Look for table of contents issues'
echo '========================================'
echo
test/script/check-toc || exit_code=$?
set -o pipefail
docker run "${docker_flags[@]}" test/script/check-toc || exit_code=$?
set +o pipefail
echo '========================================'
echo 'Check Python code'

View File

@@ -53,17 +53,29 @@ check_errors() {
regex="$1"
message="$2"
include_arg=''
exclude_arg=''
if [ $# -gt 2 ]; then
include_arg="--include $3"
fi
if [ $# -gt 3 ]; then
shift
shift
shift
while (( "$#" )); do
exclude_arg="$exclude_arg --exclude $1"
shift
done
fi
for directory in "${directories[@]}"; do
# shellcheck disable=SC2086
while read -r; do
RETURN_CODE=1
echo "$REPLY $message"
done < <(grep -H -n "$regex" $include_arg "$directory"/**/*.vim \
done < <(grep -H -n "$regex" $include_arg $exclude_arg "$directory"/**/*.vim \
| grep -v 'no-custom-checks' \
| grep -o '^[^:]\+:[0-9]\+' \
| sed 's:^\./::')
@@ -92,7 +104,7 @@ if (( FIX_ERRORS )); then
done
fi
# The arguments are: regex, explanation, [filename_filter]
# The arguments are: regex, explanation, [filename_filter], [list, of, exclusions]
check_errors \
'^function.*) *$' \
'Function without abort keyword (See :help except-compat)'
@@ -114,7 +126,10 @@ 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 $'name.:.*\'[a-z_]*[^a-z_0-9][a-z_0-9]*\',$' 'Use snake_case names for linters' '*/ale_linters/*'
# Exclusions for grandfathered-in exceptions
exclusions="clojure/clj_kondo.vim elixir/elixir_ls.vim go/golangci_lint.vim swift/swiftformat.vim"
# shellcheck disable=SC2086
check_errors $'name.:.*\'[a-z_]*[^a-z_0-9][a-z_0-9]*\',$' 'Use snake_case names for linters' '*/ale_linters/*' $exclusions
# Checks for improving type checks.
check_errors $'\\(==.\\?\\|is\\) type([\'"]\+)' "Use 'is v:t_string' instead"
check_errors '\(==.\?\|is\) type([0-9]\+)' "Use 'is v:t_number' instead"

View File

@@ -0,0 +1,92 @@
Before:
let g:ale_floating_preview = 0
let g:ale_hover_to_floating_preview = 0
let g:ale_detail_to_floating_preview = 0
runtime autoload/ale/floating_preview.vim
let g:floated_lines = []
let g:floating_preview_show_called = 0
" Stub out so we can track the call
function! ale#floating_preview#Show(lines, ...) abort
let g:floating_preview_show_called = 1
let g:floated_lines = a:lines
endfunction
let g:ale_buffer_info = {
\ bufnr('%'): {
\ 'loclist': [
\ {
\ 'lnum': 1,
\ 'col': 10,
\ 'bufnr': bufnr('%'),
\ 'vcol': 0,
\ 'linter_name': 'notalinter',
\ 'nr': -1,
\ 'type': 'E',
\ 'code': 'semi',
\ 'text': "Missing semicolon.\r",
\ 'detail': "Every statement should end with a semicolon\nsecond line",
\ },
\ ],
\ }
\}
call ale#linter#Reset()
call ale#linter#PreventLoading('javascript')
After:
Restore
let g:ale_floating_preview = 0
let g:ale_hover_to_floating_preview = 0
let g:ale_detail_to_floating_preview = 0
call cursor(1, 1)
let g:ale_buffer_info = {}
" Close the preview window if it's open.
if &filetype is# 'ale-preview'
noautocmd :q!
endif
call ale#linter#Reset()
Given javascript(A file with warnings/errors):
var x = 3 + 12345678
var x = 5*2 + parseInt("10");
// comment
Execute(Floating preview is used with ALEDetail when g:ale_floating_preview set):
let g:ale_floating_preview = 1
call cursor(1, 10)
ALEDetail
let expected = ["Every statement should end with a semicolon", "second line"]
AssertEqual 1, g:floating_preview_show_called
AssertEqual expected, g:floated_lines
Execute(Floating preview is used with ALEDetail when g:ale_detail_to_floating_preview set):
let g:ale_detail_to_floating_preview = 1
call cursor(1, 10)
ALEDetail
let expected = ["Every statement should end with a semicolon", "second line"]
AssertEqual 1, g:floating_preview_show_called
AssertEqual expected, g:floated_lines
Execute(Floating preview is not used with ALEDetail by default):
call cursor(1, 10)
ALEDetail
AssertEqual 0, g:floating_preview_show_called

View File

@@ -7,9 +7,25 @@ Before:
let g:item_list = []
let g:show_message_arg_list = []
let g:ale_floating_preview = 0
let g:ale_hover_to_floating_preview = 0
let g:ale_detail_to_floating_preview = 0
runtime autoload/ale/linter.vim
runtime autoload/ale/lsp.vim
runtime autoload/ale/lsp_linter.vim
runtime autoload/ale/util.vim
runtime autoload/ale/floating_preview.vim
runtime autoload/ale/hover.vim
let g:floated_lines = []
let g:floating_preview_show_called = 0
" Stub out so we can track the call
function! ale#floating_preview#Show(lines, ...) abort
let g:floating_preview_show_called = 1
let g:floated_lines = a:lines
endfunction
function! ale#lsp_linter#StartLSP(buffer, linter, callback) abort
let g:Callback = a:callback
@@ -50,6 +66,7 @@ Before:
\)
endfunction
After:
call ale#hover#SetMap({})
call ale#test#RestoreDirectory()
@@ -65,6 +82,7 @@ After:
runtime autoload/ale/lsp_linter.vim
runtime autoload/ale/lsp.vim
runtime autoload/ale/util.vim
runtime autoload/ale/floating_preview.vim
Given python(Some Python file):
foo
@@ -168,6 +186,28 @@ Execute(LSP hover response with lists of strings and marked strings should be ha
\], g:show_message_arg_list
AssertEqual {}, ale#hover#GetMap()
Execute(LSP hover with ale_floating_preview should float):
let g:ale_floating_preview = 1
call HandleValidLSPResult({'contents': "the message\ncontinuing"})
AssertEqual 1, g:floating_preview_show_called
AssertEqual ["the message", "continuing"], g:floated_lines
Execute(LSP hover ale_hover_to_floating_preview should float):
let g:ale_hover_to_floating_preview = 1
call HandleValidLSPResult({'contents': "the message\ncontinuing"})
AssertEqual 1, g:floating_preview_show_called
AssertEqual ["the message", "continuing"], g:floated_lines
Execute(LSP hover by default should not float):
call HandleValidLSPResult({'contents': "the message\ncontinuing"})
AssertEqual 0, g:floating_preview_show_called
Execute(tsserver responses for documentation requests should be handled):
call ale#hover#SetMap({3: {'show_documentation': 1, 'buffer': bufnr('')}})
@@ -187,3 +227,46 @@ Execute(tsserver responses for documentation requests should be handled):
" The preview window should show the text.
AssertEqual ['foo is a very good method'], ale#test#GetPreviewWindowText()
silent! pclose
Execute(hover with show_documentation should be in the preview window, not floating):
let g:ale_hover_to_floating_preview = 1
let g:ale_floating_preview = 1
call ale#hover#SetMap({3: {'show_documentation': 1, 'buffer': bufnr('')}})
call ale#hover#HandleTSServerResponse(
\ 1,
\ {
\ 'command': 'quickinfo',
\ 'request_seq': 3,
\ 'success': v:true,
\ 'body': {
\ 'documentation': 'foo is a very good method',
\ 'displayString': 'foo bar ',
\ },
\ }
\)
let expected = ["Every statement should end with a semicolon", "second line"]
AssertEqual 0, g:floating_preview_show_called
Execute(TSServer hover without show_documentation and ale_floating_preview should float):
let g:ale_floating_preview = 1
call ale#hover#SetMap({3: {'buffer': bufnr('')}})
call ale#hover#HandleTSServerResponse(
\ 1,
\ {
\ 'command': 'quickinfo',
\ 'request_seq': 3,
\ 'success': v:true,
\ 'body': {
\ 'displayString': "the message\ncontinuing",
\ },
\ }
\)
AssertEqual 1, g:floating_preview_show_called
AssertEqual ["the message", "continuing"], g:floated_lines