Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix multiple reporting of same warnings in vue/no-unregistered-component #1382

Merged
merged 3 commits into from Dec 18, 2020

Conversation

enzo360
Copy link
Contributor

@enzo360 enzo360 commented Dec 17, 2020

Hi 馃憢 First, thank you for your work on this project 馃檹
It is my first open-source PR, I hope it is the right way to do.

Issue

In components' templates using multiple <template> to target named slots, I noticed the vue/no-unregistered-component linter warnings were repeated as many times as there are <template>s, for the same unregistered components.
It is not very convenient, especially for large projects ongoing refactoring.

Example

<template>
  <TableView>

    <template #name>
      {{ tableViewName }}
    </template>

    <template #footer>
      <TableViewFooter>

        <template #action>
          <CustomButton />
        </template>

      </TableViewFooter>
    </template>

  </TableView>
</template>
Would display these errors:
warning: The "TableView" component has been used but not registered (vue/no-unregistered-components) at src/components/HelloWorld.vue:2:3:
  1 | <template>
> 2 |   <TableView>
    |   ^
  3 |     <template #name>
  4 |       {{ tableViewName }}
  5 |     </template>


warning: The "TableView" component has been used but not registered (vue/no-unregistered-components) at src/components/HelloWorld.vue:2:3:
  1 | <template>
> 2 |   <TableView>
    |   ^
  3 |     <template #name>
  4 |       {{ tableViewName }}
  5 |     </template>


warning: The "TableView" component has been used but not registered (vue/no-unregistered-components) at src/components/HelloWorld.vue:2:3:
  1 | <template>
> 2 |   <TableView>
    |   ^
  3 |     <template #name>
  4 |       {{ tableViewName }}
  5 |     </template>


warning: The "TableView" component has been used but not registered (vue/no-unregistered-components) at src/components/HelloWorld.vue:2:3:
  1 | <template>
> 2 |   <TableView>
    |   ^
  3 |     <template #name>
  4 |       {{ tableViewName }}
  5 |     </template>


warning: The "TableViewFooter" component has been used but not registered (vue/no-unregistered-components) at src/components/HelloWorld.vue:7:7:
   5 |     </template>
   6 |     <template #footer>
>  7 |       <TableViewFooter>
     |       ^
   8 |         <template #action>
   9 |           <CustomButton />
  10 |         </template>


warning: The "TableViewFooter" component has been used but not registered (vue/no-unregistered-components) at src/components/HelloWorld.vue:7:7:
   5 |     </template>
   6 |     <template #footer>
>  7 |       <TableViewFooter>
     |       ^
   8 |         <template #action>
   9 |           <CustomButton />
  10 |         </template>


warning: The "TableViewFooter" component has been used but not registered (vue/no-unregistered-components) at src/components/HelloWorld.vue:7:7:
   5 |     </template>
   6 |     <template #footer>
>  7 |       <TableViewFooter>
     |       ^
   8 |         <template #action>
   9 |           <CustomButton />
  10 |         </template>


warning: The "CustomButton" component has been used but not registered (vue/no-unregistered-components) at src/components/HelloWorld.vue:9:11:
   7 |       <TableViewFooter>
   8 |         <template #action>
>  9 |           <CustomButton />
     |           ^
  10 |         </template>
  11 |       </TableViewFooter>
  12 |     </template>


warning: The "CustomButton" component has been used but not registered (vue/no-unregistered-components) at src/components/HelloWorld.vue:9:11:
   7 |       <TableViewFooter>
   8 |         <template #action>
>  9 |           <CustomButton />
     |           ^
  10 |         </template>
  11 |       </TableViewFooter>
  12 |     </template>


warning: The "CustomButton" component has been used but not registered (vue/no-unregistered-components) at src/components/HelloWorld.vue:9:11:
   7 |       <TableViewFooter>
   8 |         <template #action>
>  9 |           <CustomButton />
     |           ^
  10 |         </template>
  11 |       </TableViewFooter>
  12 |     </template>


10 warnings found.

Potential fix

Quick fix I could find from the existing code is to only use the root template to report the errors.

Resulting in the following warnings:
warning: The "TableView" component has been used but not registered (vue/no-unregistered-components) at src/components/HelloWorld.vue:2:3:
  1 | <template>
> 2 |   <TableView>
    |   ^
  3 |     <template #name>
  4 |       {{ tableViewName }}
  5 |     </template>


warning: The "TableViewFooter" component has been used but not registered (vue/no-unregistered-components) at src/components/HelloWorld.vue:7:7:
   5 |     </template>
   6 |     <template #footer>
>  7 |       <TableViewFooter>
     |       ^
   8 |         <template #action>
   9 |           <CustomButton />
  10 |         </template>


warning: The "CustomButton" component has been used but not registered (vue/no-unregistered-components) at src/components/HelloWorld.vue:9:11:
   7 |       <TableViewFooter>
   8 |         <template #action>
>  9 |           <CustomButton />
     |           ^
  10 |         </template>
  11 |       </TableViewFooter>
  12 |     </template>


3 warnings found.

Changes

  • Target <template> whose parent is of type VDocumentFragment (root template) to report the unregisteredComponents.
  • Add tests using named template to prevent potential regressions.

Copy link
Member

@ota-meshi ota-meshi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for this PR!
Could you fix the linting errors?

@enzo360
Copy link
Contributor Author

enzo360 commented Dec 18, 2020

@ota-meshi Done! Sorry I forgot to run the linter 馃槄 Thanks for the review.

Copy link
Member

@ota-meshi ota-meshi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thank you!

@ota-meshi ota-meshi merged commit 2567f16 into vuejs:master Dec 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants