diff --git a/autoload/ale/fix/registry.vim b/autoload/ale/fix/registry.vim index eae29000..2e772419 100644 --- a/autoload/ale/fix/registry.vim +++ b/autoload/ale/fix/registry.vim @@ -540,6 +540,11 @@ let s:default_registry = { \ 'function': 'ale#fixers#vfmt#Fix', \ 'suggested_filetypes': ['v'], \ 'description': 'A formatter for V source code.', +\ }, +\ 'zigfmt': { +\ 'function': 'ale#fixers#zigfmt#Fix', +\ 'suggested_filetypes': ['zig'], +\ 'description': 'Official formatter for Zig', \ } \} diff --git a/autoload/ale/fixers/zigfmt.vim b/autoload/ale/fixers/zigfmt.vim new file mode 100644 index 00000000..b22e5b83 --- /dev/null +++ b/autoload/ale/fixers/zigfmt.vim @@ -0,0 +1,14 @@ +scriptencoding utf-8 +" Author: Arash Mousavi +" Description: Official formatter for Zig. + +call ale#Set('zig_zigfmt_executable', 'zig') + +function! ale#fixers#zigfmt#Fix(buffer) abort + let l:executable = ale#Var(a:buffer, 'zig_zigfmt_executable') + + return { + \ 'command': ale#Escape(l:executable) . ' fmt %t', + \ 'read_temporary_file': 1, + \} +endfunction diff --git a/doc/ale-supported-languages-and-tools.txt b/doc/ale-supported-languages-and-tools.txt index 5e5e0124..218832bc 100644 --- a/doc/ale-supported-languages-and-tools.txt +++ b/doc/ale-supported-languages-and-tools.txt @@ -668,6 +668,7 @@ Notes: * Zeek * `zeek`!! * Zig + * `zigfmt` * `zls` =============================================================================== diff --git a/doc/ale-zig.txt b/doc/ale-zig.txt index 70a53bbb..cafa12a1 100644 --- a/doc/ale-zig.txt +++ b/doc/ale-zig.txt @@ -7,6 +7,18 @@ Integration Information Currently, the only supported linter for zig is zls. + +=============================================================================== +zigfmt *ale-zig-zigfmt* + +g:ale_zig_zigfmt_executable *g:ale_zig_zigfmt_executable* + *b:ale_zig_zigfmt_executable* + Type: |String| + Default: `'zig'` + + The executable that will be run for the `zig fmt` fixer. + + =============================================================================== zls *ale-zig-zls* diff --git a/doc/ale.txt b/doc/ale.txt index 4f55258f..c969cb9e 100644 --- a/doc/ale.txt +++ b/doc/ale.txt @@ -3294,6 +3294,7 @@ documented in additional help files. zeek....................................|ale-zeek-options| zeek..................................|ale-zeek-zeek| zig.....................................|ale-zig-options| + zigfmt................................|ale-zig-zigfmt| zls...................................|ale-zig-zls| diff --git a/supported-tools.md b/supported-tools.md index c4e26f23..24e8de42 100644 --- a/supported-tools.md +++ b/supported-tools.md @@ -677,4 +677,5 @@ formatting. * Zeek * [zeek](http://zeek.org) :floppy_disk: * Zig + * [zigfmt](https://github.com/ziglang/zig) * [zls](https://github.com/zigtools/zls) diff --git a/test/fixers/test_zigfmt_fixer_callback.vader b/test/fixers/test_zigfmt_fixer_callback.vader new file mode 100644 index 00000000..47e3ddee --- /dev/null +++ b/test/fixers/test_zigfmt_fixer_callback.vader @@ -0,0 +1,20 @@ +Before: + call ale#assert#SetUpFixerTest('zig', 'zigfmt') + +After: + call ale#assert#TearDownFixerTest() + +Execute(The zig callback should return the correct default values): + AssertFixer { + \ 'command': ale#Escape('zig') . ' fmt %t', + \ 'read_temporary_file': 1, + \} + +Execute(The zig callback should allow custom zig executables): + let g:ale_zig_zigfmt_executable = 'foo/bar' + + AssertFixer { + \ 'command': ale#Escape('foo/bar') . ' fmt %t', + \ 'read_temporary_file': 1, + \} +