Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: prefix unused params with underscores #406

Merged
merged 2 commits into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions example/example-auto-pipeline.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ fastify.get('/', {
timeWindow: '1 minute'
}
}
}, (req, reply) => {
}, (_req, reply) => {
reply.send({ hello: 'from ... root' })
})

Expand All @@ -45,11 +45,11 @@ fastify.get('/private', {
timeWindow: '1 minute'
}
}
}, (req, reply) => {
}, (_req, reply) => {
reply.send({ hello: 'from ... private' })
})

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

Expand All @@ -58,15 +58,15 @@ fastify.get('/public/sub-rated-1', {
rateLimit: {
timeWindow: '1 minute',
allowList: ['127.0.2.1'],
onExceeding: function (req) {
onExceeding: function () {
console.log('callback on exceededing ... executed before response to client. req is give as argument')
},
onExceeded: function (req) {
onExceeded: function () {
console.log('callback on exceeded ... to black ip in security group for example, req is give as argument')
}
}
}
}, (req, reply) => {
}, (_req, reply) => {
reply.send({ hello: 'from sub-rated-1 ... using default max value ... ' })
})

Expand All @@ -75,15 +75,15 @@ fastify.get('/public/sub-rated-2', {
rateLimit: {
max: 3,
timeWindow: '1 minute',
onExceeding: function (req) {
onExceeding: function () {
console.log('callback on exceededing ... executed before response to client. req is give as argument')
},
onExceeded: function (req) {
onExceeded: function () {
console.log('callback on exceeded ... to black ip in security group for example, req is give as argument')
}
}
}
}, (req, reply) => {
}, (_req, reply) => {
reply.send({ hello: 'from ... sub-rated-2' })
})

Expand All @@ -94,7 +94,7 @@ fastify.get('/home', {
timeWindow: '1 minute'
}
}
}, (req, reply) => {
}, (_req, reply) => {
reply.send({ hello: 'toto' })
})

Expand All @@ -103,10 +103,10 @@ fastify.get('/customerrormessage', {
rateLimit: {
max: 2,
timeWindow: '1 minute',
errorResponseBuilder: (req, context) => ({ code: 429, timeWindow: context.after, limit: context.max })
errorResponseBuilder: (_req, context) => ({ code: 429, timeWindow: context.after, limit: context.max })
}
}
}, (req, reply) => {
}, (_req, reply) => {
reply.send({ hello: 'toto' })
})

Expand Down
10 changes: 5 additions & 5 deletions example/example-knex-mysql.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ KnexStore.prototype.incr = async function (key, cb) {
process.nextTick(cb, null, { current: d.count + 1, ttl: d.ttl })
} else {
await trx
.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])
process.nextTick(cb, null, { current: 1, ttl: (d && d.ttl) || ttl })
.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])
process.nextTick(cb, null, { current: 1, ttl: d?.ttl || ttl })
}
await trx.commit()
} catch (err) {
Expand Down Expand Up @@ -104,7 +104,7 @@ fastify.get('/', {
timeWindow: '1 minute'
}
}
}, (req, reply) => {
}, (_req, reply) => {
reply.send({ hello: 'from ... root' })
})

Expand All @@ -115,10 +115,10 @@ fastify.get('/private', {
timeWindow: '1 minute'
}
}
}, (req, reply) => {
}, (_req, reply) => {
reply.send({ hello: 'from ... private' })
})

fastify.get('/public', (req, reply) => {
fastify.get('/public', (_req, reply) => {
reply.send({ hello: 'from ... public' })
})
6 changes: 3 additions & 3 deletions example/example-knex.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ fastify.get('/', {
timeWindow: '1 minute'
}
}
}, (req, reply) => {
}, (_req, reply) => {
reply.send({ hello: 'from ... root' })
})

Expand All @@ -104,11 +104,11 @@ fastify.get('/private', {
timeWindow: '1 minute'
}
}
}, (req, reply) => {
}, (_req, reply) => {
reply.send({ hello: 'from ... private' })
})

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

Expand Down
10 changes: 5 additions & 5 deletions example/example-sequelize.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,13 @@ RateLimiterStore.prototype.incr = async function incr (key, cb) {
sequelize.query(
`INSERT INTO "RateLimits"("Route", "Source", "Count", "TTL")
VALUES('${this.route}', '${key}', 1,
${(RateLimit && RateLimit.TTL) || ttl})
${RateLimit?.TTL || ttl})
ON CONFLICT("Route", "Source") DO UPDATE SET "Count"=1, "TTL"=${ttl}`
)
.then(() => {
cb(null, {
current: 1,
ttl: (RateLimit && RateLimit.TTL) || ttl
ttl: RateLimit?.TTL || ttl
})
})
.catch(err => {
Expand Down Expand Up @@ -160,7 +160,7 @@ fastify.get('/', {
timeWindow: '1 minute'
}
}
}, (req, reply) => {
}, (_req, reply) => {
reply.send({ hello: 'from ... root' })
})

Expand All @@ -171,11 +171,11 @@ fastify.get('/private', {
timeWindow: '1 minute'
}
}
}, (req, reply) => {
}, (_req, reply) => {
reply.send({ hello: 'from ... private' })
})

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

