Merge pull request #1209 from butlerx/java-fixer
add google-java-format fixer
This commit is contained in:
commit
a22def45b9
@ -108,7 +108,7 @@ formatting.
|
|||||||
| Haskell | [brittany](https://github.com/lspitzner/brittany), [ghc](https://www.haskell.org/ghc/), [stack-ghc](https://haskellstack.org/), [stack-build](https://haskellstack.org/) !!, [ghc-mod](https://github.com/DanielG/ghc-mod), [stack-ghc-mod](https://github.com/DanielG/ghc-mod), [hlint](https://hackage.haskell.org/package/hlint), [hdevtools](https://hackage.haskell.org/package/hdevtools), [hfmt](https://github.com/danstiner/hfmt) |
|
| Haskell | [brittany](https://github.com/lspitzner/brittany), [ghc](https://www.haskell.org/ghc/), [stack-ghc](https://haskellstack.org/), [stack-build](https://haskellstack.org/) !!, [ghc-mod](https://github.com/DanielG/ghc-mod), [stack-ghc-mod](https://github.com/DanielG/ghc-mod), [hlint](https://hackage.haskell.org/package/hlint), [hdevtools](https://hackage.haskell.org/package/hdevtools), [hfmt](https://github.com/danstiner/hfmt) |
|
||||||
| HTML | [HTMLHint](http://htmlhint.com/), [proselint](http://proselint.com/), [tidy](http://www.html-tidy.org/), [write-good](https://github.com/btford/write-good) |
|
| HTML | [HTMLHint](http://htmlhint.com/), [proselint](http://proselint.com/), [tidy](http://www.html-tidy.org/), [write-good](https://github.com/btford/write-good) |
|
||||||
| Idris | [idris](http://www.idris-lang.org/) |
|
| Idris | [idris](http://www.idris-lang.org/) |
|
||||||
| Java | [checkstyle](http://checkstyle.sourceforge.net), [javac](http://www.oracle.com/technetwork/java/javase/downloads/index.html) |
|
| Java | [checkstyle](http://checkstyle.sourceforge.net), [javac](http://www.oracle.com/technetwork/java/javase/downloads/index.html), [google-java-format](https://github.com/google/google-java-format) |
|
||||||
| JavaScript | [eslint](http://eslint.org/), [flow](https://flowtype.org/), [jscs](http://jscs.info/), [jshint](http://jshint.com/), [prettier](https://github.com/prettier/prettier), prettier-eslint >= 4.2.0, prettier-standard, [standard](http://standardjs.com/), [xo](https://github.com/sindresorhus/xo)
|
| JavaScript | [eslint](http://eslint.org/), [flow](https://flowtype.org/), [jscs](http://jscs.info/), [jshint](http://jshint.com/), [prettier](https://github.com/prettier/prettier), prettier-eslint >= 4.2.0, prettier-standard, [standard](http://standardjs.com/), [xo](https://github.com/sindresorhus/xo)
|
||||||
| JSON | [jsonlint](http://zaa.ch/jsonlint/), [prettier](https://github.com/prettier/prettier) |
|
| JSON | [jsonlint](http://zaa.ch/jsonlint/), [prettier](https://github.com/prettier/prettier) |
|
||||||
| Kotlin | [kotlinc](https://kotlinlang.org) !!, [ktlint](https://ktlint.github.io) !! see `:help ale-integration-kotlin` for configuration instructions |
|
| Kotlin | [kotlinc](https://kotlinlang.org) !!, [ktlint](https://ktlint.github.io) !! see `:help ale-integration-kotlin` for configuration instructions |
|
||||||
|
@ -154,6 +154,11 @@ let s:default_registry = {
|
|||||||
\ 'suggested_filetypes': ['sh'],
|
\ 'suggested_filetypes': ['sh'],
|
||||||
\ 'description': 'Fix sh files with shfmt.',
|
\ 'description': 'Fix sh files with shfmt.',
|
||||||
\ },
|
\ },
|
||||||
|
\ 'google_java_format': {
|
||||||
|
\ 'function': 'ale#fixers#google_java_format#Fix',
|
||||||
|
\ 'suggested_filetypes': ['java'],
|
||||||
|
\ 'description': 'Fix Java files with google-java-format.',
|
||||||
|
\ },
|
||||||
\}
|
\}
|
||||||
|
|
||||||
" Reset the function registry to the default entries.
|
" Reset the function registry to the default entries.
|
||||||
|
23
autoload/ale/fixers/google_java_format.vim
Normal file
23
autoload/ale/fixers/google_java_format.vim
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
" Author: butlerx <butlerx@notthe,cloud>
|
||||||
|
" Description: Integration of Google-java-format with ALE.
|
||||||
|
|
||||||
|
call ale#Set('google_java_format_executable', 'google-java-format')
|
||||||
|
call ale#Set('google_java_format_use_global', 0)
|
||||||
|
call ale#Set('google_java_format_options', '')
|
||||||
|
|
||||||
|
function! ale#fixers#google_java_format#Fix(buffer) abort
|
||||||
|
let l:options = ale#Var(a:buffer, 'google_java_format_options')
|
||||||
|
let l:executable = ale#Var(a:buffer, 'google_java_format_executable')
|
||||||
|
|
||||||
|
if !executable(l:executable)
|
||||||
|
return 0
|
||||||
|
endif
|
||||||
|
|
||||||
|
return {
|
||||||
|
\ 'command': ale#Escape(l:executable)
|
||||||
|
\ . ' ' . (empty(l:options) ? '' : ' ' . l:options)
|
||||||
|
\ . ' --replace'
|
||||||
|
\ . ' %t',
|
||||||
|
\ 'read_temporary_file': 1,
|
||||||
|
\}
|
||||||
|
endfunction
|
@ -33,5 +33,24 @@ g:ale_java_javac_options *g:ale_java_javac_options*
|
|||||||
This variable can be set to pass additional options to javac.
|
This variable can be set to pass additional options to javac.
|
||||||
|
|
||||||
|
|
||||||
|
===============================================================================
|
||||||
|
google-java-format *ale-java-google-java-format*
|
||||||
|
|
||||||
|
|
||||||
|
g:ale_java_google_java_format_executable *g:ale_java_google_java_format_executable*
|
||||||
|
*b:ale_java_google_java_format_executable*
|
||||||
|
Type: |String|
|
||||||
|
Default: `'google-java-format'`
|
||||||
|
|
||||||
|
See |ale-integrations-local-executables|
|
||||||
|
|
||||||
|
|
||||||
|
g:ale_java_google_java_format_options *g:ale_java_google_java_format_options*
|
||||||
|
*b:ale_java_google_java_format_options*
|
||||||
|
Type: |String|
|
||||||
|
Default: `''`
|
||||||
|
|
||||||
|
This variable can be set to pass additional options
|
||||||
|
|
||||||
===============================================================================
|
===============================================================================
|
||||||
vim:tw=78:ts=2:sts=2:sw=2:ft=help:norl:
|
vim:tw=78:ts=2:sts=2:sw=2:ft=help:norl:
|
||||||
|
@ -93,6 +93,7 @@ CONTENTS *ale-contents*
|
|||||||
java..................................|ale-java-options|
|
java..................................|ale-java-options|
|
||||||
checkstyle..........................|ale-java-checkstyle|
|
checkstyle..........................|ale-java-checkstyle|
|
||||||
javac...............................|ale-java-javac|
|
javac...............................|ale-java-javac|
|
||||||
|
google-java-format..................|ale-java-google-java-format|
|
||||||
javascript............................|ale-javascript-options|
|
javascript............................|ale-javascript-options|
|
||||||
eslint..............................|ale-javascript-eslint|
|
eslint..............................|ale-javascript-eslint|
|
||||||
flow................................|ale-javascript-flow|
|
flow................................|ale-javascript-flow|
|
||||||
@ -307,7 +308,7 @@ Notes:
|
|||||||
* Haskell: `brittany`, `ghc`, `stack-ghc`, `stack-build`!!, `ghc-mod`, `stack-ghc-mod`, `hlint`, `hdevtools`, `hfmt`
|
* Haskell: `brittany`, `ghc`, `stack-ghc`, `stack-build`!!, `ghc-mod`, `stack-ghc-mod`, `hlint`, `hdevtools`, `hfmt`
|
||||||
* HTML: `HTMLHint`, `proselint`, `tidy`, `write-good`
|
* HTML: `HTMLHint`, `proselint`, `tidy`, `write-good`
|
||||||
* Idris: `idris`
|
* Idris: `idris`
|
||||||
* Java: `checkstyle`, `javac`
|
* Java: `checkstyle`, `javac`, `google-java-format`
|
||||||
* JavaScript: `eslint`, `flow`, `jscs`, `jshint`, `prettier`, `prettier-eslint` >= 4.2.0, `prettier-standard`, `standard`, `xo`
|
* JavaScript: `eslint`, `flow`, `jscs`, `jshint`, `prettier`, `prettier-eslint` >= 4.2.0, `prettier-standard`, `standard`, `xo`
|
||||||
* JSON: `jsonlint`, `prettier`
|
* JSON: `jsonlint`, `prettier`
|
||||||
* Kotlin: `kotlinc`, `ktlint`
|
* Kotlin: `kotlinc`, `ktlint`
|
||||||
|
27
test/fixers/test_goofle_java_format_fixer_callback.vader
Normal file
27
test/fixers/test_goofle_java_format_fixer_callback.vader
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
Before:
|
||||||
|
Save g:ale_google_java_format_executable
|
||||||
|
|
||||||
|
" Use an invalid global executable, so we don't match it.
|
||||||
|
let g:ale_google_java_format_executable = 'xxxinvalid'
|
||||||
|
|
||||||
|
call ale#test#SetDirectory('/testplugin/test/fixers')
|
||||||
|
|
||||||
|
After:
|
||||||
|
Restore
|
||||||
|
|
||||||
|
call ale#test#RestoreDirectory()
|
||||||
|
|
||||||
|
Execute(The google-java-format callback should return 0 when the executable isn't executable):
|
||||||
|
AssertEqual
|
||||||
|
\ 0,
|
||||||
|
\ ale#fixers#google_java_format#Fix(bufnr(''))
|
||||||
|
|
||||||
|
Execute(The google-java-format callback should run the command when the executable test passes):
|
||||||
|
let g:ale_google_java_format_executable = has('win32') ? 'cmd' : 'echo'
|
||||||
|
|
||||||
|
AssertEqual
|
||||||
|
\ {
|
||||||
|
\ 'read_temporary_file': 1,
|
||||||
|
\ 'command': ale#Escape(ale_google_java_format_executable) . ' --replace %t'
|
||||||
|
\ },
|
||||||
|
\ ale#fixers#google_java_format#Fix(bufnr(''))
|
Loading…
Reference in New Issue
Block a user