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

fix(eslint-plugin): [prefer-nullish-coalescing] treat enums and literals as their underlying primitive types #9376

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

Conversation

jakebailey
Copy link
Collaborator

@jakebailey jakebailey commented Jun 17, 2024

PR Checklist

Overview

The ignorePrimitives flag did not treat literals or enums as their underlying primitive types; for enum heavy codebases like TS, setting ignorePrimitives 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.

@typescript-eslint
Copy link
Contributor

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.

Copy link

netlify bot commented Jun 17, 2024

Deploy Preview for typescript-eslint ready!

Name Link
🔨 Latest commit 2cc31cd
🔍 Latest deploy log https://app.netlify.com/sites/typescript-eslint/deploys/6670b449f0df1a00084f1a86
😎 Deploy Preview https://deploy-preview-9376--typescript-eslint.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
Lighthouse
Lighthouse
1 paths audited
Performance: 98 (no change from production)
Accessibility: 100 (no change from production)
Best Practices: 92 (no change from production)
SEO: 90 (no change from production)
PWA: 80 (no change from production)
View the detailed breakdown and full score reports

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link

nx-cloud bot commented Jun 17, 2024

☁️ Nx Cloud Report

CI 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 target

Sent with 💌 from NxCloud.

@jakebailey
Copy link
Collaborator Author

jakebailey commented Jun 17, 2024

Comment on lines 1243 to 1162
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' }],
},
Copy link
Collaborator Author

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

Copy link
Member

@JoshuaKGoldberg JoshuaKGoldberg left a comment

Choose a reason for hiding this comment

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

Steve Carrell and Will Ferrell happily exclaiming "super duper!"

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.

Bug: [prefer-nullish-coalescing] ignorePrimitives does not apply to literals or enums
2 participants