no-v-model-argument.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /**
  2. * @author Przemyslaw Falowski (@przemkow)
  3. * @fileoverview This rule checks whether v-model used on custom component do not have an argument
  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:
  18. 'disallow adding an argument to `v-model` used in custom component',
  19. categories: ['essential'],
  20. url: 'https://eslint.vuejs.org/rules/no-v-model-argument.html'
  21. },
  22. fixable: null,
  23. schema: [],
  24. messages: {
  25. vModelRequireNoArgument: "'v-model' directives require no argument."
  26. }
  27. },
  28. /** @param {RuleContext} context */
  29. create(context) {
  30. return utils.defineTemplateBodyVisitor(context, {
  31. /** @param {VDirective} node */
  32. "VAttribute[directive=true][key.name.name='model']"(node) {
  33. const element = node.parent.parent
  34. if (node.key.argument && utils.isCustomComponent(element)) {
  35. context.report({
  36. node,
  37. loc: node.loc,
  38. messageId: 'vModelRequireNoArgument'
  39. })
  40. }
  41. }
  42. })
  43. }
  44. }