Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
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
14 changes: 13 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,19 @@ module.exports = {
url: 'https://eslint.vuejs.org/rules/no-deprecated-slot-attribute.html'
},
fixable: 'code',
schema: [],
schema: [
{
type: 'object',
properties: {
ignore: {
type: 'array',
items: { type: 'string' },
uniqueItems: true
}
},
additionalProperties: false
}
],
messages: {
forbiddenSlotAttribute: '`slot` attributes are deprecated.'
}
Expand Down
14 changes: 14 additions & 0 deletions lib/rules/syntaxes/slot-attribute.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,17 @@
'use strict'

const canConvertToVSlot = require('./utils/can-convert-to-v-slot')
const casing = require('../../utils/casing')

module.exports = {
deprecated: '2.6.0',
supported: '<3.0.0',
/** @param {RuleContext} context @returns {TemplateListener} */
createTemplateBodyVisitor(context) {
const options = context.options[0] || {}
/** @type {Set<string>} */
const ignore = new Set(options.ignore)

const sourceCode = context.getSourceCode()
const tokenStore =
context.parserServices.getTemplateBodyTokenStore &&
Expand Down Expand Up @@ -95,6 +100,15 @@ module.exports = {
* @returns {void}
*/
function reportSlot(slotAttr) {
const componentName = slotAttr.parent.parent.rawName
if (
ignore.has(componentName) ||
ignore.has(casing.pascalCase(componentName)) ||
ignore.has(casing.kebabCase(componentName))
) {
return
}

context.report({
node: slotAttr.key,
messageId: 'forbiddenSlotAttribute',
Expand Down
34 changes: 33 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,19 @@ 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" />
<myComponent slot="myComponent-slot" />
<MyComponent slot="MyComponent-slot" />
</LinkList>
</template>`,
options: [{ ignore: ['one', 'two', 'my-component'] }]
}
],
invalid: [
{
Expand Down Expand Up @@ -594,6 +606,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.']
}
]
})