Skip to content

Commit

Permalink
Add auto-fixer for crystal
Browse files Browse the repository at this point in the history
  • Loading branch information
grepsedawk committed Dec 19, 2021
1 parent 7413dfd commit d3b2d5c
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 0 deletions.
5 changes: 5 additions & 0 deletions autoload/ale/fix/registry.vim
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,11 @@ let s:default_registry = {
\ 'suggested_filetypes': ['hcl', 'terraform'],
\ 'description': 'Fix tf and hcl files with terraform fmt.',
\ },
\ 'crystal': {
\ 'function': 'ale#fixers#crystal#Fix',
\ 'suggested_filetypes': ['cr'],
\ 'description': 'Fix cr (crystal).',
\ },
\ 'ktlint': {
\ 'function': 'ale#fixers#ktlint#Fix',
\ 'suggested_filetypes': ['kt', 'kotlin'],
Expand Down
14 changes: 14 additions & 0 deletions autoload/ale/fixers/crystal.vim
Original file line number Diff line number Diff line change
@@ -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'
\ . (empty(l:options) ? '' : ' ' . l:options)
\ . ' -'
\}
endfunction
33 changes: 33 additions & 0 deletions test/fixers/test_crystal_format_fixer_callback.vader
Original file line number Diff line number Diff line change
@@ -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') . ' 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')
\ . ' ' . g:ale_crystal_format_options
\ . ' -',
\ },
\ ale#fixers#crystal#Fix(bufnr(''))

0 comments on commit d3b2d5c

Please sign in to comment.