This rule raises an issue when an arrow function with a parenthesized expression body is immediately invoked.
Immediately Invoked Function Expressions (IIFEs) that use arrow functions with parenthesized expression bodies create unnecessarily complex and hard-to-read code.
When you combine an arrow function’s concise syntax with parentheses around the expression body and immediate invocation, the result is visually dense and difficult to parse. The multiple layers of parentheses make it challenging to distinguish between the function parameters, the expression body, and the invocation arguments.
This pattern often indicates that the code would be clearer if broken down into separate steps or refactored into a named function. The immediate invocation suggests the logic might be better expressed as sequential statements or extracted into a reusable function.
This issue primarily affects code maintainability and readability. Complex IIFE patterns can slow down development, make debugging more difficult, and increase the likelihood of introducing bugs during code modifications. While not a security or performance concern, poor readability can lead to misunderstandings and errors in code reviews and maintenance.
Break down the IIFE into separate, clear statements. This makes the logic more explicit and easier to follow.
const foo = (bar => (bar ? bar.baz : baz))(getBar()); // Noncompliant
const bar = getBar(); const foo = bar ? bar.baz : baz;