From 467e9ffc193e9c66491446681fbb7143a680bd36 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nico=20Schl=C3=B6mer?= Date: Fri, 25 Dec 2015 16:25:05 +0100 Subject: [PATCH] replace jscs, jshint by eslint --- .eslintrc | 10 ++++++++++ .jscsrc | 3 --- package.json | 9 ++++----- src/index.js | 34 +++++++++++++++++----------------- test/.eslintrc | 13 +++++++++++++ test/index.js | 33 +++++++++++++++------------------ test/mocha.opts | 3 +++ 7 files changed, 62 insertions(+), 43 deletions(-) create mode 100644 .eslintrc delete mode 100644 .jscsrc create mode 100644 test/.eslintrc create mode 100644 test/mocha.opts diff --git a/.eslintrc b/.eslintrc new file mode 100644 index 0000000..a9b68c5 --- /dev/null +++ b/.eslintrc @@ -0,0 +1,10 @@ +{ + "extends": "airbnb/base", + "ecmaFeatures": { + "generators": true + }, + "rules": { + "object-curly-spacing": 0, + "no-cond-assign": [2, "except-parens"] + } +} diff --git a/.jscsrc b/.jscsrc deleted file mode 100644 index 4b5fa83..0000000 --- a/.jscsrc +++ /dev/null @@ -1,3 +0,0 @@ -{ - "preset": "google" -} diff --git a/package.json b/package.json index 185dbe8..e2d92c3 100644 --- a/package.json +++ b/package.json @@ -4,9 +4,8 @@ "description": "Erase collections, models and schemas for unit testing with mongoose", "main": "src/index.js", "scripts": { - "test": "npm run jshint && npm run jscs && mocha", - "jshint": "jshint **/*.js", - "jscs": "jscs **/*.js", + "lint": "eslint test src", + "test": "npm run lint && mocha test/", "coveralls": "mocha --require blanket -R mocha-lcov-reporter | coveralls" }, "repository": { @@ -32,8 +31,8 @@ "devDependencies": { "blanket": "^1.1.7", "coveralls": "^2.11.4", - "jscs": "^2.1.0", - "jshint": "^2.8.0", + "eslint": "^1.9.0", + "eslint-config-airbnb": "^2.0.0", "mocha": "^2.2.5", "mocha-lcov-reporter": "1.0.0", "mongoose": "^4.1.2", diff --git a/src/index.js b/src/index.js index 4346403..f2ed228 100644 --- a/src/index.js +++ b/src/index.js @@ -1,38 +1,38 @@ -var async = require('async'); +const async = require('async'); // requires mongoose to be connected to the database function erase(mongoose, done) { async.waterfall([ // ensure a database connection is established - function(cb) { + (cb) => { if (!mongoose.connection.db) { return cb(new Error('no established database connection')); } cb(); }, // get collections - function(cb) { + (cb) => { mongoose.connection.db.collections(cb); }, // drop collections - function(collections, cb) { - async.each(collections, function(collection, eachCb) { + (collections, cb) => { + async.each(collections, (collection, eachCb) => { if (collection.collectionName.match(/^system\./)) {return eachCb();} // drop collection collection.drop(eachCb); }, cb); }, // reset mongoose models - function(cb) { + (cb) => { mongoose.connection.models = {}; mongoose.models = {}; mongoose.modelSchemas = {}; cb(); }, - //// ensureIndexes - //_.map(models, function (model) { - // return model.ensureIndexes.bind(model); - //}) + // // ensureIndexes + // _.map(models, function (model) { + // return model.ensureIndexes.bind(model); + // }) ], done); } @@ -42,15 +42,15 @@ function connect(mongoose, dbURI, options, cb) { } function connectAndErase(mongoose, dbURI, options) { - options = options || {}; - return function(done) { + const newOptions = options || {}; + return (done) => { async.series([ - function(cb) { - connect(mongoose, dbURI, options, cb); + (cb) => { + connect(mongoose, dbURI, newOptions, cb); }, - function(cb) { + (cb) => { erase(mongoose, cb); - } + }, ], done); }; } @@ -58,5 +58,5 @@ function connectAndErase(mongoose, dbURI, options) { module.exports = { connect: connect, erase: erase, - connectAndErase: connectAndErase + connectAndErase: connectAndErase, }; diff --git a/test/.eslintrc b/test/.eslintrc new file mode 100644 index 0000000..349da3b --- /dev/null +++ b/test/.eslintrc @@ -0,0 +1,13 @@ +{ + "extends": "../.eslintrc", + "env": { + "mocha": true + }, + "globals": { + "should": true + }, + "rules": { + "func-names": 0, + "no-unused-expressions": 0 + } +} diff --git a/test/index.js b/test/index.js index b023116..4bcd816 100644 --- a/test/index.js +++ b/test/index.js @@ -1,42 +1,39 @@ -var dbURI = 'mongodb://localhost/mongoose-erase'; -var mongoose = require('mongoose'); -var async = require('async'); -var should = require('should'); +const dbURI = 'mongodb://localhost/mongoose-erase'; +const mongoose = require('mongoose'); +const async = require('async'); -var erase = require('../'); +const erase = require('../'); -describe('erase()', function() { - - before(function(done) { +describe('erase()', () => { + before((done) => { async.series([ // make sure that database is connected and erase it erase.connectAndErase(mongoose, dbURI), // add collection users - function(cb) { - var User = mongoose.model('User', new mongoose.Schema({ - name: {type: String, index: true} + (cb) => { + const User = mongoose.model('User', new mongoose.Schema({ + name: {type: String, index: true}, })); User.create({name: 'Darth'}, cb); }, // erase - function(cb) { + (cb) => { erase.erase(mongoose, cb); - } + }, ], done); }); - it('should remove collections', function(done) { - mongoose.connection.db.collections(function(err, collections) { + it('should remove collections', function assertDeletion(done) { + mongoose.connection.db.collections((err, collections) => { if (err) {return done(err);} collections.should.have.lengthOf(1); done(); }); }); - it('should remove models', function() { - (function() { + it('should remove models', () => { + (() => { mongoose.model('User'); }).should.throw(); }); - }); diff --git a/test/mocha.opts b/test/mocha.opts new file mode 100644 index 0000000..8bbfc3a --- /dev/null +++ b/test/mocha.opts @@ -0,0 +1,3 @@ +--compilers js:babel-core/register +--recursive +-r should