Skip to content

Commit 448139a

Browse files
committed
Merge pull request #17 from arusakov/eslint
JavaScript code linting via eslint
2 parents 2f4e506 + e1b3954 commit 448139a

File tree

6 files changed

+92
-37
lines changed

6 files changed

+92
-37
lines changed

.eslintrc

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{
2+
"env": {
3+
"node": true
4+
},
5+
"parserOptions": {
6+
"ecmaVersion": 6,
7+
"ecmaFeatures": {}
8+
},
9+
"rules": {
10+
"block-scoped-var": 2,
11+
"no-cond-assign": 2,
12+
"no-control-regex": 2,
13+
"no-debugger": 2,
14+
"no-dupe-args": 2,
15+
"no-dupe-keys": 2,
16+
"no-duplicate-case": 2,
17+
"no-ex-assign": 2,
18+
"no-extra-semi": 2,
19+
"no-func-assign": 2,
20+
"no-invalid-regexp": 2,
21+
"no-irregular-whitespace": 2,
22+
"no-negated-in-lhs": 2,
23+
"no-obj-calls": 2,
24+
"no-redeclare": 2,
25+
"no-regex-spaces": 2,
26+
"no-sparse-arrays": 2,
27+
"no-unexpected-multiline": 2,
28+
"no-unreachable": 2,
29+
"no-delete-var": 2,
30+
"no-shadow": 2,
31+
"no-undef": 2,
32+
"radix": 2,
33+
"semi": 2,
34+
"use-isnan": 2,
35+
"valid-jsdoc": 2,
36+
"valid-typeof": 2
37+
}
38+
}

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@ node_modules/*
44
.idea/*
55
*.snap
66
*.xlog
7+
8+
npm-debug.log

.travis.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,5 @@ script:
1818
- sudo apt-get -y install tarantool
1919
- ./test/box.lua &
2020
- sleep 2
21-
- npm test
21+
- npm run lint
22+
- npm test

lib/connection.js

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
/* global Promise */
2+
13
'use strict';
24
var tarantoolConstants = require('./const');
35
var net = require('net');
@@ -18,7 +20,7 @@ var exampleCustomMsgpack = {
1820
return msgpack.encode(obj);
1921
},
2022
decode: function(buf){
21-
return msgpack.decode(obj);
23+
return msgpack.decode(buf);
2224
}
2325
};
2426

@@ -91,7 +93,7 @@ TarantoolConnection.prototype._getSpaceId = function(name){
9193
{
9294
throw new Error('Cannot read a space name or space is not defined');
9395
}
94-
}.bind(this))
96+
}.bind(this));
9597
};
9698

9799
TarantoolConnection.prototype._getIndexId = function(spaceId, indexName){
@@ -126,7 +128,7 @@ TarantoolConnection.prototype._getMetadata = function(spaceName, indexName){
126128
return this._getSpaceId(spaceName)
127129
.then(function(spaceId){
128130
return Promise.all([spaceId, this._getIndexId(spaceId, indexName)]);
129-
}.bind(this))
131+
}.bind(this));
130132
}
131133
var promises = [];
132134
if (typeof(spaceName) == 'string')
@@ -143,7 +145,7 @@ TarantoolConnection.prototype._getMetadata = function(spaceName, indexName){
143145
};
144146

