From 3a159beb21bbf0ddfa0fe4863525a8149fa57f0f Mon Sep 17 00:00:00 2001 From: David Baker Date: Thu, 9 May 2024 10:42:26 +0100 Subject: [PATCH 1/5] Add code style rule for multiple return types --- code_style.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/code_style.md b/code_style.md index 0462f3a4a9..4bd9cebffe 100644 --- a/code_style.md +++ b/code_style.md @@ -224,6 +224,10 @@ Unless otherwise specified, the following applies to all code: // ... } ``` +37. Avoid functions whose behaviour / return type varies with different parameter types. + Multiple return types are fine when appropriate (eg. SDKConfig.get() with a string param which + returns the type according to the param given) but SDKConfig.get() with no args returning the + whole config object is not: this could just be a separate function. ## React From 36571edb9563724b552dbce0bd4d20260ca7ef07 Mon Sep 17 00:00:00 2001 From: David Baker Date: Thu, 9 May 2024 10:53:33 +0100 Subject: [PATCH 2/5] Prettier --- code_style.md | 1 + 1 file changed, 1 insertion(+) diff --git a/code_style.md b/code_style.md index 4bd9cebffe..eab031b46d 100644 --- a/code_style.md +++ b/code_style.md @@ -224,6 +224,7 @@ Unless otherwise specified, the following applies to all code: // ... } ``` + 37. Avoid functions whose behaviour / return type varies with different parameter types. Multiple return types are fine when appropriate (eg. SDKConfig.get() with a string param which returns the type according to the param given) but SDKConfig.get() with no args returning the From 8ba3f53d2c84b14fed0901f5e31115658479fe7a Mon Sep 17 00:00:00 2001 From: David Baker Date: Fri, 10 May 2024 10:48:11 +0100 Subject: [PATCH 3/5] Hopefully clarify --- code_style.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/code_style.md b/code_style.md index eab031b46d..f18de37e0d 100644 --- a/code_style.md +++ b/code_style.md @@ -226,9 +226,10 @@ Unless otherwise specified, the following applies to all code: ``` 37. Avoid functions whose behaviour / return type varies with different parameter types. - Multiple return types are fine when appropriate (eg. SDKConfig.get() with a string param which - returns the type according to the param given) but SDKConfig.get() with no args returning the - whole config object is not: this could just be a separate function. + Multiple return types are fine, but the function's fundamental behaviour should not + change according its arguments: have two separate functions. For example,SDKConfig.get() + with a string param which returns the type according to the param given but SDKConfig.get() + with no args returning the whole config object is not: this could just be a separate function. ## React From f2da5fcf2c928565f9815278719551e77557ff58 Mon Sep 17 00:00:00 2001 From: David Baker Date: Fri, 10 May 2024 16:49:05 +0100 Subject: [PATCH 4/5] Fix typos and clarify wording Co-authored-by: Richard van der Hoff <1389908+richvdh@users.noreply.github.com> --- code_style.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/code_style.md b/code_style.md index f18de37e0d..cab6d36d08 100644 --- a/code_style.md +++ b/code_style.md @@ -227,9 +227,9 @@ Unless otherwise specified, the following applies to all code: 37. Avoid functions whose behaviour / return type varies with different parameter types. Multiple return types are fine, but the function's fundamental behaviour should not - change according its arguments: have two separate functions. For example,SDKConfig.get() - with a string param which returns the type according to the param given but SDKConfig.get() - with no args returning the whole config object is not: this could just be a separate function. + change according its arguments: have two separate functions. For example, `SDKConfig.get()` + with a string param which returns the type according to the param given is ok, but `SDKConfig.get()` + with no args returning the whole config object would not be: this should just be a separate function. ## React From 5f1f018a30f3b98e75af77a57fba399eee78fa0b Mon Sep 17 00:00:00 2001 From: David Baker Date: Fri, 10 May 2024 16:52:19 +0100 Subject: [PATCH 5/5] Fundamental behaviour, not return type --- code_style.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/code_style.md b/code_style.md index cab6d36d08..e6ad053111 100644 --- a/code_style.md +++ b/code_style.md @@ -225,11 +225,11 @@ Unless otherwise specified, the following applies to all code: } ``` -37. Avoid functions whose behaviour / return type varies with different parameter types. - Multiple return types are fine, but the function's fundamental behaviour should not - change according its arguments: have two separate functions. For example, `SDKConfig.get()` - with a string param which returns the type according to the param given is ok, but `SDKConfig.get()` - with no args returning the whole config object would not be: this should just be a separate function. +37. Avoid functions whose fundamental behaviour varies with different parameter types. + Multiple return types are fine, but if the function's behaviour is going to change significantly, + have two separate functions. For example, `SDKConfig.get()` with a string param which returns the + type according to the param given is ok, but `SDKConfig.get()` with no args returning the whole + config object would not be: this should just be a separate function. ## React