Skip to content

Commit

Permalink
test: prefix unused params with underscores (#277)
Browse files Browse the repository at this point in the history
  • Loading branch information
Fdawgs authored Jan 3, 2025
1 parent 8c04dca commit 7d46361
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 53 deletions.
4 changes: 2 additions & 2 deletions examples/example.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ const opts = {
}
}

fastify.get('/', opts, function (request, reply) {
fastify.get('/', opts, function (_request, reply) {
reply
.header('Content-Type', 'application/json')
.code(200)
.send({ hello: 'world' })
})

fastify.get('/route-with-disabled-helmet', { ...opts, helmet: false }, function (request, reply) {
fastify.get('/route-with-disabled-helmet', { ...opts, helmet: false }, function (_request, reply) {
reply
.header('Content-Type', 'application/json')
.code(200)
Expand Down
62 changes: 31 additions & 31 deletions test/global.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ test('It should set the default headers', async (t) => {
const fastify = Fastify()
await fastify.register(helmet)

fastify.get('/', (request, reply) => {
fastify.get('/', (_request, reply) => {
reply.send({ hello: 'world' })
})

Expand Down Expand Up @@ -46,7 +46,7 @@ test('It should not set the default headers when global is set to `false`', asyn
const fastify = Fastify()
await fastify.register(helmet, { global: false })

fastify.get('/', (request, reply) => {
fastify.get('/', (_request, reply) => {
reply.send({ hello: 'world' })
})

Expand Down Expand Up @@ -80,7 +80,7 @@ test('It should set the default cross-domain-policy', async (t) => {
const fastify = Fastify()
await fastify.register(helmet)

fastify.get('/', (request, reply) => {
fastify.get('/', (_request, reply) => {
reply.send({ hello: 'world' })
})

Expand All @@ -106,7 +106,7 @@ test('It should be able to set cross-domain-policy', async (t) => {
permittedCrossDomainPolicies: { permittedPolicies: 'by-content-type' }
})

fastify.get('/', (request, reply) => {
fastify.get('/', (_request, reply) => {
reply.send({ hello: 'world' })
})

Expand All @@ -131,7 +131,7 @@ test('It should not disable the other headers when disabling one header', async
const fastify = Fastify()
await fastify.register(helmet, { frameguard: false })

fastify.get('/', (request, reply) => {
fastify.get('/', (_request, reply) => {
reply.send({ hello: 'world' })
})

Expand Down Expand Up @@ -173,7 +173,7 @@ test('It should be able to access default CSP directives through plugin export',
}
})

fastify.get('/', (request, reply) => {
fastify.get('/', (_request, reply) => {
reply.send({ hello: 'world' })
})

Expand Down Expand Up @@ -206,7 +206,7 @@ test('It should not set default directives when useDefaults is set to `false`',
}
})

fastify.get('/', (request, reply) => {
fastify.get('/', (_request, reply) => {
reply.send({ hello: 'world' })
})

Expand All @@ -231,7 +231,7 @@ test('It should auto generate nonce per request', async (t) => {
enableCSPNonces: true
})

fastify.get('/', (request, reply) => {
fastify.get('/', (_request, reply) => {
t.assert.ok(reply.cspNonce)
reply.send(reply.cspNonce)
})
Expand Down Expand Up @@ -265,7 +265,7 @@ test('It should allow merging options for enableCSPNonces', async (t) => {
}
})

fastify.get('/', (request, reply) => {
fastify.get('/', (_request, reply) => {
t.assert.ok(reply.cspNonce)
reply.send(reply.cspNonce)
})
Expand Down Expand Up @@ -297,7 +297,7 @@ test('It should not set default directives when using enableCSPNonces and useDef
}
})

fastify.get('/', (request, reply) => {
fastify.get('/', (_request, reply) => {
t.assert.ok(reply.cspNonce)
reply.send(reply.cspNonce)
})
Expand Down Expand Up @@ -328,7 +328,7 @@ test('It should not stack nonce array in csp header', async (t) => {
}
})

fastify.get('/', (request, reply) => {
fastify.get('/', (_request, reply) => {
t.assert.ok(reply.cspNonce)
reply.send(reply.cspNonce)
})
Expand Down Expand Up @@ -368,7 +368,7 @@ test('It should access the correct options property', async (t) => {
}
})

fastify.get('/', (request, reply) => {
fastify.get('/', (_request, reply) => {
t.assert.ok(reply.cspNonce)
reply.send(reply.cspNonce)
})
Expand Down Expand Up @@ -397,7 +397,7 @@ test('It should not set script-src or style-src', async (t) => {
}
})

fastify.get('/', (request, reply) => {
fastify.get('/', (_request, reply) => {
t.assert.ok(reply.cspNonce)
reply.send(reply.cspNonce)
})
Expand All @@ -418,7 +418,7 @@ test('It should add hooks correctly', async (t) => {

const fastify = Fastify()

fastify.addHook('onRequest', async (request, reply) => {
fastify.addHook('onRequest', async (_request, reply) => {
reply.header('x-fastify-global-test', 'ok')
})

Expand All @@ -428,29 +428,29 @@ test('It should add hooks correctly', async (t) => {
'/one',
{
onRequest: [
async (request, reply) => {
async (_request, reply) => {
reply.header('x-fastify-test-one', 'ok')
}
]
},
(request, reply) => {
() => {
return { message: 'one' }
}
)

fastify.get(
'/two',
{
onRequest: async (request, reply) => {
onRequest: async (_request, reply) => {
reply.header('x-fastify-test-two', 'ok')
}
},
(request, reply) => {
() => {
return { message: 'two' }
}
)

fastify.get('/three', { onRequest: async () => {} }, (request, reply) => {
fastify.get('/three', { onRequest: async () => {} }, () => {
return { message: 'three' }
})

Expand Down Expand Up @@ -537,7 +537,7 @@ test('It should add the `helmet` reply decorator', async (t) => {
const fastify = Fastify()
await fastify.register(helmet, { global: false })

fastify.get('/', async (request, reply) => {
fastify.get('/', async (_request, reply) => {
t.assert.ok(reply.helmet)
t.assert.notStrictEqual(reply.helmet, null)

Expand Down Expand Up @@ -579,7 +579,7 @@ test('It should not throw when trying to add the `helmet` and `cspNonce` reply d

await fastify.register(helmet, { enableCSPNonces: true, global: true })

fastify.get('/', async (request, reply) => {
fastify.get('/', async (_request, reply) => {
t.assert.ok(reply.helmet)
t.assert.notDeepStrictEqual(reply.helmet, null)
t.assert.ok(reply.cspNonce)
Expand Down Expand Up @@ -622,7 +622,7 @@ test('It should be able to pass custom options to the `helmet` reply decorator',
const fastify = Fastify()
await fastify.register(helmet, { global: false })

fastify.get('/', async (request, reply) => {
fastify.get('/', async (_request, reply) => {
t.assert.ok(reply.helmet)
t.assert.notDeepStrictEqual(reply.helmet, null)

Expand Down Expand Up @@ -744,17 +744,17 @@ test('It should apply helmet headers when returning error messages', async (t) =
fastify.get(
'/',
{
onRequest: async (request, reply) => {
onRequest: async (_request, reply) => {
reply.code(401)
reply.send({ message: 'Unauthorized' })
}
},
async (request, reply) => {
async () => {
return { message: 'ok' }
}
)

fastify.get('/error-handler', {}, async (request, reply) => {
fastify.get('/error-handler', {}, async () => {
return Promise.reject(new Error('error handler triggered'))
})

Expand Down Expand Up @@ -828,7 +828,7 @@ test('It should not return a fastify `FST_ERR_REP_ALREADY_SENT - Reply already s

const logs = []
const destination = new stream.Writable({
write: function (chunk, encoding, next) {
write: function (chunk, _encoding, next) {
logs.push(JSON.parse(chunk))
next()
}
Expand All @@ -839,7 +839,7 @@ test('It should not return a fastify `FST_ERR_REP_ALREADY_SENT - Reply already s
await fastify.register(helmet)
await fastify.register(
fp(
async (instance, options) => {
async (instance, _options) => {
instance.addHook('onRequest', async (request, reply) => {
const unauthorized = new Error('Unauthorized')

Expand Down Expand Up @@ -873,7 +873,7 @@ test('It should not return a fastify `FST_ERR_REP_ALREADY_SENT - Reply already s
{
config: { fail: true }
},
async (request, reply) => {
async () => {
return { message: 'unreachable' }
}
)
Expand Down Expand Up @@ -934,7 +934,7 @@ test('It should forward `helmet` errors to `fastify-helmet`', async (t) => {
}
})

fastify.get('/', async (request, reply) => {
fastify.get('/', async () => {
return { message: 'ok' }
})

Expand Down Expand Up @@ -981,14 +981,14 @@ test('It should be able to catch `helmet` errors with a fastify `onError` hook',
}
})

fastify.addHook('onError', async (request, reply, error) => {
fastify.addHook('onError', async (_request, _reply, error) => {
if (error) {
errorDetected.push(error)
t.assert.ok(error)
}
})

fastify.get('/', async (request, reply) => {
fastify.get('/', async () => {
return { message: 'ok' }
})

Expand Down
26 changes: 13 additions & 13 deletions test/routes.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ test('It should apply route specific helmet options over the global options', as
const fastify = Fastify()
await fastify.register(helmet, { global: true })

fastify.get('/', { helmet: { frameguard: false } }, (request, reply) => {
fastify.get('/', { helmet: { frameguard: false } }, (_request, reply) => {
reply.send({ hello: 'world' })
})

Expand Down Expand Up @@ -50,11 +50,11 @@ test('It should disable helmet on specific route when route `helmet` option is s
const fastify = Fastify()
await fastify.register(helmet, { global: true })

fastify.get('/disabled', { helmet: false }, (request, reply) => {
fastify.get('/disabled', { helmet: false }, (_request, reply) => {
reply.send({ hello: 'disabled' })
})

fastify.get('/enabled', (request, reply) => {
fastify.get('/enabled', (_request, reply) => {
reply.send({ hello: 'enabled' })
})

Expand Down Expand Up @@ -129,7 +129,7 @@ test('It should add CSPNonce decorator and hooks when route `enableCSPNonces` op
enableCSPNonces: true
}
},
(request, reply) => {
(_request, reply) => {
t.assert.ok(reply.cspNonce)
reply.send(reply.cspNonce)
}
Expand Down Expand Up @@ -160,7 +160,7 @@ test('It should add CSPNonce decorator and hooks with default options when route
enableCSPNonces: false
})

fastify.get('/no-csp', (request, reply) => {
fastify.get('/no-csp', (_request, reply) => {
t.assert.equal(reply.cspNonce, null)
reply.send({ message: 'no csp' })
})
Expand All @@ -172,7 +172,7 @@ test('It should add CSPNonce decorator and hooks with default options when route
enableCSPNonces: true
}
},
(request, reply) => {
(_request, reply) => {
t.assert.ok(reply.cspNonce)
reply.send(reply.cspNonce)
}
Expand Down Expand Up @@ -207,15 +207,15 @@ test('It should not add CSPNonce decorator when route `enableCSPNonces` option i
enableCSPNonces: true
})

fastify.get('/with-csp', (request, reply) => {
fastify.get('/with-csp', (_request, reply) => {
t.assert.ok(reply.cspNonce)
reply.send(reply.cspNonce)
})

fastify.get(
'/no-csp',
{ helmet: { enableCSPNonces: false } },
(request, reply) => {
(_request, reply) => {
t.assert.equal(reply.cspNonce, null)
reply.send({ message: 'no csp' })
}
Expand Down Expand Up @@ -267,7 +267,7 @@ test('It should not set default directives when route useDefaults is set to `fal
}
}
},
(request, reply) => {
(_request, reply) => {
reply.send({ hello: 'world' })
}
)
Expand Down Expand Up @@ -306,7 +306,7 @@ test('It should not set `content-security-policy` header, if route contentSecuri
contentSecurityPolicy: false
}
},
(request, reply) => {
(_request, reply) => {
reply.send({ hello: 'world' })
}
)
Expand Down Expand Up @@ -403,7 +403,7 @@ test('It should throw an error when route specific helmet options are of an inva
await fastify.register(helmet)

try {
fastify.get('/', { helmet: 'invalid_options' }, (request, reply) => {
fastify.get('/', { helmet: 'invalid_options' }, () => {
return { message: 'ok' }
})
} catch (error) {
Expand All @@ -421,7 +421,7 @@ test('It should forward `helmet` reply decorator and route specific errors to `f
const fastify = Fastify()
await fastify.register(helmet, { global: false })

fastify.get('/helmet-reply-decorator-error', async (request, reply) => {
fastify.get('/helmet-reply-decorator-error', async (_request, reply) => {
await reply.helmet({
contentSecurityPolicy: {
directives: {
Expand All @@ -444,7 +444,7 @@ test('It should forward `helmet` reply decorator and route specific errors to `f
}
}
},
async (request, reply) => {
async () => {
return { message: 'ok' }
}
)
Expand Down
Loading

0 comments on commit 7d46361

Please sign in to comment.