valid-v-text.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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: 'enforce valid `v-text` directives',
  19. category: 'essential',
  20. url: 'https://eslint.vuejs.org/rules/valid-v-text.html'
  21. },
  22. fixable: null,
  23. schema: []
  24. },
  25. create (context) {
  26. return utils.defineTemplateBodyVisitor(context, {
  27. "VAttribute[directive=true][key.name='text']" (node) {
  28. if (node.key.argument) {
  29. context.report({
  30. node,
  31. loc: node.loc,
  32. message: "'v-text' directives require no argument."
  33. })
  34. }
  35. if (node.key.modifiers.length > 0) {
  36. context.report({
  37. node,
  38. loc: node.loc,
  39. message: "'v-text' directives require no modifier."
  40. })
  41. }
  42. if (!utils.hasAttributeValue(node)) {
  43. context.report({
  44. node,
  45. loc: node.loc,
  46. message: "'v-text' directives require that attribute value."
  47. })
  48. }
  49. }
  50. })
  51. }
  52. }