[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/xr 658f469058 3/7: Add check for erroneous escape seque
From: |
ELPA Syncer |
Subject: |
[elpa] externals/xr 658f469058 3/7: Add check for erroneous escape sequences in character alternatives |
Date: |
Tue, 1 Aug 2023 09:59:28 -0400 (EDT) |
branch: externals/xr
commit 658f4690584ecda813c2ee5c03c0ba25f9a93a53
Author: Mattias EngdegÄrd <mattiase@acm.org>
Commit: Mattias EngdegÄrd <mattiase@acm.org>
Add check for erroneous escape sequences in character alternatives
This detects patterns like "[ \\t]" and "[\\d.]" that may be a
mistaken use of escape sequences where none is allowed, or too
many backslashes. Only enabled for checks = `all`.
---
README | 11 +++++++++++
xr-test.el | 8 ++++++++
xr.el | 13 +++++++++++++
3 files changed, 32 insertions(+)
diff --git a/README b/README
index 314a161ffe..07b3d76516 100644
--- a/README
+++ b/README
@@ -127,6 +127,17 @@ The xr package can be used interactively or by other code
as a library.
+ and -.
This check is only enable when CHECKS=all.
+ - Possibly erroneous '\X' in character alternative
+
+ A character alternative includes something that looks like a
+ escape sequence, but no escape sequences are allowed there since
+ backslash is not a special character in that context.
+ It could also be a caused by too many backslashes.
+
+ For example, "[\\n\\t]" matches the characters 'n', 't' and
+ backslash, but could be an attempt to match newline and tab.
+ This check is only enable when CHECKS=all.
+
- Duplicated character class '[:class:]'
A character class occurs twice in a single character alternative
diff --git a/xr-test.el b/xr-test.el
index 7eccd8dd80..4e8d1fadfc 100644
--- a/xr-test.el
+++ b/xr-test.el
@@ -488,6 +488,14 @@
'((4 . "Suspect character range `+-/': should `-' be literal?")
(10 . "Suspect character range `&-+': should `-' be literal?"))
nil)))
+
+ (should
+ (equal
+ (xr-lint "[ \\t][-.\\d][\\Sw][\\rnt]" nil checks)
+ (if (eq checks 'all)
+ '((2 . "Possibly erroneous `\\t' in character alternative")
+ (8 . "Possibly erroneous `\\d' in character alternative")
+ (12 . "Possibly erroneous `\\S' in character alternative")))))
))))
(ert-deftest xr-lint-repetition-of-empty ()
diff --git a/xr.el b/xr.el
index e8ba75582c..f81a4d9e5e 100644
--- a/xr.el
+++ b/xr.el
@@ -204,6 +204,19 @@
warnings (point)
(format-message
"Literal `-' not first or last in character alternative")))
+ (when (eq checks 'all)
+ (let ((last (car-safe intervals)))
+ (when (and last
+ (eq (aref last 1) ?\\)
+ (or (memq ch '( ?t ?n ?r ?f ?x ?e ?b ; char escapes
+ ?s ?S ?d ?D ?w ?W)) ; PCRE sequences
+ (and (<= ?0 ch ?7))) ; octal escapes
+ ;; Suppress some common false positives, eg [\\nrt]
+ (not (looking-at-p (rx (= 2 (in "tnrfeb"))))))
+ (xr--report
+ warnings (- (point) 1)
+ (format-message
+ "Possibly erroneous `\\%c' in character alternative" ch)))))
(push (vector ch ch (point)) intervals)
(forward-char))))
- [elpa] externals/xr updated (4a1b867438 -> 2d7bedc104), ELPA Syncer, 2023/08/01
- [elpa] externals/xr 8bdec5e753 1/7: Add `checks` arguments to xr-lint and propagate it, ELPA Syncer, 2023/08/01
- [elpa] externals/xr eb4dd40a92 5/7: Add check for or-pattern that could be character alternatives, ELPA Syncer, 2023/08/01
- [elpa] externals/xr d1131ce501 2/7: Add check for [+-X] and [X-+], ELPA Syncer, 2023/08/01
- [elpa] externals/xr 2d7bedc104 7/7: Increment version to 1.24, ELPA Syncer, 2023/08/01
- [elpa] externals/xr 658f469058 3/7: Add check for erroneous escape sequences in character alternatives,
ELPA Syncer <=
- [elpa] externals/xr 054824b57b 4/7: Add check for \(:? as a typo for \(?: (#6), ELPA Syncer, 2023/08/01
- [elpa] externals/xr 699521793d 6/7: Add check for repetition of effective repetition, ELPA Syncer, 2023/08/01