vuejs / pinia

🍍 Intuitive, type safe, light and flexible Store for Vue using the composition api with DevTools support
https://pinia.vuejs.org
MIT License
12.72k stars 996 forks source link

Pinia Eslint plugin #2612

Open MickL opened 4 months ago

MickL commented 4 months ago

What problem is this solving

Would be cool to have an Eslint plugin that provides best practices. E.g. With a setup store all variables need to be exported (according to the docs) and a plugin could warn / error if we forgot to export a variable / function.

Maybe there are more best practices or anti patterns that the plugin could warn / error about.

Proposed solution

-

Describe alternatives you've considered

No response

posva commented 4 months ago

Yes, I've been hoping for an eslint expert to show up for the last 3 years 😄. I still haven't lost hope

lisilinhart commented 3 months ago

I've been looking into what rules would make sense for a pinia eslint plugin. Looking at the docs and came up with some ideas, what do you think @posva and @MickL?

MickL commented 3 months ago

Sounds very good! Would it be possible to enforce that ALL variables that are defined in the store also need to be exported by the store?

lisilinhart commented 3 months ago

Hi @MickL, here is the first version including three rules, I tried it with a vue scaffold already:

image
posva commented 3 months ago

Nice, thanks a lot for the initiative @lisilinhart ! A few notes regarding the rules:

As for other other ideas:

What do you think? I think Discussions is a great place to find where people are struggling

lisilinhart commented 3 months ago

Hey @posva, thanks for the detailed feedback. Your suggestions make a lot of sense and I'll look into adding those changes into the already existing rules in the next few days. I thought the same thing about only warning around ref reactive, it makes sense not to warn about more constant / helper variables or inner functions. I also need to look into more detail, which ones would be possible to autofix.

Discussions sounds like a good place to gain insight from actual use cases, should I open one and summarise the points that were mentioned here?

posva commented 3 months ago

Feel free to open a discussion if that helps you

MickL commented 3 months ago

Hey @lisilinhart this sounds amazing! Unfortunately I am currently focusing on backend work but next week I will be back at Nuxt and try it out!

lisilinhart commented 3 months ago

Feel free to open a discussion if that helps you

I opened the discussion here: https://github.com/vuejs/pinia/discussions/2638