Skip to content

Commit

Permalink
Checkdoc batch mode
Browse files Browse the repository at this point in the history
  • Loading branch information
federicotdn committed Jun 30, 2024
1 parent 966e087 commit 9828744
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 5 deletions.
8 changes: 3 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
SHELL = bash
EMACS ?= emacs
PORT ?= 8000
NOOUTPUT = grep -v '^Loading' | { ! grep '^'; }
PACKAGES = packages
FONT_SIZE ?= 180
ENV ?= env
Expand Down Expand Up @@ -68,12 +67,11 @@ lint-file:
@printf "\n--> Step: Byte-compile file\n\n"
$(EMACS) --batch -L . \
--eval "(setq byte-compile-error-on-warn t)" \
-f batch-byte-compile "$(filename)" 2>&1
-f batch-byte-compile "$(filename)"
@printf "\n--> Step: Run checkdoc\n\n"
yes n | $(EMACS) --batch \
--eval '(find-file "$(filename)")' \
--eval '(setq sentence-end-double-space nil)' \
--eval '(checkdoc-current-buffer)' 2>&1 | $(NOOUTPUT)
-l test/checkdoc-batch.el \
-f checkdoc-batch-and-exit "$(filename)"
@printf "\n--> Step: Run package-lint\n\n"
$(EMACS) --batch --eval "(setq package-user-dir \"$$PWD/$(PACKAGES)\")" \
--eval "(package-initialize)" \
Expand Down
28 changes: 28 additions & 0 deletions test/checkdoc-batch.el
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
;; checkdoc-batch.el --- Batch mode for checkdoc -*- lexical-binding: t; -*-

(defun checkdoc-batch-and-exit ()
"Run checkdoc in batch mode for a set of files.
Exit with 1 if one or more warnings were emitted, otherwise with 0."
(unless noninteractive
(error "`checkdoc-batch-and-exit' is to be used only with -batch"))
(let ((status 0)
path)
(while command-line-args-left
(setq path (car command-line-args-left))
(with-current-buffer (find-file-noselect path)
(checkdoc-current-buffer t))
(with-current-buffer "*Style Warnings*"
(goto-char (point-min))
(while (not (eobp))
(let* ((rule "[ \t\n\r\f]+")
(line (string-trim (buffer-substring-no-properties
(line-beginning-position)
(line-end-position))
rule rule)))
(when (and (not (string= line ""))
(not (string-prefix-p "*" line)))
(princ (concat line "\n"))
(setq status 1)))
(ignore-errors (next-line))))
(setq command-line-args-left (cdr command-line-args-left)))
(kill-emacs status)))

0 comments on commit 9828744

Please sign in to comment.