Skip to content

Commit

Permalink
Add nix-linter checker
Browse files Browse the repository at this point in the history
  • Loading branch information
marsam committed Dec 23, 2018
1 parent baf96df commit fb9bffd
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 1 deletion.
6 changes: 6 additions & 0 deletions doc/languages.rst
Expand Up @@ -755,6 +755,12 @@ to view the docstring of the syntax checker. Likewise, you may use

.. _nix-instantiate: https://nixos.org/nix/manual/#sec-nix-instantiate

.. syntax-checker:: nix-linter

Check Nix with nix-linter_.

.. _nix-linter: https://github.com/Synthetica9/nix-linter

.. supported-language:: Perl

Flycheck checks Perl with `perl` and `perl-perlcritic`.
Expand Down
31 changes: 31 additions & 0 deletions flycheck.el
Expand Up @@ -211,6 +211,7 @@ attention to case differences."
markdown-markdownlint-cli
markdown-mdl
nix
nix-linter
perl
perl-perlcritic
php
Expand Down Expand Up @@ -9421,6 +9422,36 @@ See URL `https://nixos.org/nix/manual/#sec-nix-instantiate'."
(lambda (errors)
(flycheck-sanitize-errors
(flycheck-remove-error-file-names "(string)" errors)))
:next-checkers ((warning . nix-linter))
:modes nix-mode)

(defun flycheck-parse-nix-linter (output checker buffer)
"Parse nix-linter warnings from JSON OUTPUT.

CHECKER and BUFFER denote the CHECKER that returned OUTPUT and
the BUFFER that was checked respectively.

See URL `https://github.com/Synthetica9/nix-linter' for more
information about nix-linter."
(mapcar (lambda (err)
(let-alist err
(flycheck-error-new-at
.pos.spanBegin.sourceLine
.pos.spanBegin.sourceColumn
'warning
.description
:id .offense
:checker checker
:buffer buffer
:filename (buffer-file-name buffer))))
(flycheck-parse-json output)))

(flycheck-define-checker nix-linter
"Nix checker using nix-linter.

See URL `https://github.com/Synthetica9/nix-linter'."
:command ("nix-linter" "--json-stream" source)
:error-parser flycheck-parse-nix-linter
:modes nix-mode)

(defun flycheck-locate-sphinx-source-directory ()
Expand Down
9 changes: 8 additions & 1 deletion test/flycheck-test.el
Expand Up @@ -4062,9 +4062,16 @@ Why not:

(flycheck-ert-def-checker-test nix nix nil
(flycheck-ert-should-syntax-check
"language/nix.nix" 'nix-mode
"language/nix/syntax-error.nix" 'nix-mode
'(3 1 error "syntax error, unexpected IN, expecting ';'," :checker nix)))

(flycheck-ert-def-checker-test nix-linter nix nil
(flycheck-ert-should-syntax-check
"language/nix/warnings.nix" 'nix-mode
'(1 1 warning "LetInInheritRecset" :id "LetInInheritRecset" :checker nix-linter)
'(2 3 warning "Unused `let` bind `x`" :id "UnusedLetBind" :checker nix-linter)
'(3 4 warning "Unneeded `rec` on set" :id "UnneededRec" :checker nix-linter)))

(ert-deftest flycheck-locate-sphinx-source-directory/not-in-a-sphinx-project ()
:tags '(language-rst)
(flycheck-ert-with-resource-buffer "language/rst/errors.rst"
Expand Down
File renamed without changes.
5 changes: 5 additions & 0 deletions test/resources/language/nix/warnings.nix
@@ -0,0 +1,5 @@
let
x = 5;
in rec {
inherit x;
}

0 comments on commit fb9bffd

Please sign in to comment.