Skip to content

Commit 52ff252

Browse files
committed
lint: use standard style
1 parent e75248c commit 52ff252

File tree

7 files changed

+110
-91
lines changed

7 files changed

+110
-91
lines changed

.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 & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ cache:
1414
- node_modules
1515
before_install:
1616
# Setup Node.js version-specific dependencies
17-
- "test $TRAVIS_NODE_VERSION != '0.8' || npm rm --save-dev istanbul"
17+
- "test $TRAVIS_NODE_VERSION != '0.8' || npm rm --save-dev eslint eslint-config-standard eslint-plugin-promise eslint-plugin-standard istanbul"
1818

1919
# Update Node.js modules
2020
- "test ! -d node_modules || npm prune"
@@ -23,5 +23,6 @@ script:
2323
# Run test script, depending on istanbul install
2424
- "test ! -z $(npm -ps ls istanbul) || npm test"
2525
- "test -z $(npm -ps ls istanbul) || npm run-script test-travis"
26+
- "test -z $(npm -ps ls eslint ) || npm run-script lint"
2627
after_script:
2728
- "test -e ./coverage/lcov.info && npm install coveralls@2 && cat ./coverage/lcov.info | coveralls"

index.js

Lines changed: 40 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ var cacheControlNoTransformRegExp = /(?:^|,)\s*?no-transform\s*?(?:,|$)/
4444
* @public
4545
*/
4646

