1

Flycheck seems to enable checkers based on the major mode. Meanwhile, web-mode can be used to edit a variety of different types of files (html, javascript, etc.) which would each have their own distinct set of checker(s) that make sense to use.

For example, I've just enabled linting of my jsx files using the javascript-eslint checker, but now when I open an html file (in web-mode) flycheck tries to lint that using javascript-eslint, which fails miserably, of course, since the file is html, not javascript.

Is there any other way to tell flycheck which checker to use other than by the major mode? Is there a way to tell flycheck to enable checkers for a given mode but only if some predicate passes, for example?

There's an answer to this question that recommends completely disabling flycheck depending on the file type, but I don't want to do that since I'd like to lint my other web-mode files as well.

1 Answer 1

5

The following works, not sure if there's a "built-in" way of doing it...

(flycheck-add-mode 'javascript-eslint 'web-mode)

(defun my/configure-web-mode-flycheck-checkers ()
  ;; in order to have flycheck enabled in web-mode, add an entry to this
  ;; cond that matches the web-mode engine/content-type/etc and returns the
  ;; appropriate checker.
  (-when-let (checker (cond
                       ((string= web-mode-content-type "jsx")
                        'javascript-eslint)))
    (flycheck-mode)
    (flycheck-select-checker checker)))

(add-hook 'web-mode-hook #'my/configure-web-mode-flycheck-checkers)
1
  • 2
    Strangly, if I do M-x flycheck-select-checker javascript-eslint in a web-mode file (say, .vue), a buffer similar to M-x flycheck-verify-setup opens showing, under javascript-eslint, that major-mode "web-mode is not supported", and an error saying Flycheck cannot use this syntax checker for this buffer.
    – Caleb Jay
    Commented Oct 7, 2020 at 22:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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