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

vue/no-side-effects-in-computed-properties with composition api's computed #1393

Closed
sapphi-red opened this issue Dec 29, 2020 · 1 comment · Fixed by #1407
Closed

vue/no-side-effects-in-computed-properties with composition api's computed #1393

sapphi-red opened this issue Dec 29, 2020 · 1 comment · Fixed by #1407

Comments

@sapphi-red
Copy link
Contributor

What rule do you want to change?
vue/no-side-effects-in-computed-properties

Does this change cause the rule to produce more or fewer warnings?
more warnings

How will the change be implemented? (New option, new default behavior, etc.)?
new default behavior

Please provide some example code that this change will affect:

<script>
import { defineComponent, ref, computed } from 'vue'

export default defineComponent({
  setup() {
    const arr = ref(['aaa', 'b', 'c'])
    const sorted = computed(() => arr.value.sort((a,b) => a.length - b.length)) // here arr is being mutated
    return { sorted }
  }
})
</script>

What does the rule currently do for this code?
no warning

What will the rule do after it's changed?
show warning like computed properties

Additional context

Actually, this new feature does not affect computed properties, so it might have to be a new rule.

@sapphi-red
Copy link
Contributor Author

sapphi-red commented Dec 29, 2020

I think vue/return-in-computed-property and vue/no-async-in-computed-properties have the same thing with this.
Should I create another issue?

sapphi-red added a commit to sapphi-red/eslint-plugin-vue that referenced this issue Dec 30, 2020
ota-meshi pushed a commit that referenced this issue Jan 3, 2021
…mputed-properties refs #1393 (#1398)

* Add composition api's computed function support to vue/no-async-in-computed-properties refs #1393

* rename getComputedGetterBody to getGetterBodyFromComputedFunction

* add testcase without return

* use array instead of set
sapphi-red added a commit to sapphi-red/eslint-plugin-vue that referenced this issue Jan 3, 2021
sapphi-red added a commit to sapphi-red/eslint-plugin-vue that referenced this issue Jan 3, 2021
sapphi-red added a commit to sapphi-red/eslint-plugin-vue that referenced this issue Jan 3, 2021
ota-meshi pushed a commit that referenced this issue Jan 21, 2021
…s-in-computed-properties close #1393 (#1407)

* Add composition api's computed function support to vue/no-side-effects-in-computed-properties close #1393

* check targetBody

* fix false negative with arr.reverse()

* only report variables declared inside setup
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants