Skip to content

Latest commit

 

History

History
114 lines (89 loc) · 1.8 KB

README.md

File metadata and controls

114 lines (89 loc) · 1.8 KB

eslint-enforce-return-parens

Installation

Install eslint-plugin-return-parens:

$ npm install eslint-plugin-return-parens --save-dev

Usage

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"
  }
}

Rule Details

This rule enforces that a return statement is always surrounded by parentheses.

Examples

// 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');
  });
}

Reason

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: