Rule proposal: arrow-return-style
evaluatingnew rule
## Preamble
I use a ESLint plugin called [eslint-plugin-arrow-return-style](https://github.com/u3u/eslint-plugin-arrow-return-style). It went completely unmaintained 2 years ago.
A fork emerged 1 year ago, called [eslint-plugin-arrow-return-style-x](https://github.com/christopher-buss/eslint-plugin-arrow-return-style-x). It went unmaintained shortly after the first release.
Unfortunately this is a problem because it's incompatible with ESLint V10 in 2 ways:
1. it relies on an old `@typescript-eslint/utils` version that is not compatible with ESLint V10
2. it uses `context.getSourceCode` instead of `context.sourceCode`
## Rule description
As per the description of the original library:
> Enforce arrow function return style and automatically fix it.
>
> This rule serves as an alternative to the [arrow-body-style](https://eslint.org/docs/latest/rules/arrow-body-style#as-needed) with as-needed options, used to improve the style of arrow function return statement.
>
> - When arrow function expressions are multiline or exceed a certain length, explicit return should be enforced to improve readability and extensibility.
> - When an arrow function has only one return statement (and does not contain any comments), implicit return should be used to simplify the code and improve readability.
> - When using arrow functions as named exports, explicit return should always be used to maintain consistency with regular functions.
> - When using arrow functions as React components, always use explicit return to facilitate the addition of props and hooks in the future.
## My request
It would be nice if `eslint-plugin-unicorn` implemented the functionality of the rule `arrow-return-style/arrow-return-style` (or the extended version `arrow-return-style-x/arrow-return-style`, although, I always ever used the original version).
It worked really well for me through the years, and i think it would be a valuable addition to the community.
If this is not accepted, i will just replicate this into my own ESLint plugin, no problem, but i figured i might give this a try.
### Examples
```js
// ❌
const delay = () =>
new Promise((resolve) => {
setTimeout(resolve, 1000);
});
// ✅
const delay = () => {
return new Promise((resolve) => {
setTimeout(resolve, 1000);
});
};
```
```js
// ❌
const foo = () => {
return 'foo';
};
// ✅
const foo = () => 'foo';
```
```js
// ❌
const Div = () => (
<>
<div />
</>
);
Pass
// ✅
const Div = () => {
return (
<>
<div />
</>
);
};
```
Other examples [here](https://github.com/u3u/eslint-plugin-arrow-return-style/blob/main/docs/rules/arrow-return-style.md).
### Proposed rule name
arrow-return-style
### Additional Info
Other related rules:
- [consistent-function-style](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/consistent-function-style.md)
- [prefer-short-arrow-method](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/prefer-short-arrow-method.md)
0 条评论