]> git.madduck.net Git - etc/vim.git/blob - ale_linters/sh/shell.vim

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

All patches and comments are welcome. Please squash your changes to logical commits before using git-format-patch and git-send-email to patches@git.madduck.net. If you'd read over the Git project's submission guidelines and adhered to them, I'd be especially grateful.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

Squashed '.vim/bundle/ale/' content from commit 22185c4c
[etc/vim.git] / ale_linters / sh / shell.vim
1 " Author: w0rp <devw0rp@gmail.com>
2 " Description: Lints shell files by invoking the shell with -n
3
4 " This option can be changed to change the default shell when the shell
5 " cannot be taken from the hashbang line.
6 if !exists('g:ale_sh_shell_default_shell')
7     let g:ale_sh_shell_default_shell = fnamemodify($SHELL, ':t')
8
9     if g:ale_sh_shell_default_shell is# '' || g:ale_sh_shell_default_shell is# 'fish'
10         let g:ale_sh_shell_default_shell = 'bash'
11     endif
12 endif
13
14 function! ale_linters#sh#shell#GetExecutable(buffer) abort
15     let l:shell_type = ale#handlers#sh#GetShellType(a:buffer)
16
17     if !empty(l:shell_type)
18         return l:shell_type
19     endif
20
21     return ale#Var(a:buffer, 'sh_shell_default_shell')
22 endfunction
23
24 function! ale_linters#sh#shell#GetCommand(buffer) abort
25     return ale_linters#sh#shell#GetExecutable(a:buffer) . ' -n %t'
26 endfunction
27
28 function! ale_linters#sh#shell#Handle(buffer, lines) abort
29     " Matches patterns line the following:
30     "
31     " bash: line 13: syntax error near unexpected token `d'
32     " bash:行0: 未预期的符号“done”附近有语法错误
33     " bash: 列 90: 尋找匹配的「"」時遇到了未預期的檔案結束符
34     " sh: 11: Syntax error: "(" unexpected
35     let l:pattern = '\v([^:]+:\D*)(\d+): (.+)$'
36     let l:output = []
37
38     for l:match in ale#util#GetMatches(a:lines, l:pattern)
39         call add(l:output, {
40         \   'lnum': str2nr(l:match[2]),
41         \   'text': l:match[3],
42         \})
43     endfor
44
45     return l:output
46 endfunction
47
48 call ale#linter#Define('sh', {
49 \   'name': 'shell',
50 \   'output_stream': 'stderr',
51 \   'executable': function('ale_linters#sh#shell#GetExecutable'),
52 \   'command': function('ale_linters#sh#shell#GetCommand'),
53 \   'callback': 'ale_linters#sh#shell#Handle',
54 \})