Skip to content
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: no-use-v-if-with-v-slot #1273

Open
bowencool opened this issue Aug 7, 2020 · 1 comment
Open

Rule Proposal: no-use-v-if-with-v-slot #1273

bowencool opened this issue Aug 7, 2020 · 1 comment

Comments

@bowencool
Copy link

@bowencool bowencool commented Aug 7, 2020

Please describe what the rule should do:

disallow use v-if on the same element as v-slot

What category should the rule belong to?

  • Enforces code style
  • Warns about a potential error
  • Suggests an alternate way of doing something
  • Other (please specify:)

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

<template>
  <MyComp>
    <!-- ✓ GOOD -->
    <template v-slot="scope">
      <span v-if="scope.show">{{scope.msg}}</span>
    </template>

    <!-- ✗ BAD -->
    <template
      v-slot="scope"
      v-if="scope.show"
    >
      <span>{{scope.msg}}</span>
    </template>
    <!-- ↑ In this case, `scope` will be not defined. -->
  </MyComp>
</template>

Additional context

vue#11574

@bowencool bowencool changed the title no-use-v-if-with-v-slot Rule Proposal: no-use-v-if-with-v-slot Aug 7, 2020
@ota-meshi
Copy link
Member

@ota-meshi ota-meshi commented Aug 11, 2020

Thank you for the rule suggestion.

What happens to this rule in the following cases?

    <template
      v-slot="scope"
      v-if="show"
    >
      <span>{{scope.msg}}</span>
    </template>

If this is an error, why is it an error?
If this is not an error, then your code may not be able to judge well.

<template>
  <MyComp>
    <template
      v-slot="scope"
      v-if="scope.show"
    >
      <span>{{scope.msg}}</span>
    </template>
  </MyComp>
</template>
<script>
export default {
  data () {
    return {
      scope: {
        show: true // v-if uses this data.
      }
    }
  }
}
</script>

Perhaps I think extending vue/no-template-shadow might solve your problem.

<template>
  <MyComp>
    <template
      v-slot="scope"
      v-if="scope.show /* <- scope is shadowing */"
    >
      <span>{{scope.msg}}</span>
    </template>
  </MyComp>
</template>

However, the parser may not parse it right now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.