SonarSource / eslint-plugin-sonarjs

SonarJS rules for ESLint
GNU Lesser General Public License v3.0
1.19k stars 73 forks source link

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

Closed akx closed 4 months ago

akx commented 8 months ago

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

Wohops commented 4 months ago

This issue has been migrated to Jira. ESLINTJS-31