zammad-detect-translatable-string.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. // Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. /**
  3. * @fileoverview Detect unmarked translatable strings
  4. * @author Martin Gruner
  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-detect-translatable-string.js')
  12. /* eslint-enable @typescript-eslint/no-require-imports */
  13. //------------------------------------------------------------------------------
  14. // Tests
  15. //------------------------------------------------------------------------------
  16. const ruleTester = new RuleTester()
  17. ruleTester.run('zammad-detect-translatable-string', rule, {
  18. valid: [
  19. {
  20. filename: 'test.ts',
  21. code: `'OnlyOneWord'`,
  22. },
  23. {
  24. filename: 'test.ts',
  25. code: `'starts with lower case'`,
  26. },
  27. {
  28. filename: 'test.ts',
  29. code: `if (variable === 'Some test string') true`,
  30. },
  31. {
  32. filename: 'test.ts',
  33. code: `__('Already marked message.')`,
  34. },
  35. {
  36. filename: 'test.ts',
  37. code: `i18n.t('Already translated string.')`,
  38. },
  39. {
  40. filename: 'test.ts',
  41. code: `console.log('Some debug message.')`,
  42. },
  43. {
  44. filename: 'test.ts',
  45. // eslint-disable-next-line no-template-curly-in-string
  46. code: '"String with ${interpolation}..."', // Not fully correct, but a ``-template string does not seem to work.
  47. },
  48. ],
  49. invalid: [
  50. {
  51. filename: 'test.js',
  52. code: `'String that should be translatable'`,
  53. errors: [
  54. {
  55. message:
  56. 'This string looks like it should be marked as translatable via __(...)',
  57. },
  58. ],
  59. output: `__('String that should be translatable')`,
  60. },
  61. ],
  62. })