[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
- [elpa] externals/relint eb178d5 06/21: Check assignments to imenu-generic-expression, (continued)
- [elpa] externals/relint eb178d5 06/21: Check assignments to imenu-generic-expression, Mattias Engdegård, 2020/05/03
- [elpa] externals/relint 2eba4d7 09/21: Describe new bol/eol/eos warnings, Mattias Engdegård, 2020/05/03
- [elpa] externals/relint cf2a2ae 14/21: Do file-specific checks on arguments to known functions, Mattias Engdegård, 2020/05/03
- [elpa] externals/relint f6d0fed 15/21: Describe the new file-specific warnings, Mattias Engdegård, 2020/05/03
- [elpa] externals/relint 1bf7f25 13/21: Check auto-mode-alist with file-specific checks, Mattias Engdegård, 2020/05/03
- [elpa] externals/relint 4fcc322 16/21: Delay call to file-relative-name until needed, Mattias Engdegård, 2020/05/03
- [elpa] externals/relint 326cfe2 11/21: Check calls to directory-files(-and-attributes), Mattias Engdegård, 2020/05/03
- [elpa] externals/relint 5d3f78d 19/21: Update xr messages ("repetition" changed to "option"), Mattias Engdegård, 2020/05/03
- [elpa] externals/relint a50ed0b 20/21: Don't escape printable chars in rx warnings, Mattias Engdegård, 2020/05/03
- [elpa] externals/relint cdd65ae 10/21: Add section about how relint works, Mattias Engdegård, 2020/05/03
- [elpa] externals/relint 636e172 12/21: Add filename-specific checks (unused so far),
Mattias Engdegård <=
- [elpa] externals/relint 008fad0 17/21: Repair relint-current-buffer after thunking file parameter, Mattias Engdegård, 2020/05/03
- [elpa] externals/relint 8f49686 18/21: Move file-specific checks to xr, Mattias Engdegård, 2020/05/03
- [elpa] externals/relint a001a05 21/21: Increment version to 1.16, Mattias Engdegård, 2020/05/03