branch: externals/relint commit 8f49686f268dc10e1074f1c344084e3f2bafc7ee Author: Mattias Engdegård <matti...@acm.org> Commit: Mattias Engdegård <matti...@acm.org>
Move file-specific checks to xr --- relint.el | 48 ++++++------------------------------------------ test/12.expected | 24 ++++++++++++------------ 2 files changed, 18 insertions(+), 54 deletions(-) diff --git a/relint.el b/relint.el index ba10355..b775b8a 100644 --- a/relint.el +++ b/relint.el @@ -320,6 +320,9 @@ or nil if no position could be determined." (defun relint--check-re-string (re name file pos path) (relint--check-string re #'xr-lint name file pos path)) +(defun relint--check-file-re-string (re name file pos path) + (relint--check-string re (lambda (x) (xr-lint x 'file)) name file pos path)) + (defun relint--check-syntax-string (syntax name file pos path) (relint--check-string syntax #'relint--syntax-string-lint name file pos path)) @@ -1176,59 +1179,20 @@ 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)))) + (relint--check-file-re-string re name file pos path)))) (defun relint--check-auto-mode-alist-expr (form name file pos path) "Check a single element added to `auto-mode-alist'." (pcase form (`(quote (,(and (pred stringp) str) . ,_)) - (relint--check-file-name-re str name file pos (cons 0 (cons 1 path)))) + (relint--check-file-re-string str name file pos (cons 0 (cons 1 path)))) (_ (let ((val (relint--eval-or-nil form))) (when (and (consp val) (stringp (car val))) - (relint--check-file-name-re (car val) name file pos path)))))) + (relint--check-file-re-string (car val) name file pos path)))))) (defun relint--check-auto-mode-alist (form name file pos path) (relint--eval-list-iter diff --git a/test/12.expected b/test/12.expected index ecef078..e0ab05b 100644 --- a/test/12.expected +++ b/test/12.expected @@ -1,37 +1,37 @@ -12.elisp:9:6: Possibly unescaped `.' in file-matching regexp (pos 0) +12.elisp:9:6: In define-generic-mode my-mode: Possibly unescaped `.' in file-matching regexp (pos 0) ".aa\\'" ^ -12.elisp:9:20: Use \' instead of $ in file-matching regexp (pos 4) +12.elisp:9:20: In define-generic-mode my-mode: Use \' instead of $ in file-matching regexp (pos 4) "\\.bb$" .....^ -12.elisp:9:24: Use \` instead of ^ in file-matching regexp (pos 0) +12.elisp:9:24: In define-generic-mode my-mode: Use \` instead of ^ in file-matching regexp (pos 0) "^cc.*dd" ^ -12.elisp:11:39: Use \' instead of $ in file-matching regexp (pos 4) +12.elisp:11:39: In add-to-list: Use \' instead of $ in file-matching regexp (pos 4) "\\.ee$" .....^ -12.elisp:12:10: Possibly unescaped `.' in file-matching regexp (pos 0) +12.elisp:12:10: In auto-mode-alist: Possibly unescaped `.' in file-matching regexp (pos 0) ".ff\\'" ^ -12.elisp:13:32: Possibly unescaped `.' in file-matching regexp (pos 0) +12.elisp:13:32: In auto-mode-alist: Possibly unescaped `.' in file-matching regexp (pos 0) ".gg\\'" ^ -12.elisp:14:35: Possibly unescaped `.' in file-matching regexp (pos 0) +12.elisp:14:35: In auto-mode-alist: Possibly unescaped `.' in file-matching regexp (pos 0) ".hh\\'" ^ -12.elisp:15:35: Possibly unescaped `.' in file-matching regexp (pos 0) +12.elisp:15:35: In auto-mode-alist: Possibly unescaped `.' in file-matching regexp (pos 0) ".ii\\'" ^ -12.elisp:21:27: Possibly unescaped `.' in file-matching regexp (pos 0) +12.elisp:21:27: In call to directory-files: Possibly unescaped `.' in file-matching regexp (pos 0) ".txt\\'" ^ -12.elisp:22:48: Use \' instead of $ in file-matching regexp (pos 5) +12.elisp:22:48: In call to directory-files-and-attributes: Use \' instead of $ in file-matching regexp (pos 5) "\\.pas$" ......^ -12.elisp:23:35: Use \` instead of ^ in file-matching regexp (pos 0) +12.elisp:23:35: In call to directory-files-recursively: Use \` instead of ^ in file-matching regexp (pos 0) "^abc" ^ -12.elisp:24:43: Use \' instead of $ in file-matching regexp (pos 4) +12.elisp:24:43: In call to modify-coding-system-alist: 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)