require-component-is.js 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. /**
  2. * @author Toru Nagashima
  3. * @copyright 2017 Toru Nagashima. All rights reserved.
  4. * See LICENSE file in root directory for full license.
  5. */
  6. 'use strict'
  7. const utils = require('../utils')
  8. module.exports = {
  9. meta: {
  10. type: 'problem',
  11. docs: {
  12. description: 'require `v-bind:is` of `<component>` elements',
  13. categories: ['vue3-essential', 'vue2-essential'],
  14. url: 'https://eslint.vuejs.org/rules/require-component-is.html'
  15. },
  16. fixable: null,
  17. schema: [],
  18. messages: {
  19. requireComponentIs:
  20. "Expected '<component>' elements to have 'v-bind:is' attribute."
  21. }
  22. },
  23. /** @param {RuleContext} context */
  24. create(context) {
  25. return utils.defineTemplateBodyVisitor(context, {
  26. /** @param {VElement} node */
  27. "VElement[name='component']"(node) {
  28. if (!utils.hasDirective(node, 'bind', 'is')) {
  29. context.report({
  30. node,
  31. loc: node.loc,
  32. messageId: 'requireComponentIs'
  33. })
  34. }
  35. }
  36. })
  37. }
  38. }