Skip to content

Commit 0622df2

Browse files
committed
Merge pull request #482 from kingcody/fix/jshint
fix(app-jshint): improve jshint usage
2 parents c89364c + 35fcf49 commit 0622df2

File tree

14 files changed

+73
-44
lines changed

14 files changed

+73
-44
lines changed

Diff for: app/templates/Gruntfile.js

+10-1
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,16 @@ module.exports = function (grunt) {
167167
options: {
168168
jshintrc: 'server/.jshintrc'
169169
},
170-
src: [ 'server/{,*/}*.js']
170+
src: [
171+
'server/**/*.js',
172+
'!server/**/*.spec.js'
173+
]
174+
},
175+
serverTest: {
176+
options: {
177+
jshintrc: 'server/.jshintrc-spec'
178+
},
179+
src: ['server/**/*.spec.js']
171180
},
172181
all: [
173182
'<%%= yeoman.client %>/{app,components}/**/*.js',

Diff for: app/templates/client/app/account(auth)/settings/settings.controller(coffee).coffee

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ angular.module '<%= scriptAppName %>'
88
$scope.email = {}
99

1010
getEmail = (user) ->
11-
return [null, null] unless $scope.user.credentials.length
11+
return [null, null] unless user.credentials.length
1212

13-
for c in $scope.user.credentials when c.type is 'email'
13+
for c in user.credentials when c.type is 'email'
1414
return [c.value, c.confirmed]
1515

1616
[null, null]

Diff for: app/templates/client/app/account(auth)/settings/settings.controller(js).js

+7-5
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,15 @@ angular.module('<%= scriptAppName %>')
88
$scope.email = {};
99

1010
var getEmail = function(user) {
11-
if (!$scope.user.credentials.length) {
11+
if (!user.credentials.length) {
1212
return null;
1313
}
1414

15-
for(var i in $scope.user.credentials) {
16-
var c = $scope.user.credentials[i];
17-
if(c.type==='email') return [c.value, c.confirmed];
15+
for(var i in user.credentials) {
16+
var c = user.credentials[i];
17+
if (c.type === 'email') {
18+
return [c.value, c.confirmed];
19+
}
1820
}
1921
};
2022

@@ -36,7 +38,7 @@ angular.module('<%= scriptAppName %>')
3638
$scope.message = '';
3739
});
3840
}
39-
}
41+
};
4042

4143
$scope.changePassword = function() {
4244
$scope.pwd.submitted = true;

Diff for: app/templates/client/app/admin(auth)/admin.controller(js).js

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ angular.module('<%= scriptAppName %>')
88

99
$scope.delete = <% if(filters.uibootstrap) { %>Modal.confirm.delete(<% } %>function(user) {
1010
User.remove({ id: user._id });
11-
_.remove($scope.users, user)
11+
_.remove($scope.users, user);
1212
}<% if(filters.uibootstrap) { %>)<% } %>;
1313
});

Diff for: app/templates/client/app/main/main.controller(coffee).coffee

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict'
22

33
angular.module '<%= scriptAppName %>'
4-
.controller 'MainCtrl', ($scope, $http<% if(filters.socketio) { %>, socket<% } %><% if(filters.uibootstrap && filters.mongoose) { %>, Modal<% } %>) ->
4+
.controller 'MainCtrl', ($scope, $http<% if(filters.socketio) { %>, socket<% } %>) ->
55
$scope.awesomeThings = []
66

77
$http.get('/api/things').success (awesomeThings) ->
@@ -19,4 +19,4 @@ angular.module '<%= scriptAppName %>'
1919
$http.delete '/api/things/' + thing._id<% } %><% if(filters.socketio) { %>
2020

2121
$scope.$on '$destroy', ->
22-
socket.unsyncUpdates 'thing'<% } %>
22+
socket.unsyncUpdates 'thing'<% } %>

Diff for: app/templates/client/app/main/main.controller(js).js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict';
22

33
angular.module('<%= scriptAppName %>')
4-
.controller('MainCtrl', function ($scope, $http<% if(filters.socketio) { %>, socket<% } %><% if(filters.uibootstrap && filters.mongoose) { %>, Modal<% } %>) {
4+
.controller('MainCtrl', function ($scope, $http<% if(filters.socketio) { %>, socket<% } %>) {
55
$scope.awesomeThings = [];
66

77
$http.get('/api/things').success(function(awesomeThings) {
@@ -24,4 +24,4 @@ angular.module('<%= scriptAppName %>')
2424
$scope.$on('$destroy', function () {
2525
socket.unsyncUpdates('thing');
2626
});<% } %>
27-
});
27+
});

Diff for: app/templates/server/.jshintrc

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
"bitwise": true,
55
"eqeqeq": true,
66
"immed": true,
7-
"latedef": true,
7+
"latedef": "nofunc",
88
"newcap": true,
99
"noarg": true,
1010
"regexp": true,
1111
"undef": true,
1212
"smarttabs": true,
1313
"asi": true,
1414
"debug": true
15-
}
15+
}

Diff for: app/templates/server/.jshintrc-spec

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"extends": ".jshintrc",
3+
"globals": {
4+
"describe": true,
5+
"it": true,
6+
"before": true,
7+
"beforeEach": true,
8+
"after": true,
9+
"afterEach": true
10+
}
11+
}

Diff for: app/templates/server/api/thing/thing.spec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@ describe('GET /api/things', function() {
1717
done();
1818
});
1919
});
20-
});
20+
});

Diff for: app/templates/server/api/user(auth)/user.model.js

+10-10
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ UserSchema
8181
// returns only first found email
8282
// TODO: in case of multiple emails, should prioritize confirmed ones
8383
return this.credentials.filter(function(c) {
84-
return c.type==='email';
84+
return c.type === 'email';
8585

8686
})[0].value;
8787
});
@@ -90,21 +90,21 @@ UserSchema
9090
.virtual('emails')
9191
.get(function() {
9292
return this.credentials
93-
.filter(function(c) { return c.type==='email'; })
93+
.filter(function(c) { return c.type === 'email'; })
9494
.map(function(c) { return c.value; });
9595

9696
});
9797

