This ESLint plugin provides a rule to enforce that a return statement is used when utilizing Fastify's reply object.
First, you'll need to install ESLint:
npm install eslint --save-dev
Next, install eslint-plugin-enforce-return-on-reply
:
npm install eslint-plugin-enforce-return-on-reply --save-dev
Note: If you installed ESLint globally (using the -g
flag) then you must also install eslint-plugin-enforce-return-on-reply
globally.
Add enforce-return-on-reply
to the plugins section of your .eslintrc
configuration file. You can omit the eslint-plugin-
prefix:
{
"plugins": [
"enforce-return-on-reply"
]
}
Then configure the rule under the rules
section.
{
"rules": {
"enforce-return-on-reply/enforce-return-on-fastify-reply": "error"
}
}
enforce-return-on-fastify-reply
: Enforces the use of a return statement when utilizing Fastify's reply object.
With this rule, the following code would result in an error:
fastify.get('/', async (request, reply) => {
reply.code(200).send({ hello: 'world' });
});
A valid example:
fastify.get('/', async (request, reply) => {
return reply.code(200).send({ hello: 'world' });
});
Feel free to open issues or PRs!