forked from github-mirrors/ale
Add auto-fixer for crystal (#4016)
This commit is contained in:
parent
dcec4b3c37
commit
48f68598cb
|
@ -431,6 +431,11 @@ let s:default_registry = {
|
||||||
\ 'suggested_filetypes': ['hcl', 'terraform'],
|
\ 'suggested_filetypes': ['hcl', 'terraform'],
|
||||||
\ 'description': 'Fix tf and hcl files with terraform fmt.',
|
\ 'description': 'Fix tf and hcl files with terraform fmt.',
|
||||||
\ },
|
\ },
|
||||||
|
\ 'crystal': {
|
||||||
|
\ 'function': 'ale#fixers#crystal#Fix',
|
||||||
|
\ 'suggested_filetypes': ['cr'],
|
||||||
|
\ 'description': 'Fix cr (crystal).',
|
||||||
|
\ },
|
||||||
\ 'ktlint': {
|
\ 'ktlint': {
|
||||||
\ 'function': 'ale#fixers#ktlint#Fix',
|
\ 'function': 'ale#fixers#ktlint#Fix',
|
||||||
\ 'suggested_filetypes': ['kt', 'kotlin'],
|
\ 'suggested_filetypes': ['kt', 'kotlin'],
|
||||||
|
|
|
@ -0,0 +1,14 @@
|
||||||
|
call ale#Set('crystal_format_executable', 'crystal')
|
||||||
|
call ale#Set('crystal_format_options', '')
|
||||||
|
|
||||||
|
function! ale#fixers#crystal#Fix(buffer) abort
|
||||||
|
let l:executable = ale#Var(a:buffer, 'crystal_format_executable')
|
||||||
|
let l:options = ale#Var(a:buffer, 'crystal_format_options')
|
||||||
|
|
||||||
|
return {
|
||||||
|
\ 'command': ale#Escape(l:executable)
|
||||||
|
\ . ' tool format'
|
||||||
|
\ . ale#Pad(l:options)
|
||||||
|
\ . ' -'
|
||||||
|
\}
|
||||||
|
endfunction
|
|
@ -0,0 +1,33 @@
|
||||||
|
Before:
|
||||||
|
Save g:ale_crystal_format_executable
|
||||||
|
Save g:ale_crystal_format_options
|
||||||
|
|
||||||
|
" Use an invalid global executable, so we don't match it.
|
||||||
|
let g:ale_crystal_format_executable = 'xxxinvalid'
|
||||||
|
let g:ale_crystal_format_options = ''
|
||||||
|
|
||||||
|
call ale#test#SetDirectory('/testplugin/test/fixers')
|
||||||
|
|
||||||
|
After:
|
||||||
|
Restore
|
||||||
|
|
||||||
|
call ale#test#RestoreDirectory()
|
||||||
|
|
||||||
|
Execute(The crystal format callback should return the correct default values):
|
||||||
|
|
||||||
|
AssertEqual
|
||||||
|
\ {
|
||||||
|
\ 'command': ale#Escape('xxxinvalid') . ' tool format -',
|
||||||
|
\ },
|
||||||
|
\ ale#fixers#crystal#Fix(bufnr(''))
|
||||||
|
|
||||||
|
Execute(The crystal format callback should include custom options):
|
||||||
|
let g:ale_crystal_format_options = "-list=true"
|
||||||
|
|
||||||
|
AssertEqual
|
||||||
|
\ {
|
||||||
|
\ 'command': ale#Escape('xxxinvalid')
|
||||||
|
\ . ' tool format ' . g:ale_crystal_format_options
|
||||||
|
\ . ' -',
|
||||||
|
\ },
|
||||||
|
\ ale#fixers#crystal#Fix(bufnr(''))
|
Loading…
Reference in New Issue