emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/flycheck 3e394f0eba 2/2: Add salt-lint checker (#2073)


From: ELPA Syncer
Subject: [nongnu] elpa/flycheck 3e394f0eba 2/2: Add salt-lint checker (#2073)
Date: Sat, 29 Jun 2024 00:59:35 -0400 (EDT)

branch: elpa/flycheck
commit 3e394f0eba60cedfad5ebf39121adbf802efb008
Author: Henrik Jürges <juerges.henrik@gmail.com>
Commit: GitHub <noreply@github.com>

    Add salt-lint checker (#2073)
---
 CHANGES.rst       |  1 +
 doc/languages.rst |  8 ++++++++
 flycheck.el       | 37 +++++++++++++++++++++++++++++++++++++
 3 files changed, 46 insertions(+)

diff --git a/CHANGES.rst b/CHANGES.rst
index 52aea50fe4..7ef8f628a4 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -12,6 +12,7 @@ New Features
 - [#2059]: Enable checkers for new AUCTeX 14 modes.
 - [#2067]: Handle correctly GHC 9.6 error output format.
 - [#2070]: Add a new syntax checker ``r`` for R with the builtin ``parse`` 
function.
+- [#2073]: Add new syntax checker ``salt-lint`` for the salt 
infrastructure-as-code language.
 - [#2071]: Add a new checker ``perl-perlimports``, for cleaning up Perl import 
statements.
 
 -----------
diff --git a/doc/languages.rst b/doc/languages.rst
index 56704da5e7..8b08cafcc9 100644
--- a/doc/languages.rst
+++ b/doc/languages.rst
@@ -1351,6 +1351,14 @@ to view the docstring of the syntax checker.  Likewise, 
you may use
          A list of additional library directories. Relative paths are relative
          to the buffer being checked.
 
+.. supported-language:: SaltStack
+
+   .. syntax-checker:: salt-lint
+
+      Flycheck checks SaltStack YAML files with SALT-Lint_.
+
+      .. _SALT-Lint: https://salt-lint.readthedocs.io/en/latest/
+
 .. supported-language:: Sass/SCSS
 
    Flycheck checks SASS with `sass/scss-sass-lint` or
diff --git a/flycheck.el b/flycheck.el
index 93004a7e81..66428e2419 100644
--- a/flycheck.el
+++ b/flycheck.el
@@ -219,6 +219,7 @@
     rust-cargo
     rust
     rust-clippy
+    salt-lint
     scala
     scala-scalastyle
     scheme-chicken
@@ -11935,6 +11936,42 @@ See URL 
`https://github.com/rust-lang-nursery/rust-clippy'."
              :message (if has-toml "Found" "Missing")
              :face (if has-toml 'success '(bold warning))))))))
 
+(flycheck-define-checker salt-lint
+  "A salt linter which apply common best practices for SaltStack.
+
+See URL `https://salt-lint.readthedocs.io/en/latest/'."
+  :command ("python" "-m" "saltlint" "--json")
+  :standard-input t
+  :error-parser flycheck-salt-lint-parser
+  :error-filter (lambda (errors) (flycheck-sanitize-errors errors))
+  :modes salt-mode)
+
+(defun flycheck-salt-lint-parser (output checker buffer)
+  "Parse salt lint JSON errors from OUTPUT.
+
+The arguments CHECKER and BUFFER are only passed through."
+  (condition-case nil
+      (let* ((json-array-type 'list)
+             (json-object-type 'plist)
+            (filename (buffer-file-name buffer))
+            (errors (json-read-from-string output)))
+        (mapcar (lambda (e)
+                  (flycheck-error-new
+                   :checker checker
+                   :buffer buffer
+                   :filename filename
+                   :level (pcase (plist-get e :severity)
+                            ("HIGH" 'error)
+                            ("MEDIUM" 'warning)
+                            ("LOW" 'warning)
+                            ("INFO" 'info)
+                            (_ 'info))
+                   :line (plist-get e :linenumber)
+                   :column 0
+                   :message (concat (plist-get e :message) (plist-get e :line))
+                   :id (plist-get e :id))) errors))
+    (json-error nil)))
+
 (defvar flycheck-sass-scss-cache-directory nil
   "The cache directory for `sass' and `scss'.")
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]