From 13e46e2c1d33a3a48ecdcb56b745dbc53a4a3831 Mon Sep 17 00:00:00 2001 From: Stefan Kangas Date: Sun, 24 Dec 2023 14:27:48 +0100 Subject: [PATCH] checkdoc: Avoid false positive for keybinding in docstring * lisp/emacs-lisp/checkdoc.el (checkdoc-this-string-valid-engine): Avoid false positive when a variable contains a keybinding (for example, "C-g"). (Bug#68002) * test/lisp/emacs-lisp/checkdoc-tests.el (checkdoc-docstring-avoid-false-positive-ok): New test. --- lisp/emacs-lisp/checkdoc.el | 7 +++++-- test/lisp/emacs-lisp/checkdoc-tests.el | 9 +++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/lisp/emacs-lisp/checkdoc.el b/lisp/emacs-lisp/checkdoc.el index 471a2fbdf48..dd7cfd82b1d 100644 --- a/lisp/emacs-lisp/checkdoc.el +++ b/lisp/emacs-lisp/checkdoc.el @@ -1611,8 +1611,11 @@ may require more formatting") (let ((f nil) (m nil) (start (point)) ;; Ignore the "A-" modifier: it is uncommon in practice, ;; and leads to false positives in regexp ranges. - (re "[^`‘A-Za-z0-9_]\\([CMs]-[a-zA-Z]\\|\\(\\([CMs]-\\)?\ -mouse-[0-3]\\)\\)\\>")) + (re (rx (not (any "0-9A-Za-z_`‘-")) + (group (or (seq (any "CMs") "-" (any "A-Za-z")) + (group (opt (group (any "CMs") "-")) + "mouse-" (any "0-3")))) + eow))) ;; Find the first key sequence not in a sample (while (and (not f) (setq m (re-search-forward re e t))) (setq f (not (checkdoc-in-sample-code-p start e)))) diff --git a/test/lisp/emacs-lisp/checkdoc-tests.el b/test/lisp/emacs-lisp/checkdoc-tests.el index 57694bd424b..242e41c7f08 100644 --- a/test/lisp/emacs-lisp/checkdoc-tests.el +++ b/test/lisp/emacs-lisp/checkdoc-tests.el @@ -37,6 +37,15 @@ (insert "(defun foo())") (should-error (checkdoc-defun) :type 'user-error))) +(ert-deftest checkdoc-docstring-avoid-false-positive-ok () + "Check that Bug#68002 is fixed." + (with-temp-buffer + (emacs-lisp-mode) + (insert "(defvar org-element--cache-interrupt-C-g-count 0 + \"Current number of `org-element--cache-sync' calls. +See `org-element--cache-interrupt-C-g'.\")") + (checkdoc-defun))) + (ert-deftest checkdoc-cl-defmethod-ok () "Checkdoc should be happy with a simple correct cl-defmethod." (with-temp-buffer -- 2.39.2