valid-v-bind.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. type: 'problem',
  21. docs: {
  22. description: 'enforce valid `v-bind` directives',
  23. category: 'essential',
  24. url: 'https://eslint.vuejs.org/rules/valid-v-bind.html'
  25. },
  26. fixable: null,
  27. schema: []
  28. },
  29. create (context) {
  30. return utils.defineTemplateBodyVisitor(context, {
  31. "VAttribute[directive=true][key.name='bind']" (node) {
  32. for (const modifier of node.key.modifiers) {
  33. if (!VALID_MODIFIERS.has(modifier)) {
  34. context.report({
  35. node,
  36. loc: node.key.loc,
  37. message: "'v-bind' directives don't support the modifier '{{name}}'.",
  38. data: { name: modifier }
  39. })
  40. }
  41. }
  42. if (!utils.hasAttributeValue(node)) {
  43. context.report({
  44. node,
  45. loc: node.loc,
  46. message: "'v-bind' directives require an attribute value."
  47. })
  48. }
  49. }
  50. })
  51. }
  52. }