eslint-plugin-sonarjs
eslint-plugin-sonarjs copied to clipboard
add "checkNextLine" flag for "prefer-single-boolean-return"
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
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)
@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'.
This issue has been migrated to Jira. ESLINTJS-20