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] jsx-boolean-value: assumeUndefinedIsFalse with never must not allow explicit true value #3757

Merged
merged 1 commit into from
Jun 1, 2024

Conversation

6uliver
Copy link
Contributor

@6uliver 6uliver commented May 14, 2024

assumeUndefinedIsFalse should not affect the behaviour of props with true values when we have the "never" setting

@ljharb
Copy link
Member

ljharb commented May 16, 2024

Can you elaborate a bit more?

@6uliver
Copy link
Contributor Author

6uliver commented May 16, 2024

Can you elaborate a bit more?

Yes, sure. I think the new test cases are self-explaining but I can give more examples here.

So if I turn on the rule with the config "never" my expectation is that I don't need to set boolean values explicitly. For true values it's very straightforward since JSX syntax makes foo to true for <App foo /> but for false values it can be tricky since the absent of a prop does not mean false but undefined so <App /> will receiveundefined instead of false for the prop foo. Because of this it's a common pattern in React that we fallback this kind of undefined boolean props to false. To support this pattern assumeUndefinedIsFalse option has been introduced here: #3234 #3675
But I think it has a bug since if I turn this flag on <App /> is working and valid and foo will be undefined in the received props which can have a fallback but <App foo /> will be invalid and will cause an ESLint error despite we used the "never" config.

Concrete examples, you can see problematic valid and invalid code in the second column highlighted with bold:

Rule config ['never', { assumeUndefinedIsFalse: true }] ['never', { assumeUndefinedIsFalse: false }]
Expected valid <App foo /> and <App /> <App foo /> and <App foo={false}/>
Expected invalid <App foo={true} /> and <App foo={false} /> <App foo={true} /> and <App />
Actual valid <App foo={true} /> and <App /> <App foo /> and <App foo={false}/>
Actual invalid <App foo /> and <App foo={false} /> <App foo={true} /> and <App />

@ljharb ljharb changed the title [Fix] jsx-boolean-value: assumeUndefinedIsFalse with never must not allow explicit true value [Fix] jsx-boolean-value: assumeUndefinedIsFalse with never must not allow explicit true value Jun 1, 2024
Copy link
Member

@ljharb ljharb left a comment

Choose a reason for hiding this comment

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

Thanks!

@ljharb ljharb merged commit a944aa5 into jsx-eslint:master Jun 1, 2024
328 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants