Skip to content

Commit

Permalink
Changed to not autofix, if if the element have v-bind:slot
Browse files Browse the repository at this point in the history
  • Loading branch information
ota-meshi committed Feb 28, 2019
1 parent b1a0e7d commit 9195bf8
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 7 deletions.
27 changes: 20 additions & 7 deletions lib/rules/syntaxes/slot-scope-attribute.js
Expand Up @@ -12,15 +12,28 @@ module.exports = {
/**
* Checks whether the given node can convert to the `v-slot`.
* @param {VAttribute | null} slotAttr node of `slot`
* @param {VElement} slotAttr node of `slot`
* @returns {boolean} `true` if the given node can convert to the `v-slot`
*/
function canConvertToVSlot (slotAttr) {
if (!slotAttr || !slotAttr.value) {
return true
function canConvertToVSlot (slotAttr, element) {
if (slotAttr) {
if (!slotAttr.value) {
return true
}
const slotName = slotAttr.value.value
// If non-Latin characters are included it can not be converted.
return !/[^a-z]/i.test(slotName)
}
const slotName = slotAttr.value.value
// If non-Latin characters are included it can not be converted.
return !/[^a-z]/i.test(slotName)

const vBindSlotAttr = element.attributes
.find(attr =>
attr.directive === true &&
attr.key.name.name === 'bind' &&
attr.key.argument &&
attr.key.argument.name === 'slot')
// if the element have `v-bind:slot` it can not be converted.
// Conversion of `v-bind:slot` is done with `vue/no-deprecated-slot-attribute`.
return !vBindSlotAttr
}

/**
Expand Down Expand Up @@ -62,7 +75,7 @@ module.exports = {
const element = scopeAttr.parent
const slotAttr = element.attributes
.find(attr => attr.directive === false && attr.key.name === 'slot')
if (!canConvertToVSlot(slotAttr)) {
if (!canConvertToVSlot(slotAttr, element)) {
return null
}
return fixSlotToVSlot(fixer, slotAttr, scopeAttr)
Expand Down
15 changes: 15 additions & 0 deletions tests/lib/rules/no-deprecated-slot-scope-attribute.js
Expand Up @@ -139,6 +139,21 @@ tester.run('no-deprecated-slot-scope-attribute', rule, {
line: 4
}
]
},
{
code: `
<template>
<LinkList>
<a slot-scope="{a}" :slot="arg"/>
</LinkList>
</template>`,
output: null,
errors: [
{
message: '`slot-scope` are deprecated.',
line: 4
}
]
}
]
})

0 comments on commit 9195bf8

Please sign in to comment.