-
-
Notifications
You must be signed in to change notification settings - Fork 669
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
Rule Proposal: disallow imports from @vue/* dependencies #1780
Comments
Thank you for posting this issue. |
Very good point, thanks for linking the resource. I'll try putting a rule together using that in the coming days! |
Note that many people are (slowly) migrating from Vue 2 to Vue 3 and start by using the Composition API plugin like that: import { ref, reactive } from '@vue/composition-api' |
Good to know, thanks. I can see about excluding that specific plugin in the rule, unless there are others you know of to avoid? This is also the first time I'm working with eslint, so I'm not sure of its limitations. The rule I suggested here is intended to help prevent people from bundling Vue when they're building a library with Vue CLI (with the |
These are some packages in the List
I haven't checked which ones are allowed to be imported from libraries and which aren't. If you are planning to write a new rule for this ESLint plugin, I'd rather only report specific packages, so we don't necessarily have to keep up with new ones. I don't think there is any way of knowing whether the project is built as a library. If the rule is not included in any preset, users will have to explicitly enable it on their own, so that should be okay. |
@ota-meshi can we wrap eslint's The rule could look something like this: 'no-restricted-imports': [
'error',
{
paths: ['@vue/reactivity', '@vue/runtime-core', '@vue/runtime-dom', '@vue/shared'],
message: "Please always import these APIs from the main 'vue' package"
}
] Excluding these runtime packages should be enough to catch most of the problematic autocomplete imports like |
If importing |
At the very least, importing from the following packages is practically always a mistake, usually by a bad autocomplete suggestion in the editor/IDE:
These are transitive dependencies of So someone switching from npm to pnpm could find their app to be broken in lots if places because imports from those packages don't work anymore. For library authors it's even worse: Excluding So yeah, restricting imports from these transitive dependencies would benefit all users, and since it's not just a cosmetic thing, I would tend to add it to essentials. |
I just opened a PR to try adding what Linus outlined above. My tests currently aren't passing so I don't think I've implemented it completely correct. @ota-meshi or @FloEdelmann I'll be thankful for any help to get this working. |
@jbhammon Thank you for the pull request. However, I don't think the new rule is an extended rule for The rule reports an import from Also, the rule name will probably be different. |
Please describe what the rule should do:
Disallow or warn about imports from
@vue/*
dependencies. Particularly when using Vue CLI and the build target is a library.What category should the rule belong to?
[ ] Enforces code style (layout)
[x] Warns about a potential error (problem)
[ ] Suggests an alternate way of doing something (suggestion)
[ ] Other (please specify:)
Provide 2-3 code examples that this rule should warn about:
<!-- Fail or Warn --> import { computed } from "@vue/reactivity"; import { something, another, } from "@vue/compiler-dom";
<!-- Pass --> import { computed } from "vue";
Additional context
Full context can be found in this issue I opened in the core repo.
In short, using the
@vue/reactivity
import broke the components I was building for my UI library with Vue CLI and they were failing silently.The text was updated successfully, but these errors were encountered: