summaryrefslogtreecommitdiff
path: root/tw/home/files/emacs-packages/actionlint.el
blob: 3c37e34b5a33c9ba9ecf12de30e689acb0e6d359 (about) (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
;;; actionlint.el --- Flycheck checker for GitHub Actions.
;;; Commentary:
;; GitHub Actions are defined using mostly plain YAML files.
;; Actionlint is a linter catching GitHub Action-specific mistakes, and also
;; checks Shell and Python code embedded in Actions (using shellcheck and
;; pyflakes, respectively).
;;; Code:

(require 'flycheck)

(defun actionlint-github-workflow-p ()
  "Does the current buffer contain a GitHub Action?"
  (string-match-p "\\.github/workflows/[^/]+\\.yml\\'" (buffer-file-name)))

(flycheck-def-executable-var actionlint "actionlint")

(flycheck-define-checker actionlint
  "A syntax checker and linter for alidist recipes."
  ;; `flycheck-alidist-executable' automatically overrides the car of the
  ;; :command list if set and non-nil.
  :command ("actionlint" "-no-color" "-oneline" source)
  :error-patterns
  ((error line-start (file-name) ":" line ":" column ": " (message)
          " [" (id (minimal-match (one-or-more not-newline))) "]" line-end))
  ;; Only enable this in actual GitHub Actions, not just any YAML document.
  :modes (yaml-mode)
  :predicate actionlint-github-workflow-p
  ;; Also check the document with YAML checkers, whether or not we have errors.
  :next-checkers (yaml-ruby yaml-yamllint))

(add-to-list 'flycheck-checkers 'actionlint)

(provide 'actionlint)
;;; actionlint.el ends here