-
-
Notifications
You must be signed in to change notification settings - Fork 681
Add "require-default-prop" rule (fixes #122) #135
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
Conversation
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.
I was thinking how we should treat type: null
, it means any type, than undefined is valid for this case.
lib/rules/require-default-prop.js
Outdated
function findPropsWithoutDefaultValue (propsNode) { | ||
return propsNode.value.properties | ||
.filter(prop => { | ||
if (prop.value.type !== 'ObjectExpression') return true |
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.
In case of spread operator value
is going to be undefined:
TypeError: Cannot read property 'type' of undefined
export default {
props: {
a: {
...test
}
}
}
*/ | ||
function propHasDefault (prop) { | ||
const propDefaultNode = prop.value.properties | ||
.find(p => p.key.name === 'default') |
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.
In case of spread operator key
is going to be undefined:
TypeError: Cannot read property 'name' of undefined
export default {
props: {
...test
}
}
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.
Ah, I totally forgot about this case.. Thanks for the heads up @armano2 :)
lib/rules/require-default-prop.js
Outdated
p.key.name === 'props' | ||
) | ||
|
||
if (!propsNode || propsNode.value.type !== 'ObjectExpression') return |
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.
you can move propsNode.value.type !== 'ObjectExpression'
into find
@michalsnik there is few issues when someone is going to use spread operator in props |
453490c
to
624e8cd
Compare
@armano2 thanks for the review! Can you please check once again? Btw. regarding:
I don't check |
This PR implements
require-default-prop
rule, that was proposed in #122.cc @armano2