JamieMason / eslint-plugin-prefer-arrow-functions

Auto-fix plain Functions into Arrow Functions, in all cases where conversion would result in the same behaviour
https://www.npmjs.com/package/eslint-plugin-prefer-arrow-functions
MIT License
43 stars 11 forks source link

Syntactically invalid fix for function that’s an operand of an operator #37

Open andersk opened 3 weeks ago

andersk commented 3 weeks ago

This rule auto-fixes f || function () {} to f || () => {}, which is syntactically invalid. Since an arrow function has lower precedence than a function expression, the auto-fix needs to parenthesize it when it’s an operand of most operators: f || (() => {}).

The exceptions are that an unparenthesized arrow function is allowed on the right side of an assignment =, augmenting assignment +=, -=, …, another arrow =>, yield, yield*, spread ..., the middle or right side of a ternary ? :, or either side of a comma ,.