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

Computed Side Effects false positives #431

Open
sevenmay opened this issue Oct 25, 2024 · 4 comments
Open

Computed Side Effects false positives #431

sevenmay opened this issue Oct 25, 2024 · 4 comments
Assignees
Labels
bug Something isn't working

Comments

@sevenmay
Copy link

The "Computed Side Effects" rule produces false positives.

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

const str1 = ref('abc');

const str2 = computed(() => {
  const inner = 'def';
  return str1.value + inner;
});
</script>

<template>
  <div>
    <p>Test</p>
    <p>{{ str1 }}</p>
    <p>{{ str2 }}</p>
  </div>
</template>

The problem is const inner = 'def';.

image

Node v20.10.0
vue-mess-detector v0.63.1

Thanks, great job!

@sevenmay sevenmay added the bug Something isn't working label Oct 25, 2024
@rrd108
Copy link
Owner

rrd108 commented Oct 25, 2024

Thanks for reporting.

Do you want to send a PR with a failing test or a fix?

@sevenmay
Copy link
Author

This regex \b(set|push|pop|shift|unshift|splice|reverse|sort)\b|(?<!=)=(?!=) simply matches assignments, ex: = in const mult = 3;.

The rule "Computed Side Effects" is quite complicated to check: ref, reactive, direct assignment, assignment calling a method, etc.
I don't know how far you want to go.

For example, how do you find a mutation made by calling a method?

Even checking the mutation of a property in a reactive object is complicated. How do you differentiate between a local object (scoped in the computed body) and a reactive object?

Maybe it's better to narrow the scope and call it "Mutate ref in computed" and check only for .value = .

@David-Pena
Copy link
Collaborator

What do you think? @rrd108

@rrd108
Copy link
Owner

rrd108 commented Nov 2, 2024

I think we should keep the rule and we can incremently add suportfor all the different use cases.

Defining a varibale inside a computed property is not really a good practice, but I can understand why it is there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants