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(lint): created local rule to use isNullish and nonNullish #2553

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

AntonioVentilii-DFINITY
Copy link
Contributor

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

Motivation

We would like to enforce the usage of functions isNullish and nonNullish in the code whenever possible. As first step we look for instances of comparing a variable with undefined and/or null.

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 || ...

Note

In this PR, we will not solve all the new issues raised by the new rule, otherwise it would become too big: we add the exceptions to the rule with a TODO, for all the functions that we need to fix in other PRs.

Changes

  • Created custom local lint rule for isNullish usage.
  • Created custom local lint rule for nonNullish usage.
  • Create exceptions where necessary.
  • Fix issues created by new rules related to .find function.
  • Add temporary exceptions to the rule with a TODO associated.

Tests

It raised issues, correctly, and we fixed it.

@AntonioVentilii-DFINITY
Copy link
Contributor Author

AntonioVentilii-DFINITY commented Sep 27, 2024

After PR #2552 , I am moving the rule definition to the https://github.com/dfinity/eslint-config-oisy-wallet repo and the change this PR to be just the adaptation to the new rule.

Working on it with PR:

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