SonarSource / eslint-plugin-sonarjs

SonarJS rules for ESLint

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

prefer-immediate-return disallows function name inference

slikts opened this issue · comments

Feature request

This should be a valid pattern:

const makeFooHandler = () => {
  const fooHandler = () => {
    //
  }
  return fooHandler
}

The returned function's .name in this example is inferred to fooHandler and makes it easy to recognise in a call stack.

The prefer-immediate-return rule "fixes" this example by returning an anonymous function:

const makeFooHandler = () => {
  return () => {
    //
  }
}

The rule should make an exception for named functions since otherwise it's actually changing the semantics and can even change runtime behavior if anything is relying on the .name property.

This issue has been migrated to Jira. ESLINTJS-17