[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/relint c33b893 06/15: Refactor error reporting
From: |
Mattias Engdegård |
Subject: |
[elpa] externals/relint c33b893 06/15: Refactor error reporting |
Date: |
Sat, 29 Feb 2020 17:22:29 -0500 (EST) |
branch: externals/relint
commit c33b893eb306ba8facb78b87820958fef6a3b418
Author: Mattias Engdegård <address@hidden>
Commit: Mattias Engdegård <address@hidden>
Refactor error reporting
---
relint-test.el | 4 +---
relint.el | 61 +++++++++++++++++++++++++++++++++++-----------------------
2 files changed, 38 insertions(+), 27 deletions(-)
diff --git a/relint-test.el b/relint-test.el
index 8dbbd54..2c3d840 100644
--- a/relint-test.el
+++ b/relint-test.el
@@ -79,9 +79,7 @@ and a path."
(dolist (item (relint-test--enumerate-nodes toplevel-form nil))
(let* ((node (car item))
(path (cdr item))
- (pos-line-col (relint--pos-line-col-from-toplevel-pos-path
- toplevel-pos path))
- (pos (nth 0 pos-line-col)))
+ (pos (relint--pos-from-toplevel-pos-path toplevel-pos path)))
;; Skip sugared items; they cannot be read in isolation.
(unless (memq node '(quote function \` \, \,@))
(goto-char pos)
diff --git a/relint.el b/relint.el
index afd6ed9..e12c784 100644
--- a/relint.el
+++ b/relint.el
@@ -134,10 +134,9 @@
(seq ";" (0+ nonl))))))
(goto-char (match-end 0))))
-(defun relint--go-to-pos-path (toplevel-pos path)
- "Move point to TOPLEVEL-POS and PATH (reversed list of list
-indices to follow to target)."
- (goto-char toplevel-pos)
+(defun relint--follow-path (path)
+ "Move point forward along PATH (reversed list of list indices
+to follow to target)."
(let ((p (reverse path)))
(while p
(relint--skip-whitespace)
@@ -168,13 +167,19 @@ indices to follow to target)."
(setq p (cdr p))))
(relint--skip-whitespace))
-(defun relint--pos-line-col-from-toplevel-pos-path (toplevel-pos path)
- "Compute (POSITION LINE COLUMN) from TOPLEVEL-POS and PATH (reversed
-list of list indices to follow to target)."
+(defun relint--pos-from-toplevel-pos-path (toplevel-pos path)
+ "Compute position from TOPLEVEL-POS and PATH (reversed list of
+list indices to follow to target)."
(save-excursion
- (relint--go-to-pos-path toplevel-pos path)
- (list (point)
- (line-number-at-pos (point) t)
+ (goto-char toplevel-pos)
+ (relint--follow-path path)
+ (point)))
+
+(defun relint--line-col-from-pos (pos)
+ "(LINE . COLUMN), both 1-based, from POS."
+ (save-excursion
+ (goto-char pos)
+ (cons (line-number-at-pos pos t)
(1+ (current-column)))))
(defun relint--suppression (pos message)
@@ -211,13 +216,20 @@ list of list indices to follow to target)."
(message "%s" string)
(relint--add-to-error-buffer (concat string "\n"))))
-(defun relint--report (file pos path message)
- (let ((pos-line-col (relint--pos-line-col-from-toplevel-pos-path pos path)))
- (if (relint--suppression (nth 0 pos-line-col) message)
+(defun relint--report (file toplevel-pos path message &optional str str-pos)
+ (let* ((pos (relint--pos-from-toplevel-pos-path toplevel-pos path))
+ (line-col (relint--line-col-from-pos pos))
+ (line (car line-col))
+ (col (cdr line-col)))
+ (if (relint--suppression pos message)
(setq relint--suppression-count (1+ relint--suppression-count))
(relint--output-error
- (format "%s:%d:%d: %s"
- file (nth 1 pos-line-col) (nth 2 pos-line-col) message))))
+ (concat
+ (format "%s:%d:%d: %s" file line col message)
+ (and str
+ (format "\n %s\n %s"
+ (relint--quote-string str)
+ (relint--caret-string str str-pos)))))))
(setq relint--error-count (1+ relint--error-count)))
(defun relint--escape-string (str escape-printable)
@@ -250,16 +262,17 @@ list of list indices to follow to target)."
(condition-case err
(mapcar (lambda (warning)
(let ((ofs (car warning)))
- (format "In %s: %s (pos %d)\n %s\n %s"
- name (cdr warning) ofs
- (relint--quote-string string)
- (relint--caret-string string ofs))))
+ (list (format "In %s: %s (pos %d)"
+ name (cdr warning) ofs)
+ string ofs)))
(funcall checker string))
- (error (list (format "In %s: Error: %s: %s"
- name (cadr err)
- (relint--quote-string string)))))))
- (dolist (msg complaints)
- (relint--report file pos path msg))))
+ (error (list (list
+ (format "In %s: Error: %s: %s"
+ name (cadr err)
+ (relint--quote-string string))
+ nil nil))))))
+ (dolist (c complaints)
+ (relint--report file pos path (nth 0 c) (nth 1 c) (nth 2 c)))))
(defun relint--check-skip-set (skip-set-string name file pos path)
(relint--check-string skip-set-string #'xr-skip-set-lint name file pos path))
- [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, 2020/02/29
- [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 <=
- [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