]> git.madduck.net Git - etc/vim.git/blob - ale_linters/swift/appleswiftformat.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 / swift / appleswiftformat.vim
1 " Authors: Klaas Pieter Annema <https://github.com/klaaspieter>, bosr <bosr@bosr.cc>
2 " Description: Support for swift-format https://github.com/apple/swift-format
3
4 function! ale_linters#swift#appleswiftformat#GetLinterCommand(buffer) abort
5     let l:command_args = ale#swift#GetAppleSwiftFormatCommand(a:buffer) . ' lint %t'
6     let l:config_args = ale#swift#GetAppleSwiftFormatConfigArgs(a:buffer)
7
8     if l:config_args isnot# ''
9         let l:command_args = l:command_args . ' ' . l:config_args
10     endif
11
12     return l:command_args
13 endfunction
14
15 function! ale_linters#swift#appleswiftformat#Handle(buffer, lines) abort
16     " Matches the typical output of swift-format, that is lines of the following pattern:
17     "
18     " Sources/main.swift:4:21: warning: [DoNotUseSemicolons] remove ';' and move the next statement to the new line
19     " Sources/main.swift:3:12: warning: [Spacing] remove 1 space
20     let l:pattern = '\v^.*:(\d+):(\d+): (\S+): \[(\S+)\] (.*)$'
21     let l:output = []
22
23     for l:match in ale#util#GetMatches(a:lines, l:pattern)
24         call add(l:output, {
25         \   'lnum': l:match[1] + 0,
26         \   'col': l:match[2] + 0,
27         \   'type': l:match[3] is# 'error' ? 'E' : 'W',
28         \   'code': l:match[4],
29         \   'text': l:match[5],
30         \})
31     endfor
32
33     return l:output
34 endfunction
35
36 call ale#linter#Define('swift', {
37 \   'name': 'apple-swift-format',
38 \   'executable': function('ale#swift#GetAppleSwiftFormatExecutable'),
39 \   'command': function('ale_linters#swift#appleswiftformat#GetLinterCommand'),
40 \   'output_stream': 'stderr',
41 \   'language': 'swift',
42 \   'callback': 'ale_linters#swift#appleswiftformat#Handle'
43 \})