require-component-is.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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. // ------------------------------------------------------------------------------
  8. // Requirements
  9. // ------------------------------------------------------------------------------
  10. const utils = require('../utils')
  11. // ------------------------------------------------------------------------------
  12. // Rule Definition
  13. // ------------------------------------------------------------------------------
  14. module.exports = {
  15. meta: {
  16. type: 'problem',
  17. docs: {
  18. description: 'require `v-bind:is` of `<component>` elements',
  19. categories: ['vue3-essential', 'essential'],
  20. url: 'https://eslint.vuejs.org/rules/require-component-is.html'
  21. },
  22. fixable: null,
  23. schema: []
  24. },
  25. /** @param {RuleContext} context */
  26. create(context) {
  27. return utils.defineTemplateBodyVisitor(context, {
  28. /** @param {VElement} node */
  29. "VElement[name='component']"(node) {
  30. if (!utils.hasDirective(node, 'bind', 'is')) {
  31. context.report({
  32. node,
  33. loc: node.loc,
  34. message:
  35. "Expected '<component>' elements to have 'v-bind:is' attribute."
  36. })
  37. }
  38. }
  39. })
  40. }
  41. }