Skip to content

Commit 954a642

Browse files
authored
refactor: prefix unused params with underscores (#399)
1 parent 59ed388 commit 954a642

File tree

7 files changed

+39
-39
lines changed

7 files changed

+39
-39
lines changed

benchmarks/origin.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ async function startOrigin () {
66
const origin = Fastify({
77
http2: !!process.env.HTTP2
88
})
9-
origin.get('/', async (request, reply) => {
9+
origin.get('/', async () => {
1010
return 'this is root'
1111
})
1212

13-
origin.get('/a', async (request, reply) => {
13+
origin.get('/a', async () => {
1414
return 'this is a'
1515
})
1616

17-
origin.post('/this-has-data', async (request, reply) => {
17+
origin.post('/this-has-data', async (request) => {
1818
if (request.body.hello === 'world') {
1919
return { something: 'posted' }
2020
}

examples/example.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,19 @@ const proxy = require('..')
66
async function startOrigin () {
77
const origin = Fastify()
88

9-
origin.get('/', async (request, reply) => {
9+
origin.get('/', async () => {
1010
return 'this is root'
1111
})
1212

13-
origin.get('/redirect', async (request, reply) => {
13+
origin.get('/redirect', async (_request, reply) => {
1414
return reply.redirect(302, 'https://fastify.dev')
1515
})
1616

17-
origin.get('/a', async (request, reply) => {
17+
origin.get('/a', async () => {
1818
return 'this is a'
1919
})
2020

21-
origin.post('/this-has-data', async (request, reply) => {
21+
origin.post('/this-has-data', async (request) => {
2222
if (request.body.hello === 'world') {
2323
return { something: 'posted' }
2424
}

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ async function fastifyHttpProxy (fastify, opts) {
266266
return headers
267267
}
268268

269-
function bodyParser (req, payload, done) {
269+
function bodyParser (_req, payload, done) {
270270
done(null, payload)
271271
}
272272

test/test.js

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ const qs = require('fast-querystring')
1010

1111
async function run () {
1212
const origin = Fastify()
13-
origin.get('/', async (request, reply) => {
13+
origin.get('/', async () => {
1414
return 'this is root'
1515
})
1616

17-
origin.get('/a', async (request, reply) => {
17+
origin.get('/a', async () => {
1818
return 'this is a'
1919
})
2020

21-
origin.get('/redirect', async (request, reply) => {
21+
origin.get('/redirect', async (_request, reply) => {
2222
return reply.redirect('https://fastify.dev', 302)
2323
})
2424

@@ -30,24 +30,24 @@ async function run () {
3030
throw new Error('kaboom')
3131
})
3232

33-
origin.post('/redirect-to-relative-url', async (request, reply) => {
33+
origin.post('/redirect-to-relative-url', async (_request, reply) => {
3434
reply.header('location', '/relative-url')
3535
return { status: 'ok' }
3636
})
3737

38-
origin.get('/api2/a', async (request, reply) => {
38+
origin.get('/api2/a', async () => {
3939
return 'this is /api2/a'
4040
})
4141

42-
origin.get('/variable-api/:id/endpoint', async (request, reply) => {
42+
origin.get('/variable-api/:id/endpoint', async (request) => {
4343
return `this is "variable-api" endpoint with id ${request.params.id}`
4444
})
4545

46-
origin.get('/variable-api/:id/endpoint-with-query', async (request, reply) => {
46+
origin.get('/variable-api/:id/endpoint-with-query', async (request) => {
4747
return `this is "variable-api" endpoint with id ${request.params.id} and query params ${JSON.stringify(request.query)}`
4848
})
4949

50-
origin.get('/timeout', async (request, reply) => {
50+
origin.get('/timeout', async () => {
5151
await new Promise((resolve) => setTimeout(resolve, 600))
5252
return 'this is never received'
5353
})
@@ -84,7 +84,7 @@ async function run () {
8484
t.fail('should never be called')
8585
},
8686
replyOptions: {
87-
getUpstream: function (original, base) {
87+
getUpstream: function () {
8888
return `http://localhost:${origin.server.address().port}`
8989
}
9090
}
@@ -130,7 +130,7 @@ async function run () {
130130
server.register(proxy, {
131131
upstream: '',
132132
replyOptions: {
133-
getUpstream: function (original, base) {
133+
getUpstream: function () {
134134
return `http://localhost:${origin.server.address().port}`
135135
}
136136
}
@@ -195,7 +195,7 @@ async function run () {
195195
upstream: '',
196196
prefix: '/my-prefix',
197197
replyOptions: {
198-
getUpstream: function (original, base) {
198+
getUpstream: function () {
199199
return `http://localhost:${origin.server.address().port}`
200200
}
201201
}
@@ -301,7 +301,7 @@ async function run () {
301301
server.register(proxy, {
302302
upstream: '',
303303
replyOptions: {
304-
getUpstream: function (original, base) {
304+
getUpstream: function () {
305305
return `http://localhost:${origin.server.address().port}`
306306
}
307307
}
@@ -326,7 +326,7 @@ async function run () {
326326
server.register(proxy, {
327327
upstream: `http://localhost:${origin.server.address().port}`,
328328
proxyPayloads: false,
329-
preHandler (request, reply, next) {
329+
preHandler (request, _reply, next) {
330330
t.same(request.body, { hello: 'world' })
331331
next()
332332
}
@@ -349,7 +349,7 @@ async function run () {
349349
const server = Fastify()
350350
server.register(proxy, {
351351
upstream: `http://localhost:${origin.server.address().port}`,
352-
async preHandler (request, reply) {
352+
async preHandler () {
353353
throw new Unauthorized()
354354
}
355355
})
@@ -381,7 +381,7 @@ async function run () {
381381
server.register(proxy, {
382382
upstream: `http://localhost:${origin.server.address().port}`,
383383
config: { foo: 'bar' },
384-
async preHandler (request, reply) {
384+
async preHandler (request) {
385385
t.same(request.routeOptions.config, {
386386
foo: 'bar',
387387
url: '/',
@@ -415,7 +415,7 @@ async function run () {
415415
test('multiple prefixes with multiple plugins', async t => {
416416
const origin2 = Fastify()
417417

418-
origin2.get('/', async (request, reply) => {
418+
origin2.get('/', async () => {
419419
return 'this is root for origin2'
420420
})
421421

@@ -666,11 +666,11 @@ async function run () {
666666
upstream: `http://localhost:${origin.server.address().port}`,
667667
prefix: '/api',
668668
replyOptions: {
669-
onResponse (request, reply, { stream }) {
669+
onResponse (_request, reply, { stream }) {
670670
return reply.send(
671671
stream.pipe(
672672
new Transform({
673-
transform: function (chunk, enc, cb) {
673+
transform: function (chunk, _enc, cb) {
674674
this.push(chunk.toString().toUpperCase())
675675
cb()
676676
}
@@ -788,8 +788,8 @@ async function run () {
788788
empty: () => { headerValues = {} }
789789
}
790790
},
791-
validate (value) { return true },
792-
deriveConstraint: (req, ctx) => {
791+
validate () { return true },
792+
deriveConstraint: (req) => {
793793
return req.headers['test-header']
794794
}
795795
})
@@ -867,10 +867,10 @@ async function run () {
867867
test('prefixed proxy with query search', async t => {
868868
const appServer = Fastify()
869869

870-
appServer.get('/second-service', async (request, reply) => {
870+
appServer.get('/second-service', async (request) => {
871871
return `Hello World - lang = ${request.query.lang}`
872872
})
873-
appServer.get('/second-service/foo', async (request, reply) => {
873+
appServer.get('/second-service/foo', async (request) => {
874874
return `Hello World (foo) - lang = ${request.query.lang}`
875875
})
876876
const address = await appServer.listen({ port: 0 })

test/websocket.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ test('websocket proxy trigger hooks', async (t) => {
284284
await promisify(origin.listen.bind(origin))({ port: 0, host: '127.0.0.1' })
285285

286286
const server = Fastify()
287-
server.addHook('onRequest', (request, reply, done) => {
287+
server.addHook('onRequest', (_request, _reply, done) => {
288288
t.pass('onRequest')
289289
done()
290290
})
@@ -347,7 +347,7 @@ test('websocket proxy with rewriteRequestHeaders', async (t) => {
347347
upstream: `ws://127.0.0.1:${origin.address().port}`,
348348
websocket: true,
349349
wsClientOptions: {
350-
rewriteRequestHeaders: (headers, request) => {
350+
rewriteRequestHeaders: (headers) => {
351351
return {
352352
...headers,
353353
myauth: 'myauth'
@@ -461,7 +461,7 @@ test('Should gracefully close when clients attempt to connect after calling clos
461461
server.server.close = function (cb) {
462462
const ws = new WebSocket('ws://127.0.0.1:' + server.server.address().port)
463463

464-
p = once(ws, 'unexpected-response').then(([req, res]) => {
464+
p = once(ws, 'unexpected-response').then(([_req, res]) => {
465465
t.equal(res.statusCode, 503)
466466
oldClose.call(this, cb)
467467
})

test/ws-prefix-rewrite-core.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,15 @@ async function processRequest (t, frontendURL, path, expected) {
5151
t.comment('websocket closed')
5252
wsResult = 'error'
5353
}
54-
} catch (e) {
54+
} catch {
5555
wsResult = 'error'
5656
ws.terminate()
5757
}
5858

5959
try {
6060
const result = await got(url)
6161
gotResult = result.body
62-
} catch (e) {
62+
} catch {
6363
gotResult = 'error'
6464
}
6565

@@ -79,7 +79,7 @@ async function handleProxy (info, { backendPath, proxyOptions, wrapperOptions },
7979
wsHandler: (socket, req) => {
8080
socket.send(req.url)
8181

82-
socket.once('message', chunk => {
82+
socket.once('message', () => {
8383
socket.close()
8484
})
8585
}

test/ws-prefix-rewrite.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,15 @@ async function processRequest (t, frontendURL, path, expected) {
4949
t.comment('websocket closed')
5050
wsResult = 'error'
5151
}
52-
} catch (e) {
52+
} catch {
5353
wsResult = 'error'
5454
ws.terminate()
5555
}
5656

5757
try {
5858
const result = await got(url)
5959
gotResult = result.body
60-
} catch (e) {
60+
} catch {
6161
gotResult = 'error'
6262
}
6363

@@ -77,7 +77,7 @@ async function handleProxy (info, { backendPath, proxyOptions, wrapperOptions },
7777
wsHandler: (socket, req) => {
7878
socket.send(req.url)
7979

80-
socket.once('message', chunk => {
80+
socket.once('message', () => {
8181
socket.close()
8282
})
8383
}

0 commit comments

Comments
 (0)