[emacs] Add flycheck eslint hook for js-mode(s)
* emacs.d/emacs.org (Linting and Code Quality): Added.master
parent
c703113de9
commit
ddbb70a236
|
@ -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.
|
||||
|
|
Loading…
Reference in New Issue