Skip to content

Commit bd386d3

Browse files
committed
lint: use standard style
1 parent b4dc075 commit bd386d3

16 files changed

+377
-358
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
@@ -15,7 +15,7 @@ cache:
1515
- node_modules
1616
before_install:
1717
# Setup Node.js version-specific dependencies
18-
- "test $TRAVIS_NODE_VERSION != '0.8' || npm rm --save-dev istanbul"
18+
- "test $TRAVIS_NODE_VERSION != '0.8' || npm rm --save-dev eslint eslint-config-standard eslint-plugin-promise eslint-plugin-standard istanbul"
1919

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

index.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -90,13 +90,13 @@ Object.defineProperty(exports, 'urlencoded', {
9090
* @public
9191
*/
9292

93-
function bodyParser(options){
93+
function bodyParser (options) {
9494
var opts = {}
9595

9696
// exclude type option
9797
if (options) {
9898
for (var prop in options) {
99-
if ('type' !== prop) {
99+
if (prop !== 'type') {
100100
opts[prop] = options[prop]
101101
}
102102
}
@@ -105,11 +105,11 @@ function bodyParser(options){
105105
var _urlencoded = exports.urlencoded(opts)
106106
var _json = exports.json(opts)
107107

108-
return function bodyParser(req, res, next) {
109-
_json(req, res, function(err){
110-
if (err) return next(err);
111-
_urlencoded(req, res, next);
112-
});
108+
return function bodyParser (req, res, next) {
109+
_json(req, res, function (err) {
110+
if (err) return next(err)
111+
_urlencoded(req, res, next)
112+
})
113113
}
114114
}
115115

@@ -118,8 +118,8 @@ function bodyParser(options){
118118
* @private
119119
*/
120120

121-
function createParserGetter(name) {
122-
return function get() {
121+
function createParserGetter (name) {
122+
return function get () {
123123
return loadParser(name)
124124
}
125125
}
@@ -129,7 +129,7 @@ function createParserGetter(name) {
129129
* @private
130130
*/
131131

132-
function loadParser(parserName) {
132+
function loadParser (parserName) {
133133
var parser = parsers[parserName]
134134

135135
if (parser !== undefined) {
@@ -153,5 +153,5 @@ function loadParser(parserName) {
153153
}
154154

155155
// store to prevent invoking require()
156-
return parsers[parserName] = parser
156+
return (parsers[parserName] = parser)
157157
}

lib/read.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ module.exports = read
3535
* @api private
3636
*/
3737

38-
function read(req, res, next, parse, debug, options) {
38+
function read (req, res, next, parse, debug, options) {
3939
var length
4040
var opts = options || {}
4141
var stream
@@ -87,7 +87,7 @@ function read(req, res, next, parse, debug, options) {
8787

8888
// read off entire request
8989
stream.resume()
90-
onFinished(req, function onfinished() {
90+
onFinished(req, function onfinished () {
9191
next(err)
9292
})
9393
return
@@ -140,7 +140,7 @@ function read(req, res, next, parse, debug, options) {
140140
* @api private
141141
*/
142142

143-
function contentstream(req, debug, inflate) {
143+
function contentstream (req, debug, inflate) {
144144
var encoding = (req.headers['content-encoding'] || 'identity').toLowerCase()
145145
var length = req.headers['content-length']
146146
var stream
@@ -180,7 +180,7 @@ function contentstream(req, debug, inflate) {
180180
* @private
181181
*/
182182

183-
function setErrorStatus(error, status) {
183+
function setErrorStatus (error, status) {
184184
if (!error.status && !error.statusCode) {
185185
error.status = status
186186
error.statusCode = status

lib/types/json.js

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ module.exports = json
3737
* %x0D ) ; Carriage return
3838
*/
3939

40-
var firstcharRegExp = /^[\x20\x09\x0a\x0d]*(.)/
40+
var FIRST_CHAR_REGEXP = /^[\x20\x09\x0a\x0d]*(.)/ // eslint-disable-line no-control-regex
4141

4242
/**
4343
* Create a middleware to parse JSON bodies.
@@ -47,7 +47,7 @@ var firstcharRegExp = /^[\x20\x09\x0a\x0d]*(.)/
4747
* @public
4848
*/
4949

50-
function json(options) {
50+
function json (options) {
5151
var opts = options || {}
5252

5353
var limit = typeof opts.limit !== 'number'
@@ -68,7 +68,7 @@ function json(options) {
6868
? typeChecker(type)
6969
: type
7070

71-
function parse(body) {
71+
function parse (body) {
7272
if (body.length === 0) {
7373
// special-case empty json body, as it's a common client-side mistake
7474
// TODO: maybe make this configurable or part of "strict" option
@@ -88,23 +88,29 @@ function json(options) {
8888
return JSON.parse(body, reviver)
8989
}
9090

91-
return function jsonParser(req, res, next) {
91+
return function jsonParser (req, res, next) {
9292
if (req._body) {
93-
return debug('body already parsed'), next()
93+
debug('body already parsed')
94+
next()
95+
return
9496
}
9597

9698
req.body = req.body || {}
9799

98100
// skip requests without bodies
99101
if (!typeis.hasBody(req)) {
100-
return debug('skip empty body'), next()
102+
debug('skip empty body')
103+
next()
104+
return
101105
}
102106

103107
debug('content-type %j', req.headers['content-type'])
104108

105109
// determine if request should be parsed
106110
if (!shouldParse(req)) {
107-
return debug('skip parsing'), next()
111+
debug('skip parsing')
112+
next()
113+
return
108114
}
109115

110116
// assert charset per RFC 7159 sec 8.1
@@ -135,9 +141,8 @@ function json(options) {
135141
* @api public
136142
*/
137143

138-
139-
function firstchar(str) {
140-
var match = firstcharRegExp.exec(str)
144+
function firstchar (str) {
145+
var match = FIRST_CHAR_REGEXP.exec(str)
141146
return match ? match[1] : ''
142147
}
143148

@@ -148,7 +153,7 @@ function firstchar(str) {
148153
* @api private
149154
*/
150155

151-
function getCharset(req) {
156+
function getCharset (req) {
152157
try {
153158
return contentType.parse(req).parameters.charset.toLowerCase()
154159
} catch (e) {
@@ -163,8 +168,8 @@ function getCharset(req) {
163168
* @return {function}
164169
*/
165170

166-
function typeChecker(type) {
167-
return function checkType(req) {
171+
function typeChecker (type) {
172+
return function checkType (req) {
168173
return Boolean(typeis(req, type))
169174
}
170175
}

lib/types/raw.js

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ module.exports = raw
2929
* @api public
3030
*/
3131

32-
function raw(options) {
33-
var opts = options || {};
32+
function raw (options) {
33+
var opts = options || {}
3434

3535
var inflate = opts.inflate !== false
3636
var limit = typeof opts.limit !== 'number'
@@ -48,27 +48,33 @@ function raw(options) {
4848
? typeChecker(type)
4949
: type
5050

51-
function parse(buf) {
51+
function parse (buf) {
5252
return buf
5353
}
5454

55-
return function rawParser(req, res, next) {
55+
return function rawParser (req, res, next) {
5656
if (req._body) {
57-
return debug('body already parsed'), next()
57+
debug('body already parsed')
58+
next()
59+
return
5860
}
5961

6062
req.body = req.body || {}
6163

6264
// skip requests without bodies
6365
if (!typeis.hasBody(req)) {
64-
return debug('skip empty body'), next()
66+
debug('skip empty body')
67+
next()
68+
return
6569
}
6670

6771
debug('content-type %j', req.headers['content-type'])
6872

6973
// determine if request should be parsed
7074
if (!shouldParse(req)) {
71-
return debug('skip parsing'), next()
75+
debug('skip parsing')
76+
next()
77+
return
7278
}
7379

7480
// read
@@ -88,8 +94,8 @@ function raw(options) {
8894
* @return {function}
8995
*/
9096

91-
function typeChecker(type) {
92-
return function checkType(req) {
97+
function typeChecker (type) {
98+
return function checkType (req) {
9399
return Boolean(typeis(req, type))
94100
}
95101
}

lib/types/text.js

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ module.exports = text
3030
* @api public
3131
*/
3232

33-
function text(options) {
33+
function text (options) {
3434
var opts = options || {}
3535

3636
var defaultCharset = opts.defaultCharset || 'utf-8'
@@ -50,27 +50,33 @@ function text(options) {
5050
? typeChecker(type)
5151
: type
5252

53-
function parse(buf) {
53+
function parse (buf) {
5454
return buf
5555
}
5656

57-
return function textParser(req, res, next) {
57+
return function textParser (req, res, next) {
5858
if (req._body) {
59-
return debug('body already parsed'), next()
59+
debug('body already parsed')
60+
next()
61+
return
6062
}
6163

6264
req.body = req.body || {}
6365

6466
// skip requests without bodies
6567
if (!typeis.hasBody(req)) {
66-
return debug('skip empty body'), next()
68+
debug('skip empty body')
69+
next()
70+
return
6771
}
6872

6973
debug('content-type %j', req.headers['content-type'])
7074

7175
// determine if request should be parsed
7276
if (!shouldParse(req)) {
73-
return debug('skip parsing'), next()
77+
debug('skip parsing')
78+
next()
79+
return
7480
}
7581

7682
// get charset
@@ -93,7 +99,7 @@ function text(options) {
9399
* @api private
94100
*/
95101

96-
function getCharset(req) {
102+
function getCharset (req) {
97103
try {
98104
return contentType.parse(req).parameters.charset.toLowerCase()
99105
} catch (e) {
@@ -108,8 +114,8 @@ function getCharset(req) {
108114
* @return {function}
109115
*/
110116

111-
function typeChecker(type) {
112-
return function checkType(req) {
117+
function typeChecker (type) {
118+
return function checkType (req) {
113119
return Boolean(typeis(req, type))
114120
}
115121
}

0 commit comments

Comments
 (0)