vuejs / eslint-plugin-vue

Official ESLint plugin for Vue.js
https://eslint.vuejs.org/
MIT License
4.38k stars 649 forks source link

enforce usage of 'const' or trigger error when reassigning reactive value #2419

Open andredewaard opened 2 months ago

andredewaard commented 2 months ago

Please describe what the rule should do:

Whenever someone wants to use reactive over ref for whatever reason it is really easy to lose reactivity on that object since you can just reassign the value. Enforcing the usage of 'const' or show a message that you can't do just, just like you get an warning when reassigning a ref value without .value.

What category should the rule belong to?

[X] Enforces code style (layout) [ ] Warns about a potential error (problem) [ ] Suggests an alternate way of doing something (suggestion) [ ] Other (please specify:)

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

let data = reactive({}) // reactive assign only on const
data = {} // no error, but will lose reactivity. should throw error that this isn't possible.

// Example of enforcing this on .value which already works.
let test1 = ref({}) 
test1 = {} // Must use `.value` to read or write the value wrapped by