summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorw0rp <w0rp@users.noreply.github.com>2017-03-06 18:33:00 +0000
committerGitHub <noreply@github.com>2017-03-06 18:33:00 +0000
commit70fb1606adbbcfd29ba54b22f9b85fa8e3bd8e64 (patch)
tree7b30145cb6b6e0e4643b8013de02d925c92fffb6
parent76df2d393b6b79f1f0d3095589e7f3ac90de2b40 (diff)
parentf659d975049720f4bf3723c0aa29e6391e06f4e2 (diff)
downloadale-70fb1606adbbcfd29ba54b22f9b85fa8e3bd8e64.zip
Merge pull request #383 from alibabzo/add-nix-linter
Add support for nix linting
-rw-r--r--README.md1
-rw-r--r--ale_linters/nix/nix.vim34
-rw-r--r--doc/ale.txt1
-rw-r--r--test/test_nix_handler.vader26
4 files changed, 62 insertions, 0 deletions
diff --git a/README.md b/README.md
index e11984c9..efaad69a 100644
--- a/README.md
+++ b/README.md
@@ -81,6 +81,7 @@ name. That seems to be the fairest way to arrange this table.
| Lua | [luacheck](https://github.com/mpeterv/luacheck) |
| Markdown | [mdl](https://github.com/mivok/markdownlint), [proselint](http://proselint.com/)|
| MATLAB | [mlint](https://www.mathworks.com/help/matlab/ref/mlint.html) |
+| nix | [nix-instantiate](http://nixos.org/nix/manual/#sec-nix-instantiate) |
| nroff | [proselint](http://proselint.com/)|
| OCaml | [merlin](https://github.com/the-lambda-church/merlin) see `:help ale-integration-ocaml-merlin` for configuration instructions
| Perl | [perl -c](https://perl.org/), [perl-critic](https://metacpan.org/pod/Perl::Critic) |
diff --git a/ale_linters/nix/nix.vim b/ale_linters/nix/nix.vim
new file mode 100644
index 00000000..27c1d51a
--- /dev/null
+++ b/ale_linters/nix/nix.vim
@@ -0,0 +1,34 @@
+" Author: Alistair Bill <@alibabzo>
+" Description: nix-instantiate linter for nix files
+
+function! ale_linters#nix#nix#Handle(buffer, lines) abort
+
+ let l:pattern = '^\(.\+\): \(.\+\), at .*:\(\d\+\):\(\d\+\)$'
+ let l:output = []
+
+ for l:line in a:lines
+ let l:match = matchlist(l:line, l:pattern)
+
+ if len(l:match) == 0
+ continue
+ endif
+
+ call add(l:output, {
+ \ 'bufnr': a:buffer,
+ \ 'lnum': l:match[3] + 0,
+ \ 'col': l:match[4] + 0,
+ \ 'text': l:match[1] . ': ' . l:match[2],
+ \ 'type': l:match[1] =~# '^error' ? 'E' : 'W',
+ \})
+ endfor
+
+ return l:output
+endfunction
+
+call ale#linter#Define('nix', {
+\ 'name': 'nix',
+\ 'output_stream': 'stderr',
+\ 'executable': 'nix-instantiate',
+\ 'command': 'nix-instantiate --parse -',
+\ 'callback': 'ale_linters#nix#nix#Handle',
+\})
diff --git a/doc/ale.txt b/doc/ale.txt
index 734c389c..1660ecd5 100644
--- a/doc/ale.txt
+++ b/doc/ale.txt
@@ -101,6 +101,7 @@ The following languages and tools are supported.
* Lua: 'luacheck'
* Markdown: 'mdl', 'proselint'
* MATLAB: 'mlint'
+* nix: 'nix-instantiate'
* nroff: 'proselint'
* OCaml: 'merlin' (see |ale-linter-integration-ocaml-merlin|)
* Perl: 'perl' (-c flag), 'perlcritic'
diff --git a/test/test_nix_handler.vader b/test/test_nix_handler.vader
new file mode 100644
index 00000000..188d3fa9
--- /dev/null
+++ b/test/test_nix_handler.vader
@@ -0,0 +1,26 @@
+Execute(The nix handler should parse nix-instantiate error messages correctly):
+ runtime ale_linters/nix/nix.vim
+
+ AssertEqual
+ \ [
+ \ {
+ \ 'bufnr': 47,
+ \ 'lnum': 23,
+ \ 'col': 14,
+ \ 'text': 'error: syntax error, unexpected IN',
+ \ 'type': 'E',
+ \ },
+ \ {
+ \ 'bufnr': 47,
+ \ 'lnum': 3,
+ \ 'col': 12,
+ \ 'text': 'error: syntax error, unexpected ''='', expecting '';''',
+ \ 'type': 'E',
+ \ },
+ \
+ \ ],
+ \ ale_linters#nix#nix#Handle(47, [
+ \ 'This line should be ignored',
+ \ 'error: syntax error, unexpected IN, at /path/to/filename.nix:23:14',
+ \ 'error: syntax error, unexpected ''='', expecting '';'', at /path/to/filename.nix:3:12',
+ \ ])