eslint-plugin-no-multiple-returns
Version:
An ESLint plugin to enforce a single `return` statement per function, encouraging clearer and more maintainable code.
67 lines (47 loc) โข 961 B
Markdown
# eslint-plugin-no-multiple-returns
An ESLint plugin to enforce a single `return` statement per function, encouraging clearer and more maintainable code.
## ๐ฆ Installation
```bash
npm install --save-dev eslint-plugin-no-multiple-returns
```
## ๐ง Usage
Add `no-multiple-returns` to your ESLint configuration:
```json
{
"plugins": ["no-multiple-returns"],
"rules": {
"no-multiple-returns/no-multiple-returns": "error"
}
}
```
## โ
Rule Details
This rule disallows functions that contain more than one `return` statement.
### ๐ Examples of **correct** code:
```ts
function singleReturn() {
return 1;
}
const fn = () => {
return 42;
};
const concise = () => 123;
```
### โ Examples of **incorrect** code:
```ts
function bad(x) {
if (x) return 1;
return 2;
}
const multipleReturns = () => {
if (a) return 1;
return 2;
};
```
## ๐งช Development
```bash
npm install
npm run build
npm test
```
## ๐ License
MIT