Avoiding a specific flycheck decoration is not built-in but can easily be added.
The flycheck overlays are generated by flycheck-add-overlay
which is luckily only called via the hook flycheck-process-error-functions
.
Functions in that hook are run with a single arg -- the error -- until one of them succeeds.
The strategy is to add a function in flycheck-process-error-functions
in front of flycheck-add-overlay
that returns t
when the error should be ignored.
That function can be added locally for buffers in emacs-lisp-mode
.
In the following example flycheck errors are ignored in emacs-lisp-mode
if the line with the error ends in ;noflycheck
. You can add the code to your init file.
(defcustom flycheck-elisp-noflycheck-marker ";noflycheck"
"Flycheck line regions marked with this marker string are ignored."
:type 'string
:group 'flycheck)
(defun flycheck-elisp-noflycheck (err)
"Ignore flycheck if line of ERR ends with `flycheck-elisp-noflycheck-marker'."
(save-excursion
(goto-char (cdr (flycheck-error-line-region err)))
(looking-back flycheck-elisp-noflycheck-marker
(max (- (point) (length flycheck-elisp-noflycheck-marker))
(point-min)))))
(defun elisp-noflycheck-hook ()
"Add the ;;;###noflycheck thing to elisp."
(require 'flycheck)
(add-hook 'flycheck-process-error-functions #'flycheck-elisp-noflycheck nil t))
(add-hook 'emacs-lisp-mode-hook #'elisp-noflycheck-hook)
The application in your usage example would be like follows.
(require 'prelude-packages) ;noflycheck
Python
andflake8
here but describe what you want to know.flycheck
usesbyte-compile
in a separate asynchronous Emacs process. So the listbyte-compile-warnings
is relevant for the issued warnings. Emacs is called with-Q
and--batch
so your initialization is ignored in the checker. But you can inject your code with options such asflycheck-emacs-lisp-package-initialize-form
. Seeflycheck-define-checker emacs-lisp
inflycheck.el
.flake8
does and what you expect. Better describe exactly what you expect. (E.g.: It could work like follows: If I add a commentnoqa
as in the following picture then the warning about the non-existingprelude-packages
should be suppressed.)(require 'prelude-packages nil t)
instead of(require 'prelude-packages)
? You can even use something like(unless (require 'prelude-packages nil t) (user-error "Library prelude-packages not found"))
.