branch: externals/relint
commit cf2a2ae075f132aab97a32fc4d0c8921068217bb
Author: Mattias Engdegård <matti...@acm.org>
Commit: Mattias Engdegård <matti...@acm.org>

    Do file-specific checks on arguments to known functions
    
    This includes directory-files, directory-files-and-attributes,
    directory-files-recursively, load-history-filename-element,
    and modify-coding-system-alist (with type = file).
---
 relint.el        | 20 +++++++++++++++-----
 test/12.elisp    |  9 +++++++++
 test/12.expected | 15 +++++++++++++++
 3 files changed, 39 insertions(+), 5 deletions(-)

diff --git a/relint.el b/relint.el
index 03a9421..1adcaee 100644
--- a/relint.el
+++ b/relint.el
@@ -1887,7 +1887,6 @@ directly."
                'posix-looking-at 'posix-search-backward 'posix-search-forward
                'posix-string-match
                'search-forward-regexp 'search-backward-regexp
-               'load-history-filename-element
                'kill-matching-buffers
                'keep-lines 'flush-lines 'how-many)
           ,re-arg . ,_)
@@ -1895,9 +1894,14 @@ directly."
                      (memq re-arg relint--checked-variables))
           (relint--check-re re-arg (format "call to %s" (car form))
                             file pos (cons 1 path))))
+       (`(load-history-filename-element ,re-arg)
+        (relint--check-file-name-re re-arg (format "call to %s" (car form))
+                                    file pos (cons 1 path)))
+       (`(directory-files-recursively ,_ ,re-arg . ,_)
+        (relint--check-file-name-re re-arg (format "call to %s" (car form))
+                                    file pos (cons 2 path)))
        (`(,(or 'split-string 'split-string-and-unquote
-               'string-trim-left 'string-trim-right 'string-trim
-               'directory-files-recursively)
+               'string-trim-left 'string-trim-right 'string-trim)
           ,_ ,re-arg . ,rest)
         (unless (and (symbolp re-arg)
                      (memq re-arg relint--checked-variables))
@@ -1921,8 +1925,8 @@ directly."
                                 file pos (cons 4 path))))))
        (`(,(or 'directory-files 'directory-files-and-attributes)
           ,_ ,_ ,re-arg . ,_)
-        (relint--check-re re-arg (format "call to %s" (car form))
-                          file pos (cons 3 path)))
+        (relint--check-file-name-re re-arg (format "call to %s" (car form))
+                                    file pos (cons 3 path)))
        (`(,(or 'skip-chars-forward 'skip-chars-backward)
           ,skip-arg . ,_)
         (let ((str (relint--get-string skip-arg)))
@@ -2078,6 +2082,12 @@ directly."
        (`(add-to-list 'auto-mode-alist ,elem . ,_)
         (relint--check-auto-mode-alist-expr
          elem (car form) file pos (cons 2 path)))
+       (`(modify-coding-system-alist ,type ,re-arg ,_)
+        (funcall
+         (if (eq (relint--eval-or-nil type) 'file)
+             #'relint--check-file-name-re
+           #'relint--check-re)
+         re-arg (format "call to %s" (car form)) file pos (cons 2 path)))
        (`(,name . ,args)
         (let ((alias (assq name relint--alias-defs)))
           (when alias
diff --git a/test/12.elisp b/test/12.elisp
index ea04551..04ea09c 100644
--- a/test/12.elisp
+++ b/test/12.elisp
@@ -14,3 +14,12 @@
 (setq auto-mode-alist (append '((".hh\\'" . some-mode)
                                 (".ii\\'" . some-mode))
                               auto-mode-alist))
+
+;; File-matching regexp functions
+
+(defun f12 (d)
+  (directory-files d nil ".txt\\'")
+  (directory-files-and-attributes d nil "\\.pas$")
+  (directory-files-recursively d "^abc")
+  (modify-coding-system-alist 'file "\\.ml$" 'utf-8)
+  (modify-coding-system-alist 'process "+xx$" 'utf-8))
diff --git a/test/12.expected b/test/12.expected
index 6abea93..ecef078 100644
--- a/test/12.expected
+++ b/test/12.expected
@@ -22,3 +22,18 @@
 12.elisp:15:35: Possibly unescaped `.' in file-matching regexp (pos 0)
   ".ii\\'"
    ^
+12.elisp:21:27: Possibly unescaped `.' in file-matching regexp (pos 0)
+  ".txt\\'"
+   ^
+12.elisp:22:48: Use \' instead of $ in file-matching regexp (pos 5)
+  "\\.pas$"
+   ......^
+12.elisp:23:35: Use \` instead of ^ in file-matching regexp (pos 0)
+  "^abc"
+   ^
+12.elisp:24:43: Use \' instead of $ in file-matching regexp (pos 4)
+  "\\.ml$"
+   .....^
+12.elisp:25:41: In call to modify-coding-system-alist: Unescaped literal `+' 
(pos 0)
+  "+xx$"
+   ^

Reply via email to