Skip to content

Add no-shared-component-data rule. #84

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 3 commits into from
Jul 23, 2017

Conversation

armano2
Copy link
Contributor

@armano2 armano2 commented Jul 16, 2017

This PR implements rules proposed in #79

DONE:

  • Create documtation
  • Add tests
  • Implement rule

Importnant:

This rule splits executeOnVueComponent into executeOnVueInstance and executeOnVueComponent and adds alias executeOnVue

  • if you want to process only Vue components use utils.executeOnVueComponent
  • if you want to process only new Vue use utils.executeOnVueInstance
  • If you want to process both use utils.executeOnVue

@armano2 armano2 changed the title WIP: Add component-date rule. Add component-date rule. Jul 16, 2017
@armano2 armano2 changed the title Add component-date rule. Add component-data rule. Jul 16, 2017
@armano2 armano2 force-pushed the patch-8-component-data branch from 89f7ec3 to 8f4c945 Compare July 19, 2017 16:20
@armano2
Copy link
Contributor Author

armano2 commented Jul 19, 2017

@michalsnik cleaned up and merged

@mysticatea
Copy link
Member

I'm considering the rule name. In general, eslint rules which disallow something starts with no-.

I don't have the best idea, but maybe no-shared-component-data?
I guess that it's shared by component instances if the data is not a function.

@armano2
Copy link
Contributor Author

armano2 commented Jul 19, 2017

@mysticatea no-shared-component-data make more sense than component-data, i will rename it

@armano2 armano2 changed the title Add component-data rule. Add no-shared-component-data rule. Jul 19, 2017
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.

Few minor suggestions @armano2

).forEach(cp => {
context.report({
node: cp.value,
message: 'Component `data` must be a function.'
Copy link
Member

Choose a reason for hiding this comment

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

What do you think about changing the message to:
data property in component must be a function

module.exports = {
meta: {
docs: {
description: 'Enforces that a component data must be a function',
Copy link
Member

Choose a reason for hiding this comment

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

component's

@@ -0,0 +1,33 @@
# Enforces that a component data must be a function (no-shared-component-data)
Copy link
Member

Choose a reason for hiding this comment

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

What about: Enforces component's data property to be a function ?

@@ -0,0 +1,51 @@
/**
* @fileoverview When using the data property on a component (i.e. anywhere except on new Vue), the value must be a function that returns an object.
Copy link
Member

Choose a reason for hiding this comment

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

I'd use the same title as in documentation

p.key.name === 'data' &&
p.value.type !== 'FunctionExpression' &&
p.value.type !== 'Identifier'
).forEach(cp => {
Copy link
Member

Choose a reason for hiding this comment

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

Move .forEach to new line for consistency

@armano2 armano2 force-pushed the patch-8-component-data branch from 5992614 to 7453a77 Compare July 22, 2017 12:29
@armano2
Copy link
Contributor Author

armano2 commented Jul 22, 2017

@michalsnik suggestions applied + i rebased changes and applied executeOnVueInstance, executeOnVueComponent, executeOnVue to already merged code.

// Public
// ----------------------------------------------------------------------

return Object.assign({},
Copy link
Member

Choose a reason for hiding this comment

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

Object.assign seems to be redundant

@armano2
Copy link
Contributor Author

armano2 commented Jul 23, 2017

@michalsnik fixed

@michalsnik michalsnik merged commit 1ea1396 into vuejs:master Jul 23, 2017
@armano2 armano2 deleted the patch-8-component-data branch July 23, 2017 13:49
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.

3 participants