Skip to content

Commit 58afd04

Browse files
authored
Merge pull request #47 from KunalKapadia/develop
Update eslint to v3.5. Fix lint errors. Move from gulp to npm task fo…
2 parents 086c115 + c1c8dbe commit 58afd04

File tree

10 files changed

+68
-61
lines changed

10 files changed

+68
-61
lines changed

.eslintrc

+14-1
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,27 @@
2121
// TODO: turn on later
2222
"comma-dangle": [
2323
0
24+
],
25+
"import/no-extraneous-dependencies": [
26+
"error",
27+
{
28+
"devDependencies": true
29+
}
30+
],
31+
"no-underscore-dangle": [
32+
0
2433
]
2534
},
2635
"env": {
2736
"node": true,
2837
"mocha": true
2938
},
39+
"parserOptions": {
40+
"ecmaVersion": 6,
41+
"sourceType": "module"
42+
},
3043
"extends": [
3144
"eslint:recommended",
32-
"airbnb/base"
45+
"airbnb-base"
3346
]
3447
}

gulpfile.babel.js

+3-17
Original file line numberDiff line numberDiff line change
@@ -37,20 +37,6 @@ gulp.task('set-env', () => {
3737
});
3838
});
3939

40-
// Lint Javascript
41-
gulp.task('lint', () =>
42-
gulp.src(paths.js)
43-
// eslint() attaches the lint output to the "eslint" property
44-
// of the file object so it can be used by other modules.
45-
.pipe(plugins.eslint())
46-
// eslint.format() outputs the lint results to the console.
47-
// Alternatively use eslint.formatEach() (see Docs).
48-
.pipe(plugins.eslint.format())
49-
// To have the process exit with an error code (1) on
50-
// lint error, return the stream and pipe to failAfterError last.
51-
.pipe(plugins.eslint.failAfterError())
52-
);
53-
5440
// Copy non-js files to dist
5541
gulp.task('copy', () =>
5642
gulp.src(paths.nonJs)
@@ -74,12 +60,12 @@ gulp.task('babel', () =>
7460
);
7561

7662
// Start server with restart on file changes
77-
gulp.task('nodemon', ['lint', 'copy', 'babel'], () =>
63+
gulp.task('nodemon', ['copy', 'babel'], () =>
7864
plugins.nodemon({
7965
script: path.join('dist', 'index.js'),
8066
ext: 'js',
8167
ignore: ['node_modules/**/*.js', 'dist/**/*.js'],
82-
tasks: ['lint', 'copy', 'babel']
68+
tasks: ['copy', 'babel']
8369
})
8470
);
8571

@@ -98,7 +84,7 @@ gulp.task('pre-test', () =>
9884
// triggers mocha test with code coverage
9985
gulp.task('test', ['pre-test', 'set-env'], () => {
10086
let reporters;
101-
let exitCode = 0;
87+
let exitCode = 0;
10288

10389
if (plugins.util.env['code-coverage-reporter']) {
10490
reporters = [...options.codeCoverage.reporters, plugins.util.env['code-coverage-reporter']];

package.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"scripts": {
1313
"start": "gulp serve",
1414
"build": "gulp",
15-
"lint": "gulp lint",
15+
"lint": "eslint *.js server/**/*.js config/**/*.js && echo Lint Passed ❤",
1616
"test": "gulp mocha",
1717
"commit": "git-cz",
1818
"report-coverage": "coveralls < ./coverage/lcov.info"
@@ -65,13 +65,13 @@
6565
"coveralls": "^2.11.6",
6666
"cz-conventional-changelog": "1.1.5",
6767
"del": "^2.2.0",
68-
"eslint": "^1.10.3",
69-
"eslint-config-airbnb": "5.0.1",
68+
"eslint": "3.5.0",
69+
"eslint-config-airbnb-base": "7.1.0",
70+
"eslint-plugin-import": "1.16.0",
7071
"ghooks": "^1.2.4",
7172
"gulp": "3.9.1",
7273
"gulp-babel": "6.1.2",
7374
"gulp-env": "^0.4.0",
74-
"gulp-eslint": "^1.1.1",
7575
"gulp-istanbul": "1.0.0",
7676
"gulp-load-plugins": "^1.2.0",
7777
"gulp-mocha": "^2.2.0",

server/controllers/user.js

+10-10
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ import User from '../models/user';
66
function load(req, res, next, id) {
77
User.get(id)
88
.then((user) => {
9-
req.user = user; // eslint-disable-line no-param-reassign
9+
req.user = user; // eslint-disable-line no-param-reassign
1010
return next();
1111
})
12-
.catch((e) => next(e));
12+
.catch(e => next(e));
1313
}
1414

1515
/**
@@ -33,8 +33,8 @@ function create(req, res, next) {
3333
});
3434

3535
user.save()
36-
.then((savedUser) => res.json(savedUser))
37-
.catch((e) => next(e));
36+
.then(savedUser => res.json(savedUser))
37+
.catch(e => next(e));
3838
}
3939

4040
/**
@@ -49,8 +49,8 @@ function update(req, res, next) {
4949
user.mobileNumber = req.body.mobileNumber;
5050

5151
user.save()
52-
.then((savedUser) => res.json(savedUser))
53-
.catch((e) => next(e));
52+
.then(savedUser => res.json(savedUser))
53+
.catch(e => next(e));
5454
}
5555

5656
/**
@@ -62,8 +62,8 @@ function update(req, res, next) {
6262
function list(req, res, next) {
6363
const { limit = 50, skip = 0 } = req.query;
6464
User.list({ limit, skip })
65-
.then((users) => res.json(users))
66-
.catch((e) => next(e));
65+
.then(users => res.json(users))
66+
.catch(e => next(e));
6767
}
6868

6969
/**
@@ -73,8 +73,8 @@ function list(req, res, next) {
7373
function remove(req, res, next) {
7474
const user = req.user;
7575
user.remove()
76-
.then((deletedUser) => res.json(deletedUser))
77-
.catch((e) => next(e));
76+
.then(deletedUser => res.json(deletedUser))
77+
.catch(e => next(e));
7878
}
7979

8080
export default { load, get, create, update, list, remove };

server/helpers/APIError.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class ExtendableError extends Error {
1010
this.message = message;
1111
this.status = status;
1212
this.isPublic = isPublic;
13-
this.isOperational = true; // This is required since bluebird 4 doesn't append it anymore.
13+
this.isOperational = true; // This is required since bluebird 4 doesn't append it anymore.
1414
Error.captureStackTrace(this, this.constructor.name);
1515
}
1616
}

server/routes/auth.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import paramValidation from '../../config/param-validation';
55
import authCtrl from '../controllers/auth';
66
import config from '../../config/env';
77

8-
const router = express.Router(); // eslint-disable-line new-cap
8+
const router = express.Router(); // eslint-disable-line new-cap
99

1010
/** POST /api/auth/login - Returns token if correct username and password is provided */
1111
router.route('/login')

server/routes/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import express from 'express';
22
import userRoutes from './user';
33
import authRoutes from './auth';
44

5-
const router = express.Router(); // eslint-disable-line new-cap
5+
const router = express.Router(); // eslint-disable-line new-cap
66

77
/** GET /health-check - Check service health */
88
router.get('/health-check', (req, res) =>

server/routes/user.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import validate from 'express-validation';
33
import paramValidation from '../../config/param-validation';
44
import userCtrl from '../controllers/user';
55

6-
const router = express.Router(); // eslint-disable-line new-cap
6+
const router = express.Router(); // eslint-disable-line new-cap
77

88
router.route('/')
99
/** GET /api/users - Get list of users */

server/tests/misc.test.js

+14-11
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import request from 'supertest-as-promised';
22
import httpStatus from 'http-status';
3-
import chai from 'chai';
4-
import { expect } from 'chai';
3+
import chai, { expect } from 'chai';
54
import app from '../../index';
65

76
chai.config.includeStack = true;
@@ -12,10 +11,11 @@ describe('## Misc', () => {
1211
request(app)
1312
.get('/api/health-check')
1413
.expect(httpStatus.OK)
15-
.then(res => {
14+
.then((res) => {
1615
expect(res.text).to.equal('OK');
1716
done();
18-
});
17+
})
18+
.catch(done);
1919
});
2020
});
2121

@@ -24,10 +24,11 @@ describe('## Misc', () => {
2424
request(app)
2525
.get('/api/404')
2626
.expect(httpStatus.NOT_FOUND)
27-
.then(res => {
27+
.then((res) => {
2828
expect(res.body.message).to.equal('Not Found');
2929
done();
30-
});
30+
})
31+
.catch(done);
3132
});
3233
});
3334

@@ -36,10 +37,11 @@ describe('## Misc', () => {
3637
request(app)
3738
.get('/api/users/56z787zzz67fc')
3839
.expect(httpStatus.INTERNAL_SERVER_ERROR)
39-
.then(res => {
40+
.then((res) => {
4041
expect(res.body.message).to.equal('Internal Server Error');
4142
done();
42-
});
43+
})
44+
.catch(done);
4345
});
4446

4547
it('should handle express validation error - username is required', (done) => {
@@ -49,10 +51,11 @@ describe('## Misc', () => {
4951
mobileNumber: '1234567890'
5052
})
5153
.expect(httpStatus.BAD_REQUEST)
52-
.then(res => {
53-
expect(res.body.message).to.equal(`"username" is required`);
54+
.then((res) => {
55+
expect(res.body.message).to.equal('"username" is required');
5456
done();
55-
});
57+
})
58+
.catch(done);
5659
});
5760
});
5861
});

