Complete Computing Environment: JavaScript

Table of Contents

(provide 'cce-js)

Programming JavaScript with js2-mode

For JavaScript I use js2-mode, which is a great set of systems built on top of the OG javascript-mode which has automagic linting on top of jshint.

(install-pkgs '(flymake-jshint js2-mode js2-refactor))
(require 'js2-mode)
(add-to-list 'auto-mode-alist '("\\.js$" . js2-mode))
(eval-after-load 'js2-mode (lambda ()
                             (add-hook 'js2-mode-hook 'flymake-mode)))

We have some configuration to feed in to js2-mode. We are pretty noisy with our syntax highlighting, we tweak it to work with Node.js specifically, and we disable parse errors and strict.

Since jshint runs in the context of $PWD, jshintrc files for the project I'm working on aren't found. I'm almost always working on Dispatch, this should be Good Enough, though I could probably do a better job using Projectile or something.

(setq js2-highlight-level 3
      js2-include-node-externs t
      js2-init-hook nil
      js2-mode-show-parse-errors nil
      js2-mode-show-strict-warnings nil
      jshint-configuration-path "~/Work/dispatch")

js2 also has a really powerful refactor library, we should use it!

(eval-after-load 'js2-mode (lambda ()
                             (add-hook 'js2-mode-hook #'js2-refactor-mode)
                             (js2r-add-keybindings-with-prefix "C-c C-m")))

Author: Ryan Rix

Created: 2019-05-07 Tue 11:12

Validate XHTML 1.0