Skip to content

Commit

Permalink
refactor: prefix unused params with underscores (#206)
Browse files Browse the repository at this point in the history
  • Loading branch information
Fdawgs authored Jan 6, 2025
1 parent 2844e6a commit fbc99b4
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ function fastifyRequestContext(fastify, opts, next) {
const hook = opts.hook || 'onRequest'
const hasDefaultStoreValuesFactory = typeof opts.defaultStoreValues === 'function'

fastify.addHook(hook, (req, res, done) => {
fastify.addHook(hook, (req, _res, done) => {
const defaultStoreValues = hasDefaultStoreValuesFactory
? opts.defaultStoreValues(req)
: opts.defaultStoreValues
Expand All @@ -48,7 +48,7 @@ function fastifyRequestContext(fastify, opts, next) {
// in a different async context, as req/res may emit events in a different context.
// Related to https://github.com/nodejs/node/issues/34430 and https://github.com/nodejs/node/issues/33723
if (hook === 'onRequest' || hook === 'preParsing') {
fastify.addHook('preValidation', (req, res, done) => {
fastify.addHook('preValidation', (req, _res, done) => {
const asyncResource = req[asyncResourceSymbol]
asyncResource.runInAsyncScope(done, req.raw)
})
Expand Down
12 changes: 6 additions & 6 deletions test/internal/appInitializer.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ function initAppPostWithPrevalidation(endpoint) {
const app = fastify({ logger: true })
app.register(fastifyRequestContext, { hook: 'preValidation' })

const preValidationFn = (req, reply, done) => {
const preValidationFn = (req, _reply, done) => {
const requestId = Number.parseInt(req.body.requestId)
req.requestContext.set('testKey', `testValue${requestId}`)
done()
Expand All @@ -44,30 +44,30 @@ function initAppPostWithAllPlugins(endpoint, requestHook) {
const app = fastify({ logger: true })
app.register(fastifyRequestContext, { hook: requestHook })

app.addHook('onRequest', (req, reply, done) => {
app.addHook('onRequest', (req, _reply, done) => {
req.requestContext.set('onRequest', 'dummy')
done()
})

app.addHook('preParsing', (req, reply, payload, done) => {
app.addHook('preParsing', (req, _reply, payload, done) => {
req.requestContext.set('preParsing', 'dummy')
done(null, payload)
})

app.addHook('preValidation', (req, reply, done) => {
app.addHook('preValidation', (req, _reply, done) => {
const requestId = Number.parseInt(req.body.requestId)
req.requestContext.set('preValidation', requestId)
req.requestContext.set('testKey', `testValue${requestId}`)
done()
})

app.addHook('preHandler', (req, reply, done) => {
app.addHook('preHandler', (req, _reply, done) => {
const requestId = Number.parseInt(req.body.requestId)
req.requestContext.set('preHandler', requestId)
done()
})

app.addHook('preSerialization', (req, reply, payload, done) => {
app.addHook('preSerialization', (req, _reply, payload, done) => {
const onRequestValue = req.requestContext.get('onRequest')
const preValidationValue = req.requestContext.get('preValidation')
done(null, {
Expand Down
4 changes: 2 additions & 2 deletions types/index.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ expectAssignable<RequestContextDataFactory>((req) => ({
log: req.log.child({ childLog: true }),
}))

expectError<RequestContextDataFactory>((req) => ({ bar: 'dummy' }))
expectError<RequestContextDataFactory>((req) => ({ log: 'dummy' }))
expectError<RequestContextDataFactory>(() => ({ bar: 'dummy' }))
expectError<RequestContextDataFactory>(() => ({ log: 'dummy' }))

expectType<RequestContext>(app.requestContext)
expectType<RequestContext>(requestContext)
Expand Down

0 comments on commit fbc99b4

Please sign in to comment.