Expand Down
2 changes: 1 addition & 1 deletion example/example-simple.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ await server.register(fastifyRateLimit, {
timeWindow: '1 minute'
})

server.get('/', (request, reply) => {
server.get('/', (_request, reply) => {
reply.send('Hello, world!')
})

Expand Down
24 changes: 12 additions & 12 deletions example/example.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ fastify.get('/', {
timeWindow: '1 minute'
}
}
}, (req, reply) => {
}, (_req, reply) => {
reply.send({ hello: 'from ... root' })
})

Expand All @@ -42,11 +42,11 @@ fastify.get('/private', {
timeWindow: '1 minute'
}
}
}, (req, reply) => {
}, (_req, reply) => {
reply.send({ hello: 'from ... private' })
})

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

Expand All @@ -55,15 +55,15 @@ fastify.get('/public/sub-rated-1', {
rateLimit: {
timeWindow: '1 minute',
allowList: ['127.0.2.1'],
onExceeding: function (req) {
onExceeding: function () {
console.log('callback on exceededing ... executed before response to client. req is give as argument')
},
onExceeded: function (req) {
onExceeded: function () {
console.log('callback on exceeded ... to black ip in security group for example, req is give as argument')
}
}
}
}, (req, reply) => {
}, (_req, reply) => {
reply.send({ hello: 'from sub-rated-1 ... using default max value ... ' })
})

Expand All @@ -72,15 +72,15 @@ fastify.get('/public/sub-rated-2', {
rateLimit: {
max: 3,
timeWindow: '1 minute',
onExceeding: function (req) {
onExceeding: function () {
console.log('callback on exceededing ... executed before response to client. req is give as argument')
},
onExceeded: function (req) {
onExceeded: function () {
console.log('callback on exceeded ... to black ip in security group for example, req is give as argument')
}
}
}
}, (req, reply) => {
}, (_req, reply) => {
reply.send({ hello: 'from ... sub-rated-2' })
})

Expand All @@ -91,7 +91,7 @@ fastify.get('/home', {
timeWindow: '1 minute'
}
}
}, (req, reply) => {
}, (_req, reply) => {
reply.send({ hello: 'toto' })
})

Expand All @@ -100,10 +100,10 @@ fastify.get('/customerrormessage', {
rateLimit: {
max: 2,
timeWindow: '1 minute',
errorResponseBuilder: (req, context) => ({ code: 429, timeWindow: context.after, limit: context.max })
errorResponseBuilder: (_req, context) => ({ code: 429, timeWindow: context.after, limit: context.max })
}
}
}, (req, reply) => {
}, (_req, reply) => {
reply.send({ hello: 'toto' })
})

Expand Down
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const defaultOnFn = () => {}

const defaultKeyGenerator = (req) => req.ip

const defaultErrorResponse = (req, context) => {
const defaultErrorResponse = (_req, context) => {
const err = new Error(`Rate limit exceeded, retry in ${context.after}`)
err.statusCode = context.statusCode
return err
Expand Down
12 changes: 6 additions & 6 deletions test/exponential-backoff.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const rateLimit = require('../index')

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

test('Exponential Backoff', async (t) => {
test('Exponential Backoff', async () => {
const fastify = Fastify()

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

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

test('Global Exponential Backoff', async (t) => {
test('Global Exponential Backoff', async () => {
const fastify = Fastify()

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

// Test
Expand Down Expand Up @@ -151,7 +151,7 @@ test('Global Exponential Backoff', async (t) => {
)
})

test('MAx safe Exponential Backoff', async (t) => {
test('MAx safe Exponential Backoff', async () => {
const fastify = Fastify()

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

// Test
Expand Down
2 changes: 1 addition & 1 deletion test/github-issues/issue-284.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ test("issue #284 - don't set the reply code automatically", async (t) => {
global: false
})

fastify.setErrorHandler((err, req, res) => {
fastify.setErrorHandler((err, _req, res) => {
t.assert.deepStrictEqual(res.statusCode, 200)
t.assert.deepStrictEqual(err.statusCode, 429)

Expand Down
Loading
Loading