Skip to content

Commit

Permalink
lint: apply standard 13 style
Browse files Browse the repository at this point in the history
  • Loading branch information
dougwilson committed Oct 14, 2021
1 parent 5a6cd9f commit b12d519
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 42 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ jobs:
shell: bash
run: |
# eslint for linting
# - remove on Node.js < 6
if [[ "$(cut -d. -f1 <<< "${{ matrix.node-version }}")" -lt 6 ]]; then
# - remove on Node.js < 8
if [[ "$(cut -d. -f1 <<< "${{ matrix.node-version }}")" -lt 8 ]]; then
node -pe 'Object.keys(require("./package").devDependencies).join("\n")' | \
grep -E '^eslint(-|$)' | \
sort -r | \
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ var http = require('http')
var serveStatic = require('serve-static')

// Serve up public/ftp folder
var serve = serveStatic('public/ftp', { 'index': ['index.html', 'index.htm'] })
var serve = serveStatic('public/ftp', { index: ['index.html', 'index.htm'] })

// Create server
var server = http.createServer(function onRequest (req, res) {
Expand All @@ -162,8 +162,8 @@ var serveStatic = require('serve-static')

// Serve up public/ftp folder
var serve = serveStatic('public/ftp', {
'index': false,
'setHeaders': setHeaders
index: false,
setHeaders: setHeaders
})

// Set header to force download
Expand Down Expand Up @@ -192,7 +192,7 @@ var serveStatic = require('serve-static')

var app = express()

app.use(serveStatic('public/ftp', { 'index': ['default.html', 'default.htm'] }))
app.use(serveStatic('public/ftp', { index: ['default.html', 'default.htm'] }))
app.listen(3000)
```

Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
"send": "0.17.1"
},
"devDependencies": {
"eslint": "5.16.0",
"eslint-config-standard": "12.0.0",
"eslint": "6.8.0",
"eslint-config-standard": "13.0.1",
"eslint-plugin-import": "2.25.2",
"eslint-plugin-markdown": "1.0.0",
"eslint-plugin-node": "8.0.1",
"eslint-plugin-promise": "4.1.1",
"eslint-plugin-node": "9.2.0",
"eslint-plugin-promise": "4.3.1",
"eslint-plugin-standard": "4.0.0",
"istanbul": "0.4.5",
"mocha": "6.1.4",
Expand Down
64 changes: 32 additions & 32 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,14 +150,14 @@ describe('serveStatic()', function () {
describe('acceptRanges', function () {
describe('when false', function () {
it('should not include Accept-Ranges', function (done) {
request(createServer(fixtures, { 'acceptRanges': false }))
request(createServer(fixtures, { acceptRanges: false }))
.get('/nums.txt')
.expect(shouldNotHaveHeader('Accept-Ranges'))
.expect(200, '123456789', done)
})

it('should ignore Rage request header', function (done) {
request(createServer(fixtures, { 'acceptRanges': false }))
request(createServer(fixtures, { acceptRanges: false }))
.get('/nums.txt')
.set('Range', 'bytes=0-3')
.expect(shouldNotHaveHeader('Accept-Ranges'))
Expand All @@ -168,14 +168,14 @@ describe('serveStatic()', function () {

describe('when true', function () {
it('should include Accept-Ranges', function (done) {
request(createServer(fixtures, { 'acceptRanges': true }))
request(createServer(fixtures, { acceptRanges: true }))
.get('/nums.txt')
.expect('Accept-Ranges', 'bytes')
.expect(200, '123456789', done)
})

it('should obey Rage request header', function (done) {
request(createServer(fixtures, { 'acceptRanges': true }))
request(createServer(fixtures, { acceptRanges: true }))
.get('/nums.txt')
.set('Range', 'bytes=0-3')
.expect('Accept-Ranges', 'bytes')
Expand All @@ -188,14 +188,14 @@ describe('serveStatic()', function () {
describe('cacheControl', function () {
describe('when false', function () {
it('should not include Cache-Control', function (done) {
request(createServer(fixtures, { 'cacheControl': false }))
request(createServer(fixtures, { cacheControl: false }))
.get('/nums.txt')
.expect(shouldNotHaveHeader('Cache-Control'))
.expect(200, '123456789', done)
})

it('should ignore maxAge', function (done) {
request(createServer(fixtures, { 'cacheControl': false, 'maxAge': 12000 }))
request(createServer(fixtures, { cacheControl: false, maxAge: 12000 }))
.get('/nums.txt')
.expect(shouldNotHaveHeader('Cache-Control'))
.expect(200, '123456789', done)
Expand All @@ -204,7 +204,7 @@ describe('serveStatic()', function () {

describe('when true', function () {
it('should include Cache-Control', function (done) {
request(createServer(fixtures, { 'cacheControl': true }))
request(createServer(fixtures, { cacheControl: true }))
.get('/nums.txt')
.expect('Cache-Control', 'public, max-age=0')
.expect(200, '123456789', done)
Expand All @@ -222,31 +222,31 @@ describe('serveStatic()', function () {
})

it('should be configurable', function (done) {
var server = createServer(fixtures, { 'extensions': 'txt' })
var server = createServer(fixtures, { extensions: 'txt' })

request(server)
.get('/todo')
.expect(200, '- groceries', done)
})

it('should support disabling extensions', function (done) {
var server = createServer(fixtures, { 'extensions': false })
var server = createServer(fixtures, { extensions: false })

request(server)
.get('/todo')
.expect(404, done)
})

it('should support fallbacks', function (done) {
var server = createServer(fixtures, { 'extensions': ['htm', 'html', 'txt'] })
var server = createServer(fixtures, { extensions: ['htm', 'html', 'txt'] })

request(server)
.get('/todo')
.expect(200, '<li>groceries</li>', done)
})

it('should 404 if nothing found', function (done) {
var server = createServer(fixtures, { 'extensions': ['htm', 'html', 'txt'] })
var server = createServer(fixtures, { extensions: ['htm', 'html', 'txt'] })

request(server)
.get('/bob')
Expand All @@ -263,7 +263,7 @@ describe('serveStatic()', function () {

describe('when true', function () {
before(function () {
this.server = createServer(fixtures, { 'fallthrough': true })
this.server = createServer(fixtures, { fallthrough: true })
})

it('should fall-through when OPTIONS request', function (done) {
Expand All @@ -287,14 +287,14 @@ describe('serveStatic()', function () {
it('should fall-through when URL too long', function (done) {
var root = fixtures + Array(10000).join('/foobar')

request(createServer(root, { 'fallthrough': true }))
request(createServer(root, { fallthrough: true }))
.get('/')
.expect(404, 'sorry!', done)
})

describe('with redirect: true', function () {
before(function () {
this.server = createServer(fixtures, { 'fallthrough': true, 'redirect': true })
this.server = createServer(fixtures, { fallthrough: true, redirect: true })
})

it('should fall-through when directory', function (done) {
Expand All @@ -312,7 +312,7 @@ describe('serveStatic()', function () {

describe('with redirect: false', function () {
before(function () {
this.server = createServer(fixtures, { 'fallthrough': true, 'redirect': false })
this.server = createServer(fixtures, { fallthrough: true, redirect: false })
})

it('should fall-through when directory', function (done) {
Expand All @@ -331,7 +331,7 @@ describe('serveStatic()', function () {

describe('when false', function () {
before(function () {
this.server = createServer(fixtures, { 'fallthrough': false })
this.server = createServer(fixtures, { fallthrough: false })
})

it('should 405 when OPTIONS request', function (done) {
Expand All @@ -356,14 +356,14 @@ describe('serveStatic()', function () {
it('should 404 when URL too long', function (done) {
var root = fixtures + Array(10000).join('/foobar')

request(createServer(root, { 'fallthrough': false }))
request(createServer(root, { fallthrough: false }))
.get('/')
.expect(404, /ENAMETOOLONG/, done)
})

describe('with redirect: true', function () {
before(function () {
this.server = createServer(fixtures, { 'fallthrough': false, 'redirect': true })
this.server = createServer(fixtures, { fallthrough: false, redirect: true })
})

it('should 404 when directory', function (done) {
Expand All @@ -381,7 +381,7 @@ describe('serveStatic()', function () {

describe('with redirect: false', function () {
before(function () {
this.server = createServer(fixtures, { 'fallthrough': false, 'redirect': false })
this.server = createServer(fixtures, { fallthrough: false, redirect: false })
})

it('should 404 when directory', function (done) {
Expand All @@ -402,7 +402,7 @@ describe('serveStatic()', function () {
describe('hidden files', function () {
var server
before(function () {
server = createServer(fixtures, { 'dotfiles': 'allow' })
server = createServer(fixtures, { dotfiles: 'allow' })
})

it('should be served when dotfiles: "allow" is given', function (done) {
Expand All @@ -422,7 +422,7 @@ describe('serveStatic()', function () {
})

it('should set immutable directive in Cache-Control', function (done) {
request(createServer(fixtures, { 'immutable': true, 'maxAge': '1h' }))
request(createServer(fixtures, { immutable: true, maxAge: '1h' }))
.get('/nums.txt')
.expect('Cache-Control', 'public, max-age=3600, immutable', done)
})
Expand All @@ -431,7 +431,7 @@ describe('serveStatic()', function () {
describe('lastModified', function () {
describe('when false', function () {
it('should not include Last-Modifed', function (done) {
request(createServer(fixtures, { 'lastModified': false }))
request(createServer(fixtures, { lastModified: false }))
.get('/nums.txt')
.expect(shouldNotHaveHeader('Last-Modified'))
.expect(200, '123456789', done)
Expand All @@ -440,7 +440,7 @@ describe('serveStatic()', function () {

describe('when true', function () {
it('should include Last-Modifed', function (done) {
request(createServer(fixtures, { 'lastModified': true }))
request(createServer(fixtures, { lastModified: true }))
.get('/nums.txt')
.expect('Last-Modified', /^\w{3}, \d+ \w+ \d+ \d+:\d+:\d+ \w+$/)
.expect(200, '123456789', done)
Expand All @@ -450,14 +450,14 @@ describe('serveStatic()', function () {

describe('maxAge', function () {
it('should accept string', function (done) {
request(createServer(fixtures, { 'maxAge': '30d' }))
request(createServer(fixtures, { maxAge: '30d' }))
.get('/todo.txt')
.expect('cache-control', 'public, max-age=' + (60 * 60 * 24 * 30))
.expect(200, done)
})

it('should be reasonable when infinite', function (done) {
request(createServer(fixtures, { 'maxAge': Infinity }))
request(createServer(fixtures, { maxAge: Infinity }))
.get('/todo.txt')
.expect('cache-control', 'public, max-age=' + (60 * 60 * 24 * 365))
.expect(200, done)
Expand Down Expand Up @@ -524,7 +524,7 @@ describe('serveStatic()', function () {
describe('when false', function () {
var server
before(function () {
server = createServer(fixtures, { 'redirect': false })
server = createServer(fixtures, { redirect: false })
})

it('should disable redirect', function (done) {
Expand All @@ -537,11 +537,11 @@ describe('serveStatic()', function () {

describe('setHeaders', function () {
it('should reject non-functions', function () {
assert.throws(serveStatic.bind(null, fixtures, { 'setHeaders': 3 }), /setHeaders.*function/)
assert.throws(serveStatic.bind(null, fixtures, { setHeaders: 3 }), /setHeaders.*function/)
})

it('should get called when sending file', function (done) {
var server = createServer(fixtures, { 'setHeaders': function (res) {
var server = createServer(fixtures, { setHeaders: function (res) {
res.setHeader('x-custom', 'set')
} })

Expand All @@ -552,7 +552,7 @@ describe('serveStatic()', function () {
})

it('should not get called on 404', function (done) {
var server = createServer(fixtures, { 'setHeaders': function (res) {
var server = createServer(fixtures, { setHeaders: function (res) {
res.setHeader('x-custom', 'set')
} })

Expand All @@ -563,7 +563,7 @@ describe('serveStatic()', function () {
})

it('should not get called on redirect', function (done) {
var server = createServer(fixtures, { 'setHeaders': function (res) {
var server = createServer(fixtures, { setHeaders: function (res) {
res.setHeader('x-custom', 'set')
} })

Expand All @@ -576,7 +576,7 @@ describe('serveStatic()', function () {

describe('when traversing past root', function () {
before(function () {
this.server = createServer(fixtures, { 'fallthrough': false })
this.server = createServer(fixtures, { fallthrough: false })
})

it('should catch urlencoded ../', function (done) {
Expand Down Expand Up @@ -787,7 +787,7 @@ describe('serveStatic()', function () {
describe('when index file serving disabled', function () {
var server
before(function () {
server = createServer(fixtures, { 'index': false }, function (req) {
server = createServer(fixtures, { index: false }, function (req) {
// mimic express/connect mount
req.originalUrl = req.url
req.url = '/' + req.url.split('/').slice(2).join('/')
Expand Down

0 comments on commit b12d519

Please sign in to comment.