diff options
author | Horacio Sanson <horacio@allm.net> | 2020-03-23 12:18:35 +0900 |
---|---|---|
committer | Horacio Sanson <horacio@allm.net> | 2020-03-23 12:18:35 +0900 |
commit | 7b9855f1fe811f4ec80bdeb81b5ab9b6d9249a49 (patch) | |
tree | cace14fc0780ed392140fc5bb8ada0f81d4d4e72 | |
parent | bbe5153fcb36dec9860ced33ae8ff0b5d76ac02a (diff) | |
download | ale-7b9855f1fe811f4ec80bdeb81b5ab9b6d9249a49.zip |
Fix 2732 - Add bashate support
-rw-r--r-- | ale_linters/sh/bashate.vim | 43 | ||||
-rw-r--r-- | doc/ale-sh.txt | 23 | ||||
-rw-r--r-- | doc/ale-supported-languages-and-tools.txt | 1 | ||||
-rw-r--r-- | doc/ale.txt | 1 | ||||
-rw-r--r-- | supported-tools.md | 1 | ||||
-rw-r--r-- | test/command_callback/test_bashate_command_callback.vader | 15 | ||||
-rw-r--r-- | test/handler/test_bashate_handler.vader | 36 |
7 files changed, 120 insertions, 0 deletions
diff --git a/ale_linters/sh/bashate.vim b/ale_linters/sh/bashate.vim new file mode 100644 index 00000000..3cd84245 --- /dev/null +++ b/ale_linters/sh/bashate.vim @@ -0,0 +1,43 @@ +" Author: hsanson <hsanson@gmail.com> +" Description: Lints sh files using bashate +" URL: https://github.com/openstack/bashate + +call ale#Set('sh_bashate_executable', 'bashate') +call ale#Set('sh_bashate_options', '') + +function! ale_linters#sh#bashate#GetExecutable(buffer) abort + return ale#Var(a:buffer, 'sh_bashate_executable') +endfunction + +function! ale_linters#sh#bashate#GetCommand(buffer) abort + let l:options = ale#Var(a:buffer, 'sh_bashate_options') + let l:executable = ale_linters#sh#bashate#GetExecutable(a:buffer) + + return ale#Escape(l:executable) . ' ' . l:options . ' ' . '%t' +endfunction + +function! ale_linters#sh#bashate#Handle(buffer, lines) abort + " Matches patterns line the following: + " + " /path/to/script/file:694:1: E003 Indent not multiple of 4 + let l:pattern = ':\(\d\+\):\(\d\+\): \(.*\)$' + let l:output = [] + + for l:match in ale#util#GetMatches(a:lines, l:pattern) + call add(l:output, { + \ 'lnum': str2nr(l:match[1]), + \ 'col': str2nr(l:match[2]), + \ 'text': l:match[3], + \}) + endfor + + return l:output +endfunction + +call ale#linter#Define('sh', { +\ 'name': 'bashate', +\ 'output_stream': 'stdout', +\ 'executable': function('ale_linters#sh#bashate#GetExecutable'), +\ 'command': function('ale_linters#sh#bashate#GetCommand'), +\ 'callback': 'ale_linters#sh#bashate#Handle', +\}) diff --git a/doc/ale-sh.txt b/doc/ale-sh.txt index 3eac9038..7897d0ce 100644 --- a/doc/ale-sh.txt +++ b/doc/ale-sh.txt @@ -3,6 +3,29 @@ ALE Shell Integration *ale-sh-options* =============================================================================== +bashate *ale-sh-bashate* + +g:ale_sh_bashate_executable *g:ale_sh_bashate_executable* + *b:ale_sh_bashate_executable* + Type: |String| + Default: `'bashate'` + + This variable sets executable used for bashate. + + +g:ale_sh_bashate_options *g:ale_sh_bashate_options* + *b:ale_sh_bashate_options* + Type: |String| + Default: `''` + + With this variable we are able to pass extra arguments for bashate. For + example to ignore the indentation rule: + +> + let g:ale_sh_shellcheck_options = '-i E003' +< + +=============================================================================== sh-language-server *ale-sh-language-server* g:ale_sh_language_server_executable *g:ale_sh_language_server_executable* diff --git a/doc/ale-supported-languages-and-tools.txt b/doc/ale-supported-languages-and-tools.txt index 29dabab7..cf537e6c 100644 --- a/doc/ale-supported-languages-and-tools.txt +++ b/doc/ale-supported-languages-and-tools.txt @@ -31,6 +31,7 @@ Notes: * Awk * `gawk` * Bash + * `bashate` * `language-server` * `shell` (-n flag) * `shellcheck` diff --git a/doc/ale.txt b/doc/ale.txt index da4328d9..c75bde16 100644 --- a/doc/ale.txt +++ b/doc/ale.txt @@ -2593,6 +2593,7 @@ documented in additional help files. sasslint..............................|ale-scss-sasslint| stylelint.............................|ale-scss-stylelint| sh......................................|ale-sh-options| + bashate...............................|ale-sh-bashate| sh-language-server....................|ale-sh-language-server| shell.................................|ale-sh-shell| shellcheck............................|ale-sh-shellcheck| diff --git a/supported-tools.md b/supported-tools.md index 0abc6b75..3c36af22 100644 --- a/supported-tools.md +++ b/supported-tools.md @@ -40,6 +40,7 @@ formatting. * Awk * [gawk](https://www.gnu.org/software/gawk/) * Bash + * [bashate](https://github.com/openstack/bashate) * [language-server](https://github.com/mads-hartmann/bash-language-server) * shell [-n flag](https://www.gnu.org/software/bash/manual/bash.html#index-set) * [shellcheck](https://www.shellcheck.net/) diff --git a/test/command_callback/test_bashate_command_callback.vader b/test/command_callback/test_bashate_command_callback.vader new file mode 100644 index 00000000..714cf690 --- /dev/null +++ b/test/command_callback/test_bashate_command_callback.vader @@ -0,0 +1,15 @@ +Before: + call ale#assert#SetUpLinterTest('sh', 'bashate') + call ale#test#SetFilename('test.sh') + +After: + call ale#assert#TearDownLinterTest() + +Execute(The default bashate command should be correct): + AssertLinter 'bashate', ale#Escape('bashate') . ' %t' + +Execute(The bashate command should accept options): + let b:ale_sh_bashate_options = '-i E310 --max-line-length 100' + + AssertLinter 'bashate', + \ ale#Escape('bashate') . ' -i E310 --max-line-length 100 %t' diff --git a/test/handler/test_bashate_handler.vader b/test/handler/test_bashate_handler.vader new file mode 100644 index 00000000..b61bb956 --- /dev/null +++ b/test/handler/test_bashate_handler.vader @@ -0,0 +1,36 @@ +Before: + runtime ale_linters/sh/bashate.vim + +After: + call ale#linter#Reset() + +Execute(The bashate handler should handle basic errors): + AssertEqual + \ [ + \ { + \ 'lnum': 777, + \ 'col': 1, + \ 'text': 'E003 Indent not multiple of 4', + \ }, + \ { + \ 'lnum': 783, + \ 'col': 1, + \ 'text': 'E020 Function declaration not in format ^function name {$', + \ }, + \ { + \ 'lnum': 786, + \ 'col': 1, + \ 'text': 'E010 The "do" should be on same line as for', + \ }, + \ { + \ 'lnum': 791, + \ 'col': 1, + \ 'text': 'E006 Line too long', + \ }, + \ ], + \ ale_linters#sh#bashate#Handle(bufnr(''), [ + \ 'run:777:1: E003 Indent not multiple of 4', + \ 'run:783:1: E020 Function declaration not in format ^function name {$', + \ 'run:786:1: E010 The "do" should be on same line as for', + \ 'run:791:1: E006 Line too long', + \ ]) |