[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/relint cbde6e35c7 4/6: Add check for duplicates in rx o
From: |
Mattias Engdegård |
Subject: |
[elpa] externals/relint cbde6e35c7 4/6: Add check for duplicates in rx or-forms |
Date: |
Mon, 23 Jan 2023 08:30:08 -0500 (EST) |
branch: externals/relint
commit cbde6e35c777ce9e1fe5ace93d3d4374c867d2fd
Author: Mattias Engdegård <mattiase@acm.org>
Commit: Mattias Engdegård <mattiase@acm.org>
Add check for duplicates in rx or-forms
Since rx may run `regexp-opt` on strings in an or-pattern and that
function implicitly deduplicates the set of strings, we would
otherwise not know about the duplication.
---
relint.el | 17 +++++++++++++++++
test/11.elisp | 3 +++
test/11.expected | 4 ++++
3 files changed, 24 insertions(+)
diff --git a/relint.el b/relint.el
index 753a6e2c32..2b293cff99 100644
--- a/relint.el
+++ b/relint.el
@@ -1470,6 +1470,23 @@ than just to a surrounding or producing expression."
'group 'submatch
'group-n 'submatch-n)
. ,args)
+ (when (memq (car item) '(| or))
+ ;; Check or-patterns for duplicates, because if rx runs `regexp-opt'
+ ;; on them then they are effectively deduplicated and we'd never
+ ;; know about it.
+ (let ((i 1)
+ (tail args))
+ (while (consp tail)
+ (when (member (car tail) (cdr tail))
+ (relint--warn pos (if exact-path (cons i path) path)
+ (format-message
+ "Duplicated rx form in or-pattern: %s"
+ (replace-regexp-in-string
+ (rx (+ (in " \n"))) " "
+ (string-trim (xr-pp-rx-to-str (car tail)))
+ t t))))
+ (setq i (1+ i))
+ (setq tail (cdr tail)))))
;; Form with subforms: recurse.
(let ((i 1))
(dolist (arg args)
diff --git a/test/11.elisp b/test/11.elisp
index d629a5639a..3f4527b23a 100644
--- a/test/11.elisp
+++ b/test/11.elisp
@@ -31,4 +31,7 @@
(rx (any "a-z" ?m))
(rx (any "a-f" "\000-\377"))
(rx (any "\240-\277" "\000-\377"))
+
+ (rx (or "abc" ?A "def" "ghi" ?A "def"))
+ (rx (| "abc" (= 3 ?*) "def" (= 3 ?*) "ghi" "abc"))
)
diff --git a/test/11.expected b/test/11.expected
index 2c0eb6b5b1..9b8c9b1b19 100644
--- a/test/11.expected
+++ b/test/11.expected
@@ -59,3 +59,7 @@
11.elisp:33:25: Range `\000-\377' overlaps previous `\240-\277' (pos 0)
"\000-\377"
^
+11.elisp:35:17: Duplicated rx form in or-pattern: ?A
+11.elisp:35:20: Duplicated rx form in or-pattern: "def"
+11.elisp:36:10: Duplicated rx form in or-pattern: "abc"
+11.elisp:36:16: Duplicated rx form in or-pattern: (= 3 ?*)
- [elpa] externals/relint updated (d29dd3757f -> f3da21d174), Mattias Engdegård, 2023/01/23
- [elpa] externals/relint f3da21d174 6/6: Increment version to 1.21, Mattias Engdegård, 2023/01/23
- [elpa] externals/relint dce0a4488e 2/6: Update copyright year to 2023, Mattias Engdegård, 2023/01/23
- [elpa] externals/relint 99f24863d1 5/6: Require subr-x for string-trim in older Emacs versions, Mattias Engdegård, 2023/01/23
- [elpa] externals/relint acf8c7101d 3/6: Correct constant evaluation of alist-get, Mattias Engdegård, 2023/01/23
- [elpa] externals/relint fe1c11d733 1/6: Fix source position computation in certain dotted lists, Mattias Engdegård, 2023/01/23
- [elpa] externals/relint cbde6e35c7 4/6: Add check for duplicates in rx or-forms,
Mattias Engdegård <=