Skip to content

Commit fb1fb79

Browse files
authored
Add vue/no-deprecated-dollar-scopedslots-api rule. (#1177)
1 parent 67b3e79 commit fb1fb79

File tree

6 files changed

+417
-0
lines changed

6 files changed

+417
-0
lines changed

docs/rules/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ Enforce all the rules in this category, as well as all higher priority rules, wi
4343
| [vue/no-async-in-computed-properties](./no-async-in-computed-properties.md) | disallow asynchronous actions in computed properties | |
4444
| [vue/no-deprecated-data-object-declaration](./no-deprecated-data-object-declaration.md) | disallow using deprecated object declaration on data (in Vue.js 3.0.0+) | :wrench: |
4545
| [vue/no-deprecated-dollar-listeners-api](./no-deprecated-dollar-listeners-api.md) | disallow using deprecated `$listeners` (in Vue.js 3.0.0+) | |
46+
| [vue/no-deprecated-dollar-scopedslots-api](./no-deprecated-dollar-scopedslots-api.md) | disallow using deprecated `$scopedSlots` (in Vue.js 3.0.0+) | :wrench: |
4647
| [vue/no-deprecated-events-api](./no-deprecated-events-api.md) | disallow using deprecated events api (in Vue.js 3.0.0+) | |
4748
| [vue/no-deprecated-filter](./no-deprecated-filter.md) | disallow using deprecated filters syntax (in Vue.js 3.0.0+) | |
4849
| [vue/no-deprecated-functional-template](./no-deprecated-functional-template.md) | disallow using deprecated the `functional` template (in Vue.js 3.0.0+) | |
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
---
2+
pageClass: rule-details
3+
sidebarDepth: 0
4+
title: vue/no-deprecated-dollar-scopedslots-api
5+
description: disallow using deprecated `$scopedSlots` (in Vue.js 3.0.0+)
6+
---
7+
# vue/no-deprecated-dollar-scopedslots-api
8+
> disallow using deprecated `$scopedSlots` (in Vue.js 3.0.0+)
9+
10+
- :gear: This rule is included in all of `"plugin:vue/vue3-essential"`, `"plugin:vue/vue3-strongly-recommended"` and `"plugin:vue/vue3-recommended"`.
11+
- :wrench: The `--fix` option on the [command line](https://eslint.org/docs/user-guide/command-line-interface#fixing-problems) can automatically fix some of the problems reported by this rule.
12+
13+
## :book: Rule Details
14+
15+
This rule reports use of deprecated `$scopedSlots`. (in Vue.js 3.0.0+).
16+
17+
<eslint-code-block fix :rules="{'vue/no-deprecated-dollar-scopedslots-api': ['error']}">
18+
19+
```vue
20+
<template>
21+
<!-- ✗ BAD -->
22+
<div v-if="$scopedSlots.default"><slot /></div>
23+
</template>
24+
<script>
25+
export default {
26+
render() {
27+
/* ✗ BAD */
28+
return this.$scopedSlots.default()
29+
}
30+
}
31+
</script>
32+
```
33+
34+
</eslint-code-block>
35+
36+
## :wrench: Options
37+
38+
Nothing.
39+
40+
## :books: Further reading
41+
42+
- [Vue RFCs - 0006-slots-unification](https://github.com/vuejs/rfcs/blob/master/active-rfcs/0006-slots-unification.md)
43+
44+
## :mag: Implementation
45+
46+
- [Rule source](https://github.com/vuejs/eslint-plugin-vue/blob/master/lib/rules/no-deprecated-dollar-scopedslots-api.js)
47+
- [Test source](https://github.com/vuejs/eslint-plugin-vue/blob/master/tests/lib/rules/no-deprecated-dollar-scopedslots-api.js)

lib/configs/vue3-essential.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ module.exports = {
1111
'vue/no-async-in-computed-properties': 'error',
1212
'vue/no-deprecated-data-object-declaration': 'error',
1313
'vue/no-deprecated-dollar-listeners-api': 'error',
14+
'vue/no-deprecated-dollar-scopedslots-api': 'error',
1415
'vue/no-deprecated-events-api': 'error',
1516
'vue/no-deprecated-filter': 'error',
1617
'vue/no-deprecated-functional-template': 'error',

lib/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ module.exports = {
5050
'no-custom-modifiers-on-v-model': require('./rules/no-custom-modifiers-on-v-model'),
5151
'no-deprecated-data-object-declaration': require('./rules/no-deprecated-data-object-declaration'),
5252
'no-deprecated-dollar-listeners-api': require('./rules/no-deprecated-dollar-listeners-api'),
53+
'no-deprecated-dollar-scopedslots-api': require('./rules/no-deprecated-dollar-scopedslots-api'),
5354
'no-deprecated-events-api': require('./rules/no-deprecated-events-api'),
5455
'no-deprecated-filter': require('./rules/no-deprecated-filter'),
5556
'no-deprecated-functional-template': require('./rules/no-deprecated-functional-template'),
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/**
2+
* @author Yosuke Ota
3+
* See LICENSE file in root directory for full license.
4+
*/
5+
'use strict'
6+
7+
// ------------------------------------------------------------------------------
8+
// Requirements
9+
// ------------------------------------------------------------------------------
10+
11+
const utils = require('../utils')
12+
13+
// ------------------------------------------------------------------------------
14+
// Rule Definition
15+
// ------------------------------------------------------------------------------
16+
17+
module.exports = {
18+
meta: {
19+
type: 'problem',
20+
docs: {
21+
description:
22+
'disallow using deprecated `$scopedSlots` (in Vue.js 3.0.0+)',
23+
categories: ['vue3-essential'],
24+
url:
25+
'https://eslint.vuejs.org/rules/no-deprecated-dollar-scopedslots-api.html'
26+
},
27+
fixable: 'code',
28+
schema: [],
29+
messages: {
30+
deprecated: 'The `$scopedSlots` is deprecated.'
31+
}
32+
},
33+
34+
create(context) {
35+
return utils.defineTemplateBodyVisitor(
36+
context,
37+
{
38+
VExpressionContainer(node) {
39+
for (const reference of node.references) {
40+
if (reference.variable != null) {
41+
// Not vm reference
42+
continue
43+
}
44+
if (reference.id.name === '$scopedSlots') {
45+
context.report({
46+
node: reference.id,
47+
messageId: 'deprecated',
48+
fix(fixer) {
49+
return fixer.replaceText(reference.id, '$slots')
50+
}
51+
})
52+
}
53+
}
54+
}
55+
},
56+
utils.defineVueVisitor(context, {
57+
MemberExpression(node) {
58+
if (
59+
node.property.type !== 'Identifier' ||
60+
node.property.name !== '$scopedSlots'
61+
) {
62+
return
63+
}
64+
if (!utils.isThis(node.object, context)) {
65+
return
66+
}
67+
68+
context.report({
69+
node: node.property,
70+
messageId: 'deprecated',
71+
fix(fixer) {
72+
return fixer.replaceText(node.property, '$slots')
73+
}
74+
})
75+
}
76+
})
77+
)
78+
}
79+
}

0 commit comments

Comments
 (0)