After spending some time working in AWS Cloudformation and running
cfn-lint manually, I decided to incorporate it into my Emacs config.
Here’s a basic cloudformation-mode for DOOM Emacs, complete with a flycheck checker for cfn-lint:
;; cloudformation-mode
(define-derived-mode cfn-mode yaml-mode
"Cloudformation"
"Cloudformation template mode.")
(add-to-list 'auto-mode-alist '(".template\\'" . cfn-mode))
(after! flycheck
(flycheck-define-checker cfn-lint
"A Cloudformation linter using cfn-python-lint.
See URL 'https://github.com/awslabs/cfn-python-lint'."
:command ("cfn-lint" "-f" "parseable" source)
:error-patterns (
(warning line-start (file-name) ":" line ":" column
":" (one-or-more digit) ":" (one-or-more digit) ":"
(id "W" (one-or-more digit)) ":" (message) line-end)
(error line-start (file-name) ":" line ":" column
":" (one-or-more digit) ":" (one-or-more digit) ":"
(id "E" (one-or-more digit)) ":" (message) line-end)
)
:modes (cfn-mode)
)
(add-to-list 'flycheck-checkers 'cfn-lint)
)
Of course, this only covers the YAML case, and technically JSON is valid Cloudformation as well... but who hates themselves enough to write Cloudformation in JSON?