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 erlfmt fixer to the registry and use it with stdin #4868

Merged
merged 3 commits into from
Dec 29, 2024
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 @@ -104,6 +104,11 @@ let s:default_registry = {
\ 'description': 'Indent with the Erlang mode for Emacs',
\ 'aliases': ['erlang-mode'],
\ },
\ 'erlfmt': {
\ 'function': 'ale#fixers#erlfmt#Fix',
\ 'suggested_filetypes': ['erlang'],
\ 'description': 'Format Erlang code with erlfmt',
\ },
\ 'fecs': {
\ 'function': 'ale#fixers#fecs#Fix',
\ 'suggested_filetypes': ['javascript', 'css', 'html'],
Expand Down
6 changes: 2 additions & 4 deletions autoload/ale/fixers/erlfmt.vim
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ function! ale#fixers#erlfmt#Fix(buffer) abort
let l:options = ale#Var(a:buffer, 'erlang_erlfmt_options')
let l:executable = ale#fixers#erlfmt#GetExecutable(a:buffer)

let l:command = ale#Escape(l:executable) . (empty(l:options) ? '' : ' ' . l:options) . ' %s'
let l:command = ale#Escape(l:executable) . ale#Pad(l:options) . ' -'

return {
\ 'command': l:command
\}
return {'command': l:command}
endfunction
43 changes: 26 additions & 17 deletions test/fixers/test_erlfmt_fixer_callback.vader
Original file line number Diff line number Diff line change
@@ -1,25 +1,34 @@
Before:
Save b:ale_elm_format_executable
Save b:ale_elm_format_options

let b:ale_elm_format_executable = 'erlfmt'
let b:ale_elm_format_options = ''
call ale#assert#SetUpFixerTest('erlang', 'erlfmt')

After:
Restore
unlet! b:root

call ale#assert#TearDownFixerTest()

Execute(The local erlfmt executable should be used by default):
" Not sure if this is a good default though. It seems to imply
" that the executable is committed to the repository.

let b:root = '../test-files/erlang/app_with_erlfmt'

call ale#test#SetFilename(b:root . '/src/app.erl')
AssertFixer {
\ 'command': ale#Escape(ale#test#GetFilename(b:root . '/erlfmt')) . ' -',
\}

Execute(The global erlfmt executable should be configurable):
let b:root = '../test-files/erlang/app_with_erlfmt'

let b:ale_erlang_erlfmt_executable = '/path/to/erlfmt'
let b:ale_erlang_erlfmt_use_global = 1

call ale#test#SetFilename(b:root . '/src/app.erl')
AssertFixer {'command': ale#Escape('/path/to/erlfmt') . ' -'}

Execute(The erlfmt command should handle empty options):
AssertEqual
\ {
\ 'command': ale#Escape('erlfmt') . ' %s'
\ },
\ ale#fixers#erlfmt#Fix(bufnr(''))
AssertFixer {'command': ale#Escape('erlfmt') . ' -'}

Execute(The erlfmt command should handle custom options):
let b:ale_erlang_erlfmt_options = '--insert-pragma'

AssertEqual
\ {
\ 'command': ale#Escape('erlfmt') . ' --insert-pragma %s'
\ },
\ ale#fixers#erlfmt#Fix(bufnr(''))
AssertFixer {'command': ale#Escape('erlfmt') . ' --insert-pragma -'}
Empty file.