Skip to content

Rule proposal: no-arrow-functions-in-watch #1113

Closed
@alert-debug

Description

@alert-debug

Please describe what the rule should do:
According to the Vue docs, "you should not use an arrow function to define a watcher". The rule should detect when a component uses an arrow function inside the watch section. Code that doesn't follow this requirement leads to confusing errors about this not being defined.

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:

watch: {
    propShow: {
        handler: (val, oldVal) => {
            this.show = val;
        }
    }
}

(The above example is taken from an actual question asked on StackOverflow.)

watch: {
    dialog: (newState) => {
        this.$nextTick(() => {
            console.log('Tick')
        })
    }
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions