Skip to content

Enhancement: [explicit-function-return-type] add option to ignore IIFEs #6115

Closed
@bradzacher

Description

@bradzacher

Before You File a Proposal Please Confirm You Have Done The Following...

My proposal is suitable for this project

  • I believe my proposal would be useful to the broader TypeScript community (meaning it is not a niche proposal).

Link to the rule's documentation

https://typescript-eslint.io/rules/explicit-function-return-type/

Description

Right now the rule will error on IIFE's (immediately invoked function expressions).

IIFEs really shouldn't be covered by the rule because there's no "contract" that needs to be enforced between callers - there's no external callers at all - just one immediate, inline callsite.

In most IIFE cases you are just using an IIFE to wrap-up some logic for a specific variable to be initialised with a value.
By forcing you to annotate an IIFE's return essentially you're forcing someone to annotate the variable declaration explicitly (which isn't what the rule is about!)

We should have an option that allows the rule to ignore IIFEs.

Fail

function foo() {}
const bar = () => {}
const baz = function () {}

Pass

const bar = (() => {})();
const baz = (function () {})();

Additional Info

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    accepting prsGo ahead, send a pull request that resolves this issueenhancement: plugin rule optionNew rule option for an existing eslint-plugin rulepackage: eslint-pluginIssues related to @typescript-eslint/eslint-plugin

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions