diff --git a/index.js b/index.js index 84ee6b1..29e6949 100644 --- a/index.js +++ b/index.js @@ -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 @@ -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) }) diff --git a/test/internal/appInitializer.js b/test/internal/appInitializer.js index 1cc60c4..b7db375 100644 --- a/test/internal/appInitializer.js +++ b/test/internal/appInitializer.js @@ -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() @@ -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, { diff --git a/types/index.test-d.ts b/types/index.test-d.ts index d0f88e1..c9bfbd0 100644 --- a/types/index.test-d.ts +++ b/types/index.test-d.ts @@ -56,8 +56,8 @@ expectAssignable((req) => ({ log: req.log.child({ childLog: true }), })) -expectError((req) => ({ bar: 'dummy' })) -expectError((req) => ({ log: 'dummy' })) +expectError(() => ({ bar: 'dummy' })) +expectError(() => ({ log: 'dummy' })) expectType(app.requestContext) expectType(requestContext)