JS.VUE.COMPONENT.NAME.IN.TEMPLATE.CASING

Enforce specific casing for the component naming style in template

Define a style for the component name in template casing for consistency purposes.

Rule Details

This rule aims to warn the tag names other than the configured casing in Vue.js template.

Options

Copy
{
  "vue/component-name-in-template-casing": ["error", "PascalCase" | "kebab-case", {
    "registeredComponentsOnly": true,
    "ignores": []
  }]
}
  • "PascalCase" (default) ... enforce tag names to pascal case. E.g. <CoolComponent>. This is consistent with the JSX practice.
  • "kebab-case" ... enforce tag names to kebab case: E.g. <cool-component>. This is consistent with the HTML practice which is case-insensitive originally.
  • registeredComponentsOnly ... If true, only registered components (in PascalCase) are checked. If false, check all. default true
  • ignores (string[]) ... The element names to ignore. Sets the element name to allow. For example, custom elements or Vue components with special name. You can set the regexp by writing it like "/^name/".

"PascalCase", { registeredComponentsOnly: true } (default)

{'vue/component-name-in-template-casing': ['error']}

Copy
<template>
  <!-- GOOD -->
  <CoolComponent />

  <!-- BAD -->
  <cool-component />
  <coolComponent />
  <Cool-component />

  <!-- ignore -->
  <UnregisteredComponent />
  <unregistered-component />

  <registered-in-kebab-case />
  <registeredInCamelCase />
</template>
<script>
export default {
  components: {
    CoolComponent,
    'registered-in-kebab-case': VueComponent1,
    'registeredInCamelCase': VueComponent2
  }
}
</script>

"kebab-case"

{'vue/component-name-in-template-casing': ['error', 'kebab-case']}

Copy
<template>
  <!-- GOOD -->
  <cool-component />

  <!-- BAD -->
  <CoolComponent />
  <coolComponent />
  <Cool-component />

  <!-- ignore -->
  <unregistered-component />
  <UnregisteredComponent />
</template>
<script>
export default {
  components: {
    CoolComponent
  }
}
</script>

"PascalCase", { registeredComponentsOnly: false }

{'vue/component-name-in-template-casing': ['error', 'PascalCase', { registeredComponentsOnly: false }]}

Copy
<template>
  <!-- GOOD -->
  <CoolComponent />
  <UnregisteredComponent />

  <!-- BAD -->
  <cool-component />
  <unregistered-component />
</template>
<script>
export default {
  components: {
    CoolComponent
  }
}
</script>

"PascalCase", { ignores: ["/^custom-/"], registeredComponentsOnly: false }

{'vue/component-name-in-template-casing': ['error', 'PascalCase', {ignores: ['/^custom-/'], registeredComponentsOnly: false}]}

Copy
<template>
  <!-- GOOD -->
  <CoolComponent/>
  <custom-element></custom-element>
  <custom-button></custom-button>
  <custom-input />

  <!-- BAD -->
  <magic-element></magic-element>
</template>

Further Reading

  • Style guide - Component name casing in templates (https://vuejs.org/style-guide/rules-strongly-recommended.html#component-name-casing-in-templates)

The content on this page is adapted from the ESLint User Guide. Copyright © OpenJS Foundation and other contributors, www.openjsf.org. All rights reserved. https://eslint.org/docs/rules/