0

In Python with flake8 we can do that with #noqa in the end of line. How the same can be done with Emacs Lisp?

enter image description here

My ambition is to disable a particular lint error by just make a annotation with a comment like is provided in the above picture. This is possible in Emacs Lisp or there is a better way for it?

  • Please do not refer to Python and flake8 here but describe what you want to know. – Tobias Feb 18 at 9:12
  • From a short analysis (maybe not right, maybe not comprehensive): flycheck uses byte-compile in a separate asynchronous Emacs process. So the list byte-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 as flycheck-emacs-lisp-package-initialize-form. See flycheck-define-checker emacs-lisp in flycheck.el. – Tobias Feb 18 at 9:12
  • I want ignore a lint error perline using Emacs Lisp as it's possible in other linters (like I said before). – Manoel Vilela Feb 18 at 14:43
  • 1
    My point is: Emacs experts like Drew, phils, Stefan, Dan, ... do not necessarily know Python well enough. It may be that you exclude them from giving you an expert advice with your reference to Python because they cannot be sure what exactly flake8 does and what you expect. Better describe exactly what you expect. (E.g.: It could work like follows: If I add a comment noqa as in the following picture then the warning about the non-existing prelude-packages should be suppressed.) – Tobias Feb 18 at 15:11
  • By the way have you tried (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")). – Tobias Feb 18 at 15:14
2

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.