Skip to content

Commit b1f95dc

Browse files
authored
Add nixfmt as a Nix fixer. (#3651)
* Add nixfmt fixer. * Replace manual options pad with ale#Pad()
1 parent eb0ebe6 commit b1f95dc

File tree

7 files changed

+65
-0
lines changed

7 files changed

+65
-0
lines changed

autoload/ale/fix/registry.vim

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,11 @@ let s:default_registry = {
406406
\ 'suggested_filetypes': ['ada'],
407407
\ 'description': 'Format Ada files with gnatpp.',
408408
\ },
409+
\ 'nixfmt': {
410+
\ 'function': 'ale#fixers#nixfmt#Fix',
411+
\ 'suggested_filetypes': ['nix'],
412+
\ 'description': 'A nix formatter written in Haskell.',
413+
\ },
409414
\ 'nixpkgs-fmt': {
410415
\ 'function': 'ale#fixers#nixpkgsfmt#Fix',
411416
\ 'suggested_filetypes': ['nix'],

autoload/ale/fixers/nixfmt.vim

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
scriptencoding utf-8
2+
" Author: houstdav000 <[email protected]>
3+
" Description: Fix files with nixfmt
4+
5+
call ale#Set('nix_nixfmt_executable', 'nixfmt')
6+
call ale#Set('nix_nixfmt_options', '')
7+
8+
function! ale#fixers#nixfmt#Fix(buffer) abort
9+
let l:executable = ale#Var(a:buffer, 'nix_nixfmt_executable')
10+
let l:options = ale#Var(a:buffer, 'nix_nixfmt_options')
11+
12+
return {
13+
\ 'command': ale#Escape(l:executable) . ale#Pad(l:options),
14+
\}
15+
endfunction

doc/ale-nix.txt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,24 @@
22
ALE Nix Integration *ale-nix-options*
33

44

5+
===============================================================================
6+
nixfmt *ale-nix-nixfmt*
7+
8+
g:ale_nix_nixfmt_executable *g:ale_nix_nixfmt_executable*
9+
*b:ale_nix_nixfmt_executable*
10+
Type: String
11+
Default: 'nixfmt'
12+
13+
This variable sets the executable used for nixfmt.
14+
15+
g:ale_nix_nixfmt_options *g:ale_nix_nixfmt_options*
16+
*b:ale_nix_nixfmt_options*
17+
Type: String
18+
Default: ''
19+
20+
This variable can be set to pass additional options to the nixfmt fixer.
21+
22+
523
===============================================================================
624
nixpkgs-fmt *ale-nix-nixpkgs-fmt*
725

doc/ale-supported-languages-and-tools.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,7 @@ Notes:
319319
* `nimpretty`
320320
* nix
321321
* `nix-instantiate`
322+
* `nixfmt`
322323
* `nixpkgs-fmt`
323324
* `rnix-lsp`
324325
* nroff

doc/ale.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2859,6 +2859,7 @@ documented in additional help files.
28592859
nimlsp................................|ale-nim-nimlsp|
28602860
nimpretty.............................|ale-nim-nimpretty|
28612861
nix.....................................|ale-nix-options|
2862+
nixfmt................................|ale-nix-nixfmt|
28622863
nixpkgs-fmt...........................|ale-nix-nixpkgs-fmt|
28632864
nroff...................................|ale-nroff-options|
28642865
write-good............................|ale-nroff-write-good|

supported-tools.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,7 @@ formatting.
328328
* nimpretty
329329
* nix
330330
* [nix-instantiate](http://nixos.org/nix/manual/#sec-nix-instantiate)
331+
* [nixfmt](https://github.com/serokell/nixfmt)
331332
* [nixpkgs-fmt](https://github.com/nix-community/nixpkgs-fmt)
332333
* [rnix-lsp](https://github.com/nix-community/rnix-lsp)
333334
* nroff
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
Before:
2+
Save g:ale_nix_nixfmt_executable
3+
Save g:ale_nix_nixfmt_options
4+
5+
After:
6+
Restore
7+
8+
Execute(The nixfmt callback should return the correct default values):
9+
AssertEqual
10+
\ {
11+
\ 'command': ale#Escape('nixfmt')
12+
\ },
13+
\ ale#fixers#nixfmt#Fix(bufnr(''))
14+
15+
Execute(The nixfmt executable and options should be configurable):
16+
let g:ale_nix_nixfmt_executable = '/path/to/nixfmt'
17+
let g:ale_nix_nixfmt_options = '--help'
18+
19+
AssertEqual
20+
\ {
21+
\ 'command': ale#Escape('/path/to/nixfmt')
22+
\ . ' --help',
23+
\ },
24+
\ ale#fixers#nixfmt#Fix(bufnr(''))

0 commit comments

Comments
 (0)