From 31668a049c791a5fbf4a69e88e1ee92e6fe9e621 Mon Sep 17 00:00:00 2001 From: reluc Date: Thu, 21 Sep 2023 11:35:04 +0200 Subject: [PATCH] style(contributing): format edited text --- CONTRIBUTING.md | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index a48b7495a..d371bb902 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -84,19 +84,23 @@ function startFoo() { error("This is an error message!"); } ``` + ### Checking for `undefined` or `null` -In node-wot, we enabled [strict boolean expressions](https://typescript-eslint.io/rules/strict-boolean-expressions/). In summary, this means that in the -the code base is not allowed to use non-boolean expressions where a boolean is expected (see the [examples](https://typescript-eslint.io/rules/strict-boolean-expressions/#examples)). +In node-wot, we enabled [strict boolean expressions](https://typescript-eslint.io/rules/strict-boolean-expressions/). In summary, this means that in the +the code base is not allowed to use non-boolean expressions where a boolean is expected (see the [examples](https://typescript-eslint.io/rules/strict-boolean-expressions/#examples)). How then should the contributor deal with nullable variables? For example: + ```ts function(arg1: string | null | undefined) { - // ERROR: not allowed by strict-boolean-expressions + // ERROR: not allowed by strict-boolean-expressions if(!arg) { throw new Error("arg should be defined!))} } ``` -Instead of checking for both null and `undefiend` values (`if(arg !== undefined && arg !== null)`) the preferred solution is to use `!=` or `==` operator. Interestingly in JavaScript + +Instead of checking for both null and `undefiend` values (`if(arg !== undefined && arg !== null)`) the preferred solution is to use `!=` or `==` operator. Interestingly in JavaScript with ==, null and undefined are only equal to each other. Example: + ```ts function(arg1: string | null | undefined) { // OK @@ -104,7 +108,7 @@ function(arg1: string | null | undefined) { } ``` -Further reading on the motivations can be found [here](https://basarat.gitbook.io/typescript/recap/null-undefined#checking-for-either). +Further reading on the motivations can be found [here](https://basarat.gitbook.io/typescript/recap/null-undefined#checking-for-either). ## Commits