mirror of https://github.com/dense-analysis/ale
Fix 2732 - Add bashate support
This commit is contained in:
parent
bbe5153fcb
commit
7b9855f1fe
|
@ -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*
|
||||
|
||||
|
||||
===============================================================================
|
||||
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*
|
||||
|
||||
|
|
|
@ -31,6 +31,7 @@ Notes:
|
|||
* Awk
|
||||
* `gawk`
|
||||
* Bash
|
||||
* `bashate`
|
||||
* `language-server`
|
||||
* `shell` (-n flag)
|
||||
* `shellcheck`
|
||||
|
|
|
@ -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|
|
||||
|
|
|
@ -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/)
|
||||
|
|
|
@ -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'
|
|
@ -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',
|
||||
\ ])
|
Loading…
Reference in New Issue