zammad-symbol-description.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. // Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. /**
  3. * @fileoverview Enforce kebab-case for Symbol descriptors
  4. * @author Benjamin Scharf
  5. */
  6. //------------------------------------------------------------------------------
  7. // Requirements
  8. //------------------------------------------------------------------------------
  9. /* eslint-disable @typescript-eslint/no-require-imports */
  10. const { RuleTester } = require('eslint')
  11. const rule = require('../../../lib/rules/zammad-symbol-description.js')
  12. /* eslint-enable @typescript-eslint/no-require-imports */
  13. //------------------------------------------------------------------------------
  14. // Tests
  15. //------------------------------------------------------------------------------
  16. const ruleTester = new RuleTester({
  17. parser: require.resolve('vue-eslint-parser'),
  18. parserOptions: {
  19. ecmaVersion: 2020,
  20. sourceType: 'module',
  21. },
  22. })
  23. ruleTester.run('zammad-symbol-descriptor', rule, {
  24. valid: [
  25. {
  26. filename: 'test.ts',
  27. code: `Symbol('foo-bar')`,
  28. },
  29. {
  30. filename: 'test.ts',
  31. code: `Symbol('foo')`,
  32. },
  33. {
  34. filename: 'test.js',
  35. code: `Symbol('foo')`,
  36. },
  37. {
  38. filename: 'test.js',
  39. code: `Symbol('foo-bar')`,
  40. },
  41. {
  42. filename: 'test.vue',
  43. code: `<script lang="ts" setup>Symbol('foo-bar')</script>`,
  44. },
  45. {
  46. filename: 'test.vue',
  47. code: `<script lang="ts" setup>Symbol('foo')</script>`,
  48. },
  49. ],
  50. invalid: [
  51. {
  52. filename: 'test.ts',
  53. code: `Symbol('FooBar')`,
  54. errors: [{ message: 'Symbol description should be in kebab-case.' }],
  55. },
  56. {
  57. filename: 'test.ts',
  58. code: `Symbol('fooBar')`,
  59. errors: [{ message: 'Symbol description should be in kebab-case.' }],
  60. },
  61. {
  62. filename: 'test.ts',
  63. code: `Symbol('foo bar')`,
  64. errors: [{ message: 'Symbol description should be in kebab-case.' }],
  65. },
  66. {
  67. filename: 'test.js',
  68. code: `Symbol('FooBar')`,
  69. errors: [{ message: 'Symbol description should be in kebab-case.' }],
  70. },
  71. {
  72. filename: 'test.js',
  73. code: `Symbol('fooBar')`,
  74. errors: [{ message: 'Symbol description should be in kebab-case.' }],
  75. },
  76. {
  77. filename: 'test.ts',
  78. code: `Symbol('foo bar')`,
  79. errors: [{ message: 'Symbol description should be in kebab-case.' }],
  80. },
  81. {
  82. filename: 'test.vue',
  83. code: `<script lang="ts" setup> Symbol('FooBar')</script>`,
  84. errors: [{ message: 'Symbol description should be in kebab-case.' }],
  85. },
  86. {
  87. filename: 'test.vue',
  88. code: `<script lang="ts" setup> Symbol('fooBar')</script>`,
  89. errors: [{ message: 'Symbol description should be in kebab-case.' }],
  90. },
  91. {
  92. filename: 'test.vue',
  93. code: `<script lang="ts" setup> Symbol('foo bar')</script>`,
  94. errors: [{ message: 'Symbol description should be in kebab-case.' }],
  95. },
  96. ],
  97. })