Skip to content

Commit 906880e

Browse files
committed
lint: use standard style
1 parent a1b9330 commit 906880e

7 files changed

Lines changed: 98 additions & 82 deletions

File tree

.eslintignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
coverage
2+
node_modules

.eslintrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"extends": "standard"
3+
}

.travis.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,14 @@ cache:
1616
before_install:
1717
# Setup Node.js version-specific dependencies
1818
- "test $TRAVIS_NODE_VERSION != '0.8' || npm rm --save-dev istanbul"
19+
- "test $(echo $TRAVIS_NODE_VERSION | cut -d'.' -f1) -ge 4 || npm rm --save-dev eslint eslint-config-standard eslint-plugin-promise eslint-plugin-standard"
1920
# Update Node.js modules
2021
- "test ! -d node_modules || npm prune"
2122
- "test ! -d node_modules || npm rebuild"
2223
script:
2324
# Run test script, depending on istanbul install
2425
- "test ! -z $(npm -ps ls istanbul) || npm test"
2526
- "test -z $(npm -ps ls istanbul) || npm run-script test-travis"
27+
- "test -z $(npm -ps ls eslint ) || npm run-script lint"
2628
after_script:
2729
- "test -e ./coverage/lcov.info && npm install coveralls@2 && cat ./coverage/lcov.info | coveralls"

index.js

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@
55
* MIT Licensed
66
*/
77

8-
'use strict';
8+
'use strict'
99

1010
/**
1111
* Module dependencies.
1212
*/
1313

14-
var createError = require('http-errors');
15-
var ms = require('ms');
16-
var onFinished = require('on-finished');
17-
var onHeaders = require('on-headers');
14+
var createError = require('http-errors')
15+
var ms = require('ms')
16+
var onFinished = require('on-finished')
17+
var onHeaders = require('on-headers')
1818

1919
/**
2020
* Timeout:
@@ -27,48 +27,48 @@ var onHeaders = require('on-headers');
2727
* @api public
2828
*/
2929

30-
module.exports = function timeout(time, options) {
31-
var opts = options || {};
30+
module.exports = function timeout (time, options) {
31+
var opts = options || {}
3232

3333
var delay = typeof time === 'string'
3434
? ms(time)
35-
: Number(time || 5000);
35+
: Number(time || 5000)
3636

37-
var respond = opts.respond === undefined || opts.respond === true;
37+
var respond = opts.respond === undefined || opts.respond === true
3838

39-
return function(req, res, next) {
40-
var id = setTimeout(function(){
41-
req.timedout = true;
42-
req.emit('timeout', delay);
43-
}, delay);
39+
return function (req, res, next) {
40+
var id = setTimeout(function () {
41+
req.timedout = true
42+
req.emit('timeout', delay)
43+
}, delay)
4444

4545
if (respond) {
46-
req.on('timeout', onTimeout(delay, next));
46+
req.on('timeout', onTimeout(delay, next))
4747
}
4848

49-
req.clearTimeout = function(){
50-
clearTimeout(id);
51-
};
49+
req.clearTimeout = function () {
50+
clearTimeout(id)
51+
}
5252

53-
req.timedout = false;
53+
req.timedout = false
5454

5555
onFinished(res, function () {
56-
clearTimeout(id);
57-
});
56+
clearTimeout(id)
57+
})
5858

5959
onHeaders(res, function () {
60-
clearTimeout(id);
61-
});
60+
clearTimeout(id)
61+
})
6262

63-
next();
64-
};
65-
};
63+
next()
64+
}
65+
}
6666

67-
function onTimeout(delay, cb) {
68-
return function(){
67+
function onTimeout (delay, cb) {
68+
return function () {
6969
cb(createError(503, 'Response timeout', {
7070
code: 'ETIMEDOUT',
7171
timeout: delay
72-
}));
73-
};
72+
}))
73+
}
7474
}

package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@
1515
"on-headers": "~1.0.1"
1616
},
1717
"devDependencies": {
18+
"eslint": "3.10.2",
19+
"eslint-config-standard": "6.2.1",
20+
"eslint-plugin-promise": "3.4.0",
21+
"eslint-plugin-standard": "2.0.1",
1822
"istanbul": "0.4.5",
1923
"mocha": "2.5.3",
2024
"supertest": "1.1.0"
@@ -28,6 +32,7 @@
2832
"node": ">= 0.8"
2933
},
3034
"scripts": {
35+
"lint": "eslint .",
3136
"test": "mocha --reporter spec --bail --check-leaks test/",
3237
"test-cov": "istanbul cover node_modules/mocha/bin/_mocha -- --reporter dot --check-leaks test/",
3338
"test-travis": "istanbul cover node_modules/mocha/bin/_mocha --report lcovonly -- --reporter dot --check-leaks test/"

test/.eslintrc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"env": {
3+
"mocha": true
4+
}
5+
}

test/test.js

Lines changed: 51 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11

2-
var assert = require('assert');
3-
var http = require('http');
4-
var request = require('supertest');
5-
var timeout = require('..');
2+
var assert = require('assert')
3+
var http = require('http')
4+
var request = require('supertest')
5+
var timeout = require('..')
66

