Skip to content

Instantly share code, notes, and snippets.

@mstepniowski
Created June 17, 2011 13:30
Show Gist options
  • Save mstepniowski/1031420 to your computer and use it in GitHub Desktop.
Save mstepniowski/1031420 to your computer and use it in GitHub Desktop.
node-jslint configuration for flymake
(require 'flymake)
(defun flymake-jslint-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))))
;; Change it to path of the jslint.js executable file on your system
(list "/Users/zuber/node_modules/jslint/bin/jslint.js" (list local-file))))
(setq flymake-allowed-file-name-masks
(cons '(".+\\.js$"
flymake-jslint-init
flymake-simple-cleanup
flymake-get-real-file-name)
flymake-allowed-file-name-masks))
(add-hook 'js-mode-hook
(lambda ()
(flymake-mode 1)))
// Overwrite reporter.js file from node-jslint package with this one
/*jslint forin: true */
var log = console.log;
exports.report = function(file, lint) {
var options = [], key, value,
i, len, pad, e;
for (key in lint.options) {
value = lint.options[key];
options.push(key + ": " + value);
}
// log("/*jslint " + options.join(", ") + " */");
if (!lint.ok) {
len = lint.errors.length;
for (i=0; i<len; i++) {
pad = String(i + 1);
while (pad.length < 3) {
pad = ' ' + pad;
}
e = lint.errors[i];
if (e) {
log(file + ':' + e.line + ':' + e.character + ': ' + e.reason);
}
}
} else {
log("No errors found.");
}
return lint.ok;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment