0

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.

2

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)

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.