Skip to content

Commit 41a9611

Browse files
committed
Fixed linting
1 parent 6945537 commit 41a9611

2 files changed

Lines changed: 44 additions & 52 deletions

File tree

index.js

Lines changed: 31 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ var statuses = require('statuses')
3030
var Stream = require('stream')
3131
var util = require('util')
3232

33-
var dirname = path.dirname
33+
var dirname = path.dirname
3434
var relative = path.relative
3535
var url = require('url')
3636

@@ -82,10 +82,9 @@ module.exports.mime = mime
8282
var listenerCount = EventEmitter.listenerCount ||
8383
function (emitter, type) { return emitter.listeners(type).length }
8484

85-
86-
function responseStatus(res, code, msg) {
85+
function responseStatus (res, code, msg) {
8786
var errMsg = msg
88-
if(errMsg == null) {
87+
if (errMsg == null) {
8988
errMsg = statuses[code]
9089

9190
res.setHeader('Content-Type', 'text/plain; charset=UTF-8')
@@ -97,7 +96,7 @@ function responseStatus(res, code, msg) {
9796
res.end(errMsg)
9897
}
9998

100-
function redirect(res, loc) {
99+
function redirect (res, loc) {
101100
// redirect
102101
res.setHeader('Content-Type', 'text/html; charset=UTF-8')
103102
res.setHeader('Location', loc)
@@ -108,7 +107,6 @@ function redirect(res, loc) {
108107
responseStatus(res, 301, msg)
109108
}
110109

111-
112110
/**
113111
* Return a `SendStream` for `req` and `path`.
114112
*
@@ -461,7 +459,7 @@ SendStream.prototype.isRangeFresh = function isRangeFresh () {
461459
* @private
462460
*/
463461

464-
SendStream.prototype.redirect = function redirectDirectory(path) {
462+
SendStream.prototype.redirect = function redirectDirectory (path) {
465463
if (listenerCount(this, 'directory') !== 0) {
466464
this.emit('directory')
467465
return
@@ -482,19 +480,18 @@ SendStream.prototype.redirect = function redirectDirectory(path) {
482480
* @private
483481
*/
484482

485-
SendStream.prototype.redirectSymbolicLink = function redirectSymbolicLink(path) {
483+
SendStream.prototype.redirectSymbolicLink = function redirectSymbolicLink (path) {
486484
var self = this
487485

488-
fs.readlink(path, function(err, linkString)
489-
{
486+
fs.readlink(path, function (err, linkString) {
490487
if (err) return self.onStatError(err)
491488

492489
// Get absolute path on the real filesystem of the destination
493490
path = dirname(path)
494491
var to = resolve(path, linkString)
495492

496493
// Check destination is not out of files root
497-
if(to.indexOf(self._root) !== 0) return this.error(403)
494+
if (to.indexOf(self._root) !== 0) return this.error(403)
498495

499496
// Get relative paths for all symlinks, also for absolute ones
500497
linkString = relative(path, to)
@@ -714,11 +711,11 @@ SendStream.prototype.sendFile = function sendFile (path) {
714711
var i = 0
715712
var self = this
716713

717-
debug('stat "%s"', path);
718-
fs.lstat(path, function onstat(err, stat) {
719-
if (err && err.code === 'ENOENT'
720-
&& !extname(path)
721-
&& path[path.length - 1] !== sep) {
714+
debug('stat "%s"', path)
715+
fs.lstat(path, function onstat (err, stat) {
716+
if (err && err.code === 'ENOENT' &&
717+
!extname(path) &&
718+
path[path.length - 1] !== sep) {
722719
// not found, check extensions
723720
return next(err)
724721
}
@@ -727,17 +724,18 @@ SendStream.prototype.sendFile = function sendFile (path) {
727724

728725
if (stat.isDirectory()) return self.redirect(self.path)
729726

730-
if (stat.isSymbolicLink() && self._redirectSymlinks)
727+
if (stat.isSymbolicLink() && self._redirectSymlinks) {
731728
return self.redirectSymbolicLink(path)
729+
}
732730

733731
self.emit('file', path, stat)
734732
self.send(path, stat)
735733
})
736734

737735
function next (err) {
738736
if (self._extensions.length <= i) {
739-
if (err) return self.onStatError(err);
740-
return self.error(404);
737+
if (err) return self.onStatError(err)
738+
return self.error(404)
741739
}
742740

743741
var p = path + '.' + self._extensions[i++]
@@ -760,27 +758,27 @@ SendStream.prototype.sendFile = function sendFile (path) {
760758
* @param {String} path
761759
* @api private
762760
*/
763-
SendStream.prototype.sendIndex = function sendIndex(path){
764-
var i = 0;
765-
var self = this;
761+
SendStream.prototype.sendIndex = function sendIndex (path) {
762+
var i = 0
763+
var self = this
766764

767-
function next(err){
765+
function next (err) {
768766
if (self._index.length <= i) {
769-
if (err) return self.onStatError(err);
770-
return self.error(404);
767+
if (err) return self.onStatError(err)
768+
return self.error(404)
771769
}
772770

773-
var p = join(path, self._index[i++]);
771+
var p = join(path, self._index[i++])
774772

775-
debug('stat "%s"', p);
776-
fs.stat(p, function(err, stat){
777-
if (err) return next(err);
773+
debug('stat "%s"', p)
774+
fs.stat(p, function (err, stat) {
775+
if (err) return next(err)
778776

779-
if (stat.isDirectory()) return next();
777+
if (stat.isDirectory()) return next()
780778

781-
self.emit('file', p, stat);
782-
self.send(p, stat);
783-
});
779+
self.emit('file', p, stat)
780+
self.send(p, stat)
781+
})
784782
}
785783

786784
next()

test/send.js

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -132,34 +132,31 @@ describe('send(file).pipe(res)', function () {
132132
.expect(200, '404 ENOENT', done)
133133
})
134134

135-
it('should 301 if the directory exists', function(done){
135+
it('should 301 if the directory exists', function (done) {
136136
request(app)
137137
.get('/pets')
138138
.expect('Location', '/pets/')
139139
.expect(301, 'Redirecting to <a href="/pets/">/pets/</a>\n', done)
140140
})
141141

142-
it("should not redirect on symbolic links", function(done){
142+
it('should not redirect on symbolic links', function (done) {
143143
var destination = 'name.txt'
144144
var path2 = path.join(fixtures, 'symlink')
145145

146-
fs.symlink(destination, path2, function(error)
147-
{
148-
if(error && error.code !== 'EEXIST') return done(error)
146+
fs.symlink(destination, path2, function (error) {
147+
if (error && error.code !== 'EEXIST') return done(error)
149148

150149
request(app)
151150
.get('/symlink')
152-
.expect(200, 'tobi', function(error)
153-
{
154-
fs.unlink(path2, function(error2)
155-
{
151+
.expect(200, 'tobi', function (error) {
152+
fs.unlink(path2, function (error2) {
156153
done(error || error2)
157154
})
158155
})
159156
})
160157
})
161158

162-
it("should 301 if it's a symbolic link and we want to redirect", function(done){
159+
it("should 301 if it's a symbolic link and we want to redirect", function (done) {
163160
var app = http.createServer(function (req, res) {
164161
send(req, req.url, {root: fixtures, redirectSymlinks: true})
165162
.on('error', function (err) { res.end(err.statusCode + ' ' + err.code) })
@@ -169,25 +166,22 @@ describe('send(file).pipe(res)', function () {
169166
var destination = 'name.txt'
170167
var path2 = path.join(fixtures, 'symlink')
171168

172-
fs.symlink(destination, path2, function(error)
173-
{
174-
if(error && error.code !== 'EEXIST') return done(error)
169+
fs.symlink(destination, path2, function (error) {
170+
if (error && error.code !== 'EEXIST') return done(error)
175171

176172
request(app)
177173
.get('/symlink')
178174
.expect('Location', destination)
179-
.expect(301, 'Redirecting to <a href="'+destination+'">'+destination+'</a>\n', function(error)
180-
{
181-
fs.unlink(path2, function(error2)
182-
{
175+
.expect(301, 'Redirecting to <a href="' + destination + '">' + destination + '</a>\n', function (error) {
176+
fs.unlink(path2, function (error2) {
183177
done(error || error2)
184178
})
185179
})
186180
})
187181
})
188182

189-
it('should not override content-type', function(done){
190-
var app = http.createServer(function(req, res){
183+
it('should not override content-type', function (done) {
184+
var app = http.createServer(function (req, res) {
191185
res.setHeader('Content-Type', 'application/x-custom')
192186
send(req, req.url, {root: fixtures}).pipe(res)
193187
})

0 commit comments

Comments
 (0)