[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/relint d6320f9 14/44: Detect functions with regexp argu
From: |
Mattias Engdegård |
Subject: |
[elpa] externals/relint d6320f9 14/44: Detect functions with regexp arguments |
Date: |
Tue, 26 Mar 2019 12:57:26 -0400 (EDT) |
branch: externals/relint
commit d6320f9227509b5d4e0de23fb7660d1e13f990d0
Author: Mattias Engdegård <address@hidden>
Commit: Mattias Engdegård <address@hidden>
Detect functions with regexp arguments
Spot functions with argument names like `regexp', and check corresponding
arguments in calls to them. Right now, this is only done in the same file,
and only if the definition precedes the call.
---
trawl.el | 48 +++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 47 insertions(+), 1 deletion(-)
diff --git a/trawl.el b/trawl.el
index e2d5501..4298210 100644
--- a/trawl.el
+++ b/trawl.el
@@ -148,6 +148,10 @@
;; checking direct uses of it.
(defvar trawl--checked-variables)
+;; Alist of functions taking regexp argument(s).
+;; The names map to a list of the regexp argument indices.
+(defvar trawl--regexp-functions)
+
;; Whether form is a safe expression to evaluate.
(defun trawl--safe-expr (form)
(cond
@@ -535,7 +539,48 @@
(trawl--check-font-lock-keywords font-lock-list origin
file pos (cons 4 path))
(trawl--check-list auto-mode-list origin file pos (cons 5 path))))
+ (`(,(or `defun `defmacro `defsubst)
+ ,name ,args . ,_)
+ ;; If any argument looks like a regexp, remember it so that it can be
+ ;; checked in calls.
+ (when (consp args)
+ (let ((indices nil)
+ (index 0))
+ (while args
+ (let ((arg (car args)))
+ (when (symbolp arg)
+ (cond
+ ((eq arg '&optional))
+ ((eq arg '&rest)
+ (setq args nil))
+ (t
+ (when (or (string-suffix-p "regexp" (symbol-name arg))
+ (string-suffix-p "regex" (symbol-name arg))
+ (eq arg 're)
+ (string-suffix-p "-re" (symbol-name arg)))
+ (push index indices))
+ (setq index (1+ index)))))
+ (setq args (cdr args))))
+ (when indices
+ (push (cons name (reverse indices)) trawl--regexp-functions)))))
)
+
+ ;; Check calls to remembered functions with regexp arguments.
+ (when (consp form)
+ (let ((indices (cdr (assq (car form) trawl--regexp-functions))))
+ (when indices
+ (let ((index 0)
+ (args (cdr form)))
+ (while (and indices args)
+ (when (= index (car indices))
+ (unless (and (symbolp (car args))
+ (memq (car args) trawl--checked-variables))
+ (trawl--check-re (car args) (format "call to %s" (car form))
+ file pos (cons (1+ index) path)))
+ (setq indices (cdr indices)))
+ (setq args (cdr args))
+ (setq index (1+ index)))))))
+
(let ((index 0))
(while (consp form)
(when (consp (car form))
@@ -563,7 +608,8 @@
(keep-going t)
(read-circle nil)
(trawl--variables nil)
- (trawl--checked-variables nil))
+ (trawl--checked-variables nil)
+ (trawl--regexp-functions nil))
(while keep-going
(setq pos (point))
; (trawl--report file (point) nil "reading")
- [elpa] externals/relint 3f8509a 13/44: Add more functions to check for regexp arguments, (continued)
- [elpa] externals/relint 3f8509a 13/44: Add more functions to check for regexp arguments, Mattias Engdegård, 2019/03/26
- [elpa] externals/relint f8878ca 16/44: Report rx errors in the result buffer, Mattias Engdegård, 2019/03/26
- [elpa] externals/relint 8e37762 18/44: Protect against improper lists in function calls, Mattias Engdegård, 2019/03/26
- [elpa] externals/relint 66522ca 12/44: Increment version to 1.1, Mattias Engdegård, 2019/03/26
- [elpa] externals/relint 683f31b 28/44: Increment version to 1.3, Mattias Engdegård, 2019/03/26
- [elpa] externals/relint ac5d0cf 25/44: Add more safe functions, Mattias Engdegård, 2019/03/26
- [elpa] externals/relint 02bf0ba 21/44: Use explicit list of pure functions, Mattias Engdegård, 2019/03/26
- [elpa] externals/relint 7d0e177 20/44: Rewrite the higher-order function handling, Mattias Engdegård, 2019/03/26
- [elpa] externals/relint be3979a 19/44: Check TRIM argument of `split-string' as well, Mattias Engdegård, 2019/03/26
- [elpa] externals/relint 5143edf 17/44: Fix indentation accidents, Mattias Engdegård, 2019/03/26
- [elpa] externals/relint d6320f9 14/44: Detect functions with regexp arguments,
Mattias Engdegård <=
- [elpa] externals/relint d19133e 09/44: Better variable name patterns, Mattias Engdegård, 2019/03/26
- [elpa] externals/relint d4d8f97 11/44: Eval mapcar and mapcan with partial-evaluated lists, Mattias Engdegård, 2019/03/26
- [elpa] externals/relint 34304b4 08/44: Add (provides) line to make file importable, Mattias Engdegård, 2019/03/26
- [elpa] externals/relint 62ca3d4 05/44: Slight performance improvement, Mattias Engdegård, 2019/03/26
- [elpa] externals/relint 6ab713e 07/44: Reinstate erroneously removed line, Mattias Engdegård, 2019/03/26
- [elpa] externals/relint cb1fdc5 06/44: Add caret pointing out the error in the quoted regexp, Mattias Engdegård, 2019/03/26
- [elpa] externals/relint b4fc385 04/44: Rename trawl--batch to trawl-batch, Mattias Engdegård, 2019/03/26
- [elpa] externals/relint 0214845 01/44: Move to github, Mattias Engdegård, 2019/03/26
- [elpa] externals/relint 830f4bf 03/44: Allow use from batch mode, Mattias Engdegård, 2019/03/26
- [elpa] externals/relint 125b869 02/44: Try harder recovering from read errors, Mattias Engdegård, 2019/03/26