Skip to content

Instantly share code, notes, and snippets.

@localredhead
Last active August 29, 2015 14:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save localredhead/b3a074b4aaf0d6050e88 to your computer and use it in GitHub Desktop.
Save localredhead/b3a074b4aaf0d6050e88 to your computer and use it in GitHub Desktop.
npm install -g jsxhint
(define-derived-mode jsx2-mode js2-mode "jsx2" "JSX mode based on js2")
(add-to-list 'auto-mode-alist '("\\.jsx$" . jsx2-mode))
(require 'flycheck)
(flycheck-define-checker jsxhint-checker
"A JSX syntax and style checker based on JSXHint."
:command ("jsxhint" (config-file "--config=" jshint-configuration-path) source)
:error-patterns ((error line-start (1+ nonl) ": line " line ", col " column ", " (message) line-end))
:modes (jsx-mode jsx2-mode))
(defun find-jshintrc ()
(expand-file-name ".jshintrc"
(locate-dominating-file
(or (buffer-file-name) default-directory) ".jshintrc")))
(defun setup-jsxhint ()
(setq-local jshint-configuration-path (find-jshintrc))
(flycheck-select-checker 'jsxhint-checker)
(flycheck-mode))
(add-hook 'jsx2-mode-hook 'setup-jsxhint)
(add-hook 'jsx-mode-hook 'setup-jsxhint)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment