Skip to content

noVueComputedPropertyCall (JavaScript)

Language JavaScript (and super languages)
biome.json
{
"linter": {
"rules": {
"nursery": {
"noVueComputedPropertyCall": "error"
}
}
}
}

Disallow calling a Vue computed property whose value is not a function.

A computed property is read like a regular property: this.total in the script, or total in the template. Vue runs its getter and gives you the value the getter returns. Adding parentheses, as in this.total(), calls that value. When the value is a string, a number, an object, or anything else that is not a function, the call throws a TypeError when the code runs.

This rule reports a call to a computed property when every value its getter can return is something other than a function. The rule follows what the getter returns through data, props, methods and other computed properties of the component. It doesn’t report the call when it can’t tell what the value is, for example when the getter returns the result of an imported function.

import { defineComponent } from "vue";
export default defineComponent({
data() {
return { price: 10, quantity: 2 };
},
computed: {
total() {
return this.price * this.quantity;
},
},
methods: {
logTotal() {
console.log(this.total());
},
},
});
code-block.js:14:19 lint/nursery/noVueComputedPropertyCall ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

✖ The computed property total is called like a method, but its value is not a function.

12 │ methods: {
13 │ logTotal() {
> 14 │ console.log(this.total());
│ ^^^^^^^^^^^^
15 │ },
16 │ },

ℹ Vue gives you the value that the getter of a computed property returns. Calling a value that is not a function throws an error when the code runs.

ℹ Remove the parentheses and the arguments to read the value of the computed property.

ℹ This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.

import { defineComponent } from "vue";
export default defineComponent({
data() {
return { price: 10, quantity: 2 };
},
computed: {
total() {
return this.price * this.quantity;
},
formatter() {
return (value) => `$${value}`;
},
},
methods: {
logTotal() {
console.log(this.total);
console.log(this.formatter(this.total));
},
},
});