matrix-js-sdk icon indicating copy to clipboard operation
matrix-js-sdk copied to clipboard

Maybe enable `strict-boolean-expressions`

Open ShadowJonathan opened this issue 4 years ago • 2 comments

https://typescript-eslint.io/rules/strict-boolean-expressions

Together with https://github.com/matrix-org/matrix-js-sdk/issues/2120 and https://github.com/matrix-org/matrix-js-sdk/issues/2121, this'd do with all truthiness/falsiness checks, and requires these to be explicitly checked by themselves.

ShadowJonathan avatar Jan 23 '22 15:01 ShadowJonathan

Why?

turt2live avatar Jan 24 '22 18:01 turt2live

This would remove truthy/falsy expressions, such as;

let num: number | undefined = 0;
if (num) {
  console.log('num is defined');
}

These assertions may be difficult to follow, and also catch a lot more than just nullability; the above branch would never pass, 0 is falsy.

Instead, this lint would enforce the following;

let num: number | undefined = 0;
if (num !== undefined) {  // or `!= null`, as `undefined == null` 
  console.log('num is defined');
}

This would enable a ton more correctness in the code, and help subtle edgecases around falsifiable non-undefined values.

ShadowJonathan avatar Jan 24 '22 21:01 ShadowJonathan