zammad-symbol-description.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. // Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. /**
  3. * @fileoverview Enforces consistent kebab-case for Symbol descriptors
  4. * @author Benjamin Scharf
  5. */
  6. //------------------------------------------------------------------------------
  7. // Rule Definition
  8. //------------------------------------------------------------------------------
  9. /**
  10. * @type {import('eslint').Rule.RuleModule}
  11. */
  12. const kebabCaseRegex = /^[a-z-]+$/
  13. module.exports = {
  14. meta: {
  15. type: 'problem',
  16. docs: {
  17. description: 'Enforce kebab-case for Symbol description',
  18. category: 'Stylistic Issues',
  19. recommended: true,
  20. },
  21. schema: [],
  22. },
  23. create(context) {
  24. return {
  25. // eslint-disable-next-line object-shorthand
  26. 'CallExpression[callee.name="Symbol"]'(node) {
  27. const descriptor = node.arguments[0]
  28. if (!descriptor && typeof descriptor.value !== 'string') return
  29. if (!kebabCaseRegex.test(descriptor.value))
  30. context.report({
  31. node: descriptor,
  32. message: 'Symbol description should be in kebab-case.',
  33. })
  34. },
  35. }
  36. },
  37. }