diff options
-rw-r--r-- | ale_linters/java/checkstyle.vim | 21 | ||||
-rw-r--r-- | doc/ale-java.txt | 41 | ||||
-rw-r--r-- | test/command_callback/checkstyle_paths/google_checks.xml | 0 | ||||
-rw-r--r-- | test/command_callback/checkstyle_paths/other_config.xml | 0 | ||||
-rw-r--r-- | test/command_callback/test_checkstyle_command_callback.vader | 62 |
5 files changed, 110 insertions, 14 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, diff --git a/doc/ale-java.txt b/doc/ale-java.txt index 4a71d9ef..65d2299b 100644 --- a/doc/ale-java.txt +++ b/doc/ale-java.txt @@ -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: `''` diff --git a/test/command_callback/checkstyle_paths/google_checks.xml b/test/command_callback/checkstyle_paths/google_checks.xml new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/test/command_callback/checkstyle_paths/google_checks.xml diff --git a/test/command_callback/checkstyle_paths/other_config.xml b/test/command_callback/checkstyle_paths/other_config.xml new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/test/command_callback/checkstyle_paths/other_config.xml diff --git a/test/command_callback/test_checkstyle_command_callback.vader b/test/command_callback/test_checkstyle_command_callback.vader new file mode 100644 index 00000000..d775f9f2 --- /dev/null +++ b/test/command_callback/test_checkstyle_command_callback.vader @@ -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' |