Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add auto-fixer for crystal #4016

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions autoload/ale/fix/registry.vim
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,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'
\ . ale#Pad(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') . ' 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
grepsedawk marked this conversation as resolved.
Show resolved Hide resolved
\ {
\ 'command': ale#Escape('xxxinvalid')
\ . ' tool format ' . g:ale_crystal_format_options
\ . ' -',
\ },
\ ale#fixers#crystal#Fix(bufnr(''))