1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2025-12-10 08:10:21 -08:00

Add empty-body warning for when, unless etc

Warn about code like (when SOME-CONDITION) because these may indicate
bugs.  Warnings currently apply to `when`, `unless`, `ignore-error`,
`with-suppressed-warnings` and (as before) `let` and `let*`.

* lisp/emacs-lisp/byte-run.el (with-suppressed-warnings):
Update doc string.
* lisp/emacs-lisp/bytecomp.el: (byte-compile-warning-types)
(byte-compile-warnings): Add empty-body.
(byte-compile-initial-macro-environment):
Add empty-body warning for with-suppressed-warnings.
* lisp/emacs-lisp/macroexp.el (macroexp--expand-all):
Use the empty-body category for let and let*.
* lisp/subr.el (when, unless, ignore-error): Add empty-body warning.
* test/lisp/emacs-lisp/bytecomp-tests.el
(bytecomp-test--with-suppressed-warnings): Add test cases.
This commit is contained in:
Mattias Engdegård 2022-12-29 13:01:47 +01:00
parent 2de25accaf
commit 7c63b632e4
5 changed files with 84 additions and 24 deletions

View file

@ -1433,7 +1433,50 @@ literals (Bug#20852)."
(set-buffer (get-buffer-create "foo"))
nil))
'((suspicious set-buffer))
"Warning: Use .with-current-buffer. rather than"))
"Warning: Use .with-current-buffer. rather than")
(test-suppression
'(defun zot ()
(let ((_ 1))
))
'((empty-body let))
"Warning: Empty let body")
(test-suppression
'(defun zot ()
(let* ((_ 1))
))
'((empty-body let*))
"Warning: Empty let\\* body")
(test-suppression
'(defun zot (x)
(when x
))
'((empty-body when))
"Warning: `when' with empty body")
(test-suppression
'(defun zot (x)
(unless x
))
'((empty-body unless))
"Warning: `unless' with empty body")
(test-suppression
'(defun zot (x)
(ignore-error arith-error
))
'((empty-body ignore-error))
"Warning: `ignore-error' with empty body")
(test-suppression
'(defun zot (x)
(with-suppressed-warnings ((suspicious eq))
))
'((empty-body with-suppressed-warnings))
"Warning: `with-suppressed-warnings' with empty body")
)
(ert-deftest bytecomp-tests--not-writable-directory ()
"Test that byte compilation works if the output directory isn't