Skip to content

Commit 2f451eb

Browse files
committed
update component-name-in-template-casing
1 parent 2cd1959 commit 2f451eb

File tree

1 file changed

+43
-33
lines changed

1 file changed

+43
-33
lines changed

docs/rules/component-name-in-template-casing.md

Lines changed: 43 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -6,68 +6,78 @@ Define a style for the component name in template casing for consistency purpose
66

77
## :book: Rule Details
88

9-
:+1: Examples of **correct** code for `PascalCase`:
9+
This rule aims to warn the tag names other than the configured casing in Vue.js template.
1010

11-
```html
12-
<template>
13-
<TheComponent />
14-
</template>
11+
## :wrench: Options
12+
13+
```json
14+
{
15+
"vue/component-name-in-template-casing": [
16+
"error",
17+
"PascalCase" | "kebab-case",
18+
{ "ignores": [] }
19+
]
20+
}
1521
```
1622

17-
:-1: Examples of **incorrect** code for `PascalCase`:
23+
- `"PascalCase"` (default) ... enforce tag names to pascal case. E.g. `<CoolComponent>`. This is consistent with the JSX practice.
24+
- `"kebab-case"` ... enforce tag names to kebab case: E.g. `<cool-component>`. This is consistent with the HTML practice which is case-insensitive originally.
25+
- `ignores` (`string[]`) ... The element names to ignore. Sets the element name to allow. For example, a custom element or a non-Vue component.
1826

19-
```html
27+
### `"PascalCase"`
28+
29+
<eslint-code-block :rules="{'vue/component-name-in-template-casing': ['error']}">
30+
```
2031
<template>
32+
<!-- ✓ GOOD -->
33+
<TheComponent />
34+
35+
<!-- ✗ BAD -->
2136
<the-component />
2237
<theComponent />
2338
<The-component />
2439
</template>
2540
```
41+
</eslint-code-block>
2642

27-
:+1: Examples of **correct** code for `kebab-case`:
43+
### `"kebab-case"`
2844

29-
```html
45+
<eslint-code-block :rules="{'vue/component-name-in-template-casing': ['error', 'kebab-case']}">
46+
```
3047
<template>
48+
<!-- ✓ GOOD -->
3149
<the-component />
32-
</template>
33-
```
3450
35-
:-1: Examples of **incorrect** code for `kebab-case`:
36-
37-
```html
38-
<template>
51+
<!-- ✗ BAD -->
3952
<TheComponent />
4053
<theComponent />
4154
<Thecomponent />
4255
<The-component />
4356
</template>
4457
```
58+
</eslint-code-block>
4559

46-
## :wrench: Options
4760

48-
Default casing is set to `PascalCase`.
61+
### `"PascalCase", { ignores: ["custom-element"] }`
4962

50-
```json
51-
"vue/component-name-in-template-casing": ["error",
52-
"PascalCase|kebab-case",
53-
{
54-
"ignores": []
55-
}
56-
]
63+
<eslint-code-block :rules="{'vue/component-name-in-template-casing': ['error', 'PascalCase', {ignores: ['custom-element']}]}">
5764
```
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
6565
<template>
66-
<custom-element></custom-element>
66+
<!-- ✓ GOOD -->
6767
<TheComponent/>
68+
<custom-element></custom-element>
69+
70+
<!-- ✗ BAD -->
71+
<magic-element></magic-element>
6872
</template>
6973
```
74+
</eslint-code-block>
7075

71-
## Related links
76+
## :books: Further reading
7277

7378
- [Style guide - Component name casing in templates](https://vuejs.org/v2/style-guide/#Component-name-casing-in-templates-strongly-recommended)
79+
80+
## :mag: Implementation
81+
82+
- [Rule source](https://github.com/vuejs/eslint-plugin-vue/blob/master/lib/rules/component-name-in-template-casing.js)
83+
- [Test source](https://github.com/vuejs/eslint-plugin-vue/blob/master/tests/lib/rules/component-name-in-template-casing.js)

0 commit comments

Comments
 (0)