Skip to content

⭐️New: Add vue/require-direct-export rule #581

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

Merged
merged 7 commits into from
Jan 7, 2019

Conversation

privatenumber
Copy link
Contributor

@privatenumber privatenumber commented Sep 22, 2018

Vue SFC only allows default export where the default export must be a component object. A lot of the linting rules in this package only work when the component is directly exported like so (this is why I mark is as "essential"):

export default {
     name: 'ComponentName'
};

My team follows the Airbnb JS style, and sometimes the components are assigned to a variable before getting exported.

This rule is to deter components from being assigned to a variable before being exported so that all linting rules can be correctly applied.

Copy link
Member

@michalsnik michalsnik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the PR @hirokiosame ! It looks like a nice addition to the current set :) I have one suggestion though

meta: {
docs: {
description: 'require the component to be directly exported',
category: 'essential',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We add every new rule as uncategorized to have a nice period for testing it and introducing breaking changes if necessary, without having to wait for another major release. So I think we should change the category to undefined for the time being :) We're still in v5 beta though, so it might land in v5 after all - we'll see.

In theory it's perfectly fine to have the component assigned to a variable and then exported. You can use a special comment for determining that this is a Vue component and it will be linted properly:

// @vue/component
const ComponentA = {
  ...
}

export default ComponentA;

The way I see it - essentials are here to prevent errors. And this is technically not an error-situation so I think it would better fit in strongly-recommended :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh I didn't know about the comment. Good to know, thank you!

}
}

export default Component A
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unwanted space in Component A


## Rule Details

This rule aims to...
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please provide the short description?

@privatenumber
Copy link
Contributor Author

Hey @michalsnik Apologies for the delayed changes, but made the fixes now. Let me know if there's anything else you'd like me to do!

@michalsnik
Copy link
Member

The category @hirokiosame is still not undefined as pointed in the comment.

@michalsnik michalsnik merged commit fd4b062 into vuejs:master Jan 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants