[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/relint 1741e2c 09/15: Locate error position in 'concat'
From: |
Mattias Engdegård |
Subject: |
[elpa] externals/relint 1741e2c 09/15: Locate error position in 'concat' forms |
Date: |
Sat, 29 Feb 2020 17:22:29 -0500 (EST) |
branch: externals/relint
commit 1741e2cb6d95773c18d4474844a3e93c3b460472
Author: Mattias Engdegård <address@hidden>
Commit: Mattias Engdegård <address@hidden>
Locate error position in 'concat' forms
This only works if the string position and everything up to it are in
string literals.
---
relint-test.el | 11 ++++++++---
relint.el | 24 +++++++++++++++++++++---
test/3.expected | 4 ++--
test/4.expected | 2 +-
4 files changed, 32 insertions(+), 9 deletions(-)
diff --git a/relint-test.el b/relint-test.el
index 178fa7d..9b835b1 100644
--- a/relint-test.el
+++ b/relint-test.el
@@ -125,14 +125,19 @@ and a path."
(eval `(relint-test--deftest ,base))))
(ert-deftest relint-buffer ()
- (let ((buf (get-buffer-create " *relint-test*")))
+ (let ((buf (get-buffer-create " *relint-test*"))
+ (text-quoting-style 'grave))
(unwind-protect
(progn
(with-current-buffer buf
(emacs-lisp-mode)
- (insert ";hello\n(looking-at \"broken**regexp\")\n"))
+ (insert ";hello\n(looking-at \"broken**regexp\")\n")
+ (insert "(looking-at (concat \"ab\" \"cdef\" \"[gg]\"))\n"))
(should (equal
(relint-buffer buf)
'(("In call to looking-at: Repetition of repetition" 28
- "broken**regexp" 7)))))
+ "broken**regexp" 7)
+ ("In call to looking-at: Duplicated `g' inside character
alternative"
+ 73
+ "abcdef[gg]" 8)))))
(kill-buffer buf))))
diff --git a/relint.el b/relint.el
index 7e2fb15..fa0d043 100644
--- a/relint.el
+++ b/relint.el
@@ -203,6 +203,25 @@ list indices to follow to target)."
(goto-char (match-end 0)))
(point)))
+(defun relint--string-pos (pos n)
+ "Position of character N in a string expression at POS,
+or nil if no position could be determined."
+ (save-excursion
+ (goto-char pos)
+ (pcase (read (current-buffer))
+ ((pred stringp) (relint--literal-string-pos pos n))
+ (`(concat . ,args)
+ ;; Find out in which argument the sought position is.
+ (let ((index 1))
+ (while (and args (stringp (car args)) (>= n (length (car args))))
+ (setq n (- n (length (car args))))
+ (setq index (1+ index))
+ (setq args (cdr args)))
+ (and args (stringp (car args))
+ (let ((string-pos
+ (relint--pos-from-toplevel-pos-path pos (list index))))
+ (relint--literal-string-pos string-pos n))))))))
+
(defun relint--suppression (pos message)
"Whether there is a suppression for MESSAGE at POS."
(save-excursion
@@ -256,9 +275,8 @@ list indices to follow to target)."
(defun relint--report (file toplevel-pos path message &optional str str-pos)
(let* ((base-pos (relint--pos-from-toplevel-pos-path toplevel-pos path))
- (pos (if (eq (char-after base-pos) ?\")
- (relint--literal-string-pos base-pos str-pos)
- base-pos)))
+ (pos (or (relint--string-pos base-pos str-pos)
+ base-pos)))
(if (relint--suppression pos message)
(setq relint--suppression-count (1+ relint--suppression-count))
(funcall relint--report-function file pos message str str-pos)))
diff --git a/test/3.expected b/test/3.expected
index a72d52f..a04ba03 100644
--- a/test/3.expected
+++ b/test/3.expected
@@ -34,10 +34,10 @@
3.elisp:130:3: In another-bad-regexp-list: Duplicated `7' inside character
alternative (pos 2)
"[77]"
..^
-3.elisp:141:4: In call to looking-at: Unescaped literal `+' (pos 0)
+3.elisp:141:13: In call to looking-at: Unescaped literal `+' (pos 0)
"+abcdefgh"
^
-3.elisp:157:4: In call to looking-at: Unescaped literal `?' (pos 0)
+3.elisp:157:13: In call to looking-at: Unescaped literal `?' (pos 0)
"?abc"
^
3.elisp:164:4: In call to looking-at: Duplicated `A' inside character
alternative (pos 2)
diff --git a/test/4.expected b/test/4.expected
index fc3ca31..9d5488c 100644
--- a/test/4.expected
+++ b/test/4.expected
@@ -28,7 +28,7 @@
4.elisp:25:15: In call to looking-at: Unescaped literal `*' (pos 0)
"*ab"
^
-4.elisp:26:15: In call to looking-at: Unescaped literal `+' (pos 0)
+4.elisp:26:24: In call to looking-at: Unescaped literal `+' (pos 0)
"+c"
^
4.elisp:43:15: In call to looking-at: Unescaped literal `^' (pos 1)
- [elpa] externals/relint updated (3315f03 -> c2d3f3b), Mattias Engdegård, 2020/02/29
- [elpa] externals/relint 55070de 02/15: Update copyright year to 2020, Mattias Engdegård, 2020/02/29
- [elpa] externals/relint a2a29d6 03/15: Scan arguments to search-{forward, backward}-regexp, Mattias Engdegård, 2020/02/29
- [elpa] externals/relint c733b47 05/15: Use text quoting for all messages, Mattias Engdegård, 2020/02/29
- [elpa] externals/relint b46ee8b 04/15: Update copyright year to 2020, Mattias Engdegård, 2020/02/29
- [elpa] externals/relint bb7d8a1 10/15: Fix mistake in previous commit, Mattias Engdegård, 2020/02/29
- [elpa] externals/relint 1741e2c 09/15: Locate error position in 'concat' forms,
Mattias Engdegård <=
- [elpa] externals/relint 8cc1017 12/15: Rename relint--pos-from-toplevel-pos-path, Mattias Engdegård, 2020/02/29
- [elpa] externals/relint 9de65a6 11/15: Remove package description in relint.el, Mattias Engdegård, 2020/02/29
- [elpa] externals/relint c33b893 06/15: Refactor error reporting, Mattias Engdegård, 2020/02/29
- [elpa] externals/relint 803579c 01/15: More font-lock-keywords detection, Mattias Engdegård, 2020/02/29
- [elpa] externals/relint 47490f3 08/15: Add relint-buffer for easier use of relint as a library, Mattias Engdegård, 2020/02/29
- [elpa] externals/relint 159a210 13/15: Simplify line/column computation and reindent, Mattias Engdegård, 2020/02/29
- [elpa] externals/relint c2d3f3b 15/15: Increment version to 1.14, Mattias Engdegård, 2020/02/29
- [elpa] externals/relint 4a8b0ef 14/15: Return position of both expression and error from relint-buffer, Mattias Engdegård, 2020/02/29
- [elpa] externals/relint 7b93662 07/15: Report error position inside string literals, Mattias Engdegård, 2020/02/29