Tuesday, April 15, 2008

Recently I was introduced to a tool that was to a tool that would analyze Javascript for syntactical errors as well as usage of bad practices. This tool is JSLint. Douglas Crockford from Yahoo! created, and maintains, JSLint. If you haven't heard of him, he is a well known Javascript expert.

Now how can we verify our Javascript with JSLint & MSBuild? In my open source project Sedodream MSBuild I have created a new JSLint task. You can get the installer by going to http://www.codeplex.com/Release/ProjectReleases.aspx?ProjectName=Sedodream&ReleaseId=12530. After you install the msi you can follow these steps to invoke the JSLint on your projects.

Edit your web project file and include the following snippet before the </Project> tag.

<Import Project="$(MSBuildExtensionsPath)\Sedodream\Sedodream.tasks"/>

<Import Project="$(MSBuildExtensionsPath)\Sedodream\JSLint.targets"/>

 

<PropertyGroup>

<BuildDependsOn>

$(BuildDependsOn);

RunJSLint;

</BuildDependsOn>

</PropertyGroup>

 

The first line includes makes the tasks from my project available, and the second line includes the file that knows how to execute the JSLint tool. Following that I extend the build process to execute the RunJSLint target. If you are not familiar with this take a look at my article Inside MSBuild.

After you do this you may be prompted with a security warning from Visual Studio, you should pick 'Load Project Normally'. You can read more about how to disable it at http://msdn2.microsoft.com/en-us/library/ms228217.aspx. I chose to not have my installer set that registry flag. For the time being I think that users should make that decision themselves, although I would like to think I'm trustworthy J

After you do this and allow Visual Studio to load the project normally, if your create Javascript files that have errors, or JSLint doesn't like you will be warned in the error list as shown below.

 

With that being said keep in mind this is a V1 deal, so this may not work perfect. I am working to make sure that it works well, but it was kinda tricky to get this to work period!

As always I welcome your feedback and I will post more info about this later. Oh yeah by default from JSLint the GoodParts are enforced keep an eye on this blog, or send me a message, to see how to change that.

Sayed Ibrahim Hashimi

4/15/2008 1:25:01 AM (Eastern Daylight Time, UTC-04:00)  #    Comments [4]  | 
5/8/2008 5:19:03 AM (Eastern Daylight Time, UTC-04:00)
Trying to install the .msi i get the error
"Failed to open the XML file, system error : -2147024786"

Which XML file ?
Roberto Alessi
5/8/2008 9:13:26 AM (Eastern Daylight Time, UTC-04:00)
Most likely this is the XSD that Visual Studio uses for intellisense for MSBuild files. Do you have Visual Studio installed? If so what versions?

Please send me your email so I can work with you to fix this issue.

Sayed Ibrahim Hashimi
5/15/2008 1:38:39 PM (Eastern Daylight Time, UTC-04:00)
This is great, however i cannot seem to get it to work on .js files that are very large. Your example .js files work fine, and any small files are also fine. I used a production .js file that was 2000+ lines, and it either gives an error that JSLint failed or compiles as if there are no errors. It would be interesting to get this working on our CCNet CI builds...
Brad
5/15/2008 1:50:46 PM (Eastern Daylight Time, UTC-04:00)
I have created a ticket to track this, I will try and re-create it.
http://www.codeplex.com/Sedodream/WorkItem/View.aspx?WorkItemId=16611

Sayed Ibrahim Hashimi
Name
E-mail
Home page

Comment (HTML not allowed)  

Enter the code shown (prevents robots):

Theme design by Jelle Druyts