branch: externals/relint commit 9259a5c5e82f75aa4efd20746c6d0887acd64e0f Author: Mattias Engdegård <matti...@acm.org> Commit: Mattias Engdegård <matti...@acm.org>
Check some :value parameters in defcustom :type clauses For example, this catches :type '(string :value "some bad regexp") --- relint.el | 13 +++++++------ test/1.elisp | 13 +++++++++++++ test/1.expected | 30 +++++++++++++++++++++--------- 3 files changed, 41 insertions(+), 15 deletions(-) diff --git a/relint.el b/relint.el index bc4a9af..d484116 100644 --- a/relint.el +++ b/relint.el @@ -1551,12 +1551,13 @@ RANGES is a list of (X . Y) representing the interval [X,Y]." (defun relint--check-defcustom-type (type name file pos path) (pcase type - (`(const . ,rest) - ;; Skip keywords. - (while (and rest (symbolp (car rest))) - (setq rest (cddr rest))) - (when rest - (relint--check-re (car rest) name file pos path))) + (`(,(or 'const 'string 'regexp) . ,rest) + (while (consp rest) + (cond ((eq (car rest) :value) + (relint--check-re (cadr rest) name file pos path)) + ((not (cdr rest)) + (relint--check-re (car rest) name file pos path))) + (setq rest (cddr rest)))) (`(,(or 'choice 'radio) . ,choices) (dolist (choice choices) (relint--check-defcustom-type choice name file pos path))))) diff --git a/test/1.elisp b/test/1.elisp index 865d21a..c00681a 100644 --- a/test/1.elisp +++ b/test/1.elisp @@ -75,6 +75,19 @@ :group 'relint-test :type '(repeat regexp)) +(defcustom bad-custom-8 nil + "Doc" + :type '(choice (regexp :tag "*" :value "[11]") + (string :tag "+" :value "[22]"))) + +(defcustom bad-custom-9-regexp nil + "Doc" + :type '(string :tag "+" :value "[33]")) + +(defcustom bad-custom-10 nil + "regular expression" + :type '(string :tag "+" "[44]")) + ;; Special case. (defvar compilation-error-regexp-alist-alist '((aa "a^a" 1 2) diff --git a/test/1.expected b/test/1.expected index 8d1e997..4014a72 100644 --- a/test/1.expected +++ b/test/1.expected @@ -138,30 +138,42 @@ 1.elisp:73:35: In bad-custom-7: Duplicated `a' inside character alternative (pos 2) "[aa]" ..^ -1.elisp:80:11: In compilation-error-regexp-alist-alist (aa): Unescaped literal `^' (pos 1) +1.elisp:80:9: In bad-custom-8: Duplicated `1' inside character alternative (pos 2) + "[11]" + ..^ +1.elisp:80:9: In bad-custom-8: Duplicated `2' inside character alternative (pos 2) + "[22]" + ..^ +1.elisp:85:9: In bad-custom-9-regexp: Duplicated `3' inside character alternative (pos 2) + "[33]" + ..^ +1.elisp:89:9: In bad-custom-10: Duplicated `4' inside character alternative (pos 2) + "[44]" + ..^ +1.elisp:93:11: In compilation-error-regexp-alist-alist (aa): Unescaped literal `^' (pos 1) "a^a" .^ -1.elisp:81:11: In compilation-error-regexp-alist-alist (bb): Unescaped literal `$' (pos 1) +1.elisp:94:11: In compilation-error-regexp-alist-alist (bb): Unescaped literal `$' (pos 1) "b$b" .^ -1.elisp:86:8: In define-generic-mode my-mode: Unescaped literal `^' (pos 1) +1.elisp:99:8: In define-generic-mode my-mode: Unescaped literal `^' (pos 1) "1^" .^ -1.elisp:87:8: In define-generic-mode my-mode: Unescaped literal `^' (pos 1) +1.elisp:100:8: In define-generic-mode my-mode: Unescaped literal `^' (pos 1) "2^" .^ -1.elisp:88:12: In define-generic-mode my-mode: Repetition of repetition (pos 2) +1.elisp:101:12: In define-generic-mode my-mode: Repetition of repetition (pos 2) "b++" ..^ -1.elisp:94:6: In call to syntax-propertize-rules: Unescaped literal `$' (pos 0) +1.elisp:107:6: In call to syntax-propertize-rules: Unescaped literal `$' (pos 0) "$1$" ^ -1.elisp:95:8: In call to syntax-propertize-rules: Unescaped literal `^' (pos 2) +1.elisp:108:8: In call to syntax-propertize-rules: Unescaped literal `^' (pos 2) "^2^" ..^ -1.elisp:100:6: In call to syntax-propertize-precompile-rules: Unescaped literal `$' (pos 0) +1.elisp:113:6: In call to syntax-propertize-precompile-rules: Unescaped literal `$' (pos 0) "$3$" ^ -1.elisp:101:8: In call to syntax-propertize-precompile-rules: Unescaped literal `^' (pos 2) +1.elisp:114:8: In call to syntax-propertize-precompile-rules: Unescaped literal `^' (pos 2) "^4^" ..^