Permalink
Browse files

Run JSHint on the scripts in Sandcastle examples too.

This also builds the JSHint options for Sandcastle as part of the build process so that they stay in sync with the Eclipse JSHint settings.
  • Loading branch information...
shunter committed Feb 14, 2013
1 parent 902df25 commit b2ae467eeb5e63f55233dcb8fc17514837a9405b
View
@@ -85,6 +85,15 @@
<arguments>1.0-name-matches-false-false-buildTasks</arguments>
</matcher>
</filter>
+ <filter>
+ <id>1360870693679</id>
+ <name>Apps/Sandcastle</name>
+ <type>6</type>
+ <matcher>
+ <id>org.eclipse.ui.ide.multiFilter</id>
+ <arguments>1.0-name-matches-false-false-jsHintOptions.js</arguments>
+ </matcher>
+ </filter>
<filter>
<id>1338843689105</id>
<name>Source/Shaders</name>
@@ -0,0 +1 @@
+/jsHintOptions.js
@@ -1,4 +1,6 @@
-/*global require,Blob,CodeMirror,JSHINT,gallery_demos*/
+/*global require,Blob,CodeMirror,JSHINT*/
+/*global gallery_demos*/// defined by gallery/gallery-index.js, created by build
+/*global sandcastleJsHintOptions*/// defined by jsHintOptions.js, created by build
require({
baseUrl : '../../Source',
packages : [{
@@ -131,63 +133,6 @@ require({
var highlightLines = [];
var searchTerm = '';
var searchRegExp;
- var hintGlobals = [
- 'require',
- 'document',
- 'window',
- 'console',
- 'Sandcastle',
- 'Cesium'
- ];
- var hintOptions = {
- predef : hintGlobals,
- // These are copied from the Eclipse jsHint plugin options on the Cesium project itself.
- // They should be kept in sync with that list of options.
- bitwise : false,
- camelcase : false,
- curly : true,
- eqeqeq : true,
- forin : true,
- immed : false,
- latedef : true,
- newcap : true,
- noarg : true,
- noempty : false,
- nonew : true,
- plusplus : false,
- quotmark : false,
- regexp : false,
- undef : true,
- unused : false,
- strict : true,
- trailing : true,
- asi : false,
- boss : false,
- debug : false,
- eqnull : false,
- es5 : false,
- esnext : false,
- evil : false,
- expr : false,
- funcscope : false,
- globalstrict : false,
- iterator : false,
- lastsemic : false,
- laxbreak : false,
- laxcomma : false,
- loopfunc : false,
- multistr : false,
- onecase : false,
- proto : false,
- regexdash : false,
- scripturl : false,
- smarttabs : false,
- shadow : false,
- sub : false,
- supernew : false,
- validthis : false,
- browser : true
- };
var hintTimer;
var galleryErrorMsg = document.createElement('span');
@@ -373,7 +318,7 @@ require({
}
}
}
- if (!JSHINT(code, hintOptions)) {
+ if (!JSHINT(code, sandcastleJsHintOptions)) {
var hints = JSHINT.errors;
for (i = 0, len = hints.length; i < len; ++i) {
var hint = hints[i];
@@ -27,10 +27,11 @@
<script src="../../ThirdParty/CodeMirror-2.24/mode/xml/xml.js"></script>
<script src="../../ThirdParty/CodeMirror-2.24/mode/htmlmixed/htmlmixed.js"></script>
- <script data-dojo-config="async: 1, tlmSiblingOfDojo: 0" src="../../ThirdParty/dojo-release-1.8.3-src/dojo/dojo.js"> </script>
+ <script data-dojo-config="async: 1, tlmSiblingOfDojo: 0" src="../../ThirdParty/dojo-release-1.8.3-src/dojo/dojo.js"></script>
+ <script src="jsHintOptions.js"></script>
<script src="gallery/gallery-index.js"></script>
- <script src="CesiumSandcastle.js"> </script>
+ <script src="CesiumSandcastle.js"></script>
<script type="text/javascript">
if (window.location.host === "cesium.agi.com") {
var _gaq = _gaq || [];
@@ -0,0 +1,26 @@
+/*global importClass,project,attributes,elements,java,Packages*/
+/*jshint multistr:true,evil:true*/
+importClass(java.io.File); /*global File*/
+importClass(java.io.FileReader); /*global FileReader*/
+importClass(java.io.FileWriter); /*global FileWriter*/
+importClass(Packages.org.apache.tools.ant.util.FileUtils); /*global FileUtils*/
+
+var jsHintOptions = eval('({' + attributes.get('jshintoptions') + '})');
+jsHintOptions.predef = ['require', 'console', 'Sandcastle', 'Cesium'];
+
+var output = attributes.get("output");
+if (new File(output).exists()) {
+ var reader = new FileReader(output);
+ var oldContents = String(FileUtils.readFully(reader));
+ reader.close();
+}
+
+var contents = '\
+// This file is automatically rebuilt by the Cesium build process.\n\
+var sandcastleJsHintOptions = ' + JSON.stringify(jsHintOptions, null, 2) + ';';
+
+if (oldContents !== contents) {
+ var writer = new FileWriter(output);
+ writer.write(contents);
+ writer.close();
+}
@@ -14,8 +14,16 @@ var load = Main.global.load;
load(jsHintPath); /*global JSHINT*/
var jsHintOptions = eval('({' + attributes.get('jshintoptions') + '})');
+
+var sandcastleJsHintOptionsPath = attributes.get('sandcastlejshintoptionspath');
+load(sandcastleJsHintOptionsPath);/*global sandcastleJsHintOptions*/
+
var errors = [];
+var jsFileRegex = /\.js$/i;
+var htmlFileRegex = /\.html$/i;
+var sandcastleScriptRegex = /<script id="cesium_sandcastle_script">([\S\s]*?)<\/script>/img;
+
var sourceFilesets = elements.get('sourcefiles');
for ( var i = 0, len = sourceFilesets.size(); i < len; ++i) {
var sourceFileset = sourceFilesets.get(i);
@@ -34,7 +42,21 @@ for ( var i = 0, len = sourceFilesets.size(); i < len; ++i) {
var contents = String(FileUtils.readFully(reader));
reader.close();
- if (!JSHINT(contents, jsHintOptions)) {
+ var source;
+ var options;
+ if (jsFileRegex.test(sourceFilename)) {
+ source = contents;
+ options = jsHintOptions;
+ } else if (htmlFileRegex.test(sourceFilename)) {
+ var result = sandcastleScriptRegex.exec(contents);
+ if (result === null) {
+ continue;
+ }
+ source = result[1];
+ options = sandcastleJsHintOptions;
+ }
+
+ if (!JSHINT(source, options)) {
JSHINT.errors.forEach(function(error) {
if (error) {
errors.push(sourceFilename + ': line ' + error.line + ', col ' + error.character + ', ' + error.reason);
View
@@ -5,25 +5,25 @@
<existingjsfiles dir="${shadersDirectory}" includes="**/*.js" excludes="*.profile.js" />
</glslToJavascript>
- <parallel>
- <createCesiumJs output="${sourceDirectory}/Cesium.js">
- <sourcefiles dir="${sourceDirectory}">
- <include name="**/*.js" />
- <exclude name="*.js" />
- <exclude name="Widgets/**" />
- <exclude name="Workers/**" />
- <exclude name="**/*.profile.js" />
- </sourcefiles>
- </createCesiumJs>
-
- <createSpecList output="${specsDirectory}/SpecList.js">
- <specs dir="${specsDirectory}" includes="**/*.js" excludes="*.js" />
- </createSpecList>
-
- <createGalleryList output="${galleryDirectory}/gallery-index.js">
- <demos dir="${galleryDirectory}" includes="**/*.html" />
- </createGalleryList>
- </parallel>
+ <createCesiumJs output="${sourceDirectory}/Cesium.js">
+ <sourcefiles dir="${sourceDirectory}">
+ <include name="**/*.js" />
+ <exclude name="*.js" />
+ <exclude name="Widgets/**" />
+ <exclude name="Workers/**" />
+ <exclude name="**/*.profile.js" />
+ </sourcefiles>
+ </createCesiumJs>
+
+ <createSpecList output="${specsDirectory}/SpecList.js">
+ <specs dir="${specsDirectory}" includes="**/*.js" excludes="*.js" />
+ </createSpecList>
+
+ <createGalleryList output="${galleryDirectory}/gallery-index.js">
+ <demos dir="${galleryDirectory}" includes="**/*.html" />
+ </createGalleryList>
+
+ <createSandcastleJsHintOptions output="${sandcastleDirectory}/jsHintOptions.js" jshintoptions="${jsHintEclipseSettings.options}" />
</target>
<target name="combine" description="Combines all source files into a single stand-alone script." depends="build, combineJavaScript" />
@@ -87,7 +87,8 @@
<property name="sourceDirectory" location="Source" />
<property name="shadersDirectory" location="${sourceDirectory}/Shaders" />
<property name="examplesDirectory" location="Examples" />
- <property name="galleryDirectory" location="Apps/Sandcastle/gallery" />
+ <property name="sandcastleDirectory" location="Apps/Sandcastle" />
+ <property name="galleryDirectory" location="${sandcastleDirectory}/gallery" />
<property name="specsDirectory" location="Specs" />
<property name="toolsDirectory" location="Tools" />
<property name="tasksDirectory" location="${toolsDirectory}/buildTasks" />
@@ -109,51 +110,62 @@
<property name="buildDocumentationImagesDirectory" location="${buildDocumentationDirectory}/images" />
<property name="instrumentedDirectory" location="Instrumented" />
- <scriptdef name="glslToJavascript" language="javascript" src="${tasksDirectory}/glslToJavaScript.js">
+ <path id="javascriptClassPath">
+ <pathelement path="${toolsDirectory}/rhino-1.7R4/js.jar" />
+ <pathelement path="${toolsDirectory}/bsf-2.4.0/bsf.jar" />
+ <pathelement path="${toolsDirectory}/commons-logging-1.1.1/commons-logging-1.1.1.jar" />
+ </path>
+
+ <scriptdef name="glslToJavascript" language="javascript" src="${tasksDirectory}/glslToJavaScript.js" manager="bsf" classpathref="javascriptClassPath" loaderref="javascript.loader">
<attribute name="stripcomments" />
<element name="glslfiles" type="fileset" />
<element name="existingjsfiles" type="fileset" />
</scriptdef>
- <scriptdef name="extractShaderComments" language="javascript" src="${tasksDirectory}/extractShaderComments.js">
+ <scriptdef name="extractShaderComments" language="javascript" src="${tasksDirectory}/extractShaderComments.js" manager="bsf" classpathref="javascriptClassPath" loaderref="javascript.loader">
<element name="glslfiles" type="fileset" />
</scriptdef>
- <scriptdef name="createCesiumJs" language="javascript" src="${tasksDirectory}/createCesiumJs.js">
+ <scriptdef name="createCesiumJs" language="javascript" src="${tasksDirectory}/createCesiumJs.js" manager="bsf" classpathref="javascriptClassPath" loaderref="javascript.loader">
<attribute name="output" />
<element name="sourcefiles" type="fileset" />
</scriptdef>
- <scriptdef name="createSpecList" language="javascript" src="${tasksDirectory}/createSpecList.js">
+ <scriptdef name="createSpecList" language="javascript" src="${tasksDirectory}/createSpecList.js" manager="bsf" classpathref="javascriptClassPath" loaderref="javascript.loader">
<attribute name="output" />
<element name="specs" type="fileset" />
</scriptdef>
- <scriptdef name="createGalleryList" language="javascript" src="${tasksDirectory}/createGalleryList.js">
+ <scriptdef name="createGalleryList" language="javascript" src="${tasksDirectory}/createGalleryList.js" manager="bsf" classpathref="javascriptClassPath" loaderref="javascript.loader">
<attribute name="output" />
<element name="demos" type="fileset" />
</scriptdef>
- <target name="jsHint">
- <scriptdef name="runJsHint" language="javascript" src="${tasksDirectory}/runJsHint.js" manager="bsf">
- <attribute name="jshintpath" />
- <attribute name="jshintoptions" />
- <attribute name="failureproperty" />
- <element name="sourcefiles" type="fileset" />
- <classpath path="${toolsDirectory}/rhino-1.7R4/js.jar" />
- <classpath path="${toolsDirectory}/bsf-2.4.0/bsf.jar" />
- <classpath path="${toolsDirectory}/commons-logging-1.1.1/commons-logging-1.1.1.jar" />
- </scriptdef>
-
- <property file="${basedir}/.settings/com.eclipsesource.jshint.ui.prefs" prefix="jsHintEclipseSettings" />
- <runJsHint jshintpath="${jsHintPath}" jshintoptions="${jsHintEclipseSettings.options}" failureproperty="jsHint.failure">
+ <scriptdef name="createSandcastleJsHintOptions" language="javascript" src="${tasksDirectory}/createSandcastleJsHintOptions.js" manager="bsf" classpathref="javascriptClassPath" loaderref="javascript.loader">
+ <attribute name="output" />
+ <attribute name="jshintoptions" />
+ </scriptdef>
+
+ <scriptdef name="runJsHint" language="javascript" src="${tasksDirectory}/runJsHint.js" manager="bsf" classpathref="javascriptClassPath" loaderref="javascript.loader">
+ <attribute name="jshintpath" />
+ <attribute name="jshintoptions" />
+ <attribute name="sandcastlejshintoptionspath" />
+ <attribute name="failureproperty" />
+ <element name="sourcefiles" type="fileset" />
+ </scriptdef>
+
+ <property file="${basedir}/.settings/com.eclipsesource.jshint.ui.prefs" prefix="jsHintEclipseSettings" />
+
+ <target name="jsHint" depends="build">
+ <runJsHint jshintpath="${jsHintPath}" jshintoptions="${jsHintEclipseSettings.options}" sandcastlejshintoptionspath="${sandcastleDirectory}/jsHintOptions.js" failureproperty="jsHint.failure">
<sourcefiles dir="${basedir}">
<include name="Source/**/*.js" />
<exclude name="Source/Shaders/**" />
<exclude name="Source/ThirdParty/**" />
<exclude name="Source/Workers/cesiumWorkerBootstrapper.js" />
<include name="Apps/**/*.js" />
+ <include name="Apps/Sandcastle/gallery/*.html" />
<exclude name="Apps/Sandcastle/Cesium-hint.js" />
<include name="Specs/**/*.js" />

0 comments on commit b2ae467

Please sign in to comment.