Skip to content

noUnreadableIife (JavaScript)

Language JavaScript (and super languages)
biome.json
{
"linter": {
"rules": {
"nursery": {
"noUnreadableIife": "error"
}
}
}
}

Disallow immediately called arrow functions whose body is wrapped in parentheses.

An immediately invoked function expression, or IIFE, is a function that is called right where it is defined, such as (() => value)().

When the body of such an arrow function is also wrapped in parentheses, the code contains several nested pairs of parentheses. This makes the function look like a grouped expression and hides where the function body starts and ends.

const foo = (bar => (bar ? bar.baz : baz))(getBar());
code-block.js:1:21 lint/nursery/noUnreadableIife  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

ℹ This immediately called arrow function has a body wrapped in parentheses.

> 1 │ const foo = (bar => (bar ? bar.baz : baz))(getBar());
│ ^^^^^^^^^^^^^^^^^^^^^
2 │

ℹ The extra parentheses make the function look like a grouped expression, which hides where the function body starts.

ℹ Move the code out of the function, or use a body in braces with a return statement.

ℹ This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.

ℹ Unsafe fix: Use a body in braces with a return statement.

1 │ - const·foo·=·(bar·=>·(bar·?·bar.baz·:·baz))(getBar());
1 │ + const·foo·=·(bar·=>·{·return·bar·?·bar.baz·:·baz;·})(getBar());
2 2 │

const foo = ((bar, baz) => ({ bar, baz }))(bar, baz);
code-block.js:1:28 lint/nursery/noUnreadableIife  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

ℹ This immediately called arrow function has a body wrapped in parentheses.

> 1 │ const foo = ((bar, baz) => ({ bar, baz }))(bar, baz);
│ ^^^^^^^^^^^^^^
2 │

ℹ The extra parentheses make the function look like a grouped expression, which hides where the function body starts.

ℹ Move the code out of the function, or use a body in braces with a return statement.

ℹ This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.

ℹ Unsafe fix: Use a body in braces with a return statement.

1 │ - const·foo·=·((bar,·baz)·=>·({·bar,·baz·}))(bar,·baz);
1 │ + const·foo·=·((bar,·baz)·=>·{·return·{·bar,·baz·};·})(bar,·baz);
2 2 │

const bar = getBar();
const foo = bar ? bar.baz : baz;
const getBaz = bar => (bar ? bar.baz : baz);
const qux = getBaz(getBar());
const quux = (bar => {
return bar ? bar.baz : baz;
})(getBar());