Skip to content

Commit b5a2da4

Browse files
committed
Merge remote-tracking branch 'origin/master' into vuepress
# Conflicts: # README.md
2 parents f624ae9 + 74f7dc6 commit b5a2da4

File tree

81 files changed

+1160
-128
lines changed

Some content is hidden

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

81 files changed

+1160
-128
lines changed

README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,30 @@ Contributing is welcome!
3232

3333
See https://vuejs.github.io/eslint-plugin-vue/developer-guide/
3434

35+
### Working with rules
36+
37+
Before you start writing new rule, please read the [official ESLint guide](https://eslint.org/docs/developer-guide/working-with-rules).
38+
39+
Next in order to get an idea how does the AST of the code that you want to check looks like, you can use one of the following applications:
40+
- [astexplorer.net](http://astexplorer.net/) - best tool to inspect ASTs, but it doesn't support Vue templates yet
41+
- [ast.js.org](https://ast.js.org/) - not fully featured, but supports Vue templates syntax
42+
43+
Since single file components in Vue are not plain JavaScript, we can't use the default parser, and we had to introduce additional one: `vue-eslint-parser`, that generates enhanced AST with nodes that represent specific parts of the template syntax, as well as what's inside the `<script>` tag.
44+
45+
To know more about certain nodes in produced ASTs, go here:
46+
- [ESTree docs](https://github.com/estree/estree)
47+
- [vue-eslint-parser AST docs](https://github.com/mysticatea/vue-eslint-parser/blob/master/docs/ast.md)
48+
49+
The `vue-eslint-parser` provides few useful parser services, to help traverse the produced AST and access tokens of the template:
50+
- `context.parserServices.defineTemplateBodyVisitor(visitor, scriptVisitor)`
51+
- `context.parserServices.getTemplateBodyTokenStore()`
52+
53+
Check out an [example rule](https://github.com/vuejs/eslint-plugin-vue/blob/master/lib/rules/mustache-interpolation-spacing.js) to get a better understanding of how these work.
54+
55+
Please be aware that regarding what kind of code examples you'll write in tests, you'll have to accordingly setup the parser in `RuleTester` (you can do it on per test case basis though). [See an example here](https://github.com/vuejs/eslint-plugin-vue/blob/master/tests/lib/rules/attribute-hyphenation.js#L19)
56+
57+
If you'll stuck, remember there are plenty of rules you can learn from already, and if you can't find the right solution - don't hesitate to reach out in issues. We're happy to help!
58+
3559
## :lock: License
3660

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

docs/rules/attributes-order.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,16 @@ Specify custom order of attribute groups
9090
:+1: Examples of **correct** code with custom order`:
9191

9292
```html
93-
<!-- 'vue/attributes-order': [2, { order: ['LIST_RENDERING', 'CONDITIONALS', 'RENDER_MODIFIERS', 'GLOBAL', 'UNIQUE', 'TWO_WAY_BINDING', 'OTHER_DIRECTIVES', 'OTHER_ATTR', 'EVENTS', 'CONTENT', 'DEFINITION'] }] -->
93+
<!-- 'vue/attributes-order': [2, { order: ['DEFINITION', 'LIST_RENDERING', 'CONDITIONALS', 'RENDER_MODIFIERS', 'GLOBAL', 'UNIQUE', ['BINDING', 'OTHER_ATTR'], 'EVENTS', 'CONTENT'] }] -->
94+
<div
95+
is="header"
96+
prop-one="prop"
97+
:prop-two="prop">
98+
</div>
99+
```
100+
101+
```html
102+
<!-- 'vue/attributes-order': [2, { order: ['LIST_RENDERING', 'CONDITIONALS', 'RENDER_MODIFIERS', 'GLOBAL', 'UNIQUE', 'BINDING', 'OTHER_ATTR', 'EVENTS', 'CONTENT', 'DEFINITION'] }] -->
94103
<div
95104
prop-one="prop"
96105
prop-two="prop"
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
# enforce specific casing for the component naming style in template (vue/component-name-in-template-casing)
2+
3+
- :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.
4+
5+
Define a style for the component name in template casing for consistency purposes.
6+
7+
## :book: Rule Details
8+
9+
:+1: Examples of **correct** code for `PascalCase`:
10+
11+
```html
12+
<template>
13+
<TheComponent />
14+
</template>
15+
```
16+
17+
:-1: Examples of **incorrect** code for `PascalCase`:
18+
19+
```html
20+
<template>
21+
<the-component />
22+
<theComponent />
23+
<The-component />
24+
</template>
25+
```
26+
27+
:+1: Examples of **correct** code for `kebab-case`:
28+
29+
```html
30+
<template>
31+
<the-component />
32+
</template>
33+
```
34+
35+
:-1: Examples of **incorrect** code for `kebab-case`:
36+
37+
```html
38+
<template>
39+
<TheComponent />
40+
<theComponent />
41+
<Thecomponent />
42+
<The-component />
43+
</template>
44+
```
45+
46+
## :wrench: Options
47+
48+
Default casing is set to `PascalCase`.
49+
50+
```json
51+
"vue/component-name-in-template-casing": ["error",
52+
"PascalCase|kebab-case",
53+
{
54+
"ignores": []
55+
}
56+
]
57+
```
58+
59+
- `ignores` (`string[]`) ... The element name to ignore. Sets the element name to allow. For example, a custom element or a non-Vue component.
60+
61+
62+
:+1: Examples of **correct** code for `{ignores: ["custom-element"]}`:
63+
64+
```html
65+
<template>
66+
<custom-element></custom-element>
67+
<TheComponent/>
68+
</template>
69+
```
70+
71+
## Related links
72+
73+
- [Style guide - Component name casing in templates](https://vuejs.org/v2/style-guide/#Component-name-casing-in-templates-strongly-recommended)

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

Lines changed: 17 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# require or disallow a line break before tag's closing brackets (vue/html-closing-bracket-newline)
22

3+
- :gear: This rule is included in `"plugin:vue/strongly-recommended"` and `"plugin:vue/recommended"`.
34
- :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.
45

56
People have own preference about the ___location of closing brackets.
@@ -24,7 +25,7 @@ This rule enforces a line break (or no line break) before tag's closing brackets
2425
{
2526
"vue/html-closing-bracket-newline": ["error", {
2627
"singleline": "never",
27-
"multiline": "never"
28+
"multiline": "always"
2829
}]
2930
}
3031
```
@@ -33,65 +34,55 @@ This rule enforces a line break (or no line break) before tag's closing brackets
3334
- `"never"` ... disallow line breaks before the closing bracket. This is the default.
3435
- `"always"` ... require one line break before the closing bracket.
3536
- `multiline` ... the configuration for multiline elements. It's a multiline element if the last attribute is not on the same line of the opening bracket.
36-
- `"never"` ... disallow line breaks before the closing bracket. This is the default.
37-
- `"always"` ... require one line break before the closing bracket.
37+
- `"never"` ... disallow line breaks before the closing bracket.
38+
- `"always"` ... require one line break before the closing bracket. This is the default.
3839

3940
Plus, you can use [`vue/html-indent`](./html-indent.md) rule to enforce indent-level of the closing brackets.
4041

4142
:-1: Examples of **incorrect** code for this rule:
4243

4344
```html
44-
/*eslint html-closing-bracket-newline: "error"*/
45+
<!-- eslint html-closing-bracket-newline: "error" -->
4546

4647
<div id="foo" class="bar"
4748
>
49+
4850
<div
4951
id="foo"
50-
class="bar"
51-
>
52-
<div
53-
id="foo"
54-
class="bar"
55-
>
52+
class="bar">
5653
```
5754

5855
:+1: Examples of **correct** code for this rule:
5956

6057
```html
61-
/*eslint html-closing-bracket-newline: "error"*/
58+
<!-- eslint html-closing-bracket-newline: "error" -->
6259

6360
<div id="foo" class="bar">
6461
<div
6562
id="foo"
66-
class="bar">
63+
class="bar"
64+
>
6765
```
6866

69-
:-1: Examples of **incorrect** code for `{ "multiline": "always" }`:
67+
:-1: Examples of **incorrect** code for `{ "multiline": "never" }`:
7068

7169
```html
72-
/*eslint html-closing-bracket-newline: ["error", { multiline: always }]*/
70+
<!-- eslint html-closing-bracket-newline: ["error", { multiline: never }] -->
7371

74-
<div id="foo" class="bar"
75-
>
7672
<div
7773
id="foo"
78-
class="bar">
74+
class="bar"
75+
>
7976
```
8077

81-
:+1: Examples of **correct** code for `{ "multiline": "always" }`:
78+
:+1: Examples of **correct** code for `{ "multiline": "never" }`:
8279

8380
```html
84-
/*eslint html-closing-bracket-newline: ["error", { multiline: always }]*/
81+
<!-- html-closing-bracket-newline: ["error", { multiline: never }] -->
8582

86-
<div id="foo" class="bar">
8783
<div
8884
id="foo"
89-
class="bar"
90-
>
91-
<div
92-
id="foo"
93-
class="bar"
94-
>
85+
class="bar">
9586
```
9687

9788
## :mag: Implementation

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# require or disallow a space before tag's closing brackets (vue/html-closing-bracket-spacing)
22

3+
- :gear: This rule is included in `"plugin:vue/strongly-recommended"` and `"plugin:vue/recommended"`.
34
- :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.
45

56
This rule enforces consistent spacing style before closing brackets `>` of tags.

docs/rules/no-confusing-v-for-v-if.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# disallow confusing `v-for` and `v-if` on the same element (vue/no-confusing-v-for-v-if)
22

33
- :gear: This rule is included in `"plugin:vue/recommended"`.
4+
- :warning: This rule was **deprecated** and replaced by [vue/no-use-v-if-with-v-for](no-use-v-if-with-v-for.md) rule.
45

56
> When they exist on the same node, `v-for` has a higher priority than `v-if`. That means the `v-if` will be run on each iteration of the loop separately.
67
>

docs/rules/no-template-shadow.md

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# disallow variable declarations from shadowing variables declared in the outer scope (vue/no-template-shadow)
2+
3+
- :gear: This rule is included in `"plugin:vue/strongly-recommended"` and `"plugin:vue/recommended"`.
4+
5+
`no-template-shadow` should report variable definitions of v-for directives or scope attributes if those shadows the variables in parent scopes.
6+
7+
## :book: Rule Details
8+
9+
This rule aims to eliminate shadowed variable declarations of v-for directives or scope attributes.
10+
11+
:-1: Examples of **incorrect** code for this rule:
12+
13+
```html
14+
<template>
15+
<div>
16+
<div v-for="i in 5">
17+
<div v-for="i in 10"></div>
18+
</div>
19+
</div>
20+
</template>
21+
```
22+
23+
```html
24+
<template>
25+
<div>
26+
<div v-for="i in 5"></div>
27+
</div>
28+
</template>
29+
<script>
30+
export default {
31+
data () {
32+
return {
33+
i: 10
34+
}
35+
}
36+
}
37+
</script>
38+
```
39+
40+
:+1: Examples of **correct** code for this rule:
41+
42+
```html
43+
<template>
44+
<div v-for="i in 5"></div>
45+
<div v-for="i in 5"></div>
46+
</template>
47+
<script>
48+
export default {
49+
computed: {
50+
f () { }
51+
}
52+
}
53+
</script>
54+
```
55+
56+
## :wrench: Options
57+
58+
Nothing.

docs/rules/no-use-v-if-with-v-for.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# disallow use v-if on the same element as v-for (vue/no-use-v-if-with-v-for)
22

3+
- :gear: This rule is included in all of `"plugin:vue/essential"`, `"plugin:vue/strongly-recommended"` and `"plugin:vue/recommended"`.
4+
35
> Never use `v-if` on the same element as `v-for`.
46
>
57
> There are two common cases where this can be tempting:

docs/rules/no-v-html.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# disallow use of v-html to prevent XSS attack (vue/no-v-html)
22

3+
- :gear: This rule is included in `"plugin:vue/recommended"`.
4+
35
This rule reports use of `v-html` directive in order to reduce the risk of injecting potentially unsafe / unescaped html into the browser leading to Cross Side Scripting (XSS) attacks.
46

57
## :book: Rule Details

docs/rules/prop-name-casing.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# enforce specific casing for the Prop name in Vue components (vue/prop-name-casing)
22

3+
- :gear: This rule is included in `"plugin:vue/strongly-recommended"` and `"plugin:vue/recommended"`.
34
- :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.
45

56
This rule would enforce proper casing of props in vue components(camelCase).

0 commit comments

Comments
 (0)