podkot / eslint-plugin-vue

Official ESLint plugin for Vue.js

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

eslint-plugin-vue

NPM version NPM downloads CircleCI

Official ESLint plugin for Vue.js

❗ Attention - this is documentation for version 4.x ❗

This branch contains eslint-plugin-vue@next which is a pre-released 4.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": "next" in package.json or do npm install eslint-plugin-vue@next.

Please try it and report any issues that you might have encountered.

If you want to check previous releases go here.

🎨 Playground on the Web

You can try this plugin on the Web.

❕ Requirements

  • ESLint >=3.18.0.
  • Node.js >=4.0.0

πŸ’Ώ Installation

npm install --save-dev eslint eslint-plugin-vue@next

πŸš€ Usage

Create .eslintrc.* file to configure rules. See also: http://eslint.org/docs/user-guide/configuring.

Example .eslintrc.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'
  }
}

Attention

All component-related rules are being applied to code that passes any of the following checks:

  • Vue.component() 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.:

// @vue/component
const CustomComponent = {
  name: 'custom-component',
  template: '<div></div>'
}
Vue.component('AsyncComponent', (resolve, reject) => {
  setTimeout(() => {
    // @vue/component
    resolve({
      name: 'async-component',
      template: '<div></div>'
    })
  }, 500)
})

βš™οΈ Configs

This plugin provides two 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

πŸ’‘ 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 πŸ”§ below.

Base Rules (Enabling Correct ESLint Parsing)

Enforce all the rules in this category, as well as all higher priority rules, with:

"extends": "plugin:vue/base"
Rule ID Description
jsx-uses-vars 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:

"extends": "plugin:vue/essential"
Rule ID Description
no-async-in-computed-properties disallow asynchronous actions in computed properties
no-dupe-keys disallow duplication of field names
no-duplicate-attributes disallow duplication of attributes
no-parsing-error disallow parsing errors in <template>
no-reserved-keys disallow overwriting reserved keys
no-shared-component-data enforce component's data property to be a function
no-side-effects-in-computed-properties disallow side effects in computed properties
no-template-key disallow key attribute on <template>
no-textarea-mustache disallow mustaches in <textarea>
no-unused-vars disallow unused variable definitions of v-for directives or scope attributes
require-component-is require v-bind:is of <component> elements
require-render-return enforce render function to always return value
require-v-for-key require v-bind:key with v-for directives
require-valid-default-prop enforce props default values to be valid
return-in-computed-property enforce that a return statement is present in computed property
valid-template-root enforce valid template root
valid-v-bind enforce valid v-bind directives
valid-v-cloak enforce valid v-cloak directives
valid-v-else-if enforce valid v-else-if directives
valid-v-else enforce valid v-else directives
valid-v-for enforce valid v-for directives
valid-v-html enforce valid v-html directives
valid-v-if enforce valid v-if directives
valid-v-model enforce valid v-model directives
valid-v-on enforce valid v-on directives
valid-v-once enforce valid v-once directives
valid-v-pre enforce valid v-pre directives
valid-v-show enforce valid v-show directives
valid-v-text enforce valid v-text directives

Priority B: Strongly Recommended (Improving Readability)

Enforce all the rules in this category, as well as all higher priority rules, with:

"extends": "plugin:vue/strongly-recommended"
Rule ID Description
πŸ”§ attribute-hyphenation enforce attribute naming style in template
πŸ”§ html-end-tags enforce end tag style
πŸ”§ html-indent enforce consistent indentation in <template>
πŸ”§ html-self-closing enforce self-closing style
max-attributes-per-line enforce the maximum number of attributes per line
πŸ”§ mustache-interpolation-spacing enforce unified spacing in mustache interpolations
πŸ”§ name-property-casing enforce specific casing for the name property in Vue components
πŸ”§ no-multi-spaces disallow multiple spaces
require-default-prop require default value for props
require-prop-types require type definitions in props
πŸ”§ v-bind-style enforce v-bind directive style
πŸ”§ v-on-style enforce v-on directive style

Priority C: Recommended (Minimizing Arbitrary Choices and Cognitive Overhead)

Enforce all the rules in this category, as well as all higher priority rules, with:

"extends": "plugin:vue/recommended"
Rule ID Description
html-quotes enforce quotes style of HTML attributes
no-confusing-v-for-v-if disallow confusing v-for and v-if on the same element
order-in-components enforce order of properties in components
this-in-template enforce usage of this in template

πŸ‘« FAQ

What is the "Use the latest vue-eslint-parser" error?

The most rules of eslint-plugin-vue require vue-eslint-parser to check <template> ASTs.

Make sure you have one of the following settings in your .eslintrc:

  • "extends": ["plugin:vue/recommended"]
  • "extends": ["plugin:vue/base"]

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:

- "parser": "babel-eslint",
  "parserOptions": {
+     "parser": "babel-eslint",
      "ecmaVersion": 2017,
      "sourceType": "module"
  }

The vue-eslint-parser uses the parser which is set by parserOptions.parser to parse scripts.

Can my javascript code have increased indentation?

It depends on the version of eslint you're using.

indent rule in eslint@3.x makes it possible, but if you use eslint@4.x be aware that this rule has been rewritten and is more strict now, thus it doesn't allow to have increased initial indentation.

You can however use indent-legacy rule instead. More informations here.

βš“ Semantic Versioning Policy

This plugin follows semantic versioning and ESLint's Semantic Versioning Policy.

πŸ“° Changelog

We're using GitHub Releases.

🍻 Contribution guide

In order to add a new rule, you should:

  • Create issue on GH with description of proposed rule
  • Generate a new rule using the official yeoman generator
  • Run npm start
  • Write test scenarios & implement logic
  • Describe the rule in the generated docs file
  • Make sure all tests are passing
  • Run npm run update in order to update readme and recommended configuration
  • Create PR and link created issue in description

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, but first please make sure your question does not repeat previous ones.

πŸ”’ License

See the LICENSE file for license rights and limitations (MIT).

About

Official ESLint plugin for Vue.js

License:MIT License


Languages

Language:JavaScript 100.0%Language:Vue 0.0%