Skip to content

Commit a9d44bc

Browse files
mysticateamichalsnik
authored andcommitted
Update: deprecate no-invalid-* rules and add valid-* rules (fixes #103) (#132)
* Update: deprecate `no-invalid-*` rules and add `valid-*` rules (fixes #103) * Docs: update docs about deprecated rules * update for review
1 parent 0e46f31 commit a9d44bc

Some content is hidden

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

59 files changed

+3331
-67
lines changed

README.md

+55-34
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ module.exports = {
3939
],
4040
rules: {
4141
// override/add rules' settings here
42-
'vue/no-invalid-v-if': 'error'
42+
'vue/valid-v-if': 'error'
4343
}
4444
}
4545
```
@@ -86,27 +86,41 @@ No rules are enabled by `plugin:vue/base` config. The `plugin:vue/recommended` c
8686

8787
The `--fix` option on the command line automatically fixes problems reported by rules which have a wrench :wrench: below.
8888

89-
Deprecated rules witch should be used with caution and only enabled when you know what you are doing have a warning :warning: icon.
90-
9189
<!--RULES_TABLE_START-->
9290

93-
### Stylistic Issues
91+
### Possible Errors
9492

9593
| | Rule ID | Description |
9694
|:---|:--------|:------------|
97-
| :wrench: | [attribute-hyphenation](./docs/rules/attribute-hyphenation.md) | Define a style for the props casing in templates. |
98-
| | [html-quotes](./docs/rules/html-quotes.md) | enforce quotes style of HTML attributes. |
99-
| :wrench: | [name-property-casing](./docs/rules/name-property-casing.md) | Requires specific casing for the name property in Vue components |
100-
| :wrench: | [v-bind-style](./docs/rules/v-bind-style.md) | enforce `v-bind` directive style. |
101-
| :wrench: | [v-on-style](./docs/rules/v-on-style.md) | enforce `v-on` directive style. |
95+
| | [no-dupe-keys](./docs/rules/no-dupe-keys.md) | Prevents duplication of field names. |
96+
| :white_check_mark: | [no-parsing-error](./docs/rules/no-parsing-error.md) | disallow parsing errors in `<template>`. |
97+
| | [no-reservered-keys](./docs/rules/no-reservered-keys.md) | Prevent overwrite reserved keys. |
98+
| | [no-shared-component-data](./docs/rules/no-shared-component-data.md) | Enforces component's data property to be a function. |
99+
| | [no-template-key](./docs/rules/no-template-key.md) | disallow `key` attribute on `<template>`. |
100+
| | [require-render-return](./docs/rules/require-render-return.md) | Enforces render function to always return value. |
101+
| | [require-valid-default-prop](./docs/rules/require-valid-default-prop.md) | Enforces props default values to be valid. |
102+
| | [return-in-computed-property](./docs/rules/return-in-computed-property.md) | Enforces that a return statement is present in computed property. |
103+
| :white_check_mark: | [valid-template-root](./docs/rules/valid-template-root.md) | enforce valid template root. |
104+
| :white_check_mark: | [valid-v-bind](./docs/rules/valid-v-bind.md) | enforce valid `v-bind` directives. |
105+
| :white_check_mark: | [valid-v-cloak](./docs/rules/valid-v-cloak.md) | enforce valid `v-cloak` directives. |
106+
| :white_check_mark: | [valid-v-else-if](./docs/rules/valid-v-else-if.md) | enforce valid `v-else-if` directives. |
107+
| :white_check_mark: | [valid-v-else](./docs/rules/valid-v-else.md) | enforce valid `v-else` directives. |
108+
| :white_check_mark: | [valid-v-for](./docs/rules/valid-v-for.md) | enforce valid `v-for` directives. |
109+
| :white_check_mark: | [valid-v-html](./docs/rules/valid-v-html.md) | enforce valid `v-html` directives. |
110+
| :white_check_mark: | [valid-v-if](./docs/rules/valid-v-if.md) | enforce valid `v-if` directives. |
111+
| :white_check_mark: | [valid-v-model](./docs/rules/valid-v-model.md) | enforce valid `v-model` directives. |
112+
| :white_check_mark: | [valid-v-on](./docs/rules/valid-v-on.md) | enforce valid `v-on` directives. |
113+
| :white_check_mark: | [valid-v-once](./docs/rules/valid-v-once.md) | enforce valid `v-once` directives. |
114+
| :white_check_mark: | [valid-v-pre](./docs/rules/valid-v-pre.md) | enforce valid `v-pre` directives. |
115+
| :white_check_mark: | [valid-v-show](./docs/rules/valid-v-show.md) | enforce valid `v-show` directives. |
116+
| :white_check_mark: | [valid-v-text](./docs/rules/valid-v-text.md) | enforce valid `v-text` directives. |
102117

103118

104119
### Best Practices
105120

106121
| | Rule ID | Description |
107122
|:---|:--------|:------------|
108123
| :wrench: | [html-end-tags](./docs/rules/html-end-tags.md) | enforce end tag style. |
109-
| :wrench::warning: | [html-no-self-closing](./docs/rules/html-no-self-closing.md) | disallow self-closing elements. - (deprecated) |
110124
| | [no-async-in-computed-properties](./docs/rules/no-async-in-computed-properties.md) | Check if there are no asynchronous actions inside computed properties. |
111125
| :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. |
112126
| | [no-duplicate-attributes](./docs/rules/no-duplicate-attributes.md) | disallow duplicate attributes. |
@@ -118,38 +132,45 @@ Deprecated rules witch should be used with caution and only enabled when you kno
118132
| :white_check_mark: | [require-v-for-key](./docs/rules/require-v-for-key.md) | require `v-bind:key` with `v-for` directives. |
119133

120134

121-
### Variables
135+
### Stylistic Issues
122136

123137
| | Rule ID | Description |
124138
|:---|:--------|:------------|
125-
| :white_check_mark: | [jsx-uses-vars](./docs/rules/jsx-uses-vars.md) | Prevent variables used in JSX to be marked as unused |
139+
| :wrench: | [attribute-hyphenation](./docs/rules/attribute-hyphenation.md) | Define a style for the props casing in templates. |
140+
| | [html-quotes](./docs/rules/html-quotes.md) | enforce quotes style of HTML attributes. |
141+
| :wrench: | [name-property-casing](./docs/rules/name-property-casing.md) | Requires specific casing for the name property in Vue components |
142+
| :wrench: | [v-bind-style](./docs/rules/v-bind-style.md) | enforce `v-bind` directive style. |
143+
| :wrench: | [v-on-style](./docs/rules/v-on-style.md) | enforce `v-on` directive style. |
126144

127145

128-
### Possible Errors
146+
### Variables
129147

130148
| | Rule ID | Description |
131149
|:---|:--------|:------------|
132-
| | [no-dupe-keys](./docs/rules/no-dupe-keys.md) | Prevents duplication of field names. |
133-
| :white_check_mark: | [no-invalid-template-root](./docs/rules/no-invalid-template-root.md) | disallow invalid template root. |
134-
| :white_check_mark: | [no-invalid-v-bind](./docs/rules/no-invalid-v-bind.md) | disallow invalid `v-bind` directives. |
135-
| :white_check_mark: | [no-invalid-v-cloak](./docs/rules/no-invalid-v-cloak.md) | disallow invalid `v-cloak` directives. |
136-
| :white_check_mark: | [no-invalid-v-else-if](./docs/rules/no-invalid-v-else-if.md) | disallow invalid `v-else-if` directives. |
137-
| :white_check_mark: | [no-invalid-v-else](./docs/rules/no-invalid-v-else.md) | disallow invalid `v-else` directives. |
138-
| :white_check_mark: | [no-invalid-v-for](./docs/rules/no-invalid-v-for.md) | disallow invalid `v-for` directives. |
139-
| :white_check_mark: | [no-invalid-v-html](./docs/rules/no-invalid-v-html.md) | disallow invalid `v-html` directives. |
140-
| :white_check_mark: | [no-invalid-v-if](./docs/rules/no-invalid-v-if.md) | disallow invalid `v-if` directives. |
141-
| :white_check_mark: | [no-invalid-v-model](./docs/rules/no-invalid-v-model.md) | disallow invalid `v-model` directives. |
142-
| :white_check_mark: | [no-invalid-v-on](./docs/rules/no-invalid-v-on.md) | disallow invalid `v-on` directives. |
143-
| :white_check_mark: | [no-invalid-v-once](./docs/rules/no-invalid-v-once.md) | disallow invalid `v-once` directives. |
144-
| :white_check_mark: | [no-invalid-v-pre](./docs/rules/no-invalid-v-pre.md) | disallow invalid `v-pre` directives. |
145-
| :white_check_mark: | [no-invalid-v-show](./docs/rules/no-invalid-v-show.md) | disallow invalid `v-show` directives. |
146-
| :white_check_mark: | [no-invalid-v-text](./docs/rules/no-invalid-v-text.md) | disallow invalid `v-text` directives. |
147-
| :white_check_mark: | [no-parsing-error](./docs/rules/no-parsing-error.md) | disallow parsing errors in `<template>`. |
148-
| | [no-reservered-keys](./docs/rules/no-reservered-keys.md) | Prevent overwrite reserved keys. |
149-
| | [no-shared-component-data](./docs/rules/no-shared-component-data.md) | Enforces component's data property to be a function. |
150-
| | [no-template-key](./docs/rules/no-template-key.md) | disallow `key` attribute on `<template>`. |
151-
| | [require-render-return](./docs/rules/require-render-return.md) | Enforces render function to always return value. |
152-
| | [return-in-computed-property](./docs/rules/return-in-computed-property.md) | Enforces that a return statement is present in computed property. |
150+
| :white_check_mark: | [jsx-uses-vars](./docs/rules/jsx-uses-vars.md) | Prevent variables used in JSX to be marked as unused |
151+
152+
### Deprecated
153+
154+
> - :warning: We're going to remove deprecated rules in the next major release. Please migrate to successor/new rules.
155+
> - :innocent: We don't fix bugs which are in deprecated rules since we don't have enough resources.
156+
157+
| Rule ID | Replaced by |
158+
|:--------|:------------|
159+
| [html-no-self-closing](./rules/html-no-self-closing.md) | (no replacement) |
160+
| [no-invalid-template-root](./rules/no-invalid-template-root.md) | [valid-template-root](./rules/valid-template-root.md) |
161+
| [no-invalid-v-bind](./rules/no-invalid-v-bind.md) | [valid-v-bind](./rules/valid-v-bind.md) |
162+
| [no-invalid-v-cloak](./rules/no-invalid-v-cloak.md) | [valid-v-cloak](./rules/valid-v-cloak.md) |
163+
| [no-invalid-v-else-if](./rules/no-invalid-v-else-if.md) | [valid-v-else-if](./rules/valid-v-else-if.md) |
164+
| [no-invalid-v-else](./rules/no-invalid-v-else.md) | [valid-v-else](./rules/valid-v-else.md) |
165+
| [no-invalid-v-for](./rules/no-invalid-v-for.md) | [valid-v-for](./rules/valid-v-for.md) |
166+
| [no-invalid-v-html](./rules/no-invalid-v-html.md) | [valid-v-html](./rules/valid-v-html.md) |
167+
| [no-invalid-v-if](./rules/no-invalid-v-if.md) | [valid-v-if](./rules/valid-v-if.md) |
168+
| [no-invalid-v-model](./rules/no-invalid-v-model.md) | [valid-v-model](./rules/valid-v-model.md) |
169+
| [no-invalid-v-on](./rules/no-invalid-v-on.md) | [valid-v-on](./rules/valid-v-on.md) |
170+
| [no-invalid-v-once](./rules/no-invalid-v-once.md) | [valid-v-once](./rules/valid-v-once.md) |
171+
| [no-invalid-v-pre](./rules/no-invalid-v-pre.md) | [valid-v-pre](./rules/valid-v-pre.md) |
172+
| [no-invalid-v-show](./rules/no-invalid-v-show.md) | [valid-v-show](./rules/valid-v-show.md) |
173+
| [no-invalid-v-text](./rules/no-invalid-v-text.md) | [valid-v-text](./rules/valid-v-text.md) |
153174

154175
<!--RULES_TABLE_END-->
155176

docs/rules/valid-template-root.md

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# Enforce valid template root (valid-root-element)
2+
3+
This rule checks whether every template root is valid.
4+
5+
## :book: Rule Details
6+
7+
This rule reports the template root in the following cases:
8+
9+
- The root is nothing. E.g. `<template></template>`.
10+
- The root is text. E.g. `<template>hello</template>`.
11+
- The root is multiple elements. E.g. `<template><div>one</div><div>two</div></template>`.
12+
- The root element has `v-for` directives. E.g. `<template><div v-for="x in list">{{x}}</div></template>`.
13+
- The root element is `<template>` or `<slot>` elements. E.g. `<template><template>hello</template></template>`.
14+
15+
:-1: Examples of **incorrect** code for this rule:
16+
17+
```html
18+
<template>
19+
</template>
20+
```
21+
22+
```html
23+
<template>
24+
<div>hello</div>
25+
<div>hello</div>
26+
</template>
27+
```
28+
29+
```html
30+
<template>
31+
abc
32+
</template>
33+
```
34+
35+
```html
36+
<template>
37+
<div v-for="x in list"></div>
38+
</template>
39+
```
40+
41+
:+1: Examples of **correct** code for this rule:
42+
43+
```html
44+
<template>
45+
<div>abc</div>
46+
</template>
47+
```
48+
49+
```html
50+
<template>
51+
<div v-if="foo"></div>
52+
</template>
53+
```
54+
55+
```html
56+
<template>
57+
<div v-if="foo">abc</div>
58+
<div v-else>def</div>
59+
</template>
60+
```
61+
62+
## :wrench: Options
63+
64+
Nothing.

docs/rules/valid-v-bind.md

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# Enforce valid `v-bind` directives (valid-v-bind)
2+
3+
This rule checks whether every `v-bind` directive is valid.
4+
5+
## :book: Rule Details
6+
7+
This rule reports `v-bind` directives in the following cases:
8+
9+
- The directive does not have that attribute value. E.g. `<div v-bind:aaa></div>`
10+
- The directive has invalid modifiers. E.g. `<div v-bind:aaa.bbb="ccc"></div>`
11+
12+
This rule does not report `v-bind` directives which do not have their argument (E.g. `<div v-bind="aaa"></div>`) because it's valid if the attribute value is an object.
13+
14+
This rule does not check syntax errors in directives because it's checked by [no-parsing-error] rule.
15+
16+
:-1: Examples of **incorrect** code for this rule:
17+
18+
```html
19+
<template>
20+
<div>
21+
<div v-bind></div>
22+
<div :aaa></div>
23+
<div v-bind:aaa.bbb="foo"></div>
24+
</div>
25+
</template>
26+
```
27+
28+
:+1: Examples of **correct** code for this rule:
29+
30+
```html
31+
<template>
32+
<div>
33+
<div v-bind="foo"></div>
34+
<div v-bind:aaa="foo"></div>
35+
<div :aaa="foo"></div>
36+
<div :aaa.prop="foo"></div>
37+
</div>
38+
</template>
39+
```
40+
41+
## :wrench: Options
42+
43+
Nothing.
44+
45+
## :couple: Related rules
46+
47+
- [no-parsing-error]
48+
49+
50+
[no-parsing-error]: no-parsing-error.md

docs/rules/valid-v-cloak.md

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Enforce valid `v-cloak` directives (valid-v-cloak)
2+
3+
This rule checks whether every `v-cloak` directive is valid.
4+
5+
## :book: Rule Details
6+
7+
This rule reports `v-cloak` directives in the following cases:
8+
9+
- The directive has that argument. E.g. `<div v-cloak:aaa></div>`
10+
- The directive has that modifier. E.g. `<div v-cloak.bbb></div>`
11+
- The directive has that attribute value. E.g. `<div v-cloak="ccc"></div>`
12+
13+
:-1: Examples of **incorrect** code for this rule:
14+
15+
```html
16+
<template>
17+
<div>
18+
<div v-cloak:aaa></div>
19+
<div v-cloak.bbb></div>
20+
<div v-cloak="ccc"></div>
21+
</div>
22+
</template>
23+
```
24+
25+
:+1: Examples of **correct** code for this rule:
26+
27+
```html
28+
<template>
29+
<div>
30+
<div v-cloak></div>
31+
</div>
32+
</template>
33+
```
34+
35+
## :wrench: Options
36+
37+
Nothing.

docs/rules/valid-v-else-if.md

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# Enforce valid `v-else-if` directives (valid-v-else-if)
2+
3+
This rule checks whether every `v-else-if` directive is valid.
4+
5+
## :book: Rule Details
6+
7+
This rule reports `v-else-if` directives in the following cases:
8+
9+
- The directive has that argument. E.g. `<div v-if="foo"></div><div v-else-if:aaa="bar"></div>`
10+
- The directive has that modifier. E.g. `<div v-if="foo"></div><div v-else-if.bbb="bar"></div>`
11+
- The directive does not have that attribute value. E.g. `<div v-if="foo"></div><div v-else-if></div>`
12+
- The directive is on the elements that the previous element don't have `v-if`/`v-else-if` directives. E.g. `<div v-else-if="bar"></div>`
13+
- The directive is on the elements which have `v-if`/`v-else` directives. E.g. `<div v-if="foo" v-else-if="bar"></div>`
14+
15+
This rule does not check syntax errors in directives because it's checked by [no-parsing-error] rule.
16+
17+
:-1: Examples of **incorrect** code for this rule:
18+
19+
```html
20+
<template>
21+
<div>
22+
<div v-else-if></div>
23+
<div v-else-if:aaa="foo"></div>
24+
<div v-else-if.bbb="foo"></div>
25+
</div>
26+
</template>
27+
```
28+
29+
:+1: Examples of **correct** code for this rule:
30+
31+
```html
32+
<template>
33+
<div>
34+
<div v-if="foo"></div>
35+
<div v-else-if="bar"></div>
36+
</div>
37+
</template>
38+
```
39+
40+
## :wrench: Options
41+
42+
Nothing.
43+
44+
## :couple: Related rules
45+
46+
- [valid-v-if]
47+
- [valid-v-else]
48+
- [no-parsing-error]
49+
50+
51+
[valid-v-if]: valid-v-if.md
52+
[valid-v-else]: valid-v-else.md
53+
[no-parsing-error]: no-parsing-error.md

docs/rules/valid-v-else.md

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Enforce valid `v-else` directives (valid-v-else)
2+
3+
This rule checks whether every `v-else` directive is valid.
4+
5+
## :book: Rule Details
6+
7+
This rule reports `v-else` directives in the following cases:
8+
9+
- The directive has that argument. E.g. `<div v-if="foo"></div><div v-else:aaa></div>`
10+
- The directive has that modifier. E.g. `<div v-if="foo"></div><div v-else.bbb></div>`
11+
- The directive has that attribute value. E.g. `<div v-if="foo"></div><div v-else="bar"></div>`
12+
- The directive is on the elements that the previous element don't have `v-if`/`v-if-else` directives. E.g. `<div v-else></div>`
13+
- The directive is on the elements which have `v-if`/`v-if-else` directives. E.g. `<div v-if="foo" v-else></div>`
14+
15+
:-1: Examples of **incorrect** code for this rule:
16+
17+
```html
18+
<template>
19+
<div>
20+
<div v-else="foo"></div>
21+
<div v-else:aaa></div>
22+
<div v-else.bbb></div>
23+
</div>
24+
</template>
25+
```
26+
27+
:+1: Examples of **correct** code for this rule:
28+
29+
```html
30+
<template>
31+
<div>
32+
<div v-if="foo"></div>
33+
<div v-else></div>
34+
</div>
35+
</template>
36+
```
37+
38+
## :wrench: Options
39+
40+
Nothing.
41+
42+
## :couple: Related rules
43+
44+
- [valid-v-if]
45+
- [valid-v-else-if]
46+
- [no-parsing-error]
47+
48+
49+
[valid-v-if]: valid-v-if.md
50+
[valid-v-else-if]: valid-v-else-if.md
51+
[no-parsing-error]: no-parsing-error.md

0 commit comments

Comments
 (0)