emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/relint 963e232 02/10: Check more defcustom strings


From: Mattias Engdegård
Subject: [elpa] externals/relint 963e232 02/10: Check more defcustom strings
Date: Sun, 4 Aug 2019 13:42:47 -0400 (EDT)

branch: externals/relint
commit 963e232b977fa2651f4dfe444b8c971f9d77289d
Author: Mattias Engdegård <address@hidden>
Commit: Mattias Engdegård <address@hidden>

    Check more defcustom strings
    
    Use :type to find more defcustoms to check, and also check values in
    certain types, like (choice (const "regexp1") (const "regexp2")).
---
 relint.el | 120 ++++++++++++++++++++++++++++++++++++++++----------------------
 1 file changed, 78 insertions(+), 42 deletions(-)

diff --git a/relint.el b/relint.el
index 308c0be..d2d85d7 100644
--- a/relint.el
+++ b/relint.el
@@ -919,6 +919,31 @@ character alternative: `[' followed by a regexp-generating 
expression."
          (setq form (cdr form))
          (setq index (1+ index)))))))
 
+(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 'choice 'radio) . ,choices)
+     (dolist (choice choices)
+       (relint--check-defcustom-type choice name file pos path)))))
+
+(defun relint--check-defcustom-re (form name file pos path)
+  (let ((args (nthcdr 4 form))
+        (index 5))
+    (while (consp args)
+      (pcase args
+        (`(:type ,type)
+         (relint--check-defcustom-type (relint--eval-or-nil type)
+                                       name file pos (cons index path)))
+        (`(:options ,options)
+         (relint--check-list options name file pos (cons index path))))
+      (setq index (+ index 2))
+      (setq args (cddr args)))))
+
 (defun relint--check-form-recursively-2 (form file pos path)
   (pcase form
     (`(,(or `looking-at `re-search-forward `re-search-backward
@@ -976,48 +1001,59 @@ character alternative: `[' followed by a 
regexp-generating expression."
          (relint--check-format-mixup template args file pos path))))
     (`(,(or `defvar `defconst `defcustom)
        ,name ,re-arg . ,rest)
-     (when (symbolp name)
-       (cond
-        ((string-match-p (rx (or "-regexp" "-re" "-regex" "-pattern") eos)
-                         (symbol-name name))
-         (relint--check-re re-arg name file pos (cons 2 path))
-         (push name relint--checked-variables))
-        ((string-match-p (rx (or (or "-regexps" "-regexes")
-                                 (seq (or "-regexp" "-re" "-regex")
-                                      "-list"))
-                             eos)
-                         (symbol-name name))
-         (relint--check-list re-arg name file pos (cons 2 path))
-         (push name relint--checked-variables))
-        ((string-match-p (rx "-font-lock-keywords" eos)
-                         (symbol-name name))
-         (relint--check-font-lock-keywords re-arg name file pos (cons 2 path))
-         (push name relint--checked-variables))
-        ((eq name 'compilation-error-regexp-alist-alist)
-         (relint--check-compilation-error-regexp-alist-alist
-          re-arg name file pos (cons 2 path))
-         (push name relint--checked-variables))
-        ((string-match-p (rx (or "-regexp" "-re" "-regex" "-pattern")
-                             "-alist" eos)
-                         (symbol-name name))
-         (relint--check-list-any re-arg name file pos (cons 2 path))
-         (push name relint--checked-variables))
-        ((string-match-p (rx "-mode-alist" eos)
-                         (symbol-name name))
-         (relint--check-list-any re-arg name file pos (cons 2 path))
-         (push name relint--checked-variables))
-        ((string-match-p (rx "-rules-list" eos)
-                         (symbol-name name))
-         (relint--check-rules-list re-arg name file pos (cons 2 path))
-         (push name relint--checked-variables))
-        ;; Doc string starting with "regexp"?
-        ((and (stringp (car rest))
-              (let ((case-fold-search t))
-                (string-match-p (rx bos "regexp") (car rest))))
-         (relint--check-re re-arg name file pos (cons 2 path))
-         (push name relint--checked-variables))
-        )
-       (push (cons name re-arg) relint--variables)))
+     (let ((type (and (eq (car form) 'defcustom)
+                          (relint--eval-or-nil (plist-get (cdr rest) :type)))))
+       (when (symbolp name)
+         (cond
+          ((or (eq type 'regexp)
+               (string-match-p (rx (or "-regexp" "-re" "-regex" "-pattern") 
eos)
+                               (symbol-name name)))
+           (relint--check-re re-arg name file pos (cons 2 path))
+           (when (eq (car form) 'defcustom)
+             (relint--check-defcustom-re form name file pos path))
+           (push name relint--checked-variables))
+          ((or (equal type '(repeat regexp))
+               (string-match-p (rx (or (or "-regexps" "-regexes")
+                                       (seq (or "-regexp" "-re" "-regex")
+                                            "-list"))
+                                   eos)
+                               (symbol-name name)))
+           (relint--check-list re-arg name file pos (cons 2 path))
+           (push name relint--checked-variables))
+          ((string-match-p (rx "-font-lock-keywords" eos)
+                           (symbol-name name))
+           (relint--check-font-lock-keywords re-arg name file pos (cons 2 
path))
+           (push name relint--checked-variables))
+          ((eq name 'compilation-error-regexp-alist-alist)
+           (relint--check-compilation-error-regexp-alist-alist
+            re-arg name file pos (cons 2 path))
+           (push name relint--checked-variables))
+          ((or (and (consp type)
+                    (eq (car type) 'alist)
+                    (eq (plist-get (cdr type) :key-type) 'regexp))
+               (string-match-p (rx (or "-regexp" "-re" "-regex" "-pattern")
+                                   "-alist" eos)
+                               (symbol-name name)))
+           (relint--check-list-any re-arg name file pos (cons 2 path))
+           (push name relint--checked-variables))
+          ((string-match-p (rx "-mode-alist" eos)
+                           (symbol-name name))
+           (relint--check-list-any re-arg name file pos (cons 2 path))
+           (push name relint--checked-variables))
+          ((string-match-p (rx "-rules-list" eos)
+                           (symbol-name name))
+           (relint--check-rules-list re-arg name file pos (cons 2 path))
+           (push name relint--checked-variables))
+          ;; Doc string starting with "regexp"?
+          ((and (stringp (car rest))
+                (let ((case-fold-search t))
+                  (string-match-p (rx bos "regexp") (car rest))))
+           (relint--check-re re-arg name file pos (cons 2 path))
+           (when (eq (car form) 'defcustom)
+             (relint--check-defcustom-re form name file pos path))
+           (push name relint--checked-variables))
+          )
+         (push (cons name re-arg) relint--variables))))
     (`(define-generic-mode ,name ,_ ,_ ,font-lock-list ,auto-mode-list . ,_)
      (let ((origin (format "define-generic-mode %s" name)))
        (relint--check-font-lock-keywords font-lock-list origin



reply via email to

[Prev in Thread] Current Thread [Next in Thread]