eslint-plugin-prefer-arrow-functions icon indicating copy to clipboard operation
eslint-plugin-prefer-arrow-functions copied to clipboard

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

Open andersk opened this issue 1 year ago • 0 comments

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 ,.

andersk avatar Jun 07 '24 20:06 andersk