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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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:
  21. 'https://eslint.vuejs.org/rules/no-deprecated-dollar-scopedslots-api.html'
  22. },
  23. fixable: 'code',
  24. schema: [],
  25. messages: {
  26. deprecated: 'The `$scopedSlots` is deprecated.'
  27. }
  28. },
  29. /** @param {RuleContext} context */
  30. create(context) {
  31. return utils.defineTemplateBodyVisitor(
  32. context,
  33. {
  34. VExpressionContainer(node) {
  35. for (const reference of node.references) {
  36. if (reference.variable != null) {
  37. // Not vm reference
  38. continue
  39. }
  40. if (reference.id.name === '$scopedSlots') {
  41. context.report({
  42. node: reference.id,
  43. messageId: 'deprecated',
  44. fix(fixer) {
  45. return fixer.replaceText(reference.id, '$slots')
  46. }
  47. })
  48. }
  49. }
  50. }
  51. },
  52. utils.defineVueVisitor(context, {
  53. MemberExpression(node) {
  54. if (
  55. node.property.type !== 'Identifier' ||
  56. node.property.name !== '$scopedSlots'
  57. ) {
  58. return
  59. }
  60. if (!utils.isThis(node.object, context)) {
  61. return
  62. }
  63. context.report({
  64. node: node.property,
  65. messageId: 'deprecated',
  66. fix(fixer) {
  67. return fixer.replaceText(node.property, '$slots')
  68. }
  69. })
  70. }
  71. })
  72. )
  73. }
  74. }