diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 000000000..872909c93 --- /dev/null +++ b/.eslintignore @@ -0,0 +1,2 @@ +node_modules +lib/recommended-rules.js diff --git a/.eslintrc.js b/.eslintrc.js new file mode 100644 index 000000000..0d0779434 --- /dev/null +++ b/.eslintrc.js @@ -0,0 +1,22 @@ +module.exports = { + root: true, + parserOptions: { + ecmaVersion: 6 + }, + env: { + node: true, + mocha: true + }, + extends: [ + 'plugin:eslint-plugin/recommended', + 'plugin:vue-libs/recommended' + ], + plugins: [ + 'eslint-plugin' + ], + rules: { + 'eslint-plugin/report-message-format': ['error', '^[A-Z].*\\.$'], + 'eslint-plugin/prefer-placeholders': 'error', + 'eslint-plugin/consistent-output': 'error' + } +} diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 000000000..6313b56c5 --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +* text=auto eol=lf diff --git a/.gitignore b/.gitignore index fd4f2b066..0f23426ce 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ -node_modules -.DS_Store +/.nyc_output +/coverage +/node_modules +/test.* diff --git a/LICENSE b/LICENSE index 32cc6c272..c914149a6 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ -The MIT License (MIT) +MIT License -Copyright (c) 2016 Evan You +Copyright (c) 2017 Toru Nagashima Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -9,13 +9,13 @@ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md index f61d40bdb..bd50cf3e7 100644 --- a/README.md +++ b/README.md @@ -1,34 +1,138 @@ # eslint-plugin-vue -ESLint plugin for Vue.js projects +[![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) -## Usage +> Official ESLint plugin for Vue.js -1. `npm install --save-dev eslint-plugin-vue` -2. create a file named `.eslintrc` in your project: +## :exclamation: Attention - this is documentation for beta `3.0.0` :exclamation: + +This branch contains `eslint-plugin-vue@beta` which is pre-released `3.0`, but it's not the default version that you get with `npm install eslint-plugin-vue`. In order to install this you need to specify either `"eslint-plugin-vue": "beta"` in `package.json` or do `npm install eslint-plugin-vue@beta`. + +Please try it and report any issues that you might experience. + +If you want to check previous releases [go here](https://github.com/vuejs/eslint-plugin-vue/releases). + +## :grey_exclamation: Requirements + +- [ESLint](http://eslint.org/) `>=3.18.0`. +- Node.js `>=4.0.0` + +## :cd: Installation -```js -{ - extends: [ /* your usual extends */ ], -  plugins: ["vue"], - rules: { -    'vue/jsx-uses-vars': 2, - }, -} ``` -3. OPTIONAL: install [eslint-config-vue](https://github.com/vuejs/eslint-config-vue): `npm install --save-dev eslint-config-vue` -4. OPTIONAL: then use the recommended configurations in your `.eslintrc`: - -```js -{ -  extends: ["vue", /* your other extends */], -  plugins: ["vue"], -  rules: { -    /* your overrides -- vue/jsx-uses-vars is included in eslint-config-vue */ -  }, +npm install --save-dev eslint eslint-plugin-vue@beta +``` + +## :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**: + +```javascript +module.exports = { + extends: [ + 'eslint:recommended', + 'plugin:vue/recommended' // or 'plugin:vue/base' + ], + rules: { + // override/add rules' settings here + 'vue/no-invalid-v-if': 'error' + } } ``` -## License +## ⚙ Configs + +This plugin provides two predefined configs: +- `plugin:vue/base` - contains necessary settings for this plugin to work properly +- `plugin:vue/recommended` - extends base config with recommended rules (the ones with check mark :white_check_mark: in the table below) + +## :bulb: Rules + +Rules are grouped by category to help you understand their purpose. + +No rules are enabled by `plugin:vue/base` config. The `plugin:vue/recommended` config enables rules that report common problems, which have a check mark :white_check_mark: below. + +The `--fix` option on the command line automatically fixes problems reported by rules which have a wrench :wrench: below. + + + +### Best Practices + +| | Rule ID | Description | +|:---|:--------|:------------| +| :wrench: | [html-end-tags](./docs/rules/html-end-tags.md) | enforce end tag style. | +| :white_check_mark::wrench: | [html-no-self-closing](./docs/rules/html-no-self-closing.md) | disallow self-closing elements. | +| :white_check_mark: | [no-confusing-v-for-v-if](./docs/rules/no-confusing-v-for-v-if.md) | disallow confusing `v-for` and `v-if` on the same element. | +| | [no-duplicate-attributes](./docs/rules/no-duplicate-attributes.md) | disallow duplicate arguments. | +| :white_check_mark: | [no-textarea-mustache](./docs/rules/no-textarea-mustache.md) | disallow mustaches in ` + +
+ +
+ + +``` + +## 🔧 Options + +Nothing. + +## 👫 Related rules + +- [no-parsing-error] + + +[no-parsing-error]: no-parsing-error.md diff --git a/docs/rules/no-invalid-v-on.md b/docs/rules/no-invalid-v-on.md new file mode 100644 index 000000000..38da1e6e6 --- /dev/null +++ b/docs/rules/no-invalid-v-on.md @@ -0,0 +1,48 @@ +# Disallow invalid v-on directives (no-invalid-v-on) + +This rule checks whether every `v-on` directive is valid. + +## 📖 Rule Details + +This rule reports `v-on` directives if the following cases: + +- The directive does not have that event name. E.g. `
` +- The directive has invalid modifiers. E.g. `
` +- The directive does not have that attribute value. E.g. `
` + +This rule does not check syntax errors in directives because it's checked by [no-parsing-error] rule. + +👎 Examples of **incorrect** code for this rule: + +```html + +``` + +👍 Examples of **correct** code for this rule: + +```html + +``` + +## 🔧 Options + +Nothing. + +## 👫 Related rules + +- [no-parsing-error] + + +[no-parsing-error]: no-parsing-error.md diff --git a/docs/rules/no-invalid-v-once.md b/docs/rules/no-invalid-v-once.md new file mode 100644 index 000000000..8f5ab7b13 --- /dev/null +++ b/docs/rules/no-invalid-v-once.md @@ -0,0 +1,37 @@ +# Disallow invalid v-once directives (no-invalid-v-once) + +This rule checks whether every `v-once` directive is valid. + +## 📖 Rule Details + +This rule reports `v-once` directives if the following cases: + +- The directive has that argument. E.g. `
` +- The directive has that modifier. E.g. `
` +- The directive has that attribute value. E.g. `
` + +👎 Examples of **incorrect** code for this rule: + +```html + +``` + +👍 Examples of **correct** code for this rule: + +```html + +``` + +## 🔧 Options + +Nothing. diff --git a/docs/rules/no-invalid-v-pre.md b/docs/rules/no-invalid-v-pre.md new file mode 100644 index 000000000..989120333 --- /dev/null +++ b/docs/rules/no-invalid-v-pre.md @@ -0,0 +1,37 @@ +# Disallow invalid v-pre directives (no-invalid-v-pre) + +This rule checks whether every `v-pre` directive is valid. + +## 📖 Rule Details + +This rule reports `v-pre` directives if the following cases: + +- The directive has that argument. E.g. `
` +- The directive has that modifier. E.g. `
` +- The directive has that attribute value. E.g. `
` + +👎 Examples of **incorrect** code for this rule: + +```html + +``` + +👍 Examples of **correct** code for this rule: + +```html + +``` + +## 🔧 Options + +Nothing. diff --git a/docs/rules/no-invalid-v-show.md b/docs/rules/no-invalid-v-show.md new file mode 100644 index 000000000..1a13ef881 --- /dev/null +++ b/docs/rules/no-invalid-v-show.md @@ -0,0 +1,46 @@ +# Disallow invalid v-show directives (no-invalid-v-show) + +This rule checks whether every `v-show` directive is valid. + +## 📖 Rule Details + +This rule reports `v-show` directives if the following cases: + +- The directive has that argument. E.g. `
` +- The directive has that modifier. E.g. `
` +- The directive does not have that attribute value. E.g. `
` + +This rule does not check syntax errors in directives because it's checked by [no-parsing-error] rule. + +👎 Examples of **incorrect** code for this rule: + +```html + +``` + +👍 Examples of **correct** code for this rule: + +```html + +``` + +## 🔧 Options + +Nothing. + +## 👫 Related rules + +- [no-parsing-error] + + +[no-parsing-error]: no-parsing-error.md diff --git a/docs/rules/no-invalid-v-text.md b/docs/rules/no-invalid-v-text.md new file mode 100644 index 000000000..39e966202 --- /dev/null +++ b/docs/rules/no-invalid-v-text.md @@ -0,0 +1,46 @@ +# Disallow invalid v-text directives (no-invalid-v-text) + +This rule checks whether every `v-text` directive is valid. + +## 📖 Rule Details + +This rule reports `v-text` directives if the following cases: + +- The directive has that argument. E.g. `
` +- The directive has that modifier. E.g. `
` +- The directive does not have that attribute value. E.g. `
` + +This rule does not check syntax errors in directives because it's checked by [no-parsing-error] rule. + +👎 Examples of **incorrect** code for this rule: + +```html + +``` + +👍 Examples of **correct** code for this rule: + +```html + +``` + +## 🔧 Options + +Nothing. + +## 👫 Related rules + +- [no-parsing-error] + + +[no-parsing-error]: no-parsing-error.md diff --git a/docs/rules/no-parsing-error.md b/docs/rules/no-parsing-error.md new file mode 100644 index 000000000..8294de388 --- /dev/null +++ b/docs/rules/no-parsing-error.md @@ -0,0 +1,28 @@ +# Disallow parsing errors in `