9898
UserSchema
9999
.pre('save', function(next) {<% if (filters.oauth) { %>
100100
if(!this.localEnabled) {
101-
if (Object.keys(this.strategies).length===0) {
101+
if (Object.keys(this.strategies).length === 0) {
102102
return next(new Error('No connected accounts'));
103103
}
104104
return next();
105105
}<% } %>
106106

107-
mongoose.models['User']<% if (filters.oauth) { %>
107+
mongoose.models.User<% if (filters.oauth) { %>
108108
.find({ localEnabled:true })<% } %>
109109
.where('credentials.type').equals('email')
110110
.where('credentials.value').equals(this.email)
@@ -132,15 +132,15 @@ UserSchema.methods = {
132132
},
133133
confirm: function(emailOrPhone, cb) {
134134
this.credentials.forEach(function(c) {
135-
if (c.value===emailOrPhone) {
135+
if (c.value === emailOrPhone) {
136136
c.confirmed = true;
137137
}
138138
});
139139
this.save(cb);
140140
},
141141
changeEmail: function(oldEmail, newEmail, cb) {
142142
this.credentials.forEach(function(c) {
143-
if (c.value===oldEmail) {
143+
if (c.value === oldEmail) {
144144
c.value = newEmail;
145145
c.confirmed = false;
146146
}
@@ -177,14 +177,14 @@ UserSchema.statics = {
177177
var dataFormatted;
178178
dataFormatted = [];
179179

180-
if (data.email != null) {
180+
if (data.email !== null) {
181181
dataFormatted.push({
182182
'credentials.type': 'email',
183183
'credentials.value': data.email
184184
});
185185
}
186186

187-
if (data.phone != null) {
187+
if (data.phone !== null) {
188188
dataFormatted.push({
189189
'credentials.type': 'phone',
190190
'credentials.value': data.phone
@@ -195,11 +195,11 @@ UserSchema.statics = {
195195
.or(dataFormatted)
196196
.exec(function(err, users) {
197197
if (err) return cb(err);
198-
if (users.length===0) return cb(null, null);
198+
if (users.length === 0) return cb(null, null);
199199

200200
cb(null, users);
201201
});
202202
}<% } %>
203203
};
204204

205-
module.exports = mongoose.model('User', UserSchema);
205+
module.exports = mongoose.model('User', UserSchema);

Diff for: app/templates/server/api/user(auth)/user.model.spec.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,10 @@ describe('User Model', function() {
5151
});
5252

5353
it("should authenticate user if password is valid", function() {
54-
user.authenticate('password').should.be.true;
54+
return user.authenticate('password').should.be.true;
5555
});
5656

5757
it("should not authenticate user if password is invalid", function() {
58-
user.authenticate('blah').should.not.be.true;
58+
return user.authenticate('blah').should.not.be.true;
5959
});
60-
});
60+
});

Diff for: app/templates/server/auth(auth)/facebook(facebookAuth)/passport.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@ exports.setup = function (User, config) {
2121
}, function (err, users) {
2222
if (err) return done(err);
2323
if (users) {
24-
var user = users[0];
24+
user = users[0];
2525
user.absorb(profile.provider, profile);
2626

2727
// we can do that because we have it handled by Facebook
2828
user.confirm(profile.emails[0].value);
2929
return done(null, user);
3030
}
3131

32-
var user = new User({
32+
user = new User({
3333
name: profile.displayName,
3434
email: profile.emails[0].value,
3535
username: profile.username,
@@ -46,4 +46,4 @@ exports.setup = function (User, config) {
4646
});
4747
}
4848
));
49-
};
49+
};

Diff for: app/templates/server/auth(auth)/google(googleAuth)/passport.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@ exports.setup = function (User, config) {
2121
}, function (err, users) {
2222
if (err) return done(err);
2323
if (users) {
24-
var user = users[0];
24+
user = users[0];
2525
user.absorb(profile.provider, profile);
2626

2727
// we can do that because we have it handled by Google
2828
user.confirm(profile.emails[0].value);
2929
return done(null, user);
3030
}
3131

32-
var user = new User({
32+
user = new User({
3333
name: profile.displayName,
3434
email: profile.emails[0].value,
3535
username: profile.username,
@@ -46,4 +46,4 @@ exports.setup = function (User, config) {
4646
});
4747
}
4848
));
49-
};
49+
};

Diff for: test/test-file-creation.js

+16-9
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ describe('angular-fullstack generator', function () {
5454
});
5555

5656
describe('running app', function() {
57-
;
57+
5858
beforeEach(function() {
5959
this.timeout(20000);
6060
fs.mkdirSync(__dirname + '/temp/client');
@@ -77,6 +77,16 @@ describe('angular-fullstack generator', function () {
7777
});
7878
});
7979

80+
it('should pass jshint', function(done) {
81+
this.timeout(60000);
82+
gen.run({}, function () {
83+
exec('grunt jshint', function (error, stdout, stderr) {
84+
expect(stdout).to.contain('Done, without errors.');
85+
done();
86+
});
87+
});
88+
});
89+
8090
it('should run server tests successfully', function(done) {
8191
this.timeout(60000);
8292
gen.run({}, function () {
@@ -161,8 +171,7 @@ describe('angular-fullstack generator', function () {
161171
this.timeout(60000);
162172
gen.run({}, function () {
163173
exec('grunt jshint', function (error, stdout, stderr) {
164-
expect(stdout).to.contain('Running "jshint:server" (jshint) task\u001b[24m\n\n✔ No problems');
165-
expect(stdout).to.contain('Running "jshint:all" (jshint) task\u001b[24m\n\n✔ No problems');
174+
expect(stdout).to.contain('Done, without errors.');
166175
done();
167176
});
168177
});
@@ -203,13 +212,12 @@ describe('angular-fullstack generator', function () {
203212
});
204213
});
205214
});
206-
215+
207216
it('should pass jshint', function(done) {
208217
this.timeout(60000);
209218
gen.run({}, function () {
210219
exec('grunt jshint', function (error, stdout, stderr) {
211-
expect(stdout).to.contain('Running "jshint:server" (jshint) task\u001b[24m\n\n✔ No problems');
212-
expect(stdout).to.contain('Running "jshint:all" (jshint) task\u001b[24m\n\n✔ No problems');
220+
expect(stdout).to.contain('Done, without errors.');
213221
done();
214222
});
215223
});
@@ -255,8 +263,7 @@ describe('angular-fullstack generator', function () {
255263
this.timeout(60000);
256264
gen.run({}, function () {
257265
exec('grunt jshint', function (error, stdout, stderr) {
258-
expect(stdout).to.contain('Running "jshint:server" (jshint) task\u001b[24m\n\n✔ No problems');
259-
expect(stdout).to.contain('Running "jshint:all" (jshint) task\u001b[24m\n\n✔ No problems');
266+
expect(stdout).to.contain('Done, without errors.');
260267
done();
261268
});
262269
});
@@ -299,4 +306,4 @@ describe('angular-fullstack generator', function () {
299306
});
300307
});
301308
});
302-
});
309+
});

0 commit comments

Comments
 (0)