zammad-detect-translatable-string.js 1.8 KB

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