summaryrefslogtreecommitdiff
path: root/ale_linters/java/checkstyle.vim
diff options
context:
space:
mode:
Diffstat (limited to 'ale_linters/java/checkstyle.vim')
-rw-r--r--ale_linters/java/checkstyle.vim21
1 files changed, 14 insertions, 7 deletions
diff --git a/ale_linters/java/checkstyle.vim b/ale_linters/java/checkstyle.vim
index cc93ee8a..ee3ca7a3 100644
--- a/ale_linters/java/checkstyle.vim
+++ b/ale_linters/java/checkstyle.vim
@@ -1,6 +1,10 @@
" Author: Devon Meunier <devon.meunier@gmail.com>
" Description: checkstyle for Java files
+call ale#Set('java_checkstyle_executable', 'checkstyle')
+call ale#Set('java_checkstyle_config', 'google_checks.xml')
+call ale#Set('java_checkstyle_options', '')
+
function! ale_linters#java#checkstyle#Handle(buffer, lines) abort
let l:output = []
@@ -36,18 +40,21 @@ function! ale_linters#java#checkstyle#Handle(buffer, lines) abort
endfunction
function! ale_linters#java#checkstyle#GetCommand(buffer) abort
- return 'checkstyle '
- \ . ale#Var(a:buffer, 'java_checkstyle_options')
+ let l:options = ale#Var(a:buffer, 'java_checkstyle_options')
+ let l:config_option = ale#Var(a:buffer, 'java_checkstyle_config')
+ let l:config = l:options !~# '\v(^| )-c' && !empty(l:config_option)
+ \ ? ale#path#FindNearestFile(a:buffer, l:config_option)
+ \ : ''
+
+ return '%e'
+ \ . ale#Pad(l:options)
+ \ . (!empty(l:config) ? ' -c ' . ale#Escape(l:config) : '')
\ . ' %s'
endfunction
-if !exists('g:ale_java_checkstyle_options')
- let g:ale_java_checkstyle_options = '-c /google_checks.xml'
-endif
-
call ale#linter#Define('java', {
\ 'name': 'checkstyle',
-\ 'executable': 'checkstyle',
+\ 'executable': {b -> ale#Var(b, 'java_checkstyle_executable')},
\ 'command': function('ale_linters#java#checkstyle#GetCommand'),
\ 'callback': 'ale_linters#java#checkstyle#Handle',
\ 'lint_file': 1,