|
1 |
| -# enforce specific casing for component definition name (vue/component-definition-name-casing) |
| 1 | +--- |
| 2 | +pageClass: rule-details |
| 3 | +sidebarDepth: 0 |
| 4 | +title: vue/component-definition-name-casing |
| 5 | +description: enforce specific casing for component definition name |
| 6 | +--- |
| 7 | +# vue/component-definition-name-casing |
| 8 | +> enforce specific casing for component definition name |
2 | 9 |
|
3 | 10 | - :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 | 11 |
|
| 12 | +## :book: Rule Details |
| 13 | + |
5 | 14 | Define a style for component definition name casing for consistency purposes.
|
6 | 15 |
|
7 |
| -## :book: Rule Details |
| 16 | +## :wrench: Options |
8 | 17 |
|
9 |
| -:+1: Examples of **correct** code for `PascalCase`: |
| 18 | +Default casing is set to `PascalCase`. |
10 | 19 |
|
11 |
| -```js |
| 20 | +```json |
| 21 | +{ |
| 22 | + "vue/component-definition-name-casing": ["error", "PascalCase" | "kebab-case"] |
| 23 | +} |
| 24 | +``` |
| 25 | + |
| 26 | +- `"PascalCase"` (default) ... enforce component definition names to pascal case. |
| 27 | +- `"kebab-case"` ... enforce component definition names to kebab case. |
| 28 | + |
| 29 | +### `"PascalCase" (default) |
| 30 | + |
| 31 | +<eslint-code-block fix :rules="{'vue/component-definition-name-casing': ['error']}"> |
| 32 | + |
| 33 | +```vue |
| 34 | +<script> |
12 | 35 | export default {
|
| 36 | + /* ✓ GOOD */ |
13 | 37 | name: 'MyComponent'
|
14 | 38 | }
|
| 39 | +</script> |
15 | 40 | ```
|
| 41 | + |
| 42 | +</eslint-code-block> |
| 43 | + |
| 44 | +<eslint-code-block fix :rules="{'vue/component-definition-name-casing': ['error']}"> |
| 45 | + |
| 46 | +```vue |
| 47 | +<script> |
| 48 | +export default { |
| 49 | + /* ✗ BAD */ |
| 50 | + name: 'my-component' |
| 51 | +} |
| 52 | +</script> |
| 53 | +``` |
| 54 | + |
| 55 | +</eslint-code-block> |
| 56 | + |
| 57 | +<eslint-code-block fix language="javascript" filename="src/MyComponent.js" :rules="{'vue/component-definition-name-casing': ['error']}"> |
| 58 | + |
16 | 59 | ```js
|
| 60 | +/* ✓ GOOD */ |
17 | 61 | Vue.component('MyComponent', {
|
18 | 62 |
|
| 63 | +}) |
| 64 | + |
| 65 | +/* ✗ BAD */ |
| 66 | +Vue.component('my-component', { |
| 67 | + |
19 | 68 | })
|
20 | 69 | ```
|
21 | 70 |
|
22 |
| -:+1: Examples of **correct** code for `kebab-case`: |
| 71 | +</eslint-code-block> |
23 | 72 |
|
24 |
| -```js |
| 73 | +### `"kebab-case" |
| 74 | + |
| 75 | +<eslint-code-block fix :rules="{'vue/component-definition-name-casing': ['error', 'kebab-case']}"> |
| 76 | + |
| 77 | +```vue |
| 78 | +<script> |
25 | 79 | export default {
|
| 80 | + /* ✓ GOOD */ |
26 | 81 | name: 'my-component'
|
27 | 82 | }
|
| 83 | +</script> |
28 | 84 | ```
|
| 85 | + |
| 86 | +</eslint-code-block> |
| 87 | + |
| 88 | +<eslint-code-block fix :rules="{'vue/component-definition-name-casing': ['error', 'kebab-case']}"> |
| 89 | + |
| 90 | +```vue |
| 91 | +<script> |
| 92 | +export default { |
| 93 | + /* ✗ BAD */ |
| 94 | + name: 'MyComponent' |
| 95 | +} |
| 96 | +</script> |
| 97 | +``` |
| 98 | + |
| 99 | +</eslint-code-block> |
| 100 | + |
| 101 | +<eslint-code-block fix language="javascript" filename="src/MyComponent.js" :rules="{'vue/component-definition-name-casing': ['error', 'kebab-case']}"> |
| 102 | + |
29 | 103 | ```js
|
| 104 | +/* ✓ GOOD */ |
30 | 105 | Vue.component('my-component', {
|
31 | 106 |
|
| 107 | +}) |
| 108 | + |
| 109 | +/* ✗ BAD */ |
| 110 | +Vue.component('MyComponent', { |
| 111 | + |
32 | 112 | })
|
33 | 113 | ```
|
34 | 114 |
|
35 |
| -## :wrench: Options |
| 115 | +</eslint-code-block> |
36 | 116 |
|
37 |
| -Default casing is set to `PascalCase`. |
| 117 | +## :books: Further reading |
38 | 118 |
|
39 |
| -```json |
40 |
| -{ |
41 |
| - "vue/component-definition-name-casing": ["error", "PascalCase|kebab-case"] |
42 |
| -} |
43 |
| -``` |
| 119 | +- [Style guide - Component name casing in JS/JSX](https://vuejs.org/v2/style-guide/#Component-name-casing-in-JS-JSX-strongly-recommended) |
44 | 120 |
|
45 |
| -## Related links |
| 121 | +## :mag: Implementation |
46 | 122 |
|
47 |
| -- [Style guide - Component name casing in JS/JSX](https://vuejs.org/v2/style-guide/#Component-name-casing-in-JS-JSX-strongly-recommended) |
| 123 | +- [Rule source](https://github.com/vuejs/eslint-plugin-vue/blob/master/lib/rules/component-definition-name-casing.js) |
| 124 | +- [Test source](https://github.com/vuejs/eslint-plugin-vue/blob/master/tests/lib/rules/component-definition-name-casing.js) |
0 commit comments