-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
feat(eslint-plugin): [prefer-nullish-coalescing] add ignorePrimitives
option
#6487
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(eslint-plugin): [prefer-nullish-coalescing] add ignorePrimitives
option
#6487
Conversation
Thanks for the PR, @omril1! typescript-eslint is a 100% community driven project, and we are incredibly grateful that you are contributing to that community. The core maintainers work on this in their personal time, so please understand that it may not be possible for them to review your work immediately. Thanks again! 🙏 Please, if you or your company is finding typescript-eslint valuable, help us sustain the project by sponsoring it transparently on https://opencollective.com/typescript-eslint. |
❌ Deploy Preview for typescript-eslint failed.
|
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## main #6487 +/- ##
=======================================
Coverage 87.39% 87.40%
=======================================
Files 386 386
Lines 13198 13208 +10
Branches 3873 3878 +5
=======================================
+ Hits 11535 11545 +10
Misses 1296 1296
Partials 367 367
Flags with carried forward coverage won't be shown. Click here to find out more.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A good start, thanks for sending this in! ❤️
Requesting changes on more test cases, docs cleanups, and some code shenanigans.
packages/eslint-plugin/tests/rules/prefer-nullish-coalescing.test.ts
Outdated
Show resolved
Hide resolved
packages/eslint-plugin/tests/rules/prefer-nullish-coalescing.test.ts
Outdated
Show resolved
Hide resolved
👋 Hey @omril1! Just checking in, is this still something you have time for? No worries if not - I just don't want to leave it hanging. |
@JoshuaKGoldberg I'm still on it, I have some more work that I left in the middle |
Any updates here? 😄 |
Mmm, yeah I left it out for a while, got a bit of a burnout at work 🥲. |
…ullish-enhancment
- Literal types (true, 1, etc.) - Template literals (`hello${string}`) - Bigints (1n) - Combinations of the types (boolean | string | ...), etc.
The website tests keep failing in CI and I can't re-run them. |
Ah don't worry about the website CI tests, that's a separate thing. I'll put this back in the queue to review - thanks! |
FWIW you don't have to keep merging |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code looks great! Just requesting changes on a docs example & clearer tests now. Thanks! 🚀
@@ -131,6 +131,15 @@ a ?? (b && c && d); | |||
|
|||
**_NOTE:_** Errors for this specific case will be presented as suggestions (see below), instead of fixes. This is because it is not always safe to automatically convert `||` to `??` within a mixed logical expression, as we cannot tell the intended precedence of the operator. Note that by design, `??` requires parentheses when used with `&&` or `||` in the same expression. | |||
|
|||
### `ignorePrimitives` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Docs] Could you add some examples please? We generally try to -at least for newly added rule options- so users can see exactly how the code looks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried to look at the style for examples with options, this rule seems unique in how the examples are presented but decided to keep it the same since I've noticed bradzacher did the same
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Heh yeah we'll eventually clean all these up... eventually. Thanks!
boolean?: boolean; | ||
number?: boolean; | ||
string?: boolean; | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Non-actionable] In theory we could allow this to be a boolean
to configure all of the primitives at once. I think it's fine to leave that as a follow-up to this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea, leaving it for now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do I need to open an issue for it or can I reference the same one?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should have a new issue for tracking. It gets confusing having multiple PRs target the same issue.
If you don't have the time to file a new issue, no worries (I do hate asking folks to fill out paperwork). I'll set a reminder for a couple days from now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#7180 ✨
ignoreablePrimitive: ['boolean'], | ||
literalPrimitive: 'true | false | null', | ||
}, | ||
].map<TSESLint.InvalidTestCase<MessageIds, Options>>( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.map
[Testing] I can't find a tracking right now, but I'm slowly getting more and more sour on generating tests this way. I'm finding it very difficult to read through them and the generation code obfuscates what the test actually does. Could you just have manually written error cases for these please?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand what you mean here, I'm all for flatting them, I thought it was how it works here based on a small sample of tests I've seen
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah :/ it's an unfortunate bit of IMO tech debt we should really clean up at some point...
…ullish-enhancment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💯 looks great, thanks for all the touchups! Sorry to keep you waiting 😅 this really is a great PR.
PR Checklist
nullable boolean
#7055Overview
Add
ignorePrimitives
option that can be set individually forstring
,boolean
,number
andbigint