Skip to content

Commit 65545aa

Browse files
authored
refactor: prefix unused params with underscores (#406)
* refactor: prefix unused params with underscores * chore: fix
1 parent a1c44eb commit 65545aa

16 files changed

+186
-186
lines changed

example/example-auto-pipeline.mjs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ fastify.get('/', {
3333
timeWindow: '1 minute'
3434
}
3535
}
36-
}, (req, reply) => {
36+
}, (_req, reply) => {
3737
reply.send({ hello: 'from ... root' })
3838
})
3939

@@ -45,11 +45,11 @@ fastify.get('/private', {
4545
timeWindow: '1 minute'
4646
}
4747
}
48-
}, (req, reply) => {
48+
}, (_req, reply) => {
4949
reply.send({ hello: 'from ... private' })
5050
})
5151

52-
fastify.get('/public', (req, reply) => {
52+
fastify.get('/public', (_req, reply) => {
5353
reply.send({ hello: 'from ... public' })
5454
})
5555

@@ -58,15 +58,15 @@ fastify.get('/public/sub-rated-1', {
5858
rateLimit: {
5959
timeWindow: '1 minute',
6060
allowList: ['127.0.2.1'],
61-
onExceeding: function (req) {
61+
onExceeding: function () {
6262
console.log('callback on exceededing ... executed before response to client. req is give as argument')
6363
},
64-
onExceeded: function (req) {
64+
onExceeded: function () {
6565
console.log('callback on exceeded ... to black ip in security group for example, req is give as argument')
6666
}
6767
}
6868
}
69-
}, (req, reply) => {
69+
}, (_req, reply) => {
7070
reply.send({ hello: 'from sub-rated-1 ... using default max value ... ' })
7171
})
7272

@@ -75,15 +75,15 @@ fastify.get('/public/sub-rated-2', {
7575
rateLimit: {
7676
max: 3,
7777
timeWindow: '1 minute',
78-
onExceeding: function (req) {
78+
onExceeding: function () {
7979
console.log('callback on exceededing ... executed before response to client. req is give as argument')
8080
},
81-
onExceeded: function (req) {
81+
onExceeded: function () {
8282
console.log('callback on exceeded ... to black ip in security group for example, req is give as argument')
8383
}
8484
}
8585
}
86-
}, (req, reply) => {
86+
}, (_req, reply) => {
8787
reply.send({ hello: 'from ... sub-rated-2' })
8888
})
8989

@@ -94,7 +94,7 @@ fastify.get('/home', {
9494
timeWindow: '1 minute'
9595
}
9696
}
97-
}, (req, reply) => {
97+
}, (_req, reply) => {
9898
reply.send({ hello: 'toto' })
9999
})
100100

@@ -103,10 +103,10 @@ fastify.get('/customerrormessage', {
103103
rateLimit: {
104104
max: 2,
105105
timeWindow: '1 minute',
106-
errorResponseBuilder: (req, context) => ({ code: 429, timeWindow: context.after, limit: context.max })
106+
errorResponseBuilder: (_req, context) => ({ code: 429, timeWindow: context.after, limit: context.max })
107107
}
108108
}
109-
}, (req, reply) => {
109+
}, (_req, reply) => {
110110
reply.send({ hello: 'toto' })
111111
})
112112

example/example-knex-mysql.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ KnexStore.prototype.incr = async function (key, cb) {
6666
process.nextTick(cb, null, { current: d.count + 1, ttl: d.ttl })
6767
} else {
6868
await trx
69-
.raw('INSERT INTO rate_limits(route, source, count, ttl) VALUES(?,?,1,?) ON DUPLICATE KEY UPDATE count = 1, ttl = ?', [cond.route, key, (d && d.ttl) || ttl, ttl])
70-
process.nextTick(cb, null, { current: 1, ttl: (d && d.ttl) || ttl })
69+
.raw('INSERT INTO rate_limits(route, source, count, ttl) VALUES(?,?,1,?) ON DUPLICATE KEY UPDATE count = 1, ttl = ?', [cond.route, key, d?.ttl || ttl, ttl])
70+
process.nextTick(cb, null, { current: 1, ttl: d?.ttl || ttl })
7171
}
7272
await trx.commit()
7373
} catch (err) {
@@ -104,7 +104,7 @@ fastify.get('/', {
104104
timeWindow: '1 minute'
105105
}
106106
}
107-
}, (req, reply) => {
107+
}, (_req, reply) => {
108108
reply.send({ hello: 'from ... root' })
109109
})
110110