145147
TarantoolConnection.prototype.onData = function(data){
146-
148+
var trackResult;
147149
switch(this.state){
148150
case states.PREHELLO:
149151
for (var i = 0; i<this.commandsQueue.length; i++)
@@ -163,7 +165,7 @@ TarantoolConnection.prototype.onData = function(data){
163165
this.state = states.CONNECTED;
164166
break;
165167
case states.CONNECTED:
166-
var trackResult = this._responseBufferTrack(data);
168+
trackResult = this._responseBufferTrack(data);
167169
if (trackResult.length == 2)
168170
{
169171
this.state = states.AWAITING;
@@ -185,7 +187,7 @@ TarantoolConnection.prototype.onData = function(data){
185187
}
186188
break;
187189
case states.AWAITING:
188-
var trackResult = this._responseBufferTrack(Buffer.concat([this.buffer, data]), this.awaitingResponseLength);
190+
trackResult = this._responseBufferTrack(Buffer.concat([this.buffer, data]), this.awaitingResponseLength);
189191
if (trackResult.length == 2)
190192
{
191193
this.state = states.AWAITING;
@@ -257,13 +259,16 @@ TarantoolConnection.prototype._processResponse = function(buffer){
257259
{
258260
this.schemaId = obj[0][5];
259261
}
260-
for(var i = 0; i<this.commandsQueue.length; i++)
261-
if (this.commandsQueue[i][1] == reqId)
262-
{
263-
var task = this.commandsQueue[i];
264-
this.commandsQueue.splice(i, 1);
265-
break;
266-
}
262+
var task;
263+
for(var i = 0; i<this.commandsQueue.length; i++) {
264+
task = this.commandsQueue[i];
265+
if (task[1] == reqId)
266+
{
267+
this.commandsQueue.splice(i, 1);
268+
break;
269+
}
270+
}
271+
267272
var dfd = task[2];
268273
var success = obj[0][0] == 0 ? true : false;
269274
if (this.options.log)
@@ -577,8 +582,7 @@ function scramble(password, salt){
577582
var step1 = shatransform(password);
578583
var step2 = shatransform(step1);
579584
var step3 = shatransform(Buffer.concat([encSalt.slice(0, 20), step2]));
580-
var scramble = xor(step1, step3);
581-
return scramble;
585+
return xor(step1, step3);
582586
}
583587

584588
TarantoolConnection.prototype._header = function(command, reqId){

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
"description": "Tarantool driver for 1.6",
55
"main": "index.js",
66
"scripts": {
7-
"test": "./node_modules/mocha/bin/mocha -t 5000"
7+
"lint": "eslint ./lib ./test",
8+
"test": "mocha -t 5000"
89
},
910
"repository": {
1011
"type": "git",
@@ -30,6 +31,7 @@
3031
},
3132
"devDependencies": {
3233
"benchmark": "^2.1.0",
34+
"eslint": "^2.5.3",
3335
"mocha": "^2.2.4"
3436
}
3537
}

test/app.js

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
/**
22
* Created by klond on 05.04.15.
33
*/
4+
5+
/*eslint-env mocha */
6+
/* global Promise */
7+
48
var fs = require('fs');
59
var assert = require('assert');
610
var TarantoolConnection = require('../lib/connection');
@@ -18,27 +22,29 @@ describe('Tarantool Connection tests', function(){
1822
it('connect', function(done){
1923
conn.connect().then(function(){
2024
done();
21-
}, function(e){ throw 'not connected'; done();});
25+
}, function(e){ throw 'not connected'; });
2226
});
2327
it('auth', function(done){
2428
conn.connect().then(function(){
2529
return conn.auth('test', 'test');
26-
}, function(e){ throw 'not connected'; done();})
30+
}, function(e){ throw 'not connected'; })
2731
.then(function(){
2832
done();
29-
}, function(e){ throw 'not auth'; done();})
33+
}, function(e){ throw 'not auth'; });
3034
});
3135
});
3236
describe('requests', function(){
3337
var insertTuple = [50, 10, 'my key', 30];
38+
/*eslint-disable no-shadow */
3439
var conn;
40+
/*eslint-enable no-shadow */
3541
before(function(done){
3642
console.log('before call');
3743
try{
3844
conn = new TarantoolConnection({port: 33013});
3945
conn.connect().then(function(){
4046
return conn.auth('test', 'test');
41-
}, function(e){ throw 'not connected'; done();})
47+
}, function(e){ throw 'not connected';})
4248
.then(function(){
4349
return Promise.all([conn.delete(514, 0, [1]),conn.delete(514, 0, [2]),
4450
conn.delete(514, 0, [3]),conn.delete(514, 0, [4]),
@@ -118,7 +124,7 @@ describe('Tarantool Connection tests', function(){
118124
assert.equal(a.length, 1);
119125
assert.equal(a[0][3], insertTuple[3]+10);
120126
done();
121-
}).catch(function(e){ done(e) });
127+
}).catch(function(e){ done(e); });
122128
});
123129
it('a lot of insert', function(done){
124130
var promises = [];
@@ -145,35 +151,35 @@ describe('Tarantool Connection tests', function(){
145151
it('call print', function(done){
146152
conn.call('myprint', ['test'])
147153
.then(function(){
148-
done()
154+
done();
149155
})
150156
.catch(function(e){
151157
console.log(e);
152158
done(e);
153-
})
159+
});
154160
});
155161
it('call batch', function(done){
156162
conn.call('batch', [[1], [2], [3]])
157163
.then(function(){
158-
done()
164+
done();
159165
})
160166
.catch(function(e){
161167
console.log(e);
162168
done(e);
163-
})
169+
});
164170
});
165171
it('call get', function(done){
166172
conn.insert(514, [4])
167173
.then(function() {
168-
return conn.call('myget', 4)
174+
return conn.call('myget', 4);
169175
})
170176
.then(function(value){
171-
done()
177+
done();
172178
})
173179
.catch(function(e){
174180
console.log(e);
175181
done(e);
176-
})
182+
});
177183
});
178184
it('get metadata space by name', function(done){
179185
conn._getSpaceId('batched')
@@ -183,7 +189,7 @@ describe('Tarantool Connection tests', function(){
183189
})
184190
.catch(function(e){
185191
done(e);
186-
})
192+
});
187193
});
188194
it('get metadata index by name', function(done){
189195
conn._getIndexId(514, 'primary')
@@ -193,7 +199,7 @@ describe('Tarantool Connection tests', function(){
193199
})
194200
.catch(function(e){
195201
done(e);
196-
})
202+
});
197203
});
198204
it('insert with space name', function(done){
199205
conn.insert('test', [999, 999, 'fear'])
@@ -239,13 +245,15 @@ describe('Tarantool Connection tests', function(){
239245
});
240246
});
241247
describe('upsert', function(){
248+
/*eslint-disable no-shadow */
242249
var conn;
250+
/*eslint-enable no-shadow */
243251
before(function(done){
244252
try{
245253
conn = new TarantoolConnection({port: 33013});
246254
conn.connect().then(function(){
247255
return conn.auth('test', 'test');
248-
}, function(e){ throw 'not connected'; done();})
256+
}, function(e){ throw 'not connected'; })
249257
.then(function(){
250258
return Promise.all([
251259
conn.delete('upstest', 'primary', 1),
@@ -276,7 +284,7 @@ describe('Tarantool Connection tests', function(){
276284

277285
.catch(function(e){
278286
done(e);
279-
})
287+
});
280288
});
281289
it('update', function(done){
282290
conn.upsert('upstest', 2, [['+', 2, 2]], [2, 4, 3])
@@ -294,7 +302,7 @@ describe('Tarantool Connection tests', function(){
294302

295303
.catch(function(e){
296304
done(e);
297-
})
305+
});
298306
});
299307
});
300308
describe('connection test with custom msgpack implementation', function(){
@@ -317,15 +325,15 @@ describe('Tarantool Connection tests', function(){
317325
it('connect', function(done){
318326
customConn.connect().then(function(){
319327
done();
320-
}, function(e){ throw 'not connected'; done();});
328+
}, function(e){ throw 'not connected'; });
321329
});
322330
it('auth', function(done){
323331
customConn.connect().then(function(){
324332
return customConn.auth('test', 'test');
325-
}, function(e){ throw 'not connected'; done();})
333+
}, function(e){ throw 'not connected'; })
326334
.then(function(){
327335
done();
328-
}, function(e){ throw 'not auth'; done();})
336+
}, function(e){ throw 'not auth'; });
329337
});
330338
});
331339
});

0 commit comments

Comments
 (0)