Skip to content

Commit bc34d54

Browse files
authored
refactor: prefix unused params with underscores (#350)
1 parent 4471cd7 commit bc34d54

File tree

7 files changed

+79
-79
lines changed

7 files changed

+79
-79
lines changed

bench.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22

33
const fastify = require('fastify')()
44

5-
fastify.register((instance, opts, next) => {
5+
fastify.register((instance, _opts, next) => {
66
instance.register(require('./index'))
7-
instance.get('/fastify', (req, reply) => reply.send('ok'))
7+
instance.get('/fastify', (_req, reply) => reply.send('ok'))
88
next()
99
})
1010

11-
fastify.register((instance, opts, next) => {
11+
fastify.register((instance, _opts, next) => {
1212
instance.use(require('cors')())
13-
instance.get('/express', (req, reply) => reply.send('ok'))
13+
instance.get('/express', (_req, reply) => reply.send('ok'))
1414
next()
1515
})
1616

index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ function fastifyCors (fastify, opts, next) {
5656
const corsOptions = normalizeCorsOptions(opts)
5757
validateHook(corsOptions.hook, next)
5858
if (hookWithPayload.indexOf(corsOptions.hook) !== -1) {
59-
fastify.addHook(corsOptions.hook, function handleCors (req, reply, payload, next) {
59+
fastify.addHook(corsOptions.hook, function handleCors (req, reply, _payload, next) {
6060
addCorsHeadersHandler(fastify, corsOptions, req, reply, next)
6161
})
6262
} else {
@@ -90,7 +90,7 @@ function handleCorsOptionsDelegator (optionsResolver, fastify, opts, next) {
9090
validateHook(hook, next)
9191
if (optionsResolver.length === 2) {
9292
if (hookWithPayload.indexOf(hook) !== -1) {
93-
fastify.addHook(hook, function handleCors (req, reply, payload, next) {
93+
fastify.addHook(hook, function handleCors (req, reply, _payload, next) {
9494
handleCorsOptionsCallbackDelegator(optionsResolver, fastify, req, reply, next)
9595
})
9696
} else {
@@ -101,7 +101,7 @@ function handleCorsOptionsDelegator (optionsResolver, fastify, opts, next) {
101101
} else {
102102
if (hookWithPayload.indexOf(hook) !== -1) {
103103
// handle delegator based on Promise
104-
fastify.addHook(hook, function handleCors (req, reply, payload, next) {
104+
fastify.addHook(hook, function handleCors (req, reply, _payload, next) {
105105
const ret = optionsResolver(req)
106106
if (ret && typeof ret.then === 'function') {
107107
ret.then(options => addCorsHeadersHandler(fastify, normalizeCorsOptions(options, true), req, reply, next)).catch(next)

test/cors.test.js

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ test('Should add cors headers', async t => {
1313
const fastify = Fastify()
1414
fastify.register(cors)
1515

16-
fastify.get('/', (req, reply) => {
16+
fastify.get('/', (_req, reply) => {
1717
reply.send('ok')
1818
})
1919

@@ -38,7 +38,7 @@ test('Should add cors headers when payload is a stream', async t => {
3838
fastify.register(cors)
3939
const filePath = resolve(__dirname, __filename)
4040

41-
fastify.get('/', (req, reply) => {
41+
fastify.get('/', (_req, reply) => {
4242
const stream = createReadStream(filePath)
4343
reply
4444
.type('application/json')
@@ -81,7 +81,7 @@ test('Should add cors headers (custom values)', async t => {
8181
cacheControl: 321
8282
})
8383

84-
fastify.get('/', (req, reply) => {
84+
fastify.get('/', (_req, reply) => {
8585
reply.send('ok')
8686
})
8787

@@ -181,7 +181,7 @@ test('Should support dynamic config (callback)', async t => {
181181
}
182182
await fastify.register(cors, () => configDelegation)
183183

184-
fastify.get('/', (req, reply) => {
184+
fastify.get('/', (_req, reply) => {
185185
reply.send('ok')
186186
})
187187

@@ -305,7 +305,7 @@ test('Should support dynamic config (Promise)', async t => {
305305
}
306306
await fastify.register(cors, () => configDelegation)
307307

308-
fastify.get('/', (req, reply) => {
308+
fastify.get('/', (_req, reply) => {
309309
reply.send('ok')
310310
})
311311

@@ -417,9 +417,9 @@ test('Should support dynamic config. (Invalid function)', async t => {
417417
t.plan(2)
418418

419419
const fastify = Fastify()
420-
fastify.register(cors, () => (a, b, c) => {})
420+
fastify.register(cors, () => () => {})
421421

422-
fastify.get('/', (req, reply) => {
422+
fastify.get('/', (_req, reply) => {
423423
reply.send('ok')
424424
})
425425

@@ -446,7 +446,7 @@ test('Dynamic origin resolution (valid origin)', async t => {
446446
}
447447
fastify.register(cors, { origin })
448448

449-
fastify.get('/', (req, reply) => {
449+
fastify.get('/', (_req, reply) => {
450450
reply.send('ok')
451451
})
452452

@@ -479,7 +479,7 @@ test('Dynamic origin resolution (not valid origin)', async t => {
479479
}
480480
fastify.register(cors, { origin })
481481

482-
fastify.get('/', (req, reply) => {
482+
fastify.get('/', (_req, reply) => {
483483
reply.send('ok')
484484
})
485485

@@ -548,15 +548,15 @@ test('Dynamic origin resolution (valid origin - promises)', async t => {
548548
t.plan(5)
549549

550550
const fastify = Fastify()
551-
const origin = (header, cb) => {
552-
return new Promise((resolve, reject) => {
551+
const origin = (header) => {
552+
return new Promise((resolve) => {
553553
t.assert.strictEqual(header, 'example.com')
554554
resolve(true)
555555
})
556556
}
557557
fastify.register(cors, { origin })
558558

559-
fastify.get('/', (req, reply) => {
559+
fastify.get('/', (_req, reply) => {
560560
reply.send('ok')
561561
})
562562

@@ -583,15 +583,15 @@ test('Dynamic origin resolution (not valid origin - promises)', async t => {
583583
t.plan(5)
584584

585585
const fastify = Fastify()
586-
const origin = (header, cb) => {
587-
return new Promise((resolve, reject) => {
586+
const origin = (header) => {
587+
return new Promise((resolve) => {
588588
t.assert.strictEqual(header, 'example.com')
589589
resolve(false)
590590
})
591591
}
592592
fastify.register(cors, { origin })
593593

594-
fastify.get('/', (req, reply) => {
594+
fastify.get('/', (_req, reply) => {
595595
reply.send('ok')
596596
})
597597

@@ -622,8 +622,8 @@ test('Dynamic origin resolution (errored - promises)', async t => {
622622
t.plan(3)
623623

624624
const fastify = Fastify()
625-
const origin = (header, cb) => {
626-
return new Promise((resolve, reject) => {
625+
const origin = (header) => {
626+
return new Promise((_resolve, reject) => {
627627
t.assert.strictEqual(header, 'example.com')
628628
reject(new Error('ouch'))
629629
})
@@ -652,7 +652,7 @@ test('Should reply 404 without cors headers when origin is false', async t => {
652652
maxAge: 123
653653
})
654654

655-
fastify.get('/', (req, reply) => {
655+
fastify.get('/', (_req, reply) => {
656656
reply.send('ok')
657657
})
658658

@@ -723,7 +723,7 @@ test('Allow only request from a specific origin', async t => {
723723
const fastify = Fastify()
724724
fastify.register(cors, { origin: 'other.io' })
725725

726-
fastify.get('/', (req, reply) => {
726+
fastify.get('/', (_req, reply) => {
727727
reply.send('ok')
728728
})
729729

@@ -748,7 +748,7 @@ test('Allow only request from multiple specific origin', async t => {
748748
const fastify = Fastify()
749749
fastify.register(cors, { origin: ['other.io', 'example.com'] })
750750

751-
fastify.get('/', (req, reply) => {
751+
fastify.get('/', (_req, reply) => {
752752
reply.send('ok')
753753
})
754754

@@ -791,7 +791,7 @@ test('Allow only request from a specific origin using regex', async t => {
791791
const fastify = Fastify()
792792
fastify.register(cors, { origin: /(?:example|other)\.com/giu })
793793

794-
fastify.get('/', (req, reply) => {
794+
fastify.get('/', (_req, reply) => {
795795
reply.send('ok')
796796
})
797797

@@ -825,7 +825,7 @@ test('Disable preflight', async t => {
825825
const fastify = Fastify()
826826
fastify.register(cors, { preflight: false })
827827

828-
fastify.get('/', (req, reply) => {
828+
fastify.get('/', (_req, reply) => {
829829
reply.send('ok')
830830
})
831831

@@ -859,7 +859,7 @@ test('Should always add vary header to `Origin` for reflected origin', async t =
859859
const fastify = Fastify()
860860
fastify.register(cors, { origin: true })
861861

862-
fastify.get('/', (req, reply) => {
862+
fastify.get('/', (_req, reply) => {
863863
reply.send('ok')
864864
})
865865

@@ -913,11 +913,11 @@ test('Should always add vary header to `Origin` for reflected origin (vary is ar
913913
const fastify = Fastify()
914914

915915
// Mock getHeader function
916-
fastify.decorateReply('getHeader', (name) => ['foo', 'bar'])
916+
fastify.decorateReply('getHeader', () => ['foo', 'bar'])
917917

918918
fastify.register(cors, { origin: true })
919919

920-
fastify.get('/', (req, reply) => {
920+
fastify.get('/', (_req, reply) => {
921921
reply.send('ok')
922922
})
923923

@@ -943,7 +943,7 @@ test('Allow only request from with specific headers', async t => {
943943
exposedHeaders: 'bar'
944944
})
945945

946-
fastify.get('/', (req, reply) => {
946+
fastify.get('/', (_req, reply) => {
947947
reply.send('ok')
948948
})
949949

@@ -982,7 +982,7 @@ test('Should support wildcard config /1', async t => {
982982
const fastify = Fastify()
983983
fastify.register(cors, { origin: '*' })
984984

985-
fastify.get('/', (req, reply) => {
985+
fastify.get('/', (_req, reply) => {
986986
reply.send('ok')
987987
})
988988

@@ -1002,7 +1002,7 @@ test('Should support wildcard config /2', async t => {
10021002
const fastify = Fastify()
10031003
fastify.register(cors, { origin: ['*'] })
10041004

1005-
fastify.get('/', (req, reply) => {
1005+
fastify.get('/', (_req, reply) => {
10061006
reply.send('ok')
10071007
})
10081008

0 commit comments

Comments
 (0)