Skip to content

Commit

Permalink
test: prefix unused params with underscores (#184)
Browse files Browse the repository at this point in the history
  • Loading branch information
Fdawgs authored Jan 4, 2025
1 parent 236bccb commit d6a5fcd
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 32 deletions.
22 changes: 11 additions & 11 deletions test/cache-control.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ test('reply.cacheControl API', t => {
const fastify = Fastify()
fastify.register(Sensible)

fastify.get('/', (req, reply) => {
fastify.get('/', (_req, reply) => {
reply.cacheControl('public')
reply.send('ok')
})
Expand All @@ -32,7 +32,7 @@ test('reply.cacheControl API (multiple values)', t => {
const fastify = Fastify()
fastify.register(Sensible)

fastify.get('/', (req, reply) => {
fastify.get('/', (_req, reply) => {
reply
.cacheControl('public')
.cacheControl('max-age', 604800)
Expand All @@ -57,7 +57,7 @@ test('reply.preventCache API', t => {
const fastify = Fastify()
fastify.register(Sensible)

fastify.get('/', (req, reply) => {
fastify.get('/', (_req, reply) => {
reply.preventCache().send('ok')
})

Expand All @@ -80,7 +80,7 @@ test('reply.stale API', t => {
const fastify = Fastify()
fastify.register(Sensible)

fastify.get('/', (req, reply) => {
fastify.get('/', (_req, reply) => {
reply.stale('while-revalidate', 42).send('ok')
})

Expand All @@ -101,7 +101,7 @@ test('reply.stale API (multiple values)', t => {
const fastify = Fastify()
fastify.register(Sensible)

fastify.get('/', (req, reply) => {
fastify.get('/', (_req, reply) => {
reply
.stale('while-revalidate', 42)
.stale('if-error', 1)
Expand All @@ -125,7 +125,7 @@ test('reply.stale API (bad value)', t => {
const fastify = Fastify()
fastify.register(Sensible)

fastify.get('/', (req, reply) => {
fastify.get('/', (_req, reply) => {
try {
reply.stale('foo', 42).send('ok')
t.fail('Should throw')
Expand All @@ -152,7 +152,7 @@ test('reply.revalidate API', t => {
const fastify = Fastify()
fastify.register(Sensible)

fastify.get('/', (req, reply) => {
fastify.get('/', (_req, reply) => {
reply.revalidate().send('ok')
})

Expand All @@ -173,7 +173,7 @@ test('reply.staticCache API', t => {
const fastify = Fastify()
fastify.register(Sensible)

fastify.get('/', (req, reply) => {
fastify.get('/', (_req, reply) => {
reply.staticCache(42).send('ok')
})

Expand All @@ -194,7 +194,7 @@ test('reply.staticCache API (as string)', t => {
const fastify = Fastify()
fastify.register(Sensible)

fastify.get('/', (req, reply) => {
fastify.get('/', (_req, reply) => {
reply.staticCache('42s').send('ok')
})

Expand All @@ -215,7 +215,7 @@ test('reply.maxAge and reply.stale API', t => {
const fastify = Fastify()
fastify.register(Sensible)

fastify.get('/', (req, reply) => {
fastify.get('/', (_req, reply) => {
reply
.maxAge(42)
.stale('while-revalidate', 3)
Expand All @@ -239,7 +239,7 @@ test('reply.cacheControl API (string time)', t => {
const fastify = Fastify()
fastify.register(Sensible)

fastify.get('/', (req, reply) => {
fastify.get('/', (_req, reply) => {
reply.cacheControl('max-age', '1d')
reply.send('ok')
})
Expand Down
6 changes: 3 additions & 3 deletions test/httpErrorsReply.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ test('Should generate the correct http error', t => {
const fastify = Fastify()
fastify.register(Sensible)

fastify.get('/', (req, reply) => {
fastify.get('/', (_req, reply) => {
const name = normalize(code, statusCodes[code])
t.equal(reply[name](), reply)
})
Expand Down Expand Up @@ -51,7 +51,7 @@ test('Should generate the correct http error using getter', t => {
const fastify = Fastify()
fastify.register(Sensible)

fastify.get('/', (req, reply) => {
fastify.get('/', (_req, reply) => {
t.equal(reply.getHttpError(code), reply)
})

Expand Down Expand Up @@ -80,7 +80,7 @@ test('Should generate the correct http error (with custom message)', t => {
const fastify = Fastify()
fastify.register(Sensible)

fastify.get('/', (req, reply) => {
fastify.get('/', (_req, reply) => {
const name = normalize(code, statusCodes[code])
reply[name]('custom')
})
Expand Down
2 changes: 1 addition & 1 deletion test/schema.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ test('Should add shared schema', t => {
400: { $ref: 'myError' }
}
},
handler: (req, reply) => {
handler: (_req, reply) => {
reply.badRequest()
}
})
Expand Down
6 changes: 3 additions & 3 deletions test/vary.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ test('reply.vary API', t => {
const fastify = Fastify()
fastify.register(Sensible)

fastify.get('/', (req, reply) => {
fastify.get('/', (_req, reply) => {
reply.vary('Accept')
reply.vary('Origin')
reply.vary('User-Agent')
Expand All @@ -37,7 +37,7 @@ test('reply.vary API', t => {
const fastify = Fastify()
fastify.register(Sensible)

fastify.get('/', (req, reply) => {
fastify.get('/', (_req, reply) => {
reply.header('Vary', ['Accept', 'Origin'])
reply.vary('User-Agent')
reply.send('ok')
Expand All @@ -61,7 +61,7 @@ test('reply.vary.append API', t => {
const fastify = Fastify()
fastify.register(Sensible)

fastify.get('/', (req, reply) => {
fastify.get('/', (_req, reply) => {
t.equal(
reply.vary.append('', ['Accept', 'Accept-Language']), 'Accept, Accept-Language'
)
Expand Down
28 changes: 14 additions & 14 deletions types/index.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ expectAssignable<FastifySensibleOptions>({})
expectAssignable<FastifySensibleOptions>({ sharedSchemaId: 'HttpError' })
expectNotAssignable<FastifySensibleOptions>({ notSharedSchemaId: 'HttpError' })

app.get('/', (req, reply) => {
app.get('/', (_req, reply) => {
expectAssignable<typeof reply>(reply.badRequest())
expectAssignable<typeof reply>(reply.unauthorized())
expectAssignable<typeof reply>(reply.paymentRequired())
Expand Down Expand Up @@ -52,22 +52,22 @@ app.get('/', (req, reply) => {
expectAssignable<typeof reply>(reply.networkAuthenticationRequired())
})

app.get('/', (req, reply) => {
app.get('/', (_req, reply) => {
expectAssignable<typeof reply>(reply.getHttpError(405, 'Method Not Allowed'))
})

app.get('/', (req, reply) => {
app.get('/', () => {
expectAssignable<HttpError>(app.httpErrors.createError(405, 'Method Not Allowed'))
})

app.get('/', (req, reply) => {
app.get('/', () => {
expectAssignable<HttpError>(
app.httpErrors.createError(405, 'Method Not Allowed')
)
expectAssignable<HttpError>(app.httpErrors.badRequest())
})

app.get('/', async (req, reply) => {
app.get('/', async () => {
expectAssignable<HttpError>(app.httpErrors.badRequest())
expectAssignable<HttpError>(app.httpErrors.unauthorized())
expectAssignable<HttpError>(app.httpErrors.paymentRequired())
Expand Down Expand Up @@ -109,7 +109,7 @@ app.get('/', async (req, reply) => {
expectAssignable<HttpError>(app.httpErrors.networkAuthenticationRequired())
})

app.get('/', async (req, reply) => {
app.get('/', async () => {
expectType<void>(app.assert(1))
expectType<void>(app.assert.ok(true))
expectType<void>(app.assert.equal(1, 1))
Expand All @@ -120,38 +120,38 @@ app.get('/', async (req, reply) => {
expectType<void>(app.assert.notDeepEqual({}, { a: 1 }))
})

app.get('/', async (req, reply) => {
app.get('/', async () => {
expectType<Promise<[Error, void]>>(app.to<void>(new Promise(resolve => resolve())))
})

app.get('/', (req, reply) => {
app.get('/', (_req, reply) => {
expectAssignable<typeof reply>(reply.cacheControl('public'))
})

app.get('/', (req, reply) => {
app.get('/', (_req, reply) => {
expectAssignable<typeof reply>(reply.preventCache())
})

app.get('/', (req, reply) => {
app.get('/', (_req, reply) => {
expectAssignable<typeof reply>(reply.cacheControl('max-age', 42))
})

app.get('/', (req, reply) => {
app.get('/', (_req, reply) => {
expectError(reply.cacheControl('foobar'))
})

app.get('/', (req, reply) => {
app.get('/', (_req, reply) => {
expectAssignable<typeof reply>(reply.stale('while-revalidate', 42))
})

app.get('/', async (req, reply) => {
app.get('/', async (_req, reply) => {
expectType<void>(reply.vary('test'))
expectType<void>(reply.vary(['test']))
expectType<string>(reply.vary.append('X-Header', 'field1'))
expectType<string>(reply.vary.append('X-Header', ['field1']))
})

app.get('/', async (req, reply) => {
app.get('/', async (req) => {
expectType<string[]>(req.forwarded())
expectType<string | false | null>(req.is(['foo', 'bar']))
expectType<string | false | null>(req.is('foo', 'bar'))
Expand Down

0 comments on commit d6a5fcd

Please sign in to comment.