[narval] adjust jslint checker for jslint update
authorJulien Cristau <julien.cristau@logilab.fr>
Fri, 11 Jul 2014 15:24:10 +0200
changeset 1554 852401fe8b19
parent 1553 ba466ae29ba8
child 1555 9d25cbbdead8
[narval] adjust jslint checker for jslint update It's no longer a command line utility, so add a tiny wrapper to call it.
_narval/checkers/apycot/jslint.py
_narval/data/jslint-runner.js
--- a/_narval/checkers/apycot/jslint.py	Fri Jul 11 14:40:31 2014 +0200
+++ b/_narval/checkers/apycot/jslint.py	Fri Jul 11 15:24:10 2014 +0200
@@ -14,7 +14,7 @@
     NARVALDIR = dirname(dirname(checkers.__file__))
 else:
     NARVALDIR = join(INSTALL_PREFIX, 'share', 'narval')
-JSLINT_PATH = join(NARVALDIR, 'data', 'jslint.js')
+JSLINT_PATH = join(NARVALDIR, 'data', 'jslint-runner.js')
 
 
 class JsLintParser(OutputParser):
@@ -168,9 +168,10 @@
         checked_extensions = ('.js', )
 
         def check_file(self, path):
-            command = ['rhino', JSLINT_PATH, path]
+            abspath = os.path.abspath(path)
+            command = ['rhino', JSLINT_PATH, abspath]
             return ParsedCommand(self.writer, command, parsercls=JsLintParser,
-                                 path=path).run()
+                                 path=path, cwd=os.path.dirname(JSLINT_PATH)).run()
 
         def version_info(self):
             super(JsLintChecker, self).version_info()
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/_narval/data/jslint-runner.js	Fri Jul 11 15:24:10 2014 +0200
@@ -0,0 +1,28 @@
+(function(a){
+    var e,i,input;
+    if(!a[0]){
+        print("Usage: jslint.js file.js");
+        quit(1);
+    }
+
+    input=readFile(a[0]);
+    if(!input){
+        print("jslint: Couldn't open file '"+a[0]+"'.");
+        quit(1);
+    }
+    load("./jslint.js");
+    if(!JSLINT(input, {bitwise:true,eqeqeq:true,immed:true,newcap:true,nomen:true,onevar:true,plusplus:true,regexp:true,rhino:true,undef:true,white:true,sloppy:true})){
+        for(i=0;i<JSLINT.errors.length;i+=1){
+            e=JSLINT.errors[i];
+            if(e){
+                print('Lint at line '+e.line+' character '+ e.character+': '+e.reason);
+                print((e.evidence||'').replace(/^\s*(\S*(\s+\S+)*)\s*$/,"$1"));
+                print('');
+            }
+        }
+        quit(2);
+    }else{
+        print("jslint: No problems found in "+a[0]);
+        quit();
+    }
+}(arguments));