Skip to content

Commit 022afb5

Browse files
Add new option to specify tags to ignore vue/no-deprecated-slot-attribute (#2314)
Co-authored-by: Flo Edelmann <[email protected]>
1 parent 86ab768 commit 022afb5

File tree

4 files changed

+103
-2
lines changed

4 files changed

+103
-2
lines changed

Diff for: docs/rules/no-deprecated-slot-attribute.md

+43
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,49 @@ This rule reports deprecated `slot` attribute in Vue.js v2.6.0+.
3737

3838
</eslint-code-block>
3939

40+
## :wrench: Options
41+
42+
```json
43+
{
44+
"vue/no-deprecated-slot-attribute": ["error", {
45+
"ignore": ["my-component"]
46+
}]
47+
}
48+
```
49+
50+
- `"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.
51+
52+
### `"ignore": ["my-component"]`
53+
54+
<eslint-code-block :rules="{'vue/no-dupe-keys': ['error', {ignore: ['my-component']}]}">
55+
56+
```vue
57+
<template>
58+
<ListComponent>
59+
<!-- ✓ GOOD -->
60+
<template v-slot:name>
61+
{{ props.title }}
62+
</template>
63+
</ListComponent>
64+
65+
<ListComponent>
66+
<!-- ✓ GOOD -->
67+
<my-component slot="name">
68+
{{ props.title }}
69+
</my-component>
70+
</ListComponent>
71+
72+
<ListComponent>
73+
<!-- ✗ BAD -->
74+
<other-component slot="name">
75+
{{ props.title }}
76+
</other-component>
77+
</ListComponent>
78+
</template>
79+
```
80+
81+
</eslint-code-block>
82+
4083
## :books: Further Reading
4184

4285
- [API - slot](https://v2.vuejs.org/v2/api/#slot-deprecated)

Diff for: lib/rules/no-deprecated-slot-attribute.js

+13-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,19 @@ module.exports = {
1616
url: 'https://eslint.vuejs.org/rules/no-deprecated-slot-attribute.html'
1717
},
1818
fixable: 'code',
19-
schema: [],
19+
schema: [
20+
{
21+
type: 'object',
22+
properties: {
23+
ignore: {
24+
type: 'array',
25+
items: { type: 'string' },
26+
uniqueItems: true
27+
}
28+
},
29+
additionalProperties: false
30+
}
31+
],
2032
messages: {
2133
forbiddenSlotAttribute: '`slot` attributes are deprecated.'
2234
}

Diff for: lib/rules/syntaxes/slot-attribute.js

+14
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,17 @@
55
'use strict'
66

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

910
module.exports = {
1011
deprecated: '2.6.0',
1112
supported: '<3.0.0',
1213
/** @param {RuleContext} context @returns {TemplateListener} */
1314
createTemplateBodyVisitor(context) {
15+
const options = context.options[0] || {}
16+
/** @type {Set<string>} */
17+
const ignore = new Set(options.ignore)
18+
1419
const sourceCode = context.getSourceCode()
1520
const tokenStore =
1621
context.parserServices.getTemplateBodyTokenStore &&
@@ -95,6 +100,15 @@ module.exports = {
95100
* @returns {void}
96101
*/
97102
function reportSlot(slotAttr) {
103+
const componentName = slotAttr.parent.parent.rawName
104+
if (
105+
ignore.has(componentName) ||
106+
ignore.has(casing.pascalCase(componentName)) ||
107+
ignore.has(casing.kebabCase(componentName))
108+
) {
109+
return
110+
}
111+
98112
context.report({
99113
node: slotAttr.key,
100114
messageId: 'forbiddenSlotAttribute',

Diff for: tests/lib/rules/no-deprecated-slot-attribute.js

+33-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,19 @@ tester.run('no-deprecated-slot-attribute', rule, {
4646
<LinkList>
4747
<a />
4848
</LinkList>
49-
</template>`
49+
</template>`,
50+
{
51+
code: `<template>
52+
<LinkList>
53+
<one slot="one" />
54+
<two slot="two" />
55+
<my-component slot="my-component-slot" />
56+
<myComponent slot="myComponent-slot" />
57+
<MyComponent slot="MyComponent-slot" />
58+
</LinkList>
59+
</template>`,
60+
options: [{ ignore: ['one', 'two', 'my-component'] }]
61+
}
5062
],
5163
invalid: [
5264
{
@@ -594,6 +606,26 @@ tester.run('no-deprecated-slot-attribute', rule, {
594606
'`slot` attributes are deprecated.',
595607
'`slot` attributes are deprecated.'
596608
]
609+
},
610+
{
611+
code: `
612+
<template>
613+
<my-component>
614+
<one slot="one">
615+
A
616+
</one>
617+
<two slot="two">
618+
B
619+
</two>
620+
</my-component>
621+
</template>`,
622+
output: null,
623+
options: [
624+
{
625+
ignore: ['one']
626+
}
627+
],
628+
errors: ['`slot` attributes are deprecated.']
597629
}
598630
]
599631
})

0 commit comments

Comments
 (0)