File: checkdock.el

package info (click to toggle)
treemacs 3.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 6,480 kB
  • sloc: lisp: 15,942; python: 345; makefile: 87
file content (156 lines) | stat: -rw-r--r-- 4,199 bytes parent folder | download
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
;;; -*- lexical-binding: t -*-
;;; Based on https://github.com/flycheck/flycheck/blob/master/maint/flycheck-checkdoc.el

(require 'bytecomp)
(require 'checkdoc)
(require 'dash)
(require 's)

(defconst all-el-files (append (directory-files "./src/elisp" :full ".el")
                               (directory-files "./src/extra" :full ".el")))

(defconst valid-doc-words
  (append checkdoc-ispell-lisp-words
          '("accessor"
            "adoc"
            "api"
            "arg"
            "args"
            "async"
            "baz"
            "boolean"
            "bool"
            "btn"
            "changelog"
            "config"
            "configs"
            "cpp"
            "customisations"
            "debounce"
            "debounced"
            "dir"
            "dired"
            "dirs"
            "dir's"
            "dom"
            "Dotfiles"
            "dotfile"
            "dotfiles"
            "eieio"
            "el"
            "eldoc"
            "elisp"
            "elpa"
            "filename"
            "filesystem"
            "filetree"
            "FilePath"
            "filepath"
            "filepaths"
            "filewatch"
            "flycheck"
            "fn"
            "fontification"
            "git"
            "gitignore"
            "goto"
            "gui"
            "HashMap"
            "hoc"
            "ImageMagick"
            "imenu"
            "init"
            "initialiser"
            "inlined"
            "iter"
            "keybind"
            "keybinds"
            "keybindings"
            "kqueue"
            "leftclick"
            "linux"
            "localized"
            "macos"
            "MacOS"
            "magit"
            "maildir"
            "maildirs"
            "makefile"
            "metadata"
            "minibuffer"
            "modeline"
            "org"
            "org's"
            "persp"
            "Pfuture"
            "pfuture"
            "plist"
            "png"
            "plaintext"
            "pos"
            "programmatically"
            "propertized"
            "px"
            "py"
            "rebase"
            "recentering"
            "regex"
            "resize"
            "resized"
            "resizing"
            "sb"
            "spaceline"
            "splittable"
            "struct"
            "subdir"
            "subdirs"
            "subprocess"
            "treemacs"
            "tui"
            "txt"
            "unmark"
            "untracked"
            "variadic"
            "wayland"
            "whitespace"
            "workspace"
            "workspaces")))

(defun checkdoc-buffer (filename)
  ;; output only /src/elisp/filename.el as when compiling
  (message "Checkdoc %s" (substring filename (1+ (s-index-of "/src" filename))))
  (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)
    (delay-mode-hooks (emacs-lisp-mode))
    (setf delay-mode-hooks nil
          ispell-dictionary "british")
    (let ((checkdoc-autofix-flag 'never)
          (checkdoc-force-docstrings-flag t)
          (checkdoc-force-history-flag nil)
          (checkdoc-permit-comma-termination-flag nil)
          (checkdoc-spellcheck-documentation-flag t)
          (checkdoc-ispell-lisp-words valid-doc-words)
          (checkdoc-arguments-in-order-flag t)
          (checkdoc-verb-check-experimental-flag t))
      (checkdoc-current-buffer :take-notes))
    (get-errors)))

(defun get-errors ()
  (with-current-buffer checkdoc-diagnostic-buffer
    (goto-char (point-min))
    ;; Skip over the checkdoc header
    (re-search-forward (rx line-start "***" (1+ not-newline)
                           ": checkdoc-current-buffer"))
    (forward-line 1)
    (prog1
        (let ((text (buffer-substring-no-properties (point) (point-max))))
          (and (not (s-blank-p text))
               (split-string text "\n")))
      (kill-buffer))))

(let ((errors (-mapcat #'checkdoc-buffer all-el-files)))
  (-each errors #'message)
  (kill-emacs (if errors 1 0)))