SonarSource / eslint-plugin-sonarjs

SonarJS rules for ESLint

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

`sonarjs/no-redundant-jump` should not be flagged for trailing `return;`s for a function returning `undefined`

akx opened this issue · comments

Reproducer

function foo(): string | undefined {
  if (Math.random() > 0.5) {
    return 'hello';
  }
  return;  // Remove this redundant jump [sonarjs/no-redundant-jump]
}

Expected behavior

The last return; should preferably not be flagged; it's not a jump.

Turning this into return undefined; quiesces the plugin, but return undefined; is uglier than return;.

Eliding the last return; is against the tsconfig noImplicitReturns rule, so that is not an option.

Environment.

eslint-plugin-sonarjs version: 0.23.0

eslint version: 8.55.0

Node.js version: 21.5.0

Rule key: sonarjs/no-redundant-jump

This issue has been migrated to Jira. ESLINTJS-31