#2542 - Improve checkstyle project configuration

This commit is contained in:
w0rp 2019-06-03 23:40:22 +01:00
parent 4496c9b3c1
commit eb6015c6fd
No known key found for this signature in database
GPG Key ID: 0FC1ECAA8C81CD83
5 changed files with 110 additions and 14 deletions

View File

@ -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,

View File

@ -5,14 +5,41 @@ ALE Java Integration *ale-java-options*
===============================================================================
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*
*b:ale_java_checkstyle_options*
Type: String
Default: '-c /google_checks.xml'
Type: |String|
Default: `''`
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*
@ -118,7 +145,7 @@ located inside the repository folder `eclipse.jdt.ls`. Please ensure to set
|g:ale_java_eclipselsp_path| to the absolute path of that folder.
You could customize compiler options and code assists of the server.
Under your project folder, modify the file `.settings/org.eclipse.jdt.core.prefs`
Under your project folder, modify the file `.settings/org.eclipse.jdt.core.prefs`
with options presented at
https://help.eclipse.org/neon/topic/org.eclipse.jdt.doc.isv/reference/api/org/eclipse/jdt/core/JavaCore.html.
@ -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.
g:ale_java_eclipselsp_config_path *g:ale_java_eclipse_config_path*
*b:ale_java_eclipse_config_path*
g:ale_java_eclipselsp_config_path *g:ale_java_eclipse_config_path*
*b:ale_java_eclipse_config_path*
Type: |String|
Default: `''`
@ -155,8 +182,8 @@ g:ale_java_eclipselsp_config_path *g:ale_java_eclipse_config_path
installed via system package.
g:ale_java_eclipselsp_workspace_path *g:ale_java_eclipselsp_workspace_path*
*b:ale_java_eclipselsp_workspace_path*
g:ale_java_eclipselsp_workspace_path *g:ale_java_eclipselsp_workspace_path*
*b:ale_java_eclipselsp_workspace_path*
Type: |String|
Default: `''`

View 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'