summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Houston <houstdav000@gmail.com>2021-03-23 20:02:17 -0400
committerGitHub <noreply@github.com>2021-03-24 09:02:17 +0900
commitb1f95dc4fb15efb1d5238845c99548f2906e2ba3 (patch)
tree669b5cba5963b96624628cdc7160b6ba3ef99571
parenteb0ebe622102cc6da3d7e943a3b739db7b6ed216 (diff)
downloadale-b1f95dc4fb15efb1d5238845c99548f2906e2ba3.zip
Add nixfmt as a Nix fixer. (#3651)
* Add nixfmt fixer. * Replace manual options pad with ale#Pad()
-rw-r--r--autoload/ale/fix/registry.vim5
-rw-r--r--autoload/ale/fixers/nixfmt.vim15
-rw-r--r--doc/ale-nix.txt18
-rw-r--r--doc/ale-supported-languages-and-tools.txt1
-rw-r--r--doc/ale.txt1
-rw-r--r--supported-tools.md1
-rw-r--r--test/fixers/test_nixfmt_fixer_callback.vader24
7 files changed, 65 insertions, 0 deletions
diff --git a/autoload/ale/fix/registry.vim b/autoload/ale/fix/registry.vim
index 7ef502c8..632bc890 100644
--- a/autoload/ale/fix/registry.vim
+++ b/autoload/ale/fix/registry.vim
@@ -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'],
diff --git a/autoload/ale/fixers/nixfmt.vim b/autoload/ale/fixers/nixfmt.vim
new file mode 100644
index 00000000..4a548b23
--- /dev/null
+++ b/autoload/ale/fixers/nixfmt.vim
@@ -0,0 +1,15 @@
+scriptencoding utf-8
+" Author: houstdav000 <houstdav000@gh0st.sh>
+" 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
diff --git a/doc/ale-nix.txt b/doc/ale-nix.txt
index 5b2bd6cb..c38b93db 100644
--- a/doc/ale-nix.txt
+++ b/doc/ale-nix.txt
@@ -3,6 +3,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*
g:ale_nix_nixpkgsfmt_executable *g:ale_nix_nixpkgsfmt_executable*
diff --git a/doc/ale-supported-languages-and-tools.txt b/doc/ale-supported-languages-and-tools.txt
index 211b3729..fe19ae63 100644
--- a/doc/ale-supported-languages-and-tools.txt
+++ b/doc/ale-supported-languages-and-tools.txt
@@ -319,6 +319,7 @@ Notes:
* `nimpretty`
* nix
* `nix-instantiate`
+ * `nixfmt`
* `nixpkgs-fmt`
* `rnix-lsp`
* nroff
diff --git a/doc/ale.txt b/doc/ale.txt
index 95365d33..81162348 100644
--- a/doc/ale.txt
+++ b/doc/ale.txt
@@ -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|
diff --git a/supported-tools.md b/supported-tools.md
index a43a583c..4a557538 100644
--- a/supported-tools.md
+++ b/supported-tools.md
@@ -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
diff --git a/test/fixers/test_nixfmt_fixer_callback.vader b/test/fixers/test_nixfmt_fixer_callback.vader
new file mode 100644
index 00000000..880ac83e
--- /dev/null
+++ b/test/fixers/test_nixfmt_fixer_callback.vader
@@ -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(''))