-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
jsx-boolean-value
: enhance configuration to handle false
literals
#3234
Comments
Why would you want them removed completely? False and undefined are distinctly different, and it’s not possible to know from the consumer side whether the component is sloppily equating the two or not. |
While I'm sure they exist, off the top of my head I can't picture a use-case where a component intentionally exhibits different behavior depending on if an optional boolean prop passed into it is In our case, optional boolean props get coerced into boolean values ( We also use Typescript, so if we wanted a component with a required boolean prop, then it'd be typed as In the situations where that doesn't work (i.e., where the prop is required rather than optional), then I think it should be possible to pass an array of prop-names to be treated as exceptions from the rule, which is something |
Any time a boolean prop is required, omitting it is an error. Typescript would enforce this as well. An eslint rule that allowed an optional false to be omitted also might not make sense, because sometimes a missing boolean defaults to true. In other words, the assumption you want to rely on is just not possible to rely on, and isn’t even necessarily the majority case. |
I don't think we'll pursue this, for the reasons indicated. |
For what it's worth, I had exactly this issue and came here searching for the same fix as well. Is it possible to reconsider? |
@tylerlaprade if the prop is a required prop, and is marked as a boolean (via propTypes and/or TS prop types), why would you need a rule here? |
@ljharb In my project, we have agreed to use
but not the other half:
I agree that this second replacement is not correct unless a project has agreed to treat all boolean props in this manner, so it should not be the default behavior of the rule, but it would be useful to us as an option. |
Hmm, that specific convention does make sense, but only when it's a boolean literal - because when it's a variable, you'd want to be able to do As an option to this rule, it would only make sense when the mode is set to "never", so it'd need to be an option that only applies to "never" things. That seems kind of weird - what would such an option be named? |
@ljharb, some possible option name suggestions if defaulting the option to
and some suggestions if defaulting the option to
|
it's more like |
Yeah, that's a good one! |
The
react/jsx-boolean-value
rule appears to only work with boolean props that have been assignedtrue
literals. However, I have a codebase that sometimes contains (as an example)<MyComponent someBooleanProp={false} ... />
Is it possible to add a configuration option for this rule to flag these instances as props that should be removed completely (maybe even with autofix)?
If not, is there perhaps another rule that can help me achieve this?
Thanks!
The text was updated successfully, but these errors were encountered: