require-name-property.js 966 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. /**
  2. * @fileoverview Require a name property in Vue components
  3. * @author LukeeeeBennett
  4. */
  5. 'use strict'
  6. const utils = require('../utils')
  7. /**
  8. * @param {Property | SpreadElement} node
  9. * @returns {node is ObjectExpressionProperty}
  10. */
  11. function isNameProperty(node) {
  12. return (
  13. node.type === 'Property' &&
  14. utils.getStaticPropertyName(node) === 'name' &&
  15. !node.computed
  16. )
  17. }
  18. module.exports = {
  19. meta: {
  20. type: 'suggestion',
  21. docs: {
  22. description: 'require a name property in Vue components',
  23. categories: undefined,
  24. url: 'https://eslint.vuejs.org/rules/require-name-property.html'
  25. },
  26. fixable: null,
  27. schema: []
  28. },
  29. /** @param {RuleContext} context */
  30. create(context) {
  31. return utils.executeOnVue(context, (component) => {
  32. if (component.properties.some(isNameProperty)) return
  33. context.report({
  34. node: component,
  35. message: 'Required name property is not set.'
  36. })
  37. })
  38. }
  39. }