uɐʎɹ ррoʇ uɐʎɹ bio photo

uɐʎɹ ррoʇ uɐʎɹ

Hello. Is is me you're looking for?
僕は猿ーロボット。
robotic life signs.
makes noise, hears sounds, intafon.
affe auf deux roues.

Email Github Github Gist Last.fm Soundcloud Flickr

The previous post detailed a way to simply run JsLint from TextMate. I put together this shell script that can be run as a command on the selected files in the project drawer and on the current document not in a project window, which is more robust than the previous script. I will try to upload a bundle for this later, but for now, you can create the command in the bundle editor yourself. Make sure that the input is none and that the output is set to the HTML option. Also, *very important*, make sure that you add the unix path to jsl to your shell variables in TextMate using the variable name “JSLINT”.

if [[ -n "$TM_SELECTED_FILES" ]]
then

   # THIS WILL RUN JSLINT ON THE SELECTED
   # FILES IN THE PROJECT DRAWER
   eval arr=("$TM_SELECTED_FILES")

   for (( i = 0; i < ${#arr[@]}; i++ )); do

      filePath=${arr[$i]}
      pathLen=${#filePath}-3
      pathEnd=${filePath:$pathLen:3}

      if [ $pathEnd == ".js" ]
         then
            outputFormat='<br/><a href="txmt://open?url=file://__FILE__&line=__LINE__">__FILE__</a> (Line __LINE__):<br/>__ERROR__<br/>'
            $JSLINT -process "$filePath" -output-format "$outputFormat" -context -nologo
         else
            outputFormat='<a href="txmt://open?url=file://__FILE__&line=__LINE__">__FILE__</a> (Line __LINE__):<br/>__ERROR__<br/><br/>'
            $JSLINT -process "$filePath/*" -output-format "$outputFormat" +recurse -context -nofilelisting -nologo
      fi

      echo "<br/><br/>"

   done

else

   # THIS RUNS JSLINT ON THE CURRENT FILE
   filePath=$TM_FILEPATH
   outputFormat='<br/><a href="txmt://open?url=file://__FILE__&line=__LINE__">__FILE__</a> (Line __LINE__):<br/>__ERROR__<br/>'
   $JSLINT -process "$filePath" -output-format "$outputFormat" -context -nologo

fi

If you would like to see which files were skipped due to no error or warning, you can remove the “-nofilelisting” portion of the else statement in the for loop. I especially like the way that you can specify a URL in the html output in TextMate that will allow you to link back to documents that can be opened in TextMate, even down to the line. I’m not sure where that is referenced specifically, but its a pretty cool trick; I found that litte tidbit somewhere out there – I lost it in my browser. Anyway, the above script dumps your jslint output in the HTML output window, and clicking the links for the errors will take you to the document and line where the error was found.