dfmt support (#2662)

* Add support for `dfmt`
This commit is contained in:
theoremoon 2019-09-11 04:54:14 +09:00 committed by w0rp
parent 6e18c03d80
commit 2e323b529d
8 changed files with 75 additions and 0 deletions

View file

@ -27,6 +27,11 @@ let s:default_registry = {
\ 'suggested_filetypes': ['python'], \ 'suggested_filetypes': ['python'],
\ 'description': 'Fix PEP8 issues with black.', \ 'description': 'Fix PEP8 issues with black.',
\ }, \ },
\ 'dfmt': {
\ 'function': 'ale#fixers#dfmt#Fix',
\ 'suggested_filetypes': ['d'],
\ 'description': 'Fix D files with dfmt.',
\ },
\ 'fecs': { \ 'fecs': {
\ 'function': 'ale#fixers#fecs#Fix', \ 'function': 'ale#fixers#fecs#Fix',
\ 'suggested_filetypes': ['javascript', 'css', 'html'], \ 'suggested_filetypes': ['javascript', 'css', 'html'],

View file

@ -0,0 +1,18 @@
" Author: theoldmoon0602
" Description: Integration of dfmt with ALE.
call ale#Set('d_dfmt_executable', 'dfmt')
call ale#Set('d_dfmt_options', '')
function! ale#fixers#dfmt#Fix(buffer) abort
let l:executable = ale#Var(a:buffer, 'd_dfmt_executable')
let l:options = ale#Var(a:buffer, 'd_dfmt_options')
return {
\ 'command': ale#Escape(l:executable)
\ . ' -i'
\ . (empty(l:options) ? '' : ' ' . l:options)
\ . ' %t',
\ 'read_temporary_file': 1,
\}
endfunction

View file

@ -1,6 +1,15 @@
=============================================================================== ===============================================================================
ALE D Integration *ale-d-options* ALE D Integration *ale-d-options*
===============================================================================
dfmt *ale-d-dfmt*
g:ale_d_dfmt_options *g:ale_d_dfmt_options*
*b:ale_d_dfmt_options*
Type: |String|
Default: `''`
This variable can be set to pass additional options to the dfmt fixer.
=============================================================================== ===============================================================================
dls *ale-d-dls* dls *ale-d-dls*

View file

@ -103,6 +103,7 @@ Notes:
* Cython (pyrex filetype) * Cython (pyrex filetype)
* `cython` * `cython`
* D * D
* `dfmt`
* `dls` * `dls`
* `dmd` * `dmd`
* `uncrustify` * `uncrustify`

View file

@ -2066,6 +2066,7 @@ documented in additional help files.
nvcc..................................|ale-cuda-nvcc| nvcc..................................|ale-cuda-nvcc|
clang-format..........................|ale-cuda-clangformat| clang-format..........................|ale-cuda-clangformat|
d.......................................|ale-d-options| d.......................................|ale-d-options|
dfmt..................................|ale-d-dfmt|
dls...................................|ale-d-dls| dls...................................|ale-d-dls|
uncrustify............................|ale-d-uncrustify| uncrustify............................|ale-d-uncrustify|
dart....................................|ale-dart-options| dart....................................|ale-dart-options|

View file

@ -112,6 +112,7 @@ formatting.
* Cython (pyrex filetype) * Cython (pyrex filetype)
* [cython](http://cython.org/) * [cython](http://cython.org/)
* D * D
* [dfmt](https://github.com/dlang-community/dfmt)
* [dls](https://github.com/d-language-server/dls) * [dls](https://github.com/d-language-server/dls)
* [dmd](https://dlang.org/dmd-linux.html) * [dmd](https://dlang.org/dmd-linux.html)
* [uncrustify](https://github.com/uncrustify/uncrustify) * [uncrustify](https://github.com/uncrustify/uncrustify)

0
test/d_files/test.d Normal file
View file

View file

@ -0,0 +1,40 @@
Before:
Save g:ale_d_dfmt_executable
Save g:ale_d_dfmt_options
" Use an invalid global executable, so we don't match it.
let g:ale_d_dfmt_executable = 'xxxinvalid'
let g:ale_d_dfmt_options = ''
call ale#test#SetDirectory('/testplugin/test/fixers')
After:
Restore
call ale#test#RestoreDirectory()
Execute(The dfmt callback should return the correct default values):
call ale#test#SetFilename('../d_files/test.d')
AssertEqual
\ {
\ 'read_temporary_file': 1,
\ 'command': ale#Escape('xxxinvalid')
\ . ' -i'
\ . ' %t',
\ },
\ ale#fixers#dfmt#Fix(bufnr(''))
Execute(The dfmt callback should include custom dfmt options):
let g:ale_d_dfmt_options = "--space-after-cast"
call ale#test#SetFilename('../d_files/test.d')
AssertEqual
\ {
\ 'read_temporary_file': 1,
\ 'command': ale#Escape('xxxinvalid')
\ . ' -i'
\ . ' ' . g:ale_d_dfmt_options
\ . ' %t',
\ },
\ ale#fixers#dfmt#Fix(bufnr(''))