Back to Biomejs

noVueReservedProps

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

latest7.1 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.2` - Diagnostic Category: [`lint/correctness/noVueReservedProps`](/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-props`](https://eslint.vuejs.org/rules/no-reserved-props)

How to configure

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

Description

Disallow reserved names to be used as props.

Vue reserves certain prop names for its internal use. Using these reserved names as prop names can cause conflicts and unexpected behavior in your Vue components.

This rule prevents the use of the following reserved prop names:

  • key - Used by Vue for list rendering and component identification
  • ref - Used by Vue for template refs

Examples

Invalid

vue
<script setup>
defineProps({
    ref: String,
});
</script>
<pre class="language-text"><code class="language-text">code-block.vue:2:5 <a href="https://biomejs.dev/linter/rules/no-vue-reserved-props">lint/correctness/noVueReservedProps</a> ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ <strong><span style="color: Tomato;">✖</span></strong> <span style="color: Tomato;"><strong>ref</strong></span><span style="color: Tomato;"> is a reserved attribute and cannot be used as props.</span> <strong>1 │ </strong>defineProps(&#123; <strong><span style="color: Tomato;">&gt;</span></strong> <strong>2 │ </strong> ref: String, <strong> │ </strong> <strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong> <strong>3 │ </strong>&#125;); <strong>4 │ </strong> <strong><span style="color: lightgreen;">ℹ</span></strong> <span style="color: lightgreen;">Rename the prop to avoid possible conflicts.</span> </code></pre>
js
import {defineComponent} from 'vue';

export default defineComponent({
    props: [
        'key',
    ]
});
<pre class="language-text"><code class="language-text">code-block.js:5:9 <a href="https://biomejs.dev/linter/rules/no-vue-reserved-props">lint/correctness/noVueReservedProps</a> ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ <strong><span style="color: Tomato;">✖</span></strong> <span style="color: Tomato;"><strong>key</strong></span><span style="color: Tomato;"> is a reserved attribute and cannot be used as props.</span> <strong>3 │ </strong>export default defineComponent(&#123; <strong>4 │ </strong> props: [ <strong><span style="color: Tomato;">&gt;</span></strong> <strong>5 │ </strong> 'key', <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>6 │ </strong> ] <strong>7 │ </strong>&#125;); <strong><span style="color: lightgreen;">ℹ</span></strong> <span style="color: lightgreen;">Rename the prop to avoid possible conflicts.</span> </code></pre>
vue
<script setup lang="ts">
defineProps<{
    ref: string,
}>();
</script>
<pre class="language-text"><code class="language-text">code-block.vue:2:5 <a href="https://biomejs.dev/linter/rules/no-vue-reserved-props">lint/correctness/noVueReservedProps</a> ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ <strong><span style="color: Tomato;">✖</span></strong> <span style="color: Tomato;"><strong>ref</strong></span><span style="color: Tomato;"> is a reserved attribute and cannot be used as props.</span> <strong>1 │ </strong>defineProps&lt;&#123; <strong><span style="color: Tomato;">&gt;</span></strong> <strong>2 │ </strong> ref: string, <strong> │ </strong> <strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong> <strong>3 │ </strong>&#125;&gt;(); <strong>4 │ </strong> <strong><span style="color: lightgreen;">ℹ</span></strong> <span style="color: lightgreen;">Rename the prop to avoid possible conflicts.</span> </code></pre>
vue
<script>
export default {
    props: {
        key: String,
    }
};
</script>
<pre class="language-text"><code class="language-text">code-block.vue:3:9 <a href="https://biomejs.dev/linter/rules/no-vue-reserved-props">lint/correctness/noVueReservedProps</a> ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ <strong><span style="color: Tomato;">✖</span></strong> <span style="color: Tomato;"><strong>key</strong></span><span style="color: Tomato;"> is a reserved attribute and cannot be used as props.</span> <strong>1 │ </strong>export default &#123; <strong>2 │ </strong> props: &#123; <strong><span style="color: Tomato;">&gt;</span></strong> <strong>3 │ </strong> key: String, <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 prop to avoid possible conflicts.</span> </code></pre>

Valid

js
import {defineComponent} from 'vue';

export default defineComponent({
    props: ['foo']
});
vue
<script setup>
defineProps({ foo: String });
</script>
vue
<script setup lang="ts">
defineProps<{
    foo: string,
    bar: string,
}>();
</script>
vue
<script>
export default {
    props: {
        foo: String,
        bar: String,
    }
};
</script>
</TabItem> </Tabs>