branch: elpa/flycheck
commit 114c47b6ec35461e26a269dd649e38cbb6cc605f
Author: Peter Oliver <[email protected]>
Commit: Bozhidar Batsov <[email protected]>
Fix proselint version detection
The newest versions of `proselint` restored the `--version` option.
Inspect its output to determine the version number. A version that rejects the
option (0.16.0) prints none, and is treated as new.
---
CHANGELOG.md | 1 +
flycheck.el | 21 +++++++++++++++++----
test/specs/languages/test-proselint.el | 11 +++++------
test/specs/test-tramp.el | 4 +++-
4 files changed, 26 insertions(+), 11 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 28ef27892b..ad0a760ffd 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -36,6 +36,7 @@
### Bugs fixed
+- [#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.
- [#2394](https://github.com/flycheck/flycheck/pull/2394): A checker that
reads the buffer from standard input now works on a remote host, where the
check used to run for ever without ever reporting: Flycheck writes the buffer
to a file there and has the remote shell redirect it, since standard input
cannot be closed over a TRAMP connection.
diff --git a/flycheck.el b/flycheck.el
index aed7726d00..66d7c837cc 100644
--- a/flycheck.el
+++ b/flycheck.el
@@ -18402,15 +18402,28 @@ absent from the table has not been probed yet.")
(defvar flycheck-proselint-executable)
+(defun flycheck--proselint-version ()
+ "Return the version number of Proselint, as a string.
+Return nil if Proselint or its version number could not be found."
+ (with-temp-buffer
+ (ignore-errors
+ ;; Probe on the host the check will run on (remote over TRAMP).
+ (process-file (or flycheck-proselint-executable "proselint")
+ nil t nil "--version")
+ (goto-char (point-min))
+ (search-forward-regexp
+ (rx line-start
+ (zero-or-one "Proselint ")
+ (group digit (zero-or-more (any digit ".")) digit)
+ line-end))
+ (match-string 1))))
+
(defun flycheck--proselint-args ()
"Return command arguments for proselint, detecting the version once per
host."
(let ((host (file-remote-p default-directory)))
(when (eq (gethash host flycheck--proselint-old-args-by-host 'unknown)
'unknown)
(puthash host
- ;; Probe on the host the check will run on (remote over TRAMP).
- (zerop (process-file
- (or flycheck-proselint-executable "proselint")
- nil nil nil "--version"))
+ (version< (or (flycheck--proselint-version) "1") "0.16")
flycheck--proselint-old-args-by-host))
(if (gethash host flycheck--proselint-old-args-by-host)
;; Proselint versions <= 0.14.0:
diff --git a/test/specs/languages/test-proselint.el
b/test/specs/languages/test-proselint.el
index 9639b7fe42..820c7d4a80 100644
--- a/test/specs/languages/test-proselint.el
+++ b/test/specs/languages/test-proselint.el
@@ -11,25 +11,24 @@
(clrhash flycheck--proselint-old-args-by-host))
(it "probes a host once and caches the detected version"
- ;; Exit 0 -> old proselint, which takes the "--json -" arguments.
- (spy-on 'process-file :and-return-value 0)
+ (spy-on 'flycheck--proselint-version :and-return-value "0.14.0")
(let ((default-directory "/tmp/"))
(expect (flycheck--proselint-args) :to-equal '("--json" "-"))
(expect (flycheck--proselint-args) :to-equal '("--json" "-")))
- (expect 'process-file :to-have-been-called-times 1))
+ (expect 'flycheck--proselint-version :to-have-been-called-times 1))
(it "detects the version independently on each host"
;; `file-remote-p' parses the prefix without connecting, so the probe
;; can be faked per host without a live remote.
- (spy-on 'process-file :and-call-fake
+ (spy-on 'flycheck--proselint-version :and-call-fake
(lambda (&rest _)
- (if (file-remote-p default-directory) 1 0)))
+ (if (file-remote-p default-directory) "0.16.0" "0.14.0")))
(let ((default-directory "/tmp/"))
(expect (flycheck--proselint-args) :to-equal '("--json" "-")))
(let ((default-directory "/ssh:host:/tmp/"))
(expect (flycheck--proselint-args)
:to-equal '("check" "--output-format=json")))
- (expect 'process-file :to-have-been-called-times 2)))
+ (expect 'flycheck--proselint-version :to-have-been-called-times 2)))
(flycheck-buttercup-def-checker-test proselint (text markdown) nil
(let ((flycheck-disabled-checkers '(markdown-markdownlint-cli
markdown-markdownlint-cli2 markdown-mdl markdown-pymarkdown)))
diff --git a/test/specs/test-tramp.el b/test/specs/test-tramp.el
index abb29c007b..12ae63e12a 100644
--- a/test/specs/test-tramp.el
+++ b/test/specs/test-tramp.el
@@ -123,7 +123,9 @@ would reach for the host, so it stays offline on any
machine.")
((symbol-function 'process-file) (lambda (&rest _) 1))
((symbol-function 'flycheck-find-checker-executable)
(lambda (&rest _) nil))
- ((symbol-function 'flycheck--file-truename) (lambda (f) f)))
+ ((symbol-function 'flycheck--file-truename) (lambda (f) f))
+ ((symbol-function 'flycheck--proselint-version)
+ (lambda (&rest _) "0.16.0")))
(dolist (checker flycheck-checkers)
(when-let* ((mode (car (flycheck-checker-get checker 'modes))))
(with-temp-buffer