Skip to content

Commit 9f98f7c

Browse files
authored
Merge pull request #2158 from angular-fullstack/gen-run-eslint-fix
Fix ESLint errors
2 parents 34457bb + 231e500 commit 9f98f7c

File tree

27 files changed

+99
-75
lines changed

27 files changed

+99
-75
lines changed

Diff for: package.json

+2
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
"prepublish": "gulp build"
3636
},
3737
"dependencies": {
38+
"babel-eslint": "^6.1.2",
3839
"babel-plugin-syntax-class-properties": "^6.5.0",
3940
"babel-plugin-syntax-flow": "^6.5.0",
4041
"babel-plugin-transform-flow-strip-types": "^6.7.0",
@@ -44,6 +45,7 @@
4445
"glob": "^7.0.5",
4546
"gulp-babel": "^6.1.2",
4647
"gulp-beautify": "^2.0.0",
48+
"gulp-eslint": "^3.0.1",
4749
"gulp-filter": "^4.0.0",
4850
"gulp-tap": "^0.1.3",
4951
"insight": "~0.8.3",

Diff for: src/generators/app/index.js

+20-3
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import babelStream from 'gulp-babel';
1313
import beaufityStream from 'gulp-beautify';
1414
import tap from 'gulp-tap';
1515
import filter from 'gulp-filter';
16+
import eslint from 'gulp-eslint';
1617
import semver from 'semver';
1718

1819
export class Generator extends Base {
@@ -485,9 +486,11 @@ export class Generator extends Base {
485486
babelPlugins.push('babel-plugin-transform-flow-strip-types');
486487
}
487488

488-
let jsFilter = filter(['client/**/*.js'], {restore: true});
489+
const genDir = path.join(__dirname, '../../');
490+
491+
let clientJsFilter = filter(['client/**/*.js'], {restore: true});
489492
this.registerTransformStream([
490-
jsFilter,
493+
clientJsFilter,
491494
babelStream({
492495
plugins: babelPlugins.map(require.resolve),
493496
/* Babel get's confused about these if you're using an `npm link`ed
@@ -523,7 +526,11 @@ export class Generator extends Base {
523526
"wrap_attributes_indent_size": 4,
524527
"end_with_newline": true
525528
}),
526-
jsFilter.restore
529+
eslint({
530+
fix: true,
531+
configFile: path.join(genDir, 'templates/app/client/.eslintrc(babel)')
532+
}),
533+
clientJsFilter.restore
527534
]);
528535

529536
/**
@@ -563,6 +570,16 @@ export class Generator extends Base {
563570
]);
564571
}
565572

573+
let serverJsFilter = filter(['server/**/*.js'], {restore: true});
574+
this.registerTransformStream([
575+
serverJsFilter,
576+
eslint({
577+
fix: true,
578+
configFile: path.join(genDir, 'templates/app/server/.eslintrc')
579+
}),
580+
serverJsFilter.restore
581+
]);
582+
566583
let self = this;
567584
this.sourceRoot(path.join(__dirname, '../../templates/app'));
568585
this.processDirectory('.', '.');

Diff for: templates/app/.eslintrc

+4-1
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,10 @@
175175
"new-parens": 2, //disallow the omission of parentheses when invoking a constructor with no arguments
176176
"newline-after-var": 0, //require or disallow an empty newline after variable declarations
177177
"newline-before-return": 0, //require newline before return statement
178-
"newline-per-chained-call": 0, //enforce newline after each call when chaining the calls
178+
"newline-per-chained-call": [
179+
"error",
180+
{"ignoreChainWithDepth": 2}
181+
], //enforce newline after each call when chaining the calls
179182
"no-array-constructor": 2, //disallow use of the Array constructor
180183
"no-bitwise": 0, //disallow use of bitwise operators
181184
"no-continue": 0, //disallow use of the continue statement

Diff for: templates/app/client/app/account(auth)/login/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
'use strict';
2+
import angular from 'angular';
23
import LoginController from './login.controller';
34

45
export default angular.module('<%= scriptAppName %>.login', [])

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

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
'use strict';
2+
import angular from 'angular';
23
import SettingsController from './settings.controller';
34

45
export default angular.module('<%= scriptAppName %>.settings', [])

Diff for: templates/app/client/app/account(auth)/signup/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
'use strict';
2-
2+
import angular from 'angular';
33
import SignupController from './signup.controller';
44

55
export default angular.module('<%= scriptAppName %>.signup', [])

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

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
'use strict';
22
// @flow
3+
import angular from 'angular';
4+
35
<%_ if(filters.flow) { -%>
46
type User = {
57
name: string;

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

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
'use strict';
2+
import angular from 'angular';
23
import routes from './admin.routes';
34
import AdminController from './admin.controller';
45

Diff for: templates/app/client/app/app.js

+1-4
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import uiRouter from 'angular-ui-router';<% } %>
1414
import uiBootstrap from 'angular-ui-bootstrap';<% } %>
1515
// import ngMessages from 'angular-messages';
1616
<%_ if(filters.auth) { _%>
17-
//import ngValidationMatch from 'angular-validation-match';<% } %>
17+
// import ngValidationMatch from 'angular-validation-match';<% } %>
1818

1919

2020
import {routeConfig} from './app.config';
@@ -35,7 +35,6 @@ import socket from '../components/socket/socket.service';<% } %>
3535
import './app.<%= styleExt %>';
3636

3737
angular.module('<%= scriptAppName %>', [
38-
// ngAnimate,
3938
ngCookies,
4039
ngResource,
4140
ngSanitize,
@@ -47,9 +46,7 @@ angular.module('<%= scriptAppName %>', [
4746
uiRouter,<% } _%>
4847
<%_ if(filters.uibootstrap) { %>
4948
uiBootstrap,<% } %>
50-
// ngMessages,
5149
<%_ if(filters.auth) { %>
52-
// ngValidationMatch,
5350
_Auth,
5451
account,
5552
admin,<% } _%>

Diff for: templates/app/client/components/auth(auth)/auth.service.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict';
22
// @flow
3-
class User {
3+
class _User {
44
_id: string = '';
55
name: string = '';
66
email: string = '';
@@ -11,7 +11,7 @@ class User {
1111
export function AuthService($location, $http, $cookies, $q, appConfig, Util, User) {
1212
'ngInject';
1313
var safeCb = Util.safeCb;
14-
var currentUser: User = new User();
14+
var currentUser: _User = new _User();
1515
var userRoles = appConfig.userRoles || [];
1616
/**
1717
* Check if userRole is >= role
@@ -27,7 +27,6 @@ export function AuthService($location, $http, $cookies, $q, appConfig, Util, Use
2727
}
2828

2929
var Auth = {
30-
3130
/**
3231
* Authenticate user and save token
3332
*

Diff for: templates/app/client/components/auth(auth)/router.decorator.js

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
'use strict';
2-
import * as _ from 'lodash';
32

43
export function routerDecorator($rootScope<% if(filters.ngroute) { %>, $location<% } if(filters.uirouter) { %>, $state<% } %>, Auth) {
54
'ngInject';

Diff for: templates/app/client/components/modal(uibootstrap)/modal.service.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
'use strict';
2+
import angular from 'angular';
23

34
export function Modal($rootScope, $uibModal) {
45
/**
@@ -37,9 +38,9 @@ export function Modal($rootScope, $uibModal) {
3738
* @param {All} - any additional args are passed straight to del callback
3839
*/
3940
return function() {
40-
var args = Array.prototype.slice.call(arguments),
41-
name = args.shift(),
42-
deleteModal;
41+
var args = Array.prototype.slice.call(arguments);
42+
var name = args.shift();
43+
var deleteModal;
4344

4445
deleteModal = openModal({
4546
modal: {

Diff for: templates/app/client/components/mongoose-error(auth)/mongoose-error.directive.js

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
'use strict';
2+
import angular from 'angular';
23

34
/**
45
* Removes server error when user updates input

Diff for: templates/app/client/components/navbar/navbar.component.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
'use strict';
2+
/* eslint no-sync: 0 */
3+
import angular from 'angular';
24

35
export class NavbarComponent {
46
menu = [{

Diff for: templates/app/client/components/oauth-buttons(oauth)/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
'use strict';
2+
import angular from 'angular';
23

34
export function OauthButtonsController($window) {
45
this.loginOauth = function(provider) {

Diff for: templates/app/client/components/socket(socketio)/socket.service.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
'use strict';
2-
2+
import * as _ from 'lodash';
3+
import angular from 'angular';
34
import io from 'socket.io-client';
45

56
function Socket(socketFactory) {

Diff for: templates/app/client/components/util/util.module.js

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
'use strict';
2+
import angular from 'angular';
23
import {UtilService} from './util.service';
34

45
export default angular.module('<%= scriptAppName %>.util', [])

Diff for: templates/app/client/components/util/util.service.js

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
'use strict';
2+
import angular from 'angular';
23

34
/**
45
* The Util service is for thin, globally reusable, utility functions

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

+3-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
<% if (filters.mongooseModels) { %>
33
import User from './user.model';<% } %><% if (filters.sequelizeModels) { %>
44
import {User} from '../../sqldb';<% } %>
5-
import passport from 'passport';
65
import config from '../../config/environment';
76
import jwt from 'jsonwebtoken';
87

@@ -44,7 +43,7 @@ export function index(req, res) {
4443
/**
4544
* Creates a new user
4645
*/
47-
export function create(req, res, next) {
46+
export function create(req, res) {
4847
<% if (filters.mongooseModels) { %>var newUser = new User(req.body);
4948
newUser.provider = 'local';
5049
newUser.role = 'user';
@@ -99,7 +98,7 @@ export function destroy(req, res) {
9998
/**
10099
* Change a users password
101100
*/
102-
export function changePassword(req, res, next) {
101+
export function changePassword(req, res) {
103102
var userId = req.user._id;
104103
var oldPass = String(req.body.oldPassword);
105104
var newPass = String(req.body.newPassword);
@@ -155,6 +154,6 @@ export function me(req, res, next) {
155154
/**
156155
* Authentication callback
157156
*/
158-
export function authCallback(req, res, next) {
157+
export function authCallback(req, res) {
159158
res.redirect('/');
160159
}

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

+7-7
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,18 @@ UserEvents.setMaxListeners(0);
1414

1515
// Model events<% if (filters.mongooseModels) { %>
1616
var events = {
17-
'save': 'save',
18-
'remove': 'remove'
17+
save: 'save',
18+
remove: 'remove'
1919
};<% } if (filters.sequelizeModels) { %>
2020
var events = {
21-
'afterCreate': 'save',
22-
'afterUpdate': 'save',
23-
'afterDestroy': 'remove'
21+
afterCreate: 'save',
22+
afterUpdate: 'save',
23+
afterDestroy: 'remove'
2424
};<% } %>
2525

2626
// Register the event emitter to the model events
27-
for (var e in events) {
28-
var event = events[e];<% if (filters.mongooseModels) { %>
27+
for(var e in events) {
28+
let event = events[e];<% if (filters.mongooseModels) { %>
2929
User.schema.post(e, emitEvent(event));<% } if (filters.sequelizeModels) { %>
3030
User.hook(e, emitEvent(event));<% } %>
3131
}

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -244,14 +244,14 @@ UserSchema.methods = {
244244

245245
if(!callback) {
246246
return crypto.pbkdf2Sync(password, salt, defaultIterations, defaultKeyLength)
247-
.toString('base64');
247+
.toString('base64');
248248
}
249249

250250
return crypto.pbkdf2(password, salt, defaultIterations, defaultKeyLength, (err, key) => {
251251
if(err) {
252-
callback(err);
252+
return callback(err);
253253
} else {
254-
callback(null, key.toString('base64'));
254+
return callback(null, key.toString('base64'));
255255
}
256256
});
257257
}

Diff for: templates/app/server/app.js

+6-4
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,13 @@ import http from 'http';
1515
mongoose.connect(config.mongo.uri, config.mongo.options);
1616
mongoose.connection.on('error', function(err) {
1717
console.error('MongoDB connection error: ' + err);
18-
process.exit(-1);
18+
process.exit(-1); // eslint-disable-line no-process-exit
1919
});
20-
<% } %><% if (filters.models) { %>
20+
<% } %><% if(filters.models) { %>
2121
// Populate databases with sample data
22-
if (config.seedDB) { require('./config/seed'); }
22+
if(config.seedDB) {
23+
require('./config/seed');
24+
}
2325
<% } %>
2426
// Setup server
2527
var app = express();
@@ -38,7 +40,7 @@ function startServer() {
3840
console.log('Express server listening on %d, in %s mode', config.port, app.get('env'));
3941
});
4042
}
41-
<% if (filters.sequelize) { %>
43+
<% if(filters.sequelize) { %>
4244
sqldb.sequelize.sync()
4345
.then(startServer)
4446
.catch(function(err) {

Diff for: templates/app/server/auth(auth)/auth.service.js

+3-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
'use strict';
2-
3-
import passport from 'passport';
42
import config from '../config/environment';
53
import jwt from 'jsonwebtoken';
64
import expressJwt from 'express-jwt';
@@ -60,11 +58,10 @@ export function hasRole(roleRequired) {
6058
return compose()
6159
.use(isAuthenticated())
6260
.use(function meetsRequirements(req, res, next) {
63-
if (config.userRoles.indexOf(req.user.role) >=
64-
config.userRoles.indexOf(roleRequired)) {
65-
next();
61+
if (config.userRoles.indexOf(req.user.role) >= config.userRoles.indexOf(roleRequired)) {
62+
return next();
6663
} else {
67-
res.status(403).send('Forbidden');
64+
return res.status(403).send('Forbidden');
6865
}
6966
});
7067
}

Diff for: templates/app/server/auth(auth)/index.js

-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
'use strict';
2-
32
import express from 'express';
4-
import passport from 'passport';
53
import config from '../config/environment';<% if (filters.mongooseModels) { %>
64
import User from '../api/user/user.model';<% } %><% if (filters.sequelizeModels) { %>
75
import {User} from '../sqldb';<% } %>

0 commit comments

Comments
 (0)