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
2 changes: 1 addition & 1 deletion docs/rules/no-deprecated-slot-attribute.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ This rule reports deprecated `slot` attribute in Vue.js v2.6.0+.
}
```

- `"ignore"` (`string[]`) An array of tags that ignore this rules. This option will check both kebab-case and PascalCase versions of the given tag names. Default is empty.
- `"ignore"` (`string[]`) An array of tags or regular expression patterns (e.g. `/^custom-/`) that ignore this rules. This option will check both kebab-case and PascalCase versions of the given tag names. Default is empty.

### `"ignore": ["my-component"]`

Expand Down
24 changes: 20 additions & 4 deletions lib/rules/syntaxes/slot-attribute.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,29 @@
'use strict'

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

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

for (const str of ignore) {
if (regexp.isRegExp(str)) {
ignorePatterns.push(regexp.toRegExp(str))
} else {
ignoreStrings.add(str)
}
}

const sourceCode = context.getSourceCode()
const tokenStore =
Expand Down Expand Up @@ -123,12 +136,15 @@ module.exports = {
function reportSlot(slotAttr) {
const componentName = slotAttr.parent.parent.rawName
if (
ignore.has(componentName) ||
ignore.has(casing.pascalCase(componentName)) ||
ignore.has(casing.kebabCase(componentName))
ignoreStrings.has(componentName) ||
ignoreStrings.has(casing.pascalCase(componentName)) ||
ignoreStrings.has(casing.kebabCase(componentName))
) {
return
}
if (ignorePatterns.some((pattern) => pattern.test(componentName))) {
return
}

context.report({
node: slotAttr.key,
Expand Down
72 changes: 72 additions & 0 deletions tests/lib/rules/no-deprecated-slot-attribute.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,18 @@ tester.run('no-deprecated-slot-attribute', rule, {
</LinkList>
</template>`,
options: [{ ignore: ['one', 'two', 'my-component'] }]
},
{
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$/i', '/^my-.*/i'] }]
}
],
invalid: [
Expand Down Expand Up @@ -644,6 +656,66 @@ tester.run('no-deprecated-slot-attribute', rule, {
],
errors: ['`slot` attributes are deprecated.']
},
{
code: `
<template>
<my-component>
<one slot="one">
A
</one>
<two slot="two">
B
</two>
</my-component>
</template>`,
output: `
<template>
<my-component>
<one slot="one">
A
</one>
<template v-slot:two>\n<two >
B
</two>\n</template>
</my-component>
</template>`,
options: [
{
ignore: ['/one/']
}
],
errors: ['`slot` attributes are deprecated.']
},
{
code: `
<template>
<my-component>
<one slot="one">
A
</one>
<two slot="two">
B
</two>
</my-component>
</template>`,
output: `
<template>
<my-component>
<one slot="one">
A
</one>
<template v-slot:two>\n<two >
B
</two>\n</template>
</my-component>
</template>`,
options: [
{
ignore: ['/^one$/']
}
],
errors: ['`slot` attributes are deprecated.']
},
{
code: `
<template>
Expand Down