emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/relint 7b93662 07/15: Report error position inside stri


From: Mattias Engdegård
Subject: [elpa] externals/relint 7b93662 07/15: Report error position inside string literals
Date: Sat, 29 Feb 2020 17:22:29 -0500 (EST)

branch: externals/relint
commit 7b93662a65c540ccf0643b06fa173b16ba276c8b
Author: Mattias Engdegård <address@hidden>
Commit: Mattias Engdegård <address@hidden>

    Report error position inside string literals
    
    When the error points out a string literal, use the position of the
    actual character.  Suggested by Steve Purcell.
---
 relint.el       | 26 ++++++++++++++++-
 test/1.expected | 26 ++++++++---------
 test/2.expected | 90 ++++++++++++++++++++++++++++-----------------------------
 test/6.expected |  8 ++---
 test/9.expected | 24 +++++++--------
 5 files changed, 99 insertions(+), 75 deletions(-)

diff --git a/relint.el b/relint.el
index e12c784..093ea86 100644
--- a/relint.el
+++ b/relint.el
@@ -182,6 +182,27 @@ list indices to follow to target)."
     (cons (line-number-at-pos pos t)
           (1+ (current-column)))))
 
+(defun relint--literal-string-pos (string-pos n)
+  "Position of character N in a literal string at STRING-POS."
+  (save-excursion
+    (goto-char (1+ string-pos))         ; Skip first double quote.
+    (dotimes (_ n)
+      ;; Match a single character in a string. Since we already read it,
+      ;; we know that it's well-formed.
+      (looking-at
+       (rx (* ?\\ (any " \n"))   ; Skip escaped space and newline.
+           (or (not (any ?\\))   ; Unescaped char.
+               (seq ?\\
+                    (or (** 1 3 (any "0-7"))              ; Octal.
+                        (seq ?x (+ (any "0-9A-Fa-f")))    ; Hex.
+                        (seq ?u (= 4 (any "0-9A-Fa-f")))  ; Unicode.
+                        (seq ?U (= 8 (any "0-9A-Fa-f")))  ; Unicode.
+                        (seq "N{" (+ (not (any "}"))) "}")  ; Named.
+                        (seq (any "CMS") "-" anything)    ; Keystroke.
+                        anything)))))
+      (goto-char (match-end 0)))
+    (point)))
+
 (defun relint--suppression (pos message)
   "Whether there is a suppression for MESSAGE at POS."
   (save-excursion
@@ -217,7 +238,10 @@ list indices to follow to target)."
     (relint--add-to-error-buffer (concat string "\n"))))
 
 (defun relint--report (file toplevel-pos path message &optional str str-pos)
-  (let* ((pos (relint--pos-from-toplevel-pos-path toplevel-pos path))
+  (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))
          (line-col (relint--line-col-from-pos pos))
          (line (car line-col))
          (col (cdr line-col)))
diff --git a/test/1.expected b/test/1.expected
index 07daa8a..5cc17e0 100644
--- a/test/1.expected
+++ b/test/1.expected
@@ -1,13 +1,13 @@
-1.elisp:6:22: In bad-regexp: Duplicated `A' inside character alternative (pos 
2)
+1.elisp:6:25: In bad-regexp: Duplicated `A' inside character alternative (pos 
2)
   "[AA]"
    ..^
-1.elisp:7:21: In bad-regex: Duplicated `A' inside character alternative (pos 2)
+1.elisp:7:24: In bad-regex: Duplicated `A' inside character alternative (pos 2)
   "[AA]"
    ..^
-1.elisp:8:18: In bad-re: Duplicated `A' inside character alternative (pos 2)
+1.elisp:8:21: In bad-re: Duplicated `A' inside character alternative (pos 2)
   "[AA]"
    ..^
-1.elisp:9:23: In bad-pattern: Duplicated `A' inside character alternative (pos 
2)
+1.elisp:9:26: In bad-pattern: Duplicated `A' inside character alternative (pos 
2)
   "[AA]"
    ..^
 1.elisp:11:23: In bad-regexps: Unescaped literal `+' (pos 0)
@@ -103,19 +103,19 @@
 1.elisp:33:33: In font-lock-add-keywords: Duplicated `t' inside character 
alternative (pos 2)
   "[tt]"
    ..^
-1.elisp:36:21: In bad-var-1: Unescaped literal `^' (pos 1)
+1.elisp:36:23: In bad-var-1: Unescaped literal `^' (pos 1)
   "a^"
    .^
-1.elisp:38:19: In bad-var-2: Duplicated `z' inside character alternative (pos 
2)
+1.elisp:38:22: In bad-var-2: Duplicated `z' inside character alternative (pos 
2)
   "[zz]"
    ..^
