From 236338460f6129351260f217aac93a4bd705ac98 Mon Sep 17 00:00:00 2001 From: Frazer Smith Date: Sun, 5 Jan 2025 11:06:26 +0000 Subject: [PATCH] refactor: prefix unused params with underscores (#179) --- examples/example.mjs | 6 +++--- index.js | 6 +++--- test/basic.test.js | 8 ++++---- test/user-info.test.js | 6 +++--- types/index.test-d.ts | 4 ++-- 5 files changed, 15 insertions(+), 15 deletions(-) diff --git a/examples/example.mjs b/examples/example.mjs index f7a49d6..885494b 100644 --- a/examples/example.mjs +++ b/examples/example.mjs @@ -14,7 +14,7 @@ fastify.post( { preHandler: fastify.csrfProtection }, - async (req, reply) => { + async (req) => { return req.body } ) @@ -23,7 +23,7 @@ fastify.post( fastify.route({ method: 'GET', url: '/', - handler: async (req, reply) => { + handler: async (_req, reply) => { const token = reply.generateCsrf() reply.type('text/html') @@ -57,7 +57,7 @@ fastify.route({ }) // Run the server! -fastify.listen({ port: 3001 }, function (err, address) { +fastify.listen({ port: 3001 }, function (err) { if (err) { fastify.log.error(err) process.exit(1) diff --git a/index.js b/index.js index e5d808a..e32329b 100644 --- a/index.js +++ b/index.js @@ -64,9 +64,9 @@ async function fastifyCsrfProtection (fastify, opts) { let getSecret if (sessionPlugin === '@fastify/secure-session') { - getSecret = function getSecret (req, reply) { return req.session.get(sessionKey) } + getSecret = function getSecret (req, _reply) { return req.session.get(sessionKey) } } else if (sessionPlugin === '@fastify/session') { - getSecret = function getSecret (req, reply) { return req.session[sessionKey] } + getSecret = function getSecret (req, _reply) { return req.session[sessionKey] } } else { getSecret = function getSecret (req, reply) { return isCookieSigned @@ -132,7 +132,7 @@ function getTokenDefault (req) { req.headers['x-xsrf-token'] } -function getUserInfoDefault (req) { +function getUserInfoDefault (_req) { return undefined } diff --git a/test/basic.test.js b/test/basic.test.js index cb122d8..ad75742 100644 --- a/test/basic.test.js +++ b/test/basic.test.js @@ -31,7 +31,7 @@ test('Cookies', async t => { await t.test('Default cookie options', async t => { const fastify = await load() - fastify.get('/', async (req, reply) => { + fastify.get('/', async (_req, reply) => { const token = reply.generateCsrf() return { token } }) @@ -181,12 +181,12 @@ async function runtTest (t, load, tkn, hook = 'onRequest') { await t.test(`Token in ${tkn.place}`, async t => { const fastify = await load() - fastify.get('/', async (req, reply) => { + fastify.get('/', async (_req, reply) => { const token = reply.generateCsrf() return { token } }) - fastify.post('/', { [hook]: fastify.csrfProtection }, async (req, reply) => { + fastify.post('/', { [hook]: fastify.csrfProtection }, async (req) => { return req.body }) @@ -276,7 +276,7 @@ async function runCookieOpts (t, load) { await t.test('Custom cookie options', async t => { const fastify = await load() - fastify.get('/', async (req, reply) => { + fastify.get('/', async (_req, reply) => { const token = reply.generateCsrf({ path: '/hello' }) return { token } }) diff --git a/test/user-info.test.js b/test/user-info.test.js index 3d4fcef..4d393ce 100644 --- a/test/user-info.test.js +++ b/test/user-info.test.js @@ -33,7 +33,7 @@ test('Cookies with User-Info', async t => { }) // must be preHandler as we are parsing the body - fastify.post('/', { preHandler: fastify.csrfProtection }, async (req, reply) => { + fastify.post('/', { preHandler: fastify.csrfProtection }, async (req) => { return req.body }) @@ -89,7 +89,7 @@ test('Session with User-Info', async t => { }) // must be preHandler as we are parsing the body - fastify.post('/', { preHandler: fastify.csrfProtection }, async (req, reply) => { + fastify.post('/', { preHandler: fastify.csrfProtection }, async (req) => { return req.body }) @@ -141,7 +141,7 @@ test('SecureSession with User-Info', async t => { }) // must be preHandler as we are parsing the body - fastify.post('/', { preHandler: fastify.csrfProtection }, async (req, reply) => { + fastify.post('/', { preHandler: fastify.csrfProtection }, async (req) => { return req.body }) diff --git a/types/index.test-d.ts b/types/index.test-d.ts index 48490eb..6f5e50f 100644 --- a/types/index.test-d.ts +++ b/types/index.test-d.ts @@ -19,7 +19,7 @@ async function run () { fastify.route({ method: 'GET', url: '/', - handler: async (req, reply) => { + handler: async (_req, reply) => { const token = reply.generateCsrf() expectType(token) return token @@ -30,7 +30,7 @@ async function run () { method: 'POST', url: '/', onRequest: fastify.csrfProtection, - handler: async (req, reply) => { + handler: async (req) => { return req.body } })