Bug 572259 - Part 4: Create a JSLint save hook
authorPatrick Walton <pwalton@mozilla.com>
Mon, 20 Sep 2010 18:19:11 -0700
changeset 2042 19b3a4bad8230bd734ff4c1b3371e35e8e59b3ed
parent 2041 46b17280cf9ef3c47d355bcd80669bf902bc8ecc
child 2043 947a0420f4994bdfa0056a90b0a1a389d998b375
push id919
push userpwalton@mozilla.com
push dateTue, 21 Sep 2010 01:19:18 +0000
bugs572259
Bug 572259 - Part 4: Create a JSLint save hook
plugins/supported/jslint_command.js
--- a/plugins/supported/jslint_command.js
+++ b/plugins/supported/jslint_command.js
@@ -32,27 +32,33 @@
  * 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": { "jslint": "0.0.0" },
+    "dependencies": { "file_commands": "0.0.0", "jslint": "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",
             "predicates": { "context": "js" }
+        },
+        {
+            "ep": "savehook",
+            "name": "jslint",
+            "description": "Runs JSLint when a JavaScript file is saved",
+            "pointer": "#jslintSaveHook"
         }
     ]
 });
 "end";
 
 var env = require('environment').env;
 var jslint = require('jslint').jslint;
 
@@ -95,10 +101,19 @@ function runJSLint(model) {
 
     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;