Skip to content

Commit 5663572

Browse files
authored
Add the ruleset for Vue.js 3 (#1061)
- Add `plugin:vue/vue3-essential` config - Add `plugin:vue/vue3-strongly-recommended` config - Add `plugin:vue/vue3-recommended` config
1 parent 60a5f6c commit 5663572

File tree

185 files changed

+696
-220
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

185 files changed

+696
-220
lines changed

.eslintrc.js

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ module.exports = {
2929
rules: {
3030
"consistent-docs-description": "error",
3131
"no-invalid-meta": "error",
32+
"no-invalid-meta-docs-categories": "error",
3233
'eslint-plugin/require-meta-type': 'error',
3334
"require-meta-docs-url": ["error", {
3435
"pattern": `https://eslint.vuejs.org/rules/{{name}}.html`

docs/.vuepress/config.js

+39-7
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,47 @@
55
'use strict'
66

77
const rules = require('../../tools/lib/rules')
8-
const categories = require('../../tools/lib/categories')
98

10-
const uncategorizedRules = rules.filter(rule => !rule.meta.docs.category && !rule.meta.deprecated)
9+
const uncategorizedRules = rules.filter(rule => !rule.meta.docs.categories && !rule.meta.deprecated)
1110
const deprecatedRules = rules.filter(rule => rule.meta.deprecated)
1211

12+
const sidebarCategories = [
13+
{ title: 'Base Rules', categoryIds: ['base'] },
14+
{ title: 'Priority A: Essential', categoryIds: ['vue3-essential', 'essential'] },
15+
{ title: 'Priority A: Essential for Vue.js 3.x', categoryIds: ['vue3-essential'] },
16+
{ title: 'Priority A: Essential for Vue.js 2.x', categoryIds: ['essential'] },
17+
{ title: 'Priority B: Strongly Recommended', categoryIds: ['vue3-strongly-recommended', 'strongly-recommended'] },
18+
{ title: 'Priority B: Strongly Recommended for Vue.js 3.x', categoryIds: ['vue3-strongly-recommended'] },
19+
{ title: 'Priority B: Strongly Recommended for Vue.js 2.x', categoryIds: ['strongly-recommended'] },
20+
{ title: 'Priority C: Recommended', categoryIds: ['vue3-recommended', 'recommended'] },
21+
{ title: 'Priority C: Recommended for Vue.js 3.x', categoryIds: ['vue3-recommended'] },
22+
{ title: 'Priority C: Recommended for Vue.js 2.x', categoryIds: ['recommended'] }
23+
]
24+
25+
const categorizedRules = []
26+
for (const { title, categoryIds } of sidebarCategories) {
27+
const categoryRules = rules
28+
.filter(rule => rule.meta.docs.categories && !rule.meta.deprecated)
29+
.filter(rule => categoryIds
30+
.every(categoryId => rule.meta.docs.categories.includes(categoryId))
31+
)
32+
const children = categoryRules
33+
.filter(({ ruleId }) => {
34+
const exists = categorizedRules.some(({ children }) => children.some(([, alreadyRuleId]) => alreadyRuleId === ruleId))
35+
return !exists
36+
})
37+
.map(({ ruleId, name }) => [`/rules/${name}`, ruleId])
38+
39+
if (children.length === 0) {
40+
continue
41+
}
42+
categorizedRules.push({
43+
title,
44+
collapsable: false,
45+
children
46+
})
47+
}
48+
1349
const extraCategories = []
1450
if (uncategorizedRules.length > 0) {
1551
extraCategories.push({
@@ -59,11 +95,7 @@ module.exports = {
5995
'/rules/',
6096

6197
// Rules in each category.
62-
...categories.map(({ title, rules }) => ({
63-
title: title.replace(/ \(.+?\)/, ''),
64-
collapsable: false,
65-
children: rules.map(({ ruleId, name }) => [`/rules/${name}`, ruleId])
66-
})),
98+
...categorizedRules,
6799

68100
// Rules in no category.
69101
...extraCategories

docs/rules/README.md

+110-11
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,114 @@ Enforce all the rules in this category, as well as all higher priority rules, wi
2626
| [vue/comment-directive](./comment-directive.md) | support comment-directives in `<template>` | |
2727
| [vue/jsx-uses-vars](./jsx-uses-vars.md) | prevent variables used in JSX to be marked as unused | |
2828

29-
## Priority A: Essential (Error Prevention)
29+
## Priority A: Essential (Error Prevention) <badge text="for Vue.js 3.x" vertical="middle">for Vue.js 3.x</badge>
30+
31+
Enforce all the rules in this category, as well as all higher priority rules, with:
32+
33+
```json
34+
{
35+
"extends": "plugin:vue/vue3-essential"
36+
}
37+
```
38+
39+
| Rule ID | Description | |
40+
|:--------|:------------|:---|
41+
| [vue/no-async-in-computed-properties](./no-async-in-computed-properties.md) | disallow asynchronous actions in computed properties | |
42+
| [vue/no-deprecated-filter](./no-deprecated-filter.md) | disallow using deprecated filters syntax | |
43+
| [vue/no-deprecated-scope-attribute](./no-deprecated-scope-attribute.md) | disallow deprecated `scope` attribute (in Vue.js 2.5.0+) | :wrench: |
44+
| [vue/no-deprecated-slot-attribute](./no-deprecated-slot-attribute.md) | disallow deprecated `slot` attribute (in Vue.js 2.6.0+) | :wrench: |
45+
| [vue/no-deprecated-slot-scope-attribute](./no-deprecated-slot-scope-attribute.md) | disallow deprecated `slot-scope` attribute (in Vue.js 2.6.0+) | :wrench: |
46+
| [vue/no-deprecated-v-bind-sync](./no-deprecated-v-bind-sync.md) | disallow use of deprecated `.sync` modifier on `v-bind` directive (in Vue.js 3.0.0+) | :wrench: |
47+
| [vue/no-dupe-keys](./no-dupe-keys.md) | disallow duplication of field names | |
48+
| [vue/no-duplicate-attributes](./no-duplicate-attributes.md) | disallow duplication of attributes | |
49+
| [vue/no-lifecycle-after-await](./no-lifecycle-after-await.md) | disallow asynchronously registered lifecycle hooks | |
50+
| [vue/no-parsing-error](./no-parsing-error.md) | disallow parsing errors in `<template>` | |
51+
| [vue/no-ref-as-operand](./no-ref-as-operand.md) | disallow use of value wrapped by `ref()` (Composition API) as an operand | |
52+
| [vue/no-reserved-keys](./no-reserved-keys.md) | disallow overwriting reserved keys | |
53+
| [vue/no-setup-props-destructure](./no-setup-props-destructure.md) | disallow destructuring of `props` passed to `setup` | |
54+
| [vue/no-shared-component-data](./no-shared-component-data.md) | enforce component's data property to be a function | :wrench: |
55+
| [vue/no-side-effects-in-computed-properties](./no-side-effects-in-computed-properties.md) | disallow side effects in computed properties | |
56+
| [vue/no-template-key](./no-template-key.md) | disallow `key` attribute on `<template>` | |
57+
| [vue/no-textarea-mustache](./no-textarea-mustache.md) | disallow mustaches in `<textarea>` | |
58+
| [vue/no-unused-components](./no-unused-components.md) | disallow registering components that are not used inside templates | |
59+
| [vue/no-unused-vars](./no-unused-vars.md) | disallow unused variable definitions of v-for directives or scope attributes | |
60+
| [vue/no-use-v-if-with-v-for](./no-use-v-if-with-v-for.md) | disallow use v-if on the same element as v-for | |
61+
| [vue/require-component-is](./require-component-is.md) | require `v-bind:is` of `<component>` elements | |
62+
| [vue/require-prop-type-constructor](./require-prop-type-constructor.md) | require prop type to be a constructor | :wrench: |
63+
| [vue/require-render-return](./require-render-return.md) | enforce render function to always return value | |
64+
| [vue/require-v-for-key](./require-v-for-key.md) | require `v-bind:key` with `v-for` directives | |
65+
| [vue/require-valid-default-prop](./require-valid-default-prop.md) | enforce props default values to be valid | |
66+
| [vue/return-in-computed-property](./return-in-computed-property.md) | enforce that a return statement is present in computed property | |
67+
| [vue/use-v-on-exact](./use-v-on-exact.md) | enforce usage of `exact` modifier on `v-on` | |
68+
| [vue/valid-template-root](./valid-template-root.md) | enforce valid template root | |
69+
| [vue/valid-v-bind](./valid-v-bind.md) | enforce valid `v-bind` directives | |
70+
| [vue/valid-v-cloak](./valid-v-cloak.md) | enforce valid `v-cloak` directives | |
71+
| [vue/valid-v-else-if](./valid-v-else-if.md) | enforce valid `v-else-if` directives | |
72+
| [vue/valid-v-else](./valid-v-else.md) | enforce valid `v-else` directives | |
73+
| [vue/valid-v-for](./valid-v-for.md) | enforce valid `v-for` directives | |
74+
| [vue/valid-v-html](./valid-v-html.md) | enforce valid `v-html` directives | |
75+
| [vue/valid-v-if](./valid-v-if.md) | enforce valid `v-if` directives | |
76+
| [vue/valid-v-model](./valid-v-model.md) | enforce valid `v-model` directives | |
77+
| [vue/valid-v-on](./valid-v-on.md) | enforce valid `v-on` directives | |
78+
| [vue/valid-v-once](./valid-v-once.md) | enforce valid `v-once` directives | |
79+
| [vue/valid-v-pre](./valid-v-pre.md) | enforce valid `v-pre` directives | |
80+
| [vue/valid-v-show](./valid-v-show.md) | enforce valid `v-show` directives | |
81+
| [vue/valid-v-slot](./valid-v-slot.md) | enforce valid `v-slot` directives | |
82+
| [vue/valid-v-text](./valid-v-text.md) | enforce valid `v-text` directives | |
83+
84+
## Priority B: Strongly Recommended (Improving Readability) <badge text="for Vue.js 3.x" vertical="middle">for Vue.js 3.x</badge>
85+
86+
Enforce all the rules in this category, as well as all higher priority rules, with:
87+
88+
```json
89+
{
90+
"extends": "plugin:vue/vue3-strongly-recommended"
91+
}
92+
```
93+
94+
| Rule ID | Description | |
95+
|:--------|:------------|:---|
96+
| [vue/attribute-hyphenation](./attribute-hyphenation.md) | enforce attribute naming style on custom components in template | :wrench: |
97+
| [vue/component-definition-name-casing](./component-definition-name-casing.md) | enforce specific casing for component definition name | :wrench: |
98+
| [vue/html-closing-bracket-newline](./html-closing-bracket-newline.md) | require or disallow a line break before tag's closing brackets | :wrench: |
99+
| [vue/html-closing-bracket-spacing](./html-closing-bracket-spacing.md) | require or disallow a space before tag's closing brackets | :wrench: |
100+
| [vue/html-end-tags](./html-end-tags.md) | enforce end tag style | :wrench: |
101+
| [vue/html-indent](./html-indent.md) | enforce consistent indentation in `<template>` | :wrench: |
102+
| [vue/html-quotes](./html-quotes.md) | enforce quotes style of HTML attributes | :wrench: |
103+
| [vue/html-self-closing](./html-self-closing.md) | enforce self-closing style | :wrench: |
104+
| [vue/max-attributes-per-line](./max-attributes-per-line.md) | enforce the maximum number of attributes per line | :wrench: |
105+
| [vue/multiline-html-element-content-newline](./multiline-html-element-content-newline.md) | require a line break before and after the contents of a multiline element | :wrench: |
106+
| [vue/mustache-interpolation-spacing](./mustache-interpolation-spacing.md) | enforce unified spacing in mustache interpolations | :wrench: |
107+
| [vue/no-multi-spaces](./no-multi-spaces.md) | disallow multiple spaces | :wrench: |
108+
| [vue/no-spaces-around-equal-signs-in-attribute](./no-spaces-around-equal-signs-in-attribute.md) | disallow spaces around equal signs in attribute | :wrench: |
109+
| [vue/no-template-shadow](./no-template-shadow.md) | disallow variable declarations from shadowing variables declared in the outer scope | |
110+
| [vue/prop-name-casing](./prop-name-casing.md) | enforce specific casing for the Prop name in Vue components | |
111+
| [vue/require-default-prop](./require-default-prop.md) | require default value for props | |
112+
| [vue/require-prop-types](./require-prop-types.md) | require type definitions in props | |
113+
| [vue/singleline-html-element-content-newline](./singleline-html-element-content-newline.md) | require a line break before and after the contents of a singleline element | :wrench: |
114+
| [vue/v-bind-style](./v-bind-style.md) | enforce `v-bind` directive style | :wrench: |
115+
| [vue/v-on-style](./v-on-style.md) | enforce `v-on` directive style | :wrench: |
116+
| [vue/v-slot-style](./v-slot-style.md) | enforce `v-slot` directive style | :wrench: |
117+
118+
## Priority C: Recommended (Minimizing Arbitrary Choices and Cognitive Overhead) <badge text="for Vue.js 3.x" vertical="middle">for Vue.js 3.x</badge>
119+
120+
Enforce all the rules in this category, as well as all higher priority rules, with:
121+
122+
```json
123+
{
124+
"extends": "plugin:vue/vue3-recommended"
125+
}
126+
```
127+
128+
| Rule ID | Description | |
129+
|:--------|:------------|:---|
130+
| [vue/attributes-order](./attributes-order.md) | enforce order of attributes | :wrench: |
131+
| [vue/component-tags-order](./component-tags-order.md) | enforce order of component top-level elements | |
132+
| [vue/no-v-html](./no-v-html.md) | disallow use of v-html to prevent XSS attack | |
133+
| [vue/order-in-components](./order-in-components.md) | enforce order of properties in components | :wrench: |
134+
| [vue/this-in-template](./this-in-template.md) | disallow usage of `this` in template | |
135+
136+
## Priority A: Essential (Error Prevention) <badge text="for Vue.js 2.x" vertical="middle" type="warn">for Vue.js 2.x</badge>
30137

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

@@ -77,7 +184,7 @@ Enforce all the rules in this category, as well as all higher priority rules, wi
77184
| [vue/valid-v-slot](./valid-v-slot.md) | enforce valid `v-slot` directives | |
78185
| [vue/valid-v-text](./valid-v-text.md) | enforce valid `v-text` directives | |
79186

80-
## Priority B: Strongly Recommended (Improving Readability)
187+
## Priority B: Strongly Recommended (Improving Readability) <badge text="for Vue.js 2.x" vertical="middle" type="warn">for Vue.js 2.x</badge>
81188

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

@@ -111,7 +218,7 @@ Enforce all the rules in this category, as well as all higher priority rules, wi
111218
| [vue/v-on-style](./v-on-style.md) | enforce `v-on` directive style | :wrench: |
112219
| [vue/v-slot-style](./v-slot-style.md) | enforce `v-slot` directive style | :wrench: |
113220

114-
## Priority C: Recommended (Minimizing Arbitrary Choices and Cognitive Overhead)
221+
## Priority C: Recommended (Minimizing Arbitrary Choices and Cognitive Overhead) <badge text="for Vue.js 2.x" vertical="middle" type="warn">for Vue.js 2.x</badge>
115222

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

@@ -160,18 +267,10 @@ For example:
160267
| [vue/match-component-file-name](./match-component-file-name.md) | require component name property to match its file name | |
161268
| [vue/max-len](./max-len.md) | enforce a maximum line length | |
162269
| [vue/no-boolean-default](./no-boolean-default.md) | disallow boolean defaults | :wrench: |
163-
| [vue/no-deprecated-filter](./no-deprecated-filter.md) | disallow using deprecated filters syntax | |
164-
| [vue/no-deprecated-scope-attribute](./no-deprecated-scope-attribute.md) | disallow deprecated `scope` attribute (in Vue.js 2.5.0+) | :wrench: |
165-
| [vue/no-deprecated-slot-attribute](./no-deprecated-slot-attribute.md) | disallow deprecated `slot` attribute (in Vue.js 2.6.0+) | :wrench: |
166-
| [vue/no-deprecated-slot-scope-attribute](./no-deprecated-slot-scope-attribute.md) | disallow deprecated `slot-scope` attribute (in Vue.js 2.6.0+) | :wrench: |
167-
| [vue/no-deprecated-v-bind-sync](./no-deprecated-v-bind-sync.md) | disallow use of deprecated `.sync` modifier on `v-bind` directive (in Vue.js 3.0.0+) | :wrench: |
168270
| [vue/no-empty-pattern](./no-empty-pattern.md) | disallow empty destructuring patterns | |
169271
| [vue/no-irregular-whitespace](./no-irregular-whitespace.md) | disallow irregular whitespace | |
170-
| [vue/no-lifecycle-after-await](./no-lifecycle-after-await.md) | disallow asynchronously registered lifecycle hooks | |
171-
| [vue/no-ref-as-operand](./no-ref-as-operand.md) | disallow use of value wrapped by `ref()` (Composition API) as an operand | |
172272
| [vue/no-reserved-component-names](./no-reserved-component-names.md) | disallow the use of reserved names in component definitions | |
173273
| [vue/no-restricted-syntax](./no-restricted-syntax.md) | disallow specified syntax | |
174-
| [vue/no-setup-props-destructure](./no-setup-props-destructure.md) | disallow destructuring of `props` passed to `setup` | |
175274
| [vue/no-static-inline-styles](./no-static-inline-styles.md) | disallow static inline `style` attributes | |
176275
| [vue/no-unsupported-features](./no-unsupported-features.md) | disallow unsupported Vue.js syntax on the specified version | :wrench: |
177276
| [vue/object-curly-spacing](./object-curly-spacing.md) | enforce consistent spacing inside braces | :wrench: |

docs/rules/attribute-hyphenation.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ description: enforce attribute naming style on custom components in template
77
# vue/attribute-hyphenation
88
> enforce attribute naming style on custom components in template
99
10-
- :gear: This rule is included in `"plugin:vue/strongly-recommended"` and `"plugin:vue/recommended"`.
10+
- :gear: This rule is included in all of `"plugin:vue/vue3-strongly-recommended"`, `"plugin:vue/strongly-recommended"`, `"plugin:vue/vue3-recommended"` and `"plugin:vue/recommended"`.
1111
- :wrench: The `--fix` option on the [command line](https://eslint.org/docs/user-guide/command-line-interface#fixing-problems) can automatically fix some of the problems reported by this rule.
1212

1313
## :book: Rule Details

docs/rules/attributes-order.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ description: enforce order of attributes
77
# vue/attributes-order
88
> enforce order of attributes
99
10-
- :gear: This rule is included in `"plugin:vue/recommended"`.
10+
- :gear: This rule is included in `"plugin:vue/vue3-recommended"` and `"plugin:vue/recommended"`.
1111
- :wrench: The `--fix` option on the [command line](https://eslint.org/docs/user-guide/command-line-interface#fixing-problems) can automatically fix some of the problems reported by this rule.
1212

1313
## :book: Rule Details

docs/rules/component-definition-name-casing.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ description: enforce specific casing for component definition name
77
# vue/component-definition-name-casing
88
> enforce specific casing for component definition name
99
10-
- :gear: This rule is included in `"plugin:vue/strongly-recommended"` and `"plugin:vue/recommended"`.
10+
- :gear: This rule is included in all of `"plugin:vue/vue3-strongly-recommended"`, `"plugin:vue/strongly-recommended"`, `"plugin:vue/vue3-recommended"` and `"plugin:vue/recommended"`.
1111
- :wrench: The `--fix` option on the [command line](https://eslint.org/docs/user-guide/command-line-interface#fixing-problems) can automatically fix some of the problems reported by this rule.
1212

1313
Define a style for component definition name casing for consistency purposes.

docs/rules/component-tags-order.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ description: enforce order of component top-level elements
77
# vue/component-tags-order
88
> enforce order of component top-level elements
99
10-
- :gear: This rule is included in `"plugin:vue/recommended"`.
10+
- :gear: This rule is included in `"plugin:vue/vue3-recommended"` and `"plugin:vue/recommended"`.
1111

1212
## :book: Rule Details
1313

docs/rules/html-closing-bracket-newline.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ description: require or disallow a line break before tag's closing brackets
77
# vue/html-closing-bracket-newline
88
> require or disallow a line break before tag's closing brackets
99
10-
- :gear: This rule is included in `"plugin:vue/strongly-recommended"` and `"plugin:vue/recommended"`.
10+
- :gear: This rule is included in all of `"plugin:vue/vue3-strongly-recommended"`, `"plugin:vue/strongly-recommended"`, `"plugin:vue/vue3-recommended"` and `"plugin:vue/recommended"`.
1111
- :wrench: The `--fix` option on the [command line](https://eslint.org/docs/user-guide/command-line-interface#fixing-problems) can automatically fix some of the problems reported by this rule.
1212

1313
People have their own preference about the location of closing brackets.

docs/rules/html-closing-bracket-spacing.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ description: require or disallow a space before tag's closing brackets
77
# vue/html-closing-bracket-spacing
88
> require or disallow a space before tag's closing brackets
99
10-
- :gear: This rule is included in `"plugin:vue/strongly-recommended"` and `"plugin:vue/recommended"`.
10+
- :gear: This rule is included in all of `"plugin:vue/vue3-strongly-recommended"`, `"plugin:vue/strongly-recommended"`, `"plugin:vue/vue3-recommended"` and `"plugin:vue/recommended"`.
1111
- :wrench: The `--fix` option on the [command line](https://eslint.org/docs/user-guide/command-line-interface#fixing-problems) can automatically fix some of the problems reported by this rule.
1212

1313
## :book: Rule Details

docs/rules/html-end-tags.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ description: enforce end tag style
77
# vue/html-end-tags
88
> enforce end tag style
99
10-
- :gear: This rule is included in `"plugin:vue/strongly-recommended"` and `"plugin:vue/recommended"`.
10+
- :gear: This rule is included in all of `"plugin:vue/vue3-strongly-recommended"`, `"plugin:vue/strongly-recommended"`, `"plugin:vue/vue3-recommended"` and `"plugin:vue/recommended"`.
1111
- :wrench: The `--fix` option on the [command line](https://eslint.org/docs/user-guide/command-line-interface#fixing-problems) can automatically fix some of the problems reported by this rule.
1212

1313
## :book: Rule Details

0 commit comments

Comments
 (0)