Skip to content

Commit 4b41399

Browse files
authored
Improved autofix of vue/no-deprecated-slot-attribute rule when slot name contains _. (#1436)
1 parent b978258 commit 4b41399

File tree

2 files changed

+59
-2
lines changed

2 files changed

+59
-2
lines changed

lib/rules/syntaxes/slot-attribute.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ module.exports = {
2323
return true
2424
}
2525
const slotName = slotAttr.value.value
26-
// If non-Latin characters are included it can not be converted.
27-
return !/[^a-z]/i.test(slotName)
26+
// If other than alphanumeric, underscore and hyphen characters are included it can not be converted.
27+
return !/[^\w\-]/u.test(slotName)
2828
}
2929

3030
/**

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

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,63 @@ tester.run('no-deprecated-slot-attribute', rule, {
348348
line: 4
349349
}
350350
]
351+
},
352+
{
353+
code: `
354+
<template>
355+
<MyComponent>
356+
<template slot="foo-bar">
357+
<a/>
358+
</template>
359+
</MyComponent>
360+
</template>`,
361+
output: `
362+
<template>
363+
<MyComponent>
364+
<template v-slot:foo-bar>
365+
<a/>
366+
</template>
367+
</MyComponent>
368+
</template>`,
369+
errors: ['`slot` attributes are deprecated.']
370+
},
371+
{
372+
code: `
373+
<template>
374+
<MyComponent>
375+
<template slot="foo_bar">
376+
<a/>
377+
</template>
378+
</MyComponent>
379+
</template>`,
380+
output: `
381+
<template>
382+
<MyComponent>
383+
<template v-slot:foo_bar>
384+
<a/>
385+
</template>
386+
</MyComponent>
387+
</template>`,
388+
errors: ['`slot` attributes are deprecated.']
389+
},
390+
{
391+
code: `
392+
<template>
393+
<MyComponent>
394+
<template slot="123">
395+
<a/>
396+
</template>
397+
</MyComponent>
398+
</template>`,
399+
output: `
400+
<template>
401+
<MyComponent>
402+
<template v-slot:123>
403+
<a/>
404+
</template>
405+
</MyComponent>
406+
</template>`,
407+
errors: ['`slot` attributes are deprecated.']
351408
}
352409
]
353410
})

0 commit comments

Comments
 (0)