Skip to content

Instantly share code, notes, and snippets.

@kshwetabh
Created June 20, 2014 06:48
Show Gist options
  • Save kshwetabh/d7b613546735db5821dd to your computer and use it in GitHub Desktop.
Save kshwetabh/d7b613546735db5821dd to your computer and use it in GitHub Desktop.
Ant based task to Lint the modified files with JSHint.
<?xml version="1.0" encoding="UTF-8"?>
<!-- @author Kumar Shwetabh, @version 1.0 -->
<!-- Based upon https://github.com/philmander/ant-jshint -->
<!-- Add reference to http://jslinterrors.com in the reports file -->
<project name="LintTasks" default="LintTasks" basedir=".">
<property name="FilesToLint" value="C:/LintFiles"/>
<property name="ReportFile" value="${basedir}/jshint/results.html"/>
<target name="LintTasks">
<!--<antcall target="SetupForLint"/>-->
<antcall target="CopyFilesToLint"/>
<antcall target="runJsHint"/>
<antcall target="DisplayJSHintReport"/>
</target>
<target name="SetupForLint">
<!-- Cleanup the FilesToLint directory -->
<echo>Cleaning up the ${FilesToLint} directory</echo>
<delete includeEmptyDirs="false">
<fileset dir="${FilesToLint}"/>
</delete>
<!-- Delete the old JSHint reports file-->
<!--<delete file="${basedir}/jshint/results.xml"/>-->
</target>
<target name="CopyFilesToLint">
<echo>Copying the modified files to ${FilesToLint}</echo>
<copy todir="${FilesToLint}" flatten="true">
<fileset dir="./src/main/webapp">
<modified update="true"
seldirs="false"
cache="propertyfile"
algorithm="digest"
comparator="equal">
<param name="cache.cachefile" value="cache.properties"/>
<param name="algorithm.algorithm" value="MD5"/>
</modified>
</fileset>
</copy>
<mkdir dir="${FilesToLint}"/>
</target>
<!-- Define the task -->
<taskdef name="jshint" classname="com.philmander.jshint.JsHintAntTask"
classpath="${basedir}/jshint/ant-jshint-0.3.6-SNAPSHOT-deps.jar" />
<target name="runJsHint">
<!-- Lint the code -->
<echo>Linting the files in ${FilesToLint}</echo>
<jshint dir="${FilesToLint}" fail="false"
optionsFile="${basedir}/jshint/options.properties"
globalsFile="${basedir}/jshint/globals.properties">
<include name="**/*.js"/>
<exclude name="**/*.min.js"/>
<report type="html" destFile="${ReportFile}" />
</jshint>
</target>
<target name="DisplayJSHintReport">
<echo>Displaying JSHint Report...</echo>
<!-- Modify the install path of browser if needed -->
<exec executable="C:\Program Files (x86)\Google\Chrome\Application\chrome.exe">
<arg value="${ReportFile}" />
</exec>
</target>
</project>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment