Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Add `no-mutating-props` rule. * update * support vue3 * delete unused function Co-authored-by: Armano <armano2@users.noreply.github.com>
- Loading branch information
Showing
8 changed files
with
1,124 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
--- | ||
pageClass: rule-details | ||
sidebarDepth: 0 | ||
title: vue/no-mutating-props | ||
description: disallow mutation of component props | ||
--- | ||
# vue/no-mutating-props | ||
> disallow mutation of component props | ||
- :gear: This rule is included in all of `"plugin:vue/vue3-essential"`, `"plugin:vue/essential"`, `"plugin:vue/vue3-strongly-recommended"`, `"plugin:vue/strongly-recommended"`, `"plugin:vue/vue3-recommended"` and `"plugin:vue/recommended"`. | ||
|
||
## :book: Rule Details | ||
|
||
This rule reports mutation of component props. | ||
|
||
<eslint-code-block :rules="{'vue/no-mutating-props': ['error']}"> | ||
|
||
```vue | ||
<!-- ✗ BAD --> | ||
<template> | ||
<div> | ||
<input v-model="value" @click="openModal"> | ||
</div> | ||
</template> | ||
<script> | ||
export default { | ||
props: { | ||
value: { | ||
type: String, | ||
required: true | ||
} | ||
}, | ||
methods: { | ||
openModal() { | ||
this.value = 'test' | ||
} | ||
} | ||
} | ||
</script> | ||
``` | ||
|
||
</eslint-code-block> | ||
|
||
<eslint-code-block :rules="{'vue/no-mutating-props': ['error']}"> | ||
|
||
```vue | ||
<!-- ✓ GOOD --> | ||
<template> | ||
<div> | ||
<input :value="value" @input="$emit('input', $event.target.value)" @click="openModal"> | ||
</div> | ||
</template> | ||
<script> | ||
export default { | ||
props: { | ||
value: { | ||
type: String, | ||
required: true | ||
} | ||
}, | ||
methods: { | ||
openModal() { | ||
this.$emit('input', 'test') | ||
} | ||
} | ||
} | ||
</script> | ||
``` | ||
|
||
</eslint-code-block> | ||
|
||
<eslint-code-block :rules="{'vue/no-mutating-props': ['error']}"> | ||
|
||
```vue | ||
<script> | ||
export default { | ||
setup (props) { | ||
// ✗ BAD | ||
props.value = 'test' | ||
} | ||
} | ||
</script> | ||
``` | ||
|
||
</eslint-code-block> | ||
|
||
## :wrench: Options | ||
|
||
Nothing. | ||
|
||
## :books: Further reading | ||
|
||
- [Vue - Prop Mutation - deprecated](https://vuejs.org/v2/guide/migration.html#Prop-Mutation-deprecated) | ||
- [Style guide - Implicit parent-child communication](https://vuejs.org/v2/style-guide/#Implicit-parent-child-communication-use-with-caution) | ||
|
||
## :mag: Implementation | ||
|
||
- [Rule source](https://github.com/vuejs/eslint-plugin-vue/blob/master/lib/rules/no-mutating-props.js) | ||
- [Test source](https://github.com/vuejs/eslint-plugin-vue/blob/master/tests/lib/rules/no-mutating-props.js) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.