mirror of https://github.com/dense-analysis/ale
Add deadnix linter (#4443)
This commit is contained in:
parent
c8e9146049
commit
6ae26df22b
|
@ -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',
|
||||
\})
|
|
@ -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
|
|
@ -93,5 +93,23 @@ g:ale_nix_statix_fix_options *g:ale_nix_statix_fix_options*
|
|||
it as a fixer.
|
||||
|
||||
|
||||
===============================================================================
|
||||
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:
|
||||
|
|
|
@ -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|
|
||||
|
|
|
@ -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":[{}]}'])
|
|
@ -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'
|
Loading…
Reference in New Issue