Skip to content
This repository
Browse code

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...
commit b2ae467eeb5e63f55233dcb8fc17514837a9405b 1 parent 902df25
Scott Hunter authored February 14, 2013
9  .project
@@ -86,6 +86,15 @@
86 86
 			</matcher>
87 87
 		</filter>
88 88
 		<filter>
  89
+			<id>1360870693679</id>
  90
+			<name>Apps/Sandcastle</name>
  91
+			<type>6</type>
  92
+			<matcher>
  93
+				<id>org.eclipse.ui.ide.multiFilter</id>
  94
+				<arguments>1.0-name-matches-false-false-jsHintOptions.js</arguments>
  95
+			</matcher>
  96
+		</filter>
  97
+		<filter>
89 98
 			<id>1338843689105</id>
90 99
 			<name>Source/Shaders</name>
91 100
 			<type>22</type>
1  Apps/Sandcastle/.gitignore
... ...
@@ -0,0 +1 @@
  1
+/jsHintOptions.js
63  Apps/Sandcastle/CesiumSandcastle.js
... ...
@@ -1,4 +1,6 @@
1  
-/*global require,Blob,CodeMirror,JSHINT,gallery_demos*/
  1
+/*global require,Blob,CodeMirror,JSHINT*/
  2
+/*global gallery_demos*/// defined by gallery/gallery-index.js, created by build
  3
