react: use node_modules version of eslint or global if not available

This commit is contained in:
Andrea Moretti 2016-04-22 09:27:38 +02:00 committed by syl20bnr
parent cf3068e4ef
commit f88a7889a4
1 changed files with 14 additions and 0 deletions

View File

@ -38,6 +38,20 @@
(defun react/post-init-flycheck ()
(with-eval-after-load 'flycheck
(flycheck-add-mode 'javascript-eslint 'react-mode))
(defun react/use-eslint-from-node-modules ()
(let* ((root (locate-dominating-file
(or (buffer-file-name) default-directory)
"node_modules"))
(global-eslint (executable-find "eslint"))
(local-eslint (expand-file-name "node_modules/.bin/eslint"
root))
(eslint (if (file-executable-p local-eslint)
local-eslint
global-eslint)))
(setq-local flycheck-javascript-eslint-executable eslint)))
(add-hook 'react-mode-hook #'react/use-eslint-from-node-modules)
(spacemacs/add-flycheck-hook 'react-mode))
(defun react/post-init-js-doc ()