summaryrefslogtreecommitdiff
path: root/ale_linters/sh
diff options
context:
space:
mode:
authorw0rp <w0rp@users.noreply.github.com>2020-07-21 12:47:33 +0100
committerGitHub <noreply@github.com>2020-07-21 12:47:33 +0100
commitf4668c751fba1af496d933af9fdcf1cf162a26f4 (patch)
tree80b05de5e073f426400fc34da274b9cdb86f6fac /ale_linters/sh
parent70ab831001dbe806fc5af3f33727f1fa32e3ff13 (diff)
parent7b9855f1fe811f4ec80bdeb81b5ab9b6d9249a49 (diff)
downloadale-f4668c751fba1af496d933af9fdcf1cf162a26f4.zip
Merge pull request #3070 from hsanson/2732-add-bashate-support
Fix 2732 - Add bashate support
Diffstat (limited to 'ale_linters/sh')
-rw-r--r--ale_linters/sh/bashate.vim43
1 files changed, 43 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',
+\})