Skip to content

Commit 639f778

Browse files
authored
refactor: prefix unused params with underscores (#316)
1 parent 0f1acb1 commit 639f778

File tree

4 files changed

+34
-34
lines changed

4 files changed

+34
-34
lines changed

benchmark/cookie-multi.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const secret = 'testsecret'
88
const fastify = Fastify()
99
fastify.register(plugin, { secret })
1010

11-
fastify.get('/', (req, reply) => {
11+
fastify.get('/', (_req, reply) => {
1212
reply
1313
.setCookie('foo', 'foo')
1414
.setCookie('foo', 'foo', { path: '/1' })

benchmark/cookie.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const secret = 'testsecret'
88
const fastify = Fastify()
99
fastify.register(plugin, { secret })
1010

11-
fastify.get('/', (req, reply) => {
11+
fastify.get('/', (_req, reply) => {
1212
reply
1313
.setCookie('foo', 'foo', { path: '/' })
1414
.send({ hello: 'world' })

plugin.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ function parseCookies (fastify, request, reply) {
5959

6060
function onReqHandlerWrapper (fastify, hook) {
6161
return hook === 'preParsing'
62-
? function fastifyCookieHandler (fastifyReq, fastifyRes, payload, done) {
62+
? function fastifyCookieHandler (fastifyReq, fastifyRes, _payload, done) {
6363
parseCookies(fastify, fastifyReq, fastifyRes)
6464
done()
6565
}
@@ -98,7 +98,7 @@ function setCookies (reply) {
9898
reply[kReplySetCookies].clear()
9999
}
100100

101-
function fastifyCookieOnSendHandler (fastifyReq, fastifyRes, payload, done) {
101+
function fastifyCookieOnSendHandler (_fastifyReq, fastifyRes, _payload, done) {
102102
if (!fastifyRes[kReplySetCookies]) {
103103
done()
104104
return

test/cookie.test.js

+30-30
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ test('cookies get set correctly', async (t) => {
1212
const fastify = Fastify()
1313
fastify.register(plugin)
1414

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

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

68-
fastify.get('/', (req, reply) => {
68+
fastify.get('/', (_req, reply) => {
6969
reply
7070
.setCookie('foo', 'foo')
7171
.cookie('bar', 'test')
@@ -96,7 +96,7 @@ test('should set multiple cookies', async (t) => {
9696
const fastify = Fastify()
9797
fastify.register(plugin)
9898

99-
fastify.get('/', (req, reply) => {
99+
fastify.get('/', (_req, reply) => {
100100
reply
101101
.setCookie('foo', 'foo')
102102
.cookie('bar', 'test', {
@@ -135,7 +135,7 @@ test('should set multiple cookies (an array already exists)', async (t) => {
135135
const fastify = Fastify()
136136
fastify.register(plugin)
137137

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

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

204-
fastify.get('/test1', (req, reply) => {
204+
fastify.get('/test1', (_req, reply) => {
205205
reply
206206
.setCookie('foo', 'foo', cookieOptions)
207207
.clearCookie('foo', cookieOptions)
@@ -236,7 +236,7 @@ test('expires should not be overridden in clearCookie', async (t) => {
236236
expires: Date.now() + 1000
237237
}
238238

239-
fastify.get('/test1', (req, reply) => {
239+
fastify.get('/test1', (_req, reply) => {
240240
reply
241241
.setCookie('foo', 'foo', cookieOptions)
242242
.clearCookie('foo', cookieOptions)
@@ -266,15 +266,15 @@ test('parses incoming cookies', async (t) => {
266266

267267
// check that it parses the cookies in the onRequest hook
268268
for (const hook of ['preValidation', 'preHandler']) {
269-
fastify.addHook(hook, (req, reply, done) => {
269+
fastify.addHook(hook, (req, _reply, done) => {
270270
t.assert.ok(req.cookies)
271271
t.assert.ok(req.cookies.bar)
272272
t.assert.strictEqual(req.cookies.bar, 'bar')
273273
done()
274274
})
275275
}
276276

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

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

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

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

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

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

391-
fastify.get('/test1', (req, reply) => {
391+
fastify.get('/test1', (_req, reply) => {
392392
reply
393393
.clearCookie('foo')
394394
.send({ hello: 'world' })
@@ -414,7 +414,7 @@ describe('cookies signature', () => {
414414
const secret = 'bar'
415415
fastify.register(plugin, { secret })
416416

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

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

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

789-
fastify.get('/test', (req, reply) => {
789+
fastify.get('/test', (_req, reply) => {
790790
reply.setCookie('foo', 'foo').send({ hello: 'world' })
791791
})
792792

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

836836
await fastify.register(plugin)
837837

838-
fastify.get('/test1', (req, reply) => {
838+
fastify.get('/test1', (_req, reply) => {
839839
reply
840840
.setCookie('foo', 'foo', { path: '/', secure: 'auto' })
841841
.send()
@@ -1011,7 +1011,7 @@ test('clearCookie should include parseOptions', async (t) => {
10111011
maxAge: 36000
10121012
}
10131013

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

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

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

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

1210-
fastify.addHook('onSend', async (req, reply, payload) => {
1210+
fastify.addHook('onSend', async (_req, reply, payload) => {
12111211
reply.setCookie('foo', 'foo', { path: '/' })
12121212
return payload
12131213
})
12141214

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

1240-
fastify.addHook('onSend', async (req, reply, payload) => {
1240+
fastify.addHook('onSend', async (_req, reply, _payload) => {
12411241
reply.setCookie('foo', 'foo', { path: '/' })
12421242
})
12431243

1244-
fastify.addHook('onSend', async (req, reply, payload) => {
1244+
fastify.addHook('onSend', async (_req, reply, payload) => {
12451245
reply.setCookie('foo', 'foos', { path: '/' })
12461246
return payload
12471247
})
12481248

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

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

13001300
const fastify = Fastify()
1301-
fastify.addHook('onRequest', async (req, reply) => {
1301+
fastify.addHook('onRequest', async (_req, reply) => {
13021302
return reply.send({ hello: 'world' })
13031303
})
13041304

0 commit comments

Comments
 (0)