-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
fix(eslint-plugin): [prefer-nullish-coalescing] treat enums and literals as their underlying primitive types #9376
base: main
Are you sure you want to change the base?
Conversation
…als as their underlying primitive types
Thanks for the PR, @jakebailey! 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 ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
☁️ Nx Cloud ReportCI is running/has finished running commands for commit 2cc31cd. As they complete they will appear below. Click to see the status, the terminal output, and the build insights. 📂 See all runs for this CI Pipeline Execution ✅ Successfully ran 1 targetSent with 💌 from NxCloud. |
declare const x: 0 | 1 | 0n | 1n | undefined; | ||
x || y; | ||
`, | ||
output: null, | ||
options: [ | ||
{ | ||
ignorePrimitives: { | ||
string: true, | ||
number: false, | ||
boolean: true, | ||
bigint: true, | ||
}, | ||
}, | ||
], | ||
errors: [{ messageId: 'preferNullishOverOr' }], | ||
}, |
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 believe these tests to have been wrong originally; this says "ignore bigint", and there's a bigint in the union, but the union is not ignored. Now moved up to "valid" (with the other similar tests).
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.
PR Checklist
Overview
The
ignorePrimitives
flag did not treat literals or enums as their underlying primitive types; for enum heavy codebases like TS, settingignorePrimitives
still leads to hundreds of "please use??
" errors even when applying that fix would change behavior.This PR instead uses the
-Like
flags variants, which also match against literals and enum values.I have yet to test this on TS's codebase; just trying to figure out how I can even do that locally... I'll probably just hack the published package, since this change is so small.