From 59178eededfe5414767dd16fa0b10346d9e71658 Mon Sep 17 00:00:00 2001 From: Frazer Smith Date: Mon, 6 Jan 2025 16:51:42 +0000 Subject: [PATCH] refactor: prefix unused params with underscores (#190) --- index.js | 6 +++--- test/initialization.test.js | 4 ++-- test/req-initialization.test.js | 34 ++++++++++++++++----------------- test/transaction.test.js | 2 +- 4 files changed, 23 insertions(+), 23 deletions(-) diff --git a/index.js b/index.js index 3a44415..7c0577d 100644 --- a/index.js +++ b/index.js @@ -96,7 +96,7 @@ function fastifyPostgres (fastify, options, next) { transact: transact.bind(pool) } - fastify.addHook('onClose', (fastify, done) => pool.end(done)) + fastify.addHook('onClose', (_fastify, done) => pool.end(done)) if (name) { if (db[name]) { @@ -135,7 +135,7 @@ function fastifyPostgres (fastify, options, next) { return } - const preHandler = async (req, reply) => { + const preHandler = async (req) => { const client = await pool.connect() if (name) { @@ -164,7 +164,7 @@ function fastifyPostgres (fastify, options, next) { await client.query('BEGIN') } - const onError = (req, reply, error, done) => { + const onError = (req, _reply, _error, done) => { req[transactionFailedSymbol] = true extractRequestClient(req, transact).query('ROLLBACK', done) } diff --git a/test/initialization.test.js b/test/initialization.test.js index ff75f71..ebaf2d6 100644 --- a/test/initialization.test.js +++ b/test/initialization.test.js @@ -51,7 +51,7 @@ test('Should not throw if registered within different scopes (with and without n const fastify = Fastify() t.after(() => fastify.close()) - await fastify.register(function scopeOne (instance, opts, next) { + await fastify.register(function scopeOne (instance, _opts, next) { instance.register(fastifyPostgres, { connectionString }) @@ -59,7 +59,7 @@ test('Should not throw if registered within different scopes (with and without n next() }) - await fastify.register(function scopeTwo (instance, opts, next) { + await fastify.register(function scopeTwo (instance, _opts, next) { instance.register(fastifyPostgres, { connectionString, name: 'one' diff --git a/test/req-initialization.test.js b/test/req-initialization.test.js index 485b815..6f71d40 100644 --- a/test/req-initialization.test.js +++ b/test/req-initialization.test.js @@ -18,13 +18,13 @@ test('When we use the fastify-postgres transaction route option', async t => { await fastify.pg.query('DELETE FROM "users" WHERE TRUE') - fastify.get('/count-users', async (req, reply) => { + fastify.get('/count-users', async () => { const result = await fastify.pg.query('SELECT COUNT(*) AS "userCount" FROM users WHERE username=\'pass-opt-in\'') return result }) - fastify.get('/pass', { pg: { transact: true } }, async (req, reply) => { + fastify.get('/pass', { pg: { transact: true } }, async (req) => { await req.pg.query('INSERT INTO users(username) VALUES($1) RETURNING id', ['pass-opt-in']) await req.pg.query('INSERT INTO users(username) VALUES($1) RETURNING id', ['pass-opt-in']) return 'complete' @@ -51,13 +51,13 @@ test('When we use the fastify-postgres transaction route option', async t => { await fastify.pg.test.query('DELETE FROM "users" WHERE TRUE') - fastify.get('/count-users', async (req, reply) => { + fastify.get('/count-users', async () => { const result = await fastify.pg.test.query('SELECT COUNT(*) AS "userCount" FROM users WHERE username=\'pass-opt-in\'') return result }) - fastify.get('/pass', { pg: { transact: 'test' } }, async (req, reply) => { + fastify.get('/pass', { pg: { transact: 'test' } }, async (req) => { await req.pg.test.query('INSERT INTO users(username) VALUES($1) RETURNING id', ['pass-opt-in']) await req.pg.test.query('INSERT INTO users(username) VALUES($1) RETURNING id', ['pass-opt-in']) @@ -84,7 +84,7 @@ test('When we use the fastify-postgres transaction route option', async t => { await fastify.pg.query('DELETE FROM "users" WHERE TRUE') - fastify.get('/count-users', async (req, reply) => { + fastify.get('/count-users', async (_req, reply) => { const result = await fastify.pg.query('SELECT COUNT(*) AS "userCount" FROM users WHERE username=\'fail-opt-in\'') reply.send(result) @@ -119,7 +119,7 @@ test('When we use the fastify-postgres transaction route option', async t => { await fastify.pg.test.query('DELETE FROM "users" WHERE TRUE') - fastify.get('/count-users', async (req, reply) => { + fastify.get('/count-users', async (_req, reply) => { const result = await fastify.pg.test.query('SELECT COUNT(*) AS "userCount" FROM users WHERE username=\'fail-opt-in\'') reply.send(result) @@ -162,7 +162,7 @@ test('When we use the fastify-postgres transaction route option', async t => { } }, pg: { transact: true } - }, async (req, reply) => { + }, async () => { t.assert.fail('should never execute the handler') }) @@ -186,7 +186,7 @@ test('Should not add hooks with combinations of registration `options.name` and await fastify.register(fastifyPostgres, { connectionString }) - fastify.get('/', async (req, reply) => { + fastify.get('/', async (req) => { t.assert.strictEqual(req.pg, null) }) await fastify.inject({ url: '/' }) @@ -202,7 +202,7 @@ test('Should not add hooks with combinations of registration `options.name` and connectionString, name: 'test' }) - fastify.get('/', async (req, reply) => { + fastify.get('/', async (req) => { t.assert.strictEqual(req.pg, null) }) @@ -219,7 +219,7 @@ test('Should not add hooks with combinations of registration `options.name` and connectionString, name: 'test' }) - fastify.get('/', { pg: { transact: true } }, async (req, reply) => { + fastify.get('/', { pg: { transact: true } }, async (req) => { t.assert.strictEqual(req.pg, null) }) @@ -235,7 +235,7 @@ test('Should not add hooks with combinations of registration `options.name` and await fastify.register(fastifyPostgres, { connectionString }) - fastify.get('/', { pg: { transact: 'test' } }, async (req, reply) => { + fastify.get('/', { pg: { transact: 'test' } }, async (req) => { t.assert.strictEqual(req.pg, null) }) @@ -252,7 +252,7 @@ test('Should not add hooks with combinations of registration `options.name` and connectionString, name: 'test' }) - fastify.get('/', { pg: { transact: 'different' } }, async (req, reply) => { + fastify.get('/', { pg: { transact: 'different' } }, async (req) => { t.assert.strictEqual(req.pg, null) }) @@ -272,7 +272,7 @@ test('Should throw errors with incorrect combinations of registration `options.n name }) - fastify.get('/', { pg: { transact: name } }, async (req, reply) => {}) + fastify.get('/', { pg: { transact: name } }, async () => {}) const response = await fastify.inject({ url: '/' }) t.assert.deepStrictEqual(response.json(), { @@ -292,10 +292,10 @@ test('Should throw errors with incorrect combinations of registration `options.n connectionString, name }) - fastify.addHook('onRequest', async (req, reply) => { + fastify.addHook('onRequest', async (req) => { req.pg = { [name]: await fastify.pg[name].connect() } }) - fastify.get('/', { pg: { transact: name } }, async (req, reply) => {}) + fastify.get('/', { pg: { transact: name } }, async () => {}) const response = await fastify.inject({ url: '/' }) t.assert.deepStrictEqual(response.json(), { @@ -312,10 +312,10 @@ test('Should throw errors with incorrect combinations of registration `options.n await fastify.register(fastifyPostgres, { connectionString }) - fastify.addHook('onRequest', async (req, reply) => { + fastify.addHook('onRequest', async (req) => { req.pg = await fastify.pg.connect() }) - fastify.get('/', { pg: { transact: true } }, async (req, reply) => {}) + fastify.get('/', { pg: { transact: true } }, async () => {}) const response = await fastify.inject({ url: '/' }) t.assert.deepStrictEqual(response.json(), { diff --git a/test/transaction.test.js b/test/transaction.test.js index 49ef630..8453f05 100644 --- a/test/transaction.test.js +++ b/test/transaction.test.js @@ -239,7 +239,7 @@ test('When fastify.pg root namespace is used:', async (t) => { t.assert.ok(ready) await t.assert.rejects( - async () => await fastify.pg.transact((client) => {}), + async () => await fastify.pg.transact(() => {}), (err) => { t.assert.ok(err) t.assert.strictEqual(err.message, 'Boom')