|
| 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