Skip to content

bug(vue/no-deprecated-slot-attribute): invalid autofix on non-immediate slot attributes #1499

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

Closed
2 tasks done
privatenumber opened this issue May 27, 2021 · 1 comment · Fixed by #1521
Closed
2 tasks done
Labels

Comments

@privatenumber
Copy link
Contributor

Checklist

  • I have tried restarting my IDE and the issue persists.
  • I have read the FAQ and my problem is not listed.

Tell us about your environment

  • ESLint version: 7.23.0
  • eslint-plugin-vue version: 7.9.0
  • Node version: v14.16.1
  • Operating System: macOS 11.4

Please show your full configuration:

Sorry, partial config but the autofixes are coming from vue/no-deprecated-slot-attribute so I think this should suffice. Can provide full config if necessary.

'vue/no-deprecated-data-object-declaration': 'warn',
'vue/no-deprecated-slot-attribute': 'warn',
'vue/no-deprecated-slot-scope-attribute': 'warn',
'vue/no-deprecated-scope-attribute': 'warn',

What did you do?

Ran autofix with vue/no-deprecated-slot-attribute enabled.

It autocorrected the old slot="slot-name" to the new #slot-name syntax, but broke the code in places where the element with slot="slot-name" is not an immediate child.

With the deprecated syntax slot="slot-name", it appears that content passed into the slot can be in nested <template> tags. https://jsfiddle.net/hirokiosame/vy6hejcx/

With the new syntax #slot-name, it appears that content passed into the slot much be an immediate child of the component it's being passed into. https://jsfiddle.net/hirokiosame/njbof5rv/

SomeComponent.vue

<template>
    <div>
        <slot name="some-slot" />
    </div>
</template>

This works:

<template>
  <some-component>
    <template slot="some-slot">
      This works 1
    </template>

    <template v-if="true"> <!-- some arbitrary conditional -->
      <template slot="some-slot">
        This works 2
      </template>
    </template>
  </some-component>
</template>

<script>
import SomeComponent from './SomeComponent.vue';

export default {
  components: {
    SomeComponent
  }
}

This doesn't work:

<template>
  <some-component>
    <template #some-slot>
      This works 1
    </template>

    <template v-if="true"> <!-- some arbitrary conditional -->
      <template #some-slot>
        This doesn't work
      </template>
    </template>
  </some-component>
</template>

<script>
import SomeComponent from './SomeComponent.vue';

export default {
  components: {
    SomeComponent
  }
}

What did you expect to happen?
For the autofix to not convert the slot="slot-name" to #slot-name if it's not being used on an immediate child.

What actually happened?

It autofixed, and is caught as an invalid slot usage by vue/valid-v-slot.

Repository to reproduce this issue
JSFiddle links above should suffice.

@privatenumber
Copy link
Contributor Author

Thank you @ota-meshi ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
2 participants