Skip to content

Add nixfmt as a Nix fixer. #3651

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

Merged
merged 2 commits into from
Mar 24, 2021
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 @@ -406,6 +406,11 @@ let s:default_registry = {
\ 'suggested_filetypes': ['ada'],
\ 'description': 'Format Ada files with gnatpp.',
\ },
\ 'nixfmt': {
\ 'function': 'ale#fixers#nixfmt#Fix',
\ 'suggested_filetypes': ['nix'],
\ 'description': 'A nix formatter written in Haskell.',
\ },
\ 'nixpkgs-fmt': {
\ 'function': 'ale#fixers#nixpkgsfmt#Fix',
\ 'suggested_filetypes': ['nix'],
Expand Down
15 changes: 15 additions & 0 deletions autoload/ale/fixers/nixfmt.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
scriptencoding utf-8
" Author: houstdav000 <[email protected]>
" Description: Fix files with nixfmt

call ale#Set('nix_nixfmt_executable', 'nixfmt')
call ale#Set('nix_nixfmt_options', '')

function! ale#fixers#nixfmt#Fix(buffer) abort
let l:executable = ale#Var(a:buffer, 'nix_nixfmt_executable')
let l:options = ale#Var(a:buffer, 'nix_nixfmt_options')

return {
\ 'command': ale#Escape(l:executable) . ale#Pad(l:options),
\}
endfunction
18 changes: 18 additions & 0 deletions doc/ale-nix.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,24 @@
ALE Nix Integration *ale-nix-options*


===============================================================================
nixfmt *ale-nix-nixfmt*

g:ale_nix_nixfmt_executable *g:ale_nix_nixfmt_executable*
*b:ale_nix_nixfmt_executable*
Type: String
Default: 'nixfmt'

This variable sets the executable used for nixfmt.

g:ale_nix_nixfmt_options *g:ale_nix_nixfmt_options*
*b:ale_nix_nixfmt_options*
Type: String
Default: ''

This variable can be set to pass additional options to the nixfmt fixer.


===============================================================================
nixpkgs-fmt *ale-nix-nixpkgs-fmt*

Expand Down
1 change: 1 addition & 0 deletions doc/ale-supported-languages-and-tools.txt
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,7 @@ Notes:
* `nimpretty`
* nix
* `nix-instantiate`
* `nixfmt`
* `nixpkgs-fmt`
* `rnix-lsp`
* nroff
Expand Down
1 change: 1 addition & 0 deletions doc/ale.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2859,6 +2859,7 @@ documented in additional help files.
nimlsp................................|ale-nim-nimlsp|
nimpretty.............................|ale-nim-nimpretty|
nix.....................................|ale-nix-options|
nixfmt................................|ale-nix-nixfmt|
nixpkgs-fmt...........................|ale-nix-nixpkgs-fmt|
nroff...................................|ale-nroff-options|
write-good............................|ale-nroff-write-good|
Expand Down
1 change: 1 addition & 0 deletions supported-tools.md
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,7 @@ formatting.
* nimpretty
* nix
* [nix-instantiate](http://nixos.org/nix/manual/#sec-nix-instantiate)
* [nixfmt](https://github.com/serokell/nixfmt)
* [nixpkgs-fmt](https://github.com/nix-community/nixpkgs-fmt)
* [rnix-lsp](https://github.com/nix-community/rnix-lsp)
* nroff
Expand Down
24 changes: 24 additions & 0 deletions test/fixers/test_nixfmt_fixer_callback.vader
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
Before:
Save g:ale_nix_nixfmt_executable
Save g:ale_nix_nixfmt_options

After:
Restore

Execute(The nixfmt callback should return the correct default values):
AssertEqual
\ {
\ 'command': ale#Escape('nixfmt')
\ },
\ ale#fixers#nixfmt#Fix(bufnr(''))

Execute(The nixfmt executable and options should be configurable):
let g:ale_nix_nixfmt_executable = '/path/to/nixfmt'
let g:ale_nix_nixfmt_options = '--help'

AssertEqual
\ {
\ 'command': ale#Escape('/path/to/nixfmt')
\ . ' --help',
\ },
\ ale#fixers#nixfmt#Fix(bufnr(''))