Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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
5 changes: 5 additions & 0 deletions .changeset/tangy-eagles-start.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'eslint-plugin-vue': patch
---

[`vue/no-deprecated-slot-attribute`](https://eslint.vuejs.org/rules/no-deprecated-slot-attribute.html) `ignore` option now supports regex patterns.
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 these rules. This option will check both kebab-case and PascalCase versions of the given tag names. Default is empty.

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

Expand Down
21 changes: 16 additions & 5 deletions lib/rules/syntaxes/slot-attribute.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,23 @@
'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] || {}
/** @type {Set<string>} */
const ignore = new Set(options.ignore)
const { ignore = [] } = options
/** @type {RegExp[]} */
const ignorePatterns = []

for (const str of ignore) {
ignorePatterns.push(regexp.toRegExp(str))
}

const sourceCode = context.getSourceCode()
const tokenStore =
Expand Down Expand Up @@ -123,9 +130,13 @@ 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))
ignorePatterns.some((pattern) => pattern.test(componentName)) ||
ignorePatterns.some((pattern) =>
pattern.test(casing.pascalCase(componentName))
) ||
ignorePatterns.some((pattern) =>
pattern.test(casing.kebabCase(componentName))
)
) {
return
}
Expand Down
88 changes: 88 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,82 @@ 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: [
{
message: '`slot` attributes are deprecated.',
line: 7,
endLine: 7,
column: 16,
endColumn: 20
}
]
},
{
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: [
{
message: '`slot` attributes are deprecated.',
line: 7,
endLine: 7,
column: 16,
endColumn: 20
}
]
},
{
code: `
<template>
Expand Down