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

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

[elpa] externals/relint 636e172 12/21: Add filename-specific checks (unu


From: Mattias Engdegård
Subject: [elpa] externals/relint 636e172 12/21: Add filename-specific checks (unused so far)
Date: Sun, 3 May 2020 11:13:37 -0400 (EDT)

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

    Add filename-specific checks (unused so far)
    
    This includes checks for ^ and $ (use \` and \' instead),
    and for . (should probably be \.)
---
 relint.el | 44 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 44 insertions(+)

diff --git a/relint.el b/relint.el
index 6c81221..89c2461 100644
--- a/relint.el
+++ b/relint.el
@@ -1171,6 +1171,50 @@ or in the car of an element."
         file pos (if literal (cons 1 elem-path) elem-path))))
    form path))
 
+(defun relint--extra-file-name-re-checks (string file pos path)
+  "Perform extra checks on STRING assuming it matches file names."
+
+  ;; It would be much easier to do these checks (and more) on the rx
+  ;; representation, but unfortunately xr doesn't return a
+  ;; location-annotated expression right now.
+  (let ((len (length string))
+        (start 0))
+    (while (and (< start len)
+                ;; Skip anything that is NOT one of . ^ $
+                (string-match (rx (* (or (not (any "\\.$^["))
+                                         (seq "\\" anything)
+                                         (seq "[" (opt "^") (opt "]")
+                                              (* (not (any "]")))
+                                              "]"))))
+                              string start))
+      (setq start (match-end 0))
+      (let* ((m (string-match (rx (or "^" "$" (seq "." (opt (any "*+?")))))
+                              string start))
+             (end (match-end 0)))
+        (when (and m (= m start))
+          (pcase (match-string 0 string)
+            ("^" (relint--warn
+                  file pos path
+                  "Use \\` instead of ^ in file-matching regexp"
+                  string start))
+            ("$" (relint--warn
+                  file pos path
+                  "Use \\' instead of $ in file-matching regexp"
+                  string start))
+            ;; We assume that .* etc are intended.
+            ("." (relint--warn
+                  file pos path
+                  (format-message
+                   "Possibly unescaped `.' in file-matching regexp")
+                  string start)))
+          (setq start end))))))
+
+(defun relint--check-file-name-re (form name file pos path)
+  (let ((re (relint--get-string form)))
+    (when re
+      (relint--check-re re name file pos path)
+      (relint--extra-file-name-re-checks re file pos path))))
+
 (defun relint--check-rules-list (form name file pos path)
   "Check a variable on `align-mode-rules-list' format"
   (relint--eval-list-iter



reply via email to

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