no-v-text-v-html-on-component.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /**
  2. * @author Yosuke Ota
  3. * See LICENSE file in root directory for full license.
  4. */
  5. 'use strict'
  6. const utils = require('../utils')
  7. module.exports = {
  8. meta: {
  9. type: 'problem',
  10. docs: {
  11. description: 'disallow v-text / v-html on component',
  12. categories: ['essential', 'vue3-essential'],
  13. url: 'https://eslint.vuejs.org/rules/no-v-text-v-html-on-component.html'
  14. },
  15. fixable: null,
  16. schema: [],
  17. messages: {
  18. disallow:
  19. "Using {{directiveName}} on component may break component's content."
  20. }
  21. },
  22. /** @param {RuleContext} context */
  23. create(context) {
  24. /**
  25. * Verify for v-text and v-html directive
  26. * @param {VDirective} node
  27. */
  28. function verify(node) {
  29. const element = node.parent.parent
  30. if (utils.isCustomComponent(element)) {
  31. context.report({
  32. node,
  33. loc: node.loc,
  34. messageId: 'disallow',
  35. data: {
  36. directiveName: `v-${node.key.name.name}`
  37. }
  38. })
  39. }
  40. }
  41. return utils.defineTemplateBodyVisitor(context, {
  42. "VAttribute[directive=true][key.name.name='text']": verify,
  43. "VAttribute[directive=true][key.name.name='html']": verify
  44. })
  45. }
  46. }