-
-
Notifications
You must be signed in to change notification settings - Fork 669
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
New rule order-in-components
#42
Conversation
CallExpression (node) { | ||
// Vue.component('xxx', {}) || component('xxx', {}) | ||
if (!isVueComponent(node)) return | ||
checkOrder(node.arguments.slice(-1)[0].properties, orderMap, context) |
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 guess that this line can throw TypeError
if component()
with no argument exists.
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.
Good point, but I couldn't imagine such a component though. Fixed it anyway :)
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.
Many people use ESLint in editor integrations. In that case, ESLint runs on every character typing, so TypeErrors mess development experience. 😉
NewExpression (node) { | ||
// new Vue({}) | ||
if (!isVueInstance(node)) return | ||
checkOrder(node.arguments[0].properties, orderMap, context) |
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.
Same here.
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.
Fixed
lib/rules/order-in-components.js
Outdated
ExportDefaultDeclaration (node) { | ||
// export default {} in .vue || .jsx | ||
if (!isComponentFile(filePath)) return | ||
checkOrder(node.declaration.properties, orderMap, context) |
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 guess that this line can cause TypeError
if default exports without object literals (e.g. export default 777
) exists.
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.
Very good point! Fixed :)
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.
lib/rules/order-in-components.js
Outdated
docs: { | ||
description: 'Keep order of properties in components', | ||
category: 'Best Practices', | ||
recommended: 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.
I think that it needs major version if we keep recommended: 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.
yeah, I was thinking the same. So maybe we'll wait with this until other PR's are merged, and then we'll bump to 4.0.0. If it will be quite stable - then we could finally release it without the beta
tag.
I removed |
@michalsnik Will this eventually have support for components that were assigned to a variable, and then exported? eg.
|
I'm not sure yet @hirokiosame. Theoretically we could support this case, and one when you only use that component in current template, but don't even export it. But this needs further investigation, so feel free to create a proposition as separate issue. |
This PR adds new rule regarding this proposition: #13
This rule will be applied on:
export default {}
inside.vue
and.jsx
filesnew Vue({})
in any fileVue.component('xxx', {})
orcomponent('xxx', {})
in any fileThing to be noted - we won't support dynamically loaded components, as it's not so obvious to tell if it actually is or is not a vue component.