Skip to content

Issues with vue/no-unused-components #556

Closed
@sqal

Description

@sqal

Tell us about your environment

  • ESLint Version: 5.3.0
  • eslint-plugin-vue Version: 5.0.0-beta.3
  • Node Version: 10.4.1

Please show your full configuration:

module.exports = {
  root: true,
  extends: [
    'airbnb-base',
    'plugin:vue/strongly-recommended',
  ],
  parserOptions: {
    parser: 'babel-eslint',
  },
  plugins: ['vue'],
};

What did you do? Please include the actual source code causing the issue.

Issue 1

<template>
  <div id="app" class="flex flex-col h-screen">
    <Header></Header>
    <div class="flex-fill">
      <router-view></router-view>
    </div>
    <Footer></Footer>
  </div>
</template>

<script>
  import Header from 'components/Layout/Header';
  import Footer from 'components/Layout/Footer';

  export default {
    name: 'App',
    components: {
      Header,
      Footer,
    },
  };
</script>

Erors:

  18:7  error  The "Header" component has been registered but not used  vue/no-unused-components
  19:7  error  The "Footer" component has been registered but not used  vue/no-unused-components

Issue 2

<template>
  <div>
    <component :is="dynamicComponent"></component>
  </div>
</template>

<script>
  import Foo from 'components/Foo';
  import Bar from 'components/Bar';

  export default {
    name: 'App',
    components: {
      Foo,
      Bar,
    },
    computed: {
      dynamicComponent() {
        if (this.condition) {
          return 'Foo';
        }

        return 'Bar';
      },
    },
  };
</script>

Errors:

  14:7   error  The "Foo" component has been registered but not used  vue/no-unused-components
  15:7   error  The "Bar" component has been registered but not used  vue/no-unused-components

What did you expect to happen?

Regarding issue nr. 1.

As you can see, in the template I write components names in PascalCase because both header and footer are reserved html names. In this case I expect the plugin can detect whether component name is written in PascalCase or kebab-case.

Regarding issue nr. 2.

This is probably a very common case when someone uses dynamic component tag and uses computed property to switch between some components. In this case I think it would be great if I could somehow tell the plugin to ignore the components that are registered via special <component /> tag.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions