summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlbert Peschar <albert@peschar.net>2023-03-07 02:31:14 +0100
committerGitHub <noreply@github.com>2023-03-07 01:31:14 +0000
commit6ae26df22b982e8b19824af96b3e937a0de0bf59 (patch)
tree2d996429f30131a3b3f0e13bf13a4feddd5ef234
parentc8e914604963063b7bb827e9b6f5a6ca741dad60 (diff)
downloadale-6ae26df22b982e8b19824af96b3e937a0de0bf59.zip
Add deadnix linter (#4443)
-rw-r--r--ale_linters/nix/deadnix.vim13
-rw-r--r--autoload/ale/handlers/deadnix.vim33
-rw-r--r--doc/ale-nix.txt18
-rw-r--r--doc/ale.txt1
-rw-r--r--test/handler/test_deadnix_handler.vader27
-rw-r--r--test/linter/test_nix_deadnix.vader19
6 files changed, 111 insertions, 0 deletions
diff --git a/ale_linters/nix/deadnix.vim b/ale_linters/nix/deadnix.vim
new file mode 100644
index 00000000..3e8aec66
--- /dev/null
+++ b/ale_linters/nix/deadnix.vim
@@ -0,0 +1,13 @@
+call ale#Set('nix_deadnix_executable', 'deadnix')
+call ale#Set('nix_deadnix_options', '')
+
+function! ale_linters#nix#deadnix#GetCommand(buffer) abort
+ return '%e -o json' . ale#Pad(ale#Var(a:buffer, 'nix_deadnix_options')) . ' -- %t'
+endfunction
+
+call ale#linter#Define('nix', {
+\ 'name': 'deadnix',
+\ 'executable': {b -> ale#Var(b, 'nix_deadnix_executable')},
+\ 'command': function('ale_linters#nix#deadnix#GetCommand'),
+\ 'callback': 'ale#handlers#deadnix#Handle',
+\})
diff --git a/autoload/ale/handlers/deadnix.vim b/autoload/ale/handlers/deadnix.vim
new file mode 100644
index 00000000..8f03f38e
--- /dev/null
+++ b/autoload/ale/handlers/deadnix.vim
@@ -0,0 +1,33 @@
+function! ale#handlers#deadnix#Handle(buffer, lines) abort
+ let l:output = []
+
+ for l:line in a:lines
+ try
+ let l:file = ale#util#FuzzyJSONDecode(l:line, v:null)
+ catch
+ continue
+ endtry
+
+ if type(l:file) isnot v:t_dict
+ continue
+ endif
+
+ for l:error in l:file['results']
+ try
+ let l:ale_error = {
+ \ 'lnum': l:error['line'],
+ \ 'col': l:error['column'],
+ \ 'end_col': l:error['endColumn'],
+ \ 'text': l:error['message'],
+ \ 'type': 'W',
+ \}
+ catch
+ continue
+ endtry
+
+ call add(l:output, l:ale_error)
+ endfor
+ endfor
+
+ return l:output
+endfunction
diff --git a/doc/ale-nix.txt b/doc/ale-nix.txt
index 8600c281..5f4199ed 100644
--- a/doc/ale-nix.txt
+++ b/doc/ale-nix.txt
@@ -94,4 +94,22 @@ g:ale_nix_statix_fix_options *g:ale_nix_statix_fix_options*
===============================================================================
+deadnix *ale-nix-deadnix*
+
+g:ale_nix_deadnix_executable *g:ale_nix_deadnix_executable*
+ *b:ale_nix_deadnix_executable*
+ Type: |String|
+ Default: `'deadnix'`
+
+ This variable sets the executable used for deadnix.
+
+g:ale_nix_deadnix_options *g:ale_nix_deadnix_options*
+ *b:ale_nix_deadnix_options*
+ Type: |String|
+ Default: `''`
+
+ This variable can be used to pass additional options to deadnix.
+
+
+===============================================================================
vim:tw=78:ts=2:sts=2:sw=2:ft=help:norl:
diff --git a/doc/ale.txt b/doc/ale.txt
index 066ba59e..60fcb05a 100644
--- a/doc/ale.txt
+++ b/doc/ale.txt
@@ -3102,6 +3102,7 @@ documented in additional help files.
nixfmt................................|ale-nix-nixfmt|
nixpkgs-fmt...........................|ale-nix-nixpkgs-fmt|
statix................................|ale-nix-statix|
+ deadnix...............................|ale-nix-deadnix|
nroff...................................|ale-nroff-options|
write-good............................|ale-nroff-write-good|
objc....................................|ale-objc-options|
diff --git a/test/handler/test_deadnix_handler.vader b/test/handler/test_deadnix_handler.vader
new file mode 100644
index 00000000..242af881
--- /dev/null
+++ b/test/handler/test_deadnix_handler.vader
@@ -0,0 +1,27 @@
+Execute(The deadnix handler should handle deadnix output):
+ let output = [
+ \'{"file":"./flake.nix","results":[{"column":5,"endColumn":9,"line":23,"message":"Unused lambda pattern: self"},{"column":2,"endColumn":6,"line":1,"message":"Unused lambda pattern: pkgs"}]}'
+ \]
+
+ AssertEqual
+ \ [
+ \ {
+ \ 'lnum': 23,
+ \ 'col': 5,
+ \ 'end_col': 9,
+ \ 'text': 'Unused lambda pattern: self',
+ \ 'type': 'W',
+ \ },
+ \ {
+ \ 'lnum': 1,
+ \ 'col': 2,
+ \ 'end_col': 6,
+ \ 'text': 'Unused lambda pattern: pkgs',
+ \ 'type': 'W',
+ \ },
+ \ ],
+ \ ale#handlers#deadnix#Handle(bufnr(''), output)
+
+ AssertEqual [], ale#handlers#deadnix#Handle(bufnr(''), [''])
+ AssertEqual [], ale#handlers#deadnix#Handle(bufnr(''), ['not json'])
+ AssertEqual [], ale#handlers#deadnix#Handle(bufnr(''), ['{"results":[{}]}'])
diff --git a/test/linter/test_nix_deadnix.vader b/test/linter/test_nix_deadnix.vader
new file mode 100644
index 00000000..90416302
--- /dev/null
+++ b/test/linter/test_nix_deadnix.vader
@@ -0,0 +1,19 @@
+Before:
+ call ale#assert#SetUpLinterTest('nix', 'deadnix')
+
+After:
+ call ale#assert#TearDownLinterTest()
+
+Execute(The deadnix command should be correct):
+ AssertLinter 'deadnix', ale#Escape('deadnix') . ' -o json -- %t'
+
+Execute(Additional deadnix options should be configurable):
+ let g:ale_nix_deadnix_options = '--foobar'
+
+ AssertLinter 'deadnix',
+ \ ale#Escape('deadnix') . ' -o json --foobar -- %t'
+
+Execute(The deadnix command should be configurable):
+ let g:ale_nix_deadnix_executable = 'foo/bar'
+
+ AssertLinter 'foo/bar', ale#Escape('foo/bar') . ' -o json -- %t'