v-bind-prop-modifier-shorthand.js 972 B

123456789101112131415161718192021222324252627282930313233
  1. /**
  2. * @author Yosuke Ota
  3. * See LICENSE file in root directory for full license.
  4. */
  5. 'use strict'
  6. const { Range } = require('semver')
  7. const unsupported = new Range('<=2.5 || >=2.6.0')
  8. module.exports = {
  9. // >=2.6.0-beta.1 <=2.6.0-beta.3
  10. supported: (versionRange) => {
  11. return !versionRange.intersects(unsupported)
  12. },
  13. createTemplateBodyVisitor (context) {
  14. /**
  15. * Reports `.prop` shorthand node
  16. * @param {VDirectiveKey} bindPropKey node of `.prop` shorthand
  17. * @returns {void}
  18. */
  19. function reportPropModifierShorthand (bindPropKey) {
  20. context.report({
  21. node: bindPropKey,
  22. messageId: 'forbiddenVBindPropModifierShorthand',
  23. // fix to use `:x.prop` (downgrade)
  24. fix: fixer => fixer.replaceText(bindPropKey, `:${bindPropKey.argument.rawName}.prop`)
  25. })
  26. }
  27. return {
  28. "VAttribute[directive=true] > VDirectiveKey[name.name='bind'][name.rawName='.']": reportPropModifierShorthand
  29. }
  30. }
  31. }