branch: elpa/flycheck
commit 5bf4c1672947247140c86c935d7fecfa5c0eb21f
Author: Peter Oliver <[email protected]>
Commit: Bozhidar Batsov <[email protected]>
Work around off-by-one errors from proselint
Proselint 0.14 often reports an error as ending one character further than
it does (https://github.com/amperser/proselint/issues/1048). When the last two
characters of a reported span differ in syntax class, drop the last one.
---
CHANGELOG.md | 1 +
flycheck.el | 21 +++++++++++++++++++--
test/specs/languages/test-proselint.el | 8 ++++----
3 files changed, 24 insertions(+), 6 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index ad0a760ffd..747b96a813 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -36,6 +36,7 @@
### Bugs fixed
+- [#2302](https://github.com/flycheck/flycheck/pull/2302): `proselint` errors
no longer extend one character past the text they flag with proselint 0.14.
- [#2302](https://github.com/flycheck/flycheck/pull/2302): `proselint` detects
the tool's version from what `proselint --version` prints rather than whether
it succeeds, so a development build of proselint, which accepts the option
again, is no longer run with the arguments of 0.14.
- [#2396](https://github.com/flycheck/flycheck/pull/2396): A language server
running on a remote host is stopped there when Flycheck gives up on it, so a
server that never answers the `initialize` handshake no longer leaves a copy of
itself behind on every attempt.
- [#2395](https://github.com/flycheck/flycheck/pull/2395): A check that is
stopped, or superseded by the next one, no longer leaves its checker running on
the remote host: Flycheck interrupts the command there, which is what actually
stops it, rather than only dropping its own end of the process.
diff --git a/flycheck.el b/flycheck.el
index 66d7c837cc..19cb23f9eb 100644
--- a/flycheck.el
+++ b/flycheck.el
@@ -18371,8 +18371,9 @@ See URL `https://proselint.com/' for more information
about proselint."
:id .check
:buffer buffer
:checker checker
- ;; See https://github.com/amperser/proselint/issues/1048
- :end-pos .end)))
+ :end-pos (+ .end
(flycheck--proselint-off-by-one-correction
+ buffer
+ .end)))))
(let-alist (car response)
.data.errors))
;; Proselint versions >= 0.16.0
@@ -18389,6 +18390,22 @@ See URL `https://proselint.com/' for more information
about proselint."
(let-alist (car response)
.result.<stdin>.diagnostics)))))
+;; Proselint 0.14 will often tell us that an error extends one character
+;; further than it actually does. This is fairly trivial until we try
+;; to apply a replacement, at which point it causes us trouble.
+;; https://github.com/amperser/proselint/issues/1048
+(defun flycheck--proselint-off-by-one-correction (buffer end-pos)
+ "Return an offset if END-POS of BUFFER doesn't look like the end of an
error."
+ (with-current-buffer buffer
+ (let ((penultimate-char (char-before (- end-pos 1)))
+ (ultimate-char (char-before end-pos)))
+ (if (and penultimate-char
+ ultimate-char
+ (not (char-equal (char-syntax penultimate-char)
+ (char-syntax ultimate-char))))
+ -1
+ 0))))
+
;; A hash table (not the scalar of earlier versions -- hence the new name,
;; so an in-session reload does not leave a stale non-table value that
;; `gethash' would choke on).
diff --git a/test/specs/languages/test-proselint.el
b/test/specs/languages/test-proselint.el
index 820c7d4a80..6e096c16d0 100644
--- a/test/specs/languages/test-proselint.el
+++ b/test/specs/languages/test-proselint.el
@@ -39,17 +39,17 @@
:id "weasel_words.very"
:checker proselint
:end-line 1
- :end-column 12)
+ :end-column 11)
'(2 4 warning "Redundancy. Use 'associate' instead of 'associate
together'."
:id "redundancy.garner"
:checker proselint
- :end-line 3
- :end-column 1)
+ :end-line 2
+ :end-column 22)
'(3 5 warning "Gender bias. Use 'lawyer' instead of 'lady lawyer'."
:id "sexism.misc"
:checker proselint
:end-line 3
- :end-column 17)))))
+ :end-column 16)))))
(describe "reading the tool's output"
;; Read from output recorded earlier, so this runs whether or