Skip to content

Commit 31bbfaf

Browse files
committed
Changed not to autofix, if it becomes an invalid attribute
1 parent e8fba6a commit 31bbfaf

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

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

+19-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,21 @@ module.exports = {
88
supported: '2.5.0',
99
createTemplateBodyVisitor (context, { fixToUpgrade } = {}) {
1010
const sourceCode = context.getSourceCode()
11+
12+
/**
13+
* Checks whether the given node can convert to the `v-slot`.
14+
* @param {VAttribute | null} slotAttr node of `slot`
15+
* @returns {boolean} `true` if the given node can convert to the `v-slot`
16+
*/
17+
function canConvertToVSlot (slotAttr) {
18+
if (!slotAttr || !slotAttr.value) {
19+
return true
20+
}
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)
24+
}
25+
1126
/**
1227
* Convert to `v-slot`.
1328
* @param {object} fixer fixer
@@ -16,7 +31,7 @@ module.exports = {
1631
* @returns {*} fix data
1732
*/
1833
function fixSlotToVSlot (fixer, slotAttr, scopeAttr) {
19-
const nameArgument = slotAttr && slotAttr.value && slotAttr && slotAttr.value.value
34+
const nameArgument = slotAttr && slotAttr.value && slotAttr.value.value
2035
? `:${slotAttr.value.value}`
2136
: ''
2237
const scopeValue = scopeAttr && scopeAttr.value
@@ -47,6 +62,9 @@ module.exports = {
4762
const element = scopeAttr.parent
4863
const slotAttr = element.attributes
4964
.find(attr => attr.directive === false && attr.key.name === 'slot')
65+
if (!canConvertToVSlot(slotAttr)) {
66+
return null
67+
}
5068
return fixSlotToVSlot(fixer, slotAttr, scopeAttr)
5169
}
5270
: null

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

+16
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,22 @@ tester.run('no-deprecated-slot-scope-attribute', rule, {
123123
line: 4
124124
}
125125
]
126+
},
127+
// cannot fix
128+
{
129+
code: `
130+
<template>
131+
<LinkList>
132+
<a slot-scope="{a}" slot="f o o"/>
133+
</LinkList>
134+
</template>`,
135+
output: null,
136+
errors: [
137+
{
138+
message: '`slot-scope` are deprecated.',
139+
line: 4
140+
}
141+
]
126142
}
127143
]
128144
})

0 commit comments

Comments
 (0)