@atlaskit/eslint-plugin-ui-styling-standard 0.17.0 → 0.18.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (152) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/dist/cjs/presets/all.codegen.js +3 -2
  3. package/dist/cjs/presets/recommended.codegen.js +3 -2
  4. package/dist/cjs/rules/external-rules.js +3 -1
  5. package/dist/es2019/presets/all.codegen.js +3 -2
  6. package/dist/es2019/presets/recommended.codegen.js +3 -2
  7. package/dist/es2019/rules/external-rules.js +3 -1
  8. package/dist/esm/presets/all.codegen.js +3 -2
  9. package/dist/esm/presets/recommended.codegen.js +3 -2
  10. package/dist/esm/rules/external-rules.js +3 -1
  11. package/dist/types/index.codegen.d.ts +2 -0
  12. package/dist/types/presets/all.codegen.d.ts +2 -1
  13. package/dist/types/presets/recommended.codegen.d.ts +2 -1
  14. package/dist/types-ts4.5/index.codegen.d.ts +2 -0
  15. package/dist/types-ts4.5/presets/all.codegen.d.ts +2 -1
  16. package/dist/types-ts4.5/presets/recommended.codegen.d.ts +2 -1
  17. package/package.json +2 -2
  18. package/afm-cc/tsconfig.json +0 -28
  19. package/afm-jira/tsconfig.json +0 -28
  20. package/build/tsconfig.json +0 -18
  21. package/constellation/atlaskit-theme/usage.mdx +0 -132
  22. package/constellation/consistent-css-prop-usage/usage.mdx +0 -7
  23. package/constellation/convert-props-syntax/usage.mdx +0 -130
  24. package/constellation/enforce-style-prop/usage.mdx +0 -47
  25. package/constellation/index/migration-guide.mdx +0 -309
  26. package/constellation/index/overview.mdx +0 -250
  27. package/constellation/index/props.mdx +0 -30
  28. package/constellation/local-cx-xcss/usage.mdx +0 -53
  29. package/constellation/no-array-arguments/usage.mdx +0 -49
  30. package/constellation/no-classname-prop/usage.mdx +0 -49
  31. package/constellation/no-container-queries/usage.mdx +0 -101
  32. package/constellation/no-css-tagged-template-expression/usage.mdx +0 -8
  33. package/constellation/no-dynamic-styles/usage.mdx +0 -130
  34. package/constellation/no-empty-styled-expression/usage.mdx +0 -8
  35. package/constellation/no-exported-css/usage.mdx +0 -8
  36. package/constellation/no-exported-keyframes/usage.mdx +0 -8
  37. package/constellation/no-exported-styles/usage.mdx +0 -87
  38. package/constellation/no-global-styles/usage.mdx +0 -60
  39. package/constellation/no-important-styles/usage.mdx +0 -33
  40. package/constellation/no-imported-style-values/usage.mdx +0 -157
  41. package/constellation/no-invalid-css-map/usage.mdx +0 -8
  42. package/constellation/no-js-xcss/usage.mdx +0 -7
  43. package/constellation/no-keyframes-tagged-template-expression/usage.mdx +0 -8
  44. package/constellation/no-nested-selectors/usage.mdx +0 -95
  45. package/constellation/no-styled/usage.mdx +0 -92
  46. package/constellation/no-styled-tagged-template-expression/usage.mdx +0 -8
  47. package/constellation/no-suppress-xcss/usage.mdx +0 -28
  48. package/constellation/no-unsafe-selectors/usage.mdx +0 -370
  49. package/constellation/no-unsafe-values/usage.mdx +0 -318
  50. package/constellation/use-compiled/usage.mdx +0 -54
  51. package/index.js +0 -24
  52. package/scripts/codegen.tsx +0 -373
  53. package/src/index.codegen.tsx +0 -14
  54. package/src/index.tsx +0 -1
  55. package/src/presets/all.codegen.tsx +0 -79
  56. package/src/presets/recommended.codegen.tsx +0 -79
  57. package/src/rules/TEMPLATE.md +0 -29
  58. package/src/rules/__tests__/utils/_tester.tsx +0 -40
  59. package/src/rules/atlaskit-theme/README.md +0 -130
  60. package/src/rules/atlaskit-theme/__tests__/test.ts +0 -133
  61. package/src/rules/atlaskit-theme/index.ts +0 -134
  62. package/src/rules/convert-props-syntax/README.md +0 -128
  63. package/src/rules/convert-props-syntax/__tests__/invalid.test.tsx +0 -76
  64. package/src/rules/convert-props-syntax/__tests__/rule.test.tsx +0 -584
  65. package/src/rules/convert-props-syntax/__tests__/type-annotations.test.tsx +0 -140
  66. package/src/rules/convert-props-syntax/__tests__/unusual-properties.test.tsx +0 -69
  67. package/src/rules/convert-props-syntax/index.tsx +0 -414
  68. package/src/rules/enforce-style-prop/README.md +0 -45
  69. package/src/rules/enforce-style-prop/__tests__/rule.test.tsx +0 -243
  70. package/src/rules/enforce-style-prop/index.tsx +0 -172
  71. package/src/rules/external-rules.tsx +0 -175
  72. package/src/rules/index.codegen.tsx +0 -42
  73. package/src/rules/local-cx-xcss/README.md +0 -51
  74. package/src/rules/local-cx-xcss/__tests__/rule.test.tsx +0 -102
  75. package/src/rules/local-cx-xcss/index.tsx +0 -62
  76. package/src/rules/no-array-arguments/README.md +0 -47
  77. package/src/rules/no-array-arguments/__tests__/rule.test.tsx +0 -107
  78. package/src/rules/no-array-arguments/index.tsx +0 -86
  79. package/src/rules/no-classname-prop/README.md +0 -47
  80. package/src/rules/no-classname-prop/__tests__/rule.test.tsx +0 -39
  81. package/src/rules/no-classname-prop/index.tsx +0 -34
  82. package/src/rules/no-container-queries/README.md +0 -99
  83. package/src/rules/no-container-queries/__tests__/rule.test.tsx +0 -139
  84. package/src/rules/no-container-queries/index.tsx +0 -94
  85. package/src/rules/no-dynamic-styles/README.md +0 -128
  86. package/src/rules/no-dynamic-styles/__tests__/rule.test.tsx +0 -135
  87. package/src/rules/no-dynamic-styles/index.tsx +0 -60
  88. package/src/rules/no-exported-styles/README.md +0 -85
  89. package/src/rules/no-exported-styles/__tests__/rule.test.tsx +0 -216
  90. package/src/rules/no-exported-styles/index.tsx +0 -52
  91. package/src/rules/no-global-styles/README.md +0 -58
  92. package/src/rules/no-global-styles/__tests__/no-css-modules.test.tsx +0 -33
  93. package/src/rules/no-global-styles/__tests__/no-global-styles.test.tsx +0 -46
  94. package/src/rules/no-global-styles/index.tsx +0 -82
  95. package/src/rules/no-important-styles/README.md +0 -31
  96. package/src/rules/no-important-styles/__tests__/rule.test.tsx +0 -165
  97. package/src/rules/no-important-styles/index.tsx +0 -70
  98. package/src/rules/no-imported-style-values/README.md +0 -155
  99. package/src/rules/no-imported-style-values/__tests__/rule.test.tsx +0 -491
  100. package/src/rules/no-imported-style-values/index.tsx +0 -188
  101. package/src/rules/no-nested-selectors/README.md +0 -93
  102. package/src/rules/no-nested-selectors/__tests__/rule.test.tsx +0 -335
  103. package/src/rules/no-nested-selectors/index.tsx +0 -99
  104. package/src/rules/no-styled/README.md +0 -90
  105. package/src/rules/no-styled/__tests__/rule.test.tsx +0 -73
  106. package/src/rules/no-styled/index.tsx +0 -45
  107. package/src/rules/no-unsafe-selectors/README.md +0 -368
  108. package/src/rules/no-unsafe-selectors/__tests__/no-ambiguous-pseudos.test.tsx +0 -368
  109. package/src/rules/no-unsafe-selectors/__tests__/no-grouped-at-rules.test.tsx +0 -57
  110. package/src/rules/no-unsafe-selectors/__tests__/no-increased-specificity.test.tsx +0 -73
  111. package/src/rules/no-unsafe-selectors/__tests__/no-keyframes-at-rules.test.tsx +0 -40
  112. package/src/rules/no-unsafe-selectors/__tests__/no-legacy-pseudo-element-syntax.test.tsx +0 -101
  113. package/src/rules/no-unsafe-selectors/__tests__/no-restricted-at-rules.test.tsx +0 -131
  114. package/src/rules/no-unsafe-selectors/__tests__/no-restricted-pseudos.test.tsx +0 -132
  115. package/src/rules/no-unsafe-selectors/__tests__/no-selectors-object.test.tsx +0 -25
  116. package/src/rules/no-unsafe-selectors/__tests__/no-unparsable-selectors.test.tsx +0 -35
  117. package/src/rules/no-unsafe-selectors/__tests__/rule.test.tsx +0 -257
  118. package/src/rules/no-unsafe-selectors/constants.tsx +0 -91
  119. package/src/rules/no-unsafe-selectors/index.tsx +0 -198
  120. package/src/rules/no-unsafe-selectors/lint-selector.tsx +0 -155
  121. package/src/rules/no-unsafe-selectors/source-position-utils.tsx +0 -55
  122. package/src/rules/no-unsafe-selectors/walk-css-map.tsx +0 -226
  123. package/src/rules/no-unsafe-values/README.md +0 -316
  124. package/src/rules/no-unsafe-values/__tests__/no-array-values.test.tsx +0 -27
  125. package/src/rules/no-unsafe-values/__tests__/no-conditional-values.test.tsx +0 -37
  126. package/src/rules/no-unsafe-values/__tests__/no-dynamic-keys.test.tsx +0 -229
  127. package/src/rules/no-unsafe-values/__tests__/no-function-calls.test.tsx +0 -267
  128. package/src/rules/no-unsafe-values/__tests__/no-identifier-arguments.test.tsx +0 -52
  129. package/src/rules/no-unsafe-values/__tests__/no-object-access.test.tsx +0 -106
  130. package/src/rules/no-unsafe-values/__tests__/no-object-references.test.tsx +0 -44
  131. package/src/rules/no-unsafe-values/__tests__/no-spread-elements.test.tsx +0 -48
  132. package/src/rules/no-unsafe-values/__tests__/no-unsafe-values.test.tsx +0 -75
  133. package/src/rules/no-unsafe-values/__tests__/no-variables.test.tsx +0 -121
  134. package/src/rules/no-unsafe-values/index.tsx +0 -94
  135. package/src/rules/no-unsafe-values/messages.tsx +0 -86
  136. package/src/rules/no-unsafe-values/utils.tsx +0 -387
  137. package/src/rules/use-compiled/README.md +0 -52
  138. package/src/rules/use-compiled/__tests__/can-auto-fix.test.tsx +0 -73
  139. package/src/rules/use-compiled/__tests__/css.test.tsx +0 -126
  140. package/src/rules/use-compiled/__tests__/imports.test.tsx +0 -158
  141. package/src/rules/use-compiled/__tests__/keyframes.test.tsx +0 -140
  142. package/src/rules/use-compiled/__tests__/pragma.test.tsx +0 -108
  143. package/src/rules/use-compiled/__tests__/styled.test.tsx +0 -114
  144. package/src/rules/use-compiled/__tests__/use-compiled.test.tsx +0 -15
  145. package/src/rules/use-compiled/index.tsx +0 -252
  146. package/src/rules/use-compiled/is-safe.tsx +0 -159
  147. package/src/rules/use-compiled/utils.tsx +0 -33
  148. package/src/rules/utils/create-rule-with-typed-config.tsx +0 -86
  149. package/src/rules/utils/create-rule.tsx +0 -13
  150. package/tsconfig.app.json +0 -47
  151. package/tsconfig.dev.json +0 -45
  152. package/tsconfig.json +0 -25
