require-name-property.js 800 B

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