Skip to content

Commit

Permalink
refactor: prefix unused params with underscores (#316)
Browse files Browse the repository at this point in the history
  • Loading branch information
Fdawgs authored Jan 4, 2025
1 parent 0f1acb1 commit 639f778
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 34 deletions.
2 changes: 1 addition & 1 deletion benchmark/cookie-multi.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const secret = 'testsecret'
const fastify = Fastify()
fastify.register(plugin, { secret })

fastify.get('/', (req, reply) => {
fastify.get('/', (_req, reply) => {
reply
.setCookie('foo', 'foo')
.setCookie('foo', 'foo', { path: '/1' })
Expand Down
2 changes: 1 addition & 1 deletion benchmark/cookie.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const secret = 'testsecret'
const fastify = Fastify()
fastify.register(plugin, { secret })

fastify.get('/', (req, reply) => {
fastify.get('/', (_req, reply) => {
reply
.setCookie('foo', 'foo', { path: '/' })
.send({ hello: 'world' })
Expand Down
4 changes: 2 additions & 2 deletions plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ function parseCookies (fastify, request, reply) {

function onReqHandlerWrapper (fastify, hook) {
return hook === 'preParsing'
? function fastifyCookieHandler (fastifyReq, fastifyRes, payload, done) {
? function fastifyCookieHandler (fastifyReq, fastifyRes, _payload, done) {
parseCookies(fastify, fastifyReq, fastifyRes)
done()
}
Expand Down Expand Up @@ -98,7 +98,7 @@ function setCookies (reply) {
reply[kReplySetCookies].clear()
}

function fastifyCookieOnSendHandler (fastifyReq, fastifyRes, payload, done) {
function fastifyCookieOnSendHandler (_fastifyReq, fastifyRes, _payload, done) {
if (!fastifyRes[kReplySetCookies]) {
done()
return
Expand Down
60 changes: 30 additions & 30 deletions test/cookie.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ test('cookies get set correctly', async (t) => {
const fastify = Fastify()
fastify.register(plugin)

fastify.get('/test1', (req, reply) => {
fastify.get('/test1', (_req, reply) => {
reply
.setCookie('foo', 'foo', { path: '/' })
.send({ hello: 'world' })
Expand All @@ -39,7 +39,7 @@ test('express cookie compatibility', async (t) => {
const fastify = Fastify()
fastify.register(plugin)

fastify.get('/espresso', (req, reply) => {
fastify.get('/espresso', (_req, reply) => {
reply
.cookie('foo', 'foo', { path: '/' })
.send({ hello: 'world' })
Expand All @@ -65,7 +65,7 @@ test('should set multiple cookies', async (t) => {
const fastify = Fastify()
fastify.register(plugin)

fastify.get('/', (req, reply) => {
fastify.get('/', (_req, reply) => {
reply
.setCookie('foo', 'foo')
.cookie('bar', 'test')
Expand Down Expand Up @@ -96,7 +96,7 @@ test('should set multiple cookies', async (t) => {
const fastify = Fastify()
fastify.register(plugin)

fastify.get('/', (req, reply) => {
fastify.get('/', (_req, reply) => {
reply
.setCookie('foo', 'foo')
.cookie('bar', 'test', {
Expand Down Expand Up @@ -135,7 +135,7 @@ test('should set multiple cookies (an array already exists)', async (t) => {
const fastify = Fastify()
fastify.register(plugin)

fastify.get('/test1', (req, reply) => {
fastify.get('/test1', (_req, reply) => {
reply
.header('Set-Cookie', ['bar=bar'])
.setCookie('foo', 'foo', { path: '/' })
Expand Down Expand Up @@ -167,7 +167,7 @@ test('cookies get set correctly with millisecond dates', async (t) => {
const fastify = Fastify()
fastify.register(plugin)

fastify.get('/test1', (req, reply) => {
fastify.get('/test1', (_req, reply) => {
reply
.setCookie('foo', 'foo', { path: '/', expires: Date.now() + 1000 })
.send({ hello: 'world' })
Expand Down Expand Up @@ -201,7 +201,7 @@ test('share options for setCookie and clearCookie', async (t) => {
maxAge: 36000
}

fastify.get('/test1', (req, reply) => {
fastify.get('/test1', (_req, reply) => {
reply
.setCookie('foo', 'foo', cookieOptions)
.clearCookie('foo', cookieOptions)
Expand Down Expand Up @@ -236,7 +236,7 @@ test('expires should not be overridden in clearCookie', async (t) => {
expires: Date.now() + 1000
}

fastify.get('/test1', (req, reply) => {
fastify.get('/test1', (_req, reply) => {
reply
.setCookie('foo', 'foo', cookieOptions)
.clearCookie('foo', cookieOptions)
Expand Down Expand Up @@ -266,15 +266,15 @@ test('parses incoming cookies', async (t) => {

// check that it parses the cookies in the onRequest hook
for (const hook of ['preValidation', 'preHandler']) {
fastify.addHook(hook, (req, reply, done) => {
fastify.addHook(hook, (req, _reply, done) => {
t.assert.ok(req.cookies)
t.assert.ok(req.cookies.bar)
t.assert.strictEqual(req.cookies.bar, 'bar')
done()
})
}

fastify.addHook('preParsing', (req, reply, payload, done) => {
fastify.addHook('preParsing', (req, _reply, _payload, done) => {
t.assert.ok(req.cookies)
t.assert.ok(req.cookies.bar)
t.assert.strictEqual(req.cookies.bar, 'bar')
Expand Down Expand Up @@ -307,7 +307,7 @@ test('defined and undefined cookies', async (t) => {

// check that it parses the cookies in the onRequest hook
for (const hook of ['preValidation', 'preHandler']) {
fastify.addHook(hook, (req, reply, done) => {
fastify.addHook(hook, (req, _reply, done) => {
t.assert.ok(req.cookies)

t.assert.ok(req.cookies.bar)
Expand All @@ -319,7 +319,7 @@ test('defined and undefined cookies', async (t) => {
})
}

fastify.addHook('preParsing', (req, reply, payload, done) => {
fastify.addHook('preParsing', (req, _reply, _payload, done) => {
t.assert.ok(req.cookies)

t.assert.ok(req.cookies.bar)
Expand Down Expand Up @@ -365,7 +365,7 @@ test('does not modify supplied cookie options object', async (t) => {
const fastify = Fastify()
fastify.register(plugin)

fastify.get('/test1', (req, reply) => {
fastify.get('/test1', (_req, reply) => {
reply
.setCookie('foo', 'foo', cookieOptions)
.send({ hello: 'world' })
Expand All @@ -388,7 +388,7 @@ test('cookies gets cleared correctly', async (t) => {
const fastify = Fastify()
fastify.register(plugin)

fastify.get('/test1', (req, reply) => {
fastify.get('/test1', (_req, reply) => {
reply
.clearCookie('foo')
.send({ hello: 'world' })
Expand All @@ -414,7 +414,7 @@ describe('cookies signature', () => {
const secret = 'bar'
fastify.register(plugin, { secret })

fastify.get('/test1', (req, reply) => {
fastify.get('/test1', (_req, reply) => {
reply
.setCookie('foo', 'foo', { signed: true })
.send({ hello: 'world' })
Expand All @@ -441,7 +441,7 @@ describe('cookies signature', () => {
const secret2 = 'secret-2'
fastify.register(plugin, { secret: [secret1, secret2] })

fastify.get('/test1', (req, reply) => {
fastify.get('/test1', (_req, reply) => {
reply
.setCookie('foo', 'cookieVal', { signed: true })
.send({ hello: 'world' })
Expand Down Expand Up @@ -643,7 +643,7 @@ test('custom signer', async (t) => {
const secret = { sign: signStub, unsign: unsignStub }
fastify.register(plugin, { secret })

fastify.get('/test1', (req, reply) => {
fastify.get('/test1', (_req, reply) => {
reply
.setCookie('foo', 'bar', { signed: true })
.send({ hello: 'world' })
Expand Down Expand Up @@ -786,7 +786,7 @@ test('cookies set with plugin options parseOptions field', async (t) => {
}
})

fastify.get('/test', (req, reply) => {
fastify.get('/test', (_req, reply) => {
reply.setCookie('foo', 'foo').send({ hello: 'world' })
})

Expand Down Expand Up @@ -835,7 +835,7 @@ test('handle secure:auto of cookieOptions', async (t) => {

await fastify.register(plugin)

fastify.get('/test1', (req, reply) => {
fastify.get('/test1', (_req, reply) => {
reply
.setCookie('foo', 'foo', { path: '/', secure: 'auto' })
.send()
Expand Down Expand Up @@ -1011,7 +1011,7 @@ test('clearCookie should include parseOptions', async (t) => {
maxAge: 36000
}

fastify.get('/test1', (req, reply) => {
fastify.get('/test1', (_req, reply) => {
reply
.setCookie('foo', 'foo', cookieOptions)
.clearCookie('foo', cookieOptions)
Expand Down Expand Up @@ -1055,7 +1055,7 @@ test('should update a cookie value when setCookie is called multiple times', asy
maxAge: 36000
}

fastify.get('/test1', (req, reply) => {
fastify.get('/test1', (_req, reply) => {
reply
.setCookie('foo', 'foo', cookieOptions)
.clearCookie('foo', cookieOptions)
Expand Down Expand Up @@ -1109,7 +1109,7 @@ test('should update a cookie value when setCookie is called multiple times (empt
maxAge: 36000
}

fastify.get('/test1', (req, reply) => {
fastify.get('/test1', (_req, reply) => {
reply
.header('Set-Cookie', '', cookieOptions)
.setCookie('foo', 'foo', cookieOptions)
Expand Down Expand Up @@ -1164,7 +1164,7 @@ test('should update a cookie value when setCookie is called multiple times (non-
maxAge: 36000
}

fastify.get('/test1', (req, reply) => {
fastify.get('/test1', (_req, reply) => {
reply
.header('Set-Cookie', 'manual=manual', cookieOptions)
.setCookie('foo', 'foo', cookieOptions)
Expand Down Expand Up @@ -1207,12 +1207,12 @@ test('cookies get set correctly if set inside onSend', async (t) => {
const fastify = Fastify()
fastify.register(plugin)

fastify.addHook('onSend', async (req, reply, payload) => {
fastify.addHook('onSend', async (_req, reply, payload) => {
reply.setCookie('foo', 'foo', { path: '/' })
return payload
})

fastify.get('/test1', (req, reply) => {
fastify.get('/test1', (_req, reply) => {
reply
.send({ hello: 'world' })
})
Expand All @@ -1237,16 +1237,16 @@ test('cookies get set correctly if set inside multiple onSends', async (t) => {
const fastify = Fastify()
fastify.register(plugin)

fastify.addHook('onSend', async (req, reply, payload) => {
fastify.addHook('onSend', async (_req, reply, _payload) => {
reply.setCookie('foo', 'foo', { path: '/' })
})

fastify.addHook('onSend', async (req, reply, payload) => {
fastify.addHook('onSend', async (_req, reply, payload) => {
reply.setCookie('foo', 'foos', { path: '/' })
return payload
})

fastify.get('/test1', (req, reply) => {
fastify.get('/test1', (_req, reply) => {
reply
.send({ hello: 'world' })
})
Expand All @@ -1273,7 +1273,7 @@ test('cookies get set correctly if set inside onRequest', async (t) => {
t.plan(6)

const fastify = Fastify()
fastify.addHook('onRequest', async (req, reply) => {
fastify.addHook('onRequest', async (_req, reply) => {
reply.setCookie('foo', 'foo', { path: '/' })
return reply.send({ hello: 'world' })
})
Expand All @@ -1298,7 +1298,7 @@ test('do not crash if the onRequest hook is not run', async (t) => {
t.plan(2)

const fastify = Fastify()
fastify.addHook('onRequest', async (req, reply) => {
fastify.addHook('onRequest', async (_req, reply) => {
return reply.send({ hello: 'world' })
})

Expand Down

0 comments on commit 639f778

Please sign in to comment.