Emacs - Can't get Flymake to work with JSHint

1.9k views Asked by At

I'm trying to get JSHint to work with Flymake.

jshint is indeed installed in /opt/bin and works. /opt/bin is in Emacs' exec-path.

I've followed the directions on the EmacsWiki and have this in my init.el:

(defun flymake-jshint-init ()
  (let* ((temp-file (flymake-init-create-temp-buffer-copy
                     'flymake-create-temp-inplace))
         (local-file (file-relative-name
                      temp-file
                      (file-name-directory buffer-file-name))))
    (list "jshint" (list local-file))))

(setq flymake-err-line-patterns
      (cons '("^  [[:digit:]]+ \\([[:digit:]]+\\),\\([[:digit:]]+\\): \\(.+\\)$"
              nil 1 2 3)
            flymake-err-line-patterns))

(add-to-list 'flymake-allowed-file-name-masks
             '("\\.js\\'" flymake-jshint-init))

When I open JavaScript files, my modeline appears as:

[(Javascript Flymake* AC)]

This is odd because the * usually doesn't appear when I'm using Flymake with C++ or Python. According to the Flymake docs, Flymake* means "Flymake is currently running." However, Flymake isn't showing any errors.

I've checked the *Messages* buffer but it only lists a few lines of Fontifying foo.js... (regexps...................). No errors.

Other suggestions?

3

There are 3 answers

0
a paid nerd On BEST ANSWER

I found a project called jshint-mode and tried that. It created a buffer called *jshint-mode* which revealed the error: JSHint couldn't find the formidable module.

I ran M-x setenv in Emacs to set NODE_PATH so that jshint could find the formidable library. I also set NODE_PATH in /etc/profile.

0
scorpiodawg On

jshint-mode did not work for me (I use Linux Mint 14 'Nadia') -- I was getting errors with "flymake's configuration" when it runs curl to talk to the Node.js instance running the jshint script. This was perplexing, and I'm not familiar with ELisp to go around messing with the .el files.

I solved this by instead going straight to the Emacs flymake project fork on github which now has support for jshint built-in (it needs to be installed as npm -g install jshint which in turn requires you to install npm and node.js if you haven't already). This made things work.

One more caveat: on my Linux box, node was an executable already existing in /usr/sbin and I had to make a symbolic link named node in /usr/local/bin to override the former. This was necessary as the Node.js binary for Linux Mint (possibly Ubuntu as well, I haven't checked) is named nodejs instead and will cause many scripts written assuming a binary name of node to fail. You can test this by typing node: if it is the pre-existing binary it generally returns to the prompt silently, but if it is Node.js it prompts you with a > (you can Ctrl-D to quit out of there)

0
sanityinc On

Try using M-: to execute (setq flymake-log-level 3), which will cause flymake to print debug info into *Messages*.

Here's how I use flymake with jslint, which works nicely for me -- that code might give you a clue about what's going wrong for you.

You might also consider js2-mode, which provides some language-aware lint-like warnings without resorting to running an external process.