dfinity / eslint-config-oisy-wallet

Shared ESLint configurations from the Oisy Wallet team
Apache License 2.0
2 stars 0 forks source link

feat: enforce usage of nullish check utils #32

Closed AntonioVentilii closed 1 week ago

AntonioVentilii commented 1 week ago

Note

This PR replaced PR #12 , because I changed my account.

Motivation

An useful rule is to enforce the usage of utils isNullish and nonNullish from repo @dfinity/utils for a simple nullish comparison.

isNullish

Incorrect

param === undefined

param === null

param === undefined || param === null

Correct

isNullish(param);

nonNullish

Incorrect

param !== undefined

param !== null

param !== null && param !== undefined

Correct

nonNullish(param);

Future Improvements

The rule will be improved to recognize nullish check even with the following cases (and their negation counterparty):

const param: NonBooleanType | undefined | null;

if (param) {...}

param ? ... : ...

param && ...

param || ...

Tests

Create specific tests for the new rule.

AntonioVentilii commented 1 week ago

@peterpeterparker as discussed offline, done with: