From 93b018c664e1f95b41d0239c651a79a237edfc38 Mon Sep 17 00:00:00 2001 From: Lars Ingebrigtsen Date: Sun, 19 Jun 2022 13:37:10 +0200 Subject: [PATCH] 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. --- lisp/Makefile.in | 3 ++- lisp/emacs-lisp/bytecomp.el | 41 +++++++++++++++++++++++++++++-------- 2 files changed, 35 insertions(+), 9 deletions(-) diff --git a/lisp/Makefile.in b/lisp/Makefile.in index 8728467977a..9516f2fc364 100644 --- a/lisp/Makefile.in +++ b/lisp/Makefile.in @@ -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. 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. # A larger `max-specpdl-size' is needed for emacs-lisp/comp.el. compile-first: BYTE_COMPILE_FLAGS = \ diff --git a/lisp/emacs-lisp/bytecomp.el b/lisp/emacs-lisp/bytecomp.el index 7f408472da1..2ae9aa13bb6 100644 --- a/lisp/emacs-lisp/bytecomp.el +++ b/lisp/emacs-lisp/bytecomp.el @@ -299,10 +299,10 @@ The information is logged to `byte-compile-log-buffer'." '(redefine callargs free-vars unresolved obsolete noruntime interactive-only 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.") (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: @@ -327,15 +327,28 @@ Elements of the list may be: `byte-compile-docstring-max-column' or `fill-column' characters, whichever is bigger) or 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. 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) (set :menu-tag "Some" ,@(mapcar (lambda (x) `(const ,x)) 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 "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))) (setq suppress t))) (and (not suppress) - (or (eq byte-compile-warnings t) - (if (eq (car byte-compile-warnings) 'not) - (not (memq warning byte-compile-warnings)) - (memq warning byte-compile-warnings)))))) + ;; During an Emacs build, we want all warnings. + (or (eq byte-compile-warnings 'all) + ;; If t, we want almost all the warnings, but not the + ;; 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 (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) (byte-compile-warn-x 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) ;; If we have compiled any calls to functions which are not known to be -- 2.39.2