Skip to content

Commit 9195bf8

Browse files
committed
Changed to not autofix, if if the element have v-bind:slot
1 parent b1a0e7d commit 9195bf8

File tree

2 files changed

+35
-7
lines changed

2 files changed

+35
-7
lines changed

lib/rules/syntaxes/slot-scope-attribute.js

+20-7
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,28 @@ module.exports = {
1212
/**
1313
* Checks whether the given node can convert to the `v-slot`.
1414
* @param {VAttribute | null} slotAttr node of `slot`
15+
* @param {VElement} slotAttr node of `slot`
1516
* @returns {boolean} `true` if the given node can convert to the `v-slot`
1617
*/
17-
function canConvertToVSlot (slotAttr) {
18-
if (!slotAttr || !slotAttr.value) {
19-
return true
18+
function canConvertToVSlot (slotAttr, element) {
19+
if (slotAttr) {
20+
if (!slotAttr.value) {
21+
return true
22+
}
23+
const slotName = slotAttr.value.value
24+
// If non-Latin characters are included it can not be converted.
25+
return !/[^a-z]/i.test(slotName)
2026
}
21-
const slotName = slotAttr.value.value
22-
// If non-Latin characters are included it can not be converted.
23-
return !/[^a-z]/i.test(slotName)
27+
28+
const vBindSlotAttr = element.attributes
29+
.find(attr =>
30+
attr.directive === true &&
31+
attr.key.name.name === 'bind' &&
32+
attr.key.argument &&
33+
attr.key.argument.name === 'slot')
34+
// if the element have `v-bind:slot` it can not be converted.
35+
// Conversion of `v-bind:slot` is done with `vue/no-deprecated-slot-attribute`.
36+
return !vBindSlotAttr
2437
}
2538

2639
/**
@@ -62,7 +75,7 @@ module.exports = {
6275
const element = scopeAttr.parent
6376
const slotAttr = element.attributes
6477
.find(attr => attr.directive === false && attr.key.name === 'slot')
65-
if (!canConvertToVSlot(slotAttr)) {
78+
if (!canConvertToVSlot(slotAttr, element)) {
6679
return null
6780
}
6881
return fixSlotToVSlot(fixer, slotAttr, scopeAttr)

tests/lib/rules/no-deprecated-slot-scope-attribute.js

+15
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,21 @@ tester.run('no-deprecated-slot-scope-attribute', rule, {
139139
line: 4
140140
}
141141
]
142+
},
143+
{
144+
code: `
145+
<template>
146+
<LinkList>
147+
<a slot-scope="{a}" :slot="arg"/>
148+
</LinkList>
149+
</template>`,
150+
output: null,
151+
errors: [
152+
{
153+
message: '`slot-scope` are deprecated.',
154+
line: 4
155+
}
156+
]
142157
}
143158
]
144159
})

0 commit comments

Comments
 (0)