Back to Biomejs

noVueReservedKeys

src/content/docs/linter/rules/no-vue-reserved-keys.mdx

latest7.7 KB
Original Source

import { Tabs, TabItem } from '@astrojs/starlight/components';

<Tabs> <TabItem label="JavaScript (and super languages)" icon="seti:javascript"> ## Summary - Rule available since: `v2.1.3` - Diagnostic Category: [`lint/correctness/noVueReservedKeys`](/reference/diagnostics#diagnostic-category) - This rule is **recommended**, meaning it is enabled by default. - This rule doesn't have a fix. - The default severity of this rule is [**error**](/reference/diagnostics#error). - This rule belongs to the following domains: - [`vue`](/linter/domains#vue) - Sources: - Same as [`vue/no-reserved-keys`](https://eslint.vuejs.org/rules/no-reserved-keys)

How to configure

json
{
	"linter": {
		"rules": {
			"correctness": {
				"noVueReservedKeys": "error"
			}
		}
	}
}

Description

Disallow reserved keys in Vue component data and computed properties.

Vue reserves certain keys for its internal use. Using these reserved keys in data properties, computed properties, methods, or other component options can cause conflicts and unpredictable behavior in your Vue components.

This rule prevents the use of Vue reserved keys such as:

  • Keys starting with $ (e.g., $el, $data, $props, $refs, etc.)
  • Keys starting with _ in data properties (reserved for Vue internals)

Examples

Invalid

vue
<script>
export default {
    data: {
        $el: '',
    },
};
</script>
<pre class="language-text"><code class="language-text">code-block.vue:3:9 <a href="https://biomejs.dev/linter/rules/no-vue-reserved-keys">lint/correctness/noVueReservedKeys</a> ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ <strong><span style="color: Tomato;">✖</span></strong> <span style="color: Tomato;">Key </span><span style="color: Tomato;"><strong>$el</strong></span><span style="color: Tomato;"> is reserved in Vue.</span> <strong>1 │ </strong>export default &#123; <strong>2 │ </strong> data: &#123; <strong><span style="color: Tomato;">&gt;</span></strong> <strong>3 │ </strong> $el: '', <strong> │ </strong> <strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong> <strong>4 │ </strong> &#125;, <strong>5 │ </strong>&#125;; <strong><span style="color: lightgreen;">ℹ</span></strong> <span style="color: lightgreen;">Rename the key to avoid conflicts with Vue reserved keys.</span> </code></pre>
vue
<script>
export default {
    data() {
        return {
            _foo: 'bar',
        };
    },
};
</script>
<pre class="language-text"><code class="language-text">code-block.vue:4:13 <a href="https://biomejs.dev/linter/rules/no-vue-reserved-keys">lint/correctness/noVueReservedKeys</a> ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ <strong><span style="color: Tomato;">✖</span></strong> <span style="color: Tomato;">Keys starting with an underscore are reserved in Vue.</span> <strong>2 │ </strong> data() &#123; <strong>3 │ </strong> return &#123; <strong><span style="color: Tomato;">&gt;</span></strong> <strong>4 │ </strong> &#95;foo: 'bar', <strong> │ </strong> <strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong> <strong>5 │ </strong> &#125;; <strong>6 │ </strong> &#125;, <strong><span style="color: lightgreen;">ℹ</span></strong> <span style="color: lightgreen;">Rename the key to avoid conflicts with Vue reserved keys.</span> </code></pre>
vue
<script>
export default {
    computed: {
        $data() {
            return this.someData;
        },
    },
};
</script>
<pre class="language-text"><code class="language-text">code-block.vue:3:9 <a href="https://biomejs.dev/linter/rules/no-vue-reserved-keys">lint/correctness/noVueReservedKeys</a> ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ <strong><span style="color: Tomato;">✖</span></strong> <span style="color: Tomato;">Key </span><span style="color: Tomato;"><strong>$data</strong></span><span style="color: Tomato;"> is reserved in Vue.</span> <strong>1 │ </strong>export default &#123; <strong>2 │ </strong> computed: &#123; <strong><span style="color: Tomato;">&gt;</span></strong> <strong>3 │ </strong> $data() &#123; <strong> │ </strong> <strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong> <strong>4 │ </strong> return this.someData; <strong>5 │ </strong> &#125;, <strong><span style="color: lightgreen;">ℹ</span></strong> <span style="color: lightgreen;">Rename the key to avoid conflicts with Vue reserved keys.</span> </code></pre>
vue
<script>
export default {
    methods: {
        $emit() {
            // This conflicts with Vue's built-in $emit
        },
    },
};
</script>
<pre class="language-text"><code class="language-text">code-block.vue:3:9 <a href="https://biomejs.dev/linter/rules/no-vue-reserved-keys">lint/correctness/noVueReservedKeys</a> ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ <strong><span style="color: Tomato;">✖</span></strong> <span style="color: Tomato;">Key </span><span style="color: Tomato;"><strong>$emit</strong></span><span style="color: Tomato;"> is reserved in Vue.</span> <strong>1 │ </strong>export default &#123; <strong>2 │ </strong> methods: &#123; <strong><span style="color: Tomato;">&gt;</span></strong> <strong>3 │ </strong> $emit() &#123; <strong> │ </strong> <strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong> <strong>4 │ </strong> // This conflicts with Vue's built-in $emit <strong>5 │ </strong> &#125;, <strong><span style="color: lightgreen;">ℹ</span></strong> <span style="color: lightgreen;">Rename the key to avoid conflicts with Vue reserved keys.</span> </code></pre>

Valid

vue
<script>
export default {
    data() {
        return {
            message: 'Hello Vue!',
            count: 0,
        };
    },
};
</script>
vue
<script>
export default {
    computed: {
        displayMessage() {
            return this.message;
        },
    },
};
</script>
</TabItem> </Tabs>