Skip to content

Commit 12275f0

Browse files
committedJun 15, 2019
better linting
1 parent eb23b1e commit 12275f0

12 files changed

+1732
-1286
lines changed
 

‎.eslintrc

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{
2+
"extends": [
3+
"standard",
4+
"prettier",
5+
"prettier/standard"
6+
],
7+
"parserOptions": {
8+
"ecmaVersion": 9
9+
},
10+
"plugins": [
11+
"prettier",
12+
"mocha"
13+
],
14+
"rules": {
15+
"mocha/no-exclusive-tests": "error",
16+
"prettier/prettier": "error",
17+
"standard/no-callback-literal": "off",
18+
"no-unused-vars": [
19+
"error",
20+
{
21+
"args": "none",
22+
"varsIgnorePattern": "^_",
23+
"argsIgnorePattern": "^_"
24+
}
25+
],
26+
"prefer-const": [
27+
"error", {
28+
"destructuring": "any",
29+
"ignoreReadBeforeAssign": false
30+
}
31+
]
32+
},
33+
"env": {
34+
"node": true,
35+
"es6": true,
36+
"mocha": true
37+
}
38+
}

‎.npmignore

+1
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ examples/
88
support/
99
test/
1010
coverage/
11+
.vscode/

‎.prettierrc.yml

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
semi: false
2+
singleQuote: true
3+
trailingComma: es5
4+
printWidth: 80

‎.vscode/settings.json

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"editor.formatOnSave": false,
3+
"editor.formatOnPaste": false,
4+
"editor.tabSize": 2,
5+
"eslint.autoFixOnSave": true,
6+
"javascript.updateImportsOnFileMove.enabled": "never",
7+
}

‎package.json

+17-7
Original file line numberDiff line numberDiff line change
@@ -25,21 +25,31 @@
2525
"mongodb": "^3.1.0"
2626
},
2727
"devDependencies": {
28+
"@commitlint/cli": "^8.0.0",
29+
"@commitlint/config-conventional": "^8.0.0",
30+
"eslint": "^5.16.0",
31+
"eslint-config-prettier": "^4.3.0",
32+
"eslint-config-prettier-standard": "^2.0.0",
33+
"eslint-config-standard": "^12.0.0",
34+
"eslint-plugin-import": "^2.17.3",
35+
"eslint-plugin-mocha": "^5.3.0",
36+
"eslint-plugin-node": "^9.1.0",
37+
"eslint-plugin-prettier": "^3.1.0",
38+
"eslint-plugin-promise": "^4.1.1",
39+
"eslint-plugin-standard": "^4.0.0",
2840
"expect.js": "^0.3.1",
2941
"express-session": "^1.0.0",
42+
"husky": "^2.4.1",
43+
"lint-staged": "^8.2.1",
3044
"mocha": "^5.0.1",
3145
"mongoose": "^5.2.0",
3246
"nyc": "^11.2.1",
33-
"xo": "^0.20.3"
47+
"prettier": "^1.18.2"
3448
},
3549
"scripts": {
36-
"lint": "xo src",
50+
"lint": "eslint src test",
51+
"lint:fix": "eslint src test --fix",
3752
"cover": "nyc report --reporter=text-lcov",
3853
"test": "nyc mocha"
39-
},
40-
"xo": {
41-
"space": 2,
42-
"semicolon": false,
43-
"prettier": true
4454
}
4555
}

‎src/crypto.js

+24-24
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,22 @@ class Crypto {
1313
}
1414

