<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Gigu's blog &#187; build</title>
	<atom:link href="http://blog.gigoo.org/tag/build/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.gigoo.org</link>
	<description>wEBbLOG</description>
	<lastBuildDate>Thu, 01 Jul 2010 22:59:21 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Verify JavaScript with JSLint during build using Nant</title>
		<link>http://blog.gigoo.org/2009/03/25/verify-javascript-with-jslint-during-build-using-nant/</link>
		<comments>http://blog.gigoo.org/2009/03/25/verify-javascript-with-jslint-during-build-using-nant/#comments</comments>
		<pubDate>Wed, 25 Mar 2009 13:39:06 +0000</pubDate>
		<dc:creator>Greg Gigon</dc:creator>
				<category><![CDATA[development]]></category>
		<category><![CDATA[.net]]></category>
		<category><![CDATA[build]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jslint]]></category>
		<category><![CDATA[microsoft]]></category>
		<category><![CDATA[nant]]></category>
		<category><![CDATA[validation]]></category>

		<guid isPermaLink="false">http://blog.gigoo.org/2009/03/25/verify-javascript-with-jslint-during-build-using-nant/</guid>
		<description><![CDATA[ Project I’m working on has a lot of JavaScript. We are minimizing JavaScript files during the build and combining them into one file. Problem is when someone checks in some invalid JavaScript into repository that doesn’t minify properly. As a result you can end up with not working JavaScript at all. There is a [...]]]></description>
			<content:encoded><![CDATA[<p><img title="image" style="display: inline; margin: 0px 5px 0px 0px" height="40" alt="image" src="http://blog.gigoo.org/wp-content/uploads/2009/03/image1.png" width="129" align="left" /> Project I’m working on has a lot of JavaScript. We are minimizing JavaScript files during the build and combining them into one file. Problem is when someone checks in some invalid JavaScript into repository that doesn’t minify properly. As a result you can end up with not working JavaScript at all. There is a tool called <a title="JSLint" href="http://www.jslint.com/lint.html" onclick="javascript:pageTracker._trackPageview('/outbound/article/www.jslint.com');" target="_blank">JSLint</a>. It is created by <strong><em>Douglas Crockford</em></strong> who is also the author of a very good book about JavaScript: “<em><strong><a href="http://www.amazon.com/exec/obidos/ASIN/0596517742/" onclick="javascript:pageTracker._trackPageview('/outbound/article/www.amazon.com');" target="_blank">JavaScript: The Good Pars</a></strong></em>”.</p>
<p><a title="JSLint" href="http://www.jslint.com/lint.html" onclick="javascript:pageTracker._trackPageview('/outbound/article/www.jslint.com');" target="_blank">JSLint</a> is a very strict JavaScript verifier. JS files corrected to a JSLint specification could be minified with confidence. </p>
<p>We made the decision that build should brake when <a title="JSLint" href="http://www.jslint.com/lint.html" onclick="javascript:pageTracker._trackPageview('/outbound/article/www.jslint.com');" target="_blank">JSLint</a> detects invalid JavaScript file, so developer will need to fix it before the code checkin.</p>
<h2>Prepare the tool base</h2>
<p>As a first step we need to get all the tools that will execute JSLint validation against our codebase. You can grab <a href="http://www.jslint.com/fulljslint.js" onclick="javascript:pageTracker._trackPageview('/outbound/article/www.jslint.com');" target="_blank"><strong><em>fulljslint.js</em></strong></a> from the JSLint home page. There is no executable binary for JSLint, it is just a JavaScript file with set of rules and function to execute verification. Our working environment is Windows we can execute validation using <strong><em>cscript.exe</em></strong> command line tool that Windows has. There is a very useful script created by <strong><em>Jason Diamond </em></strong>that helps to execute JSLint validation. You can get it from from here: <a href="http://jason.diamond.name/downloads/jslint.wsf" onclick="javascript:pageTracker._trackPageview('/outbound/article/jason.diamond.name');" target="_blank"><strong><em>jslint.wsf</em></strong></a><strong><em>. </em></strong>One last thing is a command line batch file that helps execute this tool. You can name it whatever you would like to. I named it <strong><em>jslint.bat. </em></strong>The content of it looks like this:</p>
<blockquote><pre><strong>@cscript //nologo %~dp0\jslint.wsf %*</strong></pre>
</blockquote>
<p>I put all those three files into build tree, in tools folder. You can check if all the files are valid and working properly by running this command from command line:</p>
<blockquote>
<p><strong>jslint.bat c:\path\to\your\js\file.js</strong></p>
</blockquote>
<h2>Create a build target</h2>
<p>Now that we have all the tools we can create a build target. We are using <strong><em><a title="Nant build tool" href="http://nant.sourceforge.net/" onclick="javascript:pageTracker._trackPageview('/outbound/article/nant.sourceforge.net');" target="_blank">Nant</a></em></strong> as a build tool. I created Nant target and called it jslint. It looks like this.</p>
<blockquote>
<p><strong>&lt;target name=&quot;jslint&quot; description=&quot;validates JS files&quot;&gt;<br />
      <br />&#160;&#160;&#160; &lt;foreach item=&quot;File&quot; property=&quot;jsfile&quot;&gt; </p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;in&gt; </p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;items&gt; </p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;include name=&quot;path\to\scripts\folder\**\*.js&quot; /&gt; </p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;/items&gt; </p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;/in&gt; </p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;do&gt; </p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;exec program=&quot;jslint.bat&quot; commandline=&quot;${jsfile}&quot; /&gt; </p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;/do&gt; </p>
<p>&#160;&#160;&#160; &lt;/foreach&gt; </p>
<p>&lt;/target&gt;</strong></p>
</blockquote>
<p>There is a lot of stuff that could be turned on/off during validation. If you type <strong><em>jslint.bat </em></strong>without any parameters it will give you a list of possible options. Those could as well be tweaked in the <a href="http://jason.diamond.name/downloads/jslint.wsf" onclick="javascript:pageTracker._trackPageview('/outbound/article/jason.diamond.name');" target="_blank"><strong><em>jslint.wsf</em></strong></a> file.</p>
<p>Hope this helps you as it did for us.</p>
<p>Some says that JSLint might hurt your feelings. I say, bring it on <img src='http://blog.gigoo.org/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Gregster</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.gigoo.org/2009/03/25/verify-javascript-with-jslint-during-build-using-nant/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
