mirror of
https://git.savannah.gnu.org/git/emacs.git
synced 2024-12-02 08:22:22 +00:00
Make checkdoc warn if not using lexical-binding
* lisp/emacs-lisp/checkdoc.el (checkdoc-file-comments-engine): Warn if there is no lexical-binding cookie. (Bug#59920) (checkdoc-lexical-binding-flag): New user option.
This commit is contained in:
parent
05a7c91b91
commit
7d60d1652f
8
etc/NEWS
8
etc/NEWS
@ -711,6 +711,14 @@ without specifying a file, like this:
|
||||
*** New user option 'image-dired-thumb-naming'.
|
||||
You can now configure how a thumbnail is named using this option.
|
||||
|
||||
** checkdoc
|
||||
|
||||
---
|
||||
*** New checkdock warning if not using lexical-binding.
|
||||
Checkdoc now warns if the first line of an Emacs Lisp file does not
|
||||
end with a "-*- lexical-binding: t -*-" cookie. Customize the user
|
||||
option 'checkdoc-lexical-binding-flag' to nil to disable this warning.
|
||||
|
||||
|
||||
* New Modes and Packages in Emacs 30.1
|
||||
|
||||
|
@ -128,6 +128,14 @@
|
||||
;; simple style rules to follow which checkdoc will auto-fix for you.
|
||||
;; `y-or-n-p' and `yes-or-no-p' should also end in "?".
|
||||
;;
|
||||
;; Lexical binding:
|
||||
;;
|
||||
;; We recommend always using lexical binding in new code, and
|
||||
;; converting old code to use it. Checkdoc warns if you don't have
|
||||
;; the recommended string "-*- lexical-binding: t -*-" at the top of
|
||||
;; the file. You can disable this check with the user option
|
||||
;; `checkdoc-lexical-binding-flag'.
|
||||
;;
|
||||
;; Adding your own checks:
|
||||
;;
|
||||
;; You can experiment with adding your own checks by setting the
|
||||
@ -339,6 +347,12 @@ See Info node `(elisp) Documentation Tips' for background."
|
||||
:type 'boolean
|
||||
:version "28.1")
|
||||
|
||||
(defcustom checkdoc-lexical-binding-flag t
|
||||
"Non-nil means generate warnings if file is not using lexical binding.
|
||||
See Info node `(elisp) Converting to Lexical Binding' for more."
|
||||
:type 'boolean
|
||||
:version "30.1")
|
||||
|
||||
;; This is how you can use checkdoc to make mass fixes on the Emacs
|
||||
;; source tree:
|
||||
;;
|
||||
@ -2377,6 +2391,31 @@ Code:, and others referenced in the style guide."
|
||||
(point-min) (save-excursion (goto-char (point-min))
|
||||
(line-end-position))))
|
||||
nil))
|
||||
(when checkdoc-lexical-binding-flag
|
||||
(setq
|
||||
err
|
||||
;; Lexical binding cookie.
|
||||
(if (not (save-excursion
|
||||
(save-restriction
|
||||
(goto-char (point-min))
|
||||
(narrow-to-region (point) (pos-eol))
|
||||
(re-search-forward
|
||||
(rx "-*-" (* (* nonl) ";")
|
||||
(* space) "lexical-binding:" (* space) "t" (* space)
|
||||
(* ";" (* nonl))
|
||||
"-*-")
|
||||
nil t))))
|
||||
(let ((pos (save-excursion (goto-char (point-min))
|
||||
(goto-char (pos-eol))
|
||||
(point))))
|
||||
(if (checkdoc-y-or-n-p "There is no lexical-binding cookie! Add one?")
|
||||
(progn
|
||||
(goto-char pos)
|
||||
(insert " -*- lexical-binding: t -*-"))
|
||||
(checkdoc-create-error
|
||||
"The first line should end with \"-*- lexical-binding: t -*-\""
|
||||
pos (1+ pos) t)))
|
||||
nil)))
|
||||
(setq
|
||||
err
|
||||
(or
|
||||
|
Loading…
Reference in New Issue
Block a user