valid-v-pre.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. const utils = require('../utils')
  8. module.exports = {
  9. meta: {
  10. type: 'problem',
  11. docs: {
  12. description: 'enforce valid `v-pre` directives',
  13. categories: ['vue3-essential', 'vue2-essential'],
  14. url: 'https://eslint.vuejs.org/rules/valid-v-pre.html'
  15. },
  16. fixable: null,
  17. schema: [],
  18. messages: {
  19. unexpectedArgument: "'v-pre' directives require no argument.",
  20. unexpectedModifier: "'v-pre' directives require no modifier.",
  21. unexpectedValue: "'v-pre' directives require no attribute value."
  22. }
  23. },
  24. /** @param {RuleContext} context */
  25. create(context) {
  26. return utils.defineTemplateBodyVisitor(context, {
  27. /** @param {VDirective} node */
  28. "VAttribute[directive=true][key.name.name='pre']"(node) {
  29. if (node.key.argument) {
  30. context.report({
  31. node: node.key.argument,
  32. messageId: 'unexpectedArgument'
  33. })
  34. }
  35. if (node.key.modifiers.length > 0) {
  36. context.report({
  37. node,
  38. loc: {
  39. start: node.key.modifiers[0].loc.start,
  40. end: node.key.modifiers[node.key.modifiers.length - 1].loc.end
  41. },
  42. messageId: 'unexpectedModifier'
  43. })
  44. }
  45. if (node.value) {
  46. context.report({
  47. node: node.value,
  48. messageId: 'unexpectedValue'
  49. })
  50. }
  51. }
  52. })
  53. }
  54. }