Skip to content
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

Rule Proposal: order-in-computed #901

Open
1 of 4 tasks
lennoximus opened this issue Jun 3, 2019 · 0 comments
Open
1 of 4 tasks

Rule Proposal: order-in-computed #901

lennoximus opened this issue Jun 3, 2019 · 0 comments

Comments

@lennoximus
Copy link

lennoximus commented Jun 3, 2019

Please describe what the rule should do:

Allows to choose order of computed properties which can be defined in several manners, such as:

  • "Typical" computed. Properties that were defined by using a simple return expression like
computed: {
  messages () {
    return this.$store.state.user.messages
  }
}
  • Computed properties with custom getters/setters. E.g.
computed: {
  messages: {
    get () {
      return this.$store.state.user.messages
    },
    set (newValue) {
      this.$store.commit('SET_USER_MESSAGES', newValue)
    }
  }
}
  • Computed properties described by Vuex mapState and mapGetters helpers.
computed: {
  ...mapGetters(['isAuthorized']),
  ...mapState({
    userStatus: state => state.user.status
  })
}

Rule should add an opportunity to enforce the same code style by ordering these different definition types of computed properties in desired sequence.

What category should the rule belong to?

  • Enforces code style
  • Warns about a potential error
  • Suggests an alternate way of doing something
  • Other (please specify:)

Provide 2-3 code examples that this rule should warn about:

  • With order: ['mapGetters', 'mapState', 'getters/setters', 'normal'] passed as configuration.
// Bad.

messages: {
  get () {
    return this.$store.state.user.messages
  },
  set (newValue) {
    this.$store.commit('SET_USER_MESSAGES', newValue)
  }
},
hideHeader () {
  return this.$route.meta.hideHeader
},
...mapGetters(['isAuthorized']),
...mapState({
  userStatus: state => state.user.status,
  nextStep: state => state.user.next_step
}),
noAuthRequired () {
  return this.$route.meta.noAuthRequired
}
// Good.

...mapGetters(['isAuthorized']),
...mapState({
  userStatus: state => state.user.status,
  nextStep: state => state.user.next_step
}),
messages: {
  get () {
    return this.$store.state.user.messages
  },
  set (newValue) {
    this.$store.commit('SET_USER_MESSAGES', newValue)
  }
},
hideHeader () {
  return this.$route.meta.hideHeader
},
noAuthRequired () {
  return this.$route.meta.noAuthRequired
}
@lennoximus lennoximus changed the title order-in-computed Rule Proposal: order-in-computed Jun 3, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants