diff --git a/README.md b/README.md index 5abb5fe..1be25cd 100644 --- a/README.md +++ b/README.md @@ -286,7 +286,7 @@ expect(actualValue, 'should contains foo, bar') ### Do not use ternary inside ternary - no nested ternary -It's really hard to maintain such code +> Reason: it's really hard to maintain such code ```javascript // BAD @@ -300,6 +300,27 @@ if (foo < bar) { result = foo > baz ? 'FOO' : baz; } ``` +### Don't use else, if return stops function execution before +> Reason: it's necessary and makes code cleaner +```javascript +// BAD +const foo = () => { + if (isBar) { + return 'bar'; + } else { + return 'baz'; + } +} + +// GOOD +const foo = () => { + if (isBar) { + return 'bar'; + } + + return 'baz'; +} +``` ### Make function calls clear and predictable @@ -426,7 +447,7 @@ Do not leave console calls in your code ### Do not exceed 120 column width -> Reason: It's hard to read and maintain +> Reason: it's hard to read and maintain Exception: long links and international strings can exceed that limitation diff --git a/eslint-config-ringcentral/index.js b/eslint-config-ringcentral/index.js index fab9408..d39ef43 100644 --- a/eslint-config-ringcentral/index.js +++ b/eslint-config-ringcentral/index.js @@ -140,6 +140,9 @@ module.exports = { // http://eslint.org/docs/rules/no-with 'no-with': 'error', + // https://eslint.org/docs/rules/no-else-return + 'no-else-return': 'error', + // require one `var` or `let` or 'const` for each variable/const. disallow multiple declarations // http://eslint.org/docs/rules/one-var 'one-var': ['error', 'never'],