branch: elpa/flycheck
commit 1814cec13ae0771dda18561de76e564de73ed344
Author: Bozhidar Batsov <[email protected]>
Commit: Bozhidar Batsov <[email protected]>
[Fix #2402] Keep quiet about the untrusted startup *scratch*
Emacs 30 never trusts the *scratch* buffer it starts with (only the one
`scratch-buffer' recreates), so `emacs-lisp' stays off there, and as
`lisp-interaction-mode' has no other checker, Flycheck announced at every
startup that nothing could check it. That message is there to point at
a missing tool. A buffer Emacs deliberately doesn't trust isn't one, and
`flycheck-verify-setup' still explains it.
This only applies where `emacs-lisp' is the mode's sole checker. In
`emacs-lisp-mode', Checkdoc runs whatever the trust, so reaching the
message there means something besides trust is wrong.
The docs now show how to trust *scratch* for anyone who wants it checked.
---
CHANGELOG.md | 1 +
doc/languages.rst | 10 ++++++++++
flycheck.el | 23 +++++++++++++++++++++--
test/specs/test-flycheck-mode.el | 37 ++++++++++++++++++++++++++++++++++++-
4 files changed, 68 insertions(+), 3 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 1e5ac6a531..24f918cd38 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -36,6 +36,7 @@
### Bugs fixed
+- [#2407](https://github.com/flycheck/flycheck/pull/2407): Flycheck no longer
says at every startup on Emacs 30+ that no syntax checker can run in
`*scratch*`, which Emacs doesn't trust; the `emacs-lisp` docs show how to trust
it ([#2402](https://github.com/flycheck/flycheck/issues/2402)).
- [#2405](https://github.com/flycheck/flycheck/pull/2405): The Flycheck menu
shows up in the context menu of `context-menu-mode`
([#2401](https://github.com/flycheck/flycheck/issues/2401)).
- [#2406](https://github.com/flycheck/flycheck/pull/2406): Stop the `*eldoc*`
window popping open with an eager `eldoc-documentation-strategy`, such as
`eldoc-documentation-compose-eagerly`, which displays again each time a source
answers ([#2387](https://github.com/flycheck/flycheck/issues/2387)).
- [#2302](https://github.com/flycheck/flycheck/pull/2302): `proselint` errors
no longer extend one character past the text they flag with proselint 0.14.
diff --git a/doc/languages.rst b/doc/languages.rst
index 87e7d6fc69..3f21707ed5 100644
--- a/doc/languages.rst
+++ b/doc/languages.rst
@@ -374,6 +374,16 @@ to view the docstring of the syntax checker. Likewise,
you may use
checker doesn't expand macros and remains enabled for untrusted
files.
+ Emacs doesn't trust the ``*scratch*`` buffer it starts with, so this
+ checker leaves it alone. To have it checked anyway:
+
+ .. code-block:: elisp
+
+ (add-hook 'lisp-interaction-mode-hook
+ (lambda ()
+ (when (equal (buffer-name) "*scratch*")
+ (setq-local trusted-content :all))))
+
.. defcustom:: flycheck-emacs-lisp-load-path
The load path as list of strings. Relative directories are expanded
diff --git a/flycheck.el b/flycheck.el
index 72db2f5ea8..b3f9295a0a 100644
--- a/flycheck.el
+++ b/flycheck.el
@@ -3805,9 +3805,14 @@ inert mode line with no idea why.")
Distinguish a mode nothing supports, where there is nothing to be done,
from one whose checkers are all unusable here, which usually means the
-tool is not installed and is worth looking into."
+tool is not installed and is worth looking into.
+
+Stay quiet where only `trusted-content' keeps `emacs-lisp' off: Emacs
+never trusts the *scratch* buffer it starts with, and saying so at
+every startup would only be noise."
(unless (or (memq major-mode flycheck--modes-without-checker)
- (flycheck-ephemeral-buffer-p))
+ (flycheck-ephemeral-buffer-p)
+ (flycheck--emacs-lisp-only-untrusted-p))
(push major-mode flycheck--modes-without-checker)
(let ((supported (seq-some (lambda (checker)
(flycheck-checker-supports-major-mode-p
@@ -15992,6 +15997,20 @@ Return nil as well where there is no notion of trust,
that is, without
;; Only a `trusted-content' of `:all' trusts a buffer without a file
"buffer visits no file")))
+(defun flycheck--emacs-lisp-only-untrusted-p ()
+ "Whether the current buffer goes unchecked only for want of trust.
+
+Only in modes no checker but `emacs-lisp' supports, such as
+`lisp-interaction-mode': elsewhere `emacs-lisp-checkdoc' doesn't care
+about trust, so something else is keeping it off too."
+ (and (equal (seq-filter #'flycheck-checker-supports-major-mode-p
+ flycheck-checkers)
+ '(emacs-lisp))
+ (not (flycheck-manually-disabled-checker-p 'emacs-lisp))
+ (flycheck-find-checker-executable 'emacs-lisp)
+ (flycheck--emacs-lisp-enabled-p)
+ (flycheck--emacs-lisp-untrusted-reason)))
+
(defun flycheck--emacs-lisp-checkdoc-enabled-p ()
"Check whether to enable Emacs Lisp Checkdoc in the current buffer."
(not (flycheck--emacs-lisp-checkdoc-disabled-reason)))
diff --git a/test/specs/test-flycheck-mode.el b/test/specs/test-flycheck-mode.el
index 2ac10dc520..12082c15c8 100644
--- a/test/specs/test-flycheck-mode.el
+++ b/test/specs/test-flycheck-mode.el
@@ -257,9 +257,44 @@
(it "says something different when checkers exist but none can run"
;; That usually means the tool is missing, which is worth chasing
- (let ((messages (test-nochecker/messages #'emacs-lisp-mode)))
+ (let ((messages (test-nochecker/messages #'js-mode)))
(expect (car messages) :to-match "can run here")))
+ (it "speaks up in emacs-lisp-mode, where checkdoc ignores trust"
+ ;; So with nothing running, something besides trust is wrong
+ (expect (car (test-nochecker/messages #'emacs-lisp-mode))
+ :to-match "can run here"))
+
+ (it "stays quiet where only trust keeps emacs-lisp off"
+ (assume (fboundp 'trusted-content-p) "Requires Emacs 30+")
+ (expect (test-nochecker/messages #'lisp-interaction-mode) :to-be nil))
+
+ (it "speaks up in a trusted buffer, even after staying quiet"
+ (assume (fboundp 'trusted-content-p) "Requires Emacs 30+")
+ (test-nochecker/messages #'lisp-interaction-mode)
+ (expect (car (test-nochecker/messages
+ (lambda ()
+ (lisp-interaction-mode)
+ (setq-local trusted-content :all))))
+ :to-match "can run here"))
+
+ (it "speaks up when emacs-lisp is disabled by hand"
+ (assume (fboundp 'trusted-content-p) "Requires Emacs 30+")
+ (expect (car (test-nochecker/messages
+ (lambda ()
+ (lisp-interaction-mode)
+ (setq-local flycheck-disabled-checkers '(emacs-lisp)))))
+ :to-match "can run here"))
+
+ (it "speaks up when emacs is missing"
+ (assume (fboundp 'trusted-content-p) "Requires Emacs 30+")
+ (expect (car (test-nochecker/messages
+ (lambda ()
+ (lisp-interaction-mode)
+ (setq-local flycheck-emacs-lisp-executable
+ "flycheck-no-such-emacs"))))
+ :to-match "can run here"))
+
(it "says it once, however many times the buffer is checked"
(expect (length (test-nochecker/messages #'fundamental-mode)) :to-equal 1))