+/*global sandcastleJsHintOptions*/// defined by jsHintOptions.js, created by build
2 4
 require({
3 5
     baseUrl : '../../Source',
4 6
     packages : [{
@@ -131,63 +133,6 @@ require({
131 133
     var highlightLines = [];
132 134
     var searchTerm = '';
133 135
     var searchRegExp;
134  
-    var hintGlobals = [
135  
-                       'require',
136  
-                       'document',
137  
-                       'window',
138  
-                       'console',
139  
-                       'Sandcastle',
140  
-                       'Cesium'
141  
-                      ];
142  
-    var hintOptions = {
143  
-        predef : hintGlobals,
144  
-        // These are copied from the Eclipse jsHint plugin options on the Cesium project itself.
145  
-        // They should be kept in sync with that list of options.
146  
-        bitwise : false,
147  
-        camelcase : false,
148  
-        curly : true,
149  
-        eqeqeq : true,
150  
-        forin : true,
151  
-        immed : false,
152  
-        latedef : true,
153  
-        newcap : true,
154  
-        noarg : true,
155  
-        noempty : false,
156  
-        nonew : true,
157  
-        plusplus : false,
158  
-        quotmark : false,
159  
-        regexp : false,
160  
-        undef : true,
161  
-        unused : false,
162  
-        strict : true,
163  
-        trailing : true,
164  
-        asi : false,
165  
-        boss : false,
166  
-        debug : false,
167  
-        eqnull : false,
168  
-        es5 : false,
169  
-        esnext : false,
170  
-        evil : false,
171  
-        expr : false,
172  
-        funcscope : false,
173  
-        globalstrict : false,
174  
-        iterator : false,
175  
-        lastsemic : false,
176  
-        laxbreak : false,
177  
-        laxcomma : false,
178  
-        loopfunc : false,
179  
-        multistr : false,
180  
-        onecase : false,
181  
-        proto : false,
182  
-        regexdash : false,
183  
-        scripturl : false,
184  
-        smarttabs : false,
185  
-        shadow : false,
186  
-        sub : false,
187  
-        supernew : false,
188  
-        validthis : false,
189  
-        browser : true
190  
-    };
191 136
     var hintTimer;
192 137
 
193 138
     var galleryErrorMsg = document.createElement('span');
@@ -373,7 +318,7 @@ require({
373 318
                 }
374 319
             }
375 320
         }
376  
-        if (!JSHINT(code, hintOptions)) {
  321
+        if (!JSHINT(code, sandcastleJsHintOptions)) {
377 322
             var hints = JSHINT.errors;
378 323
             for (i = 0, len = hints.length; i < len; ++i) {
379 324
                 var hint = hints[i];
5  Apps/Sandcastle/index.html
@@ -27,10 +27,11 @@
27 27
     <script src="../../ThirdParty/CodeMirror-2.24/mode/xml/xml.js"></script>
28 28
     <script src="../../ThirdParty/CodeMirror-2.24/mode/htmlmixed/htmlmixed.js"></script>
29 29
 
30  
-    <script data-dojo-config="async: 1, tlmSiblingOfDojo: 0" src="../../ThirdParty/dojo-release-1.8.3-src/dojo/dojo.js"> </script>
  30
+    <script data-dojo-config="async: 1, tlmSiblingOfDojo: 0" src="../../ThirdParty/dojo-release-1.8.3-src/dojo/dojo.js"></script>
31 31
 
  32
+    <script src="jsHintOptions.js"></script>
32 33
     <script src="gallery/gallery-index.js"></script>
33  
-    <script src="CesiumSandcastle.js"> </script>
  34
+    <script src="CesiumSandcastle.js"></script>
34 35
     <script type="text/javascript">
35 36
         if (window.location.host === "cesium.agi.com") {
36 37
             var _gaq = _gaq || [];
26  Tools/buildTasks/createSandcastleJsHintOptions.js
... ...
@@ -0,0 +1,26 @@
  1
+/*global importClass,project,attributes,elements,java,Packages*/
  2
+/*jshint multistr:true,evil:true*/
  3
+importClass(java.io.File); /*global File*/
  4
+importClass(java.io.FileReader); /*global FileReader*/
  5
+importClass(java.io.FileWriter); /*global FileWriter*/
  6
+importClass(Packages.org.apache.tools.ant.util.FileUtils); /*global FileUtils*/
  7
+
  8
+var jsHintOptions = eval('({' + attributes.get('jshintoptions') + '})');
  9
+jsHintOptions.predef = ['require', 'console', 'Sandcastle', 'Cesium'];
  10
+
  11
+var output = attributes.get("output");
  12
+if (new File(output).exists()) {
  13
+    var reader = new FileReader(output);
  14
+    var oldContents = String(FileUtils.readFully(reader));
  15
+    reader.close();
  16
+}
  17
+
  18
+var contents = '\
  19
+// This file is automatically rebuilt by the Cesium build process.\n\
  20
+var sandcastleJsHintOptions = ' + JSON.stringify(jsHintOptions, null, 2) + ';';
  21
+
  22
+if (oldContents !== contents) {
  23
+    var writer = new FileWriter(output);
  24
+    writer.write(contents);
  25
+    writer.close();
  26
+}
24  Tools/buildTasks/runJsHint.js
@@ -14,8 +14,16 @@ var load = Main.global.load;
14 14
 load(jsHintPath); /*global JSHINT*/
15 15
 
16 16
 var jsHintOptions = eval('({' + attributes.get('jshintoptions') + '})');
  17
+
  18
+var sandcastleJsHintOptionsPath = attributes.get('sandcastlejshintoptionspath');
  19
+load(sandcastleJsHintOptionsPath);/*global sandcastleJsHintOptions*/
  20
+
17 21
 var errors = [];
18 22
 
  23
+var jsFileRegex = /\.js$/i;
  24
+var htmlFileRegex = /\.html$/i;
  25
+var sandcastleScriptRegex = /<script id="cesium_sandcastle_script">([\S\s]*?)<\/script>/img;
  26
+
19 27
 var sourceFilesets = elements.get('sourcefiles');
20 28
 for ( var i = 0, len = sourceFilesets.size(); i < len; ++i) {
21 29
     var sourceFileset = sourceFilesets.get(i);
@@ -34,7 +42,21 @@ for ( var i = 0, len = sourceFilesets.size(); i < len; ++i) {
34 42
         var contents = String(FileUtils.readFully(reader));
35 43
         reader.close();
36 44
 
37  
-        if (!JSHINT(contents, jsHintOptions)) {
  45
+        var source;
  46
+        var options;
  47
+        if (jsFileRegex.test(sourceFilename)) {
  48
+            source = contents;
  49
+            options = jsHintOptions;
  50
+        } else if (htmlFileRegex.test(sourceFilename)) {
  51
+            var result = sandcastleScriptRegex.exec(contents);
  52
+            if (result === null) {
  53
+                continue;
  54
+            }
  55
+            source = result[1];
  56
+            options = sandcastleJsHintOptions;
  57
+        }
  58
+
  59
+        if (!JSHINT(source, options)) {
38 60
             JSHINT.errors.forEach(function(error) {
39 61
                 if (error) {
40 62
                     errors.push(sourceFilename + ': line ' + error.line + ', col ' + error.character + ', ' + error.reason);
88  build.xml
@@ -5,25 +5,25 @@
5 5
 			<existingjsfiles dir="${shadersDirectory}" includes="**/*.js" excludes="*.profile.js" />
6 6
 		</glslToJavascript>
7 7
 
8  
-		<parallel>
9  
-			<createCesiumJs output="${sourceDirectory}/Cesium.js">
10  
-				<sourcefiles dir="${sourceDirectory}">
11  
-					<include name="**/*.js" />
12  
-					<exclude name="*.js" />
13  
-					<exclude name="Widgets/**" />
14  
-					<exclude name="Workers/**" />
15  
-					<exclude name="**/*.profile.js" />
16  
-				</sourcefiles>
17  
-			</createCesiumJs>
18  
-
19  
-			<createSpecList output="${specsDirectory}/SpecList.js">
20  
-				<specs dir="${specsDirectory}" includes="**/*.js" excludes="*.js" />
21  
-			</createSpecList>
22  
-
23  
-			<createGalleryList output="${galleryDirectory}/gallery-index.js">
24  
-				<demos dir="${galleryDirectory}" includes="**/*.html" />
25  
-			</createGalleryList>
26  
-		</parallel>
  8
+		<createCesiumJs output="${sourceDirectory}/Cesium.js">
  9
+			<sourcefiles dir="${sourceDirectory}">
  10
+				<include name="**/*.js" />
  11
+				<exclude name="*.js" />
  12
+				<exclude name="Widgets/**" />
  13
+				<exclude name="Workers/**" />
  14
+				<exclude name="**/*.profile.js" />
  15
+			</sourcefiles>
  16
+		</createCesiumJs>
  17
+
  18
+		<createSpecList output="${specsDirectory}/SpecList.js">
  19
+			<specs dir="${specsDirectory}" includes="**/*.js" excludes="*.js" />
  20
+		</createSpecList>
  21
+
  22
+		<createGalleryList output="${galleryDirectory}/gallery-index.js">
  23
+			<demos dir="${galleryDirectory}" includes="**/*.html" />
  24
+		</createGalleryList>
  25
+
  26
+		<createSandcastleJsHintOptions output="${sandcastleDirectory}/jsHintOptions.js" jshintoptions="${jsHintEclipseSettings.options}" />
27 27
 	</target>
28 28
 
29 29
 	<target name="combine" description="Combines all source files into a single stand-alone script." depends="build, combineJavaScript" />
@@ -87,7 +87,8 @@
87 87
 	<property name="sourceDirectory" location="Source" />
88 88
 	<property name="shadersDirectory" location="${sourceDirectory}/Shaders" />
89 89
 	<property name="examplesDirectory" location="Examples" />
90  
-	<property name="galleryDirectory" location="Apps/Sandcastle/gallery" />
  90
+	<property name="sandcastleDirectory" location="Apps/Sandcastle" />
  91
+	<property name="galleryDirectory" location="${sandcastleDirectory}/gallery" />
91 92
 	<property name="specsDirectory" location="Specs" />
92 93
 	<property name="toolsDirectory" location="Tools" />
93 94
 	<property name="tasksDirectory" location="${toolsDirectory}/buildTasks" />
@@ -109,44 +110,54 @@
109 110
 	<property name="buildDocumentationImagesDirectory" location="${buildDocumentationDirectory}/images" />
110 111
 	<property name="instrumentedDirectory" location="Instrumented" />
111 112
 
112  
-	<scriptdef name="glslToJavascript" language="javascript" src="${tasksDirectory}/glslToJavaScript.js">
  113
+	<path id="javascriptClassPath">
  114
+		<pathelement path="${toolsDirectory}/rhino-1.7R4/js.jar" />
  115
+		<pathelement path="${toolsDirectory}/bsf-2.4.0/bsf.jar" />
  116
+		<pathelement path="${toolsDirectory}/commons-logging-1.1.1/commons-logging-1.1.1.jar" />
  117
+	</path>
  118
+
  119
+	<scriptdef name="glslToJavascript" language="javascript" src="${tasksDirectory}/glslToJavaScript.js" manager="bsf" classpathref="javascriptClassPath" loaderref="javascript.loader">
113 120
 		<attribute name="stripcomments" />
114 121
 		<element name="glslfiles" type="fileset" />
115 122
 		<element name="existingjsfiles" type="fileset" />
116 123
 	</scriptdef>
117 124
 
118  
-	<scriptdef name="extractShaderComments" language="javascript" src="${tasksDirectory}/extractShaderComments.js">
  125
+	<scriptdef name="extractShaderComments" language="javascript" src="${tasksDirectory}/extractShaderComments.js" manager="bsf" classpathref="javascriptClassPath" loaderref="javascript.loader">
119 126
 		<element name="glslfiles" type="fileset" />
120 127
 	</scriptdef>
121 128
 
122  
-	<scriptdef name="createCesiumJs" language="javascript" src="${tasksDirectory}/createCesiumJs.js">
  129
+	<scriptdef name="createCesiumJs" language="javascript" src="${tasksDirectory}/createCesiumJs.js" manager="bsf" classpathref="javascriptClassPath" loaderref="javascript.loader">
123 130
 		<attribute name="output" />
124 131
 		<element name="sourcefiles" type="fileset" />
125 132
 	</scriptdef>
126 133
 
127  
-	<scriptdef name="createSpecList" language="javascript" src="${tasksDirectory}/createSpecList.js">
  134
+	<scriptdef name="createSpecList" language="javascript" src="${tasksDirectory}/createSpecList.js" manager="bsf" classpathref="javascriptClassPath" loaderref="javascript.loader">
128 135
 		<attribute name="output" />
129 136
 		<element name="specs" type="fileset" />
130 137
 	</scriptdef>
131 138
 
132  
-	<scriptdef name="createGalleryList" language="javascript" src="${tasksDirectory}/createGalleryList.js">
  139
+	<scriptdef name="createGalleryList" language="javascript" src="${tasksDirectory}/createGalleryList.js" manager="bsf" classpathref="javascriptClassPath" loaderref="javascript.loader">
133 140
 		<attribute name="output" />
134 141
 		<element name="demos" type="fileset" />
135 142
 	</scriptdef>
136 143
 
137  
-	<target name="jsHint">
138  
-		<scriptdef name="runJsHint" language="javascript" src="${tasksDirectory}/runJsHint.js" manager="bsf">
139  
-			<attribute name="jshintpath" />
140  
-			<attribute name="jshintoptions" />
141  
-			<attribute name="failureproperty" />
142  
-			<element name="sourcefiles" type="fileset" />
143  
-			<classpath path="${toolsDirectory}/rhino-1.7R4/js.jar" />
144  
-			<classpath path="${toolsDirectory}/bsf-2.4.0/bsf.jar" />
145  
-			<classpath path="${toolsDirectory}/commons-logging-1.1.1/commons-logging-1.1.1.jar" />
146  
-		</scriptdef>
147  
-
148  
-		<property file="${basedir}/.settings/com.eclipsesource.jshint.ui.prefs" prefix="jsHintEclipseSettings" />
149  
-		<runJsHint jshintpath="${jsHintPath}" jshintoptions="${jsHintEclipseSettings.options}" failureproperty="jsHint.failure">
  144
+	<scriptdef name="createSandcastleJsHintOptions" language="javascript" src="${tasksDirectory}/createSandcastleJsHintOptions.js" manager="bsf" classpathref="javascriptClassPath" loaderref="javascript.loader">
  145
+		<attribute name="output" />
  146
+		<attribute name="jshintoptions" />
  147
+	</scriptdef>
  148
+
  149
+	<scriptdef name="runJsHint" language="javascript" src="${tasksDirectory}/runJsHint.js" manager="bsf" classpathref="javascriptClassPath" loaderref="javascript.loader">
  150
+		<attribute name="jshintpath" />
  151
+		<attribute name="jshintoptions" />
  152
+		<attribute name="sandcastlejshintoptionspath" />
  153
+		<attribute name="failureproperty" />
  154
+		<element name="sourcefiles" type="fileset" />
  155
+	</scriptdef>
  156
+
  157
+	<property file="${basedir}/.settings/com.eclipsesource.jshint.ui.prefs" prefix="jsHintEclipseSettings" />
  158
+
  159
+	<target name="jsHint" depends="build">
  160
+		<runJsHint jshintpath="${jsHintPath}" jshintoptions="${jsHintEclipseSettings.options}" sandcastlejshintoptionspath="${sandcastleDirectory}/jsHintOptions.js" failureproperty="jsHint.failure">
150 161
 			<sourcefiles dir="${basedir}">
151 162
 				<include name="Source/**/*.js" />
152 163
 				<exclude name="Source/Shaders/**" />
@@ -154,6 +165,7 @@
154 165
 				<exclude name="Source/Workers/cesiumWorkerBootstrapper.js" />
155 166
 
156 167
 				<include name="Apps/**/*.js" />
  168
+				<include name="Apps/Sandcastle/gallery/*.html" />
157 169
 				<exclude name="Apps/Sandcastle/Cesium-hint.js" />
158 170
 
159 171
 				<include name="Specs/**/*.js" />

0 notes on commit b2ae467

Please sign in to comment.
Something went wrong with that request. Please try again.