--- a/plugins/supported/jslint_command.js
+++ b/plugins/supported/jslint_command.js
@@ -32,51 +32,59 @@
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
"define metadata";
({
- "dependencies": { "file_commands": "0.0.0", "jslint": "0.0.0" },
+ "dependencies": { "jslint": "0.0.0", "notifier": "0.0.0" },
"description": "Provides the JSLint command to check code for errors.",
"objects": [],
"provides": [
{
"ep": "command",
"name": "jslint",
"params": [],
"description": "Run JSLint to check the current file",
"pointer": "#jslintCommand",
+ "key": "ctrl_shift_v",
"predicates": { "context": "js" }
},
{
"ep": "savehook",
"name": "jslint",
"description": "Runs JSLint when a JavaScript file is saved",
"pointer": "#jslintSaveHook"
+ },
+ {
+ "ep": "notification",
+ "name": "jslint_error",
+ "description": "JSLint errors",
+ "level": "error"
}
]
});
"end";
var env = require('environment').env;
var jslint = require('jslint').jslint;
+var catalog = require("bespin:plugins").catalog;
function runJSLint(model) {
var ok = jslint(model.getValue());
if (ok) {
return "JSLint succeeded";
}
var errors = jslint.errors;
var plural = (errors.length === 1) ? "" : "s";
- var output = [ "<div>JSLint reported ", errors.length, " error", plural,
- ":</div>" ];
+ var message = "JSLint reported " + errors.length + " error" + plural;
+ var output = [ "<div>", message, ":</div>" ];
errors.forEach(function(err) {
if (err == null) {
return;
}
output.push("<div>");
output.push(err.line);
@@ -93,27 +101,38 @@ function runJSLint(model) {
output.push("<pre>");
output.push(line);
output.push("\n");
for (var i = 0; i < character; i++) {
output.push(".");
}
output.push('^</pre>');
});
+
+ if (errors[errors.length-1] === null) {
+ var notifier = catalog.getObject('notifier');
+ if (notifier) {
+ notifier.notify({
+ plugin: 'jslint_command',
+ notification: 'jslint_error',
+ body: message
+ });
+ }
+ }
return output.join("");
-}
+};
exports.jslintCommand = function(args, req) {
req.done(runJSLint(env.model));
-}
+};
exports.jslintSaveHook = function(file) {
var extension = file.extension();
if (extension !== "js" && extension !== "jsm") {
return "";
}
return runJSLint(env.model);
-}
+};
exports.runJSLint = runJSLint;