8000 Rule proposal: no-unused-component · Issue #414 · vuejs/eslint-plugin-vue · GitHub
[go: up one dir, main page]

Skip to content

Rule proposal: no-unused-component #414

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
xiGUAwanOU opened this issue Mar 1, 2018 · 3 comments
Closed

Rule proposal: no-unused-component #414

xiGUAwanOU opened this issue Mar 1, 2018 · 3 comments

Comments

@xiGUAwanOU
Copy link
xiGUAwanOU commented Mar 1, 2018

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

@chrisvfritz
Copy link
Contributor

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

michalsnik added a commit that referenced this issue Aug 13, 2018
* Add "no-unused-components" rule

* Handle case with Literal in :is binding expression, update docs

* Update no-unused-components.md
@xiGUAwanOU
Copy link
Author

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

@AnonymousArthur
Copy link

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
Projects
None yet
Development

No branches or pull requests

4 participants
0