close

no-unreadable-iife

Unreleased

Configuration

PresetConfigured Value
✅ unicornPlugin.configs.recommended"error"
rslint.config.ts
import { defineConfig, unicornPlugin } from '@rslint/core';

export default defineConfig([
  unicornPlugin.configs.recommended,
  {
    rules: {
      'unicorn/no-unreadable-iife': 'error',
    },
  },
]);

Rule Details

Disallow immediately invoked arrow functions with parenthesized expression bodies. A block body makes the function body easier to distinguish from the surrounding call.

Examples of incorrect code for this rule:

const foo = (bar => (bar ? bar.baz : baz))(getBar());
const value = (() => ({ ready: true }))();

Examples of correct code for this rule:

const foo = (bar => {
  return bar ? bar.baz : baz;
})(getBar());
const value = { ready: true };

Suggestions

This rule offers an editor suggestion to replace the parenthesized body with a block containing a return statement. It does not automatically fix code. The suggestion is withheld when removing the parentheses would discard comments outside the expression. Comments inside the expression are preserved.

Options

This rule has no options.

Original Documentation