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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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: 'disallow v-text / v-html on component',
  18. // TODO We will change it in the next major version.
  19. // categories: ['essential', 'vue3-essential'],
  20. categories: undefined,
  21. url: 'https://eslint.vuejs.org/rules/no-v-text-v-html-on-component.html'
  22. },
  23. fixable: null,
  24. schema: [],
  25. messages: {
  26. disallow:
  27. "Using {{directiveName}} on component may break component's content."
  28. }
  29. },
  30. /** @param {RuleContext} context */
  31. create(context) {
  32. /**
  33. * Verify for v-text and v-html directive
  34. * @param {VDirective} node
  35. */
  36. function verify(node) {
  37. const element = node.parent.parent
  38. if (utils.isCustomComponent(element)) {
  39. context.report({
  40. node,
  41. loc: node.loc,
  42. messageId: 'disallow',
  43. data: {
  44. directiveName: `v-${node.key.name.name}`
  45. }
  46. })
  47. }
  48. }
  49. return utils.defineTemplateBodyVisitor(context, {
  50. "VAttribute[directive=true][key.name.name='text']": verify,
  51. "VAttribute[directive=true][key.name.name='html']": verify
  52. })
  53. }
  54. }