-
-
Notifications
You must be signed in to change notification settings - Fork 666
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
vue/no-deprecated-dollar-scopedslots-api
rule. (#1177)
- Loading branch information
Showing
6 changed files
with
417 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
--- | ||
pageClass: rule-details | ||
sidebarDepth: 0 | ||
title: vue/no-deprecated-dollar-scopedslots-api | ||
description: disallow using deprecated `$scopedSlots` (in Vue.js 3.0.0+) | ||
--- | ||
# vue/no-deprecated-dollar-scopedslots-api | ||
> disallow using deprecated `$scopedSlots` (in Vue.js 3.0.0+) | ||
- :gear: This rule is included in all of `"plugin:vue/vue3-essential"`, `"plugin:vue/vue3-strongly-recommended"` and `"plugin:vue/vue3-recommended"`. | ||
- :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. | ||
|
||
## :book: Rule Details | ||
|
||
This rule reports use of deprecated `$scopedSlots`. (in Vue.js 3.0.0+). | ||
|
||
<eslint-code-block fix :rules="{'vue/no-deprecated-dollar-scopedslots-api': ['error']}"> | ||
|
||
```vue | ||
<template> | ||
<!-- ✗ BAD --> | ||
<div v-if="$scopedSlots.default"><slot /></div> | ||
</template> | ||
<script> | ||
export default { | ||
render() { | ||
/* ✗ BAD */ | ||
return this.$scopedSlots.default() | ||
} | ||
} | ||
</script> | ||
``` | ||
|
||
</eslint-code-block> | ||
|
||
## :wrench: Options | ||
|
||
Nothing. | ||
|
||
## :books: Further reading | ||
|
||
- [Vue RFCs - 0006-slots-unification](https://github.com/vuejs/rfcs/blob/master/active-rfcs/0006-slots-unification.md) | ||
|
||
## :mag: Implementation | ||
|
||
- [Rule source](https://github.com/vuejs/eslint-plugin-vue/blob/master/lib/rules/no-deprecated-dollar-scopedslots-api.js) | ||
- [Test source](https://github.com/vuejs/eslint-plugin-vue/blob/master/tests/lib/rules/no-deprecated-dollar-scopedslots-api.js) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/** | ||
* @author Yosuke Ota | ||
* See LICENSE file in root directory for full license. | ||
*/ | ||
'use strict' | ||
|
||
// ------------------------------------------------------------------------------ | ||
// Requirements | ||
// ------------------------------------------------------------------------------ | ||
|
||
const utils = require('../utils') | ||
|
||
// ------------------------------------------------------------------------------ | ||
// Rule Definition | ||
// ------------------------------------------------------------------------------ | ||
|
||
module.exports = { | ||
meta: { | ||
type: 'problem', | ||
docs: { | ||
description: | ||
'disallow using deprecated `$scopedSlots` (in Vue.js 3.0.0+)', | ||
categories: ['vue3-essential'], | ||
url: | ||
'https://eslint.vuejs.org/rules/no-deprecated-dollar-scopedslots-api.html' | ||
}, | ||
fixable: 'code', | ||
schema: [], | ||
messages: { | ||
deprecated: 'The `$scopedSlots` is deprecated.' | ||
} | ||
}, | ||
|
||
create(context) { | ||
return utils.defineTemplateBodyVisitor( | ||
context, | ||
{ | ||
VExpressionContainer(node) { | ||
for (const reference of node.references) { | ||
if (reference.variable != null) { | ||
// Not vm reference | ||
continue | ||
} | ||
if (reference.id.name === '$scopedSlots') { | ||
context.report({ | ||
node: reference.id, | ||
messageId: 'deprecated', | ||
fix(fixer) { | ||
return fixer.replaceText(reference.id, '$slots') | ||
} | ||
}) | ||
} | ||
} | ||
} | ||
}, | ||
utils.defineVueVisitor(context, { | ||
MemberExpression(node) { | ||
if ( | ||
node.property.type !== 'Identifier' || | ||
node.property.name !== '$scopedSlots' | ||
) { | ||
return | ||
} | ||
if (!utils.isThis(node.object, context)) { | ||
return | ||
} | ||
|
||
context.report({ | ||
node: node.property, | ||
messageId: 'deprecated', | ||
fix(fixer) { | ||
return fixer.replaceText(node.property, '$slots') | ||
} | ||
}) | ||
} | ||
}) | ||
) | ||
} | ||
} |
Oops, something went wrong.