@@ -115,10 +115,10 @@ fastify.get('/private', {
115115
timeWindow: '1 minute'
116116
}
117117
}
118-
}, (req, reply) => {
118+
}, (_req, reply) => {
119119
reply.send({ hello: 'from ... private' })
120120
})
121121

122-
fastify.get('/public', (req, reply) => {
122+
fastify.get('/public', (_req, reply) => {
123123
reply.send({ hello: 'from ... public' })
124124
})

example/example-knex.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ fastify.get('/', {
9393
timeWindow: '1 minute'
9494
}
9595
}
96-
}, (req, reply) => {
96+
}, (_req, reply) => {
9797
reply.send({ hello: 'from ... root' })
9898
})
9999

@@ -104,11 +104,11 @@ fastify.get('/private', {
104104
timeWindow: '1 minute'
105105
}
106106
}
107-
}, (req, reply) => {
107+
}, (_req, reply) => {
108108
reply.send({ hello: 'from ... private' })
109109
})
110110

111-
fastify.get('/public', (req, reply) => {
111+
fastify.get('/public', (_req, reply) => {
112112
reply.send({ hello: 'from ... public' })
113113
})
114114

example/example-sequelize.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -120,13 +120,13 @@ RateLimiterStore.prototype.incr = async function incr (key, cb) {
120120
sequelize.query(
121121
`INSERT INTO "RateLimits"("Route", "Source", "Count", "TTL")
122122
VALUES('${this.route}', '${key}', 1,
123-
${(RateLimit && RateLimit.TTL) || ttl})
123+
${RateLimit?.TTL || ttl})
124124
ON CONFLICT("Route", "Source") DO UPDATE SET "Count"=1, "TTL"=${ttl}`
125125
)
126126
.then(() => {
127127
cb(null, {
128128
current: 1,
129-
ttl: (RateLimit && RateLimit.TTL) || ttl
129+
ttl: RateLimit?.TTL || ttl
130130
})
131131
})
132132
.catch(err => {
@@ -160,7 +160,7 @@ fastify.get('/', {
160160
timeWindow: '1 minute'
161161
}
162162
}
163-
}, (req, reply) => {
163+
}, (_req, reply) => {
164164
reply.send({ hello: 'from ... root' })
165165
})
166166

@@ -171,11 +171,11 @@ fastify.get('/private', {
171171
timeWindow: '1 minute'
172172
}
173173
}
174-
}, (req, reply) => {
174+
}, (_req, reply) => {
175175
reply.send({ hello: 'from ... private' })
176176
})
177177

178-
fastify.get('/public', (req, reply) => {
178+
fastify.get('/public', (_req, reply) => {
179179
reply.send({ hello: 'from ... public' })
180180
})
181181

example/example-simple.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ await server.register(fastifyRateLimit, {
99
timeWindow: '1 minute'
1010
})
1111

12-
server.get('/', (request, reply) => {
12+
server.get('/', (_request, reply) => {
1313
reply.send('Hello, world!')
1414
})
1515

example/example.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ fastify.get('/', {
3030
timeWindow: '1 minute'
3131
}
3232
}
33-
}, (req, reply) => {
33+
}, (_req, reply) => {
3434
reply.send({ hello: 'from ... root' })
3535
})
3636

@@ -42,11 +42,11 @@ fastify.get('/private', {
4242
timeWindow: '1 minute'
4343
}
4444
}
45-
}, (req, reply) => {
45+
}, (_req, reply) => {
4646
reply.send({ hello: 'from ... private' })
4747
})
4848

49-
fastify.get('/public', (req, reply) => {
49+
fastify.get('/public', (_req, reply) => {
5050
reply.send({ hello: 'from ... public' })
5151
})
5252

@@ -55,15 +55,15 @@ fastify.get('/public/sub-rated-1', {
5555
rateLimit: {
5656
timeWindow: '1 minute',
5757
allowList: ['127.0.2.1'],
58-
onExceeding: function (req) {
58+
onExceeding: function () {
5959
console.log('callback on exceededing ... executed before response to client. req is give as argument')
6060
},
61-
onExceeded: function (req) {
61+
onExceeded: function () {
6262
console.log('callback on exceeded ... to black ip in security group for example, req is give as argument')
6363
}
6464
}
6565
}
66-
}, (req, reply) => {
66+
}, (_req, reply) => {
6767
reply.send({ hello: 'from sub-rated-1 ... using default max value ... ' })
6868
})
6969

@@ -72,15 +72,15 @@ fastify.get('/public/sub-rated-2', {
7272
rateLimit: {
7373
max: 3,
7474
timeWindow: '1 minute',
75-
onExceeding: function (req) {
75+
onExceeding: function () {
7676
console.log('callback on exceededing ... executed before response to client. req is give as argument')
7777
},
78-
onExceeded: function (req) {
78+
onExceeded: function () {
7979
console.log('callback on exceeded ... to black ip in security group for example, req is give as argument')
8080
}
8181
}
8282
}
83-
}, (req, reply) => {
83+
}, (_req, reply) => {
8484
reply.send({ hello: 'from ... sub-rated-2' })
8585
})
8686

@@ -91,7 +91,7 @@ fastify.get('/home', {
9191
timeWindow: '1 minute'
9292
}
9393
}
94-
}, (req, reply) => {
94+
}, (_req, reply) => {
9595
reply.send({ hello: 'toto' })
9696
})
9797

@@ -100,10 +100,10 @@ fastify.get('/customerrormessage', {
100100
rateLimit: {
101101
max: 2,
102102
timeWindow: '1 minute',
103-
errorResponseBuilder: (req, context) => ({ code: 429, timeWindow: context.after, limit: context.max })
103+
errorResponseBuilder: (_req, context) => ({ code: 429, timeWindow: context.after, limit: context.max })
104104
}
105105
}
106-
}, (req, reply) => {
106+
}, (_req, reply) => {
107107
reply.send({ hello: 'toto' })
108108
})
109109

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ const defaultOnFn = () => {}
2828

2929
const defaultKeyGenerator = (req) => req.ip
3030

31-
const defaultErrorResponse = (req, context) => {
31+
const defaultErrorResponse = (_req, context) => {
3232
const err = new Error(`Rate limit exceeded, retry in ${context.after}`)
3333
err.statusCode = context.statusCode
3434
return err

test/exponential-backoff.test.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const rateLimit = require('../index')
66

77
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms))
88

9-
test('Exponential Backoff', async (t) => {
9+
test('Exponential Backoff', async () => {
1010
const fastify = Fastify()
1111

1212
// Register rate limit plugin with exponentialBackoff set to true in routeConfig
@@ -23,7 +23,7 @@ test('Exponential Backoff', async (t) => {
2323
}
2424
}
2525
},
26-
async (req, reply) => 'exponential backoff applied!'
26+
async () => 'exponential backoff applied!'
2727
)
2828

2929
// Test
@@ -71,7 +71,7 @@ test('Exponential Backoff', async (t) => {
7171
assert.deepStrictEqual(res5.headers['x-ratelimit-remaining'], '1')
7272
})
7373

74-
test('Global Exponential Backoff', async (t) => {
74+
test('Global Exponential Backoff', async () => {
7575
const fastify = Fastify()
7676

7777
// Register rate limit plugin with exponentialBackoff set to true in routeConfig
@@ -87,7 +87,7 @@ test('Global Exponential Backoff', async (t) => {
8787
}
8888
}
8989
},
90-
async (req, reply) => 'exponential backoff applied!'
90+
async () => 'exponential backoff applied!'
9191
)
9292

9393
// Test
@@ -151,7 +151,7 @@ test('Global Exponential Backoff', async (t) => {
151151
)
152152
})
153153

154-
test('MAx safe Exponential Backoff', async (t) => {
154+
test('MAx safe Exponential Backoff', async () => {
155155
const fastify = Fastify()
156156

157157
// Register rate limit plugin with exponentialBackoff set to true in routeConfig
@@ -167,7 +167,7 @@ test('MAx safe Exponential Backoff', async (t) => {
167167
}
168168
}
169169
},
170-
async (req, reply) => 'exponential backoff applied!'
170+
async () => 'exponential backoff applied!'
171171
)
172172

173173
// Test

test/github-issues/issue-284.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ test("issue #284 - don't set the reply code automatically", async (t) => {
1313
global: false
1414
})
1515

16-
fastify.setErrorHandler((err, req, res) => {
16+
fastify.setErrorHandler((err, _req, res) => {
1717
t.assert.deepStrictEqual(res.statusCode, 200)
1818
t.assert.deepStrictEqual(err.statusCode, 429)
1919

0 commit comments

Comments
 (0)