7-
describe('timeout()', function(){
7+
describe('timeout()', function () {
88
it('should have a default timeout', function (done) {
99
this.timeout(10000)
1010
var server = createServer()
@@ -27,9 +27,9 @@ describe('timeout()', function(){
2727
.expect(503, /45ms/, done)
2828
})
2929

30-
describe('when below the timeout', function(){
31-
it('should do nothing', function(done){
32-
var server = createServer(null, function(req, res){
30+
describe('when below the timeout', function () {
31+
it('should do nothing', function (done) {
32+
var server = createServer(null, function (req, res) {
3333
res.end('Hello')
3434
})
3535
request(server)
@@ -38,10 +38,10 @@ describe('timeout()', function(){
3838
})
3939
})
4040

41-
describe('when above the timeout', function(){
42-
describe('with no response made', function(){
43-
it('should respond with 503 Request timeout', function(done){
44-
var server = createServer(null, null, function(req, res){
41+
describe('when above the timeout', function () {
42+
describe('with no response made', function () {
43+
it('should respond with 503 Request timeout', function (done) {
44+
var server = createServer(null, null, function (req, res) {
4545
assert.ok(req.timedout)
4646
res.end('Hello')
4747
})
@@ -51,8 +51,8 @@ describe('timeout()', function(){
5151
.expect(503, done)
5252
})
5353

54-
it('should pass the error to next()', function(done){
55-
var server = createServer(null, null, function(req, res){
54+
it('should pass the error to next()', function (done) {
55+
var server = createServer(null, null, function (req, res) {
5656
assert.ok(req.timedout)
5757
res.end('Hello')
5858
})
@@ -63,11 +63,11 @@ describe('timeout()', function(){
6363
})
6464
})
6565

66-
describe('with a partial response', function(){
67-
it('should do nothing', function(done){
66+
describe('with a partial response', function () {
67+
it('should do nothing', function (done) {
6868
var server = createServer(null,
69-
function(req, res){ res.write('Hello') },
70-
function(req, res){
69+
function (req, res) { res.write('Hello') },
70+
function (req, res) {
7171
assert.ok(!req.timedout)
7272
res.end(' World')
7373
})
@@ -79,9 +79,9 @@ describe('timeout()', function(){
7979
})
8080
})
8181

82-
describe('options', function(){
83-
it('can disable auto response', function(done){
84-
var server = createServer({respond: false}, null, function(req, res){
82+
describe('options', function () {
83+
it('can disable auto response', function (done) {
84+
var server = createServer({respond: false}, null, function (req, res) {
8585
res.end('Timedout ' + req.timedout)
8686
})
8787

@@ -91,11 +91,11 @@ describe('timeout()', function(){
9191
})
9292
})
9393

94-
describe('req.clearTimeout()', function(){
95-
it('should revert this behavior', function(done){
94+
describe('req.clearTimeout()', function () {
95+
it('should revert this behavior', function (done) {
9696
var server = createServer(null,
97-
function(req, res){ req.clearTimeout() },
98-
function(req, res){
97+
function (req, res) { req.clearTimeout() },
98+
function (req, res) {
9999
assert.ok(!req.timedout)
100100
res.end('Hello')
101101
})
@@ -106,80 +106,79 @@ describe('timeout()', function(){
106106
})
107107
})
108108

109-
describe('destroy()', function(){
110-
it('req should clear timer', function(done){
109+
describe('destroy()', function () {
110+
it('req should clear timer', function (done) {
111111
var server = createServer(null,
112-
function(req, res){ req.destroy() },
113-
function(req, res){
112+
function (req, res) { req.destroy() },
113+
function (req, res) {
114114
assert.equal(error.code, 'ECONNRESET')
115115
assert.ok(!req.timedout)
116116
done()
117117
})
118-
var error;
118+
var error
119119

120120
request(server)
121121
.get('/')
122-
.end(function(err){
122+
.end(function (err) {
123123
error = err
124-
});
124+
})
125125
})
126126

127-
it('res should clear timer', function(done){
127+
it('res should clear timer', function (done) {
128128
var server = createServer(null,
129-
function(req, res){ res.destroy() },
130-
function(req, res){
129+
function (req, res) { res.destroy() },
130+
function (req, res) {
131131
assert.equal(error.code, 'ECONNRESET')
132132
assert.ok(!req.timedout)
133133
done()
134134
})
135-
var error;
135+
var error
136136

137137
request(server)
138138
.get('/')
139-
.end(function(err){
139+
.end(function (err) {
140140
error = err
141-
});
141+
})
142142
})
143143

144-
it('socket should clear timer', function(done){
144+
it('socket should clear timer', function (done) {
145145
var server = createServer(null,
146-
function(req, res){ req.socket.destroy() },
147-
function(req, res){
146+
function (req, res) { req.socket.destroy() },
147+
function (req, res) {
148148
assert.equal(error.code, 'ECONNRESET')
149149
assert.ok(!req.timedout)
150150
done()
151151
})
152-
var error;
152+
var error
153153

154154
request(server)
155155
.get('/')
156-
.end(function(err){
156+
.end(function (err) {
157157
error = err
158-
});
158+
})
159159
})
160160
})
161161

162-
describe('when request aborted', function(){
163-
it('should clear timeout', function(done){
162+
describe('when request aborted', function () {
163+
it('should clear timeout', function (done) {
164164
var aborted = false
165165
var server = createServer(null,
166-
function(req, res){
167-
req.on('aborted', function(){ aborted = true })
166+
function (req, res) {
167+
req.on('aborted', function () { aborted = true })
168168
test.abort()
169169
},
170-
function(req, res){
170+
function (req, res) {
171171
assert.ok(aborted)
172172
assert.ok(!req.timedout)
173173
done()
174174
})
175-
var error
176175
var test = request(server).post('/')
177176
test.write('0')
178177
})
179178
})
180179
})
181180

182-
function createServer(options, before, after) {
181+
function createServer (options, before, after) {
183182
var _ms = 100
184183

185184
if (typeof options !== 'object') {
@@ -202,7 +201,7 @@ function createServer(options, before, after) {
202201
}
203202

204203
if (after) {
205-
setTimeout(function(){
204+
setTimeout(function () {
206205
after(req, res)
207206
}, (_ms + 100))
208207
}

0 commit comments

Comments
 (0)