noVueDuplicateKeys
Summary
Section titled “Summary”- Rule available since:
v2.2.5
- Diagnostic Category:
lint/nursery/noVueDuplicateKeys
- This rule doesn’t have a fix.
- The default severity of this rule is error.
- This rule belongs to the following domains:
- Sources:
- Same as
vue/no-dupe-keys
- Same as
How to configure
Section titled “How to configure”{ "linter": { "rules": { "nursery": { "noVueDuplicateKeys": "error" } } }}
Description
Section titled “Description”Disallow duplicate keys in Vue component data, methods, computed properties, and other options.
This rule prevents the use of duplicate keys across different Vue component options
such as props
, data
, computed
, methods
, and setup
. Even if keys don’t conflict
in the script tag, they may cause issues in the template since Vue allows direct
access to these keys.
Examples
Section titled “Examples”Invalid
Section titled “Invalid”<script>export default { props: ['foo'], data() { return { foo: 'bar' }; }};</script>
code-block.vue:2:13 lint/nursery/noVueDuplicateKeys ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ Duplicate key foo found in Vue component.
1 │ export default {
> 2 │ props: [‘foo’],
│ ^^^^^
3 │ data() {
4 │ return {
ℹ Key foo is also defined here.
3 │ data() {
4 │ return {
> 5 │ foo: ‘bar’
│ ^^^
6 │ };
7 │ }
ℹ Keys defined in different Vue component options (props, data, methods, computed) can conflict when accessed in the template. Rename the key to avoid conflicts.
<script>export default { data() { return { message: 'hello' }; }, methods: { message() { console.log('duplicate key'); } }};</script>
code-block.vue:4:13 lint/nursery/noVueDuplicateKeys ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ Duplicate key message found in Vue component.
2 │ data() {
3 │ return {
> 4 │ message: ‘hello’
│ ^^^^^^^
5 │ };
6 │ },
ℹ Key message is also defined here.
6 │ },
7 │ methods: {
> 8 │ message() {
│ ^^^^^^^
9 │ console.log(‘duplicate key’);
10 │ }
ℹ Keys defined in different Vue component options (props, data, methods, computed) can conflict when accessed in the template. Rename the key to avoid conflicts.
<script>export default { computed: { count() { return this.value * 2; } }, methods: { count() { this.value++; } }};</script>
code-block.vue:3:9 lint/nursery/noVueDuplicateKeys ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ Duplicate key count found in Vue component.
1 │ export default {
2 │ computed: {
> 3 │ count() {
│ ^^^^^
4 │ return this.value * 2;
5 │ }
ℹ Key count is also defined here.
6 │ },
7 │ methods: {
> 8 │ count() {
│ ^^^^^
9 │ this.value++;
10 │ }
ℹ Keys defined in different Vue component options (props, data, methods, computed) can conflict when accessed in the template. Rename the key to avoid conflicts.
<script>export default { props: ['foo'], data() { return { bar: 'baz' }; }, methods: { handleClick() { console.log('unique key'); } }};</script>
<script>export default { computed: { displayMessage() { return this.message.toUpperCase(); } }, methods: { clearMessage() { this.message = ''; } }};</script>
Related links
Section titled “Related links”Copyright (c) 2023-present Biome Developers and Contributors.