question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Rule proposition: `no-side-effects-in-computed-properties`

See original GitHub issue

This rule would check if there are no side effects inside computed properties.

So this example would throw an error:

export default {
  computed: {
    hello() {
      this.lastName = 'Dolor' // <- error "Unexpected side effect in computed property 'hello'"
      return `Hello ${this.firstName} ${this.lastName}`
    }
  },
  data() {
    return {
      firstName: 'Lorem',
      lastName: 'Ipsum'
    }
  }
}

What do you think @mysticatea @chrisvfritz ?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:5
  • Comments:17 (14 by maintainers)

github_iconTop GitHub Comments

4reactions
LinusBorgcommented, Jun 28, 2017

Would this rule also check for things like:

export default {
  computed: {
    hello() {
      this.sideEffect() // <- error "Unexpected side effect in computed property 'hello'"
      const formattedValue = this.format(value) // <- no error
      return `Hello ${this.firstName} ${this.lastName}`
    }
  },
methods: {
  sideEffect() {
    // some side effect.
  },
  format(value) {
    return // ...
  }
}

3reactions
michalsnikcommented, Jul 19, 2017

Ready in v3.6.0 🚀 Let’s leave such edge cases for further consideration, we need to be agile and constantly improve those rules starting with simple solutions. I’m going to move those ideas to separate issue and closing this one. Thanks for a great discussion here guys!

Read more comments on GitHub >

github_iconTop Results From Across the Web

vue/no-side-effects-in-computed-properties
This rule is aimed at preventing the code which makes side effects in computed properties and functions. It is considered a very bad...
Read more >
How to fix vue/no-side-effects-in-computed-properties?
1. Remove the ESLint rule. Just add // eslint-disable-next-line vue/no-side-effects-in-computed-properties in the line above the line that ...
Read more >
vue/no-side-effects-in-computed-properties | eslint-plugin-vue
This rule is aimed at preventing the code which makes side effects in computed properties. It is considered a very bad practice to...
Read more >
How to fix vue/no-side-effects-in-computed-properties?-Vue.js
ESLint throws this warning (or error - depending on your setup), because an unwanted side-effect is there in your computed property, namely: you...
Read more >
3 Anti-Patterns to avoid in Vue.js - Binarcode
Side effects inside computed properties ... We mutate the prop without letting the parent now about it; We might get unexpected behavior or...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found