Skip to content

Commit 974a263

Browse files
authored
style: add jshint, resolve #63 (#65)
close #63
1 parent 2d632cf commit 974a263

25 files changed

+206
-87
lines changed

.jshintrc

+98
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
{
2+
// JSHint Default Configuration File (as on JSHint website)
3+
// See http://jshint.com/docs/ for more details
4+
5+
"maxerr" : 50, // {int} Maximum error before stopping
6+
7+
// Enforcing
8+
"bitwise" : false, // true: Prohibit bitwise operators (&, |, ^, etc.)
9+
"camelcase" : false, // true: Identifiers must be in camelCase
10+
"curly" : false, // true: Require {} for every new block or scope
11+
"eqeqeq" : false, // true: Require triple equals (===) for comparison
12+
"forin" : false, // true: Require filtering for..in loops with obj.hasOwnProperty()
13+
"freeze" : true, // true: prohibits overwriting prototypes of native objects such as Array, Date etc.
14+
"immed" : false, // true: Require immediate invocations to be wrapped in parens e.g. `(function () { } ());`
15+
"latedef" : false, // true: Require variables/functions to be defined before being used
16+
"newcap" : false, // true: Require capitalization of all constructor functions e.g. `new F()`
17+
"noarg" : true, // true: Prohibit use of `arguments.caller` and `arguments.callee`
18+
"noempty" : true, // true: Prohibit use of empty blocks
19+
"nonbsp" : true, // true: Prohibit "non-breaking whitespace" characters.
20+
"nonew" : false, // true: Prohibit use of constructors for side-effects (without assignment)
21+
"plusplus" : false, // true: Prohibit use of `++` and `--`
22+
"quotmark" : false, // Quotation mark consistency:
23+
// false : do nothing (default)
24+
// true : ensure whatever is used is consistent
25+
// "single" : require single quotes
26+
// "double" : require double quotes
27+
"undef" : true, // true: Require all non-global variables to be declared (prevents global leaks)
28+
"unused" : "vars", // Unused variables:
29+
// true : all variables, last function parameter
30+
// "vars" : all variables only
31+
// "strict" : all variables, all function parameters
32+
"strict" : false, // true: Requires all functions run in ES5 Strict Mode
33+
"maxparams" : false, // {int} Max number of formal params allowed per function
34+
"maxdepth" : false, // {int} Max depth of nested blocks (within functions)
35+
"maxstatements" : false, // {int} Max number statements per function
36+
"maxcomplexity" : false, // {int} Max cyclomatic complexity per function
37+
"maxlen" : false, // {int} Max number of characters per line
38+
"varstmt" : false, // true: Disallow any var statements. Only `let` and `const` are allowed.
39+
40+
// Relaxing
41+
"asi" : false, // true: Tolerate Automatic Semicolon Insertion (no semicolons)
42+
"boss" : true, // true: Tolerate assignments where comparisons would be expected
43+
"debug" : false, // true: Allow debugger statements e.g. browser breakpoints.
44+
"eqnull" : true, // true: Tolerate use of `== null`
45+
"esversion" : 5, // {int} Specify the ECMAScript version to which the code must adhere.
46+
"moz" : false, // true: Allow Mozilla specific syntax (extends and overrides esnext features)
47+
// (ex: `for each`, multiple try/catch, function expression…)
48+
"evil" : false, // true: Tolerate use of `eval` and `new Function()`
49+
"expr" : true, // true: Tolerate `ExpressionStatement` as Programs
50+
"funcscope" : false, // true: Tolerate defining variables inside control statements
51+
"globalstrict" : false, // true: Allow global "use strict" (also enables 'strict')
52+
"iterator" : false, // true: Tolerate using the `__iterator__` property
53+
"lastsemic" : false, // true: Tolerate omitting a semicolon for the last statement of a 1-line block
54+
"laxbreak" : false, // true: Tolerate possibly unsafe line breakings
55+
"laxcomma" : false, // true: Tolerate comma-first style coding
56+
"loopfunc" : false, // true: Tolerate functions being defined in loops
57+
"multistr" : true, // true: Tolerate multi-line strings
58+
"noyield" : false, // true: Tolerate generator functions with no yield statement in them.
59+
"notypeof" : false, // true: Tolerate invalid typeof operator values
60+
"proto" : true, // true: Tolerate using the `__proto__` property
61+
"scripturl" : false, // true: Tolerate script-targeted URLs
62+
"shadow" : false, // true: Allows re-define variables later in code e.g. `var x=1; x=2;`
63+
"sub" : false, // true: Tolerate using `[]` notation when it can still be expressed in dot notation
64+
"supernew" : false, // true: Tolerate `new function () { ... };` and `new Object;`
65+
"validthis" : false, // true: Tolerate using this in a non-constructor function
66+
67+
// Environments
68+
"browser" : true, // Web Browser (window, document, etc)
69+
"browserify" : false, // Browserify (node.js code in the browser)
70+
"couch" : false, // CouchDB
71+
"devel" : true, // Development/debugging (alert, confirm, etc)
72+
"dojo" : false, // Dojo Toolkit
73+
"jasmine" : false, // Jasmine
74+
"jquery" : false, // jQuery
75+
"mocha" : true, // Mocha
76+
"mootools" : false, // MooTools
77+
"node" : false, // Node.js
78+
"nonstandard" : false, // Widely adopted globals (escape, unescape, etc)
79+
"phantom" : false, // PhantomJS
80+
"prototypejs" : false, // Prototype and Scriptaculous
81+
"qunit" : false, // QUnit
82+
"rhino" : false, // Rhino
83+
"shelljs" : false, // ShellJS
84+
"typed" : false, // Globals for typed array constructions
85+
"worker" : false, // Web Workers
86+
"wsh" : false, // Windows Scripting Host
87+
"yui" : false, // Yahoo User Interface
88+
89+
//see https://github.com/jshint/jshint/blob/master/src/messages.js
90+
91+
"-W008":false,
92+
"-W041":false,
93+
"-W014":false,
94+
95+
// Custom Globals
96+
"globals" : {} // additional predefined global variables
97+
98+
}

gulpfile.js

+10-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ var zip = require('gulp-zip');
1212
var shell = require('gulp-shell');
1313
var uitest = require('gulp-uitest');
1414
var transformModule = require('gulp-transform-module');
15-
15+
var jshint = require('gulp-jshint');
1616
var pkg = require('./package.json');
1717

1818
var isWatch = false;
@@ -246,8 +246,16 @@ gulp.task('npm', ['commonjs-format', 'standalone-format'], function(){
246246
return merge(standaloneStream, packageStream);
247247
});
248248

249+
gulp.task('jshint', ['setIsWatch', 'standalone'], function(){
250+
return gulp.src(['build/standalone/hilo/**/*.js', '!build/standalone/hilo/**/*.min.js'])
251+
.pipe(jshint())
252+
.pipe(jshint.reporter('default'))
253+
.pipe(jshint.reporter('fail'))
254+
255+
});
256+
249257
//test
250-
gulp.task('test', ['setIsWatch', 'standalone', 'flash'], function () {
258+
gulp.task('test', ['jshint'], function () {
251259
return gulp
252260
.src('test/html/index.html')
253261
.pipe(uitest({

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"gulp-footer": "^1.0.5",
2121
"gulp-header": "^1.2.2",
2222
"gulp-if": "^1.2.5",
23+
"gulp-jshint": "^2.0.4",
2324
"gulp-rename": "^1.2.2",
2425
"gulp-replace": "~0.5.4",
2526
"gulp-shell": "^0.4.2",

src/core/Class.js

+6-5
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ var create = function(properties){
9393
var clazz = properties.hasOwnProperty('constructor') ? properties.constructor : function(){};
9494
implement.call(clazz, properties);
9595
return clazz;
96-
}
96+
};
9797

9898
/**
9999
* @language=en
@@ -158,13 +158,13 @@ var createProto = (function(){
158158
if(Object.__proto__){
159159
return function(proto){
160160
return {__proto__: proto};
161-
}
161+
};
162162
}else{
163163
var Ctor = function(){};
164164
return function(proto){
165165
Ctor.prototype = proto;
166166
return new Ctor();
167-
}
167+
};
168168
}
169169
})();
170170

@@ -202,9 +202,10 @@ var mix = function(target){
202202
return target;
203203
};
204204

205+
var defineProperty, defineProperties;
205206
try{
206-
var defineProperty = Object.defineProperty,
207-
defineProperties = Object.defineProperties;
207+
defineProperty = Object.defineProperty;
208+
defineProperties = Object.defineProperties;
208209
defineProperty({}, '$', {value:0});
209210
}catch(e){
210211
if('__defineGetter__' in Object){

src/core/Hilo.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ return {
149149
localStorage.setItem(value, value);
150150
localStorage.removeItem(value);
151151
data.supportStorage = true;
152-
}catch(e){ };
152+
}catch(e){}
153153

154154
//vendor prefix
155155
var jsVendor = data.jsVendor = data.webkit ? 'webkit' : data.firefox ? 'moz' : data.opera ? 'o' : data.ie ? 'ms' : '';
@@ -169,7 +169,7 @@ return {
169169
supportTransform3D = testElem.offsetHeight == 3;
170170
doc.head.removeChild(style);
171171
docElem.removeChild(testElem);
172-
};
172+
}
173173
data.supportTransform = supportTransform;
174174
data.supportTransform3D = supportTransform3D;
175175

@@ -258,9 +258,10 @@ return {
258258
* @returns {Object} DOM元素的可视区域。格式为:{left:0, top:0, width:100, height:100}。
259259
*/
260260
getElementRect: function(elem){
261+
var bounds;
261262
try{
262263
//this fails if it's a disconnected DOM node
263-
var bounds = elem.getBoundingClientRect();
264+
bounds = elem.getBoundingClientRect();
264265
}catch(e){
265266
bounds = {top:elem.offsetTop, left:elem.offsetLeft, right:elem.offsetLeft + elem.offsetWidth, bottom:elem.offsetTop + elem.offsetHeight};
266267
}

src/event/EventMixin.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -175,5 +175,5 @@ if(RawEvent){
175175
proto.stopImmediatePropagation = function(){
176176
stop && stop.call(this);
177177
this._stopped = true;
178-
}
178+
};
179179
}

src/game/ParticleSystem.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
* @requires hilo/core/Class
1515
* @requires hilo/view/View
1616
* @requires hilo/view/Container
17-
* @requires hilo/view/Bitmap
1817
* @requires hilo/view/Drawable
1918
* @property {Number} emitTime Emit time interval.
2019
* @property {Number} emitTimeVar Emit time interval variances.
@@ -303,7 +302,7 @@ var ParticleSystem = (function(){
303302
*/
304303
setImage: function(img, frame) {
305304
this.drawable = this.drawable||new Drawable();
306-
var frame = frame || [0, 0, img.width, img.height];
305+
frame = frame || [0, 0, img.width, img.height];
307306

308307
this.width = frame[2];
309308
this.height = frame[3];

src/geom/Matrix.js

+9-3
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,16 @@ var Matrix = Class.create(/** @lends Matrix.prototype */{
5555
a = this.a, b = this.b, c = this.c, d = this.d,
5656
tx = this.tx, ty = this.ty;
5757

58+
var ma, mb, mc, md, mx, my;
5859
if(args.length >= 6){
59-
var ma = args[0], mb = args[1], mc = args[2],
60-
md = args[3], mx = args[4], my = args[5];
61-
}else{
60+
ma = args[0];
61+
mb = args[1];
62+
mc = args[2];
63+
md = args[3];
64+
mx = args[4];
65+
my = args[5];
66+
}
67+
else{
6268
ma = mtx.a;
6369
mb = mtx.b;
6470
mc = mtx.c;

src/loader/ImageLoader.js

+4-7
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,14 @@ var ImageLoader = Class.create({
2727
image.crossOrigin = data.crossOrigin;
2828
}
2929

30-
image.onload = //me.onLoad.bind(image);
31-
function(){
32-
me.onLoad(image)
30+
image.onload = function(){
31+
me.onLoad(image);
3332
};
3433
image.onerror = image.onabort = me.onError.bind(image);
35-
image.src = data.src + (data.noCache ? (data.src.indexOf('?') == -1 ? '?' : '&') + 't=' + (+new Date) : '');
34+
image.src = data.src + (data.noCache ? (data.src.indexOf('?') == -1 ? '?' : '&') + 't=' + (+new Date()) : '');
3635
},
3736

38-
onLoad: function(e){
39-
e = e||window.event;
40-
var image = e//e.target;
37+
onLoad: function(image){
4138
image.onload = image.onerror = image.onabort = null;
4239
return image;
4340
},

src/loader/LoadQueue.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ var LoadQueue = Class.create(/** @lends LoadQueue.prototype */{
191191
* @private
192192
*/
193193
_getLoader: function(item){
194-
var me = this, loader = item.loader;
194+
var loader = item.loader;
195195
if(loader) return loader;
196196

197197
var type = item.type || getExtension(item.src);

src/loader/ScriptLoader.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,12 @@ var ScriptLoader = Class.create({
3030
if(!win[callback]){
3131
win[callback] = function(result){
3232
delete win[callback];
33-
}
33+
};
3434
}
35+
36+
src += (src.indexOf('?') == -1 ? '?' : '&') + callbackName + '=' + callback;
3537
}
3638

37-
if(isJSONP) src += (src.indexOf('?') == -1 ? '?' : '&') + callbackName + '=' + callback;
3839
if(data.noCache) src += (src.indexOf('?') == -1 ? '?' : '&') + 't=' + (+new Date());
3940

4041
var script = document.createElement('script');

src/media/HTMLAudio.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,9 @@ var HTMLAudio = Class.create(/** @lends HTMLAudio.prototype */{
6969
*/
7070
load: function(){
7171
if(!this._element){
72+
var elem;
7273
try{
73-
var elem = this._element = new Audio();
74+
elem = this._element = new Audio();
7475
elem.addEventListener('canplaythrough', this._onAudioEvent, false);
7576
elem.addEventListener('ended', this._onAudioEvent, false);
7677
elem.addEventListener('error', this._onAudioEvent, false);
@@ -80,7 +81,7 @@ var HTMLAudio = Class.create(/** @lends HTMLAudio.prototype */{
8081
}
8182
catch(err){
8283
//ie9 某些版本有Audio对象,但是执行play,pause会报错!
83-
var elem = this._element = {};
84+
elem = this._element = {};
8485
elem.play = elem.pause = function(){
8586

8687
};

src/renderer/WebGLRenderer.js

+17-18
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ var WebGLRenderer = Class.create(/** @lends WebGLRenderer.prototype */{
8787
constructor: function(properties){
8888
WebGLRenderer.superclass.constructor.call(this, properties);
8989
var that = this;
90-
var gl = this.gl = this.canvas.getContext("webgl")||this.canvas.getContext('experimental-webgl');
90+
this.gl = this.canvas.getContext("webgl")||this.canvas.getContext('experimental-webgl');
9191

9292
this.maxBatchNum = WebGLRenderer.MAX_BATCH_NUM;
9393
this.positionStride = WebGLRenderer.ATTRIBUTE_NUM * 4;
@@ -167,16 +167,16 @@ var WebGLRenderer = Class.create(/** @lends WebGLRenderer.prototype */{
167167
* @see Renderer#draw
168168
*/
169169
draw: function(target){
170-
var ctx = this.context, w = target.width, h = target.height;
170+
var w = target.width,
171+
h = target.height;
171172

172173
//TODO:draw background
173-
var bg = target.background;
174+
var bg = target.background; // jshint ignore:line
174175

175176
//draw image
176177
var drawable = target.drawable, image = drawable && drawable.image;
177178
if(image){
178-
var gl = this.gl;
179-
var rect = drawable.rect, sw = rect[2], sh = rect[3], offsetX = rect[4], offsetY = rect[5];
179+
var rect = drawable.rect, sw = rect[2], sh = rect[3];
180180
if(!w && !h){
181181
//fix width/height TODO: how to get rid of this?
182182
w = target.width = sw;
@@ -206,25 +206,25 @@ var WebGLRenderer = Class.create(/** @lends WebGLRenderer.prototype */{
206206
float32Array[index + 8] = vertexs[7];
207207
uint32Array[index + 9] = tint;
208208

209-
float32Array[index + 10] = vertexs[8]
210-
float32Array[index + 11] = vertexs[9]
211-
float32Array[index + 12] = vertexs[10]
212-
float32Array[index + 13] = vertexs[11]
209+
float32Array[index + 10] = vertexs[8];
210+
float32Array[index + 11] = vertexs[9];
211+
float32Array[index + 12] = vertexs[10];
212+
float32Array[index + 13] = vertexs[11];
213213
uint32Array[index + 14] = tint;
214214

215-
float32Array[index + 15] = vertexs[12]
216-
float32Array[index + 16] = vertexs[13]
217-
float32Array[index + 17] = vertexs[14]
218-
float32Array[index + 18] = vertexs[15]
215+
float32Array[index + 15] = vertexs[12];
216+
float32Array[index + 16] = vertexs[13];
217+
float32Array[index + 17] = vertexs[14];
218+
float32Array[index + 18] = vertexs[15];
219219
uint32Array[index + 19] = tint;
220220

221221
var matrix = target.__webglWorldMatrix;
222222
for(var i = 0;i < 4;i ++){
223223
var x = float32Array[index + i*5];
224224
var y = float32Array[index + i*5 + 1];
225225

226-
float32Array[index + i*5] = matrix.a*x+matrix.c*y + matrix.tx;
227-
float32Array[index + i*5 + 1] = matrix.b*x+matrix.d*y + matrix.ty;
226+
float32Array[index + i*5] = matrix.a*x + matrix.c*y + matrix.tx;
227+
float32Array[index + i*5 + 1] = matrix.b*x + matrix.d*y + matrix.ty;
228228
}
229229

230230
target.__textureImage = image;
@@ -252,8 +252,7 @@ var WebGLRenderer = Class.create(/** @lends WebGLRenderer.prototype */{
252252
return;
253253
}
254254

255-
var ctx = this.context,
256-
scaleX = target.scaleX,
255+
var scaleX = target.scaleX,
257256
scaleY = target.scaleY;
258257

259258
if(target === this.stage){
@@ -503,7 +502,7 @@ var Shader = function(renderer, source, attr){
503502
attr = attr||{};
504503
this.attributes = attr.attributes||[];
505504
this.uniforms = attr.uniforms||[];
506-
}
505+
};
507506

508507
Shader.prototype = {
509508
active:function(){

0 commit comments

Comments
 (0)