Javascript validator on Emacs (v2)

A Javascript validator that I use frequently, mentioned here for Textmate, now on Emacs:
(defun my-js-validate ()
  (interactive)
  (if (string-match "\\.js$" (buffer-file-name))
      (shell-command
       (concat
        "java -jar /Bins/Javascript/rhino1_7R2/js.jar /Bins/Javascript/lint/rhino_jslint.js "
        (buffer-file-name (current-buffer))))))

(defun my-js-hooks ()
  (progn
    (message "Entered Javascript Mode")
    (add-hook 'after-save-hook 'my-js-validate)))

(add-hook 'javascript-mode-hook 'my-js-hooks)

To force to run: M-x my-js-validate

With the hooks setup, whenever a javascript file is saved then my-js-validate is executed.

(if you use js2-mode or espresso-mode, then you need to change 'javascript-mode-hook accordingly, for example to 'espresso-mode-hook)

No comments: