Skip to content
  • Sponsor
  • Notifications You must be signed in to change notification settings
  • Fork 696

Rule proposal: no-unused-component #414

@xiGUAwanOU

Description

@xiGUAwanOU

Hello there,

In the SFC-styled component definition, one can import a component, and then register it in the components section, while not using it in the template. See the example below:

<template>
  <div>I'm not using any component.</div>
</template>

<script>
  import SomeComponent from './somewhere'
  export default {
    components: {
      SomeComponent  // Should be treated as unused component
    }
  }
</script>

In this case, the imported component is considered as used variable according to standard eslint rules, since the components section contains its reference. If there is a rule in eslint-plugin-vue that could prevent this happening, it would be great.

Cheers,
Zihan

Activity

chrisvfritz

chrisvfritz commented on Jul 31, 2018

@chrisvfritz
Contributor

I agree this would be great - I'd put it in strongly-recommended.

added a commit that references this issue on Aug 13, 2018
Error8673fc3
xiGUAwanOU

xiGUAwanOU commented on Aug 14, 2018

@xiGUAwanOU
Author

Thank you very much for implementing the rule, it helps us a lot! 👍

AnonymousArthur

AnonymousArthur commented on Aug 15, 2018

@AnonymousArthur

What about syntax like:
<template><component is="component_name"/></template>
when

const component_1 = import('./component_1.vue')
export default {
  components: {
    'component_name': component_1
  }
}

this is primarily used for dynamic components.
This currently can not be identified as used component.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Rule proposal: no-unused-component · Issue #414 · vuejs/eslint-plugin-vue