mirror of
https://github.com/dense-analysis/ale.git
synced 2025-12-06 20:54:26 +08:00
Fix 2732 - Add bashate support
This commit is contained in:
43
ale_linters/sh/bashate.vim
Normal file
43
ale_linters/sh/bashate.vim
Normal file
@@ -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',
|
||||||
|
\})
|
||||||
@@ -2,6 +2,29 @@
|
|||||||
ALE Shell Integration *ale-sh-options*
|
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*
|
sh-language-server *ale-sh-language-server*
|
||||||
|
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ Notes:
|
|||||||
* Awk
|
* Awk
|
||||||
* `gawk`
|
* `gawk`
|
||||||
* Bash
|
* Bash
|
||||||
|
* `bashate`
|
||||||
* `language-server`
|
* `language-server`
|
||||||
* `shell` (-n flag)
|
* `shell` (-n flag)
|
||||||
* `shellcheck`
|
* `shellcheck`
|
||||||
|
|||||||
@@ -2593,6 +2593,7 @@ documented in additional help files.
|
|||||||
sasslint..............................|ale-scss-sasslint|
|
sasslint..............................|ale-scss-sasslint|
|
||||||
stylelint.............................|ale-scss-stylelint|
|
stylelint.............................|ale-scss-stylelint|
|
||||||
sh......................................|ale-sh-options|
|
sh......................................|ale-sh-options|
|
||||||
|
bashate...............................|ale-sh-bashate|
|
||||||
sh-language-server....................|ale-sh-language-server|
|
sh-language-server....................|ale-sh-language-server|
|
||||||
shell.................................|ale-sh-shell|
|
shell.................................|ale-sh-shell|
|
||||||
shellcheck............................|ale-sh-shellcheck|
|
shellcheck............................|ale-sh-shellcheck|
|
||||||
|
|||||||
@@ -40,6 +40,7 @@ formatting.
|
|||||||
* Awk
|
* Awk
|
||||||
* [gawk](https://www.gnu.org/software/gawk/)
|
* [gawk](https://www.gnu.org/software/gawk/)
|
||||||
* Bash
|
* Bash
|
||||||
|
* [bashate](https://github.com/openstack/bashate)
|
||||||
* [language-server](https://github.com/mads-hartmann/bash-language-server)
|
* [language-server](https://github.com/mads-hartmann/bash-language-server)
|
||||||
* shell [-n flag](https://www.gnu.org/software/bash/manual/bash.html#index-set)
|
* shell [-n flag](https://www.gnu.org/software/bash/manual/bash.html#index-set)
|
||||||
* [shellcheck](https://www.shellcheck.net/)
|
* [shellcheck](https://www.shellcheck.net/)
|
||||||
|
|||||||
15
test/command_callback/test_bashate_command_callback.vader
Normal file
15
test/command_callback/test_bashate_command_callback.vader
Normal file
@@ -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'
|
||||||
36
test/handler/test_bashate_handler.vader
Normal file
36
test/handler/test_bashate_handler.vader
Normal file
@@ -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',
|
||||||
|
\ ])
|
||||||
Reference in New Issue
Block a user