vuejs / eslint-plugin-vue

Official ESLint plugin for Vue.js
https://eslint.vuejs.org/
MIT License
4.38k stars 649 forks source link

vue/no-undef-components-exclude-auto-import #2461

Closed MQYForverT closed 2 weeks ago

MQYForverT commented 2 weeks ago

Please describe what the rule should do:

It will detect undefined components, but exclude automatically imported components [unplugin vue components/vite]

What category should the rule belong to?

[ ] Enforces code style (layout) [ ] Warns about a potential error (problem) [x] Suggests an alternate way of doing something (suggestion) [] Other (please specify:)

Provide 2-3 code examples that this rule should warn about:

"Unplugin Vue components/vite" will automatically generate a "components. d. ts" file

export {}
declare module 'vue' {
  export interface GlobalComponents {
    HelloWorld: typeof import('./src/components/HelloWorld.vue')['default']
  }
}
<HelloWorld msg="Farm + Vue" />
<HelloWorld2 msg="Farm + Vue" />

HelloWorld will not error HelloWorld2 will report an error

Additional context

“vue/no-undef-components-exclude-auto-import” can accept a file[components. d. ts] path ,This rule can filter configuration files based on this path

by the way I just want to implement this feature, of course, it may be because I didn't realize it had already been implemented. If it has been implemented, please tell me how to write。thanks

FloEdelmann commented 2 weeks ago

You can already use vue/no-undef-components and set ignorePatterns to exclude some components.

MQYForverT commented 2 weeks ago

You can already use vue/no-undef-components and set ignorePatterns to exclude some components.

IgnorePatterns have significant limitations, such as when I use Element ui, I will match all components starting with El, IgnorePatterns: ['El (\ \ - \ \ w+)+'] For example, my custom components are also automatically imported, and I want to filter them out. This will require all my components to start with Xd in order to be hit by this rule, IgnorePatterns: ['El (\ \ - \ \ w+)+', ['Xd (\ \ - \ \ w+)+'] Am I correct in understanding this way?

FloEdelmann commented 2 weeks ago

Yes, either all your components have a common prefix (or suffix) that you can match, or you list the components manually in ignorePatterns. But there is no way that an eslint-plugin-vue rule could know which components are auto-imported and which ones are not.

Note that there is a style guide rule that suggests using a common prefix for core components anyway: https://vuejs.org/style-guide/rules-strongly-recommended.html#base-component-names