From ddbb70a23638a4a3ea03ea3378bca8b084640875 Mon Sep 17 00:00:00 2001 From: Mike Gerwitz Date: Mon, 19 Sep 2016 23:44:37 -0400 Subject: [PATCH] [emacs] Add flycheck eslint hook for js-mode(s) * emacs.d/emacs.org (Linting and Code Quality): Added. --- emacs.d/emacs.org | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/emacs.d/emacs.org b/emacs.d/emacs.org index 153b7cd..c3d8c6b 100644 --- a/emacs.d/emacs.org +++ b/emacs.d/emacs.org @@ -717,6 +717,7 @@ side-by-side windows. #+END_SRC ** JavaScript +*** Indentation =js-mode='s indentation strategy is abhorrent. #+BEGIN_SRC emacs-lisp @@ -725,12 +726,44 @@ side-by-side windows. (setq indent-line-function 'indent-relative))) #+END_SRC +*** Linting and Code Quality +[[http://eslint.org/][ESLint]] is a linting and codestyle tool for ECMAScript. Flycheck +supports it. + +#+BEGIN_SRC emacs-lisp + (add-hook 'js-mode-hook 'flycheck-mode t) +#+END_SRC + +This code is based on [[https://emacs.stackexchange.com/questions/21205/flycheck-with-file-relative-eslint-executable/21207#21207][an Emacs StackExchange answer]]: + +#+BEGIN_SRC emacs-lisp + (defun my-flycheck-find-eslint () + (let* ((root (locate-dominating-file + (or (buffer-file-name) + default-directory) + "node_modules")) + (esbin (and root + (expand-file-name + "node_modules/.bin/eslint" + root)))) + (and esbin + (file-executable-p esbin) + esbin))) + + (defun my-flycheck-set-eslint () + (setq-local flycheck-javascript-eslint-executable + (my-flycheck-find-eslint))) + + (add-hook 'flycheck-mode-hook #'my-flycheck-set-eslint) +#+END_SRC + ** Web Mode #+BEGIN_SRC emacs-lisp (setq web-mode-markup-indent-offset 2 web-mode-enable-auto-pairing t web-mode-enable-auto-closing t) #+END_SRC + * Editing I'm told that Emacs is an operating system. I'm also told that it is an editor. I've been convinced of both.