Skip to content

Commit

Permalink
Update eslint to v3.5. Fix lint errors. Move from gulp to npm task fo…
Browse files Browse the repository at this point in the history
…r… (#46)

* Update eslint to v3.5. Fix lint errors. Move from gulp to npm task for lint. Closes #44, #45.

* Remove gulp-eslint
  • Loading branch information
kunalkapadia committed Sep 23, 2016
1 parent 7ddaa73 commit c1c8dbe
Show file tree
Hide file tree
Showing 10 changed files with 68 additions and 61 deletions.
15 changes: 14 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,27 @@
// TODO: turn on later
"comma-dangle": [
0
],
"import/no-extraneous-dependencies": [
"error",
{
"devDependencies": true
}
],
"no-underscore-dangle": [
0
]
},
"env": {
"node": true,
"mocha": true
},
"parserOptions": {
"ecmaVersion": 6,
"sourceType": "module"
},
"extends": [
"eslint:recommended",
"airbnb/base"
"airbnb-base"
]
}
20 changes: 3 additions & 17 deletions gulpfile.babel.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,6 @@ gulp.task('set-env', () => {
});
});

// Lint Javascript
gulp.task('lint', () =>
gulp.src(paths.js)
// eslint() attaches the lint output to the "eslint" property
// of the file object so it can be used by other modules.
.pipe(plugins.eslint())
// eslint.format() outputs the lint results to the console.
// Alternatively use eslint.formatEach() (see Docs).
.pipe(plugins.eslint.format())
// To have the process exit with an error code (1) on
// lint error, return the stream and pipe to failAfterError last.
.pipe(plugins.eslint.failAfterError())
);

// Copy non-js files to dist
gulp.task('copy', () =>
gulp.src(paths.nonJs)
Expand All @@ -74,12 +60,12 @@ gulp.task('babel', () =>
);

// Start server with restart on file changes
gulp.task('nodemon', ['lint', 'copy', 'babel'], () =>
gulp.task('nodemon', ['copy', 'babel'], () =>
plugins.nodemon({
script: path.join('dist', 'index.js'),
ext: 'js',
ignore: ['node_modules/**/*.js', 'dist/**/*.js'],
tasks: ['lint', 'copy', 'babel']
tasks: ['copy', 'babel']
})
);

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

if (plugins.util.env['code-coverage-reporter']) {
reporters = [...options.codeCoverage.reporters, plugins.util.env['code-coverage-reporter']];
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"scripts": {
"start": "gulp serve",
"build": "gulp",
"lint": "gulp lint",
"lint": "eslint *.js server/**/*.js config/**/*.js && echo Lint Passed ❤",
"test": "gulp mocha",
"commit": "git-cz",
"report-coverage": "coveralls < ./coverage/lcov.info"
Expand Down Expand Up @@ -65,13 +65,13 @@
"coveralls": "^2.11.6",
"cz-conventional-changelog": "1.1.5",
"del": "^2.2.0",
"eslint": "^1.10.3",
"eslint-config-airbnb": "5.0.1",
"eslint": "3.5.0",
"eslint-config-airbnb-base": "7.1.0",
"eslint-plugin-import": "1.16.0",
"ghooks": "^1.2.4",
"gulp": "3.9.1",
"gulp-babel": "6.1.2",
"gulp-env": "^0.4.0",
"gulp-eslint": "^1.1.1",
"gulp-istanbul": "1.0.0",
"gulp-load-plugins": "^1.2.0",
"gulp-mocha": "^2.2.0",
Expand Down
20 changes: 10 additions & 10 deletions server/controllers/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import User from '../models/user';
function load(req, res, next, id) {
User.get(id)
.then((user) => {
req.user = user; // eslint-disable-line no-param-reassign
req.user = user; // eslint-disable-line no-param-reassign
return next();
})
.catch((e) => next(e));
.catch(e => next(e));
}

/**
Expand All @@ -33,8 +33,8 @@ function create(req, res, next) {
});

user.save()
.then((savedUser) => res.json(savedUser))
.catch((e) => next(e));
.then(savedUser => res.json(savedUser))
.catch(e => next(e));
}

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

user.save()
.then((savedUser) => res.json(savedUser))
.catch((e) => next(e));
.then(savedUser => res.json(savedUser))
.catch(e => next(e));
}

/**
Expand All @@ -62,8 +62,8 @@ function update(req, res, next) {
function list(req, res, next) {
const { limit = 50, skip = 0 } = req.query;
User.list({ limit, skip })
.then((users) => res.json(users))
.catch((e) => next(e));
.then(users => res.json(users))
.catch(e => next(e));
}

/**
Expand All @@ -73,8 +73,8 @@ function list(req, res, next) {
function remove(req, res, next) {
const user = req.user;
user.remove()
.then((deletedUser) => res.json(deletedUser))
.catch((e) => next(e));
.then(deletedUser => res.json(deletedUser))
.catch(e => next(e));
}

export default { load, get, create, update, list, remove };
2 changes: 1 addition & 1 deletion server/helpers/APIError.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class ExtendableError extends Error {
this.message = message;
this.status = status;
this.isPublic = isPublic;
this.isOperational = true; // This is required since bluebird 4 doesn't append it anymore.
this.isOperational = true; // This is required since bluebird 4 doesn't append it anymore.
Error.captureStackTrace(this, this.constructor.name);
}
}
Expand Down
2 changes: 1 addition & 1 deletion server/routes/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import paramValidation from '../../config/param-validation';
import authCtrl from '../controllers/auth';
import config from '../../config/env';

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

/** POST /api/auth/login - Returns token if correct username and password is provided */
router.route('/login')
Expand Down
2 changes: 1 addition & 1 deletion server/routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import express from 'express';
import userRoutes from './user';
import authRoutes from './auth';

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

/** GET /health-check - Check service health */
router.get('/health-check', (req, res) =>
Expand Down
2 changes: 1 addition & 1 deletion server/routes/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import validate from 'express-validation';
import paramValidation from '../../config/param-validation';
import userCtrl from '../controllers/user';

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

router.route('/')
/** GET /api/users - Get list of users */
Expand Down
25 changes: 14 additions & 11 deletions server/tests/misc.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import request from 'supertest-as-promised';
import httpStatus from 'http-status';
import chai from 'chai';
import { expect } from 'chai';
import chai, { expect } from 'chai';
import app from '../../index';

chai.config.includeStack = true;
Expand All @@ -12,10 +11,11 @@ describe('## Misc', () => {
request(app)
.get('/api/health-check')
.expect(httpStatus.OK)
.then(res => {
.then((res) => {
expect(res.text).to.equal('OK');
done();
});
})
.catch(done);
});
});

Expand All @@ -24,10 +24,11 @@ describe('## Misc', () => {
request(app)
.get('/api/404')
.expect(httpStatus.NOT_FOUND)
.then(res => {
.then((res) => {
expect(res.body.message).to.equal('Not Found');
done();
});
})
.catch(done);
});
});

Expand All @@ -36,10 +37,11 @@ describe('## Misc', () => {
request(app)
.get('/api/users/56z787zzz67fc')
.expect(httpStatus.INTERNAL_SERVER_ERROR)
.then(res => {
.then((res) => {
expect(res.body.message).to.equal('Internal Server Error');
done();
});
})
.catch(done);
});

it('should handle express validation error - username is required', (done) => {
Expand All @@ -49,10 +51,11 @@ describe('## Misc', () => {
mobileNumber: '1234567890'
})
.expect(httpStatus.BAD_REQUEST)
.then(res => {
expect(res.body.message).to.equal(`"username" is required`);
.then((res) => {
expect(res.body.message).to.equal('"username" is required');
done();
});
})
.catch(done);
});
});
});
33 changes: 19 additions & 14 deletions server/tests/user.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import request from 'supertest-as-promised';
import httpStatus from 'http-status';
import chai from 'chai';
import { expect } from 'chai';
import chai, { expect } from 'chai';
import app from '../../index';