-1.elisp:40:22: In bad-var-3: Reversed range `o-O' matches nothing (pos 1)
+1.elisp:40:24: In bad-var-3: Reversed range `o-O' matches nothing (pos 1)
   "[o-O]"
    .^
-1.elisp:46:25: In bad-custom-1: Duplicated `n' inside character alternative 
(pos 2)
+1.elisp:46:28: In bad-custom-1: Duplicated `n' inside character alternative 
(pos 2)
   "[nn]"
    ..^
-1.elisp:50:25: In bad-custom-2: Duplicated `s' inside character alternative 
(pos 2)
+1.elisp:50:28: In bad-custom-2: Duplicated `s' inside character alternative 
(pos 2)
   "[ss]"
    ..^
 1.elisp:57:9: In bad-custom-3-regexp: Unescaped literal `+' (pos 0)
@@ -152,15 +152,15 @@
 1.elisp:88:3: In define-generic-mode my-mode: Repetition of repetition (pos 2)
   "b++"
    ..^
-1.elisp:94:5: In call to syntax-propertize-rules: Unescaped literal `$' (pos 0)
+1.elisp:94:6: In call to syntax-propertize-rules: Unescaped literal `$' (pos 0)
   "$1$"
    ^
-1.elisp:95:5: In call to syntax-propertize-rules: Unescaped literal `^' (pos 2)
+1.elisp:95:8: In call to syntax-propertize-rules: Unescaped literal `^' (pos 2)
   "^2^"
    ..^
-1.elisp:100:5: In call to syntax-propertize-precompile-rules: Unescaped 
literal `$' (pos 0)
+1.elisp:100:6: In call to syntax-propertize-precompile-rules: Unescaped 
literal `$' (pos 0)
   "$3$"
    ^
-1.elisp:101:5: In call to syntax-propertize-precompile-rules: Unescaped 
literal `^' (pos 2)
+1.elisp:101:8: In call to syntax-propertize-precompile-rules: Unescaped 
literal `^' (pos 2)
   "^4^"
    ..^
diff --git a/test/2.expected b/test/2.expected
index 876b12d..0bde370 100644
--- a/test/2.expected
+++ b/test/2.expected
@@ -1,135 +1,135 @@
-2.elisp:5:15: In call to looking-at: Duplicated `a' inside character 
alternative (pos 2)
+2.elisp:5:18: In call to looking-at: Duplicated `a' inside character 
alternative (pos 2)
   "[aa]"
    ..^
-2.elisp:6:22: In call to re-search-forward: Duplicated `b' inside character 
alternative (pos 2)
+2.elisp:6:25: In call to re-search-forward: Duplicated `b' inside character 
alternative (pos 2)
   "[bb]"
    ..^
-2.elisp:7:23: In call to re-search-backward: Duplicated `c' inside character 
alternative (pos 2)
+2.elisp:7:26: In call to re-search-backward: Duplicated `c' inside character 
alternative (pos 2)
   "[cc]"
    ..^
-2.elisp:8:26: In call to search-forward-regexp: Duplicated `B' inside 
character alternative (pos 2)
+2.elisp:8:29: In call to search-forward-regexp: Duplicated `B' inside 
character alternative (pos 2)
   "[BB]"
    ..^
-2.elisp:9:26: In call to search-forward-regexp: Duplicated `C' inside 
character alternative (pos 2)
+2.elisp:9:29: In call to search-forward-regexp: Duplicated `C' inside 
character alternative (pos 2)
   "[CC]"
    ..^
-2.elisp:10:17: In call to string-match: Duplicated `d' inside character 
alternative (pos 2)
+2.elisp:10:20: In call to string-match: Duplicated `d' inside character 
alternative (pos 2)
   "[dd]"
    ..^
-2.elisp:11:19: In call to string-match-p: Duplicated `e' inside character 
alternative (pos 2)
+2.elisp:11:22: In call to string-match-p: Duplicated `e' inside character 
alternative (pos 2)
   "[ee]"
    ..^
-2.elisp:12:17: In call to looking-at-p: Duplicated `f' inside character 
alternative (pos 2)
+2.elisp:12:20: In call to looking-at-p: Duplicated `f' inside character 
alternative (pos 2)
   "[ff]"
    ..^
-2.elisp:13:17: In call to looking-back: Duplicated `g' inside character 
alternative (pos 2)
+2.elisp:13:20: In call to looking-back: Duplicated `g' inside character 
alternative (pos 2)
   "[gg]"
    ..^
-2.elisp:14:29: In call to replace-regexp-in-string: Duplicated `h' inside 
character alternative (pos 2)
+2.elisp:14:32: In call to replace-regexp-in-string: Duplicated `h' inside 
character alternative (pos 2)
   "[hh]"
    ..^
-2.elisp:15:25: In call to query-replace-regexp: Duplicated `j' inside 
character alternative (pos 2)
+2.elisp:15:28: In call to query-replace-regexp: Duplicated `j' inside 
character alternative (pos 2)
   "[jj]"
    ..^
-2.elisp:16:21: In call to posix-looking-at: Duplicated `k' inside character 
alternative (pos 2)
+2.elisp:16:24: In call to posix-looking-at: Duplicated `k' inside character 
alternative (pos 2)
   "[kk]"
    ..^
-2.elisp:17:26: In call to posix-search-backward: Duplicated `l' inside 
character alternative (pos 2)
+2.elisp:17:29: In call to posix-search-backward: Duplicated `l' inside 
character alternative (pos 2)
   "[ll]"
    ..^
-2.elisp:18:25: In call to posix-search-forward: Duplicated `m' inside 
character alternative (pos 2)
+2.elisp:18:28: In call to posix-search-forward: Duplicated `m' inside 
character alternative (pos 2)
   "[mm]"
    ..^
-2.elisp:19:23: In call to posix-string-match: Duplicated `n' inside character 
alternative (pos 2)
+2.elisp:19:26: In call to posix-string-match: Duplicated `n' inside character 
alternative (pos 2)
   "[nn]"
    ..^
-2.elisp:20:34: In call to load-history-filename-element: Duplicated `o' inside 
character alternative (pos 2)
+2.elisp:20:37: In call to load-history-filename-element: Duplicated `o' inside 
character alternative (pos 2)
   "[oo]"
    ..^
-2.elisp:21:26: In call to kill-matching-buffers: Duplicated `p' inside 
character alternative (pos 2)
+2.elisp:21:29: In call to kill-matching-buffers: Duplicated `p' inside 
character alternative (pos 2)
   "[pp]"
    ..^
-2.elisp:22:15: In call to keep-lines: Duplicated `q' inside character 
alternative (pos 2)
+2.elisp:22:18: In call to keep-lines: Duplicated `q' inside character 
alternative (pos 2)
   "[qq]"
    ..^
-2.elisp:23:16: In call to flush-lines: Duplicated `r' inside character 
alternative (pos 2)
+2.elisp:23:19: In call to flush-lines: Duplicated `r' inside character 
alternative (pos 2)
   "[rr]"
    ..^
-2.elisp:24:13: In call to how-many: Duplicated `s' inside character 
alternative (pos 2)
+2.elisp:24:16: In call to how-many: Duplicated `s' inside character 
alternative (pos 2)
   "[ss]"
    ..^
-2.elisp:25:19: In call to split-string: Duplicated `t' inside character 
alternative (pos 2)
+2.elisp:25:22: In call to split-string: Duplicated `t' inside character 
alternative (pos 2)
   "[tt]"
    ..^
-2.elisp:25:30: In call to split-string: Duplicated `u' inside character 
alternative (pos 2)
+2.elisp:25:33: In call to split-string: Duplicated `u' inside character 
alternative (pos 2)
   "[uu]"
    ..^
-2.elisp:26:31: In call to split-string-and-unquote: Duplicated `v' inside 
character alternative (pos 2)
+2.elisp:26:34: In call to split-string-and-unquote: Duplicated `v' inside 
character alternative (pos 2)
   "[vv]"
    ..^
-2.elisp:27:23: In call to string-trim-left: Duplicated `w' inside character 
alternative (pos 2)
+2.elisp:27:26: In call to string-trim-left: Duplicated `w' inside character 
alternative (pos 2)
   "[ww]"
    ..^
-2.elisp:28:24: In call to string-trim-right: Duplicated `x' inside character 
alternative (pos 2)
+2.elisp:28:27: In call to string-trim-right: Duplicated `x' inside character 
alternative (pos 2)
   "[xx]"
    ..^
-2.elisp:29:18: In call to string-trim: Duplicated `y' inside character 
alternative (pos 2)
+2.elisp:29:21: In call to string-trim: Duplicated `y' inside character 
alternative (pos 2)
   "[yy]"
    ..^
-2.elisp:29:25: In call to string-trim: Duplicated `z' inside character 
alternative (pos 2)
+2.elisp:29:28: In call to string-trim: Duplicated `z' inside character 
alternative (pos 2)
   "[zz]"
    ..^
-2.elisp:42:14: In call to f2: Duplicated `B' inside character alternative (pos 
2)
+2.elisp:42:17: In call to f2: Duplicated `B' inside character alternative (pos 
2)
   "[BB]"
    ..^
-2.elisp:42:28: In call to f2: Duplicated `D' inside character alternative (pos 
2)
+2.elisp:42:31: In call to f2: Duplicated `D' inside character alternative (pos 
2)
   "[DD]"
    ..^
-2.elisp:42:42: In call to f2: Duplicated `F' inside character alternative (pos 
2)
+2.elisp:42:45: In call to f2: Duplicated `F' inside character alternative (pos 
2)
   "[FF]"
    ..^
-2.elisp:42:56: In call to f2: Duplicated `H' inside character alternative (pos 
2)
+2.elisp:42:59: In call to f2: Duplicated `H' inside character alternative (pos 
2)
   "[HH]"
    ..^
-2.elisp:42:70: In call to f2: Duplicated `J' inside character alternative (pos 
2)
+2.elisp:42:73: In call to f2: Duplicated `J' inside character alternative (pos 
2)
   "[JJ]"
    ..^
-2.elisp:43:14: In call to s2: Duplicated `B' inside character alternative (pos 
2)
+2.elisp:43:17: In call to s2: Duplicated `B' inside character alternative (pos 
2)
   "[BB]"
    ..^
-2.elisp:43:28: In call to s2: Duplicated `D' inside character alternative (pos 
2)
+2.elisp:43:31: In call to s2: Duplicated `D' inside character alternative (pos 
2)
   "[DD]"
    ..^
-2.elisp:43:42: In call to s2: Duplicated `F' inside character alternative (pos 
2)
+2.elisp:43:45: In call to s2: Duplicated `F' inside character alternative (pos 
2)
   "[FF]"
    ..^
-2.elisp:43:56: In call to s2: Duplicated `H' inside character alternative (pos 
2)
+2.elisp:43:59: In call to s2: Duplicated `H' inside character alternative (pos 
2)
   "[HH]"
    ..^
-2.elisp:43:70: In call to s2: Duplicated `J' inside character alternative (pos 
2)
+2.elisp:43:73: In call to s2: Duplicated `J' inside character alternative (pos 
2)
   "[JJ]"
    ..^
-2.elisp:44:14: In call to m2: Duplicated `B' inside character alternative (pos 
2)
+2.elisp:44:17: In call to m2: Duplicated `B' inside character alternative (pos 
2)
   "[BB]"
    ..^
-2.elisp:44:28: In call to m2: Duplicated `D' inside character alternative (pos 
2)
+2.elisp:44:31: In call to m2: Duplicated `D' inside character alternative (pos 
2)
   "[DD]"
    ..^
-2.elisp:44:42: In call to m2: Duplicated `F' inside character alternative (pos 
2)
+2.elisp:44:45: In call to m2: Duplicated `F' inside character alternative (pos 
2)
   "[FF]"
    ..^
-2.elisp:44:56: In call to m2: Duplicated `H' inside character alternative (pos 
2)
+2.elisp:44:59: In call to m2: Duplicated `H' inside character alternative (pos 
2)
   "[HH]"
    ..^
-2.elisp:44:70: In call to m2: Duplicated `J' inside character alternative (pos 
2)
+2.elisp:44:73: In call to m2: Duplicated `J' inside character alternative (pos 
2)
   "[JJ]"
    ..^
-2.elisp:52:14: In call to f5: Duplicated `b' inside character alternative (pos 
2)
+2.elisp:52:17: In call to f5: Duplicated `b' inside character alternative (pos 
2)
   "[bb]"
    ..^
-2.elisp:52:21: In call to f5: Duplicated `c' inside character alternative (pos 
2)
+2.elisp:52:24: In call to f5: Duplicated `c' inside character alternative (pos 
2)
   "[cc]"
    ..^
-2.elisp:52:28: In call to f5: Duplicated `d' inside character alternative (pos 
2)
+2.elisp:52:31: In call to f5: Duplicated `d' inside character alternative (pos 
2)
   "[dd]"
    ..^
diff --git a/test/6.expected b/test/6.expected
index a7840e1..0e8728e 100644
--- a/test/6.expected
+++ b/test/6.expected
@@ -8,10 +8,10 @@
 6.elisp:18:19: Value from `regexp-opt' cannot be spliced into `[...]'
 6.elisp:19:19: Value from `rx' cannot be spliced into `[...]'
 6.elisp:20:19: Value from `rx-to-string' cannot be spliced into `[...]'
