Linting coffee-script in Emacs

I’ve been doing a lot of node.js recently, and I started editing coffee-script in my favourite editor which is Emacs. Now one thing I use regularly in Emacs is flymake-mode which essentially provides a set of hooks that are activated when you type into a buffer in Emacs.

So, I did a bit of investigation and discovered coffeelint. Then, all I needed to do was adapt lintnode (or rather the fork I use) and make it work with coffeeline. And coffeelintnode is the result.

You need a bit of emacs configuration to make it work. I use:

;; make coffeelinenode work nicely!
(add-to-list 'load-path "path-to-coffeelintnode")
(require 'flymake-coffeelint)
;; Make sure we can find the lintnode executable
(setq coffeelintnode-location "path-to-coffeelintnode")
(setq coffeelintnode-node-program "path-to-node-executable")
(setq coffeelintnode-coffeelint-excludes (list 'max_line_length))
(setq coffeelintnode-coffeelint-includes '())
(setq coffeelintnode-coffeelint-set "")
;; Start the server when we first open a coffee file and start checking
(setq coffeelintnode-autostart 'true)
(add-hook 'coffee-mode-hook
  (lambda ()
    (coffeelintnode-hook)
    (unless (eq buffer-file-name nil) (flymake-mode 1)) ;dont invoke flymake on temporary buffers for the interpreter
    (local-set-key [f2] 'flymake-goto-prev-error)
    (local-set-key [f3] 'flymake-goto-next-error)))