zammad-tailwind-ltr.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. // Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. /**
  3. * @fileoverview Enforce "ltr/rtl" rule, if positioning classes are used
  4. * @author Vladimir Sheremet
  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-tailwind-ltr.js')
  12. /* eslint-enable @typescript-eslint/no-require-imports */
  13. //------------------------------------------------------------------------------
  14. // Tests
  15. //------------------------------------------------------------------------------
  16. const error =
  17. 'When positioning classes are used, they must be prefixed with ltr/rtl.'
  18. const ruleTester = new RuleTester()
  19. ruleTester.run('zammad-tailwind-ltr', rule, {
  20. valid: [
  21. {
  22. filename: 'test.ts',
  23. code: `console.log('i am testing')`,
  24. },
  25. {
  26. filename: 'test.ts',
  27. code: `'ltr:pl-2 rtl:pr-2'`,
  28. },
  29. {
  30. filename: 'test.ts',
  31. code: `'text-black flex flex-col'`,
  32. },
  33. {
  34. filename: 'test.ts',
  35. code: `{ name: 'ltr:pl-2 rtl:pr-2' }`,
  36. },
  37. {
  38. filename: 'test.js',
  39. code: `'pl-2 pr-2'`,
  40. },
  41. {
  42. filename: 'test.js',
  43. code: `{ name: 'pl-2 pr-2' }`,
  44. },
  45. {
  46. filename: 'test.js',
  47. code: `{ name: 'left-0 right-0' }`,
  48. },
  49. {
  50. filename: 'test.js',
  51. code: `'left-0 right-0'`,
  52. },
  53. ],
  54. invalid: [
  55. {
  56. filename: 'test.js',
  57. code: `'pl-2'`,
  58. output: `'rtl:pr-2 ltr:pl-2'`,
  59. errors: [{ message: error }],
  60. },
  61. {
  62. filename: 'test.js',
  63. code: `'!pl-2'`,
  64. output: `'rtl:!pr-2 ltr:!pl-2'`,
  65. errors: [{ message: error }],
  66. },
  67. {
  68. filename: 'test.js',
  69. code: `'-pl-2'`,
  70. output: `'rtl:-pr-2 ltr:-pl-2'`,
  71. errors: [{ message: error }],
  72. },
  73. {
  74. filename: 'test.js',
  75. code: `'!-pl-2'`,
  76. output: `'rtl:!-pr-2 ltr:!-pl-2'`,
  77. errors: [{ message: error }],
  78. },
  79. {
  80. filename: 'test.js',
  81. code: `'left-2'`,
  82. output: `'rtl:right-2 ltr:left-2'`,
  83. errors: [{ message: error }],
  84. },
  85. {
  86. filename: 'test.js',
  87. code: `'!left-2'`,
  88. output: `'rtl:!right-2 ltr:!left-2'`,
  89. errors: [{ message: error }],
  90. },
  91. {
  92. filename: 'test.js',
  93. code: `{ name: 'pl-2' }`,
  94. output: `{ name: 'rtl:pr-2 ltr:pl-2' }`,
  95. errors: [{ message: error }],
  96. },
  97. {
  98. filename: 'test.js',
  99. code: `'pr-2'`,
  100. output: `'rtl:pl-2 ltr:pr-2'`,
  101. errors: [{ message: error }],
  102. },
  103. {
  104. filename: 'test.js',
  105. code: `'right-2'`,
  106. output: `'rtl:left-2 ltr:right-2'`,
  107. errors: [{ message: error }],
  108. },
  109. {
  110. filename: 'test.js',
  111. code: `{ name: 'pr-2' }`,
  112. output: `{ name: 'rtl:pl-2 ltr:pr-2' }`,
  113. errors: [{ message: error }],
  114. },
  115. {
  116. filename: 'test.js',
  117. code: `{ name: 'rtl:pl-2 pr-2' }`,
  118. output: `{ name: 'rtl:pl-2 ltr:pr-2' }`,
  119. errors: [{ message: error }],
  120. },
  121. {
  122. filename: 'test.js',
  123. code: `{ name: 'ml-2 pr-2' }`,
  124. output: `{ name: 'rtl:mr-2 ltr:ml-2 rtl:pl-2 ltr:pr-2' }`,
  125. errors: [{ message: error }],
  126. },
  127. {
  128. filename: 'test.js',
  129. code: `{ name: 'ltr:mr-2' }`,
  130. output: `{ name: 'ltr:mr-2 rtl:ml-2' }`,
  131. errors: [{ message: error }],
  132. },
  133. {
  134. filename: 'test.ts',
  135. code: `{ name: 'rtl:pl-2' }`,
  136. output: `{ name: 'rtl:pl-2 ltr:pr-2' }`,
  137. errors: [{ message: error }],
  138. },
  139. {
  140. filename: 'test.ts',
  141. code: `{ name: 'rtl:left-2' }`,
  142. output: `{ name: 'rtl:left-2 ltr:right-2' }`,
  143. errors: [{ message: error }],
  144. },
  145. {
  146. filename: 'test.ts',
  147. code: `'translate-x-2'`,
  148. output: `'rtl:-translate-x-2 ltr:translate-x-2'`,
  149. errors: [{ message: error }],
  150. },
  151. {
  152. filename: 'test.ts',
  153. code: `'!translate-x-2'`,
  154. output: `'rtl:!-translate-x-2 ltr:!translate-x-2'`,
  155. errors: [{ message: error }],
  156. },
  157. {
  158. filename: 'test.ts',
  159. code: `'-translate-x-2'`,
  160. output: `'rtl:translate-x-2 ltr:-translate-x-2'`,
  161. errors: [{ message: error }],
  162. },
  163. {
  164. filename: 'test.ts',
  165. code: `'!-translate-x-2'`,
  166. output: `'rtl:!translate-x-2 ltr:!-translate-x-2'`,
  167. errors: [{ message: error }],
  168. },
  169. {
  170. filename: 'test.js',
  171. code: `'left-0 right-1'`,
  172. output: `'rtl:right-0 ltr:left-0 rtl:left-1 ltr:right-1'`,
  173. errors: [{ message: error }],
  174. },
  175. ],
  176. })