Skip to content

Rule proposal: vue/no-direct-ref-in-watch #2657

Open
@Revadike

Description

@Revadike

Please describe what the rule should do:
This rule should enforce the use of arrow functions for dependencies in the watch function in Vue 3. Instead of directly passing a ref or variable, the rule should ensure that developers use a function returning the reactive value. This will help avoid potential issues with reactive tracking and align with best practices.

What category should the rule belong to?
[ ] Enforces code style (layout)
[ ] Warns about a potential error (problem)
[X] Suggests an alternate way of doing something (suggestion)
[ ] Other (please specify:)

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

// Incorrect usage (should warn)
watch(myVar, handler)

// Correct usage
watch(() => myVar.value, handler)

Additional context
This rule would provide clear guidance for writing more consistent and reliable watch expressions in Vue 3.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions