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

Merge commit '76265755a1add77121c8f9dabb3e9bb70fe9a972' as '.vim/bundle/ale'
[etc/vim.git] / .vim / bundle / ale / ale_linters / swift / swiftlint.vim
1 " Author: David Mohundro <david@mohundro.com>, Gordon Fontenot <gordon@fonten.io>
2 " Description: swiftlint for swift files
3
4 call ale#Set('swift_swiftlint_executable', 'swiftlint')
5 call ale#Set('swift_swiftlint_use_global', get(g:, 'ale_use_global_executables', 0))
6
7 function! ale_linters#swift#swiftlint#GetExecutable(buffer) abort
8     return ale#path#FindExecutable(a:buffer, 'swift_swiftlint', [
9     \ 'Pods/SwiftLint/swiftlint',
10     \ 'ios/Pods/SwiftLint/swiftlint',
11     \ 'swiftlint',
12     \])
13 endfunction
14
15 function! ale_linters#swift#swiftlint#GetCommand(buffer) abort
16     let l:executable = ale_linters#swift#swiftlint#GetExecutable(a:buffer)
17     let l:args = 'lint --use-stdin'
18
19     return ale#Escape(l:executable)
20     \ . ' ' .l:args
21 endfunction
22
23 function! ale_linters#swift#swiftlint#Handle(buffer, lines) abort
24     let l:pattern = '\v^([a-zA-Z]?:?[^:]+):(\d+):(\d+)?:? ([^:]+): (.+)$'
25     let l:output = []
26
27     for l:match in ale#util#GetMatches(a:lines, l:pattern)
28         let l:item = {
29         \   'lnum': str2nr(l:match[2]),
30         \   'type': l:match[4] is# 'error' ? 'E' : 'W',
31         \   'text': l:match[5],
32         \}
33
34         if l:match[4] is# 'error'
35             let l:item.type = 'E'
36         elseif l:match[4] is# 'note'
37             let l:item.type = 'I'
38         endif
39
40         if !empty(l:match[3])
41             let l:item.col = str2nr(l:match[3])
42         endif
43
44         " If the filename is something like <stdin>, <nofile> or -, then
45         " this is an error for the file we checked.
46         if l:match[1] isnot# '-' && l:match[1][0] isnot# '<'
47             let l:item['filename'] = l:match[1]
48         endif
49
50         " Parse the code if it's there.
51         let l:code_match = matchlist(l:item.text, '\v^(.+) \(([^ (]+)\)$')
52
53         if !empty(l:code_match)
54             let l:item.text = l:code_match[1]
55             let l:item.code = l:code_match[2]
56         endif
57
58         call add(l:output, l:item)
59     endfor
60
61     return l:output
62 endfunction
63
64 call ale#linter#Define('swift', {
65 \   'name': 'swiftlint',
66 \   'executable': function('ale_linters#swift#swiftlint#GetExecutable'),
67 \   'command': function('ale_linters#swift#swiftlint#GetCommand'),
68 \   'callback': 'ale_linters#swift#swiftlint#Handle',
69 \})