#2542 - Improve checkstyle project configuration
This commit is contained in:
parent
4496c9b3c1
commit
eb6015c6fd
@ -1,6 +1,10 @@
|
|||||||
" Author: Devon Meunier <devon.meunier@gmail.com>
|
" Author: Devon Meunier <devon.meunier@gmail.com>
|
||||||
" Description: checkstyle for Java files
|
" 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
|
function! ale_linters#java#checkstyle#Handle(buffer, lines) abort
|
||||||
let l:output = []
|
let l:output = []
|
||||||
|
|
||||||
@ -36,18 +40,21 @@ function! ale_linters#java#checkstyle#Handle(buffer, lines) abort
|
|||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! ale_linters#java#checkstyle#GetCommand(buffer) abort
|
function! ale_linters#java#checkstyle#GetCommand(buffer) abort
|
||||||
return 'checkstyle '
|
let l:options = ale#Var(a:buffer, 'java_checkstyle_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'
|
\ . ' %s'
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
if !exists('g:ale_java_checkstyle_options')
|
|
||||||
let g:ale_java_checkstyle_options = '-c /google_checks.xml'
|
|
||||||
endif
|
|
||||||
|
|
||||||
call ale#linter#Define('java', {
|
call ale#linter#Define('java', {
|
||||||
\ 'name': 'checkstyle',
|
\ 'name': 'checkstyle',
|
||||||
\ 'executable': 'checkstyle',
|
\ 'executable': {b -> ale#Var(b, 'java_checkstyle_executable')},
|
||||||
\ 'command': function('ale_linters#java#checkstyle#GetCommand'),
|
\ 'command': function('ale_linters#java#checkstyle#GetCommand'),
|
||||||
\ 'callback': 'ale_linters#java#checkstyle#Handle',
|
\ 'callback': 'ale_linters#java#checkstyle#Handle',
|
||||||
\ 'lint_file': 1,
|
\ 'lint_file': 1,
|
||||||
|
@ -5,14 +5,41 @@ ALE Java Integration *ale-java-options*
|
|||||||
===============================================================================
|
===============================================================================
|
||||||
checkstyle *ale-java-checkstyle*
|
checkstyle *ale-java-checkstyle*
|
||||||
|
|
||||||
|
g:ale_java_checkstyle_config *g:ale_java_checkstyle_config*
|
||||||
|
*b:ale_java_checkstyle_config*
|
||||||
|
|
||||||
|
Type: |String|
|
||||||
|
Default: `'google_checks.xml'`
|
||||||
|
|
||||||
|
A path to a checkstyle configuration file.
|
||||||
|
|
||||||
|
If a configuration file is specified with |g:ale_java_checkstyle_options|,
|
||||||
|
it will be preferred over this setting.
|
||||||
|
|
||||||
|
The path to the configuration file can be an absolute path or a relative
|
||||||
|
path. ALE will search for the relative path in parent directories.
|
||||||
|
|
||||||
|
|
||||||
|
g:ale_java_checkstyle_executable *g:ale_java_checkstyle_executable*
|
||||||
|
*b:ale_java_checkstyle_executable*
|
||||||
|
|
||||||
|
Type: |String|
|
||||||
|
Default: 'checkstyle'
|
||||||
|
|
||||||
|
This variable can be changed to modify the executable used for checkstyle.
|
||||||
|
|
||||||
|
|
||||||
g:ale_java_checkstyle_options *g:ale_java_checkstyle_options*
|
g:ale_java_checkstyle_options *g:ale_java_checkstyle_options*
|
||||||
*b:ale_java_checkstyle_options*
|
*b:ale_java_checkstyle_options*
|
||||||
|
|
||||||
Type: String
|
Type: |String|
|
||||||
Default: '-c /google_checks.xml'
|
Default: `''`
|
||||||
|
|
||||||
This variable can be changed to modify flags given to checkstyle.
|
This variable can be changed to modify flags given to checkstyle.
|
||||||
|
|
||||||
|
If a configuration file is specified with `-c`, it will be used instead of
|
||||||
|
configuration files set with |g:ale_java_checkstyle_config|.
|
||||||
|
|
||||||
|
|
||||||
===============================================================================
|
===============================================================================
|
||||||
javac *ale-java-javac*
|
javac *ale-java-javac*
|
||||||
@ -141,8 +168,8 @@ g:ale_java_eclipselsp_executable *g:ale_java_eclipse_executable*
|
|||||||
This variable can be set to change the executable path used for java.
|
This variable can be set to change the executable path used for java.
|
||||||
|
|
||||||
|
|
||||||
g:ale_java_eclipselsp_config_path *g:ale_java_eclipse_config_path*
|
g:ale_java_eclipselsp_config_path *g:ale_java_eclipse_config_path*
|
||||||
*b:ale_java_eclipse_config_path*
|
*b:ale_java_eclipse_config_path*
|
||||||
Type: |String|
|
Type: |String|
|
||||||
Default: `''`
|
Default: `''`
|
||||||
|
|
||||||
@ -155,8 +182,8 @@ g:ale_java_eclipselsp_config_path *g:ale_java_eclipse_config_path
|
|||||||
installed via system package.
|
installed via system package.
|
||||||
|
|
||||||
|
|
||||||
g:ale_java_eclipselsp_workspace_path *g:ale_java_eclipselsp_workspace_path*
|
g:ale_java_eclipselsp_workspace_path *g:ale_java_eclipselsp_workspace_path*
|
||||||
*b:ale_java_eclipselsp_workspace_path*
|
*b:ale_java_eclipselsp_workspace_path*
|
||||||
|
|
||||||
Type: |String|
|
Type: |String|
|
||||||
Default: `''`
|
Default: `''`
|
||||||
|
62
test/command_callback/test_checkstyle_command_callback.vader
Normal file
62
test/command_callback/test_checkstyle_command_callback.vader
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
Before:
|
||||||
|
call ale#assert#SetUpLinterTest('java', 'checkstyle')
|
||||||
|
call ale#test#SetFilename('dummy.java')
|
||||||
|
|
||||||
|
After:
|
||||||
|
call ale#assert#TearDownLinterTest()
|
||||||
|
|
||||||
|
Execute(The checkstyle callback should return the correct default value):
|
||||||
|
AssertLinter 'checkstyle', ale#Escape('checkstyle') . ' %s'
|
||||||
|
|
||||||
|
Execute(The checkstyle executable should be configurable):
|
||||||
|
let b:ale_java_checkstyle_executable = 'foobar'
|
||||||
|
|
||||||
|
AssertLinter 'foobar', ale#Escape('foobar') . ' %s'
|
||||||
|
|
||||||
|
Execute(Custom options should be supported):
|
||||||
|
let b:ale_java_checkstyle_options = '--foobar'
|
||||||
|
|
||||||
|
AssertLinter 'checkstyle', ale#Escape('checkstyle') . ' --foobar %s'
|
||||||
|
|
||||||
|
Execute(configuration files set in _config should be supported):
|
||||||
|
let b:ale_java_checkstyle_config = ale#path#Simplify(g:dir . '/checkstyle_paths/other_config.xml')
|
||||||
|
|
||||||
|
AssertLinter 'checkstyle',
|
||||||
|
\ ale#Escape('checkstyle')
|
||||||
|
\ . ' -c ' . ale#Escape(ale#path#Simplify(g:dir . '/checkstyle_paths/other_config.xml'))
|
||||||
|
\ . ' %s'
|
||||||
|
|
||||||
|
Execute(configuration files set in _options should be preferred over _config):
|
||||||
|
let b:ale_java_checkstyle_config = '/foo.xml'
|
||||||
|
let b:ale_java_checkstyle_options = '-c /bar.xml'
|
||||||
|
|
||||||
|
AssertLinter 'checkstyle', ale#Escape('checkstyle') . ' -c /bar.xml %s'
|
||||||
|
|
||||||
|
let b:ale_java_checkstyle_options = '-x -c /bar.xml'
|
||||||
|
|
||||||
|
AssertLinter 'checkstyle', ale#Escape('checkstyle') . ' -x -c /bar.xml %s'
|
||||||
|
|
||||||
|
Execute(google_checks.xml should be detected automatically):
|
||||||
|
call ale#test#SetFilename('checkstyle_paths/test.java')
|
||||||
|
|
||||||
|
AssertLinter 'checkstyle',
|
||||||
|
\ ale#Escape('checkstyle')
|
||||||
|
\ . ' -c ' . ale#Escape(ale#path#Simplify(g:dir . '/checkstyle_paths/google_checks.xml'))
|
||||||
|
\ . ' %s'
|
||||||
|
|
||||||
|
Execute(Other relative paths should be supported):
|
||||||
|
let b:ale_java_checkstyle_config = 'checkstyle_paths/other_config.xml'
|
||||||
|
|
||||||
|
AssertLinter 'checkstyle',
|
||||||
|
\ ale#Escape('checkstyle')
|
||||||
|
\ . ' -c ' . ale#Escape(ale#path#Simplify(g:dir . '/checkstyle_paths/other_config.xml'))
|
||||||
|
\ . ' %s'
|
||||||
|
|
||||||
|
call ale#test#SetFilename('checkstyle_paths/test.java')
|
||||||
|
|
||||||
|
let b:ale_java_checkstyle_config = 'other_config.xml'
|
||||||
|
|
||||||
|
AssertLinter 'checkstyle',
|
||||||
|
\ ale#Escape('checkstyle')
|
||||||
|
\ . ' -c ' . ale#Escape(ale#path#Simplify(g:dir . '/checkstyle_paths/other_config.xml'))
|
||||||
|
\ . ' %s'
|
Loading…
Reference in New Issue
Block a user