DevTools/CodingStandards: Difference between revisions

teach emacs how to find eslint in the source tree
(Update to modern eslint setup.)
(teach emacs how to find eslint in the source tree)
Line 71: Line 71:
* First, install the flycheck package (flymake doesn't support ESLint yet).  You can get flycheck from the [https://marmalade-repo.org/ marmalade] or [http://stable.melpa.org/#/ melpa-stable] repositories.
* First, install the flycheck package (flymake doesn't support ESLint yet).  You can get flycheck from the [https://marmalade-repo.org/ marmalade] or [http://stable.melpa.org/#/ melpa-stable] repositories.


* Tell flycheck to disable jslint, and enable flycheck in your javascript mode.  This snippet assumes the built-in javascript mode, but with minor changes (just the name of the hook) should work fine with js2-mode as well:
* Tell flycheck to disable jslint, and enable flycheck in your javascript mode.  Some care is needed to find the eslint installed in the source tree.  This snippet assumes the built-in javascript mode, but with minor changes (just the name of the hook) should work fine with js2-mode as well:
  <nowiki>
  <nowiki>
(defun my-js-mode-hacks ()
(defun my-js-mode-hacks ()
  (setq-local mode-name "JS")
   ;; Set this locally so that the head.js rule continues to work
   ;; Set this locally so that the head.js rule continues to work
   ;; properly.  In particular for a mochitest we want to preserve the
   ;; properly.  In particular for a mochitest we want to preserve the
Line 80: Line 81:
     (let ((base (file-name-nondirectory (buffer-file-name))))
     (let ((base (file-name-nondirectory (buffer-file-name))))
       (when (string-match "^\\([a-z]+_\\)" base)
       (when (string-match "^\\([a-z]+_\\)" base)
(setq-local flycheck-temp-prefix (match-string 1 base)))))
(setq-local flycheck-temp-prefix (match-string 1 base))))
    (let ((base-dir (locate-dominating-file (buffer-file-name)
    ".eslintignore")))
      (when base-dir
(let ((eslint (expand-file-name
      "testing/eslint/node_modules/.bin/eslint" base-dir)))
  (when (file-exists-p eslint)
    (setq-local flycheck-javascript-eslint-executable eslint))))))
   (flycheck-mode 1))
   (flycheck-mode 1))
(require 'flycheck)
(require 'flycheck)
10

edits