]> git.madduck.net Git - etc/vim.git/blob - .vim/bundle/ale/ale_linters/fish/fish.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:

Do not set EDITOR/VISUAL for shell
[etc/vim.git] / .vim / bundle / ale / ale_linters / fish / fish.vim
1 " Author: Niraj Thapaliya - https://github.com/nthapaliya
2 " Description: Lints fish files using fish -n
3
4 function! ale_linters#fish#fish#Handle(buffer, lines) abort
5     " Matches patterns such as:
6     "
7     " home/.config/fish/functions/foo.fish (line 1): Missing end to balance this function definition
8     " function foo
9     " ^
10     "
11     " OR, patterns such as:
12     "
13     " Unsupported use of '||'. In fish, please use 'COMMAND; or COMMAND'.
14     " /tmp/vLz620o/258/test.fish (line 2): if set -q SSH_CLIENT || set -q SSH_TTY
15     "                                                            ^
16     "
17     " fish -n can return errors in either format.
18     let l:pattern = '^\(.* (line \(\d\+\)): \)\(.*\)$'
19     let l:column_pattern = '^ *\^'
20     let l:output = []
21     let l:column_offset = 0
22     let l:last_line_with_message = ''
23
24     for l:line in a:lines
25         " Look for error lines first.
26         let l:match = matchlist(l:line, l:pattern)
27
28         if !empty(l:match)
29             if !empty(l:last_line_with_message)
30                 let l:text = l:last_line_with_message
31             else
32                 let l:text = l:match[3]
33             endif
34
35             let l:column_offset = len(l:match[1])
36
37             let l:last_line_with_message = ''
38             call add(l:output, {
39             \  'col': 0,
40             \  'lnum': str2nr(l:match[2]),
41             \  'text': l:text,
42             \})
43         else
44             " Look for column markers like '   ^' second.
45             " The column index will be set according to how long the line is.
46             let l:column_match = matchstr(l:line, l:column_pattern)
47
48             if !empty(l:column_match) && !empty(l:output)
49                 let l:output[-1].col = len(l:column_match) - l:column_offset
50                 let l:last_line_with_message = ''
51             else
52                 let l:last_line_with_message = l:line
53                 let l:column_offset = 0
54             endif
55         endif
56     endfor
57
58     return l:output
59 endfunction
60
61 call ale#linter#Define('fish', {
62 \   'name': 'fish',
63 \   'output_stream': 'stderr',
64 \   'executable': 'fish',
65 \   'command': 'fish -n %t',
66 \   'callback': 'ale_linters#fish#fish#Handle',
67 \})