From 986bf7ac0dbfee0522cbe1e89872309d3a4f182c Mon Sep 17 00:00:00 2001 From: Mauro Aranda Date: Thu, 4 Mar 2021 10:13:26 -0300 Subject: Remove duplicated tests in checkdoc-tests.el * test/lisp/emacs-lisp/checkdoc-tests.el (checkdoc-cl-defmethod-ok) (checkdoc-cl-defmethod-with-types-ok, checkdoc-cl-defun-with-key-ok) (checkdoc-cl-defun-with-allow-other-keys-ok) (checkdoc-cl-defun-with-default-optional-value-ok) (checkdoc-cl-defun-with-destructuring-ok): This tests were duplicated, so keep one copy of them. Checked by diffing two files with the suspected tests, and supported by the fact that running occur with the regexp "^(ert-deftest" reported 14 matches, while the tests being run were 8. --- test/lisp/emacs-lisp/checkdoc-tests.el | 45 ---------------------------------- 1 file changed, 45 deletions(-) (limited to 'test/lisp/emacs-lisp/checkdoc-tests.el') diff --git a/test/lisp/emacs-lisp/checkdoc-tests.el b/test/lisp/emacs-lisp/checkdoc-tests.el index cf7baf4ce44..93015fbb105 100644 --- a/test/lisp/emacs-lisp/checkdoc-tests.el +++ b/test/lisp/emacs-lisp/checkdoc-tests.el @@ -82,51 +82,6 @@ (insert "(cl-defun foo ((a b &optional c) d) \"Return A+B+C+D.\")") (checkdoc-defun))) -(ert-deftest checkdoc-cl-defmethod-ok () - "Checkdoc should be happy with a simple correct cl-defmethod." - (with-temp-buffer - (emacs-lisp-mode) - (insert "(cl-defmethod foo (a) \"Return A.\")") - (checkdoc-defun))) - -(ert-deftest checkdoc-cl-defmethod-with-types-ok () - "Checkdoc should be happy with a cl-defmethod using types." - (with-temp-buffer - (emacs-lisp-mode) - ;; this method matches if A is the symbol `smthg' and if b is a list: - (insert "(cl-defmethod foo ((a (eql smthg)) (b list)) \"Return A+B.\")") - (checkdoc-defun))) - -(ert-deftest checkdoc-cl-defun-with-key-ok () - "Checkdoc should be happy with a cl-defun using &key." - (with-temp-buffer - (emacs-lisp-mode) - (insert "(cl-defun foo (&key a (b 27)) \"Return :A+:B.\")") - (checkdoc-defun))) - -(ert-deftest checkdoc-cl-defun-with-allow-other-keys-ok () - "Checkdoc should be happy with a cl-defun using &allow-other-keys." - (with-temp-buffer - (emacs-lisp-mode) - (insert "(cl-defun foo (&key a &allow-other-keys) \"Return :A.\")") - (checkdoc-defun))) - -(ert-deftest checkdoc-cl-defun-with-default-optional-value-ok () - "Checkdoc should be happy with a cl-defun using default values for optional args." - (with-temp-buffer - (emacs-lisp-mode) - ;; B is optional and equals 1+a if not provided. HAS-BS is non-nil - ;; if B was provided in the call: - (insert "(cl-defun foo (a &optional (b (1+ a) has-bs)) \"Return A + B.\")") - (checkdoc-defun))) - -(ert-deftest checkdoc-cl-defun-with-destructuring-ok () - "Checkdoc should be happy with a cl-defun destructuring its arguments." - (with-temp-buffer - (emacs-lisp-mode) - (insert "(cl-defun foo ((a b &optional c) d) \"Return A+B+C+D.\")") - (checkdoc-defun))) - (ert-deftest checkdoc-tests--next-docstring () "Checks that the one-argument form of `defvar' works. See the comments in Bug#24998." -- cgit v1.2.3 From fd9202304c8e08665c5dd468cdd56b523ffc7997 Mon Sep 17 00:00:00 2001 From: Mauro Aranda Date: Thu, 4 Mar 2021 08:34:58 -0300 Subject: Make checkdoc work with qualified methods * lisp/emacs-lisp/checkdoc.el (checkdoc--next-docstring): Handle cl-defmethod in a case of its own. Check for the presence of qualifiers, and skip them accordingly until the docstring. * test/lisp/emacs-lisp/checkdoc-tests.el (checkdoc-cl-defmethod-qualified-ok) (checkdoc-cl-defmethod-with-extra-qualifier-ok) (checkdoc-cl-defmethod-with-extra-and-nil-args-ok): Add tests for the fix. --- lisp/emacs-lisp/checkdoc.el | 21 ++++++++++++++++++++- test/lisp/emacs-lisp/checkdoc-tests.el | 27 +++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 1 deletion(-) (limited to 'test/lisp/emacs-lisp/checkdoc-tests.el') diff --git a/lisp/emacs-lisp/checkdoc.el b/lisp/emacs-lisp/checkdoc.el index 75aefdc7ba0..213ab43184f 100644 --- a/lisp/emacs-lisp/checkdoc.el +++ b/lisp/emacs-lisp/checkdoc.el @@ -932,7 +932,7 @@ don't move point." ;; definition ends prematurely. (end-of-file))) (`(,(or 'defun 'defvar 'defcustom 'defmacro 'defconst 'defsubst 'defadvice - 'cl-defun 'cl-defgeneric 'cl-defmethod 'cl-defmacro) + 'cl-defun 'cl-defgeneric 'cl-defmacro) ,(pred symbolp) ;; Require an initializer, i.e. ignore single-argument `defvar' ;; forms, which never have a doc string. @@ -942,6 +942,25 @@ don't move point." ;; initializer or argument list. (forward-sexp 3) (skip-chars-forward " \n\t") + t) + (`(,'cl-defmethod + ,(pred symbolp) + . ,rest) + (down-list) + (forward-sexp (pcase (car rest) + ;; No qualifier, so skip like we would have skipped in + ;; the first clause of the outer `pcase'. + ((pred listp) 3) + (':extra + ;; Skip the :extra qualifier together with its string too. + ;; Skip any additional qualifier. + (if (memq (nth 2 rest) '(:around :before :after)) + 6 + 5)) + ;; Skip :before, :after or :around qualifier too. + ((or ':around ':before ':after) + 4))) + (skip-chars-forward " \n\t") t))) ;;;###autoload diff --git a/test/lisp/emacs-lisp/checkdoc-tests.el b/test/lisp/emacs-lisp/checkdoc-tests.el index 93015fbb105..7a7aa9fb3cd 100644 --- a/test/lisp/emacs-lisp/checkdoc-tests.el +++ b/test/lisp/emacs-lisp/checkdoc-tests.el @@ -52,6 +52,33 @@ (insert "(cl-defmethod foo ((a (eql smthg)) (b list)) \"Return A+B.\")") (checkdoc-defun))) +(ert-deftest checkdoc-cl-defmethod-qualified-ok () + "Checkdoc should be happy with a `cl-defmethod' using qualifiers." + (with-temp-buffer + (emacs-lisp-mode) + (insert "(cl-defmethod test :around ((a (eql smthg))) \"Return A.\")") + (checkdoc-defun))) + +(ert-deftest checkdoc-cl-defmethod-with-extra-qualifier-ok () + "Checkdoc should be happy with a :extra qualified `cl-defmethod'." + (with-temp-buffer + (emacs-lisp-mode) + (insert "(cl-defmethod foo :extra \"foo\" ((a (eql smthg))) \"Return A.\")") + (checkdoc-defun)) + + (with-temp-buffer + (emacs-lisp-mode) + (insert + "(cl-defmethod foo :extra \"foo\" :after ((a (eql smthg))) \"Return A.\")") + (checkdoc-defun))) + +(ert-deftest checkdoc-cl-defmethod-with-extra-qualifier-and-nil-args-ok () + "Checkdoc should be happy with a 0-arity :extra qualified `cl-defmethod'." + (with-temp-buffer + (emacs-lisp-mode) + (insert "(cl-defmethod foo :extra \"foo\" () \"Return A.\")") + (checkdoc-defun))) + (ert-deftest checkdoc-cl-defun-with-key-ok () "Checkdoc should be happy with a cl-defun using &key." (with-temp-buffer -- cgit v1.2.3