summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorw0rp <w0rp@users.noreply.github.com>2019-10-07 19:22:01 +0100
committerGitHub <noreply@github.com>2019-10-07 19:22:01 +0100
commitd3a3f4011bf514372584344e3860b8c9c39e01f1 (patch)
treec98279b70322d3d58ce9a329b18a7bfca40f97a9
parentcebbb67ea6e2555f4438d61333c96764a389cf6b (diff)
parent6aeb46217177924367fe1961a7e615f3e4052298 (diff)
downloadale-d3a3f4011bf514372584344e3860b8c9c39e01f1.zip
Merge pull request #2676 from davidtwco/nixfmt-fixer
Add nixpkgs-fmt fixer.
-rw-r--r--autoload/ale/fix/registry.vim5
-rw-r--r--autoload/ale/fixers/nixpkgsfmt.vim12
-rw-r--r--doc/ale-nix.txt24
-rw-r--r--doc/ale-supported-languages-and-tools.txt1
-rw-r--r--doc/ale.txt2
-rw-r--r--supported-tools.md1
-rw-r--r--test/fixers/test_nixpkgsfmt_fixer_callback.vader24
7 files changed, 69 insertions, 0 deletions
diff --git a/autoload/ale/fix/registry.vim b/autoload/ale/fix/registry.vim
index 750d2196..2a96a7d6 100644
--- a/autoload/ale/fix/registry.vim
+++ b/autoload/ale/fix/registry.vim
@@ -345,6 +345,11 @@ let s:default_registry = {
\ 'suggested_filetypes': ['ada'],
\ 'description': 'Format Ada files with gnatpp.',
\ },
+\ 'nixpkgs-fmt': {
+\ 'function': 'ale#fixers#nixpkgsfmt#Fix',
+\ 'suggested_filetypes': ['nix'],
+\ 'description': 'A formatter for Nix code',
+\ },
\}
" Reset the function registry to the default entries.
diff --git a/autoload/ale/fixers/nixpkgsfmt.vim b/autoload/ale/fixers/nixpkgsfmt.vim
new file mode 100644
index 00000000..403ce798
--- /dev/null
+++ b/autoload/ale/fixers/nixpkgsfmt.vim
@@ -0,0 +1,12 @@
+call ale#Set('nix_nixpkgsfmt_executable', 'nixpkgs-fmt')
+call ale#Set('nix_nixpkgsfmt_options', '')
+
+function! ale#fixers#nixpkgsfmt#Fix(buffer) abort
+ let l:executable = ale#Var(a:buffer, 'nix_nixpkgsfmt_executable')
+ let l:options = ale#Var(a:buffer, 'nix_nixpkgsfmt_options')
+
+ return {
+ \ 'command': ale#Escape(l:executable)
+ \ . (empty(l:options) ? '' : ' ' . l:options),
+ \}
+endfunction
diff --git a/doc/ale-nix.txt b/doc/ale-nix.txt
new file mode 100644
index 00000000..5b2bd6cb
--- /dev/null
+++ b/doc/ale-nix.txt
@@ -0,0 +1,24 @@
+===============================================================================
+ALE Nix Integration *ale-nix-options*
+
+
+===============================================================================
+nixpkgs-fmt *ale-nix-nixpkgs-fmt*
+
+g:ale_nix_nixpkgsfmt_executable *g:ale_nix_nixpkgsfmt_executable*
+ *b:ale_nix_nixpkgsfmt_executable*
+ Type: |String|
+ Default: `'nixpkgs-fmt'`
+
+ This variable sets executable used for nixpkgs-fmt.
+
+g:ale_nix_nixpkgsfmt_options *g:ale_nix_nixpkgsfmt_options*
+ *b:ale_nix_nixpkgsfmt_options*
+ Type: |String|
+ Default: `''`
+
+ This variable can be set to pass additional options to the nixpkgs-fmt fixer.
+
+
+===============================================================================
+ vim:tw=78:ts=2:sts=2:sw=2:ft=help:norl:
diff --git a/doc/ale-supported-languages-and-tools.txt b/doc/ale-supported-languages-and-tools.txt
index 7a536239..19e27570 100644
--- a/doc/ale-supported-languages-and-tools.txt
+++ b/doc/ale-supported-languages-and-tools.txt
@@ -284,6 +284,7 @@ Notes:
* `nim check`!!
* nix
* `nix-instantiate`
+ * `nixpkgs-fmt`
* nroff
* `alex`!!
* `proselint`
diff --git a/doc/ale.txt b/doc/ale.txt
index 42dba257..eaf47d37 100644
--- a/doc/ale.txt
+++ b/doc/ale.txt
@@ -2305,6 +2305,8 @@ documented in additional help files.
mmc...................................|ale-mercury-mmc|
nasm....................................|ale-nasm-options|
nasm..................................|ale-nasm-nasm|
+ nix.....................................|ale-nix-options|
+ nixpkgs-fmt...........................|ale-nix-nixpkgs-fmt|
nroff...................................|ale-nroff-options|
write-good............................|ale-nroff-write-good|
objc....................................|ale-objc-options|
diff --git a/supported-tools.md b/supported-tools.md
index ad72c267..06e01784 100644
--- a/supported-tools.md
+++ b/supported-tools.md
@@ -293,6 +293,7 @@ formatting.
* [nim check](https://nim-lang.org/docs/nimc.html) :floppy_disk:
* nix
* [nix-instantiate](http://nixos.org/nix/manual/#sec-nix-instantiate)
+ * [nixpkgs-fmt](https://github.com/nix-community/nixpkgs-fmt)
* nroff
* [alex](https://github.com/wooorm/alex) :floppy_disk:
* [proselint](http://proselint.com/)
diff --git a/test/fixers/test_nixpkgsfmt_fixer_callback.vader b/test/fixers/test_nixpkgsfmt_fixer_callback.vader
new file mode 100644
index 00000000..0065f77b
--- /dev/null
+++ b/test/fixers/test_nixpkgsfmt_fixer_callback.vader
@@ -0,0 +1,24 @@
+Before:
+ Save g:ale_nix_nixpkgsfmt_executable
+ Save g:ale_nix_nixpkgsfmt_options
+
+After:
+ Restore
+
+Execute(The nixpkgs-fmt callback should return the correct default values):
+ AssertEqual
+ \ {
+ \ 'command': ale#Escape('nixpkgs-fmt')
+ \ },
+ \ ale#fixers#nixpkgsfmt#Fix(bufnr(''))
+
+Execute(The nixpkgs-fmt executable and options should be configurable):
+ let g:ale_nix_nixpkgsfmt_executable = '/path/to/nixpkgs-fmt'
+ let g:ale_nix_nixpkgsfmt_options = '-h'
+
+ AssertEqual
+ \ {
+ \ 'command': ale#Escape('/path/to/nixpkgs-fmt')
+ \ . ' -h',
+ \ },
+ \ ale#fixers#nixpkgsfmt#Fix(bufnr(''))