-
-
Notifications
You must be signed in to change notification settings - Fork 679
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
Boolean props should be false by default always. (require-default-prop) #222
Comments
This is a really interesting proposal @jpickwell. I agree that setting default value for What do you think about this @chrisvfritz ? It might be a good practice to add in the styleguide, as it would definitely improve consistency in components APIs. |
If we do include it, I think it should be a new rule, but probably not part of the style guide. I agree that most defaults should be false, but there are legitimate exceptions. For example, you may have an alert component that you want to be dismissible 99% of the time in your app. But sometimes, you want notifications that aren't dismissible, so you make the behavior optional with a new |
I really like this proposal, and to be honest I have never thought of the boolean properties this way. But it does make a lot of sense! Let's say we have a star-rating component which simply displays the 5-star rating and the total amount of ratings. Now sometimes you only need to show the stars, without the total count. With this idiomatic stuff in mind you can either create a But I also understand that this is maybe too early or too "opinionated" to include this into the style guide. But as said, I really like this proposal and would love to see it as one of the available rules! |
I feel that this is a good idea 👍, but it should be separated from |
@chrisvfritz This prop could be named <alert dismissible="false">You have to accept our new terms to continue using XY.</alert>
<!-- vs -->
<alert persistent>You have to accept our new terms to continue using XY.</alert> I can't think of a single situation where this problem cannot be solved by renaming the prop. I think that with the right error message this rule could really benefit developers, especially if it includes a tip like this:
If I find the time, I might have a shot at implementing this rule. |
Feel free to create such rule @shroudedcode ! It would be appreciated :) And we'll ignore |
Just checking in on all the new rule proposals. What does everything think about calling this |
I strongly disagree with this, but unfortunately it's a common pattern of 'false by default', which was taken up by HTML with things like There are two problems with this 'negative by default', both stemming from not designing an interface 'positively'. Property names should represent the 'positive' state of the concept being represented (even when the most likely value is the 'false' of that state). Making a property false by default induces unnecessary extra cognitive load by making the user have to work out what the true value of a negative concept is- it's not how people think. For example, one often sees something like this: One can't look at that and immediately know the state. For instance,'Today is Tuesday? Can I click on the control?' Whereas: It is much better (IMHO) to work out the positive concept. After all, with something like Interfaces, on the whole allow you to do things, designing an interface around what you can't do, it's much of a user journey. By taking a 'positive' approach, it does force one to think what the purpose and journey of a concept is- by thinking 'how can I name this positively', it makes one think a bit more deeply about what you're trying to achieve and whether it's the appropriate way. |
@chrisvfritz I'm a bit confused here, am I right in thinking that on the one hand you're saying that the default value of
I fully agree with this, but I can't see the sense in saying 'the default value of false means it will actually do the opposite of the natural-language meaning'.
So, the correct implementation is:
Again, I really don't see this. By default I'm not hiding the text. Thinking negatively about things is really hard. The default position should be to show the text and then there should be a few occasions when you don't show the text. This You end up with a Alice-in-Wonderland sort of situation, it's like having this conversation with someone:
You may have guessed that this is my No 1 bugbear in software dev. Hopefully I haven't misunderstood everything. |
@Worthaboutapig It's perfectly fine not to like this style - as an uncategorized rule, the only way for it to be active would be if you explicitly chose to include it. 🙂 |
It looks like this issue had been covered by the new rule |
It is covered by |
Tell us about your environment
Please show your full configuration:
What did you do? Please include the actual source code causing the issue.
What did you expect to happen?
An error should be shown for the
showText
prop indicating that it should not have a default oftrue
. TheautoPlay
prop should considered correct even with therequire-default-prop
rule turned on.What actually happened? Please include the actual, raw output from ESLint.
With the
require-default-prop
rule enabled,autoPlay
will be flagged.showText
will be considered correct.To make Vue components work like idiomatic HTML elements
Boolean
attributes/props should always default tofalse
. If aBoolean
prop defaults totrue
then a user who wants to turn that prop off has to bind the prop to a constantfalse
(e.g.,:show-text="false"
).The
require-default-prop
rule would need to be modified to either enforce this, or ignoreBoolean
props. If the rule ignoresBoolean
props, then a new rule could be added to enforce properBoolean
props.Boolean
props should also never be required.someBooleanProp: Boolean
is how allBoolean
props should be declared. There's no need for any other prop options.At the very least, something should be added to the rules to allow enforcing this. I also believe this rule should be added to the Style Guide.
The text was updated successfully, but these errors were encountered: