Add make checkdoc to check doc style

Runs as part of the recently added “make check” and replaces the code
style specs we had before.
parent 82ed054d
......@@ -8,6 +8,7 @@
"doc/flycheck.texi")
(development
(depends-on "f") ; For some maintenance tools
(depends-on "buttercup") ; BDD test framework for Emacs
(depends-on "shut-up") ; Silence Emacs
......
......@@ -104,8 +104,12 @@ format:
check-format:
$(RUNEMACS) -l maint/flycheck-format.el -f flycheck/batch-check-format
.PHONY: checkdoc
checkdoc:
$(RUNEMACS) -l maint/flycheck-checkdoc.el -f flycheck/batch-checkdoc
.PHONY: check
check: check-format
check: check-format checkdoc
.PHONY: compile
compile: $(OBJS)
......
;;; flycheck-checkdoc.el --- Flycheck: Checkdoc runner -*- lexical-binding: t; -*-
;; Copyright (C) 2016 Sebastian Wiesner and Flycheck contributors
;; Author: Sebastian Wiesner <swiesner@lunaryorn.com>
;; This file is not part of GNU Emacs.
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
;;; Commentary:
;; This file provides checkdoc linting for Flycheck. It's intended for
;; non-interactive use, see "make checkdoc".
;;; Code:
(unless (version<= "25" emacs-version)
(user-error "Emacs 25 required for checkdoc"))
(require 'subr-x)
(require 'seq)
(require 'f)
(require 'checkdoc)
(require 'flycheck-maint
(expand-file-name "flycheck-maint"
(file-name-directory (f-this-file))))
(defconst flycheck/source-dir (locate-dominating-file load-file-name "Cask")
"The source directory of Flycheck.")
(defun flycheck/checkdoc-get-current-errors ()
"Get the current checkdoc errors.
Return a list of all error messages from checkdoc, and erase the
error message buffer, so that the next checkdoc check starts
fresh without previous errors.
Each error is just a string with the complete human-readable
location and error message."
(with-current-buffer checkdoc-diagnostic-buffer
(unwind-protect
(progn
(goto-char (point-min))
;; Skip over the checkdoc header
(re-search-forward (rx line-start "***" (1+ not-newline)
": checkdoc-current-buffer"))
(forward-line 1)
(let ((text (buffer-substring-no-properties (point) (point-max))))
(and (not (string-empty-p text))
(split-string text "\n"))))
(kill-buffer))))
(defun flycheck/checkdoc-file (filename)
"Run checkdoc on FILENAME and return a list of errors.
Each error is just a string with the complete human-readable
location and error message."
(with-temp-buffer
;; Visit the file to make sure that the filename is set, as some checkdoc
;; lints only apply for buffers with filenames
(insert-file-contents filename 'visit)
(set-buffer-modified-p nil)
;; Switch to Emacs Lisp mode to give checkdoc the proper syntax table, etc.
(delay-mode-hooks (emacs-lisp-mode))
(setq delay-mode-hooks nil)
(checkdoc-current-buffer 'take-notes)
(flycheck/checkdoc-get-current-errors)))
(defun flycheck/batch-checkdoc ()
"Run checkdoc on all source files and exit."
(let ((errors (seq-mapcat #'flycheck/checkdoc-file
(flycheck/all-source-files))))
(seq-do (lambda (err) (message "%s" err)) errors)
(kill-emacs (if errors 1 0))))
;;; flycheck-checkdoc.el ends here
......@@ -25,42 +25,18 @@
;;; Code:
(unless (version<= "25" emacs-version)
(user-error "Emacs 25 required for formatting"))
(require 'seq)
(require 'rx)
(require 'f)
(require 'whitespace)
(require 'elisp-mode)
(unless noninteractive
(error "This file must not be used interactively"))
(unless (version<= "25" emacs-version)
(user-error "Emacs 25 required for formatting"))
(defconst flycheck/source-dir (locate-dominating-file load-file-name "Cask")
"The source directory of Flycheck.")
(defun flycheck/collect-el-files (directory &optional recursive)
"Collect all Emacs Lisp files in DIRECTORY.
If RECURSIVE is given and non-nil collect files recursively."
(let ((fn-re (rx ".el" eos)))
(if recursive
(directory-files-recursively directory fn-re)
(directory-files directory 'full fn-re))))
(defun flycheck/all-source-files ()
"Find all source files of Flycheck."
(append
(seq-mapcat (lambda (rel-name)
(flycheck/collect-el-files
(expand-file-name rel-name flycheck/source-dir)))
'("." "maint/" "doc/" "test/"))
(flycheck/collect-el-files
(expand-file-name "test/specs/" flycheck/source-dir) 'recursive)))
(defun flycheck/already-loaded-p (filename)
"Whether FILENAME is already loaded."
(not (null (assoc filename load-history))))
(require 'flycheck-maint
(expand-file-name "flycheck-maint"
(file-name-directory (f-this-file))))
(defun flycheck/eval-and-format-buffer (filename)
"Format the current buffer for FILENAME.
......
;;; flycheck-maint.el --- Flycheck: Maintenace library -*- lexical-binding: t; -*-
;; Copyright (C) 2016 Sebastian Wiesner and Flycheck contributors
;; Author: Sebastian Wiesner <swiesner@lunaryorn.com>
;; This file is not part of GNU Emacs.
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
;;; Commentary:
;; This file provides helper functions for maintenance tools.
;;; Code:
(unless noninteractive
(error "This file must not be used interactively"))
(defconst flycheck/source-dir (locate-dominating-file load-file-name "Cask")
"The source directory of Flycheck.")
(defun flycheck/collect-el-files (directory &optional recursive)
"Collect all Emacs Lisp files in DIRECTORY.
If RECURSIVE is given and non-nil collect files recursively."
(let ((fn-re (rx ".el" eos)))
(if recursive
(directory-files-recursively directory fn-re)
(directory-files directory 'full fn-re))))
(defun flycheck/all-source-files ()
"Find all source files of Flycheck."
(append
(seq-mapcat (lambda (rel-name)
(flycheck/collect-el-files
(expand-file-name rel-name flycheck/source-dir)))
'("." "maint/" "doc/" "test/"))
(flycheck/collect-el-files
(expand-file-name "test/specs/" flycheck/source-dir) 'recursive)))
(defun flycheck/already-loaded-p (filename)
"Whether FILENAME is already loaded."
(not (null (assoc filename load-history))))
(provide 'flycheck-maint)
;;; flycheck-maint.el ends here
;;; test-code-style.el --- Flycheck Specs: Code style -*- lexical-binding: t; -*-
;; Copyright (C) 2016 Sebastian Wiesner
;; Author: Sebastian Wiesner <swiesner@lunaryorn.com>
;; This file is not part of GNU Emacs.
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
;;; Commentary:
;; Specs for code style.
;;; Code:
(require 'flycheck-buttercup)
(require 'checkdoc)
(require 'seq)
(defun flycheck/checkstyle (file-name)
"Run `checkstyle' on FILE-NAME and return the results."
(with-temp-buffer
(insert-file-contents file-name 'visit)
(delay-mode-hooks (emacs-lisp-mode))
(setq delay-mode-hooks nil)
(with-demoted-errors "Error in checkdoc: %S"
(checkdoc-current-buffer t)
(with-current-buffer checkdoc-diagnostic-buffer
(unwind-protect
(progn
(goto-char (point-min))
;; Skip over the checkdoc header
(re-search-forward (rx line-start "***" (1+ not-newline)
": checkdoc-current-buffer"))
(forward-line 1)
(buffer-substring-no-properties (point) (point-max)))
(kill-buffer))))))
(defun flycheck/find-all-elisp-files ()
"Find all Emacs Lisp files in our source code."
(let* ((source-dir (locate-dominating-file default-directory "Cask"))
(default-directory source-dir)
(sources (seq-map #'expand-file-name (process-lines "git" "ls-files"))))
(seq-filter (lambda (fn) (and (string-match-p (rx ".el" eos) fn)
(not (string-match-p (rx "test/resources/") fn))))
sources)))
(describe "Code style"
(dolist (source (flycheck/find-all-elisp-files))
(describe (format "File %s" (file-relative-name source))
(before-each
(assume (version<= "25" emacs-version) "Our style must match Emacs 25"))
(it "has proper documentation format"
(expect (flycheck/checkstyle source)
:to-equal "")))))
;;; test-code-style.el ends here
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment