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
This commit is contained in:
parent
7c68889bbc
commit
2c89a4c98a
3 changed files with 80 additions and 1 deletions
|
@ -84,7 +84,7 @@ name. That seems to be the fairest way to arrange this table.
|
||||||
| Java | [checkstyle](http://checkstyle.sourceforge.net), [javac](http://www.oracle.com/technetwork/java/javase/downloads/index.html) |
|
| Java | [checkstyle](http://checkstyle.sourceforge.net), [javac](http://www.oracle.com/technetwork/java/javase/downloads/index.html) |
|
||||||
| JavaScript | [eslint](http://eslint.org/), [jscs](http://jscs.info/), [jshint](http://jshint.com/), [flow](https://flowtype.org/), [standard](http://standardjs.com/), [xo](https://github.com/sindresorhus/xo)
|
| JavaScript | [eslint](http://eslint.org/), [jscs](http://jscs.info/), [jshint](http://jshint.com/), [flow](https://flowtype.org/), [standard](http://standardjs.com/), [xo](https://github.com/sindresorhus/xo)
|
||||||
| JSON | [jsonlint](http://zaa.ch/jsonlint/) |
|
| JSON | [jsonlint](http://zaa.ch/jsonlint/) |
|
||||||
| Kotlin | [kotlinc](https://kotlinlang.org) see `:help ale-integration-kotlin` for configuration instructions
|
| Kotlin | [kotlinc](https://kotlinlang.org), [ktlint](https://ktlint.github.io) see `:help ale-integration-kotlin` for configuration instructions
|
||||||
| LaTeX | [chktex](http://www.nongnu.org/chktex/), [lacheck](https://www.ctan.org/pkg/lacheck), [proselint](http://proselint.com/) |
|
| LaTeX | [chktex](http://www.nongnu.org/chktex/), [lacheck](https://www.ctan.org/pkg/lacheck), [proselint](http://proselint.com/) |
|
||||||
| Lua | [luacheck](https://github.com/mpeterv/luacheck) |
|
| Lua | [luacheck](https://github.com/mpeterv/luacheck) |
|
||||||
| Markdown | [mdl](https://github.com/mivok/markdownlint), [proselint](http://proselint.com/), [vale](https://github.com/ValeLint/vale) |
|
| Markdown | [mdl](https://github.com/mivok/markdownlint), [proselint](http://proselint.com/), [vale](https://github.com/ValeLint/vale) |
|
||||||
|
|
54
ale_linters/kotlin/ktlint.vim
Normal file
54
ale_linters/kotlin/ktlint.vim
Normal file
|
@ -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
|
||||||
|
\})
|
|
@ -62,4 +62,29 @@ g:ale_kotlin_kotlinc_module_filename *g:ale_kotlin_kotlinc_module_filename*
|
||||||
The filename of the module file that the linter should pass to the kotlin
|
The filename of the module file that the linter should pass to the kotlin
|
||||||
compiler.
|
compiler.
|
||||||
|
|
||||||
|
|
||||||
|
-------------------------------------------------------------------------------
|
||||||
|
ktlint *ale-kotlin-ktlint*
|
||||||
|
|
||||||
|
g:ale_kotlin_ktlint_executable *g:ale_kotlin_ktlint_executable*
|
||||||
|
Type: |String|
|
||||||
|
Default: `''`
|
||||||
|
|
||||||
|
The Ktlint executable.
|
||||||
|
|
||||||
|
Posix-compliant shell scripts are the only executables that can be found on
|
||||||
|
Ktlint's github release page. If you are not on such a system, your best
|
||||||
|
bet will be to download the ktlint jar and set this option to something
|
||||||
|
similar to `'java -jar /path/to/ktlint.jar'`
|
||||||
|
|
||||||
|
g:ale_kotlin_ktlint_rulesets *g:ale_kotlin_ktlint_rulesets*
|
||||||
|
Type: |List| of |String|s
|
||||||
|
Default: []
|
||||||
|
|
||||||
|
This list should contain paths to ruleset jars and/or strings of maven
|
||||||
|
artifact triples. Example:
|
||||||
|
>
|
||||||
|
let g:ale_kotlin_ktlint_rulesets = ['/path/to/custom-rulset.jar',
|
||||||
|
'com.ktlint.rulesets:mycustomrule:1.0.0']
|
||||||
|
|
||||||
vim:tw=78:ts=2:sts=2:sw=2:ft=help:norl:
|
vim:tw=78:ts=2:sts=2:sw=2:ft=help:norl:
|
||||||
|
|
Reference in a new issue