47-
function compression(options) {
47+
function compression (options) {
4848
var opts = options || {}
4949

5050
// options
@@ -55,25 +55,26 @@ function compression(options) {
5555
threshold = 1024
5656
}
5757

58-
return function compression(req, res, next){
58+
return function compression (req, res, next) {
5959
var ended = false
6060
var length
6161
var listeners = []
62-
var write = res.write
63-
var on = res.on
64-
var end = res.end
6562
var stream
6663

64+
var _end = res.end
65+
var _on = res.on
66+
var _write = res.write
67+
6768
// flush
68-
res.flush = function flush() {
69+
res.flush = function flush () {
6970
if (stream) {
7071
stream.flush()
7172
}
7273
}
7374

7475
// proxy
7576

76-
res.write = function(chunk, encoding){
77+
res.write = function write (chunk, encoding) {
7778
if (ended) {
7879
return false
7980
}
@@ -84,10 +85,10 @@ function compression(options) {
8485

8586
return stream
8687
? stream.write(new Buffer(chunk, encoding))
87-
: write.call(this, chunk, encoding)
88-
};
88+
: _write.call(this, chunk, encoding)
89+
}
8990

90-
res.end = function(chunk, encoding){
91+
res.end = function end (chunk, encoding) {
9192
if (ended) {
9293
return false
9394
}
@@ -102,7 +103,7 @@ function compression(options) {
102103
}
103104

104105
if (!stream) {
105-
return end.call(this, chunk, encoding)
106+
return _end.call(this, chunk, encoding)
106107
}
107108

108109
// mark ended
@@ -112,11 +113,11 @@ function compression(options) {
112113
return chunk
113114
? stream.end(new Buffer(chunk, encoding))
114115
: stream.end()
115-
};
116+
}
116117

117-
res.on = function(type, listener){
118+
res.on = function on (type, listener) {
118119
if (!listeners || type !== 'drain') {
119-
return on.call(this, type, listener)
120+
return _on.call(this, type, listener)
120121
}
121122

122123
if (stream) {
@@ -129,13 +130,13 @@ function compression(options) {
129130
return this
130131
}
131132

132-
function nocompress(msg) {
133+
function nocompress (msg) {
133134
debug('no compression: %s', msg)
134-
addListeners(res, on, listeners)
135+
addListeners(res, _on, listeners)
135136
listeners = null
136137
}
137138

138-
onHeaders(res, function(){
139+
onHeaders(res, function onResponseHeaders () {
139140
// determine if request is filtered
140141
if (!filter(req, res)) {
141142
nocompress('filtered')
@@ -157,16 +158,16 @@ function compression(options) {
157158
return
158159
}
159160

160-
var encoding = res.getHeader('Content-Encoding') || 'identity';
161+
var encoding = res.getHeader('Content-Encoding') || 'identity'
161162

162163
// already encoded
163-
if ('identity' !== encoding) {
164+
if (encoding !== 'identity') {
164165
nocompress('already encoded')
165166
return
166167
}
167168

168169
// head
169-
if ('HEAD' === req.method) {
170+
if (req.method === 'HEAD') {
170171
nocompress('HEAD request')
171172
return
172173
}
@@ -196,35 +197,35 @@ function compression(options) {
196197
addListeners(stream, stream.on, listeners)
197198

198199
// header fields
199-
res.setHeader('Content-Encoding', method);
200-
res.removeHeader('Content-Length');
200+
res.setHeader('Content-Encoding', method)
201+
res.removeHeader('Content-Length')
201202

202203
// compression
203-
stream.on('data', function(chunk){
204-
if (write.call(res, chunk) === false) {
204+
stream.on('data', function onStreamData (chunk) {
205+
if (_write.call(res, chunk) === false) {
205206
stream.pause()
206207
}
207-
});
208+
})
208209

209-
stream.on('end', function(){
210-
end.call(res);
211-
});
210+
stream.on('end', function onStreamEnd () {
211+
_end.call(res)
212+
})
212213

213-
on.call(res, 'drain', function() {
214+
_on.call(res, 'drain', function onResponseDrain () {
214215
stream.resume()
215-
});
216-
});
216+
})
217+
})
217218

218-
next();
219-
};
219+
next()
220+
}
220221
}
221222

222223
/**
223224
* Add bufferred listeners to stream
224225
* @private
225226
*/
226227

227-
function addListeners(stream, on, listeners) {
228+
function addListeners (stream, on, listeners) {
228229
for (var i = 0; i < listeners.length; i++) {
229230
on.apply(stream, listeners[i])
230231
}
@@ -234,7 +235,7 @@ function addListeners(stream, on, listeners) {
234235
* Get the length of a given chunk
235236
*/
236237

237-
function chunkLength(chunk, encoding) {
238+
function chunkLength (chunk, encoding) {
238239
if (!chunk) {
239240
return 0
240241
}
@@ -249,7 +250,7 @@ function chunkLength(chunk, encoding) {
249250
* @private
250251
*/
251252

252-
function shouldCompress(req, res) {
253+
function shouldCompress (req, res) {
253254
var type = res.getHeader('Content-Type')
254255

255256
if (type === undefined || !compressible(type)) {
@@ -265,11 +266,11 @@ function shouldCompress(req, res) {
265266
* @private
266267
*/
267268

268-
function shouldTransform(req, res) {
269+
function shouldTransform (req, res) {
269270
var cacheControl = res.getHeader('Cache-Control')
270271

271272
// Don't compress for Cache-Control: no-transform
272273
// https://tools.ietf.org/html/rfc7234#section-5.2.2.4
273-
return !cacheControl
274-
|| !cacheControlNoTransformRegExp.test(cacheControl)
274+
return !cacheControl ||
275+
!cacheControlNoTransformRegExp.test(cacheControl)
275276
}

package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717
"vary": "~1.1.0"
1818
},
1919
"devDependencies": {
20+
"eslint": "2.9.0",
21+
"eslint-config-standard": "5.3.1",
22+
"eslint-plugin-promise": "1.1.0",
23+
"eslint-plugin-standard": "1.3.2",
2024
"istanbul": "0.4.3",
2125
"mocha": "2.4.5",
2226
"supertest": "1.1.0"
@@ -30,6 +34,7 @@
3034
"node": ">= 0.8.0"
3135
},
3236
"scripts": {
37+
"lint": "eslint **/*.js",
3338
"test": "mocha --check-leaks --reporter spec --bail",
3439
"test-cov": "istanbul cover node_modules/mocha/bin/_mocha -- --check-leaks --reporter dot",
3540
"test-travis": "istanbul cover node_modules/mocha/bin/_mocha --report lcovonly -- --check-leaks --reporter spec"

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+
}

0 commit comments

Comments
 (0)