Skip to content

Commit 6c09ab5

Browse files
committed
refactor: prefix unused params with underscores
1 parent 7ba7b7f commit 6c09ab5

File tree

5 files changed

+62
-62
lines changed

5 files changed

+62
-62
lines changed

index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ function fastifyWebsocket (fastify, opts, next) {
130130
})
131131
}
132132

133-
fastify.addHook('onRequest', (request, reply, done) => { // this adds req.ws to the Request object
133+
fastify.addHook('onRequest', (request, _reply, done) => { // this adds req.ws to the Request object
134134
if (request.raw[kWs]) {
135135
request.ws = true
136136
} else {
@@ -139,7 +139,7 @@ function fastifyWebsocket (fastify, opts, next) {
139139
done()
140140
})
141141

142-
fastify.addHook('onResponse', (request, reply, done) => {
142+
fastify.addHook('onResponse', (request, _reply, done) => {
143143
if (request.ws) {
144144
request.raw[kWs].destroy()
145145
}

test/base.test.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -651,7 +651,7 @@ test('clashing upgrade handler', async (t) => {
651651
const fastify = Fastify()
652652
t.teardown(() => fastify.close())
653653

654-
fastify.server.on('upgrade', (req, socket, head) => {
654+
fastify.server.on('upgrade', (req, socket) => {
655655
const res = new http.ServerResponse(req)
656656
res.assignSocket(socket)
657657
res.end()
@@ -660,7 +660,7 @@ test('clashing upgrade handler', async (t) => {
660660

661661
await fastify.register(fastifyWebsocket)
662662

663-
fastify.get('/', { websocket: true }, (connection) => {
663+
fastify.get('/', { websocket: true }, () => {
664664
t.fail('this should never be invoked')
665665
})
666666

test/hooks.test.js

+29-29
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ test('Should run onRequest, preValidation, preHandler hooks', t => {
1616
fastify.register(fastifyWebsocket)
1717

1818
fastify.register(async function (fastify) {
19-
fastify.addHook('onRequest', async (request, reply) => t.ok('called', 'onRequest'))
20-
fastify.addHook('preParsing', async (request, reply, payload) => t.ok('called', 'preParsing'))
21-
fastify.addHook('preValidation', async (request, reply) => t.ok('called', 'preValidation'))
22-
fastify.addHook('preHandler', async (request, reply) => t.ok('called', 'preHandler'))
19+
fastify.addHook('onRequest', async () => t.ok('called', 'onRequest'))
20+
fastify.addHook('preParsing', async () => t.ok('called', 'preParsing'))
21+
fastify.addHook('preValidation', async () => t.ok('called', 'preValidation'))
22+
fastify.addHook('preHandler', async () => t.ok('called', 'preHandler'))
2323

24-
fastify.get('/echo', { websocket: true }, (socket, request) => {
24+
fastify.get('/echo', { websocket: true }, (socket) => {
2525
socket.send('hello client')
2626
t.teardown(() => socket.terminate())
2727

@@ -56,7 +56,7 @@ test('Should not run onTimeout hook', t => {
5656
fastify.register(fastifyWebsocket)
5757

5858
fastify.register(async function () {
59-
fastify.addHook('onTimeout', async (request, reply) => t.fail('called', 'onTimeout'))
59+
fastify.addHook('onTimeout', async () => t.fail('called', 'onTimeout'))
6060

6161
fastify.get('/echo', { websocket: true }, (socket, request) => {
6262
socket.send('hello client')
@@ -86,10 +86,10 @@ test('Should run onError hook before handler is executed (error thrown in onRequ
8686
fastify.register(fastifyWebsocket)
8787

8888
fastify.register(async function (fastify) {
89-
fastify.addHook('onRequest', async (request, reply) => { throw new Error('Fail') })
90-
fastify.addHook('onError', async (request, reply) => t.ok('called', 'onError'))
89+
fastify.addHook('onRequest', async () => { throw new Error('Fail') })
90+
fastify.addHook('onError', async () => t.ok('called', 'onError'))
9191

92-
fastify.get('/echo', { websocket: true }, (conn, request) => {
92+
fastify.get('/echo', { websocket: true }, () => {
9393
t.fail()
9494
})
9595
})
@@ -110,14 +110,14 @@ test('Should run onError hook before handler is executed (error thrown in preVal
110110
fastify.register(fastifyWebsocket)
111111

112112
fastify.register(async function (fastify) {
113-
fastify.addHook('preValidation', async (request, reply) => {
113+
fastify.addHook('preValidation', async () => {
114114
await Promise.resolve()
115115
throw new Error('Fail')
116116
})
117117

118-
fastify.addHook('onError', async (request, reply) => t.ok('called', 'onError'))
118+
fastify.addHook('onError', async () => t.ok('called', 'onError'))
119119

120-
fastify.get('/echo', { websocket: true }, (conn, request) => {
120+
fastify.get('/echo', { websocket: true }, () => {
121121
t.fail()
122122
})
123123
})
@@ -138,17 +138,17 @@ test('onError hooks can send a reply and prevent hijacking', t => {
138138
fastify.register(fastifyWebsocket)
139139

140140
fastify.register(async function (fastify) {
141-
fastify.addHook('preValidation', async (request, reply) => {
141+
fastify.addHook('preValidation', async () => {
142142
await Promise.resolve()
143143
throw new Error('Fail')
144144
})
145145

146-
fastify.addHook('onError', async (request, reply) => {
146+
fastify.addHook('onError', async (_request, reply) => {
147147
t.ok('called', 'onError')
148148
await reply.code(501).send('there was an error')
149149
})
150150

151-
fastify.get('/echo', { websocket: true }, (conn, request) => {
151+
fastify.get('/echo', { websocket: true }, () => {
152152
t.fail()
153153
})
154154
})
@@ -169,18 +169,18 @@ test('setErrorHandler functions can send a reply and prevent hijacking', t => {
169169
fastify.register(fastifyWebsocket)
170170

171171
fastify.register(async function (fastify) {
172-
fastify.addHook('preValidation', async (request, reply) => {
172+
fastify.addHook('preValidation', async () => {
173173
await Promise.resolve()
174174
throw new Error('Fail')
175175
})
176176

177-
fastify.setErrorHandler(async (error, request, reply) => {
177+
fastify.setErrorHandler(async (error, _request, reply) => {
178178
t.ok('called', 'onError')
179179
t.ok(error)
180180
await reply.code(501).send('there was an error')
181181
})
182182

183-
fastify.get('/echo', { websocket: true }, (conn, request) => {
183+
fastify.get('/echo', { websocket: true }, () => {
184184
t.fail()
185185
})
186186
})
@@ -201,9 +201,9 @@ test('Should not run onError hook if reply was already hijacked (error thrown in
201201
fastify.register(fastifyWebsocket)
202202

203203
fastify.register(async function (fastify) {
204-
fastify.addHook('onError', async (request, reply) => t.fail('called', 'onError'))
204+
fastify.addHook('onError', async () => t.fail('called', 'onError'))
205205

206-
fastify.get('/echo', { websocket: true }, async (socket, request) => {
206+
fastify.get('/echo', { websocket: true }, async (socket) => {
207207
t.teardown(() => socket.terminate())
208208
throw new Error('Fail')
209209
})
@@ -227,10 +227,10 @@ test('Should not run preSerialization/onSend hooks', t => {
227227
fastify.register(fastifyWebsocket)
228228

229229
fastify.register(async function (fastify) {
230-
fastify.addHook('onSend', async (request, reply) => t.fail('called', 'onSend'))
231-
fastify.addHook('preSerialization', async (request, reply) => t.fail('called', 'preSerialization'))
230+
fastify.addHook('onSend', async () => t.fail('called', 'onSend'))
231+
fastify.addHook('preSerialization', async () => t.fail('called', 'preSerialization'))
232232

233-
fastify.get('/echo', { websocket: true }, async (socket, request) => {
233+
fastify.get('/echo', { websocket: true }, async (socket) => {
234234
socket.send('hello client')
235235
t.teardown(() => socket.terminate())
236236
})
@@ -258,7 +258,7 @@ test('Should not hijack reply for a normal http request in the internal onError
258258
fastify.register(fastifyWebsocket)
259259

260260
fastify.register(async function (fastify) {
261-
fastify.get('/', async (request, reply) => {
261+
fastify.get('/', async () => {
262262
throw new Error('Fail')
263263
})
264264
})
@@ -294,7 +294,7 @@ test('Should run async hooks and still deliver quickly sent messages', (t) => {
294294
async () => await new Promise((resolve) => setTimeout(resolve, 25))
295295
)
296296

297-
fastify.get('/echo', { websocket: true }, (socket, request) => {
297+
fastify.get('/echo', { websocket: true }, (socket) => {
298298
socket.send('hello client')
299299
t.teardown(() => socket.terminate())
300300

@@ -329,11 +329,11 @@ test('Should not hijack reply for an normal request to a websocket route that is
329329

330330
fastify.register(fastifyWebsocket)
331331
fastify.register(async function (fastify) {
332-
fastify.addHook('preValidation', async (request, reply) => {
332+
fastify.addHook('preValidation', async (_request, reply) => {
333333
await Promise.resolve()
334334
await reply.code(404).send('not found')
335335
})
336-
fastify.get('/echo', { websocket: true }, (conn, request) => {
336+
fastify.get('/echo', { websocket: true }, () => {
337337
t.fail()
338338
})
339339
})
@@ -361,10 +361,10 @@ test('Should not hijack reply for an WS request to a WS route that gets sent a n
361361

362362
fastify.register(fastifyWebsocket)
363363
fastify.register(async function (fastify) {
364-
fastify.addHook('preValidation', async (request, reply) => {
364+
fastify.addHook('preValidation', async (_request, reply) => {
365365
await reply.code(404).send('not found')
366366
})
367-
fastify.get('/echo', { websocket: true }, (conn, request) => {
367+
fastify.get('/echo', { websocket: true }, () => {
368368
t.fail()
369369
})
370370
})

test/inject.test.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ test('routes correctly the message between two routes', async (t) => {
6868
fastify.register(
6969
async function (instance) {
7070
instance.get('/ws', { websocket: true }, function (socket) {
71-
socket.once('message', chunk => {
71+
socket.once('message', () => {
7272
_reject('wrong-route')
7373
})
7474
})
@@ -121,11 +121,11 @@ test('rejects if the websocket is not upgraded', async (t) => {
121121

122122
fastify.register(
123123
async function (instance) {
124-
instance.addHook('preValidation', async (request, reply) => {
124+
instance.addHook('preValidation', async (_request, reply) => {
125125
return reply.code(401).send()
126126
})
127127

128-
instance.get('/', { websocket: true }, function (conn) {
128+
instance.get('/', { websocket: true }, function () {
129129
})
130130
})
131131

0 commit comments

Comments
 (0)