zammad-tailwind-ltr.js 4.5 KB

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