no-deprecated-dollar-scopedslots-api.js 2.1 KB

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