-6.elisp:24:23: In call to skip-chars-forward: Suspect skip set framed in 
`[...]' (pos 0)
+6.elisp:24:24: In call to skip-chars-forward: Suspect skip set framed in 
`[...]' (pos 0)
   "[a-z]"
    ^
-6.elisp:25:24: In call to skip-chars-backward: Duplicated character `a' (pos 1)
+6.elisp:25:26: In call to skip-chars-backward: Duplicated character `a' (pos 1)
   "aa"
    .^
 6.elisp:26:23: `some-re' cannot be used for arguments to `skip-chars-forward'
@@ -19,10 +19,10 @@
 6.elisp:28:23: `regexp-opt' cannot be used for arguments to 
`skip-chars-forward'
 6.elisp:29:24: `rx' cannot be used for arguments to `skip-chars-backward'
 6.elisp:30:23: `rx-to-string' cannot be used for arguments to 
`skip-chars-forward'
-6.elisp:34:24: In call to skip-syntax-forward: Invalid char `s' in syntax 
string (pos 1)
+6.elisp:34:27: In call to skip-syntax-forward: Invalid char `s' in syntax 
string (pos 1)
   "\\s-"
    ..^
-6.elisp:35:25: In call to skip-syntax-backward: Duplicated syntax code ` ' 
(pos 1)
+6.elisp:35:27: In call to skip-syntax-backward: Duplicated syntax code ` ' 
(pos 1)
   "- "
    .^
 6.elisp:36:24: `some-re' cannot be used for arguments to `skip-syntax-forward'
