vuejs / eslint-plugin-vue

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

Supports for Vue.js 3.x #1035

Closed ota-meshi closed 4 years ago

ota-meshi commented 4 years ago

In this issue, I will list the Vue.js 3.x changes that need to be supported by eslint-plugin-vue.



List the changes after #1036 was merged.


refs

https://medium.com/the-vue-point/plans-for-the-next-iteration-of-vue-js-777ffea6fabf https://github.com/vuejs/rfcs/pulls?utf8=%E2%9C%93&q=is%3Apr+label%3A3.x+ https://vueschool.io/articles/vuejs-tutorials/exciting-new-features-in-vue-3/ https://vue-composition-api-rfc.netlify.com/

haoqunjiang commented 4 years ago

/cc @vuejs/docs

I think these changes are also to be addressed in the new style guide. Any thoughts?

haoqunjiang commented 4 years ago

I think a require-v-if-inside-transition rule can be added for RFC0017

yyx990803 commented 4 years ago

Some rules I had in mind:

ota-meshi commented 4 years ago

@sodatea @yyx990803 Thank you for your comments!

I have added new rules to the list.

ota-meshi commented 4 years ago

@michalsnik @mysticatea Could you comment on this issue if you have any feedback?

codebender828 commented 4 years ago

Hi! Thanks @ota-meshi @sodatea @yyx990803 for the work done with this plugin.

Will we be adding any rules for when consumers try to access refs in the template through .value? I feel like some people would try to do this, yet based on the RFC docs, Vue internally does this for you.

yyx990803 commented 4 years ago

@codebender828 that's a good one, although a user may very well have an object with .value so we will need the component's type information to be able to warn without false positives.

przemkow commented 4 years ago

I have a question about v-model changes. 🙂
If i understood RFC 0011 right, v-model api will provide also support for custom modifiers. Adding that feature wouldn't require also some changes to vue/valid-v-model rule? Ex.:

yyx990803 commented 4 years ago

Note that custom modifiers are only supported for v-model on custom components. Usage on native <input>, <select> and <textarea> still only support the built-in modifiers.

ota-meshi commented 4 years ago

@przemkow Thank you for your comment. And thank you for your contribution. I overlooked the custom modifiers change. I think we need to change the valid-v-model rule and add new rule as you say.

przemkow commented 4 years ago

Thank you for the clarification @yyx990803 🙂 No problem @ota-meshi 😉 I hope this contribution will be helpful for the whole community.

I updated previously created PR ( #1039 ) so now it handles both RFC0005 and RFC0011.

przemkow commented 4 years ago

@ota-meshi setup function should be added to vue/no-dupe-keys rule as well isn't it?

ota-meshi commented 4 years ago

@przemkow I think it needs to be added as you say.

chiptus commented 4 years ago

what about no this in setup function? I really miss that in eslint on vue2

victorgarciaesgi commented 4 years ago

I was thinking of adding something similar to react-hooks/exhaustive-deps that autofix in the return statement all the reactive and ref variables present in the setup function

ota-meshi commented 4 years ago

Hi @chiptus @victorgarciaesgi. Sorry for the late reply. Could you open a new issue and include sample code? Because I don't understand your proposed rule correctly.

victorgarciaesgi commented 4 years ago

@ota-meshi Sure!

Consider this code in React

export function Component() {
  const isMobile = useMedia({ maxWidth: '768px' })

  useEffect(() => {
    if (isMobile) {
      console.log(isMobile)
    }
  })
  return <div>{isMobile}</div>
}

With the rule react-hooks/exhaustive-deps, eslint will autofix the code to add missing deps to useEffect, resulting in:

useEffect(() => {
    if (isMobile) {
      console.log(isMobile)
    }
  }, [isMobile])

In Vue3 we can have the same thing but for the return statement in setup Exemple:

export default defineComponent({
 setup(props, ctx) {
  const search = ref('')
 } 
})

Will become:

export default defineComponent({
 setup(props, ctx) {
  const search = ref('')
  return {search}
 } 
})
LinusBorg commented 4 years ago

I'm not too sure about this. I'm pretty sure we will rather often have state in setup that doesn't have to be exposed to the template.

victorgarciaesgi commented 4 years ago

@LinusBorg Yeah i thought of that too, maybe complete the return statement with only values present in the template?

yoyo930021 commented 4 years ago

Does we need about no-this-in-setup rule?

haoqunjiang commented 4 years ago

We also need a vue/no-inline-template for RFC0016: Remove inline-template

ota-meshi commented 4 years ago

Hi @sodatea. I haven't used the inline-template and I'm not familiar with it. Can the inline-template be used in SFC?

haoqunjiang commented 4 years ago

Yeah, it can be used in SFC.

ota-meshi commented 4 years ago

I did not know that. Thank you!

haoqunjiang commented 4 years ago

Per RFC0007, I think a no-functional-template rule is needed. I'm not sure if it's auto-fixable though.


I just found out that the no-reserved-component-names rule does not throw on Vue's own built-in component names like transition, transition-group, keep-alive and component. As of Vue.js 3.x, teleport should be added to the list too.


Per RFC0027, we need a new rule to restrict the is prop usage to the reserved <component> tag only.

haoqunjiang commented 4 years ago

The vue/no-deprecated-v-on-number-modifiers rule needs to also detect the usage of Vue.config.keyCodes and warn the deprecation.

ota-meshi commented 4 years ago

@sodatea Thank you for suggesting the rules and changes. I will make those changes.

haoqunjiang commented 4 years ago

Thanks!

ota-meshi commented 4 years ago

Currently this plugin has finished implementing most of the rules defined in this issue.

Open the remaining issue with another and close this issue.

If you would like to propose a new rule, please open a new issue.

yyx990803 commented 4 years ago

@ota-meshi thanks for the hard work!