dev(ci): fix scope checker in commit linter

- Linter wasn't failing on any invalid scopes due to logic error.
- Linter was failing to recognize module categories as valid
  scopes (e.g. :lang, :ui, etc).
- Adds 'ci' and 'lib' as valid scopes.
This commit is contained in:
Henrik Lissner 2021-09-24 12:31:46 +02:00
parent c9ac6a9cbf
commit 2a0aa3d15b

View file

@ -78,13 +78,11 @@
(fn! (&key type scopes) (fn! (&key type scopes)
(unless (memq type '(bump revert merge module release)) (unless (memq type '(bump revert merge module release))
(cl-loop with scopes = (cl-loop with valid-scopes =
(cl-loop for path (let ((modules (mapcar #'doom-module-from-path (cdr (doom-module-load-path (list doom-modules-dir))))))
in (cdr (doom-module-load-path (list doom-modules-dir))) (append (seq-uniq (mapcar #'car modules))
for (_category . module) (mapcar #'cdr modules)))
= (doom-module-from-path path) with extra-scopes = '("cli" "ci" "lib")
collect (symbol-name module))
with extra-scopes = '("cli")
with regexp-scopes = '("^&") with regexp-scopes = '("^&")
with type-scopes = with type-scopes =
(pcase type (pcase type
@ -94,15 +92,20 @@
(doom-glob doom-docs-dir "[a-z]*.org"))))) (doom-glob doom-docs-dir "[a-z]*.org")))))
with scopes-re = with scopes-re =
(concat (string-join regexp-scopes "\\|") (concat (string-join regexp-scopes "\\|")
"\\|" "\\|^\\("
(regexp-opt (append type-scopes extra-scopes scopes))) (regexp-opt (append type-scopes
extra-scopes
(mapcar #'symbol-name valid-scopes)))
"\\)$")
for scope in scopes for scope in scopes
if (not (string-match scopes-re scope)) if (not (string-match scopes-re scope))
collect scope into error-scopes collect scope into error-scopes
finally return finally return
(when error-scopes (when error-scopes
(cons 'error (format "Commit has invalid scope(s): %s" (cons 'error
error-scopes)))))) (format "Commit has invalid scope%s: %s"
(if (cdr error-scopes) "s" "")
(string-join (nreverse error-scopes) ", ")))))))
(fn! (&key scopes) (fn! (&key scopes)
(unless (equal scopes (sort scopes #'string-lessp)) (unless (equal scopes (sort scopes #'string-lessp))