Install eslint-plugin-return-parens
:
$ npm install eslint-plugin-return-parens --save-dev
Add eslint-plugin-return-parens
to the plugins section of your .eslintrc
configuration file.
{
"plugins": [
"return-parens"
]
}
Then configure the rules you want to use under the rules section.
{
"rules": {
"return-parens/return-parens": "error"
}
}
This rule enforces that a return statement is always surrounded by parentheses.
// Incorrect
function foo() {
return 'bar';
}
// Correct
function foo() {
return ('bar');
}
// Incorrect
function foo() {
return 1;
}
// Correct
function foo() {
return (1);
}
// Incorrect
function foo() {
return true;
}
// Correct
function foo() {
return (true);
}
// Incorrect
function foo() {
return undefined;
}
// Correct
function foo() {
return (undefined);
}
function foo() {
return;
}
// Incorrect
function foo() {
return function() {
return 'bar';
};
}
// Correct
function foo() {
return (function() {
return ('bar');
});
}
This rule is useful for enforcing a consistent style when returning values from functions. It is also useful for preventing the confusing behavior of the return statement.
Also, if you find this rule useless, you are probably right and I agree with you.
Try these rules:
- no-extra-parens - disallow unnecessary parentheses
- consistent-return - require return statements to either always or never specify values