eslint-plugin-sonarjs icon indicating copy to clipboard operation
eslint-plugin-sonarjs copied to clipboard

add "checkNextLine" flag for "prefer-single-boolean-return"

Open eyal1990 opened this issue 3 years ago • 2 comments

I want to request a feature.

TL;DR - I would like to have "checkNextLine" flag for "prefer-single-boolean-return" so I'll be able to disable the new rule behavior.

In the new version, 0.12.0, the rule "prefer-single-boolean-return" was added the ability to look at the next line and warn about these cases as well. I find in my codebase stark difference between the initial if(condition) {return true} else {return false} and the new behavior. The issue is mostly with cases like a validator function:

function isValid() {

if (condition) {
    return false;
}

if(condition2){
    return false
}

return true;
}

I would like to have a flag to enable/disable the new behavior so I'll be able to still use the original errors but ignore these cases.

eslint-plugin-sonarjs version: 0.12.0
eslint version: 8.5.0
Node.js version: 14.17.6

Rule key: prefer-single-boolean-return

eyal1990 avatar Feb 20 '22 08:02 eyal1990

Hey,

I think we will try to improve the rule to ignore such pattern to avoid the rule parameter.

Thanks for the feedback!

The pattern to ignore: the sequence of if-statements with a final return:

if (...) {
  return false
}

if (...) {
  return false
}

return true;

P.S. There are many such FPs on Peach (e.g. this - internal link)

vilchik-elena avatar Jun 24 '22 08:06 vilchik-elena

@eyal1990 valchik concoders this as a bug (added a bug label). So i think you can remove that 'FR' from the title, which I guess stands for 'Feature Request'.

DerZyklop avatar Oct 21 '22 08:10 DerZyklop

This issue has been migrated to Jira. ESLINTJS-20

Wohops avatar Apr 29 '24 08:04 Wohops