Closed u3u closed 10 months ago
I hope that arrow functions can be forced to convert to implicit style when there is only one line.
implicit
const arr = [0, 1, 2] arr.filter((x) => { return x % 2 === 0 }) // ↓ ↓ ↓ ↓ ↓ ↓ arr.filter((x) => x % 2 === 0)
But if there are multiple lines, it can be forced to convert to the explicit style.
explicit
export const delay = (timeout) => new Promise((resolve) => { setTimeout(() => { resolve() }, timeout) }) // ↓ ↓ ↓ ↓ ↓ ↓ export const delay = (timeout) => { return new Promise((resolve) => { setTimeout(() => { resolve() }, timeout) }) }
This also makes it easier to extend React functional components.
React
export const Button = () => ( <button> <span></span> </button> ) // ↓ ↓ ↓ ↓ ↓ ↓ export const Button = () => { return ( <button> <span></span> </button> ) }
ref: https://github.com/eslint/eslint/issues/9062
Add a new smart enumeration to the returnStyle option for intelligent judgment.
smart
returnStyle
I implemented it myself. https://github.com/u3u/eslint-plugin-arrow-return-style
/cc @tjbenton
Great work @u3u, thank you.
Description
I hope that arrow functions can be forced to convert to
implicit
style when there is only one line.But if there are multiple lines, it can be forced to convert to the
explicit
style.This also makes it easier to extend
React
functional components.ref: https://github.com/eslint/eslint/issues/9062
Suggested Solution
Add a new
smart
enumeration to thereturnStyle
option for intelligent judgment.