1515
set(plaintext) {
16-
let iv = this.crypto.randomBytes(this.iv_size).toString(this.encodeas),
17-
aad = this._digest(
18-
iv + this.secret,
19-
JSON.stringify(plaintext),
20-
this.hashing,
21-
this.encodeas
22-
),
23-
ct = this._encrypt(
24-
this.secret,
25-
JSON.stringify(plaintext),
26-
this.algorithm,
27-
this.encodeas,
28-
iv,
29-
aad
30-
),
31-
hmac = this._digest(this.secret, ct.ct, this.hashing, this.encodeas)
16+
const iv = this.crypto.randomBytes(this.iv_size).toString(this.encodeas)
17+
const aad = this._digest(
18+
iv + this.secret,
19+
JSON.stringify(plaintext),
20+
this.hashing,
21+
this.encodeas
22+
)
23+
const ct = this._encrypt(
24+
this.secret,
25+
JSON.stringify(plaintext),
26+
this.algorithm,
27+
this.encodeas,
28+
iv,
29+
aad
30+
)
31+
const hmac = this._digest(this.secret, ct.ct, this.hashing, this.encodeas)
3232

3333
const obj = JSON.stringify({
3434
hmac,
@@ -84,11 +84,11 @@ class Crypto {
8484
}
8585

8686
_encrypt(key, pt, algo, encodeas, iv, aad) {
87-
let cipher = this.crypto.createCipheriv(algo, key, iv, {
88-
authTagLength: this.at_size,
89-
}),
90-
ct,
91-
at
87+
const cipher = this.crypto.createCipheriv(algo, key, iv, {
88+
authTagLength: this.at_size,
89+
})
90+
let ct
91+
let at
9292

9393
if (aad) {
9494
try {
@@ -109,12 +109,12 @@ class Crypto {
109109
throw err
110110
}
111111

112-
return at ? {ct, at} : {ct}
112+
return at ? { ct, at } : { ct }
113113
}
114114

115115
_decrypt(key, ct, algo, encodeas, iv, at, aad) {
116-
let cipher = this.crypto.createDecipheriv(algo, key, iv),
117-
pt
116+
const cipher = this.crypto.createDecipheriv(algo, key, iv)
117+
let pt
118118

119119
if (at) {
120120
try {

‎src/index.js

+21-12
Original file line numberDiff line numberDiff line change
@@ -147,20 +147,23 @@ module.exports = function(connect) {
147147

148148
setAutoRemoveAsync() {
149149
const removeQuery = () => {
150-
return {expires: {$lt: new Date()}}
150+
return { expires: { $lt: new Date() } }
151151
}
152152
switch (this.autoRemove) {
153153
case 'native':
154154
return this.collection.createIndex(
155-
{expires: 1},
156-
Object.assign({expireAfterSeconds: 0}, this.writeOperationOptions)
155+
{ expires: 1 },
156+
Object.assign({ expireAfterSeconds: 0 }, this.writeOperationOptions)
157157
)
158158
case 'interval':
159159
this.timer = setInterval(
160160
() =>
161161
this.collection.deleteMany(
162162
removeQuery(),
163-
Object.assign({}, this.writeOperationOptions, {w: 0, j: false})
163+
Object.assign({}, this.writeOperationOptions, {
164+
w: 0,
165+
j: false,
166+
})
164167
),
165168
this.autoRemoveInterval * 1000 * 60
166169
)
@@ -223,7 +226,10 @@ module.exports = function(connect) {
223226
.then(collection =>
224227
collection.findOne({
225228
_id: this.computeStorageId(sid),
226-
$or: [{expires: {$exists: false}}, {expires: {$gt: new Date()}}],
229+
$or: [
230+
{ expires: { $exists: false } },
231+
{ expires: { $gt: new Date() } },
232+
],
227233
})
228234
)
229235
.then(session => {
@@ -297,9 +303,9 @@ module.exports = function(connect) {
297303
this.collectionReady()
298304
.then(collection =>
299305
collection.updateOne(
300-
{_id: this.computeStorageId(sid)},
301-
{$set: s},
302-
Object.assign({upsert: true}, this.writeOperationOptions)
306+
{ _id: this.computeStorageId(sid) },
307+
{ $set: s },
308+
Object.assign({ upsert: true }, this.writeOperationOptions)
303309
)
304310
)
305311
.then(rawResponse => {
@@ -347,8 +353,8 @@ module.exports = function(connect) {
347353
this.collectionReady()
348354
.then(collection =>
349355
collection.updateOne(
350-
{_id: this.computeStorageId(sid)},
351-
{$set: updateFields},
356+
{ _id: this.computeStorageId(sid) },
357+
{ $set: updateFields },
352358
this.writeOperationOptions
353359
)
354360
)
@@ -368,7 +374,10 @@ module.exports = function(connect) {
368374
this.collectionReady()
369375
.then(collection =>
370376
collection.find({
371-
$or: [{expires: {$exists: false}}, {expires: {$gt: new Date()}}],
377+
$or: [
378+
{ expires: { $exists: false } },
379+
{ expires: { $gt: new Date() } },
380+
],
372381
})
373382
)
374383
.then(sessions => {
@@ -398,7 +407,7 @@ module.exports = function(connect) {
398407
this.collectionReady()
399408
.then(collection =>
400409
collection.deleteOne(
401-
{_id: this.computeStorageId(sid)},
410+
{ _id: this.computeStorageId(sid) },
402411
this.writeOperationOptions
403412
)
404413
)

‎test/crypto.js

+8-9
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const expect = require('expect.js')
44
const Crypto = require('../src/crypto.js')
55

66
const options = {
7-
secret: 'squirrel'
7+
secret: 'squirrel',
88
}
99

1010
Crypto.init(options)
@@ -35,7 +35,7 @@ describe('Crypto', () => {
3535

3636
try {
3737
pt = Crypto.get(ct)
38-
} catch(err) {
38+
} catch (err) {
3939
expect(err).to.equal('Encrypted session was tampered with!')
4040
}
4141
done()
@@ -44,16 +44,15 @@ describe('Crypto', () => {
4444
it('Authentication tag validation', done => {
4545
ct = JSON.parse(ct)
4646
ct.hmac = hmac
47-
48-
if (!ct.at)
49-
done()
50-
47+
48+
if (!ct.at) done()
49+
5150
ct.at = 'funky chicken'
5251
ct = JSON.stringify(ct)
5352

5453
try {
5554
pt = Crypto.get(ct)
56-
} catch(err) {
55+
} catch (err) {
5756
expect(err).to.match(/Unsupported state or unable to authenticate data/)
5857
}
5958
done()
@@ -63,13 +62,13 @@ describe('Crypto', () => {
6362
ct = JSON.parse(ct)
6463

6564
if (!ct.aad) done()
66-
65+
6766
ct.aad = 'funky chicken'
6867
ct = JSON.stringify(ct)
6968

7069
try {
7170
pt = Crypto.get(ct)
72-
} catch(err) {
71+
} catch (err) {
7372
expect(err).to.match(/Unsupported state or unable to authenticate data/)
7473
}
7574
done()

‎test/events.js

+38-25
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,19 @@ const MongoStore = require('..')(expressSession)
77

88
const futureDate = new Date(2030, 1)
99

10-
const connectionString = process.env.MONGODB_URL || 'mongodb://localhost:27017/connect-mongo-test'
10+
const connectionString =
11+
process.env.MONGODB_URL || 'mongodb://localhost:27017/connect-mongo-test'
1112

1213
function noop() {}
1314

1415
describe('Events', () => {
1516
let store, collection
16-
beforeEach(function (done) {
17+
beforeEach(function(done) {
1718
this.timeout(10000)
1819
store = new MongoStore({
1920
url: connectionString,
2021
mongoOptions: { useNewUrlParser: true },
21-
collection: 'sessions-test'
22+
collection: 'sessions-test',
2223
})
2324
store.once('connected', () => {
2425
collection = store.collection
@@ -35,14 +36,14 @@ describe('Events', () => {
3536
expect(sid).to.be('foo1')
3637
done()
3738
})
38-
store.set('foo1', {foo: 'bar'}, noop)
39+
store.set('foo1', { foo: 'bar' }, noop)
3940
})
4041
it('should emit a `set` event', done => {
4142
store.once('set', sid => {
4243
expect(sid).to.be('foo2')
4344
done()
4445
})
45-
store.set('foo2', {foo: 'bar'}, noop)
46+
store.set('foo2', { foo: 'bar' }, noop)
4647
})
4748
})
4849

@@ -52,33 +53,39 @@ describe('Events', () => {
5253
expect(sid).to.be('foo3')
5354
done()
5455
})
55-
collection.insertOne({_id: 'foo3', session: {foo: 'bar1'}, expires: futureDate}, err => {
56-
expect(err).not.to.be.ok()
57-
store.set('foo3', {foo: 'bar2'}, noop)
58-
})
56+
collection.insertOne(
57+
{ _id: 'foo3', session: { foo: 'bar1' }, expires: futureDate },
58+
err => {
59+
expect(err).not.to.be.ok()
60+
store.set('foo3', { foo: 'bar2' }, noop)
61+
}
62+
)
5963
})
6064
it('should emit an `set` event', done => {
6165
store.once('update', sid => {
6266
expect(sid).to.be('foo4')
6367
done()
6468
})
65-
collection.insertOne({_id: 'foo4', session: {foo: 'bar1'}, expires: futureDate}, err => {
66-
expect(err).not.to.be.ok()
67-
store.set('foo4', {foo: 'bar2'}, noop)
68-
})
69+
collection.insertOne(
70+
{ _id: 'foo4', session: { foo: 'bar1' }, expires: futureDate },
71+
err => {
72+
expect(err).not.to.be.ok()
73+
store.set('foo4', { foo: 'bar2' }, noop)
74+
}
75+
)
6976
})
7077
})
7178
})
7279

7380
describe('Events w/ Crypto', () => {
7481
let store, collection
75-
beforeEach(function (done) {
82+
beforeEach(function(done) {
7683
this.timeout(10000)
7784
store = new MongoStore({
7885
url: connectionString,
7986
mongoOptions: { useNewUrlParser: true },
8087
collection: 'sessions-test',
81-
secret: 'squirrel'
88+
secret: 'squirrel',
8289
})
8390
store.once('connected', () => {
8491
collection = store.collection
@@ -95,14 +102,14 @@ describe('Events w/ Crypto', () => {
95102
expect(sid).to.be('foo1')
96103
done()
97104
})
98-
store.set('foo1', {foo: 'bar'}, noop)
105+
store.set('foo1', { foo: 'bar' }, noop)
99106
})
100107
it('should emit a `set` event', done => {
101108
store.once('set', sid => {
102109
expect(sid).to.be('foo2')
103110
done()
104111
})
105-
store.set('foo2', {foo: 'bar'}, noop)
112+
store.set('foo2', { foo: 'bar' }, noop)
106113
})
107114
})
108115

@@ -112,20 +119,26 @@ describe('Events w/ Crypto', () => {
112119
expect(sid).to.be('foo3')
113120
done()
114121
})
115-
collection.insertOne({_id: 'foo3', session: {foo: 'bar1'}, expires: futureDate}, err => {
116-
expect(err).not.to.be.ok()
117-
store.set('foo3', {foo: 'bar2'}, noop)
118-
})
122+
collection.insertOne(
123+
{ _id: 'foo3', session: { foo: 'bar1' }, expires: futureDate },
124+
err => {
125+
expect(err).not.to.be.ok()
126+
store.set('foo3', { foo: 'bar2' }, noop)
127+
}
128+
)
119129
})
120130
it('should emit an `set` event', done => {
121131
store.once('update', sid => {
122132
expect(sid).to.be('foo4')
123133
done()
124134
})
125-
collection.insertOne({_id: 'foo4', session: {foo: 'bar1'}, expires: futureDate}, err => {
126-
expect(err).not.to.be.ok()
127-
store.set('foo4', {foo: 'bar2'}, noop)
128-
})
135+
collection.insertOne(
136+
{ _id: 'foo4', session: { foo: 'bar1' }, expires: futureDate },
137+
err => {
138+
expect(err).not.to.be.ok()
139+
store.set('foo4', { foo: 'bar2' }, noop)
140+
}
141+
)
129142
})
130143
})
131144
})

‎test/legacy-loader.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ process.on('unhandledRejection', (reason, err) => {
1010
process.exit(1)
1111
})
1212

13-
describe('Legacy tests', function () {
13+
describe('Legacy tests', function() {
1414
this.timeout(6000)
1515
Object.keys(legacyTests).forEach(testName => {
1616
it(testName, legacyTests[testName])

‎test/legacy-tests.js

+283-224
Large diffs are not rendered by default.

‎yarn.lock

+1,290-984
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)
Please sign in to comment.