Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion lib/rules/no-deprecated-slot-attribute.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,17 @@ module.exports = {
url: 'https://eslint.vuejs.org/rules/no-deprecated-slot-attribute.html'
},
fixable: 'code',
schema: [],
schema: [
{
type: 'object',
properties: {
ignore: {
type: 'array'
}
},
additionalProperties: false
}
],
messages: {
forbiddenSlotAttribute: '`slot` attributes are deprecated.'
}
Expand Down
9 changes: 9 additions & 0 deletions lib/rules/syntaxes/slot-attribute.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ module.exports = {
supported: '<3.0.0',
/** @param {RuleContext} context @returns {TemplateListener} */
createTemplateBodyVisitor(context) {
const options = context.options[0] || {}
/** @type {string[]} */
const ignore = Array.isArray(options.ignore)
? options.ignore
: [options.ignore]

const sourceCode = context.getSourceCode()
const tokenStore =
context.parserServices.getTemplateBodyTokenStore &&
Expand Down Expand Up @@ -95,6 +101,9 @@ module.exports = {
* @returns {void}
*/
function reportSlot(slotAttr) {
if (ignore.includes(slotAttr.parent.parent.name)) {
return
}
context.report({
node: slotAttr.key,
messageId: 'forbiddenSlotAttribute',
Expand Down
32 changes: 31 additions & 1 deletion tests/lib/rules/no-deprecated-slot-attribute.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,17 @@ tester.run('no-deprecated-slot-attribute', rule, {
<LinkList>
<a />
</LinkList>
</template>`
</template>`,
{
code: `<template>
<LinkList>
<one slot="one" />
<two slot="two" />
<my-component slot="my-component-slot" />
</LinkList>
</template>`,
options: [{ ignore: ['one', 'two', 'my-component'] }]
}
],
invalid: [
{
Expand Down Expand Up @@ -594,6 +604,26 @@ tester.run('no-deprecated-slot-attribute', rule, {
'`slot` attributes are deprecated.',
'`slot` attributes are deprecated.'
]
},
{
code: `
<template>
<my-component>
<one slot="one">
A
</one>
<two slot="two">
B
</two>
</my-component>
</template>`,
output: null,
options: [
{
ignore: ['one']
}
],
errors: ['`slot` attributes are deprecated.']
}
]
})