mirror of
https://github.com/dense-analysis/ale.git
synced 2025-12-08 21:44:47 +08:00
Merge pull request #2577 from hsanson/fix-checkstyle-defaults
Fix checkstyle default configuration.
This commit is contained in:
@@ -2,7 +2,7 @@
|
|||||||
" Description: checkstyle for Java files
|
" Description: checkstyle for Java files
|
||||||
|
|
||||||
call ale#Set('java_checkstyle_executable', 'checkstyle')
|
call ale#Set('java_checkstyle_executable', 'checkstyle')
|
||||||
call ale#Set('java_checkstyle_config', 'google_checks.xml')
|
call ale#Set('java_checkstyle_config', '/google_checks.xml')
|
||||||
call ale#Set('java_checkstyle_options', '')
|
call ale#Set('java_checkstyle_options', '')
|
||||||
|
|
||||||
function! ale_linters#java#checkstyle#Handle(buffer, lines) abort
|
function! ale_linters#java#checkstyle#Handle(buffer, lines) abort
|
||||||
@@ -39,11 +39,21 @@ function! ale_linters#java#checkstyle#Handle(buffer, lines) abort
|
|||||||
return l:output
|
return l:output
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
function! s:GetConfig(buffer, config) abort
|
||||||
|
if ale#path#IsAbsolute(a:config)
|
||||||
|
return a:config
|
||||||
|
endif
|
||||||
|
|
||||||
|
let s:file = ale#path#FindNearestFile(a:buffer, a:config)
|
||||||
|
|
||||||
|
return !empty(s:file) ? s:file : a:config
|
||||||
|
endfunction
|
||||||
|
|
||||||
function! ale_linters#java#checkstyle#GetCommand(buffer) abort
|
function! ale_linters#java#checkstyle#GetCommand(buffer) abort
|
||||||
let l:options = 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_option = ale#Var(a:buffer, 'java_checkstyle_config')
|
||||||
let l:config = l:options !~# '\v(^| )-c' && !empty(l:config_option)
|
let l:config = l:options !~# '\v(^| )-c' && !empty(l:config_option)
|
||||||
\ ? ale#path#FindNearestFile(a:buffer, l:config_option)
|
\ ? s:GetConfig(a:buffer, l:config_option)
|
||||||
\ : ''
|
\ : ''
|
||||||
|
|
||||||
return '%e'
|
return '%e'
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ g:ale_java_checkstyle_config *g:ale_java_checkstyle_config*
|
|||||||
*b:ale_java_checkstyle_config*
|
*b:ale_java_checkstyle_config*
|
||||||
|
|
||||||
Type: |String|
|
Type: |String|
|
||||||
Default: `'google_checks.xml'`
|
Default: `'/google_checks.xml'`
|
||||||
|
|
||||||
A path to a checkstyle configuration file.
|
A path to a checkstyle configuration file.
|
||||||
|
|
||||||
|
|||||||
@@ -6,17 +6,27 @@ After:
|
|||||||
call ale#assert#TearDownLinterTest()
|
call ale#assert#TearDownLinterTest()
|
||||||
|
|
||||||
Execute(The checkstyle callback should return the correct default value):
|
Execute(The checkstyle callback should return the correct default value):
|
||||||
AssertLinter 'checkstyle', ale#Escape('checkstyle') . ' %s'
|
AssertLinter 'checkstyle',
|
||||||
|
\ ale#Escape('checkstyle')
|
||||||
|
\ . ' -c ' . ale#Escape('/google_checks.xml')
|
||||||
|
\ . ' %s'
|
||||||
|
|
||||||
Execute(The checkstyle executable should be configurable):
|
Execute(The checkstyle executable should be configurable):
|
||||||
let b:ale_java_checkstyle_executable = 'foobar'
|
let b:ale_java_checkstyle_executable = 'foobar'
|
||||||
|
|
||||||
AssertLinter 'foobar', ale#Escape('foobar') . ' %s'
|
AssertLinter 'foobar',
|
||||||
|
\ ale#Escape('foobar')
|
||||||
|
\ . ' -c ' . ale#Escape('/google_checks.xml')
|
||||||
|
\ . ' %s'
|
||||||
|
|
||||||
Execute(Custom options should be supported):
|
Execute(Custom options should be supported):
|
||||||
let b:ale_java_checkstyle_options = '--foobar'
|
let b:ale_java_checkstyle_options = '--foobar'
|
||||||
|
|
||||||
AssertLinter 'checkstyle', ale#Escape('checkstyle') . ' --foobar %s'
|
AssertLinter 'checkstyle',
|
||||||
|
\ ale#Escape('checkstyle')
|
||||||
|
\ . ' --foobar'
|
||||||
|
\ . ' -c ' . ale#Escape('/google_checks.xml')
|
||||||
|
\ . ' %s'
|
||||||
|
|
||||||
Execute(configuration files set in _config should be supported):
|
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')
|
let b:ale_java_checkstyle_config = ale#path#Simplify(g:dir . '/checkstyle_paths/other_config.xml')
|
||||||
@@ -36,12 +46,12 @@ Execute(configuration files set in _options should be preferred over _config):
|
|||||||
|
|
||||||
AssertLinter 'checkstyle', ale#Escape('checkstyle') . ' -x -c /bar.xml %s'
|
AssertLinter 'checkstyle', ale#Escape('checkstyle') . ' -x -c /bar.xml %s'
|
||||||
|
|
||||||
Execute(google_checks.xml should be detected automatically):
|
Execute(google_checks.xml should be used by default):
|
||||||
call ale#test#SetFilename('checkstyle_paths/test.java')
|
call ale#test#SetFilename('checkstyle_paths/test.java')
|
||||||
|
|
||||||
AssertLinter 'checkstyle',
|
AssertLinter 'checkstyle',
|
||||||
\ ale#Escape('checkstyle')
|
\ ale#Escape('checkstyle')
|
||||||
\ . ' -c ' . ale#Escape(ale#path#Simplify(g:dir . '/checkstyle_paths/google_checks.xml'))
|
\ . ' -c ' . ale#Escape('/google_checks.xml')
|
||||||
\ . ' %s'
|
\ . ' %s'
|
||||||
|
|
||||||
Execute(Other relative paths should be supported):
|
Execute(Other relative paths should be supported):
|
||||||
|
|||||||
Reference in New Issue
Block a user