-
-
Notifications
You must be signed in to change notification settings - Fork 668
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
feat: add no-required-prop-with-default
rule
#1943
Conversation
Maybe we should add this rule in vue2 and vue3 presets. |
EDIT: Thank you for this PR. I think a rule that checks for unnecessary defaults would be useful. However, I think it would be better to be able to check other than <script>
export default {
props: {
foo: {
required: true,
default: 42
}
}
}
</script> <script setup>
defineProps({
foo: {
required: true,
default: 42
}
})
</script> In this case, don't use |
Regarding the design: I think that design might be more performant as all the checks are done in one pass. What do you think? |
Hmm... I think it's a good idea to follow the precedent, but I think the name |
@neferqiqi can you change this PR? |
ok, i will change the rule to supoort the case
but i want to reserve the auto-fix. Because firstly, it only fix the props in current file, so it's safe to auto fix; secondly, for example in my project, there are many cases that assign default values to required props, i think need a auto fix way to fix these cases. what do you think? :) |
I don't think it should auto-fix. As I wrote earlier, it's because we don't know which of the two methods the user intended. However, I do understand that your team need auto-fix. What do you think of adding an option to enable auto-fix? |
ok, i will add an option to enable auto-fix. |
no-required-prop-with-default
rule
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.
Looks good to me, apart from some smaller remarks. Is this now ready to be merged?
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.
LGTM! Thank you!
This rule enforce props with default values to be optional.
Because when a required prop declared with a default value, but it doesn't be passed value when using it, it will be assigned the default value. So a required prop with default value is same as a optional prop.