Skip to content

Commit 59178ee

Browse files
authored
refactor: prefix unused params with underscores (#190)
1 parent 5bb4c9c commit 59178ee

File tree

4 files changed

+23
-23
lines changed

4 files changed

+23
-23
lines changed

index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ function fastifyPostgres (fastify, options, next) {
9696
transact: transact.bind(pool)
9797
}
9898

99-
fastify.addHook('onClose', (fastify, done) => pool.end(done))
99+
fastify.addHook('onClose', (_fastify, done) => pool.end(done))
100100

101101
if (name) {
102102
if (db[name]) {
@@ -135,7 +135,7 @@ function fastifyPostgres (fastify, options, next) {
135135
return
136136
}
137137

138-
const preHandler = async (req, reply) => {
138+
const preHandler = async (req) => {
139139
const client = await pool.connect()
140140

141141
if (name) {
@@ -164,7 +164,7 @@ function fastifyPostgres (fastify, options, next) {
164164
await client.query('BEGIN')
165165
}
166166

167-
const onError = (req, reply, error, done) => {
167+
const onError = (req, _reply, _error, done) => {
168168
req[transactionFailedSymbol] = true
169169
extractRequestClient(req, transact).query('ROLLBACK', done)
170170
}

test/initialization.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,15 @@ test('Should not throw if registered within different scopes (with and without n
5151
const fastify = Fastify()
5252
t.after(() => fastify.close())
5353

54-
await fastify.register(function scopeOne (instance, opts, next) {
54+
await fastify.register(function scopeOne (instance, _opts, next) {
5555
instance.register(fastifyPostgres, {
5656
connectionString
5757
})
5858

5959
next()
6060
})
6161

62-
await fastify.register(function scopeTwo (instance, opts, next) {
62+
await fastify.register(function scopeTwo (instance, _opts, next) {
6363
instance.register(fastifyPostgres, {
6464
connectionString,
6565
name: 'one'

test/req-initialization.test.js

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ test('When we use the fastify-postgres transaction route option', async t => {
1818

1919
await fastify.pg.query('DELETE FROM "users" WHERE TRUE')
2020

21-
fastify.get('/count-users', async (req, reply) => {
21+
fastify.get('/count-users', async () => {
2222
const result = await fastify.pg.query('SELECT COUNT(*) AS "userCount" FROM users WHERE username=\'pass-opt-in\'')
2323

2424
return result
2525
})
2626

27-
fastify.get('/pass', { pg: { transact: true } }, async (req, reply) => {
27+
fastify.get('/pass', { pg: { transact: true } }, async (req) => {
2828
await req.pg.query('INSERT INTO users(username) VALUES($1) RETURNING id', ['pass-opt-in'])
2929
await req.pg.query('INSERT INTO users(username) VALUES($1) RETURNING id', ['pass-opt-in'])
3030
return 'complete'
@@ -51,13 +51,13 @@ test('When we use the fastify-postgres transaction route option', async t => {
5151

5252
await fastify.pg.test.query('DELETE FROM "users" WHERE TRUE')
5353

54-
fastify.get('/count-users', async (req, reply) => {
54+
fastify.get('/count-users', async () => {
5555
const result = await fastify.pg.test.query('SELECT COUNT(*) AS "userCount" FROM users WHERE username=\'pass-opt-in\'')
5656

5757
return result
5858
})
5959

60-
fastify.get('/pass', { pg: { transact: 'test' } }, async (req, reply) => {
60+
fastify.get('/pass', { pg: { transact: 'test' } }, async (req) => {
6161
await req.pg.test.query('INSERT INTO users(username) VALUES($1) RETURNING id', ['pass-opt-in'])
6262
await req.pg.test.query('INSERT INTO users(username) VALUES($1) RETURNING id', ['pass-opt-in'])
6363

@@ -84,7 +84,7 @@ test('When we use the fastify-postgres transaction route option', async t => {
8484

8585
await fastify.pg.query('DELETE FROM "users" WHERE TRUE')
8686

87-
fastify.get('/count-users', async (req, reply) => {
87+
fastify.get('/count-users', async (_req, reply) => {
8888
const result = await fastify.pg.query('SELECT COUNT(*) AS "userCount" FROM users WHERE username=\'fail-opt-in\'')
8989

9090
reply.send(result)
@@ -119,7 +119,7 @@ test('When we use the fastify-postgres transaction route option', async t => {
119119

120120
await fastify.pg.test.query('DELETE FROM "users" WHERE TRUE')
121121

122-
fastify.get('/count-users', async (req, reply) => {
122+
fastify.get('/count-users', async (_req, reply) => {
123123
const result = await fastify.pg.test.query('SELECT COUNT(*) AS "userCount" FROM users WHERE username=\'fail-opt-in\'')
124124

125125
reply.send(result)
@@ -162,7 +162,7 @@ test('When we use the fastify-postgres transaction route option', async t => {
162162
}
163163
},
164164
pg: { transact: true }
165-
}, async (req, reply) => {
165+
}, async () => {
166166
t.assert.fail('should never execute the handler')
167167
})
168168

@@ -186,7 +186,7 @@ test('Should not add hooks with combinations of registration `options.name` and
186186
await fastify.register(fastifyPostgres, {
187187
connectionString
188188
})
189-
fastify.get('/', async (req, reply) => {
189+
fastify.get('/', async (req) => {
190190
t.assert.strictEqual(req.pg, null)
191191
})
192192
await fastify.inject({ url: '/' })
@@ -202,7 +202,7 @@ test('Should not add hooks with combinations of registration `options.name` and
202202
connectionString,
203203
name: 'test'
204204
})
205-
fastify.get('/', async (req, reply) => {
205+
fastify.get('/', async (req) => {
206206
t.assert.strictEqual(req.pg, null)
207207
})
208208

@@ -219,7 +219,7 @@ test('Should not add hooks with combinations of registration `options.name` and
219219
connectionString,
220220
name: 'test'
221221
})
222-
fastify.get('/', { pg: { transact: true } }, async (req, reply) => {
222+
fastify.get('/', { pg: { transact: true } }, async (req) => {
223223
t.assert.strictEqual(req.pg, null)
224224
})
225225

@@ -235,7 +235,7 @@ test('Should not add hooks with combinations of registration `options.name` and
235235
await fastify.register(fastifyPostgres, {
236236
connectionString
237237
})
238-
fastify.get('/', { pg: { transact: 'test' } }, async (req, reply) => {
238+
fastify.get('/', { pg: { transact: 'test' } }, async (req) => {
239239
t.assert.strictEqual(req.pg, null)
240240
})
241241

@@ -252,7 +252,7 @@ test('Should not add hooks with combinations of registration `options.name` and
252252
connectionString,
253253
name: 'test'
254254
})
255-
fastify.get('/', { pg: { transact: 'different' } }, async (req, reply) => {
255+
fastify.get('/', { pg: { transact: 'different' } }, async (req) => {
256256
t.assert.strictEqual(req.pg, null)
257257
})
258258

@@ -272,7 +272,7 @@ test('Should throw errors with incorrect combinations of registration `options.n
272272
name
273273
})
274274

275-
fastify.get('/', { pg: { transact: name } }, async (req, reply) => {})
275+
fastify.get('/', { pg: { transact: name } }, async () => {})
276276

277277
const response = await fastify.inject({ url: '/' })
278278
t.assert.deepStrictEqual(response.json(), {
@@ -292,10 +292,10 @@ test('Should throw errors with incorrect combinations of registration `options.n
292292
connectionString,
293293
name
294294
})
295-
fastify.addHook('onRequest', async (req, reply) => {
295+
fastify.addHook('onRequest', async (req) => {
296296
req.pg = { [name]: await fastify.pg[name].connect() }
297297
})
298-
fastify.get('/', { pg: { transact: name } }, async (req, reply) => {})
298+
fastify.get('/', { pg: { transact: name } }, async () => {})
299299

300300
const response = await fastify.inject({ url: '/' })
301301
t.assert.deepStrictEqual(response.json(), {
@@ -312,10 +312,10 @@ test('Should throw errors with incorrect combinations of registration `options.n
312312
await fastify.register(fastifyPostgres, {
313313
connectionString
314314
})
315-
fastify.addHook('onRequest', async (req, reply) => {
315+
fastify.addHook('onRequest', async (req) => {
316316
req.pg = await fastify.pg.connect()
317317
})
318-
fastify.get('/', { pg: { transact: true } }, async (req, reply) => {})
318+
fastify.get('/', { pg: { transact: true } }, async () => {})
319319

320320
const response = await fastify.inject({ url: '/' })
321321
t.assert.deepStrictEqual(response.json(), {

test/transaction.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ test('When fastify.pg root namespace is used:', async (t) => {
239239
t.assert.ok(ready)
240240

241241
await t.assert.rejects(
242-
async () => await fastify.pg.transact((client) => {}),
242+
async () => await fastify.pg.transact(() => {}),
243243
(err) => {
244244
t.assert.ok(err)
245245
t.assert.strictEqual(err.message, 'Boom')

0 commit comments

Comments
 (0)