From d9fafd295601f75cc82ed505772362092e33befe Mon Sep 17 00:00:00 2001 From: Andrew Henry Date: Wed, 17 Jun 2020 10:52:30 -0700 Subject: [PATCH] Tweaked code standards for ternaries and return statements (#3082) * Tweaked code standards for ternaries and return statements * Tweaked language slightly Co-authored-by: Deep Tailor --- CONTRIBUTING.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 69898f3d63..1975675dcc 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -178,7 +178,7 @@ The following guidelines are provided for anyone contributing source code to the code, and present these in the following order: * First, variable declarations and initialization. * Secondly, imperative statements. - * Finally, the returned value. Functions should only have a single return statement. + * Finally, the returned value. A single return statement at the end of the function should be used, except where an early return would improve code clarity. 1. Avoid the use of "magic" values. eg. ```JavaScript @@ -189,7 +189,7 @@ The following guidelines are provided for anyone contributing source code to the ```JavaScript if (responseCode === 401) ``` -1. Don’t use the ternary operator. Yes it's terse, but there's probably a clearer way of writing it. +1. Use the ternary operator only for simple cases such as variable assignment. Nested ternaries should be avoided in all cases. 1. Test specs should reside alongside the source code they test, not in a separate directory. 1. Organize code by feature, not by type. eg.