UNPKG

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
# 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