Skip to content

Commit 5ad5a09

Browse files
authored
refactor: prefix unused params with underscores (#162)
1 parent 8bcd94b commit 5ad5a09

File tree

4 files changed

+36
-36
lines changed

4 files changed

+36
-36
lines changed

index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ function cachingLoadByEtag (req, res, next) {
3838
})
3939
}
4040

41-
function cachingStoreByEtag (req, res, payload, next) {
41+
function cachingStoreByEtag (_req, res, payload, next) {
4242
const etag = res.getHeader('etag')
4343
if (!etag || !res._etagLife) return next()
4444
this.cache.set(
@@ -70,7 +70,7 @@ function fastifyCaching (instance, options, next) {
7070
value += `, s-maxage=${_options.serverExpiresIn}`
7171
}
7272

73-
instance.addHook('onRequest', function cachingSetCacheControlHeader (req, res, next) {
73+
instance.addHook('onRequest', function cachingSetCacheControlHeader (_req, res, next) {
7474
if (!res.hasHeader('Cache-control')) {
7575
res.header('Cache-control', value)
7676
}

test/cache.test.js

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,25 +21,25 @@ test('cache is usable', async (t) => {
2121
t.plan(4)
2222

2323
const fastify = Fastify()
24-
await fastify.register(async (instance, options) => {
25-
instance.addHook('onRequest', async function checkCachingRegistered (req, reply) {
24+
await fastify.register(async (instance) => {
25+
instance.addHook('onRequest', async function checkCachingRegistered () {
2626
t.assert.ifError(instance[Symbol.for('fastify-caching.registered')])
2727
})
2828
})
2929
await fastify.register(plugin)
3030

31-
fastify.addHook('onRequest', async function checkCachingRegistered (req, reply) {
31+
fastify.addHook('onRequest', async function checkCachingRegistered () {
3232
t.assert.strictEqual(this[Symbol.for('fastify-caching.registered')], true)
3333
})
3434

35-
fastify.get('/one', (req, reply) => {
35+
fastify.get('/one', (_req, reply) => {
3636
fastify.cache.set('one', { one: true }, 1000, (err) => {
3737
if (err) return reply.send(err)
3838
reply.redirect('/two')
3939
})
4040
})
4141

42-
fastify.get('/two', (req, reply) => {
42+
fastify.get('/two', (_req, reply) => {
4343
fastify.cache.get('one', (err, obj) => {
4444
t.assert.ifError(err)
4545
t.assert.strictEqual(obj.item, { one: true })
@@ -70,25 +70,25 @@ test('cache is usable with function as plugin default options input', async (t)
7070
t.plan(4)
7171

7272
const fastify = Fastify()
73-
await fastify.register(async (instance, options) => {
74-
instance.addHook('onRequest', async function checkCachingNotRegistered (req, reply) {
73+
await fastify.register(async (instance) => {
74+
instance.addHook('onRequest', async function checkCachingNotRegistered () {
7575
t.assert.failure(instance[Symbol.for('fastify-caching.registered')])
7676
})
7777
})
7878
await fastify.register(plugin, () => () => {})
7979

80-
fastify.addHook('onRequest', async function checkCachingRegistered (req, reply) {
80+
fastify.addHook('onRequest', async function checkCachingRegistered () {
8181
t.assert.strictEqual(this[Symbol.for('fastify-caching.registered')], true)
8282
})
8383

84-
fastify.get('/one', (req, reply) => {
84+
fastify.get('/one', (_req, reply) => {
8585
fastify.cache.set('one', { one: true }, 1000, (err) => {
8686
if (err) return reply.send(err)
8787
reply.redirect('/two')
8888
})
8989
})
9090

91-
fastify.get('/two', (req, reply) => {
91+
fastify.get('/two', (_req, reply) => {
9292
fastify.cache.get('one', (err, obj) => {
9393
t.assert.ifError(err)
9494
t.assert.strictEqual(obj.item, { one: true })
@@ -120,21 +120,21 @@ test('getting cache item with error returns error', async (t) => {
120120
t.plan(1)
121121

122122
const mockCache = {
123-
get: (info, callback) => callback(new Error('cache.get always errors')),
124-
set: (key, value, ttl, callback) => callback()
123+
get: (_info, callback) => callback(new Error('cache.get always errors')),
124+
set: (_key, _value, _ttl, callback) => callback()
125125
}
126126

127127
const fastify = Fastify()
128128
await fastify.register(plugin, { cache: mockCache })
129129

130-
fastify.get('/one', (req, reply) => {
130+
fastify.get('/one', (_req, reply) => {
131131
fastify.cache.set('one', { one: true }, 1000, (err) => {
132132
if (err) return reply.send(err)
133133
return reply.etag('123456').send({ hello: 'world' })
134134
})
135135
})
136136

137-
fastify.get('/two', (req, reply) => {
137+
fastify.get('/two', () => {
138138
fastify.cache.get('one', (err, obj) => {
139139
t.assert.failure(err)
140140
t.assert.failure(obj)
@@ -164,7 +164,7 @@ test('etags get stored in cache', async (t) => {
164164
const fastify = Fastify()
165165
await fastify.register(plugin)
166166

167-
fastify.get('/one', (req, reply) => {
167+
fastify.get('/one', (_req, reply) => {
168168
reply.etag('123456').send({ hello: 'world' })
169169
})
170170

@@ -191,7 +191,7 @@ test('etag cache life is customizable', async (t) => {
191191
const fastify = Fastify()
192192
await fastify.register(plugin)
193193

194-
fastify.get('/one', function (req, reply) {
194+
fastify.get('/one', function (_req, reply) {
195195
reply
196196
// We set a cache lifetime of 50 milliseconds
197197
.etag('123456', 50)
@@ -237,7 +237,7 @@ test('returns response payload', async (t) => {
237237
const fastify = Fastify()
238238
await fastify.register(plugin)
239239

240-
fastify.get('/one', (req, reply) => {
240+
fastify.get('/one', (_req, reply) => {
241241
reply.etag('123456', 300).send({ hello: 'world' })
242242
})
243243

test/headers.test.js

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ test('decorators get added', async (t) => {
1010
const fastify = Fastify()
1111
await fastify.register(plugin)
1212

13-
fastify.get('/', (req, reply) => {
13+
fastify.get('/', (_req, reply) => {
1414
t.assert.ok(reply.etag)
1515
reply.send()
1616
})
@@ -31,7 +31,7 @@ test('decorators add headers', async (t) => {
3131
const fastify = Fastify()
3232
await fastify.register(plugin)
3333

34-
fastify.get('/', (req, reply) => {
34+
fastify.get('/', (_req, reply) => {
3535
reply.etag(tag).send()
3636
})
3737

@@ -51,7 +51,7 @@ test('sets etag header for falsy argument', async (t) => {
5151
const fastify = Fastify()
5252
await fastify.register(plugin)
5353

54-
fastify.get('/', (req, reply) => {
54+
fastify.get('/', (_req, reply) => {
5555
reply.etag().send()
5656
})
5757

@@ -70,7 +70,7 @@ test('sets no-cache header', async (t) => {
7070
const fastify = Fastify()
7171
await fastify.register(plugin, { privacy: plugin.privacy.NOCACHE })
7272

73-
fastify.get('/', (req, reply) => {
73+
fastify.get('/', (_req, reply) => {
7474
reply.send({ hello: 'world' })
7575
})
7676

@@ -95,7 +95,7 @@ test('sets private with max-age header', async (t) => {
9595
const fastify = Fastify()
9696
await fastify.register(plugin, opts)
9797

98-
fastify.get('/', (req, reply) => {
98+
fastify.get('/', (_req, reply) => {
9999
reply.send({ hello: 'world' })
100100
})
101101

@@ -124,7 +124,7 @@ test('sets public with max-age and s-maxage header', async (t) => {
124124
const fastify = Fastify()
125125
await fastify.register(plugin, opts)
126126

127-
fastify.get('/', (req, reply) => {
127+
fastify.get('/', (_req, reply) => {
128128
reply.send({ hello: 'world' })
129129
})
130130

@@ -151,12 +151,12 @@ test('do not set headers if another upstream plugin already sets it', async (t)
151151
}
152152

153153
const fastify = Fastify()
154-
fastify.addHook('onRequest', async function checkCachingDoesNotOverrideCacheControlHeader (req, reply) {
154+
fastify.addHook('onRequest', async function checkCachingDoesNotOverrideCacheControlHeader (_req, reply) {
155155
reply.header('cache-control', 'do not override')
156156
})
157157
await fastify.register(plugin, opts)
158158

159-
fastify.get('/', (req, reply) => {
159+
fastify.get('/', (_req, reply) => {
160160
reply.send({ hello: 'world' })
161161
})
162162

@@ -182,7 +182,7 @@ test('only sets max-age and ignores s-maxage with private header', async (t) =>
182182
const fastify = Fastify()
183183
await fastify.register(plugin, opts)
184184

185-
fastify.get('/', (req, reply) => {
185+
fastify.get('/', (_req, reply) => {
186186
reply.send({ hello: 'world' })
187187
})
188188

@@ -210,7 +210,7 @@ test('s-maxage is optional with public header', async (t) => {
210210
const fastify = Fastify()
211211
await fastify.register(plugin, opts)
212212

213-
fastify.get('/', (req, reply) => {
213+
fastify.get('/', (_req, reply) => {
214214
reply.send({ hello: 'world' })
215215
})
216216

@@ -230,7 +230,7 @@ test('sets no-store with max-age header', async (t) => {
230230
const fastify = Fastify()
231231
await fastify.register(plugin, { privacy: 'no-store', expiresIn: 300 })
232232

233-
fastify.get('/', (req, reply) => {
233+
fastify.get('/', (_req, reply) => {
234234
reply.send({ hello: 'world' })
235235
})
236236

@@ -255,7 +255,7 @@ test('sets the expires header', async (t) => {
255255
const fastify = Fastify()
256256
await fastify.register(plugin, { privacy: plugin.privacy.NOCACHE })
257257

258-
fastify.get('/', (req, reply) => {
258+
fastify.get('/', (_req, reply) => {
259259
reply.expires(now).send({ hello: 'world' })
260260
})
261261

@@ -275,7 +275,7 @@ test('sets the expires header to a falsy value', async (t) => {
275275
const fastify = Fastify()
276276
await fastify.register(plugin, { privacy: plugin.privacy.NOCACHE })
277277

278-
fastify.get('/', (req, reply) => {
278+
fastify.get('/', (_req, reply) => {
279279
reply.expires().send({ hello: 'world' })
280280
})
281281

@@ -294,7 +294,7 @@ test('sets the expires header to a custom value', async (t) => {
294294
const fastify = Fastify()
295295
await fastify.register(plugin, { privacy: plugin.privacy.NOCACHE })
296296

297-
fastify.get('/', (req, reply) => {
297+
fastify.get('/', (_req, reply) => {
298298
reply.expires('foobar').send({ hello: 'world' })
299299
})
300300

types/index.test-d.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ expectType<AbstractCacheCompliantObject['set']>(fastify.cache.set)
2222
expectType<string>(fastify.cacheSegment)
2323
// expectType<number>(fastify.etagMaxLife);
2424

25-
fastify.get('/one', async (request, reply) => {
25+
fastify.get('/one', async (_request, reply) => {
2626
expectType<(tag?: string, timeToLive?: number) => FastifyReply>(reply.etag)
2727
expectType<(date?: Date) => FastifyReply>(reply.expires)
2828

@@ -32,7 +32,7 @@ fastify.get('/one', async (request, reply) => {
3232
return { message: 'one' }
3333
})
3434

35-
fastify.get('/two', async (request, reply) => {
35+
fastify.get('/two', async (_request, reply) => {
3636
expectType<FastifyReply>(
3737
reply.etag('hello', 6000).expires(new Date(Date.now() + 6000))
3838
)
@@ -51,7 +51,7 @@ const badCachingOptions = {
5151

5252
expectError(shouldErrorApp.register(fastifyCaching, badCachingOptions))
5353

54-
fastify.get('/three', async (request, reply) => {
54+
fastify.get('/three', async () => {
5555
expectAssignable<Promise<unknown>>(
5656
fastify.cache.get('well-known')
5757
)

0 commit comments

Comments
 (0)