Open jods4 opened 9 months ago
The rule should have a list of all
vue
exports and not trigger when the imported value is not one of them (false positive).
It will be quite tedious to update this list manually; maybe even separately per Vue version... Maybe adding an allow
option would be easier and more maintainable?
Managing the list manually would be tedious and error-prone, indeed.
Could this be automated during the build step of eslint-plugin-vue
?
// During build:
import * as vue from "vue";
const jsArray = JSON.stringify(Object.keys(vue));
const virtualFile = `export vueExports = new Set(${jsArray})`;
// At runtime only raise error for imports that are found in `vueExports`
Yes, we already have several such update scripts. If you (or someone else) would like to implement this, feel welcome to do so :blush:
However, we need to think if the latest vue
version's exports are always correct, or if we need to do this for every (minor?) version and then during runtime change the logic based on the available Vue version.
Hah, looks like we already have that list and update script :sweat_smile:
I think using the latest version as the baseline for the linter is likely to be enough.
This is only a linter, if someone has an older version and gets a false positive or negative, it can be ignored. This should be exceedingly rare as: (1) most people do not import from @vue/*
packages; (2) those exports don't vary much from release to another.
IMHO it's an improvement over the current situation which is always incorrect. Maybe it can be revised if a lot of issues are raised by users?
Sounds good to me :slightly_smiling_face:
Checklist
Tell us about your environment
Please show your full configuration:
What did you do?
What did you expect to happen? Nothing, that's fine code because
vue
itself does not exporttrigger
nortrack
.What actually happened? Error
vue/prefer-import-from-vue
suggesting to import those members fromvue
, which is impossible.Suggested fix It's generally good practice to import from
vue
directly, so I'd like to keep this rule enabled. The rule should have a list of allvue
exports and not trigger when the imported value is not one of them (false positive).