server/tests/user.test.js

+19-14
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import request from 'supertest-as-promised';
22
import httpStatus from 'http-status';
3-
import chai from 'chai';
4-
import { expect } from 'chai';
3+
import chai, { expect } from 'chai';
54
import app from '../../index';
65

76
chai.config.includeStack = true;
@@ -18,12 +17,13 @@ describe('## User APIs', () => {
1817
.post('/api/users')
1918
.send(user)
2019
.expect(httpStatus.OK)
21-
.then(res => {
20+
.then((res) => {
2221
expect(res.body.username).to.equal(user.username);
2322
expect(res.body.mobileNumber).to.equal(user.mobileNumber);
2423
user = res.body;
2524
done();
26-
});
25+
})
26+
.catch(done);
2727
});
2828
});
2929

@@ -32,21 +32,23 @@ describe('## User APIs', () => {
3232
request(app)
3333
.get(`/api/users/${user._id}`)
3434
.expect(httpStatus.OK)
35-
.then(res => {
35+
.then((res) => {
3636
expect(res.body.username).to.equal(user.username);
3737
expect(res.body.mobileNumber).to.equal(user.mobileNumber);
3838
done();
39-
});
39+
})
40+
.catch(done);
4041
});
4142

4243
it('should report error with message - Not found, when user does not exists', (done) => {
4344
request(app)
4445
.get('/api/users/56c787ccc67fc16ccc1a5e92')
4546
.expect(httpStatus.NOT_FOUND)
46-
.then(res => {
47+
.then((res) => {
4748
expect(res.body.message).to.equal('Not Found');
4849
done();
49-
});
50+
})
51+
.catch(done);
5052
});
5153
});
5254

@@ -57,11 +59,12 @@ describe('## User APIs', () => {
5759
.put(`/api/users/${user._id}`)
5860
.send(user)
5961
.expect(httpStatus.OK)
60-
.then(res => {
62+
.then((res) => {
6163
expect(res.body.username).to.equal('KK');
6264
expect(res.body.mobileNumber).to.equal(user.mobileNumber);
6365
done();
64-
});
66+
})
67+
.catch(done);
6568
});
6669
});
6770

@@ -70,10 +73,11 @@ describe('## User APIs', () => {
7073
request(app)
7174
.get('/api/users')
7275
.expect(httpStatus.OK)
73-
.then(res => {
76+
.then((res) => {
7477
expect(res.body).to.be.an('array');
7578
done();
76-
});
79+
})
80+
.catch(done);
7781
});
7882
});
7983

@@ -82,11 +86,12 @@ describe('## User APIs', () => {
8286
request(app)
8387
.delete(`/api/users/${user._id}`)
8488
.expect(httpStatus.OK)
85-
.then(res => {
89+
.then((res) => {
8690
expect(res.body.username).to.equal('KK');
8791
expect(res.body.mobileNumber).to.equal(user.mobileNumber);
8892
done();
89-
});
93+
})
94+
.catch(done);
9095
});
9196
});
9297
});

0 commit comments

Comments
 (0)