sonarjs/prefer-immediate-return
eslint-plugin-sonarjs
Safe autofix
eslint.config.js
export default [
{
rules: {
"sonarjs/prefer-immediate-return": "error",
},
},
];Local variables should not be declared and then immediately returned or thrown
function computeDurationInMilliseconds(hours, minutes, seconds) {
let duration = (((hours * 60) + minutes) * 60 + seconds ) * 1000;
return duration;
}function computeDurationInMilliseconds(hours, minutes, seconds) {
return (((hours * 60) + minutes) * 60 + seconds ) * 1000;
}Examples from the ESLint documentation.
No tracked preset enables this rule, so it has no reach yet.
None of the tracked presets enable this rule. Turn it on with the config below.
sonarjs/prefer-immediate-return
eslint-plugin-sonarjs
export default [
{
rules: {
"sonarjs/prefer-immediate-return": "error",
},
},
];Oxlint does not have this rule.
Biome does not have this rule.
Arithmetic operations should not result in "NaN"
Shorthand object properties should be grouped at the beginning or end of an object declaration
Arithmetic operators should only have numbers as operands