项目原始demo,不改动
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.
Repozitorijs ir arhivēts. Tam var aplūkot failus un to var klonēt, bet nevar iesūtīt jaunas izmaiņas, kā arī atvērt jaunas problēmas/izmaiņu pieprasījumus.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  1. # eslint-plugin-vue
  2. [![NPM version](https://img.shields.io/npm/v/eslint-plugin-vue.svg?style=flat)](https://npmjs.org/package/eslint-plugin-vue)
  3. [![NPM downloads](https://img.shields.io/npm/dm/eslint-plugin-vue.svg?style=flat)](https://npmjs.org/package/eslint-plugin-vue)
  4. [![CircleCI](https://circleci.com/gh/vuejs/eslint-plugin-vue.svg?style=svg)](https://circleci.com/gh/vuejs/eslint-plugin-vue)
  5. > Official ESLint plugin for Vue.js
  6. ## :art: Playground on the Web
  7. You can try this plugin on the Web.
  8. - https://mysticatea.github.io/vue-eslint-demo/
  9. ## :grey_exclamation: Requirements
  10. - [ESLint](http://eslint.org/) `>=3.18.0`.
  11. - `>=4.7.0` to use `eslint --fix`.
  12. - `>=4.14.0` to use with `babel-eslint`.
  13. - Node.js `>=4.0.0`
  14. ## :cd: Installation
  15. ```bash
  16. npm install --save-dev eslint eslint-plugin-vue
  17. ```
  18. ## :rocket: Usage
  19. Create `.eslintrc.*` file to configure rules. See also: [http://eslint.org/docs/user-guide/configuring](http://eslint.org/docs/user-guide/configuring).
  20. Example **.eslintrc.js**:
  21. ```js
  22. module.exports = {
  23. extends: [
  24. // add more generic rulesets here, such as:
  25. // 'eslint:recommended',
  26. 'plugin:vue/essential'
  27. ],
  28. rules: {
  29. // override/add rules settings here, such as:
  30. // 'vue/no-unused-vars': 'error'
  31. }
  32. }
  33. ```
  34. ### Single File Components
  35. 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.
  36. Examples:
  37. ```bash
  38. eslint --ext .js,.vue src
  39. eslint src/**/*.{js,vue}
  40. ```
  41. ### Attention
  42. All component-related rules are being applied to code that passes any of the following checks:
  43. * `Vue.component()` expression
  44. * `Vue.extend()` expression
  45. * `Vue.mixin()` expression
  46. * `export default {}` in `.vue` or `.jsx` file
  47. 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.:
  48. ```js
  49. // @vue/component
  50. const CustomComponent = {
  51. name: 'custom-component',
  52. template: '<div></div>'
  53. }
  54. ```
  55. ```js
  56. Vue.component('AsyncComponent', (resolve, reject) => {
  57. setTimeout(() => {
  58. // @vue/component
  59. resolve({
  60. name: 'async-component',
  61. template: '<div></div>'
  62. })
  63. }, 500)
  64. })
  65. ```
  66. ### `eslint-disable` functionality in `<template>`
  67. You can use `<!-- eslint-disable -->`-like HTML comments in `<template>` of `.vue` files. For example:
  68. ```html
  69. <template>
  70. <!-- eslint-disable-next-line vue/max-attributes-per-line -->
  71. <div a="1" b="2" c="3" d="4">
  72. </div>
  73. </template>
  74. ```
  75. If you want to disallow `eslint-disable` functionality, please disable [vue/comment-directive](./docs/rules/comment-directive.md) rule.
  76. ## :gear: Configs
  77. This plugin provides four predefined configs:
  78. - `plugin:vue/base` - Settings and rules to enable correct ESLint parsing
  79. - `plugin:vue/essential` - Above, plus rules to prevent errors or unintended behavior
  80. - `plugin:vue/strongly-recommended` - Above, plus rules to considerably improve code readability and/or dev experience
  81. - `plugin:vue/recommended` - Above, plus rules to enforce subjective community defaults to ensure consistency
  82. ## :bulb: Rules
  83. 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.
  84. <!--RULES_TABLE_START-->
  85. ### Base Rules (Enabling Correct ESLint Parsing)
  86. Enforce all the rules in this category, as well as all higher priority rules, with:
  87. ```json
  88. {
  89. "extends": "plugin:vue/base"
  90. }
  91. ```
  92. | | Rule ID | Description |
  93. |:---|:--------|:------------|
  94. | | [vue/comment-directive](./docs/rules/comment-directive.md) | support comment-directives in `<template>` |
  95. | | [vue/jsx-uses-vars](./docs/rules/jsx-uses-vars.md) | prevent variables used in JSX to be marked as unused |
  96. ### Priority A: Essential (Error Prevention)
  97. Enforce all the rules in this category, as well as all higher priority rules, with:
  98. ```json
  99. {
  100. "extends": "plugin:vue/essential"
  101. }
  102. ```
  103. | | Rule ID | Description |
  104. |:---|:--------|:------------|
  105. | | [vue/no-async-in-computed-properties](./docs/rules/no-async-in-computed-properties.md) | disallow asynchronous actions in computed properties |
  106. | | [vue/no-dupe-keys](./docs/rules/no-dupe-keys.md) | disallow duplication of field names |
  107. | | [vue/no-duplicate-attributes](./docs/rules/no-duplicate-attributes.md) | disallow duplication of attributes |
  108. | | [vue/no-parsing-error](./docs/rules/no-parsing-error.md) | disallow parsing errors in `<template>` |
  109. | | [vue/no-reserved-keys](./docs/rules/no-reserved-keys.md) | disallow overwriting reserved keys |
  110. | :wrench: | [vue/no-shared-component-data](./docs/rules/no-shared-component-data.md) | enforce component's data property to be a function |
  111. | | [vue/no-side-effects-in-computed-properties](./docs/rules/no-side-effects-in-computed-properties.md) | disallow side effects in computed properties |
  112. | | [vue/no-template-key](./docs/rules/no-template-key.md) | disallow `key` attribute on `<template>` |
  113. | | [vue/no-textarea-mustache](./docs/rules/no-textarea-mustache.md) | disallow mustaches in `<textarea>` |
  114. | | [vue/no-unused-vars](./docs/rules/no-unused-vars.md) | disallow unused variable definitions of v-for directives or scope attributes |
  115. | | [vue/require-component-is](./docs/rules/require-component-is.md) | require `v-bind:is` of `<component>` elements |
  116. | | [vue/require-render-return](./docs/rules/require-render-return.md) | enforce render function to always return value |
  117. | | [vue/require-v-for-key](./docs/rules/require-v-for-key.md) | require `v-bind:key` with `v-for` directives |
  118. | | [vue/require-valid-default-prop](./docs/rules/require-valid-default-prop.md) | enforce props default values to be valid |
  119. | | [vue/return-in-computed-property](./docs/rules/return-in-computed-property.md) | enforce that a return statement is present in computed property |
  120. | | [vue/valid-template-root](./docs/rules/valid-template-root.md) | enforce valid template root |
  121. | | [vue/valid-v-bind](./docs/rules/valid-v-bind.md) | enforce valid `v-bind` directives |
  122. | | [vue/valid-v-cloak](./docs/rules/valid-v-cloak.md) | enforce valid `v-cloak` directives |
  123. | | [vue/valid-v-else-if](./docs/rules/valid-v-else-if.md) | enforce valid `v-else-if` directives |
  124. | | [vue/valid-v-else](./docs/rules/valid-v-else.md) | enforce valid `v-else` directives |
  125. | | [vue/valid-v-for](./docs/rules/valid-v-for.md) | enforce valid `v-for` directives |
  126. | | [vue/valid-v-html](./docs/rules/valid-v-html.md) | enforce valid `v-html` directives |
  127. | | [vue/valid-v-if](./docs/rules/valid-v-if.md) | enforce valid `v-if` directives |
  128. | | [vue/valid-v-model](./docs/rules/valid-v-model.md) | enforce valid `v-model` directives |
  129. | | [vue/valid-v-on](./docs/rules/valid-v-on.md) | enforce valid `v-on` directives |
  130. | | [vue/valid-v-once](./docs/rules/valid-v-once.md) | enforce valid `v-once` directives |
  131. | | [vue/valid-v-pre](./docs/rules/valid-v-pre.md) | enforce valid `v-pre` directives |
  132. | | [vue/valid-v-show](./docs/rules/valid-v-show.md) | enforce valid `v-show` directives |
  133. | | [vue/valid-v-text](./docs/rules/valid-v-text.md) | enforce valid `v-text` directives |
  134. ### Priority B: Strongly Recommended (Improving Readability)
  135. Enforce all the rules in this category, as well as all higher priority rules, with:
  136. ```json
  137. {
  138. "extends": "plugin:vue/strongly-recommended"
  139. }
  140. ```
  141. | | Rule ID | Description |
  142. |:---|:--------|:------------|
  143. | :wrench: | [vue/attribute-hyphenation](./docs/rules/attribute-hyphenation.md) | enforce attribute naming style on custom components in template |
  144. | :wrench: | [vue/html-end-tags](./docs/rules/html-end-tags.md) | enforce end tag style |
  145. | :wrench: | [vue/html-indent](./docs/rules/html-indent.md) | enforce consistent indentation in `<template>` |
  146. | :wrench: | [vue/html-self-closing](./docs/rules/html-self-closing.md) | enforce self-closing style |
  147. | :wrench: | [vue/max-attributes-per-line](./docs/rules/max-attributes-per-line.md) | enforce the maximum number of attributes per line |
  148. | :wrench: | [vue/mustache-interpolation-spacing](./docs/rules/mustache-interpolation-spacing.md) | enforce unified spacing in mustache interpolations |
  149. | :wrench: | [vue/name-property-casing](./docs/rules/name-property-casing.md) | enforce specific casing for the name property in Vue components |
  150. | :wrench: | [vue/no-multi-spaces](./docs/rules/no-multi-spaces.md) | disallow multiple spaces |
  151. | | [vue/require-default-prop](./docs/rules/require-default-prop.md) | require default value for props |
  152. | | [vue/require-prop-types](./docs/rules/require-prop-types.md) | require type definitions in props |
  153. | :wrench: | [vue/v-bind-style](./docs/rules/v-bind-style.md) | enforce `v-bind` directive style |
  154. | :wrench: | [vue/v-on-style](./docs/rules/v-on-style.md) | enforce `v-on` directive style |
  155. ### Priority C: Recommended (Minimizing Arbitrary Choices and Cognitive Overhead)
  156. Enforce all the rules in this category, as well as all higher priority rules, with:
  157. ```json
  158. {
  159. "extends": "plugin:vue/recommended"
  160. }
  161. ```
  162. | | Rule ID | Description |
  163. |:---|:--------|:------------|
  164. | :wrench: | [vue/attributes-order](./docs/rules/attributes-order.md) | enforce order of attributes |
  165. | :wrench: | [vue/html-quotes](./docs/rules/html-quotes.md) | enforce quotes style of HTML attributes |
  166. | | [vue/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 |
  167. | :wrench: | [vue/order-in-components](./docs/rules/order-in-components.md) | enforce order of properties in components |
  168. | | [vue/this-in-template](./docs/rules/this-in-template.md) | enforce usage of `this` in template |
  169. ### Uncategorized
  170. | | Rule ID | Description |
  171. |:---|:--------|:------------|
  172. | :wrench: | [vue/html-closing-bracket-newline](./docs/rules/html-closing-bracket-newline.md) | require or disallow a line break before tag's closing brackets |
  173. | :wrench: | [vue/html-closing-bracket-spacing](./docs/rules/html-closing-bracket-spacing.md) | require or disallow a space before tag's closing brackets |
  174. | | [vue/no-use-v-if-with-v-for](./docs/rules/no-use-v-if-with-v-for.md) | disallow use v-if on the same element as v-for |
  175. | | [vue/no-v-html](./docs/rules/no-v-html.md) | disallow use of v-html to prevent XSS attack |
  176. | :wrench: | [vue/prop-name-casing](./docs/rules/prop-name-casing.md) | enforce specific casing for the Prop name in Vue components |
  177. | :wrench: | [vue/script-indent](./docs/rules/script-indent.md) | enforce consistent indentation in `<script>` |
  178. <!--RULES_TABLE_END-->
  179. ## :couple: FAQ
  180. ### What is the "Use the latest vue-eslint-parser" error?
  181. The most rules of `eslint-plugin-vue` require `vue-eslint-parser` to check `<template>` ASTs.
  182. Make sure you have one of the following settings in your **.eslintrc**:
  183. - `"extends": ["plugin:vue/recommended"]`
  184. - `"extends": ["plugin:vue/base"]`
  185. If you already use other parser (e.g. `"parser": "babel-eslint"`), please move it into `parserOptions`, so it doesn't collide with the `vue-eslint-parser` used by this plugin's configuration:
  186. ```diff
  187. - "parser": "babel-eslint",
  188. "parserOptions": {
  189. + "parser": "babel-eslint",
  190. "ecmaVersion": 2017,
  191. "sourceType": "module"
  192. }
  193. ```
  194. The `vue-eslint-parser` uses the parser which is set by `parserOptions.parser` to parse scripts.
  195. ### Why doesn't it work on .vue file?
  196. 1. Make sure you don't have `eslint-plugin-html` in your config. The `eslint-plugin-html` extracts the content from `<script>` tags, but `eslint-plugin-vue` requires `<script>` tags and `<template>` tags in order to distinguish template and script in single file components.
  197. ```diff
  198. "plugins": [
  199. "vue",
  200. - "html"
  201. ]
  202. ```
  203. 2. Make sure your tool is set to lint `.vue` files.
  204. - CLI targets only `.js` files by default. You have to specify additional extensions by `--ext` option or glob patterns. E.g. `eslint "src/**/*.{js,vue}"` or `eslint src --ext .vue`.
  205. - VSCode targets only JavaScript or HTML files by default. You have to add `"vue"` to the `"eslint.validate"` array in vscode settings. e.g. `"eslint.validate": [ "javascript", "javascriptreact", "vue" ]`
  206. ## :anchor: Semantic Versioning Policy
  207. This plugin follows [semantic versioning](http://semver.org/) and [ESLint's Semantic Versioning Policy](https://github.com/eslint/eslint#semantic-versioning-policy).
  208. ## :newspaper: Changelog
  209. We're using [GitHub Releases](https://github.com/vuejs/eslint-plugin-vue/releases).
  210. ## :beers: Contribution guide
  211. In order to add a new rule, you should:
  212. - Create issue on GH with description of proposed rule
  213. - Generate a new rule using the [official yeoman generator](https://github.com/eslint/generator-eslint)
  214. - Run `npm start`
  215. - Write test scenarios & implement logic
  216. - Describe the rule in the generated `docs` file
  217. - Make sure all tests are passing
  218. - Run `npm run update` in order to update readme and recommended configuration
  219. - Create PR and link created issue in description
  220. We're more than happy to see potential contributions, so don't hesitate. If you have any suggestions, ideas or problems feel free to add new [issue](https://github.com/vuejs/eslint-plugin-vue/issues), but first please make sure your question does not repeat previous ones.
  221. ## :lock: License
  222. See the [LICENSE](LICENSE) file for license rights and limitations (MIT).