# eslint-plugin-vue
[![NPM version](https://img.shields.io/npm/v/eslint-plugin-vue.svg?style=flat)](https://npmjs.org/package/eslint-plugin-vue)
[![NPM downloads](https://img.shields.io/npm/dm/eslint-plugin-vue.svg?style=flat)](https://npmjs.org/package/eslint-plugin-vue)
[![CircleCI](https://circleci.com/gh/vuejs/eslint-plugin-vue.svg?style=svg)](https://circleci.com/gh/vuejs/eslint-plugin-vue)
> Official ESLint plugin for Vue.js
## :art: Playground on the Web
You can try this plugin on the Web.
- https://mysticatea.github.io/vue-eslint-demo/
## :grey_exclamation: Requirements
- [ESLint](http://eslint.org/) `>=3.18.0`.
- `>=4.7.0` to use `eslint --fix`.
- `>=4.14.0` to use with `babel-eslint`.
- Node.js `>=4.0.0`
## :cd: Installation
```bash
npm install --save-dev eslint eslint-plugin-vue
```
## :rocket: Usage
Create `.eslintrc.*` file to configure rules. See also: [http://eslint.org/docs/user-guide/configuring](http://eslint.org/docs/user-guide/configuring).
Example **.eslintrc.js**:
```js
module.exports = {
extends: [
// add more generic rulesets here, such as:
// 'eslint:recommended',
'plugin:vue/essential'
],
rules: {
// override/add rules settings here, such as:
// 'vue/no-unused-vars': 'error'
}
}
```
### Single File Components
ESLint only targets `.js` files by default. You must include the `.vue` extension using [the `--ext` option](https://eslint.org/docs/user-guide/configuring#specifying-file-extensions-to-lint) or a glob pattern.
Examples:
```bash
eslint --ext .js,.vue src
eslint src/**/*.{js,vue}
```
### Attention
All component-related rules are being applied to code that passes any of the following checks:
* `Vue.component()` expression
* `Vue.extend()` expression
* `Vue.mixin()` expression
* `export default {}` in `.vue` or `.jsx` file
If you however want to take advantage of our rules in any of your custom objects that are Vue components, you might need to use special comment `// @vue/component` that marks object in the next line as a Vue component in any file, e.g.:
```js
// @vue/component
const CustomComponent = {
name: 'custom-component',
template: '
'
}
```
```js
Vue.component('AsyncComponent', (resolve, reject) => {
setTimeout(() => {
// @vue/component
resolve({
name: 'async-component',
template: ''
})
}, 500)
})
```
### `eslint-disable` functionality in ``
You can use ``-like HTML comments in `` of `.vue` files. For example:
```html
```
If you want to disallow `eslint-disable` functionality, please disable [vue/comment-directive](./docs/rules/comment-directive.md) rule.
## :gear: Configs
This plugin provides four predefined configs:
- `plugin:vue/base` - Settings and rules to enable correct ESLint parsing
- `plugin:vue/essential` - Above, plus rules to prevent errors or unintended behavior
- `plugin:vue/strongly-recommended` - Above, plus rules to considerably improve code readability and/or dev experience
- `plugin:vue/recommended` - Above, plus rules to enforce subjective community defaults to ensure consistency
## :bulb: Rules
Rules are grouped by priority to help you understand their purpose. The `--fix` option on the command line automatically fixes problems reported by rules which have a wrench :wrench: below.
### Base Rules (Enabling Correct ESLint Parsing)
Enforce all the rules in this category, as well as all higher priority rules, with:
```json
{
"extends": "plugin:vue/base"
}
```
| | Rule ID | Description |
|:---|:--------|:------------|
| | [vue/comment-directive](./docs/rules/comment-directive.md) | support comment-directives in `` |
| | [vue/jsx-uses-vars](./docs/rules/jsx-uses-vars.md) | prevent variables used in JSX to be marked as unused |
### Priority A: Essential (Error Prevention)
Enforce all the rules in this category, as well as all higher priority rules, with:
```json
{
"extends": "plugin:vue/essential"
}
```
| | Rule ID | Description |
|:---|:--------|:------------|
| | [vue/no-async-in-computed-properties](./docs/rules/no-async-in-computed-properties.md) | disallow asynchronous actions in computed properties |
| | [vue/no-dupe-keys](./docs/rules/no-dupe-keys.md) | disallow duplication of field names |
| | [vue/no-duplicate-attributes](./docs/rules/no-duplicate-attributes.md) | disallow duplication of attributes |
| | [vue/no-parsing-error](./docs/rules/no-parsing-error.md) | disallow parsing errors in `` |
| | [vue/no-reserved-keys](./docs/rules/no-reserved-keys.md) | disallow overwriting reserved keys |
| :wrench: | [vue/no-shared-component-data](./docs/rules/no-shared-component-data.md) | enforce component's data property to be a function |
| | [vue/no-side-effects-in-computed-properties](./docs/rules/no-side-effects-in-computed-properties.md) | disallow side effects in computed properties |
| | [vue/no-template-key](./docs/rules/no-template-key.md) | disallow `key` attribute on `` |
| | [vue/no-textarea-mustache](./docs/rules/no-textarea-mustache.md) | disallow mustaches in `