noUnreadableIife (JavaScript)
Language JavaScript (and super languages)
Summary
Section titled “Summary”- Rule available since:
v2.6.4 - Diagnostic Category:
lint/nursery/noUnreadableIife - This rule has an unsafe fix.
- The default severity of this rule is information.
- Sources:
- Same as
unicorn/no-unreadable-iife
- Same as
How to configure
Section titled “How to configure”{ "linter": { "rules": { "nursery": { "noUnreadableIife": "error" } } }}Description
Section titled “Description”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.
Examples
Section titled “Examples”Invalid
Section titled “Invalid”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());Related links
Section titled “Related links”Copyright (c) 2023-present Biome Developers and Contributors.