@@ -1,584 +0,0 @@
1
- import { typescriptEslintTester } from '../../__tests__/utils/_tester';
2
- import rule from '../index';
3
-
4
- typescriptEslintTester.run(
5
- 'convert-props-syntax',
6
- // @ts-expect-error
7
- rule,
8
- {
9
- valid: [
10
- {
11
- name: 'ignores styled-components usages using supported props syntax',
12
- code: `
13
- import styled from 'styled-components';
14
-
15
- styled.div((props) => ({
16
- color: props.color,
17
- }));
18
- `,
19
- },
20
- {
21
- name: 'ignores @emotion/styled usages using supported props syntax',
22
- code: `
23
- import styled from '@emotion/styled';
24
-
25
- styled.div((props) => ({
26
- color: props.color,
27
- }));
28
- `,
29
- },
30
- {
31
- name: 'ignores styled-components usages already using supported props syntax (with logical operator)',
32
- code: `
33
- import styled from 'styled-components';
34
-
35
- styled.div((props) => ({
36
- color: props => props.color || 'red',
37
- }));
38
- `,
39
- },
40
- {
41
- name: 'ignores styled-components usages using supported props syntax (with multiple properties)',
42
- code: `
43
- import styled from 'styled-components';
44
-
45
- styled.div((props) => ({
46
- color: props.color,
47
- backgroundColor: props.backgroundColor,
48
- }));
49
- `,
50
- },
51
- {
52
- name: 'ignores compiled usages (props argument)',
53
- code: `
54
- import { styled } from '@compiled/react';
55
-
56
- styled.div({
57
- color: (props) => props.color,
58
- backgroundColor: (props) => props.backgroundColor,
59
- });
60
- `,
61
- },
62
- {
63
- name: 'ignores compiled usages (destructured props)',
64
- code: `
65
- import { styled } from '@compiled/react';
66
-
67
- styled.div({
68
- color: ({ color }) => color,
69
- backgroundColor: ({ backgroundColor }) => backgroundColor,
70
- });
71
- `,
72
- },
73
- {
74
- name: 'ignores compiled usages (styled-components style syntax)',
75
- code: `
76
- import { styled } from '@compiled/react';
77
-
78
- styled.div((props) => ({
79
- color: props.color,
80
- backgroundColor: props.backgroundColor,
81
- }));
82
- `,
83
- },
84
- {
85
- name: 'ignores template literals passed to styled-components',
86
- code: `
87
- import { styled } from 'styled-components';
88
-
89
- const someStyles = \`border-radius: \${token('border.radius', '3px')};\`;
90
-
91
- styled.div(someStyles);
92
- `,
93
- },
94
- {
95
- name: 'ignores token function passed to styled-components',
96
- code: `
97
- import styled from 'styled-components';
98
- import { token } from 'some-package';
99
- import { someFallback } from 'other-package';
100
-
101
- styled.div({
102
- color: token('some-token', someFallback),
103
- });
104
- `,
105
- },
106
- {
107
- name: 'ignores styled(...).attrs() call',
108
- code: `
109
- import { styled } from 'styled-components';
110
-
111
- const StyledMinimized = styled(Minimized).attrs({
112
- className: (props) => props.transitionClass,
113
- })\`
114
- color: blue;
115
- \`;
116
- `,
117
- },
118
- {
119
- name: 'ignores styled.div.attrs<...>() call',
120
- code: `
121
- import { styled } from '@compiled/react';
122
-
123
- export const ModalAnchorOld = styled.div.attrs<ModalAnchorProps>({
124
- style: ({ left, top }: ModalAnchorProps) => ({
125
- left,
126
- top,
127
- }),
128
- })\`
129
- position: fixed;
130
- \`;
131
- `,
132
- },
133
- {
134
- name: 'ignores styled.div.attrs() call',
135
- code: `
136
- const BlanketControl = styled.div.attrs({
137
- style: ({ scrollOffset, width }) => ({
138
- top: scrollOffset,
139
- bottom: -scrollOffset,
140
- width,
141
- }),
142
- })\`
143
- display: flex;
144
- justify-content: center;
145
- \`;
146
- `,
147
- },
148
- {
149
- name: 'ignores styled.img.attrs() call',
150
- code: `
151
- export const FieldsRestoredIllustration = styled.img.attrs({ src: fieldsRestoredImage })\`
152
- display: block;
153
- min-height: 190px;
154
- max-width: 290px;
155
- \`;
156
- `,
157
- },
158
- {
159
- name: 'ignores options passed to base components',
160
- code: `
161
- import styled from '@emotion/styled';
162
- import { token } from 'some-package';
163
- import { someFallback } from 'other-package';
164
-
165
- styled(BaseComponent, {
166
- // This should not get flagged
167
- shouldForwardProp: prop => prop !== 'seen'
168
- })({
169
- color: token('some-token', someFallback),
170
- });
171
- `,
172
- },
173
- {
174
- name: 'ignores options passed to base components when using template string',
175
- code: `
176
- import styled from '@emotion/styled';
177
- import { token } from 'some-package';
178
- import { someFallback } from 'other-package';
179
-
180
- styled(Link, {
181
- // This should not get flagged
182
- shouldForwardProp: prop => prop !== 'seen',
183
- })<{ seen?: boolean }>\`
184
- cursor: pointer;
185
- \`;
186
- `,
187
- },
188
- {
189
- name: 'No error on TSAsExpression node type when using ESTraverse',
190
- code: `
191
- import styled from '@emotion/styled';
192
-
193
- const Component = styled.div({
194
- color: token('color.text') as string,
195
- });
196
- `,
197
- },
198
- ],
199
- invalid: [
200
- {
201
- name: 'converts @emotion/styled props argument',
202
- code: `
203
- import styled from '@emotion/styled';
204
-
205
- styled.div({
206
- color: (props) => props.color,
207
- backgroundColor: (props) => props.backgroundColor,
208
- });
209
- `,
210
- output: `
211
- import styled from '@emotion/styled';
212
-
213
- styled.div((props) => ({
214
- color: props.color,
215
- backgroundColor: props.backgroundColor,
216
- }));
217
- `,
218
- errors: [{ messageId: 'unsupported-prop-syntax' }],
219
- },
220
- {
221
- name: 'converts styled-components props argument',
222
- code: `
223
- import styled from 'styled-components';
224
-
225
- styled.div({
226
- color: (props) => props.color,
227
- backgroundColor: (props) => props.backgroundColor,
228
- });
229
- `,
230
- output: `
231
- import styled from 'styled-components';
232
-
233
- styled.div((props) => ({
234
- color: props.color,
235
- backgroundColor: props.backgroundColor,
236
- }));
237
- `,
238
- errors: [{ messageId: 'unsupported-prop-syntax' }],
239
- },
240
- {
241
- name: 'converts styled-components destructured props',
242
- code: `
243
- import styled from 'styled-components';
244
-
245
- styled.div({
246
- color: ({ color }) => color,
247
- backgroundColor: ({ backgroundColor }) => backgroundColor,
248
- });
249
- `,
250
- output: `
251
- import styled from 'styled-components';
252
-
253
- styled.div((props) => ({
254
- color: props.color,
255
- backgroundColor: props.backgroundColor,
256
- }));
257
- `,
258
- errors: [{ messageId: 'unsupported-prop-syntax' }],
259
- },
260
- {
261
- name: 'converts mixture of props argument and destructured props',
262
- code: `
263
- import styled from 'styled-components';
264
-
265
- styled.div({
266
- color: ({ color }) => color,
267
- backgroundColor: (props) => props.backgroundColor,
268
- });
269
- `,
270
- output: `
271
- import styled from 'styled-components';
272
-
273
- styled.div((props) => ({
274
- color: props.color,
275
- backgroundColor: props.backgroundColor,
276
- }));
277
- `,
278
- errors: [{ messageId: 'unsupported-prop-syntax' }],
279
- },
280
- {
281
- name: 'converts mix of valid props syntax and invalid props syntax',
282
- code: `
283
- import styled from 'styled-components';
284
-
285
- styled.div(
286
- (props) => ({
287
- color: props.color,
288
- backgroundColor: props.backgroundColor,
289
- }),
290
- {
291
- height: (props) => props.height,
292
- }
293
- );
294
- `,
295
- output: `
296
- import styled from 'styled-components';
297
-
298
- styled.div(
299
- (props) => ({
300
- color: props.color,
301
- backgroundColor: props.backgroundColor,
302
- }),
303
- (props) => ({
304
- height: props.height,
305
- })
306
- );
307
- `,
308
- errors: [{ messageId: 'unsupported-prop-syntax' }],
309
- },
310
- {
311
- name: 'converts mix of renamed props argument and destructured props',
312
- code: `
313
- import styled from 'styled-components';
314
-
315
- styled.div({
316
- color: ({ customColor }) => customColor,
317
- backgroundColor: (myProps) => myProps.backgroundColor,
318
- height: (props) => props.customHeight,
319
- });
320
- `,
321
- output: `
322
- import styled from 'styled-components';
323
-
324
- styled.div((props) => ({
325
- color: props.customColor,
326
- backgroundColor: props.backgroundColor,
327
- height: props.customHeight,
328
- }));
329
- `,
330
- errors: [{ messageId: 'unsupported-prop-syntax' }],
331
- },
332
- {
333
- name: 'converts props with same name',
334
- code: `
335
- import styled from 'styled-components';
336
-
337
- styled.div({
338
- color: ({ customColor }) => customColor,
339
- backgroundColor: (myProps) => myProps.customColor,
340
- height: (props) => props.customHeight,
341
- });
342
- `,
343
- output: `
344
- import styled from 'styled-components';
345
-
346
- styled.div((props) => ({
347
- color: props.customColor,
348
- backgroundColor: props.customColor,
349
- height: props.customHeight,
350
- }));
351
- `,
352
- errors: [{ messageId: 'unsupported-prop-syntax' }],
353
- },
354
- {
355
- name: 'converts props with same name (variant two)',
356
- code: `
357
- import styled from 'styled-components';
358
-
359
- styled.div({
360
- color: ({ customColor }) => customColor,
361
- backgroundColor: ({ customColor }) => customColor,
362
- height: (props) => props.customHeight,
363
- });
364
- `,
365
- output: `
366
- import styled from 'styled-components';
367
-
368
- styled.div((props) => ({
369
- color: props.customColor,
370
- backgroundColor: props.customColor,
371
- height: props.customHeight,
372
- }));
373
- `,
374
- errors: [{ messageId: 'unsupported-prop-syntax' }],
375
- },
376
- {
377
- name: 'converts props with same name (variant three)',
378
- code: `
379
- import styled from 'styled-components';
380
-
381
- styled.div({
382
- color: (props) => props.customColor,
383
- backgroundColor: (props) => props.customColor,
384
- height: (props) => props.customHeight,
385
- });
386
- `,
387
- output: `
388
- import styled from 'styled-components';
389
-
390
- styled.div((props) => ({
391
- color: props.customColor,
392
- backgroundColor: props.customColor,
393
- height: props.customHeight,
394
- }));
395
- `,
396
- errors: [{ messageId: 'unsupported-prop-syntax' }],
397
- },
398
- {
399
- name: 'converts props inside template literal',
400
- code: `
401
- import styled from 'styled-components';
402
-
403
- styled.div({
404
- backgroundImage: \`url(\${({ src }) => src})\`,
405
- backgroundSize: 'cover',
406
- });
407
- `,
408
- output: `
409
- import styled from 'styled-components';
410
-
411
- styled.div((props) => ({
412
- backgroundImage: \`url(\${props.src})\`,
413
- backgroundSize: 'cover',
414
- }));
415
- `,
416
- errors: [{ messageId: 'unsupported-prop-syntax' }],
417
- },
418
- {
419
- name: 'converts props with complicated expressions',
420
- code: `
421
- import styled from 'styled-components';
422
-
423
- styled.div({
424
- height: ({ height, width }) => height + width,
425
- width: ({ height }) => height,
426
- padding: ({ width }) => \`\${width}px \${width + 3}px \${width + 2}px\`,
427
- });
428
- `,
429
- output: `
430
- import styled from 'styled-components';
431
-
432
- styled.div((props) => ({
433
- height: props.height + props.width,
434
- width: props.height,
435
- padding: \`\${props.width}px \${props.width + 3}px \${props.width + 2}px\`,
436
- }));
437
- `,
438
- errors: [{ messageId: 'unsupported-prop-syntax' }],
439
- },
440
- {
441
- name: 'converts props with overlapping names',
442
- code: `
443
- import styled from 'styled-components';
444
-
445
- styled.div({
446
- height: ({ height, newHeight, oldHeight }) => height + newHeight / oldHeight,
447
- width: ({ height, oldHeight }) => height + oldHeight,
448
- });
449
- `,
450
- output: `
451
- import styled from 'styled-components';
452
-
453
- styled.div((props) => ({
454
- height: props.height + props.newHeight / props.oldHeight,
455
- width: props.height + props.oldHeight,
456
- }));
457
- `,
458
- errors: [{ messageId: 'unsupported-prop-syntax' }],
459
- },
460
- {
461
- name: 'converts props mixed with token function',
462
- code: `
463
- import styled from 'styled-components';
464
- import { someFallback } from 'some-package';
465
-
466
- styled.div({
467
- padding: ({ myPadding }) => \`\${token('some-token', someFallback)} \${myPadding}\`,
468
- });
469
- `,
470
- output: `
471
- import styled from 'styled-components';
472
- import { someFallback } from 'some-package';
473
-
474
- styled.div((props) => ({
475
- padding: \`\${token('some-token', someFallback)} \${props.myPadding}\`,
476
- }));
477
- `,
478
- errors: [{ messageId: 'unsupported-prop-syntax' }],
479
- },
480
- {
481
- name: 'converts mix of styled variable arguments and object arguments',
482
- code: `
483
- import styled from 'styled-components';
484
- import { someFallback } from 'some-package';
485
-
486
- const someVariable = {
487
- color: 'blue',
488
- }
489
-
490
- styled.div(
491
- someVariable,
492
- css\`
493
- color: 'pink';
494
- \`,
495
- {
496
- height: ({ myHeight }) => \`\${myHeight + 5}px\`,
497
- }
498
- );
499
- `,
500
- output: `
501
- import styled from 'styled-components';
502
- import { someFallback } from 'some-package';
503
-
504
- const someVariable = {
505
- color: 'blue',
506
- }
507
-
508
- styled.div(
509
- someVariable,
510
- css\`
511
- color: 'pink';
512
- \`,
513
- (props) => ({
514
- height: \`\${props.myHeight + 5}px\`,
515
- })
516
- );
517
- `,
518
- errors: [{ messageId: 'unsupported-prop-syntax' }],
519
- },
520
- {
521
- name: 'converts mix of props and non-props',
522
- code: `
523
- import styled from 'styled-components';
524
-
525
- styled.div({
526
- padding: '5px',
527
- width: ({ myWidth }) => myWidth,
528
- margin: \`2px \${token('some-token')}\`
529
- });
530
- `,
531
- output: `
532
- import styled from 'styled-components';
533
-
534
- styled.div((props) => ({
535
- padding: '5px',
536
- width: props.myWidth,
537
- margin: \`2px \${token('some-token')}\`
538
- }));
539
- `,
540
- errors: [{ messageId: 'unsupported-prop-syntax' }],
541
- },
542
- {
543
- name: 'converts styled-components props argument when extending existing component',
544
- code: `
545
- import styled from 'styled-components';
546
-
547
- styled(BaseComponent)({
548
- color: (props) => props.color,
549
- backgroundColor: (props) => props.backgroundColor,
550
- });
551
- `,
552
- output: `
553
- import styled from 'styled-components';
554
-
555
- styled(BaseComponent)((props) => ({
556
- color: props.color,
557
- backgroundColor: props.backgroundColor,
558
- }));
559
- `,
560
- errors: [{ messageId: 'unsupported-prop-syntax' }],
561
- },
562
- {
563
- name: 'converts styled-components props argument when using css function',
564
- code: `
565
- import { css } from 'styled-components';
566
-
567
- css({
568
- color: (props) => props.color,
569
- backgroundColor: (props) => props.backgroundColor,
570
- });
571
- `,
572
- output: `
573
- import { css } from 'styled-components';
574
-
575
- css((props) => ({
576
- color: props.color,
577
- backgroundColor: props.backgroundColor,
578
- }));
579
- `,
580
- errors: [{ messageId: 'unsupported-prop-syntax' }],
581
- },
582
- ],
583
- },
584
- );
@@ -1,140 +0,0 @@
1
- import { typescriptEslintTester } from '../../__tests__/utils/_tester';
2
- import rule from '../index';
3
-
4
- typescriptEslintTester.run(
5
- 'convert-props-syntax',
6
- // @ts-expect-error
7
- rule,
8
- {
9
- valid: [
10
- {
11
- name: 'ignores type annotation in props argument',
12
- code: `
13
- import styled from 'styled-components';
14
-
15
- type Props = {
16
- color: string;
17
- myBackground: string;
18
- }
19
-
20
- styled.div((props: Props) => ({
21
- color: props.color,
22
- backgroundColor: props.myBackground,
23
- }))
24
- `,
25
- },
26
- ],
27
- invalid: [
28
- {
29
- name: 'converts styled usages with type annotation on the outside',
30
- code: `
31
- import styled from 'styled-components';
32
-
33
- styled.div<{ color: string; backgroundColor: string; }>({
34
- color: (props) => props.color,
35
- backgroundColor: ({ backgroundColor }) => backgroundColor,
36
- });
37
- `,
38
- output: `
39
- import styled from 'styled-components';
40
-
41
- styled.div<{ color: string; backgroundColor: string; }>((props) => ({
42
- color: props.color,
43
- backgroundColor: props.backgroundColor,
44
- }));
45
- `,
46
- errors: [{ messageId: 'unsupported-prop-syntax' }],
47
- },
48
- {
49
- name: 'converts styled usages with type annotation on the outside (as a variable)',
50
- code: `
51
- import styled from 'styled-components';
52
-
53
- type Props = {
54
- color: string; backgroundColor: string;
55
- };
56
-
57
- styled.div<Props>({
58
- color: (props) => props.color,
59
- backgroundColor: ({ backgroundColor }) => backgroundColor,
60
- });
61
- `,
62
- output: `
63
- import styled from 'styled-components';
64
-
65
- type Props = {
66
- color: string; backgroundColor: string;
67
- };
68
-
69
- styled.div<Props>((props) => ({
70
- color: props.color,
71
- backgroundColor: props.backgroundColor,
72
- }));
73
- `,
74
- errors: [{ messageId: 'unsupported-prop-syntax' }],
75
- },
76
- {
77
- name: 'disables autofixer when type annotation is inside props argument',
78
- code: `
79
- import styled from 'styled-components';
80
-
81
- type Props = {
82
- color: string;
83
- backgroundColor: string;
84
- }
85
-
86
- styled.div({
87
- color: (props: Props) => props.color,
88
- backgroundColor: (props: Props) => props.backgroundColor,
89
- });
90
- `,
91
- errors: [
92
- {
93
- messageId: 'unsupported-prop-syntax-no-autofixer',
94
- },
95
- ],
96
- },
97
- {
98
- name: 'disables autofixer when type annotation is given for destructured props',
99
- code: `
100
- import styled from 'styled-components';
101
-
102
- type Props = {
103
- color: string;
104
- backgroundColor: string;
105
- }
106
-
107
- styled.div({
108
- color: ({ color }: Props) => color,
109
- backgroundColor: ({ backgroundColor }: Props) => backgroundColor,
110
- });
111
- `,
112
- errors: [
113
- {
114
- messageId: 'unsupported-prop-syntax-no-autofixer',
115
- },
116
- ],
117
- },
118
- {
119
- name: 'disables autofixer when type annotation is inside props within template literal',
120
- code: `
121
- import styled from 'styled-components';
122
-
123
- interface ThumbnailProps {
124
- src: string;
125
- }
126
-
127
- styled.div({
128
- backgroundImage: \`url(\${({ src }: ThumbnailProps) => src})\`,
129
- backgroundSize: 'cover',
130
- });
131
- `,
132
- errors: [
133
- {
134
- messageId: 'unsupported-prop-syntax-no-autofixer',
135
- },
136
- ],
137
- },
138
- ],
139
- },
140
- );