valid-v-bind.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. // Helpers
  13. // ------------------------------------------------------------------------------
  14. const VALID_MODIFIERS = new Set(['prop', 'camel', 'sync'])
  15. // ------------------------------------------------------------------------------
  16. // Rule Definition
  17. // ------------------------------------------------------------------------------
  18. module.exports = {
  19. meta: {
  20. docs: {
  21. description: 'enforce valid `v-bind` directives',
  22. category: 'essential',
  23. url: 'https://github.com/vuejs/eslint-plugin-vue/blob/v4.7.1/docs/rules/valid-v-bind.md'
  24. },
  25. fixable: null,
  26. schema: []
  27. },
  28. create (context) {
  29. return utils.defineTemplateBodyVisitor(context, {
  30. "VAttribute[directive=true][key.name='bind']" (node) {
  31. for (const modifier of node.key.modifiers) {
  32. if (!VALID_MODIFIERS.has(modifier)) {
  33. context.report({
  34. node,
  35. loc: node.key.loc,
  36. message: "'v-bind' directives don't support the modifier '{{name}}'.",
  37. data: { name: modifier }
  38. })
  39. }
  40. }
  41. if (!utils.hasAttributeValue(node)) {
  42. context.report({
  43. node,
  44. loc: node.loc,
  45. message: "'v-bind' directives require an attribute value."
  46. })
  47. }
  48. }
  49. })
  50. }
  51. }