diff --git a/test/9.expected b/test/9.expected
index 1f51f63..38469fd 100644
--- a/test/9.expected
+++ b/test/9.expected
@@ -1,37 +1,37 @@
-9.elisp:6:30: In page-delimiter: Duplicated `a' inside character alternative 
(pos 2)
+9.elisp:6:33: In page-delimiter: Duplicated `a' inside character alternative 
(pos 2)
   "[aa]"
    ..^
-9.elisp:7:34: In paragraph-separate: Duplicated `b' inside character 
alternative (pos 2)
+9.elisp:7:37: In paragraph-separate: Duplicated `b' inside character 
alternative (pos 2)
   "[bb]"
    ..^
-9.elisp:8:31: In paragraph-start: Duplicated `c' inside character alternative 
(pos 2)
+9.elisp:8:34: In paragraph-start: Duplicated `c' inside character alternative 
(pos 2)
   "[cc]"
    ..^
-9.elisp:9:28: In sentence-end: Duplicated `d' inside character alternative 
(pos 2)
+9.elisp:9:31: In sentence-end: Duplicated `d' inside character alternative 
(pos 2)
   "[dd]"
    ..^
-9.elisp:10:34: In comment-start-skip: Duplicated `e' inside character 
alternative (pos 2)
+9.elisp:10:37: In comment-start-skip: Duplicated `e' inside character 
alternative (pos 2)
   "[ee]"
    ..^
