]> git.madduck.net Git - etc/vim.git/blob - autoload/ale/handlers/ktlint.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] / autoload / ale / handlers / ktlint.vim
1 " Author: Michael Phillips <michaeljoelphillips@gmail.com>
2 " Description: Handler functions for ktlint.
3
4 call ale#Set('kotlin_ktlint_executable', 'ktlint')
5 call ale#Set('kotlin_ktlint_rulesets', [])
6 call ale#Set('kotlin_ktlint_options', '')
7
8 function! ale#handlers#ktlint#GetCommand(buffer) abort
9     let l:executable = ale#Var(a:buffer, 'kotlin_ktlint_executable')
10     let l:options = ale#Var(a:buffer, 'kotlin_ktlint_options')
11     let l:rulesets = ale#handlers#ktlint#GetRulesets(a:buffer)
12
13     return ale#Escape(l:executable)
14     \   . (empty(l:options) ? '' : ' ' . l:options)
15     \   . (empty(l:rulesets) ? '' : ' ' . l:rulesets)
16     \   . ' --stdin'
17 endfunction
18
19 function! ale#handlers#ktlint#GetRulesets(buffer) abort
20     let l:rulesets = map(ale#Var(a:buffer, 'kotlin_ktlint_rulesets'), '''--ruleset '' . v:val')
21
22     return join(l:rulesets, ' ')
23 endfunction
24
25 function! ale#handlers#ktlint#Handle(buffer, lines) abort
26     let l:message_pattern = '^\(.*\):\([0-9]\+\):\([0-9]\+\):\s\+\(.*\)'
27     let l:output = []
28
29     for l:match in ale#util#GetMatches(a:lines, l:message_pattern)
30         let l:line = l:match[2] + 0
31         let l:column = l:match[3] + 0
32         let l:text = l:match[4]
33
34         let l:type = l:text =~? 'not a valid kotlin file' ? 'E' : 'W'
35
36         call add(l:output, {
37         \   'lnum': l:line,
38         \   'col': l:column,
39         \   'text': l:text,
40         \   'type': l:type
41         \})
42     endfor
43
44     return l:output
45 endfunction