1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2025-12-06 06:20:55 -08:00

Add mechanism for gradually phasing in new byte compilation warnings

* lisp/Makefile.in (BYTE_COMPILE_FLAGS): Enable all byte
compilation warnings.
* lisp/emacs-lisp/bytecomp.el (byte-compile-warning-types): Add
docstrings-non-ascii-quotes and document new semantics for `all'
and t.
(byte-compile--emacs-build-warning-types): New constant.
(byte-compile-warning-enabled-p): Implement the new semantics.
(byte-compile-docstring-style-warn): Reinstate the Unicode quote
warning.
This commit is contained in:
Lars Ingebrigtsen 2022-06-19 13:37:10 +02:00
parent 76f3878e28
commit 93b018c664
2 changed files with 35 additions and 9 deletions

View file

@ -67,7 +67,8 @@ AUTOGENEL = ${loaddefs} ${srcdir}/cus-load.el ${srcdir}/finder-inf.el \
# Set load-prefer-newer for the benefit of the non-bootstrappers. # Set load-prefer-newer for the benefit of the non-bootstrappers.
BYTE_COMPILE_FLAGS = \ BYTE_COMPILE_FLAGS = \
--eval '(setq load-prefer-newer t)' $(BYTE_COMPILE_EXTRA_FLAGS) --eval "(setq load-prefer-newer t byte-compile-warnings 'all)" \
$(BYTE_COMPILE_EXTRA_FLAGS)
# ... but we must prefer .elc files for those in the early bootstrap. # ... but we must prefer .elc files for those in the early bootstrap.
# A larger `max-specpdl-size' is needed for emacs-lisp/comp.el. # A larger `max-specpdl-size' is needed for emacs-lisp/comp.el.
compile-first: BYTE_COMPILE_FLAGS = \ compile-first: BYTE_COMPILE_FLAGS = \

View file

@ -299,10 +299,10 @@ The information is logged to `byte-compile-log-buffer'."
'(redefine callargs free-vars unresolved '(redefine callargs free-vars unresolved
obsolete noruntime interactive-only obsolete noruntime interactive-only
make-local mapcar constants suspicious lexical lexical-dynamic make-local mapcar constants suspicious lexical lexical-dynamic
docstrings not-unused) docstrings docstrings-non-ascii-quotes not-unused)
"The list of warning types used when `byte-compile-warnings' is t.") "The list of warning types used when `byte-compile-warnings' is t.")
(defcustom byte-compile-warnings t (defcustom byte-compile-warnings t
"List of warnings that the byte-compiler should issue (t for all). "List of warnings that the byte-compiler should issue (t for almost all).
Elements of the list may be: Elements of the list may be:
@ -327,15 +327,28 @@ Elements of the list may be:
`byte-compile-docstring-max-column' or `byte-compile-docstring-max-column' or
`fill-column' characters, whichever is bigger) or `fill-column' characters, whichever is bigger) or
have other stylistic issues. have other stylistic issues.
docstrings-non-ascii-quotes docstrings that have non-ASCII quotes.
This depends on the `docstrings' warning type.
suspicious constructs that usually don't do what the coder wanted. suspicious constructs that usually don't do what the coder wanted.
If the list begins with `not', then the remaining elements specify warnings to If the list begins with `not', then the remaining elements specify warnings to
suppress. For example, (not mapcar) will suppress warnings about mapcar." suppress. For example, (not mapcar) will suppress warnings about mapcar.
The t value means \"all non experimental warning types\", and
excludes the types in `byte-compile--emacs-build-warning-types'.
A value of `all' really means all."
:type `(choice (const :tag "All" t) :type `(choice (const :tag "All" t)
(set :menu-tag "Some" (set :menu-tag "Some"
,@(mapcar (lambda (x) `(const ,x)) ,@(mapcar (lambda (x) `(const ,x))
byte-compile-warning-types)))) byte-compile-warning-types))))
(defconst byte-compile--emacs-build-warning-types
'(docstrings-non-ascii-quotes)
"List of warning types that are only enabled during Emacs builds.
This is typically either warning types that are being phased in
(but shouldn't be enabled for packages yet), or that are only relevant
for the Emacs build itself.")
(defvar byte-compile--suppressed-warnings nil (defvar byte-compile--suppressed-warnings nil
"Dynamically bound by `with-suppressed-warnings' to suppress warnings.") "Dynamically bound by `with-suppressed-warnings' to suppress warnings.")
@ -354,10 +367,15 @@ suppress. For example, (not mapcar) will suppress warnings about mapcar."
(memq symbol (cdr elem))) (memq symbol (cdr elem)))
(setq suppress t))) (setq suppress t)))
(and (not suppress) (and (not suppress)
(or (eq byte-compile-warnings t) ;; During an Emacs build, we want all warnings.
(if (eq (car byte-compile-warnings) 'not) (or (eq byte-compile-warnings 'all)
(not (memq warning byte-compile-warnings)) ;; If t, we want almost all the warnings, but not the
(memq warning byte-compile-warnings)))))) ;; ones that are Emacs build specific.
(and (not (memq warning byte-compile--emacs-build-warning-types))
(or (eq byte-compile-warnings t)
(if (eq (car byte-compile-warnings) 'not)
(not (memq warning byte-compile-warnings))
(memq warning byte-compile-warnings))))))))
;;;###autoload ;;;###autoload
(defun byte-compile-disable-warning (warning) (defun byte-compile-disable-warning (warning)
@ -1761,7 +1779,14 @@ It is too wide if it has any lines longer than the largest of
(when (string-match-p "\\( \"\\|[ \t]\\|^\\)'[a-z(]" docs) (when (string-match-p "\\( \"\\|[ \t]\\|^\\)'[a-z(]" docs)
(byte-compile-warn-x (byte-compile-warn-x
name "%s%sdocstring has wrong usage of unescaped single quotes (use \\= or different quoting)" name "%s%sdocstring has wrong usage of unescaped single quotes (use \\= or different quoting)"
kind name))))) kind name))
;; There's a "Unicode quote" in the string -- it should probably
;; be an ASCII one instead.
(when (byte-compile-warning-enabled-p 'docstrings-non-ascii-quotes)
(when (string-match-p "\\( \"\\|[ \t]\\|^\\)[]" docs)
(byte-compile-warn-x
name "%s%sdocstring has wrong usage of \"fancy\" single quotation marks"
kind name))))))
form) form)
;; If we have compiled any calls to functions which are not known to be ;; If we have compiled any calls to functions which are not known to be