chai.config.includeStack = true;
Expand All @@ -18,12 +17,13 @@ describe('## User APIs', () => {
.post('/api/users')
.send(user)
.expect(httpStatus.OK)
.then(res => {
.then((res) => {
expect(res.body.username).to.equal(user.username);
expect(res.body.mobileNumber).to.equal(user.mobileNumber);
user = res.body;
done();
});
})
.catch(done);
});
});

Expand All @@ -32,21 +32,23 @@ describe('## User APIs', () => {
request(app)
.get(`/api/users/${user._id}`)
.expect(httpStatus.OK)
.then(res => {
.then((res) => {
expect(res.body.username).to.equal(user.username);
expect(res.body.mobileNumber).to.equal(user.mobileNumber);
done();
});
})
.catch(done);
});

it('should report error with message - Not found, when user does not exists', (done) => {
request(app)
.get('/api/users/56c787ccc67fc16ccc1a5e92')
.expect(httpStatus.NOT_FOUND)
.then(res => {
.then((res) => {
expect(res.body.message).to.equal('Not Found');
done();
});
})
.catch(done);
});
});

Expand All @@ -57,11 +59,12 @@ describe('## User APIs', () => {
.put(`/api/users/${user._id}`)
.send(user)
.expect(httpStatus.OK)
.then(res => {
.then((res) => {
expect(res.body.username).to.equal('KK');
expect(res.body.mobileNumber).to.equal(user.mobileNumber);
done();
});
})
.catch(done);
});
});

Expand All @@ -70,10 +73,11 @@ describe('## User APIs', () => {
request(app)
.get('/api/users')
.expect(httpStatus.OK)
.then(res => {
.then((res) => {
expect(res.body).to.be.an('array');
done();
});
})
.catch(done);
});
});

Expand All @@ -82,11 +86,12 @@ describe('## User APIs', () => {
request(app)
.delete(`/api/users/${user._id}`)
.expect(httpStatus.OK)
.then(res => {
.then((res) => {
expect(res.body.username).to.equal('KK');
expect(res.body.mobileNumber).to.equal(user.mobileNumber);
done();
});
})
.catch(done);
});
});
});

0 comments on commit c1c8dbe

Please sign in to comment.