Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: enforce usage of nullish check utils #12

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

AntonioVentilii-DFINITY
Copy link
Collaborator

@AntonioVentilii-DFINITY AntonioVentilii-DFINITY commented Sep 27, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant