Skip to content

Fix ESLint errors #2158

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Aug 19, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"prepublish": "gulp build"
},
"dependencies": {
"babel-eslint": "^6.1.2",
"babel-plugin-syntax-class-properties": "^6.5.0",
"babel-plugin-syntax-flow": "^6.5.0",
"babel-plugin-transform-flow-strip-types": "^6.7.0",
Expand All @@ -44,6 +45,7 @@
"glob": "^7.0.5",
"gulp-babel": "^6.1.2",
"gulp-beautify": "^2.0.0",
"gulp-eslint": "^3.0.1",
"gulp-filter": "^4.0.0",
"gulp-tap": "^0.1.3",
"insight": "~0.8.3",
Expand Down
23 changes: 20 additions & 3 deletions src/generators/app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import babelStream from 'gulp-babel';
import beaufityStream from 'gulp-beautify';
import tap from 'gulp-tap';
import filter from 'gulp-filter';
import eslint from 'gulp-eslint';
import semver from 'semver';

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

let jsFilter = filter(['client/**/*.js'], {restore: true});
const genDir = path.join(__dirname, '../../');

let clientJsFilter = filter(['client/**/*.js'], {restore: true});
this.registerTransformStream([
jsFilter,
clientJsFilter,
babelStream({
plugins: babelPlugins.map(require.resolve),
/* Babel get's confused about these if you're using an `npm link`ed
Expand Down Expand Up @@ -523,7 +526,11 @@ export class Generator extends Base {
"wrap_attributes_indent_size": 4,
"end_with_newline": true
}),
jsFilter.restore
eslint({
fix: true,
configFile: path.join(genDir, 'templates/app/client/.eslintrc(babel)')
}),
clientJsFilter.restore
]);

/**
Expand Down Expand Up @@ -563,6 +570,16 @@ export class Generator extends Base {
]);
}

let serverJsFilter = filter(['server/**/*.js'], {restore: true});
this.registerTransformStream([
serverJsFilter,
eslint({
fix: true,
configFile: path.join(genDir, 'templates/app/server/.eslintrc')
}),
serverJsFilter.restore
]);

let self = this;
this.sourceRoot(path.join(__dirname, '../../templates/app'));
this.processDirectory('.', '.');
Expand Down
5 changes: 4 additions & 1 deletion templates/app/.eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,10 @@
"new-parens": 2, //disallow the omission of parentheses when invoking a constructor with no arguments
"newline-after-var": 0, //require or disallow an empty newline after variable declarations
"newline-before-return": 0, //require newline before return statement
"newline-per-chained-call": 0, //enforce newline after each call when chaining the calls
"newline-per-chained-call": [
"error",
{"ignoreChainWithDepth": 2}
], //enforce newline after each call when chaining the calls
"no-array-constructor": 2, //disallow use of the Array constructor
"no-bitwise": 0, //disallow use of bitwise operators
"no-continue": 0, //disallow use of the continue statement
Expand Down
1 change: 1 addition & 0 deletions templates/app/client/app/account(auth)/login/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
'use strict';
import angular from 'angular';
import LoginController from './login.controller';

export default angular.module('<%= scriptAppName %>.login', [])
Expand Down
1 change: 1 addition & 0 deletions templates/app/client/app/account(auth)/settings/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
'use strict';
import angular from 'angular';
import SettingsController from './settings.controller';

export default angular.module('<%= scriptAppName %>.settings', [])
Expand Down
2 changes: 1 addition & 1 deletion templates/app/client/app/account(auth)/signup/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use strict';

import angular from 'angular';
import SignupController from './signup.controller';

export default angular.module('<%= scriptAppName %>.signup', [])
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
'use strict';
// @flow
import angular from 'angular';

<%_ if(filters.flow) { -%>
type User = {
name: string;
Expand Down
1 change: 1 addition & 0 deletions templates/app/client/app/admin(auth)/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
'use strict';
import angular from 'angular';
import routes from './admin.routes';
import AdminController from './admin.controller';

Expand Down
5 changes: 1 addition & 4 deletions templates/app/client/app/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import uiRouter from 'angular-ui-router';<% } %>
import uiBootstrap from 'angular-ui-bootstrap';<% } %>
// import ngMessages from 'angular-messages';
<%_ if(filters.auth) { _%>
//import ngValidationMatch from 'angular-validation-match';<% } %>
// import ngValidationMatch from 'angular-validation-match';<% } %>


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

angular.module('<%= scriptAppName %>', [
// ngAnimate,
ngCookies,
ngResource,
ngSanitize,
Expand All @@ -47,9 +46,7 @@ angular.module('<%= scriptAppName %>', [
uiRouter,<% } _%>
<%_ if(filters.uibootstrap) { %>
uiBootstrap,<% } %>
// ngMessages,
<%_ if(filters.auth) { %>
// ngValidationMatch,
_Auth,
account,
admin,<% } _%>
Expand Down
5 changes: 2 additions & 3 deletions templates/app/client/components/auth(auth)/auth.service.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';
// @flow
class User {
class _User {
_id: string = '';
name: string = '';
email: string = '';
Expand All @@ -11,7 +11,7 @@ class User {
export function AuthService($location, $http, $cookies, $q, appConfig, Util, User) {
'ngInject';
var safeCb = Util.safeCb;
var currentUser: User = new User();
var currentUser: _User = new _User();
var userRoles = appConfig.userRoles || [];
/**
* Check if userRole is >= role
Expand All @@ -27,7 +27,6 @@ export function AuthService($location, $http, $cookies, $q, appConfig, Util, Use
}

var Auth = {

/**
* Authenticate user and save token
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
'use strict';
import * as _ from 'lodash';

export function routerDecorator($rootScope<% if(filters.ngroute) { %>, $location<% } if(filters.uirouter) { %>, $state<% } %>, Auth) {
'ngInject';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
'use strict';
import angular from 'angular';

export function Modal($rootScope, $uibModal) {
/**
Expand Down Expand Up @@ -37,9 +38,9 @@ export function Modal($rootScope, $uibModal) {
* @param {All} - any additional args are passed straight to del callback
*/
return function() {
var args = Array.prototype.slice.call(arguments),
name = args.shift(),
deleteModal;
var args = Array.prototype.slice.call(arguments);
var name = args.shift();
var deleteModal;

deleteModal = openModal({
modal: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
'use strict';
import angular from 'angular';

/**
* Removes server error when user updates input
Expand Down
2 changes: 2 additions & 0 deletions templates/app/client/components/navbar/navbar.component.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
'use strict';
/* eslint no-sync: 0 */
import angular from 'angular';

export class NavbarComponent {
menu = [{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
'use strict';
import angular from 'angular';

export function OauthButtonsController($window) {
this.loginOauth = function(provider) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict';

import * as _ from 'lodash';
import angular from 'angular';
import io from 'socket.io-client';

function Socket(socketFactory) {
Expand Down
1 change: 1 addition & 0 deletions templates/app/client/components/util/util.module.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
'use strict';
import angular from 'angular';
import {UtilService} from './util.service';

export default angular.module('<%= scriptAppName %>.util', [])
Expand Down
1 change: 1 addition & 0 deletions templates/app/client/components/util/util.service.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
'use strict';
import angular from 'angular';

/**
* The Util service is for thin, globally reusable, utility functions
Expand Down
7 changes: 3 additions & 4 deletions templates/app/server/api/user(auth)/user.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
<% if (filters.mongooseModels) { %>
import User from './user.model';<% } %><% if (filters.sequelizeModels) { %>
import {User} from '../../sqldb';<% } %>
import passport from 'passport';
import config from '../../config/environment';
import jwt from 'jsonwebtoken';

Expand Down Expand Up @@ -44,7 +43,7 @@ export function index(req, res) {
/**
* Creates a new user
*/
export function create(req, res, next) {
export function create(req, res) {
<% if (filters.mongooseModels) { %>var newUser = new User(req.body);
newUser.provider = 'local';
newUser.role = 'user';
Expand Down Expand Up @@ -99,7 +98,7 @@ export function destroy(req, res) {
/**
* Change a users password
*/
export function changePassword(req, res, next) {
export function changePassword(req, res) {
var userId = req.user._id;
var oldPass = String(req.body.oldPassword);
var newPass = String(req.body.newPassword);
Expand Down Expand Up @@ -155,6 +154,6 @@ export function me(req, res, next) {
/**
* Authentication callback
*/
export function authCallback(req, res, next) {
export function authCallback(req, res) {
res.redirect('/');
}
14 changes: 7 additions & 7 deletions templates/app/server/api/user(auth)/user.events.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,18 @@ UserEvents.setMaxListeners(0);

// Model events<% if (filters.mongooseModels) { %>
var events = {
'save': 'save',
'remove': 'remove'
save: 'save',
remove: 'remove'
};<% } if (filters.sequelizeModels) { %>
var events = {
'afterCreate': 'save',
'afterUpdate': 'save',
'afterDestroy': 'remove'
afterCreate: 'save',
afterUpdate: 'save',
afterDestroy: 'remove'
};<% } %>

// Register the event emitter to the model events
for (var e in events) {
var event = events[e];<% if (filters.mongooseModels) { %>
for(var e in events) {
let event = events[e];<% if (filters.mongooseModels) { %>
User.schema.post(e, emitEvent(event));<% } if (filters.sequelizeModels) { %>
User.hook(e, emitEvent(event));<% } %>
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,14 +244,14 @@ UserSchema.methods = {

if(!callback) {
return crypto.pbkdf2Sync(password, salt, defaultIterations, defaultKeyLength)
.toString('base64');
.toString('base64');
}

return crypto.pbkdf2(password, salt, defaultIterations, defaultKeyLength, (err, key) => {
if(err) {
callback(err);
return callback(err);
} else {
callback(null, key.toString('base64'));
return callback(null, key.toString('base64'));
}
});
}
Expand Down
10 changes: 6 additions & 4 deletions templates/app/server/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@ import http from 'http';
mongoose.connect(config.mongo.uri, config.mongo.options);
mongoose.connection.on('error', function(err) {
console.error('MongoDB connection error: ' + err);
process.exit(-1);
process.exit(-1); // eslint-disable-line no-process-exit
});
<% } %><% if (filters.models) { %>
<% } %><% if(filters.models) { %>
// Populate databases with sample data
if (config.seedDB) { require('./config/seed'); }
if(config.seedDB) {
require('./config/seed');
}
<% } %>
// Setup server
var app = express();
Expand All @@ -38,7 +40,7 @@ function startServer() {
console.log('Express server listening on %d, in %s mode', config.port, app.get('env'));
});
}
<% if (filters.sequelize) { %>
<% if(filters.sequelize) { %>
sqldb.sequelize.sync()
.then(startServer)
.catch(function(err) {
Expand Down
9 changes: 3 additions & 6 deletions templates/app/server/auth(auth)/auth.service.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
'use strict';

import passport from 'passport';
import config from '../config/environment';
import jwt from 'jsonwebtoken';
import expressJwt from 'express-jwt';
Expand Down Expand Up @@ -60,11 +58,10 @@ export function hasRole(roleRequired) {
return compose()
.use(isAuthenticated())
.use(function meetsRequirements(req, res, next) {
if (config.userRoles.indexOf(req.user.role) >=
config.userRoles.indexOf(roleRequired)) {
next();
if (config.userRoles.indexOf(req.user.role) >= config.userRoles.indexOf(roleRequired)) {
return next();
} else {
res.status(403).send('Forbidden');
return res.status(403).send('Forbidden');
}
});
}
Expand Down
2 changes: 0 additions & 2 deletions templates/app/server/auth(auth)/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
'use strict';

import express from 'express';
import passport from 'passport';
import config from '../config/environment';<% if (filters.mongooseModels) { %>
import User from '../api/user/user.model';<% } %><% if (filters.sequelizeModels) { %>
import {User} from '../sqldb';<% } %>
Expand Down
Loading