Skip to content

Commit 0933c98

Browse files
committed
lint: use standard style
1 parent 58b0e7b commit 0933c98

File tree

7 files changed

+47
-30
lines changed

7 files changed

+47
-30
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 & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,14 @@ cache:
1717
before_install:
1818
# Setup Node.js version-specific dependencies
1919
- "test $TRAVIS_NODE_VERSION != '0.8' || npm rm --save-dev istanbul"
20+
- "test $(echo $TRAVIS_NODE_VERSION | cut -d. -f1) -ge 4 || npm rm --save-dev eslint eslint-config-standard eslint-plugin-promise eslint-plugin-standard"
2021
# Update Node.js modules
2122
- "test ! -d node_modules || npm prune"
2223
- "test ! -d node_modules || npm rebuild"
2324
script:
2425
# Run test script, depending on istanbul install
2526
- "test ! -z $(npm -ps ls istanbul) || npm test"
2627
- "test -z $(npm -ps ls istanbul) || npm run-script test-travis"
28+
- "test -z $(npm -ps ls eslint ) || npm run-script lint"
2729
after_script:
2830
- "test -e ./coverage/lcov.info && npm install coveralls@2 && cat ./coverage/lcov.info | coveralls"

index.js

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
*/
1616

1717
var accepts = require('accepts')
18-
var escapeHtml = require('escape-html');
19-
var fs = require('fs');
18+
var escapeHtml = require('escape-html')
19+
var fs = require('fs')
2020
var path = require('path')
2121
var util = require('util')
2222

@@ -25,17 +25,17 @@ var util = require('util')
2525
* @private
2626
*/
2727

28-
var TEMPLATE = fs.readFileSync(path.join(__dirname, '/public/error.html'), 'utf8')
28+
var DOUBLE_SPACE_REGEXP = /\x20{2}/g
29+
var NEW_LINE_REGEXP = /\n/g
2930
var STYLESHEET = fs.readFileSync(path.join(__dirname, '/public/style.css'), 'utf8')
30-
var doubleSpaceGlobalRegExp = / /g
31+
var TEMPLATE = fs.readFileSync(path.join(__dirname, '/public/error.html'), 'utf8')
3132
var inspect = util.inspect
32-
var newLineGlobalRegExp = /\n/g
3333
var toString = Object.prototype.toString
3434

3535
/* istanbul ignore next */
3636
var defer = typeof setImmediate === 'function'
3737
? setImmediate
38-
: function(fn){ process.nextTick(fn.bind.apply(fn, arguments)) }
38+
: function (fn) { process.nextTick(fn.bind.apply(fn, arguments)) }
3939

4040
/**
4141
* Error handler:
@@ -62,7 +62,7 @@ var defer = typeof setImmediate === 'function'
6262
* @api public
6363
*/
6464

65-
exports = module.exports = function errorHandler(options) {
65+
exports = module.exports = function errorHandler (options) {
6666
// get environment
6767
var env = process.env.NODE_ENV || 'development'
6868

@@ -83,7 +83,7 @@ exports = module.exports = function errorHandler(options) {
8383
log = logerror
8484
}
8585

86-
return function errorHandler(err, req, res, next){
86+
return function errorHandler (err, req, res, next) {
8787
// respect err.statusCode
8888
if (err.statusCode) {
8989
res.statusCode = err.statusCode
@@ -139,42 +139,42 @@ exports = module.exports = function errorHandler(options) {
139139
res.end(body)
140140
// json
141141
} else if (type === 'json') {
142-
var error = { message: err.message, stack: err.stack };
143-
for (var prop in err) error[prop] = err[prop];
142+
var error = { message: err.message, stack: err.stack }
143+
for (var prop in err) error[prop] = err[prop]
144144
var json = JSON.stringify({ error: error }, null, 2)
145145
res.setHeader('Content-Type', 'application/json; charset=utf-8')
146-
res.end(json);
146+
res.end(json)
147147
// plain text
148148
} else {
149149
res.setHeader('Content-Type', 'text/plain; charset=utf-8')
150150
res.end(str)
151151
}
152-
};
153-
};
152+
}
153+
}
154154

155155
/**
156156
* Template title, framework authors may override this value.
157157
*/
158158

159-
exports.title = 'Connect';
159+
exports.title = 'Connect'
160160

161161
/**
162162
* Escape a block of HTML, preserving whitespace.
163163
* @api private
164164
*/
165165

166-
function escapeHtmlBlock(str) {
166+
function escapeHtmlBlock (str) {
167167
return escapeHtml(str)
168-
.replace(doubleSpaceGlobalRegExp, '  ')
169-
.replace(newLineGlobalRegExp, '<br>')
168+
.replace(DOUBLE_SPACE_REGEXP, ' &nbsp;')
169+
.replace(NEW_LINE_REGEXP, '<br>')
170170
}
171171

172172
/**
173173
* Stringify a value.
174174
* @api private
175175
*/
176176

177-
function stringify(val) {
177+
function stringify (val) {
178178
var stack = val.stack
179179

180180
if (stack) {
@@ -193,6 +193,6 @@ function stringify(val) {
193193
* @api private
194194
*/
195195

196-
function logerror(err, str) {
197-
console.error(str)
196+
function logerror (err, str) {
197+
console.error(str || err.stack)
198198
}

package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414
},
1515
"devDependencies": {
1616
"after": "0.8.2",
17+
"eslint": "3.10.2",
18+
"eslint-config-standard": "6.2.1",
19+
"eslint-plugin-promise": "3.3.2",
20+
"eslint-plugin-standard": "2.0.1",
1721
"istanbul": "0.4.5",
1822
"mocha": "2.5.3",
1923
"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 spec --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: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,10 @@ describe('errorHandler()', function () {
113113
var server
114114

115115
before(function () {
116-
error = new Error('boom!')
117-
error.description = 'it went this way'
118-
server = createServer(error)
119-
});
116+
error = new Error('boom!')
117+
error.description = 'it went this way'
118+
server = createServer(error)
119+
})
120120

121121
describe('when "Accept: text/html"', function () {
122122
it('should return a html response', function (done) {
@@ -201,9 +201,9 @@ describe('errorHandler()', function () {
201201
it('should not die', function (done) {
202202
request(server)
203203
.get('/')
204-
.expect(200, done);
205-
});
206-
});
204+
.expect(200, done)
205+
})
206+
})
207207

208208
describe('console', function () {
209209
var _consoleerror
@@ -376,7 +376,7 @@ describe('errorHandler(options)', function () {
376376
var error = new Error('boom!')
377377
var server = createServer(error, {log: log})
378378

379-
function log(err, str, req, res) {
379+
function log (err, str, req, res) {
380380
assert.equal(err, error)
381381
assert.equal(str, error.stack.toString())
382382
assert.equal(req.url, '/')
@@ -393,7 +393,7 @@ describe('errorHandler(options)', function () {
393393
})
394394
})
395395

396-
function createServer(error, options) {
396+
function createServer (error, options) {
397397
var _errorHandler = errorHandler(options)
398398

399399
return http.createServer(function (req, res) {
@@ -404,7 +404,7 @@ function createServer(error, options) {
404404
})
405405
}
406406

407-
function alterEnvironment(key, value) {
407+
function alterEnvironment (key, value) {
408408
var prev
409409

410410
before(function () {

0 commit comments

Comments
 (0)