Skip to content

Commit

Permalink
refactor: prefix unused params with underscores (#179)
Browse files Browse the repository at this point in the history
  • Loading branch information
Fdawgs authored Jan 5, 2025
1 parent 7d38e59 commit 2363384
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 15 deletions.
6 changes: 3 additions & 3 deletions examples/example.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ fastify.post(
{
preHandler: fastify.csrfProtection
},
async (req, reply) => {
async (req) => {
return req.body
}
)
Expand All @@ -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')

Expand Down Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -132,7 +132,7 @@ function getTokenDefault (req) {
req.headers['x-xsrf-token']
}

function getUserInfoDefault (req) {
function getUserInfoDefault (_req) {
return undefined
}

Expand Down
8 changes: 4 additions & 4 deletions test/basic.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
})
Expand Down Expand Up @@ -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
})

Expand Down Expand Up @@ -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 }
})
Expand Down
6 changes: 3 additions & 3 deletions test/user-info.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
})

Expand Down Expand Up @@ -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
})

Expand Down Expand Up @@ -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
})

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 @@ -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<string>(token)
return token
Expand All @@ -30,7 +30,7 @@ async function run () {
method: 'POST',
url: '/',
onRequest: fastify.csrfProtection,
handler: async (req, reply) => {
handler: async (req) => {
return req.body
}
})
Expand Down

0 comments on commit 2363384

Please sign in to comment.