-9.elisp:11:32: In comment-end-skip: Duplicated `f' inside character 
alternative (pos 2)
+9.elisp:11:35: In comment-end-skip: Duplicated `f' inside character 
alternative (pos 2)
   "[ff]"
    ..^
-9.elisp:13:22: In sentence-end: Duplicated `g' inside character alternative 
(pos 2)
+9.elisp:13:25: In sentence-end: Duplicated `g' inside character alternative 
(pos 2)
   "[gg]"
    ..^
-9.elisp:14:47: In paragraph-start: Duplicated `h' inside character alternative 
(pos 2)
+9.elisp:14:50: In paragraph-start: Duplicated `h' inside character alternative 
(pos 2)
   "[hh]"
    ..^
-9.elisp:16:29: In paragraph-separate: Duplicated `i' inside character 
alternative (pos 2)
+9.elisp:16:32: In paragraph-separate: Duplicated `i' inside character 
alternative (pos 2)
   "[ii]"
    ..^
-9.elisp:17:25: In page-delimiter: Duplicated `j' inside character alternative 
(pos 2)
+9.elisp:17:28: In page-delimiter: Duplicated `j' inside character alternative 
(pos 2)
   "[jj]"
    ..^
-9.elisp:18:32: In comment-start-skip: Duplicated `k' inside character 
alternative (pos 2)
+9.elisp:18:35: In comment-start-skip: Duplicated `k' inside character 
alternative (pos 2)
   "[kk]"
    ..^
-9.elisp:19:30: In comment-end-skip: Duplicated `l' inside character 
alternative (pos 2)
+9.elisp:19:33: In comment-end-skip: Duplicated `l' inside character 
alternative (pos 2)
   "[ll]"
    ..^
 9.elisp:23:34: In font-lock-defaults (tag): Duplicated `m' inside character 
alternative (pos 2)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]