summaryrefslogtreecommitdiff
path: root/ale_linters/kotlin
diff options
context:
space:
mode:
authorFrancis Agyapong <francisagyapong2@gmail.com>2017-06-02 12:41:46 -0600
committerw0rp <w0rp@users.noreply.github.com>2017-06-02 19:41:46 +0100
commit2c89a4c98a5a3435ed2b5b479a20f0e715553596 (patch)
tree9b60e63be3ae594dddf4f929a6c8f23c6c18c6c7 /ale_linters/kotlin
parent7c68889bbcf04091ea19bd4d3d18d5f800d24c30 (diff)
downloadale-2c89a4c98a5a3435ed2b5b479a20f0e715553596.zip
Add ktlint support (without formatting) for kotlin filetype (#610)
* Add ktlint support (without formatting) for kotlin filetype * Fix code style and refactor to use ALE utility functions (GetMatches) * Remove options for configuration file * Refactor: Rename exec variable and use ale#Set for variable configuration
Diffstat (limited to 'ale_linters/kotlin')
-rw-r--r--ale_linters/kotlin/ktlint.vim54
1 files changed, 54 insertions, 0 deletions
diff --git a/ale_linters/kotlin/ktlint.vim b/ale_linters/kotlin/ktlint.vim
new file mode 100644
index 00000000..f474e845
--- /dev/null
+++ b/ale_linters/kotlin/ktlint.vim
@@ -0,0 +1,54 @@
+" Author: Francis Agyapong <francisagyapong2@gmail.com>
+" Description: Lint kotlin files using ktlint
+
+call ale#Set('kotlin_ktlint_executable', 'ktlint')
+call ale#Set('kotlin_ktlint_rulesets', [])
+call ale#Set('kotlin_ktlint_format', 0)
+
+
+function! ale_linters#kotlin#ktlint#GetCommand(buffer) abort
+ let l:executable = ale#Var(a:buffer, 'kotlin_ktlint_executable')
+ let l:file_path = expand('#' . a:buffer . ':p')
+ let l:options = ''
+
+ " Formmatted content written to original file, not sure how to handle
+ " if ale#Var(a:buffer, 'kotlin_ktlint_format')
+ " let l:options = l:options . ' --format'
+ " endif
+
+ for l:ruleset in ale#Var(a:buffer, 'kotlin_ktlint_rulesets')
+ let l:options = l:options . ' --ruleset ' . l:ruleset
+ endfor
+
+ return l:executable . ' ' . l:options . ' ' . l:file_path
+endfunction
+
+function! ale_linters#kotlin#ktlint#Handle(buffer, lines) abort
+ let l:message_pattern = '^\(.*\):\([0-9]\+\):\([0-9]\+\):\s\+\(.*\)'
+ let l:output = []
+
+ for l:match in ale#util#GetMatches(a:lines, l:message_pattern)
+ let l:line = l:match[2] + 0
+ let l:column = l:match[3] + 0
+ let l:text = l:match[4]
+
+ let l:type = l:text =~? 'not a valid kotlin file' ? 'E' : 'W'
+
+ call add(l:output, {
+ \ 'lnum': l:line,
+ \ 'col': l:column,
+ \ 'text': l:text,
+ \ 'type': l:type
+ \})
+ endfor
+
+ return l:output
+endfunction
+
+call ale#linter#Define('kotlin', {
+\ 'name': 'ktlint',
+\ 'executable': 'ktlint',
+\ 'command_callback': 'ale_linters#kotlin#ktlint#GetCommand',
+\ 'callback': 'ale_linters#kotlin#ktlint#Handle',
+\ 'lint_file': 1
+\})