Skip to content

Document how to automatically run ansible-lint inside code editors, e.g. flycheck in emacs #1326

Closed Answered by Perdu
omsai asked this question in Ideas
Discussion options

You must be logged in to vote

Here's what I ended up writing in my .emacs:

;;; ansible-lint
; Compile regex for ansible-lint
(require 'compile)
(add-to-list 'compilation-error-regexp-alist
             'yaml)
(add-to-list 'compilation-error-regexp-alist-alist
             '(yaml "^\\(.*?\\):\\([0-9]+\\)" 1 2)
             )

; Replace make -k with ansible-lint, with an UTF-8 locale to avoid crashes
(defun ansible-lint-errors ()
  (make-local-variable 'compile-command)
  (let ((ansiblelint_command "ansible-lint ") (loc "LANG=C.UTF-8 "))
    (setq compile-command (concat loc ansiblelint_command buffer-file-name)))
)
(add-hook 'yaml-mode-hook 'ansible-lint-errors)

Then you can use the classical compile workflow (M-x compile

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by omsai
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Ideas
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #551 on February 09, 2021 15:33.