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

Monorepo: eslint strict boolean expressions #2030

Merged
merged 15 commits into from
Jul 13, 2022

Conversation

gabrocheleau
Copy link
Contributor

@gabrocheleau gabrocheleau commented Jul 8, 2022

This PR adds the strict-boolean-expressions eslint rule and applies it throughout the monorepo. I also added isTruthy and isFalsy type guard utils for convenience. Eventually, I think we can refactor most of those isTruthy and isFalsy by providing more accurate types upstream and explicitly checking for truthy/falsy cases instead of relying on JS truthiness.

Related to #1935

@gabrocheleau gabrocheleau force-pushed the monorepo/eslint-strict-boolean-expressions branch from 502f85e to cb08b48 Compare July 9, 2022 17:07
@codecov
Copy link

codecov bot commented Jul 9, 2022

Codecov Report

Merging #2030 (c9053dc) into master (8cc3a00) will increase coverage by 0.01%.
The diff coverage is 54.01%.

Impacted file tree graph

Flag Coverage Δ
block 84.01% <76.66%> (-0.29%) ⬇️
blockchain 80.10% <59.25%> (+0.04%) ⬆️
client 78.37% <52.29%> (+0.02%) ⬆️
common 94.90% <93.33%> (-0.13%) ⬇️
devp2p 82.41% <43.20%> (-0.30%) ⬇️
ethash 90.81% <66.66%> (ø)
evm 40.82% <35.44%> (+0.37%) ⬆️
rlp 90.47% <100.00%> (ø)
statemanager 84.55% <70.00%> (ø)
trie 73.79% <41.66%> (+0.06%) ⬆️
tx 92.18% <100.00%> (+0.01%) ⬆️
util 87.19% <64.28%> (+0.15%) ⬆️
vm 78.76% <70.83%> (+0.08%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

@gabrocheleau gabrocheleau force-pushed the monorepo/eslint-strict-boolean-expressions branch from 1c6be76 to 3348602 Compare July 10, 2022 18:44
@gabrocheleau gabrocheleau marked this pull request as ready for review July 10, 2022 19:40
@gabrocheleau gabrocheleau force-pushed the monorepo/eslint-strict-boolean-expressions branch 3 times, most recently from 4517466 to 5894a17 Compare July 11, 2022 03:37
@holgerd77
Copy link
Member

Ugh. What a PR. 😜

Great though! 🙏 ❤️


type Falsy = false | '' | 0 | null | undefined

export function isFalsy(value: unknown): value is Falsy {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a very very explicit note here (and for isTruthy as well) that this is a function which should only temporarily be used and otherwise be replaced with the direct checks (as you mentioned as well), together with some overall context why this function exists?

I otherwise have the strong fear that this looks like as something "how we do things" and other developers rather align with this.

Copy link
Contributor Author

@gabrocheleau gabrocheleau Jul 13, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. I added a note and marked them as deprecated. The goal should definitely to get rid of those eventually, and they should not be used in new code (I think the @deprecated natspec will help achieve that)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, that's a good solution! 👍 😄


export function isTruthy<T>(value: T | Falsy): value is T {
return !isFalsy(value)
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, on another note: are you confident that this code is correct, since we would be using this all over the place now in our libraries (for now)? So does this match 1:1 the previous behavior?

I guess we very much would want to have some tests (or rather: somewhat complete, type-wise) on this, to be really sure this behaves correctly in all cases.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I am confident, but can definitely add tests since as you say this is used throughout

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, yeah, guess this should be some really compact LoCs to cover the various cases.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added some tests

@gabrocheleau gabrocheleau force-pushed the monorepo/eslint-strict-boolean-expressions branch from 5894a17 to 38e5bf9 Compare July 13, 2022 03:27
@gabrocheleau gabrocheleau force-pushed the monorepo/eslint-strict-boolean-expressions branch from 38e5bf9 to c9053dc Compare July 13, 2022 03:37
Copy link
Member

@holgerd77 holgerd77 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, great PR!!! 🎉

(also: we'll see here if the GitPOAP bot will work for the first time 😊, exciting! ❤️)

@holgerd77 holgerd77 merged commit c17346c into master Jul 13, 2022
@holgerd77 holgerd77 deleted the monorepo/eslint-strict-boolean-expressions branch July 13, 2022 09:38
@holgerd77
Copy link
Member

Ah, interestingly enough it is not working here (GitPOAP), but activated here #2035.

Two theories:

  1. The other PR got submitted later and the Bot also takes the submission point into account or something like that.
  2. PRs are only counted when not submitted from the original repo but from a fork.

We'll see (or someone has already the answer). 🙂

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

Successfully merging this pull request may close these issues.

2 participants